3 This file contains the keyboard processing code to the HII database.
5 Copyright (c) 2006, 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"
20 InitializeHiiDatabase (
21 IN EFI_HANDLE ImageHandle
,
22 IN EFI_SYSTEM_TABLE
*SystemTable
27 Initialize HII Database
30 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
33 EFI_SUCCESS - Setup loaded.
39 EFI_HII_DATA
*HiiData
;
40 EFI_HII_GLOBAL_DATA
*GlobalData
;
41 EFI_HANDLE
*HandleBuffer
;
47 // There will be only one HII Database in the system
48 // If there is another out there, someone is trying to install us
49 // again. Fail that scenario.
51 Status
= gBS
->LocateHandleBuffer (
60 // If there was no error, assume there is an installation and fail to load
62 if (!EFI_ERROR (Status
)) {
63 if (HandleBuffer
!= NULL
) {
64 FreePool (HandleBuffer
);
67 return EFI_DEVICE_ERROR
;
70 HiiData
= AllocatePool (sizeof (EFI_HII_DATA
));
74 GlobalData
= AllocateZeroPool (sizeof (EFI_HII_GLOBAL_DATA
));
79 // Seed the Font Database with a known non-character glyph
81 for (Index
= 0; Index
<= MAX_GLYPH_COUNT
; Index
++) {
83 // Seeding the UnicodeWeight with 0 signifies that it is uninitialized
85 GlobalData
->NarrowGlyphs
[Index
].UnicodeWeight
= 0;
86 GlobalData
->WideGlyphs
[Index
].UnicodeWeight
= 0;
87 GlobalData
->NarrowGlyphs
[Index
].Attributes
= 0;
88 GlobalData
->WideGlyphs
[Index
].Attributes
= 0;
89 CopyMem (GlobalData
->NarrowGlyphs
[Index
].GlyphCol1
, &mUnknownGlyph
, NARROW_GLYPH_ARRAY_SIZE
);
90 CopyMem (GlobalData
->WideGlyphs
[Index
].GlyphCol1
, &mUnknownGlyph
, WIDE_GLYPH_ARRAY_SIZE
);
95 HiiData
->Signature
= EFI_HII_DATA_SIGNATURE
;
96 HiiData
->GlobalData
= GlobalData
;
97 HiiData
->GlobalData
->SystemKeyboardUpdate
= FALSE
;
98 HiiData
->DatabaseHead
= NULL
;
99 HiiData
->Hii
.NewPack
= HiiNewPack
;
100 HiiData
->Hii
.RemovePack
= HiiRemovePack
;
101 HiiData
->Hii
.FindHandles
= HiiFindHandles
;
102 HiiData
->Hii
.ExportDatabase
= HiiExportDatabase
;
103 HiiData
->Hii
.GetGlyph
= HiiGetGlyph
;
104 HiiData
->Hii
.GetPrimaryLanguages
= HiiGetPrimaryLanguages
;
105 HiiData
->Hii
.GetSecondaryLanguages
= HiiGetSecondaryLanguages
;
106 HiiData
->Hii
.NewString
= HiiNewString
;
107 HiiData
->Hii
.GetString
= HiiGetString
;
108 HiiData
->Hii
.ResetStrings
= HiiResetStrings
;
109 HiiData
->Hii
.TestString
= HiiTestString
;
110 HiiData
->Hii
.GetLine
= HiiGetLine
;
111 HiiData
->Hii
.GetForms
= HiiGetForms
;
112 HiiData
->Hii
.GetDefaultImage
= HiiGetDefaultImage
;
113 HiiData
->Hii
.UpdateForm
= HiiUpdateForm
;
114 HiiData
->Hii
.GetKeyboardLayout
= HiiGetKeyboardLayout
;
115 HiiData
->Hii
.GlyphToBlt
= HiiGlyphToBlt
;
118 // Install protocol interface
121 Status
= gBS
->InstallProtocolInterface (
123 &gEfiHiiProtocolGuid
,
124 EFI_NATIVE_INTERFACE
,
128 ASSERT_EFI_ERROR (Status
);
136 IN EFI_HII_PROTOCOL
*This
,
137 IN OUT UINT16
*HandleBufferLength
,
138 OUT FRAMEWORK_EFI_HII_HANDLE Handle
[1]
143 Determines the handles that are currently active in the database.
151 EFI_HII_HANDLE_DATABASE
*Database
;
152 EFI_HII_DATA
*HiiData
;
156 return EFI_INVALID_PARAMETER
;
159 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
161 Database
= HiiData
->DatabaseHead
;
163 if (Database
== NULL
) {
164 *HandleBufferLength
= 0;
165 return EFI_NOT_FOUND
;
168 for (HandleCount
= 0; Database
!= NULL
; HandleCount
++) {
169 Database
= Database
->NextHandleDatabase
;
172 // Is there a sufficient buffer for the data being passed back?
174 if (*HandleBufferLength
>= (sizeof (FRAMEWORK_EFI_HII_HANDLE
) * HandleCount
)) {
175 Database
= HiiData
->DatabaseHead
;
178 // Copy the Head information
180 if (Database
->Handle
!= 0) {
181 CopyMem (&Handle
[0], &Database
->Handle
, sizeof (FRAMEWORK_EFI_HII_HANDLE
));
182 Database
= Database
->NextHandleDatabase
;
185 // Copy more data if appropriate
187 for (HandleCount
= 1; Database
!= NULL
; HandleCount
++) {
188 CopyMem (&Handle
[HandleCount
], &Database
->Handle
, sizeof (FRAMEWORK_EFI_HII_HANDLE
));
189 Database
= Database
->NextHandleDatabase
;
192 *HandleBufferLength
= (UINT16
) (sizeof (FRAMEWORK_EFI_HII_HANDLE
) * HandleCount
);
196 // Insufficient buffer length
198 *HandleBufferLength
= (UINT16
) (sizeof (FRAMEWORK_EFI_HII_HANDLE
) * HandleCount
);
199 return EFI_BUFFER_TOO_SMALL
;
205 HiiGetPrimaryLanguages (
206 IN EFI_HII_PROTOCOL
*This
,
207 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
208 OUT EFI_STRING
*LanguageString
214 This function allows a program to determine what the primary languages that are supported on a given handle.
223 EFI_HII_PACKAGE_INSTANCE
*PackageInstance
;
224 EFI_HII_PACKAGE_INSTANCE
*StringPackageInstance
;
225 EFI_HII_DATA
*HiiData
;
226 EFI_HII_HANDLE_DATABASE
*HandleDatabase
;
227 EFI_HII_STRING_PACK
*StringPack
;
228 EFI_HII_STRING_PACK
*Location
;
233 return EFI_INVALID_PARAMETER
;
236 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
238 PackageInstance
= NULL
;
240 // Find matching handle in the handle database. Then get the package instance.
242 for (HandleDatabase
= HiiData
->DatabaseHead
;
243 HandleDatabase
!= NULL
;
244 HandleDatabase
= HandleDatabase
->NextHandleDatabase
246 if (Handle
== HandleDatabase
->Handle
) {
247 PackageInstance
= HandleDatabase
->Buffer
;
251 // No handle was found - error condition
253 if (PackageInstance
== NULL
) {
254 return EFI_INVALID_PARAMETER
;
257 ValidatePack (This
, PackageInstance
, &StringPackageInstance
, NULL
);
260 // Based on if there is IFR data in this package instance, determine
261 // what the location is of the beginning of the string data.
263 if (StringPackageInstance
->IfrSize
> 0) {
264 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (&StringPackageInstance
->IfrData
) + StringPackageInstance
->IfrSize
);
266 StringPack
= (EFI_HII_STRING_PACK
*) (&StringPackageInstance
->IfrData
);
269 Location
= StringPack
;
271 // Remember that the string packages are formed into contiguous blocks of language data.
273 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
274 for (Count
= 0; Length
!= 0; Count
= Count
+ 3) {
275 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);
276 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
279 *LanguageString
= AllocateZeroPool (2 * (Count
+ 1));
281 ASSERT (*LanguageString
);
283 StringPack
= (EFI_HII_STRING_PACK
*) Location
;
286 // Copy the 6 bytes to LanguageString - keep concatenating it. Shouldn't we just store uint8's since the ISO
287 // standard defines the lettering as all US English characters anyway? Save a few bytes.
289 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
290 for (Count
= 0; Length
!= 0; Count
= Count
+ 3) {
291 CopyMem (&Token
, &StringPack
->LanguageNameString
, sizeof (RELOFST
));
292 CopyMem (*LanguageString
+ Count
, (VOID
*) ((CHAR8
*) (StringPack
) + Token
), 6);
293 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);
294 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
302 HiiGetSecondaryLanguages (
303 IN EFI_HII_PROTOCOL
*This
,
304 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
305 IN CHAR16
*PrimaryLanguage
,
306 OUT EFI_STRING
*LanguageString
312 This function allows a program to determine which secondary languages are supported
313 on a given handle for a given primary language.
322 EFI_HII_PACKAGE_INSTANCE
*PackageInstance
;
323 EFI_HII_PACKAGE_INSTANCE
*StringPackageInstance
;
324 EFI_HII_DATA
*HiiData
;
325 EFI_HII_HANDLE_DATABASE
*HandleDatabase
;
326 EFI_HII_STRING_PACK
*StringPack
;
331 return EFI_INVALID_PARAMETER
;
334 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
336 // Check numeric value against the head of the database
338 PackageInstance
= NULL
;
339 for (HandleDatabase
= HiiData
->DatabaseHead
;
340 HandleDatabase
!= NULL
;
341 HandleDatabase
= HandleDatabase
->NextHandleDatabase
344 // Match the numeric value with the database entry - if matched, extract PackageInstance
346 if (Handle
== HandleDatabase
->Handle
) {
347 PackageInstance
= HandleDatabase
->Buffer
;
351 // No handle was found - error condition
353 if (PackageInstance
== NULL
) {
354 return EFI_INVALID_PARAMETER
;
357 ValidatePack (This
, PackageInstance
, &StringPackageInstance
, NULL
);
360 // Based on if there is IFR data in this package instance, determine
361 // what the location is of the beginning of the string data.
363 if (StringPackageInstance
->IfrSize
> 0) {
364 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (&StringPackageInstance
->IfrData
) + StringPackageInstance
->IfrSize
);
366 StringPack
= (EFI_HII_STRING_PACK
*) (&StringPackageInstance
->IfrData
);
370 // Remember that the string packages are formed into contiguous blocks of language data.
372 for (; StringPack
->Header
.Length
!= 0;) {
374 // Find the PrimaryLanguage being requested
376 Token
= StringPack
->LanguageNameString
;
377 if (CompareMem ((VOID
*) ((CHAR8
*) (StringPack
) + Token
), PrimaryLanguage
, 3) == 0) {
379 // Now that we found the primary, the secondary languages will follow immediately
380 // or the next character is a NULL if there are no secondary languages. We determine
381 // the number by getting the stringsize based on the StringPack origination + the LanguageNameString
382 // offset + 6 (which is the size of the first 3 letter ISO primary language name). If we get 2, there
383 // are no secondary languages (2 = null-terminator).
385 Count
= StrSize ((VOID
*) ((CHAR8
*) (StringPack
) + Token
+ 6));
387 *LanguageString
= AllocateZeroPool (2 * (Count
+ 1));
389 ASSERT (*LanguageString
);
391 CopyMem (*LanguageString
, (VOID
*) ((CHAR8
*) (StringPack
) + Token
+ 6), Count
);
395 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
396 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);