Changeset 77662 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
- Timestamp:
- Mar 12, 2019 12:40:12 PM (6 years ago)
- 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 /vendor/edk2/current 103735-103757,103769-103776,129194-129237
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
r58466 r77662 1 1 /** @file 2 2 3 Copyright (c) 2010 , Intel Corporation. All rights reserved.<BR>3 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR> 4 4 5 5 This program and the accompanying materials … … 21 21 #include <Library/LockBoxLib.h> 22 22 #include <Library/DebugLib.h> 23 #include <Library/UefiLib.h> 23 24 #include <Protocol/SmmCommunication.h> 24 25 #include <Guid/SmmLockBox.h> 26 #include <Guid/PiSmmCommunicationRegionTable.h> 25 27 26 28 #include "SmmLockBoxLibPrivate.h" 29 30 EFI_SMM_COMMUNICATION_PROTOCOL *mLockBoxSmmCommProtocol = NULL; 31 UINT8 *mLockBoxSmmCommBuffer = NULL; 32 33 /** 34 Get smm communication protocol for lockbox. 35 36 @return Pointer to smm communication protocol, NULL if not found. 37 38 **/ 39 EFI_SMM_COMMUNICATION_PROTOCOL * 40 LockBoxGetSmmCommProtocol ( 41 VOID 42 ) 43 { 44 EFI_STATUS Status; 45 46 // 47 // If the protocol has been got previously, return it. 48 // 49 if (mLockBoxSmmCommProtocol != NULL) { 50 return mLockBoxSmmCommProtocol; 51 } 52 53 Status = gBS->LocateProtocol ( 54 &gEfiSmmCommunicationProtocolGuid, 55 NULL, 56 (VOID **)&mLockBoxSmmCommProtocol 57 ); 58 if (EFI_ERROR (Status)) { 59 mLockBoxSmmCommProtocol = NULL; 60 } 61 return mLockBoxSmmCommProtocol; 62 } 63 64 /** 65 Get smm communication buffer for lockbox. 66 67 @return Pointer to smm communication buffer, NULL if not found. 68 69 **/ 70 UINT8 * 71 LockBoxGetSmmCommBuffer ( 72 VOID 73 ) 74 { 75 EFI_STATUS Status; 76 UINTN MinimalSizeNeeded; 77 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable; 78 UINT32 Index; 79 EFI_MEMORY_DESCRIPTOR *Entry; 80 UINTN Size; 81 82 // 83 // If the buffer has been got previously, return it. 84 // 85 if (mLockBoxSmmCommBuffer != NULL) { 86 return mLockBoxSmmCommBuffer; 87 } 88 89 MinimalSizeNeeded = sizeof (EFI_GUID) + 90 sizeof (UINTN) + 91 MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE), 92 MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES), 93 MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE), 94 MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE), 95 sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE))))); 96 97 Status = EfiGetSystemConfigurationTable ( 98 &gEdkiiPiSmmCommunicationRegionTableGuid, 99 (VOID **) &PiSmmCommunicationRegionTable 100 ); 101 if (EFI_ERROR (Status)) { 102 mLockBoxSmmCommBuffer = NULL; 103 return mLockBoxSmmCommBuffer; 104 } 105 ASSERT (PiSmmCommunicationRegionTable != NULL); 106 Entry = (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + 1); 107 Size = 0; 108 for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) { 109 if (Entry->Type == EfiConventionalMemory) { 110 Size = EFI_PAGES_TO_SIZE ((UINTN) Entry->NumberOfPages); 111 if (Size >= MinimalSizeNeeded) { 112 break; 113 } 114 } 115 Entry = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + PiSmmCommunicationRegionTable->DescriptorSize); 116 } 117 if (Index >= PiSmmCommunicationRegionTable->NumberOfEntries) { 118 mLockBoxSmmCommBuffer = NULL; 119 } else { 120 mLockBoxSmmCommBuffer = (UINT8 *) (UINTN) Entry->PhysicalStart; 121 } 122 return mLockBoxSmmCommBuffer; 123 } 27 124 28 125 /** … … 53 150 EFI_SMM_LOCK_BOX_PARAMETER_SAVE *LockBoxParameterSave; 54 151 EFI_SMM_COMMUNICATE_HEADER *CommHeader; 55 UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)]; 152 UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)]; 153 UINT8 *CommBuffer; 56 154 UINTN CommSize; 57 155 … … 65 163 } 66 164 67 // 68 // Get needed resource 69 // 70 Status = gBS->LocateProtocol ( 71 &gEfiSmmCommunicationProtocolGuid, 72 NULL, 73 (VOID **)&SmmCommunication 74 ); 75 if (EFI_ERROR (Status)) { 165 SmmCommunication = LockBoxGetSmmCommProtocol (); 166 if (SmmCommunication == NULL) { 76 167 return EFI_NOT_STARTED; 77 168 } … … 80 171 // Prepare parameter 81 172 // 173 CommBuffer = LockBoxGetSmmCommBuffer (); 174 if (CommBuffer == NULL) { 175 CommBuffer = &TempCommBuffer[0]; 176 } 82 177 CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; 83 178 CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid)); … … 95 190 // Send command 96 191 // 97 CommSize = sizeof( CommBuffer);192 CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE); 98 193 Status = SmmCommunication->Communicate ( 99 194 SmmCommunication, … … 137 232 EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES *LockBoxParameterSetAttributes; 138 233 EFI_SMM_COMMUNICATE_HEADER *CommHeader; 139 UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)]; 234 UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)]; 235 UINT8 *CommBuffer; 140 236 UINTN CommSize; 141 237 … … 146 242 // 147 243 if ((Guid == NULL) || 148 ((Attributes & ~ LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0)) {244 ((Attributes & ~(LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE | LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY)) != 0)) { 149 245 return EFI_INVALID_PARAMETER; 150 246 } 151 247 152 // 153 // Get needed resource 154 // 155 Status = gBS->LocateProtocol ( 156 &gEfiSmmCommunicationProtocolGuid, 157 NULL, 158 (VOID **)&SmmCommunication 159 ); 160 if (EFI_ERROR (Status)) { 248 SmmCommunication = LockBoxGetSmmCommProtocol (); 249 if (SmmCommunication == NULL) { 161 250 return EFI_NOT_STARTED; 162 251 } … … 165 254 // Prepare parameter 166 255 // 256 CommBuffer = LockBoxGetSmmCommBuffer (); 257 if (CommBuffer == NULL) { 258 CommBuffer = &TempCommBuffer[0]; 259 } 167 260 CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; 168 261 CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid)); … … 179 272 // Send command 180 273 // 181 CommSize = sizeof( CommBuffer);274 CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES); 182 275 Status = SmmCommunication->Communicate ( 183 276 SmmCommunication, … … 226 319 EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *LockBoxParameterUpdate; 227 320 EFI_SMM_COMMUNICATE_HEADER *CommHeader; 228 UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)]; 321 UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)]; 322 UINT8 *CommBuffer; 229 323 UINTN CommSize; 230 324 … … 238 332 } 239 333 240 // 241 // Get needed resource 242 // 243 Status = gBS->LocateProtocol ( 244 &gEfiSmmCommunicationProtocolGuid, 245 NULL, 246 (VOID **)&SmmCommunication 247 ); 248 if (EFI_ERROR (Status)) { 334 SmmCommunication = LockBoxGetSmmCommProtocol (); 335 if (SmmCommunication == NULL) { 249 336 return EFI_NOT_STARTED; 250 337 } … … 253 340 // Prepare parameter 254 341 // 342 CommBuffer = LockBoxGetSmmCommBuffer (); 343 if (CommBuffer == NULL) { 344 CommBuffer = &TempCommBuffer[0]; 345 } 255 346 CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; 256 347 CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid)); … … 269 360 // Send command 270 361 // 271 CommSize = sizeof( CommBuffer);362 CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE); 272 363 Status = SmmCommunication->Communicate ( 273 364 SmmCommunication, … … 317 408 EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *LockBoxParameterRestore; 318 409 EFI_SMM_COMMUNICATE_HEADER *CommHeader; 319 UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)]; 410 UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)]; 411 UINT8 *CommBuffer; 320 412 UINTN CommSize; 321 413 … … 331 423 } 332 424 333 // 334 // Get needed resource 335 // 336 Status = gBS->LocateProtocol ( 337 &gEfiSmmCommunicationProtocolGuid, 338 NULL, 339 (VOID **)&SmmCommunication 340 ); 341 if (EFI_ERROR (Status)) { 425 SmmCommunication = LockBoxGetSmmCommProtocol (); 426 if (SmmCommunication == NULL) { 342 427 return EFI_NOT_STARTED; 343 428 } … … 346 431 // Prepare parameter 347 432 // 433 CommBuffer = LockBoxGetSmmCommBuffer (); 434 if (CommBuffer == NULL) { 435 CommBuffer = &TempCommBuffer[0]; 436 } 348 437 CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; 349 438 CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid)); … … 365 454 // Send command 366 455 // 367 CommSize = sizeof( CommBuffer);456 CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE); 368 457 Status = SmmCommunication->Communicate ( 369 458 SmmCommunication, … … 404 493 EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE *LockBoxParameterRestoreAllInPlace; 405 494 EFI_SMM_COMMUNICATE_HEADER *CommHeader; 406 UINT8 CommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)]; 495 UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)]; 496 UINT8 *CommBuffer; 407 497 UINTN CommSize; 408 498 409 499 DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Enter\n")); 410 500 411 // 412 // Get needed resource 413 // 414 Status = gBS->LocateProtocol ( 415 &gEfiSmmCommunicationProtocolGuid, 416 NULL, 417 (VOID **)&SmmCommunication 418 ); 419 if (EFI_ERROR (Status)) { 501 SmmCommunication = LockBoxGetSmmCommProtocol (); 502 if (SmmCommunication == NULL) { 420 503 return EFI_NOT_STARTED; 421 504 } … … 424 507 // Prepare parameter 425 508 // 509 CommBuffer = LockBoxGetSmmCommBuffer (); 510 if (CommBuffer == NULL) { 511 CommBuffer = &TempCommBuffer[0]; 512 } 426 513 CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; 427 514 CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid)); … … 436 523 // Send command 437 524 // 438 CommSize = sizeof( CommBuffer);525 CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE); 439 526 Status = SmmCommunication->Communicate ( 440 527 SmmCommunication,
Note:
See TracChangeset
for help on using the changeset viewer.