VirtualBox

Ignore:
Timestamp:
Aug 14, 2024 1:16:30 PM (6 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
164367
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

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

Legend:

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

  • trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/SmmAccess/SmmAccess2Dxe.c

    r99404 r105670  
    77
    88  Copyright (C) 2013, 2015, Red Hat, Inc.<BR>
    9   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
     9  Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved.<BR>
    1010
    1111  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    116116{
    117117  return SmramAccessGetCapabilities (
    118            This->LockState,
    119            This->OpenState,
    120118           SmramMapSize,
    121119           SmramMap
  • trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/SmmAccess/SmmAccess2Dxe.inf

    r85718 r105670  
    66#
    77# Copyright (C) 2013, 2015, Red Hat, Inc.
     8# Copyright (c) 2024 Intel Corporation.
    89#
    910# SPDX-License-Identifier: BSD-2-Clause-Patent
     
    4243  UefiBootServicesTableLib
    4344  UefiDriverEntryPoint
     45  HobLib
    4446
    4547[Protocols]
     
    4951  gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
    5052
     53[Guids]
     54  gEfiSmmSmramMemoryGuid             # ALWAYS_CONSUMED
     55
    5156[Pcd]
    5257  gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase
  • trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/SmmAccess/SmmAccessPei.c

    r101291 r105670  
    44
    55  - verify & configure the Q35 TSEG in the entry point,
    6   - provide SMRAM access by producing PEI_SMM_ACCESS_PPI,
    7   - set aside the SMM_S3_RESUME_STATE object at the bottom of TSEG, and expose
    8     it via the gEfiAcpiVariableGuid GUID HOB.
     6  - provide SMRAM access by producing PEI_SMM_ACCESS_PPI
    97
    108  This PEIM runs from RAM, so we can write to variables with static storage
     
    1210
    1311  Copyright (C) 2013, 2015, Red Hat, Inc.<BR>
    14   Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
     12  Copyright (c) 2010 - 2024, Intel Corporation. All rights reserved.<BR>
    1513
    1614  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    1816**/
    1917
    20 #include <Guid/AcpiS3Context.h>
    2118#include <Library/BaseLib.h>
    2219#include <Library/BaseMemoryLib.h>
    2320#include <Library/DebugLib.h>
    24 #include <Library/HobLib.h>
    2521#include <Library/IoLib.h>
    2622#include <Library/PcdLib.h>
     
    6561  )
    6662{
    67   if (DescriptorIndex >= DescIdxCount) {
     63  EFI_HOB_GUID_TYPE               *GuidHob;
     64  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK  *DescriptorBlock;
     65
     66  //
     67  // Get the number of regions in the system that can be usable for SMRAM
     68  //
     69  GuidHob         = GetFirstGuidHob (&gEfiSmmSmramMemoryGuid);
     70  DescriptorBlock = GET_GUID_HOB_DATA (GuidHob);
     71  ASSERT (DescriptorBlock);
     72
     73  if (DescriptorIndex >= DescriptorBlock->NumberOfSmmReservedRegions) {
    6874    return EFI_INVALID_PARAMETER;
    6975  }
     
    103109  )
    104110{
    105   if (DescriptorIndex >= DescIdxCount) {
     111  EFI_HOB_GUID_TYPE               *GuidHob;
     112  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK  *DescriptorBlock;
     113
     114  //
     115  // Get the number of regions in the system that can be usable for SMRAM
     116  //
     117  GuidHob         = GetFirstGuidHob (&gEfiSmmSmramMemoryGuid);
     118  DescriptorBlock = GET_GUID_HOB_DATA (GuidHob);
     119  ASSERT (DescriptorBlock);
     120
     121  if (DescriptorIndex >= DescriptorBlock->NumberOfSmmReservedRegions) {
    106122    return EFI_INVALID_PARAMETER;
    107123  }
     
    140156  )
    141157{
    142   if (DescriptorIndex >= DescIdxCount) {
     158  EFI_HOB_GUID_TYPE               *GuidHob;
     159  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK  *DescriptorBlock;
     160
     161  //
     162  // Get the number of regions in the system that can be usable for SMRAM
     163  //
     164  GuidHob         = GetFirstGuidHob (&gEfiSmmSmramMemoryGuid);
     165  DescriptorBlock = GET_GUID_HOB_DATA (GuidHob);
     166  ASSERT (DescriptorBlock);
     167
     168  if (DescriptorIndex >= DescriptorBlock->NumberOfSmmReservedRegions) {
    143169    return EFI_INVALID_PARAMETER;
    144170  }
     
    179205{
    180206  return SmramAccessGetCapabilities (
    181            This->LockState,
    182            This->OpenState,
    183207           SmramMapSize,
    184208           SmramMap
     
    241265  )
    242266{
    243   UINT16                HostBridgeDevId;
    244   UINT8                 EsmramcVal;
    245   UINT8                 RegMask8;
    246   UINT32                TopOfLowRam, TopOfLowRamMb;
    247   EFI_STATUS            Status;
    248   UINTN                 SmramMapSize;
    249   EFI_SMRAM_DESCRIPTOR  SmramMap[DescIdxCount];
    250   VOID                  *GuidHob;
     267  UINT16  HostBridgeDevId;
     268  UINT8   EsmramcVal;
     269  UINT8   RegMask8;
     270  UINT32  TopOfLowRam, TopOfLowRamMb;
    251271
    252272  //
     
    357377    );
    358378
    359   //
    360   // Create the GUID HOB and point it to the first SMRAM range.
    361   //
    362379  GetStates (&mAccess.LockState, &mAccess.OpenState);
    363   SmramMapSize = sizeof SmramMap;
    364   Status       = SmramAccessGetCapabilities (
    365                    mAccess.LockState,
    366                    mAccess.OpenState,
    367                    &SmramMapSize,
    368                    SmramMap
    369                    );
    370   ASSERT_EFI_ERROR (Status);
    371 
    372   DEBUG_CODE_BEGIN ();
    373   {
    374     UINTN  Count;
    375     UINTN  Idx;
    376 
    377     Count = SmramMapSize / sizeof SmramMap[0];
    378     DEBUG ((
    379       DEBUG_VERBOSE,
    380       "%a: SMRAM map follows, %d entries\n",
    381       __func__,
    382       (INT32)Count
    383       ));
    384     DEBUG ((
    385       DEBUG_VERBOSE,
    386       "% 20a % 20a % 20a % 20a\n",
    387       "PhysicalStart(0x)",
    388       "PhysicalSize(0x)",
    389       "CpuStart(0x)",
    390       "RegionState(0x)"
    391       ));
    392     for (Idx = 0; Idx < Count; ++Idx) {
    393       DEBUG ((
    394         DEBUG_VERBOSE,
    395         "% 20Lx % 20Lx % 20Lx % 20Lx\n",
    396         SmramMap[Idx].PhysicalStart,
    397         SmramMap[Idx].PhysicalSize,
    398         SmramMap[Idx].CpuStart,
    399         SmramMap[Idx].RegionState
    400         ));
    401     }
    402   }
    403   DEBUG_CODE_END ();
    404 
    405   GuidHob = BuildGuidHob (
    406               &gEfiAcpiVariableGuid,
    407               sizeof SmramMap[DescIdxSmmS3ResumeState]
    408               );
    409   if (GuidHob == NULL) {
    410     return EFI_OUT_OF_RESOURCES;
    411   }
    412 
    413   CopyMem (
    414     GuidHob,
    415     &SmramMap[DescIdxSmmS3ResumeState],
    416     sizeof SmramMap[DescIdxSmmS3ResumeState]
    417     );
    418380
    419381  //
  • trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/SmmAccess/SmmAccessPei.inf

    r85718 r105670  
    33#
    44# - provide SMRAM access by producing PEI_SMM_ACCESS_PPI,
    5 # - verify & configure the Q35 TSEG in the entry point,
    6 # - set aside the SMM_S3_RESUME_STATE object at the bottom of TSEG, and expose
    7 #   it via the gEfiAcpiVariableGuid GUIDed HOB.
     5# - verify & configure the Q35 TSEG in the entry point.
    86#
    97# Copyright (C) 2013, 2015, Red Hat, Inc.
     8# Copyright (c) 2024 Intel Corporation.
    109#
    1110# SPDX-License-Identifier: BSD-2-Clause-Patent
     
    3736  OvmfPkg/OvmfPkg.dec
    3837
    39 [Guids]
    40   gEfiAcpiVariableGuid
    41 
    4238[LibraryClasses]
    4339  BaseLib
     
    5854  gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes
    5955
     56[Guids]
     57  gEfiSmmSmramMemoryGuid             # ALWAYS_CONSUMED
     58
    6059[Ppis]
    6160  gPeiSmmAccessPpiGuid           ## PRODUCES
  • trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/SmmAccess/SmramInternal.c

    r99404 r105670  
    44
    55  Copyright (C) 2015, Red Hat, Inc.
     6  Copyright (c) 2024 Intel Corporation.
    67
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
    89
    910**/
    10 
    11 #include <Guid/AcpiS3Context.h>
    1211#include <IndustryStandard/Q35MchIch9.h>
    1312#include <Library/DebugLib.h>
     
    167166EFI_STATUS
    168167SmramAccessGetCapabilities (
    169   IN BOOLEAN                   LockState,
    170   IN BOOLEAN                   OpenState,
    171168  IN OUT UINTN                 *SmramMapSize,
    172169  IN OUT EFI_SMRAM_DESCRIPTOR  *SmramMap
    173170  )
    174171{
    175   UINTN   OriginalSize;
    176   UINT32  TsegMemoryBaseMb, TsegMemoryBase;
    177   UINT64  CommonRegionState;
    178   UINT8   TsegSizeBits;
    179 
    180   OriginalSize  = *SmramMapSize;
    181   *SmramMapSize = DescIdxCount * sizeof *SmramMap;
    182   if (OriginalSize < *SmramMapSize) {
     172  UINTN                           BufferSize;
     173  EFI_HOB_GUID_TYPE               *GuidHob;
     174  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK  *DescriptorBlock;
     175  UINTN                           Index;
     176
     177  //
     178  // Get Hob list
     179  //
     180  GuidHob         = GetFirstGuidHob (&gEfiSmmSmramMemoryGuid);
     181  DescriptorBlock = GET_GUID_HOB_DATA (GuidHob);
     182  ASSERT (DescriptorBlock);
     183
     184  BufferSize = DescriptorBlock->NumberOfSmmReservedRegions * sizeof (EFI_SMRAM_DESCRIPTOR);
     185
     186  if (*SmramMapSize < BufferSize) {
     187    *SmramMapSize = BufferSize;
    183188    return EFI_BUFFER_TOO_SMALL;
    184189  }
    185190
    186191  //
    187   // Read the TSEG Memory Base register.
    188   //
    189   TsegMemoryBaseMb = PciRead32 (DRAMC_REGISTER_Q35 (MCH_TSEGMB));
    190   TsegMemoryBase   = (TsegMemoryBaseMb >> MCH_TSEGMB_MB_SHIFT) << 20;
    191 
    192   //
    193   // Precompute the region state bits that will be set for all regions.
    194   //
    195   CommonRegionState = (OpenState ? EFI_SMRAM_OPEN : EFI_SMRAM_CLOSED) |
    196                       (LockState ? EFI_SMRAM_LOCKED : 0) |
    197                       EFI_CACHEABLE;
    198 
    199   //
    200   // The first region hosts an SMM_S3_RESUME_STATE object. It is located at the
    201   // start of TSEG. We round up the size to whole pages, and we report it as
    202   // EFI_ALLOCATED, so that the SMM_CORE stays away from it.
    203   //
    204   SmramMap[DescIdxSmmS3ResumeState].PhysicalStart = TsegMemoryBase;
    205   SmramMap[DescIdxSmmS3ResumeState].CpuStart      = TsegMemoryBase;
    206   SmramMap[DescIdxSmmS3ResumeState].PhysicalSize  =
    207     EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (sizeof (SMM_S3_RESUME_STATE)));
    208   SmramMap[DescIdxSmmS3ResumeState].RegionState =
    209     CommonRegionState | EFI_ALLOCATED;
    210 
    211   //
    212   // Get the TSEG size bits from the ESMRAMC register.
    213   //
    214   TsegSizeBits = PciRead8 (DRAMC_REGISTER_Q35 (MCH_ESMRAMC)) &
    215                  MCH_ESMRAMC_TSEG_MASK;
    216 
    217   //
    218   // The second region is the main one, following the first.
    219   //
    220   SmramMap[DescIdxMain].PhysicalStart =
    221     SmramMap[DescIdxSmmS3ResumeState].PhysicalStart +
    222     SmramMap[DescIdxSmmS3ResumeState].PhysicalSize;
    223   SmramMap[DescIdxMain].CpuStart     = SmramMap[DescIdxMain].PhysicalStart;
    224   SmramMap[DescIdxMain].PhysicalSize =
    225     (TsegSizeBits == MCH_ESMRAMC_TSEG_8MB ? SIZE_8MB :
    226      TsegSizeBits == MCH_ESMRAMC_TSEG_2MB ? SIZE_2MB :
    227      TsegSizeBits == MCH_ESMRAMC_TSEG_1MB ? SIZE_1MB :
    228      mQ35TsegMbytes * SIZE_1MB) -
    229     SmramMap[DescIdxSmmS3ResumeState].PhysicalSize;
    230   SmramMap[DescIdxMain].RegionState = CommonRegionState;
    231 
    232   return EFI_SUCCESS;
    233 }
     192  // Update SmramMapSize to real return SMRAM map size
     193  //
     194  *SmramMapSize = BufferSize;
     195
     196  //
     197  // Use the hob to publish SMRAM capabilities
     198  //
     199  for (Index = 0; Index < DescriptorBlock->NumberOfSmmReservedRegions; Index++) {
     200    SmramMap[Index].PhysicalStart = DescriptorBlock->Descriptor[Index].PhysicalStart;
     201    SmramMap[Index].CpuStart      = DescriptorBlock->Descriptor[Index].CpuStart;
     202    SmramMap[Index].PhysicalSize  = DescriptorBlock->Descriptor[Index].PhysicalSize;
     203    SmramMap[Index].RegionState   = DescriptorBlock->Descriptor[Index].RegionState;
     204  }
     205
     206  return EFI_SUCCESS;
     207}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/SmmAccess/SmramInternal.h

    r99404 r105670  
    44
    55  Copyright (C) 2015, Red Hat, Inc.
     6  Copyright (c) 2024 Intel Corporation.
    67
    78  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    1112#include <Pi/PiMultiPhase.h>
    1213
    13 //
    14 // We'll have two SMRAM ranges.
    15 //
    16 // The first is a tiny one that hosts an SMM_S3_RESUME_STATE object, to be
    17 // filled in by the CPU SMM driver during normal boot, for the PEI instance of
    18 // the LockBox library (which will rely on the object during S3 resume).
    19 //
    20 // The other SMRAM range is the main one, for the SMM core and the SMM drivers.
    21 //
    22 typedef enum {
    23   DescIdxSmmS3ResumeState = 0,
    24   DescIdxMain             = 1,
    25   DescIdxCount            = 2
    26 } DESCRIPTOR_INDEX;
     14#include <Guid/SmramMemoryReserve.h>
     15#include <Library/HobLib.h>
    2716
    2817//
     
    9887EFI_STATUS
    9988SmramAccessGetCapabilities (
    100   IN BOOLEAN                   LockState,
    101   IN BOOLEAN                   OpenState,
    10289  IN OUT UINTN                 *SmramMapSize,
    10390  IN OUT EFI_SMRAM_DESCRIPTOR  *SmramMap
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