Changeset 80721 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
- Timestamp:
- Sep 11, 2019 8:46:37 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 133262
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-129237 /vendor/edk2/current 103735-103757,103769-103776,129194-133213
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
r77662 r80721 2 2 Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU. 3 3 4 Copyright (c) 2009 - 201 8, Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR> 5 5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> 6 6 7 This program and the accompanying materials 8 are licensed and made available under the terms and conditions of the BSD License 9 which accompanies this distribution. The full text of the license may be found at 10 http://opensource.org/licenses/bsd-license.php 11 12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 7 SPDX-License-Identifier: BSD-2-Clause-Patent 14 8 15 9 **/ … … 27 21 #include <Protocol/SmmCpuService.h> 28 22 #include <Protocol/SmmMemoryAttribute.h> 23 #include <Protocol/MmMp.h> 29 24 30 25 #include <Guid/AcpiS3Context.h> … … 39 34 #include <Library/BaseMemoryLib.h> 40 35 #include <Library/PcdLib.h> 41 #include <Library/CacheMaintenanceLib.h>42 36 #include <Library/MtrrLib.h> 43 37 #include <Library/SmmCpuPlatformHookLib.h> … … 55 49 #include <Library/SmmCpuFeaturesLib.h> 56 50 #include <Library/PeCoffGetEntryPointLib.h> 51 #include <Library/RegisterCpuFeaturesLib.h> 57 52 58 53 #include <AcpiCpuData.h> 59 54 #include <CpuHotPlugData.h> 60 55 61 #include <Register/ Cpuid.h>62 #include <Register/ Msr.h>56 #include <Register/Intel/Cpuid.h> 57 #include <Register/Intel/Msr.h> 63 58 64 59 #include "CpuService.h" 65 60 #include "SmmProfile.h" 61 62 // 63 // CET definition 64 // 65 #define CPUID_CET_SS BIT7 66 #define CPUID_CET_IBT BIT20 67 68 #define CR4_CET_ENABLE BIT23 69 70 #define MSR_IA32_S_CET 0x6A2 71 #define MSR_IA32_PL0_SSP 0x6A4 72 #define MSR_IA32_INTERRUPT_SSP_TABLE_ADDR 0x6A8 73 74 typedef union { 75 struct { 76 // enable shadow stacks 77 UINT32 SH_STK_ENP:1; 78 // enable the WRSS{D,Q}W instructions. 79 UINT32 WR_SHSTK_EN:1; 80 // enable tracking of indirect call/jmp targets to be ENDBRANCH instruction. 81 UINT32 ENDBR_EN:1; 82 // enable legacy compatibility treatment for indirect call/jmp tracking. 83 UINT32 LEG_IW_EN:1; 84 // enable use of no-track prefix on indirect call/jmp. 85 UINT32 NO_TRACK_EN:1; 86 // disable suppression of CET indirect branch tracking on legacy compatibility. 87 UINT32 SUPPRESS_DIS:1; 88 UINT32 RSVD:4; 89 // indirect branch tracking is suppressed. 90 // This bit can be written to 1 only if TRACKER is written as IDLE. 91 UINT32 SUPPRESS:1; 92 // Value of the endbranch state machine 93 // Values: IDLE (0), WAIT_FOR_ENDBRANCH(1). 94 UINT32 TRACKER:1; 95 // linear address of a bitmap in memory indicating valid 96 // pages as target of CALL/JMP_indirect that do not land on ENDBRANCH when CET is enabled 97 // and not suppressed. Valid when ENDBR_EN is 1. Must be machine canonical when written on 98 // parts that support 64 bit mode. On parts that do not support 64 bit mode, the bits 63:32 are 99 // reserved and must be 0. This value is extended by 12 bits at the low end to form the base address 100 // (this automatically aligns the address on a 4-Kbyte boundary). 101 UINT32 EB_LEG_BITMAP_BASE_low:12; 102 UINT32 EB_LEG_BITMAP_BASE_high:32; 103 } Bits; 104 UINT64 Uint64; 105 } MSR_IA32_CET; 66 106 67 107 // … … 128 168 // 129 169 #define TSS_SIZE 104 170 #define EXCEPTION_TSS_SIZE (TSS_SIZE + 4) // Add 4 bytes SSP 130 171 #define TSS_X64_IST1_OFFSET 36 131 172 #define TSS_IA32_CR3_OFFSET 28 132 173 #define TSS_IA32_ESP_OFFSET 56 174 #define TSS_IA32_SSP_OFFSET 104 133 175 134 176 #define CR0_WP BIT16 … … 158 200 159 201 // 202 // Wrapper used to convert EFI_AP_PROCEDURE2 and EFI_AP_PROCEDURE. 203 // 204 typedef struct { 205 EFI_AP_PROCEDURE Procedure; 206 VOID *ProcedureArgument; 207 } PROCEDURE_WRAPPER; 208 209 #define PROCEDURE_TOKEN_SIGNATURE SIGNATURE_32 ('P', 'R', 'T', 'S') 210 211 typedef struct { 212 UINTN Signature; 213 LIST_ENTRY Link; 214 215 SPIN_LOCK *ProcedureToken; 216 } PROCEDURE_TOKEN; 217 218 #define PROCEDURE_TOKEN_FROM_LINK(a) CR (a, PROCEDURE_TOKEN, Link, PROCEDURE_TOKEN_SIGNATURE) 219 220 // 160 221 // Private structure for the SMM CPU module that is stored in DXE Runtime memory 161 222 // Contains the SMM Configuration Protocols that is produced. … … 179 240 180 241 EFI_SMM_CONFIGURATION_PROTOCOL SmmConfiguration; 242 243 PROCEDURE_WRAPPER *ApWrapperFunc; 244 LIST_ENTRY TokenList; 245 181 246 } SMM_CPU_PRIVATE_DATA; 182 247 … … 186 251 extern UINTN mNumberOfCpus; 187 252 extern EFI_SMM_CPU_PROTOCOL mSmmCpu; 253 extern EFI_MM_MP_PROTOCOL mSmmMp; 188 254 189 255 /// … … 298 364 ); 299 365 300 //301 //302 //303 typedef struct {304 UINT32 Offset;305 UINT16 Segment;306 UINT16 Reserved;307 } IA32_FAR_ADDRESS;308 309 extern IA32_FAR_ADDRESS gSmmJmpAddr;310 311 366 extern CONST UINT8 gcSmmInitTemplate[]; 312 367 extern CONST UINT16 gcSmmInitSize; 313 extern UINT32 gSmmCr0; 314 extern UINT32 gSmmCr3; 315 extern UINT32 gSmmCr4; 316 extern UINTN gSmmInitStack; 368 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr0; 369 extern UINT32 mSmmCr0; 370 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr3; 371 extern UINT32 mSmmCr4; 372 X86_ASSEMBLY_PATCH_LABEL gPatchSmmCr4; 373 X86_ASSEMBLY_PATCH_LABEL gPatchSmmInitStack; 374 X86_ASSEMBLY_PATCH_LABEL mPatchCetSupported; 375 extern BOOLEAN mCetSupported; 317 376 318 377 /** … … 330 389 typedef struct { 331 390 SPIN_LOCK *Busy; 332 volatile EFI_AP_PROCEDURE 391 volatile EFI_AP_PROCEDURE2 Procedure; 333 392 volatile VOID *Parameter; 334 393 volatile UINT32 *Run; 335 394 volatile BOOLEAN *Present; 395 SPIN_LOCK *Token; 396 EFI_STATUS *Status; 336 397 } SMM_CPU_DATA_BLOCK; 337 398 … … 355 416 volatile BOOLEAN SwitchBsp; 356 417 volatile BOOLEAN *CandidateBsp; 418 EFI_AP_PROCEDURE StartupProcedure; 419 VOID *StartupProcArgs; 357 420 } SMM_DISPATCHER_MP_SYNC_DATA; 358 359 #define MSR_SPIN_LOCK_INIT_NUM 15360 361 typedef struct {362 SPIN_LOCK *SpinLock;363 UINT32 MsrIndex;364 } MP_MSR_LOCK;365 421 366 422 #define SMM_PSD_OFFSET 0xfb00 … … 375 431 SPIN_LOCK *PFLock; 376 432 SPIN_LOCK *CodeAccessCheckLock; 377 SPIN_LOCK *MemoryMappedLock;378 433 } SMM_CPU_SEMAPHORE_GLOBAL; 379 434 … … 385 440 volatile UINT32 *Run; 386 441 volatile BOOLEAN *Present; 442 SPIN_LOCK *Token; 387 443 } SMM_CPU_SEMAPHORE_CPU; 388 389 ///390 /// All MSRs semaphores' pointer and counter391 ///392 typedef struct {393 SPIN_LOCK *Msr;394 UINTN AvailableCounter;395 } SMM_CPU_SEMAPHORE_MSR;396 444 397 445 /// … … 401 449 SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal; 402 450 SMM_CPU_SEMAPHORE_CPU SemaphoreCpu; 403 SMM_CPU_SEMAPHORE_MSR SemaphoreMsr;404 451 } SMM_CPU_SEMAPHORES; 405 452 … … 420 467 extern SPIN_LOCK *mPFLock; 421 468 extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock; 422 extern SPIN_LOCK *mMemoryMappedLock;423 469 extern EFI_SMRAM_DESCRIPTOR *mSmmCpuSmramRanges; 424 470 extern UINTN mSmmCpuSmramRangeCount; … … 446 492 Initialize global data for MP synchronization. 447 493 448 @param Stacks Base address of SMI stack buffer for all processors. 449 @param StackSize Stack size for each processor in SMM. 494 @param Stacks Base address of SMI stack buffer for all processors. 495 @param StackSize Stack size for each processor in SMM. 496 @param ShadowStackSize Shadow Stack size for each processor in SMM. 450 497 451 498 **/ … … 453 500 InitializeMpServiceData ( 454 501 IN VOID *Stacks, 455 IN UINTN StackSize 502 IN UINTN StackSize, 503 IN UINTN ShadowStackSize 456 504 ); 457 505 … … 1065 1113 1066 1114 /** 1115 Set ShadowStack memory. 1116 1117 @param[in] Cr3 The page table base address. 1118 @param[in] BaseAddress The physical address that is the start address of a memory region. 1119 @param[in] Length The size in bytes of the memory region. 1120 1121 @retval EFI_SUCCESS The shadow stack memory is set. 1122 **/ 1123 EFI_STATUS 1124 SetShadowStack ( 1125 IN UINTN Cr3, 1126 IN EFI_PHYSICAL_ADDRESS BaseAddress, 1127 IN UINT64 Length 1128 ); 1129 1130 /** 1131 Set not present memory. 1132 1133 @param[in] Cr3 The page table base address. 1134 @param[in] BaseAddress The physical address that is the start address of a memory region. 1135 @param[in] Length The size in bytes of the memory region. 1136 1137 @retval EFI_SUCCESS The not present memory is set. 1138 **/ 1139 EFI_STATUS 1140 SetNotPresentPage ( 1141 IN UINTN Cr3, 1142 IN EFI_PHYSICAL_ADDRESS BaseAddress, 1143 IN UINT64 Length 1144 ); 1145 1146 /** 1147 Initialize the shadow stack related data structure. 1148 1149 @param CpuIndex The index of CPU. 1150 @param ShadowStack The bottom of the shadow stack for this CPU. 1151 **/ 1152 VOID 1153 InitShadowStack ( 1154 IN UINTN CpuIndex, 1155 IN VOID *ShadowStack 1156 ); 1157 1158 /** 1067 1159 This function set given attributes of the memory region specified by 1068 1160 BaseAddress and Length. … … 1082 1174 bytes of the memory resource range specified 1083 1175 by BaseAddress and Length. 1084 The bit mask of attributes is not support for1176 The bit mask of attributes is not supported for 1085 1177 the memory resource range specified by 1086 1178 BaseAddress and Length. … … 1104 1196 a memory region. 1105 1197 @param Length The size in bytes of the memory region. 1106 @param Attributes The bit mask of attributes to setfor the memory1198 @param Attributes The bit mask of attributes to clear for the memory 1107 1199 region. 1108 1200 1109 @retval EFI_SUCCESS The attributes were setfor the memory region.1201 @retval EFI_SUCCESS The attributes were cleared for the memory region. 1110 1202 @retval EFI_INVALID_PARAMETER Length is zero. 1111 1203 Attributes specified an illegal combination of 1112 attributes that cannot be settogether.1204 attributes that cannot be cleared together. 1113 1205 @retval EFI_UNSUPPORTED The processor does not support one or more 1114 1206 bytes of the memory resource range specified 1115 1207 by BaseAddress and Length. 1116 The bit mask of attributes is not support for1208 The bit mask of attributes is not supported for 1117 1209 the memory resource range specified by 1118 1210 BaseAddress and Length. … … 1129 1221 1130 1222 /** 1131 This function retrieve the attributes of the memory region specified by1223 This function retrieves the attributes of the memory region specified by 1132 1224 BaseAddress and Length. If different attributes are got from different part 1133 1225 of the memory region, EFI_NO_MAPPING will be returned. … … 1147 1239 bytes of the memory resource range specified 1148 1240 by BaseAddress and Length. 1149 The bit mask of attributes is not support for1150 the memory resource range specified by1151 BaseAddress and Length.1152 1241 1153 1242 **/ … … 1179 1268 ); 1180 1269 1270 /** 1271 This function reads CR2 register when on-demand paging is enabled 1272 for 64 bit and no action for 32 bit. 1273 1274 @param[out] *Cr2 Pointer to variable to hold CR2 register value. 1275 **/ 1276 VOID 1277 SaveCr2 ( 1278 OUT UINTN *Cr2 1279 ); 1280 1281 /** 1282 This function writes into CR2 register when on-demand paging is enabled 1283 for 64 bit and no action for 32 bit. 1284 1285 @param[in] Cr2 Value to write into CR2 register. 1286 **/ 1287 VOID 1288 RestoreCr2 ( 1289 IN UINTN Cr2 1290 ); 1291 1292 /** 1293 Schedule a procedure to run on the specified CPU. 1294 1295 @param[in] Procedure The address of the procedure to run 1296 @param[in] CpuIndex Target CPU Index 1297 @param[in,out] ProcArguments The parameter to pass to the procedure 1298 @param[in,out] Token This is an optional parameter that allows the caller to execute the 1299 procedure in a blocking or non-blocking fashion. If it is NULL the 1300 call is blocking, and the call will not return until the AP has 1301 completed the procedure. If the token is not NULL, the call will 1302 return immediately. The caller can check whether the procedure has 1303 completed with CheckOnProcedure or WaitForProcedure. 1304 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for the APs to finish 1305 execution of Procedure, either for blocking or non-blocking mode. 1306 Zero means infinity. If the timeout expires before all APs return 1307 from Procedure, then Procedure on the failed APs is terminated. If 1308 the timeout expires in blocking mode, the call returns EFI_TIMEOUT. 1309 If the timeout expires in non-blocking mode, the timeout determined 1310 can be through CheckOnProcedure or WaitForProcedure. 1311 Note that timeout support is optional. Whether an implementation 1312 supports this feature can be determined via the Attributes data 1313 member. 1314 @param[in,out] CpuStatus This optional pointer may be used to get the status code returned 1315 by Procedure when it completes execution on the target AP, or with 1316 EFI_TIMEOUT if the Procedure fails to complete within the optional 1317 timeout. The implementation will update this variable with 1318 EFI_NOT_READY prior to starting Procedure on the target AP. 1319 1320 @retval EFI_INVALID_PARAMETER CpuNumber not valid 1321 @retval EFI_INVALID_PARAMETER CpuNumber specifying BSP 1322 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber did not enter SMM 1323 @retval EFI_INVALID_PARAMETER The AP specified by CpuNumber is busy 1324 @retval EFI_SUCCESS The procedure has been successfully scheduled 1325 1326 **/ 1327 EFI_STATUS 1328 InternalSmmStartupThisAp ( 1329 IN EFI_AP_PROCEDURE2 Procedure, 1330 IN UINTN CpuIndex, 1331 IN OUT VOID *ProcArguments OPTIONAL, 1332 IN OUT MM_COMPLETION *Token, 1333 IN UINTN TimeoutInMicroseconds, 1334 IN OUT EFI_STATUS *CpuStatus 1335 ); 1336 1337 /** 1338 Checks whether the input token is the current used token. 1339 1340 @param[in] Token This parameter describes the token that was passed into DispatchProcedure or 1341 BroadcastProcedure. 1342 1343 @retval TRUE The input token is the current used token. 1344 @retval FALSE The input token is not the current used token. 1345 **/ 1346 BOOLEAN 1347 IsTokenInUse ( 1348 IN SPIN_LOCK *Token 1349 ); 1350 1351 /** 1352 Checks status of specified AP. 1353 1354 This function checks whether the specified AP has finished the task assigned 1355 by StartupThisAP(), and whether timeout expires. 1356 1357 @param[in] Token This parameter describes the token that was passed into DispatchProcedure or 1358 BroadcastProcedure. 1359 1360 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs(). 1361 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired. 1362 **/ 1363 EFI_STATUS 1364 IsApReady ( 1365 IN SPIN_LOCK *Token 1366 ); 1367 1368 /** 1369 Check whether it is an present AP. 1370 1371 @param CpuIndex The AP index which calls this function. 1372 1373 @retval TRUE It's a present AP. 1374 @retval TRUE This is not an AP or it is not present. 1375 1376 **/ 1377 BOOLEAN 1378 IsPresentAp ( 1379 IN UINTN CpuIndex 1380 ); 1381 1382 /** 1383 Worker function to execute a caller provided function on all enabled APs. 1384 1385 @param[in] Procedure A pointer to the function to be run on 1386 enabled APs of the system. 1387 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for 1388 APs to return from Procedure, either for 1389 blocking or non-blocking mode. 1390 @param[in,out] ProcedureArguments The parameter passed into Procedure for 1391 all APs. 1392 @param[in,out] Token This is an optional parameter that allows the caller to execute the 1393 procedure in a blocking or non-blocking fashion. If it is NULL the 1394 call is blocking, and the call will not return until the AP has 1395 completed the procedure. If the token is not NULL, the call will 1396 return immediately. The caller can check whether the procedure has 1397 completed with CheckOnProcedure or WaitForProcedure. 1398 @param[in,out] CPUStatus This optional pointer may be used to get the status code returned 1399 by Procedure when it completes execution on the target AP, or with 1400 EFI_TIMEOUT if the Procedure fails to complete within the optional 1401 timeout. The implementation will update this variable with 1402 EFI_NOT_READY prior to starting Procedure on the target AP. 1403 1404 @retval EFI_SUCCESS In blocking mode, all APs have finished before 1405 the timeout expired. 1406 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched 1407 to all enabled APs. 1408 @retval others Failed to Startup all APs. 1409 1410 **/ 1411 EFI_STATUS 1412 InternalSmmStartupAllAPs ( 1413 IN EFI_AP_PROCEDURE2 Procedure, 1414 IN UINTN TimeoutInMicroseconds, 1415 IN OUT VOID *ProcedureArguments OPTIONAL, 1416 IN OUT MM_COMPLETION *Token, 1417 IN OUT EFI_STATUS *CPUStatus 1418 ); 1419 1420 /** 1421 1422 Register the SMM Foundation entry point. 1423 1424 @param[in] Procedure A pointer to the code stream to be run on the designated target AP 1425 of the system. Type EFI_AP_PROCEDURE is defined below in Volume 2 1426 with the related definitions of 1427 EFI_MP_SERVICES_PROTOCOL.StartupAllAPs. 1428 If caller may pass a value of NULL to deregister any existing 1429 startup procedure. 1430 @param[in,out] ProcedureArguments Allows the caller to pass a list of parameters to the code that is 1431 run by the AP. It is an optional common mailbox between APs and 1432 the caller to share information 1433 1434 @retval EFI_SUCCESS The Procedure has been set successfully. 1435 @retval EFI_INVALID_PARAMETER The Procedure is NULL but ProcedureArguments not NULL. 1436 1437 **/ 1438 EFI_STATUS 1439 RegisterStartupProcedure ( 1440 IN EFI_AP_PROCEDURE Procedure, 1441 IN OUT VOID *ProcedureArguments OPTIONAL 1442 ); 1443 1444 /** 1445 Allocate buffer for SpinLock and Wrapper function buffer. 1446 1447 **/ 1448 VOID 1449 InitializeDataForMmMp ( 1450 VOID 1451 ); 1452 1181 1453 #endif
Note:
See TracChangeset
for help on using the changeset viewer.