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 EFI_IFR_VARSTORE where the Question's value is stored.
88 @param FormSet The Form Set.
90 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
91 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
94 GetStorageFromQuestionId (
95 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
96 IN EFI_QUESTION_ID QuestionId
100 LIST_ENTRY
*StatementList
;
101 FORM_BROWSER_FORM
*Form
;
102 FORM_BROWSER_STATEMENT
*Statement
;
104 FormList
= GetFirstNode (&FormSet
->FormListHead
);
106 while (!IsNull (&FormSet
->FormListHead
, FormList
)) {
107 Form
= FORM_BROWSER_FORM_FROM_LINK (FormList
);
109 StatementList
= GetFirstNode (&Form
->StatementListHead
);
111 while (!IsNull (&Form
->StatementListHead
, StatementList
)) {
112 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (StatementList
);
113 if ((QuestionId
== Statement
->QuestionId
) && (Statement
->Storage
!= NULL
)) {
115 // UEFI Question ID is unique in a FormSet.
117 ASSERT (Statement
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
);
118 return Statement
->Storage
;
120 StatementList
= GetNextNode (&Form
->StatementListHead
, StatementList
);
123 FormList
= GetNextNode (&FormSet
->FormListHead
, FormList
);
130 Get the EFI_IFR_VARSTORE based the ID.
132 @param FormSet The Form Set.
134 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE with the ID.
135 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
138 GetStorageFromVarStoreId (
139 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
140 IN EFI_VARSTORE_ID VarStoreId
143 LIST_ENTRY
*StorageList
;
144 FORMSET_STORAGE
*Storage
;
146 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
148 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
149 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
151 if (VarStoreId
== Storage
->VarStoreId
) {
155 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
162 Get the EFI_IFR_VARSTORE based the <ConfigHdr> string in a <ConfigRequest>
163 or a <ConfigResp> string.
165 @param FormSet The Form Set.
166 @param ConfigString The Configuration String which is defined by UEFI HII.
168 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
169 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
172 GetStorageFromConfigString (
173 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
174 IN CONST EFI_STRING ConfigString
177 LIST_ENTRY
*StorageList
;
178 FORMSET_STORAGE
*Storage
;
181 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
183 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
184 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
186 if ((Storage
->VarStoreId
== FormSet
->DefaultVarStoreId
) && (FormSet
->OriginalDefaultVarStoreName
!= NULL
)) {
187 Name
= FormSet
->OriginalDefaultVarStoreName
;
189 Name
= Storage
->Name
;
192 if (IsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Name
)) {
196 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
203 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
204 by a module using Framework HII Protocol Interfaces.
206 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
207 that Setup Utility can load the Buffer Storage using this protocol.
209 @param Packages The Package List.
210 @param ThunkContext The Thunk Context.
212 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
213 @retval EFI_OUT_RESOURCE There is not enough memory.
217 InstallDefaultConfigAccessProtocol (
218 IN CONST EFI_HII_PACKAGES
*Packages
,
219 IN OUT HII_THUNK_CONTEXT
*ThunkContext
223 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
224 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
226 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
228 ConfigAccessInstance
= AllocateCopyPool (
229 sizeof (CONFIG_ACCESS_PRIVATE
),
230 &gConfigAccessPrivateTempate
232 ASSERT (ConfigAccessInstance
!= NULL
);
235 // Use memory address as unique ID to distinguish from different device paths
236 // This function may be called multi times by the framework HII driver.
238 HiiVendorPath
= AllocateCopyPool (
239 sizeof (HII_VENDOR_DEVICE_PATH
),
240 &mUefiHiiVendorDevicePath
242 ASSERT (HiiVendorPath
!= NULL
);
244 HiiVendorPath
->Node
.UniqueId
= (UINT64
) ((UINTN
) HiiVendorPath
);
246 Status
= gBS
->InstallMultipleProtocolInterfaces (
247 &ThunkContext
->UefiHiiDriverHandle
,
248 &gEfiDevicePathProtocolGuid
,
250 &gEfiHiiConfigAccessProtocolGuid
,
251 &ConfigAccessInstance
->ConfigAccessProtocol
,
254 ASSERT_EFI_ERROR (Status
);
256 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
262 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
263 by a module using Framework HII Protocol Interfaces.
265 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
267 @param ThunkContext The Thunk Context.
271 UninstallDefaultConfigAccessProtocol (
272 IN HII_THUNK_CONTEXT
*ThunkContext
276 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
277 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
279 Status
= gBS
->HandleProtocol (
280 ThunkContext
->UefiHiiDriverHandle
,
281 &gEfiHiiConfigAccessProtocolGuid
,
282 (VOID
**) &ConfigAccess
284 ASSERT_EFI_ERROR (Status
);
286 Status
= gBS
->HandleProtocol (
287 ThunkContext
->UefiHiiDriverHandle
,
288 &gEfiDevicePathProtocolGuid
,
289 (VOID
**) &HiiVendorPath
291 ASSERT_EFI_ERROR (Status
);
293 Status
= gBS
->UninstallMultipleProtocolInterfaces (
294 ThunkContext
->UefiHiiDriverHandle
,
295 &gEfiDevicePathProtocolGuid
,
297 &gEfiHiiConfigAccessProtocolGuid
,
301 ASSERT_EFI_ERROR (Status
);
307 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
309 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
310 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
311 @param Data The data read.
312 @param DataSize The size of data.
314 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
315 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
316 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
320 IN FORMSET_STORAGE
*BufferStorage
,
321 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
331 Status
= FwFormCallBack
->NvRead (
334 &BufferStorage
->Guid
,
339 if (Status
== EFI_BUFFER_TOO_SMALL
) {
340 if (BufferStorage
->Size
!= *DataSize
) {
342 return EFI_INVALID_PARAMETER
;
345 *Data
= AllocateZeroPool (*DataSize
);
347 return EFI_OUT_OF_RESOURCES
;
350 FwFormCallBack
->NvRead (
353 &BufferStorage
->Guid
,
365 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
367 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
368 @param Data The data read.
369 @param DataSize The size of data.
371 If the UEFI Variable Get Service return the size information of the data
372 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
375 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
376 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
377 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
382 IN FORMSET_STORAGE
*BufferStorage
,
391 Status
= gRT
->GetVariable (
393 &BufferStorage
->Guid
,
398 if (Status
== EFI_BUFFER_TOO_SMALL
) {
400 if (BufferStorage
->Size
!= *DataSize
) {
402 return EFI_INVALID_PARAMETER
;
405 *Data
= AllocateZeroPool (*DataSize
);
407 return EFI_OUT_OF_RESOURCES
;
410 Status
= gRT
->GetVariable (
412 &BufferStorage
->Guid
,
424 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
425 so that data can be read from the data storage such as UEFI Variable or module's
426 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
428 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
429 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
430 includes the routing information as well as the configurable name / value pairs. It is
431 invalid for this string to be in <MultiConfigRequest> format.
433 @param Progress On return, points to a character in the Request string. Points to the string's null
434 terminator if request was successful. Points to the most recent '&' before the first
435 failing name / value pair (or the beginning of the string if the failure is in the first
436 name / value pair) if the request was not successful
437 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
438 values filled in for the names in the Request string. String to be allocated by the called
441 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
442 @retval EFI_SUCCESS The setting is retrived successfully.
443 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
448 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
449 IN CONST EFI_STRING Request
,
450 OUT EFI_STRING
*Progress
,
451 OUT EFI_STRING
*Results
455 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
456 FORMSET_STORAGE
*BufferStorage
;
460 if (Request
== NULL
) {
461 return EFI_NOT_FOUND
;
465 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
467 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
469 if (BufferStorage
== NULL
) {
470 *Progress
= (EFI_STRING
) Request
;
471 return EFI_NOT_FOUND
;
474 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
476 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
478 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
479 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
480 Status
= GetUefiVariable (
486 Status
= CallFormCallBack (
488 ConfigAccess
->FormCallbackProtocol
,
495 // Use the NvMapOverride.
497 DataSize
= BufferStorage
->Size
;
498 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
501 Status
= EFI_SUCCESS
;
503 Status
= EFI_OUT_OF_RESOURCES
;
507 if (!EFI_ERROR (Status
)) {
508 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
509 mHiiConfigRoutingProtocol
,
525 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
526 so that data can be written to the data storage such as UEFI Variable or module's
527 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
529 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
530 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
531 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
532 failing name / value pair (or the beginning of the string if the failure is in the first
533 name / value pair) or the terminating NULL if all was successful.
535 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
536 @retval EFI_SUCCESS The setting is saved successfully.
537 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
542 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
543 IN CONST EFI_STRING Configuration
,
544 OUT EFI_STRING
*Progress
548 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
549 FORMSET_STORAGE
*BufferStorage
;
553 UINTN LastModifiedByteIndex
;
554 BOOLEAN ResetRequired
;
555 BOOLEAN DataAllocated
;
557 if (Configuration
== NULL
) {
558 return EFI_INVALID_PARAMETER
;
562 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
564 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
566 if (BufferStorage
== NULL
) {
567 *Progress
= Configuration
;
568 return EFI_NOT_FOUND
;
571 DataSize2
= BufferStorage
->Size
;
572 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
573 DataAllocated
= TRUE
;
574 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
575 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
576 Status
= GetUefiVariable (
582 Status
= CallFormCallBack (
584 ConfigAccess
->FormCallbackProtocol
,
591 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
593 Status
= EFI_SUCCESS
;
594 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
595 DataSize
= DataSize2
;
596 DataAllocated
= FALSE
;
598 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
600 Data
= AllocateZeroPool (DataSize2
);
604 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
605 mHiiConfigRoutingProtocol
,
608 &LastModifiedByteIndex
,
611 if (EFI_ERROR (Status
)) {
615 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
616 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
617 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
618 Status
= gRT
->SetVariable (
620 &BufferStorage
->Guid
,
621 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
626 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
627 ConfigAccess
->FormCallbackProtocol
,
629 &BufferStorage
->Guid
,
630 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
640 if (DataAllocated
&& (Data
!= NULL
)) {
648 Build the FRAMEWORK_EFI_IFR_DATA_ARRAY which will be used to pass to
649 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of FRAMEWORK_EFI_IFR_DATA_ARRAY
652 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
654 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
655 @param QuestionId The Question ID.
656 @param Type The Question Type.
657 @param Value The Question Value.
658 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
660 @return A pointer to FRAMEWORK_EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
662 FRAMEWORK_EFI_IFR_DATA_ARRAY
*
664 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
665 IN EFI_QUESTION_ID QuestionId
,
667 IN EFI_IFR_TYPE_VALUE
*Value
,
668 OUT BOOLEAN
*NvMapAllocated
671 FRAMEWORK_EFI_IFR_DATA_ARRAY
*IfrDataArray
;
672 FRAMEWORK_EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
673 UINTN BrowserDataSize
;
674 FORMSET_STORAGE
*BufferStorage
;
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
:
695 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
696 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
698 String
= AllocateZeroPool (StringSize
);
699 ASSERT (String
!= NULL
);
701 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
702 ASSERT_EFI_ERROR (Status
);
713 IfrDataArray
= AllocateZeroPool (sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
) + sizeof (FRAMEWORK_EFI_IFR_DATA_ENTRY
) + Size
);
714 ASSERT (IfrDataArray
!= NULL
);
716 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
718 if (BufferStorage
== NULL
) {
720 // The QuestionId is not associated with a Buffer Storage.
721 // Try to get the first Buffer Storage then.
723 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
726 if (BufferStorage
!= NULL
) {
727 BrowserDataSize
= BufferStorage
->Size
;
729 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
730 *NvMapAllocated
= TRUE
;
731 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
733 *NvMapAllocated
= FALSE
;
734 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
737 Status
= GetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, &BrowserDataSize
, IfrDataArray
->NvRamMap
);
738 ASSERT_EFI_ERROR (Status
);
740 IfrDataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
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
:
752 ASSERT (String
!= NULL
);
753 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
762 // Need to fiil in the information for the rest of field for FRAMEWORK_EFI_IFR_DATA_ENTRY.
763 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
765 //UINT8 OpCode; // Likely a string, numeric, or one-of
766 //UINT8 Length; // Length of the FRAMEWORK_EFI_IFR_DATA_ENTRY packet
767 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
768 //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
769 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
770 // If the OpCode is a String type - Data is a CHAR16[x] type
771 // If the OpCode is a Checkbox type - Data is a UINT8 value
772 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
779 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
780 needs to be informed when data changed in NvMapOverride. This function will invoke
781 SetBrowserData () to set internal data of Form Browser.
783 @param ConfigAccess The Config Access Private Context.
784 @param QuestionId The Question Id that invokes the callback.
789 SyncBrowserDataForNvMapOverride (
790 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
791 IN EFI_QUESTION_ID QuestionId
794 FORMSET_STORAGE
*BufferStorage
;
796 UINTN BrowserDataSize
;
798 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
800 BufferStorage
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
802 if (BufferStorage
== NULL
) {
804 // QuestionId is a statement without Storage.
808 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
812 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
814 ASSERT (BufferStorage
!= NULL
);
816 BrowserDataSize
= BufferStorage
->Size
;
818 Status
= SetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
819 ASSERT_EFI_ERROR (Status
);
825 Free up resource allocated for a FRAMEWORK_EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
827 @param Array The FRAMEWORK_EFI_IFR_DATA_ARRAY allocated.
828 @param NvMapAllocated If the NvRamMap is allocated for FRAMEWORK_EFI_IFR_DATA_ARRAY.
832 DestroyIfrDataArray (
833 IN FRAMEWORK_EFI_IFR_DATA_ARRAY
*Array
,
834 IN BOOLEAN NvMapAllocated
838 if (NvMapAllocated
) {
839 FreePool (Array
->NvRamMap
);
847 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
848 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
849 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
850 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
851 for detailed information.
853 @param ThunkContext The Thunk Context.
854 @param QuestionId The Question Id.
855 @param Type The Question Type.
856 @param Value The One Of Option's value.
858 @return The ONE_OF_OPTION_MAP_ENTRY found.
859 @retval NULL If no entry is found.
861 ONE_OF_OPTION_MAP_ENTRY
*
862 GetOneOfOptionMapEntry (
863 IN HII_THUNK_CONTEXT
*ThunkContext
,
864 IN EFI_QUESTION_ID QuestionId
,
866 IN EFI_IFR_TYPE_VALUE
*Value
871 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
872 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
873 FORM_BROWSER_FORMSET
*FormSet
;
875 FormSet
= ThunkContext
->FormSet
;
877 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
879 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
880 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
881 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
882 ASSERT (OneOfOptionMap
->ValueType
== Type
);
884 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
886 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
887 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
889 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
890 return OneOfOptionMapEntry
;
893 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
897 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
905 Functions which are registered to receive notification of
906 database events have this prototype. The actual event is encoded
907 in NotifyType. The following table describes how PackageType,
908 PackageGuid, Handle, and Package are used for each of the
911 If any Pakcage List in database is updated, mHiiPackageListUpdated
912 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
913 will force the UEFI Setup Browser to save the uncommitted data. This
914 is needed as Framework's Callback function may dynamically update
915 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
916 the Package List's IFR and display it. UEFI Config Access's implementation
917 is required to save the modified (SetBrowserData or directly save the data
918 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
919 we will enforce the rule in ThunkCallback (). The side effect of force saving
920 of NV data is the NV flag in browser may not flag a update as data has already
921 been saved to NV storage.
923 @param PackageType Package type of the notification.
925 @param PackageGuid If PackageType is
926 EFI_HII_PACKAGE_TYPE_GUID, then this is
927 the pointer to the GUID from the Guid
928 field of EFI_HII_PACKAGE_GUID_HEADER.
929 Otherwise, it must be NULL.
931 @param Package Points to the package referred to by the
932 notification Handle The handle of the package
933 list which contains the specified package.
935 @param Handle The HII handle.
937 @param NotifyType The type of change concerning the
939 EFI_HII_DATABASE_NOTIFY_TYPE.
945 IN UINT8 PackageType
,
946 IN CONST EFI_GUID
*PackageGuid
,
947 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
948 IN EFI_HII_HANDLE Handle
,
949 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
952 mHiiPackageListUpdated
= TRUE
;
958 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
959 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
961 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
962 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
963 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
964 type of data to expect. The format of the data tends to vary based on the opcode that
965 generated the callback.
966 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
967 EFI_IFR_ONE_OF_OPTION.
968 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
969 by Type. Type EFI_IFR_TYPE_VALUE is defined in
970 EFI_IFR_ONE_OF_OPTION.
971 @param ActionRequest On return, points to the action requested by the callback function. Type
972 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
975 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
976 focuse to be INTERRACTIVE.
977 @retval EFI_SUCCESS The callback complete successfully.
978 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
984 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
985 IN EFI_BROWSER_ACTION Action
,
986 IN EFI_QUESTION_ID QuestionId
,
988 IN EFI_IFR_TYPE_VALUE
*Value
,
989 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
993 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
994 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
995 EFI_HII_CALLBACK_PACKET
*Packet
;
996 FRAMEWORK_EFI_IFR_DATA_ARRAY
*Data
;
997 FRAMEWORK_EFI_IFR_DATA_ENTRY
*DataEntry
;
999 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
1000 EFI_HANDLE NotifyHandle
;
1002 BOOLEAN NvMapAllocated
;
1004 ASSERT (This
!= NULL
);
1005 ASSERT (Value
!= NULL
);
1006 ASSERT (ActionRequest
!= NULL
);
1008 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1010 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
1012 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
1013 if (FormCallbackProtocol
== NULL
) {
1015 return EFI_UNSUPPORTED
;
1019 // Check if the QuestionId match a OneOfOption.
1021 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
1023 if (OneOfOptionMapEntry
== NULL
) {
1025 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1027 KeyValue
= QuestionId
;
1030 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1032 KeyValue
= OneOfOptionMapEntry
->FwKey
;
1036 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
1038 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
1040 Status
= mHiiDatabase
->RegisterPackageNotify (
1042 EFI_HII_PACKAGE_FORMS
,
1045 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1049 //Call the Framework Callback function.
1052 Status
= FormCallbackProtocol
->Callback (
1053 FormCallbackProtocol
,
1058 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1061 // Callback require browser to perform action
1063 if (EFI_ERROR (Status
)) {
1064 if (Packet
!= NULL
) {
1066 IfrLibCreatePopUp (1, &Key
, Packet
->String
);
1067 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1070 // Error Code in Status is discarded.
1073 if (Packet
!= NULL
) {
1074 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1075 DataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
));
1076 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1077 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1080 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1081 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1082 &ConfigAccess
->ConfigAccessProtocol
,
1093 // Unregister notify for Form package update
1095 Status
= mHiiDatabase
->UnregisterPackageNotify (
1100 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1101 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1102 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1103 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1104 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1105 // the form and load all the variable storages.
1107 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1108 mHiiPackageListUpdated
= FALSE
;
1109 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1111 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1112 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1113 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1121 DestroyIfrDataArray (Data
, NvMapAllocated
);