2 This file implements functions related to Config Access Protocols installed by
3 by HII Thunk Modules. These Config access Protocols are used to thunk UEFI Config
4 Access Callback to Framework HII Callback and EFI Variable Set/Get operations.
6 Copyright (c) 2008 - 2010, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "HiiDatabase.h"
18 #include "UefiIfrParser.h"
20 BOOLEAN mHiiPackageListUpdated
= FALSE
;
22 HII_VENDOR_DEVICE_PATH mUefiHiiVendorDevicePath
= {
29 (UINT8
) (sizeof (HII_VENDOR_DEVICE_PATH_NODE
)),
30 (UINT8
) ((sizeof (HII_VENDOR_DEVICE_PATH_NODE
)) >> 8)
40 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
42 (UINT8
) (sizeof (EFI_DEVICE_PATH_PROTOCOL
)),
43 (UINT8
) ((sizeof (EFI_DEVICE_PATH_PROTOCOL
)) >> 8)
48 CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate
= {
49 CONFIG_ACCESS_PRIVATE_SIGNATURE
,
54 }, //ConfigAccessProtocol
55 NULL
, //FormCallbackProtocol
60 Get the first EFI_IFR_VARSTORE from the FormSet.
62 @param FormSet The Form Set.
64 @retval FORMSET_STORAGE * Return the first EFI_IFR_VARSTORE.
65 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
68 GetFirstStorageOfFormSet (
69 IN CONST FORM_BROWSER_FORMSET
* FormSet
72 LIST_ENTRY
*StorageList
;
73 FORMSET_STORAGE
*Storage
;
75 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
77 if (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
78 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
86 Get the FORM_BROWSER_STATEMENT that matches the Question's value.
88 @param FormSet The Form Set.
89 @param QuestionId QuestionId
91 @retval FORM_BROWSER_STATEMENT* FORM_BROWSER_STATEMENT that match Question's value.
92 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
94 FORM_BROWSER_STATEMENT
*
95 GetStorageFromQuestionId (
96 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
97 IN EFI_QUESTION_ID QuestionId
100 LIST_ENTRY
*FormList
;
101 LIST_ENTRY
*StatementList
;
102 FORM_BROWSER_FORM
*Form
;
103 FORM_BROWSER_STATEMENT
*Statement
;
105 FormList
= GetFirstNode (&FormSet
->FormListHead
);
107 while (!IsNull (&FormSet
->FormListHead
, FormList
)) {
108 Form
= FORM_BROWSER_FORM_FROM_LINK (FormList
);
110 StatementList
= GetFirstNode (&Form
->StatementListHead
);
112 while (!IsNull (&Form
->StatementListHead
, StatementList
)) {
113 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (StatementList
);
114 if ((QuestionId
== Statement
->QuestionId
) && (Statement
->Storage
!= NULL
)) {
116 // UEFI Question ID is unique in a FormSet.
118 ASSERT (Statement
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
);
121 StatementList
= GetNextNode (&Form
->StatementListHead
, StatementList
);
124 FormList
= GetNextNode (&FormSet
->FormListHead
, FormList
);
131 Get the EFI_IFR_VARSTORE based the ID.
133 @param FormSet The Form Set.
135 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE with the ID.
136 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
139 GetStorageFromVarStoreId (
140 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
141 IN EFI_VARSTORE_ID VarStoreId
144 LIST_ENTRY
*StorageList
;
145 FORMSET_STORAGE
*Storage
;
147 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
149 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
150 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
152 if (VarStoreId
== Storage
->VarStoreId
) {
156 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
163 Get the EFI_IFR_VARSTORE based the <ConfigHdr> string in a <ConfigRequest>
164 or a <ConfigResp> string.
166 @param FormSet The Form Set.
167 @param ConfigString The Configuration String which is defined by UEFI HII.
169 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
170 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
173 GetStorageFromConfigString (
174 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
175 IN CONST EFI_STRING ConfigString
178 LIST_ENTRY
*StorageList
;
179 FORMSET_STORAGE
*Storage
;
182 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
184 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
185 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
187 if ((Storage
->VarStoreId
== FormSet
->DefaultVarStoreId
) && (FormSet
->OriginalDefaultVarStoreName
!= NULL
)) {
188 Name
= FormSet
->OriginalDefaultVarStoreName
;
190 Name
= Storage
->Name
;
193 if (HiiIsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Name
)) {
197 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
204 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
205 by a module using Framework HII Protocol Interfaces.
207 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
208 that Setup Utility can load the Buffer Storage using this protocol.
210 @param Packages The Package List.
211 @param ThunkContext The Thunk Context.
213 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
214 @retval EFI_OUT_RESOURCE There is not enough memory.
218 InstallDefaultConfigAccessProtocol (
219 IN CONST EFI_HII_PACKAGES
*Packages
,
220 IN OUT HII_THUNK_CONTEXT
*ThunkContext
224 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
225 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
227 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
229 ConfigAccessInstance
= AllocateCopyPool (
230 sizeof (CONFIG_ACCESS_PRIVATE
),
231 &gConfigAccessPrivateTempate
233 ASSERT (ConfigAccessInstance
!= NULL
);
236 // Use memory address as unique ID to distinguish from different device paths
237 // This function may be called multi times by the framework HII driver.
239 HiiVendorPath
= AllocateCopyPool (
240 sizeof (HII_VENDOR_DEVICE_PATH
),
241 &mUefiHiiVendorDevicePath
243 ASSERT (HiiVendorPath
!= NULL
);
245 HiiVendorPath
->Node
.UniqueId
= (UINT64
) ((UINTN
) HiiVendorPath
);
247 Status
= gBS
->InstallMultipleProtocolInterfaces (
248 &ThunkContext
->UefiHiiDriverHandle
,
249 &gEfiDevicePathProtocolGuid
,
251 &gEfiHiiConfigAccessProtocolGuid
,
252 &ConfigAccessInstance
->ConfigAccessProtocol
,
255 ASSERT_EFI_ERROR (Status
);
257 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
263 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
264 by a module using Framework HII Protocol Interfaces.
266 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
268 @param ThunkContext The Thunk Context.
272 UninstallDefaultConfigAccessProtocol (
273 IN HII_THUNK_CONTEXT
*ThunkContext
277 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
278 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
280 Status
= gBS
->HandleProtocol (
281 ThunkContext
->UefiHiiDriverHandle
,
282 &gEfiHiiConfigAccessProtocolGuid
,
283 (VOID
**) &ConfigAccess
285 ASSERT_EFI_ERROR (Status
);
287 Status
= gBS
->HandleProtocol (
288 ThunkContext
->UefiHiiDriverHandle
,
289 &gEfiDevicePathProtocolGuid
,
290 (VOID
**) &HiiVendorPath
292 ASSERT_EFI_ERROR (Status
);
294 Status
= gBS
->UninstallMultipleProtocolInterfaces (
295 ThunkContext
->UefiHiiDriverHandle
,
296 &gEfiDevicePathProtocolGuid
,
298 &gEfiHiiConfigAccessProtocolGuid
,
302 ASSERT_EFI_ERROR (Status
);
308 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
310 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
311 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
312 @param Data The data read.
313 @param DataSize The size of data.
315 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
316 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
317 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
321 IN FORMSET_STORAGE
*BufferStorage
,
322 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
332 Status
= FwFormCallBack
->NvRead (
335 &BufferStorage
->Guid
,
340 if (Status
== EFI_BUFFER_TOO_SMALL
) {
341 if (BufferStorage
->Size
!= *DataSize
) {
343 return EFI_INVALID_PARAMETER
;
346 *Data
= AllocateZeroPool (*DataSize
);
348 return EFI_OUT_OF_RESOURCES
;
351 Status
= FwFormCallBack
->NvRead (
354 &BufferStorage
->Guid
,
366 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
368 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
369 @param Data The data read.
370 @param DataSize The size of data.
372 If the UEFI Variable Get Service return the size information of the data
373 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
376 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
377 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
378 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
383 IN FORMSET_STORAGE
*BufferStorage
,
392 Status
= gRT
->GetVariable (
394 &BufferStorage
->Guid
,
399 if (Status
== EFI_BUFFER_TOO_SMALL
) {
401 if (BufferStorage
->Size
!= *DataSize
) {
403 return EFI_INVALID_PARAMETER
;
406 *Data
= AllocateZeroPool (*DataSize
);
408 return EFI_OUT_OF_RESOURCES
;
411 Status
= gRT
->GetVariable (
413 &BufferStorage
->Guid
,
425 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
426 so that data can be read from the data storage such as UEFI Variable or module's
427 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
429 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
430 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
431 includes the routing information as well as the configurable name / value pairs. It is
432 invalid for this string to be in <MultiConfigRequest> format.
434 @param Progress On return, points to a character in the Request string. Points to the string's null
435 terminator if request was successful. Points to the most recent '&' before the first
436 failing name / value pair (or the beginning of the string if the failure is in the first
437 name / value pair) if the request was not successful
438 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
439 values filled in for the names in the Request string. String to be allocated by the called
442 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
443 @retval EFI_SUCCESS The setting is retrived successfully.
444 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
449 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
450 IN CONST EFI_STRING Request
,
451 OUT EFI_STRING
*Progress
,
452 OUT EFI_STRING
*Results
456 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
457 FORMSET_STORAGE
*BufferStorage
;
461 if (Request
== NULL
) {
462 return EFI_NOT_FOUND
;
466 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
468 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
470 if (BufferStorage
== NULL
) {
471 *Progress
= (EFI_STRING
) Request
;
472 return EFI_NOT_FOUND
;
475 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
477 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
479 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
480 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
481 Status
= GetUefiVariable (
487 Status
= CallFormCallBack (
489 ConfigAccess
->FormCallbackProtocol
,
496 // Use the NvMapOverride.
498 DataSize
= BufferStorage
->Size
;
499 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
502 Status
= EFI_SUCCESS
;
504 Status
= EFI_OUT_OF_RESOURCES
;
508 if (!EFI_ERROR (Status
)) {
509 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
510 mHiiConfigRoutingProtocol
,
526 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
527 so that data can be written to the data storage such as UEFI Variable or module's
528 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
530 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
531 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
532 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
533 failing name / value pair (or the beginning of the string if the failure is in the first
534 name / value pair) or the terminating NULL if all was successful.
536 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
537 @retval EFI_SUCCESS The setting is saved successfully.
538 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
543 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
544 IN CONST EFI_STRING Configuration
,
545 OUT EFI_STRING
*Progress
549 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
550 FORMSET_STORAGE
*BufferStorage
;
554 UINTN LastModifiedByteIndex
;
555 BOOLEAN ResetRequired
;
556 BOOLEAN DataAllocated
;
558 if (Configuration
== NULL
) {
559 return EFI_INVALID_PARAMETER
;
563 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
565 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
567 if (BufferStorage
== NULL
) {
568 *Progress
= Configuration
;
569 return EFI_NOT_FOUND
;
572 DataSize2
= BufferStorage
->Size
;
573 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
574 DataAllocated
= TRUE
;
575 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
576 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
577 Status
= GetUefiVariable (
583 Status
= CallFormCallBack (
585 ConfigAccess
->FormCallbackProtocol
,
592 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
594 Status
= EFI_SUCCESS
;
595 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
596 DataSize
= DataSize2
;
597 DataAllocated
= FALSE
;
599 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
601 Data
= AllocateZeroPool (DataSize2
);
605 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
606 mHiiConfigRoutingProtocol
,
609 &LastModifiedByteIndex
,
612 if (EFI_ERROR (Status
)) {
616 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
617 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
618 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
619 Status
= gRT
->SetVariable (
621 &BufferStorage
->Guid
,
622 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
627 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
628 ConfigAccess
->FormCallbackProtocol
,
630 &BufferStorage
->Guid
,
631 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
641 if (DataAllocated
&& (Data
!= NULL
)) {
649 Build the EFI_IFR_DATA_ARRAY which will be used to pass to
650 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of EFI_IFR_DATA_ARRAY
653 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
655 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
656 @param QuestionId The Question ID.
657 @param Type The Question Type.
658 @param Value The Question Value.
659 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
661 @return A pointer to EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
665 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
666 IN EFI_QUESTION_ID QuestionId
,
668 IN EFI_IFR_TYPE_VALUE
*Value
,
669 OUT BOOLEAN
*NvMapAllocated
672 EFI_IFR_DATA_ARRAY
*IfrDataArray
;
673 EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
674 UINTN BrowserDataSize
;
675 FORMSET_STORAGE
*BufferStorage
;
678 FORM_BROWSER_STATEMENT
*Statement
;
680 *NvMapAllocated
= FALSE
;
685 case EFI_IFR_TYPE_NUM_SIZE_8
:
686 case EFI_IFR_TYPE_NUM_SIZE_16
:
687 case EFI_IFR_TYPE_NUM_SIZE_32
:
688 case EFI_IFR_TYPE_NUM_SIZE_64
:
689 case EFI_IFR_TYPE_BOOLEAN
:
690 Size
= sizeof (*Value
);
693 case EFI_IFR_TYPE_STRING
:
694 if (Value
->string
== 0) {
697 String
= HiiGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, NULL
);
698 ASSERT (String
!= NULL
);
700 Size
= StrSize (String
);
704 case EFI_IFR_TYPE_ACTION
:
714 IfrDataArray
= AllocateZeroPool (sizeof (EFI_IFR_DATA_ARRAY
) + sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
715 ASSERT (IfrDataArray
!= NULL
);
716 IfrDataArray
->EntryCount
= 1;
717 IfrDataEntry
= (EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
719 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
721 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
723 // The QuestionId is not associated with a Buffer Storage.
724 // Try to get the first Buffer Storage then.
726 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
728 BufferStorage
= Statement
->Storage
;
729 IfrDataEntry
->OpCode
= Statement
->Operand
;
732 if (BufferStorage
!= NULL
) {
733 BrowserDataSize
= BufferStorage
->Size
;
734 IfrDataEntry
->Length
= (UINT8
) (sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
736 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
737 *NvMapAllocated
= TRUE
;
738 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
740 *NvMapAllocated
= FALSE
;
741 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
744 ASSERT (HiiGetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, (UINT8
*) IfrDataArray
->NvRamMap
));
747 case EFI_IFR_TYPE_NUM_SIZE_8
:
748 case EFI_IFR_TYPE_NUM_SIZE_16
:
749 case EFI_IFR_TYPE_NUM_SIZE_32
:
750 case EFI_IFR_TYPE_NUM_SIZE_64
:
751 case EFI_IFR_TYPE_BOOLEAN
:
752 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
755 case EFI_IFR_TYPE_STRING
:
757 ASSERT (String
!= NULL
);
758 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
763 case EFI_IFR_TYPE_ACTION
:
772 // Need to fiil in the information for the rest of field for EFI_IFR_DATA_ENTRY.
773 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
775 //UINT8 OpCode; // Likely a string, numeric, or one-of
776 //UINT8 Length; // Length of the EFI_IFR_DATA_ENTRY packet
777 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
778 //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
779 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
780 // If the OpCode is a String type - Data is a CHAR16[x] type
781 // If the OpCode is a Checkbox type - Data is a UINT8 value
782 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
789 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
790 needs to be informed when data changed in NvMapOverride. This function will invoke
791 SetBrowserData () to set internal data of Form Browser.
793 @param ConfigAccess The Config Access Private Context.
794 @param QuestionId The Question Id that invokes the callback.
799 SyncBrowserDataForNvMapOverride (
800 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
801 IN EFI_QUESTION_ID QuestionId
804 FORMSET_STORAGE
*BufferStorage
;
806 UINTN BrowserDataSize
;
807 FORM_BROWSER_STATEMENT
*Statement
;
809 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
811 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
813 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
815 // QuestionId is a statement without Storage.
819 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
821 BufferStorage
= Statement
->Storage
;
825 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
827 ASSERT (BufferStorage
!= NULL
);
829 BrowserDataSize
= BufferStorage
->Size
;
831 CheckFlag
= HiiSetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
838 Free up resource allocated for a EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
840 @param Array The EFI_IFR_DATA_ARRAY allocated.
841 @param NvMapAllocated If the NvRamMap is allocated for EFI_IFR_DATA_ARRAY.
845 DestroyIfrDataArray (
846 IN EFI_IFR_DATA_ARRAY
*Array
,
847 IN BOOLEAN NvMapAllocated
851 if (NvMapAllocated
) {
852 FreePool (Array
->NvRamMap
);
860 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
861 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
862 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
863 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
864 for detailed information.
866 @param ThunkContext The Thunk Context.
867 @param QuestionId The Question Id.
868 @param Type The Question Type.
869 @param Value The One Of Option's value.
871 @return The ONE_OF_OPTION_MAP_ENTRY found.
872 @retval NULL If no entry is found.
874 ONE_OF_OPTION_MAP_ENTRY
*
875 GetOneOfOptionMapEntry (
876 IN HII_THUNK_CONTEXT
*ThunkContext
,
877 IN EFI_QUESTION_ID QuestionId
,
879 IN EFI_IFR_TYPE_VALUE
*Value
884 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
885 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
886 FORM_BROWSER_FORMSET
*FormSet
;
888 FormSet
= ThunkContext
->FormSet
;
890 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
892 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
893 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
894 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
895 ASSERT (OneOfOptionMap
->ValueType
== Type
);
897 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
899 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
900 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
902 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
903 return OneOfOptionMapEntry
;
906 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
910 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
918 Functions which are registered to receive notification of
919 database events have this prototype. The actual event is encoded
920 in NotifyType. The following table describes how PackageType,
921 PackageGuid, Handle, and Package are used for each of the
924 If any Pakcage List in database is updated, mHiiPackageListUpdated
925 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
926 will force the UEFI Setup Browser to save the uncommitted data. This
927 is needed as Framework's Callback function may dynamically update
928 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
929 the Package List's IFR and display it. UEFI Config Access's implementation
930 is required to save the modified (SetBrowserData or directly save the data
931 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
932 we will enforce the rule in ThunkCallback (). The side effect of force saving
933 of NV data is the NV flag in browser may not flag a update as data has already
934 been saved to NV storage.
936 @param PackageType Package type of the notification.
938 @param PackageGuid If PackageType is
939 EFI_HII_PACKAGE_TYPE_GUID, then this is
940 the pointer to the GUID from the Guid
941 field of EFI_HII_PACKAGE_GUID_HEADER.
942 Otherwise, it must be NULL.
944 @param Package Points to the package referred to by the
945 notification Handle The handle of the package
946 list which contains the specified package.
948 @param Handle The HII handle.
950 @param NotifyType The type of change concerning the
952 EFI_HII_DATABASE_NOTIFY_TYPE.
958 IN UINT8 PackageType
,
959 IN CONST EFI_GUID
*PackageGuid
,
960 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
961 IN EFI_HII_HANDLE Handle
,
962 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
965 mHiiPackageListUpdated
= TRUE
;
971 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
972 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
974 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
975 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
976 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
977 type of data to expect. The format of the data tends to vary based on the opcode that
978 generated the callback.
979 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
980 EFI_IFR_ONE_OF_OPTION.
981 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
982 by Type. Type EFI_IFR_TYPE_VALUE is defined in
983 EFI_IFR_ONE_OF_OPTION.
984 @param ActionRequest On return, points to the action requested by the callback function. Type
985 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
988 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
989 focuse to be INTERRACTIVE.
990 @retval EFI_SUCCESS The callback complete successfully.
991 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
997 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
998 IN EFI_BROWSER_ACTION Action
,
999 IN EFI_QUESTION_ID QuestionId
,
1001 IN EFI_IFR_TYPE_VALUE
*Value
,
1002 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1006 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
1007 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
1008 EFI_HII_CALLBACK_PACKET
*Packet
;
1009 EFI_IFR_DATA_ARRAY
*Data
;
1010 EFI_IFR_DATA_ENTRY
*DataEntry
;
1012 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
1013 EFI_HANDLE NotifyHandle
;
1015 BOOLEAN NvMapAllocated
;
1017 if ((Action
== EFI_BROWSER_ACTION_FORM_OPEN
) || (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
)) {
1019 // Ignore UEFI OPEN/CLOSE Action for FrameworkCallback
1024 ASSERT (This
!= NULL
);
1025 ASSERT (Value
!= NULL
);
1026 ASSERT (ActionRequest
!= NULL
);
1028 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1030 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
1032 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
1033 if (FormCallbackProtocol
== NULL
) {
1035 return EFI_UNSUPPORTED
;
1039 // Check if the QuestionId match a OneOfOption.
1041 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
1043 if (OneOfOptionMapEntry
== NULL
) {
1045 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1047 KeyValue
= QuestionId
;
1050 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1052 KeyValue
= OneOfOptionMapEntry
->FwKey
;
1056 // Build the EFI_IFR_DATA_ARRAY
1058 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
1060 Status
= mHiiDatabase
->RegisterPackageNotify (
1062 EFI_HII_PACKAGE_FORMS
,
1065 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1069 //Call the Framework Callback function.
1072 Status
= FormCallbackProtocol
->Callback (
1073 FormCallbackProtocol
,
1078 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1081 // Callback require browser to perform action
1083 if (EFI_ERROR (Status
)) {
1084 if (Packet
!= NULL
) {
1086 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, Packet
->String
, NULL
);
1087 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1090 // Error Code in Status is discarded.
1093 if (Packet
!= NULL
) {
1094 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1095 DataEntry
= (EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (EFI_IFR_DATA_ARRAY
));
1096 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1097 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1100 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1101 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1102 &ConfigAccess
->ConfigAccessProtocol
,
1113 // Unregister notify for Form package update
1115 Status
= mHiiDatabase
->UnregisterPackageNotify (
1120 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1121 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1122 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1123 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1124 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1125 // the form and load all the variable storages.
1127 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1128 mHiiPackageListUpdated
= FALSE
;
1129 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1131 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1132 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1133 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1141 DestroyIfrDataArray (Data
, NvMapAllocated
);