]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.c
Sync in bug fix from EDK I:
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / HiiDatabase.c
1 /**@file
2 Framework to UEFI 2.1 HII Thunk. The driver consume UEFI HII protocols
3 to produce a Framework HII protocol.
4
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
10
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.
13
14 **/
15
16 #include "HiiDatabase.h"
17 #include "HiiHandle.h"
18
19 HII_THUNK_PRIVATE_DATA *mHiiThunkPrivateData;
20
21 HII_THUNK_PRIVATE_DATA mHiiThunkPrivateDataTempate = {
22 HII_THUNK_PRIVATE_DATA_SIGNATURE,
23 (EFI_HANDLE) NULL,
24 {
25 HiiNewPack,
26 HiiRemovePack,
27 HiiFindHandles,
28 HiiExportDatabase,
29
30 HiiTestString,
31 HiiGetGlyph,
32 HiiGlyphToBlt,
33
34 HiiNewString,
35 HiiGetPrimaryLanguages,
36 HiiGetSecondaryLanguages,
37 HiiGetString,
38 HiiResetStrings,
39 HiiGetLine,
40 HiiGetForms,
41 HiiGetDefaultImage,
42 HiiUpdateForm,
43
44 HiiGetKeyboardLayout
45 },
46
47 {
48 ///
49 /// HiiHandleLinkList
50 ///
51 NULL, NULL
52 },
53 };
54
55 EFI_FORMBROWSER_THUNK_PRIVATE_DATA mBrowserThunkPrivateDataTemplate = {
56 EFI_FORMBROWSER_THUNK_PRIVATE_DATA_SIGNATURE,
57 (EFI_HANDLE) NULL,
58 (HII_THUNK_PRIVATE_DATA *) NULL,
59 {
60 ThunkSendForm,
61 ThunkCreatePopUp
62 }
63 };
64
65
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;
72
73
74
75
76
77
78 EFI_STATUS
79 EFIAPI
80 InitializeHiiDatabase (
81 IN EFI_HANDLE ImageHandle,
82 IN EFI_SYSTEM_TABLE *SystemTable
83 )
84 /*++
85
86 Routine Description:
87 Initialize HII Database
88
89 Arguments:
90 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
91
92 Returns:
93 EFI_SUCCESS - Setup loaded.
94 other - Setup Error
95
96 --*/
97 {
98 HII_THUNK_PRIVATE_DATA *Private;
99 EFI_HANDLE Handle;
100 EFI_STATUS Status;
101 UINTN BufferLength;
102 EFI_HII_HANDLE *Buffer;
103 UINTN Index;
104 HII_THUNK_CONTEXT *ThunkContext;
105
106
107 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiCompatibilityProtocolGuid);
108 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiFormBrowserCompatibilityProtocolGuid);
109
110 Private = AllocateCopyPool (sizeof (HII_THUNK_PRIVATE_DATA), &mHiiThunkPrivateDataTempate);
111 ASSERT (Private != NULL);
112 InitializeListHead (&Private->ThunkContextListHead);
113
114 InitHiiHandleDatabase ();
115
116 mHiiThunkPrivateData = Private;
117
118 Status = gBS->LocateProtocol (
119 &gEfiHiiDatabaseProtocolGuid,
120 NULL,
121 (VOID **) &mHiiDatabase
122 );
123 ASSERT_EFI_ERROR (Status);
124
125 Status = gBS->LocateProtocol (
126 &gEfiHiiStringProtocolGuid,
127 NULL,
128 (VOID **) &mHiiStringProtocol
129 );
130 ASSERT_EFI_ERROR (Status);
131
132 Status = gBS->LocateProtocol (
133 &gEfiHiiFontProtocolGuid,
134 NULL,
135 (VOID **) &mHiiFontProtocol
136 );
137 ASSERT_EFI_ERROR (Status);
138
139 Status = gBS->LocateProtocol (
140 &gEfiHiiConfigRoutingProtocolGuid,
141 NULL,
142 (VOID **) &mHiiConfigRoutingProtocol
143 );
144 ASSERT_EFI_ERROR (Status);
145
146
147 Status = gBS->LocateProtocol (
148 &gEfiFormBrowser2ProtocolGuid,
149 NULL,
150 (VOID **) &mFormBrowser2Protocol
151 );
152 ASSERT_EFI_ERROR (Status);
153
154
155
156
157 //
158 // Install protocol interface
159 //
160 Status = gBS->InstallProtocolInterface (
161 &Private->Handle,
162 &gEfiHiiCompatibilityProtocolGuid,
163 EFI_NATIVE_INTERFACE,
164 (VOID *) &Private->Hii
165 );
166 ASSERT_EFI_ERROR (Status);
167
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);
173
174 InsertTailList (&Private->ThunkContextListHead, &ThunkContext->Link);
175 }
176
177 FreePool (Buffer);
178 }
179
180 Status = mHiiDatabase->RegisterPackageNotify (
181 mHiiDatabase,
182 EFI_HII_PACKAGE_STRINGS,
183 NULL,
184 NewOrAddPackNotify,
185 EFI_HII_DATABASE_NOTIFY_NEW_PACK,
186 &Handle
187 );
188 ASSERT_EFI_ERROR (Status);
189
190 Status = mHiiDatabase->RegisterPackageNotify (
191 mHiiDatabase,
192 EFI_HII_PACKAGE_STRINGS,
193 NULL,
194 NewOrAddPackNotify,
195 EFI_HII_DATABASE_NOTIFY_ADD_PACK,
196 &Handle
197 );
198 ASSERT_EFI_ERROR (Status);
199
200 Status = mHiiDatabase->RegisterPackageNotify (
201 mHiiDatabase,
202 EFI_HII_PACKAGE_FORMS,
203 NULL,
204 NewOrAddPackNotify,
205 EFI_HII_DATABASE_NOTIFY_NEW_PACK,
206 &Handle
207 );
208 ASSERT_EFI_ERROR (Status);
209
210 Status = mHiiDatabase->RegisterPackageNotify (
211 mHiiDatabase,
212 EFI_HII_PACKAGE_FORMS,
213 NULL,
214 NewOrAddPackNotify,
215 EFI_HII_DATABASE_NOTIFY_ADD_PACK,
216 &Handle
217 );
218 ASSERT_EFI_ERROR (Status);
219
220 Status = mHiiDatabase->RegisterPackageNotify (
221 mHiiDatabase,
222 EFI_HII_PACKAGE_STRINGS,
223 NULL,
224 RemovePackNotify,
225 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
226 &Handle
227 );
228 ASSERT_EFI_ERROR (Status);
229
230 mBrowserThunkPrivateDataTemplate.ThunkPrivate = Private;
231 Status = gBS->InstallProtocolInterface (
232 &mBrowserThunkPrivateDataTemplate.Handle,
233 &gEfiFormBrowserCompatibilityProtocolGuid,
234 EFI_NATIVE_INTERFACE,
235 (VOID *) &mBrowserThunkPrivateDataTemplate.FormBrowser
236 );
237 ASSERT_EFI_ERROR (Status);
238
239 return Status;
240 }
241
242 EFI_STATUS
243 EFIAPI
244 HiiFindHandles (
245 IN EFI_HII_PROTOCOL *This,
246 IN OUT UINT16 *HandleBufferLength,
247 OUT FRAMEWORK_EFI_HII_HANDLE Handle[1]
248 )
249 /*++
250
251 Routine Description:
252 Determines the handles that are currently active in the database.
253
254 Arguments:
255
256 Returns:
257
258 --*/
259 {
260 UINT16 Count;
261 LIST_ENTRY *Link;
262 HII_THUNK_CONTEXT *ThunkContext;
263 HII_THUNK_PRIVATE_DATA *Private;
264
265 if (HandleBufferLength == NULL) {
266 return EFI_INVALID_PARAMETER;
267 }
268
269 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
270
271 //
272 // Count the number of handles.
273 //
274 Count = 0;
275 Link = GetFirstNode (&Private->ThunkContextListHead);
276 while (!IsNull (&Private->ThunkContextListHead, Link)) {
277 Count++;
278 Link = GetNextNode (&Private->ThunkContextListHead, Link);
279 }
280
281 if (Count > *HandleBufferLength) {
282 *HandleBufferLength = (Count * sizeof (FRAMEWORK_EFI_HII_HANDLE));
283 return EFI_BUFFER_TOO_SMALL;
284 }
285
286 //
287 // Output the handles.
288 //
289 Count = 0;
290 Link = GetFirstNode (&Private->ThunkContextListHead);
291 while (!IsNull (&Private->ThunkContextListHead, Link)) {
292
293 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
294 Handle[Count] = ThunkContext->FwHiiHandle;
295
296 Count++;
297 Link = GetNextNode (&Private->ThunkContextListHead, Link);
298
299 }
300
301 *HandleBufferLength = (Count * sizeof (FRAMEWORK_EFI_HII_HANDLE));
302 return EFI_SUCCESS;
303 }
304
305 EFI_STATUS
306 LangCodes3066To639 (
307 IN CHAR8 *LangCodes3066,
308 IN CHAR8 **LangCodes639
309 )
310 {
311 CHAR8 *AsciiLangCodes;
312 CHAR8 Lang[RFC_3066_ENTRY_SIZE];
313 UINTN Index;
314 UINTN Count;
315 EFI_STATUS Status;
316
317 ASSERT (LangCodes3066 != NULL);
318 ASSERT (LangCodes639 != NULL);
319
320 //
321 // Count the number of RFC 3066 language codes.
322 //
323 Index = 0;
324 AsciiLangCodes = LangCodes3066;
325 while (AsciiStrLen (AsciiLangCodes) != 0) {
326 HiiLibGetNextLanguage (&AsciiLangCodes, Lang);
327 Index++;
328 }
329
330 Count = Index;
331
332 //
333 //
334 //
335 *LangCodes639 = AllocateZeroPool (ISO_639_2_ENTRY_SIZE * Count + 1);
336 if (*LangCodes639 == NULL) {
337 return EFI_OUT_OF_RESOURCES;
338 }
339
340 AsciiLangCodes = LangCodes3066;
341
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);
346 }
347
348 return EFI_SUCCESS;
349 }
350
351 EFI_STATUS
352 EFIAPI
353 HiiGetPrimaryLanguages (
354 IN EFI_HII_PROTOCOL *This,
355 IN FRAMEWORK_EFI_HII_HANDLE Handle,
356 OUT EFI_STRING *LanguageString
357 )
358 /*++
359
360 Routine Description:
361
362 This function allows a program to determine what the primary languages that are supported on a given handle.
363
364 Arguments:
365
366 Returns:
367
368 --*/
369 {
370 HII_THUNK_PRIVATE_DATA *Private;
371 EFI_HII_HANDLE UefiHiiHandle;
372 CHAR8 *LangCodes3066;
373 CHAR16 *UnicodeLangCodes639;
374 CHAR8 *LangCodes639;
375 EFI_STATUS Status;
376
377 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
378
379 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);
380 if (UefiHiiHandle == NULL) {
381 return EFI_INVALID_PARAMETER;
382 }
383
384 LangCodes3066 = HiiLibGetSupportedLanguages (UefiHiiHandle);
385
386 if (LangCodes3066 == NULL) {
387 return EFI_INVALID_PARAMETER;
388 }
389
390
391 LangCodes639 = NULL;
392 Status = LangCodes3066To639 (LangCodes3066, &LangCodes639);
393 if (EFI_ERROR (Status)) {
394 goto Done;
395 }
396
397 UnicodeLangCodes639 = AllocateZeroPool (AsciiStrSize (LangCodes639) * sizeof (CHAR16));
398 if (UnicodeLangCodes639 == NULL) {
399 Status = EFI_OUT_OF_RESOURCES;
400 goto Done;
401 }
402
403 //
404 // The language returned is in RFC 639-2 format.
405 //
406 AsciiStrToUnicodeStr (LangCodes639, UnicodeLangCodes639);
407 *LanguageString = UnicodeLangCodes639;
408
409 Done:
410 FreePool (LangCodes3066);
411 if (LangCodes639 != NULL) {
412 FreePool (LangCodes639);
413 }
414
415 return Status;
416 }
417
418
419
420 EFI_STATUS
421 EFIAPI
422 HiiGetSecondaryLanguages (
423 IN EFI_HII_PROTOCOL *This,
424 IN FRAMEWORK_EFI_HII_HANDLE Handle,
425 IN CHAR16 *PrimaryLanguage,
426 OUT EFI_STRING *LanguageString
427 )
428 /*++
429
430 Routine Description:
431
432 This function allows a program to determine which secondary languages are supported
433 on a given handle for a given primary language.
434
435 Arguments:
436
437 Returns:
438
439 --*/
440 {
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;
448 EFI_STATUS Status;
449
450 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
451
452 SecLangCodes639 = NULL;
453 SecLangCodes3066 = NULL;
454 UnicodeSecLangCodes639 = NULL;
455
456 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);
457 if (UefiHiiHandle == NULL) {
458 return EFI_INVALID_PARAMETER;
459 }
460
461 PrimaryLang639 = AllocateZeroPool (StrLen (PrimaryLanguage) + 1);
462 if (PrimaryLang639 == NULL) {
463 Status = EFI_OUT_OF_RESOURCES;
464 goto Done;
465 }
466
467 UnicodeStrToAsciiStr (PrimaryLanguage, PrimaryLang639);
468
469 Status = ConvertIso639LanguageToRfc3066Language (PrimaryLang639, PrimaryLang3066);
470 ASSERT_EFI_ERROR (Status);
471
472 SecLangCodes3066 = HiiLibGetSupportedSecondaryLanguages (UefiHiiHandle, PrimaryLang3066);
473
474 if (SecLangCodes3066 == NULL) {
475 Status = EFI_INVALID_PARAMETER;
476 goto Done;
477 }
478
479 Status = LangCodes3066To639 (SecLangCodes3066, &SecLangCodes639);
480 if (EFI_ERROR (Status)) {
481 goto Done;
482 }
483
484 UnicodeSecLangCodes639 = AllocateZeroPool (AsciiStrSize (SecLangCodes639) * sizeof (CHAR16));
485 if (UnicodeSecLangCodes639 == NULL) {
486 Status = EFI_OUT_OF_RESOURCES;
487 goto Done;
488 }
489
490 //
491 // The language returned is in RFC 3066 format.
492 //
493 *LanguageString = AsciiStrToUnicodeStr (SecLangCodes639, UnicodeSecLangCodes639);
494
495 Done:
496 if (PrimaryLang639 != NULL) {
497 FreePool (PrimaryLang639);
498 }
499 if (SecLangCodes639 != NULL) {
500 FreePool (SecLangCodes639);
501 }
502 if (SecLangCodes3066 != NULL) {
503 FreePool (SecLangCodes3066);
504 }
505 if (UnicodeSecLangCodes639 != NULL) {
506 FreePool (UnicodeSecLangCodes639);
507 }
508
509 return Status;
510 }
511
512