]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/PeiHobLib/HobLib.c
Since PciXXXReadBuffer/PciXXXWriteBuffer does not check the alignment of user buffer...
[mirror_edk2.git] / MdePkg / Library / PeiHobLib / HobLib.c
index 43490cc46b45d0a4b866c704eebc840568f1fb17..a70162c831288e89eb7b3352d7ac11ac1ea647d7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HOB Library.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
   All rights reserved. This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  Module Name:  HobLib.c\r
-\r
 **/\r
 \r
 \r
+#include <PiPei.h>\r
+\r
+#include <Guid/MemoryAllocationHob.h>\r
+\r
+#include <Library/HobLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
 \r
 /**\r
   Returns the pointer to the HOB list.\r
@@ -167,6 +173,32 @@ GetFirstGuidHob (
   return GetNextGuidHob (Guid, HobList);\r
 }\r
 \r
+/**\r
+  Get the Boot Mode from the HOB list.\r
+\r
+  This function returns the system boot mode information from the \r
+  PHIT HOB in HOB list.\r
+\r
+  @param  VOID\r
+\r
+  @return The Boot Mode.\r
+\r
+**/\r
+EFI_BOOT_MODE\r
+EFIAPI\r
+GetBootModeHob (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS             Status;\r
+  EFI_BOOT_MODE          BootMode;\r
+\r
+  Status = PeiServicesGetBootMode (&BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return BootMode;\r
+}\r
+\r
 /**\r
   Adds a new HOB to the HOB List.\r
 \r
@@ -222,6 +254,9 @@ BuildModuleHob (
 {\r
   EFI_HOB_MEMORY_ALLOCATION_MODULE  *Hob;\r
 \r
+  ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&\r
+          ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));\r
+\r
   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));\r
 \r
   CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);\r
@@ -372,6 +407,39 @@ BuildFvHob (
   Hob->Length      = Length;\r
 }\r
 \r
+/**\r
+  Builds a EFI_HOB_TYPE_FV2 HOB.\r
+\r
+  This function builds a EFI_HOB_TYPE_FV2 HOB.\r
+  It can only be invoked during PEI phase;\r
+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
+  If there is no additional space for HOB creation, then ASSERT().\r
+\r
+  @param  BaseAddress   The base address of the Firmware Volume.\r
+  @param  Length        The size of the Firmware Volume in bytes.\r
+  @param  FvName       The name of the Firmware Volume.\r
+  @param  FileName      The name of the file.\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+BuildFv2Hob (\r
+  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,\r
+  IN          UINT64                      Length,\r
+  IN CONST    EFI_GUID                    *FvName,\r
+  IN CONST    EFI_GUID                    *FileName\r
+  )\r
+{\r
+  EFI_HOB_FIRMWARE_VOLUME2  *Hob;\r
+\r
+  Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r
+\r
+  Hob->BaseAddress = BaseAddress;\r
+  Hob->Length      = Length;\r
+  CopyGuid (&Hob->FvName, FvName);\r
+  CopyGuid (&Hob->FileName, FileName);\r
+}\r
+\r
 /**\r
   Builds a Capsule Volume HOB.\r
 \r
@@ -391,12 +459,7 @@ BuildCvHob (
   IN UINT64                      Length\r
   )\r
 {\r
-  EFI_HOB_CAPSULE_VOLUME  *Hob;\r
-\r
-  Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, sizeof (EFI_HOB_CAPSULE_VOLUME));\r
-\r
-  Hob->BaseAddress  = BaseAddress;\r
-  Hob->Length       = Length;\r
+  ASSERT (FALSE);\r
 }\r
 \r
 /**\r
@@ -452,12 +515,15 @@ BuildStackHob (
 {\r
   EFI_HOB_MEMORY_ALLOCATION_STACK  *Hob;\r
 \r
+  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
+          ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
+\r
   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r
 \r
   CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r
   Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
   Hob->AllocDescriptor.MemoryLength      = Length;\r
-  Hob->AllocDescriptor.MemoryType        = EfiConventionalMemory;\r
+  Hob->AllocDescriptor.MemoryType        = EfiBootServicesData;\r
 \r
   //\r
   // Zero the reserved space to match HOB spec\r
@@ -488,6 +554,9 @@ BuildBspStoreHob (
 {\r
   EFI_HOB_MEMORY_ALLOCATION_BSP_STORE  *Hob;\r
 \r
+  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
+          ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
+\r
   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));\r
 \r
   CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);\r
@@ -524,8 +593,11 @@ BuildMemoryAllocationHob (
 {\r
   EFI_HOB_MEMORY_ALLOCATION  *Hob;\r
 \r
+  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r
+          ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r
+  \r
   Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));\r
-\r
+  \r
   ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r
   Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
   Hob->AllocDescriptor.MemoryLength      = Length;\r