]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/Pei/Hob/Hob.c
MdeModulePkg/Core/Pei: Fix various typos
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Hob / Hob.c
... / ...
CommitLineData
1/** @file\r
2 This module provide Hand-Off Block manipulation.\r
3\r
4Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include "PeiMain.h"\r
10\r
11/**\r
12\r
13 Gets the pointer to the HOB List.\r
14\r
15 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
16 @param HobList Pointer to the HOB List.\r
17\r
18 @retval EFI_SUCCESS Get the pointer of HOB List\r
19 @retval EFI_NOT_AVAILABLE_YET the HOB List is not yet published\r
20 @retval EFI_INVALID_PARAMETER HobList is NULL (in debug mode)\r
21\r
22**/\r
23EFI_STATUS\r
24EFIAPI\r
25PeiGetHobList (\r
26 IN CONST EFI_PEI_SERVICES **PeiServices,\r
27 IN OUT VOID **HobList\r
28 )\r
29{\r
30 PEI_CORE_INSTANCE *PrivateData;\r
31\r
32 //\r
33 // Only check this parameter in debug mode\r
34 //\r
35\r
36 DEBUG_CODE_BEGIN ();\r
37 if (HobList == NULL) {\r
38 return EFI_INVALID_PARAMETER;\r
39 }\r
40 DEBUG_CODE_END ();\r
41\r
42 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
43\r
44 *HobList = PrivateData->HobList.Raw;\r
45\r
46 return EFI_SUCCESS;\r
47}\r
48\r
49\r
50/**\r
51 Add a new HOB to the HOB List.\r
52\r
53 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
54 @param Type Type of the new HOB.\r
55 @param Length Length of the new HOB to allocate.\r
56 @param Hob Pointer to the new HOB.\r
57\r
58 @return EFI_SUCCESS Success to create HOB.\r
59 @retval EFI_INVALID_PARAMETER if Hob is NULL\r
60 @retval EFI_NOT_AVAILABLE_YET if HobList is still not available.\r
61 @retval EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.\r
62\r
63**/\r
64EFI_STATUS\r
65EFIAPI\r
66PeiCreateHob (\r
67 IN CONST EFI_PEI_SERVICES **PeiServices,\r
68 IN UINT16 Type,\r
69 IN UINT16 Length,\r
70 IN OUT VOID **Hob\r
71 )\r
72{\r
73 EFI_STATUS Status;\r
74 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
75 EFI_HOB_GENERIC_HEADER *HobEnd;\r
76 EFI_PHYSICAL_ADDRESS FreeMemory;\r
77\r
78\r
79 Status = PeiGetHobList (PeiServices, Hob);\r
80 if (EFI_ERROR(Status)) {\r
81 return Status;\r
82 }\r
83\r
84 HandOffHob = *Hob;\r
85\r
86 //\r
87 // Check Length to avoid data overflow.\r
88 //\r
89 if (0x10000 - Length <= 0x7) {\r
90 return EFI_INVALID_PARAMETER;\r
91 }\r
92 Length = (UINT16)((Length + 0x7) & (~0x7));\r
93\r
94 FreeMemory = HandOffHob->EfiFreeMemoryTop -\r
95 HandOffHob->EfiFreeMemoryBottom;\r
96\r
97 if (FreeMemory < Length) {\r
98 DEBUG ((EFI_D_ERROR, "PeiCreateHob fail: Length - 0x%08x\n", (UINTN)Length));\r
99 DEBUG ((EFI_D_ERROR, " FreeMemoryTop - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryTop));\r
100 DEBUG ((EFI_D_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));\r
101 return EFI_OUT_OF_RESOURCES;\r
102 }\r
103\r
104 *Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;\r
105 ((EFI_HOB_GENERIC_HEADER*) *Hob)->HobType = Type;\r
106 ((EFI_HOB_GENERIC_HEADER*) *Hob)->HobLength = Length;\r
107 ((EFI_HOB_GENERIC_HEADER*) *Hob)->Reserved = 0;\r
108\r
109 HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN) *Hob + Length);\r
110 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
111\r
112 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
113 HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);\r
114 HobEnd->Reserved = 0;\r
115 HobEnd++;\r
116 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
117\r
118 return EFI_SUCCESS;\r
119}\r
120\r
121/**\r
122 Install SEC HOB data to the HOB List.\r
123\r
124 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
125 @param SecHobList Pointer to SEC HOB List.\r
126\r
127 @return EFI_SUCCESS Success to install SEC HOB data.\r
128 @retval EFI_OUT_OF_RESOURCES If there is no more memory to grow the Hoblist.\r
129\r
130**/\r
131EFI_STATUS\r
132PeiInstallSecHobData (\r
133 IN CONST EFI_PEI_SERVICES **PeiServices,\r
134 IN EFI_HOB_GENERIC_HEADER *SecHobList\r
135 )\r
136{\r
137 EFI_STATUS Status;\r
138 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
139 EFI_PEI_HOB_POINTERS HobStart;\r
140 EFI_PEI_HOB_POINTERS Hob;\r
141 UINTN SecHobListLength;\r
142 EFI_PHYSICAL_ADDRESS FreeMemory;\r
143 EFI_HOB_GENERIC_HEADER *HobEnd;\r
144\r
145 HandOffHob = NULL;\r
146 Status = PeiGetHobList (PeiServices, (VOID **) &HandOffHob);\r
147 if (EFI_ERROR(Status)) {\r
148 return Status;\r
149 }\r
150 ASSERT (HandOffHob != NULL);\r
151\r
152 HobStart.Raw = (UINT8 *) SecHobList;\r
153 //\r
154 // The HobList must not contain a EFI_HOB_HANDOFF_INFO_TABLE HOB (PHIT) HOB.\r
155 //\r
156 ASSERT (HobStart.Header->HobType != EFI_HOB_TYPE_HANDOFF);\r
157 //\r
158 // Calculate the SEC HOB List length,\r
159 // not including the terminated HOB(EFI_HOB_TYPE_END_OF_HOB_LIST).\r
160 //\r
161 for (Hob.Raw = HobStart.Raw; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob));\r
162 SecHobListLength = (UINTN) Hob.Raw - (UINTN) HobStart.Raw;\r
163 //\r
164 // The length must be 8-bytes aligned.\r
165 //\r
166 ASSERT ((SecHobListLength & 0x7) == 0);\r
167\r
168 FreeMemory = HandOffHob->EfiFreeMemoryTop -\r
169 HandOffHob->EfiFreeMemoryBottom;\r
170\r
171 if (FreeMemory < SecHobListLength) {\r
172 DEBUG ((DEBUG_ERROR, "PeiInstallSecHobData fail: SecHobListLength - 0x%08x\n", SecHobListLength));\r
173 DEBUG ((DEBUG_ERROR, " FreeMemoryTop - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryTop));\r
174 DEBUG ((DEBUG_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));\r
175 return EFI_OUT_OF_RESOURCES;\r
176 }\r
177\r
178 Hob.Raw = (UINT8 *) (UINTN) HandOffHob->EfiEndOfHobList;\r
179 CopyMem (Hob.Raw, HobStart.Raw, SecHobListLength);\r
180\r
181 HobEnd = (EFI_HOB_GENERIC_HEADER *) ((UINTN) Hob.Raw + SecHobListLength);\r
182 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
183\r
184 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
185 HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);\r
186 HobEnd->Reserved = 0;\r
187 HobEnd++;\r
188 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
189\r
190 return EFI_SUCCESS;\r
191}\r
192\r
193/**\r
194\r
195 Builds a Handoff Information Table HOB\r
196\r
197 @param BootMode - Current Bootmode\r
198 @param MemoryBegin - Start Memory Address.\r
199 @param MemoryLength - Length of Memory.\r
200\r
201 @return EFI_SUCCESS Always success to initialize HOB.\r
202\r
203**/\r
204EFI_STATUS\r
205PeiCoreBuildHobHandoffInfoTable (\r
206 IN EFI_BOOT_MODE BootMode,\r
207 IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r
208 IN UINT64 MemoryLength\r
209 )\r
210{\r
211 EFI_HOB_HANDOFF_INFO_TABLE *Hob;\r
212 EFI_HOB_GENERIC_HEADER *HobEnd;\r
213\r
214 Hob = (VOID *)(UINTN)MemoryBegin;\r
215 HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1);\r
216 Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;\r
217 Hob->Header.HobLength = (UINT16) sizeof (EFI_HOB_HANDOFF_INFO_TABLE);\r
218 Hob->Header.Reserved = 0;\r
219\r
220 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
221 HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);\r
222 HobEnd->Reserved = 0;\r
223\r
224 Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;\r
225 Hob->BootMode = BootMode;\r
226\r
227 Hob->EfiMemoryTop = MemoryBegin + MemoryLength;\r
228 Hob->EfiMemoryBottom = MemoryBegin;\r
229 Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength;\r
230 Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd + 1);\r
231 Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
232\r
233 return EFI_SUCCESS;\r
234}\r