iPXE
Data Structures | Macros | Functions | Variables
cpuid.h File Reference

x86 CPU feature detection More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  x86_feature_registers
 An x86 CPU feature register set. More...
 
struct  x86_features
 x86 CPU features More...
 

Macros

#define CPUID_FLAG   0x00200000UL
 CPUID support flag. More...
 
#define CPUID_EXTENDED   0x80000000UL
 CPUID extended function. More...
 
#define CPUID_VENDOR_ID   0x00000000UL
 Get vendor ID and largest standard function. More...
 
#define CPUID_FEATURES   0x00000001UL
 Get standard features. More...
 
#define CPUID_FEATURES_INTEL_ECX_HYPERVISOR   0x80000000UL
 Hypervisor is present. More...
 
#define CPUID_AMD_MAX_FN   0x80000000UL
 Get largest extended function. More...
 
#define CPUID_AMD_CHECK   0x80000000UL
 Extended function existence check. More...
 
#define CPUID_AMD_CHECK_MASK   0xffff0000UL
 Extended function existence check mask. More...
 
#define CPUID_AMD_FEATURES   0x80000001UL
 Get extended features. More...
 
#define CPUID_MODEL   0x80000002UL
 Get CPU model. More...
 
#define CPUID_APM   0x80000007UL
 Get APM information. More...
 
