-/*++\r
+/** @file\r
+ This module provide Hand-Off Block manipulation.\r
\r
-Copyright (c) 2006, Intel Corporation \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
-http://opensource.org/licenses/bsd-license.php \r
- \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
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
-Module Name:\r
+**/\r
\r
- Hob.c\r
+#include "PeiMain.h"\r
\r
-Abstract:\r
+/**\r
\r
- EFI PEI Core HOB services\r
+ Gets the pointer to the HOB List.\r
\r
---*/\r
+ @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+ @param HobList Pointer to the HOB List.\r
\r
-#include <PeiMain.h>\r
+ @retval EFI_SUCCESS Get the pointer of HOB List\r
+ @retval EFI_NOT_AVAILABLE_YET the HOB List is not yet published\r
+ @retval EFI_INVALID_PARAMETER HobList is NULL (in debug mode)\r
\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiGetHobList (\r
- IN EFI_PEI_SERVICES **PeiServices,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
IN OUT VOID **HobList\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Gets the pointer to the HOB List.\r
-\r
-Arguments:\r
-\r
- PeiServices - The PEI core services table.\r
- HobList - Pointer to the HOB List.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Get the pointer of HOB List\r
- EFI_NOT_AVAILABLE_YET - the HOB List is not yet published\r
- EFI_INVALID_PARAMETER - HobList is NULL (in debug mode)\r
- \r
---*/\r
{\r
PEI_CORE_INSTANCE *PrivateData;\r
\r
- \r
//\r
// Only check this parameter in debug mode\r
//\r
- \r
- DEBUG_CODE_BEGIN (); \r
+\r
+ DEBUG_CODE_BEGIN ();\r
if (HobList == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
DEBUG_CODE_END ();\r
- \r
+\r
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
\r
*HobList = PrivateData->HobList.Raw;\r
\r
-\r
- return EFI_SUCCESS; \r
+ return EFI_SUCCESS;\r
}\r
\r
\r
+/**\r
+ Add a new HOB to the HOB List.\r
+\r
+ @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+ @param Type Type of the new HOB.\r
+ @param Length Length of the new HOB to allocate.\r
+ @param Hob Pointer to the new HOB.\r
+\r
+ @return EFI_SUCCESS Success to create HOB.\r
+ @retval EFI_INVALID_PARAMETER if Hob is NULL\r
+ @retval EFI_NOT_AVAILABLE_YET if HobList is still not available.\r
+ @retval EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.\r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiCreateHob (\r
- IN EFI_PEI_SERVICES **PeiServices,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
IN UINT16 Type,\r
IN UINT16 Length,\r
IN OUT VOID **Hob\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Add a new HOB to the HOB List.\r
-\r
-Arguments:\r
-\r
- PeiServices - The PEI core services table.\r
- Type - Type of the new HOB.\r
- Length - Length of the new HOB to allocate.\r
- Hob - Pointer to the new HOB.\r
-\r
-Returns:\r
-\r
- Status - EFI_SUCCESS\r
- - EFI_INVALID_PARAMETER if Hob is NULL\r
- - EFI_NOT_AVAILABLE_YET if HobList is still not available.\r
- - EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.\r
- \r
---*/\r
{\r
EFI_STATUS Status;\r
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
\r
HandOffHob = *Hob;\r
\r
+ //\r
+ // Check Length to avoid data overflow.\r
+ //\r
+ if (0x10000 - Length <= 0x7) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
Length = (UINT16)((Length + 0x7) & (~0x7));\r
\r
FreeMemory = HandOffHob->EfiFreeMemoryTop -\r
DEBUG ((EFI_D_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));\r
return EFI_OUT_OF_RESOURCES;\r
}\r
- \r
+\r
*Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;\r
((EFI_HOB_GENERIC_HEADER*) *Hob)->HobType = Type;\r
((EFI_HOB_GENERIC_HEADER*) *Hob)->HobLength = Length;\r
\r
HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN) *Hob + Length);\r
HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
- \r
+\r
HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
- HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r
+ HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);\r
HobEnd->Reserved = 0;\r
HobEnd++;\r
HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
\r
-\r
- return EFI_SUCCESS; \r
+ return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Install SEC HOB data to the HOB List.\r
+\r
+ @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+ @param SecHobList Pointer to SEC HOB List.\r
+\r
+ @return EFI_SUCCESS Success to install SEC HOB data.\r
+ @retval EFI_OUT_OF_RESOURCES If there is no more memory to grow the Hoblist.\r
\r
+**/\r
EFI_STATUS\r
-PeiCoreBuildHobHandoffInfoTable (\r
- IN EFI_BOOT_MODE BootMode,\r
- IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r
- IN UINT64 MemoryLength\r
+PeiInstallSecHobData (\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN EFI_HOB_GENERIC_HEADER *SecHobList\r
)\r
-/*++\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
+ EFI_PEI_HOB_POINTERS HobStart;\r
+ EFI_PEI_HOB_POINTERS Hob;\r
+ UINTN SecHobListLength;\r
+ EFI_PHYSICAL_ADDRESS FreeMemory;\r
+ EFI_HOB_GENERIC_HEADER *HobEnd;\r
+\r
+ HandOffHob = NULL;\r
+ Status = PeiGetHobList (PeiServices, (VOID **) &HandOffHob);\r
+ if (EFI_ERROR(Status)) {\r
+ return Status;\r
+ }\r
+ ASSERT (HandOffHob != NULL);\r
+\r
+ HobStart.Raw = (UINT8 *) SecHobList;\r
+ //\r
+ // The HobList must not contain a EFI_HOB_HANDOFF_INFO_TABLE HOB (PHIT) HOB.\r
+ //\r
+ ASSERT (HobStart.Header->HobType != EFI_HOB_TYPE_HANDOFF);\r
+ //\r
+ // Calculate the SEC HOB List length,\r
+ // not including the terminated HOB(EFI_HOB_TYPE_END_OF_HOB_LIST).\r
+ //\r
+ for (Hob.Raw = HobStart.Raw; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob));\r
+ SecHobListLength = (UINTN) Hob.Raw - (UINTN) HobStart.Raw;\r
+ //\r
+ // The length must be 8-bytes aligned.\r
+ //\r
+ ASSERT ((SecHobListLength & 0x7) == 0);\r
\r
-Routine Description:\r
+ FreeMemory = HandOffHob->EfiFreeMemoryTop -\r
+ HandOffHob->EfiFreeMemoryBottom;\r
\r
- Builds a Handoff Information Table HOB\r
+ if (FreeMemory < SecHobListLength) {\r
+ DEBUG ((DEBUG_ERROR, "PeiInstallSecHobData fail: SecHobListLength - 0x%08x\n", SecHobListLength));\r
+ DEBUG ((DEBUG_ERROR, " FreeMemoryTop - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryTop));\r
+ DEBUG ((DEBUG_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ Hob.Raw = (UINT8 *) (UINTN) HandOffHob->EfiEndOfHobList;\r
+ CopyMem (Hob.Raw, HobStart.Raw, SecHobListLength);\r
+\r
+ HobEnd = (EFI_HOB_GENERIC_HEADER *) ((UINTN) Hob.Raw + SecHobListLength);\r
+ HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
+\r
+ HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
+ HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);\r
+ HobEnd->Reserved = 0;\r
+ HobEnd++;\r
+ HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
\r
-Arguments:\r
+/**\r
\r
- BootMode - Current Bootmode\r
- MemoryBegin - Start Memory Address.\r
- MemoryLength - Length of Memory.\r
+ Builds a Handoff Information Table HOB\r
\r
-Returns:\r
+ @param BootMode - Current Bootmode\r
+ @param MemoryBegin - Start Memory Address.\r
+ @param MemoryLength - Length of Memory.\r
\r
- EFI_SUCCESS\r
+ @return EFI_SUCCESS Always success to initialize HOB.\r
\r
---*/\r
+**/\r
+EFI_STATUS\r
+PeiCoreBuildHobHandoffInfoTable (\r
+ IN EFI_BOOT_MODE BootMode,\r
+ IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r
+ IN UINT64 MemoryLength\r
+ )\r
{\r
EFI_HOB_HANDOFF_INFO_TABLE *Hob;\r
EFI_HOB_GENERIC_HEADER *HobEnd;\r
\r
- Hob = (VOID *)(UINTN)MemoryBegin;\r
- HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1);\r
- Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;\r
- Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);\r
- Hob->Header.Reserved = 0;\r
- \r
- HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
- HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r
- HobEnd->Reserved = 0;\r
+ Hob = (VOID *)(UINTN)MemoryBegin;\r
+ HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1);\r
+ Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;\r
+ Hob->Header.HobLength = (UINT16) sizeof (EFI_HOB_HANDOFF_INFO_TABLE);\r
+ Hob->Header.Reserved = 0;\r
+\r
+ HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
+ HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);\r
+ HobEnd->Reserved = 0;\r
\r
Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;\r
Hob->BootMode = BootMode;\r
- \r
+\r
Hob->EfiMemoryTop = MemoryBegin + MemoryLength;\r
Hob->EfiMemoryBottom = MemoryBegin;\r
Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength;\r
- Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd+1);\r
+ Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd + 1);\r
Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
\r
return EFI_SUCCESS;\r