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 HII_VENDOR_DEVICE_PATH mUefiHiiVendorDevicePath
= {
29 (UINT8
) (sizeof (HII_VENDOR_DEVICE_PATH_NODE
)),
30 (UINT8
) ((sizeof (HII_VENDOR_DEVICE_PATH_NODE
)) >> 8)
40 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
42 (UINT8
) (sizeof (EFI_DEVICE_PATH_PROTOCOL
)),
43 (UINT8
) ((sizeof (EFI_DEVICE_PATH_PROTOCOL
)) >> 8)
48 CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate
= {
49 CONFIG_ACCESS_PRIVATE_SIGNATURE
,
54 }, //ConfigAccessProtocol
55 NULL
, //FormCallbackProtocol
60 Get the first EFI_IFR_VARSTORE from the FormSet.
62 @param FormSet The Form Set.
64 @retval FORMSET_STORAGE * Return the first EFI_IFR_VARSTORE.
65 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
68 GetFirstStorageOfFormSet (
69 IN CONST FORM_BROWSER_FORMSET
* FormSet
72 LIST_ENTRY
*StorageList
;
73 FORMSET_STORAGE
*Storage
;
75 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
77 if (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
78 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
86 Get the FORM_BROWSER_STATEMENT that matches the Question's value.
88 @param FormSet The Form Set.
89 @param QuestionId QuestionId
91 @retval FORM_BROWSER_STATEMENT* FORM_BROWSER_STATEMENT that match Question's value.
92 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
94 FORM_BROWSER_STATEMENT
*
95 GetStorageFromQuestionId (
96 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
97 IN EFI_QUESTION_ID QuestionId
100 LIST_ENTRY
*FormList
;
101 LIST_ENTRY
*StatementList
;
102 FORM_BROWSER_FORM
*Form
;
103 FORM_BROWSER_STATEMENT
*Statement
;
105 FormList
= GetFirstNode (&FormSet
->FormListHead
);
107 while (!IsNull (&FormSet
->FormListHead
, FormList
)) {
108 Form
= FORM_BROWSER_FORM_FROM_LINK (FormList
);
110 StatementList
= GetFirstNode (&Form
->StatementListHead
);
112 while (!IsNull (&Form
->StatementListHead
, StatementList
)) {
113 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (StatementList
);
114 if ((QuestionId
== Statement
->QuestionId
) && (Statement
->Storage
!= NULL
)) {
116 // UEFI Question ID is unique in a FormSet.
118 ASSERT (Statement
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
);
121 StatementList
= GetNextNode (&Form
->StatementListHead
, StatementList
);
124 FormList
= GetNextNode (&FormSet
->FormListHead
, FormList
);
131 Get the EFI_IFR_VARSTORE based the ID.
133 @param FormSet The Form Set.
135 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE with the ID.
136 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
139 GetStorageFromVarStoreId (
140 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
141 IN EFI_VARSTORE_ID VarStoreId
144 LIST_ENTRY
*StorageList
;
145 FORMSET_STORAGE
*Storage
;
147 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
149 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
150 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
152 if (VarStoreId
== Storage
->VarStoreId
) {
156 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
163 Get the EFI_IFR_VARSTORE based the <ConfigHdr> string in a <ConfigRequest>
164 or a <ConfigResp> string.
166 @param FormSet The Form Set.
167 @param ConfigString The Configuration String which is defined by UEFI HII.
169 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
170 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
173 GetStorageFromConfigString (
174 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
175 IN CONST EFI_STRING ConfigString
178 LIST_ENTRY
*StorageList
;
179 FORMSET_STORAGE
*Storage
;
182 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
184 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
185 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
187 if ((Storage
->VarStoreId
== FormSet
->DefaultVarStoreId
) && (FormSet
->OriginalDefaultVarStoreName
!= NULL
)) {
188 Name
= FormSet
->OriginalDefaultVarStoreName
;
190 Name
= Storage
->Name
;
193 if (HiiIsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Name
)) {
197 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
204 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
205 by a module using Framework HII Protocol Interfaces.
207 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
208 that Setup Utility can load the Buffer Storage using this protocol.
210 @param Packages The Package List.
211 @param ThunkContext The Thunk Context.
213 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
214 @retval EFI_OUT_RESOURCE There is not enough memory.
218 InstallDefaultConfigAccessProtocol (
219 IN CONST EFI_HII_PACKAGES
*Packages
,
220 IN OUT HII_THUNK_CONTEXT
*ThunkContext
224 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
225 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
227 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
229 ConfigAccessInstance
= AllocateCopyPool (
230 sizeof (CONFIG_ACCESS_PRIVATE
),
231 &gConfigAccessPrivateTempate
233 ASSERT (ConfigAccessInstance
!= NULL
);
236 // Use memory address as unique ID to distinguish from different device paths
237 // This function may be called multi times by the framework HII driver.
239 HiiVendorPath
= AllocateCopyPool (
240 sizeof (HII_VENDOR_DEVICE_PATH
),
241 &mUefiHiiVendorDevicePath
243 ASSERT (HiiVendorPath
!= NULL
);
245 HiiVendorPath
->Node
.UniqueId
= (UINT64
) ((UINTN
) HiiVendorPath
);
247 Status
= gBS
->InstallMultipleProtocolInterfaces (
248 &ThunkContext
->UefiHiiDriverHandle
,
249 &gEfiDevicePathProtocolGuid
,
251 &gEfiHiiConfigAccessProtocolGuid
,
252 &ConfigAccessInstance
->ConfigAccessProtocol
,
255 ASSERT_EFI_ERROR (Status
);
257 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
263 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
264 by a module using Framework HII Protocol Interfaces.
266 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
268 @param ThunkContext The Thunk Context.
272 UninstallDefaultConfigAccessProtocol (
273 IN HII_THUNK_CONTEXT
*ThunkContext
277 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
278 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
280 Status
= gBS
->HandleProtocol (
281 ThunkContext
->UefiHiiDriverHandle
,
282 &gEfiHiiConfigAccessProtocolGuid
,
283 (VOID
**) &ConfigAccess
285 ASSERT_EFI_ERROR (Status
);
287 Status
= gBS
->HandleProtocol (
288 ThunkContext
->UefiHiiDriverHandle
,
289 &gEfiDevicePathProtocolGuid
,
290 (VOID
**) &HiiVendorPath
292 ASSERT_EFI_ERROR (Status
);
294 Status
= gBS
->UninstallMultipleProtocolInterfaces (
295 ThunkContext
->UefiHiiDriverHandle
,
296 &gEfiDevicePathProtocolGuid
,
298 &gEfiHiiConfigAccessProtocolGuid
,
302 ASSERT_EFI_ERROR (Status
);
308 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
310 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
311 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
312 @param Data The data read.
313 @param DataSize The size of data.
315 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
316 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
317 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
321 IN FORMSET_STORAGE
*BufferStorage
,
322 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
332 Status
= FwFormCallBack
->NvRead (
335 &BufferStorage
->Guid
,
340 if (Status
== EFI_BUFFER_TOO_SMALL
) {
341 if (BufferStorage
->Size
!= *DataSize
) {
343 return EFI_INVALID_PARAMETER
;
346 *Data
= AllocateZeroPool (*DataSize
);
348 return EFI_OUT_OF_RESOURCES
;
351 Status
= FwFormCallBack
->NvRead (
354 &BufferStorage
->Guid
,
366 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
368 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
369 @param Data The data read.
370 @param DataSize The size of data.
372 If the UEFI Variable Get Service return the size information of the data
373 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
376 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
377 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
378 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
383 IN FORMSET_STORAGE
*BufferStorage
,
392 Status
= gRT
->GetVariable (
394 &BufferStorage
->Guid
,
399 if (Status
== EFI_BUFFER_TOO_SMALL
) {
401 if (BufferStorage
->Size
!= *DataSize
) {
403 return EFI_INVALID_PARAMETER
;
406 *Data
= AllocateZeroPool (*DataSize
);
408 return EFI_OUT_OF_RESOURCES
;
411 Status
= gRT
->GetVariable (
413 &BufferStorage
->Guid
,
425 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
426 so that data can be read from the data storage such as UEFI Variable or module's
427 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
429 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
430 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
431 includes the routing information as well as the configurable name / value pairs. It is
432 invalid for this string to be in <MultiConfigRequest> format.
434 @param Progress On return, points to a character in the Request string. Points to the string's null
435 terminator if request was successful. Points to the most recent '&' before the first
436 failing name / value pair (or the beginning of the string if the failure is in the first
437 name / value pair) if the request was not successful
438 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
439 values filled in for the names in the Request string. String to be allocated by the called
442 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
443 @retval EFI_SUCCESS The setting is retrived successfully.
444 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
449 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
450 IN CONST EFI_STRING Request
,
451 OUT EFI_STRING
*Progress
,
452 OUT EFI_STRING
*Results
456 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
457 FORMSET_STORAGE
*BufferStorage
;
461 if (Request
== NULL
) {
462 return EFI_NOT_FOUND
;
466 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
468 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
470 if (BufferStorage
== NULL
) {
471 *Progress
= (EFI_STRING
) Request
;
472 return EFI_NOT_FOUND
;
475 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
477 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
479 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
480 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
481 Status
= GetUefiVariable (
487 Status
= CallFormCallBack (
489 ConfigAccess
->FormCallbackProtocol
,
496 // Use the NvMapOverride.
498 DataSize
= BufferStorage
->Size
;
499 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
502 Status
= EFI_SUCCESS
;
504 Status
= EFI_OUT_OF_RESOURCES
;
508 if (!EFI_ERROR (Status
)) {
509 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
510 mHiiConfigRoutingProtocol
,
526 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
527 so that data can be written to the data storage such as UEFI Variable or module's
528 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
530 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
531 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
532 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
533 failing name / value pair (or the beginning of the string if the failure is in the first
534 name / value pair) or the terminating NULL if all was successful.
536 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
537 @retval EFI_SUCCESS The setting is saved successfully.
538 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
543 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
544 IN CONST EFI_STRING Configuration
,
545 OUT EFI_STRING
*Progress
549 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
550 FORMSET_STORAGE
*BufferStorage
;
554 UINTN LastModifiedByteIndex
;
555 BOOLEAN ResetRequired
;
556 BOOLEAN DataAllocated
;
558 if (Configuration
== NULL
) {
559 return EFI_INVALID_PARAMETER
;
563 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
565 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
567 if (BufferStorage
== NULL
) {
568 *Progress
= Configuration
;
569 return EFI_NOT_FOUND
;
572 DataSize2
= BufferStorage
->Size
;
573 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
574 DataAllocated
= TRUE
;
575 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
576 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
577 Status
= GetUefiVariable (
583 Status
= CallFormCallBack (
585 ConfigAccess
->FormCallbackProtocol
,
592 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
594 Status
= EFI_SUCCESS
;
595 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
596 DataSize
= DataSize2
;
597 DataAllocated
= FALSE
;
599 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
601 Data
= AllocateZeroPool (DataSize2
);
605 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
606 mHiiConfigRoutingProtocol
,
609 &LastModifiedByteIndex
,
612 if (EFI_ERROR (Status
)) {
616 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
617 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
618 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
619 Status
= gRT
->SetVariable (
621 &BufferStorage
->Guid
,
622 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
627 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
628 ConfigAccess
->FormCallbackProtocol
,
630 &BufferStorage
->Guid
,
631 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
641 if (DataAllocated
&& (Data
!= NULL
)) {
649 Build the EFI_IFR_DATA_ARRAY which will be used to pass to
650 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of EFI_IFR_DATA_ARRAY
653 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
655 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
656 @param QuestionId The Question ID.
657 @param Type The Question Type.
658 @param Value The Question Value.
659 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
661 @return A pointer to EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
665 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
666 IN EFI_QUESTION_ID QuestionId
,
668 IN EFI_IFR_TYPE_VALUE
*Value
,
669 OUT BOOLEAN
*NvMapAllocated
672 EFI_IFR_DATA_ARRAY
*IfrDataArray
;
673 EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
674 UINTN BrowserDataSize
;
675 FORMSET_STORAGE
*BufferStorage
;
678 FORM_BROWSER_STATEMENT
*Statement
;
680 *NvMapAllocated
= FALSE
;
685 case EFI_IFR_TYPE_NUM_SIZE_8
:
686 case EFI_IFR_TYPE_NUM_SIZE_16
:
687 case EFI_IFR_TYPE_NUM_SIZE_32
:
688 case EFI_IFR_TYPE_NUM_SIZE_64
:
689 case EFI_IFR_TYPE_BOOLEAN
:
690 Size
= sizeof (*Value
);
693 case EFI_IFR_TYPE_STRING
:
694 if (Value
->string
== 0) {
697 String
= HiiGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, NULL
);
698 ASSERT (String
!= NULL
);
700 Size
= StrSize (String
);
710 IfrDataArray
= AllocateZeroPool (sizeof (EFI_IFR_DATA_ARRAY
) + sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
711 ASSERT (IfrDataArray
!= NULL
);
712 IfrDataArray
->EntryCount
= 1;
713 IfrDataEntry
= (EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
715 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
717 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
719 // The QuestionId is not associated with a Buffer Storage.
720 // Try to get the first Buffer Storage then.
722 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
724 BufferStorage
= Statement
->Storage
;
725 IfrDataEntry
->OpCode
= Statement
->Operand
;
728 if (BufferStorage
!= NULL
) {
729 BrowserDataSize
= BufferStorage
->Size
;
730 IfrDataEntry
->Length
= (UINT8
) (sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
732 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
733 *NvMapAllocated
= TRUE
;
734 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
736 *NvMapAllocated
= FALSE
;
737 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
740 ASSERT (HiiGetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, (UINT8
*) IfrDataArray
->NvRamMap
));
743 case EFI_IFR_TYPE_NUM_SIZE_8
:
744 case EFI_IFR_TYPE_NUM_SIZE_16
:
745 case EFI_IFR_TYPE_NUM_SIZE_32
:
746 case EFI_IFR_TYPE_NUM_SIZE_64
:
747 case EFI_IFR_TYPE_BOOLEAN
:
748 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
751 case EFI_IFR_TYPE_STRING
:
753 ASSERT (String
!= NULL
);
754 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
764 // Need to fiil in the information for the rest of field for EFI_IFR_DATA_ENTRY.
765 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
767 //UINT8 OpCode; // Likely a string, numeric, or one-of
768 //UINT8 Length; // Length of the EFI_IFR_DATA_ENTRY packet
769 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
770 //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
771 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
772 // If the OpCode is a String type - Data is a CHAR16[x] type
773 // If the OpCode is a Checkbox type - Data is a UINT8 value
774 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
781 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
782 needs to be informed when data changed in NvMapOverride. This function will invoke
783 SetBrowserData () to set internal data of Form Browser.
785 @param ConfigAccess The Config Access Private Context.
786 @param QuestionId The Question Id that invokes the callback.
791 SyncBrowserDataForNvMapOverride (
792 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
793 IN EFI_QUESTION_ID QuestionId
796 FORMSET_STORAGE
*BufferStorage
;
798 UINTN BrowserDataSize
;
799 FORM_BROWSER_STATEMENT
*Statement
;
801 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
803 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
805 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
807 // QuestionId is a statement without Storage.
811 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
813 BufferStorage
= Statement
->Storage
;
817 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
819 ASSERT (BufferStorage
!= NULL
);
821 BrowserDataSize
= BufferStorage
->Size
;
823 CheckFlag
= HiiSetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
830 Free up resource allocated for a EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
832 @param Array The EFI_IFR_DATA_ARRAY allocated.
833 @param NvMapAllocated If the NvRamMap is allocated for EFI_IFR_DATA_ARRAY.
837 DestroyIfrDataArray (
838 IN EFI_IFR_DATA_ARRAY
*Array
,
839 IN BOOLEAN NvMapAllocated
843 if (NvMapAllocated
) {
844 FreePool (Array
->NvRamMap
);
852 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
853 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
854 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
855 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
856 for detailed information.
858 @param ThunkContext The Thunk Context.
859 @param QuestionId The Question Id.
860 @param Type The Question Type.
861 @param Value The One Of Option's value.
863 @return The ONE_OF_OPTION_MAP_ENTRY found.
864 @retval NULL If no entry is found.
866 ONE_OF_OPTION_MAP_ENTRY
*
867 GetOneOfOptionMapEntry (
868 IN HII_THUNK_CONTEXT
*ThunkContext
,
869 IN EFI_QUESTION_ID QuestionId
,
871 IN EFI_IFR_TYPE_VALUE
*Value
876 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
877 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
878 FORM_BROWSER_FORMSET
*FormSet
;
880 FormSet
= ThunkContext
->FormSet
;
882 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
884 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
885 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
886 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
887 ASSERT (OneOfOptionMap
->ValueType
== Type
);
889 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
891 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
892 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
894 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
895 return OneOfOptionMapEntry
;
898 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
902 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
910 Functions which are registered to receive notification of
911 database events have this prototype. The actual event is encoded
912 in NotifyType. The following table describes how PackageType,
913 PackageGuid, Handle, and Package are used for each of the
916 If any Pakcage List in database is updated, mHiiPackageListUpdated
917 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
918 will force the UEFI Setup Browser to save the uncommitted data. This
919 is needed as Framework's Callback function may dynamically update
920 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
921 the Package List's IFR and display it. UEFI Config Access's implementation
922 is required to save the modified (SetBrowserData or directly save the data
923 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
924 we will enforce the rule in ThunkCallback (). The side effect of force saving
925 of NV data is the NV flag in browser may not flag a update as data has already
926 been saved to NV storage.
928 @param PackageType Package type of the notification.
930 @param PackageGuid If PackageType is
931 EFI_HII_PACKAGE_TYPE_GUID, then this is
932 the pointer to the GUID from the Guid
933 field of EFI_HII_PACKAGE_GUID_HEADER.
934 Otherwise, it must be NULL.
936 @param Package Points to the package referred to by the
937 notification Handle The handle of the package
938 list which contains the specified package.
940 @param Handle The HII handle.
942 @param NotifyType The type of change concerning the
944 EFI_HII_DATABASE_NOTIFY_TYPE.
950 IN UINT8 PackageType
,
951 IN CONST EFI_GUID
*PackageGuid
,
952 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
953 IN EFI_HII_HANDLE Handle
,
954 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
957 mHiiPackageListUpdated
= TRUE
;
963 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
964 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
966 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
967 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
968 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
969 type of data to expect. The format of the data tends to vary based on the opcode that
970 generated the callback.
971 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
972 EFI_IFR_ONE_OF_OPTION.
973 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
974 by Type. Type EFI_IFR_TYPE_VALUE is defined in
975 EFI_IFR_ONE_OF_OPTION.
976 @param ActionRequest On return, points to the action requested by the callback function. Type
977 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
980 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
981 focuse to be INTERRACTIVE.
982 @retval EFI_SUCCESS The callback complete successfully.
983 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
989 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
990 IN EFI_BROWSER_ACTION Action
,
991 IN EFI_QUESTION_ID QuestionId
,
993 IN EFI_IFR_TYPE_VALUE
*Value
,
994 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
998 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
999 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
1000 EFI_HII_CALLBACK_PACKET
*Packet
;
1001 EFI_IFR_DATA_ARRAY
*Data
;
1002 EFI_IFR_DATA_ENTRY
*DataEntry
;
1004 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
1005 EFI_HANDLE NotifyHandle
;
1007 BOOLEAN NvMapAllocated
;
1009 ASSERT (This
!= NULL
);
1010 ASSERT (Value
!= NULL
);
1011 ASSERT (ActionRequest
!= NULL
);
1013 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1015 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
1017 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
1018 if (FormCallbackProtocol
== NULL
) {
1020 return EFI_UNSUPPORTED
;
1024 // Check if the QuestionId match a OneOfOption.
1026 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
1028 if (OneOfOptionMapEntry
== NULL
) {
1030 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1032 KeyValue
= QuestionId
;
1035 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1037 KeyValue
= OneOfOptionMapEntry
->FwKey
;
1041 // Build the EFI_IFR_DATA_ARRAY
1043 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
1045 Status
= mHiiDatabase
->RegisterPackageNotify (
1047 EFI_HII_PACKAGE_FORMS
,
1050 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1054 //Call the Framework Callback function.
1057 Status
= FormCallbackProtocol
->Callback (
1058 FormCallbackProtocol
,
1063 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1066 // Callback require browser to perform action
1068 if (EFI_ERROR (Status
)) {
1069 if (Packet
!= NULL
) {
1071 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, Packet
->String
, NULL
);
1072 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1075 // Error Code in Status is discarded.
1078 if (Packet
!= NULL
) {
1079 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1080 DataEntry
= (EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (EFI_IFR_DATA_ARRAY
));
1081 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1082 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1085 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1086 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1087 &ConfigAccess
->ConfigAccessProtocol
,
1098 // Unregister notify for Form package update
1100 Status
= mHiiDatabase
->UnregisterPackageNotify (
1105 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1106 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1107 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1108 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1109 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1110 // the form and load all the variable storages.
1112 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1113 mHiiPackageListUpdated
= FALSE
;
1114 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1116 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1117 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1118 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1126 DestroyIfrDataArray (Data
, NvMapAllocated
);