]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.c
Retire FrameworkHiiLib library class. Remove FrameworkHiiLib library instance now...
[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
0a869bf8 13**/\r
14\r
ed7748fe 15\r
564995cd 16#include <FrameworkDxe.h>\r
ed7748fe 17\r
dc7b4a5c 18#include <Protocol/FrameworkHii.h>\r
19\r
8e5b17b2 20#include <Library/FrameworkHiiLib.h>\r
53f93f7e 21#include <Library/DebugLib.h>\r
22#include <Library/MemoryAllocationLib.h>\r
dc7b4a5c 23#include <Library/UefiBootServicesTableLib.h>\r
bb557845 24\r
dc7b4a5c 25EFI_HII_PROTOCOL *mHii = NULL;\r
26\r
bb557845 27/**\r
28 Library constustor function for HiiLib library instance locate the\r
29 gEfiHiiProtocolGuid firstly, the other interface in this library\r
30 instance will dependent on the protocol of gEfiHiiProtocolGuid.\r
31 So the depex of gEfiHiiProtocolGuid is required for this library \r
32 instance.\r
33 If protocol of gEfiHiiProtocolGuid is not installed, then ASSERT().\r
34 \r
409f118c 35 @param ImageHandle The image handle of driver module who use this library instance.\r
a387653d 36 @param SystemTable Pointer to the EFI System Table.\r
409f118c 37 \r
a387653d 38 @retval EFI_SUCCESS library constuctor always success.\r
bb557845 39**/\r
dc7b4a5c 40EFI_STATUS\r
41EFIAPI\r
42FrameworkHiiLibConstructor (\r
409f118c 43 IN EFI_HANDLE ImageHandle,\r
44 IN EFI_SYSTEM_TABLE *SystemTable\r
dc7b4a5c 45 )\r
46{\r
409f118c 47 EFI_STATUS Status;\r
dc7b4a5c 48 \r
49 Status = gBS->LocateProtocol (\r
409f118c 50 &gEfiHiiProtocolGuid,\r
51 NULL,\r
52 (VOID **) &mHii\r
53 );\r
dc7b4a5c 54 ASSERT_EFI_ERROR (Status);\r
55 ASSERT (mHii != NULL);\r
56\r
57 return EFI_SUCCESS;\r
58}\r
59\r
bb557845 60/**\r
61 This function is internal function that prepare and create\r
62 HII packages with given number and package's guid.\r
63 It is invoked by HiiAddPackages() and PreparePackages() interface.\r
64 If the parameter of package's number is 0, then ASSERT().\r
65 \r
66 @param NumberOfPackages Given number of package item in a HII package list.\r
67 @param Guid Given GUID of a HII package list.\r
68 @param Marker Package's content list.\r
69 \r
409f118c 70 @return pointer to new created HII package list.\r
bb557845 71**/\r
dc7b4a5c 72EFI_HII_PACKAGES *\r
73InternalPreparePackages (\r
409f118c 74 IN UINTN NumberOfPackages,\r
75 IN CONST EFI_GUID *Guid OPTIONAL,\r
76 IN VA_LIST Marker\r
dc7b4a5c 77 )\r
78{\r
409f118c 79 EFI_HII_PACKAGES *HiiPackages;\r
80 VOID **Package;\r
81 UINTN Index;\r
dc7b4a5c 82\r
83 ASSERT (NumberOfPackages > 0);\r
84\r
409f118c 85 HiiPackages = AllocateZeroPool (sizeof (EFI_HII_PACKAGES) + NumberOfPackages * sizeof (VOID *));\r
dc7b4a5c 86 ASSERT (HiiPackages != NULL);\r
87\r
88 HiiPackages->GuidId = (EFI_GUID *) Guid;\r
89 HiiPackages->NumberOfPackages = NumberOfPackages;\r
90 Package = (VOID **) (((UINT8 *) HiiPackages) + sizeof (EFI_HII_PACKAGES));\r
91\r
92 for (Index = 0; Index < NumberOfPackages; Index++) {\r
93 *Package = VA_ARG (Marker, VOID *);\r
94 Package++;\r
95 }\r
96\r
97 return HiiPackages;\r
dc7b4a5c 98}\r
99\r
0a869bf8 100/**\r
101 This function allocates pool for an EFI_HII_PACKAGES structure\r
102 with enough space for the variable argument list of package pointers.\r
53f93f7e 103 The allocated structure is initialized using NumberOfPackages, Guid,\r
0a869bf8 104 and the variable length argument list of package pointers.\r
105\r
cd15d471 106 @param NumberOfPackages The number of HII packages to prepare.\r
107 @param Guid Package GUID.\r
409f118c 108 @param ... The variable argument list of package pointers.\r
0a869bf8 109\r
409f118c 110 @return The allocated and initialized packages.\r
0a869bf8 111**/\r
112EFI_HII_PACKAGES *\r
113EFIAPI\r
114PreparePackages (\r
409f118c 115 IN UINTN NumberOfPackages,\r
116 IN CONST EFI_GUID *Guid OPTIONAL,\r
0a869bf8 117 ...\r
118 )\r
119{\r
409f118c 120 VA_LIST Args;\r
0a869bf8 121\r
dc7b4a5c 122 VA_START (Args, Guid);\r
dc7b4a5c 123 return InternalPreparePackages (NumberOfPackages, Guid, Args);\r
124}\r
0a869bf8 125\r
0a869bf8 126\r
dc7b4a5c 127/**\r
128 This function allocates pool for an EFI_HII_PACKAGE_LIST structure\r
129 with additional space that is big enough to host all packages described by the variable \r
130 argument list of package pointers. The allocated structure is initialized using NumberOfPackages, \r
131 GuidId, and the variable length argument list of package pointers.\r
0a869bf8 132\r
dc7b4a5c 133 Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The\r
134 Handle to the newly registered Package List is returned throught HiiHandle.\r
135\r
409f118c 136 @param NumberOfPackages The number of HII packages to register.\r
137 @param GuidId Package List GUID ID.\r
138 @param DriverHandle The pointer of driver handle\r
139 @param HiiHandle The ID used to retrieve the Package List later.\r
140 @param ... The variable argument list describing all HII Package.\r
dc7b4a5c 141\r
409f118c 142 @return The allocated and initialized packages.\r
dc7b4a5c 143**/\r
dc7b4a5c 144EFI_STATUS\r
145EFIAPI\r
568f78ab 146HiiLibAddPackages (\r
409f118c 147 IN UINTN NumberOfPackages,\r
148 IN CONST EFI_GUID *GuidId,\r
149 IN EFI_HANDLE DriverHandle, OPTIONAL\r
150 OUT EFI_HII_HANDLE *HiiHandle, \r
dc7b4a5c 151 ...\r
152 )\r
153{\r
409f118c 154 VA_LIST Args;\r
155 EFI_HII_PACKAGES *FrameworkHiiPacages;\r
156 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;\r
157 EFI_STATUS Status;\r
dc7b4a5c 158\r
159 VA_START (Args, HiiHandle);\r
dc7b4a5c 160\r
409f118c 161 FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);\r
162 Status = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);\r
dc7b4a5c 163 if (HiiHandle != NULL) {\r
164 if (EFI_ERROR (Status)) {\r
165 *HiiHandle = NULL;\r
166 } else {\r
167 *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;\r
168 }\r
0a869bf8 169 }\r
170\r
dc7b4a5c 171 FreePool (FrameworkHiiPacages);\r
172 \r
173 return Status;\r
174}\r
0a869bf8 175\r
bb557845 176/**\r
177 Removes a package list from the default HII database.\r
178\r
179 If HiiHandle is NULL, then ASSERT.\r
180 If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.\r
181\r
409f118c 182 @param HiiHandle The handle that was previously registered to the data base that is requested for removal.\r
bb557845 183\r
409f118c 184 @return VOID\r
bb557845 185**/\r
568f78ab 186VOID\r
dc7b4a5c 187EFIAPI\r
568f78ab 188HiiLibRemovePackages (\r
409f118c 189 IN EFI_HII_HANDLE HiiHandle\r
dc7b4a5c 190 )\r
191{\r
409f118c 192 EFI_STATUS Status;\r
568f78ab 193 \r
194 Status = mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);\r
195 ASSERT_EFI_ERROR (Status);\r
dc7b4a5c 196}\r
197\r
dc7b4a5c 198/**\r
199 This function adds the string into String Package of each language.\r
200\r
201 @param PackageList Handle of the package list where this string will\r
202 be added.\r
203 @param StringId On return, contains the new strings id, which is\r
204 unique within PackageList.\r
205 @param String Points to the new null-terminated string.\r
206\r
207 @retval EFI_SUCCESS The new string was added successfully.\r
208 @retval EFI_NOT_FOUND The specified PackageList could not be found in\r
209 database.\r
210 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.\r
211 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL is NULL.\r
212\r
213**/\r
214EFI_STATUS\r
215EFIAPI\r
568f78ab 216HiiLibNewString (\r
409f118c 217 IN EFI_HII_HANDLE PackageList,\r
218 OUT EFI_STRING_ID *StringId,\r
219 IN CONST EFI_STRING String\r
dc7b4a5c 220 )\r
221{\r
409f118c 222 FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;\r
223 EFI_STATUS Status;\r
dc7b4a5c 224\r
225 FrameworkHiiHandle = (FRAMEWORK_EFI_HII_HANDLE) (UINTN) PackageList;\r
226 Status = mHii->NewString (\r
409f118c 227 mHii,\r
228 NULL,\r
229 FrameworkHiiHandle,\r
230 StringId,\r
231 String\r
232 );\r
dc7b4a5c 233\r
234 return Status;\r
235}\r
236\r
bb557845 237/**\r
238 Get the string given the StringId and String package Producer's Guid. The caller\r
239 is responsible to free the *String.\r
dc7b4a5c 240\r
bb557845 241 If PackageList with the matching ProducerGuid is not found, then ASSERT.\r
242 If PackageList with the matching ProducerGuid is found but no String is\r
243 specified by StringId is found, then ASSERT.\r
dc7b4a5c 244\r
bb557845 245 @param ProducerGuid The Guid of String package list.\r
246 @param StringId The String ID.\r
247 @param String The output string.\r
dc7b4a5c 248\r
bb557845 249 @retval EFI_SUCCESS Operation is successful.\r
250 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.\r
bb557845 251**/\r
dc7b4a5c 252EFI_STATUS\r
253EFIAPI\r
568f78ab 254HiiLibGetStringFromToken (\r
409f118c 255 IN EFI_GUID *ProducerGuid,\r
256 IN EFI_STRING_ID StringId,\r
257 OUT EFI_STRING *String\r
dc7b4a5c 258 )\r
259{\r
260 return EFI_SUCCESS; \r
261}\r
262\r
bb557845 263/**\r
264 Get string specified by StringId form the HiiHandle. The caller\r
265 is responsible to free the *String.\r
266\r
267 If String is NULL, then ASSERT.\r
268 If HiiHandle could not be found in the default HII database, then ASSERT.\r
269 If StringId is not found in PackageList, then ASSERT.\r
270\r
7459094d 271 @param PackageList The HII handle of package list.\r
bb557845 272 @param StringId The String ID.\r
273 @param String The output string.\r
274\r
275 @retval EFI_NOT_FOUND String is not found.\r
276 @retval EFI_SUCCESS Operation is successful.\r
277 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.\r
bb557845 278\r
279**/\r
dc7b4a5c 280EFI_STATUS\r
281EFIAPI\r
282HiiLibGetStringFromHandle (\r
409f118c 283 IN EFI_HII_HANDLE PackageList,\r
284 IN EFI_STRING_ID StringId,\r
285 OUT EFI_STRING *String\r
dc7b4a5c 286 )\r
287{\r
288 return EFI_SUCCESS;\r
289}\r
290\r
bb557845 291/**\r
292 Create the driver handle for HII driver. The protocol and \r
293 Package list of this driver wili be installed into this \r
294 driver handle. \r
295 The implement set DriverHandle to NULL simpliy to let \r
296 handle manager create a default new handle.\r
297 \r
409f118c 298 @param DriverHandle The pointer of driver handle\r
299 \r
300 @return Always success.\r
bb557845 301**/\r
dc7b4a5c 302EFI_STATUS\r
303EFIAPI\r
304HiiLibCreateHiiDriverHandle (\r
409f118c 305 OUT EFI_HANDLE *DriverHandle\r
dc7b4a5c 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