From patchwork Tue Nov 11 01:00:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 409157 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id F2F3E140170 for ; Tue, 11 Nov 2014 12:10:25 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1DE584B694; Tue, 11 Nov 2014 02:10:24 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tfeFoC-Wpgw2; Tue, 11 Nov 2014 02:10:23 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 455724B6D4; Tue, 11 Nov 2014 02:10:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 02E5C4B60C for ; Tue, 11 Nov 2014 02:10:15 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m5HgEUIbGmi5 for ; Tue, 11 Nov 2014 02:10:14 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ie0-f201.google.com (mail-ie0-f201.google.com [209.85.223.201]) by theia.denx.de (Postfix) with ESMTPS id A3BDD4B60F for ; Tue, 11 Nov 2014 02:10:10 +0100 (CET) Received: by mail-ie0-f201.google.com with SMTP id rd18so1553614iec.2 for ; Mon, 10 Nov 2014 17:10:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MVYX6DtxYGAKAWi3WieTqUL6/In0JCD1DhaKNjuZ9LQ=; b=UeBZt4g8fI9rqpCbVcWXAguKucJd3R+BVNIcdrtC+jRlCMzJfaMkRllTHfZ0gziHGr LKjX4uSeJL/xbr+w9EDpAfcHnBGEejRLq+NDMy+1YG8yVcmCMvYcvyDBemA8oOLbTSXx ka8AZpH+D9ayqde/dJ8XBShO+oB0a3h8T4BJYDx3XM580cYkEnTgJT+odSOzXLRsrCzL pZ4hMibLez7DiFgFddNX6T3a8iCQrHzMGMTkdxloVrqbfNaRgRZsGk+E39DFY6KO1kuk ebAqgj7GY0rImIV1Y7QU7M0Afs+Xabaw79Hsdh/ClKja1DJ9jwfdLGCWZWieRkqUUic6 s+mA== X-Gm-Message-State: ALoCoQkmUcTHXiDNz/SIYJ8aPQZLV6OYfpNOCzJtcpEb9ma4zDMwujzgIbFaV0ZHRx55+8L3MdWE X-Received: by 10.182.4.7 with SMTP id g7mr29101871obg.36.1415668209382; Mon, 10 Nov 2014 17:10:09 -0800 (PST) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id s23si752095yhf.0.2014.11.10.17.10.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Nov 2014 17:10:09 -0800 (PST) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id 2zFP1e8n.1; Mon, 10 Nov 2014 17:10:09 -0800 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 2247C221201; Mon, 10 Nov 2014 18:01:14 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Mon, 10 Nov 2014 18:00:26 -0700 Message-Id: <1415667650-14899-10-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1415667650-14899-1-git-send-email-sjg@chromium.org> References: <1415667650-14899-1-git-send-email-sjg@chromium.org> Cc: Graeme Russ Subject: [U-Boot] [PATCH v2 09/33] x86: Replace fill_processor_name() with cpu_get_name() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This implementation has a 'cpu' prefix and returns a pointer to the string, avoiding the need for copying. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v2: - Add new patch to replace fill_processor_name() with cpu_get_name() arch/x86/cpu/cpu.c | 22 ++++++++++------------ arch/x86/include/asm/cpu.h | 11 ++++++++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c index a4e639d..0d75941 100644 --- a/arch/x86/cpu/cpu.c +++ b/arch/x86/cpu/cpu.c @@ -491,14 +491,14 @@ const char *cpu_vendor_name(int vendor) return name; } -void fill_processor_name(char *processor_name) +char *cpu_get_name(char *name) { + unsigned int *name_as_ints = (unsigned int *)name; struct cpuid_result regs; - char temp_processor_name[49]; - char *processor_name_start; - unsigned int *name_as_ints = (unsigned int *)temp_processor_name; + char *ptr; int i; + /* This bit adds up to 48 bytes */ for (i = 0; i < 3; i++) { regs = cpuid(0x80000002 + i); name_as_ints[i * 4 + 0] = regs.eax; @@ -506,19 +506,17 @@ void fill_processor_name(char *processor_name) name_as_ints[i * 4 + 2] = regs.ecx; name_as_ints[i * 4 + 3] = regs.edx; } - - temp_processor_name[48] = 0; + name[CPU_MAX_NAME_LEN - 1] = '\0'; /* Skip leading spaces. */ - processor_name_start = temp_processor_name; - while (*processor_name_start == ' ') - processor_name_start++; + ptr = name; + while (*ptr == ' ') + ptr++; - memset(processor_name, 0, 49); - strcpy(processor_name, processor_name_start); + return ptr; } -int print_cpuinfo(void) +int default_print_cpuinfo(void) { printf("CPU: %s, vendor %s, device %xh\n", cpu_has_64bit() ? "x86_64" : "x86", diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index 89b748b..c839291 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -179,12 +179,17 @@ int cpu_has_64bit(void); */ const char *cpu_vendor_name(int vendor); +#define CPU_MAX_NAME_LEN 49 + /** - * fill_processor_name() - Get processor name + * cpu_get_name() - Get the name of the current cpu * - * @processor_name: Address to hold the processor name string + * @name: Place to put name, which must be CPU_MAX_NAME_LEN bytes including + * @return pointer to name, which will likely be a few bytes after the start + * of @name + * \0 terminator */ -void fill_processor_name(char *processor_name); +char *cpu_get_name(char *name); /** * cpu_call64() - Jump to a 64-bit Linux kernel (internal function)