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.
18 #include <FrameworkDxe.h>
20 #include <Protocol/FrameworkHii.h>
23 #include <Library/FrameworkHiiLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/UefiBootServicesTableLib.h>
27 #include <Library/BaseMemoryLib.h>
29 EFI_HII_PROTOCOL
*mHii
= NULL
;
33 FrameworkHiiLibConstructor (
34 IN EFI_HANDLE ImageHandle
,
35 IN EFI_SYSTEM_TABLE
*SystemTable
40 Status
= gBS
->LocateProtocol (
45 ASSERT_EFI_ERROR (Status
);
46 ASSERT (mHii
!= NULL
);
53 InternalPreparePackages (
54 IN UINTN NumberOfPackages
,
55 IN CONST EFI_GUID
*Guid OPTIONAL
,
59 EFI_HII_PACKAGES
*HiiPackages
;
63 ASSERT (NumberOfPackages
> 0);
65 HiiPackages
= AllocateZeroPool (sizeof (EFI_HII_PACKAGES
) + NumberOfPackages
* sizeof (VOID
*));
66 ASSERT (HiiPackages
!= NULL
);
68 HiiPackages
->GuidId
= (EFI_GUID
*) Guid
;
69 HiiPackages
->NumberOfPackages
= NumberOfPackages
;
70 Package
= (VOID
**) (((UINT8
*) HiiPackages
) + sizeof (EFI_HII_PACKAGES
));
72 for (Index
= 0; Index
< NumberOfPackages
; Index
++) {
73 *Package
= VA_ARG (Marker
, VOID
*);
83 This function allocates pool for an EFI_HII_PACKAGES structure
84 with enough space for the variable argument list of package pointers.
85 The allocated structure is initialized using NumberOfPackages, Guid,
86 and the variable length argument list of package pointers.
88 @param NumberOfPackages The number of HII packages to prepare.
89 @param Guid Package GUID.
91 @return The allocated and initialized packages.
97 IN UINTN NumberOfPackages
,
98 IN CONST EFI_GUID
*Guid OPTIONAL
,
104 VA_START (Args
, Guid
);
106 return InternalPreparePackages (NumberOfPackages
, Guid
, Args
);
111 This function allocates pool for an EFI_HII_PACKAGE_LIST structure
112 with additional space that is big enough to host all packages described by the variable
113 argument list of package pointers. The allocated structure is initialized using NumberOfPackages,
114 GuidId, and the variable length argument list of package pointers.
116 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The
117 Handle to the newly registered Package List is returned throught HiiHandle.
119 @param NumberOfPackages The number of HII packages to register.
120 @param GuidId Package List GUID ID.
121 @param HiiHandle The ID used to retrieve the Package List later.
122 @param ... The variable argument list describing all HII Package.
125 The allocated and initialized packages.
132 IN UINTN NumberOfPackages
,
133 IN CONST EFI_GUID
*GuidId
,
134 IN EFI_HANDLE DriverHandle
, OPTIONAL
135 OUT EFI_HII_HANDLE
*HiiHandle
, OPTIONAL
140 EFI_HII_PACKAGES
*FrameworkHiiPacages
;
141 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
145 VA_START (Args
, HiiHandle
);
146 FrameworkHiiPacages
= InternalPreparePackages (NumberOfPackages
, GuidId
, Args
);
148 Status
= mHii
->NewPack (mHii
, FrameworkHiiPacages
, &FrameworkHiiHandle
);
149 if (HiiHandle
!= NULL
) {
150 if (EFI_ERROR (Status
)) {
153 *HiiHandle
= (EFI_HII_HANDLE
) (UINTN
) FrameworkHiiHandle
;
157 FreePool (FrameworkHiiPacages
);
164 HiiLibAddFontPackageToHiiDatabase (
166 IN CONST UINT8
*FontBinary
,
167 IN CONST EFI_GUID
*GuidId
,
168 OUT EFI_HII_HANDLE
*HiiHandle OPTIONAL
172 EFI_HII_FONT_PACK
*FontPack
;
175 FontPack
= AllocateZeroPool (sizeof (EFI_HII_FONT_PACK
) + FontSize
);
176 ASSERT (FontPack
!= NULL
);
178 FontPack
->Header
.Length
= (UINT32
) (sizeof (EFI_HII_FONT_PACK
) + FontSize
);
179 FontPack
->Header
.Type
= EFI_HII_FONT
;
180 FontPack
->NumberOfNarrowGlyphs
= (UINT16
) (FontSize
/ sizeof (EFI_NARROW_GLYPH
));
182 Location
= (UINT8
*) (&FontPack
->NumberOfWideGlyphs
+ sizeof (UINT8
));
183 CopyMem (Location
, FontBinary
, FontSize
);
187 // Register our Fonts into the global database
189 Status
= HiiLibAddPackages (1, NULL
, HiiHandle
, NULL
, FontPack
);
191 // Free the font database
200 HiiLibRemovePackages (
201 IN EFI_HII_HANDLE HiiHandle
206 Status
= mHii
->RemovePack (mHii
, (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) HiiHandle
);
207 ASSERT_EFI_ERROR (Status
);
212 This function adds the string into String Package of each language.
214 @param PackageList Handle of the package list where this string will
216 @param StringId On return, contains the new strings id, which is
217 unique within PackageList.
218 @param String Points to the new null-terminated string.
220 @retval EFI_SUCCESS The new string was added successfully.
221 @retval EFI_NOT_FOUND The specified PackageList could not be found in
223 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
224 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.
230 IN EFI_HII_HANDLE PackageList
,
231 OUT EFI_STRING_ID
*StringId
,
232 IN CONST EFI_STRING String
235 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
238 FrameworkHiiHandle
= (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) PackageList
;
239 Status
= mHii
->NewString (
254 IN EFI_HII_HANDLE PackageList
,
255 IN EFI_STRING_ID StringId
,
256 IN CONST EFI_STRING String
259 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
262 FrameworkHiiHandle
= (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) PackageList
;
263 Status
= mHii
->NewString (
275 // Just use the UEFI prototype
279 HiiLibGetStringFromToken (
280 IN EFI_GUID
*ProducerGuid
,
281 IN EFI_STRING_ID StringId
,
282 OUT EFI_STRING
*String
289 // Just use the UEFI prototype
293 HiiLibGetStringFromHandle (
294 IN EFI_HII_HANDLE PackageList
,
295 IN EFI_STRING_ID StringId
,
296 OUT EFI_STRING
*String
303 // Just use the UEFI prototype
307 HiiLibCreateHiiDriverHandle (
308 OUT EFI_HANDLE
*DriverHandle
313 // This implementation does nothing as DriverHandle concept only
314 // applies to UEFI HII specification.
317 *DriverHandle
= NULL
;