[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen staging] libx86: Introduce x86_cpuid_lookup_vendor()
commit e72309ffbe7c4e507649c74749f130cda691131c Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> AuthorDate: Wed Mar 20 14:05:11 2019 +0000 Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> CommitDate: Wed Mar 27 14:45:47 2019 +0000 libx86: Introduce x86_cpuid_lookup_vendor() Also introduce constants for the vendor strings in CPUID leaf 0. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx> --- tools/tests/cpu-policy/test-cpu-policy.c | 37 ++++++++++++++++++++++++++++++++ xen/include/asm-x86/x86-vendors.h | 21 ++++++++++++++++++ xen/include/xen/lib/x86/cpuid.h | 6 ++++++ xen/lib/x86/cpuid.c | 32 +++++++++++++++++++++++++++ xen/lib/x86/private.h | 1 + 5 files changed, 97 insertions(+) diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c index d13963e896..beced5e9a6 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -8,6 +8,7 @@ #include <err.h> #include <xen-tools/libs.h> +#include <xen/asm/x86-vendors.h> #include <xen/lib/x86/cpuid.h> #include <xen/lib/x86/msr.h> #include <xen/domctl.h> @@ -19,6 +20,40 @@ static unsigned int nr_failures; printf(fmt, ##__VA_ARGS__); \ }) +static void test_vendor_identification(void) +{ + static const struct test { + union { + char ident[12]; + struct { + uint32_t b, d, c; + }; + }; + unsigned int vendor; + } tests[] = { + { { "GenuineIntel" }, X86_VENDOR_INTEL }, + { { "AuthenticAMD" }, X86_VENDOR_AMD }, + { { "CentaurHauls" }, X86_VENDOR_CENTAUR }, + { { " Shanghai " }, X86_VENDOR_SHANGHAI }, + + { { "" }, X86_VENDOR_UNKNOWN }, + { { " " }, X86_VENDOR_UNKNOWN }, + { { "xxxxxxxxxxxx" }, X86_VENDOR_UNKNOWN }, + }; + + printf("Testing CPU vendor identification:\n"); + + for ( size_t i = 0; i < ARRAY_SIZE(tests); ++i ) + { + const struct test *t = &tests[i]; + unsigned int vendor = x86_cpuid_lookup_vendor(t->b, t->c, t->d); + + if ( vendor != t->vendor ) + fail(" Test '%.12s', expected vendor %u, got %u\n", + t->ident, t->vendor, vendor); + } +} + static void test_cpuid_serialise_success(void) { static const struct test { @@ -243,6 +278,8 @@ int main(int argc, char **argv) { printf("CPU Policy unit tests\n"); + test_vendor_identification(); + test_cpuid_serialise_success(); test_msr_serialise_success(); diff --git a/xen/include/asm-x86/x86-vendors.h b/xen/include/asm-x86/x86-vendors.h index 38a81c3c6c..774ceac74d 100644 --- a/xen/include/asm-x86/x86-vendors.h +++ b/xen/include/asm-x86/x86-vendors.h @@ -3,12 +3,33 @@ /* * CPU vendor IDs + * + * - X86_VENDOR_* are Xen-internal identifiers. Values and order are + * arbitrary. + * - X86_VENDOR_*_E?X are architectural information from CPUID leaf 0 */ #define X86_VENDOR_UNKNOWN 0 + #define X86_VENDOR_INTEL 1 +#define X86_VENDOR_INTEL_EBX 0x756e6547U /* "GenuineIntel" */ +#define X86_VENDOR_INTEL_ECX 0x6c65746eU +#define X86_VENDOR_INTEL_EDX 0x49656e69U + #define X86_VENDOR_AMD 2 +#define X86_VENDOR_AMD_EBX 0x68747541U /* "AuthenticAMD" */ +#define X86_VENDOR_AMD_ECX 0x444d4163U +#define X86_VENDOR_AMD_EDX 0x69746e65U + #define X86_VENDOR_CENTAUR 3 +#define X86_VENDOR_CENTAUR_EBX 0x746e6543U /* "CentaurHauls" */ +#define X86_VENDOR_CENTAUR_ECX 0x736c7561U +#define X86_VENDOR_CENTAUR_EDX 0x48727561U + #define X86_VENDOR_SHANGHAI 4 +#define X86_VENDOR_SHANGHAI_EBX 0x68532020U /* " Shanghai " */ +#define X86_VENDOR_SHANGHAI_ECX 0x20206961U +#define X86_VENDOR_SHANGHAI_EDX 0x68676e61U + #define X86_VENDOR_NUM 5 #endif /* __XEN_X86_VENDORS_H__ */ diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpuid.h index 95b37b6b0a..f392c78358 100644 --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -65,6 +65,12 @@ static inline void cpuid_count_leaf( #undef BX_CON #undef XCHG +/** + * Given the vendor id from CPUID leaf 0, look up Xen's internal integer + * vendor ID. Returns X86_VENDOR_UNKNOWN for any unknown vendor. + */ +unsigned int x86_cpuid_lookup_vendor(uint32_t ebx, uint32_t ecx, uint32_t edx); + #define CPUID_GUEST_NR_BASIC (0xdu + 1) #define CPUID_GUEST_NR_CACHE (5u + 1) #define CPUID_GUEST_NR_FEAT (0u + 1) diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 6c60ba8f26..104a867064 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -2,6 +2,38 @@ #include <xen/lib/x86/cpuid.h> +unsigned int x86_cpuid_lookup_vendor(uint32_t ebx, uint32_t ecx, uint32_t edx) +{ + switch ( ebx ) + { + case X86_VENDOR_INTEL_EBX: + if ( ecx == X86_VENDOR_INTEL_ECX && + edx == X86_VENDOR_INTEL_EDX ) + return X86_VENDOR_INTEL; + break; + + case X86_VENDOR_AMD_EBX: + if ( ecx == X86_VENDOR_AMD_ECX && + edx == X86_VENDOR_AMD_EDX ) + return X86_VENDOR_AMD; + break; + + case X86_VENDOR_CENTAUR_EBX: + if ( ecx == X86_VENDOR_CENTAUR_ECX && + edx == X86_VENDOR_CENTAUR_EDX ) + return X86_VENDOR_CENTAUR; + break; + + case X86_VENDOR_SHANGHAI_EBX: + if ( ecx == X86_VENDOR_SHANGHAI_ECX && + edx == X86_VENDOR_SHANGHAI_EDX ) + return X86_VENDOR_SHANGHAI; + break; + } + + return X86_VENDOR_UNKNOWN; +} + void x86_cpuid_policy_fill_native(struct cpuid_policy *p) { unsigned int i; diff --git a/xen/lib/x86/private.h b/xen/lib/x86/private.h index 6fb502269b..f5b195e46d 100644 --- a/xen/lib/x86/private.h +++ b/xen/lib/x86/private.h @@ -23,6 +23,7 @@ #include <stddef.h> #include <xen/asm/msr-index.h> +#include <xen/asm/x86-vendors.h> #include <xen-tools/libs.h> -- generated by git-patchbot for /home/xen/git/xen.git#staging _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |