]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.c
UEFI HII: Merge UEFI HII support changes from branch.
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkHiiLib / HiiLib.c
CommitLineData
0a869bf8 1/** @file\r
2 HII Library implementation that uses DXE protocols and services.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
53f93f7e 5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
0a869bf8 9\r
53f93f7e 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
0a869bf8 12\r
13 Module Name: HiiLib.c\r
14\r
15**/\r
16\r
ed7748fe 17\r
564995cd 18#include <FrameworkDxe.h>\r
ed7748fe 19\r
dc7b4a5c 20#include <Protocol/FrameworkHii.h>\r
21\r
ed7748fe 22\r
8e5b17b2 23#include <Library/FrameworkHiiLib.h>\r
53f93f7e 24#include <Library/DebugLib.h>\r
25#include <Library/MemoryAllocationLib.h>\r
dc7b4a5c 26#include <Library/UefiBootServicesTableLib.h>\r
27#include <Library/BaseMemoryLib.h>\r
28\r
29EFI_HII_PROTOCOL *mHii = NULL;\r
30\r
31EFI_STATUS\r
32EFIAPI\r
33FrameworkHiiLibConstructor (\r
34 IN EFI_HANDLE ImageHandle,\r
35 IN EFI_SYSTEM_TABLE *SystemTable\r
36 )\r
37{\r
38 EFI_STATUS Status;\r
39 \r
40 Status = gBS->LocateProtocol (\r
41 &gEfiHiiProtocolGuid,\r
42 NULL,\r
43 (VOID **) &mHii\r
44 );\r
45 ASSERT_EFI_ERROR (Status);\r
46 ASSERT (mHii != NULL);\r
47\r
48 return EFI_SUCCESS;\r
49}\r
50\r
51\r
52EFI_HII_PACKAGES *\r
53InternalPreparePackages (\r
54 IN UINTN NumberOfPackages,\r
55 IN CONST EFI_GUID *Guid OPTIONAL,\r
56 VA_LIST Marker\r
57 )\r
58{\r
59 EFI_HII_PACKAGES *HiiPackages;\r
60 VOID **Package;\r
61 UINTN Index;\r
62\r
63 ASSERT (NumberOfPackages > 0);\r
64\r
65 HiiPackages = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));\r
66 ASSERT (HiiPackages != NULL);\r
67\r
68 HiiPackages->GuidId = (EFI_GUID *) Guid;\r
69 HiiPackages->NumberOfPackages = NumberOfPackages;\r
70 Package = (VOID **) (((UINT8 *) HiiPackages) + sizeof (EFI_HII_PACKAGES));\r
71\r
72 for (Index = 0; Index < NumberOfPackages; Index++) {\r
73 *Package = VA_ARG (Marker, VOID *);\r
74 Package++;\r
75 }\r
76\r
77 return HiiPackages;\r
78\r
79}\r
80\r
0a869bf8 81\r
82/**\r
83 This function allocates pool for an EFI_HII_PACKAGES structure\r
84 with enough space for the variable argument list of package pointers.\r
53f93f7e 85 The allocated structure is initialized using NumberOfPackages, Guid,\r
0a869bf8 86 and the variable length argument list of package pointers.\r
87\r
88 @param NumberOfPackages The number of HII packages to prepare.\r
89 @param Guid Package GUID.\r
90\r
91 @return The allocated and initialized packages.\r
92\r
93**/\r
94EFI_HII_PACKAGES *\r
95EFIAPI\r
96PreparePackages (\r
97 IN UINTN NumberOfPackages,\r
98 IN CONST EFI_GUID *Guid OPTIONAL,\r
99 ...\r
100 )\r
101{\r
102 VA_LIST Args;\r
0a869bf8 103\r
dc7b4a5c 104 VA_START (Args, Guid);\r
0a869bf8 105\r
dc7b4a5c 106 return InternalPreparePackages (NumberOfPackages, Guid, Args);\r
107}\r
0a869bf8 108\r
0a869bf8 109\r
dc7b4a5c 110/**\r
111 This function allocates pool for an EFI_HII_PACKAGE_LIST structure\r
112 with additional space that is big enough to host all packages described by the variable \r
113 argument list of package pointers. The allocated structure is initialized using NumberOfPackages, \r
114 GuidId, and the variable length argument list of package pointers.\r
0a869bf8 115\r
dc7b4a5c 116 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The\r
117 Handle to the newly registered Package List is returned throught HiiHandle.\r
118\r
119 @param NumberOfPackages The number of HII packages to register.\r
120 @param GuidId Package List GUID ID.\r
121 @param HiiHandle The ID used to retrieve the Package List later.\r
122 @param ... The variable argument list describing all HII Package.\r
123\r
124 @return\r
125 The allocated and initialized packages.\r
126\r
127**/\r
128\r
129EFI_STATUS\r
130EFIAPI\r
131HiiLibAddPackagesToHiiDatabase (\r
132 IN UINTN NumberOfPackages,\r
133 IN CONST EFI_GUID *GuidId,\r
134 IN EFI_HANDLE DriverHandle, OPTIONAL\r
135 OUT EFI_HII_HANDLE *HiiHandle, OPTIONAL\r
136 ...\r
137 )\r
138{\r
139 VA_LIST Args;\r
140 EFI_HII_PACKAGES *FrameworkHiiPacages;\r
141 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;\r
142 EFI_STATUS Status;\r
143\r
144\r
145 VA_START (Args, HiiHandle);\r
146 FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);\r
147\r
148 Status = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);\r
149 if (HiiHandle != NULL) {\r
150 if (EFI_ERROR (Status)) {\r
151 *HiiHandle = NULL;\r
152 } else {\r
153 *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;\r
154 }\r
0a869bf8 155 }\r
156\r
dc7b4a5c 157 FreePool (FrameworkHiiPacages);\r
158 \r
159 return Status;\r
160}\r
0a869bf8 161\r
dc7b4a5c 162EFI_STATUS\r
163EFIAPI\r
164HiiLibAddFontPackageToHiiDatabase (\r
165 IN UINTN FontSize,\r
166 IN CONST UINT8 *FontBinary,\r
167 IN CONST EFI_GUID *GuidId,\r
168 OUT EFI_HII_HANDLE *HiiHandle OPTIONAL\r
169 )\r
170{\r
171 EFI_STATUS Status;\r
172 EFI_HII_FONT_PACK *FontPack;\r
173 UINT8 *Location;\r
174\r
175 FontPack = AllocateZeroPool (sizeof (EFI_HII_FONT_PACK) + FontSize);\r
176 ASSERT (FontPack != NULL);\r
177\r
178 FontPack->Header.Length = (UINT32) (sizeof (EFI_HII_FONT_PACK) + FontSize);\r
179 FontPack->Header.Type = EFI_HII_FONT;\r
180 FontPack->NumberOfNarrowGlyphs = (UINT16) (FontSize / sizeof (EFI_NARROW_GLYPH));\r
181\r
182 Location = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8));\r
183 CopyMem (Location, FontBinary, FontSize);\r
184\r
185\r
186 //\r
187 // Register our Fonts into the global database\r
188 //\r
189 Status = HiiLibAddPackagesToHiiDatabase (1, NULL, HiiHandle, NULL, FontPack);\r
190 //\r
191 // Free the font database\r
192 //\r
193 FreePool (FontPack);\r
0a869bf8 194\r
dc7b4a5c 195 return Status; \r
0a869bf8 196}\r
dc7b4a5c 197\r
198EFI_STATUS\r
199EFIAPI\r
200HiiLibRemovePackagesFromHiiDatabase (\r
201 IN EFI_HII_HANDLE HiiHandle\r
202 )\r
203{\r
204 return mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);\r
205}\r
206\r
207\r
208/**\r
209 This function adds the string into String Package of each language.\r
210\r
211 @param PackageList Handle of the package list where this string will\r
212 be added.\r
213 @param StringId On return, contains the new strings id, which is\r
214 unique within PackageList.\r
215 @param String Points to the new null-terminated string.\r
216\r
217 @retval EFI_SUCCESS The new string was added successfully.\r
218 @retval EFI_NOT_FOUND The specified PackageList could not be found in\r
219 database.\r
220 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.\r
221 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.\r
222\r
223**/\r
224EFI_STATUS\r
225EFIAPI\r
226HiiLibCreateString (\r
227 IN EFI_HII_HANDLE PackageList,\r
228 OUT EFI_STRING_ID *StringId,\r
229 IN CONST EFI_STRING String\r
230 )\r
231{\r
232 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;\r
233 EFI_STATUS Status;\r
234\r
235 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;\r
236 Status = mHii->NewString (\r
237 mHii,\r
238 NULL,\r
239 FrameworkHiiHandle,\r
240 StringId,\r
241 String\r
242 );\r
243\r
244 return Status;\r
245}\r
246\r
247\r
248EFI_STATUS\r
249EFIAPI\r
250HiiLibUpdateString (\r
251 IN EFI_HII_HANDLE PackageList,\r
252 IN EFI_STRING_ID StringId,\r
253 IN CONST EFI_STRING String\r
254 )\r
255{\r
256 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;\r
257 EFI_STATUS Status;\r
258\r
259 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;\r
260 Status = mHii->NewString (\r
261 mHii,\r
262 NULL,\r
263 FrameworkHiiHandle,\r
264 &StringId,\r
265 String\r
266 );\r
267\r
268 return Status;\r
269}\r
270\r
271//\r
272// Just use the UEFI prototype\r
273//\r
274EFI_STATUS\r
275EFIAPI\r
276HiiLibGetStringFromGuidId (\r
277 IN EFI_GUID *ProducerGuid,\r
278 IN EFI_STRING_ID StringId,\r
279 OUT EFI_STRING *String\r
280 )\r
281{\r
282 return EFI_SUCCESS; \r
283}\r
284\r
285//\r
286// Just use the UEFI prototype\r
287//\r
288EFI_STATUS\r
289EFIAPI\r
290HiiLibGetStringFromHandle (\r
291 IN EFI_HII_HANDLE PackageList,\r
292 IN EFI_STRING_ID StringId,\r
293 OUT EFI_STRING *String\r
294 )\r
295{\r
296 return EFI_SUCCESS;\r
297}\r
298\r
299//\r
300// Just use the UEFI prototype\r
301//\r
302EFI_STATUS\r
303EFIAPI\r
304HiiLibCreateHiiDriverHandle (\r
305 OUT EFI_HANDLE *DriverHandle\r
306 )\r
307{\r
308 //\r
309 // Driver\r
310 // This implementation does nothing as DriverHandle concept only\r
311 // applies to UEFI HII specification.\r
312 //\r
313 \r
314 *DriverHandle = NULL;\r
315 \r
316 return EFI_SUCCESS;\r
317}\r
318\r