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
;
232 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
234 HiiLibDestroyHiiDriverHandle (ThunkContext
->UefiHiiDriverHandle
);
236 Status
= gBS
->HandleProtocol (
237 ThunkContext
->UefiHiiDriverHandle
,
238 &gEfiHiiConfigAccessProtocolGuid
,
239 (VOID
**) &ConfigAccess
241 ASSERT_EFI_ERROR (Status
);
243 Status
= gBS
->UninstallProtocolInterface (
244 ThunkContext
->UefiHiiDriverHandle
,
245 &gEfiHiiConfigAccessProtocolGuid
,
248 ASSERT_EFI_ERROR (Status
);
250 ConfigAccessInstance
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (ConfigAccess
);
256 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
258 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
259 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
260 @param Data The data read.
261 @param DataSize The size of data.
263 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
264 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
265 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
269 IN FORMSET_STORAGE
*BufferStorage
,
270 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
280 Status
= FwFormCallBack
->NvRead (
283 &BufferStorage
->Guid
,
288 if (Status
== EFI_BUFFER_TOO_SMALL
) {
289 if (BufferStorage
->Size
!= *DataSize
) {
291 return EFI_INVALID_PARAMETER
;
294 *Data
= AllocateZeroPool (*DataSize
);
296 return EFI_OUT_OF_RESOURCES
;
299 FwFormCallBack
->NvRead (
302 &BufferStorage
->Guid
,
314 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
316 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
317 @param Data The data read.
318 @param DataSize The size of data.
320 If the UEFI Variable Get Service return the size information of the data
321 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
324 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
325 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
326 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
331 IN FORMSET_STORAGE
*BufferStorage
,
340 Status
= gRT
->GetVariable (
342 &BufferStorage
->Guid
,
347 if (Status
== EFI_BUFFER_TOO_SMALL
) {
349 if (BufferStorage
->Size
!= *DataSize
) {
351 return EFI_INVALID_PARAMETER
;
354 *Data
= AllocateZeroPool (*DataSize
);
356 return EFI_OUT_OF_RESOURCES
;
359 Status
= gRT
->GetVariable (
361 &BufferStorage
->Guid
,
373 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
374 so that data can be read from the data storage such as UEFI Variable or module's
375 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
377 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
378 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
379 includes the routing information as well as the configurable name / value pairs. It is
380 invalid for this string to be in <MultiConfigRequest> format.
382 @param Progress On return, points to a character in the Request string. Points to the string's null
383 terminator if request was successful. Points to the most recent '&' before the first
384 failing name / value pair (or the beginning of the string if the failure is in the first
385 name / value pair) if the request was not successful
386 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
387 values filled in for the names in the Request string. String to be allocated by the called
390 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
391 @retval EFI_SUCCESS The setting is retrived successfully.
392 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
397 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
398 IN CONST EFI_STRING Request
,
399 OUT EFI_STRING
*Progress
,
400 OUT EFI_STRING
*Results
404 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
405 FORMSET_STORAGE
*BufferStorage
;
410 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
412 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
414 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
416 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
418 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
419 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
420 Status
= GetUefiVariable (
426 Status
= CallFormCallBack (
428 ConfigAccess
->FormCallbackProtocol
,
435 // Use the NvMapOverride.
437 DataSize
= BufferStorage
->Size
;
438 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
441 Status
= EFI_SUCCESS
;
443 Status
= EFI_OUT_OF_RESOURCES
;
447 if (!EFI_ERROR (Status
)) {
448 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
449 mHiiConfigRoutingProtocol
,
465 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
466 so that data can be written to the data storage such as UEFI Variable or module's
467 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
469 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
470 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
471 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
472 failing name / value pair (or the beginning of the string if the failure is in the first
473 name / value pair) or the terminating NULL if all was successful.
475 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
476 @retval EFI_SUCCESS The setting is saved successfully.
477 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
482 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
483 IN CONST EFI_STRING Configuration
,
484 OUT EFI_STRING
*Progress
488 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
489 FORMSET_STORAGE
*BufferStorage
;
493 UINTN LastModifiedByteIndex
;
494 BOOLEAN ResetRequired
;
495 BOOLEAN DataAllocated
;
498 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
500 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
502 DataSize2
= BufferStorage
->Size
;
503 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
504 DataAllocated
= TRUE
;
505 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
506 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
507 Status
= GetUefiVariable (
513 Status
= CallFormCallBack (
515 ConfigAccess
->FormCallbackProtocol
,
522 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
524 Status
= EFI_SUCCESS
;
525 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
526 DataSize
= DataSize2
;
527 DataAllocated
= FALSE
;
529 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
531 Data
= AllocateZeroPool (DataSize2
);
535 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
536 mHiiConfigRoutingProtocol
,
539 &LastModifiedByteIndex
,
542 if (EFI_ERROR (Status
)) {
546 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
547 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
548 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
549 Status
= gRT
->SetVariable (
551 &BufferStorage
->Guid
,
552 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
557 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
558 ConfigAccess
->FormCallbackProtocol
,
560 &BufferStorage
->Guid
,
561 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
571 if (DataAllocated
&& (Data
!= NULL
)) {
579 Build the FRAMEWORK_EFI_IFR_DATA_ARRAY which will be used to pass to
580 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of FRAMEWORK_EFI_IFR_DATA_ARRAY
583 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
585 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
586 @param QuestionId The Question ID.
587 @param Type The Question Type.
588 @param Value The Question Value.
589 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
591 @return A pointer to FRAMEWORK_EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
593 FRAMEWORK_EFI_IFR_DATA_ARRAY
*
595 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
596 IN EFI_QUESTION_ID QuestionId
,
598 IN EFI_IFR_TYPE_VALUE
*Value
,
599 OUT BOOLEAN
*NvMapAllocated
602 FRAMEWORK_EFI_IFR_DATA_ARRAY
*IfrDataArray
;
603 FRAMEWORK_EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
604 UINTN BrowserDataSize
;
605 FORMSET_STORAGE
*BufferStorage
;
611 *NvMapAllocated
= FALSE
;
616 case EFI_IFR_TYPE_NUM_SIZE_8
:
617 case EFI_IFR_TYPE_NUM_SIZE_16
:
618 case EFI_IFR_TYPE_NUM_SIZE_32
:
619 case EFI_IFR_TYPE_NUM_SIZE_64
:
620 case EFI_IFR_TYPE_BOOLEAN
:
621 Size
= sizeof (*Value
);
624 case EFI_IFR_TYPE_STRING
:
626 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
627 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
629 String
= AllocateZeroPool (StringSize
);
630 ASSERT (String
!= NULL
);
632 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
633 ASSERT_EFI_ERROR (Status
);
644 IfrDataArray
= AllocateZeroPool (sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
) + sizeof (FRAMEWORK_EFI_IFR_DATA_ENTRY
) + Size
);
645 ASSERT (IfrDataArray
!= NULL
);
647 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
649 if (BufferStorage
== NULL
) {
651 // The QuestionId is not associated with a Buffer Storage.
652 // Try to get the first Buffer Storage then.
654 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
657 if (BufferStorage
!= NULL
) {
658 BrowserDataSize
= BufferStorage
->Size
;
660 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
661 *NvMapAllocated
= TRUE
;
662 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
664 *NvMapAllocated
= FALSE
;
665 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
668 Status
= GetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, &BrowserDataSize
, IfrDataArray
->NvRamMap
);
669 ASSERT_EFI_ERROR (Status
);
671 IfrDataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
674 case EFI_IFR_TYPE_NUM_SIZE_8
:
675 case EFI_IFR_TYPE_NUM_SIZE_16
:
676 case EFI_IFR_TYPE_NUM_SIZE_32
:
677 case EFI_IFR_TYPE_NUM_SIZE_64
:
678 case EFI_IFR_TYPE_BOOLEAN
:
679 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
682 case EFI_IFR_TYPE_STRING
:
683 ASSERT (String
!= NULL
);
684 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
693 // Need to fiil in the information for the rest of field for FRAMEWORK_EFI_IFR_DATA_ENTRY.
694 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
696 //UINT8 OpCode; // Likely a string, numeric, or one-of
697 //UINT8 Length; // Length of the FRAMEWORK_EFI_IFR_DATA_ENTRY packet
698 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
699 //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
700 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
701 // If the OpCode is a String type - Data is a CHAR16[x] type
702 // If the OpCode is a Checkbox type - Data is a UINT8 value
703 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
710 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
711 needs to be informed when data changed in NvMapOverride. This function will invoke
712 SetBrowserData () to set internal data of Form Browser.
714 @param ConfigAccess The Config Access Private Context.
715 @param QuestionId The Question Id that invokes the callback.
720 SyncBrowserDataForNvMapOverride (
721 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
722 IN EFI_QUESTION_ID QuestionId
725 FORMSET_STORAGE
*BufferStorage
;
727 UINTN BrowserDataSize
;
729 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
731 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
733 if (BufferStorage
== NULL
) {
735 // QuestionId is a statement without Storage.
739 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
743 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
745 ASSERT (BufferStorage
!= NULL
);
747 BrowserDataSize
= BufferStorage
->Size
;
749 Status
= SetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
750 ASSERT_EFI_ERROR (Status
);
756 Free up resource allocated for a FRAMEWORK_EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
758 @param Array The FRAMEWORK_EFI_IFR_DATA_ARRAY allocated.
759 @param NvMapAllocated If the NvRamMap is allocated for FRAMEWORK_EFI_IFR_DATA_ARRAY.
763 DestroyIfrDataArray (
764 IN FRAMEWORK_EFI_IFR_DATA_ARRAY
*Array
,
765 IN BOOLEAN NvMapAllocated
769 if (NvMapAllocated
) {
770 FreePool (Array
->NvRamMap
);
778 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
779 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
780 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
781 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
782 for detailed information.
784 @param ThunkContext The Thunk Context.
785 @param QuestionId The Question Id.
786 @param Type The Question Type.
787 @param Value The One Of Option's value.
789 @return The ONE_OF_OPTION_MAP_ENTRY found.
790 @retval NULL If no entry is found.
792 ONE_OF_OPTION_MAP_ENTRY
*
793 GetOneOfOptionMapEntry (
794 IN HII_THUNK_CONTEXT
*ThunkContext
,
795 IN EFI_QUESTION_ID QuestionId
,
797 IN EFI_IFR_TYPE_VALUE
*Value
802 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
803 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
804 FORM_BROWSER_FORMSET
*FormSet
;
806 FormSet
= ThunkContext
->FormSet
;
808 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
810 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
811 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
812 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
813 ASSERT (OneOfOptionMap
->ValueType
== Type
);
815 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
817 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
818 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
820 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
821 return OneOfOptionMapEntry
;
824 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
828 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
836 Functions which are registered to receive notification of
837 database events have this prototype. The actual event is encoded
838 in NotifyType. The following table describes how PackageType,
839 PackageGuid, Handle, and Package are used for each of the
842 If any Pakcage List in database is updated, mHiiPackageListUpdated
843 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
844 will force the UEFI Setup Browser to save the uncommitted data. This
845 is needed as Framework's Callback function may dynamically update
846 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
847 the Package List's IFR and display it. UEFI Config Access's implementation
848 is required to save the modified (SetBrowserData or directly save the data
849 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
850 we will enforce the rule in ThunkCallback (). The side effect of force saving
851 of NV data is the NV flag in browser may not flag a update as data has already
852 been saved to NV storage.
854 @param PackageType Package type of the notification.
856 @param PackageGuid If PackageType is
857 EFI_HII_PACKAGE_TYPE_GUID, then this is
858 the pointer to the GUID from the Guid
859 field of EFI_HII_PACKAGE_GUID_HEADER.
860 Otherwise, it must be NULL.
862 @param Package Points to the package referred to by the
863 notification Handle The handle of the package
864 list which contains the specified package.
866 @param Handle The HII handle.
868 @param NotifyType The type of change concerning the
870 EFI_HII_DATABASE_NOTIFY_TYPE.
876 IN UINT8 PackageType
,
877 IN CONST EFI_GUID
*PackageGuid
,
878 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
879 IN EFI_HII_HANDLE Handle
,
880 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
883 mHiiPackageListUpdated
= TRUE
;
889 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
890 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
892 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
893 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
894 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
895 type of data to expect. The format of the data tends to vary based on the opcode that
896 generated the callback.
897 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
898 EFI_IFR_ONE_OF_OPTION.
899 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
900 by Type. Type EFI_IFR_TYPE_VALUE is defined in
901 EFI_IFR_ONE_OF_OPTION.
902 @param ActionRequest On return, points to the action requested by the callback function. Type
903 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
906 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
907 focuse to be INTERRACTIVE.
908 @retval EFI_SUCCESS The callback complete successfully.
909 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
915 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
916 IN EFI_BROWSER_ACTION Action
,
917 IN EFI_QUESTION_ID QuestionId
,
919 IN EFI_IFR_TYPE_VALUE
*Value
,
920 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
924 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
925 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
926 EFI_HII_CALLBACK_PACKET
*Packet
;
927 FRAMEWORK_EFI_IFR_DATA_ARRAY
*Data
;
928 FRAMEWORK_EFI_IFR_DATA_ENTRY
*DataEntry
;
930 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
931 EFI_HANDLE NotifyHandle
;
933 BOOLEAN NvMapAllocated
;
935 ASSERT (This
!= NULL
);
936 ASSERT (Value
!= NULL
);
937 ASSERT (ActionRequest
!= NULL
);
939 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
941 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
943 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
944 if (FormCallbackProtocol
== NULL
) {
946 return EFI_UNSUPPORTED
;
950 // Check if the QuestionId match a OneOfOption.
952 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
954 if (OneOfOptionMapEntry
== NULL
) {
956 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
958 KeyValue
= QuestionId
;
961 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
963 KeyValue
= OneOfOptionMapEntry
->FwKey
;
967 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
969 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
971 Status
= mHiiDatabase
->RegisterPackageNotify (
973 EFI_HII_PACKAGE_FORMS
,
976 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
980 //Call the Framework Callback function.
983 Status
= FormCallbackProtocol
->Callback (
984 FormCallbackProtocol
,
989 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
992 // Callback require browser to perform action
994 if (EFI_ERROR (Status
)) {
995 if (Packet
!= NULL
) {
997 IfrLibCreatePopUp (1, &Key
, Packet
->String
);
998 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1001 // Error Code in Status is discarded.
1004 if (Packet
!= NULL
) {
1005 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1006 DataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
));
1007 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1008 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1011 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1012 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1013 &ConfigAccess
->ConfigAccessProtocol
,
1024 // Unregister notify for Form package update
1026 Status
= mHiiDatabase
->UnregisterPackageNotify (
1031 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1032 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1033 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1034 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1035 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1036 // the form and load all the variable storages.
1038 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1039 mHiiPackageListUpdated
= FALSE
;
1040 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1042 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1043 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1044 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1052 DestroyIfrDataArray (Data
, NvMapAllocated
);