]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Package.c
Fix a bug in BuidHobGuidType() of PeiHobLib that it does not adjust the hob length...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Package.c
1 /**@file
2 Implement protocol interface related to package registrations.
3
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
9
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.
12
13 **/
14
15
16 #include "HiiDatabase.h"
17 #include "HiiHandle.h"
18
19
20 BOOLEAN mInFrameworkHiiNewPack = FALSE;
21 BOOLEAN mInFrameworkHiiRemovePack = FALSE;
22 BOOLEAN mInFrameworkUpdatePakcage = FALSE;
23 UINT64 mGuidCount = 0;
24
25 EFI_GUID mGuidBase = { 0x14f95e01, 0xd562, 0x432e, { 0x84, 0x4a, 0x95, 0xa4, 0x39, 0x5, 0x10, 0x7e }};
26
27
28
29 /**
30 Get the number of package IFR and STRING packages in the package list passed in.
31
32 @param Packages Package List.
33 @param IfrPackageCount Number of IFR Packages.
34 @param StringPackageCount Number of String Packages.
35
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.
39
40
41 **/
42 EFI_STATUS
43 GetPackageCount (
44 IN CONST EFI_HII_PACKAGES *Packages,
45 OUT UINTN *IfrPackageCount,
46 OUT UINTN *StringPackageCount,
47 OUT UINTN *FontPackageCount
48 )
49 {
50 UINTN Index;
51 TIANO_AUTOGEN_PACKAGES_HEADER **TianoAutogenPackageHdrArray;
52
53 ASSERT (Packages != NULL);
54 ASSERT (IfrPackageCount != NULL);
55 ASSERT (StringPackageCount != NULL);
56 ASSERT (FontPackageCount != NULL);
57
58 *IfrPackageCount = 0;
59 *StringPackageCount = 0;
60 *FontPackageCount = 0;
61
62 TianoAutogenPackageHdrArray = (TIANO_AUTOGEN_PACKAGES_HEADER **) (((UINT8 *) &Packages->GuidId) + sizeof (Packages->GuidId));
63
64 for (Index = 0; Index < Packages->NumberOfPackages; Index++) {
65 //
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
70 // by HII Build tool.
71 //
72 switch (TianoAutogenPackageHdrArray[Index]->FrameworkPackageHeader.Type) {
73 case EFI_HII_IFR:
74 *IfrPackageCount += 1;
75 break;
76 case EFI_HII_STRING:
77 *StringPackageCount += 1;
78 break;
79
80 case EFI_HII_FONT:
81 *FontPackageCount += 1;
82 break;
83
84 //
85 // The following fonts are invalid for a module that using Framework to UEFI thunk layer.
86 //
87 default:
88 ASSERT (FALSE);
89 return EFI_INVALID_PARAMETER;
90 break;
91 }
92 }
93
94 return EFI_SUCCESS;
95 }
96
97 /**
98 Insert the String Package into the Package Lists which has the TAG GUID matching
99 the PackageListGuid of the String Package.
100
101 The Package List must have only IFR Package and no String Package.
102 Otherwise, ASSERT.
103
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.
107
108 **/
109 VOID
110 UpdatePackListWithOnlyIfrPack (
111 IN HII_THUNK_PRIVATE_DATA *Private,
112 IN HII_THUNK_CONTEXT *StringPackageThunkContext,
113 IN CONST EFI_HII_PACKAGE_LIST_HEADER *StringPackageListHeader
114 )
115 {
116 EFI_STATUS Status;
117 LIST_ENTRY *Link;
118 HII_THUNK_CONTEXT *ThunkContext;
119
120 Link = GetFirstNode (&Private->ThunkContextListHead);
121 while (!IsNull (&Private->ThunkContextListHead, Link)) {
122
123 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
124
125 if (StringPackageThunkContext != ThunkContext) {
126 //
127 // Skip the String Package Thunk Entry itself.
128 //
129
130 if (CompareGuid (&StringPackageListHeader->PackageListGuid, &ThunkContext->TagGuid)) {
131
132 ASSERT (ThunkContext->StringPackageCount == 0 && ThunkContext->IfrPackageCount == 1);
133
134 ThunkContext->StringPackageCount = GetPackageCountByType (StringPackageListHeader, EFI_HII_PACKAGE_STRINGS);
135
136 Status = mHiiDatabase->UpdatePackageList (
137 mHiiDatabase,
138 ThunkContext->UefiHiiHandle,
139 StringPackageListHeader
140 );
141 ASSERT_EFI_ERROR (Status);
142
143 ThunkContext->SharingStringPack = TRUE;
144 StringPackageThunkContext->SharingStringPack = TRUE;
145
146 }
147 }
148
149 Link = GetNextNode (&Private->ThunkContextListHead, Link);
150 }
151
152 }
153
154 /**
155 Caculate the size of UEFI Simple Font Package that is needed to
156 convert all the font a Framework Font Paackage.
157
158 ONLY Narrow Font is supported. Wide Font is discarded.
159
160 If the Package Header is not of EFI_HII_FONT type, then ASSERT.
161
162 @param The Package header of the Framework Font Package.
163
164 @return The size of the UEFI Simple Font Package.
165
166 **/
167 UINTN
168 GetUefiSimpleFontPackSize (
169 IN CONST EFI_HII_PACK_HEADER * PackHeader
170 )
171 {
172 UINTN Size;
173 EFI_HII_FONT_PACK *FwFontPack;
174
175 FwFontPack = (EFI_HII_FONT_PACK *) PackHeader;
176
177 ASSERT (FwFontPack->Header.Type == EFI_HII_FONT);
178
179 Size = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR)
180 + (FwFontPack->NumberOfNarrowGlyphs * sizeof (EFI_NARROW_GLYPH));
181
182 return Size;
183 }
184
185
186 /**
187 Convert Font Package in Framework format to a newly allocated UEFI
188 Simple Font Package.
189
190 ONLY Narrow Font is supported. Wide Font is discarded.
191
192 If memory allocation fails, then ASSERT.
193
194 @param FwFontPack Framework Font Package.
195
196 @reture UEFI Simple Font Package.
197 **/
198 EFI_HII_SIMPLE_FONT_PACKAGE_HDR *
199 FrameworkFontPackToUefiSimpliedFont (
200 IN CONST EFI_HII_PACK_HEADER * PackHeader
201 )
202 {
203 EFI_HII_SIMPLE_FONT_PACKAGE_HDR *FontPack;
204 UINTN Size;
205 EFI_NARROW_GLYPH *FwNarrowGlyph;
206 EFI_NARROW_GLYPH *NarrowGlyph;
207 UINTN Idx;
208 EFI_HII_FONT_PACK *FwFontPack;
209
210 Size = GetUefiSimpleFontPackSize (PackHeader);
211
212 FwFontPack = (EFI_HII_FONT_PACK *) PackHeader;
213
214 FontPack = AllocateZeroPool (Size);
215 ASSERT (FontPack != NULL);
216
217 //
218 // Prepare the Header information.
219 //
220 FontPack->Header.Length = (UINT32) Size;
221 FontPack->Header.Type = EFI_HII_PACKAGE_SIMPLE_FONTS;
222
223 FontPack->NumberOfNarrowGlyphs = FwFontPack->NumberOfNarrowGlyphs;
224
225 //
226 // ONLY Narrow Font is supported. Wide Font is discarded.
227 //
228 FontPack->NumberOfWideGlyphs = 0;
229
230 //
231 // Copy Narrow Glyph
232 //
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++) {
237 //
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
240 //
241 NarrowGlyph[Idx].Attributes = (UINT8) (NarrowGlyph[Idx].Attributes & ~(EFI_GLYPH_WIDE));
242 }
243
244 return FontPack;
245 }
246
247 /**
248 Prepare a UEFI Package List from a Framework HII package list registered
249 from a Framework HII NewPack () function.
250
251 If either Packages or PackageListGuid is NULL, then ASSERT.
252
253 @param Packages The Framework HII Package List.
254 @param PackageListGuid The Package List GUID.
255
256
257 @return The UEFI Package List.
258 **/
259 EFI_HII_PACKAGE_LIST_HEADER *
260 PrepareUefiPackageListFromFrameworkHiiPackages (
261 IN CONST EFI_HII_PACKAGES *Packages,
262 IN CONST EFI_GUID *PackageListGuid
263 )
264 {
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;
271 UINTN Index;
272 TIANO_AUTOGEN_PACKAGES_HEADER **TianoAutogenPackageHdrArray;
273 EFI_HII_SIMPLE_FONT_PACKAGE_HDR *FontPack;
274
275
276 ASSERT (Packages != NULL);
277 ASSERT (PackageListGuid != NULL);
278
279 TianoAutogenPackageHdrArray = (TIANO_AUTOGEN_PACKAGES_HEADER **) ((UINT8 *) &Packages->GuidId + sizeof (Packages->GuidId));
280 NumberOfPackages = Packages->NumberOfPackages;
281
282 PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
283
284 for (Index = 0; Index < NumberOfPackages; Index++) {
285 if (TianoAutogenPackageHdrArray[Index]->FrameworkPackageHeader.Type == EFI_HII_FONT) {
286 //
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.
292 //
293 PackageListLength = (UINT32) (PackageListLength + GetUefiSimpleFontPackSize (&TianoAutogenPackageHdrArray[Index]->FrameworkPackageHeader));
294
295 } else {
296 //
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.
300 //
301 CopyMem (&PackageLength, &TianoAutogenPackageHdrArray[Index]->FrameworkPackageHeader.Length, sizeof (UINT32));
302 //
303 // EFI_HII_PACK_HEADER.FrameworkPackageHeader.Length include the sizeof FrameworkPackageHeader itself.
304 //
305 PackageListLength += (PackageLength - sizeof(EFI_HII_PACK_HEADER));
306
307 }
308 }
309
310 //
311 // Include the lenght of EFI_HII_PACKAGE_END
312 //
313 PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER);
314 PackageListHeader = AllocateZeroPool (PackageListLength);
315 ASSERT (PackageListHeader != NULL);
316
317 CopyMem (&PackageListHeader->PackageListGuid, PackageListGuid, sizeof (EFI_GUID));
318 PackageListHeader->PackageLength = PackageListLength;
319
320 PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER);
321
322 //
323 // Build the UEFI Package List.
324 //
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);
330 FreePool (FontPack);
331
332 } else {
333 CopyMem (&PackageLength, &(TianoAutogenPackageHdrArray[Index]->FrameworkPackageHeader.Length), sizeof (UINT32));
334 PackageLength -= sizeof (EFI_HII_PACK_HEADER);
335 CopyMem (PackageListData, &(TianoAutogenPackageHdrArray[Index]->PackageHeader), PackageLength);
336
337 }
338 PackageListData += PackageLength;
339 }
340
341 //
342 // Append EFI_HII_PACKAGE_END
343 //
344 PackageHeader.Type = EFI_HII_PACKAGE_END;
345 PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER);
346 CopyMem (PackageListData, &PackageHeader, PackageHeader.Length);
347
348 return PackageListHeader;
349 }
350
351
352 /**
353 Generate a Random GUID.
354
355 @param Guid On output, a Random GUID will be filled.
356
357 **/
358 VOID
359 GenerateRandomGuid (
360 OUT EFI_GUID * Guid
361 )
362 {
363 CopyGuid (Guid, &mGuidBase);
364
365 mGuidCount++;
366 *((UINT64 *) Guid) = *((UINT64 *) Guid) + mGuidCount;
367 }
368
369 /**
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.
373
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.
376
377 @param Private The HII THUNK driver context data.
378 @param IfrThunkContext Package List with only a IFR package.
379
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.
383 **/
384 EFI_STATUS
385 FindStringPackAndUpdatePackListWithOnlyIfrPack (
386 IN HII_THUNK_PRIVATE_DATA *Private,
387 IN HII_THUNK_CONTEXT *IfrThunkContext
388 )
389 {
390 EFI_STATUS Status;
391 LIST_ENTRY *Link;
392 EFI_HII_PACKAGE_LIST_HEADER *StringPackageListHeader;
393 UINTN Size;
394 HII_THUNK_CONTEXT *ThunkContext;
395
396 Link = GetFirstNode (&Private->ThunkContextListHead);
397
398 while (!IsNull (&Private->ThunkContextListHead, Link)) {
399
400 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
401
402 if (ThunkContext != IfrThunkContext) {
403 if (CompareGuid (&IfrThunkContext->TagGuid, &ThunkContext->TagGuid) && (ThunkContext->IfrPackageCount == 0)) {
404 Status = ExportPackageLists (ThunkContext->UefiHiiHandle, &StringPackageListHeader, &Size);
405 ASSERT_EFI_ERROR (Status);
406
407 IfrThunkContext->StringPackageCount = GetPackageCountByType (StringPackageListHeader, EFI_HII_PACKAGE_STRINGS);
408 //
409 // Add Function to only get only String Packages from the Package List
410 //
411 Status = mHiiDatabase->UpdatePackageList (
412 mHiiDatabase,
413 IfrThunkContext->UefiHiiHandle,
414 StringPackageListHeader
415 );
416 ASSERT_EFI_ERROR (Status);
417
418 FreePool (StringPackageListHeader);
419
420 IfrThunkContext->SharingStringPack = TRUE;
421 ThunkContext->SharingStringPack = TRUE;
422
423 return EFI_SUCCESS;
424
425 }
426 }
427
428 Link = GetNextNode (&Private->ThunkContextListHead, Link);
429 }
430
431 //
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.
435 //
436 ASSERT (FALSE);
437 return EFI_NOT_FOUND;
438
439 }
440
441
442 /**
443 Register the Package List passed from the Framework HII NewPack () interface.
444 The FRAMEWORK_EFI_HII_HANDLE will be returned.
445
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
451 returned.
452
453 @retval EFI_SUCCESS The Package List is registered successfull in
454 the database.
455 @retval EFI_UNSUPPORTED The number of IFR package in the package list
456 is greater than 1.
457 @retval EFI_OUT_OF_RESOURCE Not enough resouce.
458
459 **/
460 EFI_STATUS
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
466 )
467 {
468 EFI_STATUS Status;
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;
475 EFI_GUID GuidId;
476 EFI_HII_PACKAGE_HEADER *IfrPackage;
477
478 PackageListHeader = NULL;
479
480 Status = GetPackageCount (Packages, &IfrPackageCount, &StringPackageCount, &FontPackageCount);
481 ASSERT_EFI_ERROR (Status);
482
483 if (IfrPackageCount > 1) {
484 //
485 // HII Thunk only handle package with 0 or 1 IFR package.
486 //
487 ASSERT (FALSE);
488 return EFI_UNSUPPORTED;
489 }
490
491 ThunkContext = CreateThunkContext (Private, StringPackageCount, IfrPackageCount);
492 if (ThunkContext == NULL) {
493 return EFI_OUT_OF_RESOURCES;
494 }
495 ThunkContext->ByFrameworkHiiNewPack = TRUE;
496
497 if (Packages->GuidId == NULL) {
498 //
499 // UEFI HII Database require Package List GUID must be unique.
500 //
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
504 // GUID instead.
505 //
506 ASSERT ((StringPackageCount >=1 && IfrPackageCount == 1) || (FontPackageCount > 0));
507 if (IfrPackageCount > 0) {
508 IfrPackage = GetIfrPackage (Packages);
509 GetFormSetGuid (IfrPackage, &ThunkContext->TagGuid);
510 } else {
511 ASSERT (FontPackageCount > 0);
512 GenerateRandomGuid (&ThunkContext->TagGuid);
513 }
514
515 } else {
516 ThunkContextToRemove = TagGuidToIfrPackThunkContext (Private, Packages->GuidId);
517
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);
524 }
525 CopyGuid (&ThunkContext->TagGuid, Packages->GuidId);
526
527 }
528
529 //
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.
534 //
535 if (IfrPackageCount != 0) {
536 InstallDefaultConfigAccessProtocol (Packages, ThunkContext);
537 }
538
539 PackageListHeader = PrepareUefiPackageListFromFrameworkHiiPackages (Packages, &ThunkContext->TagGuid);
540 Status = mHiiDatabase->NewPackageList (
541 mHiiDatabase,
542 PackageListHeader,
543 ThunkContext->UefiHiiDriverHandle,
544 &ThunkContext->UefiHiiHandle
545 );
546 if (Status == EFI_INVALID_PARAMETER) {
547 FreePool (PackageListHeader);
548
549 //
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.
553 //
554 GenerateRandomGuid (&GuidId);
555
556 PackageListHeader = PrepareUefiPackageListFromFrameworkHiiPackages (Packages, &GuidId);
557 Status = mHiiDatabase->NewPackageList (
558 mHiiDatabase,
559 PackageListHeader,
560 ThunkContext->UefiHiiDriverHandle,
561 &ThunkContext->UefiHiiHandle
562 );
563 }
564
565 //
566 // BUGBUG: Remove when development is done
567 //
568 ASSERT_EFI_ERROR (Status);
569 if (EFI_ERROR (Status)) {
570 goto Done;
571 }
572
573 if (IfrPackageCount == 0) {
574 if (StringPackageCount != 0) {
575 //
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.
580 //
581 UpdatePackListWithOnlyIfrPack (
582 Private,
583 ThunkContext,
584 PackageListHeader
585 );
586 }
587 } else {
588 if (StringPackageCount == 0) {
589 //
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.
594 //
595 Status = FindStringPackAndUpdatePackListWithOnlyIfrPack (
596 Private,
597 ThunkContext
598 );
599
600 if (EFI_ERROR (Status)) {
601 goto Done;
602 }
603 }
604
605 //
606 // Parse the Formset. Must be called after FindStringPackAndUpdatePackListWithOnlyIfrPack is called so
607 // that String Package is ready.
608 //
609 ThunkContext->FormSet = ParseFormSet (ThunkContext->UefiHiiHandle);
610 ASSERT (ThunkContext->FormSet != NULL);
611
612 }
613
614 Done:
615 if (EFI_ERROR (Status)) {
616 DestroyThunkContext (ThunkContext);
617 } else {
618 InsertTailList (&Private->ThunkContextListHead, &ThunkContext->Link);
619 *Handle = ThunkContext->FwHiiHandle;
620 }
621
622 if (PackageListHeader != NULL) {
623 FreePool (PackageListHeader);
624 }
625
626 return Status;
627 }
628
629
630 /**
631
632 Registers the various packages that are passed in a Package List.
633
634 @param This Pointer of Frameowk HII protocol instance.
635 @param Packages Pointer of HII packages.
636 @param Handle Handle value to be returned.
637
638 @retval EFI_SUCCESS Pacakges has added to HII database successfully.
639 @retval EFI_INVALID_PARAMETER If Handle or Packages is NULL.
640
641 **/
642 EFI_STATUS
643 EFIAPI
644 HiiNewPack (
645 IN EFI_HII_PROTOCOL *This,
646 IN EFI_HII_PACKAGES *Packages,
647 OUT FRAMEWORK_EFI_HII_HANDLE *Handle
648 )
649 {
650 EFI_STATUS Status;
651 HII_THUNK_PRIVATE_DATA *Private;
652 EFI_TPL OldTpl;
653
654 if (Handle == NULL) {
655 return EFI_INVALID_PARAMETER;
656 }
657
658 if (Packages == NULL) {
659 return EFI_INVALID_PARAMETER;
660 }
661
662 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
663
664 //
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.
669 //
670 mInFrameworkHiiNewPack = TRUE;
671
672 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
673
674 Status = UefiRegisterPackageList (
675 This,
676 Private,
677 Packages,
678 Handle
679 );
680
681 mInFrameworkHiiNewPack = FALSE;
682
683 gBS->RestoreTPL (OldTpl);
684
685 return Status;
686 }
687
688 /**
689
690 Remove a package from the HII database.
691
692 @param This Pointer of Frameowk HII protocol instance.
693 @param Handle Handle value to be removed.
694
695 @retval EFI_SUCCESS Pacakges has added to HII database successfully.
696 @retval EFI_INVALID_PARAMETER If Handle or Packages is NULL.
697
698 **/
699 EFI_STATUS
700 EFIAPI
701 HiiRemovePack (
702 IN EFI_HII_PROTOCOL *This,
703 IN FRAMEWORK_EFI_HII_HANDLE Handle
704 )
705 {
706 EFI_STATUS Status;
707 HII_THUNK_PRIVATE_DATA *Private;
708 HII_THUNK_CONTEXT *ThunkContext;
709 EFI_TPL OldTpl;
710
711 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
712
713 mInFrameworkHiiRemovePack = TRUE;
714
715 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
716
717 ThunkContext = FwHiiHandleToThunkContext (Private, Handle);
718
719 if (ThunkContext != NULL) {
720 Status = mHiiDatabase->RemovePackageList (
721 mHiiDatabase,
722 ThunkContext->UefiHiiHandle
723 );
724 ASSERT_EFI_ERROR (Status);
725
726 if (ThunkContext->IfrPackageCount != 0) {
727 UninstallDefaultConfigAccessProtocol (ThunkContext);
728 }
729
730 DestroyThunkContext (ThunkContext);
731 }else {
732 Status = EFI_NOT_FOUND;
733 }
734
735 mInFrameworkHiiRemovePack = FALSE;
736 gBS->RestoreTPL (OldTpl);
737
738 return Status;
739 }
740
741 /**
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.
746
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.
750
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.
756
757 @retval EFI_SUCCESS The notification function is successful.
758
759 **/
760 EFI_STATUS
761 EFIAPI
762 NewOrAddPackNotify (
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
768 )
769 {
770 EFI_STATUS Status;
771 HII_THUNK_PRIVATE_DATA *Private;
772 HII_THUNK_CONTEXT *ThunkContext;
773
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);
776
777 Status = EFI_SUCCESS;
778 Private = mHiiThunkPrivateData;
779
780 if (mInFrameworkHiiNewPack || mInFrameworkUpdatePakcage) {
781 return EFI_SUCCESS;
782 }
783
784 //
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.
787 //
788 ThunkContext = UefiHiiHandleToThunkContext (Private, Handle);
789 if (ThunkContext == NULL) {
790 ThunkContext = CreateThunkContextForUefiHiiHandle (Handle);
791 ASSERT (ThunkContext != NULL);
792
793 InsertTailList (&Private->ThunkContextListHead, &ThunkContext->Link);
794 }
795
796 if (PackageType == EFI_HII_PACKAGE_FORMS) {
797 if (ThunkContext->FormSet != NULL) {
798 DestroyFormSet (ThunkContext->FormSet);
799 }
800
801 //
802 // Reparse the FormSet.
803 //
804 ThunkContext->FormSet = ParseFormSet (ThunkContext->UefiHiiHandle);
805 ASSERT (ThunkContext->FormSet != NULL);
806 }
807
808 return Status;
809 }
810
811 /**
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.
815
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.
819
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.
825
826 @retval EFI_SUCCESS The notification function is successful.
827
828 **/
829 EFI_STATUS
830 EFIAPI
831 RemovePackNotify (
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
837 )
838 {
839 EFI_STATUS Status;
840 HII_THUNK_PRIVATE_DATA *Private;
841 HII_THUNK_CONTEXT *ThunkContext;
842 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
843 UINTN BufferSize;
844
845 Status = EFI_SUCCESS;
846
847 ASSERT (PackageType == EFI_HII_PACKAGE_STRINGS);
848 ASSERT (NotifyType == EFI_HII_DATABASE_NOTIFY_REMOVE_PACK);
849
850 if (mInFrameworkHiiRemovePack || mInFrameworkUpdatePakcage) {
851 return EFI_SUCCESS;
852 }
853
854 Private = mHiiThunkPrivateData;
855
856 ThunkContext = UefiHiiHandleToThunkContext (Private, Handle);
857
858 //
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.
861 //
862 if (ThunkContext != NULL) {
863 if (!ThunkContext->ByFrameworkHiiNewPack) {
864 Status = ExportPackageLists (Handle, &HiiPackageList, &BufferSize);
865 ASSERT_EFI_ERROR (Status);
866
867 if (GetPackageCountByType (HiiPackageList, EFI_HII_PACKAGE_STRINGS) == 1) {
868 //
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
871 // database.
872 //
873 DestroyThunkContextForUefiHiiHandle (Private, Handle);
874 }
875
876 FreePool (HiiPackageList);
877 }
878 }
879
880
881 return Status;
882 }
883
884
885