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