]>
Commit | Line | Data |
---|---|---|
1 | /**@file\r | |
2 | This file implements functions related to Config Access Protocols installed by\r | |
3 | by HII Thunk Modules. These Config access Protocols are used to thunk UEFI Config \r | |
4 | Access Callback to Framework HII Callback and EFI Variable Set/Get operations.\r | |
5 | \r | |
6 | Copyright (c) 2008, Intel Corporation\r | |
7 | All rights reserved. This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include "HiiDatabase.h"\r | |
18 | #include "UefiIfrParser.h"\r | |
19 | \r | |
20 | BOOLEAN mHiiPackageListUpdated = FALSE;\r | |
21 | \r | |
22 | HII_VENDOR_DEVICE_PATH mUefiHiiVendorDevicePath = {\r | |
23 | {\r | |
24 | {\r | |
25 | {\r | |
26 | HARDWARE_DEVICE_PATH,\r | |
27 | HW_VENDOR_DP,\r | |
28 | {\r | |
29 | (UINT8) (sizeof (HII_VENDOR_DEVICE_PATH_NODE)),\r | |
30 | (UINT8) ((sizeof (HII_VENDOR_DEVICE_PATH_NODE)) >> 8)\r | |
31 | }\r | |
32 | },\r | |
33 | EFI_CALLER_ID_GUID\r | |
34 | },\r | |
35 | 0,\r | |
36 | 0\r | |
37 | },\r | |
38 | {\r | |
39 | END_DEVICE_PATH_TYPE,\r | |
40 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
41 | { \r | |
42 | (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL)),\r | |
43 | (UINT8) ((sizeof (EFI_DEVICE_PATH_PROTOCOL)) >> 8)\r | |
44 | }\r | |
45 | }\r | |
46 | };\r | |
47 | \r | |
48 | CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate = {\r | |
49 | CONFIG_ACCESS_PRIVATE_SIGNATURE,\r | |
50 | {\r | |
51 | ThunkExtractConfig,\r | |
52 | ThunkRouteConfig,\r | |
53 | ThunkCallback\r | |
54 | }, //ConfigAccessProtocol\r | |
55 | NULL, //FormCallbackProtocol\r | |
56 | NULL \r | |
57 | };\r | |
58 | \r | |
59 | /**\r | |
60 | Get the first EFI_IFR_VARSTORE from the FormSet. \r | |
61 | \r | |
62 | @param FormSet The Form Set.\r | |
63 | \r | |
64 | @retval FORMSET_STORAGE * Return the first EFI_IFR_VARSTORE.\r | |
65 | @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.\r | |
66 | **/\r | |
67 | FORMSET_STORAGE *\r | |
68 | GetFirstStorageOfFormSet (\r | |
69 | IN CONST FORM_BROWSER_FORMSET * FormSet\r | |
70 | ) \r | |
71 | {\r | |
72 | LIST_ENTRY *StorageList;\r | |
73 | FORMSET_STORAGE *Storage;\r | |
74 | \r | |
75 | StorageList = GetFirstNode (&FormSet->StorageListHead);\r | |
76 | \r | |
77 | if (!IsNull (&FormSet->StorageListHead, StorageList)) {\r | |
78 | Storage = FORMSET_STORAGE_FROM_LINK (StorageList);\r | |
79 | return Storage;\r | |
80 | }\r | |
81 | \r | |
82 | return NULL;\r | |
83 | }\r | |
84 | \r | |
85 | /**\r | |
86 | Get the EFI_IFR_VARSTORE where the Question's value is stored.\r | |
87 | \r | |
88 | @param FormSet The Form Set.\r | |
89 | \r | |
90 | @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.\r | |
91 | @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.\r | |
92 | **/\r | |
93 | FORMSET_STORAGE *\r | |
94 | GetStorageFromQuestionId (\r | |
95 | IN CONST FORM_BROWSER_FORMSET * FormSet,\r | |
96 | IN EFI_QUESTION_ID QuestionId\r | |
97 | )\r | |
98 | {\r | |
99 | LIST_ENTRY *FormList;\r | |
100 | LIST_ENTRY *StatementList;\r | |
101 | FORM_BROWSER_FORM *Form;\r | |
102 | FORM_BROWSER_STATEMENT *Statement;\r | |
103 | \r | |
104 | FormList = GetFirstNode (&FormSet->FormListHead);\r | |
105 | \r | |
106 | while (!IsNull (&FormSet->FormListHead, FormList)) {\r | |
107 | Form = FORM_BROWSER_FORM_FROM_LINK (FormList);\r | |
108 | \r | |
109 | StatementList = GetFirstNode (&Form->StatementListHead);\r | |
110 | \r | |
111 | while (!IsNull (&Form->StatementListHead, StatementList)) {\r | |
112 | Statement = FORM_BROWSER_STATEMENT_FROM_LINK (StatementList);\r | |
113 | if ((QuestionId == Statement->QuestionId) && (Statement->Storage != NULL)) {\r | |
114 | //\r | |
115 | // UEFI Question ID is unique in a FormSet.\r | |
116 | //\r | |
117 | ASSERT (Statement->Storage->Type == EFI_HII_VARSTORE_BUFFER);\r | |
118 | return Statement->Storage;\r | |
119 | }\r | |
120 | StatementList = GetNextNode (&Form->StatementListHead, StatementList);\r | |
121 | }\r | |
122 | \r | |
123 | FormList = GetNextNode (&FormSet->FormListHead, FormList);\r | |
124 | }\r | |
125 | \r | |
126 | return NULL;\r | |
127 | }\r | |
128 | \r | |
129 | /**\r | |
130 | Get the EFI_IFR_VARSTORE based the ID.\r | |
131 | \r | |
132 | @param FormSet The Form Set.\r | |
133 | \r | |
134 | @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE with the ID.\r | |
135 | @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.\r | |
136 | **/\r | |
137 | FORMSET_STORAGE *\r | |
138 | GetStorageFromVarStoreId (\r | |
139 | IN CONST FORM_BROWSER_FORMSET * FormSet,\r | |
140 | IN EFI_VARSTORE_ID VarStoreId\r | |
141 | )\r | |
142 | {\r | |
143 | LIST_ENTRY *StorageList;\r | |
144 | FORMSET_STORAGE *Storage;\r | |
145 | \r | |
146 | StorageList = GetFirstNode (&FormSet->StorageListHead);\r | |
147 | \r | |
148 | while (!IsNull (&FormSet->StorageListHead, StorageList)) {\r | |
149 | Storage = FORMSET_STORAGE_FROM_LINK (StorageList);\r | |
150 | \r | |
151 | if (VarStoreId == Storage->VarStoreId) {\r | |
152 | return Storage;\r | |
153 | }\r | |
154 | \r | |
155 | StorageList = GetNextNode (&FormSet->StorageListHead, StorageList);\r | |
156 | }\r | |
157 | \r | |
158 | return NULL;\r | |
159 | }\r | |
160 | \r | |
161 | /**\r | |
162 | Get the EFI_IFR_VARSTORE based the <ConfigHdr> string in a <ConfigRequest>\r | |
163 | or a <ConfigResp> string.\r | |
164 | \r | |
165 | @param FormSet The Form Set.\r | |
166 | @param ConfigString The Configuration String which is defined by UEFI HII.\r | |
167 | \r | |
168 | @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.\r | |
169 | @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.\r | |
170 | **/\r | |
171 | FORMSET_STORAGE *\r | |
172 | GetStorageFromConfigString (\r | |
173 | IN CONST FORM_BROWSER_FORMSET *FormSet,\r | |
174 | IN CONST EFI_STRING ConfigString\r | |
175 | )\r | |
176 | {\r | |
177 | LIST_ENTRY *StorageList;\r | |
178 | FORMSET_STORAGE *Storage;\r | |
179 | CHAR16 *Name;\r | |
180 | \r | |
181 | StorageList = GetFirstNode (&FormSet->StorageListHead);\r | |
182 | \r | |
183 | while (!IsNull (&FormSet->StorageListHead, StorageList)) {\r | |
184 | Storage = FORMSET_STORAGE_FROM_LINK (StorageList);\r | |
185 | \r | |
186 | if ((Storage->VarStoreId == FormSet->DefaultVarStoreId) && (FormSet->OriginalDefaultVarStoreName != NULL)) {\r | |
187 | Name = FormSet->OriginalDefaultVarStoreName;\r | |
188 | } else {\r | |
189 | Name = Storage->Name;\r | |
190 | }\r | |
191 | \r | |
192 | if (HiiIsConfigHdrMatch (ConfigString, &Storage->Guid, Name)) {\r | |
193 | return Storage;\r | |
194 | }\r | |
195 | \r | |
196 | StorageList = GetNextNode (&FormSet->StorageListHead, StorageList);\r | |
197 | }\r | |
198 | \r | |
199 | return NULL;\r | |
200 | }\r | |
201 | \r | |
202 | /**\r | |
203 | This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered\r | |
204 | by a module using Framework HII Protocol Interfaces.\r | |
205 | \r | |
206 | UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so\r | |
207 | that Setup Utility can load the Buffer Storage using this protocol.\r | |
208 | \r | |
209 | @param Packages The Package List.\r | |
210 | @param ThunkContext The Thunk Context.\r | |
211 | \r | |
212 | @retval EFI_SUCCESS The Config Access Protocol is installed successfully.\r | |
213 | @retval EFI_OUT_RESOURCE There is not enough memory.\r | |
214 | \r | |
215 | **/\r | |
216 | EFI_STATUS\r | |
217 | InstallDefaultConfigAccessProtocol (\r | |
218 | IN CONST EFI_HII_PACKAGES *Packages,\r | |
219 | IN OUT HII_THUNK_CONTEXT *ThunkContext\r | |
220 | )\r | |
221 | {\r | |
222 | EFI_STATUS Status;\r | |
223 | CONFIG_ACCESS_PRIVATE *ConfigAccessInstance;\r | |
224 | HII_VENDOR_DEVICE_PATH *HiiVendorPath;\r | |
225 | \r | |
226 | ASSERT (ThunkContext->IfrPackageCount != 0);\r | |
227 | \r | |
228 | ConfigAccessInstance = AllocateCopyPool (\r | |
229 | sizeof (CONFIG_ACCESS_PRIVATE), \r | |
230 | &gConfigAccessPrivateTempate\r | |
231 | );\r | |
232 | ASSERT (ConfigAccessInstance != NULL);\r | |
233 | \r | |
234 | //\r | |
235 | // Use memory address as unique ID to distinguish from different device paths\r | |
236 | // This function may be called multi times by the framework HII driver.\r | |
237 | //\r | |
238 | HiiVendorPath = AllocateCopyPool (\r | |
239 | sizeof (HII_VENDOR_DEVICE_PATH), \r | |
240 | &mUefiHiiVendorDevicePath\r | |
241 | );\r | |
242 | ASSERT (HiiVendorPath != NULL);\r | |
243 | \r | |
244 | HiiVendorPath->Node.UniqueId = (UINT64) ((UINTN) HiiVendorPath);\r | |
245 | \r | |
246 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
247 | &ThunkContext->UefiHiiDriverHandle,\r | |
248 | &gEfiDevicePathProtocolGuid, \r | |
249 | HiiVendorPath,\r | |
250 | &gEfiHiiConfigAccessProtocolGuid,\r | |
251 | &ConfigAccessInstance->ConfigAccessProtocol,\r | |
252 | NULL\r | |
253 | );\r | |
254 | ASSERT_EFI_ERROR (Status);\r | |
255 | \r | |
256 | ConfigAccessInstance->ThunkContext = ThunkContext;\r | |
257 | \r | |
258 | return EFI_SUCCESS;\r | |
259 | }\r | |
260 | \r | |
261 | /**\r | |
262 | This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered\r | |
263 | by a module using Framework HII Protocol Interfaces.\r | |
264 | \r | |
265 | ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.\r | |
266 | \r | |
267 | @param ThunkContext The Thunk Context.\r | |
268 | \r | |
269 | **/\r | |
270 | VOID\r | |
271 | UninstallDefaultConfigAccessProtocol (\r | |
272 | IN HII_THUNK_CONTEXT *ThunkContext\r | |
273 | )\r | |
274 | {\r | |
275 | EFI_STATUS Status;\r | |
276 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
277 | HII_VENDOR_DEVICE_PATH *HiiVendorPath;\r | |
278 | \r | |
279 | Status = gBS->HandleProtocol (\r | |
280 | ThunkContext->UefiHiiDriverHandle,\r | |
281 | &gEfiHiiConfigAccessProtocolGuid,\r | |
282 | (VOID **) &ConfigAccess\r | |
283 | );\r | |
284 | ASSERT_EFI_ERROR (Status);\r | |
285 | \r | |
286 | Status = gBS->HandleProtocol (\r | |
287 | ThunkContext->UefiHiiDriverHandle,\r | |
288 | &gEfiDevicePathProtocolGuid,\r | |
289 | (VOID **) &HiiVendorPath\r | |
290 | );\r | |
291 | ASSERT_EFI_ERROR (Status);\r | |
292 | \r | |
293 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
294 | ThunkContext->UefiHiiDriverHandle,\r | |
295 | &gEfiDevicePathProtocolGuid,\r | |
296 | HiiVendorPath,\r | |
297 | &gEfiHiiConfigAccessProtocolGuid,\r | |
298 | ConfigAccess,\r | |
299 | NULL\r | |
300 | );\r | |
301 | ASSERT_EFI_ERROR (Status);\r | |
302 | \r | |
303 | }\r | |
304 | \r | |
305 | \r | |
306 | /**\r | |
307 | Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.\r | |
308 | \r | |
309 | @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.\r | |
310 | @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.\r | |
311 | @param Data The data read.\r | |
312 | @param DataSize The size of data.\r | |
313 | \r | |
314 | @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.\r | |
315 | @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data\r | |
316 | does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.\r | |
317 | **/\r | |
318 | EFI_STATUS\r | |
319 | CallFormCallBack (\r | |
320 | IN FORMSET_STORAGE *BufferStorage,\r | |
321 | IN EFI_FORM_CALLBACK_PROTOCOL *FwFormCallBack,\r | |
322 | OUT VOID **Data,\r | |
323 | OUT UINTN *DataSize\r | |
324 | )\r | |
325 | {\r | |
326 | EFI_STATUS Status;\r | |
327 | \r | |
328 | *DataSize = 0;\r | |
329 | *Data = NULL;\r | |
330 | \r | |
331 | Status = FwFormCallBack->NvRead (\r | |
332 | FwFormCallBack, \r | |
333 | BufferStorage->Name,\r | |
334 | &BufferStorage->Guid,\r | |
335 | NULL,\r | |
336 | DataSize,\r | |
337 | *Data\r | |
338 | );\r | |
339 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
340 | if (BufferStorage->Size != *DataSize) {\r | |
341 | ASSERT (FALSE);\r | |
342 | return EFI_INVALID_PARAMETER;\r | |
343 | }\r | |
344 | \r | |
345 | *Data = AllocateZeroPool (*DataSize);\r | |
346 | if (Data == NULL) {\r | |
347 | return EFI_OUT_OF_RESOURCES;\r | |
348 | }\r | |
349 | \r | |
350 | FwFormCallBack->NvRead (\r | |
351 | FwFormCallBack, \r | |
352 | BufferStorage->Name,\r | |
353 | &BufferStorage->Guid,\r | |
354 | NULL,\r | |
355 | DataSize,\r | |
356 | *Data\r | |
357 | );\r | |
358 | }\r | |
359 | \r | |
360 | return Status;\r | |
361 | }\r | |
362 | \r | |
363 | \r | |
364 | /**\r | |
365 | Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.\r | |
366 | \r | |
367 | @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.\r | |
368 | @param Data The data read.\r | |
369 | @param DataSize The size of data.\r | |
370 | \r | |
371 | If the UEFI Variable Get Service return the size information of the data\r | |
372 | does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.\r | |
373 | then ASSERT.\r | |
374 | \r | |
375 | @retval EFI_STATUS The status returned by the UEFI Variable Get Service.\r | |
376 | @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data\r | |
377 | does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.\r | |
378 | **/\r | |
379 | \r | |
380 | EFI_STATUS\r | |
381 | GetUefiVariable (\r | |
382 | IN FORMSET_STORAGE *BufferStorage,\r | |
383 | OUT VOID **Data,\r | |
384 | OUT UINTN *DataSize\r | |
385 | )\r | |
386 | {\r | |
387 | EFI_STATUS Status;\r | |
388 | \r | |
389 | *DataSize = 0;\r | |
390 | *Data = NULL;\r | |
391 | Status = gRT->GetVariable (\r | |
392 | BufferStorage->Name,\r | |
393 | &BufferStorage->Guid,\r | |
394 | NULL,\r | |
395 | DataSize,\r | |
396 | *Data\r | |
397 | );\r | |
398 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
399 | \r | |
400 | if (BufferStorage->Size != *DataSize) {\r | |
401 | ASSERT (FALSE);\r | |
402 | return EFI_INVALID_PARAMETER;\r | |
403 | }\r | |
404 | \r | |
405 | *Data = AllocateZeroPool (*DataSize);\r | |
406 | if (Data == NULL) {\r | |
407 | return EFI_OUT_OF_RESOURCES;\r | |
408 | }\r | |
409 | \r | |
410 | Status = gRT->GetVariable (\r | |
411 | BufferStorage->Name,\r | |
412 | &BufferStorage->Guid,\r | |
413 | NULL,\r | |
414 | DataSize,\r | |
415 | *Data\r | |
416 | );\r | |
417 | }\r | |
418 | \r | |
419 | return Status;\r | |
420 | }\r | |
421 | \r | |
422 | /**\r | |
423 | \r | |
424 | This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig\r | |
425 | so that data can be read from the data storage such as UEFI Variable or module's\r | |
426 | customized storage exposed by EFI_FRAMEWORK_CALLBACK.\r | |
427 | \r | |
428 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL\r | |
429 | @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this\r | |
430 | includes the routing information as well as the configurable name / value pairs. It is\r | |
431 | invalid for this string to be in <MultiConfigRequest> format.\r | |
432 | \r | |
433 | @param Progress On return, points to a character in the Request string. Points to the string's null\r | |
434 | terminator if request was successful. Points to the most recent '&' before the first\r | |
435 | failing name / value pair (or the beginning of the string if the failure is in the first\r | |
436 | name / value pair) if the request was not successful\r | |
437 | @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all\r | |
438 | values filled in for the names in the Request string. String to be allocated by the called\r | |
439 | function.\r | |
440 | \r | |
441 | @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.\r | |
442 | @retval EFI_SUCCESS The setting is retrived successfully.\r | |
443 | @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.\r | |
444 | **/\r | |
445 | EFI_STATUS\r | |
446 | EFIAPI\r | |
447 | ThunkExtractConfig (\r | |
448 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
449 | IN CONST EFI_STRING Request,\r | |
450 | OUT EFI_STRING *Progress,\r | |
451 | OUT EFI_STRING *Results\r | |
452 | )\r | |
453 | {\r | |
454 | EFI_STATUS Status;\r | |
455 | CONFIG_ACCESS_PRIVATE *ConfigAccess;\r | |
456 | FORMSET_STORAGE *BufferStorage;\r | |
457 | VOID *Data;\r | |
458 | UINTN DataSize;\r | |
459 | \r | |
460 | if (Request == NULL) {\r | |
461 | return EFI_NOT_FOUND;\r | |
462 | }\r | |
463 | \r | |
464 | Data = NULL;\r | |
465 | ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);\r | |
466 | \r | |
467 | BufferStorage = GetStorageFromConfigString (ConfigAccess->ThunkContext->FormSet, Request);\r | |
468 | \r | |
469 | if (BufferStorage == NULL) {\r | |
470 | *Progress = (EFI_STRING) Request;\r | |
471 | return EFI_NOT_FOUND;\r | |
472 | }\r | |
473 | \r | |
474 | if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r | |
475 | //\r | |
476 | // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.\r | |
477 | //\r | |
478 | if (ConfigAccess->FormCallbackProtocol == NULL ||\r | |
479 | ConfigAccess->FormCallbackProtocol->NvRead == NULL) {\r | |
480 | Status = GetUefiVariable (\r | |
481 | BufferStorage,\r | |
482 | &Data,\r | |
483 | &DataSize\r | |
484 | );\r | |
485 | } else {\r | |
486 | Status = CallFormCallBack (\r | |
487 | BufferStorage,\r | |
488 | ConfigAccess->FormCallbackProtocol,\r | |
489 | &Data,\r | |
490 | &DataSize\r | |
491 | );\r | |
492 | }\r | |
493 | } else {\r | |
494 | //\r | |
495 | // Use the NvMapOverride.\r | |
496 | //\r | |
497 | DataSize = BufferStorage->Size;\r | |
498 | Data = AllocateCopyPool (DataSize, ConfigAccess->ThunkContext->NvMapOverride);\r | |
499 | \r | |
500 | if (Data != NULL) {\r | |
501 | Status = EFI_SUCCESS;\r | |
502 | } else {\r | |
503 | Status = EFI_OUT_OF_RESOURCES;\r | |
504 | }\r | |
505 | }\r | |
506 | \r | |
507 | if (!EFI_ERROR (Status)) {\r | |
508 | Status = mHiiConfigRoutingProtocol->BlockToConfig (\r | |
509 | mHiiConfigRoutingProtocol,\r | |
510 | Request,\r | |
511 | Data,\r | |
512 | DataSize,\r | |
513 | Results,\r | |
514 | Progress\r | |
515 | );\r | |
516 | }\r | |
517 | \r | |
518 | if (Data != NULL) {\r | |
519 | FreePool (Data);\r | |
520 | }\r | |
521 | return Status;\r | |
522 | }\r | |
523 | \r | |
524 | /**\r | |
525 | This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig\r | |
526 | so that data can be written to the data storage such as UEFI Variable or module's\r | |
527 | customized storage exposed by EFI_FRAMEWORK_CALLBACK.\r | |
528 | \r | |
529 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL\r | |
530 | @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r | |
531 | @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first\r | |
532 | failing name / value pair (or the beginning of the string if the failure is in the first\r | |
533 | name / value pair) or the terminating NULL if all was successful.\r | |
534 | \r | |
535 | @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.\r | |
536 | @retval EFI_SUCCESS The setting is saved successfully.\r | |
537 | @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.\r | |
538 | **/ \r | |
539 | EFI_STATUS\r | |
540 | EFIAPI\r | |
541 | ThunkRouteConfig (\r | |
542 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
543 | IN CONST EFI_STRING Configuration,\r | |
544 | OUT EFI_STRING *Progress\r | |
545 | )\r | |
546 | {\r | |
547 | EFI_STATUS Status;\r | |
548 | CONFIG_ACCESS_PRIVATE *ConfigAccess;\r | |
549 | FORMSET_STORAGE *BufferStorage;\r | |
550 | VOID *Data;\r | |
551 | UINTN DataSize;\r | |
552 | UINTN DataSize2;\r | |
553 | UINTN LastModifiedByteIndex;\r | |
554 | BOOLEAN ResetRequired;\r | |
555 | BOOLEAN DataAllocated;\r | |
556 | \r | |
557 | if (Configuration == NULL) {\r | |
558 | return EFI_INVALID_PARAMETER;\r | |
559 | }\r | |
560 | \r | |
561 | Data = NULL;\r | |
562 | ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);\r | |
563 | \r | |
564 | BufferStorage = GetStorageFromConfigString (ConfigAccess->ThunkContext->FormSet, Configuration);\r | |
565 | \r | |
566 | if (BufferStorage == NULL) {\r | |
567 | *Progress = Configuration;\r | |
568 | return EFI_NOT_FOUND;\r | |
569 | }\r | |
570 | \r | |
571 | DataSize2 = BufferStorage->Size;\r | |
572 | if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r | |
573 | DataAllocated = TRUE;\r | |
574 | if (ConfigAccess->FormCallbackProtocol == NULL ||\r | |
575 | ConfigAccess->FormCallbackProtocol->NvRead == NULL) {\r | |
576 | Status = GetUefiVariable (\r | |
577 | BufferStorage,\r | |
578 | &Data,\r | |
579 | &DataSize\r | |
580 | );\r | |
581 | } else {\r | |
582 | Status = CallFormCallBack (\r | |
583 | BufferStorage,\r | |
584 | ConfigAccess->FormCallbackProtocol,\r | |
585 | &Data,\r | |
586 | &DataSize\r | |
587 | );\r | |
588 | }\r | |
589 | } else {\r | |
590 | //\r | |
591 | // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.\r | |
592 | //\r | |
593 | Status = EFI_SUCCESS;\r | |
594 | Data = ConfigAccess->ThunkContext->NvMapOverride;\r | |
595 | DataSize = DataSize2;\r | |
596 | DataAllocated = FALSE;\r | |
597 | } \r | |
598 | if (EFI_ERROR (Status) || (DataSize2 != DataSize)) {\r | |
599 | if (Data == NULL) {\r | |
600 | Data = AllocateZeroPool (DataSize2);\r | |
601 | }\r | |
602 | }\r | |
603 | \r | |
604 | Status = mHiiConfigRoutingProtocol->ConfigToBlock (\r | |
605 | mHiiConfigRoutingProtocol,\r | |
606 | Configuration,\r | |
607 | Data,\r | |
608 | &LastModifiedByteIndex,\r | |
609 | Progress\r | |
610 | );\r | |
611 | if (EFI_ERROR (Status)) {\r | |
612 | goto Done;\r | |
613 | }\r | |
614 | \r | |
615 | if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r | |
616 | if (ConfigAccess->FormCallbackProtocol == NULL ||\r | |
617 | ConfigAccess->FormCallbackProtocol->NvWrite == NULL) {\r | |
618 | Status = gRT->SetVariable (\r | |
619 | BufferStorage->Name,\r | |
620 | &BufferStorage->Guid,\r | |
621 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
622 | DataSize2,\r | |
623 | Data\r | |
624 | );\r | |
625 | } else {\r | |
626 | Status = ConfigAccess->FormCallbackProtocol->NvWrite (\r | |
627 | ConfigAccess->FormCallbackProtocol, \r | |
628 | BufferStorage->Name,\r | |
629 | &BufferStorage->Guid,\r | |
630 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
631 | DataSize2,\r | |
632 | Data,\r | |
633 | &ResetRequired\r | |
634 | );\r | |
635 | \r | |
636 | }\r | |
637 | }\r | |
638 | \r | |
639 | Done: \r | |
640 | if (DataAllocated && (Data != NULL)) {\r | |
641 | FreePool (Data);\r | |
642 | }\r | |
643 | \r | |
644 | return Status;\r | |
645 | }\r | |
646 | \r | |
647 | /**\r | |
648 | Build the EFI_IFR_DATA_ARRAY which will be used to pass to \r | |
649 | EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of EFI_IFR_DATA_ARRAY\r | |
650 | for details.\r | |
651 | \r | |
652 | ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.\r | |
653 | \r | |
654 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL\r | |
655 | @param QuestionId The Question ID.\r | |
656 | @param Type The Question Type.\r | |
657 | @param Value The Question Value.\r | |
658 | @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.\r | |
659 | \r | |
660 | @return A pointer to EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.\r | |
661 | **/ \r | |
662 | EFI_IFR_DATA_ARRAY *\r | |
663 | CreateIfrDataArray (\r | |
664 | IN CONFIG_ACCESS_PRIVATE *ConfigAccess,\r | |
665 | IN EFI_QUESTION_ID QuestionId,\r | |
666 | IN UINT8 Type,\r | |
667 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
668 | OUT BOOLEAN *NvMapAllocated\r | |
669 | )\r | |
670 | {\r | |
671 | EFI_IFR_DATA_ARRAY *IfrDataArray;\r | |
672 | EFI_IFR_DATA_ENTRY *IfrDataEntry;\r | |
673 | UINTN BrowserDataSize;\r | |
674 | FORMSET_STORAGE *BufferStorage;\r | |
675 | UINTN Size;\r | |
676 | EFI_STRING String;\r | |
677 | \r | |
678 | *NvMapAllocated = FALSE;\r | |
679 | \r | |
680 | String = NULL;\r | |
681 | \r | |
682 | switch (Type) {\r | |
683 | case EFI_IFR_TYPE_NUM_SIZE_8:\r | |
684 | case EFI_IFR_TYPE_NUM_SIZE_16:\r | |
685 | case EFI_IFR_TYPE_NUM_SIZE_32:\r | |
686 | case EFI_IFR_TYPE_NUM_SIZE_64:\r | |
687 | case EFI_IFR_TYPE_BOOLEAN:\r | |
688 | Size = sizeof (*Value);\r | |
689 | break;\r | |
690 | \r | |
691 | case EFI_IFR_TYPE_STRING:\r | |
692 | if (Value->string == 0) {\r | |
693 | Size = 0;\r | |
694 | } else {\r | |
695 | String = HiiGetString (ConfigAccess->ThunkContext->UefiHiiHandle, Value->string, NULL);\r | |
696 | ASSERT (String != NULL);\r | |
697 | \r | |
698 | Size = StrSize (String);\r | |
699 | }\r | |
700 | break;\r | |
701 | \r | |
702 | default:\r | |
703 | ASSERT (FALSE);\r | |
704 | Size = 0;\r | |
705 | break;\r | |
706 | }\r | |
707 | \r | |
708 | IfrDataArray = AllocateZeroPool (sizeof (EFI_IFR_DATA_ARRAY) + sizeof (EFI_IFR_DATA_ENTRY) + Size);\r | |
709 | ASSERT (IfrDataArray != NULL);\r | |
710 | \r | |
711 | BufferStorage = GetStorageFromQuestionId (ConfigAccess->ThunkContext->FormSet, QuestionId);\r | |
712 | \r | |
713 | if (BufferStorage == NULL) {\r | |
714 | //\r | |
715 | // The QuestionId is not associated with a Buffer Storage.\r | |
716 | // Try to get the first Buffer Storage then.\r | |
717 | //\r | |
718 | BufferStorage = GetFirstStorageOfFormSet (ConfigAccess->ThunkContext->FormSet);\r | |
719 | }\r | |
720 | \r | |
721 | if (BufferStorage != NULL) {\r | |
722 | BrowserDataSize = BufferStorage->Size;\r | |
723 | \r | |
724 | if (ConfigAccess->ThunkContext->NvMapOverride == NULL) {\r | |
725 | *NvMapAllocated = TRUE;\r | |
726 | IfrDataArray->NvRamMap = AllocateZeroPool (BrowserDataSize);\r | |
727 | } else {\r | |
728 | *NvMapAllocated = FALSE;\r | |
729 | IfrDataArray->NvRamMap = ConfigAccess->ThunkContext->NvMapOverride;\r | |
730 | }\r | |
731 | \r | |
732 | ASSERT (HiiGetBrowserData (&BufferStorage->Guid, BufferStorage->Name, BrowserDataSize, (UINT8 *) IfrDataArray->NvRamMap));\r | |
733 | IfrDataEntry = (EFI_IFR_DATA_ENTRY *) (IfrDataArray + 1);\r | |
734 | \r | |
735 | switch (Type) {\r | |
736 | case EFI_IFR_TYPE_NUM_SIZE_8:\r | |
737 | case EFI_IFR_TYPE_NUM_SIZE_16:\r | |
738 | case EFI_IFR_TYPE_NUM_SIZE_32:\r | |
739 | case EFI_IFR_TYPE_NUM_SIZE_64:\r | |
740 | case EFI_IFR_TYPE_BOOLEAN:\r | |
741 | CopyMem (&IfrDataEntry->Data, &(Value->u8), sizeof (*Value));\r | |
742 | break;\r | |
743 | \r | |
744 | case EFI_IFR_TYPE_STRING:\r | |
745 | if (Size != 0) {\r | |
746 | ASSERT (String != NULL);\r | |
747 | StrCpy ((CHAR16 *) &IfrDataEntry->Data, String);\r | |
748 | FreePool (String);\r | |
749 | }\r | |
750 | break;\r | |
751 | default:\r | |
752 | ASSERT (FALSE);\r | |
753 | break;\r | |
754 | }\r | |
755 | \r | |
756 | //\r | |
757 | // Need to fiil in the information for the rest of field for EFI_IFR_DATA_ENTRY.\r | |
758 | // It seems that no implementation is found to use other fields. Leave them uninitialized for now.\r | |
759 | //\r | |
760 | //UINT8 OpCode; // Likely a string, numeric, or one-of\r | |
761 | //UINT8 Length; // Length of the EFI_IFR_DATA_ENTRY packet\r | |
762 | //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback\r | |
763 | //VOID *Data; // The data in the form based on the op-code type - this is not a pointer to the data, the data follows immediately\r | |
764 | // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value\r | |
765 | // If the OpCode is a String type - Data is a CHAR16[x] type\r | |
766 | // If the OpCode is a Checkbox type - Data is a UINT8 value\r | |
767 | // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure\r | |
768 | }\r | |
769 | \r | |
770 | return IfrDataArray;\r | |
771 | }\r | |
772 | \r | |
773 | /**\r | |
774 | If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser\r | |
775 | needs to be informed when data changed in NvMapOverride. This function will invoke\r | |
776 | SetBrowserData () to set internal data of Form Browser.\r | |
777 | \r | |
778 | @param ConfigAccess The Config Access Private Context.\r | |
779 | @param QuestionId The Question Id that invokes the callback.\r | |
780 | \r | |
781 | \r | |
782 | **/\r | |
783 | VOID\r | |
784 | SyncBrowserDataForNvMapOverride (\r | |
785 | IN CONST CONFIG_ACCESS_PRIVATE *ConfigAccess,\r | |
786 | IN EFI_QUESTION_ID QuestionId\r | |
787 | )\r | |
788 | {\r | |
789 | FORMSET_STORAGE *BufferStorage;\r | |
790 | BOOLEAN CheckFlag;\r | |
791 | UINTN BrowserDataSize;\r | |
792 | \r | |
793 | if (ConfigAccess->ThunkContext->NvMapOverride != NULL) {\r | |
794 | \r | |
795 | BufferStorage = GetStorageFromQuestionId (ConfigAccess->ThunkContext->FormSet, QuestionId);\r | |
796 | \r | |
797 | if (BufferStorage == NULL) {\r | |
798 | //\r | |
799 | // QuestionId is a statement without Storage.\r | |
800 | // 1) It is a Goto. \r | |
801 | // \r | |
802 | //\r | |
803 | BufferStorage = GetFirstStorageOfFormSet (ConfigAccess->ThunkContext->FormSet);\r | |
804 | }\r | |
805 | \r | |
806 | //\r | |
807 | // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.\r | |
808 | //\r | |
809 | ASSERT (BufferStorage != NULL);\r | |
810 | \r | |
811 | BrowserDataSize = BufferStorage->Size;\r | |
812 | \r | |
813 | CheckFlag = HiiSetBrowserData (&BufferStorage->Guid, BufferStorage->Name, BrowserDataSize, ConfigAccess->ThunkContext->NvMapOverride, NULL);\r | |
814 | ASSERT (CheckFlag);\r | |
815 | }\r | |
816 | \r | |
817 | }\r | |
818 | \r | |
819 | /**\r | |
820 | Free up resource allocated for a EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().\r | |
821 | \r | |
822 | @param Array The EFI_IFR_DATA_ARRAY allocated.\r | |
823 | @param NvMapAllocated If the NvRamMap is allocated for EFI_IFR_DATA_ARRAY.\r | |
824 | \r | |
825 | **/\r | |
826 | VOID\r | |
827 | DestroyIfrDataArray (\r | |
828 | IN EFI_IFR_DATA_ARRAY *Array,\r | |
829 | IN BOOLEAN NvMapAllocated\r | |
830 | )\r | |
831 | {\r | |
832 | if (Array != NULL) {\r | |
833 | if (NvMapAllocated) {\r | |
834 | FreePool (Array->NvRamMap);\r | |
835 | }\r | |
836 | \r | |
837 | FreePool (Array);\r | |
838 | }\r | |
839 | }\r | |
840 | \r | |
841 | /**\r | |
842 | Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the \r | |
843 | EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as\r | |
844 | the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from \r | |
845 | EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY\r | |
846 | for detailed information.\r | |
847 | \r | |
848 | @param ThunkContext The Thunk Context.\r | |
849 | @param QuestionId The Question Id.\r | |
850 | @param Type The Question Type.\r | |
851 | @param Value The One Of Option's value.\r | |
852 | \r | |
853 | @return The ONE_OF_OPTION_MAP_ENTRY found.\r | |
854 | @retval NULL If no entry is found.\r | |
855 | **/\r | |
856 | ONE_OF_OPTION_MAP_ENTRY *\r | |
857 | GetOneOfOptionMapEntry (\r | |
858 | IN HII_THUNK_CONTEXT *ThunkContext,\r | |
859 | IN EFI_QUESTION_ID QuestionId,\r | |
860 | IN UINT8 Type,\r | |
861 | IN EFI_IFR_TYPE_VALUE *Value\r | |
862 | )\r | |
863 | {\r | |
864 | LIST_ENTRY *Link;\r | |
865 | LIST_ENTRY *Link2;\r | |
866 | ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry;\r | |
867 | ONE_OF_OPTION_MAP *OneOfOptionMap;\r | |
868 | FORM_BROWSER_FORMSET *FormSet;\r | |
869 | \r | |
870 | FormSet = ThunkContext->FormSet;\r | |
871 | \r | |
872 | Link = GetFirstNode (&FormSet->OneOfOptionMapListHead);\r | |
873 | \r | |
874 | while (!IsNull (&FormSet->OneOfOptionMapListHead, Link)) {\r | |
875 | OneOfOptionMap = ONE_OF_OPTION_MAP_FROM_LINK(Link);\r | |
876 | if (OneOfOptionMap->QuestionId == QuestionId) {\r | |
877 | ASSERT (OneOfOptionMap->ValueType == Type);\r | |
878 | \r | |
879 | Link2 = GetFirstNode (&OneOfOptionMap->OneOfOptionMapEntryListHead);\r | |
880 | \r | |
881 | while (!IsNull (&OneOfOptionMap->OneOfOptionMapEntryListHead, Link2)) {\r | |
882 | OneOfOptionMapEntry = ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2);\r | |
883 | \r | |
884 | if (CompareMem (Value, &OneOfOptionMapEntry->Value, sizeof (EFI_IFR_TYPE_VALUE)) == 0) {\r | |
885 | return OneOfOptionMapEntry;\r | |
886 | }\r | |
887 | \r | |
888 | Link2 = GetNextNode (&OneOfOptionMap->OneOfOptionMapEntryListHead, Link2);\r | |
889 | }\r | |
890 | }\r | |
891 | \r | |
892 | Link = GetNextNode (&FormSet->OneOfOptionMapListHead, Link);\r | |
893 | }\r | |
894 | \r | |
895 | \r | |
896 | return NULL;\r | |
897 | }\r | |
898 | \r | |
899 | /**\r | |
900 | Functions which are registered to receive notification of\r | |
901 | database events have this prototype. The actual event is encoded\r | |
902 | in NotifyType. The following table describes how PackageType,\r | |
903 | PackageGuid, Handle, and Package are used for each of the\r | |
904 | notification types.\r | |
905 | \r | |
906 | If any Pakcage List in database is updated, mHiiPackageListUpdated\r | |
907 | will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()\r | |
908 | will force the UEFI Setup Browser to save the uncommitted data. This\r | |
909 | is needed as Framework's Callback function may dynamically update\r | |
910 | opcode in a Package List. UEFI Setup Browser will quit itself and reparse\r | |
911 | the Package List's IFR and display it. UEFI Config Access's implementation\r | |
912 | is required to save the modified (SetBrowserData or directly save the data\r | |
913 | to NV storage). But Framework HII Modules is not aware of this rule. Therefore,\r | |
914 | we will enforce the rule in ThunkCallback (). The side effect of force saving\r | |
915 | of NV data is the NV flag in browser may not flag a update as data has already\r | |
916 | been saved to NV storage.\r | |
917 | \r | |
918 | @param PackageType Package type of the notification.\r | |
919 | \r | |
920 | @param PackageGuid If PackageType is\r | |
921 | EFI_HII_PACKAGE_TYPE_GUID, then this is\r | |
922 | the pointer to the GUID from the Guid\r | |
923 | field of EFI_HII_PACKAGE_GUID_HEADER.\r | |
924 | Otherwise, it must be NULL.\r | |
925 | \r | |
926 | @param Package Points to the package referred to by the\r | |
927 | notification Handle The handle of the package\r | |
928 | list which contains the specified package.\r | |
929 | \r | |
930 | @param Handle The HII handle.\r | |
931 | \r | |
932 | @param NotifyType The type of change concerning the\r | |
933 | database. See\r | |
934 | EFI_HII_DATABASE_NOTIFY_TYPE.\r | |
935 | \r | |
936 | **/\r | |
937 | EFI_STATUS\r | |
938 | EFIAPI\r | |
939 | FormUpdateNotify (\r | |
940 | IN UINT8 PackageType,\r | |
941 | IN CONST EFI_GUID *PackageGuid,\r | |
942 | IN CONST EFI_HII_PACKAGE_HEADER *Package,\r | |
943 | IN EFI_HII_HANDLE Handle,\r | |
944 | IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType\r | |
945 | )\r | |
946 | {\r | |
947 | mHiiPackageListUpdated = TRUE;\r | |
948 | \r | |
949 | return EFI_SUCCESS;\r | |
950 | }\r | |
951 | \r | |
952 | /**\r | |
953 | Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,\r | |
954 | the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.\r | |
955 | \r | |
956 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
957 | @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.\r | |
958 | @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the\r | |
959 | type of data to expect. The format of the data tends to vary based on the opcode that\r | |
960 | generated the callback.\r | |
961 | @param Type The type of value for the question. See EFI_IFR_TYPE_x in\r | |
962 | EFI_IFR_ONE_OF_OPTION.\r | |
963 | @param Value A pointer to the data being sent to the original exporting driver. The type is specified\r | |
964 | by Type. Type EFI_IFR_TYPE_VALUE is defined in\r | |
965 | EFI_IFR_ONE_OF_OPTION.\r | |
966 | @param ActionRequest On return, points to the action requested by the callback function. Type\r | |
967 | EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form\r | |
968 | Browser Protocol.\r | |
969 | \r | |
970 | @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under\r | |
971 | focuse to be INTERRACTIVE.\r | |
972 | @retval EFI_SUCCESS The callback complete successfully.\r | |
973 | @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.\r | |
974 | \r | |
975 | **/\r | |
976 | EFI_STATUS\r | |
977 | EFIAPI\r | |
978 | ThunkCallback (\r | |
979 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
980 | IN EFI_BROWSER_ACTION Action,\r | |
981 | IN EFI_QUESTION_ID QuestionId,\r | |
982 | IN UINT8 Type,\r | |
983 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
984 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
985 | )\r | |
986 | {\r | |
987 | EFI_STATUS Status;\r | |
988 | CONFIG_ACCESS_PRIVATE *ConfigAccess;\r | |
989 | EFI_FORM_CALLBACK_PROTOCOL *FormCallbackProtocol;\r | |
990 | EFI_HII_CALLBACK_PACKET *Packet;\r | |
991 | EFI_IFR_DATA_ARRAY *Data;\r | |
992 | EFI_IFR_DATA_ENTRY *DataEntry;\r | |
993 | UINT16 KeyValue;\r | |
994 | ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry;\r | |
995 | EFI_HANDLE NotifyHandle;\r | |
996 | EFI_INPUT_KEY Key; \r | |
997 | BOOLEAN NvMapAllocated;\r | |
998 | \r | |
999 | ASSERT (This != NULL);\r | |
1000 | ASSERT (Value != NULL);\r | |
1001 | ASSERT (ActionRequest != NULL);\r | |
1002 | \r | |
1003 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r | |
1004 | \r | |
1005 | ConfigAccess = CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This);\r | |
1006 | \r | |
1007 | FormCallbackProtocol = ConfigAccess->FormCallbackProtocol;\r | |
1008 | if (FormCallbackProtocol == NULL) {\r | |
1009 | ASSERT (FALSE);\r | |
1010 | return EFI_UNSUPPORTED;\r | |
1011 | }\r | |
1012 | \r | |
1013 | //\r | |
1014 | // Check if the QuestionId match a OneOfOption.\r | |
1015 | //\r | |
1016 | OneOfOptionMapEntry = GetOneOfOptionMapEntry (ConfigAccess->ThunkContext, QuestionId, Type, Value);\r | |
1017 | \r | |
1018 | if (OneOfOptionMapEntry == NULL) {\r | |
1019 | //\r | |
1020 | // This is not a One-Of-Option opcode. QuestionId is the KeyValue\r | |
1021 | //\r | |
1022 | KeyValue = QuestionId;\r | |
1023 | } else {\r | |
1024 | //\r | |
1025 | // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.\r | |
1026 | //\r | |
1027 | KeyValue = OneOfOptionMapEntry->FwKey;\r | |
1028 | }\r | |
1029 | \r | |
1030 | //\r | |
1031 | // Build the EFI_IFR_DATA_ARRAY\r | |
1032 | //\r | |
1033 | Data = CreateIfrDataArray (ConfigAccess, QuestionId, Type, Value, &NvMapAllocated);\r | |
1034 | \r | |
1035 | Status = mHiiDatabase->RegisterPackageNotify (\r | |
1036 | mHiiDatabase,\r | |
1037 | EFI_HII_PACKAGE_FORMS,\r | |
1038 | NULL,\r | |
1039 | FormUpdateNotify,\r | |
1040 | EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,\r | |
1041 | &NotifyHandle\r | |
1042 | );\r | |
1043 | //\r | |
1044 | //Call the Framework Callback function.\r | |
1045 | //\r | |
1046 | Packet = NULL;\r | |
1047 | Status = FormCallbackProtocol->Callback (\r | |
1048 | FormCallbackProtocol,\r | |
1049 | KeyValue,\r | |
1050 | Data,\r | |
1051 | &Packet\r | |
1052 | );\r | |
1053 | SyncBrowserDataForNvMapOverride (ConfigAccess, QuestionId);\r | |
1054 | \r | |
1055 | //\r | |
1056 | // Callback require browser to perform action\r | |
1057 | //\r | |
1058 | if (EFI_ERROR (Status)) {\r | |
1059 | if (Packet != NULL) {\r | |
1060 | do {\r | |
1061 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, Packet->String, NULL);\r | |
1062 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
1063 | }\r | |
1064 | //\r | |
1065 | // Error Code in Status is discarded.\r | |
1066 | //\r | |
1067 | } else {\r | |
1068 | if (Packet != NULL) {\r | |
1069 | if (Packet->DataArray.EntryCount == 1 && Packet->DataArray.NvRamMap == NULL) {\r | |
1070 | DataEntry = (EFI_IFR_DATA_ENTRY *) ((UINT8 *) Packet + sizeof (EFI_IFR_DATA_ARRAY));\r | |
1071 | if ((DataEntry->Flags & EXIT_REQUIRED) == EXIT_REQUIRED) {\r | |
1072 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r | |
1073 | }\r | |
1074 | \r | |
1075 | if ((DataEntry->Flags & SAVE_REQUIRED) == SAVE_REQUIRED) {\r | |
1076 | Status = ConfigAccess->ConfigAccessProtocol.RouteConfig (\r | |
1077 | &ConfigAccess->ConfigAccessProtocol,\r | |
1078 | NULL,\r | |
1079 | NULL\r | |
1080 | );\r | |
1081 | }\r | |
1082 | }\r | |
1083 | FreePool (Packet);\r | |
1084 | }\r | |
1085 | }\r | |
1086 | \r | |
1087 | //\r | |
1088 | // Unregister notify for Form package update\r | |
1089 | //\r | |
1090 | Status = mHiiDatabase->UnregisterPackageNotify (\r | |
1091 | mHiiDatabase,\r | |
1092 | NotifyHandle\r | |
1093 | );\r | |
1094 | //\r | |
1095 | // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function \r | |
1096 | // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load\r | |
1097 | // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.\r | |
1098 | // To make sure customer's previous changes is saved and the changing question behaves as expected, we\r | |
1099 | // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse\r | |
1100 | // the form and load all the variable storages.\r | |
1101 | //\r | |
1102 | if (*ActionRequest == EFI_BROWSER_ACTION_REQUEST_NONE && mHiiPackageListUpdated) {\r | |
1103 | mHiiPackageListUpdated= FALSE;\r | |
1104 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r | |
1105 | } else {\r | |
1106 | if (ConfigAccess->ThunkContext->FormSet->SubClass == EFI_FRONT_PAGE_SUBCLASS ||\r | |
1107 | ConfigAccess->ThunkContext->FormSet->SubClass == EFI_SINGLE_USE_SUBCLASS) {\r | |
1108 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r | |
1109 | }\r | |
1110 | }\r | |
1111 | \r | |
1112 | \r | |
1113 | //\r | |
1114 | // Clean up.\r | |
1115 | //\r | |
1116 | DestroyIfrDataArray (Data, NvMapAllocated);\r | |
1117 | \r | |
1118 | return Status;\r | |
1119 | }\r | |
1120 | \r |