iPXE
cpuid.h
Go to the documentation of this file.
00001 #ifndef _IPXE_CPUID_H
00002 #define _IPXE_CPUID_H
00003 
00004 /** @file
00005  *
00006  * x86 CPU feature detection
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 
00014 /** An x86 CPU feature register set */
00015 struct x86_feature_registers {
00016         /** Features returned via %ecx */
00017         uint32_t ecx;
00018         /** Features returned via %edx */
00019         uint32_t edx;
00020 };
00021 
00022 /** x86 CPU features */
00023 struct x86_features {
00024         /** Intel-defined features (%eax=0x00000001) */
00025         struct x86_feature_registers intel;
00026         /** AMD-defined features (%eax=0x80000001) */
00027         struct x86_feature_registers amd;
00028 };
00029 
00030 /** CPUID support flag */
00031 #define CPUID_FLAG 0x00200000UL
00032 
00033 /** CPUID extended function */
00034 #define CPUID_EXTENDED 0x80000000UL
00035 
00036 /** Get vendor ID and largest standard function */
00037 #define CPUID_VENDOR_ID 0x00000000UL
00038 
00039 /** Get standard features */
00040 #define CPUID_FEATURES 0x00000001UL
00041 
00042 /** Hypervisor is present */
00043 #define CPUID_FEATURES_INTEL_ECX_HYPERVISOR 0x80000000UL
00044 
00045 /** Get largest extended function */
00046 #define CPUID_AMD_MAX_FN 0x80000000UL
00047 
00048 /** Extended function existence check */
00049 #define CPUID_AMD_CHECK 0x80000000UL
00050 
00051 /** Extended function existence check mask */
00052 #define CPUID_AMD_CHECK_MASK 0xffff0000UL
00053 
00054 /** Get extended features */
00055 #define CPUID_AMD_FEATURES 0x80000001UL
00056 
00057 /** Get CPU model */
00058 #define CPUID_MODEL 0x80000002UL
00059 
00060 /** Get APM information */
00061 #define CPUID_APM 0x80000007UL
00062 
00063 /** Invariant TSC */
00064 #define CPUID_APM_EDX_TSC_INVARIANT 0x00000100UL
00065 
00066 /**
00067  * Issue CPUID instruction
00068  *
00069  * @v function          CPUID function (input via %eax)
00070  * @v subfunction       CPUID subfunction (input via %ecx)
00071  * @v eax               Output via %eax
00072  * @v ebx               Output via %ebx
00073  * @v ecx               Output via %ecx
00074  * @v edx               Output via %edx
00075  */
00076 static inline __attribute__ (( always_inline )) void
00077 cpuid ( uint32_t function, uint32_t subfunction, uint32_t *eax, uint32_t *ebx,
00078         uint32_t *ecx, uint32_t *edx ) {
00079 
00080         __asm__ ( "cpuid"
00081                   : "=a" ( *eax ), "=b" ( *ebx ), "=c" ( *ecx ), "=d" ( *edx )
00082                   : "0" ( function ), "2" ( subfunction ) );
00083 }
00084 
00085 extern int cpuid_supported ( uint32_t function );
00086 extern void x86_features ( struct x86_features *features );
00087 
00088 #endif /* _IPXE_CPUID_H */