2 This module provide Hand-Off Block manipulation.
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Gets the pointer to the HOB List.
15 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
16 @param HobList Pointer to the HOB List.
18 @retval EFI_SUCCESS Get the pointer of HOB List
19 @retval EFI_NOT_AVAILABLE_YET the HOB List is not yet published
20 @retval EFI_INVALID_PARAMETER HobList is NULL (in debug mode)
26 IN CONST EFI_PEI_SERVICES
**PeiServices
,
30 PEI_CORE_INSTANCE
*PrivateData
;
33 // Only check this parameter in debug mode
37 if (HobList
== NULL
) {
38 return EFI_INVALID_PARAMETER
;
43 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
45 *HobList
= PrivateData
->HobList
.Raw
;
51 Add a new HOB to the HOB List.
53 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
54 @param Type Type of the new HOB.
55 @param Length Length of the new HOB to allocate.
56 @param Hob Pointer to the new HOB.
58 @return EFI_SUCCESS Success to create HOB.
59 @retval EFI_INVALID_PARAMETER if Hob is NULL
60 @retval EFI_NOT_AVAILABLE_YET if HobList is still not available.
61 @retval EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.
67 IN CONST EFI_PEI_SERVICES
**PeiServices
,
74 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
75 EFI_HOB_GENERIC_HEADER
*HobEnd
;
76 EFI_PHYSICAL_ADDRESS FreeMemory
;
78 Status
= PeiGetHobList (PeiServices
, Hob
);
79 if (EFI_ERROR (Status
)) {
86 // Check Length to avoid data overflow.
88 if (0x10000 - Length
<= 0x7) {
89 return EFI_INVALID_PARAMETER
;
92 Length
= (UINT16
)((Length
+ 0x7) & (~0x7));
94 FreeMemory
= HandOffHob
->EfiFreeMemoryTop
-
95 HandOffHob
->EfiFreeMemoryBottom
;
97 if (FreeMemory
< Length
) {
98 DEBUG ((DEBUG_ERROR
, "PeiCreateHob fail: Length - 0x%08x\n", (UINTN
)Length
));
99 DEBUG ((DEBUG_ERROR
, " FreeMemoryTop - 0x%08x\n", (UINTN
)HandOffHob
->EfiFreeMemoryTop
));
100 DEBUG ((DEBUG_ERROR
, " FreeMemoryBottom - 0x%08x\n", (UINTN
)HandOffHob
->EfiFreeMemoryBottom
));
101 return EFI_OUT_OF_RESOURCES
;
104 *Hob
= (VOID
*)(UINTN
)HandOffHob
->EfiEndOfHobList
;
105 ((EFI_HOB_GENERIC_HEADER
*)*Hob
)->HobType
= Type
;
106 ((EFI_HOB_GENERIC_HEADER
*)*Hob
)->HobLength
= Length
;
107 ((EFI_HOB_GENERIC_HEADER
*)*Hob
)->Reserved
= 0;
109 HobEnd
= (EFI_HOB_GENERIC_HEADER
*)((UINTN
)*Hob
+ Length
);
110 HandOffHob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HobEnd
;
112 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
113 HobEnd
->HobLength
= (UINT16
)sizeof (EFI_HOB_GENERIC_HEADER
);
114 HobEnd
->Reserved
= 0;
116 HandOffHob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HobEnd
;
122 Install SEC HOB data to the HOB List.
124 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
125 @param SecHobList Pointer to SEC HOB List.
127 @return EFI_SUCCESS Success to install SEC HOB data.
128 @retval EFI_OUT_OF_RESOURCES If there is no more memory to grow the Hoblist.
132 PeiInstallSecHobData (
133 IN CONST EFI_PEI_SERVICES
**PeiServices
,
134 IN EFI_HOB_GENERIC_HEADER
*SecHobList
138 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
139 EFI_PEI_HOB_POINTERS HobStart
;
140 EFI_PEI_HOB_POINTERS Hob
;
141 UINTN SecHobListLength
;
142 EFI_PHYSICAL_ADDRESS FreeMemory
;
143 EFI_HOB_GENERIC_HEADER
*HobEnd
;
146 Status
= PeiGetHobList (PeiServices
, (VOID
**)&HandOffHob
);
147 if (EFI_ERROR (Status
)) {
151 ASSERT (HandOffHob
!= NULL
);
153 HobStart
.Raw
= (UINT8
*)SecHobList
;
155 // The HobList must not contain a EFI_HOB_HANDOFF_INFO_TABLE HOB (PHIT) HOB.
157 ASSERT (HobStart
.Header
->HobType
!= EFI_HOB_TYPE_HANDOFF
);
159 // Calculate the SEC HOB List length,
160 // not including the terminated HOB(EFI_HOB_TYPE_END_OF_HOB_LIST).
162 for (Hob
.Raw
= HobStart
.Raw
; !END_OF_HOB_LIST (Hob
); Hob
.Raw
= GET_NEXT_HOB (Hob
)) {
165 SecHobListLength
= (UINTN
)Hob
.Raw
- (UINTN
)HobStart
.Raw
;
167 // The length must be 8-bytes aligned.
169 ASSERT ((SecHobListLength
& 0x7) == 0);
171 FreeMemory
= HandOffHob
->EfiFreeMemoryTop
-
172 HandOffHob
->EfiFreeMemoryBottom
;
174 if (FreeMemory
< SecHobListLength
) {
175 DEBUG ((DEBUG_ERROR
, "PeiInstallSecHobData fail: SecHobListLength - 0x%08x\n", SecHobListLength
));
176 DEBUG ((DEBUG_ERROR
, " FreeMemoryTop - 0x%08x\n", (UINTN
)HandOffHob
->EfiFreeMemoryTop
));
177 DEBUG ((DEBUG_ERROR
, " FreeMemoryBottom - 0x%08x\n", (UINTN
)HandOffHob
->EfiFreeMemoryBottom
));
178 return EFI_OUT_OF_RESOURCES
;
181 Hob
.Raw
= (UINT8
*)(UINTN
)HandOffHob
->EfiEndOfHobList
;
182 CopyMem (Hob
.Raw
, HobStart
.Raw
, SecHobListLength
);
184 HobEnd
= (EFI_HOB_GENERIC_HEADER
*)((UINTN
)Hob
.Raw
+ SecHobListLength
);
185 HandOffHob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HobEnd
;
187 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
188 HobEnd
->HobLength
= (UINT16
)sizeof (EFI_HOB_GENERIC_HEADER
);
189 HobEnd
->Reserved
= 0;
191 HandOffHob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HobEnd
;
198 Builds a Handoff Information Table HOB
200 @param BootMode - Current Bootmode
201 @param MemoryBegin - Start Memory Address.
202 @param MemoryLength - Length of Memory.
204 @return EFI_SUCCESS Always success to initialize HOB.
208 PeiCoreBuildHobHandoffInfoTable (
209 IN EFI_BOOT_MODE BootMode
,
210 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
211 IN UINT64 MemoryLength
214 EFI_HOB_HANDOFF_INFO_TABLE
*Hob
;
215 EFI_HOB_GENERIC_HEADER
*HobEnd
;
217 Hob
= (VOID
*)(UINTN
)MemoryBegin
;
218 HobEnd
= (EFI_HOB_GENERIC_HEADER
*)(Hob
+1);
219 Hob
->Header
.HobType
= EFI_HOB_TYPE_HANDOFF
;
220 Hob
->Header
.HobLength
= (UINT16
)sizeof (EFI_HOB_HANDOFF_INFO_TABLE
);
221 Hob
->Header
.Reserved
= 0;
223 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
224 HobEnd
->HobLength
= (UINT16
)sizeof (EFI_HOB_GENERIC_HEADER
);
225 HobEnd
->Reserved
= 0;
227 Hob
->Version
= EFI_HOB_HANDOFF_TABLE_VERSION
;
228 Hob
->BootMode
= BootMode
;
230 Hob
->EfiMemoryTop
= MemoryBegin
+ MemoryLength
;
231 Hob
->EfiMemoryBottom
= MemoryBegin
;
232 Hob
->EfiFreeMemoryTop
= MemoryBegin
+ MemoryLength
;
233 Hob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)(HobEnd
+ 1);
234 Hob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HobEnd
;