]> xenbits.xensource.com Git - people/liuw/xtf.git/commitdiff
Collect the CPU vendor on boot, and make it available for tests
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 23 May 2016 18:21:06 +0000 (19:21 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 23 May 2016 18:44:39 +0000 (19:44 +0100)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/decode.c
arch/x86/setup.c
include/arch/x86/cpuid.h
include/arch/x86/decode.h

index 2fb65b89e6193b9aab4a5785401a94f86404a911..5924d2353856b321aa2238ca7ca81912a49026ed 100644 (file)
@@ -9,6 +9,17 @@
 #include <arch/x86/decode.h>
 #include <arch/x86/processor.h>
 
+const char *x86_vendor_name(enum x86_vendor v)
+{
+    static const char *const names[] =
+    {
+        [X86_VENDOR_INTEL] = "Intel",
+        [X86_VENDOR_AMD]   = "AMD",
+    };
+
+    return (v < ARRAY_SIZE(names) && names[v]) ? names[v] : "Unknown";
+}
+
 const char *x86_exc_short_name(unsigned int exc)
 {
     static const char *const names[] =
index dda9fe8aab025672719631c712aef9078750f386..dd214927cd96ac2898297596d1201c93cf33ae38 100644 (file)
@@ -17,6 +17,7 @@
  */
 uint8_t boot_stack[2 * PAGE_SIZE] __aligned(PAGE_SIZE);
 uint32_t x86_features[FSCAPINTS];
+enum x86_vendor x86_vendor;
 
 const char *environment_description = ENVIRONMENT_DESCRIPTION;
 
@@ -27,9 +28,22 @@ start_info_t *start_info = NULL;
 
 static void collect_cpuid(cpuid_count_fn_t cpuid_fn)
 {
-    unsigned int max, tmp;
+    unsigned int max, tmp, ebx, ecx, edx;
 
-    cpuid_fn(0, 0, &max, &tmp, &tmp, &tmp);
+    cpuid_fn(0, 0, &max, &ebx, &ecx, &edx);
+
+    if ( ebx == 0x756e6547u &&      /* "GenuineIntel" */
+         ecx == 0x6c65746eu &&
+         edx == 0x49656e69u )
+        x86_vendor = X86_VENDOR_INTEL;
+
+    else if ( ebx == 0x68747541u && /* "AuthenticAMD" */
+              ecx == 0x444d4163u &&
+              edx == 0x69746e65u )
+        x86_vendor = X86_VENDOR_AMD;
+
+    else
+        x86_vendor = X86_VENDOR_UNKNOWN;
 
     if ( max >= 1 )
         cpuid_fn(1, 0, &tmp, &tmp,
index e88d95e952185bf4aebf7d829ef62e3e46fbd7e0..04c40e06ecfab2f8fc2ece5bd8afb6ad97cae3cd 100644 (file)
@@ -13,6 +13,24 @@ typedef void (*cpuid_count_fn_t)(uint32_t leaf, uint32_t subleaf,
                                  uint32_t *eax, uint32_t *ebx,
                                  uint32_t *ecx, uint32_t *edx);
 
+enum x86_vendor
+{
+    X86_VENDOR_UNKNOWN,
+    X86_VENDOR_INTEL,
+    X86_VENDOR_AMD,
+};
+
+extern enum x86_vendor x86_vendor;
+
+static inline bool vendor_is(enum x86_vendor v)
+{
+    return x86_vendor == v;
+}
+
+#define vendor_is_intel         vendor_is(X86_VENDOR_INTEL)
+#define vendor_is_amd           vendor_is(X86_VENDOR_AMD)
+
+
 #define cpufeat_word(idx)       ((idx) / 32)
 #define cpufeat_bit(idx)        ((idx) % 32)
 #define cpufeat_mask(idx)       (_AC(1, U) << cpufeat_bit(idx))
index 3146b2aba07641f24a431b6559a5cb6937e68b97..930af1e65aa56a81bd830153b6661c821d549f21 100644 (file)
@@ -1,13 +1,23 @@
 /**
  * @file include/arch/x86/decode.h
  *
- * Helper routines for decoding x86 architectural state.
+ * Helper routines for decoding x86 state.
  */
 #ifndef XTF_X86_DECODE_H
 #define XTF_X86_DECODE_H
 
 #include <xtf/types.h>
 
+#include <arch/x86/cpuid.h>
+
+/**
+ * String of the indentified vendor @p v.
+ *
+ * @param v Vendor.
+ * @return String.
+ */
+const char *x86_vendor_name(enum x86_vendor v);
+
 /**
  * String abbreviation of @p ev.
  *