sev_guest_device_tio/lib.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! The module includes the definitions of data structures according to the SEV-TIO Firmware Interface Specification.
5//! <https://docs.amd.com/v/u/en-US/58271_0.91> AMD Document #58271 2025-07-02
6
7use bitfield_struct::bitfield;
8use zerocopy::FromBytes;
9use zerocopy::Immutable;
10use zerocopy::IntoBytes;
11use zerocopy::KnownLayout;
12
13/// See `TIO_MSG_TDI_INFO_REQ` in Table 60, "SEV-TIO Firmware Interface Specification", Revision 0.91.
14#[repr(C)]
15#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
16pub struct TioMsgTdiInfoReq {
17 /// Hypervisor supplied guest id.
18 pub guest_device_id: u16,
19 /// Reserved
20 pub _reserved0: [u8; 14],
21}
22
23static_assertions::const_assert_eq!(16, size_of::<TioMsgTdiInfoReq>());
24
25/// See `TIO_MSG_TDI_INFO_RSP` in Table 61, "SEV-TIO Firmware Interface Specification", Revision 0.91.
26#[repr(C)]
27#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
28pub struct TioMsgTdiInfoRsp {
29 /// Hypervisor supplied guest id.
30 pub guest_device_id: u16,
31 /// TDI status.
32 pub tdi_status: u16,
33 /// Reserved
34 pub _reserved0: [u8; 12],
35 /// MEAS_DIGEST info
36 pub meas_digest_info: u32,
37 /// Device lock flags
38 pub lock_flags: u32,
39 /// SPDM algorithms
40 pub spdm_algos: u64,
41 /// Certs digest
42 pub certs_digest: [u8; 48],
43 /// MEAS digest
44 pub meas_digest: [u8; 48],
45 /// Interface report digest
46 pub interface_report_digest: [u8; 48],
47 /// Tdi report count
48 pub tdi_report_count: u64,
49 /// Reserved
50 pub _reserved1: u64,
51}
52
53// Assert the size of the response field
54static_assertions::const_assert_eq!(192, size_of::<TioMsgTdiInfoRsp>());
55
56/// See `TIO_MSG_MMIO_VALIDATE_REQ` in Table 63, "SEV-TIO Firmware Interface Specification", Revision 0.91.
57#[bitfield(u16)]
58#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
59pub struct TioMsgMmioValidateReqFlags {
60 /// Desired value to set RMP. Validated for the range.
61 pub validated: bool,
62
63 /// 0: If subrange does not have RMP. Validated
64 /// set uniformly, fail.
65 /// 1: If subrange does not have RMP. Validated
66 /// set uniformly, force to requested value.
67 pub force_validated: bool,
68
69 #[bits(14)]
70 _reserved0: u16,
71}
72
73/// See `TIO_MSG_MMIO_VALIDATE_REQ` in Table 63, "SEV-TIO Firmware Interface Specification", Revision 0.91.
74#[repr(C)]
75#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
76pub struct TioMsgMmioValidateReq {
77 /// Hypervisor provided identifier used by the guest to identify the TDI in guest messages.
78 pub guest_device_id: u16,
79 /// Reserved.
80 pub _reserved0: [u8; 14],
81 /// Guest physical address of the subrange.
82 pub subrange_base: u64,
83 /// Number of 4 KB pages in the subrange.
84 pub subrange_page_count: u32,
85 /// Offset of the subrange within the MMIO range.
86 pub range_offset: u32,
87 /// Validated flags
88 pub validated_flags: TioMsgMmioValidateReqFlags,
89 /// RangeID of MMIO range.
90 pub range_id: u16,
91 /// Reserved.
92 pub _reserved2: [u8; 12],
93}
94
95static_assertions::const_assert_eq!(48, size_of::<TioMsgMmioValidateReq>());
96
97/// See `TIO_MSG_MMIO_VALIDATE_RSP` in Table 64, "SEV-TIO Firmware Interface Specification", Revision 0.91.
98#[bitfield(u16)]
99#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
100pub struct TioMsgMmioValidateResFlags {
101 /// Indicates that the Validated bit has changed due to this operation.
102 pub changed: bool,
103
104 #[bits(15)]
105 _reserved0: u16,
106}
107
108/// See `TIO_MSG_MMIO_VALIDATE_RSP` in Table 64, "SEV-TIO Firmware Interface Specification", Revision 0.91.
109#[repr(C)]
110#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
111pub struct TioMsgMmioValidateRsp {
112 /// Hypervisor provided PCIe Routing ID used by the guest to identify the TDI.
113 pub guest_device_id: u16,
114 /// Status of the operation.
115 pub status: u16,
116 /// Reserved.
117 pub _reserved0: [u8; 12],
118 /// Guest physical address of the subrange.
119 pub subrange_base: u64,
120 /// Number of 4 KB pages in the subrange.
121 pub subrange_page_count: u32,
122 /// Offset of the subrange within the MMIO range.
123 pub range_offset: u32,
124 /// Validated flags
125 pub flag_bits: TioMsgMmioValidateResFlags,
126 /// Range of the MMIO.
127 pub range_id: u16,
128 /// Reserved.
129 pub _reserved2: [u8; 12],
130}
131
132static_assertions::const_assert_eq!(48, size_of::<TioMsgMmioValidateRsp>());
133
134/// See `TIO_MSG_MMIO_CONFIG_REQ` flags in Table 65, "SEV-TIO Firmware Interface Specification", Revision 0.91.
135#[bitfield(u16)]
136#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
137pub struct TioMsgMmioConfigReqFlags {
138 #[bits(2)]
139 _reserved0: u16,
140
141 /// 0: Can be mapped only into guest private memory.
142 /// 1: Can be mapped into either guest private memory or shared memory.
143 /// Ignored if WRITE is 0.
144 pub non_tee_mem: bool,
145
146 #[bits(13)]
147 _reserved1: u16,
148}
149
150/// See `TIO_MSG_MMIO_CONFIG_REQ` in Table 65, "SEV-TIO Firmware Interface Specification", Revision 0.91.
151#[repr(C)]
152#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
153pub struct TioMsgMmioConfigReq {
154 /// Hypervisor provided identifier used by the guest to identify the TDI in guest messages.
155 pub guest_device_id: u16,
156 /// Reserved.
157 pub _reserved0: [u8; 2],
158 /// Flags for the range.
159 pub flags: TioMsgMmioConfigReqFlags,
160 /// Range ID of the MMIO range.
161 pub range_id: u16,
162 /// WRITE flag.
163 pub write: u32,
164 /// Reserved.
165 pub _reserved2: [u8; 4],
166}
167
168static_assertions::const_assert_eq!(16, size_of::<TioMsgMmioConfigReq>());
169
170/// See `TIO_MSG_MMIO_CONFIG_RSP` flags in Table 66, "SEV-TIO Firmware Interface Specification", Revision 0.91.
171#[bitfield(u16)]
172#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
173pub struct TioMsgMmioConfigRspFlags {
174 /// Indicates if the range maps MSI-X table.
175 pub msix_table: bool,
176 /// Indicates if this range maps MSI-X PBA.
177 pub msix_pba: bool,
178 /// Indicates if the range can be mapped into either guest private memory or shared memory.
179 pub non_tee_mem: bool,
180 /// Indicates if certain TDISP flags can be updated.
181 pub mem_attr_updateable: bool,
182 #[bits(12)]
183 _reserved0: u16,
184}
185
186/// See `TIO_MSG_MMIO_CONFIG_RSP` in Table 66, "SEV-TIO Firmware Interface Specification", Revision 0.91.
187#[repr(C)]
188#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
189pub struct TioMsgMmioConfigRsp {
190 /// Hypervisor provided identifier used by the guest to identify the TDI in guest messages.
191 pub guest_device_id: u16,
192 /// Status of the operation.
193 pub status: u16,
194 /// Flags for the range.
195 pub flags: TioMsgMmioConfigRspFlags,
196 /// Range ID of the MMIO range.
197 pub range_id: u16,
198 /// WRITE flag.
199 pub write: u32,
200 /// Reserved.
201 pub _reserved1: [u8; 4],
202}
203
204static_assertions::const_assert_eq!(16, size_of::<TioMsgMmioConfigRsp>());
205
206/// See `Layout of the SDTE Structure` in Table 68, "SEV-TIO Firmware Interface Specification", Revision 0.91.
207#[bitfield(u64)]
208#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
209pub struct SdtePart1 {
210 // [0]
211 pub v: bool,
212
213 #[bits(60)]
214 _reserved0: u64,
215
216 pub ir: bool,
217
218 pub iw: bool,
219
220 _reserved1: bool,
221}
222
223/// See `Layout of the SDTE Structure` in Table 68, "SEV-TIO Firmware Interface Specification", Revision 0.91.
224#[bitfield(u64)]
225#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
226pub struct SdtePart2 {
227 #[bits(49)]
228 _reserved0: u64,
229
230 #[bits(2)]
231 pub vmpl: u64,
232
233 #[bits(13)]
234 _reserved1: u64,
235}
236
237/// See `Layout of the SDTE Structure` in Table 68, "SEV-TIO Firmware Interface Specification", Revision 0.91.
238#[bitfield(u64)]
239#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
240pub struct SdtePart3 {
241 pub vtom_en: bool,
242
243 #[bits(31)]
244 pub virtual_tom: u32,
245
246 #[bits(32)]
247 _reserved1: u64,
248}
249
250/// See `Layout of the SDTE Structure` in Table 68, "SEV-TIO Firmware Interface Specification", Revision 0.91.
251#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
252#[repr(C)]
253pub struct Sdte {
254 /// Part 1 of the guest writable portion of the SDTE structure. These are split out to preserve specific alignment requirements from the spec.
255 pub part1: SdtePart1,
256 /// Reserved. Set to 0.
257 pub _reserved0: u64,
258 /// Reserved. Set to 0.
259 pub _reserved1: u64,
260 /// Part 2 of the guest writable portion of the SDTE structure. These are split out to preserve specific alignment requirements from the spec.
261 pub part2: SdtePart2,
262 /// Reserved. Set to 0.
263 pub _reserved2: u64,
264
265 /// Part 3 of the guest writable portion of the SDTE structure. These are split out to preserve specific alignment requirements from the spec.
266 pub part3: SdtePart3,
267 /// Reserved. Set to 0.
268 pub _reserved3: u64,
269 /// Reserved. Set to 0.
270 pub _reserved4: u64,
271}
272
273static_assertions::const_assert_eq!(size_of::<Sdte>(), 64);
274
275/// See `TIO_MSG_SDTE_WRITE_REQ` in Table 67, "SEV-TIO Firmware Interface Specification", Revision 0.91.
276#[repr(C)]
277#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
278pub struct TioMsgSdteWriteReq {
279 /// Hypervisor provided identifier used by the guest to identify the TDI in guest messages.
280 pub guest_device_id: u16,
281
282 /// Reserved. Set to 0.
283 pub _reserved0: [u8; 14],
284
285 /// sDTE to use to configure the guest controlled fields.
286 pub sdte: Sdte,
287}
288
289static_assertions::const_assert_eq!(size_of::<TioMsgSdteWriteReq>(), 80);
290
291/// See `TIO_MSG_SDTE_WRITE_RSP` in Table 69, "SEV-TIO Firmware Interface Specification", Revision 0.91.
292#[repr(C)]
293#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
294pub struct TioMsgSdteWriteRsp {
295 /// Hypervisor provided PCIe Routing ID used by the guest to identify the TDI.
296 pub guest_device_id: u16,
297 /// Status of the operation.
298 pub status: u16,
299 /// Reserved.
300 pub _reserved0: [u8; 12],
301}
302
303static_assertions::const_assert_eq!(size_of::<TioMsgSdteWriteRsp>(), 16);