]> git.proxmox.com Git - mirror_edk2.git/blame - StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Common.c
StandaloneMmPkg: Apply uncrustify changes
[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
91415a36
MK
59 IN UINT16 Type,\r
60 IN CONST VOID *HobStart\r
f6c488b7
KQ
61 )\r
62{\r
63 EFI_PEI_HOB_POINTERS Hob;\r
64\r
65 ASSERT (HobStart != NULL);\r
66\r
91415a36 67 Hob.Raw = (UINT8 *)HobStart;\r
f6c488b7
KQ
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
91415a36 75\r
f6c488b7
KQ
76 Hob.Raw = GET_NEXT_HOB (Hob);\r
77 }\r
91415a36 78\r
f6c488b7
KQ
79 return NULL;\r
80}\r
81\r
82/**\r
83 Returns the first instance of a HOB type among the whole HOB list.\r
84\r
85 This function searches the first instance of a HOB type among the whole HOB list.\r
86 If there does not exist such HOB type in the HOB list, it will return NULL.\r
87\r
88 If the pointer to the HOB list is NULL, then ASSERT().\r
89\r
90 @param Type The HOB type to return.\r
91\r
92 @return The next instance of a HOB type from the starting HOB.\r
93\r
94**/\r
95VOID *\r
96EFIAPI\r
97GetFirstHob (\r
91415a36 98 IN UINT16 Type\r
f6c488b7
KQ
99 )\r
100{\r
91415a36 101 VOID *HobList;\r
f6c488b7
KQ
102\r
103 HobList = GetHobList ();\r
104 return GetNextHob (Type, HobList);\r
105}\r
106\r
107/**\r
108 Returns the next instance of the matched GUID HOB from the starting HOB.\r
109\r
110 This function searches the first instance of a HOB from the starting HOB pointer.\r
111 Such HOB should satisfy two conditions:\r
112 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION, and its GUID Name equals to the input Guid.\r
113 If such a HOB from the starting HOB pointer does not exist, it will return NULL.\r
114 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
115 to extract the data section and its size information, respectively.\r
116 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
117 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
118 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
119\r
120 If Guid is NULL, then ASSERT().\r
121 If HobStart is NULL, then ASSERT().\r
122\r
123 @param Guid The GUID to match with in the HOB list.\r
124 @param HobStart A pointer to a Guid.\r
125\r
126 @return The next instance of the matched GUID HOB from the starting HOB.\r
127\r
128**/\r
129VOID *\r
130EFIAPI\r
131GetNextGuidHob (\r
91415a36
MK
132 IN CONST EFI_GUID *Guid,\r
133 IN CONST VOID *HobStart\r
f6c488b7
KQ
134 )\r
135{\r
136 EFI_PEI_HOB_POINTERS GuidHob;\r
137\r
91415a36 138 GuidHob.Raw = (UINT8 *)HobStart;\r
f6c488b7
KQ
139 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
140 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
141 break;\r
142 }\r
91415a36 143\r
f6c488b7
KQ
144 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
145 }\r
91415a36 146\r
f6c488b7
KQ
147 return GuidHob.Raw;\r
148}\r
149\r
150/**\r
151 Returns the first instance of the matched GUID HOB among the whole HOB list.\r
152\r
153 This function searches the first instance of a HOB among the whole HOB list.\r
154 Such HOB should satisfy two conditions:\r
155 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
156 If such a HOB from the starting HOB pointer does not exist, it will return NULL.\r
157 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
158 to extract the data section and its size information, respectively.\r
159\r
160 If the pointer to the HOB list is NULL, then ASSERT().\r
161 If Guid is NULL, then ASSERT().\r
162\r
163 @param Guid The GUID to match with in the HOB list.\r
164\r
165 @return The first instance of the matched GUID HOB among the whole HOB list.\r
166\r
167**/\r
168VOID *\r
169EFIAPI\r
170GetFirstGuidHob (\r
91415a36 171 IN CONST EFI_GUID *Guid\r
f6c488b7
KQ
172 )\r
173{\r
91415a36 174 VOID *HobList;\r
f6c488b7
KQ
175\r
176 HobList = GetHobList ();\r
177 return GetNextGuidHob (Guid, HobList);\r
178}\r
179\r
180/**\r
181 Get the system boot mode from the HOB list.\r
182\r
183 This function returns the system boot mode information from the\r
184 PHIT HOB in HOB list.\r
185\r
186 If the pointer to the HOB list is NULL, then ASSERT().\r
187\r
188 @param VOID\r
189\r
190 @return The Boot Mode.\r
191\r
192**/\r
193EFI_BOOT_MODE\r
194EFIAPI\r
195GetBootModeHob (\r
196 VOID\r
197 )\r
198{\r
91415a36 199 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
f6c488b7 200\r
91415a36 201 HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *)GetHobList ();\r
f6c488b7
KQ
202\r
203 return HandOffHob->BootMode;\r
204}\r
205\r
f6c488b7
KQ
206/**\r
207 Builds a HOB that describes a chunk of system memory with Owner GUID.\r
208\r
209 This function builds a HOB that describes a chunk of system memory.\r
210 If there is no additional space for HOB creation, then ASSERT().\r
211\r
212 @param ResourceType The type of resource described by this HOB.\r
213 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
214 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
215 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
216 @param OwnerGUID GUID for the owner of this resource.\r
217\r
218**/\r
219VOID\r
220EFIAPI\r
221BuildResourceDescriptorWithOwnerHob (\r
222 IN EFI_RESOURCE_TYPE ResourceType,\r
223 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
224 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
225 IN UINT64 NumberOfBytes,\r
226 IN EFI_GUID *OwnerGUID\r
227 )\r
228{\r
229 ASSERT (FALSE);\r
230}\r
231\r
232/**\r
233 Builds a Capsule Volume HOB.\r
234\r
235 This function builds a Capsule Volume HOB.\r
236 If the platform does not support Capsule Volume HOBs, then ASSERT().\r
237 If there is no additional space for HOB creation, then ASSERT().\r
238\r
239 @param BaseAddress The base address of the Capsule Volume.\r
240 @param Length The size of the Capsule Volume in bytes.\r
241\r
242**/\r
243VOID\r
244EFIAPI\r
245BuildCvHob (\r
91415a36
MK
246 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
247 IN UINT64 Length\r
f6c488b7
KQ
248 )\r
249{\r
250 ASSERT (FALSE);\r
251}\r
252\r
f6c488b7
KQ
253/**\r
254 Builds a HOB for the BSP store.\r
255\r
256 This function builds a HOB for BSP store.\r
257 If there is no additional space for HOB creation, then ASSERT().\r
258\r
259 @param BaseAddress The 64 bit physical address of the BSP.\r
260 @param Length The length of the BSP store in bytes.\r
261 @param MemoryType Type of memory allocated by this HOB.\r
262\r
263**/\r
264VOID\r
265EFIAPI\r
266BuildBspStoreHob (\r
91415a36
MK
267 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
268 IN UINT64 Length,\r
269 IN EFI_MEMORY_TYPE MemoryType\r
f6c488b7
KQ
270 )\r
271{\r
272 ASSERT (FALSE);\r
273}\r
274\r
275/**\r
276 Builds a HOB for the Stack.\r
277\r
278 This function builds a HOB for the stack.\r
279 If there is no additional space for HOB creation, then ASSERT().\r
280\r
281 @param BaseAddress The 64 bit physical address of the Stack.\r
282 @param Length The length of the stack in bytes.\r
283\r
284**/\r
285VOID\r
286EFIAPI\r
287BuildStackHob (\r
91415a36
MK
288 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
289 IN UINT64 Length\r
f6c488b7
KQ
290 )\r
291{\r
292 ASSERT (FALSE);\r
293}\r