]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Include/Register/StmApi.h
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / Include / Register / StmApi.h
CommitLineData
f7c11c53
MK
1/** @file\r
2 STM API definition\r
3\r
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
f7c11c53
MK
6\r
7 @par Specification Reference:\r
8 SMI Transfer Monitor (STM) User Guide Revision 1.00\r
9\r
10**/\r
11\r
12#ifndef _STM_API_H_\r
13#define _STM_API_H_\r
14\r
15#include <Register/StmStatusCode.h>\r
16#include <Register/StmResourceDescriptor.h>\r
17#include <Register/ArchitecturalMsr.h>\r
18\r
19#pragma pack (1)\r
20\r
21/**\r
22 STM Header Structures\r
23**/\r
24\r
25typedef struct {\r
26 UINT32 Intel64ModeSupported :1; ///> bitfield\r
27 UINT32 EptSupported :1; ///> bitfield\r
28 UINT32 Reserved :30; ///> must be 0\r
29} STM_FEAT;\r
30\r
31#define STM_SPEC_VERSION_MAJOR 1\r
32#define STM_SPEC_VERSION_MINOR 0\r
33\r
34typedef struct {\r
35 UINT8 StmSpecVerMajor;\r
36 UINT8 StmSpecVerMinor;\r
37 ///\r
38 /// Must be zero\r
39 ///\r
40 UINT16 Reserved;\r
41 UINT32 StaticImageSize;\r
42 UINT32 PerProcDynamicMemorySize;\r
43 UINT32 AdditionalDynamicMemorySize;\r
44 STM_FEAT StmFeatures;\r
45 UINT32 NumberOfRevIDs;\r
46 UINT32 StmSmmRevID[1];\r
47 ///\r
48 /// The total STM_HEADER should be 4K.\r
49 ///\r
50} SOFTWARE_STM_HEADER;\r
51\r
52typedef struct {\r
53 MSEG_HEADER HwStmHdr;\r
54 SOFTWARE_STM_HEADER SwStmHdr;\r
55} STM_HEADER;\r
56\r
57\r
58/**\r
59 VMCALL API Numbers\r
60 API number convention: BIOS facing VMCALL interfaces have bit 16 clear\r
61**/\r
62\r
63/**\r
64 StmMapAddressRange enables a SMM guest to create a non-1:1 virtual to\r
65 physical mapping of an address range into the SMM guest's virtual\r
66 memory space.\r
67\r
68 @param EAX #STM_API_MAP_ADDRESS_RANGE (0x00000001)\r
69 @param EBX Low 32 bits of physical address of caller allocated\r
70 STM_MAP_ADDRESS_RANGE_DESCRIPTOR structure.\r
71 @param ECX High 32 bits of physical address of caller allocated\r
72 STM_MAP_ADDRESS_RANGE_DESCRIPTOR structure. If Intel64Mode is\r
73 clear (0), ECX must be 0.\r
74\r
75 @note All fields of STM_MAP_ADDRESS_RANGE_DESCRIPTOR are inputs only. They\r
76 are not modified by StmMapAddressRange.\r
77\r
78 @retval CF 0\r
79 No error, EAX set to STM_SUCCESS.\r
80 The memory range was mapped as requested.\r
81 @retval CF 1\r
82 An error occurred, EAX holds relevant error value.\r
83 @retval EAX #ERROR_STM_SECURITY_VIOLATION\r
84 The requested mapping contains a protected resource.\r
85 @retval EAX #ERROR_STM_CACHE_TYPE_NOT_SUPPORTED\r
86 The requested cache type could not be satisfied.\r
87 @retval EAX #ERROR_STM_PAGE_NOT_FOUND\r
88 Page count must not be zero.\r
89 @retval EAX #ERROR_STM_FUNCTION_NOT_SUPPORTED\r
90 STM supports EPT and has not implemented StmMapAddressRange().\r
91 @retval EAX #ERROR_STM_UNSPECIFIED\r
92 An unspecified error occurred.\r
93\r
94 @note All other registers unmodified.\r
95**/\r
96#define STM_API_MAP_ADDRESS_RANGE 0x00000001\r
97\r
98/**\r
99 STM Map Address Range Descriptor for #STM_API_MAP_ADDRESS_RANGE VMCALL\r
100**/\r
101typedef struct {\r
102 UINT64 PhysicalAddress;\r
103 UINT64 VirtualAddress;\r
104 UINT32 PageCount;\r
105 UINT32 PatCacheType;\r
106} STM_MAP_ADDRESS_RANGE_DESCRIPTOR;\r
107\r
108/**\r
109 Define values for PatCacheType field of #STM_MAP_ADDRESS_RANGE_DESCRIPTOR\r
110 @{\r
111**/\r
112#define STM_MAP_ADDRESS_RANGE_PAT_CACHE_TYPE_ST_UC 0x00\r
113#define STM_MAP_ADDRESS_RANGE_PAT_CACHE_TYPE_WC 0x01\r
114#define STM_MAP_ADDRESS_RANGE_PAT_CACHE_TYPE_WT 0x04\r
115#define STM_MAP_ADDRESS_RANGE_PAT_CACHE_TYPE_WP 0x05\r
116#define STM_MAP_ADDRESS_RANGE_PAT_CACHE_TYPE_WB 0x06\r
117#define STM_MAP_ADDRESS_RANGE_PAT_CACHE_TYPE_UC 0x07\r
118#define STM_MAP_ADDRESS_RANGE_PAT_CACHE_TYPE_FOLLOW_MTRR 0xFFFFFFFF\r
119/// @}\r
120\r
121/**\r
122 StmUnmapAddressRange enables a SMM guest to remove mappings from its page\r
123 table.\r
124\r
125 If TXT_PROCESSOR_SMM_DESCRIPTOR.EptEnabled bit is set by the STM, BIOS can\r
126 control its own page tables. In this case, the STM implementation may\r
127 optionally return ERROR_STM_FUNCTION_NOT_SUPPORTED.\r
128\r
129 @param EAX #STM_API_UNMAP_ADDRESS_RANGE (0x00000002)\r
130 @param EBX Low 32 bits of virtual address of caller allocated\r
131 STM_UNMAP_ADDRESS_RANGE_DESCRIPTOR structure.\r
132 @param ECX High 32 bits of virtual address of caller allocated\r
133 STM_UNMAP_ADDRESS_RANGE_DESCRIPTOR structure. If Intel64Mode is\r
134 clear (0), ECX must be zero.\r
135\r
136 @retval CF 0\r
137 No error, EAX set to STM_SUCCESS. The memory range was unmapped\r
138 as requested.\r
139 @retval CF 1\r
140 An error occurred, EAX holds relevant error value.\r
141 @retval EAX #ERROR_STM_FUNCTION_NOT_SUPPORTED\r
142 STM supports EPT and has not implemented StmUnmapAddressRange().\r
143 @retval EAX #ERROR_STM_UNSPECIFIED\r
144 An unspecified error occurred.\r
145\r
146 @note All other registers unmodified.\r
147**/\r
148#define STM_API_UNMAP_ADDRESS_RANGE 0x00000002\r
149\r
150/**\r
151 STM Unmap Address Range Descriptor for #STM_API_UNMAP_ADDRESS_RANGE VMCALL\r
152**/\r
153typedef struct {\r
154 UINT64 VirtualAddress;\r
155 UINT32 Length;\r
156} STM_UNMAP_ADDRESS_RANGE_DESCRIPTOR;\r
157\r
158\r
159/**\r
160 Since the normal OS environment runs with a different set of page tables than\r
161 the SMM guest, virtual mappings will certainly be different. In order to do a\r
162 guest virtual to host physical translation of an address from the normal OS\r
163 code (EIP for example), it is necessary to walk the page tables governing the\r
164 OS page mappings. Since the SMM guest has no direct access to the page tables,\r
165 it must ask the STM to do this page table walk. This is supported via the\r
166 StmAddressLookup VMCALL. All OS page table formats need to be supported,\r
167 (e.g. PAE, PSE, Intel64, EPT, etc.)\r
168\r
169 StmAddressLookup takes a CR3 value and a virtual address from the interrupted\r
170 code as input and returns the corresponding physical address. It also\r
171 optionally maps the physical address into the SMM guest's virtual address\r
172 space. This new mapping persists ONLY for the duration of the SMI and if\r
173 needed in subsequent SMIs it must be remapped. PAT cache types follow the\r
174 interrupted environment's page table.\r
175\r
176 If EPT is enabled, OS CR3 only provides guest physical address information,\r
177 but the SMM guest might also need to know the host physical address. Since\r
178 SMM does not have direct access rights to EPT (it is protected by the STM),\r
179 SMM can input InterruptedEptp to let STM help to walk through it, and output\r
180 the host physical address.\r
181\r
182 @param EAX #STM_API_ADDRESS_LOOKUP (0x00000003)\r
183 @param EBX Low 32 bits of virtual address of caller allocated\r
184 STM_ADDRESS_LOOKUP_DESCRIPTOR structure.\r
185 @param ECX High 32 bits of virtual address of caller allocated\r
186 STM_ADDRESS_LOOKUP_DESCRIPTOR structure. If Intel64Mode is\r
187 clear (0), ECX must be zero.\r
188\r
189 @retval CF 0\r
190 No error, EAX set to STM_SUCCESS. PhysicalAddress contains the\r
191 host physical address determined by walking the interrupted SMM\r
192 guest's page tables. SmmGuestVirtualAddress contains the SMM\r
193 guest's virtual mapping of the requested address.\r
194 @retval CF 1\r
195 An error occurred, EAX holds relevant error value.\r
196 @retval EAX #ERROR_STM_SECURITY_VIOLATION\r
197 The requested page was a protected page.\r
198 @retval EAX #ERROR_STM_PAGE_NOT_FOUND\r
199 The requested virtual address did not exist in the page given\r
200 page table.\r
201 @retval EAX #ERROR_STM_BAD_CR3\r
202 The CR3 input was invalid. CR3 values must be from one of the\r
203 interrupted guest, or from the interrupted guest of another\r
204 processor.\r
205 @retval EAX #ERROR_STM_PHYSICAL_OVER_4G\r
206 The resulting physical address is greater than 4G and no virtual\r
207 address was supplied. The STM could not determine what address\r
208 within the SMM guest's virtual address space to do the mapping.\r
209 STM_ADDRESS_LOOKUP_DESCRIPTOR field PhysicalAddress contains the\r
210 physical address determined by walking the interrupted\r
211 environment's page tables.\r
212 @retval EAX #ERROR_STM_VIRTUAL_SPACE_TOO_SMALL\r
213 A specific virtual mapping was requested, but\r
214 SmmGuestVirtualAddress + Length exceeds 4G and the SMI handler\r
215 is running in 32 bit mode.\r
216 @retval EAX #ERROR_STM_UNSPECIFIED\r
217 An unspecified error occurred.\r
218\r
219 @note All other registers unmodified.\r
220**/\r
221#define STM_API_ADDRESS_LOOKUP 0x00000003\r
222\r
223/**\r
224 STM Lookup Address Range Descriptor for #STM_API_ADDRESS_LOOKUP VMCALL\r
225**/\r
226typedef struct {\r
227 UINT64 InterruptedGuestVirtualAddress;\r
228 UINT32 Length;\r
229 UINT64 InterruptedCr3;\r
230 UINT64 InterruptedEptp;\r
231 UINT32 MapToSmmGuest:2;\r
232 UINT32 InterruptedCr4Pae:1;\r
233 UINT32 InterruptedCr4Pse:1;\r
234 UINT32 InterruptedIa32eMode:1;\r
235 UINT32 Reserved1:27;\r
236 UINT32 Reserved2;\r
237 UINT64 PhysicalAddress;\r
238 UINT64 SmmGuestVirtualAddress;\r
239} STM_ADDRESS_LOOKUP_DESCRIPTOR;\r
240\r
241/**\r
242 Define values for the MapToSmmGuest field of #STM_ADDRESS_LOOKUP_DESCRIPTOR\r
243 @{\r
244**/\r
245#define STM_ADDRESS_LOOKUP_DESCRIPTOR_DO_NOT_MAP 0\r
246#define STM_ADDRESS_LOOKUP_DESCRIPTOR_ONE_TO_ONE 1\r
247#define STM_ADDRESS_LOOKUP_DESCRIPTOR_VIRTUAL_ADDRESS_SPECIFIED 3\r
248/// @}\r
249\r
250\r
251/**\r
252 When returning from a protection exception (see section 6.2), the SMM guest\r
253 can instruct the STM to take one of two paths. It can either request a value\r
254 be logged to the TXT.ERRORCODE register and subsequently reset the machine\r
255 (indicating it couldn't resolve the problem), or it can request that the STM\r
256 resume the SMM guest again with the specified register state.\r
257\r
258 Unlike other VMCALL interfaces, StmReturnFromProtectionException behaves more\r
259 like a jump or an IRET instruction than a "call". It does not return directly\r
260 to the caller, but indirectly to a different location specified on the\r
261 caller's stack (see section 6.2) or not at all.\r
262\r
263 If the SMM guest STM protection exception handler itself causes a protection\r
264 exception (e.g. a single nested exception), or more than 100 un-nested\r
265 exceptions occur within the scope of a single SMI event, the STM must write\r
266 STM_CRASH_PROTECTION_EXCEPTION_FAILURE to the TXT.ERRORCODE register and\r
267 assert TXT.CMD.SYS_RESET. The reason for these restrictions is to simplify\r
268 the code requirements while still enabling a reasonable debugging capability.\r
269\r
270 @param EAX #STM_API_RETURN_FROM_PROTECTION_EXCEPTION (0x00000004)\r
271 @param EBX If 0, resume SMM guest using register state found on exception\r
272 stack. If in range 0x01..0x0F, EBX contains a BIOS error code\r
273 which the STM must record in the TXT.ERRORCODE register and\r
274 subsequently reset the system via TXT.CMD.SYS_RESET. The value\r
275 of the TXT.ERRORCODE register is calculated as follows:\r
276\r
277 TXT.ERRORCODE = (EBX & 0x0F) | STM_CRASH_BIOS_PANIC\r
278\r
279 Values 0x10..0xFFFFFFFF are reserved, do not use.\r
280\r
281**/\r
282#define STM_API_RETURN_FROM_PROTECTION_EXCEPTION 0x00000004\r
283\r
284\r
285/**\r
286 VMCALL API Numbers\r
287 API number convention: MLE facing VMCALL interfaces have bit 16 set.\r
288\r
289 The STM configuration lifecycle is as follows:\r
290 1. SENTER->SINIT->MLE: MLE begins execution with SMI disabled (masked).\r
291 2. MLE invokes #STM_API_INITIALIZE_PROTECTION VMCALL to prepare STM for\r
292 setup of initial protection profile. This is done on a single CPU and\r
293 has global effect.\r
294 3. MLE invokes #STM_API_PROTECT_RESOURCE VMCALL to define the initial\r
295 protection profile. The protection profile is global across all CPUs.\r
296 4. MLE invokes #STM_API_START VMCALL to enable the STM to begin receiving\r
297 SMI events. This must be done on every logical CPU.\r
298 5. MLE may invoke #STM_API_PROTECT_RESOURCE VMCALL or\r
299 #STM_API_UNPROTECT_RESOURCE VMCALL during runtime as many times as\r
300 necessary.\r
301 6. MLE invokes #STM_API_STOP VMCALL to disable the STM. SMI is again masked\r
302 following #STM_API_STOP VMCALL.\r
303**/\r
304\r
305/**\r
306 StartStmVmcall() is used to configure an STM that is present in MSEG. SMIs\r
307 should remain disabled from the invocation of GETSEC[SENTER] until they are\r
308 re-enabled by StartStmVMCALL(). When StartStmVMCALL() returns, SMI is\r
309 enabled and the STM has been started and is active. Prior to invoking\r
310 StartStmVMCALL(), the MLE root should first invoke\r
311 InitializeProtectionVMCALL() followed by as many iterations of\r
312 ProtectResourceVMCALL() as necessary to establish the initial protection\r
313 profile. StartStmVmcall() must be invoked on all processor threads.\r
314\r
315 @param EAX #STM_API_START (0x00010001)\r
316 @param EDX STM configuration options. These provide the MLE with the\r
317 ability to pass configuration parameters to the STM.\r
318\r
319 @retval CF 0\r
320 No error, EAX set to STM_SUCCESS. The STM has been configured\r
321 and is now active and the guarding all requested resources.\r
322 @retval CF 1\r
323 An error occurred, EAX holds relevant error value.\r
324 @retval EAX #ERROR_STM_ALREADY_STARTED\r
325 The STM is already configured and active. STM remains active and\r
326 guarding previously enabled resource list.\r
327 @retval EAX #ERROR_STM_WITHOUT_SMX_UNSUPPORTED\r
328 The StartStmVMCALL() was invoked from VMX root mode, but outside\r
329 of SMX. This error code indicates the STM or platform does not\r
330 support the STM outside of SMX. The SMI handler remains active\r
331 and operates in legacy mode. See Appendix C\r
332 @retval EAX #ERROR_STM_UNSUPPORTED_MSR_BIT\r
333 The CPU doesn't support the MSR bit. The STM is not active.\r
334 @retval EAX #ERROR_STM_UNSPECIFIED\r
335 An unspecified error occurred.\r
336\r
337 @note All other registers unmodified.\r
338**/\r
339#define STM_API_START (BIT16 | 1)\r
340\r
341/**\r
342 Bit values for EDX input parameter to #STM_API_START VMCALL\r
343 @{\r
344**/\r
345#define STM_CONFIG_SMI_UNBLOCKING_BY_VMX_OFF BIT0\r
346/// @}\r
347\r
348\r
349/**\r
350 The StopStmVMCALL() is invoked by the MLE to teardown an active STM. This is\r
351 normally done as part of a full teardown of the SMX environment when the\r
352 system is being shut down. At the time the call is invoked, SMI is enabled\r
353 and the STM is active. When the call returns, the STM has been stopped and\r
354 all STM context is discarded and SMI is disabled.\r
355\r
356 @param EAX #STM_API_STOP (0x00010002)\r
357\r
358 @retval CF 0\r
359 No error, EAX set to STM_SUCCESS. The STM has been stopped and\r
360 is no longer processing SMI events. SMI is blocked.\r
361 @retval CF 1\r
362 An error occurred, EAX holds relevant error value.\r
363 @retval EAX #ERROR_STM_STOPPED\r
364 The STM was not active.\r
365 @retval EAX #ERROR_STM_UNSPECIFIED\r
366 An unspecified error occurred.\r
367\r
368 @note All other registers unmodified.\r
369**/\r
370#define STM_API_STOP (BIT16 | 2)\r
371\r
372\r
373/**\r
374 The ProtectResourceVMCALL() is invoked by the MLE root to request protection\r
375 of specific resources. The request is defined by a STM_RESOURCE_LIST, which\r
376 may contain more than one resource descriptor. Each resource descriptor is\r
377 processed separately by the STM. Whether or not protection for any specific\r
378 resource is granted is returned by the STM via the ReturnStatus bit in the\r
379 associated STM_RSC_DESC_HEADER.\r
380\r
381 @param EAX #STM_API_PROTECT_RESOURCE (0x00010003)\r
382 @param EBX Low 32 bits of physical address of caller allocated\r
383 STM_RESOURCE_LIST. Bits 11:0 are ignored and assumed to be zero,\r
384 making the buffer 4K aligned.\r
385 @param ECX High 32 bits of physical address of caller allocated\r
386 STM_RESOURCE_LIST.\r
387\r
388 @note All fields of STM_RESOURCE_LIST are inputs only, except for the\r
389 ReturnStatus bit. On input, the ReturnStatus bit must be clear. On\r
390 return, the ReturnStatus bit is set for each resource request granted,\r
391 and clear for each resource request denied. There are no other fields\r
392 modified by ProtectResourceVMCALL(). The STM_RESOURCE_LIST must be\r
393 contained entirely within a single 4K page.\r
394\r
395 @retval CF 0\r
396 No error, EAX set to STM_SUCCESS. The STM has successfully\r
397 merged the entire protection request into the active protection\r
398 profile. There is therefore no need to check the ReturnStatus\r
399 bits in the STM_RESOURCE_LIST.\r
400 @retval CF 1\r
401 An error occurred, EAX holds relevant error value.\r
402 @retval EAX #ERROR_STM_UNPROTECTABLE_RESOURCE\r
403 At least one of the requested resource protections intersects a\r
404 BIOS required resource. Therefore, the caller must walk through\r
405 the STM_RESOURCE_LIST to determine which of the requested\r
406 resources was not granted protection. The entire list must be\r
407 traversed since there may be multiple failures.\r
408 @retval EAX #ERROR_STM_MALFORMED_RESOURCE_LIST\r
409 The resource list could not be parsed correctly, or did not\r
410 terminate before crossing a 4K page boundary. The caller must\r
411 walk through the STM_RESOURCE_LIST to determine which of the\r
412 requested resources was not granted protection. The entire list\r
413 must be traversed since there may be multiple failures.\r
414 @retval EAX #ERROR_STM_OUT_OF_RESOURCES\r
415 The STM has encountered an internal error and cannot complete\r
416 the request.\r
417 @retval EAX #ERROR_STM_UNSPECIFIED\r
418 An unspecified error occurred.\r
419\r
420 @note All other registers unmodified.\r
421**/\r
422#define STM_API_PROTECT_RESOURCE (BIT16 | 3)\r
423\r
424\r
425/**\r
426 The UnProtectResourceVMCALL() is invoked by the MLE root to request that the\r
427 STM allow the SMI handler access to the specified resources.\r
428\r
429 @param EAX #STM_API_UNPROTECT_RESOURCE (0x00010004)\r
430 @param EBX Low 32 bits of physical address of caller allocated\r
431 STM_RESOURCE_LIST. Bits 11:0 are ignored and assumed to be zero,\r
432 making the buffer 4K aligned.\r
433 @param ECX High 32 bits of physical address of caller allocated\r
434 STM_RESOURCE_LIST.\r
435\r
436 @note All fields of STM_RESOURCE_LIST are inputs only, except for the\r
437 ReturnStatus bit. On input, the ReturnStatus bit must be clear. On\r
438 return, the ReturnStatus bit is set for each resource processed. For\r
439 a properly formed STM_RESOURCE_LIST, this should be all resources\r
440 listed. There are no other fields modified by\r
441 UnProtectResourceVMCALL(). The STM_RESOURCE_LIST must be contained\r
442 entirely within a single 4K page.\r
443\r
444 @retval CF 0\r
445 No error, EAX set to STM_SUCCESS. The requested resources are\r
446 not being guarded by the STM.\r
447 @retval CF 1\r
448 An error occurred, EAX holds relevant error value.\r
449 @retval EAX #ERROR_STM_MALFORMED_RESOURCE_LIST\r
450 The resource list could not be parsed correctly, or did not\r
451 terminate before crossing a 4K page boundary. The caller must\r
452 walk through the STM_RESOURCE_LIST to determine which of the\r
453 requested resources were not able to be unprotected. The entire\r
454 list must be traversed since there may be multiple failures.\r
455 @retval EAX #ERROR_STM_UNSPECIFIED\r
456 An unspecified error occurred.\r
457\r
458 @note All other registers unmodified.\r
459**/\r
460#define STM_API_UNPROTECT_RESOURCE (BIT16 | 4)\r
461\r
462\r
463/**\r
464 The GetBiosResourcesVMCALL() is invoked by the MLE root to request the list\r
465 of BIOS required resources from the STM.\r
466\r
467 @param EAX #STM_API_GET_BIOS_RESOURCES (0x00010005)\r
468 @param EBX Low 32 bits of physical address of caller allocated destination\r
469 buffer. Bits 11:0 are ignored and assumed to be zero, making the\r
470 buffer 4K aligned.\r
471 @param ECX High 32 bits of physical address of caller allocated destination\r
472 buffer.\r
473 @param EDX Indicates which page of the BIOS resource list to copy into the\r
474 destination buffer. The first page is indicated by 0, the second\r
475 page by 1, etc.\r
476\r
477 @retval CF 0\r
478 No error, EAX set to STM_SUCCESS. The destination buffer\r
479 contains the BIOS required resources. If the page retrieved is\r
480 the last page, EDX will be cleared to 0. If there are more pages\r
481 to retrieve, EDX is incremented to the next page index. Calling\r
482 software should iterate on GetBiosResourcesVMCALL() until EDX is\r
483 returned cleared to 0.\r
484 @retval CF 1\r
485 An error occurred, EAX holds relevant error value.\r
486 @retval EAX #ERROR_STM_PAGE_NOT_FOUND\r
487 The page index supplied in EDX input was out of range.\r
488 @retval EAX #ERROR_STM_UNSPECIFIED\r
489 An unspecified error occurred.\r
490 @retval EDX Page index of next page to read. A return of EDX=0 signifies\r
491 that the entire list has been read.\r
492 @note EDX is both an input and an output register.\r
493\r
494 @note All other registers unmodified.\r
495**/\r
496#define STM_API_GET_BIOS_RESOURCES (BIT16 | 5)\r
497\r
498\r
499/**\r
500 The ManageVmcsDatabaseVMCALL() is invoked by the MLE root to add or remove an\r
501 MLE guest (including the MLE root) from the list of protected domains.\r
502\r
503 @param EAX #STM_API_MANAGE_VMCS_DATABASE (0x00010006)\r
504 @param EBX Low 32 bits of physical address of caller allocated\r
505 STM_VMCS_DATABASE_REQUEST. Bits 11:0 are ignored and assumed to\r
506 be zero, making the buffer 4K aligned.\r
507 @param ECX High 32 bits of physical address of caller allocated\r
508 STM_VMCS_DATABASE_REQUEST.\r
509\r
510 @note All fields of STM_VMCS_DATABASE_REQUEST are inputs only. They are not\r
511 modified by ManageVmcsDatabaseVMCALL().\r
512\r
513 @retval CF 0\r
514 No error, EAX set to STM_SUCCESS.\r
515 @retval CF 1\r
516 An error occurred, EAX holds relevant error value.\r
517 @retval EAX #ERROR_STM_INVALID_VMCS\r
518 Indicates a request to remove a VMCS from the database was made,\r
519 but the referenced VMCS was not found in the database.\r
520 @retval EAX #ERROR_STM_VMCS_PRESENT\r
521 Indicates a request to add a VMCS to the database was made, but\r
522 the referenced VMCS was already present in the database.\r
523 @retval EAX #ERROR_INVALID_PARAMETER\r
524 Indicates non-zero reserved field.\r
525 @retval EAX #ERROR_STM_UNSPECIFIED\r
526 An unspecified error occurred\r
527\r
528 @note All other registers unmodified.\r
529**/\r
530#define STM_API_MANAGE_VMCS_DATABASE (BIT16 | 6)\r
531\r
532/**\r
533 STM VMCS Database Request for #STM_API_MANAGE_VMCS_DATABASE VMCALL\r
534**/\r
535typedef struct {\r
536 ///\r
537 /// bits 11:0 are reserved and must be 0\r
538 ///\r
539 UINT64 VmcsPhysPointer;\r
540 UINT32 DomainType :4;\r
541 UINT32 XStatePolicy :2;\r
542 UINT32 DegradationPolicy :4;\r
543 ///\r
544 /// Must be 0\r
545 ///\r
546 UINT32 Reserved1 :22;\r
547 UINT32 AddOrRemove;\r
548} STM_VMCS_DATABASE_REQUEST;\r
549\r
550/**\r
551 Values for the DomainType field of #STM_VMCS_DATABASE_REQUEST\r
552 @{\r
553**/\r
554#define DOMAIN_UNPROTECTED 0\r
555#define DOMAIN_DISALLOWED_IO_OUT BIT0\r
556#define DOMAIN_DISALLOWED_IO_IN BIT1\r
557#define DOMAIN_INTEGRITY BIT2\r
558#define DOMAIN_CONFIDENTIALITY BIT3\r
559#define DOMAIN_INTEGRITY_PROT_OUT_IN (DOMAIN_INTEGRITY)\r
560#define DOMAIN_FULLY_PROT_OUT_IN (DOMAIN_CONFIDENTIALITY | DOMAIN_INTEGRITY)\r
561#define DOMAIN_FULLY_PROT (DOMAIN_FULLY_PROT_OUT_IN | DOMAIN_DISALLOWED_IO_IN | DOMAIN_DISALLOWED_IO_OUT)\r
562/// @}\r
563\r
564/**\r
565 Values for the XStatePolicy field of #STM_VMCS_DATABASE_REQUEST\r
566 @{\r
567**/\r
568#define XSTATE_READWRITE 0x00\r
569#define XSTATE_READONLY 0x01\r
570#define XSTATE_SCRUB 0x03\r
571/// @}\r
572\r
573/**\r
574 Values for the AddOrRemove field of #STM_VMCS_DATABASE_REQUEST\r
575 @{\r
576**/\r
577#define STM_VMCS_DATABASE_REQUEST_ADD 1\r
578#define STM_VMCS_DATABASE_REQUEST_REMOVE 0\r
579/// @}\r
580\r
581\r
582/**\r
583 InitializeProtectionVMCALL() prepares the STM for setup of the initial\r
584 protection profile which is subsequently communicated via one or more\r
585 invocations of ProtectResourceVMCALL(), prior to invoking StartStmVMCALL().\r
586 It is only necessary to invoke InitializeProtectionVMCALL() on one processor\r
587 thread. InitializeProtectionVMCALL() does not alter whether SMIs are masked\r
588 or unmasked. The STM should return back to the MLE with "Blocking by SMI" set\r
589 to 1 in the GUEST_INTERRUPTIBILITY field for the VMCS the STM created for the\r
590 MLE guest.\r
591\r
592 @param EAX #STM_API_INITIALIZE_PROTECTION (0x00010007)\r
593\r
594 @retval CF 0\r
595 No error, EAX set to STM_SUCCESS, EBX bits set to indicate STM\r
596 capabilities as defined below. The STM has set up an empty\r
597 protection profile, except for the resources that it sets up to\r
598 protect itself. The STM must not allow the SMI handler to map\r
599 any pages from the MSEG Base to the top of TSEG. The STM must\r
600 also not allow SMI handler access to those MSRs which the STM\r
601 requires for its own protection.\r
602 @retval CF 1\r
603 An error occurred, EAX holds relevant error value.\r
604 @retval EAX #ERROR_STM_ALREADY_STARTED\r
605 The STM is already configured and active. The STM remains active\r
606 and guarding the previously enabled resource list.\r
607 @retval EAX #ERROR_STM_UNPROTECTABLE\r
608 The STM determines that based on the platform configuration, the\r
609 STM is unable to protect itself. For example, the BIOS required\r
610 resource list contains memory pages in MSEG.\r
611 @retval EAX #ERROR_STM_UNSPECIFIED\r
612 An unspecified error occurred.\r
613\r
614 @note All other registers unmodified.\r
615**/\r
616#define STM_API_INITIALIZE_PROTECTION (BIT16 | 7)\r
617\r
618/**\r
619 Byte granular support bits returned in EBX from #STM_API_INITIALIZE_PROTECTION\r
620 @{\r
621**/\r
622#define STM_RSC_BGI BIT1\r
623#define STM_RSC_BGM BIT2\r
624#define STM_RSC_MSR BIT3\r
625/// @}\r
626\r
627\r
628/**\r
629 The ManageEventLogVMCALL() is invoked by the MLE root to control the logging\r
630 feature. It consists of several sub-functions to facilitate establishment of\r
631 the log itself, configuring what events will be logged, and functions to\r
632 start, stop, and clear the log.\r
633\r
634 @param EAX #STM_API_MANAGE_EVENT_LOG (0x00010008)\r
635 @param EBX Low 32 bits of physical address of caller allocated\r
636 STM_EVENT_LOG_MANAGEMENT_REQUEST. Bits 11:0 are ignored and\r
637 assumed to be zero, making the buffer 4K aligned.\r
638 @param ECX High 32 bits of physical address of caller allocated\r
639 STM_EVENT_LOG_MANAGEMENT_REQUEST.\r
640\r
641 @retval CF=0\r
642 No error, EAX set to STM_SUCCESS.\r
643 @retval CF=1\r
644 An error occurred, EAX holds relevant error value. See subfunction\r
645 descriptions below for details.\r
646\r
647 @note All other registers unmodified.\r
648**/\r
649#define STM_API_MANAGE_EVENT_LOG (BIT16 | 8)\r
650\r
651///\r
652/// STM Event Log Management Request for #STM_API_MANAGE_EVENT_LOG VMCALL\r
653///\r
654typedef struct {\r
655 UINT32 SubFunctionIndex;\r
656 union {\r
657 struct {\r
658 UINT32 PageCount;\r
659 //\r
660 // number of elements is PageCount\r
661 //\r
662 UINT64 Pages[];\r
663 } LogBuffer;\r
664 //\r
665 // bitmap of EVENT_TYPE\r
666 //\r
667 UINT32 EventEnableBitmap;\r
668 } Data;\r
669} STM_EVENT_LOG_MANAGEMENT_REQUEST;\r
670\r
671/**\r
672 Defines values for the SubFunctionIndex field of\r
673 #STM_EVENT_LOG_MANAGEMENT_REQUEST\r
674 @{\r
675**/\r
676#define STM_EVENT_LOG_MANAGEMENT_REQUEST_NEW_LOG 1\r
677#define STM_EVENT_LOG_MANAGEMENT_REQUEST_CONFIGURE_LOG 2\r
678#define STM_EVENT_LOG_MANAGEMENT_REQUEST_START_LOG 3\r
679#define STM_EVENT_LOG_MANAGEMENT_REQUEST_STOP_LOG 4\r
680#define STM_EVENT_LOG_MANAGEMENT_REQUEST_CLEAR_LOG 5\r
681#define STM_EVENT_LOG_MANAGEMENT_REQUEST_DELETE_LOG 6\r
682/// @}\r
683\r
684/**\r
685 Log Entry Header\r
686**/\r
687typedef struct {\r
688 UINT32 EventSerialNumber;\r
689 UINT16 Type;\r
690 UINT16 Lock :1;\r
691 UINT16 Valid :1;\r
692 UINT16 ReadByMle :1;\r
693 UINT16 Wrapped :1;\r
694 UINT16 Reserved :12;\r
695} LOG_ENTRY_HEADER;\r
696\r
697/**\r
698 Enum values for the Type field of #LOG_ENTRY_HEADER\r
699**/\r
700typedef enum {\r
701 EvtLogStarted,\r
702 EvtLogStopped,\r
703 EvtLogInvalidParameterDetected,\r
704 EvtHandledProtectionException,\r
705 ///\r
706 /// unhandled protection exceptions result in reset & cannot be logged\r
707 ///\r
708 EvtBiosAccessToUnclaimedResource,\r
709 EvtMleResourceProtectionGranted,\r
710 EvtMleResourceProtectionDenied,\r
711 EvtMleResourceUnprotect,\r
712 EvtMleResourceUnprotectError,\r
713 EvtMleDomainTypeDegraded,\r
714 ///\r
715 /// add more here\r
716 ///\r
717 EvtMleMax,\r
718 ///\r
719 /// Not used\r
720 ///\r
721 EvtInvalid = 0xFFFFFFFF,\r
722} EVENT_TYPE;\r
723\r
724typedef struct {\r
725 UINT32 Reserved;\r
726} ENTRY_EVT_LOG_STARTED;\r
727\r
728typedef struct {\r
729 UINT32 Reserved;\r
730} ENTRY_EVT_LOG_STOPPED;\r
731\r
732typedef struct {\r
733 UINT32 VmcallApiNumber;\r
734} ENTRY_EVT_LOG_INVALID_PARAM;\r
735\r
736typedef struct {\r
737 STM_RSC Resource;\r
738} ENTRY_EVT_LOG_HANDLED_PROTECTION_EXCEPTION;\r
739\r
740typedef struct {\r
741 STM_RSC Resource;\r
742} ENTRY_EVT_BIOS_ACCESS_UNCLAIMED_RSC;\r
743\r
744typedef struct {\r
745 STM_RSC Resource;\r
746} ENTRY_EVT_MLE_RSC_PROT_GRANTED;\r
747\r
748typedef struct {\r
749 STM_RSC Resource;\r
750} ENTRY_EVT_MLE_RSC_PROT_DENIED;\r
751\r
752typedef struct {\r
753 STM_RSC Resource;\r
754} ENTRY_EVT_MLE_RSC_UNPROT;\r
755\r
756typedef struct {\r
757 STM_RSC Resource;\r
758} ENTRY_EVT_MLE_RSC_UNPROT_ERROR;\r
759\r
760typedef struct {\r
761 UINT64 VmcsPhysPointer;\r
762 UINT8 ExpectedDomainType;\r
763 UINT8 DegradedDomainType;\r
764} ENTRY_EVT_MLE_DOMAIN_TYPE_DEGRADED;\r
765\r
766typedef union {\r
767 ENTRY_EVT_LOG_STARTED Started;\r
768 ENTRY_EVT_LOG_STOPPED Stopped;\r
769 ENTRY_EVT_LOG_INVALID_PARAM InvalidParam;\r
770 ENTRY_EVT_LOG_HANDLED_PROTECTION_EXCEPTION HandledProtectionException;\r
771 ENTRY_EVT_BIOS_ACCESS_UNCLAIMED_RSC BiosUnclaimedRsc;\r
772 ENTRY_EVT_MLE_RSC_PROT_GRANTED MleRscProtGranted;\r
773 ENTRY_EVT_MLE_RSC_PROT_DENIED MleRscProtDenied;\r
774 ENTRY_EVT_MLE_RSC_UNPROT MleRscUnprot;\r
775 ENTRY_EVT_MLE_RSC_UNPROT_ERROR MleRscUnprotError;\r
776 ENTRY_EVT_MLE_DOMAIN_TYPE_DEGRADED MleDomainTypeDegraded;\r
777} LOG_ENTRY_DATA;\r
778\r
779typedef struct {\r
780 LOG_ENTRY_HEADER Hdr;\r
781 LOG_ENTRY_DATA Data;\r
782} STM_LOG_ENTRY;\r
783\r
784/**\r
785 Maximum STM Log Entry Size\r
786**/\r
787#define STM_LOG_ENTRY_SIZE 256\r
788\r
789\r
790/**\r
791 STM Protection Exception Stack Frame Structures\r
792**/\r
793\r
794typedef struct {\r
795 UINT32 Rdi;\r
796 UINT32 Rsi;\r
797 UINT32 Rbp;\r
798 UINT32 Rdx;\r
799 UINT32 Rcx;\r
800 UINT32 Rbx;\r
801 UINT32 Rax;\r
802 UINT32 Cr3;\r
803 UINT32 Cr2;\r
804 UINT32 Cr0;\r
805 UINT32 VmcsExitInstructionInfo;\r
806 UINT32 VmcsExitInstructionLength;\r
807 UINT64 VmcsExitQualification;\r
808 ///\r
809 /// An TXT_SMM_PROTECTION_EXCEPTION_TYPE num value\r
810 ///\r
811 UINT32 ErrorCode;\r
812 UINT32 Rip;\r
813 UINT32 Cs;\r
814 UINT32 Rflags;\r
815 UINT32 Rsp;\r
816 UINT32 Ss;\r
817} STM_PROTECTION_EXCEPTION_STACK_FRAME_IA32;\r
818\r
819typedef struct {\r
820 UINT64 R15;\r
821 UINT64 R14;\r
822 UINT64 R13;\r
823 UINT64 R12;\r
824 UINT64 R11;\r
825 UINT64 R10;\r
826 UINT64 R9;\r
827 UINT64 R8;\r
828 UINT64 Rdi;\r
829 UINT64 Rsi;\r
830 UINT64 Rbp;\r
831 UINT64 Rdx;\r
832 UINT64 Rcx;\r
833 UINT64 Rbx;\r
834 UINT64 Rax;\r
835 UINT64 Cr8;\r
836 UINT64 Cr3;\r
837 UINT64 Cr2;\r
838 UINT64 Cr0;\r
839 UINT64 VmcsExitInstructionInfo;\r
840 UINT64 VmcsExitInstructionLength;\r
841 UINT64 VmcsExitQualification;\r
842 ///\r
843 /// An TXT_SMM_PROTECTION_EXCEPTION_TYPE num value\r
844 ///\r
845 UINT64 ErrorCode;\r
846 UINT64 Rip;\r
847 UINT64 Cs;\r
848 UINT64 Rflags;\r
849 UINT64 Rsp;\r
850 UINT64 Ss;\r
851} STM_PROTECTION_EXCEPTION_STACK_FRAME_X64;\r
852\r
853typedef union {\r
854 STM_PROTECTION_EXCEPTION_STACK_FRAME_IA32 *Ia32StackFrame;\r
855 STM_PROTECTION_EXCEPTION_STACK_FRAME_X64 *X64StackFrame;\r
856} STM_PROTECTION_EXCEPTION_STACK_FRAME;\r
857\r
858/**\r
859 Enum values for the ErrorCode field in\r
860 #STM_PROTECTION_EXCEPTION_STACK_FRAME_IA32 and\r
861 #STM_PROTECTION_EXCEPTION_STACK_FRAME_X64\r
862**/\r
863typedef enum {\r
864 TxtSmmPageViolation = 1,\r
865 TxtSmmMsrViolation,\r
866 TxtSmmRegisterViolation,\r
867 TxtSmmIoViolation,\r
868 TxtSmmPciViolation\r
869} TXT_SMM_PROTECTION_EXCEPTION_TYPE;\r
870\r
871/**\r
872 TXT Pocessor SMM Descriptor (PSD) structures\r
873**/\r
874\r
875typedef struct {\r
876 UINT64 SpeRip;\r
877 UINT64 SpeRsp;\r
878 UINT16 SpeSs;\r
879 UINT16 PageViolationException:1;\r
880 UINT16 MsrViolationException:1;\r
881 UINT16 RegisterViolationException:1;\r
882 UINT16 IoViolationException:1;\r
883 UINT16 PciViolationException:1;\r
884 UINT16 Reserved1:11;\r
885 UINT32 Reserved2;\r
886} STM_PROTECTION_EXCEPTION_HANDLER;\r
887\r
888typedef struct {\r
889 UINT8 ExecutionDisableOutsideSmrr:1;\r
890 UINT8 Intel64Mode:1;\r
891 UINT8 Cr4Pae : 1;\r
892 UINT8 Cr4Pse : 1;\r
893 UINT8 Reserved1 : 4;\r
894} STM_SMM_ENTRY_STATE;\r
895\r
896typedef struct {\r
897 UINT8 SmramToVmcsRestoreRequired : 1; ///> BIOS restore hint\r
898 UINT8 ReinitializeVmcsRequired : 1; ///> BIOS request\r
899 UINT8 Reserved2 : 6;\r
900} STM_SMM_RESUME_STATE;\r
901\r
902typedef struct {\r
903 UINT8 DomainType : 4; ///> STM input to BIOS on each SMI\r
904 UINT8 XStatePolicy : 2; ///> STM input to BIOS on each SMI\r
905 UINT8 EptEnabled : 1;\r
906 UINT8 Reserved3 : 1;\r
907} STM_SMM_STATE;\r
908\r
909#define TXT_SMM_PSD_OFFSET 0xfb00\r
910#define TXT_PROCESSOR_SMM_DESCRIPTOR_SIGNATURE SIGNATURE_64('T', 'X', 'T', 'P', 'S', 'S', 'I', 'G')\r
911#define TXT_PROCESSOR_SMM_DESCRIPTOR_VERSION_MAJOR 1\r
912#define TXT_PROCESSOR_SMM_DESCRIPTOR_VERSION_MINOR 0\r
913\r
914typedef struct {\r
915 UINT64 Signature;\r
916 UINT16 Size;\r
917 UINT8 SmmDescriptorVerMajor;\r
918 UINT8 SmmDescriptorVerMinor;\r
919 UINT32 LocalApicId;\r
920 STM_SMM_ENTRY_STATE SmmEntryState;\r
921 STM_SMM_RESUME_STATE SmmResumeState;\r
922 STM_SMM_STATE StmSmmState;\r
923 UINT8 Reserved4;\r
924 UINT16 SmmCs;\r
925 UINT16 SmmDs;\r
926 UINT16 SmmSs;\r
927 UINT16 SmmOtherSegment;\r
928 UINT16 SmmTr;\r
929 UINT16 Reserved5;\r
930 UINT64 SmmCr3;\r
931 UINT64 SmmStmSetupRip;\r
932 UINT64 SmmStmTeardownRip;\r
933 UINT64 SmmSmiHandlerRip;\r
934 UINT64 SmmSmiHandlerRsp;\r
935 UINT64 SmmGdtPtr;\r
936 UINT32 SmmGdtSize;\r
937 UINT32 RequiredStmSmmRevId;\r
938 STM_PROTECTION_EXCEPTION_HANDLER StmProtectionExceptionHandler;\r
939 UINT64 Reserved6;\r
940 UINT64 BiosHwResourceRequirementsPtr;\r
941 // extend area\r
942 UINT64 AcpiRsdp;\r
943 UINT8 PhysicalAddressBits;\r
944} TXT_PROCESSOR_SMM_DESCRIPTOR;\r
945\r
946#pragma pack ()\r
947\r
948#endif\r