Xen Test Framework
main.c
Go to the documentation of this file.
1 
12 #include <xtf.h>
13 
14 const char test_title[] = "Guest cpuid information";
15 
16 static void dump_leaves(cpuid_count_fn_t cpuid_fn)
17 {
18  uint32_t leaf = 0, subleaf = ~0U;
19 
20  uint64_t valid_xstate_leaves = 0;
21  uint32_t max_leaf = 0, max_l7_subleaf = 0,
22  max_hv_leaf = 0, max_hv2_leaf = 0, max_extd_leaf = 0;
23  uint32_t xen_first_leaf = ~0, xen_last_leaf = 0;
24 
25  for ( ;; )
26  {
27  uint32_t eax, ebx, ecx, edx;
28 
29  cpuid_fn(leaf, subleaf, &eax, &ebx, &ecx, &edx);
30 
31  printk(" %08x:%08x -> %08x:%08x:%08x:%08x\n",
32  leaf, subleaf, eax, ebx, ecx, edx);
33 
34  switch ( leaf )
35  {
36  case 0:
37  max_leaf = eax;
38  break;
39 
40  case 0x4:
41  subleaf++;
42  if ( (eax & 0x1f) != 0 )
43  continue;
44  break;
45 
46  case 0x7:
47  if ( subleaf == 0 )
48  max_l7_subleaf = eax;
49  subleaf++;
50  if ( subleaf <= max_l7_subleaf )
51  continue;
52  break;
53 
54  case 0xd:
55  if ( subleaf == 0 )
56  valid_xstate_leaves = ((uint64_t)edx) << 32 | eax;
57  do
58  {
59  subleaf++;
60  } while ( (subleaf < 63) &&
61  !(valid_xstate_leaves & (1ULL << subleaf)) );
62  if ( subleaf < 63 )
63  continue;
64  break;
65 
66  case 0x40000000U:
67  max_hv_leaf = eax;
68 
69  if ( ebx == XEN_CPUID_SIGNATURE_EBX &&
70  ecx == XEN_CPUID_SIGNATURE_ECX &&
72  {
73  xen_first_leaf = leaf;
74  xen_last_leaf = eax;
75  }
76 
77  break;
78 
79  case 0x40000100U:
80  max_hv2_leaf = eax;
81 
82  if ( ebx == XEN_CPUID_SIGNATURE_EBX &&
83  ecx == XEN_CPUID_SIGNATURE_ECX &&
85  {
86  xen_first_leaf = leaf;
87  xen_last_leaf = eax;
88  }
89 
90  break;
91 
92  case 0x80000000U:
93  max_extd_leaf = eax;
94  break;
95  }
96 
97  if ( leaf >= xen_first_leaf && leaf <= xen_last_leaf )
98  {
99  /* The Xen leaves have no documented identification of max leaf. */
100 
101  switch ( leaf - xen_first_leaf )
102  {
103  case 3:
104  if ( subleaf < 2 ) /* Max leaf hardcoded. */
105  {
106  subleaf++;
107  continue;
108  }
109  break;
110 
111  case 4: /* Leaf semantics, but ??? */
112  break;
113  }
114  }
115 
116  leaf++;
117  if ( (leaf > 0) && (leaf < 0x40000000U) && (leaf > max_leaf) )
118  leaf = 0x40000000U;
119 
120  if ( (leaf > 0x40000000U) && (leaf < 0x40000100U) && (leaf > max_hv_leaf) )
121  leaf = 0x40000100U;
122 
123  if ( (leaf > 0x40000100U) && (leaf < 0x80000000U) && (leaf > max_hv2_leaf) )
124  leaf = 0x80000000U;
125 
126  if ( (leaf > 0x80000000U) && (leaf > max_extd_leaf) )
127  break;
128 
129  subleaf = ~0;
130  if ( leaf == 4 || leaf == 7 || leaf == 0xd ||
131  ((leaf >= xen_first_leaf && leaf <= xen_last_leaf) &&
132  ((leaf - xen_first_leaf) == 3 || (leaf - xen_first_leaf) == 4)) )
133  subleaf = 0;
134  }
135 }
136 
137 void test_main(void)
138 {
139  printk("Native cpuid:\n");
141 
142  if ( IS_DEFINED(CONFIG_PV) )
143  {
144  printk("Emulated cpuid:\n");
146  }
147 
148  xtf_success(NULL);
149 }
150 
151 /*
152  * Local variables:
153  * mode: C
154  * c-file-style: "BSD"
155  * c-basic-offset: 4
156  * tab-width: 4
157  * indent-tabs-mode: nil
158  * End:
159  */
#define XEN_CPUID_SIGNATURE_EBX
Definition: cpuid.h:26
unsigned int max_leaf
Definition: setup.c:26
#define IS_DEFINED(x)
Evalute whether the CONFIG_ token x is defined.
Definition: macro_magic.h:67
static void cpuid_count(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Definition: lib.h:64
static void pv_cpuid_count(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Definition: lib.h:73
void printk(const char *fmt,...)
Definition: console.c:134
#define NULL
Definition: stddef.h:12
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:137
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
#define XEN_CPUID_SIGNATURE_ECX
Definition: cpuid.h:27
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
const char test_title[]
The title of the test.
Definition: main.c:14
#define XEN_CPUID_SIGNATURE_EDX
Definition: cpuid.h:28
static void dump_leaves(cpuid_count_fn_t cpuid_fn)
Definition: main.c:16
void(* cpuid_count_fn_t)(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Definition: cpuid.h:12
unsigned int max_extd_leaf
Definition: setup.c:26