]> git.proxmox.com Git - mirror_edk2.git/blame - StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Common.c
StandaloneMmPkg: StandaloneMmCoreHobLib: Extend support for x64 Mm Core
[mirror_edk2.git] / StandaloneMmPkg / Library / StandaloneMmCoreHobLib / Common.c
CommitLineData
f6c488b7
KQ
1/** @file\r
2 HOB Library implementation for Standalone MM Core.\r
3\r
4Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
5Copyright (c) 2017 - 2018, ARM Limited. All rights reserved.<BR>\r
6\r
7SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#include <PiMm.h>\r
12\r
13#include <Library/HobLib.h>\r
14#include <Library/DebugLib.h>\r
15#include <Library/BaseMemoryLib.h>\r
16#include <Library/StandaloneMmCoreEntryPoint.h>\r
17\r
18#include <Guid/MemoryAllocationHob.h>\r
19\r
20/**\r
21 Returns the pointer to the HOB list.\r
22\r
23 This function returns the pointer to first HOB in the list.\r
24 If the pointer to the HOB list is NULL, then ASSERT().\r
25\r
26 @return The pointer to the HOB list.\r
27\r
28**/\r
29VOID *\r
30EFIAPI\r
31GetHobList (\r
32 VOID\r
33 )\r
34{\r
35 ASSERT (gHobList != NULL);\r
36 return gHobList;\r
37}\r
38\r
39/**\r
40 Returns the next instance of a HOB type from the starting HOB.\r
41\r
42 This function searches the first instance of a HOB type from the starting HOB pointer.\r
43 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
44 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
45 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
46 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
47\r
48 If HobStart is NULL, then ASSERT().\r
49\r
50 @param Type The HOB type to return.\r
51 @param HobStart The starting HOB pointer to search from.\r
52\r
53 @return The next instance of a HOB type from the starting HOB.\r
54\r
55**/\r
56VOID *\r
57EFIAPI\r
58GetNextHob (\r
59 IN UINT16 Type,\r
60 IN CONST VOID *HobStart\r
61 )\r
62{\r
63 EFI_PEI_HOB_POINTERS Hob;\r
64\r
65 ASSERT (HobStart != NULL);\r
66\r
67 Hob.Raw = (UINT8 *) HobStart;\r
68 //\r
69 // Parse the HOB list until end of list or matching type is found.\r
70 //\r
71 while (!END_OF_HOB_LIST (Hob)) {\r
72 if (Hob.Header->HobType == Type) {\r
73 return Hob.Raw;\r
74 }\r
75 Hob.Raw = GET_NEXT_HOB (Hob);\r
76 }\r
77 return NULL;\r
78}\r
79\r
80/**\r
81 Returns the first instance of a HOB type among the whole HOB list.\r
82\r
83 This function searches the first instance of a HOB type among the whole HOB list.\r
84 If there does not exist such HOB type in the HOB list, it will return NULL.\r
85\r
86 If the pointer to the HOB list is NULL, then ASSERT().\r
87\r
88 @param Type The HOB type to return.\r
89\r
90 @return The next instance of a HOB type from the starting HOB.\r
91\r
92**/\r
93VOID *\r
94EFIAPI\r
95GetFirstHob (\r
96 IN UINT16 Type\r
97 )\r
98{\r
99 VOID *HobList;\r
100\r
101 HobList = GetHobList ();\r
102 return GetNextHob (Type, HobList);\r
103}\r
104\r
105/**\r
106 Returns the next instance of the matched GUID HOB from the starting HOB.\r
107\r
108 This function searches the first instance of a HOB from the starting HOB pointer.\r
109 Such HOB should satisfy two conditions:\r
110 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION, and its GUID Name equals to the input Guid.\r
111 If such a HOB from the starting HOB pointer does not exist, it will return NULL.\r
112 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
113 to extract the data section and its size information, respectively.\r
114 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
115 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
116 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
117\r
118 If Guid is NULL, then ASSERT().\r
119 If HobStart is NULL, then ASSERT().\r
120\r
121 @param Guid The GUID to match with in the HOB list.\r
122 @param HobStart A pointer to a Guid.\r
123\r
124 @return The next instance of the matched GUID HOB from the starting HOB.\r
125\r
126**/\r
127VOID *\r
128EFIAPI\r
129GetNextGuidHob (\r
130 IN CONST EFI_GUID *Guid,\r
131 IN CONST VOID *HobStart\r
132 )\r
133{\r
134 EFI_PEI_HOB_POINTERS GuidHob;\r
135\r
136 GuidHob.Raw = (UINT8 *) HobStart;\r
137 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
138 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
139 break;\r
140 }\r
141 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
142 }\r
143 return GuidHob.Raw;\r
144}\r
145\r
146/**\r
147 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
148\r
149 This function searches the first instance of a HOB among the whole HOB list.\r
150 Such HOB should satisfy two conditions:\r
151 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
152 If such a HOB from the starting HOB pointer does not exist, it will return NULL.\r
153 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
154 to extract the data section and its size information, respectively.\r
155\r
156 If the pointer to the HOB list is NULL, then ASSERT().\r
157 If Guid is NULL, then ASSERT().\r
158\r
159 @param Guid The GUID to match with in the HOB list.\r
160\r
161 @return The first instance of the matched GUID HOB among the whole HOB list.\r
162\r
163**/\r
164VOID *\r
165EFIAPI\r
166GetFirstGuidHob (\r
167 IN CONST EFI_GUID *Guid\r
168 )\r
169{\r
170 VOID *HobList;\r
171\r
172 HobList = GetHobList ();\r
173 return GetNextGuidHob (Guid, HobList);\r
174}\r
175\r
176/**\r
177 Get the system boot mode from the HOB list.\r
178\r
179 This function returns the system boot mode information from the\r
180 PHIT HOB in HOB list.\r
181\r
182 If the pointer to the HOB list is NULL, then ASSERT().\r
183\r
184 @param VOID\r
185\r
186 @return The Boot Mode.\r
187\r
188**/\r
189EFI_BOOT_MODE\r
190EFIAPI\r
191GetBootModeHob (\r
192 VOID\r
193 )\r
194{\r
195 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
196\r
197 HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();\r
198\r
199 return HandOffHob->BootMode;\r
200}\r
201\r
202\r
203/**\r
204 Builds a HOB that describes a chunk of system memory with Owner GUID.\r
205\r
206 This function builds a HOB that describes a chunk of system memory.\r
207 If there is no additional space for HOB creation, then ASSERT().\r
208\r
209 @param ResourceType The type of resource described by this HOB.\r
210 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
211 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
212 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
213 @param OwnerGUID GUID for the owner of this resource.\r
214\r
215**/\r
216VOID\r
217EFIAPI\r
218BuildResourceDescriptorWithOwnerHob (\r
219 IN EFI_RESOURCE_TYPE ResourceType,\r
220 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
221 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
222 IN UINT64 NumberOfBytes,\r
223 IN EFI_GUID *OwnerGUID\r
224 )\r
225{\r
226 ASSERT (FALSE);\r
227}\r
228\r
229/**\r
230 Builds a Capsule Volume HOB.\r
231\r
232 This function builds a Capsule Volume HOB.\r
233 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
234 If there is no additional space for HOB creation, then ASSERT().\r
235\r
236 @param BaseAddress The base address of the Capsule Volume.\r
237 @param Length The size of the Capsule Volume in bytes.\r
238\r
239**/\r
240VOID\r
241EFIAPI\r
242BuildCvHob (\r
243 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
244 IN UINT64 Length\r
245 )\r
246{\r
247 ASSERT (FALSE);\r
248}\r
249\r
250\r
251/**\r
252 Builds a HOB for the BSP store.\r
253\r
254 This function builds a HOB for BSP store.\r
255 If there is no additional space for HOB creation, then ASSERT().\r
256\r
257 @param BaseAddress The 64 bit physical address of the BSP.\r
258 @param Length The length of the BSP store in bytes.\r
259 @param MemoryType Type of memory allocated by this HOB.\r
260\r
261**/\r
262VOID\r
263EFIAPI\r
264BuildBspStoreHob (\r
265 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
266 IN UINT64 Length,\r
267 IN EFI_MEMORY_TYPE MemoryType\r
268 )\r
269{\r
270 ASSERT (FALSE);\r
271}\r
272\r
273/**\r
274 Builds a HOB for the Stack.\r
275\r
276 This function builds a HOB for the stack.\r
277 If there is no additional space for HOB creation, then ASSERT().\r
278\r
279 @param BaseAddress The 64 bit physical address of the Stack.\r
280 @param Length The length of the stack in bytes.\r
281\r
282**/\r
283VOID\r
284EFIAPI\r
285BuildStackHob (\r
286 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
287 IN UINT64 Length\r
288 )\r
289{\r
290 ASSERT (FALSE);\r
291}\r