]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
x86: Show the CPU vendor in bdinfo
authorSimon Glass <sjg@chromium.org>
Wed, 28 Aug 2024 01:44:24 +0000 (19:44 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 18 Oct 2024 20:10:21 +0000 (14:10 -0600)
Refactor the cpu code and use it to show the CPU vendor, e.g.
AuthenticAMD or GenuineIntel

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/x86/cpu/i386/cpu.c
arch/x86/include/asm/u-boot-x86.h
arch/x86/lib/bdinfo.c

index d837fb97982d74c129bbf505345e7d74e45f6076..532f690c8748f9647f42c3d69aa3e96fca728b4d 100644 (file)
@@ -263,6 +263,49 @@ static int build_vendor_name(char *vendor_name)
 }
 #endif
 
+int x86_cpu_vendor_info(char *name)
+{
+       uint cpu_device;
+
+       cpu_device = 0;
+
+       /* gcc 7.3 does not want to drop x86_vendors, so use #ifdef */
+#ifndef CONFIG_TPL_BUILD
+       *name = '\0'; /* Unset */
+
+       /* Find the id and vendor_name */
+       if (!has_cpuid()) {
+               /* Its a 486 if we can modify the AC flag */
+               if (flag_is_changeable_p(X86_EFLAGS_AC))
+                       cpu_device = 0x00000400; /* 486 */
+               else
+                       cpu_device = 0x00000300; /* 386 */
+               if (cpu_device == 0x00000400 && test_cyrix_52div()) {
+                       /* If we ever care we can enable cpuid here */
+                       memcpy(name, "CyrixInstead", 13);
+
+               /* Detect NexGen with old hypercode */
+               } else if (deep_magic_nexgen_probe()) {
+                       memcpy(name, "NexGenDriven", 13);
+               }
+       } else {
+               int cpuid_level;
+
+               cpuid_level = build_vendor_name(name);
+               name[12] = '\0';
+
+               /* Intel-defined flags: level 0x00000001 */
+               if (cpuid_level >= 0x00000001)
+                       cpu_device = cpuid_eax(0x00000001);
+               else
+                       /* Have CPUID level 0 only unheard of */
+                       cpu_device = 0x00000400;
+       }
+#endif /* CONFIG_TPL_BUILD */
+
+       return cpu_device;
+}
+
 static void identify_cpu(struct cpu_device_id *cpu)
 {
        cpu->device = 0; /* fix gcc 4.4.4 warning */
@@ -289,46 +332,19 @@ static void identify_cpu(struct cpu_device_id *cpu)
                return;
        }
 
-/* gcc 7.3 does not want to drop x86_vendors, so use #ifdef */
 #ifndef CONFIG_TPL_BUILD
-       char vendor_name[16];
-       int i;
-
-       vendor_name[0] = '\0'; /* Unset */
-
-       /* Find the id and vendor_name */
-       if (!has_cpuid()) {
-               /* Its a 486 if we can modify the AC flag */
-               if (flag_is_changeable_p(X86_EFLAGS_AC))
-                       cpu->device = 0x00000400; /* 486 */
-               else
-                       cpu->device = 0x00000300; /* 386 */
-               if ((cpu->device == 0x00000400) && test_cyrix_52div()) {
-                       memcpy(vendor_name, "CyrixInstead", 13);
-                       /* If we ever care we can enable cpuid here */
-               }
-               /* Detect NexGen with old hypercode */
-               else if (deep_magic_nexgen_probe())
-                       memcpy(vendor_name, "NexGenDriven", 13);
-       } else {
-               int cpuid_level;
-
-               cpuid_level = build_vendor_name(vendor_name);
-               vendor_name[12] = '\0';
-
-               /* Intel-defined flags: level 0x00000001 */
-               if (cpuid_level >= 0x00000001) {
-                       cpu->device = cpuid_eax(0x00000001);
-               } else {
-                       /* Have CPUID level 0 only unheard of */
-                       cpu->device = 0x00000400;
-               }
-       }
-       cpu->vendor = X86_VENDOR_UNKNOWN;
-       for (i = 0; i < ARRAY_SIZE(x86_vendors); i++) {
-               if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) {
-                       cpu->vendor = x86_vendors[i].vendor;
-                       break;
+       {
+               char vendor_name[16];
+               int i;
+
+               cpu->device = x86_cpu_vendor_info(vendor_name);
+
+               cpu->vendor = X86_VENDOR_UNKNOWN;
+               for (i = 0; i < ARRAY_SIZE(x86_vendors); i++) {
+                       if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) {
+                               cpu->vendor = x86_vendors[i].vendor;
+                               break;
+                       }
                }
        }
 #endif
index 3acc58ad74b494635c79961a2210947753f1af3f..5cc8f63334ef225195c44fa7755fff007a8277f7 100644 (file)
@@ -51,6 +51,14 @@ int x86_cpu_init_tpl(void);
  */
 void cpu_reinit_fpu(void);
 
+/**
+ * x86_cpu_vendor_info() - Get the CPU-vendor name and device number
+ *
+ * @name: 13-byte area to hold the returned string
+ * Return: CPU device number read from cpuid
+ */
+int x86_cpu_vendor_info(char *name);
+
 int cpu_init_f(void);
 void setup_gdt(struct global_data *id, u64 *gdt_addr);
 /*
index 165e8ab944f016a268b309444305c9969c27cc77..2a78f578dee3976e4295a02b15a270f86f444d58 100644 (file)
@@ -19,7 +19,12 @@ void arch_print_bdinfo(void)
        bdinfo_print_num_l("clock_rate", gd->arch.clock_rate);
        bdinfo_print_num_l("tsc_base", gd->arch.tsc_base);
        bdinfo_print_num_l("vendor", gd->arch.x86_vendor);
-       bdinfo_print_str(" name", cpu_vendor_name(gd->arch.x86_vendor));
+       if (!IS_ENABLED(CONFIG_X86_64)) {
+               char vendor_name[16];
+
+               x86_cpu_vendor_info(vendor_name);
+               bdinfo_print_str(" name", vendor_name);
+       }
        bdinfo_print_num_l("model", gd->arch.x86_model);
        bdinfo_print_num_l("phys_addr in bits", cpu_phys_address_size());
        bdinfo_print_num_l("table start", gd->arch.table_start);