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 - 2010, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "HiiDatabase.h"
18 #include "UefiIfrParser.h"
20 BOOLEAN mHiiPackageListUpdated
= FALSE
;
22 HII_VENDOR_DEVICE_PATH mUefiHiiVendorDevicePath
= {
29 (UINT8
) (sizeof (HII_VENDOR_DEVICE_PATH_NODE
)),
30 (UINT8
) ((sizeof (HII_VENDOR_DEVICE_PATH_NODE
)) >> 8)
40 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
42 (UINT8
) (sizeof (EFI_DEVICE_PATH_PROTOCOL
)),
43 (UINT8
) ((sizeof (EFI_DEVICE_PATH_PROTOCOL
)) >> 8)
48 CONFIG_ACCESS_PRIVATE gConfigAccessPrivateTempate
= {
49 CONFIG_ACCESS_PRIVATE_SIGNATURE
,
54 }, //ConfigAccessProtocol
55 NULL
, //FormCallbackProtocol
60 Get the first EFI_IFR_VARSTORE from the FormSet.
62 @param FormSet The Form Set.
64 @retval FORMSET_STORAGE * Return the first EFI_IFR_VARSTORE.
65 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
68 GetFirstStorageOfFormSet (
69 IN CONST FORM_BROWSER_FORMSET
* FormSet
72 LIST_ENTRY
*StorageList
;
73 FORMSET_STORAGE
*Storage
;
75 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
77 if (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
78 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
86 Get the FORM_BROWSER_STATEMENT that matches the Question's value.
88 @param FormSet The Form Set.
89 @param QuestionId QuestionId
91 @retval FORM_BROWSER_STATEMENT* FORM_BROWSER_STATEMENT that match Question's value.
92 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
94 FORM_BROWSER_STATEMENT
*
95 GetStorageFromQuestionId (
96 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
97 IN EFI_QUESTION_ID QuestionId
100 LIST_ENTRY
*FormList
;
101 LIST_ENTRY
*StatementList
;
102 FORM_BROWSER_FORM
*Form
;
103 FORM_BROWSER_STATEMENT
*Statement
;
105 FormList
= GetFirstNode (&FormSet
->FormListHead
);
107 while (!IsNull (&FormSet
->FormListHead
, FormList
)) {
108 Form
= FORM_BROWSER_FORM_FROM_LINK (FormList
);
110 StatementList
= GetFirstNode (&Form
->StatementListHead
);
112 while (!IsNull (&Form
->StatementListHead
, StatementList
)) {
113 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (StatementList
);
114 if ((QuestionId
== Statement
->QuestionId
) && (Statement
->Storage
!= NULL
)) {
116 // UEFI Question ID is unique in a FormSet.
118 ASSERT (Statement
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
);
121 StatementList
= GetNextNode (&Form
->StatementListHead
, StatementList
);
124 FormList
= GetNextNode (&FormSet
->FormListHead
, FormList
);
131 Get the EFI_IFR_VARSTORE based the <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
:
805 IfrDataArray
= AllocateZeroPool (sizeof (EFI_IFR_DATA_ARRAY
) + sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
806 ASSERT (IfrDataArray
!= NULL
);
807 IfrDataArray
->EntryCount
= 1;
808 IfrDataEntry
= (EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
810 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
812 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
814 // The QuestionId is not associated with a Buffer Storage.
815 // Try to get the first Buffer Storage then.
817 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
819 BufferStorage
= Statement
->Storage
;
820 IfrDataEntry
->OpCode
= Statement
->Operand
;
823 if (BufferStorage
!= NULL
) {
824 BrowserDataSize
= BufferStorage
->Size
;
825 IfrDataEntry
->Length
= (UINT8
) (sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
827 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
828 *NvMapAllocated
= TRUE
;
829 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
831 *NvMapAllocated
= FALSE
;
832 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
835 ASSERT (HiiGetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, (UINT8
*) IfrDataArray
->NvRamMap
));
838 case EFI_IFR_TYPE_NUM_SIZE_8
:
839 case EFI_IFR_TYPE_NUM_SIZE_16
:
840 case EFI_IFR_TYPE_NUM_SIZE_32
:
841 case EFI_IFR_TYPE_NUM_SIZE_64
:
842 case EFI_IFR_TYPE_BOOLEAN
:
843 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
846 case EFI_IFR_TYPE_STRING
:
848 ASSERT (String
!= NULL
);
849 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
854 case EFI_IFR_TYPE_ACTION
:
863 // Need to fiil in the information for the rest of field for EFI_IFR_DATA_ENTRY.
864 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
866 //UINT8 OpCode; // Likely a string, numeric, or one-of
867 //UINT8 Length; // Length of the EFI_IFR_DATA_ENTRY packet
868 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
869 //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
870 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
871 // If the OpCode is a String type - Data is a CHAR16[x] type
872 // If the OpCode is a Checkbox type - Data is a UINT8 value
873 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
880 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
881 needs to be informed when data changed in NvMapOverride. This function will invoke
882 SetBrowserData () to set internal data of Form Browser.
884 @param ConfigAccess The Config Access Private Context.
885 @param QuestionId The Question Id that invokes the callback.
890 SyncBrowserDataForNvMapOverride (
891 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
892 IN EFI_QUESTION_ID QuestionId
895 FORMSET_STORAGE
*BufferStorage
;
897 UINTN BrowserDataSize
;
898 FORM_BROWSER_STATEMENT
*Statement
;
900 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
902 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
904 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
906 // QuestionId is a statement without Storage.
910 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
912 BufferStorage
= Statement
->Storage
;
916 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
918 ASSERT (BufferStorage
!= NULL
);
920 BrowserDataSize
= BufferStorage
->Size
;
922 CheckFlag
= HiiSetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
929 Free up resource allocated for a EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
931 @param Array The EFI_IFR_DATA_ARRAY allocated.
932 @param NvMapAllocated If the NvRamMap is allocated for EFI_IFR_DATA_ARRAY.
936 DestroyIfrDataArray (
937 IN EFI_IFR_DATA_ARRAY
*Array
,
938 IN BOOLEAN NvMapAllocated
942 if (NvMapAllocated
) {
943 FreePool (Array
->NvRamMap
);
951 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
952 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
953 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
954 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
955 for detailed information.
957 @param ThunkContext The Thunk Context.
958 @param QuestionId The Question Id.
959 @param Type The Question Type.
960 @param Value The One Of Option's value.
962 @return The ONE_OF_OPTION_MAP_ENTRY found.
963 @retval NULL If no entry is found.
965 ONE_OF_OPTION_MAP_ENTRY
*
966 GetOneOfOptionMapEntry (
967 IN HII_THUNK_CONTEXT
*ThunkContext
,
968 IN EFI_QUESTION_ID QuestionId
,
970 IN EFI_IFR_TYPE_VALUE
*Value
975 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
976 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
977 FORM_BROWSER_FORMSET
*FormSet
;
979 FormSet
= ThunkContext
->FormSet
;
981 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
983 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
984 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
985 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
986 ASSERT (OneOfOptionMap
->ValueType
== Type
);
988 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
990 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
991 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
993 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
994 return OneOfOptionMapEntry
;
997 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
1001 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
1009 Functions which are registered to receive notification of
1010 database events have this prototype. The actual event is encoded
1011 in NotifyType. The following table describes how PackageType,
1012 PackageGuid, Handle, and Package are used for each of the
1015 If any Pakcage List in database is updated, mHiiPackageListUpdated
1016 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
1017 will force the UEFI Setup Browser to save the uncommitted data. This
1018 is needed as Framework's Callback function may dynamically update
1019 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
1020 the Package List's IFR and display it. UEFI Config Access's implementation
1021 is required to save the modified (SetBrowserData or directly save the data
1022 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
1023 we will enforce the rule in ThunkCallback (). The side effect of force saving
1024 of NV data is the NV flag in browser may not flag a update as data has already
1025 been saved to NV storage.
1027 @param PackageType Package type of the notification.
1029 @param PackageGuid If PackageType is
1030 EFI_HII_PACKAGE_TYPE_GUID, then this is
1031 the pointer to the GUID from the Guid
1032 field of EFI_HII_PACKAGE_GUID_HEADER.
1033 Otherwise, it must be NULL.
1035 @param Package Points to the package referred to by the
1036 notification Handle The handle of the package
1037 list which contains the specified package.
1039 @param Handle The HII handle.
1041 @param NotifyType The type of change concerning the
1043 EFI_HII_DATABASE_NOTIFY_TYPE.
1049 IN UINT8 PackageType
,
1050 IN CONST EFI_GUID
*PackageGuid
,
1051 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
1052 IN EFI_HII_HANDLE Handle
,
1053 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
1056 mHiiPackageListUpdated
= TRUE
;
1062 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
1063 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
1065 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1066 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
1067 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
1068 type of data to expect. The format of the data tends to vary based on the opcode that
1069 generated the callback.
1070 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
1071 EFI_IFR_ONE_OF_OPTION.
1072 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
1073 by Type. Type EFI_IFR_TYPE_VALUE is defined in
1074 EFI_IFR_ONE_OF_OPTION.
1075 @param ActionRequest On return, points to the action requested by the callback function. Type
1076 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
1079 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
1080 focuse to be INTERRACTIVE.
1081 @retval EFI_SUCCESS The callback complete successfully.
1082 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
1088 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1089 IN EFI_BROWSER_ACTION Action
,
1090 IN EFI_QUESTION_ID QuestionId
,
1092 IN EFI_IFR_TYPE_VALUE
*Value
,
1093 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1097 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
1098 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
1099 EFI_HII_CALLBACK_PACKET
*Packet
;
1100 EFI_IFR_DATA_ARRAY
*Data
;
1101 EFI_IFR_DATA_ENTRY
*DataEntry
;
1103 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
1104 EFI_HANDLE NotifyHandle
;
1106 BOOLEAN NvMapAllocated
;
1108 if ((Action
== EFI_BROWSER_ACTION_FORM_OPEN
) || (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
)) {
1110 // Ignore UEFI OPEN/CLOSE Action for FrameworkCallback
1115 ASSERT (This
!= NULL
);
1116 ASSERT (Value
!= NULL
);
1117 ASSERT (ActionRequest
!= NULL
);
1119 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1121 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
1123 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
1124 if (FormCallbackProtocol
== NULL
) {
1126 return EFI_UNSUPPORTED
;
1130 // Check if the QuestionId match a OneOfOption.
1132 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
1134 if (OneOfOptionMapEntry
== NULL
) {
1136 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1138 KeyValue
= QuestionId
;
1141 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1143 KeyValue
= OneOfOptionMapEntry
->FwKey
;
1147 // Build the EFI_IFR_DATA_ARRAY
1149 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
1151 Status
= mHiiDatabase
->RegisterPackageNotify (
1153 EFI_HII_PACKAGE_FORMS
,
1156 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1160 //Call the Framework Callback function.
1163 Status
= FormCallbackProtocol
->Callback (
1164 FormCallbackProtocol
,
1169 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1172 // Callback require browser to perform action
1174 if (EFI_ERROR (Status
)) {
1175 if (Packet
!= NULL
) {
1177 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, Packet
->String
, NULL
);
1178 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1181 // Error Code in Status is discarded.
1184 if (Packet
!= NULL
) {
1185 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1186 DataEntry
= (EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (EFI_IFR_DATA_ARRAY
));
1187 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1188 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1191 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1192 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1193 &ConfigAccess
->ConfigAccessProtocol
,
1204 // Unregister notify for Form package update
1206 Status
= mHiiDatabase
->UnregisterPackageNotify (
1211 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1212 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1213 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1214 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1215 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1216 // the form and load all the variable storages.
1218 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1219 mHiiPackageListUpdated
= FALSE
;
1220 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1222 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1223 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1224 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1232 DestroyIfrDataArray (Data
, NvMapAllocated
);