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