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
;
406 if (Request
== NULL
) {
407 return EFI_NOT_FOUND
;
411 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
413 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
415 if (BufferStorage
== NULL
) {
416 *Progress
= (EFI_STRING
) Request
;
417 return EFI_NOT_FOUND
;
420 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
422 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
424 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
425 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
426 Status
= GetUefiVariable (
432 Status
= CallFormCallBack (
434 ConfigAccess
->FormCallbackProtocol
,
441 // Use the NvMapOverride.
443 DataSize
= BufferStorage
->Size
;
444 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
447 Status
= EFI_SUCCESS
;
449 Status
= EFI_OUT_OF_RESOURCES
;
453 if (!EFI_ERROR (Status
)) {
454 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
455 mHiiConfigRoutingProtocol
,
471 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
472 so that data can be written to the data storage such as UEFI Variable or module's
473 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
475 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
476 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
477 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
478 failing name / value pair (or the beginning of the string if the failure is in the first
479 name / value pair) or the terminating NULL if all was successful.
481 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
482 @retval EFI_SUCCESS The setting is saved successfully.
483 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
488 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
489 IN CONST EFI_STRING Configuration
,
490 OUT EFI_STRING
*Progress
494 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
495 FORMSET_STORAGE
*BufferStorage
;
499 UINTN LastModifiedByteIndex
;
500 BOOLEAN ResetRequired
;
501 BOOLEAN DataAllocated
;
503 if (Configuration
== NULL
) {
504 return EFI_INVALID_PARAMETER
;
508 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
510 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
512 if (BufferStorage
== NULL
) {
513 *Progress
= Configuration
;
514 return EFI_NOT_FOUND
;
517 DataSize2
= BufferStorage
->Size
;
518 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
519 DataAllocated
= TRUE
;
520 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
521 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
522 Status
= GetUefiVariable (
528 Status
= CallFormCallBack (
530 ConfigAccess
->FormCallbackProtocol
,
537 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
539 Status
= EFI_SUCCESS
;
540 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
541 DataSize
= DataSize2
;
542 DataAllocated
= FALSE
;
544 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
546 Data
= AllocateZeroPool (DataSize2
);
550 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
551 mHiiConfigRoutingProtocol
,
554 &LastModifiedByteIndex
,
557 if (EFI_ERROR (Status
)) {
561 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
562 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
563 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
564 Status
= gRT
->SetVariable (
566 &BufferStorage
->Guid
,
567 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
572 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
573 ConfigAccess
->FormCallbackProtocol
,
575 &BufferStorage
->Guid
,
576 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
586 if (DataAllocated
&& (Data
!= NULL
)) {
594 Build the FRAMEWORK_EFI_IFR_DATA_ARRAY which will be used to pass to
595 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of FRAMEWORK_EFI_IFR_DATA_ARRAY
598 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
600 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
601 @param QuestionId The Question ID.
602 @param Type The Question Type.
603 @param Value The Question Value.
604 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
606 @return A pointer to FRAMEWORK_EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
608 FRAMEWORK_EFI_IFR_DATA_ARRAY
*
610 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
611 IN EFI_QUESTION_ID QuestionId
,
613 IN EFI_IFR_TYPE_VALUE
*Value
,
614 OUT BOOLEAN
*NvMapAllocated
617 FRAMEWORK_EFI_IFR_DATA_ARRAY
*IfrDataArray
;
618 FRAMEWORK_EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
619 UINTN BrowserDataSize
;
620 FORMSET_STORAGE
*BufferStorage
;
626 *NvMapAllocated
= FALSE
;
631 case EFI_IFR_TYPE_NUM_SIZE_8
:
632 case EFI_IFR_TYPE_NUM_SIZE_16
:
633 case EFI_IFR_TYPE_NUM_SIZE_32
:
634 case EFI_IFR_TYPE_NUM_SIZE_64
:
635 case EFI_IFR_TYPE_BOOLEAN
:
636 Size
= sizeof (*Value
);
639 case EFI_IFR_TYPE_STRING
:
641 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
642 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
644 String
= AllocateZeroPool (StringSize
);
645 ASSERT (String
!= NULL
);
647 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
648 ASSERT_EFI_ERROR (Status
);
659 IfrDataArray
= AllocateZeroPool (sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
) + sizeof (FRAMEWORK_EFI_IFR_DATA_ENTRY
) + Size
);
660 ASSERT (IfrDataArray
!= NULL
);
662 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
664 if (BufferStorage
== NULL
) {
666 // The QuestionId is not associated with a Buffer Storage.
667 // Try to get the first Buffer Storage then.
669 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
672 if (BufferStorage
!= NULL
) {
673 BrowserDataSize
= BufferStorage
->Size
;
675 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
676 *NvMapAllocated
= TRUE
;
677 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
679 *NvMapAllocated
= FALSE
;
680 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
683 Status
= GetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, &BrowserDataSize
, IfrDataArray
->NvRamMap
);
684 ASSERT_EFI_ERROR (Status
);
686 IfrDataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
689 case EFI_IFR_TYPE_NUM_SIZE_8
:
690 case EFI_IFR_TYPE_NUM_SIZE_16
:
691 case EFI_IFR_TYPE_NUM_SIZE_32
:
692 case EFI_IFR_TYPE_NUM_SIZE_64
:
693 case EFI_IFR_TYPE_BOOLEAN
:
694 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
697 case EFI_IFR_TYPE_STRING
:
698 ASSERT (String
!= NULL
);
699 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
708 // Need to fiil in the information for the rest of field for FRAMEWORK_EFI_IFR_DATA_ENTRY.
709 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
711 //UINT8 OpCode; // Likely a string, numeric, or one-of
712 //UINT8 Length; // Length of the FRAMEWORK_EFI_IFR_DATA_ENTRY packet
713 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
714 //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
715 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
716 // If the OpCode is a String type - Data is a CHAR16[x] type
717 // If the OpCode is a Checkbox type - Data is a UINT8 value
718 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
725 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
726 needs to be informed when data changed in NvMapOverride. This function will invoke
727 SetBrowserData () to set internal data of Form Browser.
729 @param ConfigAccess The Config Access Private Context.
730 @param QuestionId The Question Id that invokes the callback.
735 SyncBrowserDataForNvMapOverride (
736 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
737 IN EFI_QUESTION_ID QuestionId
740 FORMSET_STORAGE
*BufferStorage
;
742 UINTN BrowserDataSize
;
744 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
746 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
748 if (BufferStorage
== NULL
) {
750 // QuestionId is a statement without Storage.
754 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
758 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
760 ASSERT (BufferStorage
!= NULL
);
762 BrowserDataSize
= BufferStorage
->Size
;
764 Status
= SetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
765 ASSERT_EFI_ERROR (Status
);
771 Free up resource allocated for a FRAMEWORK_EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
773 @param Array The FRAMEWORK_EFI_IFR_DATA_ARRAY allocated.
774 @param NvMapAllocated If the NvRamMap is allocated for FRAMEWORK_EFI_IFR_DATA_ARRAY.
778 DestroyIfrDataArray (
779 IN FRAMEWORK_EFI_IFR_DATA_ARRAY
*Array
,
780 IN BOOLEAN NvMapAllocated
784 if (NvMapAllocated
) {
785 FreePool (Array
->NvRamMap
);
793 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
794 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
795 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
796 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
797 for detailed information.
799 @param ThunkContext The Thunk Context.
800 @param QuestionId The Question Id.
801 @param Type The Question Type.
802 @param Value The One Of Option's value.
804 @return The ONE_OF_OPTION_MAP_ENTRY found.
805 @retval NULL If no entry is found.
807 ONE_OF_OPTION_MAP_ENTRY
*
808 GetOneOfOptionMapEntry (
809 IN HII_THUNK_CONTEXT
*ThunkContext
,
810 IN EFI_QUESTION_ID QuestionId
,
812 IN EFI_IFR_TYPE_VALUE
*Value
817 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
818 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
819 FORM_BROWSER_FORMSET
*FormSet
;
821 FormSet
= ThunkContext
->FormSet
;
823 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
825 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
826 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
827 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
828 ASSERT (OneOfOptionMap
->ValueType
== Type
);
830 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
832 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
833 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
835 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
836 return OneOfOptionMapEntry
;
839 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
843 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
851 Functions which are registered to receive notification of
852 database events have this prototype. The actual event is encoded
853 in NotifyType. The following table describes how PackageType,
854 PackageGuid, Handle, and Package are used for each of the
857 If any Pakcage List in database is updated, mHiiPackageListUpdated
858 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
859 will force the UEFI Setup Browser to save the uncommitted data. This
860 is needed as Framework's Callback function may dynamically update
861 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
862 the Package List's IFR and display it. UEFI Config Access's implementation
863 is required to save the modified (SetBrowserData or directly save the data
864 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
865 we will enforce the rule in ThunkCallback (). The side effect of force saving
866 of NV data is the NV flag in browser may not flag a update as data has already
867 been saved to NV storage.
869 @param PackageType Package type of the notification.
871 @param PackageGuid If PackageType is
872 EFI_HII_PACKAGE_TYPE_GUID, then this is
873 the pointer to the GUID from the Guid
874 field of EFI_HII_PACKAGE_GUID_HEADER.
875 Otherwise, it must be NULL.
877 @param Package Points to the package referred to by the
878 notification Handle The handle of the package
879 list which contains the specified package.
881 @param Handle The HII handle.
883 @param NotifyType The type of change concerning the
885 EFI_HII_DATABASE_NOTIFY_TYPE.
891 IN UINT8 PackageType
,
892 IN CONST EFI_GUID
*PackageGuid
,
893 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
894 IN EFI_HII_HANDLE Handle
,
895 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
898 mHiiPackageListUpdated
= TRUE
;
904 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
905 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
907 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
908 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
909 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
910 type of data to expect. The format of the data tends to vary based on the opcode that
911 generated the callback.
912 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
913 EFI_IFR_ONE_OF_OPTION.
914 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
915 by Type. Type EFI_IFR_TYPE_VALUE is defined in
916 EFI_IFR_ONE_OF_OPTION.
917 @param ActionRequest On return, points to the action requested by the callback function. Type
918 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
921 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
922 focuse to be INTERRACTIVE.
923 @retval EFI_SUCCESS The callback complete successfully.
924 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
930 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
931 IN EFI_BROWSER_ACTION Action
,
932 IN EFI_QUESTION_ID QuestionId
,
934 IN EFI_IFR_TYPE_VALUE
*Value
,
935 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
939 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
940 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
941 EFI_HII_CALLBACK_PACKET
*Packet
;
942 FRAMEWORK_EFI_IFR_DATA_ARRAY
*Data
;
943 FRAMEWORK_EFI_IFR_DATA_ENTRY
*DataEntry
;
945 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
946 EFI_HANDLE NotifyHandle
;
948 BOOLEAN NvMapAllocated
;
950 ASSERT (This
!= NULL
);
951 ASSERT (Value
!= NULL
);
952 ASSERT (ActionRequest
!= NULL
);
954 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
956 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
958 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
959 if (FormCallbackProtocol
== NULL
) {
961 return EFI_UNSUPPORTED
;
965 // Check if the QuestionId match a OneOfOption.
967 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
969 if (OneOfOptionMapEntry
== NULL
) {
971 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
973 KeyValue
= QuestionId
;
976 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
978 KeyValue
= OneOfOptionMapEntry
->FwKey
;
982 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
984 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
986 Status
= mHiiDatabase
->RegisterPackageNotify (
988 EFI_HII_PACKAGE_FORMS
,
991 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
995 //Call the Framework Callback function.
998 Status
= FormCallbackProtocol
->Callback (
999 FormCallbackProtocol
,
1004 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1007 // Callback require browser to perform action
1009 if (EFI_ERROR (Status
)) {
1010 if (Packet
!= NULL
) {
1012 IfrLibCreatePopUp (1, &Key
, Packet
->String
);
1013 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1016 // Error Code in Status is discarded.
1019 if (Packet
!= NULL
) {
1020 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1021 DataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
));
1022 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1023 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1026 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1027 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1028 &ConfigAccess
->ConfigAccessProtocol
,
1039 // Unregister notify for Form package update
1041 Status
= mHiiDatabase
->UnregisterPackageNotify (
1046 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1047 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1048 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1049 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1050 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1051 // the form and load all the variable storages.
1053 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1054 mHiiPackageListUpdated
= FALSE
;
1055 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1057 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1058 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1059 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1067 DestroyIfrDataArray (Data
, NvMapAllocated
);