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
;
80 InitializeHiiDatabase (
81 IN EFI_HANDLE ImageHandle
,
82 IN EFI_SYSTEM_TABLE
*SystemTable
87 Initialize HII Database
90 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
93 EFI_SUCCESS - Setup loaded.
98 HII_THUNK_PRIVATE_DATA
*Private
;
102 EFI_HII_HANDLE
*Buffer
;
104 HII_THUNK_CONTEXT
*ThunkContext
;
107 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiHiiCompatibilityProtocolGuid
);
108 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiFormBrowserCompatibilityProtocolGuid
);
110 Private
= AllocateCopyPool (sizeof (HII_THUNK_PRIVATE_DATA
), &mHiiThunkPrivateDataTempate
);
111 ASSERT (Private
!= NULL
);
112 InitializeListHead (&Private
->ThunkContextListHead
);
114 InitHiiHandleDatabase ();
116 mHiiThunkPrivateData
= Private
;
118 Status
= gBS
->LocateProtocol (
119 &gEfiHiiDatabaseProtocolGuid
,
121 (VOID
**) &mHiiDatabase
123 ASSERT_EFI_ERROR (Status
);
125 Status
= gBS
->LocateProtocol (
126 &gEfiHiiStringProtocolGuid
,
128 (VOID
**) &mHiiStringProtocol
130 ASSERT_EFI_ERROR (Status
);
132 Status
= gBS
->LocateProtocol (
133 &gEfiHiiFontProtocolGuid
,
135 (VOID
**) &mHiiFontProtocol
137 ASSERT_EFI_ERROR (Status
);
139 Status
= gBS
->LocateProtocol (
140 &gEfiHiiConfigRoutingProtocolGuid
,
142 (VOID
**) &mHiiConfigRoutingProtocol
144 ASSERT_EFI_ERROR (Status
);
147 Status
= gBS
->LocateProtocol (
148 &gEfiFormBrowser2ProtocolGuid
,
150 (VOID
**) &mFormBrowser2Protocol
152 ASSERT_EFI_ERROR (Status
);
158 // Install protocol interface
160 Status
= gBS
->InstallProtocolInterface (
162 &gEfiHiiCompatibilityProtocolGuid
,
163 EFI_NATIVE_INTERFACE
,
164 (VOID
*) &Private
->Hii
166 ASSERT_EFI_ERROR (Status
);
168 Status
= HiiLibListPackageLists (EFI_HII_PACKAGE_STRINGS
, NULL
, &BufferLength
, &Buffer
);
169 if (Status
== EFI_SUCCESS
) {
170 for (Index
= 0; Index
< BufferLength
/ sizeof (EFI_HII_HANDLE
); Index
++) {
171 ThunkContext
= CreateThunkContextForUefiHiiHandle (Buffer
[Index
]);
172 ASSERT (ThunkContext
!= NULL
);
174 InsertTailList (&Private
->ThunkContextListHead
, &ThunkContext
->Link
);
180 Status
= mHiiDatabase
->RegisterPackageNotify (
182 EFI_HII_PACKAGE_STRINGS
,
185 EFI_HII_DATABASE_NOTIFY_NEW_PACK
,
188 ASSERT_EFI_ERROR (Status
);
190 Status
= mHiiDatabase
->RegisterPackageNotify (
192 EFI_HII_PACKAGE_STRINGS
,
195 EFI_HII_DATABASE_NOTIFY_ADD_PACK
,
198 ASSERT_EFI_ERROR (Status
);
200 Status
= mHiiDatabase
->RegisterPackageNotify (
202 EFI_HII_PACKAGE_FORMS
,
205 EFI_HII_DATABASE_NOTIFY_NEW_PACK
,
208 ASSERT_EFI_ERROR (Status
);
210 Status
= mHiiDatabase
->RegisterPackageNotify (
212 EFI_HII_PACKAGE_FORMS
,
215 EFI_HII_DATABASE_NOTIFY_ADD_PACK
,
218 ASSERT_EFI_ERROR (Status
);
220 Status
= mHiiDatabase
->RegisterPackageNotify (
222 EFI_HII_PACKAGE_STRINGS
,
225 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK
,
228 ASSERT_EFI_ERROR (Status
);
230 mBrowserThunkPrivateDataTemplate
.ThunkPrivate
= Private
;
231 Status
= gBS
->InstallProtocolInterface (
232 &mBrowserThunkPrivateDataTemplate
.Handle
,
233 &gEfiFormBrowserCompatibilityProtocolGuid
,
234 EFI_NATIVE_INTERFACE
,
235 (VOID
*) &mBrowserThunkPrivateDataTemplate
.FormBrowser
237 ASSERT_EFI_ERROR (Status
);
245 IN EFI_HII_PROTOCOL
*This
,
246 IN OUT UINT16
*HandleBufferLength
,
247 OUT FRAMEWORK_EFI_HII_HANDLE Handle
[1]
252 Determines the handles that are currently active in the database.
262 HII_THUNK_CONTEXT
*ThunkContext
;
263 HII_THUNK_PRIVATE_DATA
*Private
;
265 if (HandleBufferLength
== NULL
) {
266 return EFI_INVALID_PARAMETER
;
269 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
272 // Count the number of handles.
275 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
276 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
278 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
281 if (Count
> *HandleBufferLength
) {
282 *HandleBufferLength
= (Count
* sizeof (FRAMEWORK_EFI_HII_HANDLE
));
283 return EFI_BUFFER_TOO_SMALL
;
287 // Output the handles.
290 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
291 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
293 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
294 Handle
[Count
] = ThunkContext
->FwHiiHandle
;
297 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
301 *HandleBufferLength
= (Count
* sizeof (FRAMEWORK_EFI_HII_HANDLE
));
307 IN CHAR8
*LangCodes3066
,
308 IN CHAR8
**LangCodes639
311 CHAR8
*AsciiLangCodes
;
312 CHAR8 Lang
[RFC_3066_ENTRY_SIZE
];
317 ASSERT (LangCodes3066
!= NULL
);
318 ASSERT (LangCodes639
!= NULL
);
321 // Count the number of RFC 3066 language codes.
324 AsciiLangCodes
= LangCodes3066
;
325 while (AsciiStrLen (AsciiLangCodes
) != 0) {
326 HiiLibGetNextLanguage (&AsciiLangCodes
, Lang
);
335 *LangCodes639
= AllocateZeroPool (ISO_639_2_ENTRY_SIZE
* Count
+ 1);
336 if (*LangCodes639
== NULL
) {
337 return EFI_OUT_OF_RESOURCES
;
340 AsciiLangCodes
= LangCodes3066
;
342 for (Index
= 0; Index
< Count
; Index
++) {
343 HiiLibGetNextLanguage (&AsciiLangCodes
, Lang
);
344 Status
= ConvertRfc3066LanguageToIso639Language (Lang
, *LangCodes639
+ Index
* ISO_639_2_ENTRY_SIZE
);
345 ASSERT_EFI_ERROR (Status
);
353 HiiGetPrimaryLanguages (
354 IN EFI_HII_PROTOCOL
*This
,
355 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
356 OUT EFI_STRING
*LanguageString
362 This function allows a program to determine what the primary languages that are supported on a given handle.
370 HII_THUNK_PRIVATE_DATA
*Private
;
371 EFI_HII_HANDLE UefiHiiHandle
;
372 CHAR8
*LangCodes3066
;
373 CHAR16
*UnicodeLangCodes639
;
377 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
379 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
380 if (UefiHiiHandle
== NULL
) {
381 return EFI_INVALID_PARAMETER
;
384 LangCodes3066
= HiiLibGetSupportedLanguages (UefiHiiHandle
);
386 if (LangCodes3066
== NULL
) {
387 return EFI_INVALID_PARAMETER
;
392 Status
= LangCodes3066To639 (LangCodes3066
, &LangCodes639
);
393 if (EFI_ERROR (Status
)) {
397 UnicodeLangCodes639
= AllocateZeroPool (AsciiStrSize (LangCodes639
) * sizeof (CHAR16
));
398 if (UnicodeLangCodes639
== NULL
) {
399 Status
= EFI_OUT_OF_RESOURCES
;
404 // The language returned is in RFC 639-2 format.
406 AsciiStrToUnicodeStr (LangCodes639
, UnicodeLangCodes639
);
407 *LanguageString
= UnicodeLangCodes639
;
410 FreePool (LangCodes3066
);
411 if (LangCodes639
!= NULL
) {
412 FreePool (LangCodes639
);
422 HiiGetSecondaryLanguages (
423 IN EFI_HII_PROTOCOL
*This
,
424 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
425 IN CHAR16
*PrimaryLanguage
,
426 OUT EFI_STRING
*LanguageString
432 This function allows a program to determine which secondary languages are supported
433 on a given handle for a given primary language.
441 HII_THUNK_PRIVATE_DATA
*Private
;
442 EFI_HII_HANDLE UefiHiiHandle
;
443 CHAR8 PrimaryLang3066
[RFC_3066_ENTRY_SIZE
];
444 CHAR8
*PrimaryLang639
;
445 CHAR8
*SecLangCodes3066
;
446 CHAR8
*SecLangCodes639
;
447 CHAR16
*UnicodeSecLangCodes639
;
450 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
452 SecLangCodes639
= NULL
;
453 SecLangCodes3066
= NULL
;
454 UnicodeSecLangCodes639
= NULL
;
456 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
457 if (UefiHiiHandle
== NULL
) {
458 return EFI_INVALID_PARAMETER
;
461 PrimaryLang639
= AllocateZeroPool (StrLen (PrimaryLanguage
) + 1);
462 if (PrimaryLang639
== NULL
) {
463 Status
= EFI_OUT_OF_RESOURCES
;
467 UnicodeStrToAsciiStr (PrimaryLanguage
, PrimaryLang639
);
469 Status
= ConvertIso639LanguageToRfc3066Language (PrimaryLang639
, PrimaryLang3066
);
470 ASSERT_EFI_ERROR (Status
);
472 SecLangCodes3066
= HiiLibGetSupportedSecondaryLanguages (UefiHiiHandle
, PrimaryLang3066
);
474 if (SecLangCodes3066
== NULL
) {
475 Status
= EFI_INVALID_PARAMETER
;
479 Status
= LangCodes3066To639 (SecLangCodes3066
, &SecLangCodes639
);
480 if (EFI_ERROR (Status
)) {
484 UnicodeSecLangCodes639
= AllocateZeroPool (AsciiStrSize (SecLangCodes639
) * sizeof (CHAR16
));
485 if (UnicodeSecLangCodes639
== NULL
) {
486 Status
= EFI_OUT_OF_RESOURCES
;
491 // The language returned is in RFC 3066 format.
493 *LanguageString
= AsciiStrToUnicodeStr (SecLangCodes639
, UnicodeSecLangCodes639
);
496 if (PrimaryLang639
!= NULL
) {
497 FreePool (PrimaryLang639
);
499 if (SecLangCodes639
!= NULL
) {
500 FreePool (SecLangCodes639
);
502 if (SecLangCodes3066
!= NULL
) {
503 FreePool (SecLangCodes3066
);
505 if (UnicodeSecLangCodes639
!= NULL
) {
506 FreePool (UnicodeSecLangCodes639
);