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