]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.c
1) Cleanup HiiLib, IfrSupportLib.
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkHiiLib / HiiLib.c
1 /** @file
2 HII Library implementation that uses DXE protocols and services.
3
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
9
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.
12
13 Module Name: HiiLib.c
14
15 **/
16
17
18 #include <FrameworkDxe.h>
19
20 #include <Protocol/FrameworkHii.h>
21
22
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>
28
29 EFI_HII_PROTOCOL *mHii = NULL;
30
31 EFI_STATUS
32 EFIAPI
33 FrameworkHiiLibConstructor (
34 IN EFI_HANDLE ImageHandle,
35 IN EFI_SYSTEM_TABLE *SystemTable
36 )
37 {
38 EFI_STATUS Status;
39
40 Status = gBS->LocateProtocol (
41 &gEfiHiiProtocolGuid,
42 NULL,
43 (VOID **) &mHii
44 );
45 ASSERT_EFI_ERROR (Status);
46 ASSERT (mHii != NULL);
47
48 return EFI_SUCCESS;
49 }
50
51
52 EFI_HII_PACKAGES *
53 InternalPreparePackages (
54 IN UINTN NumberOfPackages,
55 IN CONST EFI_GUID *Guid OPTIONAL,
56 VA_LIST Marker
57 )
58 {
59 EFI_HII_PACKAGES *HiiPackages;
60 VOID **Package;
61 UINTN Index;
62
63 ASSERT (NumberOfPackages > 0);
64
65 HiiPackages = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));
66 ASSERT (HiiPackages != NULL);
67
68 HiiPackages->GuidId = (EFI_GUID *) Guid;
69 HiiPackages->NumberOfPackages = NumberOfPackages;
70 Package = (VOID **) (((UINT8 *) HiiPackages) + sizeof (EFI_HII_PACKAGES));
71
72 for (Index = 0; Index < NumberOfPackages; Index++) {
73 *Package = VA_ARG (Marker, VOID *);
74 Package++;
75 }
76
77 return HiiPackages;
78
79 }
80
81
82 /**
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.
87
88 @param NumberOfPackages The number of HII packages to prepare.
89 @param Guid Package GUID.
90
91 @return The allocated and initialized packages.
92
93 **/
94 EFI_HII_PACKAGES *
95 EFIAPI
96 PreparePackages (
97 IN UINTN NumberOfPackages,
98 IN CONST EFI_GUID *Guid OPTIONAL,
99 ...
100 )
101 {
102 VA_LIST Args;
103
104 VA_START (Args, Guid);
105
106 return InternalPreparePackages (NumberOfPackages, Guid, Args);
107 }
108
109
110 /**
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.
115
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.
118
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.
123
124 @return
125 The allocated and initialized packages.
126
127 **/
128
129 EFI_STATUS
130 EFIAPI
131 HiiLibAddPackages (
132 IN UINTN NumberOfPackages,
133 IN CONST EFI_GUID *GuidId,
134 IN EFI_HANDLE DriverHandle, OPTIONAL
135 OUT EFI_HII_HANDLE *HiiHandle, OPTIONAL
136 ...
137 )
138 {
139 VA_LIST Args;
140 EFI_HII_PACKAGES *FrameworkHiiPacages;
141 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
142 EFI_STATUS Status;
143
144
145 VA_START (Args, HiiHandle);
146 FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);
147
148 Status = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);
149 if (HiiHandle != NULL) {
150 if (EFI_ERROR (Status)) {
151 *HiiHandle = NULL;
152 } else {
153 *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;
154 }
155 }
156
157 FreePool (FrameworkHiiPacages);
158
159 return Status;
160 }
161
162 EFI_STATUS
163 EFIAPI
164 HiiLibAddFontPackageToHiiDatabase (
165 IN UINTN FontSize,
166 IN CONST UINT8 *FontBinary,
167 IN CONST EFI_GUID *GuidId,
168 OUT EFI_HII_HANDLE *HiiHandle OPTIONAL
169 )
170 {
171 EFI_STATUS Status;
172 EFI_HII_FONT_PACK *FontPack;
173 UINT8 *Location;
174
175 FontPack = AllocateZeroPool (sizeof (EFI_HII_FONT_PACK) + FontSize);
176 ASSERT (FontPack != NULL);
177
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));
181
182 Location = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8));
183 CopyMem (Location, FontBinary, FontSize);
184
185
186 //
187 // Register our Fonts into the global database
188 //
189 Status = HiiLibAddPackages (1, NULL, HiiHandle, NULL, FontPack);
190 //
191 // Free the font database
192 //
193 FreePool (FontPack);
194
195 return Status;
196 }
197
198 VOID
199 EFIAPI
200 HiiLibRemovePackages (
201 IN EFI_HII_HANDLE HiiHandle
202 )
203 {
204 EFI_STATUS Status;
205
206 Status = mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);
207 ASSERT_EFI_ERROR (Status);
208 }
209
210
211 /**
212 This function adds the string into String Package of each language.
213
214 @param PackageList Handle of the package list where this string will
215 be added.
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.
219
220 @retval EFI_SUCCESS The new string was added successfully.
221 @retval EFI_NOT_FOUND The specified PackageList could not be found in
222 database.
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.
225
226 **/
227 EFI_STATUS
228 EFIAPI
229 HiiLibNewString (
230 IN EFI_HII_HANDLE PackageList,
231 OUT EFI_STRING_ID *StringId,
232 IN CONST EFI_STRING String
233 )
234 {
235 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
236 EFI_STATUS Status;
237
238 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;
239 Status = mHii->NewString (
240 mHii,
241 NULL,
242 FrameworkHiiHandle,
243 StringId,
244 String
245 );
246
247 return Status;
248 }
249
250
251 EFI_STATUS
252 EFIAPI
253 HiiLibUpdateString (
254 IN EFI_HII_HANDLE PackageList,
255 IN EFI_STRING_ID StringId,
256 IN CONST EFI_STRING String
257 )
258 {
259 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;
260 EFI_STATUS Status;
261
262 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;
263 Status = mHii->NewString (
264 mHii,
265 NULL,
266 FrameworkHiiHandle,
267 &StringId,
268 String
269 );
270
271 return Status;
272 }
273
274 //
275 // Just use the UEFI prototype
276 //
277 EFI_STATUS
278 EFIAPI
279 HiiLibGetStringFromToken (
280 IN EFI_GUID *ProducerGuid,
281 IN EFI_STRING_ID StringId,
282 OUT EFI_STRING *String
283 )
284 {
285 return EFI_SUCCESS;
286 }
287
288 //
289 // Just use the UEFI prototype
290 //
291 EFI_STATUS
292 EFIAPI
293 HiiLibGetStringFromHandle (
294 IN EFI_HII_HANDLE PackageList,
295 IN EFI_STRING_ID StringId,
296 OUT EFI_STRING *String
297 )
298 {
299 return EFI_SUCCESS;
300 }
301
302 //
303 // Just use the UEFI prototype
304 //
305 EFI_STATUS
306 EFIAPI
307 HiiLibCreateHiiDriverHandle (
308 OUT EFI_HANDLE *DriverHandle
309 )
310 {
311 //
312 // Driver
313 // This implementation does nothing as DriverHandle concept only
314 // applies to UEFI HII specification.
315 //
316
317 *DriverHandle = NULL;
318
319 return EFI_SUCCESS;
320 }
321