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