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, 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 CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate
= {
23 CONFIG_ACCESS_PRIVATE_SIGNATURE
,
28 }, //ConfigAccessProtocol
29 NULL
, //FormCallbackProtocol
34 Get the first EFI_IFR_VARSTORE from the FormSet.
36 @param FormSet The Form Set.
38 @retval FORMSET_STORAGE * Return the first EFI_IFR_VARSTORE.
39 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
42 GetFirstStorageOfFormSet (
43 IN CONST FORM_BROWSER_FORMSET
* FormSet
46 LIST_ENTRY
*StorageList
;
47 FORMSET_STORAGE
*Storage
;
49 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
51 if (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
52 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
60 Get the EFI_IFR_VARSTORE where the Question's value is stored.
62 @param FormSet The Form Set.
64 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
65 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
68 GetStorageFromQuestionId (
69 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
70 IN EFI_QUESTION_ID QuestionId
74 LIST_ENTRY
*StatementList
;
75 FORM_BROWSER_FORM
*Form
;
76 FORM_BROWSER_STATEMENT
*Statement
;
78 FormList
= GetFirstNode (&FormSet
->FormListHead
);
80 while (!IsNull (&FormSet
->FormListHead
, FormList
)) {
81 Form
= FORM_BROWSER_FORM_FROM_LINK (FormList
);
83 StatementList
= GetFirstNode (&Form
->StatementListHead
);
85 while (!IsNull (&Form
->StatementListHead
, StatementList
)) {
86 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (StatementList
);
87 if ((QuestionId
== Statement
->QuestionId
) && (Statement
->Storage
!= NULL
)) {
89 // UEFI Question ID is unique in a FormSet.
91 ASSERT (Statement
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
);
92 return Statement
->Storage
;
94 StatementList
= GetNextNode (&Form
->StatementListHead
, StatementList
);
97 FormList
= GetNextNode (&FormSet
->FormListHead
, FormList
);
104 Get the EFI_IFR_VARSTORE based the ID.
106 @param FormSet The Form Set.
108 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE with the ID.
109 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
112 GetStorageFromVarStoreId (
113 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
114 IN EFI_VARSTORE_ID VarStoreId
117 LIST_ENTRY
*StorageList
;
118 FORMSET_STORAGE
*Storage
;
120 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
122 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
123 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
125 if (VarStoreId
== Storage
->VarStoreId
) {
129 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
136 Get the EFI_IFR_VARSTORE based the <ConfigHdr> string in a <ConfigRequest>
137 or a <ConfigResp> string.
139 @param FormSet The Form Set.
140 @param ConfigString The Configuration String which is defined by UEFI HII.
142 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
143 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
146 GetStorageFromConfigString (
147 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
148 IN CONST EFI_STRING ConfigString
151 LIST_ENTRY
*StorageList
;
152 FORMSET_STORAGE
*Storage
;
154 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
156 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
157 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
159 if (IsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Storage
->Name
)) {
163 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
170 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
171 by a module using Framework HII Protocol Interfaces.
173 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
174 that Setup Utility can load the Buffer Storage using this protocol.
176 @param Packages The Package List.
177 @param ThunkContext The Thunk Context.
179 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
180 @retval EFI_OUT_RESOURCE There is not enough memory.
184 InstallDefaultConfigAccessProtocol (
185 IN CONST EFI_HII_PACKAGES
*Packages
,
186 IN OUT HII_THUNK_CONTEXT
*ThunkContext
190 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
192 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
194 Status
= HiiLibCreateHiiDriverHandle (&ThunkContext
->UefiHiiDriverHandle
);
195 ASSERT_EFI_ERROR (Status
);
197 ConfigAccessInstance
= AllocateCopyPool (
198 sizeof (CONFIG_ACCESS_PRIVATE
),
199 &gConfigAccessPrivateTempate
201 ASSERT (ConfigAccessInstance
!= NULL
);
203 Status
= gBS
->InstallMultipleProtocolInterfaces (
204 &ThunkContext
->UefiHiiDriverHandle
,
205 &gEfiHiiConfigAccessProtocolGuid
,
206 &ConfigAccessInstance
->ConfigAccessProtocol
,
209 ASSERT_EFI_ERROR (Status
);
211 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
217 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
218 by a module using Framework HII Protocol Interfaces.
220 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
222 @param ThunkContext The Thunk Context.
226 UninstallDefaultConfigAccessProtocol (
227 IN HII_THUNK_CONTEXT
*ThunkContext
231 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
233 HiiLibDestroyHiiDriverHandle (ThunkContext
->UefiHiiDriverHandle
);
235 Status
= gBS
->HandleProtocol (
236 ThunkContext
->UefiHiiDriverHandle
,
237 &gEfiHiiConfigAccessProtocolGuid
,
238 (VOID
**) &ConfigAccess
240 ASSERT_EFI_ERROR (Status
);
242 Status
= gBS
->UninstallProtocolInterface (
243 ThunkContext
->UefiHiiDriverHandle
,
244 &gEfiHiiConfigAccessProtocolGuid
,
247 ASSERT_EFI_ERROR (Status
);
253 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
255 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
256 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
257 @param Data The data read.
258 @param DataSize The size of data.
260 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
261 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
262 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
266 IN FORMSET_STORAGE
*BufferStorage
,
267 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
277 Status
= FwFormCallBack
->NvRead (
280 &BufferStorage
->Guid
,
285 if (Status
== EFI_BUFFER_TOO_SMALL
) {
286 if (BufferStorage
->Size
!= *DataSize
) {
288 return EFI_INVALID_PARAMETER
;
291 *Data
= AllocateZeroPool (*DataSize
);
293 return EFI_OUT_OF_RESOURCES
;
296 FwFormCallBack
->NvRead (
299 &BufferStorage
->Guid
,
311 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
313 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
314 @param Data The data read.
315 @param DataSize The size of data.
317 If the UEFI Variable Get Service return the size information of the data
318 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
321 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
322 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
323 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
328 IN FORMSET_STORAGE
*BufferStorage
,
337 Status
= gRT
->GetVariable (
339 &BufferStorage
->Guid
,
344 if (Status
== EFI_BUFFER_TOO_SMALL
) {
346 if (BufferStorage
->Size
!= *DataSize
) {
348 return EFI_INVALID_PARAMETER
;
351 *Data
= AllocateZeroPool (*DataSize
);
353 return EFI_OUT_OF_RESOURCES
;
356 Status
= gRT
->GetVariable (
358 &BufferStorage
->Guid
,
370 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
371 so that data can be read from the data storage such as UEFI Variable or module's
372 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
374 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
375 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
376 includes the routing information as well as the configurable name / value pairs. It is
377 invalid for this string to be in <MultiConfigRequest> format.
379 @param Progress On return, points to a character in the Request string. Points to the string's null
380 terminator if request was successful. Points to the most recent '&' before the first
381 failing name / value pair (or the beginning of the string if the failure is in the first
382 name / value pair) if the request was not successful
383 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
384 values filled in for the names in the Request string. String to be allocated by the called
387 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
388 @retval EFI_SUCCESS The setting is retrived successfully.
389 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
394 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
395 IN CONST EFI_STRING Request
,
396 OUT EFI_STRING
*Progress
,
397 OUT EFI_STRING
*Results
401 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
402 FORMSET_STORAGE
*BufferStorage
;
407 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
409 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
411 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
413 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
415 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
416 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
417 Status
= GetUefiVariable (
423 Status
= CallFormCallBack (
425 ConfigAccess
->FormCallbackProtocol
,
432 // Use the NvMapOverride.
434 DataSize
= BufferStorage
->Size
;
435 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
438 Status
= EFI_SUCCESS
;
440 Status
= EFI_OUT_OF_RESOURCES
;
444 if (!EFI_ERROR (Status
)) {
445 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
446 mHiiConfigRoutingProtocol
,
462 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
463 so that data can be written to the data storage such as UEFI Variable or module's
464 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
466 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
467 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
468 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
469 failing name / value pair (or the beginning of the string if the failure is in the first
470 name / value pair) or the terminating NULL if all was successful.
472 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
473 @retval EFI_SUCCESS The setting is saved successfully.
474 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
479 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
480 IN CONST EFI_STRING Configuration
,
481 OUT EFI_STRING
*Progress
485 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
486 FORMSET_STORAGE
*BufferStorage
;
490 UINTN LastModifiedByteIndex
;
491 BOOLEAN ResetRequired
;
492 BOOLEAN DataAllocated
;
495 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
497 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
499 DataSize2
= BufferStorage
->Size
;
500 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
501 DataAllocated
= TRUE
;
502 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
503 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
504 Status
= GetUefiVariable (
510 Status
= CallFormCallBack (
512 ConfigAccess
->FormCallbackProtocol
,
519 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
521 Status
= EFI_SUCCESS
;
522 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
523 DataSize
= DataSize2
;
524 DataAllocated
= FALSE
;
526 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
528 Data
= AllocateZeroPool (DataSize2
);
532 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
533 mHiiConfigRoutingProtocol
,
536 &LastModifiedByteIndex
,
539 if (EFI_ERROR (Status
)) {
543 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
544 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
545 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
546 Status
= gRT
->SetVariable (
548 &BufferStorage
->Guid
,
549 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
554 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
555 ConfigAccess
->FormCallbackProtocol
,
557 &BufferStorage
->Guid
,
558 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
568 if (DataAllocated
&& (Data
!= NULL
)) {
576 Build the FRAMEWORK_EFI_IFR_DATA_ARRAY which will be used to pass to
577 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of FRAMEWORK_EFI_IFR_DATA_ARRAY
580 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
582 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
583 @param QuestionId The Question ID.
584 @param Type The Question Type.
585 @param Value The Question Value.
586 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
588 @return A pointer to FRAMEWORK_EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
590 FRAMEWORK_EFI_IFR_DATA_ARRAY
*
592 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
593 IN EFI_QUESTION_ID QuestionId
,
595 IN EFI_IFR_TYPE_VALUE
*Value
,
596 OUT BOOLEAN
*NvMapAllocated
599 FRAMEWORK_EFI_IFR_DATA_ARRAY
*IfrDataArray
;
600 FRAMEWORK_EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
601 UINTN BrowserDataSize
;
602 FORMSET_STORAGE
*BufferStorage
;
608 *NvMapAllocated
= FALSE
;
613 case EFI_IFR_TYPE_NUM_SIZE_8
:
614 case EFI_IFR_TYPE_NUM_SIZE_16
:
615 case EFI_IFR_TYPE_NUM_SIZE_32
:
616 case EFI_IFR_TYPE_NUM_SIZE_64
:
617 case EFI_IFR_TYPE_BOOLEAN
:
618 Size
= sizeof (*Value
);
621 case EFI_IFR_TYPE_STRING
:
623 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
624 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
626 String
= AllocateZeroPool (StringSize
);
627 ASSERT (String
!= NULL
);
629 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
630 ASSERT_EFI_ERROR (Status
);
641 IfrDataArray
= AllocateZeroPool (sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
) + sizeof (FRAMEWORK_EFI_IFR_DATA_ENTRY
) + Size
);
642 ASSERT (IfrDataArray
!= NULL
);
644 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
646 if (BufferStorage
== NULL
) {
648 // The QuestionId is not associated with a Buffer Storage.
649 // Try to get the first Buffer Storage then.
651 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
654 if (BufferStorage
!= NULL
) {
655 BrowserDataSize
= BufferStorage
->Size
;
657 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
658 *NvMapAllocated
= TRUE
;
659 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
661 *NvMapAllocated
= FALSE
;
662 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
665 Status
= GetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, &BrowserDataSize
, IfrDataArray
->NvRamMap
);
666 ASSERT_EFI_ERROR (Status
);
668 IfrDataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
671 case EFI_IFR_TYPE_NUM_SIZE_8
:
672 case EFI_IFR_TYPE_NUM_SIZE_16
:
673 case EFI_IFR_TYPE_NUM_SIZE_32
:
674 case EFI_IFR_TYPE_NUM_SIZE_64
:
675 case EFI_IFR_TYPE_BOOLEAN
:
676 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
679 case EFI_IFR_TYPE_STRING
:
680 ASSERT (String
!= NULL
);
681 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
690 // Need to fiil in the information for the rest of field for FRAMEWORK_EFI_IFR_DATA_ENTRY.
691 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
693 //UINT8 OpCode; // Likely a string, numeric, or one-of
694 //UINT8 Length; // Length of the FRAMEWORK_EFI_IFR_DATA_ENTRY packet
695 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
696 //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
697 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
698 // If the OpCode is a String type - Data is a CHAR16[x] type
699 // If the OpCode is a Checkbox type - Data is a UINT8 value
700 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
707 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
708 needs to be informed when data changed in NvMapOverride. This function will invoke
709 SetBrowserData () to set internal data of Form Browser.
711 @param ConfigAccess The Config Access Private Context.
712 @param QuestionId The Question Id that invokes the callback.
717 SyncBrowserDataForNvMapOverride (
718 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
719 IN EFI_QUESTION_ID QuestionId
722 FORMSET_STORAGE
*BufferStorage
;
724 UINTN BrowserDataSize
;
726 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
728 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
730 if (BufferStorage
== NULL
) {
732 // QuestionId is a statement without Storage.
736 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
740 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
742 ASSERT (BufferStorage
!= NULL
);
744 BrowserDataSize
= BufferStorage
->Size
;
746 Status
= SetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
747 ASSERT_EFI_ERROR (Status
);
753 Free up resource allocated for a FRAMEWORK_EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
755 @param Array The FRAMEWORK_EFI_IFR_DATA_ARRAY allocated.
756 @param NvMapAllocated If the NvRamMap is allocated for FRAMEWORK_EFI_IFR_DATA_ARRAY.
760 DestroyIfrDataArray (
761 IN FRAMEWORK_EFI_IFR_DATA_ARRAY
*Array
,
762 IN BOOLEAN NvMapAllocated
766 if (NvMapAllocated
) {
767 FreePool (Array
->NvRamMap
);
775 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
776 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
777 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
778 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
779 for detailed information.
781 @param ThunkContext The Thunk Context.
782 @param QuestionId The Question Id.
783 @param Type The Question Type.
784 @param Value The One Of Option's value.
786 @return The ONE_OF_OPTION_MAP_ENTRY found.
787 @retval NULL If no entry is found.
789 ONE_OF_OPTION_MAP_ENTRY
*
790 GetOneOfOptionMapEntry (
791 IN HII_THUNK_CONTEXT
*ThunkContext
,
792 IN EFI_QUESTION_ID QuestionId
,
794 IN EFI_IFR_TYPE_VALUE
*Value
799 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
800 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
801 FORM_BROWSER_FORMSET
*FormSet
;
803 FormSet
= ThunkContext
->FormSet
;
805 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
807 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
808 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
809 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
810 ASSERT (OneOfOptionMap
->ValueType
== Type
);
812 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
814 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
815 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
817 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
818 return OneOfOptionMapEntry
;
821 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
825 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
833 Functions which are registered to receive notification of
834 database events have this prototype. The actual event is encoded
835 in NotifyType. The following table describes how PackageType,
836 PackageGuid, Handle, and Package are used for each of the
839 If any Pakcage List in database is updated, mHiiPackageListUpdated
840 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
841 will force the UEFI Setup Browser to save the uncommitted data. This
842 is needed as Framework's Callback function may dynamically update
843 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
844 the Package List's IFR and display it. UEFI Config Access's implementation
845 is required to save the modified (SetBrowserData or directly save the data
846 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
847 we will enforce the rule in ThunkCallback (). The side effect of force saving
848 of NV data is the NV flag in browser may not flag a update as data has already
849 been saved to NV storage.
851 @param PackageType Package type of the notification.
853 @param PackageGuid If PackageType is
854 EFI_HII_PACKAGE_TYPE_GUID, then this is
855 the pointer to the GUID from the Guid
856 field of EFI_HII_PACKAGE_GUID_HEADER.
857 Otherwise, it must be NULL.
859 @param Package Points to the package referred to by the
860 notification Handle The handle of the package
861 list which contains the specified package.
863 @param Handle The HII handle.
865 @param NotifyType The type of change concerning the
867 EFI_HII_DATABASE_NOTIFY_TYPE.
873 IN UINT8 PackageType
,
874 IN CONST EFI_GUID
*PackageGuid
,
875 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
876 IN EFI_HII_HANDLE Handle
,
877 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
880 mHiiPackageListUpdated
= TRUE
;
886 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
887 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
889 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
890 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
891 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
892 type of data to expect. The format of the data tends to vary based on the opcode that
893 generated the callback.
894 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
895 EFI_IFR_ONE_OF_OPTION.
896 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
897 by Type. Type EFI_IFR_TYPE_VALUE is defined in
898 EFI_IFR_ONE_OF_OPTION.
899 @param ActionRequest On return, points to the action requested by the callback function. Type
900 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
903 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
904 focuse to be INTERRACTIVE.
905 @retval EFI_SUCCESS The callback complete successfully.
906 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
912 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
913 IN EFI_BROWSER_ACTION Action
,
914 IN EFI_QUESTION_ID QuestionId
,
916 IN EFI_IFR_TYPE_VALUE
*Value
,
917 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
921 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
922 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
923 EFI_HII_CALLBACK_PACKET
*Packet
;
924 FRAMEWORK_EFI_IFR_DATA_ARRAY
*Data
;
925 FRAMEWORK_EFI_IFR_DATA_ENTRY
*DataEntry
;
927 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
928 EFI_HANDLE NotifyHandle
;
930 BOOLEAN NvMapAllocated
;
932 ASSERT (This
!= NULL
);
933 ASSERT (Value
!= NULL
);
934 ASSERT (ActionRequest
!= NULL
);
936 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
938 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
940 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
941 if (FormCallbackProtocol
== NULL
) {
943 return EFI_UNSUPPORTED
;
947 // Check if the QuestionId match a OneOfOption.
949 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
951 if (OneOfOptionMapEntry
== NULL
) {
953 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
955 KeyValue
= QuestionId
;
958 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
960 KeyValue
= OneOfOptionMapEntry
->FwKey
;
964 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
966 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
968 Status
= mHiiDatabase
->RegisterPackageNotify (
970 EFI_HII_PACKAGE_FORMS
,
973 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
977 //Call the Framework Callback function.
980 Status
= FormCallbackProtocol
->Callback (
981 FormCallbackProtocol
,
986 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
989 // Callback require browser to perform action
991 if (EFI_ERROR (Status
)) {
992 if (Packet
!= NULL
) {
994 IfrLibCreatePopUp (1, &Key
, Packet
->String
);
995 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
998 // Error Code in Status is discarded.
1001 if (Packet
!= NULL
) {
1002 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1003 DataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
));
1004 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1005 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1008 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1009 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1010 &ConfigAccess
->ConfigAccessProtocol
,
1021 // Unregister notify for Form package update
1023 Status
= mHiiDatabase
->UnregisterPackageNotify (
1028 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1029 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1030 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1031 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1032 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1033 // the form and load all the variable storages.
1035 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1036 mHiiPackageListUpdated
= FALSE
;
1037 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1039 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1040 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1041 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1049 DestroyIfrDataArray (Data
, NvMapAllocated
);