]>
Commit | Line | Data |
---|---|---|
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 |
24 | #include <Library/BaseMemoryLib.h>\r | |
25 | \r | |
bb557845 | 26 | \r |
dc7b4a5c | 27 | EFI_HII_PROTOCOL *mHii = NULL;\r |
28 | \r | |
bb557845 | 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 | |
dc7b4a5c | 42 | EFI_STATUS\r |
43 | EFIAPI\r | |
44 | FrameworkHiiLibConstructor (\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 | |
bb557845 | 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 | |
dc7b4a5c | 74 | EFI_HII_PACKAGES *\r |
75 | InternalPreparePackages (\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 | |
0a869bf8 | 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 | |
53f93f7e | 106 | The allocated structure is initialized using NumberOfPackages, Guid,\r |
0a869bf8 | 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 | |
115 | EFI_HII_PACKAGES *\r | |
116 | EFIAPI\r | |
117 | PreparePackages (\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 | |
0a869bf8 | 124 | \r |
dc7b4a5c | 125 | VA_START (Args, Guid);\r |
0a869bf8 | 126 | \r |
dc7b4a5c | 127 | return InternalPreparePackages (NumberOfPackages, Guid, Args);\r |
128 | }\r | |
0a869bf8 | 129 | \r |
0a869bf8 | 130 | \r |
dc7b4a5c | 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 | |
0a869bf8 | 136 | \r |
dc7b4a5c | 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 HiiHandle The ID used to retrieve the Package List later.\r | |
143 | @param ... The variable argument list describing all HII Package.\r | |
144 | \r | |
145 | @return\r | |
146 | The allocated and initialized packages.\r | |
147 | \r | |
148 | **/\r | |
149 | \r | |
150 | EFI_STATUS\r | |
151 | EFIAPI\r | |
568f78ab | 152 | HiiLibAddPackages (\r |
dc7b4a5c | 153 | IN UINTN NumberOfPackages,\r |
154 | IN CONST EFI_GUID *GuidId,\r | |
155 | IN EFI_HANDLE DriverHandle, OPTIONAL\r | |
156 | OUT EFI_HII_HANDLE *HiiHandle, OPTIONAL\r | |
157 | ...\r | |
158 | )\r | |
159 | {\r | |
160 | VA_LIST Args;\r | |
161 | EFI_HII_PACKAGES *FrameworkHiiPacages;\r | |
162 | FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle;\r | |
163 | EFI_STATUS Status;\r | |
164 | \r | |
165 | \r | |
166 | VA_START (Args, HiiHandle);\r | |
167 | FrameworkHiiPacages = InternalPreparePackages (NumberOfPackages, GuidId, Args);\r | |
168 | \r | |
169 | Status = mHii->NewPack (mHii, FrameworkHiiPacages, &FrameworkHiiHandle);\r | |
170 | if (HiiHandle != NULL) {\r | |
171 | if (EFI_ERROR (Status)) {\r | |
172 | *HiiHandle = NULL;\r | |
173 | } else {\r | |
174 | *HiiHandle = (EFI_HII_HANDLE) (UINTN) FrameworkHiiHandle;\r | |
175 | }\r | |
0a869bf8 | 176 | }\r |
177 | \r | |
dc7b4a5c | 178 | FreePool (FrameworkHiiPacages);\r |
179 | \r | |
180 | return Status;\r | |
181 | }\r | |
0a869bf8 | 182 | \r |
bb557845 | 183 | /**\r |
184 | Removes a package list from the default HII database.\r | |
185 | \r | |
186 | If HiiHandle is NULL, then ASSERT.\r | |
187 | If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.\r | |
188 | \r | |
189 | @param HiiHandle The handle that was previously registered to the data base that is requested for removal.\r | |
190 | List later.\r | |
191 | \r | |
192 | @return VOID\r | |
193 | \r | |
194 | **/\r | |
568f78ab | 195 | VOID\r |
dc7b4a5c | 196 | EFIAPI\r |
568f78ab | 197 | HiiLibRemovePackages (\r |
dc7b4a5c | 198 | IN EFI_HII_HANDLE HiiHandle\r |
199 | )\r | |
200 | {\r | |
568f78ab | 201 | EFI_STATUS Status;\r |
202 | \r | |
203 | Status = mHii->RemovePack (mHii, (FRAMEWORK_EFI_HII_HANDLE) (UINTN) HiiHandle);\r | |
204 | ASSERT_EFI_ERROR (Status);\r | |
dc7b4a5c | 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 | |
224 | EFI_STATUS\r | |
225 | EFIAPI\r | |
568f78ab | 226 | HiiLibNewString (\r |
dc7b4a5c | 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 | |
bb557845 | 247 | /**\r |
248 | Get the string given the StringId and String package Producer's Guid. The caller\r | |
249 | is responsible to free the *String.\r | |
dc7b4a5c | 250 | \r |
bb557845 | 251 | If PackageList with the matching ProducerGuid is not found, then ASSERT.\r |
252 | If PackageList with the matching ProducerGuid is found but no String is\r | |
253 | specified by StringId is found, then ASSERT.\r | |
dc7b4a5c | 254 | \r |
bb557845 | 255 | @param ProducerGuid The Guid of String package list.\r |
256 | @param StringId The String ID.\r | |
257 | @param String The output string.\r | |
dc7b4a5c | 258 | \r |
bb557845 | 259 | @retval EFI_SUCCESS Operation is successful.\r |
260 | @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.\r | |
dc7b4a5c | 261 | \r |
bb557845 | 262 | **/\r |
dc7b4a5c | 263 | EFI_STATUS\r |
264 | EFIAPI\r | |
568f78ab | 265 | HiiLibGetStringFromToken (\r |
dc7b4a5c | 266 | IN EFI_GUID *ProducerGuid,\r |
267 | IN EFI_STRING_ID StringId,\r | |
268 | OUT EFI_STRING *String\r | |
269 | )\r | |
270 | {\r | |
271 | return EFI_SUCCESS; \r | |
272 | }\r | |
273 | \r | |
bb557845 | 274 | /**\r |
275 | Get string specified by StringId form the HiiHandle. The caller\r | |
276 | is responsible to free the *String.\r | |
277 | \r | |
278 | If String is NULL, then ASSERT.\r | |
279 | If HiiHandle could not be found in the default HII database, then ASSERT.\r | |
280 | If StringId is not found in PackageList, then ASSERT.\r | |
281 | \r | |
282 | @param HiiHandle The HII handle of package list.\r | |
283 | @param StringId The String ID.\r | |
284 | @param String The output string.\r | |
285 | \r | |
286 | @retval EFI_NOT_FOUND String is not found.\r | |
287 | @retval EFI_SUCCESS Operation is successful.\r | |
288 | @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.\r | |
289 | @retval EFI_INVALID_PARAMETER The String is NULL.\r | |
290 | \r | |
291 | **/\r | |
dc7b4a5c | 292 | EFI_STATUS\r |
293 | EFIAPI\r | |
294 | HiiLibGetStringFromHandle (\r | |
295 | IN EFI_HII_HANDLE PackageList,\r | |
296 | IN EFI_STRING_ID StringId,\r | |
297 | OUT EFI_STRING *String\r | |
298 | )\r | |
299 | {\r | |
300 | return EFI_SUCCESS;\r | |
301 | }\r | |
302 | \r | |
bb557845 | 303 | /**\r |
304 | Create the driver handle for HII driver. The protocol and \r | |
305 | Package list of this driver wili be installed into this \r | |
306 | driver handle. \r | |
307 | The implement set DriverHandle to NULL simpliy to let \r | |
308 | handle manager create a default new handle.\r | |
309 | \r | |
310 | @param[out] DriverHandle the pointer of driver handle\r | |
311 | @return always successful.\r | |
312 | **/\r | |
dc7b4a5c | 313 | EFI_STATUS\r |
314 | EFIAPI\r | |
315 | HiiLibCreateHiiDriverHandle (\r | |
316 | OUT EFI_HANDLE *DriverHandle\r | |
317 | )\r | |
318 | {\r | |
319 | //\r | |
320 | // Driver\r | |
321 | // This implementation does nothing as DriverHandle concept only\r | |
322 | // applies to UEFI HII specification.\r | |
323 | //\r | |
324 | \r | |
325 | *DriverHandle = NULL;\r | |
326 | \r | |
327 | return EFI_SUCCESS;\r | |
328 | }\r | |
329 | \r |