2 Implement protocol interface related to package registrations.
4 Copyright (c) 2006 - 2008, Intel Corporation
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 "HiiHandle.h"
20 BOOLEAN mInFrameworkHiiNewPack
= FALSE
;
21 BOOLEAN mInFrameworkHiiRemovePack
= FALSE
;
22 BOOLEAN mInFrameworkUpdatePakcage
= FALSE
;
23 UINT64 mGuidCount
= 0;
27 Get the number of package IFR and STRING packages in the package list passed in.
29 @param Packages Package List.
30 @param IfrPackageCount Number of IFR Packages.
31 @param StringPackageCount Number of String Packages.
33 @retval EFI_INVALID_PARAMETER If the Package List has package with type of
34 EFI_HII_PACKAGE_KEYBOARD_LAYOUT, EFI_HII_PACKAGE_FONTS, EFI_HII_PACKAGE_IMAGES.
35 @reval EFI_SUCCESS Successfully get the number of IFR and STRING package.
41 IN CONST EFI_HII_PACKAGES
*Packages
,
42 OUT UINTN
*IfrPackageCount
,
43 OUT UINTN
*StringPackageCount
,
44 OUT UINTN
*FontPackageCount
48 TIANO_AUTOGEN_PACKAGES_HEADER
**TianoAutogenPackageHdrArray
;
50 ASSERT (Packages
!= NULL
);
51 ASSERT (IfrPackageCount
!= NULL
);
52 ASSERT (StringPackageCount
!= NULL
);
53 ASSERT (FontPackageCount
!= NULL
);
56 *StringPackageCount
= 0;
57 *FontPackageCount
= 0;
59 TianoAutogenPackageHdrArray
= (TIANO_AUTOGEN_PACKAGES_HEADER
**) (((UINT8
*) &Packages
->GuidId
) + sizeof (Packages
->GuidId
));
61 for (Index
= 0; Index
< Packages
->NumberOfPackages
; Index
++) {
63 // The current UEFI HII build tool generate a binary in the format defined by
64 // TIANO_AUTOGEN_PACKAGES_HEADER. We assume that all packages generated in
65 // this binary is with same package type. So the returned IfrPackageCount and StringPackageCount
66 // may not be the exact number of valid package number in the binary generated
69 switch (TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Type
) {
71 *IfrPackageCount
+= 1;
74 *StringPackageCount
+= 1;
78 *FontPackageCount
+= 1;
82 // The following fonts are invalid for a module that using Framework to UEFI thunk layer.
86 return EFI_INVALID_PARAMETER
;
95 Insert the String Package into the Package Lists which has the TAG GUID matching
96 the PackageListGuid of the String Package.
98 The Package List must have only IFR Package and no String Package.
101 @param Private The HII THUNK driver context data.
102 @param StringPackageThunkContext The HII THUNK context data.
103 @param StringPackageListHeader The String Package List Header.
107 UpdatePackListWithOnlyIfrPack (
108 IN HII_THUNK_PRIVATE_DATA
*Private
,
109 IN HII_THUNK_CONTEXT
*StringPackageThunkContext
,
110 IN CONST EFI_HII_PACKAGE_LIST_HEADER
*StringPackageListHeader
115 HII_THUNK_CONTEXT
*ThunkContext
;
117 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
118 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
120 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
122 if (StringPackageThunkContext
!= ThunkContext
) {
124 // Skip the String Package Thunk Entry itself.
127 if (CompareGuid (&StringPackageListHeader
->PackageListGuid
, &ThunkContext
->TagGuid
)) {
129 ASSERT (ThunkContext
->StringPackageCount
== 0 && ThunkContext
->IfrPackageCount
== 1);
131 ThunkContext
->StringPackageCount
= GetPackageCountByType (StringPackageListHeader
, EFI_HII_PACKAGE_STRINGS
);
133 Status
= mHiiDatabase
->UpdatePackageList (
135 ThunkContext
->UefiHiiHandle
,
136 StringPackageListHeader
138 ASSERT_EFI_ERROR (Status
);
140 ThunkContext
->SharingStringPack
= TRUE
;
141 StringPackageThunkContext
->SharingStringPack
= TRUE
;
146 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
152 Caculate the size of UEFI Simple Font Package that is needed to
153 convert all the font a Framework Font Paackage.
155 ONLY Narrow Font is supported. Wide Font is discarded.
157 If the Package Header is not of EFI_HII_FONT type, then ASSERT.
159 @param The Package header of the Framework Font Package.
161 @return The size of the UEFI Simple Font Package.
165 GetUefiSimpleFontPackSize (
166 IN CONST EFI_HII_PACK_HEADER
* PackHeader
170 EFI_HII_FONT_PACK
*FwFontPack
;
172 FwFontPack
= (EFI_HII_FONT_PACK
*) PackHeader
;
174 ASSERT (FwFontPack
->Header
.Type
== EFI_HII_FONT
);
176 Size
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
)
177 + (FwFontPack
->NumberOfNarrowGlyphs
* sizeof (EFI_NARROW_GLYPH
));
184 Convert Font Package in Framework format to a newly allocated UEFI
187 ONLY Narrow Font is supported. Wide Font is discarded.
189 If memory allocation fails, then ASSERT.
191 @param FwFontPack Framework Font Package.
193 @reture UEFI Simple Font Package.
195 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*
196 FrameworkFontPackToUefiSimpliedFont (
197 IN CONST EFI_HII_PACK_HEADER
* PackHeader
200 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*FontPack
;
202 EFI_NARROW_GLYPH
*FwNarrowGlyph
;
203 EFI_NARROW_GLYPH
*NarrowGlyph
;
205 EFI_HII_FONT_PACK
*FwFontPack
;
207 Size
= GetUefiSimpleFontPackSize (PackHeader
);
209 FwFontPack
= (EFI_HII_FONT_PACK
*) PackHeader
;
211 FontPack
= AllocateZeroPool (Size
);
212 ASSERT (FontPack
!= NULL
);
215 // Prepare the Header information.
217 FontPack
->Header
.Length
= (UINT32
) Size
;
218 FontPack
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
220 FontPack
->NumberOfNarrowGlyphs
= FwFontPack
->NumberOfNarrowGlyphs
;
223 // ONLY Narrow Font is supported. Wide Font is discarded.
225 FontPack
->NumberOfWideGlyphs
= 0;
230 NarrowGlyph
= (EFI_NARROW_GLYPH
*) (FontPack
+ 1);
231 FwNarrowGlyph
= (EFI_NARROW_GLYPH
*) (FwFontPack
+ 1);
232 CopyMem (NarrowGlyph
, FwNarrowGlyph
, sizeof (EFI_NARROW_GLYPH
) * FwFontPack
->NumberOfNarrowGlyphs
);
233 for (Idx
= 0; Idx
< FwFontPack
->NumberOfNarrowGlyphs
; Idx
++) {
235 // Clear the GLYPH_NON_BREAKING (EFI_GLYPH_WIDE is used here as they are all 0x02)
236 // attribute which is not defined in UEFI EFI_NARROW_GLYPH
238 NarrowGlyph
[Idx
].Attributes
= (UINT8
) (NarrowGlyph
[Idx
].Attributes
& ~(EFI_GLYPH_WIDE
));
245 Prepare a UEFI Package List from a Framework HII package list registered
246 from a Framework HII NewPack () function.
248 If either Packages or PackageListGuid is NULL, then ASSERT.
250 @param Packages The Framework HII Package List.
251 @param PackageListGuid The Package List GUID.
254 @return The UEFI Package List.
256 EFI_HII_PACKAGE_LIST_HEADER
*
257 PrepareUefiPackageListFromFrameworkHiiPackages (
258 IN CONST EFI_HII_PACKAGES
*Packages
,
259 IN CONST EFI_GUID
*PackageListGuid
262 UINTN NumberOfPackages
;
263 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
264 UINT8
*PackageListData
;
265 UINT32 PackageListLength
;
266 UINT32 PackageLength
;
267 EFI_HII_PACKAGE_HEADER PackageHeader
;
269 TIANO_AUTOGEN_PACKAGES_HEADER
**TianoAutogenPackageHdrArray
;
270 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*FontPack
;
273 ASSERT (Packages
!= NULL
);
274 ASSERT (PackageListGuid
!= NULL
);
276 TianoAutogenPackageHdrArray
= (TIANO_AUTOGEN_PACKAGES_HEADER
**) ((UINT8
*) &Packages
->GuidId
+ sizeof (Packages
->GuidId
));
277 NumberOfPackages
= Packages
->NumberOfPackages
;
279 PackageListLength
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
281 for (Index
= 0; Index
< NumberOfPackages
; Index
++) {
282 if (TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Type
== EFI_HII_FONT
) {
284 // There is no tool to generate Font package in Framework HII's implementation.
285 // Therefore, Font Package be a C structure defined in Framework HII code.
286 // Therefore, Font Package will be in Framework HII format defined by EFI_HII_FONT_PACK.
287 // We need to create a UEFI Simple Font Package and copy over all data. Hence, EFI_HII_FONT
288 // is handled differently than EFI_HII_IFR and EFI_HII_STRING.
290 PackageListLength
= (UINT32
) (PackageListLength
+ GetUefiSimpleFontPackSize (&TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
));
294 // For EFI_HII_IFR and EFI_HII_STRING, EDK II's VFR Compiler and Build.exe will generate a binary in a format
295 // defined by TIANO_AUTOGEN_PACKAGES_HEADER. A Framework HII's EFI_HII_PACK_HEADER is inserted before
296 // the UEFI package data.
298 CopyMem (&PackageLength
, &TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Length
, sizeof (UINT32
));
300 // EFI_HII_PACK_HEADER.FrameworkPackageHeader.Length include the sizeof FrameworkPackageHeader itself.
302 PackageListLength
+= (PackageLength
- sizeof(EFI_HII_PACK_HEADER
));
308 // Include the lenght of EFI_HII_PACKAGE_END
310 PackageListLength
+= sizeof (EFI_HII_PACKAGE_HEADER
);
311 PackageListHeader
= AllocateZeroPool (PackageListLength
);
312 ASSERT (PackageListHeader
!= NULL
);
314 CopyMem (&PackageListHeader
->PackageListGuid
, PackageListGuid
, sizeof (EFI_GUID
));
315 PackageListHeader
->PackageLength
= PackageListLength
;
317 PackageListData
= ((UINT8
*) PackageListHeader
) + sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
320 // Build the UEFI Package List.
322 for (Index
= 0; Index
< NumberOfPackages
; Index
++) {
323 if (TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Type
== EFI_HII_FONT
) {
324 PackageLength
= (UINT32
) GetUefiSimpleFontPackSize (&TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
);
325 FontPack
= FrameworkFontPackToUefiSimpliedFont (&TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
);
326 CopyMem (PackageListData
, FontPack
, PackageLength
);
330 CopyMem (&PackageLength
, &(TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Length
), sizeof (UINT32
));
331 PackageLength
-= sizeof (EFI_HII_PACK_HEADER
);
332 CopyMem (PackageListData
, &(TianoAutogenPackageHdrArray
[Index
]->PackageHeader
), PackageLength
);
335 PackageListData
+= PackageLength
;
339 // Append EFI_HII_PACKAGE_END
341 PackageHeader
.Type
= EFI_HII_PACKAGE_END
;
342 PackageHeader
.Length
= sizeof (EFI_HII_PACKAGE_HEADER
);
343 CopyMem (PackageListData
, &PackageHeader
, PackageHeader
.Length
);
345 return PackageListHeader
;
350 Generate a Random GUID.
352 @param Guid On output, a Random GUID will be filled.
360 EFI_GUID GuidBase
= { 0x14f95e01, 0xd562, 0x432e, { 0x84, 0x4a, 0x95, 0xa4, 0x39, 0x5, 0x10, 0x7e }};
362 CopyGuid (Guid
, &GuidBase
);
365 *((UINT64
*) Guid
) = *((UINT64
*) Guid
) + mGuidCount
;
369 Given a Package List with only a IFR package, find the Package List that only has a String Package based on
370 the TAG GUID. Then export the String Package from the Package List and insert it
371 to the given IFR package.
373 This is to handle the case of Framework HII interface which allow String Package
374 and IFR package to be registered using two different NewPack () calls.
376 @param Private The HII THUNK driver context data.
377 @param IfrThunkContext Package List with only a IFR package.
379 @retval EFI_SUCCESS If the String Package is found and inserted to the
380 Package List with only a IFR package.
381 @retval EFI_NOT_FOUND No String Package matching the TAG GUID is found.
384 FindStringPackAndUpdatePackListWithOnlyIfrPack (
385 IN HII_THUNK_PRIVATE_DATA
*Private
,
386 IN HII_THUNK_CONTEXT
*IfrThunkContext
391 EFI_HII_PACKAGE_LIST_HEADER
*StringPackageListHeader
;
393 HII_THUNK_CONTEXT
*ThunkContext
;
395 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
397 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
399 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
401 if (ThunkContext
!= IfrThunkContext
) {
402 if (CompareGuid (&IfrThunkContext
->TagGuid
, &ThunkContext
->TagGuid
) && (ThunkContext
->IfrPackageCount
== 0)) {
403 Status
= HiiLibExportPackageLists (ThunkContext
->UefiHiiHandle
, &StringPackageListHeader
, &Size
);
404 ASSERT_EFI_ERROR (Status
);
406 IfrThunkContext
->StringPackageCount
= GetPackageCountByType (StringPackageListHeader
, EFI_HII_PACKAGE_STRINGS
);
408 // Add Function to only get only String Packages from the Package List
410 Status
= mHiiDatabase
->UpdatePackageList (
412 IfrThunkContext
->UefiHiiHandle
,
413 StringPackageListHeader
415 ASSERT_EFI_ERROR (Status
);
417 FreePool (StringPackageListHeader
);
419 IfrThunkContext
->SharingStringPack
= TRUE
;
420 ThunkContext
->SharingStringPack
= TRUE
;
427 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
431 // A Form Package must have a String Package to function.
432 // If ASSERT here, check the sequence of call to Hii->NewPack.
433 // String Pack must be registered before Ifr Package is registered.
436 return EFI_NOT_FOUND
;
442 Register the Package List passed from the Framework HII NewPack () interface.
443 The FRAMEWORK_EFI_HII_HANDLE will be returned.
445 @param This The EFI_HII_PROTOCOL context data. Only used
446 to call HiiRemovePack.
447 @param Private The HII THUNK driver context data.
448 @param Package Package List.
449 @param Handle On output, a FRAMEWORK_EFI_HII_HANDLE number is
452 @retval EFI_SUCCESS The Package List is registered successfull in
454 @retval EFI_UNSUPPORTED The number of IFR package in the package list
456 @retval EFI_OUT_OF_RESOURCE Not enough resouce.
460 UefiRegisterPackageList (
461 IN EFI_HII_PROTOCOL
*This
,
462 IN HII_THUNK_PRIVATE_DATA
*Private
,
463 IN EFI_HII_PACKAGES
*Packages
,
464 OUT FRAMEWORK_EFI_HII_HANDLE
*Handle
468 UINTN StringPackageCount
;
469 UINTN IfrPackageCount
;
470 UINTN FontPackageCount
;
471 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
472 HII_THUNK_CONTEXT
*ThunkContext
;
473 HII_THUNK_CONTEXT
*ThunkContextToRemove
;
475 EFI_HII_PACKAGE_HEADER
*IfrPackage
;
477 PackageListHeader
= NULL
;
479 Status
= GetPackageCount (Packages
, &IfrPackageCount
, &StringPackageCount
, &FontPackageCount
);
480 ASSERT_EFI_ERROR (Status
);
482 if (IfrPackageCount
> 1) {
484 // HII Thunk only handle package with 0 or 1 IFR package.
487 return EFI_UNSUPPORTED
;
490 ThunkContext
= CreateThunkContext (Private
, StringPackageCount
, IfrPackageCount
);
491 if (ThunkContext
== NULL
) {
492 return EFI_OUT_OF_RESOURCES
;
494 ThunkContext
->ByFrameworkHiiNewPack
= TRUE
;
496 if (Packages
->GuidId
== NULL
) {
498 // UEFI HII Database require Package List GUID must be unique.
500 // If Packages->GuidId is NULL, the caller of FramworkHii->NewPack is registering
501 // packages with at least 1 StringPack and 1 IfrPack. Therefore, Packages->GuidId is
502 // not used as the name of the package list. Formset GUID is used as the Package List
505 ASSERT ((StringPackageCount
>=1 && IfrPackageCount
== 1) || (FontPackageCount
> 0));
506 if (IfrPackageCount
> 0) {
507 IfrPackage
= GetIfrPackage (Packages
);
508 GetFormSetGuid (IfrPackage
, &ThunkContext
->TagGuid
);
510 ASSERT (FontPackageCount
> 0);
511 GenerateRandomGuid (&ThunkContext
->TagGuid
);
515 ThunkContextToRemove
= TagGuidToIfrPackThunkContext (Private
, Packages
->GuidId
);
517 if (IfrPackageCount
> 0 &&
518 StringPackageCount
> 0 &&
519 (ThunkContextToRemove
!= NULL
)) {
520 DEBUG((EFI_D_WARN
, "Framework code registers HII package list with the same GUID more than once.\n"));
521 DEBUG((EFI_D_WARN
, "Remove the previously registered package list and register the new one.\n"));
522 HiiRemovePack (This
, ThunkContextToRemove
->FwHiiHandle
);
524 CopyGuid (&ThunkContext
->TagGuid
, Packages
->GuidId
);
529 // UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
530 // that Setup Utility can load the Buffer Storage using this protocol. An UEFI VFR can only
531 // produce IFR package generated with Buffer Storage type and EFI Variable Storage.
532 // The default EFI_HII_CONFIG_ACCESS_PROTOCOL is used to Get/Set the Buffer Storage.
534 if (IfrPackageCount
!= 0) {
535 InstallDefaultConfigAccessProtocol (Packages
, ThunkContext
);
538 PackageListHeader
= PrepareUefiPackageListFromFrameworkHiiPackages (Packages
, &ThunkContext
->TagGuid
);
539 Status
= mHiiDatabase
->NewPackageList (
542 ThunkContext
->UefiHiiDriverHandle
,
543 &ThunkContext
->UefiHiiHandle
545 if (Status
== EFI_INVALID_PARAMETER
) {
546 FreePool (PackageListHeader
);
549 // UEFI HII database does not allow two package list with the same GUID.
550 // In Framework HII implementation, Packages->GuidId is used as an identifier to associate
551 // a PackageList with only IFR to a Package list the with String package.
553 GenerateRandomGuid (&GuidId
);
555 PackageListHeader
= PrepareUefiPackageListFromFrameworkHiiPackages (Packages
, &GuidId
);
556 Status
= mHiiDatabase
->NewPackageList (
559 ThunkContext
->UefiHiiDriverHandle
,
560 &ThunkContext
->UefiHiiHandle
565 // BUGBUG: Remove when development is done
567 ASSERT_EFI_ERROR (Status
);
568 if (EFI_ERROR (Status
)) {
572 if (IfrPackageCount
== 0) {
573 if (StringPackageCount
!= 0) {
575 // Look for a Package List with only IFR Package with the same TAG GUID name.
576 // If found one, add the String Packages to the found Package List.
577 // This is needed because Framework HII Module may not register the String Package
578 // and IFR Package in one NewPack () call.
580 UpdatePackListWithOnlyIfrPack (
587 if (StringPackageCount
== 0) {
589 // Look for the String Package with the same TAG GUID name and add
590 // the found String Package to this Package List.
591 // This is needed because Framework HII Module may not register the String Package
592 // and IFR Package in one NewPack () call.
594 Status
= FindStringPackAndUpdatePackListWithOnlyIfrPack (
599 if (EFI_ERROR (Status
)) {
605 // Parse the Formset. Must be called after FindStringPackAndUpdatePackListWithOnlyIfrPack is called so
606 // that String Package is ready.
608 ThunkContext
->FormSet
= ParseFormSet (ThunkContext
->UefiHiiHandle
);
609 ASSERT (ThunkContext
->FormSet
!= NULL
);
614 if (EFI_ERROR (Status
)) {
615 DestroyThunkContext (ThunkContext
);
617 InsertTailList (&Private
->ThunkContextListHead
, &ThunkContext
->Link
);
618 *Handle
= ThunkContext
->FwHiiHandle
;
621 if (PackageListHeader
!= NULL
) {
622 FreePool (PackageListHeader
);
631 Registers the various packages that are passed in a Package List.
633 @param This Pointer of Frameowk HII protocol instance.
634 @param Packages Pointer of HII packages.
635 @param Handle Handle value to be returned.
637 @retval EFI_SUCCESS Pacakges has added to HII database successfully.
638 @retval EFI_INVALID_PARAMETER If Handle or Packages is NULL.
644 IN EFI_HII_PROTOCOL
*This
,
645 IN EFI_HII_PACKAGES
*Packages
,
646 OUT FRAMEWORK_EFI_HII_HANDLE
*Handle
650 HII_THUNK_PRIVATE_DATA
*Private
;
653 if (Handle
== NULL
) {
654 return EFI_INVALID_PARAMETER
;
657 if (Packages
== NULL
) {
658 return EFI_INVALID_PARAMETER
;
661 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
664 // We use a simple Global variable to inform NewOrAddPackNotify()
665 // that the package list registered here is already registered
666 // in the HII Thunk Layer. So NewOrAddPackNotify () does not need to
667 // call registered the Package List again.
669 mInFrameworkHiiNewPack
= TRUE
;
671 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
673 Status
= UefiRegisterPackageList (
680 mInFrameworkHiiNewPack
= FALSE
;
682 gBS
->RestoreTPL (OldTpl
);
689 Remove a package from the HII database.
691 @param This Pointer of Frameowk HII protocol instance.
692 @param Handle Handle value to be removed.
694 @retval EFI_SUCCESS Pacakges has added to HII database successfully.
695 @retval EFI_INVALID_PARAMETER If Handle or Packages is NULL.
701 IN EFI_HII_PROTOCOL
*This
,
702 IN FRAMEWORK_EFI_HII_HANDLE Handle
706 HII_THUNK_PRIVATE_DATA
*Private
;
707 HII_THUNK_CONTEXT
*ThunkContext
;
710 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
712 mInFrameworkHiiRemovePack
= TRUE
;
714 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
716 ThunkContext
= FwHiiHandleToThunkContext (Private
, Handle
);
718 if (ThunkContext
!= NULL
) {
719 Status
= mHiiDatabase
->RemovePackageList (
721 ThunkContext
->UefiHiiHandle
723 ASSERT_EFI_ERROR (Status
);
725 if (ThunkContext
->IfrPackageCount
!= 0) {
726 UninstallDefaultConfigAccessProtocol (ThunkContext
);
729 DestroyThunkContext (ThunkContext
);
731 Status
= EFI_NOT_FOUND
;
734 mInFrameworkHiiRemovePack
= FALSE
;
735 gBS
->RestoreTPL (OldTpl
);
741 This notification function will be called when a Package List is registered
742 using UEFI HII interface. The Package List registered need to be recorded in
743 Framework Thunk module as Thunk Module may need to look for String Package in
744 the package registered.
746 If the Package List registered is not either Sting Package or IFR package,
747 then ASSERT. If the NotifyType is not ADD_PACK or NEW_PACK, then ASSERT.
748 Both cases means UEFI HII Database itself is buggy.
750 @param PackageType The Package Type.
751 @param PackageGuid The Package GUID.
752 @param Package The Package Header.
753 @param Handle The HII Handle of this Package List.
754 @param NotifyType The reason of the notification.
756 @retval EFI_SUCCESS The notification function is successful.
762 IN UINT8 PackageType
,
763 IN CONST EFI_GUID
*PackageGuid
,
764 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
765 IN EFI_HII_HANDLE Handle
,
766 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
770 HII_THUNK_PRIVATE_DATA
*Private
;
771 HII_THUNK_CONTEXT
*ThunkContext
;
773 ASSERT (PackageType
== EFI_HII_PACKAGE_STRINGS
|| PackageType
== EFI_HII_PACKAGE_FORMS
);
774 ASSERT (NotifyType
== EFI_HII_DATABASE_NOTIFY_ADD_PACK
|| NotifyType
== EFI_HII_DATABASE_NOTIFY_NEW_PACK
);
776 Status
= EFI_SUCCESS
;
777 Private
= mHiiThunkPrivateData
;
779 if (mInFrameworkHiiNewPack
|| mInFrameworkUpdatePakcage
) {
784 // We will create a ThunkContext to log the package list only if the
785 // package is not registered with by Framework HII Thunk module yet.
787 ThunkContext
= UefiHiiHandleToThunkContext (Private
, Handle
);
788 if (ThunkContext
== NULL
) {
789 ThunkContext
= CreateThunkContextForUefiHiiHandle (Handle
);
790 ASSERT (ThunkContext
!= NULL
);
792 InsertTailList (&Private
->ThunkContextListHead
, &ThunkContext
->Link
);
795 if (PackageType
== EFI_HII_PACKAGE_FORMS
) {
796 if (ThunkContext
->FormSet
!= NULL
) {
797 DestroyFormSet (ThunkContext
->FormSet
);
801 // Reparse the FormSet.
803 ThunkContext
->FormSet
= ParseFormSet (ThunkContext
->UefiHiiHandle
);
804 ASSERT (ThunkContext
->FormSet
!= NULL
);
811 This notification function will be called when a Package List is removed
812 using UEFI HII interface. The Package List removed need to be removed from
813 Framework Thunk module too.
815 If the Package List registered is not Sting Package,
816 then ASSERT. If the NotifyType is not REMOVE_PACK, then ASSERT.
817 Both cases means UEFI HII Database itself is buggy.
819 @param PackageType The Package Type.
820 @param PackageGuid The Package GUID.
821 @param Package The Package Header.
822 @param Handle The HII Handle of this Package List.
823 @param NotifyType The reason of the notification.
825 @retval EFI_SUCCESS The notification function is successful.
831 IN UINT8 PackageType
,
832 IN CONST EFI_GUID
*PackageGuid
,
833 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
834 IN EFI_HII_HANDLE Handle
,
835 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
839 HII_THUNK_PRIVATE_DATA
*Private
;
840 HII_THUNK_CONTEXT
*ThunkContext
;
841 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
844 Status
= EFI_SUCCESS
;
846 ASSERT (PackageType
== EFI_HII_PACKAGE_STRINGS
);
847 ASSERT (NotifyType
== EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
);
849 if (mInFrameworkHiiRemovePack
|| mInFrameworkUpdatePakcage
) {
853 Private
= mHiiThunkPrivateData
;
855 ThunkContext
= UefiHiiHandleToThunkContext (Private
, Handle
);
858 // BugBug: Change to ASSERT if HII Database fix the bug and to also invoke
859 // NEW_PACK_NOTIFY for package (String Package) created internally.
861 if (ThunkContext
!= NULL
) {
862 if (!ThunkContext
->ByFrameworkHiiNewPack
) {
863 Status
= HiiLibExportPackageLists (Handle
, &HiiPackageList
, &BufferSize
);
864 ASSERT_EFI_ERROR (Status
);
866 if (GetPackageCountByType (HiiPackageList
, EFI_HII_PACKAGE_STRINGS
) == 1) {
868 // If the string package will be removed is the last string package
869 // in the package list, we will remove the HII Thunk entry from the
872 DestroyThunkContextForUefiHiiHandle (Private
, Handle
);
875 FreePool (HiiPackageList
);