]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Package.c
fb664a292812068051fc035f120bc93c6f6bd17b
[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 StringPackageListHeader = NULL;
405 Status = ExportPackageLists (ThunkContext->UefiHiiHandle, &StringPackageListHeader, &Size);
406 ASSERT_EFI_ERROR (Status);
407 if (StringPackageListHeader == NULL) {
408 return EFI_NOT_FOUND;
409 }
410
411 IfrThunkContext->StringPackageCount = GetPackageCountByType (StringPackageListHeader, EFI_HII_PACKAGE_STRINGS);
412 //
413 // Add Function to only get only String Packages from the Package List
414 //
415 Status = mHiiDatabase->UpdatePackageList (
416 mHiiDatabase,
417 IfrThunkContext->UefiHiiHandle,
418 StringPackageListHeader
419 );
420 ASSERT_EFI_ERROR (Status);
421
422 FreePool (StringPackageListHeader);
423
424 IfrThunkContext->SharingStringPack = TRUE;
425 ThunkContext->SharingStringPack = TRUE;
426
427 return EFI_SUCCESS;
428
429 }
430 }
431
432 Link = GetNextNode (&Private->ThunkContextListHead, Link);
433 }
434
435 //
436 // A Form Package must have a String Package to function.
437 // If ASSERT here, check the sequence of call to Hii->NewPack.
438 // String Pack must be registered before Ifr Package is registered.
439 //
440 ASSERT (FALSE);
441 return EFI_NOT_FOUND;
442
443 }
444
445
446 /**
447 Register the Package List passed from the Framework HII NewPack () interface.
448 The FRAMEWORK_EFI_HII_HANDLE will be returned.
449
450 @param This The EFI_HII_PROTOCOL context data. Only used
451 to call HiiRemovePack.
452 @param Private The HII THUNK driver context data.
453 @param Package Package List.
454 @param Handle On output, a FRAMEWORK_EFI_HII_HANDLE number is
455 returned.
456
457 @retval EFI_SUCCESS The Package List is registered successfull in
458 the database.
459 @retval EFI_UNSUPPORTED The number of IFR package in the package list
460 is greater than 1.
461 @retval EFI_OUT_OF_RESOURCE Not enough resouce.
462
463 **/
464 EFI_STATUS
465 UefiRegisterPackageList (
466 IN EFI_HII_PROTOCOL *This,
467 IN HII_THUNK_PRIVATE_DATA *Private,
468 IN EFI_HII_PACKAGES *Packages,
469 OUT FRAMEWORK_EFI_HII_HANDLE *Handle
470 )
471 {
472 EFI_STATUS Status;
473 UINTN StringPackageCount;
474 UINTN IfrPackageCount;
475 UINTN FontPackageCount;
476 EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;
477 HII_THUNK_CONTEXT *ThunkContext;
478 HII_THUNK_CONTEXT *ThunkContextToRemove;
479 EFI_GUID GuidId;
480 EFI_HII_PACKAGE_HEADER *IfrPackage;
481
482 PackageListHeader = NULL;
483
484 Status = GetPackageCount (Packages, &IfrPackageCount, &StringPackageCount, &FontPackageCount);
485 ASSERT_EFI_ERROR (Status);
486
487 if (IfrPackageCount > 1) {
488 //
489 // HII Thunk only handle package with 0 or 1 IFR package.
490 //
491 ASSERT (FALSE);
492 return EFI_UNSUPPORTED;
493 }
494
495 ThunkContext = CreateThunkContext (Private, StringPackageCount, IfrPackageCount);
496 if (ThunkContext == NULL) {
497 return EFI_OUT_OF_RESOURCES;
498 }
499 ThunkContext->ByFrameworkHiiNewPack = TRUE;
500
501 if (Packages->GuidId == NULL) {
502 //
503 // UEFI HII Database require Package List GUID must be unique.
504 //
505 // If Packages->GuidId is NULL, the caller of FramworkHii->NewPack is registering
506 // packages with at least 1 StringPack and 1 IfrPack. Therefore, Packages->GuidId is
507 // not used as the name of the package list. Formset GUID is used as the Package List
508 // GUID instead.
509 //
510 ASSERT ((StringPackageCount >=1 && IfrPackageCount == 1) || (FontPackageCount > 0));
511 if (IfrPackageCount > 0) {
512 IfrPackage = GetIfrPackage (Packages);
513 if (IfrPackage == NULL) {
514 Status = EFI_NOT_FOUND;
515 goto Done;
516 }
517 GetFormSetGuid (IfrPackage, &ThunkContext->TagGuid);
518 } else {
519 ASSERT (FontPackageCount > 0);
520 GenerateRandomGuid (&ThunkContext->TagGuid);
521 }
522
523 } else {
524 ThunkContextToRemove = TagGuidToIfrPackThunkContext (Private, Packages->GuidId);
525
526 if (IfrPackageCount > 0 &&
527 StringPackageCount > 0 &&
528 (ThunkContextToRemove != NULL)) {
529 DEBUG((EFI_D_WARN, "Framework code registers HII package list with the same GUID more than once.\n"));
530 DEBUG((EFI_D_WARN, "Remove the previously registered package list and register the new one.\n"));
531 HiiRemovePack (This, ThunkContextToRemove->FwHiiHandle);
532 }
533 CopyGuid (&ThunkContext->TagGuid, Packages->GuidId);
534
535 }
536
537 //
538 // UEFI HII require EFI_HII_CONFIG_ACCESS_PROTOCOL to be installed on a EFI_HANDLE, so
539 // that Setup Utility can load the Buffer Storage using this protocol. An UEFI VFR can only
540 // produce IFR package generated with Buffer Storage type and EFI Variable Storage.
541 // The default EFI_HII_CONFIG_ACCESS_PROTOCOL is used to Get/Set the Buffer Storage.
542 //
543 if (IfrPackageCount != 0) {
544 InstallDefaultConfigAccessProtocol (Packages, ThunkContext);
545 }
546
547 PackageListHeader = PrepareUefiPackageListFromFrameworkHiiPackages (Packages, &ThunkContext->TagGuid);
548 Status = mHiiDatabase->NewPackageList (
549 mHiiDatabase,
550 PackageListHeader,
551 ThunkContext->UefiHiiDriverHandle,
552 &ThunkContext->UefiHiiHandle
553 );
554 if (Status == EFI_INVALID_PARAMETER) {
555 FreePool (PackageListHeader);
556
557 //
558 // UEFI HII database does not allow two package list with the same GUID.
559 // In Framework HII implementation, Packages->GuidId is used as an identifier to associate
560 // a PackageList with only IFR to a Package list the with String package.
561 //
562 GenerateRandomGuid (&GuidId);
563
564 PackageListHeader = PrepareUefiPackageListFromFrameworkHiiPackages (Packages, &GuidId);
565 Status = mHiiDatabase->NewPackageList (
566 mHiiDatabase,
567 PackageListHeader,
568 ThunkContext->UefiHiiDriverHandle,
569 &ThunkContext->UefiHiiHandle
570 );
571 }
572
573 //
574 // BUGBUG: Remove when development is done
575 //
576 ASSERT_EFI_ERROR (Status);
577 if (EFI_ERROR (Status)) {
578 goto Done;
579 }
580
581 if (IfrPackageCount == 0) {
582 if (StringPackageCount != 0) {
583 //
584 // Look for a Package List with only IFR Package with the same TAG GUID name.
585 // If found one, add the String Packages to the found Package List.
586 // This is needed because Framework HII Module may not register the String Package
587 // and IFR Package in one NewPack () call.
588 //
589 UpdatePackListWithOnlyIfrPack (
590 Private,
591 ThunkContext,
592 PackageListHeader
593 );
594 }
595 } else {
596 if (StringPackageCount == 0) {
597 //
598 // Look for the String Package with the same TAG GUID name and add
599 // the found String Package to this Package List.
600 // This is needed because Framework HII Module may not register the String Package
601 // and IFR Package in one NewPack () call.
602 //
603 Status = FindStringPackAndUpdatePackListWithOnlyIfrPack (
604 Private,
605 ThunkContext
606 );
607
608 if (EFI_ERROR (Status)) {
609 goto Done;
610 }
611 }
612
613 //
614 // Parse the Formset. Must be called after FindStringPackAndUpdatePackListWithOnlyIfrPack is called so
615 // that String Package is ready.
616 //
617 ThunkContext->FormSet = ParseFormSet (ThunkContext->UefiHiiHandle);
618 ASSERT (ThunkContext->FormSet != NULL);
619
620 }
621
622 Done:
623 if (EFI_ERROR (Status)) {
624 DestroyThunkContext (ThunkContext);
625 } else {
626 InsertTailList (&Private->ThunkContextListHead, &ThunkContext->Link);
627 *Handle = ThunkContext->FwHiiHandle;
628 }
629
630 if (PackageListHeader != NULL) {
631 FreePool (PackageListHeader);
632 }
633
634 return Status;
635 }
636
637
638 /**
639
640 Registers the various packages that are passed in a Package List.
641
642 @param This Pointer of Frameowk HII protocol instance.
643 @param Packages Pointer of HII packages.
644 @param Handle Handle value to be returned.
645
646 @retval EFI_SUCCESS Pacakges has added to HII database successfully.
647 @retval EFI_INVALID_PARAMETER If Handle or Packages is NULL.
648
649 **/
650 EFI_STATUS
651 EFIAPI
652 HiiNewPack (
653 IN EFI_HII_PROTOCOL *This,
654 IN EFI_HII_PACKAGES *Packages,
655 OUT FRAMEWORK_EFI_HII_HANDLE *Handle
656 )
657 {
658 EFI_STATUS Status;
659 HII_THUNK_PRIVATE_DATA *Private;
660 EFI_TPL OldTpl;
661
662 if (Handle == NULL) {
663 return EFI_INVALID_PARAMETER;
664 }
665
666 if (Packages == NULL) {
667 return EFI_INVALID_PARAMETER;
668 }
669
670 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
671
672 //
673 // We use a simple Global variable to inform NewOrAddPackNotify()
674 // that the package list registered here is already registered
675 // in the HII Thunk Layer. So NewOrAddPackNotify () does not need to
676 // call registered the Package List again.
677 //
678 mInFrameworkHiiNewPack = TRUE;
679
680 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
681
682 Status = UefiRegisterPackageList (
683 This,
684 Private,
685 Packages,
686 Handle
687 );
688
689 mInFrameworkHiiNewPack = FALSE;
690
691 gBS->RestoreTPL (OldTpl);
692
693 return Status;
694 }
695
696 /**
697
698 Remove a package from the HII database.
699
700 @param This Pointer of Frameowk HII protocol instance.
701 @param Handle Handle value to be removed.
702
703 @retval EFI_SUCCESS Pacakges has added to HII database successfully.
704 @retval EFI_INVALID_PARAMETER If Handle or Packages is NULL.
705
706 **/
707 EFI_STATUS
708 EFIAPI
709 HiiRemovePack (
710 IN EFI_HII_PROTOCOL *This,
711 IN FRAMEWORK_EFI_HII_HANDLE Handle
712 )
713 {
714 EFI_STATUS Status;
715 HII_THUNK_PRIVATE_DATA *Private;
716 HII_THUNK_CONTEXT *ThunkContext;
717 EFI_TPL OldTpl;
718
719 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
720
721 mInFrameworkHiiRemovePack = TRUE;
722
723 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
724
725 ThunkContext = FwHiiHandleToThunkContext (Private, Handle);
726
727 if (ThunkContext != NULL) {
728 Status = mHiiDatabase->RemovePackageList (
729 mHiiDatabase,
730 ThunkContext->UefiHiiHandle
731 );
732 ASSERT_EFI_ERROR (Status);
733
734 if (ThunkContext->IfrPackageCount != 0) {
735 UninstallDefaultConfigAccessProtocol (ThunkContext);
736 }
737
738 DestroyThunkContext (ThunkContext);
739 }else {
740 Status = EFI_NOT_FOUND;
741 }
742
743 mInFrameworkHiiRemovePack = FALSE;
744 gBS->RestoreTPL (OldTpl);
745
746 return Status;
747 }
748
749 /**
750 This notification function will be called when a Package List is registered
751 using UEFI HII interface. The Package List registered need to be recorded in
752 Framework Thunk module as Thunk Module may need to look for String Package in
753 the package registered.
754
755 If the Package List registered is not either Sting Package or IFR package,
756 then ASSERT. If the NotifyType is not ADD_PACK or NEW_PACK, then ASSERT.
757 Both cases means UEFI HII Database itself is buggy.
758
759 @param PackageType The Package Type.
760 @param PackageGuid The Package GUID.
761 @param Package The Package Header.
762 @param Handle The HII Handle of this Package List.
763 @param NotifyType The reason of the notification.
764
765 @retval EFI_SUCCESS The notification function is successful.
766
767 **/
768 EFI_STATUS
769 EFIAPI
770 NewOrAddPackNotify (
771 IN UINT8 PackageType,
772 IN CONST EFI_GUID *PackageGuid,
773 IN CONST EFI_HII_PACKAGE_HEADER *Package,
774 IN EFI_HII_HANDLE Handle,
775 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
776 )
777 {
778 EFI_STATUS Status;
779 HII_THUNK_PRIVATE_DATA *Private;
780 HII_THUNK_CONTEXT *ThunkContext;
781
782 ASSERT (PackageType == EFI_HII_PACKAGE_STRINGS || PackageType == EFI_HII_PACKAGE_FORMS);
783 ASSERT (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK || NotifyType == EFI_HII_DATABASE_NOTIFY_NEW_PACK);
784
785 Status = EFI_SUCCESS;
786 Private = mHiiThunkPrivateData;
787
788 if (mInFrameworkHiiNewPack || mInFrameworkUpdatePakcage) {
789 return EFI_SUCCESS;
790 }
791
792 //
793 // We will create a ThunkContext to log the package list only if the
794 // package is not registered with by Framework HII Thunk module yet.
795 //
796 ThunkContext = UefiHiiHandleToThunkContext (Private, Handle);
797 if (ThunkContext == NULL) {
798 ThunkContext = CreateThunkContextForUefiHiiHandle (Handle);
799 ASSERT (ThunkContext != NULL);
800
801 InsertTailList (&Private->ThunkContextListHead, &ThunkContext->Link);
802 }
803
804 if (PackageType == EFI_HII_PACKAGE_FORMS) {
805 if (ThunkContext->FormSet != NULL) {
806 DestroyFormSet (ThunkContext->FormSet);
807 }
808
809 //
810 // Reparse the FormSet.
811 //
812 ThunkContext->FormSet = ParseFormSet (ThunkContext->UefiHiiHandle);
813 }
814
815 return Status;
816 }
817
818 /**
819 This notification function will be called when a Package List is removed
820 using UEFI HII interface. The Package List removed need to be removed from
821 Framework Thunk module too.
822
823 If the Package List registered is not Sting Package,
824 then ASSERT. If the NotifyType is not REMOVE_PACK, then ASSERT.
825 Both cases means UEFI HII Database itself is buggy.
826
827 @param PackageType The Package Type.
828 @param PackageGuid The Package GUID.
829 @param Package The Package Header.
830 @param Handle The HII Handle of this Package List.
831 @param NotifyType The reason of the notification.
832
833 @retval EFI_SUCCESS The notification function is successful.
834
835 **/
836 EFI_STATUS
837 EFIAPI
838 RemovePackNotify (
839 IN UINT8 PackageType,
840 IN CONST EFI_GUID *PackageGuid,
841 IN CONST EFI_HII_PACKAGE_HEADER *Package,
842 IN EFI_HII_HANDLE Handle,
843 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
844 )
845 {
846 EFI_STATUS Status;
847 HII_THUNK_PRIVATE_DATA *Private;
848 HII_THUNK_CONTEXT *ThunkContext;
849 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
850 UINTN BufferSize;
851
852 Status = EFI_SUCCESS;
853
854 ASSERT (PackageType == EFI_HII_PACKAGE_STRINGS);
855 ASSERT (NotifyType == EFI_HII_DATABASE_NOTIFY_REMOVE_PACK);
856
857 if (mInFrameworkHiiRemovePack || mInFrameworkUpdatePakcage) {
858 return EFI_SUCCESS;
859 }
860
861 Private = mHiiThunkPrivateData;
862
863 ThunkContext = UefiHiiHandleToThunkContext (Private, Handle);
864
865 //
866 // BugBug: Change to ASSERT if HII Database fix the bug and to also invoke
867 // NEW_PACK_NOTIFY for package (String Package) created internally.
868 //
869 if (ThunkContext != NULL) {
870 if (!ThunkContext->ByFrameworkHiiNewPack) {
871 HiiPackageList = NULL;
872 Status = ExportPackageLists (Handle, &HiiPackageList, &BufferSize);
873 ASSERT_EFI_ERROR (Status);
874 if (HiiPackageList == NULL) {
875 return EFI_NOT_FOUND;
876 }
877
878 if (GetPackageCountByType (HiiPackageList, EFI_HII_PACKAGE_STRINGS) == 1) {
879 //
880 // If the string package will be removed is the last string package
881 // in the package list, we will remove the HII Thunk entry from the
882 // database.
883 //
884 DestroyThunkContextForUefiHiiHandle (Private, Handle);
885 }
886
887 FreePool (HiiPackageList);
888 }
889 }
890
891
892 return Status;
893 }
894
895
896