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;
25 EFI_GUID mGuidBase
= { 0x14f95e01, 0xd562, 0x432e, { 0x84, 0x4a, 0x95, 0xa4, 0x39, 0x5, 0x10, 0x7e }};
30 Get the number of package IFR and STRING packages in the package list passed in.
32 @param Packages Package List.
33 @param IfrPackageCount Number of IFR Packages.
34 @param StringPackageCount Number of String Packages.
36 @retval EFI_INVALID_PARAMETER If the Package List has package with type of
37 EFI_HII_PACKAGE_KEYBOARD_LAYOUT, EFI_HII_PACKAGE_FONTS, EFI_HII_PACKAGE_IMAGES.
38 @reval EFI_SUCCESS Successfully get the number of IFR and STRING package.
44 IN CONST EFI_HII_PACKAGES
*Packages
,
45 OUT UINTN
*IfrPackageCount
,
46 OUT UINTN
*StringPackageCount
,
47 OUT UINTN
*FontPackageCount
51 TIANO_AUTOGEN_PACKAGES_HEADER
**TianoAutogenPackageHdrArray
;
53 ASSERT (Packages
!= NULL
);
54 ASSERT (IfrPackageCount
!= NULL
);
55 ASSERT (StringPackageCount
!= NULL
);
56 ASSERT (FontPackageCount
!= NULL
);
59 *StringPackageCount
= 0;
60 *FontPackageCount
= 0;
62 TianoAutogenPackageHdrArray
= (TIANO_AUTOGEN_PACKAGES_HEADER
**) (((UINT8
*) &Packages
->GuidId
) + sizeof (Packages
->GuidId
));
64 for (Index
= 0; Index
< Packages
->NumberOfPackages
; Index
++) {
66 // The current UEFI HII build tool generate a binary in the format defined by
67 // TIANO_AUTOGEN_PACKAGES_HEADER. We assume that all packages generated in
68 // this binary is with same package type. So the returned IfrPackageCount and StringPackageCount
69 // may not be the exact number of valid package number in the binary generated
72 switch (TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Type
) {
74 *IfrPackageCount
+= 1;
77 *StringPackageCount
+= 1;
81 *FontPackageCount
+= 1;
85 // The following fonts are invalid for a module that using Framework to UEFI thunk layer.
89 return EFI_INVALID_PARAMETER
;
98 Insert the String Package into the Package Lists which has the TAG GUID matching
99 the PackageListGuid of the String Package.
101 The Package List must have only IFR Package and no String Package.
104 @param Private The HII THUNK driver context data.
105 @param StringPackageThunkContext The HII THUNK context data.
106 @param StringPackageListHeader The String Package List Header.
110 UpdatePackListWithOnlyIfrPack (
111 IN HII_THUNK_PRIVATE_DATA
*Private
,
112 IN HII_THUNK_CONTEXT
*StringPackageThunkContext
,
113 IN CONST EFI_HII_PACKAGE_LIST_HEADER
*StringPackageListHeader
118 HII_THUNK_CONTEXT
*ThunkContext
;
120 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
121 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
123 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
125 if (StringPackageThunkContext
!= ThunkContext
) {
127 // Skip the String Package Thunk Entry itself.
130 if (CompareGuid (&StringPackageListHeader
->PackageListGuid
, &ThunkContext
->TagGuid
)) {
132 ASSERT (ThunkContext
->StringPackageCount
== 0 && ThunkContext
->IfrPackageCount
== 1);
134 ThunkContext
->StringPackageCount
= GetPackageCountByType (StringPackageListHeader
, EFI_HII_PACKAGE_STRINGS
);
136 Status
= mHiiDatabase
->UpdatePackageList (
138 ThunkContext
->UefiHiiHandle
,
139 StringPackageListHeader
141 ASSERT_EFI_ERROR (Status
);
143 ThunkContext
->SharingStringPack
= TRUE
;
144 StringPackageThunkContext
->SharingStringPack
= TRUE
;
149 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
155 Caculate the size of UEFI Simple Font Package that is needed to
156 convert all the font a Framework Font Paackage.
158 ONLY Narrow Font is supported. Wide Font is discarded.
160 If the Package Header is not of EFI_HII_FONT type, then ASSERT.
162 @param The Package header of the Framework Font Package.
164 @return The size of the UEFI Simple Font Package.
168 GetUefiSimpleFontPackSize (
169 IN CONST EFI_HII_PACK_HEADER
* PackHeader
173 EFI_HII_FONT_PACK
*FwFontPack
;
175 FwFontPack
= (EFI_HII_FONT_PACK
*) PackHeader
;
177 ASSERT (FwFontPack
->Header
.Type
== EFI_HII_FONT
);
179 Size
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
)
180 + (FwFontPack
->NumberOfNarrowGlyphs
* sizeof (EFI_NARROW_GLYPH
));
187 Convert Font Package in Framework format to a newly allocated UEFI
190 ONLY Narrow Font is supported. Wide Font is discarded.
192 If memory allocation fails, then ASSERT.
194 @param FwFontPack Framework Font Package.
196 @reture UEFI Simple Font Package.
198 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*
199 FrameworkFontPackToUefiSimpliedFont (
200 IN CONST EFI_HII_PACK_HEADER
* PackHeader
203 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*FontPack
;
205 EFI_NARROW_GLYPH
*FwNarrowGlyph
;
206 EFI_NARROW_GLYPH
*NarrowGlyph
;
208 EFI_HII_FONT_PACK
*FwFontPack
;
210 Size
= GetUefiSimpleFontPackSize (PackHeader
);
212 FwFontPack
= (EFI_HII_FONT_PACK
*) PackHeader
;
214 FontPack
= AllocateZeroPool (Size
);
215 ASSERT (FontPack
!= NULL
);
218 // Prepare the Header information.
220 FontPack
->Header
.Length
= (UINT32
) Size
;
221 FontPack
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
223 FontPack
->NumberOfNarrowGlyphs
= FwFontPack
->NumberOfNarrowGlyphs
;
226 // ONLY Narrow Font is supported. Wide Font is discarded.
228 FontPack
->NumberOfWideGlyphs
= 0;
233 NarrowGlyph
= (EFI_NARROW_GLYPH
*) (FontPack
+ 1);
234 FwNarrowGlyph
= (EFI_NARROW_GLYPH
*) (FwFontPack
+ 1);
235 CopyMem (NarrowGlyph
, FwNarrowGlyph
, sizeof (EFI_NARROW_GLYPH
) * FwFontPack
->NumberOfNarrowGlyphs
);
236 for (Idx
= 0; Idx
< FwFontPack
->NumberOfNarrowGlyphs
; Idx
++) {
238 // Clear the GLYPH_NON_BREAKING (EFI_GLYPH_WIDE is used here as they are all 0x02)
239 // attribute which is not defined in UEFI EFI_NARROW_GLYPH
241 NarrowGlyph
[Idx
].Attributes
= (UINT8
) (NarrowGlyph
[Idx
].Attributes
& ~(EFI_GLYPH_WIDE
));
248 Prepare a UEFI Package List from a Framework HII package list registered
249 from a Framework HII NewPack () function.
251 If either Packages or PackageListGuid is NULL, then ASSERT.
253 @param Packages The Framework HII Package List.
254 @param PackageListGuid The Package List GUID.
257 @return The UEFI Package List.
259 EFI_HII_PACKAGE_LIST_HEADER
*
260 PrepareUefiPackageListFromFrameworkHiiPackages (
261 IN CONST EFI_HII_PACKAGES
*Packages
,
262 IN CONST EFI_GUID
*PackageListGuid
265 UINTN NumberOfPackages
;
266 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
267 UINT8
*PackageListData
;
268 UINT32 PackageListLength
;
269 UINT32 PackageLength
;
270 EFI_HII_PACKAGE_HEADER PackageHeader
;
272 TIANO_AUTOGEN_PACKAGES_HEADER
**TianoAutogenPackageHdrArray
;
273 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*FontPack
;
276 ASSERT (Packages
!= NULL
);
277 ASSERT (PackageListGuid
!= NULL
);
279 TianoAutogenPackageHdrArray
= (TIANO_AUTOGEN_PACKAGES_HEADER
**) ((UINT8
*) &Packages
->GuidId
+ sizeof (Packages
->GuidId
));
280 NumberOfPackages
= Packages
->NumberOfPackages
;
282 PackageListLength
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
284 for (Index
= 0; Index
< NumberOfPackages
; Index
++) {
285 if (TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Type
== EFI_HII_FONT
) {
287 // There is no tool to generate Font package in Framework HII's implementation.
288 // Therefore, Font Package be a C structure defined in Framework HII code.
289 // Therefore, Font Package will be in Framework HII format defined by EFI_HII_FONT_PACK.
290 // We need to create a UEFI Simple Font Package and copy over all data. Hence, EFI_HII_FONT
291 // is handled differently than EFI_HII_IFR and EFI_HII_STRING.
293 PackageListLength
= (UINT32
) (PackageListLength
+ GetUefiSimpleFontPackSize (&TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
));
297 // For EFI_HII_IFR and EFI_HII_STRING, EDK II's VFR Compiler and Build.exe will generate a binary in a format
298 // defined by TIANO_AUTOGEN_PACKAGES_HEADER. A Framework HII's EFI_HII_PACK_HEADER is inserted before
299 // the UEFI package data.
301 CopyMem (&PackageLength
, &TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Length
, sizeof (UINT32
));
303 // EFI_HII_PACK_HEADER.FrameworkPackageHeader.Length include the sizeof FrameworkPackageHeader itself.
305 PackageListLength
+= (PackageLength
- sizeof(EFI_HII_PACK_HEADER
));
311 // Include the lenght of EFI_HII_PACKAGE_END
313 PackageListLength
+= sizeof (EFI_HII_PACKAGE_HEADER
);
314 PackageListHeader
= AllocateZeroPool (PackageListLength
);
315 ASSERT (PackageListHeader
!= NULL
);
317 CopyMem (&PackageListHeader
->PackageListGuid
, PackageListGuid
, sizeof (EFI_GUID
));
318 PackageListHeader
->PackageLength
= PackageListLength
;
320 PackageListData
= ((UINT8
*) PackageListHeader
) + sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
323 // Build the UEFI Package List.
325 for (Index
= 0; Index
< NumberOfPackages
; Index
++) {
326 if (TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Type
== EFI_HII_FONT
) {
327 PackageLength
= (UINT32
) GetUefiSimpleFontPackSize (&TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
);
328 FontPack
= FrameworkFontPackToUefiSimpliedFont (&TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
);
329 CopyMem (PackageListData
, FontPack
, PackageLength
);
333 CopyMem (&PackageLength
, &(TianoAutogenPackageHdrArray
[Index
]->FrameworkPackageHeader
.Length
), sizeof (UINT32
));
334 PackageLength
-= sizeof (EFI_HII_PACK_HEADER
);
335 CopyMem (PackageListData
, &(TianoAutogenPackageHdrArray
[Index
]->PackageHeader
), PackageLength
);
338 PackageListData
+= PackageLength
;
342 // Append EFI_HII_PACKAGE_END
344 PackageHeader
.Type
= EFI_HII_PACKAGE_END
;
345 PackageHeader
.Length
= sizeof (EFI_HII_PACKAGE_HEADER
);
346 CopyMem (PackageListData
, &PackageHeader
, PackageHeader
.Length
);
348 return PackageListHeader
;
353 Generate a Random GUID.
355 @param Guid On output, a Random GUID will be filled.
363 CopyGuid (Guid
, &mGuidBase
);
366 *((UINT64
*) Guid
) = *((UINT64
*) Guid
) + mGuidCount
;
370 Given a Package List with only a IFR package, find the Package List that only has a String Package based on
371 the TAG GUID. Then export the String Package from the Package List and insert it
372 to the given IFR package.
374 This is to handle the case of Framework HII interface which allow String Package
375 and IFR package to be registered using two different NewPack () calls.
377 @param Private The HII THUNK driver context data.
378 @param IfrThunkContext Package List with only a IFR package.
380 @retval EFI_SUCCESS If the String Package is found and inserted to the
381 Package List with only a IFR package.
382 @retval EFI_NOT_FOUND No String Package matching the TAG GUID is found.
385 FindStringPackAndUpdatePackListWithOnlyIfrPack (
386 IN HII_THUNK_PRIVATE_DATA
*Private
,
387 IN HII_THUNK_CONTEXT
*IfrThunkContext
392 EFI_HII_PACKAGE_LIST_HEADER
*StringPackageListHeader
;
394 HII_THUNK_CONTEXT
*ThunkContext
;
396 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
398 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
400 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
402 if (ThunkContext
!= IfrThunkContext
) {
403 if (CompareGuid (&IfrThunkContext
->TagGuid
, &ThunkContext
->TagGuid
) && (ThunkContext
->IfrPackageCount
== 0)) {
404 Status
= HiiLibExportPackageLists (ThunkContext
->UefiHiiHandle
, &StringPackageListHeader
, &Size
);
405 ASSERT_EFI_ERROR (Status
);
407 IfrThunkContext
->StringPackageCount
= GetPackageCountByType (StringPackageListHeader
, EFI_HII_PACKAGE_STRINGS
);
409 // Add Function to only get only String Packages from the Package List
411 Status
= mHiiDatabase
->UpdatePackageList (
413 IfrThunkContext
->UefiHiiHandle
,
414 StringPackageListHeader
416 ASSERT_EFI_ERROR (Status
);
418 FreePool (StringPackageListHeader
);
420 IfrThunkContext
->SharingStringPack
= TRUE
;
421 ThunkContext
->SharingStringPack
= TRUE
;
428 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
432 // A Form Package must have a String Package to function.
433 // If ASSERT here, check the sequence of call to Hii->NewPack.
434 // String Pack must be registered before Ifr Package is registered.
437 return EFI_NOT_FOUND
;
443 Register the Package List passed from the Framework HII NewPack () interface.
444 The FRAMEWORK_EFI_HII_HANDLE will be returned.
446 @param This The EFI_HII_PROTOCOL context data. Only used
447 to call HiiRemovePack.
448 @param Private The HII THUNK driver context data.
449 @param Package Package List.
450 @param Handle On output, a FRAMEWORK_EFI_HII_HANDLE number is
453 @retval EFI_SUCCESS The Package List is registered successfull in
455 @retval EFI_UNSUPPORTED The number of IFR package in the package list
457 @retval EFI_OUT_OF_RESOURCE Not enough resouce.
461 UefiRegisterPackageList (
462 IN EFI_HII_PROTOCOL
*This
,
463 IN HII_THUNK_PRIVATE_DATA
*Private
,
464 IN EFI_HII_PACKAGES
*Packages
,
465 OUT FRAMEWORK_EFI_HII_HANDLE
*Handle
469 UINTN StringPackageCount
;
470 UINTN IfrPackageCount
;
471 UINTN FontPackageCount
;
472 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
473 HII_THUNK_CONTEXT
*ThunkContext
;
474 HII_THUNK_CONTEXT
*ThunkContextToRemove
;
476 EFI_HII_PACKAGE_HEADER
*IfrPackage
;
478 PackageListHeader
= NULL
;
480 Status
= GetPackageCount (Packages
, &IfrPackageCount
, &StringPackageCount
, &FontPackageCount
);
481 ASSERT_EFI_ERROR (Status
);
483 if (IfrPackageCount
> 1) {
485 // HII Thunk only handle package with 0 or 1 IFR package.
488 return EFI_UNSUPPORTED
;
491 ThunkContext
= CreateThunkContext (Private
, StringPackageCount
, IfrPackageCount
);
492 if (ThunkContext
== NULL
) {
493 return EFI_OUT_OF_RESOURCES
;
495 ThunkContext
->ByFrameworkHiiNewPack
= TRUE
;
497 if (Packages
->GuidId
== NULL
) {
499 // UEFI HII Database require Package List GUID must be unique.
501 // If Packages->GuidId is NULL, the caller of FramworkHii->NewPack is registering
502 // packages with at least 1 StringPack and 1 IfrPack. Therefore, Packages->GuidId is
503 // not used as the name of the package list. Formset GUID is used as the Package List
506 ASSERT ((StringPackageCount
>=1 && IfrPackageCount
== 1) || (FontPackageCount
> 0));
507 if (IfrPackageCount
> 0) {
508 IfrPackage
= GetIfrPackage (Packages
);
509 GetFormSetGuid (IfrPackage
, &ThunkContext
->TagGuid
);
511 ASSERT (FontPackageCount
> 0);
512 GenerateRandomGuid (&ThunkContext
->TagGuid
);
516 ThunkContextToRemove
= TagGuidToIfrPackThunkContext (Private
, Packages
->GuidId
);
518 if (IfrPackageCount
> 0 &&
519 StringPackageCount
> 0 &&
520 (ThunkContextToRemove
!= NULL
)) {
521 DEBUG((EFI_D_WARN
, "Framework code registers HII package list with the same GUID more than once.\n"));
522 DEBUG((EFI_D_WARN
, "Remove the previously registered package list and register the new one.\n"));
523 HiiRemovePack (This
, ThunkContextToRemove
->FwHiiHandle
);
525 CopyGuid (&ThunkContext
->TagGuid
, Packages
->GuidId
);
530 // UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
531 // that Setup Utility can load the Buffer Storage using this protocol. An UEFI VFR can only
532 // produce IFR package generated with Buffer Storage type and EFI Variable Storage.
533 // The default EFI_HII_CONFIG_ACCESS_PROTOCOL is used to Get/Set the Buffer Storage.
535 if (IfrPackageCount
!= 0) {
536 InstallDefaultConfigAccessProtocol (Packages
, ThunkContext
);
539 PackageListHeader
= PrepareUefiPackageListFromFrameworkHiiPackages (Packages
, &ThunkContext
->TagGuid
);
540 Status
= mHiiDatabase
->NewPackageList (
543 ThunkContext
->UefiHiiDriverHandle
,
544 &ThunkContext
->UefiHiiHandle
546 if (Status
== EFI_INVALID_PARAMETER
) {
547 FreePool (PackageListHeader
);
550 // UEFI HII database does not allow two package list with the same GUID.
551 // In Framework HII implementation, Packages->GuidId is used as an identifier to associate
552 // a PackageList with only IFR to a Package list the with String package.
554 GenerateRandomGuid (&GuidId
);
556 PackageListHeader
= PrepareUefiPackageListFromFrameworkHiiPackages (Packages
, &GuidId
);
557 Status
= mHiiDatabase
->NewPackageList (
560 ThunkContext
->UefiHiiDriverHandle
,
561 &ThunkContext
->UefiHiiHandle
566 // BUGBUG: Remove when development is done
568 ASSERT_EFI_ERROR (Status
);
569 if (EFI_ERROR (Status
)) {
573 if (IfrPackageCount
== 0) {
574 if (StringPackageCount
!= 0) {
576 // Look for a Package List with only IFR Package with the same TAG GUID name.
577 // If found one, add the String Packages to the found Package List.
578 // This is needed because Framework HII Module may not register the String Package
579 // and IFR Package in one NewPack () call.
581 UpdatePackListWithOnlyIfrPack (
588 if (StringPackageCount
== 0) {
590 // Look for the String Package with the same TAG GUID name and add
591 // the found String Package to this Package List.
592 // This is needed because Framework HII Module may not register the String Package
593 // and IFR Package in one NewPack () call.
595 Status
= FindStringPackAndUpdatePackListWithOnlyIfrPack (
600 if (EFI_ERROR (Status
)) {
606 // Parse the Formset. Must be called after FindStringPackAndUpdatePackListWithOnlyIfrPack is called so
607 // that String Package is ready.
609 ThunkContext
->FormSet
= ParseFormSet (ThunkContext
->UefiHiiHandle
);
610 ASSERT (ThunkContext
->FormSet
!= NULL
);
615 if (EFI_ERROR (Status
)) {
616 DestroyThunkContext (ThunkContext
);
618 InsertTailList (&Private
->ThunkContextListHead
, &ThunkContext
->Link
);
619 *Handle
= ThunkContext
->FwHiiHandle
;
622 if (PackageListHeader
!= NULL
) {
623 FreePool (PackageListHeader
);
632 Registers the various packages that are passed in a Package List.
634 @param This Pointer of Frameowk HII protocol instance.
635 @param Packages Pointer of HII packages.
636 @param Handle Handle value to be returned.
638 @retval EFI_SUCCESS Pacakges has added to HII database successfully.
639 @retval EFI_INVALID_PARAMETER If Handle or Packages is NULL.
645 IN EFI_HII_PROTOCOL
*This
,
646 IN EFI_HII_PACKAGES
*Packages
,
647 OUT FRAMEWORK_EFI_HII_HANDLE
*Handle
651 HII_THUNK_PRIVATE_DATA
*Private
;
654 if (Handle
== NULL
) {
655 return EFI_INVALID_PARAMETER
;
658 if (Packages
== NULL
) {
659 return EFI_INVALID_PARAMETER
;
662 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
665 // We use a simple Global variable to inform NewOrAddPackNotify()
666 // that the package list registered here is already registered
667 // in the HII Thunk Layer. So NewOrAddPackNotify () does not need to
668 // call registered the Package List again.
670 mInFrameworkHiiNewPack
= TRUE
;
672 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
674 Status
= UefiRegisterPackageList (
681 mInFrameworkHiiNewPack
= FALSE
;
683 gBS
->RestoreTPL (OldTpl
);
690 Remove a package from the HII database.
692 @param This Pointer of Frameowk HII protocol instance.
693 @param Handle Handle value to be removed.
695 @retval EFI_SUCCESS Pacakges has added to HII database successfully.
696 @retval EFI_INVALID_PARAMETER If Handle or Packages is NULL.
702 IN EFI_HII_PROTOCOL
*This
,
703 IN FRAMEWORK_EFI_HII_HANDLE Handle
707 HII_THUNK_PRIVATE_DATA
*Private
;
708 HII_THUNK_CONTEXT
*ThunkContext
;
711 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
713 mInFrameworkHiiRemovePack
= TRUE
;
715 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
717 ThunkContext
= FwHiiHandleToThunkContext (Private
, Handle
);
719 if (ThunkContext
!= NULL
) {
720 Status
= mHiiDatabase
->RemovePackageList (
722 ThunkContext
->UefiHiiHandle
724 ASSERT_EFI_ERROR (Status
);
726 if (ThunkContext
->IfrPackageCount
!= 0) {
727 UninstallDefaultConfigAccessProtocol (ThunkContext
);
730 DestroyThunkContext (ThunkContext
);
732 Status
= EFI_NOT_FOUND
;
735 mInFrameworkHiiRemovePack
= FALSE
;
736 gBS
->RestoreTPL (OldTpl
);
742 This notification function will be called when a Package List is registered
743 using UEFI HII interface. The Package List registered need to be recorded in
744 Framework Thunk module as Thunk Module may need to look for String Package in
745 the package registered.
747 If the Package List registered is not either Sting Package or IFR package,
748 then ASSERT. If the NotifyType is not ADD_PACK or NEW_PACK, then ASSERT.
749 Both cases means UEFI HII Database itself is buggy.
751 @param PackageType The Package Type.
752 @param PackageGuid The Package GUID.
753 @param Package The Package Header.
754 @param Handle The HII Handle of this Package List.
755 @param NotifyType The reason of the notification.
757 @retval EFI_SUCCESS The notification function is successful.
763 IN UINT8 PackageType
,
764 IN CONST EFI_GUID
*PackageGuid
,
765 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
766 IN EFI_HII_HANDLE Handle
,
767 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
771 HII_THUNK_PRIVATE_DATA
*Private
;
772 HII_THUNK_CONTEXT
*ThunkContext
;
774 ASSERT (PackageType
== EFI_HII_PACKAGE_STRINGS
|| PackageType
== EFI_HII_PACKAGE_FORMS
);
775 ASSERT (NotifyType
== EFI_HII_DATABASE_NOTIFY_ADD_PACK
|| NotifyType
== EFI_HII_DATABASE_NOTIFY_NEW_PACK
);
777 Status
= EFI_SUCCESS
;
778 Private
= mHiiThunkPrivateData
;
780 if (mInFrameworkHiiNewPack
|| mInFrameworkUpdatePakcage
) {
785 // We will create a ThunkContext to log the package list only if the
786 // package is not registered with by Framework HII Thunk module yet.
788 ThunkContext
= UefiHiiHandleToThunkContext (Private
, Handle
);
789 if (ThunkContext
== NULL
) {
790 ThunkContext
= CreateThunkContextForUefiHiiHandle (Handle
);
791 ASSERT (ThunkContext
!= NULL
);
793 InsertTailList (&Private
->ThunkContextListHead
, &ThunkContext
->Link
);
796 if (PackageType
== EFI_HII_PACKAGE_FORMS
) {
797 if (ThunkContext
->FormSet
!= NULL
) {
798 DestroyFormSet (ThunkContext
->FormSet
);
802 // Reparse the FormSet.
804 ThunkContext
->FormSet
= ParseFormSet (ThunkContext
->UefiHiiHandle
);
805 ASSERT (ThunkContext
->FormSet
!= NULL
);
812 This notification function will be called when a Package List is removed
813 using UEFI HII interface. The Package List removed need to be removed from
814 Framework Thunk module too.
816 If the Package List registered is not Sting Package,
817 then ASSERT. If the NotifyType is not REMOVE_PACK, then ASSERT.
818 Both cases means UEFI HII Database itself is buggy.
820 @param PackageType The Package Type.
821 @param PackageGuid The Package GUID.
822 @param Package The Package Header.
823 @param Handle The HII Handle of this Package List.
824 @param NotifyType The reason of the notification.
826 @retval EFI_SUCCESS The notification function is successful.
832 IN UINT8 PackageType
,
833 IN CONST EFI_GUID
*PackageGuid
,
834 IN CONST EFI_HII_PACKAGE_HEADER
*Package
,
835 IN EFI_HII_HANDLE Handle
,
836 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
840 HII_THUNK_PRIVATE_DATA
*Private
;
841 HII_THUNK_CONTEXT
*ThunkContext
;
842 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
845 Status
= EFI_SUCCESS
;
847 ASSERT (PackageType
== EFI_HII_PACKAGE_STRINGS
);
848 ASSERT (NotifyType
== EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
);
850 if (mInFrameworkHiiRemovePack
|| mInFrameworkUpdatePakcage
) {
854 Private
= mHiiThunkPrivateData
;
856 ThunkContext
= UefiHiiHandleToThunkContext (Private
, Handle
);
859 // BugBug: Change to ASSERT if HII Database fix the bug and to also invoke
860 // NEW_PACK_NOTIFY for package (String Package) created internally.
862 if (ThunkContext
!= NULL
) {
863 if (!ThunkContext
->ByFrameworkHiiNewPack
) {
864 Status
= HiiLibExportPackageLists (Handle
, &HiiPackageList
, &BufferSize
);
865 ASSERT_EFI_ERROR (Status
);
867 if (GetPackageCountByType (HiiPackageList
, EFI_HII_PACKAGE_STRINGS
) == 1) {
869 // If the string package will be removed is the last string package
870 // in the package list, we will remove the HII Thunk entry from the
873 DestroyThunkContextForUefiHiiHandle (Private
, Handle
);
876 FreePool (HiiPackageList
);