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 - 2012, 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 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
78 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
79 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
82 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
89 Get the FORM_BROWSER_STATEMENT that matches the Question's value.
91 @param FormSet The Form Set.
92 @param QuestionId QuestionId
94 @retval FORM_BROWSER_STATEMENT* FORM_BROWSER_STATEMENT that match Question's value.
95 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE.
97 FORM_BROWSER_STATEMENT
*
98 GetStorageFromQuestionId (
99 IN CONST FORM_BROWSER_FORMSET
* FormSet
,
100 IN EFI_QUESTION_ID QuestionId
103 LIST_ENTRY
*FormList
;
104 LIST_ENTRY
*StatementList
;
105 FORM_BROWSER_FORM
*Form
;
106 FORM_BROWSER_STATEMENT
*Statement
;
108 FormList
= GetFirstNode (&FormSet
->FormListHead
);
110 while (!IsNull (&FormSet
->FormListHead
, FormList
)) {
111 Form
= FORM_BROWSER_FORM_FROM_LINK (FormList
);
113 StatementList
= GetFirstNode (&Form
->StatementListHead
);
115 while (!IsNull (&Form
->StatementListHead
, StatementList
)) {
116 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (StatementList
);
117 if ((QuestionId
== Statement
->QuestionId
) && (Statement
->Storage
!= NULL
)) {
119 // UEFI Question ID is unique in a FormSet.
121 ASSERT (Statement
->Storage
->Type
== EFI_HII_VARSTORE_BUFFER
);
124 StatementList
= GetNextNode (&Form
->StatementListHead
, StatementList
);
127 FormList
= GetNextNode (&FormSet
->FormListHead
, FormList
);
134 Get the EFI_IFR_VARSTORE based the <ConfigHdr> string in a <ConfigRequest>
135 or a <ConfigResp> string.
137 @param FormSet The Form Set.
138 @param ConfigString The Configuration String which is defined by UEFI HII.
140 @retval FORMSET_STORAGE * The EFI_IFR_VARSTORE where the Question's value is stored.
141 @retval NULL If the Form Set does not have EFI_IFR_VARSTORE with such ID.
144 GetStorageFromConfigString (
145 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
146 IN CONST EFI_STRING ConfigString
149 LIST_ENTRY
*StorageList
;
150 FORMSET_STORAGE
*Storage
;
153 if (ConfigString
== NULL
) {
157 StorageList
= GetFirstNode (&FormSet
->StorageListHead
);
159 while (!IsNull (&FormSet
->StorageListHead
, StorageList
)) {
160 Storage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
161 StorageList
= GetNextNode (&FormSet
->StorageListHead
, StorageList
);
162 if (Storage
->Type
!= EFI_HII_VARSTORE_BUFFER
) {
166 if ((Storage
->VarStoreId
== FormSet
->DefaultVarStoreId
) && (FormSet
->OriginalDefaultVarStoreName
!= NULL
)) {
167 Name
= FormSet
->OriginalDefaultVarStoreName
;
169 Name
= Storage
->Name
;
172 if (HiiIsConfigHdrMatch (ConfigString
, &Storage
->Guid
, Name
)) {
181 This function installs a EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
182 by a module using Framework HII Protocol Interfaces.
184 UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
185 that Setup Utility can load the Buffer Storage using this protocol.
187 @param Packages The Package List.
188 @param ThunkContext The Thunk Context.
190 @retval EFI_SUCCESS The Config Access Protocol is installed successfully.
191 @retval EFI_OUT_RESOURCE There is not enough memory.
195 InstallDefaultConfigAccessProtocol (
196 IN CONST EFI_HII_PACKAGES
*Packages
,
197 IN OUT HII_THUNK_CONTEXT
*ThunkContext
201 CONFIG_ACCESS_PRIVATE
*ConfigAccessInstance
;
202 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
204 ASSERT (ThunkContext
->IfrPackageCount
!= 0);
206 ConfigAccessInstance
= AllocateCopyPool (
207 sizeof (CONFIG_ACCESS_PRIVATE
),
208 &gConfigAccessPrivateTempate
210 ASSERT (ConfigAccessInstance
!= NULL
);
213 // Use memory address as unique ID to distinguish from different device paths
214 // This function may be called multi times by the framework HII driver.
216 HiiVendorPath
= AllocateCopyPool (
217 sizeof (HII_VENDOR_DEVICE_PATH
),
218 &mUefiHiiVendorDevicePath
220 ASSERT (HiiVendorPath
!= NULL
);
222 HiiVendorPath
->Node
.UniqueId
= (UINT64
) ((UINTN
) HiiVendorPath
);
224 Status
= gBS
->InstallMultipleProtocolInterfaces (
225 &ThunkContext
->UefiHiiDriverHandle
,
226 &gEfiDevicePathProtocolGuid
,
228 &gEfiHiiConfigAccessProtocolGuid
,
229 &ConfigAccessInstance
->ConfigAccessProtocol
,
232 ASSERT_EFI_ERROR (Status
);
234 ConfigAccessInstance
->ThunkContext
= ThunkContext
;
240 This function un-installs the EFI_CONFIG_ACCESS_PROTOCOL instance for a form package registered
241 by a module using Framework HII Protocol Interfaces.
243 ASSERT if no Config Access is found for such pakcage list or failed to uninstall the protocol.
245 @param ThunkContext The Thunk Context.
249 UninstallDefaultConfigAccessProtocol (
250 IN HII_THUNK_CONTEXT
*ThunkContext
254 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
255 HII_VENDOR_DEVICE_PATH
*HiiVendorPath
;
257 Status
= gBS
->HandleProtocol (
258 ThunkContext
->UefiHiiDriverHandle
,
259 &gEfiHiiConfigAccessProtocolGuid
,
260 (VOID
**) &ConfigAccess
262 ASSERT_EFI_ERROR (Status
);
264 Status
= gBS
->HandleProtocol (
265 ThunkContext
->UefiHiiDriverHandle
,
266 &gEfiDevicePathProtocolGuid
,
267 (VOID
**) &HiiVendorPath
269 ASSERT_EFI_ERROR (Status
);
271 Status
= gBS
->UninstallMultipleProtocolInterfaces (
272 ThunkContext
->UefiHiiDriverHandle
,
273 &gEfiDevicePathProtocolGuid
,
275 &gEfiHiiConfigAccessProtocolGuid
,
279 ASSERT_EFI_ERROR (Status
);
285 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to EFI_FORM_CALLBACK_PROTOCOL.NvRead.
287 @param BufferStorage The key with all attributes needed to call EFI_FORM_CALLBACK_PROTOCOL.NvRead.
288 @param FwFormCallBack The EFI_FORM_CALLBACK_PROTOCOL registered by Framework HII module.
289 @param Data The data read.
290 @param DataSize The size of data.
292 @retval EFI_STATUS The status returned by the EFI_FORM_CALLBACK_PROTOCOL.NvWrite.
293 @retval EFI_INVALID_PARAMETER If the EFI_FORM_CALLBACK_PROTOCOL.NvRead return the size information of the data
294 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
298 IN FORMSET_STORAGE
*BufferStorage
,
299 IN EFI_FORM_CALLBACK_PROTOCOL
*FwFormCallBack
,
309 Status
= FwFormCallBack
->NvRead (
312 &BufferStorage
->Guid
,
317 if (Status
== EFI_BUFFER_TOO_SMALL
) {
318 if (BufferStorage
->Size
!= *DataSize
) {
320 return EFI_INVALID_PARAMETER
;
323 *Data
= AllocateZeroPool (*DataSize
);
325 return EFI_OUT_OF_RESOURCES
;
328 Status
= FwFormCallBack
->NvRead (
331 &BufferStorage
->Guid
,
343 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig to a call to UEFI Variable Get Service.
345 @param BufferStorage The key with all attributes needed to call a UEFI Variable Get Service.
346 @param Data The data read.
347 @param DataSize The size of data.
349 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.
353 @retval EFI_STATUS The status returned by the UEFI Variable Get Service.
354 @retval EFI_INVALID_PARAMETER If the UEFI Variable Get Service return the size information of the data
355 does not match what has been recorded early in he BUFFER_STORAGE_ENTRY.
359 IN FORMSET_STORAGE
*BufferStorage
,
368 Status
= gRT
->GetVariable (
370 &BufferStorage
->Guid
,
375 if (Status
== EFI_BUFFER_TOO_SMALL
) {
377 if (BufferStorage
->Size
!= *DataSize
) {
379 return EFI_INVALID_PARAMETER
;
382 *Data
= AllocateZeroPool (*DataSize
);
384 return EFI_OUT_OF_RESOURCES
;
387 Status
= gRT
->GetVariable (
389 &BufferStorage
->Guid
,
401 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig
402 so that data can be read from the data storage such as UEFI Variable or module's
403 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
405 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
406 @param Request A null-terminated Unicode string in <ConfigRequest> format. Note that this
407 includes the routing information as well as the configurable name / value pairs. It is
408 invalid for this string to be in <MultiConfigRequest> format.
410 @param Progress On return, points to a character in the Request string. Points to the string's null
411 terminator if request was successful. Points to the most recent '&' before the first
412 failing name / value pair (or the beginning of the string if the failure is in the first
413 name / value pair) if the request was not successful
414 @param Results A null-terminated Unicode string in <ConfigAltResp> format which has all
415 values filled in for the names in the Request string. String to be allocated by the called
418 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
419 @retval EFI_SUCCESS The setting is retrived successfully.
420 @retval !EFI_SUCCESS The error returned by UEFI Get Variable or Framework Form Callback Nvread.
425 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
426 IN CONST EFI_STRING Request
,
427 OUT EFI_STRING
*Progress
,
428 OUT EFI_STRING
*Results
432 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
433 FORMSET_STORAGE
*BufferStorage
;
436 FORM_BROWSER_FORMSET
*FormSetContext
;
437 CHAR16
*VarStoreName
;
438 EFI_STRING ConfigRequestHdr
;
439 EFI_STRING ConfigRequest
;
441 BOOLEAN AllocatedRequest
;
442 LIST_ENTRY
*StorageList
;
443 EFI_STRING SingleResult
;
444 EFI_STRING FinalResults
;
445 EFI_STRING StrPointer
;
447 if (Progress
== NULL
|| Results
== NULL
) {
448 return EFI_INVALID_PARAMETER
;
452 Status
= EFI_SUCCESS
;
457 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
458 FormSetContext
= ConfigAccess
->ThunkContext
->FormSet
;
459 if (IsListEmpty (&FormSetContext
->StorageListHead
)) {
461 // No VarStorage does exist in this form.
463 return EFI_NOT_FOUND
;
465 StorageList
= GetFirstNode (&FormSetContext
->StorageListHead
);
468 if (Request
!= NULL
) {
469 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Request
);
470 if (BufferStorage
== NULL
) {
471 return EFI_NOT_FOUND
;
474 if (IsNull (&FormSetContext
->StorageListHead
, StorageList
)) {
476 // No Storage to be extracted into the results.
480 BufferStorage
= FORMSET_STORAGE_FROM_LINK (StorageList
);
481 StorageList
= GetNextNode (&FormSetContext
->StorageListHead
, StorageList
);
482 if (BufferStorage
->Type
!= EFI_HII_VARSTORE_BUFFER
) {
484 // BufferStorage type should be EFI_HII_VARSTORE_BUFFER
491 ConfigRequestHdr
= NULL
;
492 ConfigRequest
= NULL
;
494 AllocatedRequest
= FALSE
;
496 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
498 // NvMapOverride is not used. Get the Storage data from EFI Variable or Framework Form Callback.
500 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
501 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
502 Status
= GetUefiVariable (
508 Status
= CallFormCallBack (
510 ConfigAccess
->FormCallbackProtocol
,
517 // Use the NvMapOverride.
519 DataSize
= BufferStorage
->Size
;
520 Data
= AllocateCopyPool (DataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
);
523 Status
= EFI_SUCCESS
;
525 Status
= EFI_OUT_OF_RESOURCES
;
529 if (!EFI_ERROR (Status
)) {
530 ConfigRequest
= Request
;
531 if (Request
== NULL
|| (StrStr (Request
, L
"OFFSET") == NULL
)) {
533 // Request is without any request element, construct full request string.
536 if ((BufferStorage
->VarStoreId
== FormSetContext
->DefaultVarStoreId
) && (FormSetContext
->OriginalDefaultVarStoreName
!= NULL
)) {
537 VarStoreName
= FormSetContext
->OriginalDefaultVarStoreName
;
539 VarStoreName
= BufferStorage
->Name
;
543 // First Set ConfigRequestHdr string.
545 ConfigRequestHdr
= HiiConstructConfigHdr (&BufferStorage
->Guid
, VarStoreName
, ConfigAccess
->ThunkContext
->UefiHiiDriverHandle
);
546 ASSERT (ConfigRequestHdr
!= NULL
);
549 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
550 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
552 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
553 ConfigRequest
= AllocateZeroPool (Size
);
554 ASSERT (ConfigRequest
!= NULL
);
555 AllocatedRequest
= TRUE
;
556 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)DataSize
);
557 FreePool (ConfigRequestHdr
);
559 Status
= mHiiConfigRoutingProtocol
->BlockToConfig (
560 mHiiConfigRoutingProtocol
,
568 // Free the allocated config request string.
570 if (AllocatedRequest
) {
571 FreePool (ConfigRequest
);
572 ConfigRequest
= NULL
;
576 // Free the allocated Data
582 // Directly return when meet with error
584 if (EFI_ERROR (Status
)) {
588 // Merge result into the final results.
590 if (FinalResults
== NULL
) {
591 FinalResults
= SingleResult
;
594 Size
= StrLen (FinalResults
);
596 Size
= Size
+ StrLen (SingleResult
) + 1;
597 StrPointer
= AllocateZeroPool (Size
* sizeof (CHAR16
));
598 ASSERT (StrPointer
!= NULL
);
599 StrCpy (StrPointer
, FinalResults
);
600 FreePool (FinalResults
);
601 FinalResults
= StrPointer
;
602 StrPointer
= StrPointer
+ StrLen (StrPointer
);
604 StrCpy (StrPointer
+ 1, SingleResult
);
605 FreePool (SingleResult
);
607 } while (Request
== NULL
);
609 if (!EFI_ERROR (Status
)) {
610 *Results
= FinalResults
;
612 if (FinalResults
!= NULL
) {
613 FreePool (FinalResults
);
617 // Set Progress string to the original request string.
619 if (Request
== NULL
) {
621 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
622 *Progress
= Request
+ StrLen (Request
);
629 This function implement the EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig
630 so that data can be written to the data storage such as UEFI Variable or module's
631 customized storage exposed by EFI_FRAMEWORK_CALLBACK.
633 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
634 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
635 @param Progress A pointer to a string filled in with the offset of the most recent '&' before the first
636 failing name / value pair (or the beginning of the string if the failure is in the first
637 name / value pair) or the terminating NULL if all was successful.
639 @retval EFI_INVALID_PARAMETER If there is no Buffer Storage for this Config Access instance.
640 @retval EFI_SUCCESS The setting is saved successfully.
641 @retval !EFI_SUCCESS The error returned by UEFI Set Variable or Framework Form Callback Nvwrite.
646 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
647 IN CONST EFI_STRING Configuration
,
648 OUT EFI_STRING
*Progress
652 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
653 FORMSET_STORAGE
*BufferStorage
;
657 BOOLEAN ResetRequired
;
658 BOOLEAN DataAllocated
;
660 if (Configuration
== NULL
) {
661 return EFI_INVALID_PARAMETER
;
665 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
667 BufferStorage
= GetStorageFromConfigString (ConfigAccess
->ThunkContext
->FormSet
, Configuration
);
669 if (BufferStorage
== NULL
) {
670 *Progress
= Configuration
;
671 return EFI_NOT_FOUND
;
674 DataSize2
= BufferStorage
->Size
;
675 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
676 DataAllocated
= TRUE
;
677 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
678 ConfigAccess
->FormCallbackProtocol
->NvRead
== NULL
) {
679 Status
= GetUefiVariable (
685 Status
= CallFormCallBack (
687 ConfigAccess
->FormCallbackProtocol
,
694 // ConfigToBlock will convert the Config String and update the NvMapOverride accordingly.
696 Status
= EFI_SUCCESS
;
697 Data
= ConfigAccess
->ThunkContext
->NvMapOverride
;
698 DataSize
= DataSize2
;
699 DataAllocated
= FALSE
;
701 if (EFI_ERROR (Status
) || (DataSize2
!= DataSize
)) {
703 Data
= AllocateZeroPool (DataSize2
);
707 DataSize
= DataSize2
;
708 Status
= mHiiConfigRoutingProtocol
->ConfigToBlock (
709 mHiiConfigRoutingProtocol
,
715 if (EFI_ERROR (Status
)) {
719 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
720 if (ConfigAccess
->FormCallbackProtocol
== NULL
||
721 ConfigAccess
->FormCallbackProtocol
->NvWrite
== NULL
) {
722 Status
= gRT
->SetVariable (
724 &BufferStorage
->Guid
,
725 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
730 Status
= ConfigAccess
->FormCallbackProtocol
->NvWrite (
731 ConfigAccess
->FormCallbackProtocol
,
733 &BufferStorage
->Guid
,
734 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
743 if (DataAllocated
&& (Data
!= NULL
)) {
751 Build the EFI_IFR_DATA_ARRAY which will be used to pass to
752 EFI_FORM_CALLBACK_PROTOCOL.Callback. Check definition of EFI_IFR_DATA_ARRAY
755 ASSERT if the Question Type is not EFI_IFR_TYPE_NUM_SIZE_* or EFI_IFR_TYPE_STRING.
757 @param ConfigAccess Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL
758 @param QuestionId The Question ID.
759 @param Type The Question Type.
760 @param Value The Question Value.
761 @param NvMapAllocated On output indicates if a buffer is allocated for NvMap.
763 @return A pointer to EFI_IFR_DATA_ARRAY. The caller must free this buffer allocated.
767 IN CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
768 IN EFI_QUESTION_ID QuestionId
,
770 IN EFI_IFR_TYPE_VALUE
*Value
,
771 OUT BOOLEAN
*NvMapAllocated
774 EFI_IFR_DATA_ARRAY
*IfrDataArray
;
775 EFI_IFR_DATA_ENTRY
*IfrDataEntry
;
776 UINTN BrowserDataSize
;
777 FORMSET_STORAGE
*BufferStorage
;
780 FORM_BROWSER_STATEMENT
*Statement
;
782 *NvMapAllocated
= FALSE
;
787 case EFI_IFR_TYPE_NUM_SIZE_8
:
788 case EFI_IFR_TYPE_NUM_SIZE_16
:
789 case EFI_IFR_TYPE_NUM_SIZE_32
:
790 case EFI_IFR_TYPE_NUM_SIZE_64
:
791 case EFI_IFR_TYPE_BOOLEAN
:
792 Size
= sizeof (*Value
);
795 case EFI_IFR_TYPE_STRING
:
796 if (Value
->string
== 0) {
799 String
= HiiGetString (ConfigAccess
->ThunkContext
->UefiHiiHandle
, Value
->string
, NULL
);
800 ASSERT (String
!= NULL
);
802 Size
= StrSize (String
);
806 case EFI_IFR_TYPE_ACTION
:
807 case EFI_IFR_TYPE_UNDEFINED
:
817 IfrDataArray
= AllocateZeroPool (sizeof (EFI_IFR_DATA_ARRAY
) + sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
818 ASSERT (IfrDataArray
!= NULL
);
819 IfrDataArray
->EntryCount
= 1;
820 IfrDataEntry
= (EFI_IFR_DATA_ENTRY
*) (IfrDataArray
+ 1);
822 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
824 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
826 // The QuestionId is not associated with a Buffer Storage.
827 // Try to get the first Buffer Storage then.
829 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
831 BufferStorage
= Statement
->Storage
;
832 IfrDataEntry
->OpCode
= Statement
->Operand
;
835 if (BufferStorage
!= NULL
) {
836 BrowserDataSize
= BufferStorage
->Size
;
837 IfrDataEntry
->Length
= (UINT8
) (sizeof (EFI_IFR_DATA_ENTRY
) + Size
);
839 if (ConfigAccess
->ThunkContext
->NvMapOverride
== NULL
) {
840 *NvMapAllocated
= TRUE
;
841 IfrDataArray
->NvRamMap
= AllocateZeroPool (BrowserDataSize
);
843 *NvMapAllocated
= FALSE
;
844 IfrDataArray
->NvRamMap
= ConfigAccess
->ThunkContext
->NvMapOverride
;
847 ASSERT (HiiGetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, (UINT8
*) IfrDataArray
->NvRamMap
));
850 case EFI_IFR_TYPE_NUM_SIZE_8
:
851 case EFI_IFR_TYPE_NUM_SIZE_16
:
852 case EFI_IFR_TYPE_NUM_SIZE_32
:
853 case EFI_IFR_TYPE_NUM_SIZE_64
:
854 case EFI_IFR_TYPE_BOOLEAN
:
855 CopyMem (&IfrDataEntry
->Data
, &(Value
->u8
), sizeof (*Value
));
858 case EFI_IFR_TYPE_STRING
:
860 ASSERT (String
!= NULL
);
861 StrCpy ((CHAR16
*) &IfrDataEntry
->Data
, String
);
866 case EFI_IFR_TYPE_ACTION
:
867 case EFI_IFR_TYPE_UNDEFINED
:
876 // Need to fiil in the information for the rest of field for EFI_IFR_DATA_ENTRY.
877 // It seems that no implementation is found to use other fields. Leave them uninitialized for now.
879 //UINT8 OpCode; // Likely a string, numeric, or one-of
880 //UINT8 Length; // Length of the EFI_IFR_DATA_ENTRY packet
881 //UINT16 Flags; // Flags settings to determine what behavior is desired from the browser after the callback
882 //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
883 // If the OpCode is a OneOf or Numeric type - Data is a UINT16 value
884 // If the OpCode is a String type - Data is a CHAR16[x] type
885 // If the OpCode is a Checkbox type - Data is a UINT8 value
886 // If the OpCode is a NV Access type - Data is a FRAMEWORK_EFI_IFR_NV_DATA structure
893 If a NvMapOverride is passed in to EFI_FORM_BROWSER_PROTOCOL.SendForm, the Form Browser
894 needs to be informed when data changed in NvMapOverride. This function will invoke
895 SetBrowserData () to set internal data of Form Browser.
897 @param ConfigAccess The Config Access Private Context.
898 @param QuestionId The Question Id that invokes the callback.
903 SyncBrowserDataForNvMapOverride (
904 IN CONST CONFIG_ACCESS_PRIVATE
*ConfigAccess
,
905 IN EFI_QUESTION_ID QuestionId
908 FORMSET_STORAGE
*BufferStorage
;
910 UINTN BrowserDataSize
;
911 FORM_BROWSER_STATEMENT
*Statement
;
913 if (ConfigAccess
->ThunkContext
->NvMapOverride
!= NULL
) {
915 Statement
= GetStorageFromQuestionId (ConfigAccess
->ThunkContext
->FormSet
, QuestionId
);
917 if (Statement
== NULL
|| Statement
->Storage
== NULL
) {
919 // QuestionId is a statement without Storage.
923 BufferStorage
= GetFirstStorageOfFormSet (ConfigAccess
->ThunkContext
->FormSet
);
925 BufferStorage
= Statement
->Storage
;
929 // If NvMapOverride is not NULL, this Form must have at least one Buffer Type Variable Storage.
931 ASSERT (BufferStorage
!= NULL
);
933 BrowserDataSize
= BufferStorage
->Size
;
935 CheckFlag
= HiiSetBrowserData (&BufferStorage
->Guid
, BufferStorage
->Name
, BrowserDataSize
, ConfigAccess
->ThunkContext
->NvMapOverride
, NULL
);
942 Free up resource allocated for a EFI_IFR_DATA_ARRAY by CreateIfrDataArray ().
944 @param Array The EFI_IFR_DATA_ARRAY allocated.
945 @param NvMapAllocated If the NvRamMap is allocated for EFI_IFR_DATA_ARRAY.
949 DestroyIfrDataArray (
950 IN EFI_IFR_DATA_ARRAY
*Array
,
951 IN BOOLEAN NvMapAllocated
955 if (NvMapAllocated
) {
956 FreePool (Array
->NvRamMap
);
964 Get the ONE_OF_OPTION_MAP_ENTRY for a QuestionId that invokes the
965 EFI_FORM_CALLBACK_PROTOCOL.Callback. The information is needed as
966 the callback mechanism for EFI_IFR_ONE_OF_OPTION is changed from
967 EFI_IFR_ONE_OF_OPTION in Framework IFR. Check EFI_IFR_GUID_OPTIONKEY
968 for detailed information.
970 @param ThunkContext The Thunk Context.
971 @param QuestionId The Question Id.
972 @param Type The Question Type.
973 @param Value The One Of Option's value.
975 @return The ONE_OF_OPTION_MAP_ENTRY found.
976 @retval NULL If no entry is found.
978 ONE_OF_OPTION_MAP_ENTRY
*
979 GetOneOfOptionMapEntry (
980 IN HII_THUNK_CONTEXT
*ThunkContext
,
981 IN EFI_QUESTION_ID QuestionId
,
983 IN EFI_IFR_TYPE_VALUE
*Value
988 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
989 ONE_OF_OPTION_MAP
*OneOfOptionMap
;
990 FORM_BROWSER_FORMSET
*FormSet
;
992 FormSet
= ThunkContext
->FormSet
;
994 Link
= GetFirstNode (&FormSet
->OneOfOptionMapListHead
);
996 while (!IsNull (&FormSet
->OneOfOptionMapListHead
, Link
)) {
997 OneOfOptionMap
= ONE_OF_OPTION_MAP_FROM_LINK(Link
);
998 if (OneOfOptionMap
->QuestionId
== QuestionId
) {
999 ASSERT (OneOfOptionMap
->ValueType
== Type
);
1001 Link2
= GetFirstNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
);
1003 while (!IsNull (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
)) {
1004 OneOfOptionMapEntry
= ONE_OF_OPTION_MAP_ENTRY_FROM_LINK (Link2
);
1006 if (CompareMem (Value
, &OneOfOptionMapEntry
->Value
, sizeof (EFI_IFR_TYPE_VALUE
)) == 0) {
1007 return OneOfOptionMapEntry
;
1010 Link2
= GetNextNode (&OneOfOptionMap
->OneOfOptionMapEntryListHead
, Link2
);
1014 Link
= GetNextNode (&FormSet
->OneOfOptionMapListHead
, Link
);
1022 Functions which are registered to receive notification of
1023 database events have this prototype. The actual event is encoded
1024 in NotifyType. The following table describes how PackageType,
1025 PackageGuid, Handle, and Package are used for each of the
1028 If any Pakcage List in database is updated, mHiiPackageListUpdated
1029 will be set. If mHiiPackageListUpdated is set, Framework ThunkCallback()
1030 will force the UEFI Setup Browser to save the uncommitted data. This
1031 is needed as Framework's Callback function may dynamically update
1032 opcode in a Package List. UEFI Setup Browser will quit itself and reparse
1033 the Package List's IFR and display it. UEFI Config Access's implementation
1034 is required to save the modified (SetBrowserData or directly save the data
1035 to NV storage). But Framework HII Modules is not aware of this rule. Therefore,
1036 we will enforce the rule in ThunkCallback (). The side effect of force saving
1037 of NV data is the NV flag in browser may not flag a update as data has already
1038 been saved to NV storage.
1040 @param PackageType Package type of the notification.
1042 @param PackageGuid If PackageType is
1043 EFI_HII_PACKAGE_TYPE_GUID, then this is
1044 the pointer to the GUID from the Guid
1045 field of EFI_HII_PACKAGE_GUID_HEADER.
1046 Otherwise, it must be NULL.
1048 @param Package Points to the package referred to by the
1049 notification Handle The handle of the package
1050 list which contains the specified package.
1052 @param Handle The HII handle.
1054 @param NotifyType The type of change concerning the
1056 EFI_HII_DATABASE_NOTIFY_TYPE.
1062 IN UINT8 PackageType
,
1063 IN CONST EFI_GUID
*PackageGuid
,
1064 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
1065 IN EFI_HII_HANDLE Handle
,
1066 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
1069 mHiiPackageListUpdated
= TRUE
;
1075 Wrap the EFI_HII_CONFIG_ACCESS_PROTOCOL.CallBack to EFI_FORM_CALLBACK_PROTOCOL.Callback. Therefor,
1076 the framework HII module willl do no porting and work with a UEFI HII SetupBrowser.
1078 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1079 @param Action Specifies the type of action taken by the browser. See EFI_BROWSER_ACTION_x.
1080 @param QuestionId A unique value which is sent to the original exporting driver so that it can identify the
1081 type of data to expect. The format of the data tends to vary based on the opcode that
1082 generated the callback.
1083 @param Type The type of value for the question. See EFI_IFR_TYPE_x in
1084 EFI_IFR_ONE_OF_OPTION.
1085 @param Value A pointer to the data being sent to the original exporting driver. The type is specified
1086 by Type. Type EFI_IFR_TYPE_VALUE is defined in
1087 EFI_IFR_ONE_OF_OPTION.
1088 @param ActionRequest On return, points to the action requested by the callback function. Type
1089 EFI_BROWSER_ACTION_REQUEST is specified in SendForm() in the Form
1092 @retval EFI_UNSUPPORTED If the Framework HII module does not register Callback although it specify the opcode under
1093 focuse to be INTERRACTIVE.
1094 @retval EFI_SUCCESS The callback complete successfully.
1095 @retval !EFI_SUCCESS The error code returned by EFI_FORM_CALLBACK_PROTOCOL.Callback.
1101 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1102 IN EFI_BROWSER_ACTION Action
,
1103 IN EFI_QUESTION_ID QuestionId
,
1105 IN EFI_IFR_TYPE_VALUE
*Value
,
1106 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1110 CONFIG_ACCESS_PRIVATE
*ConfigAccess
;
1111 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
1112 EFI_HII_CALLBACK_PACKET
*Packet
;
1113 EFI_IFR_DATA_ARRAY
*Data
;
1114 EFI_IFR_DATA_ENTRY
*DataEntry
;
1116 ONE_OF_OPTION_MAP_ENTRY
*OneOfOptionMapEntry
;
1117 EFI_HANDLE NotifyHandle
;
1119 BOOLEAN NvMapAllocated
;
1121 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
1122 ASSERT (This
!= NULL
);
1123 ASSERT (Value
!= NULL
);
1124 ASSERT (ActionRequest
!= NULL
);
1126 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1128 ConfigAccess
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (This
);
1130 FormCallbackProtocol
= ConfigAccess
->FormCallbackProtocol
;
1131 if (FormCallbackProtocol
== NULL
) {
1133 return EFI_UNSUPPORTED
;
1137 // Check if the QuestionId match a OneOfOption.
1139 OneOfOptionMapEntry
= GetOneOfOptionMapEntry (ConfigAccess
->ThunkContext
, QuestionId
, Type
, Value
);
1141 if (OneOfOptionMapEntry
== NULL
) {
1143 // This is not a One-Of-Option opcode. QuestionId is the KeyValue
1145 KeyValue
= QuestionId
;
1148 // Otherwise, use the original Key specified in One Of Option in the Framework VFR syntax.
1150 KeyValue
= OneOfOptionMapEntry
->FwKey
;
1154 // Build the EFI_IFR_DATA_ARRAY
1156 Data
= CreateIfrDataArray (ConfigAccess
, QuestionId
, Type
, Value
, &NvMapAllocated
);
1158 Status
= mHiiDatabase
->RegisterPackageNotify (
1160 EFI_HII_PACKAGE_FORMS
,
1163 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
1167 //Call the Framework Callback function.
1170 Status
= FormCallbackProtocol
->Callback (
1171 FormCallbackProtocol
,
1176 SyncBrowserDataForNvMapOverride (ConfigAccess
, QuestionId
);
1179 // Callback require browser to perform action
1181 if (EFI_ERROR (Status
)) {
1182 if (Packet
!= NULL
) {
1184 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, Packet
->String
, NULL
);
1185 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1188 // Error Code in Status is discarded.
1191 if (Packet
!= NULL
) {
1192 if (Packet
->DataArray
.EntryCount
== 1 && Packet
->DataArray
.NvRamMap
== NULL
) {
1193 DataEntry
= (EFI_IFR_DATA_ENTRY
*) ((UINT8
*) Packet
+ sizeof (EFI_IFR_DATA_ARRAY
));
1194 if ((DataEntry
->Flags
& EXIT_REQUIRED
) == EXIT_REQUIRED
) {
1195 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1198 if ((DataEntry
->Flags
& SAVE_REQUIRED
) == SAVE_REQUIRED
) {
1199 Status
= ConfigAccess
->ConfigAccessProtocol
.RouteConfig (
1200 &ConfigAccess
->ConfigAccessProtocol
,
1211 // Unregister notify for Form package update
1213 Status
= mHiiDatabase
->UnregisterPackageNotify (
1218 // UEFI SetupBrowser behaves differently with Framework SetupBrowser when call back function
1219 // update any forms in HII database. UEFI SetupBrowser will re-parse the displaying form package and load
1220 // the values from variable storages. Framework SetupBrowser will only re-parse the displaying form packages.
1221 // To make sure customer's previous changes is saved and the changing question behaves as expected, we
1222 // issue a EFI_BROWSER_ACTION_REQUEST_SUBMIT to ask UEFI SetupBrowser to save the changes proceed to re-parse
1223 // the form and load all the variable storages.
1225 if (*ActionRequest
== EFI_BROWSER_ACTION_REQUEST_NONE
&& mHiiPackageListUpdated
) {
1226 mHiiPackageListUpdated
= FALSE
;
1227 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1229 if (ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
||
1230 ConfigAccess
->ThunkContext
->FormSet
->SubClass
== EFI_SINGLE_USE_SUBCLASS
) {
1231 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1238 DestroyIfrDataArray (Data
, NvMapAllocated
);
1244 // All other action return unsupported.
1246 return EFI_UNSUPPORTED
;