Home | History | Annotate | Download | only in ArmVirtDxeHobLib
      1 /** @file
      2   HOB Library implemenation for Dxe Phase with DebugLib dependency removed
      3 
      4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
      5 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
      6 This program and the accompanying materials
      7 are licensed and made available under the terms and conditions of the BSD License
      8 which accompanies this distribution.  The full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php
     10 
     11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #define ASSERT(Expression)      \
     17   do {                          \
     18     if (!(Expression)) {        \
     19       CpuDeadLoop ();           \
     20     }                           \
     21   } while (FALSE)
     22 
     23 #include <PiDxe.h>
     24 
     25 #include <Guid/HobList.h>
     26 
     27 #include <Library/HobLib.h>
     28 #include <Library/UefiLib.h>
     29 #include <Library/BaseMemoryLib.h>
     30 
     31 VOID  *mHobList = NULL;
     32 
     33 /**
     34   The constructor function caches the pointer to HOB list.
     35 
     36   The constructor function gets the start address of HOB list from system configuration table.
     37 
     38   @param  ImageHandle   The firmware allocated handle for the EFI image.
     39   @param  SystemTable   A pointer to the EFI System Table.
     40 
     41   @retval EFI_SUCCESS   The constructor successfully gets HobList.
     42   @retval Other value   The constructor can't get HobList.
     43 
     44 **/
     45 EFI_STATUS
     46 EFIAPI
     47 HobLibConstructor (
     48   IN EFI_HANDLE        ImageHandle,
     49   IN EFI_SYSTEM_TABLE  *SystemTable
     50   )
     51 {
     52   UINTN             Index;
     53 
     54   for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {
     55     if (CompareGuid (&gEfiHobListGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {
     56       mHobList = SystemTable->ConfigurationTable[Index].VendorTable;
     57       return EFI_SUCCESS;
     58     }
     59   }
     60 
     61   return EFI_NOT_FOUND;
     62 }
     63 
     64 /**
     65   Returns the pointer to the HOB list.
     66 
     67   This function returns the pointer to first HOB in the list.
     68   For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
     69   to the HOB list.  For the DXE phase, the HOB list pointer can be retrieved through
     70   the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
     71   Since the System Configuration Table does not exist that the time the DXE Core is
     72   launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
     73   to manage the pointer to the HOB list.
     74 
     75   If the pointer to the HOB list is NULL, then ASSERT().
     76 
     77   @return The pointer to the HOB list.
     78 
     79 **/
     80 VOID *
     81 EFIAPI
     82 GetHobList (
     83   VOID
     84   )
     85 {
     86   ASSERT (mHobList != NULL);
     87   return mHobList;
     88 }
     89 
     90 /**
     91   Returns the next instance of a HOB type from the starting HOB.
     92 
     93   This function searches the first instance of a HOB type from the starting HOB pointer.
     94   If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
     95   In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
     96   unconditionally: it returns HobStart back if HobStart itself meets the requirement;
     97   caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
     98 
     99   If HobStart is NULL, then ASSERT().
    100 
    101   @param  Type          The HOB type to return.
    102   @param  HobStart      The starting HOB pointer to search from.
    103 
    104   @return The next instance of a HOB type from the starting HOB.
    105 
    106 **/
    107 VOID *
    108 EFIAPI
    109 GetNextHob (
    110   IN UINT16                 Type,
    111   IN CONST VOID             *HobStart
    112   )
    113 {
    114   EFI_PEI_HOB_POINTERS  Hob;
    115 
    116   ASSERT (HobStart != NULL);
    117 
    118   Hob.Raw = (UINT8 *) HobStart;
    119   //
    120   // Parse the HOB list until end of list or matching type is found.
    121   //
    122   while (!END_OF_HOB_LIST (Hob)) {
    123     if (Hob.Header->HobType == Type) {
    124       return Hob.Raw;
    125     }
    126     Hob.Raw = GET_NEXT_HOB (Hob);
    127   }
    128   return NULL;
    129 }
    130 
    131 /**
    132   Returns the first instance of a HOB type among the whole HOB list.
    133 
    134   This function searches the first instance of a HOB type among the whole HOB list.
    135   If there does not exist such HOB type in the HOB list, it will return NULL.
    136 
    137   If the pointer to the HOB list is NULL, then ASSERT().
    138 
    139   @param  Type          The HOB type to return.
    140 
    141   @return The next instance of a HOB type from the starting HOB.
    142 
    143 **/
    144 VOID *
    145 EFIAPI
    146 GetFirstHob (
    147   IN UINT16                 Type
    148   )
    149 {
    150   VOID      *HobList;
    151 
    152   HobList = GetHobList ();
    153   return GetNextHob (Type, HobList);
    154 }
    155 
    156 /**
    157   Returns the next instance of the matched GUID HOB from the starting HOB.
    158 
    159   This function searches the first instance of a HOB from the starting HOB pointer.
    160   Such HOB should satisfy two conditions:
    161   its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
    162   If there does not exist such HOB from the starting HOB pointer, it will return NULL.
    163   Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
    164   to extract the data section and its size information, respectively.
    165   In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
    166   unconditionally: it returns HobStart back if HobStart itself meets the requirement;
    167   caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
    168 
    169   If Guid is NULL, then ASSERT().
    170   If HobStart is NULL, then ASSERT().
    171 
    172   @param  Guid          The GUID to match with in the HOB list.
    173   @param  HobStart      A pointer to a Guid.
    174 
    175   @return The next instance of the matched GUID HOB from the starting HOB.
    176 
    177 **/
    178 VOID *
    179 EFIAPI
    180 GetNextGuidHob (
    181   IN CONST EFI_GUID         *Guid,
    182   IN CONST VOID             *HobStart
    183   )
    184 {
    185   EFI_PEI_HOB_POINTERS  GuidHob;
    186 
    187   GuidHob.Raw = (UINT8 *) HobStart;
    188   while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
    189     if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
    190       break;
    191     }
    192     GuidHob.Raw = GET_NEXT_HOB (GuidHob);
    193   }
    194   return GuidHob.Raw;
    195 }
    196 
    197 /**
    198   Returns the first instance of the matched GUID HOB among the whole HOB list.
    199 
    200   This function searches the first instance of a HOB among the whole HOB list.
    201   Such HOB should satisfy two conditions:
    202   its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
    203   If there does not exist such HOB from the starting HOB pointer, it will return NULL.
    204   Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
    205   to extract the data section and its size information, respectively.
    206 
    207   If the pointer to the HOB list is NULL, then ASSERT().
    208   If Guid is NULL, then ASSERT().
    209 
    210   @param  Guid          The GUID to match with in the HOB list.
    211 
    212   @return The first instance of the matched GUID HOB among the whole HOB list.
    213 
    214 **/
    215 VOID *
    216 EFIAPI
    217 GetFirstGuidHob (
    218   IN CONST EFI_GUID         *Guid
    219   )
    220 {
    221   VOID      *HobList;
    222 
    223   HobList = GetHobList ();
    224   return GetNextGuidHob (Guid, HobList);
    225 }
    226 
    227 /**
    228   Get the system boot mode from the HOB list.
    229 
    230   This function returns the system boot mode information from the
    231   PHIT HOB in HOB list.
    232 
    233   If the pointer to the HOB list is NULL, then ASSERT().
    234 
    235   @param  VOID
    236 
    237   @return The Boot Mode.
    238 
    239 **/
    240 EFI_BOOT_MODE
    241 EFIAPI
    242 GetBootModeHob (
    243   VOID
    244   )
    245 {
    246   EFI_HOB_HANDOFF_INFO_TABLE    *HandOffHob;
    247 
    248   HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();
    249 
    250   return  HandOffHob->BootMode;
    251 }
    252 
    253 /**
    254   Builds a HOB for a loaded PE32 module.
    255 
    256   This function builds a HOB for a loaded PE32 module.
    257   It can only be invoked during PEI phase;
    258   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    259 
    260   If ModuleName is NULL, then ASSERT().
    261   If there is no additional space for HOB creation, then ASSERT().
    262 
    263   @param  ModuleName              The GUID File Name of the module.
    264   @param  MemoryAllocationModule  The 64 bit physical address of the module.
    265   @param  ModuleLength            The length of the module in bytes.
    266   @param  EntryPoint              The 64 bit physical address of the module entry point.
    267 
    268 **/
    269 VOID
    270 EFIAPI
    271 BuildModuleHob (
    272   IN CONST EFI_GUID         *ModuleName,
    273   IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,
    274   IN UINT64                 ModuleLength,
    275   IN EFI_PHYSICAL_ADDRESS   EntryPoint
    276   )
    277 {
    278   //
    279   // PEI HOB is read only for DXE phase
    280   //
    281   ASSERT (FALSE);
    282 }
    283 
    284 /**
    285   Builds a HOB that describes a chunk of system memory.
    286 
    287   This function builds a HOB that describes a chunk of system memory.
    288   It can only be invoked during PEI phase;
    289   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    290 
    291   If there is no additional space for HOB creation, then ASSERT().
    292 
    293   @param  ResourceType        The type of resource described by this HOB.
    294   @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
    295   @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
    296   @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
    297 
    298 **/
    299 VOID
    300 EFIAPI
    301 BuildResourceDescriptorHob (
    302   IN EFI_RESOURCE_TYPE            ResourceType,
    303   IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
    304   IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
    305   IN UINT64                       NumberOfBytes
    306   )
    307 {
    308   //
    309   // PEI HOB is read only for DXE phase
    310   //
    311   ASSERT (FALSE);
    312 }
    313 
    314 /**
    315   Builds a customized HOB tagged with a GUID for identification and returns
    316   the start address of GUID HOB data.
    317 
    318   This function builds a customized HOB tagged with a GUID for identification
    319   and returns the start address of GUID HOB data so that caller can fill the customized data.
    320   The HOB Header and Name field is already stripped.
    321   It can only be invoked during PEI phase;
    322   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    323 
    324   If Guid is NULL, then ASSERT().
    325   If there is no additional space for HOB creation, then ASSERT().
    326   If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
    327   HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
    328 
    329   @param  Guid          The GUID to tag the customized HOB.
    330   @param  DataLength    The size of the data payload for the GUID HOB.
    331 
    332   @retval  NULL         The GUID HOB could not be allocated.
    333   @retval  others       The start address of GUID HOB data.
    334 
    335 **/
    336 VOID *
    337 EFIAPI
    338 BuildGuidHob (
    339   IN CONST EFI_GUID              *Guid,
    340   IN UINTN                       DataLength
    341   )
    342 {
    343   //
    344   // PEI HOB is read only for DXE phase
    345   //
    346   ASSERT (FALSE);
    347   return NULL;
    348 }
    349 
    350 /**
    351   Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
    352   data field, and returns the start address of the GUID HOB data.
    353 
    354   This function builds a customized HOB tagged with a GUID for identification and copies the input
    355   data to the HOB data field and returns the start address of the GUID HOB data.  It can only be
    356   invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    357   The HOB Header and Name field is already stripped.
    358   It can only be invoked during PEI phase;
    359   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    360 
    361   If Guid is NULL, then ASSERT().
    362   If Data is NULL and DataLength > 0, then ASSERT().
    363   If there is no additional space for HOB creation, then ASSERT().
    364   If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
    365   HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
    366 
    367   @param  Guid          The GUID to tag the customized HOB.
    368   @param  Data          The data to be copied into the data field of the GUID HOB.
    369   @param  DataLength    The size of the data payload for the GUID HOB.
    370 
    371   @retval  NULL         The GUID HOB could not be allocated.
    372   @retval  others       The start address of GUID HOB data.
    373 
    374 **/
    375 VOID *
    376 EFIAPI
    377 BuildGuidDataHob (
    378   IN CONST EFI_GUID              *Guid,
    379   IN VOID                        *Data,
    380   IN UINTN                       DataLength
    381   )
    382 {
    383   //
    384   // PEI HOB is read only for DXE phase
    385   //
    386   ASSERT (FALSE);
    387   return NULL;
    388 }
    389 
    390 /**
    391   Builds a Firmware Volume HOB.
    392 
    393   This function builds a Firmware Volume HOB.
    394   It can only be invoked during PEI phase;
    395   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    396 
    397   If there is no additional space for HOB creation, then ASSERT().
    398   If the FvImage buffer is not at its required alignment, then ASSERT().
    399 
    400   @param  BaseAddress   The base address of the Firmware Volume.
    401   @param  Length        The size of the Firmware Volume in bytes.
    402 
    403 **/
    404 VOID
    405 EFIAPI
    406 BuildFvHob (
    407   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    408   IN UINT64                      Length
    409   )
    410 {
    411   //
    412   // PEI HOB is read only for DXE phase
    413   //
    414   ASSERT (FALSE);
    415 }
    416 
    417 /**
    418   Builds a EFI_HOB_TYPE_FV2 HOB.
    419 
    420   This function builds a EFI_HOB_TYPE_FV2 HOB.
    421   It can only be invoked during PEI phase;
    422   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    423 
    424   If there is no additional space for HOB creation, then ASSERT().
    425   If the FvImage buffer is not at its required alignment, then ASSERT().
    426 
    427   @param  BaseAddress   The base address of the Firmware Volume.
    428   @param  Length        The size of the Firmware Volume in bytes.
    429   @param  FvName        The name of the Firmware Volume.
    430   @param  FileName      The name of the file.
    431 
    432 **/
    433 VOID
    434 EFIAPI
    435 BuildFv2Hob (
    436   IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
    437   IN          UINT64                      Length,
    438   IN CONST    EFI_GUID                    *FvName,
    439   IN CONST    EFI_GUID                    *FileName
    440   )
    441 {
    442   ASSERT (FALSE);
    443 }
    444 
    445 
    446 /**
    447   Builds a Capsule Volume HOB.
    448 
    449   This function builds a Capsule Volume HOB.
    450   It can only be invoked during PEI phase;
    451   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    452 
    453   If the platform does not support Capsule Volume HOBs, then ASSERT().
    454   If there is no additional space for HOB creation, then ASSERT().
    455 
    456   @param  BaseAddress   The base address of the Capsule Volume.
    457   @param  Length        The size of the Capsule Volume in bytes.
    458 
    459 **/
    460 VOID
    461 EFIAPI
    462 BuildCvHob (
    463   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    464   IN UINT64                      Length
    465   )
    466 {
    467   //
    468   // PEI HOB is read only for DXE phase
    469   //
    470   ASSERT (FALSE);
    471 }
    472 
    473 /**
    474   Builds a HOB for the CPU.
    475 
    476   This function builds a HOB for the CPU.
    477   It can only be invoked during PEI phase;
    478   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    479 
    480   If there is no additional space for HOB creation, then ASSERT().
    481 
    482   @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.
    483   @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.
    484 
    485 **/
    486 VOID
    487 EFIAPI
    488 BuildCpuHob (
    489   IN UINT8                       SizeOfMemorySpace,
    490   IN UINT8                       SizeOfIoSpace
    491   )
    492 {
    493   //
    494   // PEI HOB is read only for DXE phase
    495   //
    496   ASSERT (FALSE);
    497 }
    498 
    499 /**
    500   Builds a HOB for the Stack.
    501 
    502   This function builds a HOB for the stack.
    503   It can only be invoked during PEI phase;
    504   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    505 
    506   If there is no additional space for HOB creation, then ASSERT().
    507 
    508   @param  BaseAddress   The 64 bit physical address of the Stack.
    509   @param  Length        The length of the stack in bytes.
    510 
    511 **/
    512 VOID
    513 EFIAPI
    514 BuildStackHob (
    515   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    516   IN UINT64                      Length
    517   )
    518 {
    519   //
    520   // PEI HOB is read only for DXE phase
    521   //
    522   ASSERT (FALSE);
    523 }
    524 
    525 /**
    526   Builds a HOB for the BSP store.
    527 
    528   This function builds a HOB for BSP store.
    529   It can only be invoked during PEI phase;
    530   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    531 
    532   If there is no additional space for HOB creation, then ASSERT().
    533 
    534   @param  BaseAddress   The 64 bit physical address of the BSP.
    535   @param  Length        The length of the BSP store in bytes.
    536   @param  MemoryType    Type of memory allocated by this HOB.
    537 
    538 **/
    539 VOID
    540 EFIAPI
    541 BuildBspStoreHob (
    542   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    543   IN UINT64                      Length,
    544   IN EFI_MEMORY_TYPE             MemoryType
    545   )
    546 {
    547   //
    548   // PEI HOB is read only for DXE phase
    549   //
    550   ASSERT (FALSE);
    551 }
    552 
    553 /**
    554   Builds a HOB for the memory allocation.
    555 
    556   This function builds a HOB for the memory allocation.
    557   It can only be invoked during PEI phase;
    558   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    559 
    560   If there is no additional space for HOB creation, then ASSERT().
    561 
    562   @param  BaseAddress   The 64 bit physical address of the memory.
    563   @param  Length        The length of the memory allocation in bytes.
    564   @param  MemoryType    Type of memory allocated by this HOB.
    565 
    566 **/
    567 VOID
    568 EFIAPI
    569 BuildMemoryAllocationHob (
    570   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    571   IN UINT64                      Length,
    572   IN EFI_MEMORY_TYPE             MemoryType
    573   )
    574 {
    575   //
    576   // PEI HOB is read only for DXE phase
    577   //
    578   ASSERT (FALSE);
    579 }
    580