]>
Commit | Line | Data |
---|---|---|
08e4b3cf | 1 | /** @file\r |
2 | HII Library implementation that uses DXE protocols and services.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "InternalHiiLib.h"\r | |
16 | \r | |
17 | CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt = NULL;\r | |
18 | CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt = NULL;\r | |
19 | \r | |
20 | /**\r | |
21 | This function locate Hii relative protocols for later usage.\r | |
22 | \r | |
23 | The constructor function caches the protocol pointer of HII Database Protocol\r | |
24 | and Hii String Protocol.\r | |
25 | \r | |
26 | It will ASSERT() if either of the protocol can't be located.\r | |
27 | \r | |
28 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
29 | @param SystemTable A pointer to the EFI System Table.\r | |
30 | \r | |
31 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
32 | \r | |
33 | **/\r | |
34 | EFI_STATUS\r | |
35 | EFIAPI\r | |
36 | HiiLibConstructor (\r | |
37 | IN EFI_HANDLE ImageHandle,\r | |
38 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
39 | )\r | |
40 | {\r | |
41 | EFI_STATUS Status;\r | |
42 | \r | |
43 | Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &mHiiDatabaseProt);\r | |
44 | ASSERT_EFI_ERROR (Status);\r | |
45 | \r | |
46 | Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &mHiiStringProt);\r | |
47 | ASSERT_EFI_ERROR (Status);\r | |
48 | \r | |
49 | return EFI_SUCCESS;\r | |
50 | }\r | |
51 | \r | |
52 | \r | |
53 | \r | |
54 | /**\r | |
55 | This funciton build the package list based on the package number,\r | |
56 | the GUID of the package list and the list of pointer which point to\r | |
57 | package header that defined by UEFI VFR compiler and StringGather\r | |
58 | tool.\r | |
59 | \r | |
60 | #pragma pack (push, 1)\r | |
61 | typedef struct {\r | |
62 | UINT32 BinaryLength;\r | |
63 | EFI_HII_PACKAGE_HEADER PackageHeader;\r | |
64 | } EDKII_AUTOGEN_PACKAGES_HEADER;\r | |
65 | #pragma pack (pop)\r | |
66 | \r | |
67 | If there is not enough resource for the new package list,\r | |
68 | the function will ASSERT.\r | |
69 | \r | |
70 | @param NumberOfPackages The number of packages be \r | |
71 | @param GuidId The GUID for the package list to be generated.\r | |
72 | @param Marker The variable argument list. Each entry represent a specific package header that is\r | |
73 | generated by VFR compiler and StrGather tool. The first 4 bytes is a UINT32 value\r | |
74 | that indicate the overall length of the package.\r | |
75 | \r | |
76 | @return The pointer to the package list header.\r | |
77 | \r | |
78 | **/\r | |
79 | EFI_HII_PACKAGE_LIST_HEADER *\r | |
80 | InternalHiiLibPreparePackages (\r | |
81 | IN UINTN NumberOfPackages,\r | |
82 | IN CONST EFI_GUID *GuidId,\r | |
83 | IN VA_LIST Marker\r | |
84 | )\r | |
85 | {\r | |
86 | EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r | |
87 | UINT8 *PackageListData;\r | |
88 | UINT32 PackageListLength;\r | |
89 | UINT32 PackageLength;\r | |
90 | EFI_HII_PACKAGE_HEADER PackageHeader;\r | |
91 | UINT8 *PackageArray;\r | |
92 | UINTN Index;\r | |
93 | VA_LIST MarkerBackup;\r | |
94 | \r | |
95 | PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r | |
96 | \r | |
97 | MarkerBackup = Marker;\r | |
98 | \r | |
99 | //\r | |
dfe687ca | 100 | // Count the length of the final package list.\r |
08e4b3cf | 101 | //\r |
102 | for (Index = 0; Index < NumberOfPackages; Index++) {\r | |
103 | CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32));\r | |
104 | //\r | |
105 | // Do not count the BinaryLength field.\r | |
106 | //\r | |
107 | PackageListLength += (PackageLength - sizeof (UINT32));\r | |
108 | }\r | |
109 | \r | |
110 | //\r | |
dfe687ca | 111 | // Include the length of EFI_HII_PACKAGE_END\r |
08e4b3cf | 112 | //\r |
113 | PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER);\r | |
114 | PackageListHeader = AllocateZeroPool (PackageListLength);\r | |
115 | ASSERT (PackageListHeader != NULL);\r | |
116 | \r | |
117 | CopyGuid (&PackageListHeader->PackageListGuid, GuidId);\r | |
118 | PackageListHeader->PackageLength = PackageListLength;\r | |
119 | \r | |
120 | PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r | |
121 | \r | |
122 | Marker = MarkerBackup;\r | |
123 | //\r | |
124 | // Prepare the final package list.\r | |
125 | //\r | |
126 | for (Index = 0; Index < NumberOfPackages; Index++) {\r | |
127 | PackageArray = (UINT8 *) VA_ARG (Marker, VOID *);\r | |
128 | //\r | |
129 | // CopyMem is used for UINT32 to cover the unaligned address access.\r | |
130 | //\r | |
131 | CopyMem (&PackageLength, PackageArray, sizeof (UINT32));\r | |
132 | PackageLength -= sizeof (UINT32);\r | |
133 | PackageArray += sizeof (UINT32);\r | |
134 | CopyMem (PackageListData, PackageArray, PackageLength);\r | |
135 | PackageListData += PackageLength;\r | |
136 | }\r | |
137 | \r | |
138 | //\r | |
139 | // Append EFI_HII_PACKAGE_END\r | |
140 | //\r | |
141 | PackageHeader.Type = EFI_HII_PACKAGE_END;\r | |
142 | PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER);\r | |
143 | CopyMem (PackageListData, &PackageHeader, PackageHeader.Length);\r | |
144 | \r | |
145 | return PackageListHeader;\r | |
146 | }\r | |
147 | \r | |
148 | /**\r | |
149 | Assemble EFI_HII_PACKAGE_LIST according to the passed in packages.\r | |
150 | \r | |
151 | If GuidId is NULL, then ASSERT.\r | |
152 | If not enough resource to complete the operation, then ASSERT.\r | |
153 | \r | |
154 | @param NumberOfPackages Number of packages.\r | |
155 | @param GuidId Package GUID.\r | |
156 | @param ... Variable argument list for packages to be assembled.\r | |
157 | \r | |
158 | @return Pointer of EFI_HII_PACKAGE_LIST_HEADER.\r | |
159 | \r | |
160 | **/\r | |
161 | EFI_HII_PACKAGE_LIST_HEADER *\r | |
162 | EFIAPI\r | |
163 | HiiLibPreparePackageList (\r | |
164 | IN UINTN NumberOfPackages,\r | |
165 | IN CONST EFI_GUID *GuidId,\r | |
166 | ...\r | |
167 | )\r | |
168 | {\r | |
169 | EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r | |
170 | VA_LIST Marker;\r | |
171 | \r | |
172 | ASSERT (GuidId != NULL);\r | |
173 | \r | |
174 | VA_START (Marker, GuidId);\r | |
175 | PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Marker);\r | |
176 | VA_END (Marker);\r | |
177 | \r | |
178 | return PackageListHeader;\r | |
179 | }\r | |
180 | \r | |
181 | \r | |
182 | /**\r | |
183 | This function allocates pool for an EFI_HII_PACKAGE_LIST structure\r | |
184 | with additional space that is big enough to host all packages described by the variable \r | |
185 | argument list of package pointers. The allocated structure is initialized using NumberOfPackages, \r | |
186 | GuidId, and the variable length argument list of package pointers.\r | |
187 | \r | |
188 | Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The\r | |
dfe687ca | 189 | Handle to the newly registered Package List is returned through HiiHandle.\r |
08e4b3cf | 190 | \r |
191 | If HiiHandle is NULL, then ASSERT.\r | |
192 | \r | |
193 | @param NumberOfPackages The number of HII packages to register.\r | |
194 | @param GuidId Package List GUID ID.\r | |
195 | @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed.\r | |
196 | This DriverHandle uniquely defines the device that the added packages are associated with.\r | |
197 | @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package \r | |
198 | List later. If the functions failed to add the package to the default HII database, this value will\r | |
199 | be set to NULL.\r | |
200 | @param ... The variable argument list describing all HII Package.\r | |
201 | \r | |
202 | @return EFI_SUCCESS If the packages are successfully added to the default HII database.\r | |
203 | @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation.\r | |
204 | \r | |
205 | **/\r | |
206 | EFI_STATUS\r | |
207 | EFIAPI\r | |
208 | HiiLibAddPackages (\r | |
209 | IN UINTN NumberOfPackages,\r | |
210 | IN CONST EFI_GUID *GuidId,\r | |
211 | IN EFI_HANDLE DriverHandle, OPTIONAL\r | |
212 | OUT EFI_HII_HANDLE *HiiHandle,\r | |
213 | ...\r | |
214 | )\r | |
215 | {\r | |
216 | VA_LIST Args;\r | |
217 | EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r | |
218 | EFI_STATUS Status;\r | |
219 | \r | |
220 | ASSERT (HiiHandle != NULL);\r | |
221 | \r | |
222 | VA_START (Args, HiiHandle);\r | |
223 | PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args);\r | |
224 | \r | |
225 | Status = mHiiDatabaseProt->NewPackageList (mHiiDatabaseProt, PackageListHeader, DriverHandle, HiiHandle);\r | |
226 | if (HiiHandle != NULL) {\r | |
227 | if (EFI_ERROR (Status)) {\r | |
228 | *HiiHandle = NULL;\r | |
229 | }\r | |
230 | }\r | |
231 | \r | |
232 | FreePool (PackageListHeader);\r | |
233 | VA_END (Args);\r | |
234 | \r | |
235 | return Status;\r | |
236 | }\r | |
237 | \r | |
238 | /**\r | |
239 | Removes a package list from the default HII database.\r | |
240 | \r | |
241 | If HiiHandle is NULL, then ASSERT.\r | |
242 | If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.\r | |
243 | \r | |
244 | @param HiiHandle The handle that was previously registered to the data base that is requested for removal.\r | |
245 | List later.\r | |
246 | \r | |
247 | **/\r | |
248 | VOID\r | |
249 | EFIAPI\r | |
250 | HiiLibRemovePackages (\r | |
251 | IN EFI_HII_HANDLE HiiHandle\r | |
252 | )\r | |
253 | {\r | |
254 | EFI_STATUS Status;\r | |
255 | ASSERT (IsHiiHandleRegistered (HiiHandle));\r | |
256 | \r | |
257 | Status = mHiiDatabaseProt->RemovePackageList (mHiiDatabaseProt, HiiHandle);\r | |
258 | ASSERT_EFI_ERROR (Status);\r | |
259 | }\r | |
260 | \r | |
261 | \r | |
262 | /**\r | |
263 | Determines the handles that are currently active in the database.\r | |
264 | It's the caller's responsibility to free handle buffer.\r | |
265 | \r | |
266 | If HandleBufferLength is NULL, then ASSERT.\r | |
267 | If HiiHandleBuffer is NULL, then ASSERT.\r | |
268 | \r | |
269 | @param HandleBufferLength On input, a pointer to the length of the handle\r | |
270 | buffer. On output, the length of the handle buffer\r | |
271 | that is required for the handles found.\r | |
272 | @param HiiHandleBuffer Pointer to an array of Hii Handles returned.\r | |
273 | \r | |
274 | @retval EFI_SUCCESS Get an array of Hii Handles successfully.\r | |
275 | \r | |
276 | **/\r | |
277 | EFI_STATUS\r | |
278 | EFIAPI\r | |
279 | HiiLibGetHiiHandles (\r | |
280 | IN OUT UINTN *HandleBufferLength,\r | |
281 | OUT EFI_HII_HANDLE **HiiHandleBuffer\r | |
282 | )\r | |
283 | {\r | |
08e4b3cf | 284 | EFI_STATUS Status;\r |
285 | \r | |
286 | ASSERT (HandleBufferLength != NULL);\r | |
287 | ASSERT (HiiHandleBuffer != NULL);\r | |
288 | \r | |
fa7b3168 | 289 | *HandleBufferLength = 0;\r |
290 | *HiiHandleBuffer = NULL;\r | |
08e4b3cf | 291 | \r |
292 | //\r | |
293 | // Try to find the actual buffer size for HiiHandle Buffer.\r | |
294 | //\r | |
295 | Status = mHiiDatabaseProt->ListPackageLists (\r | |
296 | mHiiDatabaseProt,\r | |
297 | EFI_HII_PACKAGE_TYPE_ALL,\r | |
298 | NULL,\r | |
fa7b3168 | 299 | HandleBufferLength,\r |
08e4b3cf | 300 | *HiiHandleBuffer\r |
301 | );\r | |
fa7b3168 | 302 | \r |
08e4b3cf | 303 | if (Status == EFI_BUFFER_TOO_SMALL) {\r |
fa7b3168 | 304 | *HiiHandleBuffer = AllocateZeroPool (*HandleBufferLength);\r |
08e4b3cf | 305 | ASSERT (*HiiHandleBuffer != NULL);\r |
306 | Status = mHiiDatabaseProt->ListPackageLists (\r | |
307 | mHiiDatabaseProt,\r | |
308 | EFI_HII_PACKAGE_TYPE_ALL,\r | |
309 | NULL,\r | |
fa7b3168 | 310 | HandleBufferLength,\r |
08e4b3cf | 311 | *HiiHandleBuffer\r |
312 | );\r | |
08e4b3cf | 313 | \r |
fa7b3168 | 314 | if (EFI_ERROR (Status)) {\r |
315 | FreePool (*HiiHandleBuffer);\r | |
316 | *HiiHandleBuffer = NULL;\r | |
317 | }\r | |
318 | }\r | |
08e4b3cf | 319 | \r |
320 | return Status;\r | |
321 | }\r | |
322 | \r | |
323 | /**\r | |
324 | Extract Hii package list GUID for given HII handle.\r | |
325 | \r | |
326 | If HiiHandle could not be found in the default HII database, then ASSERT.\r | |
327 | If Guid is NULL, then ASSERT.\r | |
328 | \r | |
329 | @param Handle Hii handle\r | |
330 | @param Guid Package list GUID\r | |
331 | \r | |
332 | @retval EFI_SUCCESS Successfully extract GUID from Hii database.\r | |
333 | \r | |
334 | **/\r | |
335 | EFI_STATUS\r | |
336 | EFIAPI\r | |
337 | HiiLibExtractGuidFromHiiHandle (\r | |
338 | IN EFI_HII_HANDLE Handle,\r | |
339 | OUT EFI_GUID *Guid\r | |
340 | )\r | |
341 | {\r | |
342 | EFI_STATUS Status;\r | |
343 | UINTN BufferSize;\r | |
344 | EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r | |
345 | \r | |
346 | ASSERT (Guid != NULL);\r | |
347 | ASSERT (IsHiiHandleRegistered (Handle));\r | |
348 | \r | |
349 | //\r | |
350 | // Get HII PackageList\r | |
351 | //\r | |
352 | BufferSize = 0;\r | |
353 | HiiPackageList = NULL;\r | |
354 | \r | |
355 | Status = mHiiDatabaseProt->ExportPackageLists (mHiiDatabaseProt, Handle, &BufferSize, HiiPackageList);\r | |
356 | ASSERT (Status != EFI_NOT_FOUND);\r | |
357 | \r | |
358 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
359 | HiiPackageList = AllocatePool (BufferSize);\r | |
360 | ASSERT (HiiPackageList != NULL);\r | |
361 | \r | |
362 | Status = mHiiDatabaseProt->ExportPackageLists (mHiiDatabaseProt, Handle, &BufferSize, HiiPackageList);\r | |
363 | }\r | |
364 | if (EFI_ERROR (Status)) {\r | |
365 | FreePool (HiiPackageList);\r | |
366 | return Status;\r | |
367 | }\r | |
368 | \r | |
369 | //\r | |
370 | // Extract GUID\r | |
371 | //\r | |
372 | CopyGuid (Guid, &HiiPackageList->PackageListGuid);\r | |
373 | \r | |
374 | FreePool (HiiPackageList);\r | |
375 | \r | |
376 | return EFI_SUCCESS;\r | |
377 | }\r | |
378 | \r | |
379 | /**\r | |
380 | Find HII Handle in the default HII database associated with given Device Path.\r | |
381 | \r | |
382 | If DevicePath is NULL, then ASSERT.\r | |
383 | \r | |
384 | @param DevicePath Device Path associated with the HII package list\r | |
385 | handle.\r | |
386 | \r | |
387 | @retval Handle HII package list Handle associated with the Device\r | |
388 | Path.\r | |
389 | @retval NULL Hii Package list handle is not found.\r | |
390 | \r | |
391 | **/\r | |
392 | EFI_HII_HANDLE\r | |
393 | EFIAPI\r | |
394 | HiiLibDevicePathToHiiHandle (\r | |
395 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
396 | )\r | |
397 | {\r | |
398 | EFI_STATUS Status;\r | |
399 | EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;\r | |
400 | UINTN BufferSize;\r | |
401 | UINTN HandleCount;\r | |
402 | UINTN Index;\r | |
403 | EFI_HANDLE *Handles;\r | |
404 | EFI_HANDLE Handle;\r | |
405 | UINTN Size;\r | |
406 | EFI_HANDLE DriverHandle;\r | |
407 | EFI_HII_HANDLE *HiiHandles;\r | |
408 | EFI_HII_HANDLE HiiHandle;\r | |
409 | \r | |
410 | ASSERT (DevicePath != NULL);\r | |
411 | \r | |
412 | //\r | |
413 | // Locate Device Path Protocol handle buffer\r | |
414 | //\r | |
415 | Status = gBS->LocateHandleBuffer (\r | |
416 | ByProtocol,\r | |
417 | &gEfiDevicePathProtocolGuid,\r | |
418 | NULL,\r | |
419 | &HandleCount,\r | |
420 | &Handles\r | |
421 | );\r | |
422 | if (EFI_ERROR (Status)) {\r | |
423 | return NULL;\r | |
424 | }\r | |
425 | \r | |
426 | //\r | |
427 | // Search Driver Handle by Device Path\r | |
428 | //\r | |
429 | DriverHandle = NULL;\r | |
430 | BufferSize = GetDevicePathSize (DevicePath);\r | |
431 | for(Index = 0; Index < HandleCount; Index++) {\r | |
432 | Handle = Handles[Index];\r | |
433 | gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &TmpDevicePath);\r | |
434 | \r | |
435 | //\r | |
436 | // Check whether DevicePath match\r | |
437 | //\r | |
438 | Size = GetDevicePathSize (TmpDevicePath);\r | |
439 | if ((Size == BufferSize) && CompareMem (DevicePath, TmpDevicePath, Size) == 0) {\r | |
440 | DriverHandle = Handle;\r | |
441 | break;\r | |
442 | }\r | |
443 | }\r | |
444 | FreePool (Handles);\r | |
445 | \r | |
446 | if (DriverHandle == NULL) {\r | |
447 | return NULL;\r | |
448 | }\r | |
449 | \r | |
450 | //\r | |
451 | // Retrieve all Hii Handles from HII database\r | |
452 | //\r | |
453 | BufferSize = 0x1000;\r | |
454 | HiiHandles = AllocatePool (BufferSize);\r | |
455 | ASSERT (HiiHandles != NULL);\r | |
456 | Status = mHiiDatabaseProt->ListPackageLists (\r | |
457 | mHiiDatabaseProt,\r | |
458 | EFI_HII_PACKAGE_TYPE_ALL,\r | |
459 | NULL,\r | |
460 | &BufferSize,\r | |
461 | HiiHandles\r | |
462 | );\r | |
463 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
464 | FreePool (HiiHandles);\r | |
465 | HiiHandles = AllocatePool (BufferSize);\r | |
466 | ASSERT (HiiHandles != NULL);\r | |
467 | \r | |
468 | Status = mHiiDatabaseProt->ListPackageLists (\r | |
469 | mHiiDatabaseProt,\r | |
470 | EFI_HII_PACKAGE_TYPE_ALL,\r | |
471 | NULL,\r | |
472 | &BufferSize,\r | |
473 | HiiHandles\r | |
474 | );\r | |
475 | }\r | |
476 | \r | |
477 | if (EFI_ERROR (Status)) {\r | |
478 | FreePool (HiiHandles);\r | |
479 | return NULL;\r | |
480 | }\r | |
481 | \r | |
482 | //\r | |
483 | // Search Hii Handle by Driver Handle\r | |
484 | //\r | |
485 | HiiHandle = NULL;\r | |
486 | HandleCount = BufferSize / sizeof (EFI_HII_HANDLE);\r | |
487 | for (Index = 0; Index < HandleCount; Index++) {\r | |
488 | Status = mHiiDatabaseProt->GetPackageListHandle (\r | |
489 | mHiiDatabaseProt,\r | |
490 | HiiHandles[Index],\r | |
491 | &Handle\r | |
492 | );\r | |
493 | if (!EFI_ERROR (Status) && (Handle == DriverHandle)) {\r | |
494 | HiiHandle = HiiHandles[Index];\r | |
495 | break;\r | |
496 | }\r | |
497 | }\r | |
498 | \r | |
499 | FreePool (HiiHandles);\r | |
500 | return HiiHandle;\r | |
501 | }\r | |
502 | \r | |
503 | /**\r | |
504 | Exports the contents of one or all package lists in the HII database into a buffer.\r | |
505 | \r | |
506 | If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, \r | |
507 | then ASSERT.\r | |
508 | If PackageListHeader is NULL, then ASSERT.\r | |
509 | If PackageListSize is NULL, then ASSERT.\r | |
510 | \r | |
511 | @param Handle The HII Handle.\r | |
512 | @param PackageListHeader A pointer to a buffer that will contain the results of \r | |
513 | the export function.\r | |
514 | @param PackageListSize On output, the length of the buffer that is required for the exported data.\r | |
515 | \r | |
516 | @retval EFI_SUCCESS Package exported.\r | |
517 | \r | |
518 | @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations.\r | |
519 | \r | |
520 | **/\r | |
521 | EFI_STATUS \r | |
522 | EFIAPI\r | |
523 | HiiLibExportPackageLists (\r | |
524 | IN EFI_HII_HANDLE Handle,\r | |
525 | OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader,\r | |
526 | OUT UINTN *PackageListSize\r | |
527 | )\r | |
528 | {\r | |
529 | EFI_STATUS Status;\r | |
530 | UINTN Size;\r | |
531 | EFI_HII_PACKAGE_LIST_HEADER *PackageListHdr;\r | |
532 | \r | |
533 | ASSERT (PackageListSize != NULL);\r | |
534 | ASSERT (PackageListHeader != NULL);\r | |
535 | \r | |
536 | if (Handle != NULL) {\r | |
537 | ASSERT (IsHiiHandleRegistered (Handle));\r | |
538 | }\r | |
539 | \r | |
540 | Size = 0;\r | |
541 | PackageListHdr = NULL;\r | |
542 | Status = mHiiDatabaseProt->ExportPackageLists (\r | |
543 | mHiiDatabaseProt,\r | |
544 | Handle,\r | |
545 | &Size,\r | |
546 | PackageListHdr\r | |
547 | );\r | |
548 | ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL);\r | |
549 | \r | |
550 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
551 | PackageListHdr = AllocateZeroPool (Size);\r | |
552 | \r | |
553 | if (PackageListHeader == NULL) {\r | |
554 | return EFI_OUT_OF_RESOURCES;\r | |
555 | } else {\r | |
556 | Status = mHiiDatabaseProt->ExportPackageLists (\r | |
557 | mHiiDatabaseProt,\r | |
558 | Handle,\r | |
559 | &Size,\r | |
560 | PackageListHdr\r | |
561 | );\r | |
562 | }\r | |
563 | }\r | |
564 | \r | |
565 | if (!EFI_ERROR (Status)) {\r | |
566 | *PackageListHeader = PackageListHdr;\r | |
567 | *PackageListSize = Size;\r | |
568 | } else {\r | |
569 | FreePool (PackageListHdr);\r | |
570 | }\r | |
571 | \r | |
572 | return Status;\r | |
573 | }\r | |
574 | \r | |
575 | /**\r | |
576 | \r | |
577 | This function returns a list of the package handles of the \r | |
578 | specified type that are currently active in the HII database. The \r | |
579 | pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package \r | |
580 | handles to be listed.\r | |
581 | \r | |
582 | If HandleBufferLength is NULL, then ASSERT.\r | |
583 | If HandleBuffer is NULL, the ASSERT.\r | |
584 | If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is\r | |
585 | NULL, then ASSERT.\r | |
586 | If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not\r | |
587 | NULL, then ASSERT.\r | |
588 | \r | |
589 | \r | |
590 | @param PackageType Specifies the package type of the packages\r | |
591 | to list or EFI_HII_PACKAGE_TYPE_ALL for\r | |
592 | all packages to be listed.\r | |
593 | \r | |
594 | @param PackageGuid If PackageType is\r | |
595 | EFI_HII_PACKAGE_TYPE_GUID, then this is\r | |
596 | the pointer to the GUID which must match\r | |
597 | the Guid field of\r | |
598 | EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it\r | |
599 | must be NULL.\r | |
600 | \r | |
601 | @param HandleBufferLength On output, the length of the handle buffer\r | |
602 | that is required for the handles found.\r | |
603 | \r | |
604 | @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned.\r | |
605 | The caller is responcible to free this pointer allocated.\r | |
606 | \r | |
607 | @retval EFI_SUCCESS The matching handles are outputed successfully.\r | |
608 | HandleBufferLength is updated with the actual length.\r | |
609 | @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation.\r | |
610 | @retval EFI_NOT_FOUND No matching handle could not be found in database.\r | |
611 | **/\r | |
612 | EFI_STATUS\r | |
613 | EFIAPI\r | |
614 | HiiLibListPackageLists (\r | |
615 | IN UINT8 PackageType,\r | |
616 | IN CONST EFI_GUID *PackageGuid,\r | |
617 | IN OUT UINTN *HandleBufferLength,\r | |
618 | OUT EFI_HII_HANDLE **HandleBuffer\r | |
619 | )\r | |
620 | {\r | |
621 | EFI_STATUS Status;\r | |
622 | \r | |
623 | ASSERT (HandleBufferLength != NULL);\r | |
624 | ASSERT (HandleBuffer != NULL);\r | |
625 | \r | |
626 | *HandleBufferLength = 0;\r | |
627 | *HandleBuffer = NULL;\r | |
628 | \r | |
629 | if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) {\r | |
630 | ASSERT (PackageGuid != NULL);\r | |
631 | } else {\r | |
632 | ASSERT (PackageGuid == NULL);\r | |
633 | }\r | |
634 | \r | |
635 | Status = mHiiDatabaseProt->ListPackageLists (\r | |
636 | mHiiDatabaseProt,\r | |
637 | PackageType,\r | |
638 | PackageGuid,\r | |
639 | HandleBufferLength,\r | |
640 | *HandleBuffer\r | |
641 | );\r | |
642 | if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {\r | |
643 | //\r | |
644 | // No packages is registered to UEFI HII Database, just return.\r | |
645 | // \r | |
646 | //\r | |
647 | return Status;\r | |
648 | }\r | |
649 | \r | |
650 | *HandleBuffer = AllocateZeroPool (*HandleBufferLength);\r | |
651 | \r | |
652 | if (*HandleBuffer == NULL) {\r | |
653 | return EFI_OUT_OF_RESOURCES;\r | |
654 | }\r | |
655 | \r | |
656 | return mHiiDatabaseProt->ListPackageLists (\r | |
657 | mHiiDatabaseProt,\r | |
658 | PackageType,\r | |
659 | PackageGuid,\r | |
660 | HandleBufferLength,\r | |
661 | *HandleBuffer\r | |
662 | );\r | |
663 | \r | |
664 | }\r | |
665 | /**\r | |
666 | This function check if the Hii Handle is a valid handle registered\r | |
667 | in the HII database.\r | |
668 | \r | |
669 | @param HiiHandle The HII Handle.\r | |
670 | \r | |
671 | @retval TRUE If it is a valid HII handle.\r | |
672 | @retval FALSE If it is a invalid HII handle.\r | |
673 | **/\r | |
674 | BOOLEAN\r | |
675 | IsHiiHandleRegistered (\r | |
676 | EFI_HII_HANDLE HiiHandle\r | |
677 | )\r | |
678 | {\r | |
679 | EFI_STATUS Status;\r | |
680 | UINTN BufferSize;\r | |
681 | EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;\r | |
682 | \r | |
683 | ASSERT (HiiHandle != NULL);\r | |
684 | \r | |
685 | HiiPackageList = NULL;\r | |
686 | BufferSize = 0;\r | |
687 | \r | |
688 | Status = mHiiDatabaseProt->ExportPackageLists (\r | |
689 | mHiiDatabaseProt,\r | |
690 | HiiHandle,\r | |
691 | &BufferSize,\r | |
692 | HiiPackageList\r | |
693 | );\r | |
694 | \r | |
695 | return (BOOLEAN) (Status == EFI_BUFFER_TOO_SMALL);\r | |
696 | }\r | |
697 | \r |