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 <ConfigHdr> string in a <ConfigRequest>
132 or a <ConfigResp> string.
134 @param FormSet The Form Set.
135 @param ConfigString The Configuration String which is defined by UEFI HII.
137 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
138 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
141 GetStorageFromConfigString (
142 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
143 IN CONST EFI_STRING ConfigString
146 LIST_ENTRY
*StorageList
;
147 FORMSET_STORAGE
*Storage
;
150 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
152 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
153 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
155 if ((Storage
->VarStoreId
== FormSet
->DefaultVarStoreId
) && (FormSet
->OriginalDefaultVarStoreName
!= NULL
)) {
156 Name
= FormSet
->OriginalDefaultVarStoreName
;
158 Name
= Storage
->Name
;
161 if (HiiIsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Name
)) {
165 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
172 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
173 by a module using Framework HII Protocol Interfaces.
175 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
176 that Setup Utility can load the Buffer Storage using this protocol.
178 @param Packages The Package List.
179 @param ThunkContext The Thunk Context.
181 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
182 @retval EFI_OUT_RESOURCE There is not enough memory.
186 InstallDefaultConfigAccessProtocol (
187 IN CONST EFI_HII_PACKAGES
*Packages
,
188 IN OUT HII_THUNK_CONTEXT
*ThunkContext
192 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
193 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
195 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
197 ConfigAccessInstance
= AllocateCopyPool (
198 sizeof (CONFIG_ACCESS_PRIVATE
),
199 &gConfigAccessPrivateTempate
201 ASSERT (ConfigAccessInstance
!= NULL
);
204 // Use memory address as unique ID to distinguish from different device paths
205 // This function may be called multi times by the framework HII driver.
207 HiiVendorPath
= AllocateCopyPool (
208 sizeof (HII_VENDOR_DEVICE_PATH
),
209 &mUefiHiiVendorDevicePath
211 ASSERT (HiiVendorPath
!= NULL
);
213 HiiVendorPath
->Node
.UniqueId
= (UINT64
) ((UINTN
) HiiVendorPath
);
215 Status
= gBS
->InstallMultipleProtocolInterfaces (
216 &ThunkContext
->UefiHiiDriverHandle
,
217 &gEfiDevicePathProtocolGuid
,
219 &gEfiHiiConfigAccessProtocolGuid
,
220 &ConfigAccessInstance
->ConfigAccessProtocol
,
223 ASSERT_EFI_ERROR (Status
);
225 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
231 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
232 by a module using Framework HII Protocol Interfaces.
234 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
236 @param ThunkContext The Thunk Context.
240 UninstallDefaultConfigAccessProtocol (
241 IN HII_THUNK_CONTEXT
*ThunkContext
245 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
246 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
248 Status
= gBS
->HandleProtocol (
249 ThunkContext
->UefiHiiDriverHandle
,
250 &gEfiHiiConfigAccessProtocolGuid
,
251 (VOID
**) &ConfigAccess
253 ASSERT_EFI_ERROR (Status
);
255 Status
= gBS
->HandleProtocol (
256 ThunkContext
->UefiHiiDriverHandle
,
257 &gEfiDevicePathProtocolGuid
,
258 (VOID
**) &HiiVendorPath
260 ASSERT_EFI_ERROR (Status
);
262 Status
= gBS
->UninstallMultipleProtocolInterfaces (
263 ThunkContext
->UefiHiiDriverHandle
,
264 &gEfiDevicePathProtocolGuid
,
266 &gEfiHiiConfigAccessProtocolGuid
,
270 ASSERT_EFI_ERROR (Status
);
276 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
278 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
279 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
280 @param Data The data read.
281 @param DataSize The size of data.
283 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
284 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
285 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
289 IN FORMSET_STORAGE
*BufferStorage
,
290 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
300 Status
= FwFormCallBack
->NvRead (
303 &BufferStorage
->Guid
,
308 if (Status
== EFI_BUFFER_TOO_SMALL
) {
309 if (BufferStorage
->Size
!= *DataSize
) {
311 return EFI_INVALID_PARAMETER
;
314 *Data
= AllocateZeroPool (*DataSize
);
316 return EFI_OUT_OF_RESOURCES
;
319 Status
= FwFormCallBack
->NvRead (
322 &BufferStorage
->Guid
,
334 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
336 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
337 @param Data The data read.
338 @param DataSize The size of data.
340 If the UEFI Variable Get Service return the size information of the data
341 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
344 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
345 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
346 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
350 IN FORMSET_STORAGE
*BufferStorage
,
359 Status
= gRT
->GetVariable (
361 &BufferStorage
->Guid
,
366 if (Status
== EFI_BUFFER_TOO_SMALL
) {
368 if (BufferStorage
->Size
!= *DataSize
) {
370 return EFI_INVALID_PARAMETER
;
373 *Data
= AllocateZeroPool (*DataSize
);
375 return EFI_OUT_OF_RESOURCES
;
378 Status
= gRT
->GetVariable (
380 &BufferStorage
->Guid
,
392 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
393 so that data can be read from the data storage such as UEFI Variable or module's
394 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
396 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
397 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
398 includes the routing information as well as the configurable name / value pairs. It is
399 invalid for this string to be in <MultiConfigRequest> format.
401 @param Progress On return, points to a character in the Request string. Points to the string's null
402 terminator if request was successful. Points to the most recent '&' before the first
403 failing name / value pair (or the beginning of the string if the failure is in the first
404 name / value pair) if the request was not successful
405 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
406 values filled in for the names in the Request string. String to be allocated by the called
409 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
410 @retval EFI_SUCCESS The setting is retrived successfully.
411 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
416 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
417 IN CONST EFI_STRING Request
,
418 OUT EFI_STRING
*Progress
,
419 OUT EFI_STRING
*Results
423 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
424 FORMSET_STORAGE
*BufferStorage
;
428 if (Request
== NULL
) {
429 return EFI_NOT_FOUND
;
433 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
435 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
437 if (BufferStorage
== NULL
) {
438 *Progress
= (EFI_STRING
) Request
;
439 return EFI_NOT_FOUND
;
442 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
444 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
446 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
447 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
448 Status
= GetUefiVariable (
454 Status
= CallFormCallBack (
456 ConfigAccess
->FormCallbackProtocol
,
463 // Use the NvMapOverride.
465 DataSize
= BufferStorage
->Size
;
466 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
469 Status
= EFI_SUCCESS
;
471 Status
= EFI_OUT_OF_RESOURCES
;
475 if (!EFI_ERROR (Status
)) {
476 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
477 mHiiConfigRoutingProtocol
,
493 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
494 so that data can be written to the data storage such as UEFI Variable or module's
495 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
497 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
498 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
499 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
500 failing name / value pair (or the beginning of the string if the failure is in the first
501 name / value pair) or the terminating NULL if all was successful.
503 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
504 @retval EFI_SUCCESS The setting is saved successfully.
505 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
510 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
511 IN CONST EFI_STRING Configuration
,
512 OUT EFI_STRING
*Progress
516 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
517 FORMSET_STORAGE
*BufferStorage
;
521 BOOLEAN ResetRequired
;
522 BOOLEAN DataAllocated
;
524 if (Configuration
== NULL
) {
525 return EFI_INVALID_PARAMETER
;
529 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
531 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
533 if (BufferStorage
== NULL
) {
534 *Progress
= Configuration
;
535 return EFI_NOT_FOUND
;
538 DataSize2
= BufferStorage
->Size
;
539 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
540 DataAllocated
= TRUE
;
541 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
542 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
543 Status
= GetUefiVariable (
549 Status
= CallFormCallBack (
551 ConfigAccess
->FormCallbackProtocol
,
558 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
560 Status
= EFI_SUCCESS
;
561 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
562 DataSize
= DataSize2
;
563 DataAllocated
= FALSE
;
565 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
567 Data
= AllocateZeroPool (DataSize2
);
571 DataSize
= DataSize2
;
572 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
573 mHiiConfigRoutingProtocol
,
579 if (EFI_ERROR (Status
)) {
583 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
584 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
585 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
586 Status
= gRT
->SetVariable (
588 &BufferStorage
->Guid
,
589 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
594 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
595 ConfigAccess
->FormCallbackProtocol
,
597 &BufferStorage
->Guid
,
598 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
607 if (DataAllocated
&& (Data
!= NULL
)) {
615 Build the EFI_IFR_DATA_ARRAY which will be used to pass to
616 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of EFI_IFR_DATA_ARRAY
619 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
621 @param ConfigAccess Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
622 @param QuestionId The Question ID.
623 @param Type The Question Type.
624 @param Value The Question Value.
625 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
627 @return A pointer to EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
631 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
632 IN EFI_QUESTION_ID QuestionId
,
634 IN EFI_IFR_TYPE_VALUE
*Value
,
635 OUT BOOLEAN
*NvMapAllocated
638 EFI_IFR_DATA_ARRAY
*IfrDataArray
;
639 EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
640 UINTN BrowserDataSize
;
641 FORMSET_STORAGE
*BufferStorage
;
644 FORM_BROWSER_STATEMENT
*Statement
;
646 *NvMapAllocated
= FALSE
;
651 case EFI_IFR_TYPE_NUM_SIZE_8
:
652 case EFI_IFR_TYPE_NUM_SIZE_16
:
653 case EFI_IFR_TYPE_NUM_SIZE_32
:
654 case EFI_IFR_TYPE_NUM_SIZE_64
:
655 case EFI_IFR_TYPE_BOOLEAN
:
656 Size
= sizeof (*Value
);
659 case EFI_IFR_TYPE_STRING
:
660 if (Value
->string
== 0) {
663 String
= HiiGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, NULL
);
664 ASSERT (String
!= NULL
);
666 Size
= StrSize (String
);
670 case EFI_IFR_TYPE_ACTION
:
680 IfrDataArray
= AllocateZeroPool (sizeof (EFI_IFR_DATA_ARRAY
) + sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
681 ASSERT (IfrDataArray
!= NULL
);
682 IfrDataArray
->EntryCount
= 1;
683 IfrDataEntry
= (EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
685 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
687 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
689 // The QuestionId is not associated with a Buffer Storage.
690 // Try to get the first Buffer Storage then.
692 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
694 BufferStorage
= Statement
->Storage
;
695 IfrDataEntry
->OpCode
= Statement
->Operand
;
698 if (BufferStorage
!= NULL
) {
699 BrowserDataSize
= BufferStorage
->Size
;
700 IfrDataEntry
->Length
= (UINT8
) (sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
702 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
703 *NvMapAllocated
= TRUE
;
704 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
706 *NvMapAllocated
= FALSE
;
707 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
710 ASSERT (HiiGetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, (UINT8
*) IfrDataArray
->NvRamMap
));
713 case EFI_IFR_TYPE_NUM_SIZE_8
:
714 case EFI_IFR_TYPE_NUM_SIZE_16
:
715 case EFI_IFR_TYPE_NUM_SIZE_32
:
716 case EFI_IFR_TYPE_NUM_SIZE_64
:
717 case EFI_IFR_TYPE_BOOLEAN
:
718 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
721 case EFI_IFR_TYPE_STRING
:
723 ASSERT (String
!= NULL
);
724 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
729 case EFI_IFR_TYPE_ACTION
:
738 // Need to fiil in the information for the rest of field for EFI_IFR_DATA_ENTRY.
739 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
741 //UINT8 OpCode; // Likely a string, numeric, or one-of
742 //UINT8 Length; // Length of the EFI_IFR_DATA_ENTRY packet
743 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
744 //VOID *Data; // The data in the form based on the op-code type - this is not a pointer to the data, the data follows immediately
745 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
746 // If the OpCode is a String type - Data is a CHAR16[x] type
747 // If the OpCode is a Checkbox type - Data is a UINT8 value
748 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
755 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
756 needs to be informed when data changed in NvMapOverride. This function will invoke
757 SetBrowserData () to set internal data of Form Browser.
759 @param ConfigAccess The Config Access Private Context.
760 @param QuestionId The Question Id that invokes the callback.
765 SyncBrowserDataForNvMapOverride (
766 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
767 IN EFI_QUESTION_ID QuestionId
770 FORMSET_STORAGE
*BufferStorage
;
772 UINTN BrowserDataSize
;
773 FORM_BROWSER_STATEMENT
*Statement
;
775 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
777 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
779 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
781 // QuestionId is a statement without Storage.
785 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
787 BufferStorage
= Statement
->Storage
;
791 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
793 ASSERT (BufferStorage
!= NULL
);
795 BrowserDataSize
= BufferStorage
->Size
;
797 CheckFlag
= HiiSetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
804 Free up resource allocated for a EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
806 @param Array The EFI_IFR_DATA_ARRAY allocated.
807 @param NvMapAllocated If the NvRamMap is allocated for EFI_IFR_DATA_ARRAY.
811 DestroyIfrDataArray (
812 IN EFI_IFR_DATA_ARRAY
*Array
,
813 IN BOOLEAN NvMapAllocated
817 if (NvMapAllocated
) {
818 FreePool (Array
->NvRamMap
);
826 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
827 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
828 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
829 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
830 for detailed information.
832 @param ThunkContext The Thunk Context.
833 @param QuestionId The Question Id.
834 @param Type The Question Type.
835 @param Value The One Of Option's value.
837 @return The ONE_OF_OPTION_MAP_ENTRY found.
838 @retval NULL If no entry is found.
840 ONE_OF_OPTION_MAP_ENTRY
*
841 GetOneOfOptionMapEntry (
842 IN HII_THUNK_CONTEXT
*ThunkContext
,
843 IN EFI_QUESTION_ID QuestionId
,
845 IN EFI_IFR_TYPE_VALUE
*Value
850 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
851 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
852 FORM_BROWSER_FORMSET
*FormSet
;
854 FormSet
= ThunkContext
->FormSet
;
856 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
858 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
859 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
860 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
861 ASSERT (OneOfOptionMap
->ValueType
== Type
);
863 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
865 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
866 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
868 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
869 return OneOfOptionMapEntry
;
872 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
876 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
884 Functions which are registered to receive notification of
885 database events have this prototype. The actual event is encoded
886 in NotifyType. The following table describes how PackageType,
887 PackageGuid, Handle, and Package are used for each of the
890 If any Pakcage List in database is updated, mHiiPackageListUpdated
891 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
892 will force the UEFI Setup Browser to save the uncommitted data. This
893 is needed as Framework's Callback function may dynamically update
894 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
895 the Package List's IFR and display it. UEFI Config Access's implementation
896 is required to save the modified (SetBrowserData or directly save the data
897 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
898 we will enforce the rule in ThunkCallback (). The side effect of force saving
899 of NV data is the NV flag in browser may not flag a update as data has already
900 been saved to NV storage.
902 @param PackageType Package type of the notification.
904 @param PackageGuid If PackageType is
905 EFI_HII_PACKAGE_TYPE_GUID, then this is
906 the pointer to the GUID from the Guid
907 field of EFI_HII_PACKAGE_GUID_HEADER.
908 Otherwise, it must be NULL.
910 @param Package Points to the package referred to by the
911 notification Handle The handle of the package
912 list which contains the specified package.
914 @param Handle The HII handle.
916 @param NotifyType The type of change concerning the
918 EFI_HII_DATABASE_NOTIFY_TYPE.
924 IN UINT8 PackageType
,
925 IN CONST EFI_GUID
*PackageGuid
,
926 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
927 IN EFI_HII_HANDLE Handle
,
928 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
931 mHiiPackageListUpdated
= TRUE
;
937 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
938 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
940 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
941 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
942 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
943 type of data to expect. The format of the data tends to vary based on the opcode that
944 generated the callback.
945 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
946 EFI_IFR_ONE_OF_OPTION.
947 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
948 by Type. Type EFI_IFR_TYPE_VALUE is defined in
949 EFI_IFR_ONE_OF_OPTION.
950 @param ActionRequest On return, points to the action requested by the callback function. Type
951 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
954 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
955 focuse to be INTERRACTIVE.
956 @retval EFI_SUCCESS The callback complete successfully.
957 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
963 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
964 IN EFI_BROWSER_ACTION Action
,
965 IN EFI_QUESTION_ID QuestionId
,
967 IN EFI_IFR_TYPE_VALUE
*Value
,
968 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
972 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
973 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
974 EFI_HII_CALLBACK_PACKET
*Packet
;
975 EFI_IFR_DATA_ARRAY
*Data
;
976 EFI_IFR_DATA_ENTRY
*DataEntry
;
978 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
979 EFI_HANDLE NotifyHandle
;
981 BOOLEAN NvMapAllocated
;
983 if ((Action
== EFI_BROWSER_ACTION_FORM_OPEN
) || (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
)) {
985 // Ignore UEFI OPEN/CLOSE Action for FrameworkCallback
990 ASSERT (This
!= NULL
);
991 ASSERT (Value
!= NULL
);
992 ASSERT (ActionRequest
!= NULL
);
994 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
996 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
998 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
999 if (FormCallbackProtocol
== NULL
) {
1001 return EFI_UNSUPPORTED
;
1005 // Check if the QuestionId match a OneOfOption.
1007 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
1009 if (OneOfOptionMapEntry
== NULL
) {
1011 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1013 KeyValue
= QuestionId
;
1016 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1018 KeyValue
= OneOfOptionMapEntry
->FwKey
;
1022 // Build the EFI_IFR_DATA_ARRAY
1024 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
1026 Status
= mHiiDatabase
->RegisterPackageNotify (
1028 EFI_HII_PACKAGE_FORMS
,
1031 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1035 //Call the Framework Callback function.
1038 Status
= FormCallbackProtocol
->Callback (
1039 FormCallbackProtocol
,
1044 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1047 // Callback require browser to perform action
1049 if (EFI_ERROR (Status
)) {
1050 if (Packet
!= NULL
) {
1052 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, Packet
->String
, NULL
);
1053 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1056 // Error Code in Status is discarded.
1059 if (Packet
!= NULL
) {
1060 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1061 DataEntry
= (EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (EFI_IFR_DATA_ARRAY
));
1062 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1063 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1066 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1067 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1068 &ConfigAccess
->ConfigAccessProtocol
,
1079 // Unregister notify for Form package update
1081 Status
= mHiiDatabase
->UnregisterPackageNotify (
1086 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1087 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1088 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1089 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1090 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1091 // the form and load all the variable storages.
1093 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1094 mHiiPackageListUpdated
= FALSE
;
1095 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1097 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1098 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1099 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1107 DestroyIfrDataArray (Data
, NvMapAllocated
);