Skip to main content

loader/
cpuid.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Provides common CPUID values and functions.
5
6use x86defs::cpuid::CpuidFunction;
7use zerocopy::FromBytes;
8use zerocopy::Immutable;
9use zerocopy::IntoBytes;
10use zerocopy::KnownLayout;
11
12/// CPUID information used to build the CPUID page for SNP.
13#[repr(C)]
14#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
15pub struct SNP_REQUIRED_CPUID_LEAF {
16    pub eax: u32,
17    pub ecx: u32,
18}
19
20macro_rules! cpuid_leaf {
21    ($eax: expr, $ecx: expr) => {
22        SNP_REQUIRED_CPUID_LEAF {
23            eax: $eax.0,
24            ecx: $ecx,
25        }
26    };
27}
28
29/// The list of static CPUID leaves stored in the CPUID page for SNP without a paravisor.
30/// The extended SEV leaf must be first in the list of required CPUID leaves.
31pub const SNP_REQUIRED_CPUID_LEAF_LIST_UEFI: [SNP_REQUIRED_CPUID_LEAF; 20] = [
32    cpuid_leaf!(CpuidFunction::ExtendedSevFeatures, 0),
33    cpuid_leaf!(CpuidFunction::VersionAndFeatures, 0),
34    cpuid_leaf!(CpuidFunction::CacheAndTlbInformation, 0),
35    cpuid_leaf!(CpuidFunction::MonitorMwait, 0),
36    cpuid_leaf!(CpuidFunction::PowerManagement, 0),
37    cpuid_leaf!(CpuidFunction::DirectCacheAccessParameters, 0),
38    cpuid_leaf!(CpuidFunction::PerformanceMonitoring, 0),
39    cpuid_leaf!(CpuidFunction::ExtendedFeatures, 0),
40    cpuid_leaf!(CpuidFunction::CacheParameters, 0),
41    cpuid_leaf!(CpuidFunction::CacheParameters, 1),
42    cpuid_leaf!(CpuidFunction::CacheParameters, 2),
43    cpuid_leaf!(CpuidFunction::ExtendedTopologyEnumeration, 0),
44    cpuid_leaf!(CpuidFunction::ExtendedTopologyEnumeration, 1),
45    cpuid_leaf!(CpuidFunction::ExtendedVersionAndFeatures, 0),
46    cpuid_leaf!(CpuidFunction::ExtendedL1CacheParameters, 0),
47    cpuid_leaf!(CpuidFunction::ExtendedL2CacheParameters, 0),
48    cpuid_leaf!(CpuidFunction::ExtendedPowerManagement, 0),
49    cpuid_leaf!(CpuidFunction::ExtendedAddressSpaceSizes, 0),
50    cpuid_leaf!(CpuidFunction::ExtendedSvmVersionAndFeatures, 0),
51    cpuid_leaf!(CpuidFunction::ProcessorTopologyDefinition, 0),
52];
53
54/// The list of static CPUID leaves stored in the CPUID page for SNP with an underhill based
55/// paravisor. The extended SEV leaf must be first in the list of required CPUID leaves.
56pub const SNP_REQUIRED_CPUID_LEAF_LIST_PARAVISOR: [SNP_REQUIRED_CPUID_LEAF; 35] = [
57    cpuid_leaf!(CpuidFunction::ExtendedSevFeatures, 0),
58    cpuid_leaf!(CpuidFunction::VendorAndMaxFunction, 0),
59    cpuid_leaf!(CpuidFunction::VersionAndFeatures, 0),
60    cpuid_leaf!(CpuidFunction::ExtendedMaxFunction, 0),
61    cpuid_leaf!(CpuidFunction::MonitorMwait, 0),
62    cpuid_leaf!(CpuidFunction::DirectCacheAccessParameters, 0),
63    cpuid_leaf!(CpuidFunction::PerformanceMonitoring, 0),
64    cpuid_leaf!(CpuidFunction::ExtendedFeatures, 0),
65    cpuid_leaf!(CpuidFunction::ExtendedTopologyEnumeration, 0),
66    cpuid_leaf!(CpuidFunction::ExtendedTopologyEnumeration, 1),
67    cpuid_leaf!(CpuidFunction::ExtendedVersionAndFeatures, 0),
68    cpuid_leaf!(CpuidFunction::ExtendedL1CacheParameters, 0),
69    cpuid_leaf!(CpuidFunction::ExtendedL2CacheParameters, 0),
70    cpuid_leaf!(CpuidFunction::ExtendedPowerManagement, 0),
71    cpuid_leaf!(CpuidFunction::ExtendedAddressSpaceSizes, 0),
72    cpuid_leaf!(CpuidFunction::ExtendedSvmVersionAndFeatures, 0),
73    cpuid_leaf!(CpuidFunction::ProcessorTopologyDefinition, 0),
74    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 0),
75    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 1),
76    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 2),
77    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 3),
78    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 4),
79    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 5),
80    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 6),
81    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 7),
82    cpuid_leaf!(CpuidFunction::ExtendedStateEnumeration, 8),
83    cpuid_leaf!(CpuidFunction::ExtendedBrandingString1, 0),
84    cpuid_leaf!(CpuidFunction::ExtendedBrandingString2, 0),
85    cpuid_leaf!(CpuidFunction::ExtendedBrandingString3, 0),
86    cpuid_leaf!(CpuidFunction::ExtendedTlb1GBIdentifiers, 0),
87    cpuid_leaf!(CpuidFunction::ExtendedOptimizationIdentifiers, 0),
88    cpuid_leaf!(CpuidFunction::CacheTopologyDefinition, 0),
89    cpuid_leaf!(CpuidFunction::CacheTopologyDefinition, 1),
90    cpuid_leaf!(CpuidFunction::CacheTopologyDefinition, 2),
91    cpuid_leaf!(CpuidFunction::CacheTopologyDefinition, 3),
92];
93
94#[repr(C)]
95#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Clone, Copy)]
96pub struct HV_PSP_CPUID_LEAF {
97    pub eax_in: u32,
98    pub ecx_in: u32,
99    pub xfem_in: u64,
100    pub xss_in: u64,
101    pub eax_out: u32,
102    pub ebx_out: u32,
103    pub ecx_out: u32,
104    pub edx_out: u32,
105    pub reserved_z: u64,
106}
107
108pub const HV_PSP_CPUID_LEAF_COUNT_MAX: usize = 64;
109
110#[repr(C)]
111#[derive(Debug, IntoBytes, Immutable, KnownLayout, FromBytes)]
112pub struct HV_PSP_CPUID_PAGE {
113    pub count: u32,
114    pub reserved_z1: u32,
115    pub reserved_z2: u64,
116    pub cpuid_leaf_info: [HV_PSP_CPUID_LEAF; HV_PSP_CPUID_LEAF_COUNT_MAX],
117}