Changeset 85718 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm
- Timestamp:
- Aug 12, 2020 4:09:12 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 139865
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 14 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-133213 /vendor/edk2/current 103735-103757,103769-103776,129194-139864
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
r80721 r85718 617 617 PrepareApStartupVector (mAcpiCpuData.StartupVector); 618 618 619 mNumberToFinish = mAcpiCpuData.NumberOfCpus - 1; 619 if (FeaturePcdGet (PcdCpuHotPlugSupport)) { 620 ASSERT (mNumberOfCpus <= mAcpiCpuData.NumberOfCpus); 621 } else { 622 ASSERT (mNumberOfCpus == mAcpiCpuData.NumberOfCpus); 623 } 624 mNumberToFinish = (UINT32)(mNumberOfCpus - 1); 620 625 mExchangeInfo->ApFunction = (VOID *) (UINTN) InitializeAp; 621 626 … … 647 652 ) 648 653 { 649 mNumberToFinish = mAcpiCpuData.NumberOfCpus - 1; 654 if (FeaturePcdGet (PcdCpuHotPlugSupport)) { 655 ASSERT (mNumberOfCpus <= mAcpiCpuData.NumberOfCpus); 656 } else { 657 ASSERT (mNumberOfCpus == mAcpiCpuData.NumberOfCpus); 658 } 659 mNumberToFinish = (UINT32)(mNumberOfCpus - 1); 650 660 651 661 // -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c
r80721 r85718 337 337 return ; 338 338 } 339 340 /** 341 Return whether access to non-SMRAM is restricted. 342 343 @retval TRUE Access to non-SMRAM is restricted. 344 @retval FALSE Access to non-SMRAM is not restricted. 345 **/ 346 BOOLEAN 347 IsRestrictedMemoryAccess ( 348 VOID 349 ) 350 { 351 return TRUE; 352 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
r80721 r85718 2 2 SMM MP service implementation 3 3 4 Copyright (c) 2009 - 20 19, Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR> 5 5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> 6 6 … … 138 138 UINTN Index; 139 139 140 for (Index = mMaxNumberOfCpus; Index-- > 0;) {140 for (Index = 0; Index < mMaxNumberOfCpus; Index++) { 141 141 if (IsPresentAp (Index)) { 142 142 ReleaseSemaphore (mSmmMpSyncData->CpuData[Index].Run); … … 171 171 CpuData = mSmmMpSyncData->CpuData; 172 172 ProcessorInfo = gSmmCpuPrivate->ProcessorInfo; 173 for (Index = mMaxNumberOfCpus; Index-- > 0;) {173 for (Index = 0; Index < mMaxNumberOfCpus; Index++) { 174 174 if (!(*(CpuData[Index].Present)) && ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) { 175 175 if (((Exceptions & ARRIVAL_EXCEPTION_DELAYED) != 0) && SmmCpuFeaturesGetSmmRegister (Index, SmmRegSmmDelayed) != 0) { … … 306 306 // Send SMI IPIs to bring outside processors in 307 307 // 308 for (Index = mMaxNumberOfCpus; Index-- > 0;) {308 for (Index = 0; Index < mMaxNumberOfCpus; Index++) { 309 309 if (!(*(mSmmMpSyncData->CpuData[Index].Present)) && gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) { 310 310 SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId); … … 362 362 UINTN Index; 363 363 364 for (Index = mMaxNumberOfCpus; Index-- > 0;) {364 for (Index = 0; Index < mMaxNumberOfCpus; Index++) { 365 365 // 366 366 // Ignore BSP and APs which not call in SMM. … … 404 404 405 405 /** 406 Check whether execute in single AP or all APs.407 408 Compare two Tokens used by different APs to know whether in StartAllAps call.409 410 Whether is an valid AP base on AP's Present flag.411 412 @retval TRUE IN StartAllAps call.413 @retval FALSE Not in StartAllAps call.414 415 **/416 BOOLEAN417 InStartAllApsCall (418 VOID419 )420 {421 UINTN ApIndex;422 UINTN ApIndex2;423 424 for (ApIndex = mMaxNumberOfCpus; ApIndex-- > 0;) {425 if (IsPresentAp (ApIndex) && (mSmmMpSyncData->CpuData[ApIndex].Token != NULL)) {426 for (ApIndex2 = ApIndex; ApIndex2-- > 0;) {427 if (IsPresentAp (ApIndex2) && (mSmmMpSyncData->CpuData[ApIndex2].Token != NULL)) {428 return mSmmMpSyncData->CpuData[ApIndex2].Token == mSmmMpSyncData->CpuData[ApIndex].Token;429 }430 }431 }432 }433 434 return FALSE;435 }436 437 /**438 406 Clean up the status flags used during executing the procedure. 439 407 … … 446 414 ) 447 415 { 448 UINTN Index; 449 BOOLEAN Released; 450 451 if (InStartAllApsCall ()) { 452 // 453 // In Start All APs mode, make sure all APs have finished task. 454 // 455 if (WaitForAllAPsNotBusy (FALSE)) { 456 // 457 // Clean the flags update in the function call. 458 // 459 Released = FALSE; 460 for (Index = mMaxNumberOfCpus; Index-- > 0;) { 461 // 462 // Only In SMM APs need to be clean up. 463 // 464 if (mSmmMpSyncData->CpuData[Index].Present && mSmmMpSyncData->CpuData[Index].Token != NULL) { 465 if (!Released) { 466 ReleaseSpinLock (mSmmMpSyncData->CpuData[Index].Token); 467 Released = TRUE; 468 } 469 mSmmMpSyncData->CpuData[Index].Token = NULL; 470 } 471 } 472 } 473 } else { 474 // 475 // In single AP mode. 476 // 477 if (mSmmMpSyncData->CpuData[CpuIndex].Token != NULL) { 478 ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Token); 479 mSmmMpSyncData->CpuData[CpuIndex].Token = NULL; 480 } 481 } 416 PROCEDURE_TOKEN *Token; 417 418 Token = mSmmMpSyncData->CpuData[CpuIndex].Token; 419 420 if (InterlockedDecrement (&Token->RunningApCount) == 0) { 421 ReleaseSpinLock (Token->SpinLock); 422 } 423 424 mSmmMpSyncData->CpuData[CpuIndex].Token = NULL; 482 425 } 483 426 … … 487 430 **/ 488 431 VOID 489 FreeTokens (432 ResetTokens ( 490 433 VOID 491 434 ) 492 435 { 493 LIST_ENTRY *Link; 494 PROCEDURE_TOKEN *ProcToken; 495 496 while (!IsListEmpty (&gSmmCpuPrivate->TokenList)) { 497 Link = GetFirstNode (&gSmmCpuPrivate->TokenList); 498 ProcToken = PROCEDURE_TOKEN_FROM_LINK (Link); 499 500 RemoveEntryList (&ProcToken->Link); 501 502 FreePool ((VOID *)ProcToken->ProcedureToken); 503 FreePool (ProcToken); 504 } 436 // 437 // Reset the FirstFreeToken to the beginning of token list upon exiting SMI. 438 // 439 gSmmCpuPrivate->FirstFreeToken = GetFirstNode (&gSmmCpuPrivate->TokenList); 505 440 } 506 441 … … 658 593 while (TRUE) { 659 594 PresentCount = 0; 660 for (Index = mMaxNumberOfCpus; Index-- > 0;) {595 for (Index = 0; Index < mMaxNumberOfCpus; Index++) { 661 596 if (*(mSmmMpSyncData->CpuData[Index].Present)) { 662 597 PresentCount ++; … … 726 661 727 662 // 728 // Cleanthe tokens buffer.729 // 730 FreeTokens ();663 // Reset the tokens buffer. 664 // 665 ResetTokens (); 731 666 732 667 // … … 896 831 } 897 832 833 if (mSmmMpSyncData->CpuData[CpuIndex].Token != NULL) { 834 ReleaseToken (CpuIndex); 835 } 836 898 837 // 899 838 // Release BUSY 900 839 // 901 840 ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); 902 903 ReleaseToken (CpuIndex);904 841 } 905 842 … … 1092 1029 1093 1030 Link = GetFirstNode (&gSmmCpuPrivate->TokenList); 1094 while (!IsNull (&gSmmCpuPrivate->TokenList, Link)) { 1031 // 1032 // Only search used tokens. 1033 // 1034 while (Link != gSmmCpuPrivate->FirstFreeToken) { 1095 1035 ProcToken = PROCEDURE_TOKEN_FROM_LINK (Link); 1096 1036 1097 if (ProcToken-> ProcedureToken== Token) {1037 if (ProcToken->SpinLock == Token) { 1098 1038 return TRUE; 1099 1039 } … … 1106 1046 1107 1047 /** 1108 create token and save it to the maintain list. 1109 1110 @retval return the spin lock used as token. 1111 1112 **/ 1113 SPIN_LOCK * 1114 CreateToken ( 1048 Allocate buffer for the SPIN_LOCK and PROCEDURE_TOKEN. 1049 1050 @return First token of the token buffer. 1051 **/ 1052 LIST_ENTRY * 1053 AllocateTokenBuffer ( 1115 1054 VOID 1116 1055 ) 1117 1056 { 1118 PROCEDURE_TOKEN *ProcToken;1119 SPIN_LOCK *CpuToken;1120 1057 UINTN SpinLockSize; 1058 UINT32 TokenCountPerChunk; 1059 UINTN Index; 1060 SPIN_LOCK *SpinLock; 1061 UINT8 *SpinLockBuffer; 1062 PROCEDURE_TOKEN *ProcTokens; 1121 1063 1122 1064 SpinLockSize = GetSpinLockProperties (); 1123 CpuToken = AllocatePool (SpinLockSize); 1124 ASSERT (CpuToken != NULL); 1125 InitializeSpinLock (CpuToken); 1126 AcquireSpinLock (CpuToken); 1127 1128 ProcToken = AllocatePool (sizeof (PROCEDURE_TOKEN)); 1129 ASSERT (ProcToken != NULL); 1130 ProcToken->Signature = PROCEDURE_TOKEN_SIGNATURE; 1131 ProcToken->ProcedureToken = CpuToken; 1132 1133 InsertTailList (&gSmmCpuPrivate->TokenList, &ProcToken->Link); 1134 1135 return CpuToken; 1065 1066 TokenCountPerChunk = FixedPcdGet32 (PcdCpuSmmMpTokenCountPerChunk); 1067 ASSERT (TokenCountPerChunk != 0); 1068 if (TokenCountPerChunk == 0) { 1069 DEBUG ((DEBUG_ERROR, "PcdCpuSmmMpTokenCountPerChunk should not be Zero!\n")); 1070 CpuDeadLoop (); 1071 } 1072 DEBUG ((DEBUG_INFO, "CpuSmm: SpinLock Size = 0x%x, PcdCpuSmmMpTokenCountPerChunk = 0x%x\n", SpinLockSize, TokenCountPerChunk)); 1073 1074 // 1075 // Separate the Spin_lock and Proc_token because the alignment requires by Spin_Lock. 1076 // 1077 SpinLockBuffer = AllocatePool (SpinLockSize * TokenCountPerChunk); 1078 ASSERT (SpinLockBuffer != NULL); 1079 1080 ProcTokens = AllocatePool (sizeof (PROCEDURE_TOKEN) * TokenCountPerChunk); 1081 ASSERT (ProcTokens != NULL); 1082 1083 for (Index = 0; Index < TokenCountPerChunk; Index++) { 1084 SpinLock = (SPIN_LOCK *)(SpinLockBuffer + SpinLockSize * Index); 1085 InitializeSpinLock (SpinLock); 1086 1087 ProcTokens[Index].Signature = PROCEDURE_TOKEN_SIGNATURE; 1088 ProcTokens[Index].SpinLock = SpinLock; 1089 ProcTokens[Index].RunningApCount = 0; 1090 1091 InsertTailList (&gSmmCpuPrivate->TokenList, &ProcTokens[Index].Link); 1092 } 1093 1094 return &ProcTokens[0].Link; 1095 } 1096 1097 /** 1098 Get the free token. 1099 1100 If no free token, allocate new tokens then return the free one. 1101 1102 @param RunningApsCount The Running Aps count for this token. 1103 1104 @retval return the first free PROCEDURE_TOKEN. 1105 1106 **/ 1107 PROCEDURE_TOKEN * 1108 GetFreeToken ( 1109 IN UINT32 RunningApsCount 1110 ) 1111 { 1112 PROCEDURE_TOKEN *NewToken; 1113 1114 // 1115 // If FirstFreeToken meets the end of token list, enlarge the token list. 1116 // Set FirstFreeToken to the first free token. 1117 // 1118 if (gSmmCpuPrivate->FirstFreeToken == &gSmmCpuPrivate->TokenList) { 1119 gSmmCpuPrivate->FirstFreeToken = AllocateTokenBuffer (); 1120 } 1121 NewToken = PROCEDURE_TOKEN_FROM_LINK (gSmmCpuPrivate->FirstFreeToken); 1122 gSmmCpuPrivate->FirstFreeToken = GetNextNode (&gSmmCpuPrivate->TokenList, gSmmCpuPrivate->FirstFreeToken); 1123 1124 NewToken->RunningApCount = RunningApsCount; 1125 AcquireSpinLock (NewToken->SpinLock); 1126 1127 return NewToken; 1136 1128 } 1137 1129 … … 1206 1198 ) 1207 1199 { 1200 PROCEDURE_TOKEN *ProcToken; 1201 1208 1202 if (CpuIndex >= gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus) { 1209 1203 DEBUG((DEBUG_ERROR, "CpuIndex(%d) >= gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus(%d)\n", CpuIndex, gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus)); … … 1236 1230 } 1237 1231 1238 if (Token == NULL) { 1239 AcquireSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); 1240 } else { 1241 if (!AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[CpuIndex].Busy)) { 1242 DEBUG((DEBUG_ERROR, "Can't acquire mSmmMpSyncData->CpuData[%d].Busy\n", CpuIndex)); 1243 return EFI_NOT_READY; 1244 } 1245 1246 *Token = (MM_COMPLETION) CreateToken (); 1247 } 1232 AcquireSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); 1248 1233 1249 1234 mSmmMpSyncData->CpuData[CpuIndex].Procedure = Procedure; 1250 1235 mSmmMpSyncData->CpuData[CpuIndex].Parameter = ProcArguments; 1251 1236 if (Token != NULL) { 1252 mSmmMpSyncData->CpuData[CpuIndex].Token = (SPIN_LOCK *)(*Token); 1237 ProcToken= GetFreeToken (1); 1238 mSmmMpSyncData->CpuData[CpuIndex].Token = ProcToken; 1239 *Token = (MM_COMPLETION)ProcToken->SpinLock; 1253 1240 } 1254 1241 mSmmMpSyncData->CpuData[CpuIndex].Status = CpuStatus; … … 1308 1295 UINTN Index; 1309 1296 UINTN CpuCount; 1297 PROCEDURE_TOKEN *ProcToken; 1310 1298 1311 1299 if ((TimeoutInMicroseconds != 0) && ((mSmmMp.Attributes & EFI_MM_MP_TIMEOUT_SUPPORTED) == 0)) { … … 1317 1305 1318 1306 CpuCount = 0; 1319 for (Index = mMaxNumberOfCpus; Index-- > 0;) {1307 for (Index = 0; Index < mMaxNumberOfCpus; Index++) { 1320 1308 if (IsPresentAp (Index)) { 1321 1309 CpuCount ++; … … 1336 1324 1337 1325 if (Token != NULL) { 1338 *Token = (MM_COMPLETION) CreateToken (); 1326 ProcToken = GetFreeToken ((UINT32)mMaxNumberOfCpus); 1327 *Token = (MM_COMPLETION)ProcToken->SpinLock; 1328 } else { 1329 ProcToken = NULL; 1339 1330 } 1340 1331 … … 1346 1337 // block mode. 1347 1338 // 1348 for (Index = mMaxNumberOfCpus; Index-- > 0;) {1339 for (Index = 0; Index < mMaxNumberOfCpus; Index++) { 1349 1340 if (IsPresentAp (Index)) { 1350 1341 AcquireSpinLock (mSmmMpSyncData->CpuData[Index].Busy); … … 1352 1343 } 1353 1344 1354 for (Index = mMaxNumberOfCpus; Index-- > 0;) {1345 for (Index = 0; Index < mMaxNumberOfCpus; Index++) { 1355 1346 if (IsPresentAp (Index)) { 1356 1347 mSmmMpSyncData->CpuData[Index].Procedure = (EFI_AP_PROCEDURE2) Procedure; 1357 1348 mSmmMpSyncData->CpuData[Index].Parameter = ProcedureArguments; 1358 if ( Token != NULL) {1359 mSmmMpSyncData->CpuData[Index].Token = (SPIN_LOCK *)(*Token);1349 if (ProcToken != NULL) { 1350 mSmmMpSyncData->CpuData[Index].Token = ProcToken; 1360 1351 } 1361 1352 if (CPUStatus != NULL) { … … 1372 1363 if (CPUStatus != NULL) { 1373 1364 CPUStatus[Index] = EFI_NOT_STARTED; 1365 } 1366 1367 // 1368 // Decrease the count to mark this processor(AP or BSP) as finished. 1369 // 1370 if (ProcToken != NULL) { 1371 WaitForSemaphore (&ProcToken->RunningApCount); 1374 1372 } 1375 1373 } … … 1742 1740 1743 1741 InitializeListHead (&gSmmCpuPrivate->TokenList); 1742 1743 gSmmCpuPrivate->FirstFreeToken = AllocateTokenBuffer (); 1744 1744 } 1745 1745 -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
r80721 r85718 216 216 @retval EFI_SUCCESS The register was read from Save State 217 217 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor 218 @retval EFI_INVALID_PARAM TER This or Buffer is NULL.218 @retval EFI_INVALID_PARAMETER This or Buffer is NULL. 219 219 220 220 **/ … … 288 288 @retval EFI_SUCCESS The register was written from Save State 289 289 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor 290 @retval EFI_INVALID_PARAM TER ProcessorIndex or Width is not correct290 @retval EFI_INVALID_PARAMETER ProcessorIndex or Width is not correct 291 291 292 292 **/ … … 1432 1432 SetMemMapAttributes (); 1433 1433 1434 // 1435 // For outside SMRAM, we only map SMM communication buffer or MMIO. 1436 // 1437 SetUefiMemMapAttributes (); 1438 1439 // 1440 // Set page table itself to be read-only 1441 // 1442 SetPageTableAttributes (); 1434 if (IsRestrictedMemoryAccess ()) { 1435 // 1436 // For outside SMRAM, we only map SMM communication buffer or MMIO. 1437 // 1438 SetUefiMemMapAttributes (); 1439 1440 // 1441 // Set page table itself to be read-only 1442 // 1443 SetPageTableAttributes (); 1444 } 1443 1445 1444 1446 // -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
r80721 r85718 2 2 Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU. 3 3 4 Copyright (c) 2009 - 20 19, Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR> 5 5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> 6 6 … … 213 213 LIST_ENTRY Link; 214 214 215 SPIN_LOCK *ProcedureToken; 215 SPIN_LOCK *SpinLock; 216 volatile UINT32 RunningApCount; 216 217 } PROCEDURE_TOKEN; 217 218 218 219 #define PROCEDURE_TOKEN_FROM_LINK(a) CR (a, PROCEDURE_TOKEN, Link, PROCEDURE_TOKEN_SIGNATURE) 220 221 #define TOKEN_BUFFER_SIGNATURE SIGNATURE_32 ('T', 'K', 'B', 'S') 222 223 typedef struct { 224 UINTN Signature; 225 LIST_ENTRY Link; 226 227 UINT8 *Buffer; 228 } TOKEN_BUFFER; 229 230 #define TOKEN_BUFFER_FROM_LINK(a) CR (a, TOKEN_BUFFER, Link, TOKEN_BUFFER_SIGNATURE) 219 231 220 232 // … … 243 255 PROCEDURE_WRAPPER *ApWrapperFunc; 244 256 LIST_ENTRY TokenList; 245 257 LIST_ENTRY *FirstFreeToken; 246 258 } SMM_CPU_PRIVATE_DATA; 247 259 … … 273 285 @retval EFI_SUCCESS The register was read from Save State 274 286 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor 275 @retval EFI_INVALID_PARAM TER This or Buffer is NULL.287 @retval EFI_INVALID_PARAMETER This or Buffer is NULL. 276 288 277 289 **/ … … 297 309 @retval EFI_SUCCESS The register was written from Save State 298 310 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor 299 @retval EFI_INVALID_PARAM TER ProcessorIndex or Width is not correct311 @retval EFI_INVALID_PARAMETER ProcessorIndex or Width is not correct 300 312 301 313 **/ … … 325 337 @retval EFI_SUCCESS The register was read from Save State. 326 338 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor. 327 @retval EFI_INVALID_PARAM TER This or Buffer is NULL.339 @retval EFI_INVALID_PARAMETER This or Buffer is NULL. 328 340 329 341 **/ … … 352 364 @retval EFI_SUCCESS The register was written to Save State. 353 365 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor. 354 @retval EFI_INVALID_PARAM TER ProcessorIndex or Width is not correct.366 @retval EFI_INVALID_PARAMETER ProcessorIndex or Width is not correct. 355 367 356 368 **/ … … 393 405 volatile UINT32 *Run; 394 406 volatile BOOLEAN *Present; 395 SPIN_LOCK*Token;407 PROCEDURE_TOKEN *Token; 396 408 EFI_STATUS *Status; 397 409 } SMM_CPU_DATA_BLOCK; … … 1252 1264 /** 1253 1265 This function fixes up the address of the global variable or function 1254 referred in SmmInit assembly files to be the abso ute address.1266 referred in SmmInit assembly files to be the absolute address. 1255 1267 **/ 1256 1268 VOID … … 1261 1273 /** 1262 1274 This function fixes up the address of the global variable or function 1263 referred in SmiEntry assembly files to be the abso ute address.1275 referred in SmiEntry assembly files to be the absolute address. 1264 1276 **/ 1265 1277 VOID … … 1451 1463 ); 1452 1464 1465 /** 1466 Return whether access to non-SMRAM is restricted. 1467 1468 @retval TRUE Access to non-SMRAM is restricted. 1469 @retval FALSE Access to non-SMRAM is not restricted. 1470 **/ 1471 BOOLEAN 1472 IsRestrictedMemoryAccess ( 1473 VOID 1474 ); 1475 1453 1476 #endif -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
r80721 r85718 134 134 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmCodeAccessCheckEnable ## CONSUMES 135 135 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode ## CONSUMES 136 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStaticPageTable ## CONSUMES137 136 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmShadowStackSize ## SOMETIMES_CONSUMES 138 137 gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable ## CONSUMES … … 142 141 gEfiMdePkgTokenSpaceGuid.PcdControlFlowEnforcementPropertyMask ## CONSUMES 143 142 143 [FixedPcd] 144 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmMpTokenCountPerChunk ## CONSUMES 145 146 [Pcd.X64] 147 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmRestrictedMemoryAccess ## CONSUMES 148 144 149 [Depex] 145 150 gEfiMpServiceProtocolGuid -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
r80721 r85718 466 466 467 467 // 468 // Below logic is to check 2M/4K page to make sure we do not waistmemory.468 // Below logic is to check 2M/4K page to make sure we do not waste memory. 469 469 // 470 470 while (Length != 0) { … … 1066 1066 1067 1067 /** 1068 Merge contin ous memory map entries whose type is1068 Merge continuous memory map entries whose type is 1069 1069 EfiLoaderCode/Data, EfiBootServicesCode/Data, EfiConventionalMemory, 1070 1070 EfiUnusableMemory, EfiACPIReclaimMemory, because the memory described by -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
r80721 r85718 658 658 ASSERT (Pt != NULL); 659 659 660 *Pd = (UINTN) Pt | IA32_PG_RW | IA32_PG_P;661 662 660 // Split it 663 for (PtIndex = 0; PtIndex < SIZE_4KB / sizeof(*Pt); PtIndex++ , Pt++) {664 *Pt= Address + ((PtIndex << 12) | mAddressEncMask | PAGE_ATTRIBUTE_BITS);661 for (PtIndex = 0; PtIndex < SIZE_4KB / sizeof(*Pt); PtIndex++) { 662 Pt[PtIndex] = Address + ((PtIndex << 12) | mAddressEncMask | PAGE_ATTRIBUTE_BITS); 665 663 } // end for PT 666 664 *Pd = (UINT64)(UINTN)Pt | mAddressEncMask | PAGE_ATTRIBUTE_BITS; -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
r80721 r85718 261 261 @retval EFI_SUCCESS The register was read from Save State. 262 262 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor. 263 @retval EFI_INVALID_PARAM TER This or Buffer is NULL.263 @retval EFI_INVALID_PARAMETER This or Buffer is NULL. 264 264 265 265 **/ … … 344 344 @retval EFI_SUCCESS The register was read from Save State. 345 345 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor. 346 @retval EFI_INVALID_PARAM TER This or Buffer is NULL.346 @retval EFI_INVALID_PARAMETER This or Buffer is NULL. 347 347 348 348 **/ … … 456 456 @retval EFI_SUCCESS The register was written to Save State. 457 457 @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor. 458 @retval EFI_INVALID_PARAM TER ProcessorIndex or Width is not correct.458 @retval EFI_INVALID_PARAMETER ProcessorIndex or Width is not correct. 459 459 460 460 **/ -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
r80721 r85718 16 16 LIST_ENTRY mPagePool = INITIALIZE_LIST_HEAD_VARIABLE (mPagePool); 17 17 BOOLEAN m1GPageTableSupport = FALSE; 18 BOOLEAN mCpuSmm StaticPageTable;19 BOOLEAN m5LevelPaging Support;20 X86_ASSEMBLY_PATCH_LABEL gPatch5LevelPaging Support;18 BOOLEAN mCpuSmmRestrictedMemoryAccess; 19 BOOLEAN m5LevelPagingNeeded; 20 X86_ASSEMBLY_PATCH_LABEL gPatch5LevelPagingNeeded; 21 21 22 22 /** … … 64 64 65 65 /** 66 Check if 5-level paging is supported by processor or not. 67 68 @retval TRUE 5-level paging is supported. 69 @retval FALSE 5-level paging is not supported. 70 66 The routine returns TRUE when CPU supports it (CPUID[7,0].ECX.BIT[16] is set) and 67 the max physical address bits is bigger than 48. Because 4-level paging can support 68 to address physical address up to 2^48 - 1, there is no need to enable 5-level paging 69 with max physical address bits <= 48. 70 71 @retval TRUE 5-level paging enabling is needed. 72 @retval FALSE 5-level paging enabling is not needed. 71 73 **/ 72 74 BOOLEAN 73 Is5LevelPaging Support(75 Is5LevelPagingNeeded ( 74 76 VOID 75 77 ) 76 78 { 77 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_ECX EcxFlags; 78 79 CPUID_VIR_PHY_ADDRESS_SIZE_EAX VirPhyAddressSize; 80 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_ECX ExtFeatureEcx; 81 UINT32 MaxExtendedFunctionId; 82 83 AsmCpuid (CPUID_EXTENDED_FUNCTION, &MaxExtendedFunctionId, NULL, NULL, NULL); 84 if (MaxExtendedFunctionId >= CPUID_VIR_PHY_ADDRESS_SIZE) { 85 AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE, &VirPhyAddressSize.Uint32, NULL, NULL, NULL); 86 } else { 87 VirPhyAddressSize.Bits.PhysicalAddressBits = 36; 88 } 79 89 AsmCpuidEx ( 80 90 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS, 81 91 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_SUB_LEAF_INFO, 82 NULL, 83 NULL, 84 &EcxFlags.Uint32, 85 NULL 92 NULL, NULL, &ExtFeatureEcx.Uint32, NULL 86 93 ); 87 return (BOOLEAN) (EcxFlags.Bits.FiveLevelPage != 0); 94 DEBUG (( 95 DEBUG_INFO, "PhysicalAddressBits = %d, 5LPageTable = %d.\n", 96 VirPhyAddressSize.Bits.PhysicalAddressBits, ExtFeatureEcx.Bits.FiveLevelPage 97 )); 98 99 if (VirPhyAddressSize.Bits.PhysicalAddressBits > 4 * 9 + 12) { 100 ASSERT (ExtFeatureEcx.Bits.FiveLevelPage == 1); 101 return TRUE; 102 } else { 103 return FALSE; 104 } 88 105 } 89 106 … … 191 208 // 192 209 ASSERT (mPhysicalAddressBits <= 52); 193 if (!m5LevelPaging Support&& mPhysicalAddressBits > 48) {210 if (!m5LevelPagingNeeded && mPhysicalAddressBits > 48) { 194 211 mPhysicalAddressBits = 48; 195 212 } … … 218 235 PageMapLevel4Entry = PageMap; 219 236 PageMapLevel5Entry = NULL; 220 if (m5LevelPaging Support) {237 if (m5LevelPagingNeeded) { 221 238 // 222 239 // By architecture only one PageMapLevel5 exists - so lets allocate storage for it. … … 234 251 // When 5-Level Paging is disabled, below allocation happens only once. 235 252 // 236 if (m5LevelPaging Support) {253 if (m5LevelPagingNeeded) { 237 254 PageMapLevel4Entry = (UINT64 *) ((*PageMapLevel5Entry) & ~mAddressEncMask & gPhyMask); 238 255 if (PageMapLevel4Entry == NULL) { … … 335 352 InitializeSpinLock (mPFLock); 336 353 337 mCpuSmm StaticPageTable = PcdGetBool (PcdCpuSmmStaticPageTable);338 m1GPageTableSupport = Is1GPageSupport ();339 m5LevelPaging Support = Is5LevelPagingSupport();340 mPhysicalAddressBits = CalculateMaximumSupportAddress ();341 PatchInstructionX86 (gPatch5LevelPaging Support, m5LevelPagingSupport, 1);342 DEBUG ((DEBUG_INFO, "5LevelPaging Support - %d\n", m5LevelPagingSupport));343 DEBUG ((DEBUG_INFO, "1GPageTable Support - %d\n", m1GPageTableSupport));344 DEBUG ((DEBUG_INFO, "PcdCpuSmm StaticPageTable - %d\n", mCpuSmmStaticPageTable));345 DEBUG ((DEBUG_INFO, "PhysicalAddressBits - %d\n", mPhysicalAddressBits));354 mCpuSmmRestrictedMemoryAccess = PcdGetBool (PcdCpuSmmRestrictedMemoryAccess); 355 m1GPageTableSupport = Is1GPageSupport (); 356 m5LevelPagingNeeded = Is5LevelPagingNeeded (); 357 mPhysicalAddressBits = CalculateMaximumSupportAddress (); 358 PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded, 1); 359 DEBUG ((DEBUG_INFO, "5LevelPaging Needed - %d\n", m5LevelPagingNeeded)); 360 DEBUG ((DEBUG_INFO, "1GPageTable Support - %d\n", m1GPageTableSupport)); 361 DEBUG ((DEBUG_INFO, "PcdCpuSmmRestrictedMemoryAccess - %d\n", mCpuSmmRestrictedMemoryAccess)); 362 DEBUG ((DEBUG_INFO, "PhysicalAddressBits - %d\n", mPhysicalAddressBits)); 346 363 // 347 364 // Generate PAE page table for the first 4GB memory space … … 371 388 PTEntry = Pml4Entry; 372 389 373 if (m5LevelPaging Support) {390 if (m5LevelPagingNeeded) { 374 391 // 375 392 // Fill PML5 entry … … 386 403 } 387 404 388 if (mCpuSmmStaticPageTable) { 405 if (mCpuSmmRestrictedMemoryAccess) { 406 // 407 // When access to non-SMRAM memory is restricted, create page table 408 // that covers all memory space. 409 // 389 410 SetStaticPageTable ((UINTN)PTEntry); 390 411 } else { … … 973 994 PFAddress = AsmReadCr2 (); 974 995 975 if (mCpuSmm StaticPageTable&& (PFAddress >= LShiftU64 (1, (mPhysicalAddressBits - 1)))) {996 if (mCpuSmmRestrictedMemoryAccess && (PFAddress >= LShiftU64 (1, (mPhysicalAddressBits - 1)))) { 976 997 DumpCpuContext (InterruptType, SystemContext); 977 998 DEBUG ((DEBUG_ERROR, "Do not support address 0x%lx by processor!\n", PFAddress)); … … 1050 1071 } 1051 1072 1052 if (mCpuSmm StaticPageTable&& IsSmmCommBufferForbiddenAddress (PFAddress)) {1073 if (mCpuSmmRestrictedMemoryAccess && IsSmmCommBufferForbiddenAddress (PFAddress)) { 1053 1074 DumpCpuContext (InterruptType, SystemContext); 1054 1075 DEBUG ((DEBUG_ERROR, "Access SMM communication forbidden address (0x%lx)!\n", PFAddress)); … … 1101 1122 1102 1123 // 1103 // Don't do thisif1104 // - no static page table; or1124 // Don't mark page table memory as read-only if 1125 // - no restriction on access to non-SMRAM memory; or 1105 1126 // - SMM heap guard feature enabled; or 1106 1127 // BIT2: SMM page guard enabled … … 1108 1129 // - SMM profile feature enabled 1109 1130 // 1110 if (!mCpuSmm StaticPageTable||1131 if (!mCpuSmmRestrictedMemoryAccess || 1111 1132 ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0) || 1112 1133 FeaturePcdGet (PcdCpuSmmProfileEnable)) { 1113 1134 // 1114 // Static pagingand heap guard could not be enabled at the same time.1115 // 1116 ASSERT (!(mCpuSmm StaticPageTable&&1135 // Restriction on access to non-SMRAM memory and heap guard could not be enabled at the same time. 1136 // 1137 ASSERT (!(mCpuSmmRestrictedMemoryAccess && 1117 1138 (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0)); 1118 1139 1119 1140 // 1120 // Static pagingand SMM profile could not be enabled at the same time.1121 // 1122 ASSERT (!(mCpuSmm StaticPageTable&& FeaturePcdGet (PcdCpuSmmProfileEnable)));1141 // Restriction on access to non-SMRAM memory and SMM profile could not be enabled at the same time. 1142 // 1143 ASSERT (!(mCpuSmmRestrictedMemoryAccess && FeaturePcdGet (PcdCpuSmmProfileEnable))); 1123 1144 return ; 1124 1145 } … … 1224 1245 ) 1225 1246 { 1226 if (!mCpuSmmStaticPageTable) { 1247 if (!mCpuSmmRestrictedMemoryAccess) { 1248 // 1249 // On-demand paging is enabled when access to non-SMRAM is not restricted. 1250 // 1227 1251 *Cr2 = AsmReadCr2 (); 1228 1252 } … … 1239 1263 ) 1240 1264 { 1241 if (!mCpuSmmStaticPageTable) { 1265 if (!mCpuSmmRestrictedMemoryAccess) { 1266 // 1267 // On-demand paging is enabled when access to non-SMRAM is not restricted. 1268 // 1242 1269 AsmWriteCr2 (Cr2); 1243 1270 } 1244 1271 } 1272 1273 /** 1274 Return whether access to non-SMRAM is restricted. 1275 1276 @retval TRUE Access to non-SMRAM is restricted. 1277 @retval FALSE Access to non-SMRAM is not restricted. 1278 **/ 1279 BOOLEAN 1280 IsRestrictedMemoryAccess ( 1281 VOID 1282 ) 1283 { 1284 return mCpuSmmRestrictedMemoryAccess; 1285 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c
r80721 r85718 59 59 60 60 // 61 // Use temp value to fix ICC comp lier warning61 // Use temp value to fix ICC compiler warning 62 62 // 63 63 TempValue = (UINTN)&mSmmRelocationOriginalAddress; -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm
r80721 r85718 17 17 18 18 ; 19 ; Variables refer renced by C code19 ; Variables referenced by C code 20 20 ; 21 21 … … 70 70 global ASM_PFX(gPatchSmiStack) 71 71 global ASM_PFX(gPatchSmiCr3) 72 global ASM_PFX(gPatch5LevelPaging Support)72 global ASM_PFX(gPatch5LevelPagingNeeded) 73 73 global ASM_PFX(gcSmiHandlerTemplate) 74 74 global ASM_PFX(gcSmiHandlerSize) … … 128 128 129 129 mov cl, strict byte 0 ; source operand will be patched 130 ASM_PFX(gPatch5LevelPaging Support):130 ASM_PFX(gPatch5LevelPagingNeeded): 131 131 cmp cl, 0 132 132 je SkipEnable5LevelPaging -
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm
r80721 r85718 73 73 and sp, 0xfff0 ; make sure RSP is 16-byte aligned 74 74 ; 75 ; Accor ing to X64 calling convention, XMM0~5 are volatile, we need to save75 ; According to X64 calling convention, XMM0~5 are volatile, we need to save 76 76 ; them before calling C-function. 77 77 ;
Note:
See TracChangeset
for help on using the changeset viewer.