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
;
155 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
157 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
158 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
160 if ((Storage
->VarStoreId
== FormSet
->DefaultVarStoreId
) && (FormSet
->OriginalDefaultVarStoreName
!= NULL
)) {
161 Name
= FormSet
->OriginalDefaultVarStoreName
;
163 Name
= Storage
->Name
;
166 if (IsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Name
)) {
170 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
177 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
178 by a module using Framework HII Protocol Interfaces.
180 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
181 that Setup Utility can load the Buffer Storage using this protocol.
183 @param Packages The Package List.
184 @param ThunkContext The Thunk Context.
186 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
187 @retval EFI_OUT_RESOURCE There is not enough memory.
191 InstallDefaultConfigAccessProtocol (
192 IN CONST EFI_HII_PACKAGES
*Packages
,
193 IN OUT HII_THUNK_CONTEXT
*ThunkContext
197 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
199 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
201 Status
= HiiLibCreateHiiDriverHandle (&ThunkContext
->UefiHiiDriverHandle
);
202 ASSERT_EFI_ERROR (Status
);
204 ConfigAccessInstance
= AllocateCopyPool (
205 sizeof (CONFIG_ACCESS_PRIVATE
),
206 &gConfigAccessPrivateTempate
208 ASSERT (ConfigAccessInstance
!= NULL
);
210 Status
= gBS
->InstallMultipleProtocolInterfaces (
211 &ThunkContext
->UefiHiiDriverHandle
,
212 &gEfiHiiConfigAccessProtocolGuid
,
213 &ConfigAccessInstance
->ConfigAccessProtocol
,
216 ASSERT_EFI_ERROR (Status
);
218 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
224 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
225 by a module using Framework HII Protocol Interfaces.
227 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
229 @param ThunkContext The Thunk Context.
233 UninstallDefaultConfigAccessProtocol (
234 IN HII_THUNK_CONTEXT
*ThunkContext
238 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
240 HiiLibDestroyHiiDriverHandle (ThunkContext
->UefiHiiDriverHandle
);
242 Status
= gBS
->HandleProtocol (
243 ThunkContext
->UefiHiiDriverHandle
,
244 &gEfiHiiConfigAccessProtocolGuid
,
245 (VOID
**) &ConfigAccess
247 ASSERT_EFI_ERROR (Status
);
249 Status
= gBS
->UninstallProtocolInterface (
250 ThunkContext
->UefiHiiDriverHandle
,
251 &gEfiHiiConfigAccessProtocolGuid
,
254 ASSERT_EFI_ERROR (Status
);
260 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
262 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
263 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
264 @param Data The data read.
265 @param DataSize The size of data.
267 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
268 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
269 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
273 IN FORMSET_STORAGE
*BufferStorage
,
274 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
284 Status
= FwFormCallBack
->NvRead (
287 &BufferStorage
->Guid
,
292 if (Status
== EFI_BUFFER_TOO_SMALL
) {
293 if (BufferStorage
->Size
!= *DataSize
) {
295 return EFI_INVALID_PARAMETER
;
298 *Data
= AllocateZeroPool (*DataSize
);
300 return EFI_OUT_OF_RESOURCES
;
303 FwFormCallBack
->NvRead (
306 &BufferStorage
->Guid
,
318 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
320 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
321 @param Data The data read.
322 @param DataSize The size of data.
324 If the UEFI Variable Get Service return the size information of the data
325 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
328 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
329 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
330 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
335 IN FORMSET_STORAGE
*BufferStorage
,
344 Status
= gRT
->GetVariable (
346 &BufferStorage
->Guid
,
351 if (Status
== EFI_BUFFER_TOO_SMALL
) {
353 if (BufferStorage
->Size
!= *DataSize
) {
355 return EFI_INVALID_PARAMETER
;
358 *Data
= AllocateZeroPool (*DataSize
);
360 return EFI_OUT_OF_RESOURCES
;
363 Status
= gRT
->GetVariable (
365 &BufferStorage
->Guid
,
377 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
378 so that data can be read from the data storage such as UEFI Variable or module's
379 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
381 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
382 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
383 includes the routing information as well as the configurable name / value pairs. It is
384 invalid for this string to be in <MultiConfigRequest> format.
386 @param Progress On return, points to a character in the Request string. Points to the string's null
387 terminator if request was successful. Points to the most recent '&' before the first
388 failing name / value pair (or the beginning of the string if the failure is in the first
389 name / value pair) if the request was not successful
390 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
391 values filled in for the names in the Request string. String to be allocated by the called
394 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
395 @retval EFI_SUCCESS The setting is retrived successfully.
396 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
401 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
402 IN CONST EFI_STRING Request
,
403 OUT EFI_STRING
*Progress
,
404 OUT EFI_STRING
*Results
408 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
409 FORMSET_STORAGE
*BufferStorage
;
413 if (Request
== NULL
) {
414 return EFI_NOT_FOUND
;
418 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
420 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
422 if (BufferStorage
== NULL
) {
423 *Progress
= (EFI_STRING
) Request
;
424 return EFI_NOT_FOUND
;
427 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
429 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
431 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
432 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
433 Status
= GetUefiVariable (
439 Status
= CallFormCallBack (
441 ConfigAccess
->FormCallbackProtocol
,
448 // Use the NvMapOverride.
450 DataSize
= BufferStorage
->Size
;
451 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
454 Status
= EFI_SUCCESS
;
456 Status
= EFI_OUT_OF_RESOURCES
;
460 if (!EFI_ERROR (Status
)) {
461 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
462 mHiiConfigRoutingProtocol
,
478 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
479 so that data can be written to the data storage such as UEFI Variable or module's
480 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
482 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
483 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
484 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
485 failing name / value pair (or the beginning of the string if the failure is in the first
486 name / value pair) or the terminating NULL if all was successful.
488 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
489 @retval EFI_SUCCESS The setting is saved successfully.
490 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
495 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
496 IN CONST EFI_STRING Configuration
,
497 OUT EFI_STRING
*Progress
501 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
502 FORMSET_STORAGE
*BufferStorage
;
506 UINTN LastModifiedByteIndex
;
507 BOOLEAN ResetRequired
;
508 BOOLEAN DataAllocated
;
510 if (Configuration
== NULL
) {
511 return EFI_INVALID_PARAMETER
;
515 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
517 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
519 if (BufferStorage
== NULL
) {
520 *Progress
= Configuration
;
521 return EFI_NOT_FOUND
;
524 DataSize2
= BufferStorage
->Size
;
525 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
526 DataAllocated
= TRUE
;
527 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
528 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
529 Status
= GetUefiVariable (
535 Status
= CallFormCallBack (
537 ConfigAccess
->FormCallbackProtocol
,
544 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
546 Status
= EFI_SUCCESS
;
547 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
548 DataSize
= DataSize2
;
549 DataAllocated
= FALSE
;
551 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
553 Data
= AllocateZeroPool (DataSize2
);
557 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
558 mHiiConfigRoutingProtocol
,
561 &LastModifiedByteIndex
,
564 if (EFI_ERROR (Status
)) {
568 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
569 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
570 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
571 Status
= gRT
->SetVariable (
573 &BufferStorage
->Guid
,
574 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
579 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
580 ConfigAccess
->FormCallbackProtocol
,
582 &BufferStorage
->Guid
,
583 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
593 if (DataAllocated
&& (Data
!= NULL
)) {
601 Build the FRAMEWORK_EFI_IFR_DATA_ARRAY which will be used to pass to
602 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of FRAMEWORK_EFI_IFR_DATA_ARRAY
605 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
607 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
608 @param QuestionId The Question ID.
609 @param Type The Question Type.
610 @param Value The Question Value.
611 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
613 @return A pointer to FRAMEWORK_EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
615 FRAMEWORK_EFI_IFR_DATA_ARRAY
*
617 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
618 IN EFI_QUESTION_ID QuestionId
,
620 IN EFI_IFR_TYPE_VALUE
*Value
,
621 OUT BOOLEAN
*NvMapAllocated
624 FRAMEWORK_EFI_IFR_DATA_ARRAY
*IfrDataArray
;
625 FRAMEWORK_EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
626 UINTN BrowserDataSize
;
627 FORMSET_STORAGE
*BufferStorage
;
633 *NvMapAllocated
= FALSE
;
638 case EFI_IFR_TYPE_NUM_SIZE_8
:
639 case EFI_IFR_TYPE_NUM_SIZE_16
:
640 case EFI_IFR_TYPE_NUM_SIZE_32
:
641 case EFI_IFR_TYPE_NUM_SIZE_64
:
642 case EFI_IFR_TYPE_BOOLEAN
:
643 Size
= sizeof (*Value
);
646 case EFI_IFR_TYPE_STRING
:
648 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
649 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
651 String
= AllocateZeroPool (StringSize
);
652 ASSERT (String
!= NULL
);
654 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
655 ASSERT_EFI_ERROR (Status
);
666 IfrDataArray
= AllocateZeroPool (sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
) + sizeof (FRAMEWORK_EFI_IFR_DATA_ENTRY
) + Size
);
667 ASSERT (IfrDataArray
!= NULL
);
669 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
671 if (BufferStorage
== NULL
) {
673 // The QuestionId is not associated with a Buffer Storage.
674 // Try to get the first Buffer Storage then.
676 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
679 if (BufferStorage
!= NULL
) {
680 BrowserDataSize
= BufferStorage
->Size
;
682 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
683 *NvMapAllocated
= TRUE
;
684 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
686 *NvMapAllocated
= FALSE
;
687 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
690 Status
= GetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, &BrowserDataSize
, IfrDataArray
->NvRamMap
);
691 ASSERT_EFI_ERROR (Status
);
693 IfrDataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
696 case EFI_IFR_TYPE_NUM_SIZE_8
:
697 case EFI_IFR_TYPE_NUM_SIZE_16
:
698 case EFI_IFR_TYPE_NUM_SIZE_32
:
699 case EFI_IFR_TYPE_NUM_SIZE_64
:
700 case EFI_IFR_TYPE_BOOLEAN
:
701 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
704 case EFI_IFR_TYPE_STRING
:
705 ASSERT (String
!= NULL
);
706 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
715 // Need to fiil in the information for the rest of field for FRAMEWORK_EFI_IFR_DATA_ENTRY.
716 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
718 //UINT8 OpCode; // Likely a string, numeric, or one-of
719 //UINT8 Length; // Length of the FRAMEWORK_EFI_IFR_DATA_ENTRY packet
720 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
721 //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
722 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
723 // If the OpCode is a String type - Data is a CHAR16[x] type
724 // If the OpCode is a Checkbox type - Data is a UINT8 value
725 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
732 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
733 needs to be informed when data changed in NvMapOverride. This function will invoke
734 SetBrowserData () to set internal data of Form Browser.
736 @param ConfigAccess The Config Access Private Context.
737 @param QuestionId The Question Id that invokes the callback.
742 SyncBrowserDataForNvMapOverride (
743 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
744 IN EFI_QUESTION_ID QuestionId
747 FORMSET_STORAGE
*BufferStorage
;
749 UINTN BrowserDataSize
;
751 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
753 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
755 if (BufferStorage
== NULL
) {
757 // QuestionId is a statement without Storage.
761 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
765 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
767 ASSERT (BufferStorage
!= NULL
);
769 BrowserDataSize
= BufferStorage
->Size
;
771 Status
= SetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
772 ASSERT_EFI_ERROR (Status
);
778 Free up resource allocated for a FRAMEWORK_EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
780 @param Array The FRAMEWORK_EFI_IFR_DATA_ARRAY allocated.
781 @param NvMapAllocated If the NvRamMap is allocated for FRAMEWORK_EFI_IFR_DATA_ARRAY.
785 DestroyIfrDataArray (
786 IN FRAMEWORK_EFI_IFR_DATA_ARRAY
*Array
,
787 IN BOOLEAN NvMapAllocated
791 if (NvMapAllocated
) {
792 FreePool (Array
->NvRamMap
);
800 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
801 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
802 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
803 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
804 for detailed information.
806 @param ThunkContext The Thunk Context.
807 @param QuestionId The Question Id.
808 @param Type The Question Type.
809 @param Value The One Of Option's value.
811 @return The ONE_OF_OPTION_MAP_ENTRY found.
812 @retval NULL If no entry is found.
814 ONE_OF_OPTION_MAP_ENTRY
*
815 GetOneOfOptionMapEntry (
816 IN HII_THUNK_CONTEXT
*ThunkContext
,
817 IN EFI_QUESTION_ID QuestionId
,
819 IN EFI_IFR_TYPE_VALUE
*Value
824 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
825 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
826 FORM_BROWSER_FORMSET
*FormSet
;
828 FormSet
= ThunkContext
->FormSet
;
830 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
832 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
833 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
834 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
835 ASSERT (OneOfOptionMap
->ValueType
== Type
);
837 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
839 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
840 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
842 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
843 return OneOfOptionMapEntry
;
846 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
850 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
858 Functions which are registered to receive notification of
859 database events have this prototype. The actual event is encoded
860 in NotifyType. The following table describes how PackageType,
861 PackageGuid, Handle, and Package are used for each of the
864 If any Pakcage List in database is updated, mHiiPackageListUpdated
865 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
866 will force the UEFI Setup Browser to save the uncommitted data. This
867 is needed as Framework's Callback function may dynamically update
868 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
869 the Package List's IFR and display it. UEFI Config Access's implementation
870 is required to save the modified (SetBrowserData or directly save the data
871 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
872 we will enforce the rule in ThunkCallback (). The side effect of force saving
873 of NV data is the NV flag in browser may not flag a update as data has already
874 been saved to NV storage.
876 @param PackageType Package type of the notification.
878 @param PackageGuid If PackageType is
879 EFI_HII_PACKAGE_TYPE_GUID, then this is
880 the pointer to the GUID from the Guid
881 field of EFI_HII_PACKAGE_GUID_HEADER.
882 Otherwise, it must be NULL.
884 @param Package Points to the package referred to by the
885 notification Handle The handle of the package
886 list which contains the specified package.
888 @param Handle The HII handle.
890 @param NotifyType The type of change concerning the
892 EFI_HII_DATABASE_NOTIFY_TYPE.
898 IN UINT8 PackageType
,
899 IN CONST EFI_GUID
*PackageGuid
,
900 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
901 IN EFI_HII_HANDLE Handle
,
902 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
905 mHiiPackageListUpdated
= TRUE
;
911 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
912 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
914 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
915 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
916 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
917 type of data to expect. The format of the data tends to vary based on the opcode that
918 generated the callback.
919 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
920 EFI_IFR_ONE_OF_OPTION.
921 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
922 by Type. Type EFI_IFR_TYPE_VALUE is defined in
923 EFI_IFR_ONE_OF_OPTION.
924 @param ActionRequest On return, points to the action requested by the callback function. Type
925 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
928 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
929 focuse to be INTERRACTIVE.
930 @retval EFI_SUCCESS The callback complete successfully.
931 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
937 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
938 IN EFI_BROWSER_ACTION Action
,
939 IN EFI_QUESTION_ID QuestionId
,
941 IN EFI_IFR_TYPE_VALUE
*Value
,
942 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
946 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
947 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
948 EFI_HII_CALLBACK_PACKET
*Packet
;
949 FRAMEWORK_EFI_IFR_DATA_ARRAY
*Data
;
950 FRAMEWORK_EFI_IFR_DATA_ENTRY
*DataEntry
;
952 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
953 EFI_HANDLE NotifyHandle
;
955 BOOLEAN NvMapAllocated
;
957 ASSERT (This
!= NULL
);
958 ASSERT (Value
!= NULL
);
959 ASSERT (ActionRequest
!= NULL
);
961 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
963 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
965 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
966 if (FormCallbackProtocol
== NULL
) {
968 return EFI_UNSUPPORTED
;
972 // Check if the QuestionId match a OneOfOption.
974 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
976 if (OneOfOptionMapEntry
== NULL
) {
978 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
980 KeyValue
= QuestionId
;
983 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
985 KeyValue
= OneOfOptionMapEntry
->FwKey
;
989 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
991 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
993 Status
= mHiiDatabase
->RegisterPackageNotify (
995 EFI_HII_PACKAGE_FORMS
,
998 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1002 //Call the Framework Callback function.
1005 Status
= FormCallbackProtocol
->Callback (
1006 FormCallbackProtocol
,
1011 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1014 // Callback require browser to perform action
1016 if (EFI_ERROR (Status
)) {
1017 if (Packet
!= NULL
) {
1019 IfrLibCreatePopUp (1, &Key
, Packet
->String
);
1020 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1023 // Error Code in Status is discarded.
1026 if (Packet
!= NULL
) {
1027 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1028 DataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
));
1029 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1030 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1033 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1034 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1035 &ConfigAccess
->ConfigAccessProtocol
,
1046 // Unregister notify for Form package update
1048 Status
= mHiiDatabase
->UnregisterPackageNotify (
1053 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1054 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1055 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1056 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1057 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1058 // the form and load all the variable storages.
1060 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1061 mHiiPackageListUpdated
= FALSE
;
1062 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1064 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1065 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1066 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1074 DestroyIfrDataArray (Data
, NvMapAllocated
);