Use X86_PROPERTY_SUPPORTED_XCR0_{LO,HI} to implement get_supported_xcr0(). Opportunistically rename the helper and move it to processor.h. Reviewed-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx> --- lib/x86/processor.h | 9 +++++++++ x86/xsave.c | 11 +---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 10391cc0..b3ea6881 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -442,6 +442,15 @@ static inline u8 cpuid_maxphyaddr(void) return this_cpu_property(X86_PROPERTY_MAX_PHY_ADDR); } +static inline u64 this_cpu_supported_xcr0(void) +{ + if (!this_cpu_has_p(X86_PROPERTY_SUPPORTED_XCR0_LO)) + return 0; + + return (u64)this_cpu_property(X86_PROPERTY_SUPPORTED_XCR0_LO) | + ((u64)this_cpu_property(X86_PROPERTY_SUPPORTED_XCR0_HI) << 32); +} + struct far_pointer32 { u32 offset; u16 selector; diff --git a/x86/xsave.c b/x86/xsave.c index 5d80f245..cc8e3a0a 100644 --- a/x86/xsave.c +++ b/x86/xsave.c @@ -8,15 +8,6 @@ #define uint64_t unsigned long long #endif -static uint64_t get_supported_xcr0(void) -{ - struct cpuid r; - r = cpuid_indexed(0xd, 0); - printf("eax %x, ebx %x, ecx %x, edx %x\n", - r.a, r.b, r.c, r.d); - return r.a + ((u64)r.d << 32); -} - #define XCR_XFEATURE_ENABLED_MASK 0x00000000 #define XCR_XFEATURE_ILLEGAL_MASK 0x00000010 @@ -33,7 +24,7 @@ static void test_xsave(void) printf("Legal instruction testing:\n"); - supported_xcr0 = get_supported_xcr0(); + supported_xcr0 = this_cpu_supported_xcr0(); printf("Supported XCR0 bits: %#lx\n", supported_xcr0); test_bits = XSTATE_FP | XSTATE_SSE; -- 2.50.0.rc0.642.g800a2b2222-goog