2 This file contains the form processing code to the HII database.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 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 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 EFI_IFR_END_FORM_SET_OP
,
51 sizeof (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
;
294 ASSERT(HiiPackageList
!= NULL
);
296 if ((BufferLen
== NULL
) || (Buffer
== NULL
)) {
297 return EFI_INVALID_PARAMETER
;
300 ZeroMem (&PackageHeader
, sizeof (PackageHeader
));
303 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
304 CopyMem (&PackageListLength
, &HiiPackageList
->PackageLength
, sizeof (UINT32
));
305 while (Offset
< PackageListLength
) {
306 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
307 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
308 if (Index
== PackageIndex
) {
311 Offset
+= PackageHeader
.Length
;
314 if (Offset
>= PackageListLength
) {
316 // no package found in this Package List
318 return EFI_NOT_FOUND
;
321 *BufferLen
= PackageHeader
.Length
;
327 Check if Label exist in the IFR form package and return the FormSet GUID
330 @param Package The Package Header.
331 @param Label The Label ID.
332 @param FormsetGuid Returns the FormSet GUID.
333 @param FormId Returns the Form ID.
335 @retval EFI_SUCCESS The FORM ID is found.
336 @retval EFI_NOT_FOUND The FORM ID is not found.
340 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
341 IN EFI_FORM_LABEL Label
,
342 OUT EFI_GUID
*FormsetGuid
,
343 OUT EFI_FORM_ID
*FormId
347 EFI_IFR_OP_HEADER
*IfrOpHdr
;
348 EFI_GUID InternalFormSetGuid
;
349 EFI_FORM_ID InternalFormId
;
352 EFI_IFR_GUID_LABEL
*LabelOpcode
;
354 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
355 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
358 ZeroMem (&InternalFormSetGuid
, sizeof (EFI_GUID
));
362 while (Offset
< Package
->Length
) {
363 switch (IfrOpHdr
->OpCode
) {
364 case EFI_IFR_FORM_SET_OP
:
365 CopyMem (&InternalFormSetGuid
, &((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, sizeof (EFI_GUID
));
369 case EFI_IFR_FORM_OP
:
370 CopyMem (&InternalFormId
, &((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, sizeof (EFI_FORM_ID
));
374 case EFI_IFR_GUID_OP
:
375 LabelOpcode
= (EFI_IFR_GUID_LABEL
*) IfrOpHdr
;
377 // If it is an Label opcode.
379 if ((LabelOpcode
->ExtendOpCode
== EFI_IFR_EXTEND_OP_LABEL
) && (CompareMem (&LabelOpcode
->Guid
, &mTianoHiiIfrGuid
, sizeof (EFI_GUID
)) == 0)) {
380 if (CompareMem (&Label
, &LabelOpcode
->Number
, sizeof (UINT16
)) == 0) {
381 ASSERT (GetForm
&& GetFormSet
);
382 CopyGuid (FormsetGuid
, &InternalFormSetGuid
);
383 *FormId
= InternalFormId
;
393 // Go to the next Op-Code
395 Offset
+= IfrOpHdr
->Length
;
396 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
399 return EFI_NOT_FOUND
;
403 Find the first EFI_FORM_LABEL in FormSets for a given EFI_HII_HANLDE defined.
405 EFI_FORM_LABEL is a specific to Tiano implementation. The current implementation
406 does not restrict labels with same label value to be duplicated in either FormSet
407 scope or Form scope. This function will only locate the FIRST EFI_FORM_LABEL
408 with value as the same as the input Label in the Formset registered with UefiHiiHandle. The FormSet GUID
409 and Form ID is returned if such Label is found.
411 @param Handle Uefi Hii Handle to be searched.
412 @param Label The first Label ID to be found.
413 @param FormsetGuid The matched FormSet GUID.
414 @param FormId The matched Form ID.
416 @retval EFI_INVALID_PARAMETER If UefiHiiHandle is not a valid handle.
417 @retval EFI_NOT_FOUND The package list identified by UefiHiiHandle deos not contain FormSet or
418 Form ID with value Label found in all Form Sets in the pacakge list.
419 @retval EFI_SUCCESS The first found Form ID is returned in FormId.
423 IN EFI_HII_HANDLE Handle
,
424 IN EFI_FORM_LABEL Label
,
425 OUT EFI_GUID
*FormsetGuid
,
426 OUT EFI_FORM_ID
*FormId
430 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
433 EFI_HII_PACKAGE_HEADER PackageHeader
;
434 EFI_HII_PACKAGE_HEADER
*Package
;
435 UINT32 PackageLength
;
438 HiiPackageList
= NULL
;
439 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
440 if (Status
== EFI_BUFFER_TOO_SMALL
) {
441 HiiPackageList
= AllocatePool (BufferSize
);
442 ASSERT (HiiPackageList
!= NULL
);
444 Status
= mHiiDatabase
->ExportPackageLists (mHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
445 if (EFI_ERROR (Status
)) {
450 for (Index
= 0; ; Index
++) {
451 Status
= GetPackageData (HiiPackageList
, Index
, &PackageLength
, &Package
);
452 if (!EFI_ERROR (Status
)) {
453 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
454 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
455 Status
= LocateLabel (Package
, Label
, FormsetGuid
, FormId
);
456 if (!EFI_ERROR(Status
)) {
467 FreePool (HiiPackageList
);
473 This function allows the caller to update a form that has
474 previously been registered with the EFI HII database.
477 @param This EDES_TODO: Add parameter description
478 @param Handle Hii Handle associated with the Formset to modify
479 @param Label Update information starting immediately after this label in the IFR
480 @param AddData If TRUE, add data. If FALSE, remove data
481 @param Data If adding data, this is the pointer to the data to add
483 @retval EFI_SUCCESS Update success.
484 @retval Other Update fail.
490 IN EFI_HII_PROTOCOL
*This
,
491 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
492 IN EFI_FORM_LABEL Label
,
494 IN EFI_HII_UPDATE_DATA
*Data
498 HII_THUNK_PRIVATE_DATA
*Private
;
499 HII_THUNK_CONTEXT
*ThunkContext
;
500 EFI_HII_HANDLE UefiHiiHandle
;
501 EFI_GUID FormsetGuid
;
504 VOID
*StartOpCodeHandle
;
505 VOID
*EndOpCodeHandle
;
506 EFI_IFR_GUID_LABEL
*StartLabel
;
507 EFI_IFR_GUID_LABEL
*EndLabel
;
509 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
511 mInFrameworkUpdatePakcage
= TRUE
;
512 Status
= EFI_SUCCESS
;
514 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
516 ThunkContext
= FwHiiHandleToThunkContext (Private
, Handle
);
518 if (ThunkContext
== NULL
) {
519 Status
= EFI_NOT_FOUND
;
523 if (Data
->FormSetUpdate
) {
524 Status
= UpdateFormCallBack ((EFI_HANDLE
) (UINTN
) Data
->FormCallbackHandle
, ThunkContext
);
525 if (EFI_ERROR (Status
)) {
530 if (ThunkContext
->IfrPackageCount
== 0) {
532 Status
= EFI_INVALID_PARAMETER
;
535 UefiHiiHandle
= ThunkContext
->UefiHiiHandle
;
538 Status
= LocateFormId (UefiHiiHandle
, Label
, &FormsetGuid
, &FormId
);
539 if (EFI_ERROR (Status
)) {
541 // Can't find the label.
547 // Init OpCode Handle
549 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
550 ASSERT (StartOpCodeHandle
!= NULL
);
552 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
553 ASSERT (EndOpCodeHandle
!= NULL
);
556 // Create Hii Extend Label OpCode as the start opcode
558 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
559 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
560 StartLabel
->Number
= Label
;
563 // Create Hii Extend Label OpCode as the end opcode
565 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
566 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
567 EndLabel
->Number
= 0xffff;
570 if (Data
->DataCount
!= 0) {
572 ThunkContext
= UefiHiiHandleToThunkContext (Private
, UefiHiiHandle
);
573 ASSERT (ThunkContext
!= NULL
);
574 Status
= FwUpdateDataToUefiUpdateData (ThunkContext
, Data
, StartOpCodeHandle
);
575 ASSERT_EFI_ERROR (Status
);
577 Status
= HiiUpdateForm (UefiHiiHandle
, &FormsetGuid
, FormId
, StartOpCodeHandle
, NULL
);
578 ASSERT_EFI_ERROR (Status
);
582 // Delete Opcode starting from Labe in FormId found
584 Status
= HiiUpdateForm (UefiHiiHandle
, &FormsetGuid
, FormId
, StartOpCodeHandle
, EndOpCodeHandle
);
585 ASSERT_EFI_ERROR (Status
);
588 HiiFreeOpCodeHandle (StartOpCodeHandle
);
589 HiiFreeOpCodeHandle (EndOpCodeHandle
);
593 mInFrameworkUpdatePakcage
= FALSE
;
595 gBS
->RestoreTPL (OldTpl
);