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.
131 HiiLibAddPackagesToHiiDatabase (
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
= HiiLibAddPackagesToHiiDatabase (1, NULL
, HiiHandle
, NULL
, FontPack
);
191 // Free the font database
200 HiiLibRemovePackagesFromHiiDatabase (
201 IN EFI_HII_HANDLE HiiHandle
204 return mHii
->RemovePack (mHii
, (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) HiiHandle
);
209 This function adds the string into String Package of each language.
211 @param PackageList Handle of the package list where this string will
213 @param StringId On return, contains the new strings id, which is
214 unique within PackageList.
215 @param String Points to the new null-terminated string.
217 @retval EFI_SUCCESS The new string was added successfully.
218 @retval EFI_NOT_FOUND The specified PackageList could not be found in
220 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
221 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.
227 IN EFI_HII_HANDLE PackageList
,
228 OUT EFI_STRING_ID
*StringId
,
229 IN CONST EFI_STRING String
232 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
235 FrameworkHiiHandle
= (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) PackageList
;
236 Status
= mHii
->NewString (
251 IN EFI_HII_HANDLE PackageList
,
252 IN EFI_STRING_ID StringId
,
253 IN CONST EFI_STRING String
256 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle
;
259 FrameworkHiiHandle
= (FRAMEWORK_EFI_HII_HANDLE
) (UINTN
) PackageList
;
260 Status
= mHii
->NewString (
272 // Just use the UEFI prototype
276 HiiLibGetStringFromGuidId (
277 IN EFI_GUID
*ProducerGuid
,
278 IN EFI_STRING_ID StringId
,
279 OUT EFI_STRING
*String
286 // Just use the UEFI prototype
290 HiiLibGetStringFromHandle (
291 IN EFI_HII_HANDLE PackageList
,
292 IN EFI_STRING_ID StringId
,
293 OUT EFI_STRING
*String
300 // Just use the UEFI prototype
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
;