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