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"
21 // Defintions required for EFI_FORM_CALLBACK_PROTOCOL, but they are not defined in the Framwork HII 0.92 Specification
23 #define RESET_REQUIRED 1 // Flags setting to signify that the callback operation resulted in an eventual
24 // reset to be done upon exit of the browser
25 #define EXIT_REQUIRED 2 // Flags setting to signify that after the processing of the callback results - exit the browser
26 #define SAVE_REQUIRED 4 // Flags setting to signify that after the processing of the callback results - save the NV data
27 #define NV_CHANGED 8 // Flags setting to signify that after the processing of the callback results - turn the NV flag on
28 #define NV_NOT_CHANGED 16 // Flags setting to signify that after the processing of the callback results - turn the NV flag off
31 BOOLEAN mHiiPackageListUpdated
= FALSE
;
33 HII_VENDOR_DEVICE_PATH mUefiHiiVendorDevicePath
= {
40 (UINT8
) (sizeof (HII_VENDOR_DEVICE_PATH_NODE
)),
41 (UINT8
) ((sizeof (HII_VENDOR_DEVICE_PATH_NODE
)) >> 8)
51 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
53 (UINT8
) (sizeof (EFI_DEVICE_PATH_PROTOCOL
)),
54 (UINT8
) ((sizeof (EFI_DEVICE_PATH_PROTOCOL
)) >> 8)
59 CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate
= {
60 CONFIG_ACCESS_PRIVATE_SIGNATURE
,
65 }, //ConfigAccessProtocol
66 NULL
, //FormCallbackProtocol
71 Get the first EFI_IFR_VARSTORE from the FormSet.
73 @param FormSet The Form Set.
75 @retval FORMSET_STORAGE * Return the first EFI_IFR_VARSTORE.
76 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
79 GetFirstStorageOfFormSet (
80 IN CONST FORM_BROWSER_FORMSET
* FormSet
83 LIST_ENTRY
*StorageList
;
84 FORMSET_STORAGE
*Storage
;
86 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
88 if (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
89 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
97 Get the EFI_IFR_VARSTORE where the Question's value is stored.
99 @param FormSet The Form Set.
101 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
102 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
105 GetStorageFromQuestionId (
106 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
107 IN EFI_QUESTION_ID QuestionId
110 LIST_ENTRY
*FormList
;
111 LIST_ENTRY
*StatementList
;
112 FORM_BROWSER_FORM
*Form
;
113 FORM_BROWSER_STATEMENT
*Statement
;
115 FormList
= GetFirstNode (&FormSet
->FormListHead
);
117 while (!IsNull (&FormSet
->FormListHead
, FormList
)) {
118 Form
= FORM_BROWSER_FORM_FROM_LINK (FormList
);
120 StatementList
= GetFirstNode (&Form
->StatementListHead
);
122 while (!IsNull (&Form
->StatementListHead
, StatementList
)) {
123 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (StatementList
);
124 if ((QuestionId
== Statement
->QuestionId
) && (Statement
->Storage
!= NULL
)) {
126 // UEFI Question ID is unique in a FormSet.
128 ASSERT (Statement
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
);
129 return Statement
->Storage
;
131 StatementList
= GetNextNode (&Form
->StatementListHead
, StatementList
);
134 FormList
= GetNextNode (&FormSet
->FormListHead
, FormList
);
141 Get the EFI_IFR_VARSTORE based the ID.
143 @param FormSet The Form Set.
145 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE with the ID.
146 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
149 GetStorageFromVarStoreId (
150 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
151 IN EFI_VARSTORE_ID VarStoreId
154 LIST_ENTRY
*StorageList
;
155 FORMSET_STORAGE
*Storage
;
157 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
159 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
160 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
162 if (VarStoreId
== Storage
->VarStoreId
) {
166 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
173 Get the EFI_IFR_VARSTORE based the <ConfigHdr> string in a <ConfigRequest>
174 or a <ConfigResp> string.
176 @param FormSet The Form Set.
177 @param ConfigString The Configuration String which is defined by UEFI HII.
179 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
180 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
183 GetStorageFromConfigString (
184 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
185 IN CONST EFI_STRING ConfigString
188 LIST_ENTRY
*StorageList
;
189 FORMSET_STORAGE
*Storage
;
192 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
194 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
195 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
197 if ((Storage
->VarStoreId
== FormSet
->DefaultVarStoreId
) && (FormSet
->OriginalDefaultVarStoreName
!= NULL
)) {
198 Name
= FormSet
->OriginalDefaultVarStoreName
;
200 Name
= Storage
->Name
;
203 if (HiiIsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Name
)) {
207 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
214 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
215 by a module using Framework HII Protocol Interfaces.
217 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
218 that Setup Utility can load the Buffer Storage using this protocol.
220 @param Packages The Package List.
221 @param ThunkContext The Thunk Context.
223 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
224 @retval EFI_OUT_RESOURCE There is not enough memory.
228 InstallDefaultConfigAccessProtocol (
229 IN CONST EFI_HII_PACKAGES
*Packages
,
230 IN OUT HII_THUNK_CONTEXT
*ThunkContext
234 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
235 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
237 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
239 ConfigAccessInstance
= AllocateCopyPool (
240 sizeof (CONFIG_ACCESS_PRIVATE
),
241 &gConfigAccessPrivateTempate
243 ASSERT (ConfigAccessInstance
!= NULL
);
246 // Use memory address as unique ID to distinguish from different device paths
247 // This function may be called multi times by the framework HII driver.
249 HiiVendorPath
= AllocateCopyPool (
250 sizeof (HII_VENDOR_DEVICE_PATH
),
251 &mUefiHiiVendorDevicePath
253 ASSERT (HiiVendorPath
!= NULL
);
255 HiiVendorPath
->Node
.UniqueId
= (UINT64
) ((UINTN
) HiiVendorPath
);
257 Status
= gBS
->InstallMultipleProtocolInterfaces (
258 &ThunkContext
->UefiHiiDriverHandle
,
259 &gEfiDevicePathProtocolGuid
,
261 &gEfiHiiConfigAccessProtocolGuid
,
262 &ConfigAccessInstance
->ConfigAccessProtocol
,
265 ASSERT_EFI_ERROR (Status
);
267 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
273 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
274 by a module using Framework HII Protocol Interfaces.
276 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
278 @param ThunkContext The Thunk Context.
282 UninstallDefaultConfigAccessProtocol (
283 IN HII_THUNK_CONTEXT
*ThunkContext
287 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
288 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
290 Status
= gBS
->HandleProtocol (
291 ThunkContext
->UefiHiiDriverHandle
,
292 &gEfiHiiConfigAccessProtocolGuid
,
293 (VOID
**) &ConfigAccess
295 ASSERT_EFI_ERROR (Status
);
297 Status
= gBS
->HandleProtocol (
298 ThunkContext
->UefiHiiDriverHandle
,
299 &gEfiDevicePathProtocolGuid
,
300 (VOID
**) &HiiVendorPath
302 ASSERT_EFI_ERROR (Status
);
304 Status
= gBS
->UninstallMultipleProtocolInterfaces (
305 ThunkContext
->UefiHiiDriverHandle
,
306 &gEfiDevicePathProtocolGuid
,
308 &gEfiHiiConfigAccessProtocolGuid
,
312 ASSERT_EFI_ERROR (Status
);
318 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
320 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
321 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
322 @param Data The data read.
323 @param DataSize The size of data.
325 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
326 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
327 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
331 IN FORMSET_STORAGE
*BufferStorage
,
332 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
342 Status
= FwFormCallBack
->NvRead (
345 &BufferStorage
->Guid
,
350 if (Status
== EFI_BUFFER_TOO_SMALL
) {
351 if (BufferStorage
->Size
!= *DataSize
) {
353 return EFI_INVALID_PARAMETER
;
356 *Data
= AllocateZeroPool (*DataSize
);
358 return EFI_OUT_OF_RESOURCES
;
361 FwFormCallBack
->NvRead (
364 &BufferStorage
->Guid
,
376 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
378 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
379 @param Data The data read.
380 @param DataSize The size of data.
382 If the UEFI Variable Get Service return the size information of the data
383 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
386 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
387 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
388 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
393 IN FORMSET_STORAGE
*BufferStorage
,
402 Status
= gRT
->GetVariable (
404 &BufferStorage
->Guid
,
409 if (Status
== EFI_BUFFER_TOO_SMALL
) {
411 if (BufferStorage
->Size
!= *DataSize
) {
413 return EFI_INVALID_PARAMETER
;
416 *Data
= AllocateZeroPool (*DataSize
);
418 return EFI_OUT_OF_RESOURCES
;
421 Status
= gRT
->GetVariable (
423 &BufferStorage
->Guid
,
435 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
436 so that data can be read from the data storage such as UEFI Variable or module's
437 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
439 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
440 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
441 includes the routing information as well as the configurable name / value pairs. It is
442 invalid for this string to be in <MultiConfigRequest> format.
444 @param Progress On return, points to a character in the Request string. Points to the string's null
445 terminator if request was successful. Points to the most recent '&' before the first
446 failing name / value pair (or the beginning of the string if the failure is in the first
447 name / value pair) if the request was not successful
448 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
449 values filled in for the names in the Request string. String to be allocated by the called
452 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
453 @retval EFI_SUCCESS The setting is retrived successfully.
454 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
459 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
460 IN CONST EFI_STRING Request
,
461 OUT EFI_STRING
*Progress
,
462 OUT EFI_STRING
*Results
466 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
467 FORMSET_STORAGE
*BufferStorage
;
471 if (Request
== NULL
) {
472 return EFI_NOT_FOUND
;
476 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
478 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
480 if (BufferStorage
== NULL
) {
481 *Progress
= (EFI_STRING
) Request
;
482 return EFI_NOT_FOUND
;
485 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
487 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
489 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
490 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
491 Status
= GetUefiVariable (
497 Status
= CallFormCallBack (
499 ConfigAccess
->FormCallbackProtocol
,
506 // Use the NvMapOverride.
508 DataSize
= BufferStorage
->Size
;
509 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
512 Status
= EFI_SUCCESS
;
514 Status
= EFI_OUT_OF_RESOURCES
;
518 if (!EFI_ERROR (Status
)) {
519 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
520 mHiiConfigRoutingProtocol
,
536 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
537 so that data can be written to the data storage such as UEFI Variable or module's
538 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
540 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
541 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
542 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
543 failing name / value pair (or the beginning of the string if the failure is in the first
544 name / value pair) or the terminating NULL if all was successful.
546 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
547 @retval EFI_SUCCESS The setting is saved successfully.
548 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
553 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
554 IN CONST EFI_STRING Configuration
,
555 OUT EFI_STRING
*Progress
559 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
560 FORMSET_STORAGE
*BufferStorage
;
564 UINTN LastModifiedByteIndex
;
565 BOOLEAN ResetRequired
;
566 BOOLEAN DataAllocated
;
568 if (Configuration
== NULL
) {
569 return EFI_INVALID_PARAMETER
;
573 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
575 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
577 if (BufferStorage
== NULL
) {
578 *Progress
= Configuration
;
579 return EFI_NOT_FOUND
;
582 DataSize2
= BufferStorage
->Size
;
583 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
584 DataAllocated
= TRUE
;
585 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
586 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
587 Status
= GetUefiVariable (
593 Status
= CallFormCallBack (
595 ConfigAccess
->FormCallbackProtocol
,
602 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
604 Status
= EFI_SUCCESS
;
605 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
606 DataSize
= DataSize2
;
607 DataAllocated
= FALSE
;
609 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
611 Data
= AllocateZeroPool (DataSize2
);
615 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
616 mHiiConfigRoutingProtocol
,
619 &LastModifiedByteIndex
,
622 if (EFI_ERROR (Status
)) {
626 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
627 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
628 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
629 Status
= gRT
->SetVariable (
631 &BufferStorage
->Guid
,
632 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
637 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
638 ConfigAccess
->FormCallbackProtocol
,
640 &BufferStorage
->Guid
,
641 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
651 if (DataAllocated
&& (Data
!= NULL
)) {
659 Build the FRAMEWORK_EFI_IFR_DATA_ARRAY which will be used to pass to
660 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of FRAMEWORK_EFI_IFR_DATA_ARRAY
663 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
665 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
666 @param QuestionId The Question ID.
667 @param Type The Question Type.
668 @param Value The Question Value.
669 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
671 @return A pointer to FRAMEWORK_EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
673 FRAMEWORK_EFI_IFR_DATA_ARRAY
*
675 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
676 IN EFI_QUESTION_ID QuestionId
,
678 IN EFI_IFR_TYPE_VALUE
*Value
,
679 OUT BOOLEAN
*NvMapAllocated
682 FRAMEWORK_EFI_IFR_DATA_ARRAY
*IfrDataArray
;
683 FRAMEWORK_EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
684 UINTN BrowserDataSize
;
685 FORMSET_STORAGE
*BufferStorage
;
689 *NvMapAllocated
= FALSE
;
694 case EFI_IFR_TYPE_NUM_SIZE_8
:
695 case EFI_IFR_TYPE_NUM_SIZE_16
:
696 case EFI_IFR_TYPE_NUM_SIZE_32
:
697 case EFI_IFR_TYPE_NUM_SIZE_64
:
698 case EFI_IFR_TYPE_BOOLEAN
:
699 Size
= sizeof (*Value
);
702 case EFI_IFR_TYPE_STRING
:
703 if (Value
->string
== 0) {
706 String
= HiiGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, NULL
);
707 ASSERT (String
!= NULL
);
709 Size
= StrSize (String
);
719 IfrDataArray
= AllocateZeroPool (sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
) + sizeof (FRAMEWORK_EFI_IFR_DATA_ENTRY
) + Size
);
720 ASSERT (IfrDataArray
!= NULL
);
722 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
724 if (BufferStorage
== NULL
) {
726 // The QuestionId is not associated with a Buffer Storage.
727 // Try to get the first Buffer Storage then.
729 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
732 if (BufferStorage
!= NULL
) {
733 BrowserDataSize
= BufferStorage
->Size
;
735 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
736 *NvMapAllocated
= TRUE
;
737 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
739 *NvMapAllocated
= FALSE
;
740 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
743 ASSERT (HiiGetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, (UINT8
*) IfrDataArray
->NvRamMap
));
744 IfrDataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
747 case EFI_IFR_TYPE_NUM_SIZE_8
:
748 case EFI_IFR_TYPE_NUM_SIZE_16
:
749 case EFI_IFR_TYPE_NUM_SIZE_32
:
750 case EFI_IFR_TYPE_NUM_SIZE_64
:
751 case EFI_IFR_TYPE_BOOLEAN
:
752 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
755 case EFI_IFR_TYPE_STRING
:
757 ASSERT (String
!= NULL
);
758 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
768 // Need to fiil in the information for the rest of field for FRAMEWORK_EFI_IFR_DATA_ENTRY.
769 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
771 //UINT8 OpCode; // Likely a string, numeric, or one-of
772 //UINT8 Length; // Length of the FRAMEWORK_EFI_IFR_DATA_ENTRY packet
773 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
774 //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
775 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
776 // If the OpCode is a String type - Data is a CHAR16[x] type
777 // If the OpCode is a Checkbox type - Data is a UINT8 value
778 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
785 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
786 needs to be informed when data changed in NvMapOverride. This function will invoke
787 SetBrowserData () to set internal data of Form Browser.
789 @param ConfigAccess The Config Access Private Context.
790 @param QuestionId The Question Id that invokes the callback.
795 SyncBrowserDataForNvMapOverride (
796 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
797 IN EFI_QUESTION_ID QuestionId
800 FORMSET_STORAGE
*BufferStorage
;
802 UINTN BrowserDataSize
;
804 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
806 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
808 if (BufferStorage
== NULL
) {
810 // QuestionId is a statement without Storage.
814 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
818 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
820 ASSERT (BufferStorage
!= NULL
);
822 BrowserDataSize
= BufferStorage
->Size
;
824 CheckFlag
= HiiSetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
831 Free up resource allocated for a FRAMEWORK_EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
833 @param Array The FRAMEWORK_EFI_IFR_DATA_ARRAY allocated.
834 @param NvMapAllocated If the NvRamMap is allocated for FRAMEWORK_EFI_IFR_DATA_ARRAY.
838 DestroyIfrDataArray (
839 IN FRAMEWORK_EFI_IFR_DATA_ARRAY
*Array
,
840 IN BOOLEAN NvMapAllocated
844 if (NvMapAllocated
) {
845 FreePool (Array
->NvRamMap
);
853 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
854 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
855 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
856 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
857 for detailed information.
859 @param ThunkContext The Thunk Context.
860 @param QuestionId The Question Id.
861 @param Type The Question Type.
862 @param Value The One Of Option's value.
864 @return The ONE_OF_OPTION_MAP_ENTRY found.
865 @retval NULL If no entry is found.
867 ONE_OF_OPTION_MAP_ENTRY
*
868 GetOneOfOptionMapEntry (
869 IN HII_THUNK_CONTEXT
*ThunkContext
,
870 IN EFI_QUESTION_ID QuestionId
,
872 IN EFI_IFR_TYPE_VALUE
*Value
877 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
878 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
879 FORM_BROWSER_FORMSET
*FormSet
;
881 FormSet
= ThunkContext
->FormSet
;
883 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
885 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
886 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
887 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
888 ASSERT (OneOfOptionMap
->ValueType
== Type
);
890 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
892 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
893 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
895 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
896 return OneOfOptionMapEntry
;
899 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
903 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
911 Functions which are registered to receive notification of
912 database events have this prototype. The actual event is encoded
913 in NotifyType. The following table describes how PackageType,
914 PackageGuid, Handle, and Package are used for each of the
917 If any Pakcage List in database is updated, mHiiPackageListUpdated
918 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
919 will force the UEFI Setup Browser to save the uncommitted data. This
920 is needed as Framework's Callback function may dynamically update
921 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
922 the Package List's IFR and display it. UEFI Config Access's implementation
923 is required to save the modified (SetBrowserData or directly save the data
924 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
925 we will enforce the rule in ThunkCallback (). The side effect of force saving
926 of NV data is the NV flag in browser may not flag a update as data has already
927 been saved to NV storage.
929 @param PackageType Package type of the notification.
931 @param PackageGuid If PackageType is
932 EFI_HII_PACKAGE_TYPE_GUID, then this is
933 the pointer to the GUID from the Guid
934 field of EFI_HII_PACKAGE_GUID_HEADER.
935 Otherwise, it must be NULL.
937 @param Package Points to the package referred to by the
938 notification Handle The handle of the package
939 list which contains the specified package.
941 @param Handle The HII handle.
943 @param NotifyType The type of change concerning the
945 EFI_HII_DATABASE_NOTIFY_TYPE.
951 IN UINT8 PackageType
,
952 IN CONST EFI_GUID
*PackageGuid
,
953 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
954 IN EFI_HII_HANDLE Handle
,
955 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
958 mHiiPackageListUpdated
= TRUE
;
964 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
965 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
967 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
968 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
969 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
970 type of data to expect. The format of the data tends to vary based on the opcode that
971 generated the callback.
972 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
973 EFI_IFR_ONE_OF_OPTION.
974 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
975 by Type. Type EFI_IFR_TYPE_VALUE is defined in
976 EFI_IFR_ONE_OF_OPTION.
977 @param ActionRequest On return, points to the action requested by the callback function. Type
978 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
981 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
982 focuse to be INTERRACTIVE.
983 @retval EFI_SUCCESS The callback complete successfully.
984 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
990 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
991 IN EFI_BROWSER_ACTION Action
,
992 IN EFI_QUESTION_ID QuestionId
,
994 IN EFI_IFR_TYPE_VALUE
*Value
,
995 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
999 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
1000 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
1001 EFI_HII_CALLBACK_PACKET
*Packet
;
1002 FRAMEWORK_EFI_IFR_DATA_ARRAY
*Data
;
1003 FRAMEWORK_EFI_IFR_DATA_ENTRY
*DataEntry
;
1005 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
1006 EFI_HANDLE NotifyHandle
;
1008 BOOLEAN NvMapAllocated
;
1010 ASSERT (This
!= NULL
);
1011 ASSERT (Value
!= NULL
);
1012 ASSERT (ActionRequest
!= NULL
);
1014 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1016 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
1018 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
1019 if (FormCallbackProtocol
== NULL
) {
1021 return EFI_UNSUPPORTED
;
1025 // Check if the QuestionId match a OneOfOption.
1027 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
1029 if (OneOfOptionMapEntry
== NULL
) {
1031 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1033 KeyValue
= QuestionId
;
1036 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1038 KeyValue
= OneOfOptionMapEntry
->FwKey
;
1042 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
1044 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
1046 Status
= mHiiDatabase
->RegisterPackageNotify (
1048 EFI_HII_PACKAGE_FORMS
,
1051 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1055 //Call the Framework Callback function.
1058 Status
= FormCallbackProtocol
->Callback (
1059 FormCallbackProtocol
,
1064 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1067 // Callback require browser to perform action
1069 if (EFI_ERROR (Status
)) {
1070 if (Packet
!= NULL
) {
1072 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, Packet
->String
, NULL
);
1073 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1076 // Error Code in Status is discarded.
1079 if (Packet
!= NULL
) {
1080 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1081 DataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
));
1082 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1083 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1086 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1087 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1088 &ConfigAccess
->ConfigAccessProtocol
,
1099 // Unregister notify for Form package update
1101 Status
= mHiiDatabase
->UnregisterPackageNotify (
1106 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1107 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1108 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1109 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1110 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1111 // the form and load all the variable storages.
1113 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1114 mHiiPackageListUpdated
= FALSE
;
1115 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1117 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1118 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1119 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1127 DestroyIfrDataArray (Data
, NvMapAllocated
);