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>
25 EFI_HII_PROTOCOL
*mHii
= NULL
;
28 Library constustor function for HiiLib library instance locate the
29 gEfiHiiProtocolGuid firstly, the other interface in this library
30 instance will dependent on the protocol of gEfiHiiProtocolGuid.
31 So the depex of gEfiHiiProtocolGuid is required for this library
33 If protocol of gEfiHiiProtocolGuid is not installed, then ASSERT().
35 @param ImageHandle The image handle of driver module who use this library
37 @param SystemTable Pointer to the EFI System Table.
38 @retval EFI_SUCCESS library constuctor always success.
42 FrameworkHiiLibConstructor (
43 IN EFI_HANDLE ImageHandle
,
44 IN EFI_SYSTEM_TABLE
*SystemTable
49 Status
= gBS
->LocateProtocol (
54 ASSERT_EFI_ERROR (Status
);
55 ASSERT (mHii
!= NULL
);
61 This function is internal function that prepare and create
62 HII packages with given number and package's guid.
63 It is invoked by HiiAddPackages() and PreparePackages() interface.
64 If the parameter of package's number is 0, then ASSERT().
66 @param NumberOfPackages Given number of package item in a HII package list.
67 @param Guid Given GUID of a HII package list.
68 @param Marker Package's content list.
70 @return pointer to new created HII package list.
73 InternalPreparePackages (
74 IN UINTN NumberOfPackages
,
75 IN CONST EFI_GUID
*Guid OPTIONAL
,
79 EFI_HII_PACKAGES
*HiiPackages
;
83 ASSERT (NumberOfPackages
> 0);
85 HiiPackages
= AllocateZeroPool (sizeof (EFI_HII_PACKAGES
) + NumberOfPackages
* sizeof (VOID
*));
86 ASSERT (HiiPackages
!= NULL
);
88 HiiPackages
->GuidId
= (EFI_GUID
*) Guid
;
89 HiiPackages
->NumberOfPackages
= NumberOfPackages
;
90 Package
= (VOID
**) (((UINT8
*) HiiPackages
) + sizeof (EFI_HII_PACKAGES
));
92 for (Index
= 0; Index
< NumberOfPackages
; Index
++) {
93 *Package
= VA_ARG (Marker
, VOID
*);
102 This function allocates pool for an EFI_HII_PACKAGES structure
103 with enough space for the variable argument list of package pointers.
104 The allocated structure is initialized using NumberOfPackages, Guid,
105 and the variable length argument list of package pointers.
107 @param NumberOfPackages The number of HII packages to prepare.
108 @param Guid Package GUID.
109 @Param ... The variable argument list of package pointers.
111 @return The allocated and initialized packages.
117 IN UINTN NumberOfPackages
,
118 IN CONST EFI_GUID
*Guid OPTIONAL
,
124 VA_START (Args
, Guid
);
126 return InternalPreparePackages (NumberOfPackages
, Guid
, Args
);
131 This function allocates pool for an EFI_HII_PACKAGE_LIST structure
132 with additional space that is big enough to host all packages described by the variable
133 argument list of package pointers. The allocated structure is initialized using NumberOfPackages,
134 GuidId, and the variable length argument list of package pointers.
136 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The
137 Handle to the newly registered Package List is returned throught HiiHandle.
139 @param NumberOfPackages The number of HII packages to register.
140 @param GuidId Package List GUID ID.
141 @param DriverHandle The pointer of driver handle
142 @param HiiHandle The ID used to retrieve the Package List later.
143 @param ... The variable argument list describing all HII Package.
146 The allocated and initialized packages.
152 IN UINTN NumberOfPackages
,
153 IN CONST EFI_GUID
*GuidId
,
154 IN EFI_HANDLE DriverHandle
, OPTIONAL
155 OUT EFI_HII_HANDLE
*HiiHandle
, OPTIONAL
160 EFI_HII_PACKAGES
*FrameworkHiiPacages
;
161 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
165 VA_START (Args
, HiiHandle
);
166 FrameworkHiiPacages
= InternalPreparePackages (NumberOfPackages
, GuidId
, Args
);
168 Status
= mHii
->NewPack (mHii
, FrameworkHiiPacages
, &FrameworkHiiHandle
);
169 if (HiiHandle
!= NULL
) {
170 if (EFI_ERROR (Status
)) {
173 *HiiHandle
= (EFI_HII_HANDLE
) (UINTN
) FrameworkHiiHandle
;
177 FreePool (FrameworkHiiPacages
);
183 Removes a package list from the default HII database.
185 If HiiHandle is NULL, then ASSERT.
186 If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.
188 @param HiiHandle The handle that was previously registered to the data base that is requested for removal.
196 HiiLibRemovePackages (
197 IN EFI_HII_HANDLE HiiHandle
202 Status
= mHii
->RemovePack (mHii
, (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) HiiHandle
);
203 ASSERT_EFI_ERROR (Status
);
208 This function adds the string into String Package of each language.
210 @param PackageList Handle of the package list where this string will
212 @param StringId On return, contains the new strings id, which is
213 unique within PackageList.
214 @param String Points to the new null-terminated string.
216 @retval EFI_SUCCESS The new string was added successfully.
217 @retval EFI_NOT_FOUND The specified PackageList could not be found in
219 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
220 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.
226 IN EFI_HII_HANDLE PackageList
,
227 OUT EFI_STRING_ID
*StringId
,
228 IN CONST EFI_STRING String
231 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
234 FrameworkHiiHandle
= (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) PackageList
;
235 Status
= mHii
->NewString (
247 Get the string given the StringId and String package Producer's Guid. The caller
248 is responsible to free the *String.
250 If PackageList with the matching ProducerGuid is not found, then ASSERT.
251 If PackageList with the matching ProducerGuid is found but no String is
252 specified by StringId is found, then ASSERT.
254 @param ProducerGuid The Guid of String package list.
255 @param StringId The String ID.
256 @param String The output string.
258 @retval EFI_SUCCESS Operation is successful.
259 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
264 HiiLibGetStringFromToken (
265 IN EFI_GUID
*ProducerGuid
,
266 IN EFI_STRING_ID StringId
,
267 OUT EFI_STRING
*String
274 Get string specified by StringId form the HiiHandle. The caller
275 is responsible to free the *String.
277 If String is NULL, then ASSERT.
278 If HiiHandle could not be found in the default HII database, then ASSERT.
279 If StringId is not found in PackageList, then ASSERT.
281 @param PackageList The HII handle of package list.
282 @param StringId The String ID.
283 @param String The output string.
285 @retval EFI_NOT_FOUND String is not found.
286 @retval EFI_SUCCESS Operation is successful.
287 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
292 HiiLibGetStringFromHandle (
293 IN EFI_HII_HANDLE PackageList
,
294 IN EFI_STRING_ID StringId
,
295 OUT EFI_STRING
*String
302 Create the driver handle for HII driver. The protocol and
303 Package list of this driver wili be installed into this
305 The implement set DriverHandle to NULL simpliy to let
306 handle manager create a default new handle.
308 @param[out] DriverHandle the pointer of driver handle
309 @return always successful.
313 HiiLibCreateHiiDriverHandle (
314 OUT EFI_HANDLE
*DriverHandle
319 // This implementation does nothing as DriverHandle concept only
320 // applies to UEFI HII specification.
323 *DriverHandle
= NULL
;