VirtualBox

Ignore:
Timestamp:
Mar 12, 2019 12:40:12 PM (6 years ago)
Author:
vboxsync
Message:

EFI: First step in UDK2018 merge. Does not build yet.

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c

    r58466 r77662  
    11/** @file
    22
    3 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
     3Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
    44
    55This program and the accompanying materials
     
    2121#include <Library/LockBoxLib.h>
    2222#include <Library/DebugLib.h>
     23#include <Library/UefiLib.h>
    2324#include <Protocol/SmmCommunication.h>
    2425#include <Guid/SmmLockBox.h>
     26#include <Guid/PiSmmCommunicationRegionTable.h>
    2527
    2628#include "SmmLockBoxLibPrivate.h"
     29
     30EFI_SMM_COMMUNICATION_PROTOCOL  *mLockBoxSmmCommProtocol = NULL;
     31UINT8                           *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**/
     39EFI_SMM_COMMUNICATION_PROTOCOL *
     40LockBoxGetSmmCommProtocol (
     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**/
     70UINT8 *
     71LockBoxGetSmmCommBuffer (
     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}
    27124
    28125/**
     
    53150  EFI_SMM_LOCK_BOX_PARAMETER_SAVE *LockBoxParameterSave;
    54151  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;
    56154  UINTN                           CommSize;
    57155
     
    65163  }
    66164
    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) {
    76167    return EFI_NOT_STARTED;
    77168  }
     
    80171  // Prepare parameter
    81172  //
     173  CommBuffer = LockBoxGetSmmCommBuffer ();
     174  if (CommBuffer == NULL) {
     175    CommBuffer = &TempCommBuffer[0];
     176  }
    82177  CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
    83178  CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
     
    95190  // Send command
    96191  //
    97   CommSize = sizeof(CommBuffer);
     192  CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE);
    98193  Status = SmmCommunication->Communicate (
    99194                               SmmCommunication,
     
    137232  EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES *LockBoxParameterSetAttributes;
    138233  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;
    140236  UINTN                                     CommSize;
    141237
     
    146242  //
    147243  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)) {
    149245    return EFI_INVALID_PARAMETER;
    150246  }
    151247
    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) {
    161250    return EFI_NOT_STARTED;
    162251  }
     
    165254  // Prepare parameter
    166255  //
     256  CommBuffer = LockBoxGetSmmCommBuffer ();
     257  if (CommBuffer == NULL) {
     258    CommBuffer = &TempCommBuffer[0];
     259  }
    167260  CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
    168261  CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
     
    179272  // Send command
    180273  //
    181   CommSize = sizeof(CommBuffer);
     274  CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES);
    182275  Status = SmmCommunication->Communicate (
    183276                               SmmCommunication,
     
    226319  EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *LockBoxParameterUpdate;
    227320  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;
    229323  UINTN                             CommSize;
    230324
     
    238332  }
    239333
    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) {
    249336    return EFI_NOT_STARTED;
    250337  }
     
    253340  // Prepare parameter
    254341  //
     342  CommBuffer = LockBoxGetSmmCommBuffer ();
     343  if (CommBuffer == NULL) {
     344    CommBuffer = &TempCommBuffer[0];
     345  }
    255346  CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
    256347  CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
     
    269360  // Send command
    270361  //
    271   CommSize = sizeof(CommBuffer);
     362  CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE);
    272363  Status = SmmCommunication->Communicate (
    273364                               SmmCommunication,
     
    317408  EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *LockBoxParameterRestore;
    318409  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;
    320412  UINTN                              CommSize;
    321413
     
    331423  }
    332424
    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) {
    342427    return EFI_NOT_STARTED;
    343428  }
     
    346431  // Prepare parameter
    347432  //
     433  CommBuffer = LockBoxGetSmmCommBuffer ();
     434  if (CommBuffer == NULL) {
     435    CommBuffer = &TempCommBuffer[0];
     436  }
    348437  CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
    349438  CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
     
    365454  // Send command
    366455  //
    367   CommSize = sizeof(CommBuffer);
     456  CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE);
    368457  Status = SmmCommunication->Communicate (
    369458                               SmmCommunication,
     
    404493  EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE *LockBoxParameterRestoreAllInPlace;
    405494  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;
    407497  UINTN                                           CommSize;
    408498
    409499  DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Enter\n"));
    410500
    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) {
    420503    return EFI_NOT_STARTED;
    421504  }
     
    424507  // Prepare parameter
    425508  //
     509  CommBuffer = LockBoxGetSmmCommBuffer ();
     510  if (CommBuffer == NULL) {
     511    CommBuffer = &TempCommBuffer[0];
     512  }
    426513  CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
    427514  CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
     
    436523  // Send command
    437524  //
    438   CommSize = sizeof(CommBuffer);
     525  CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE);
    439526  Status = SmmCommunication->Communicate (
    440527                               SmmCommunication,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette