x86: Replace fill_processor_name() with cpu_get_name()
authorSimon Glass <sjg@chromium.org>
Tue, 11 Nov 2014 01:00:26 +0000 (18:00 -0700)
committerSimon Glass <sjg@chromium.org>
Fri, 21 Nov 2014 06:24:12 +0000 (07:24 +0100)
This implementation has a 'cpu' prefix and returns a pointer to the string,
avoiding the need for copying.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/x86/cpu/coreboot/coreboot.c
arch/x86/cpu/cpu.c
arch/x86/include/asm/cpu.h
arch/x86/include/asm/u-boot-x86.h

index 5527183a79482754c8ad7c94ec9af458412ff196..c9f83b0e60508497a3488c05f69cb51b393f4543 100644 (file)
@@ -72,6 +72,11 @@ void show_boot_progress(int val)
        outb(val, 0x80);
 }
 
+int print_cpuinfo(void)
+{
+       return default_print_cpuinfo();
+}
+
 int last_stage_init(void)
 {
        if (gd->flags & GD_FLG_COLD_BOOT)
index 358361970fe427ccfdc2203c7ef56b6020a580cc..97c77ba161045ac86d9030356f8f94185e69d3f1 100644 (file)
@@ -492,14 +492,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;
@@ -507,19 +507,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",
index 89b748b3926d418e6ef5f931d38b4725bd9e5f58..c8392915f1dbe87ce741946970682334281d1c85 100644 (file)
@@ -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)
index 8d5b43891c32c84a13de9598c1b7ad4b0bf92f39..0399417e4094685bb05731945e019b0531021361 100644 (file)
@@ -45,6 +45,7 @@ int x86_init_cache(void);
 void reset_cpu(ulong addr);
 ulong board_get_usable_ram_top(ulong total_size);
 void dram_init_banksize(void);
+int default_print_cpuinfo(void);
 
 void setup_pcat_compatibility(void);