3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 This file contains the entry code to the HII database.
22 #include "HiiDatabase.h"
26 InitializeHiiDatabase (
27 IN EFI_HANDLE ImageHandle
,
28 IN EFI_SYSTEM_TABLE
*SystemTable
33 Initialize HII Database
36 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
39 EFI_SUCCESS - Setup loaded.
45 EFI_HII_DATA
*HiiData
;
46 EFI_HII_GLOBAL_DATA
*GlobalData
;
47 EFI_HANDLE
*HandleBuffer
;
53 // There will be only one HII Database in the system
54 // If there is another out there, someone is trying to install us
55 // again. Fail that scenario.
57 Status
= gBS
->LocateHandleBuffer (
66 // If there was no error, assume there is an installation and fail to load
68 if (!EFI_ERROR (Status
)) {
69 if (HandleBuffer
!= NULL
) {
70 gBS
->FreePool (HandleBuffer
);
73 return EFI_DEVICE_ERROR
;
76 HiiData
= AllocatePool (sizeof (EFI_HII_DATA
));
80 GlobalData
= AllocateZeroPool (sizeof (EFI_HII_GLOBAL_DATA
));
85 // Seed the Font Database with a known non-character glyph
87 for (Index
= 0; Index
<= MAX_GLYPH_COUNT
; Index
++) {
89 // Seeding the UnicodeWeight with 0 signifies that it is uninitialized
91 GlobalData
->NarrowGlyphs
[Index
].UnicodeWeight
= 0;
92 GlobalData
->WideGlyphs
[Index
].UnicodeWeight
= 0;
93 GlobalData
->NarrowGlyphs
[Index
].Attributes
= 0;
94 GlobalData
->WideGlyphs
[Index
].Attributes
= 0;
95 CopyMem (GlobalData
->NarrowGlyphs
[Index
].GlyphCol1
, &mUnknownGlyph
, NARROW_GLYPH_ARRAY_SIZE
);
96 CopyMem (GlobalData
->WideGlyphs
[Index
].GlyphCol1
, &mUnknownGlyph
, WIDE_GLYPH_ARRAY_SIZE
);
101 HiiData
->Signature
= EFI_HII_DATA_SIGNATURE
;
102 HiiData
->GlobalData
= GlobalData
;
103 HiiData
->GlobalData
->SystemKeyboardUpdate
= FALSE
;
104 HiiData
->DatabaseHead
= NULL
;
105 HiiData
->Hii
.NewPack
= HiiNewPack
;
106 HiiData
->Hii
.RemovePack
= HiiRemovePack
;
107 HiiData
->Hii
.FindHandles
= HiiFindHandles
;
108 HiiData
->Hii
.ExportDatabase
= HiiExportDatabase
;
109 HiiData
->Hii
.GetGlyph
= HiiGetGlyph
;
110 HiiData
->Hii
.GetPrimaryLanguages
= HiiGetPrimaryLanguages
;
111 HiiData
->Hii
.GetSecondaryLanguages
= HiiGetSecondaryLanguages
;
112 HiiData
->Hii
.NewString
= HiiNewString
;
113 HiiData
->Hii
.GetString
= HiiGetString
;
114 HiiData
->Hii
.ResetStrings
= HiiResetStrings
;
115 HiiData
->Hii
.TestString
= HiiTestString
;
116 HiiData
->Hii
.GetLine
= HiiGetLine
;
117 HiiData
->Hii
.GetForms
= HiiGetForms
;
118 HiiData
->Hii
.GetDefaultImage
= HiiGetDefaultImage
;
119 HiiData
->Hii
.UpdateForm
= HiiUpdateForm
;
120 HiiData
->Hii
.GetKeyboardLayout
= HiiGetKeyboardLayout
;
121 HiiData
->Hii
.GlyphToBlt
= HiiGlyphToBlt
;
124 // Install protocol interface
127 Status
= gBS
->InstallProtocolInterface (
129 &gEfiHiiProtocolGuid
,
130 EFI_NATIVE_INTERFACE
,
134 ASSERT_EFI_ERROR (Status
);
142 IN EFI_HII_PROTOCOL
*This
,
143 IN OUT UINT16
*HandleBufferLength
,
144 OUT EFI_HII_HANDLE Handle
[1]
149 Determines the handles that are currently active in the database.
157 EFI_HII_HANDLE_DATABASE
*Database
;
158 EFI_HII_DATA
*HiiData
;
162 return EFI_INVALID_PARAMETER
;
165 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
167 Database
= HiiData
->DatabaseHead
;
169 if (Database
== NULL
) {
170 *HandleBufferLength
= 0;
171 return EFI_NOT_FOUND
;
174 for (HandleCount
= 0; Database
!= NULL
; HandleCount
++) {
175 Database
= Database
->NextHandleDatabase
;
178 // Is there a sufficient buffer for the data being passed back?
180 if (*HandleBufferLength
>= (sizeof (EFI_HII_HANDLE
) * HandleCount
)) {
181 Database
= HiiData
->DatabaseHead
;
184 // Copy the Head information
186 if (Database
->Handle
!= 0) {
187 CopyMem (&Handle
[0], &Database
->Handle
, sizeof (EFI_HII_HANDLE
));
188 Database
= Database
->NextHandleDatabase
;
191 // Copy more data if appropriate
193 for (HandleCount
= 1; Database
!= NULL
; HandleCount
++) {
194 CopyMem (&Handle
[HandleCount
], &Database
->Handle
, sizeof (EFI_HII_HANDLE
));
195 Database
= Database
->NextHandleDatabase
;
198 *HandleBufferLength
= (UINT16
) (sizeof (EFI_HII_HANDLE
) * HandleCount
);
202 // Insufficient buffer length
204 *HandleBufferLength
= (UINT16
) (sizeof (EFI_HII_HANDLE
) * HandleCount
);
205 return EFI_BUFFER_TOO_SMALL
;
211 HiiGetPrimaryLanguages (
212 IN EFI_HII_PROTOCOL
*This
,
213 IN EFI_HII_HANDLE Handle
,
214 OUT EFI_STRING
*LanguageString
220 This function allows a program to determine what the primary languages that are supported on a given handle.
229 EFI_HII_PACKAGE_INSTANCE
*PackageInstance
;
230 EFI_HII_PACKAGE_INSTANCE
*StringPackageInstance
;
231 EFI_HII_DATA
*HiiData
;
232 EFI_HII_HANDLE_DATABASE
*HandleDatabase
;
233 EFI_HII_STRING_PACK
*StringPack
;
234 EFI_HII_STRING_PACK
*Location
;
239 return EFI_INVALID_PARAMETER
;
242 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
244 PackageInstance
= NULL
;
246 // Find matching handle in the handle database. Then get the package instance.
248 for (HandleDatabase
= HiiData
->DatabaseHead
;
249 HandleDatabase
!= NULL
;
250 HandleDatabase
= HandleDatabase
->NextHandleDatabase
252 if (Handle
== HandleDatabase
->Handle
) {
253 PackageInstance
= HandleDatabase
->Buffer
;
257 // No handle was found - error condition
259 if (PackageInstance
== NULL
) {
260 return EFI_INVALID_PARAMETER
;
263 ValidatePack (This
, PackageInstance
, &StringPackageInstance
, NULL
);
266 // Based on if there is IFR data in this package instance, determine
267 // what the location is of the beginning of the string data.
269 if (StringPackageInstance
->IfrSize
> 0) {
270 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (&StringPackageInstance
->IfrData
) + StringPackageInstance
->IfrSize
);
272 StringPack
= (EFI_HII_STRING_PACK
*) (&StringPackageInstance
->IfrData
);
275 Location
= StringPack
;
277 // Remember that the string packages are formed into contiguous blocks of language data.
279 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
280 for (Count
= 0; Length
!= 0; Count
= Count
+ 3) {
281 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);
282 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
285 *LanguageString
= AllocateZeroPool (2 * (Count
+ 1));
287 ASSERT (*LanguageString
);
289 StringPack
= (EFI_HII_STRING_PACK
*) Location
;
292 // Copy the 6 bytes to LanguageString - keep concatenating it. Shouldn't we just store uint8's since the ISO
293 // standard defines the lettering as all US English characters anyway? Save a few bytes.
295 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
296 for (Count
= 0; Length
!= 0; Count
= Count
+ 3) {
297 CopyMem (&Token
, &StringPack
->LanguageNameString
, sizeof (RELOFST
));
298 CopyMem (*LanguageString
+ Count
, (VOID
*) ((CHAR8
*) (StringPack
) + Token
), 6);
299 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);
300 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
308 HiiGetSecondaryLanguages (
309 IN EFI_HII_PROTOCOL
*This
,
310 IN EFI_HII_HANDLE Handle
,
311 IN CHAR16
*PrimaryLanguage
,
312 OUT EFI_STRING
*LanguageString
318 This function allows a program to determine which secondary languages are supported
319 on a given handle for a given primary language.
328 EFI_HII_PACKAGE_INSTANCE
*PackageInstance
;
329 EFI_HII_PACKAGE_INSTANCE
*StringPackageInstance
;
330 EFI_HII_DATA
*HiiData
;
331 EFI_HII_HANDLE_DATABASE
*HandleDatabase
;
332 EFI_HII_STRING_PACK
*StringPack
;
337 return EFI_INVALID_PARAMETER
;
340 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
342 // Check numeric value against the head of the database
344 PackageInstance
= NULL
;
345 for (HandleDatabase
= HiiData
->DatabaseHead
;
346 HandleDatabase
!= NULL
;
347 HandleDatabase
= HandleDatabase
->NextHandleDatabase
350 // Match the numeric value with the database entry - if matched, extract PackageInstance
352 if (Handle
== HandleDatabase
->Handle
) {
353 PackageInstance
= HandleDatabase
->Buffer
;
357 // No handle was found - error condition
359 if (PackageInstance
== NULL
) {
360 return EFI_INVALID_PARAMETER
;
363 ValidatePack (This
, PackageInstance
, &StringPackageInstance
, NULL
);
366 // Based on if there is IFR data in this package instance, determine
367 // what the location is of the beginning of the string data.
369 if (StringPackageInstance
->IfrSize
> 0) {
370 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (&StringPackageInstance
->IfrData
) + StringPackageInstance
->IfrSize
);
372 StringPack
= (EFI_HII_STRING_PACK
*) (&StringPackageInstance
->IfrData
);
376 // Remember that the string packages are formed into contiguous blocks of language data.
378 for (; StringPack
->Header
.Length
!= 0;) {
380 // Find the PrimaryLanguage being requested
382 Token
= StringPack
->LanguageNameString
;
383 if (CompareMem ((VOID
*) ((CHAR8
*) (StringPack
) + Token
), PrimaryLanguage
, 3) == 0) {
385 // Now that we found the primary, the secondary languages will follow immediately
386 // or the next character is a NULL if there are no secondary languages. We determine
387 // the number by getting the stringsize based on the StringPack origination + the LanguageNameString
388 // offset + 6 (which is the size of the first 3 letter ISO primary language name). If we get 2, there
389 // are no secondary languages (2 = null-terminator).
391 Count
= StrSize ((VOID
*) ((CHAR8
*) (StringPack
) + Token
+ 6));
393 *LanguageString
= AllocateZeroPool (2 * (Count
+ 1));
395 ASSERT (*LanguageString
);
397 CopyMem (*LanguageString
, (VOID
*) ((CHAR8
*) (StringPack
) + Token
+ 6), Count
);
401 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
402 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);