VirtualBox

Ignore:
Timestamp:
Aug 12, 2020 4:09:12 PM (4 years ago)
Author:
vboxsync
Message:

Devices/EFI: Merge edk-stable202005 and make it build, bugref:4643

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/OvmfPkg/PlatformPei/MemDetect.c

    r82249 r85718  
    1818#include <IndustryStandard/Q35MchIch9.h>
    1919#include <PiPei.h>
     20#include <Register/Intel/SmramSaveStateMap.h>
    2021
    2122//
     
    3334#include <Library/MtrrLib.h>
    3435#include <Library/QemuFwCfgLib.h>
     36#include <Library/QemuFwCfgSimpleParserLib.h>
    3537
    3638#include "Platform.h"
     
    4446STATIC UINT16 mQ35TsegMbytes;
    4547
     48BOOLEAN mQ35SmramAtDefaultSmbase;
     49
    4650UINT32 mQemuUc32Base;
    4751
     
    5458  RETURN_STATUS PcdStatus;
    5559
    56   if (mHostBridgeDevId != INTEL_Q35_MCH_DEVICE_ID) {
    57     DEBUG ((
    58       DEBUG_ERROR,
    59       "%a: no TSEG (SMRAM) on host bridge DID=0x%04x; "
    60       "only DID=0x%04x (Q35) is supported\n",
    61       __FUNCTION__,
    62       mHostBridgeDevId,
    63       INTEL_Q35_MCH_DEVICE_ID
    64       ));
    65     ASSERT (FALSE);
    66     CpuDeadLoop ();
    67   }
     60  ASSERT (mHostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID);
    6861
    6962  //
     
    9992  ASSERT_RETURN_ERROR (PcdStatus);
    10093  mQ35TsegMbytes = ExtendedTsegMbytes;
     94}
     95
     96
     97VOID
     98Q35SmramAtDefaultSmbaseInitialization (
     99  VOID
     100  )
     101{
     102  RETURN_STATUS PcdStatus;
     103
     104  ASSERT (mHostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID);
     105
     106  mQ35SmramAtDefaultSmbase = FALSE;
     107  if (FeaturePcdGet (PcdCsmEnable)) {
     108    DEBUG ((DEBUG_INFO, "%a: SMRAM at default SMBASE not checked due to CSM\n",
     109      __FUNCTION__));
     110  } else {
     111    UINTN CtlReg;
     112    UINT8 CtlRegVal;
     113
     114    CtlReg = DRAMC_REGISTER_Q35 (MCH_DEFAULT_SMBASE_CTL);
     115    PciWrite8 (CtlReg, MCH_DEFAULT_SMBASE_QUERY);
     116    CtlRegVal = PciRead8 (CtlReg);
     117    mQ35SmramAtDefaultSmbase = (BOOLEAN)(CtlRegVal ==
     118                                         MCH_DEFAULT_SMBASE_IN_RAM);
     119    DEBUG ((DEBUG_INFO, "%a: SMRAM at default SMBASE %a\n", __FUNCTION__,
     120      mQ35SmramAtDefaultSmbase ? "found" : "not found"));
     121  }
     122
     123  PcdStatus = PcdSetBoolS (PcdQ35SmramAtDefaultSmbase,
     124                mQ35SmramAtDefaultSmbase);
     125  ASSERT_RETURN_ERROR (PcdStatus);
    101126}
    102127
     
    318343  UINT64               FirstNonAddress;
    319344  UINT64               Pci64Base, Pci64Size;
    320   CHAR8                MbString[7 + 1];
     345  UINT32               FwCfgPciMmio64Mb;
    321346  EFI_STATUS           Status;
    322347  FIRMWARE_CONFIG_ITEM FwCfgItem;
     
    361386  //
    362387  // See if the user specified the number of megabytes for the 64-bit PCI host
    363   // aperture. The number of non-NUL characters in MbString allows for
    364   // 9,999,999 MB, which is approximately 10 TB.
     388  // aperture. Accept an aperture size up to 16TB.
    365389  //
    366390  // As signaled by the "X-" prefix, this knob is experimental, and might go
    367391  // away at any time.
    368392  //
    369   Status = QemuFwCfgFindFile ("opt/ovmf/X-PciMmio64Mb", &FwCfgItem,
    370              &FwCfgSize);
    371   if (!EFI_ERROR (Status)) {
    372     if (FwCfgSize >= sizeof MbString) {
    373       DEBUG ((EFI_D_WARN,
    374         "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n",
    375         __FUNCTION__));
    376     } else {
    377       QemuFwCfgSelectItem (FwCfgItem);
    378       QemuFwCfgReadBytes (FwCfgSize, MbString);
    379       MbString[FwCfgSize] = '\0';
    380       Pci64Size = LShiftU64 (AsciiStrDecimalToUint64 (MbString), 20);
     393  Status = QemuFwCfgParseUint32 ("opt/ovmf/X-PciMmio64Mb", FALSE,
     394             &FwCfgPciMmio64Mb);
     395  switch (Status) {
     396  case EFI_UNSUPPORTED:
     397  case EFI_NOT_FOUND:
     398    break;
     399  case EFI_SUCCESS:
     400    if (FwCfgPciMmio64Mb <= 0x1000000) {
     401      Pci64Size = LShiftU64 (FwCfgPciMmio64Mb, 20);
     402      break;
    381403    }
     404    //
     405    // fall through
     406    //
     407  default:
     408    DEBUG ((DEBUG_WARN,
     409      "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n",
     410      __FUNCTION__));
     411    break;
    382412  }
    383413
    384414  if (Pci64Size == 0) {
    385415    if (mBootMode != BOOT_ON_S3_RESUME) {
    386       DEBUG ((EFI_D_INFO, "%a: disabling 64-bit PCI host aperture\n",
     416      DEBUG ((DEBUG_INFO, "%a: disabling 64-bit PCI host aperture\n",
    387417        __FUNCTION__));
    388418      PcdStatus = PcdSet64S (PcdPciMmio64Size, 0);
     
    442472    ASSERT_RETURN_ERROR (PcdStatus);
    443473
    444     DEBUG ((EFI_D_INFO, "%a: Pci64Base=0x%Lx Pci64Size=0x%Lx\n",
     474    DEBUG ((DEBUG_INFO, "%a: Pci64Base=0x%Lx Pci64Size=0x%Lx\n",
    445475      __FUNCTION__, Pci64Base, Pci64Size));
    446476  }
     
    602632  } else {
    603633    PeiMemoryCap = GetPeiMemoryCap ();
    604     DEBUG ((EFI_D_INFO, "%a: mPhysMemAddressWidth=%d PeiMemoryCap=%u KB\n",
     634    DEBUG ((DEBUG_INFO, "%a: mPhysMemAddressWidth=%d PeiMemoryCap=%u KB\n",
    605635      __FUNCTION__, mPhysMemAddressWidth, PeiMemoryCap >> 10));
    606636
     
    629659
    630660  //
     661  // MEMFD_BASE_ADDRESS separates the SMRAM at the default SMBASE from the
     662  // normal boot permanent PEI RAM. Regarding the S3 boot path, the S3
     663  // permanent PEI RAM is located even higher.
     664  //
     665  if (FeaturePcdGet (PcdSmmSmramRequire) && mQ35SmramAtDefaultSmbase) {
     666    ASSERT (SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE <= MemoryBase);
     667  }
     668
     669  //
    631670  // Publish this memory to the PEI Core
    632671  //
     
    639678
    640679#ifndef VBOX
     680STATIC
     681VOID
     682QemuInitializeRamBelow1gb (
     683  VOID
     684  )
     685{
     686  if (FeaturePcdGet (PcdSmmSmramRequire) && mQ35SmramAtDefaultSmbase) {
     687    AddMemoryRangeHob (0, SMM_DEFAULT_SMBASE);
     688    AddReservedMemoryBaseSizeHob (SMM_DEFAULT_SMBASE, MCH_DEFAULT_SMBASE_SIZE,
     689      TRUE /* Cacheable */);
     690    STATIC_ASSERT (
     691      SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE < BASE_512KB + BASE_128KB,
     692      "end of SMRAM at default SMBASE ends at, or exceeds, 640KB"
     693      );
     694    AddMemoryRangeHob (SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE,
     695      BASE_512KB + BASE_128KB);
     696  } else {
     697    AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);
     698  }
     699}
     700
     701
    641702/**
    642703  Peform Memory Detection for QEMU / KVM
     
    654715  EFI_STATUS                  Status;
    655716
    656   DEBUG ((EFI_D_INFO, "%a called\n", __FUNCTION__));
     717  DEBUG ((DEBUG_INFO, "%a called\n", __FUNCTION__));
    657718
    658719  //
     
    683744    // looking for an area to borrow.
    684745    //
    685     AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);
     746    QemuInitializeRamBelow1gb ();
    686747  } else {
    687748    //
    688749    // Create memory HOBs
    689750    //
    690     AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);
     751    QemuInitializeRamBelow1gb ();
    691752
    692753    if (FeaturePcdGet (PcdSmmSmramRequire)) {
     
    923984        EfiReservedMemoryType
    924985        );
     986      //
     987      // Similarly, allocate away the (already reserved) SMRAM at the default
     988      // SMBASE, if it exists.
     989      //
     990      if (mQ35SmramAtDefaultSmbase) {
     991        BuildMemoryAllocationHob (
     992          SMM_DEFAULT_SMBASE,
     993          MCH_DEFAULT_SMBASE_SIZE,
     994          EfiReservedMemoryType
     995          );
     996      }
    925997    }
    926998  }
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