2 Framework to UEFI 2.1 HII Thunk. The driver consume UEFI HII protocols
3 to produce a Framework HII protocol.
5 Copyright (c) 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "HiiDatabase.h"
17 #include "HiiHandle.h"
19 HII_THUNK_PRIVATE_DATA
*mHiiThunkPrivateData
;
21 HII_THUNK_PRIVATE_DATA mHiiThunkPrivateDataTempate
= {
22 HII_THUNK_PRIVATE_DATA_SIGNATURE
,
35 HiiGetPrimaryLanguages
,
36 HiiGetSecondaryLanguages
,
55 EFI_FORMBROWSER_THUNK_PRIVATE_DATA mBrowserThunkPrivateDataTemplate
= {
56 EFI_FORMBROWSER_THUNK_PRIVATE_DATA_SIGNATURE
,
58 (HII_THUNK_PRIVATE_DATA
*) NULL
,
66 CONST EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
67 CONST EFI_HII_IMAGE_PROTOCOL
*mHiiImageProtocol
;
68 CONST EFI_HII_STRING_PROTOCOL
*mHiiStringProtocol
;
69 CONST EFI_HII_FONT_PROTOCOL
*mHiiFontProtocol
;
70 CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRoutingProtocol
;
71 CONST EFI_FORM_BROWSER2_PROTOCOL
*mFormBrowser2Protocol
;
75 This routine initializes the HII Database.
77 @param ImageHandle Image handle for PCD DXE driver.
78 @param SystemTable Pointer to SystemTable.
80 @retval EFI_SUCCESS The entry point alwasy return successfully.
84 InitializeHiiDatabase (
85 IN EFI_HANDLE ImageHandle
,
86 IN EFI_SYSTEM_TABLE
*SystemTable
89 HII_THUNK_PRIVATE_DATA
*Private
;
93 EFI_HII_HANDLE
*Buffer
;
95 HII_THUNK_CONTEXT
*ThunkContext
;
98 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiHiiCompatibilityProtocolGuid
);
99 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiFormBrowserCompatibilityProtocolGuid
);
101 Private
= AllocateCopyPool (sizeof (HII_THUNK_PRIVATE_DATA
), &mHiiThunkPrivateDataTempate
);
102 ASSERT (Private
!= NULL
);
103 InitializeListHead (&Private
->ThunkContextListHead
);
105 InitHiiHandleDatabase ();
107 mHiiThunkPrivateData
= Private
;
109 Status
= gBS
->LocateProtocol (
110 &gEfiHiiDatabaseProtocolGuid
,
112 (VOID
**) &mHiiDatabase
114 ASSERT_EFI_ERROR (Status
);
116 Status
= gBS
->LocateProtocol (
117 &gEfiHiiStringProtocolGuid
,
119 (VOID
**) &mHiiStringProtocol
121 ASSERT_EFI_ERROR (Status
);
123 Status
= gBS
->LocateProtocol (
124 &gEfiHiiFontProtocolGuid
,
126 (VOID
**) &mHiiFontProtocol
128 ASSERT_EFI_ERROR (Status
);
130 Status
= gBS
->LocateProtocol (
131 &gEfiHiiConfigRoutingProtocolGuid
,
133 (VOID
**) &mHiiConfigRoutingProtocol
135 ASSERT_EFI_ERROR (Status
);
138 Status
= gBS
->LocateProtocol (
139 &gEfiFormBrowser2ProtocolGuid
,
141 (VOID
**) &mFormBrowser2Protocol
143 ASSERT_EFI_ERROR (Status
);
149 // Install protocol interface
151 Status
= gBS
->InstallProtocolInterface (
153 &gEfiHiiCompatibilityProtocolGuid
,
154 EFI_NATIVE_INTERFACE
,
155 (VOID
*) &Private
->Hii
157 ASSERT_EFI_ERROR (Status
);
159 Status
= ListPackageLists (EFI_HII_PACKAGE_STRINGS
, NULL
, &BufferLength
, &Buffer
);
160 if (Status
== EFI_SUCCESS
) {
161 for (Index
= 0; Index
< BufferLength
/ sizeof (EFI_HII_HANDLE
); Index
++) {
162 ThunkContext
= CreateThunkContextForUefiHiiHandle (Buffer
[Index
]);
163 ASSERT (ThunkContext
!= NULL
);
165 InsertTailList (&Private
->ThunkContextListHead
, &ThunkContext
->Link
);
171 Status
= mHiiDatabase
->RegisterPackageNotify (
173 EFI_HII_PACKAGE_STRINGS
,
176 EFI_HII_DATABASE_NOTIFY_NEW_PACK
,
179 ASSERT_EFI_ERROR (Status
);
181 Status
= mHiiDatabase
->RegisterPackageNotify (
183 EFI_HII_PACKAGE_STRINGS
,
186 EFI_HII_DATABASE_NOTIFY_ADD_PACK
,
189 ASSERT_EFI_ERROR (Status
);
191 Status
= mHiiDatabase
->RegisterPackageNotify (
193 EFI_HII_PACKAGE_FORMS
,
196 EFI_HII_DATABASE_NOTIFY_NEW_PACK
,
199 ASSERT_EFI_ERROR (Status
);
201 Status
= mHiiDatabase
->RegisterPackageNotify (
203 EFI_HII_PACKAGE_FORMS
,
206 EFI_HII_DATABASE_NOTIFY_ADD_PACK
,
209 ASSERT_EFI_ERROR (Status
);
211 Status
= mHiiDatabase
->RegisterPackageNotify (
213 EFI_HII_PACKAGE_STRINGS
,
216 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
219 ASSERT_EFI_ERROR (Status
);
221 InitSetBrowserStrings ();
223 mBrowserThunkPrivateDataTemplate
.ThunkPrivate
= Private
;
224 Status
= gBS
->InstallProtocolInterface (
225 &mBrowserThunkPrivateDataTemplate
.Handle
,
226 &gEfiFormBrowserCompatibilityProtocolGuid
,
227 EFI_NATIVE_INTERFACE
,
228 (VOID
*) &mBrowserThunkPrivateDataTemplate
.FormBrowser
230 ASSERT_EFI_ERROR (Status
);
236 Determines the handles that are currently active in the database.
238 This function determines the handles that are currently active in the database.
239 For example, a program wishing to create a Setup-like configuration utility would use this call
240 to determine the handles that are available. It would then use calls defined in the forms section
241 below to extract forms and then interpret them.
243 @param This A pointer to the EFI_HII_PROTOCOL instance.
244 @param HandleBufferLength On input, a pointer to the length of the handle buffer.
245 On output, the length of the handle buffer that is required for the handles found.
246 @param Handle An array of EFI_HII_HANDLE instances returned.
247 Type EFI_HII_HANDLE is defined in EFI_HII_PROTOCOL.NewPack() in the Packages section.
249 @retval EFI_SUCCESS Handle was updated successfully.
251 @retval EFI_BUFFER_TOO_SMALL The HandleBufferLength parameter indicates that Handle is too small
252 to support the number of handles. HandleBufferLength is updated with a value that
253 will enable the data to fit.
258 IN EFI_HII_PROTOCOL
*This
,
259 IN OUT UINT16
*HandleBufferLength
,
260 OUT FRAMEWORK_EFI_HII_HANDLE Handle
[1]
265 HII_THUNK_CONTEXT
*ThunkContext
;
266 HII_THUNK_PRIVATE_DATA
*Private
;
268 if (HandleBufferLength
== NULL
) {
269 return EFI_INVALID_PARAMETER
;
272 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
275 // Count the number of handles.
278 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
279 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
281 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
284 if (Count
> *HandleBufferLength
) {
285 *HandleBufferLength
= (UINT16
) (Count
* sizeof (FRAMEWORK_EFI_HII_HANDLE
));
286 return EFI_BUFFER_TOO_SMALL
;
290 // Output the handles.
293 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
294 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
296 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
297 Handle
[Count
] = ThunkContext
->FwHiiHandle
;
300 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
304 *HandleBufferLength
= (UINT16
) (Count
* sizeof (FRAMEWORK_EFI_HII_HANDLE
));
310 IN CHAR8
*LangCodes3066
,
311 IN CHAR8
**LangCodes639
314 CHAR8
*AsciiLangCodes
;
320 ASSERT (LangCodes3066
!= NULL
);
321 ASSERT (LangCodes639
!= NULL
);
324 // Allocate working buffer to contain substring of LangCodes3066.
326 Lang
= AllocatePool (AsciiStrSize (LangCodes3066
));
328 return EFI_OUT_OF_RESOURCES
;
332 // Count the number of RFC 3066 language codes.
335 AsciiLangCodes
= LangCodes3066
;
336 while (AsciiStrLen (AsciiLangCodes
) != 0) {
337 HiiLibGetNextLanguage (&AsciiLangCodes
, Lang
);
346 *LangCodes639
= AllocateZeroPool (ISO_639_2_ENTRY_SIZE
* Count
+ 1);
347 if (*LangCodes639
== NULL
) {
348 Status
= EFI_OUT_OF_RESOURCES
;
352 AsciiLangCodes
= LangCodes3066
;
354 for (Index
= 0; Index
< Count
; Index
++) {
355 HiiLibGetNextLanguage (&AsciiLangCodes
, Lang
);
356 Status
= ConvertRfc3066LanguageToIso639Language (Lang
, *LangCodes639
+ Index
* ISO_639_2_ENTRY_SIZE
);
357 ASSERT_EFI_ERROR (Status
);
360 Status
= EFI_SUCCESS
;
368 Allows a program to determine the primary languages that are supported on a given handle.
370 This routine is intended to be used by drivers to query the interface database for supported languages.
371 This routine returns a string of concatenated 3-byte language identifiers, one per string package associated with the handle.
373 @param This A pointer to the EFI_HII_PROTOCOL instance.
374 @param Handle The handle on which the strings reside. Type EFI_HII_HANDLE is defined in EFI_HII_PROTOCOL.NewPack()
375 in the Packages section.
376 @param LanguageString A string allocated by GetPrimaryLanguages() that contains a list of all primary languages
377 registered on the handle. The routine will not return the three-spaces language identifier used in
378 other functions to indicate non-language-specific strings.
380 @reval EFI_SUCCESS LanguageString was correctly returned.
382 @reval EFI_INVALID_PARAMETER The Handle was unknown.
386 HiiGetPrimaryLanguages (
387 IN EFI_HII_PROTOCOL
*This
,
388 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
389 OUT EFI_STRING
*LanguageString
392 HII_THUNK_PRIVATE_DATA
*Private
;
393 EFI_HII_HANDLE UefiHiiHandle
;
394 CHAR8
*LangCodes3066
;
395 CHAR16
*UnicodeLangCodes639
;
399 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
401 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
402 if (UefiHiiHandle
== NULL
) {
403 return EFI_INVALID_PARAMETER
;
406 LangCodes3066
= HiiGetSupportedLanguages (UefiHiiHandle
);
408 if (LangCodes3066
== NULL
) {
409 return EFI_INVALID_PARAMETER
;
414 Status
= LangCodes3066To639 (LangCodes3066
, &LangCodes639
);
415 if (EFI_ERROR (Status
)) {
419 UnicodeLangCodes639
= AllocateZeroPool (AsciiStrSize (LangCodes639
) * sizeof (CHAR16
));
420 if (UnicodeLangCodes639
== NULL
) {
421 Status
= EFI_OUT_OF_RESOURCES
;
426 // The language returned is in RFC 639-2 format.
428 AsciiStrToUnicodeStr (LangCodes639
, UnicodeLangCodes639
);
429 *LanguageString
= UnicodeLangCodes639
;
432 FreePool (LangCodes3066
);
433 if (LangCodes639
!= NULL
) {
434 FreePool (LangCodes639
);
441 This function returns the list of supported 2nd languages, in the format specified
442 in UEFI specification Appendix M.
444 If HiiHandle is not a valid Handle in the HII database, then ASSERT.
445 If not enough resource to complete the operation, then ASSERT.
447 @param HiiHandle The HII package list handle.
448 @param FirstLanguage Pointer to language name buffer.
450 @return The supported languages.
455 HiiGetSupportedSecondaryLanguages (
456 IN EFI_HII_HANDLE HiiHandle
,
457 IN CONST CHAR8
*FirstLanguage
462 CHAR8
*LanguageString
;
464 ASSERT (HiiHandle
!= NULL
);
467 // Collect current supported 2nd Languages for given HII handle
468 // First try allocate 4K buffer to store the current supported 2nd languages.
471 LanguageString
= AllocateZeroPool (BufferSize
);
472 if (LanguageString
== NULL
) {
476 Status
= mHiiStringProtocol
->GetSecondaryLanguages (mHiiStringProtocol
, HiiHandle
, FirstLanguage
, LanguageString
, &BufferSize
);
477 ASSERT (Status
!= EFI_NOT_FOUND
);
479 if (Status
== EFI_BUFFER_TOO_SMALL
) {
480 FreePool (LanguageString
);
481 LanguageString
= AllocateZeroPool (BufferSize
);
482 if (LanguageString
== NULL
) {
486 Status
= mHiiStringProtocol
->GetSecondaryLanguages (mHiiStringProtocol
, HiiHandle
, FirstLanguage
, LanguageString
, &BufferSize
);
489 if (EFI_ERROR (Status
)) {
490 LanguageString
= NULL
;
493 return LanguageString
;
497 Allows a program to determine which secondary languages are supported on a given handle for a given primary language
499 This routine is intended to be used by drivers to query the interface database for supported languages.
500 This routine returns a string of concatenated 3-byte language identifiers, one per string package associated with the handle.
502 @param This A pointer to the EFI_HII_PROTOCOL instance.
503 @param Handle The handle on which the strings reside. Type EFI_HII_HANDLE is defined in EFI_HII_PROTOCOL.NewPack()
504 in the Packages section.
505 @param PrimaryLanguage Pointer to a NULL-terminated string containing a single ISO 639-2 language identifier, indicating
506 the primary language.
507 @param LanguageString A string allocated by GetSecondaryLanguages() containing a list of all secondary languages registered
508 on the handle. The routine will not return the three-spaces language identifier used in other functions
509 to indicate non-language-specific strings, nor will it return the primary language. This function succeeds
510 but returns a NULL LanguageString if there are no secondary languages associated with the input Handle and
511 PrimaryLanguage pair. Type EFI_STRING is defined in String.
513 @reval EFI_SUCCESS LanguageString was correctly returned.
514 @reval EFI_INVALID_PARAMETER The Handle was unknown.
518 HiiGetSecondaryLanguages (
519 IN EFI_HII_PROTOCOL
*This
,
520 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
521 IN CHAR16
*PrimaryLanguage
,
522 OUT EFI_STRING
*LanguageString
525 HII_THUNK_PRIVATE_DATA
*Private
;
526 EFI_HII_HANDLE UefiHiiHandle
;
527 CHAR8
*PrimaryLang3066
;
528 CHAR8
*PrimaryLang639
;
529 CHAR8
*SecLangCodes3066
;
530 CHAR8
*SecLangCodes639
;
531 CHAR16
*UnicodeSecLangCodes639
;
534 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
536 SecLangCodes639
= NULL
;
537 SecLangCodes3066
= NULL
;
538 PrimaryLang3066
= NULL
;
539 UnicodeSecLangCodes639
= NULL
;
541 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
542 if (UefiHiiHandle
== NULL
) {
543 return EFI_INVALID_PARAMETER
;
546 PrimaryLang639
= AllocateZeroPool (StrLen (PrimaryLanguage
) + 1);
547 if (PrimaryLang639
== NULL
) {
548 Status
= EFI_OUT_OF_RESOURCES
;
552 UnicodeStrToAsciiStr (PrimaryLanguage
, PrimaryLang639
);
554 PrimaryLang3066
= ConvertIso639LanguageToRfc3066Language (PrimaryLang639
);
555 ASSERT_EFI_ERROR (PrimaryLang3066
!= NULL
);
557 SecLangCodes3066
= HiiGetSupportedSecondaryLanguages (UefiHiiHandle
, PrimaryLang3066
);
559 if (SecLangCodes3066
== NULL
) {
560 Status
= EFI_INVALID_PARAMETER
;
564 Status
= LangCodes3066To639 (SecLangCodes3066
, &SecLangCodes639
);
565 if (EFI_ERROR (Status
)) {
569 UnicodeSecLangCodes639
= AllocateZeroPool (AsciiStrSize (SecLangCodes639
) * sizeof (CHAR16
));
570 if (UnicodeSecLangCodes639
== NULL
) {
571 Status
= EFI_OUT_OF_RESOURCES
;
576 // The language returned is in RFC 3066 format.
578 *LanguageString
= AsciiStrToUnicodeStr (SecLangCodes639
, UnicodeSecLangCodes639
);
581 if (PrimaryLang639
!= NULL
) {
582 FreePool (PrimaryLang639
);
585 if (SecLangCodes639
!= NULL
) {
586 FreePool (SecLangCodes639
);
589 if (PrimaryLang3066
!= NULL
) {
590 FreePool (PrimaryLang3066
);
593 if (SecLangCodes3066
!= NULL
) {
594 FreePool (SecLangCodes3066
);
596 if (UnicodeSecLangCodes639
!= NULL
) {
597 FreePool (UnicodeSecLangCodes639
);