2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <FrameworkDxe.h>
18 #include <Protocol/FrameworkHii.h>
20 #include <Library/FrameworkHiiLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/BaseMemoryLib.h>
27 EFI_HII_PROTOCOL
*mHii
= NULL
;
30 Library constustor function for HiiLib library instance locate the
31 gEfiHiiProtocolGuid firstly, the other interface in this library
32 instance will dependent on the protocol of gEfiHiiProtocolGuid.
33 So the depex of gEfiHiiProtocolGuid is required for this library
35 If protocol of gEfiHiiProtocolGuid is not installed, then ASSERT().
37 @param ImageHandle The image handle of driver module who use this library
39 @param SystemTable Pointer to the EFI System Table.
40 @retval EFI_SUCCESS library constuctor always success.
44 FrameworkHiiLibConstructor (
45 IN EFI_HANDLE ImageHandle
,
46 IN EFI_SYSTEM_TABLE
*SystemTable
51 Status
= gBS
->LocateProtocol (
56 ASSERT_EFI_ERROR (Status
);
57 ASSERT (mHii
!= NULL
);
63 This function is internal function that prepare and create
64 HII packages with given number and package's guid.
65 It is invoked by HiiAddPackages() and PreparePackages() interface.
66 If the parameter of package's number is 0, then ASSERT().
68 @param NumberOfPackages Given number of package item in a HII package list.
69 @param Guid Given GUID of a HII package list.
70 @param Marker Package's content list.
72 @return pointer to new created HII package list.
75 InternalPreparePackages (
76 IN UINTN NumberOfPackages
,
77 IN CONST EFI_GUID
*Guid OPTIONAL
,
81 EFI_HII_PACKAGES
*HiiPackages
;
85 ASSERT (NumberOfPackages
> 0);
87 HiiPackages
= AllocateZeroPool (sizeof (EFI_HII_PACKAGES
) + NumberOfPackages
* sizeof (VOID
*));
88 ASSERT (HiiPackages
!= NULL
);
90 HiiPackages
->GuidId
= (EFI_GUID
*) Guid
;
91 HiiPackages
->NumberOfPackages
= NumberOfPackages
;
92 Package
= (VOID
**) (((UINT8
*) HiiPackages
) + sizeof (EFI_HII_PACKAGES
));
94 for (Index
= 0; Index
< NumberOfPackages
; Index
++) {
95 *Package
= VA_ARG (Marker
, VOID
*);
104 This function allocates pool for an EFI_HII_PACKAGES structure
105 with enough space for the variable argument list of package pointers.
106 The allocated structure is initialized using NumberOfPackages, Guid,
107 and the variable length argument list of package pointers.
109 @param NumberOfPackages The number of HII packages to prepare.
110 @param Guid Package GUID.
112 @return The allocated and initialized packages.
118 IN UINTN NumberOfPackages
,
119 IN CONST EFI_GUID
*Guid OPTIONAL
,
125 VA_START (Args
, Guid
);
127 return InternalPreparePackages (NumberOfPackages
, Guid
, Args
);
132 This function allocates pool for an EFI_HII_PACKAGE_LIST structure
133 with additional space that is big enough to host all packages described by the variable
134 argument list of package pointers. The allocated structure is initialized using NumberOfPackages,
135 GuidId, and the variable length argument list of package pointers.
137 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The
138 Handle to the newly registered Package List is returned throught HiiHandle.
140 @param NumberOfPackages The number of HII packages to register.
141 @param GuidId Package List GUID ID.
142 @param DriverHandle The pointer of driver handle
143 @param HiiHandle The ID used to retrieve the Package List later.
144 @param ... The variable argument list describing all HII Package.
147 The allocated and initialized packages.
154 IN UINTN NumberOfPackages
,
155 IN CONST EFI_GUID
*GuidId
,
156 IN EFI_HANDLE DriverHandle
, OPTIONAL
157 OUT EFI_HII_HANDLE
*HiiHandle
, OPTIONAL
162 EFI_HII_PACKAGES
*FrameworkHiiPacages
;
163 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
167 VA_START (Args
, HiiHandle
);
168 FrameworkHiiPacages
= InternalPreparePackages (NumberOfPackages
, GuidId
, Args
);
170 Status
= mHii
->NewPack (mHii
, FrameworkHiiPacages
, &FrameworkHiiHandle
);
171 if (HiiHandle
!= NULL
) {
172 if (EFI_ERROR (Status
)) {
175 *HiiHandle
= (EFI_HII_HANDLE
) (UINTN
) FrameworkHiiHandle
;
179 FreePool (FrameworkHiiPacages
);
185 Removes a package list from the default HII database.
187 If HiiHandle is NULL, then ASSERT.
188 If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.
190 @param HiiHandle The handle that was previously registered to the data base that is requested for removal.
198 HiiLibRemovePackages (
199 IN EFI_HII_HANDLE HiiHandle
204 Status
= mHii
->RemovePack (mHii
, (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) HiiHandle
);
205 ASSERT_EFI_ERROR (Status
);
210 This function adds the string into String Package of each language.
212 @param PackageList Handle of the package list where this string will
214 @param StringId On return, contains the new strings id, which is
215 unique within PackageList.
216 @param String Points to the new null-terminated string.
218 @retval EFI_SUCCESS The new string was added successfully.
219 @retval EFI_NOT_FOUND The specified PackageList could not be found in
221 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
222 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.
228 IN EFI_HII_HANDLE PackageList
,
229 OUT EFI_STRING_ID
*StringId
,
230 IN CONST EFI_STRING String
233 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
236 FrameworkHiiHandle
= (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) PackageList
;
237 Status
= mHii
->NewString (
249 Get the string given the StringId and String package Producer's Guid. The caller
250 is responsible to free the *String.
252 If PackageList with the matching ProducerGuid is not found, then ASSERT.
253 If PackageList with the matching ProducerGuid is found but no String is
254 specified by StringId is found, then ASSERT.
256 @param ProducerGuid The Guid of String package list.
257 @param StringId The String ID.
258 @param String The output string.
260 @retval EFI_SUCCESS Operation is successful.
261 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
266 HiiLibGetStringFromToken (
267 IN EFI_GUID
*ProducerGuid
,
268 IN EFI_STRING_ID StringId
,
269 OUT EFI_STRING
*String
276 Get string specified by StringId form the HiiHandle. The caller
277 is responsible to free the *String.
279 If String is NULL, then ASSERT.
280 If HiiHandle could not be found in the default HII database, then ASSERT.
281 If StringId is not found in PackageList, then ASSERT.
283 @param PackageList The HII handle of package list.
284 @param StringId The String ID.
285 @param String The output string.
287 @retval EFI_NOT_FOUND String is not found.
288 @retval EFI_SUCCESS Operation is successful.
289 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
290 @retval EFI_INVALID_PARAMETER The String is NULL.
295 HiiLibGetStringFromHandle (
296 IN EFI_HII_HANDLE PackageList
,
297 IN EFI_STRING_ID StringId
,
298 OUT EFI_STRING
*String
305 Create the driver handle for HII driver. The protocol and
306 Package list of this driver wili be installed into this
308 The implement set DriverHandle to NULL simpliy to let
309 handle manager create a default new handle.
311 @param[out] DriverHandle the pointer of driver handle
312 @return always successful.
316 HiiLibCreateHiiDriverHandle (
317 OUT EFI_HANDLE
*DriverHandle
322 // This implementation does nothing as DriverHandle concept only
323 // applies to UEFI HII specification.
326 *DriverHandle
= NULL
;