2 This file contains the form processing code to the HII database.
4 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "HiiDatabase.h"
17 #include "UefiIfrDefault.h"
20 // This structure is only intended to be used in this file.
24 EFI_HII_PACK_HEADER PackageHeader
;
25 FRAMEWORK_EFI_IFR_FORM_SET FormSet
;
26 FRAMEWORK_EFI_IFR_END_FORM_SET EndFormSet
;
27 } FW_HII_FORMSET_TEMPLATE
;
30 FW_HII_FORMSET_TEMPLATE FormSetTemplate
= {
32 sizeof (FW_HII_FORMSET_TEMPLATE
),
37 FRAMEWORK_EFI_IFR_FORM_SET_OP
,
38 sizeof (FRAMEWORK_EFI_IFR_FORM_SET
)
40 {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}}, //Guid
50 FRAMEWORK_EFI_IFR_END_FORM_SET_OP
,
51 sizeof (FRAMEWORK_EFI_IFR_END_FORM_SET
)
57 EFI_GUID mTianoHiiIfrGuid
= EFI_IFR_TIANO_GUID
;
61 This thunk module only handles UEFI HII packages. The caller of this function
62 won¡¯t be able to parse the content. Therefore, it is not supported.
64 This function will ASSERT and return EFI_UNSUPPORTED.
68 @param BufferSize N.A.
71 @retval EFI_UNSUPPORTED
77 IN EFI_HII_PROTOCOL
*This
,
78 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
79 IN OUT UINTN
*BufferSize
,
84 return EFI_UNSUPPORTED
;
89 This function allows a program to extract a form or form package that has
90 previously been registered with the EFI HII database.
92 In this thunk module, this function will create a IFR Package with only
93 one Formset. Effectively, only the GUID of the Formset is updated and return
94 in this IFR package to caller. This is enable the Framework modules which call
95 a API named GetStringFromToken. GetStringFromToken retieves a String based on
96 a String Token from a Package List known only by the Formset GUID.
100 @param This A pointer to the EFI_HII_PROTOCOL instance.
101 @param Handle Handle on which the form resides. Type FRAMEWORK_EFI_HII_HANDLE is defined in
102 EFI_HII_PROTOCOL.NewPack() in the Packages section.
103 @param FormId Ignored by this implementation.
104 @param BufferLengthTemp On input, the size of input buffer. On output, it
105 is the size of FW_HII_FORMSET_TEMPLATE.
106 @param Buffer The buffer designed to receive the form(s).
108 @retval EFI_SUCCESS Buffer filled with the requested forms. BufferLength
110 @retval EFI_INVALID_PARAMETER The handle is unknown.
111 @retval EFI_NOT_FOUND A form on the requested handle cannot be found with the
113 @retval EFI_BUFFER_TOO_SMALL The buffer provided was not large enough to allow the form to be stored.
119 IN EFI_HII_PROTOCOL
*This
,
120 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
121 IN EFI_FORM_ID FormId
,
122 IN OUT UINTN
*BufferLengthTemp
,
126 HII_THUNK_PRIVATE_DATA
*Private
;
127 HII_THUNK_CONTEXT
*ThunkContext
;
128 FW_HII_FORMSET_TEMPLATE
*OutputFormSet
;
130 if (*BufferLengthTemp
< sizeof(FW_HII_FORMSET_TEMPLATE
)) {
131 *BufferLengthTemp
= sizeof(FW_HII_FORMSET_TEMPLATE
);
132 return EFI_BUFFER_TOO_SMALL
;
135 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
137 ThunkContext
= FwHiiHandleToThunkContext (Private
, Handle
);
139 if (ThunkContext
== NULL
) {
140 return EFI_NOT_FOUND
;
143 OutputFormSet
= (FW_HII_FORMSET_TEMPLATE
*) Buffer
;
145 CopyMem (OutputFormSet
, &FormSetTemplate
, sizeof (FW_HII_FORMSET_TEMPLATE
));
146 CopyMem (&OutputFormSet
->FormSet
.Guid
, &ThunkContext
->TagGuid
, sizeof (EFI_GUID
));
148 if (ThunkContext
->FormSet
!= NULL
) {
149 OutputFormSet
->FormSet
.Class
= ThunkContext
->FormSet
->Class
;
150 OutputFormSet
->FormSet
.SubClass
= ThunkContext
->FormSet
->SubClass
;
151 OutputFormSet
->FormSet
.Help
= ThunkContext
->FormSet
->Help
;
152 OutputFormSet
->FormSet
.FormSetTitle
= ThunkContext
->FormSet
->FormSetTitle
;
161 This function allows a program to extract the NV Image
162 that represents the default storage image
165 @param This A pointer to the EFI_HII_PROTOCOL instance.
166 @param Handle The HII handle from which will have default data retrieved.
167 UINTN - Mask used to retrieve the default image.
168 @param DefaultMask EDES_TODO: Add parameter description
169 @param VariablePackList Callee allocated, tightly-packed, link list data
170 structure that contain all default varaible packs
171 from the Hii Database.
173 @retval EFI_NOT_FOUND If Hii database does not contain any default images.
174 @retval EFI_INVALID_PARAMETER Invalid input parameter.
175 @retval EFI_SUCCESS Operation successful.
181 IN EFI_HII_PROTOCOL
*This
,
182 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
183 IN UINTN DefaultMask
,
184 OUT EFI_HII_VARIABLE_PACK_LIST
**VariablePackList
187 LIST_ENTRY
*UefiDefaults
;
189 HII_THUNK_PRIVATE_DATA
*Private
;
190 HII_THUNK_CONTEXT
*ThunkContext
;
192 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
194 ThunkContext
= FwHiiHandleToThunkContext (Private
, Handle
);
195 if (ThunkContext
== NULL
) {
197 return EFI_INVALID_PARAMETER
;
201 Status
= UefiIfrGetBufferTypeDefaults (ThunkContext
, &UefiDefaults
);
202 if (EFI_ERROR (Status
)) {
206 Status
= UefiDefaultsToFwDefaults (UefiDefaults
, DefaultMask
, ThunkContext
->FormSet
->DefaultVarStoreId
, VariablePackList
);
209 FreeDefaultList (UefiDefaults
);
215 This function update the FormCallbackProtocol cached in Config Access
216 private context data.
218 @param CallbackHandle The EFI Handle on which the Framework FormCallbackProtocol is
220 @param ThunkContext The Thunk Context.
222 @retval EFI_SUCCESS The update is successful.
223 @retval EFI_INVALID_PARAMETER If no Framework FormCallbackProtocol is located on CallbackHandle.
228 IN EFI_HANDLE CallbackHandle
,
229 IN CONST HII_THUNK_CONTEXT
*ThunkContext
233 EFI_FORM_CALLBACK_PROTOCOL
*FormCallbackProtocol
;
234 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccessProtocol
;
235 EFI_HANDLE UefiDriverHandle
;
236 CONFIG_ACCESS_PRIVATE
*ConfigAccessPrivate
;
238 Status
= gBS
->HandleProtocol (
240 &gEfiFormCallbackProtocolGuid
,
241 (VOID
**) &FormCallbackProtocol
243 if (EFI_ERROR (Status
)) {
244 return EFI_INVALID_PARAMETER
;
247 Status
= mHiiDatabase
->GetPackageListHandle (
249 ThunkContext
->UefiHiiHandle
,
252 ASSERT_EFI_ERROR (Status
);
253 Status
= gBS
->HandleProtocol (
255 &gEfiHiiConfigAccessProtocolGuid
,
256 (VOID
**) &ConfigAccessProtocol
258 ASSERT_EFI_ERROR (Status
);
260 ConfigAccessPrivate
= CONFIG_ACCESS_PRIVATE_FROM_PROTOCOL (ConfigAccessProtocol
);
262 ConfigAccessPrivate
->FormCallbackProtocol
= FormCallbackProtocol
;
269 Get the package data from the Package List.
271 @param HiiPackageList Package List.
272 @param PackageIndex The index of the Package in the Package List.
273 @param BufferLen The Length of the Pacage data.
274 @param Buffer On output, the Package data.
276 @return EFI_NOT_FOUND No Package is found for PackageIndex.
277 @return EFI_SUCCESS The package data is returned.
282 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
283 IN UINT32 PackageIndex
,
284 OUT UINT32
*BufferLen
,
285 OUT EFI_HII_PACKAGE_HEADER
**Buffer
289 EFI_HII_PACKAGE_HEADER
*Package
;
291 UINT32 PackageListLength
;
292 EFI_HII_PACKAGE_HEADER PackageHeader
= {0, 0};
294 ASSERT(HiiPackageList
!= NULL
);
296 if ((BufferLen
== NULL
) || (Buffer
== NULL
)) {
297 return EFI_INVALID_PARAMETER
;
302 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
303 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
304 while (Offset
< PackageListLength
) {
305 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
306 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
307 if (Index
== PackageIndex
) {
310 Offset
+= PackageHeader
.Length
;
313 if (Offset
>= PackageListLength
) {
315 // no package found in this Package List
317 return EFI_NOT_FOUND
;
320 *BufferLen
= PackageHeader
.Length
;
326 Check if Label exist in the IFR form package and return the FormSet GUID
329 @param Package The Package Header.
330 @param Label The Label ID.
331 @param FormsetGuid Returns the FormSet GUID.
332 @param FormId Returns the Form ID.
334 @retval EFI_SUCCESS The FORM ID is found.
335 @retval EFI_NOT_FOUND The FORM ID is not found.
339 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
340 IN EFI_FORM_LABEL Label
,
341 OUT EFI_GUID
*FormsetGuid
,
342 OUT EFI_FORM_ID
*FormId
346 EFI_IFR_OP_HEADER
*IfrOpHdr
;
347 EFI_GUID InternalFormSetGuid
;
348 EFI_FORM_ID InternalFormId
;
351 EFI_IFR_GUID_LABEL
*LabelOpcode
;
353 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
354 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
357 ZeroMem (&InternalFormSetGuid
, sizeof (EFI_GUID
));
361 while (Offset
< Package
->Length
) {
362 switch (IfrOpHdr
->OpCode
) {
363 case EFI_IFR_FORM_SET_OP
:
364 CopyMem (&InternalFormSetGuid
, &((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, sizeof (EFI_GUID
));
368 case EFI_IFR_FORM_OP
:
369 CopyMem (&InternalFormId
, &((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, sizeof (EFI_FORM_ID
));
373 case EFI_IFR_GUID_OP
:
374 LabelOpcode
= (EFI_IFR_GUID_LABEL
*) IfrOpHdr
;
376 // If it is an Label opcode.
378 if ((LabelOpcode
->ExtendOpCode
== EFI_IFR_EXTEND_OP_LABEL
) && (CompareMem (&LabelOpcode
->Guid
, &mTianoHiiIfrGuid
, sizeof (EFI_GUID
)) == 0)) {
379 if (CompareMem (&Label
, &LabelOpcode
->Number
, sizeof (UINT16
)) == 0) {
380 ASSERT (GetForm
&& GetFormSet
);
381 CopyGuid (FormsetGuid
, &InternalFormSetGuid
);
382 *FormId
= InternalFormId
;
392 // Go to the next Op-Code
394 Offset
+= IfrOpHdr
->Length
;
395 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
398 return EFI_NOT_FOUND
;
402 Find the first EFI_FORM_LABEL in FormSets for a given EFI_HII_HANLDE defined.
404 EFI_FORM_LABEL is a specific to Tiano implementation. The current implementation
405 does not restrict labels with same label value to be duplicated in either FormSet
406 scope or Form scope. This function will only locate the FIRST EFI_FORM_LABEL
407 with value as the same as the input Label in the Formset registered with UefiHiiHandle. The FormSet GUID
408 and Form ID is returned if such Label is found.
411 @retval EFI_INVALID_PARAMETER If UefiHiiHandle is not a valid handle.
412 @retval EFI_NOT_FOUND The package list identified by UefiHiiHandle deos not contain FormSet or
413 There is no Form ID with value Label found in all Form Sets in the pacakge
416 @retval EFI_SUCCESS The first found Form ID is returned in FormId.
420 IN EFI_HII_HANDLE Handle
,
421 IN EFI_FORM_LABEL Label
,
422 OUT EFI_GUID
*FormsetGuid
,
423 OUT EFI_FORM_ID
*FormId
427 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
430 EFI_HII_PACKAGE_HEADER PackageHeader
;
431 EFI_HII_PACKAGE_HEADER
*Package
;
432 UINT32 PackageLength
;
435 HiiPackageList
= NULL
;
436 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
437 if (Status
== EFI_BUFFER_TOO_SMALL
) {
438 HiiPackageList
= AllocatePool (BufferSize
);
439 ASSERT (HiiPackageList
!= NULL
);
441 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
442 if (EFI_ERROR (Status
)) {
447 for (Index
= 0; ; Index
++) {
448 Status
= GetPackageData (HiiPackageList
, Index
, &PackageLength
, &Package
);
449 if (!EFI_ERROR (Status
)) {
450 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
451 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
452 Status
= LocateLabel (Package
, Label
, FormsetGuid
, FormId
);
453 if (!EFI_ERROR(Status
)) {
464 FreePool (HiiPackageList
);
470 This function allows the caller to update a form that has
471 previously been registered with the EFI HII database.
474 @param This EDES_TODO: Add parameter description
475 @param Handle Hii Handle associated with the Formset to modify
476 @param Label Update information starting immediately after this label in the IFR
477 @param AddData If TRUE, add data. If FALSE, remove data
478 @param Data If adding data, this is the pointer to the data to add
480 @retval EFI_SUCCESS Update success.
481 @retval Other Update fail.
487 IN EFI_HII_PROTOCOL
*This
,
488 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
489 IN EFI_FORM_LABEL Label
,
491 IN FRAMEWORK_EFI_HII_UPDATE_DATA
*Data
495 HII_THUNK_PRIVATE_DATA
*Private
;
496 HII_THUNK_CONTEXT
*ThunkContext
;
497 EFI_HII_UPDATE_DATA
*UefiHiiUpdateData
;
498 EFI_HII_HANDLE UefiHiiHandle
;
499 EFI_GUID FormsetGuid
;
503 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
505 mInFrameworkUpdatePakcage
= TRUE
;
506 Status
= EFI_SUCCESS
;
507 UefiHiiUpdateData
= NULL
;
510 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
512 ThunkContext
= FwHiiHandleToThunkContext (Private
, Handle
);
514 if (ThunkContext
== NULL
) {
515 Status
= EFI_NOT_FOUND
;
519 if (Data
->FormSetUpdate
) {
520 Status
= UpdateFormCallBack ((EFI_HANDLE
) (UINTN
) Data
->FormCallbackHandle
, ThunkContext
);
521 if (EFI_ERROR (Status
)) {
526 if (ThunkContext
->IfrPackageCount
== 0) {
528 Status
= EFI_INVALID_PARAMETER
;
531 UefiHiiHandle
= ThunkContext
->UefiHiiHandle
;
534 Status
= LocateFormId (UefiHiiHandle
, Label
, &FormsetGuid
, &FormId
);
535 if (EFI_ERROR (Status
)) {
537 // Can't find the label.
543 if (Data
->DataCount
!= 0) {
545 ThunkContext
= UefiHiiHandleToThunkContext (Private
, UefiHiiHandle
);
546 Status
= FwUpdateDataToUefiUpdateData (ThunkContext
, Data
, &UefiHiiUpdateData
);
547 ASSERT_EFI_ERROR (Status
);
549 Status
= IfrLibUpdateForm (UefiHiiHandle
, &FormsetGuid
, FormId
, Label
, TRUE
, UefiHiiUpdateData
);
550 ASSERT_EFI_ERROR (Status
);
555 // Delete Opcode starting from Labe in FormId found
557 UefiHiiUpdateData
= AllocateZeroPool (sizeof (*UefiHiiUpdateData
));
559 Status
= IfrLibUpdateForm (UefiHiiHandle
, &FormsetGuid
, FormId
, Label
, FALSE
, UefiHiiUpdateData
);
560 ASSERT_EFI_ERROR (Status
);
564 if (UefiHiiUpdateData
!= NULL
) {
565 if (UefiHiiUpdateData
->Data
!= NULL
) {
566 FreePool (UefiHiiUpdateData
->Data
);
568 FreePool (UefiHiiUpdateData
);
571 mInFrameworkUpdatePakcage
= FALSE
;
573 gBS
->RestoreTPL (OldTpl
);