#define CPUID_APM_EDX_TSC_INVARIANT   0x00000100UL
 Invariant TSC. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static __attribute__ ((always_inline)) void cpuid(uint32_t function
 Issue CPUID instruction. More...
 
int cpuid_supported (uint32_t function)
 Check whether or not CPUID function is supported. More...
 
void x86_features (struct x86_features *features)
 Get x86 CPU features. More...
 

Variables

struct x86_feature_registers __attribute__
 
static uint32_t subfunction
 
static uint32_t uint32_teax
 
static uint32_t uint32_t uint32_tebx
 
static uint32_t uint32_t uint32_t uint32_tecx
 
static uint32_t uint32_t uint32_t uint32_t uint32_tedx
 

Detailed Description

x86 CPU feature detection

Definition in file cpuid.h.

Macro Definition Documentation

◆ CPUID_FLAG

#define CPUID_FLAG   0x00200000UL

CPUID support flag.

Definition at line 31 of file cpuid.h.

◆ CPUID_EXTENDED

#define CPUID_EXTENDED   0x80000000UL

CPUID extended function.

Definition at line 34 of file cpuid.h.

◆ CPUID_VENDOR_ID

#define CPUID_VENDOR_ID   0x00000000UL

Get vendor ID and largest standard function.

Definition at line 37 of file cpuid.h.

◆ CPUID_FEATURES

#define CPUID_FEATURES   0x00000001UL

Get standard features.

Definition at line 40 of file cpuid.h.

◆ CPUID_FEATURES_INTEL_ECX_HYPERVISOR

#define CPUID_FEATURES_INTEL_ECX_HYPERVISOR   0x80000000UL

Hypervisor is present.

Definition at line 43 of file cpuid.h.

◆ CPUID_AMD_MAX_FN

#define CPUID_AMD_MAX_FN   0x80000000UL

Get largest extended function.

Definition at line 46 of file cpuid.h.

◆ CPUID_AMD_CHECK

#define CPUID_AMD_CHECK   0x80000000UL

Extended function existence check.

Definition at line 49 of file cpuid.h.

◆ CPUID_AMD_CHECK_MASK

#define CPUID_AMD_CHECK_MASK   0xffff0000UL

Extended function existence check mask.

Definition at line 52 of file cpuid.h.

◆ CPUID_AMD_FEATURES

#define CPUID_AMD_FEATURES   0x80000001UL

Get extended features.

Definition at line 55 of file cpuid.h.

◆ CPUID_MODEL

#define CPUID_MODEL   0x80000002UL

Get CPU model.

Definition at line 58 of file cpuid.h.

◆ CPUID_APM

#define CPUID_APM   0x80000007UL

Get APM information.

Definition at line 61 of file cpuid.h.

◆ CPUID_APM_EDX_TSC_INVARIANT

#define CPUID_APM_EDX_TSC_INVARIANT   0x00000100UL

Invariant TSC.

Definition at line 64 of file cpuid.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Issue CPUID instruction.

Parameters
functionCPUID function (input via eax)
subfunctionCPUID subfunction (input via ecx)
eaxOutput via eax
ebxOutput via ebx
ecxOutput via ecx
edxOutput via edx

◆ cpuid_supported()

int cpuid_supported ( uint32_t  function)

Check whether or not CPUID function is supported.

Parameters
functionCPUID function
Return values
rcReturn status code

Definition at line 75 of file cpuid.c.

75  {
76  uint32_t max_function;
77  uint32_t discard_b;
79  uint32_t discard_d;
80  int rc;
81 
82  /* Check that CPUID instruction is available */
83  if ( ( rc = cpuid_instruction_supported() ) != 0 )
84  return rc;
85 
86  /* Find highest supported function number within this family */
87  cpuid ( ( function & CPUID_EXTENDED ), 0, &max_function, &discard_b,
88  &discard_c, &discard_d );
89 
90  /* Fail if maximum function number is meaningless (e.g. if we
91  * are attempting to call an extended function on a CPU which
92  * does not support them).
93  */
94  if ( ( max_function & CPUID_AMD_CHECK_MASK ) !=
95  ( function & CPUID_AMD_CHECK_MASK ) ) {
96  DBGC ( colour, "CPUID invalid maximum function %#08x\n",
97  max_function );
98  return -EINVAL;
99  }
100 
101  /* Fail if this function is not supported */
102  if ( function > max_function ) {
103  DBGC ( colour, "CPUID function %#08x not supported\n",
104  function );
105  return -ENOTTY;
106  }
107 
108  return 0;
109 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define colour
Colour for debug messages.
Definition: cpuid.c:37
#define CPUID_AMD_CHECK_MASK
Extended function existence check mask.
Definition: cpuid.h:52
#define DBGC(...)
Definition: compiler.h:505
static int cpuid_instruction_supported(void)
Check whether or not CPUID instruction is supported.
Definition: cpuid.c:44
unsigned int uint32_t
Definition: stdint.h:12
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
#define CPUID_EXTENDED
CPUID extended function.
Definition: cpuid.h:34
long discard_c
Definition: bigint.h:30

References colour, CPUID_AMD_CHECK_MASK, CPUID_EXTENDED, cpuid_instruction_supported(), DBGC, discard_c, EINVAL, ENOTTY, and rc.

Referenced by cpuid_settings_fetch(), rdtsc_probe(), x86_amd_features(), and x86_intel_features().

◆ x86_features()

void x86_features ( struct x86_features features)

Get x86 CPU features.

Parameters
featuresx86 CPU features to fill in

Definition at line 163 of file cpuid.c.

163  {
164 
165  /* Clear all features */
166  memset ( features, 0, sizeof ( *features ) );
167 
168  /* Get Intel-defined features */
170 
171  /* Get AMD-defined features */
173 }
static void x86_amd_features(struct x86_features *features)
Get AMD-defined x86 CPU features.
Definition: cpuid.c:140
static void x86_intel_features(struct x86_features *features)
Get Intel-defined x86 CPU features.
Definition: cpuid.c:116
uint32_t features
Supported features.
Definition: ena.h:16
void * memset(void *dest, int character, size_t len) __nonnull

References features, memset(), x86_amd_features(), and x86_intel_features().

Referenced by cpuid_exec(), and hv_check_hv().

Variable Documentation

◆ __attribute__

◆ subfunction

uint32_t subfunction

Definition at line 77 of file cpuid.h.

Referenced by cpuid_settings_fetch().

◆ eax

Definition at line 77 of file cpuid.h.

◆ ebx

Definition at line 77 of file cpuid.h.

Referenced by hv_map_hypercall(), and hvm_cpuid_base().

◆ ecx

Definition at line 77 of file cpuid.h.

Referenced by hv_map_hypercall(), and hvm_cpuid_base().

◆ edx

Initial value:
{
__asm__ ( "cpuid"
: "=a" ( *eax ), "=b" ( *ebx ), "=c" ( *ecx ), "=d" ( *edx )
: "0" ( function ), "2" ( subfunction ) )
static uint32_t subfunction
Definition: cpuid.h:77
static uint32_t uint32_t uint32_t * ebx
Definition: cpuid.h:77
static uint32_t uint32_t uint32_t uint32_t * ecx
Definition: cpuid.h:77
static uint32_t uint32_t uint32_t uint32_t uint32_t * edx
Definition: cpuid.h:78
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
static uint32_t uint32_t * eax
Definition: cpuid.h:77

Definition at line 78 of file cpuid.h.

Referenced by hv_map_hypercall(), and hvm_cpuid_base().