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 instance.
36 @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
*);
101 This function allocates pool for an EFI_HII_PACKAGES structure
102 with enough space for the variable argument list of package pointers.
103 The allocated structure is initialized using NumberOfPackages, Guid,
104 and the variable length argument list of package pointers.
106 @param NumberOfPackages The number of HII packages to prepare.
107 @param Guid Package GUID.
108 @param ... The variable argument list of package pointers.
110 @return The allocated and initialized packages.
115 IN UINTN NumberOfPackages
,
116 IN CONST EFI_GUID
*Guid OPTIONAL
,
122 VA_START (Args
, Guid
);
123 return InternalPreparePackages (NumberOfPackages
, Guid
, Args
);
128 This function allocates pool for an EFI_HII_PACKAGE_LIST structure
129 with additional space that is big enough to host all packages described by the variable
130 argument list of package pointers. The allocated structure is initialized using NumberOfPackages,
131 GuidId, and the variable length argument list of package pointers.
133 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The
134 Handle to the newly registered Package List is returned throught HiiHandle.
136 @param NumberOfPackages The number of HII packages to register.
137 @param GuidId Package List GUID ID.
138 @param DriverHandle The pointer of driver handle
139 @param HiiHandle The ID used to retrieve the Package List later.
140 @param ... The variable argument list describing all HII Package.
142 @return The allocated and initialized packages.
147 IN UINTN NumberOfPackages
,
148 IN CONST EFI_GUID
*GuidId
,
149 IN EFI_HANDLE DriverHandle
, OPTIONAL
150 OUT EFI_HII_HANDLE
*HiiHandle
,
155 EFI_HII_PACKAGES
*FrameworkHiiPacages
;
156 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
159 VA_START (Args
, HiiHandle
);
161 FrameworkHiiPacages
= InternalPreparePackages (NumberOfPackages
, GuidId
, Args
);
162 Status
= mHii
->NewPack (mHii
, FrameworkHiiPacages
, &FrameworkHiiHandle
);
163 if (HiiHandle
!= NULL
) {
164 if (EFI_ERROR (Status
)) {
167 *HiiHandle
= (EFI_HII_HANDLE
) (UINTN
) FrameworkHiiHandle
;
171 FreePool (FrameworkHiiPacages
);
177 Removes a package list from the default HII database.
179 If HiiHandle is NULL, then ASSERT.
180 If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.
182 @param HiiHandle The handle that was previously registered to the data base that is requested for removal.
188 HiiLibRemovePackages (
189 IN EFI_HII_HANDLE HiiHandle
194 Status
= mHii
->RemovePack (mHii
, (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) HiiHandle
);
195 ASSERT_EFI_ERROR (Status
);
199 This function adds the string into String Package of each language.
201 @param PackageList Handle of the package list where this string will
203 @param StringId On return, contains the new strings id, which is
204 unique within PackageList.
205 @param String Points to the new null-terminated string.
207 @retval EFI_SUCCESS The new string was added successfully.
208 @retval EFI_NOT_FOUND The specified PackageList could not be found in
210 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
211 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.
217 IN EFI_HII_HANDLE PackageList
,
218 OUT EFI_STRING_ID
*StringId
,
219 IN CONST EFI_STRING String
222 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
225 FrameworkHiiHandle
= (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) PackageList
;
226 Status
= mHii
->NewString (
238 Get the string given the StringId and String package Producer's Guid. The caller
239 is responsible to free the *String.
241 If PackageList with the matching ProducerGuid is not found, then ASSERT.
242 If PackageList with the matching ProducerGuid is found but no String is
243 specified by StringId is found, then ASSERT.
245 @param ProducerGuid The Guid of String package list.
246 @param StringId The String ID.
247 @param String The output string.
249 @retval EFI_SUCCESS Operation is successful.
250 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
254 HiiLibGetStringFromToken (
255 IN EFI_GUID
*ProducerGuid
,
256 IN EFI_STRING_ID StringId
,
257 OUT EFI_STRING
*String
264 Get string specified by StringId form the HiiHandle. The caller
265 is responsible to free the *String.
267 If String is NULL, then ASSERT.
268 If HiiHandle could not be found in the default HII database, then ASSERT.
269 If StringId is not found in PackageList, then ASSERT.
271 @param PackageList The HII handle of package list.
272 @param StringId The String ID.
273 @param String The output string.
275 @retval EFI_NOT_FOUND String is not found.
276 @retval EFI_SUCCESS Operation is successful.
277 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
282 HiiLibGetStringFromHandle (
283 IN EFI_HII_HANDLE PackageList
,
284 IN EFI_STRING_ID StringId
,
285 OUT EFI_STRING
*String
292 Create the driver handle for HII driver. The protocol and
293 Package list of this driver wili be installed into this
295 The implement set DriverHandle to NULL simpliy to let
296 handle manager create a default new handle.
298 @param DriverHandle The pointer of driver handle
300 @return Always success.
304 HiiLibCreateHiiDriverHandle (
305 OUT EFI_HANDLE
*DriverHandle
310 // This implementation does nothing as DriverHandle concept only
311 // applies to UEFI HII specification.
314 *DriverHandle
= NULL
;