VirtualBox

Ignore:
Timestamp:
Mar 31, 2025 11:31:09 AM (2 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168237
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, 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/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c

    r105670 r108794  
    77#include <PiPei.h>
    88#include <UniversalPayload/UniversalPayload.h>
     9#include <UniversalPayload/DeviceTree.h>
    910#include <Guid/UniversalPayloadBase.h>
    1011#include <UniversalPayload/ExtraData.h>
    11 
     12#include <UniversalPayload/DeviceTree.h>
    1213#include <Ppi/LoadFile.h>
    13 
     14#include <Library/PciHostBridgeLib.h>
     15#include <Protocol/DevicePath.h>
    1416#include <Library/DebugLib.h>
    1517#include <Library/HobLib.h>
    16 #include <Library/PeiServicesLib.h>
    1718#include <Library/MemoryAllocationLib.h>
    1819#include <Library/BaseMemoryLib.h>
    19 
     20#include <Library/FdtLib.h>
     21#include <Library/PrintLib.h>
     22#include <Library/PeiServicesLib.h>
    2023#include "FitLib.h"
     24#define STACK_SIZE  0x20000
     25
     26CONST EFI_PEI_PPI_DESCRIPTOR  gReadyToPayloadSignalPpi = {
     27  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
     28  &gUplReadyToPayloadPpiGuid,
     29  NULL
     30};
     31
     32EFI_PEI_PPI_DESCRIPTOR  mEndOfPeiSignalPpi = {
     33  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
     34  &gEfiEndOfPeiSignalPpiGuid,
     35  NULL
     36};
     37
     38#if (FixedPcdGetBool (PcdHandOffFdtEnable) == 0)
     39
     40/**
     41  Notify ReadyToPayLoad signal.
     42  @param[in] PeiServices       An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
     43  @param[in] NotifyDescriptor  Address of the notification descriptor data structure.
     44  @param[in] Ppi               Address of the PPI that was installed.
     45  @retval EFI_SUCCESS          Hobs data is discovered.
     46  @return Others               No Hobs data is discovered.
     47**/
     48EFI_STATUS
     49EFIAPI
     50EndOfPeiPpiNotifyCallback (
     51  IN EFI_PEI_SERVICES           **PeiServices,
     52  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
     53  IN VOID                       *Ppi
     54  )
     55{
     56  EFI_STATUS  Status;
     57
     58  //
     59  // Ready to Payload phase signal
     60  //
     61  Status = PeiServicesInstallPpi (&gReadyToPayloadSignalPpi);
     62
     63  return Status;
     64}
     65
     66EFI_PEI_NOTIFY_DESCRIPTOR  mEndOfPeiNotifyList[] = {
     67  {
     68    (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
     69    &gEfiEndOfPeiSignalPpiGuid,
     70    EndOfPeiPpiNotifyCallback
     71  }
     72};
     73#endif
    2174
    2275/**
     
    51104  UINTN                   Index;
    52105
     106 #if (FixedPcdGetBool (PcdHandOffFdtEnable))
     107  VOID                           *BaseOfStack;
     108  VOID                           *TopOfStack;
     109  UNIVERSAL_PAYLOAD_DEVICE_TREE  *Fdt;
     110  VOID                           *Hob;
     111
     112  Fdt = NULL;
     113 #endif
     114
    53115  Instance = 0;
    54116  do {
     
    67129  }
    68130
    69   DEBUG ((
    70     DEBUG_INFO,
    71     "Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 0x%08x\n",
    72     Context.PayloadBaseAddress,
    73     Context.PayloadSize,
    74     Context.PayloadEntryPoint
    75     ));
     131  DEBUG (
     132    (
     133     DEBUG_INFO,
     134     "Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 0x%08x\n",
     135     Context.PayloadBaseAddress,
     136     Context.PayloadSize,
     137     Context.PayloadEntryPoint
     138    )
     139    );
    76140  Context.PayloadBaseAddress = (EFI_PHYSICAL_ADDRESS)AllocatePages (EFI_SIZE_TO_PAGES (Context.PayloadSize));
    77141
     
    97161  }
    98162
    99   DEBUG ((
    100     DEBUG_INFO,
    101     "After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 0x%08x\n",
    102     Context.PayloadBaseAddress,
    103     Context.PayloadSize,
    104     Context.PayloadEntryPoint
    105     ));
     163  DEBUG (
     164    (
     165     DEBUG_INFO,
     166     "After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 0x%08x\n",
     167     Context.PayloadBaseAddress,
     168     Context.PayloadSize,
     169     Context.PayloadEntryPoint
     170    )
     171    );
    106172
    107173  Length      = sizeof (UNIVERSAL_PAYLOAD_BASE);
     
    116182  *EntryPoint      = Context.PayloadEntryPoint;
    117183
     184 #if (FixedPcdGetBool (PcdHandOffFdtEnable))
     185
     186  Status = PeiServicesInstallPpi (&mEndOfPeiSignalPpi);
     187  ASSERT_EFI_ERROR (Status);
     188
     189  Status = PeiServicesInstallPpi (&gReadyToPayloadSignalPpi);
     190  ASSERT_EFI_ERROR (Status);
     191
     192  Hob = GetFirstGuidHob (&gUniversalPayloadDeviceTreeGuid);
     193  if (Hob != NULL) {
     194    Fdt =  (UNIVERSAL_PAYLOAD_DEVICE_TREE *)GET_GUID_HOB_DATA (Hob);
     195  }
     196
     197  //
     198  // Allocate 128KB for the Stack
     199  //
     200  BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));
     201  ASSERT (BaseOfStack != NULL);
     202
     203  //
     204  // Compute the top of the stack we were allocated. Pre-allocate a UINTN
     205  // for safety.
     206  //
     207  TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
     208  TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
     209
     210  //
     211  // Transfer the control to the entry point of UniveralPayloadEntry.
     212  //
     213  SwitchStack (
     214    (SWITCH_STACK_ENTRY_POINT)(UINTN)Context.PayloadEntryPoint,
     215    (VOID *)(Fdt->DeviceTreeAddress),
     216    NULL,
     217    TopOfStack
     218    );
     219 #else
     220  Status = PeiServicesNotifyPpi (&mEndOfPeiNotifyList[0]);
     221  ASSERT_EFI_ERROR (Status);
     222 #endif
     223
    118224  return EFI_SUCCESS;
    119225}
     
    128234  &mPeiLoadFilePpi
    129235};
     236
     237#if (FixedPcdGetBool (PcdHandOffFdtEnable))
     238
     239/**
     240  Discover Hobs data and report data into a FDT.
     241  @param[in] PeiServices       An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
     242  @param[in] NotifyDescriptor  Address of the notification descriptor data structure.
     243  @param[in] Ppi               Address of the PPI that was installed.
     244  @retval EFI_SUCCESS          Hobs data is discovered.
     245  @return Others               No Hobs data is discovered.
     246**/
     247EFI_STATUS
     248EFIAPI
     249FdtPpiNotifyCallback (
     250  IN EFI_PEI_SERVICES           **PeiServices,
     251  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
     252  IN VOID                       *Ppi
     253  );
     254
     255EFI_PEI_NOTIFY_DESCRIPTOR  mReadyToPayloadNotifyList[] = {
     256  {
     257    (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
     258    &gUplReadyToPayloadPpiGuid,
     259    FdtPpiNotifyCallback
     260  }
     261};
     262#endif
     263
     264/**
     265  Print FDT data.
     266  @param[in] FdtBase         Address of the Fdt data.
     267**/
     268VOID
     269PrintFdt (
     270  IN     VOID  *FdtBase
     271  )
     272{
     273  UINT8   *Fdt;
     274  UINT32  i;
     275
     276  Fdt = NULL;
     277  i   = 0;
     278
     279  DEBUG ((DEBUG_ERROR, "FDT DTB data:"));
     280  for (Fdt = FdtBase, i = 0; i < Fdt32ToCpu (((FDT_HEADER *)FdtBase)->TotalSize); i++, Fdt++) {
     281    if (i % 16 == 0) {
     282      DEBUG ((DEBUG_ERROR, "\n"));
     283    }
     284
     285    DEBUG ((DEBUG_ERROR, "%02x ", *Fdt));
     286  }
     287
     288  DEBUG ((DEBUG_ERROR, "\n"));
     289}
     290
     291/**
     292  It will build FDT for UPL consumed.
     293  @param[in] FdtBase         Address of the Fdt data.
     294  @retval EFI_SUCCESS        If it completed successfully.
     295  @retval Others             If it failed to build required FDT.
     296**/
     297EFI_STATUS
     298BuildFdtForUPL (
     299  IN     VOID  *FdtBase
     300  );
     301
     302#if (FixedPcdGetBool (PcdHandOffFdtEnable))
     303
     304/**
     305  Discover Hobs data and report data into a FDT.
     306  @param[in] PeiServices       An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
     307  @param[in] NotifyDescriptor  Address of the notification descriptor data structure.
     308  @param[in] Ppi               Address of the PPI that was installed.
     309  @retval EFI_SUCCESS          Hobs data is discovered.
     310  @return Others               No Hobs data is discovered.
     311**/
     312EFI_STATUS
     313EFIAPI
     314FdtPpiNotifyCallback (
     315  IN EFI_PEI_SERVICES           **PeiServices,
     316  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
     317  IN VOID                       *Ppi
     318  )
     319{
     320  EFI_STATUS                     Status;
     321  UNIVERSAL_PAYLOAD_DEVICE_TREE  *Fdt;
     322  UINT32                         FdtSize;
     323  UINTN                          FdtPages;
     324  VOID                           *FdtBase;
     325  UINT32                         Data32;
     326
     327  Fdt      = NULL;
     328  FdtSize  = PcdGet8 (PcdFDTPageSize) * EFI_PAGE_SIZE;
     329  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
     330  FdtBase  = AllocatePages (FdtPages);
     331  if (FdtBase == NULL) {
     332    DEBUG ((DEBUG_ERROR, "%a: AllocatePages failed\n", __func__));
     333    return EFI_NOT_FOUND;
     334  }
     335
     336  Status = FdtCreateEmptyTree (FdtBase, (UINT32)FdtSize);
     337  if (EFI_ERROR (Status)) {
     338    DEBUG ((DEBUG_ERROR, "%a: cannot create FDT\n", __func__));
     339  }
     340
     341  // Set cell property of root node
     342  Data32 = CpuToFdt32 (2);
     343  Status = FdtSetProperty (FdtBase, 0, "#address-cells", &Data32, sizeof (UINT32));
     344  Status = FdtSetProperty (FdtBase, 0, "#size-cells", &Data32, sizeof (UINT32));
     345
     346  Status = BuildFdtForUPL (FdtBase);
     347  ASSERT_EFI_ERROR (Status);
     348
     349  PrintFdt (FdtBase);
     350
     351  Fdt = BuildGuidHob (&gUniversalPayloadDeviceTreeGuid, sizeof (UNIVERSAL_PAYLOAD_DEVICE_TREE));
     352  if (Fdt == NULL) {
     353    DEBUG ((DEBUG_ERROR, "%a: Build FDT Hob failed\n", __func__));
     354    return EFI_NOT_FOUND;
     355  }
     356
     357  DEBUG ((
     358    DEBUG_ERROR,
     359    "%a: fdt at 0x%x (size %d)\n",
     360    __func__,
     361    FdtBase,
     362    Fdt32ToCpu (((FDT_HEADER *)FdtBase)->TotalSize)
     363    ));
     364
     365  Fdt->Header.Revision   = UNIVERSAL_PAYLOAD_DEVICE_TREE_REVISION;
     366  Fdt->Header.Length     = sizeof (UNIVERSAL_PAYLOAD_DEVICE_TREE);
     367  Fdt->DeviceTreeAddress = (UINT64)FdtBase;
     368
     369  return Status;
     370}
     371
     372#endif
    130373
    131374/**
     
    147390  Status = PeiServicesInstallPpi (&gPpiLoadFilePpiList);
    148391
     392 #if (FixedPcdGetBool (PcdHandOffFdtEnable))
     393
     394  //
     395  // Build FDT in end of PEI notify callback.
     396  //
     397  Status = PeiServicesNotifyPpi (&mReadyToPayloadNotifyList[0]);
     398  ASSERT_EFI_ERROR (Status);
     399 #endif
    149400  return Status;
    150401}
Note: See TracChangeset for help on using the changeset viewer.

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