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