3 This file contains functions related to Config Access Protocols installed by
4 by HII Thunk Modules which is used to thunk UEFI Config Access Callback to
5 Framework HII Callback.
7 Copyright (c) 2008, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "HiiDatabase.h"
20 BOOLEAN mHiiPackageListUpdated
;
22 CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate
= {
23 CONFIG_ACCESS_PRIVATE_SIGNATURE
,
28 }, //ConfigAccessProtocol
29 NULL
, //FormCallbackProtocol
30 {NULL
, NULL
}, //ConfigAccessStorageListHead
35 Find and return the pointer to Package Header of the Form package
36 in the Framework Package List. The Framework Package List is created
37 by a module calling the Framework HII interface.
38 The Framwork Package List contains package data
39 generated by Intel's UEFI VFR Compiler and String gather tool. The data format
40 of the package data is defined by TIANO_AUTOGEN_PACKAGES_HEADER.
42 If the package list contains other type of packages such as KEYBOARD_LAYOUT,
43 FONTS and IMAGES, the ASSERT. This is to make sure the caller is a
44 Framework Module which does not include packages introduced by UEFI Specification
45 or packages that is not supported by Thunk layer.
47 @param Packages The Framework Package List
49 @retval EFI_HII_PACKAGE_HEADER* Return the Package Header of Form Package.
50 @retval NULL If no Form Package is found.
52 EFI_HII_PACKAGE_HEADER
*
54 IN CONST EFI_HII_PACKAGES
*Packages
57 TIANO_AUTOGEN_PACKAGES_HEADER
**TianoAutogenPackageHdrArray
;
58 EFI_HII_PACKAGE_HEADER
*IfrPackage
;
61 ASSERT (Packages
!= NULL
);
65 TianoAutogenPackageHdrArray
= (TIANO_AUTOGEN_PACKAGES_HEADER
**) (((UINT8
*) &Packages
->GuidId
) + sizeof (Packages
->GuidId
));
66 for (Index
= 0; Index
< Packages
->NumberOfPackages
; Index
++) {
68 // BugBug: The current UEFI HII build tool generate a binary in the format defined in:
69 // TIANO_AUTOGEN_PACKAGES_HEADER. We assume that all packages generated in
70 // this binary is with same package type. So the returned IfrPackNum and StringPackNum
71 // may not be the exact number of valid package number in the binary generated
74 switch (TianoAutogenPackageHdrArray
[Index
]->PackageHeader
.Type
) {
75 case EFI_HII_PACKAGE_FORM
:
76 return &TianoAutogenPackageHdrArray
[Index
]->PackageHeader
;
79 case EFI_HII_PACKAGE_STRINGS
:
80 case EFI_HII_PACKAGE_SIMPLE_FONTS
:
84 // The following fonts are invalid for a module that using Framework to UEFI thunk layer.
86 case EFI_HII_PACKAGE_KEYBOARD_LAYOUT
:
87 case EFI_HII_PACKAGE_FONTS
:
88 case EFI_HII_PACKAGE_IMAGES
:
95 return (EFI_HII_PACKAGE_HEADER
*) NULL
;
99 This function scan EFI_IFR_VARSTORE_OP in the Form Package.
100 It create entries for these VARSTORE found and append the entry
103 If FormSetPackage is not EFI_HII_PACKAGE_FORM, then ASSERT.
104 If there is no linear buffer storage in this formset, then ASSERT.
106 @param FormSetPackage The Form Package header.
107 @param BufferStorageListHead The link list for the VARSTORE found in the form package.
109 @retval EFI_SUCCESS The function scan the form set and find one or more VARSTOREs.
110 @retval EFI_OUT_OF_RESOURCES There is not enough memory to complete the function.
114 IN CONST EFI_HII_PACKAGE_HEADER
*FormSetPackage
,
115 OUT LIST_ENTRY
*BufferStorageListHead
122 EFI_IFR_VARSTORE
*VarStoreOpCode
;
123 BUFFER_STORAGE_ENTRY
*BufferStorage
;
125 ASSERT (FormSetPackage
->Type
== EFI_HII_PACKAGE_FORM
);
127 OpCodeOffset
= sizeof (EFI_HII_PACKAGE_HEADER
);
129 // Scan all opcode for the FormSet Package for
130 // EFI_IFR_VARSTORE_OP opcode.
132 while (OpCodeOffset
< FormSetPackage
->Length
) {
133 OpCodeData
= (UINT8
*) FormSetPackage
+ OpCodeOffset
;
135 OpCodeLength
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
136 OpCodeOffset
+= OpCodeLength
;
137 Operand
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
;
139 if (Operand
== EFI_IFR_VARSTORE_OP
) {
140 VarStoreOpCode
= (EFI_IFR_VARSTORE
*)OpCodeData
;
141 BufferStorage
= AllocateZeroPool (sizeof (*BufferStorage
));
142 if (BufferStorage
== NULL
) {
143 return EFI_OUT_OF_RESOURCES
;
146 // Record the attributes: GUID, Name, VarStoreId and Size.
148 CopyMem (&BufferStorage
->Guid
, &VarStoreOpCode
->Guid
, sizeof (EFI_GUID
));
150 BufferStorage
->Name
= AllocateZeroPool (AsciiStrSize (VarStoreOpCode
->Name
) * 2);
151 AsciiStrToUnicodeStr (VarStoreOpCode
->Name
, BufferStorage
->Name
);
153 BufferStorage
->VarStoreId
= VarStoreOpCode
->VarStoreId
;
155 BufferStorage
->Size
= VarStoreOpCode
->Size
;
156 BufferStorage
->Signature
= BUFFER_STORAGE_ENTRY_SIGNATURE
;
158 InsertTailList (BufferStorageListHead
, &BufferStorage
->Link
);
167 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
168 by a module using Framework HII Protocol Interfaces.
170 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
171 that Setup Utility can load the Buffer Storage using this protocol.
173 @param Packages The framework package list.
174 @param ThunkContext The Thunk Layer Handle Mapping Database Entry.
176 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
177 @retval EFI_OUT_RESOURCE There is not enough memory.
181 InstallDefaultConfigAccessProtocol (
182 IN CONST EFI_HII_PACKAGES
*Packages
,
183 IN OUT HII_THUNK_CONTEXT
*ThunkContext
186 EFI_HII_PACKAGE_HEADER
*FormSetPackage
;
188 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
190 Status
= HiiLibCreateHiiDriverHandle (&ThunkContext
->UefiHiiDriverHandle
);
191 ConfigAccessInstance
= AllocateCopyPool (
192 sizeof (CONFIG_ACCESS_PRIVATE
),
193 &gConfigAccessPrivateTempate
195 ASSERT (ConfigAccessInstance
!= NULL
);
197 InitializeListHead (&ConfigAccessInstance
->BufferStorageListHead
);
200 // We assume there is only one formset package in each Forms Package
202 FormSetPackage
= GetIfrFormSet (Packages
);
203 ASSERT (FormSetPackage
!= NULL
);
205 Status
= GetBufferStorage (FormSetPackage
, &ConfigAccessInstance
->BufferStorageListHead
);
206 if (EFI_ERROR (Status
)) {
207 FreePool (ConfigAccessInstance
);
212 Status
= gBS
->InstallMultipleProtocolInterfaces (
213 &ThunkContext
->UefiHiiDriverHandle
,
214 &gEfiHiiConfigAccessProtocolGuid
,
215 &ConfigAccessInstance
->ConfigAccessProtocol
,
219 //BUGBUG: Remove when done.
221 ASSERT_EFI_ERROR (Status
);
223 if (EFI_ERROR (Status
)) {
224 FreePool (ConfigAccessInstance
);
228 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
234 DestroyBufferStorageList (
235 IN LIST_ENTRY
*ListHead
239 BUFFER_STORAGE_ENTRY
*Entry
;
241 while (!IsListEmpty (ListHead
)) {
242 Link
= GetFirstNode (ListHead
);
244 Entry
= BUFFER_STORAGE_ENTRY_FROM_LINK(Link
);
246 FreePool (Entry
->Name
);
247 Link
= RemoveEntryList (Link
);
254 UninstallDefaultConfigAccessProtocol (
255 IN HII_THUNK_CONTEXT
*ThunkContext
259 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
260 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
262 HiiLibDestroyHiiDriverHandle (ThunkContext
->UefiHiiDriverHandle
);
264 Status
= gBS
->HandleProtocol (
265 ThunkContext
->UefiHiiDriverHandle
,
266 &gEfiHiiConfigAccessProtocolGuid
,
267 (VOID
**) &ConfigAccess
270 ASSERT_EFI_ERROR (Status
);
272 Status
= gBS
->UninstallProtocolInterface (
273 ThunkContext
->UefiHiiDriverHandle
,
274 &gEfiHiiConfigAccessProtocolGuid
,
277 ASSERT_EFI_ERROR (Status
);
279 ConfigAccessInstance
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (ConfigAccess
);
281 DestroyBufferStorageList (&ConfigAccessInstance
->BufferStorageListHead
);
287 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
289 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
290 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
291 @param Data The data read.
292 @param DataSize The size of data.
294 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
295 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
296 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
300 IN BUFFER_STORAGE_ENTRY
*BufferStorage
,
301 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
311 Status
= FwFormCallBack
->NvRead (
314 &BufferStorage
->Guid
,
319 if (Status
== EFI_BUFFER_TOO_SMALL
) {
320 if (BufferStorage
->Size
!= *DataSize
) {
322 return EFI_INVALID_PARAMETER
;
325 *Data
= AllocateZeroPool (*DataSize
);
327 return EFI_OUT_OF_RESOURCES
;
330 FwFormCallBack
->NvRead (
333 &BufferStorage
->Guid
,
345 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
347 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
348 @param Data The data read.
349 @param DataSize The size of data.
351 If the UEFI Variable Get Service return the size information of the data
352 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
355 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
356 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
357 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
362 IN BUFFER_STORAGE_ENTRY
*BufferStorage
,
371 Status
= gRT
->GetVariable (
373 &BufferStorage
->Guid
,
378 if (Status
== EFI_BUFFER_TOO_SMALL
) {
380 if (BufferStorage
->Size
!= *DataSize
) {
382 return EFI_INVALID_PARAMETER
;
385 *Data
= AllocateZeroPool (*DataSize
);
387 return EFI_OUT_OF_RESOURCES
;
390 Status
= gRT
->GetVariable (
392 &BufferStorage
->Guid
,
402 BUFFER_STORAGE_ENTRY
*
403 GetBufferStorageEntry (
404 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
409 BUFFER_STORAGE_ENTRY
*BufferStorage
;
411 Link
= GetFirstNode (&ConfigAccess
->BufferStorageListHead
);
413 while (!IsNull (&ConfigAccess
->BufferStorageListHead
, Link
)) {
414 BufferStorage
= BUFFER_STORAGE_ENTRY_FROM_LINK (Link
);
416 if (BufferStorage
->VarStoreId
== VarStoreId
) {
417 return BufferStorage
;
420 Link
= GetNextNode (&ConfigAccess
->BufferStorageListHead
, Link
);
429 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
430 so that data can be read from the data storage such as UEFI Variable or module's
431 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
433 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
434 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
435 includes the routing information as well as the configurable name / value pairs. It is
436 invalid for this string to be in <MultiConfigRequest> format.
438 @param Progress On return, points to a character in the Request string. Points to the string's null
439 terminator if request was successful. Points to the most recent '&' before the first
440 failing name / value pair (or the beginning of the string if the failure is in the first
441 name / value pair) if the request was not successful
442 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
443 values filled in for the names in the Request string. String to be allocated by the called
446 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
447 @retval EFI_SUCCESS The setting is retrived successfully.
448 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
453 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
454 IN CONST EFI_STRING Request
,
455 OUT EFI_STRING
*Progress
,
456 OUT EFI_STRING
*Results
460 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
461 BUFFER_STORAGE_ENTRY
*BufferStorage
;
466 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
469 // For now, only one var varstore is supported so that we don't need to parse the Configuration string.
471 BufferStorage
= GetBufferStorageEntry (ConfigAccess
, (UINT16
) RESERVED_VARSTORE_ID
);
473 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
474 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
475 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
476 Status
= GetUefiVariable (
482 Status
= CallFormCallBack (
484 ConfigAccess
->FormCallbackProtocol
,
490 DataSize
= BufferStorage
->Size
;
491 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
494 Status
= EFI_SUCCESS
;
496 Status
= EFI_OUT_OF_RESOURCES
;
500 if (!EFI_ERROR (Status
)) {
501 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
502 mHiiConfigRoutingProtocol
,
517 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
518 so that data can be written to the data storage such as UEFI Variable or module's
519 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
521 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
522 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
523 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
524 failing name / value pair (or the beginning of the string if the failure is in the first
525 name / value pair) or the terminating NULL if all was successful.
527 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
528 @retval EFI_SUCCESS The setting is saved successfully.
529 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
534 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
535 IN CONST EFI_STRING Configuration
,
536 OUT EFI_STRING
*Progress
540 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
541 BUFFER_STORAGE_ENTRY
*BufferStorage
;
545 UINTN LastModifiedByteIndex
;
546 BOOLEAN ResetRequired
;
547 BOOLEAN DataAllocated
;
550 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
553 // For now, only one var varstore is supported so that we don't need to parse the Configuration string.
555 BufferStorage
= GetBufferStorageEntry (ConfigAccess
, (UINT16
) RESERVED_VARSTORE_ID
);
557 DataSize2
= BufferStorage
->Size
;
558 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
559 DataAllocated
= TRUE
;
560 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
561 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
562 Status
= GetUefiVariable (
568 Status
= CallFormCallBack (
570 ConfigAccess
->FormCallbackProtocol
,
577 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
579 Status
= EFI_SUCCESS
;
580 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
581 DataSize
= DataSize2
;
582 DataAllocated
= FALSE
;
584 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
586 Data
= AllocateZeroPool (DataSize2
);
590 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
591 mHiiConfigRoutingProtocol
,
594 &LastModifiedByteIndex
,
597 if (EFI_ERROR (Status
)) {
601 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
602 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
603 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
604 Status
= gRT
->SetVariable (
606 &BufferStorage
->Guid
,
607 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
612 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
613 ConfigAccess
->FormCallbackProtocol
,
615 &BufferStorage
->Guid
,
616 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
626 if (DataAllocated
&& (Data
!= NULL
)) {
633 FRAMEWORK_EFI_IFR_DATA_ARRAY
*
635 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
636 IN EFI_QUESTION_ID QuestionId
,
638 IN EFI_IFR_TYPE_VALUE
*Value
,
639 OUT BOOLEAN
*NvMapAllocated
642 FRAMEWORK_EFI_IFR_DATA_ARRAY
*IfrDataArray
;
643 FRAMEWORK_EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
644 UINTN BrowserDataSize
;
645 BUFFER_STORAGE_ENTRY
*BufferStorageEntry
;
654 Link
= GetFirstNode (&ConfigAccess
->BufferStorageListHead
);
655 if (IsNull (&ConfigAccess
->BufferStorageListHead
, Link
)) {
660 case EFI_IFR_TYPE_NUM_SIZE_8
:
661 case EFI_IFR_TYPE_NUM_SIZE_16
:
662 case EFI_IFR_TYPE_NUM_SIZE_32
:
663 case EFI_IFR_TYPE_NUM_SIZE_64
:
664 case EFI_IFR_TYPE_BOOLEAN
:
665 Size
= sizeof (*Value
);
668 case EFI_IFR_TYPE_STRING
:
670 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
671 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
673 String
= AllocateZeroPool (StringSize
);
674 ASSERT (String
!= NULL
);
676 Status
= HiiLibGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, String
, &StringSize
);
677 ASSERT_EFI_ERROR (Status
);
688 IfrDataArray
= AllocateZeroPool (sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
) + sizeof (FRAMEWORK_EFI_IFR_DATA_ENTRY
) + Size
);
689 ASSERT (IfrDataArray
!= NULL
);
691 BufferStorageEntry
= BUFFER_STORAGE_ENTRY_FROM_LINK(Link
);
692 BrowserDataSize
= BufferStorageEntry
->Size
;
694 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
695 *NvMapAllocated
= TRUE
;
696 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
698 *NvMapAllocated
= FALSE
;
699 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
702 Status
= GetBrowserData (NULL
, NULL
, &BrowserDataSize
, IfrDataArray
->NvRamMap
);
703 ASSERT_EFI_ERROR (Status
);
705 IfrDataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
708 case EFI_IFR_TYPE_NUM_SIZE_8
:
709 case EFI_IFR_TYPE_NUM_SIZE_16
:
710 case EFI_IFR_TYPE_NUM_SIZE_32
:
711 case EFI_IFR_TYPE_NUM_SIZE_64
:
712 case EFI_IFR_TYPE_BOOLEAN
:
713 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
716 case EFI_IFR_TYPE_STRING
:
717 ASSERT (String
!= NULL
);
718 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
730 SyncBrowserDataForNvMapOverride (
731 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
734 BUFFER_STORAGE_ENTRY
*BufferStorageEntry
;
737 UINTN BrowserDataSize
;
739 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
741 Link
= GetFirstNode (&ConfigAccess
->BufferStorageListHead
);
742 ASSERT (!IsNull (&ConfigAccess
->BufferStorageListHead
, Link
));
744 BufferStorageEntry
= BUFFER_STORAGE_ENTRY_FROM_LINK(Link
);
745 BrowserDataSize
= BufferStorageEntry
->Size
;
747 Status
= SetBrowserData (NULL
, NULL
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
748 ASSERT_EFI_ERROR (Status
);
754 DestroyIfrDataArray (
755 IN FRAMEWORK_EFI_IFR_DATA_ARRAY
*Array
,
756 IN BOOLEAN NvMapAllocated
760 if (NvMapAllocated
) {
761 FreePool (Array
->NvRamMap
);
769 ONE_OF_OPTION_MAP_ENTRY
*
770 GetOneOfOptionMapEntry (
771 IN HII_THUNK_CONTEXT
*ThunkContext
,
772 IN EFI_QUESTION_ID QuestionId
,
774 IN EFI_IFR_TYPE_VALUE
*Value
779 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
780 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
782 Link
= GetFirstNode (&ThunkContext
->OneOfOptionMapListHead
);
784 while (!IsNull (&ThunkContext
->OneOfOptionMapListHead
, Link
)) {
785 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
786 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
787 ASSERT (OneOfOptionMap
->ValueType
== Type
);
789 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
791 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
792 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
794 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
795 return OneOfOptionMapEntry
;
798 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
802 Link
= GetNextNode (&ThunkContext
->OneOfOptionMapListHead
, Link
);
810 Functions which are registered to receive notification of
811 database events have this prototype. The actual event is encoded
812 in NotifyType. The following table describes how PackageType,
813 PackageGuid, Handle, and Package are used for each of the
816 @param PackageType Package type of the notification.
818 @param PackageGuid If PackageType is
819 EFI_HII_PACKAGE_TYPE_GUID, then this is
820 the pointer to the GUID from the Guid
821 field of EFI_HII_PACKAGE_GUID_HEADER.
822 Otherwise, it must be NULL.
824 @param Package Points to the package referred to by the
825 notification Handle The handle of the package
826 list which contains the specified package.
828 @param Handle The HII handle.
830 @param NotifyType The type of change concerning the
832 EFI_HII_DATABASE_NOTIFY_TYPE.
838 IN UINT8 PackageType
,
839 IN CONST EFI_GUID
*PackageGuid
,
840 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
841 IN EFI_HII_HANDLE Handle
,
842 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
845 mHiiPackageListUpdated
= TRUE
;
851 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
852 the framework HII module willl do no porting (except some porting works needed for callback for EFI_ONE_OF_OPTION opcode)
853 and still work with a UEFI HII SetupBrowser.
855 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
856 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
857 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
858 type of data to expect. The format of the data tends to vary based on the opcode that
859 generated the callback.
860 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
861 EFI_IFR_ONE_OF_OPTION.
862 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
863 by Type. Type EFI_IFR_TYPE_VALUE is defined in
864 EFI_IFR_ONE_OF_OPTION.
865 @param ActionRequest On return, points to the action requested by the callback function. Type
866 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
869 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
870 focuse to be INTERRACTIVE.
871 @retval EFI_SUCCESS The callback complete successfully.
872 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
878 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
879 IN EFI_BROWSER_ACTION Action
,
880 IN EFI_QUESTION_ID QuestionId
,
882 IN EFI_IFR_TYPE_VALUE
*Value
,
883 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
887 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
888 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
889 EFI_HII_CALLBACK_PACKET
*Packet
;
890 FRAMEWORK_EFI_IFR_DATA_ARRAY
*Data
;
891 FRAMEWORK_EFI_IFR_DATA_ENTRY
*DataEntry
;
893 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
894 EFI_HANDLE NotifyHandle
;
896 BOOLEAN NvMapAllocated
;
898 ASSERT (This
!= NULL
);
899 ASSERT (Value
!= NULL
);
900 ASSERT (ActionRequest
!= NULL
);
902 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
904 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
906 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
907 if (FormCallbackProtocol
== NULL
) {
909 return EFI_UNSUPPORTED
;
913 // Check if the QuestionId match a OneOfOption.
915 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
917 if (OneOfOptionMapEntry
== NULL
) {
919 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
921 KeyValue
= QuestionId
;
923 KeyValue
= OneOfOptionMapEntry
->FwKey
;
927 // Build the FRAMEWORK_EFI_IFR_DATA_ARRAY
929 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
931 Status
= mHiiDatabase
->RegisterPackageNotify (
933 EFI_HII_PACKAGE_FORM
,
936 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
943 Status
= FormCallbackProtocol
->Callback (
944 FormCallbackProtocol
,
949 SyncBrowserDataForNvMapOverride (ConfigAccess
);
952 // Callback require browser to perform action
954 if (EFI_ERROR (Status
)) {
955 if (Packet
!= NULL
) {
957 IfrLibCreatePopUp (1, &Key
, Packet
->String
);
958 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
961 // Error Code in Status is discarded.
964 if (Packet
!= NULL
) {
965 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
966 DataEntry
= (FRAMEWORK_EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (FRAMEWORK_EFI_IFR_DATA_ARRAY
));
967 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
968 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
971 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
972 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
973 &ConfigAccess
->ConfigAccessProtocol
,
984 // Unregister notify for Form package update
986 Status
= mHiiDatabase
->UnregisterPackageNotify (
991 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
992 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
993 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
994 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
995 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
996 // the form and load all the variable storages.
998 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
999 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1001 if (ConfigAccess
->ThunkContext
->FormSetSubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1002 ConfigAccess
->ThunkContext
->FormSetSubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1003 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1008 DestroyIfrDataArray (Data
, NvMapAllocated
);