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 - 2011, Intel Corporation. All rights reserved.<BR>
7 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 <ConfigHdr> string in a <ConfigRequest>
132 or a <ConfigResp> string.
134 @param FormSet The Form Set.
135 @param ConfigString The Configuration String which is defined by UEFI HII.
137 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
138 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
141 GetStorageFromConfigString (
142 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
143 IN CONST EFI_STRING ConfigString
146 LIST_ENTRY
*StorageList
;
147 FORMSET_STORAGE
*Storage
;
150 if (ConfigString
== NULL
) {
154 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
156 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
157 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
159 if ((Storage
->VarStoreId
== FormSet
->DefaultVarStoreId
) && (FormSet
->OriginalDefaultVarStoreName
!= NULL
)) {
160 Name
= FormSet
->OriginalDefaultVarStoreName
;
162 Name
= Storage
->Name
;
165 if (HiiIsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Name
)) {
169 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
176 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
177 by a module using Framework HII Protocol Interfaces.
179 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
180 that Setup Utility can load the Buffer Storage using this protocol.
182 @param Packages The Package List.
183 @param ThunkContext The Thunk Context.
185 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
186 @retval EFI_OUT_RESOURCE There is not enough memory.
190 InstallDefaultConfigAccessProtocol (
191 IN CONST EFI_HII_PACKAGES
*Packages
,
192 IN OUT HII_THUNK_CONTEXT
*ThunkContext
196 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
197 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
199 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
201 ConfigAccessInstance
= AllocateCopyPool (
202 sizeof (CONFIG_ACCESS_PRIVATE
),
203 &gConfigAccessPrivateTempate
205 ASSERT (ConfigAccessInstance
!= NULL
);
208 // Use memory address as unique ID to distinguish from different device paths
209 // This function may be called multi times by the framework HII driver.
211 HiiVendorPath
= AllocateCopyPool (
212 sizeof (HII_VENDOR_DEVICE_PATH
),
213 &mUefiHiiVendorDevicePath
215 ASSERT (HiiVendorPath
!= NULL
);
217 HiiVendorPath
->Node
.UniqueId
= (UINT64
) ((UINTN
) HiiVendorPath
);
219 Status
= gBS
->InstallMultipleProtocolInterfaces (
220 &ThunkContext
->UefiHiiDriverHandle
,
221 &gEfiDevicePathProtocolGuid
,
223 &gEfiHiiConfigAccessProtocolGuid
,
224 &ConfigAccessInstance
->ConfigAccessProtocol
,
227 ASSERT_EFI_ERROR (Status
);
229 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
235 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
236 by a module using Framework HII Protocol Interfaces.
238 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
240 @param ThunkContext The Thunk Context.
244 UninstallDefaultConfigAccessProtocol (
245 IN HII_THUNK_CONTEXT
*ThunkContext
249 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
250 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
252 Status
= gBS
->HandleProtocol (
253 ThunkContext
->UefiHiiDriverHandle
,
254 &gEfiHiiConfigAccessProtocolGuid
,
255 (VOID
**) &ConfigAccess
257 ASSERT_EFI_ERROR (Status
);
259 Status
= gBS
->HandleProtocol (
260 ThunkContext
->UefiHiiDriverHandle
,
261 &gEfiDevicePathProtocolGuid
,
262 (VOID
**) &HiiVendorPath
264 ASSERT_EFI_ERROR (Status
);
266 Status
= gBS
->UninstallMultipleProtocolInterfaces (
267 ThunkContext
->UefiHiiDriverHandle
,
268 &gEfiDevicePathProtocolGuid
,
270 &gEfiHiiConfigAccessProtocolGuid
,
274 ASSERT_EFI_ERROR (Status
);
280 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
282 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
283 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
284 @param Data The data read.
285 @param DataSize The size of data.
287 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
288 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
289 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
293 IN FORMSET_STORAGE
*BufferStorage
,
294 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
304 Status
= FwFormCallBack
->NvRead (
307 &BufferStorage
->Guid
,
312 if (Status
== EFI_BUFFER_TOO_SMALL
) {
313 if (BufferStorage
->Size
!= *DataSize
) {
315 return EFI_INVALID_PARAMETER
;
318 *Data
= AllocateZeroPool (*DataSize
);
320 return EFI_OUT_OF_RESOURCES
;
323 Status
= FwFormCallBack
->NvRead (
326 &BufferStorage
->Guid
,
338 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
340 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
341 @param Data The data read.
342 @param DataSize The size of data.
344 If the UEFI Variable Get Service return the size information of the data
345 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
348 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
349 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
350 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
354 IN FORMSET_STORAGE
*BufferStorage
,
363 Status
= gRT
->GetVariable (
365 &BufferStorage
->Guid
,
370 if (Status
== EFI_BUFFER_TOO_SMALL
) {
372 if (BufferStorage
->Size
!= *DataSize
) {
374 return EFI_INVALID_PARAMETER
;
377 *Data
= AllocateZeroPool (*DataSize
);
379 return EFI_OUT_OF_RESOURCES
;
382 Status
= gRT
->GetVariable (
384 &BufferStorage
->Guid
,
396 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
397 so that data can be read from the data storage such as UEFI Variable or module's
398 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
400 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
401 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
402 includes the routing information as well as the configurable name / value pairs. It is
403 invalid for this string to be in <MultiConfigRequest> format.
405 @param Progress On return, points to a character in the Request string. Points to the string's null
406 terminator if request was successful. Points to the most recent '&' before the first
407 failing name / value pair (or the beginning of the string if the failure is in the first
408 name / value pair) if the request was not successful
409 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
410 values filled in for the names in the Request string. String to be allocated by the called
413 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
414 @retval EFI_SUCCESS The setting is retrived successfully.
415 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
420 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
421 IN CONST EFI_STRING Request
,
422 OUT EFI_STRING
*Progress
,
423 OUT EFI_STRING
*Results
427 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
428 FORMSET_STORAGE
*BufferStorage
;
431 FORM_BROWSER_FORMSET
*FormSetContext
;
432 CHAR16
*VarStoreName
;
433 EFI_STRING ConfigRequestHdr
;
434 EFI_STRING ConfigRequest
;
436 BOOLEAN AllocatedRequest
;
437 LIST_ENTRY
*StorageList
;
438 EFI_STRING SingleResult
;
439 EFI_STRING FinalResults
;
440 EFI_STRING StrPointer
;
442 if (Progress
== NULL
|| Results
== NULL
) {
443 return EFI_INVALID_PARAMETER
;
447 Status
= EFI_SUCCESS
;
452 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
453 FormSetContext
= ConfigAccess
->ThunkContext
->FormSet
;
454 if (IsListEmpty (&FormSetContext
->StorageListHead
)) {
456 // No VarStorage does exist in this form.
458 return EFI_NOT_FOUND
;
460 StorageList
= GetFirstNode (&FormSetContext
->StorageListHead
);
463 if (Request
!= NULL
) {
464 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
465 if (BufferStorage
== NULL
) {
466 return EFI_NOT_FOUND
;
469 if (IsNull (&FormSetContext
->StorageListHead
, StorageList
)) {
471 // No Storage to be extracted into the results.
475 BufferStorage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
476 StorageList
= GetNextNode (&FormSetContext
->StorageListHead
, StorageList
);
480 ConfigRequestHdr
= NULL
;
481 ConfigRequest
= NULL
;
483 AllocatedRequest
= FALSE
;
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 ConfigRequest
= Request
;
520 if (Request
== NULL
|| (StrStr (Request
, L
"OFFSET") == NULL
)) {
522 // Request is without any request element, construct full request string.
525 if ((BufferStorage
->VarStoreId
== FormSetContext
->DefaultVarStoreId
) && (FormSetContext
->OriginalDefaultVarStoreName
!= NULL
)) {
526 VarStoreName
= FormSetContext
->OriginalDefaultVarStoreName
;
528 VarStoreName
= BufferStorage
->Name
;
532 // First Set ConfigRequestHdr string.
534 ConfigRequestHdr
= HiiConstructConfigHdr (&BufferStorage
->Guid
, VarStoreName
, ConfigAccess
->ThunkContext
->UefiHiiDriverHandle
);
535 ASSERT (ConfigRequestHdr
!= NULL
);
538 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
539 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
541 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
542 ConfigRequest
= AllocateZeroPool (Size
);
543 ASSERT (ConfigRequest
!= NULL
);
544 AllocatedRequest
= TRUE
;
545 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)DataSize
);
546 FreePool (ConfigRequestHdr
);
548 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
549 mHiiConfigRoutingProtocol
,
557 // Free the allocated config request string.
559 if (AllocatedRequest
) {
560 FreePool (ConfigRequest
);
561 ConfigRequest
= NULL
;
565 // Free the allocated Data
571 // Directly return when meet with error
573 if (EFI_ERROR (Status
)) {
577 // Merge result into the final results.
579 if (FinalResults
== NULL
) {
580 FinalResults
= SingleResult
;
583 Size
= StrLen (FinalResults
);
585 Size
= Size
+ StrLen (SingleResult
) + 1;
586 StrPointer
= AllocateZeroPool (Size
* sizeof (CHAR16
));
587 ASSERT (StrPointer
!= NULL
);
588 StrCpy (StrPointer
, FinalResults
);
589 FreePool (FinalResults
);
590 FinalResults
= StrPointer
;
591 StrPointer
= StrPointer
+ StrLen (StrPointer
);
593 StrCpy (StrPointer
+ 1, SingleResult
);
594 FreePool (SingleResult
);
596 } while (Request
== NULL
);
598 if (!EFI_ERROR (Status
)) {
599 *Results
= FinalResults
;
601 if (FinalResults
!= NULL
) {
602 FreePool (FinalResults
);
606 // Set Progress string to the original request string.
608 if (Request
== NULL
) {
610 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
611 *Progress
= Request
+ StrLen (Request
);
618 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
619 so that data can be written to the data storage such as UEFI Variable or module's
620 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
622 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
623 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
624 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
625 failing name / value pair (or the beginning of the string if the failure is in the first
626 name / value pair) or the terminating NULL if all was successful.
628 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
629 @retval EFI_SUCCESS The setting is saved successfully.
630 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
635 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
636 IN CONST EFI_STRING Configuration
,
637 OUT EFI_STRING
*Progress
641 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
642 FORMSET_STORAGE
*BufferStorage
;
646 BOOLEAN ResetRequired
;
647 BOOLEAN DataAllocated
;
649 if (Configuration
== NULL
) {
650 return EFI_INVALID_PARAMETER
;
654 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
656 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
658 if (BufferStorage
== NULL
) {
659 *Progress
= Configuration
;
660 return EFI_NOT_FOUND
;
663 DataSize2
= BufferStorage
->Size
;
664 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
665 DataAllocated
= TRUE
;
666 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
667 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
668 Status
= GetUefiVariable (
674 Status
= CallFormCallBack (
676 ConfigAccess
->FormCallbackProtocol
,
683 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
685 Status
= EFI_SUCCESS
;
686 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
687 DataSize
= DataSize2
;
688 DataAllocated
= FALSE
;
690 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
692 Data
= AllocateZeroPool (DataSize2
);
696 DataSize
= DataSize2
;
697 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
698 mHiiConfigRoutingProtocol
,
704 if (EFI_ERROR (Status
)) {
708 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
709 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
710 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
711 Status
= gRT
->SetVariable (
713 &BufferStorage
->Guid
,
714 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
719 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
720 ConfigAccess
->FormCallbackProtocol
,
722 &BufferStorage
->Guid
,
723 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
732 if (DataAllocated
&& (Data
!= NULL
)) {
740 Build the EFI_IFR_DATA_ARRAY which will be used to pass to
741 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of EFI_IFR_DATA_ARRAY
744 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
746 @param ConfigAccess Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
747 @param QuestionId The Question ID.
748 @param Type The Question Type.
749 @param Value The Question Value.
750 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
752 @return A pointer to EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
756 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
757 IN EFI_QUESTION_ID QuestionId
,
759 IN EFI_IFR_TYPE_VALUE
*Value
,
760 OUT BOOLEAN
*NvMapAllocated
763 EFI_IFR_DATA_ARRAY
*IfrDataArray
;
764 EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
765 UINTN BrowserDataSize
;
766 FORMSET_STORAGE
*BufferStorage
;
769 FORM_BROWSER_STATEMENT
*Statement
;
771 *NvMapAllocated
= FALSE
;
776 case EFI_IFR_TYPE_NUM_SIZE_8
:
777 case EFI_IFR_TYPE_NUM_SIZE_16
:
778 case EFI_IFR_TYPE_NUM_SIZE_32
:
779 case EFI_IFR_TYPE_NUM_SIZE_64
:
780 case EFI_IFR_TYPE_BOOLEAN
:
781 Size
= sizeof (*Value
);
784 case EFI_IFR_TYPE_STRING
:
785 if (Value
->string
== 0) {
788 String
= HiiGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, NULL
);
789 ASSERT (String
!= NULL
);
791 Size
= StrSize (String
);
795 case EFI_IFR_TYPE_ACTION
:
796 case EFI_IFR_TYPE_UNDEFINED
:
806 IfrDataArray
= AllocateZeroPool (sizeof (EFI_IFR_DATA_ARRAY
) + sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
807 ASSERT (IfrDataArray
!= NULL
);
808 IfrDataArray
->EntryCount
= 1;
809 IfrDataEntry
= (EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
811 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
813 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
815 // The QuestionId is not associated with a Buffer Storage.
816 // Try to get the first Buffer Storage then.
818 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
820 BufferStorage
= Statement
->Storage
;
821 IfrDataEntry
->OpCode
= Statement
->Operand
;
824 if (BufferStorage
!= NULL
) {
825 BrowserDataSize
= BufferStorage
->Size
;
826 IfrDataEntry
->Length
= (UINT8
) (sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
828 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
829 *NvMapAllocated
= TRUE
;
830 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
832 *NvMapAllocated
= FALSE
;
833 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
836 ASSERT (HiiGetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, (UINT8
*) IfrDataArray
->NvRamMap
));
839 case EFI_IFR_TYPE_NUM_SIZE_8
:
840 case EFI_IFR_TYPE_NUM_SIZE_16
:
841 case EFI_IFR_TYPE_NUM_SIZE_32
:
842 case EFI_IFR_TYPE_NUM_SIZE_64
:
843 case EFI_IFR_TYPE_BOOLEAN
:
844 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
847 case EFI_IFR_TYPE_STRING
:
849 ASSERT (String
!= NULL
);
850 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
855 case EFI_IFR_TYPE_ACTION
:
856 case EFI_IFR_TYPE_UNDEFINED
:
865 // Need to fiil in the information for the rest of field for EFI_IFR_DATA_ENTRY.
866 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
868 //UINT8 OpCode; // Likely a string, numeric, or one-of
869 //UINT8 Length; // Length of the EFI_IFR_DATA_ENTRY packet
870 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
871 //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
872 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
873 // If the OpCode is a String type - Data is a CHAR16[x] type
874 // If the OpCode is a Checkbox type - Data is a UINT8 value
875 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
882 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
883 needs to be informed when data changed in NvMapOverride. This function will invoke
884 SetBrowserData () to set internal data of Form Browser.
886 @param ConfigAccess The Config Access Private Context.
887 @param QuestionId The Question Id that invokes the callback.
892 SyncBrowserDataForNvMapOverride (
893 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
894 IN EFI_QUESTION_ID QuestionId
897 FORMSET_STORAGE
*BufferStorage
;
899 UINTN BrowserDataSize
;
900 FORM_BROWSER_STATEMENT
*Statement
;
902 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
904 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
906 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
908 // QuestionId is a statement without Storage.
912 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
914 BufferStorage
= Statement
->Storage
;
918 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
920 ASSERT (BufferStorage
!= NULL
);
922 BrowserDataSize
= BufferStorage
->Size
;
924 CheckFlag
= HiiSetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
931 Free up resource allocated for a EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
933 @param Array The EFI_IFR_DATA_ARRAY allocated.
934 @param NvMapAllocated If the NvRamMap is allocated for EFI_IFR_DATA_ARRAY.
938 DestroyIfrDataArray (
939 IN EFI_IFR_DATA_ARRAY
*Array
,
940 IN BOOLEAN NvMapAllocated
944 if (NvMapAllocated
) {
945 FreePool (Array
->NvRamMap
);
953 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
954 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
955 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
956 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
957 for detailed information.
959 @param ThunkContext The Thunk Context.
960 @param QuestionId The Question Id.
961 @param Type The Question Type.
962 @param Value The One Of Option's value.
964 @return The ONE_OF_OPTION_MAP_ENTRY found.
965 @retval NULL If no entry is found.
967 ONE_OF_OPTION_MAP_ENTRY
*
968 GetOneOfOptionMapEntry (
969 IN HII_THUNK_CONTEXT
*ThunkContext
,
970 IN EFI_QUESTION_ID QuestionId
,
972 IN EFI_IFR_TYPE_VALUE
*Value
977 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
978 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
979 FORM_BROWSER_FORMSET
*FormSet
;
981 FormSet
= ThunkContext
->FormSet
;
983 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
985 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
986 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
987 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
988 ASSERT (OneOfOptionMap
->ValueType
== Type
);
990 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
992 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
993 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
995 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
996 return OneOfOptionMapEntry
;
999 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
1003 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
1011 Functions which are registered to receive notification of
1012 database events have this prototype. The actual event is encoded
1013 in NotifyType. The following table describes how PackageType,
1014 PackageGuid, Handle, and Package are used for each of the
1017 If any Pakcage List in database is updated, mHiiPackageListUpdated
1018 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
1019 will force the UEFI Setup Browser to save the uncommitted data. This
1020 is needed as Framework's Callback function may dynamically update
1021 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
1022 the Package List's IFR and display it. UEFI Config Access's implementation
1023 is required to save the modified (SetBrowserData or directly save the data
1024 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
1025 we will enforce the rule in ThunkCallback (). The side effect of force saving
1026 of NV data is the NV flag in browser may not flag a update as data has already
1027 been saved to NV storage.
1029 @param PackageType Package type of the notification.
1031 @param PackageGuid If PackageType is
1032 EFI_HII_PACKAGE_TYPE_GUID, then this is
1033 the pointer to the GUID from the Guid
1034 field of EFI_HII_PACKAGE_GUID_HEADER.
1035 Otherwise, it must be NULL.
1037 @param Package Points to the package referred to by the
1038 notification Handle The handle of the package
1039 list which contains the specified package.
1041 @param Handle The HII handle.
1043 @param NotifyType The type of change concerning the
1045 EFI_HII_DATABASE_NOTIFY_TYPE.
1051 IN UINT8 PackageType
,
1052 IN CONST EFI_GUID
*PackageGuid
,
1053 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
1054 IN EFI_HII_HANDLE Handle
,
1055 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
1058 mHiiPackageListUpdated
= TRUE
;
1064 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
1065 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
1067 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1068 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
1069 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
1070 type of data to expect. The format of the data tends to vary based on the opcode that
1071 generated the callback.
1072 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
1073 EFI_IFR_ONE_OF_OPTION.
1074 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
1075 by Type. Type EFI_IFR_TYPE_VALUE is defined in
1076 EFI_IFR_ONE_OF_OPTION.
1077 @param ActionRequest On return, points to the action requested by the callback function. Type
1078 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
1081 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
1082 focuse to be INTERRACTIVE.
1083 @retval EFI_SUCCESS The callback complete successfully.
1084 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
1090 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1091 IN EFI_BROWSER_ACTION Action
,
1092 IN EFI_QUESTION_ID QuestionId
,
1094 IN EFI_IFR_TYPE_VALUE
*Value
,
1095 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1099 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
1100 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
1101 EFI_HII_CALLBACK_PACKET
*Packet
;
1102 EFI_IFR_DATA_ARRAY
*Data
;
1103 EFI_IFR_DATA_ENTRY
*DataEntry
;
1105 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
1106 EFI_HANDLE NotifyHandle
;
1108 BOOLEAN NvMapAllocated
;
1110 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1111 ASSERT (This
!= NULL
);
1112 ASSERT (Value
!= NULL
);
1113 ASSERT (ActionRequest
!= NULL
);
1115 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1117 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
1119 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
1120 if (FormCallbackProtocol
== NULL
) {
1122 return EFI_UNSUPPORTED
;
1126 // Check if the QuestionId match a OneOfOption.
1128 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
1130 if (OneOfOptionMapEntry
== NULL
) {
1132 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1134 KeyValue
= QuestionId
;
1137 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1139 KeyValue
= OneOfOptionMapEntry
->FwKey
;
1143 // Build the EFI_IFR_DATA_ARRAY
1145 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
1147 Status
= mHiiDatabase
->RegisterPackageNotify (
1149 EFI_HII_PACKAGE_FORMS
,
1152 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1156 //Call the Framework Callback function.
1159 Status
= FormCallbackProtocol
->Callback (
1160 FormCallbackProtocol
,
1165 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1168 // Callback require browser to perform action
1170 if (EFI_ERROR (Status
)) {
1171 if (Packet
!= NULL
) {
1173 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, Packet
->String
, NULL
);
1174 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1177 // Error Code in Status is discarded.
1180 if (Packet
!= NULL
) {
1181 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1182 DataEntry
= (EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (EFI_IFR_DATA_ARRAY
));
1183 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1184 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1187 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1188 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1189 &ConfigAccess
->ConfigAccessProtocol
,
1200 // Unregister notify for Form package update
1202 Status
= mHiiDatabase
->UnregisterPackageNotify (
1207 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1208 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1209 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1210 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1211 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1212 // the form and load all the variable storages.
1214 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1215 mHiiPackageListUpdated
= FALSE
;
1216 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1218 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1219 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1220 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1227 DestroyIfrDataArray (Data
, NvMapAllocated
);
1233 // All other action return unsupported.
1235 return EFI_UNSUPPORTED
;