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 - 2012, 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 
    399   @param  BaseAddress   The base address of the Firmware Volume.
    400   @param  Length        The size of the Firmware Volume in bytes.
    401 
    402 **/
    403 VOID
    404 EFIAPI
    405 BuildFvHob (
    406   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    407   IN UINT64                      Length
    408   )
    409 {
    410   //
    411   // PEI HOB is read only for DXE phase
    412   //
    413   ASSERT (FALSE);
    414 }
    415 
    416 /**
    417   Builds a EFI_HOB_TYPE_FV2 HOB.
    418 
    419   This function builds a EFI_HOB_TYPE_FV2 HOB.
    420   It can only be invoked during PEI phase;
    421   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    422 
    423   If there is no additional space for HOB creation, then ASSERT().
    424 
    425   @param  BaseAddress   The base address of the Firmware Volume.
    426   @param  Length        The size of the Firmware Volume in bytes.
    427   @param  FvName        The name of the Firmware Volume.
    428   @param  FileName      The name of the file.
    429 
    430 **/
    431 VOID
    432 EFIAPI
    433 BuildFv2Hob (
    434   IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
    435   IN          UINT64                      Length,
    436   IN CONST    EFI_GUID                    *FvName,
    437   IN CONST    EFI_GUID                    *FileName
    438   )
    439 {
    440   ASSERT (FALSE);
    441 }
    442 
    443 
    444 /**
    445   Builds a Capsule Volume HOB.
    446 
    447   This function builds a Capsule Volume HOB.
    448   It can only be invoked during PEI phase;
    449   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    450 
    451   If the platform does not support Capsule Volume HOBs, then ASSERT().
    452   If there is no additional space for HOB creation, then ASSERT().
    453 
    454   @param  BaseAddress   The base address of the Capsule Volume.
    455   @param  Length        The size of the Capsule Volume in bytes.
    456 
    457 **/
    458 VOID
    459 EFIAPI
    460 BuildCvHob (
    461   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    462   IN UINT64                      Length
    463   )
    464 {
    465   //
    466   // PEI HOB is read only for DXE phase
    467   //
    468   ASSERT (FALSE);
    469 }
    470 
    471 /**
    472   Builds a HOB for the CPU.
    473 
    474   This function builds a HOB for the CPU.
    475   It can only be invoked during PEI phase;
    476   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    477 
    478   If there is no additional space for HOB creation, then ASSERT().
    479 
    480   @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.
    481   @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.
    482 
    483 **/
    484 VOID
    485 EFIAPI
    486 BuildCpuHob (
    487   IN UINT8                       SizeOfMemorySpace,
    488   IN UINT8                       SizeOfIoSpace
    489   )
    490 {
    491   //
    492   // PEI HOB is read only for DXE phase
    493   //
    494   ASSERT (FALSE);
    495 }
    496 
    497 /**
    498   Builds a HOB for the Stack.
    499 
    500   This function builds a HOB for the stack.
    501   It can only be invoked during PEI phase;
    502   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    503 
    504   If there is no additional space for HOB creation, then ASSERT().
    505 
    506   @param  BaseAddress   The 64 bit physical address of the Stack.
    507   @param  Length        The length of the stack in bytes.
    508 
    509 **/
    510 VOID
    511 EFIAPI
    512 BuildStackHob (
    513   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    514   IN UINT64                      Length
    515   )
    516 {
    517   //
    518   // PEI HOB is read only for DXE phase
    519   //
    520   ASSERT (FALSE);
    521 }
    522 
    523 /**
    524   Builds a HOB for the BSP store.
    525 
    526   This function builds a HOB for BSP store.
    527   It can only be invoked during PEI phase;
    528   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    529 
    530   If there is no additional space for HOB creation, then ASSERT().
    531 
    532   @param  BaseAddress   The 64 bit physical address of the BSP.
    533   @param  Length        The length of the BSP store in bytes.
    534   @param  MemoryType    Type of memory allocated by this HOB.
    535 
    536 **/
    537 VOID
    538 EFIAPI
    539 BuildBspStoreHob (
    540   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    541   IN UINT64                      Length,
    542   IN EFI_MEMORY_TYPE             MemoryType
    543   )
    544 {
    545   //
    546   // PEI HOB is read only for DXE phase
    547   //
    548   ASSERT (FALSE);
    549 }
    550 
    551 /**
    552   Builds a HOB for the memory allocation.
    553 
    554   This function builds a HOB for the memory allocation.
    555   It can only be invoked during PEI phase;
    556   for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
    557 
    558   If there is no additional space for HOB creation, then ASSERT().
    559 
    560   @param  BaseAddress   The 64 bit physical address of the memory.
    561   @param  Length        The length of the memory allocation in bytes.
    562   @param  MemoryType    Type of memory allocated by this HOB.
    563 
    564 **/
    565 VOID
    566 EFIAPI
    567 BuildMemoryAllocationHob (
    568   IN EFI_PHYSICAL_ADDRESS        BaseAddress,
    569   IN UINT64                      Length,
    570   IN EFI_MEMORY_TYPE             MemoryType
    571   )
    572 {
    573   //
    574   // PEI HOB is read only for DXE phase
    575   //
    576   ASSERT (FALSE);
    577 }
    578