3 Copyright (c) 2006 - 2007, 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.
23 // Include common header file for this module.
25 #include "CommonHeader.h"
27 #include "HiiDatabase.h"
31 InitializeHiiDatabase (
32 IN EFI_HANDLE ImageHandle
,
33 IN EFI_SYSTEM_TABLE
*SystemTable
38 Initialize HII Database
41 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
44 EFI_SUCCESS - Setup loaded.
50 EFI_HII_DATA
*HiiData
;
51 EFI_HII_GLOBAL_DATA
*GlobalData
;
52 EFI_HANDLE
*HandleBuffer
;
58 // There will be only one HII Database in the system
59 // If there is another out there, someone is trying to install us
60 // again. Fail that scenario.
62 Status
= gBS
->LocateHandleBuffer (
71 // If there was no error, assume there is an installation and fail to load
73 if (!EFI_ERROR (Status
)) {
74 if (HandleBuffer
!= NULL
) {
75 FreePool (HandleBuffer
);
78 return EFI_DEVICE_ERROR
;
81 HiiData
= AllocatePool (sizeof (EFI_HII_DATA
));
85 GlobalData
= AllocateZeroPool (sizeof (EFI_HII_GLOBAL_DATA
));
90 // Seed the Font Database with a known non-character glyph
92 for (Index
= 0; Index
<= MAX_GLYPH_COUNT
; Index
++) {
94 // Seeding the UnicodeWeight with 0 signifies that it is uninitialized
96 GlobalData
->NarrowGlyphs
[Index
].UnicodeWeight
= 0;
97 GlobalData
->WideGlyphs
[Index
].UnicodeWeight
= 0;
98 GlobalData
->NarrowGlyphs
[Index
].Attributes
= 0;
99 GlobalData
->WideGlyphs
[Index
].Attributes
= 0;
100 CopyMem (GlobalData
->NarrowGlyphs
[Index
].GlyphCol1
, &mUnknownGlyph
, NARROW_GLYPH_ARRAY_SIZE
);
101 CopyMem (GlobalData
->WideGlyphs
[Index
].GlyphCol1
, &mUnknownGlyph
, WIDE_GLYPH_ARRAY_SIZE
);
106 HiiData
->Signature
= EFI_HII_DATA_SIGNATURE
;
107 HiiData
->GlobalData
= GlobalData
;
108 HiiData
->GlobalData
->SystemKeyboardUpdate
= FALSE
;
109 HiiData
->DatabaseHead
= NULL
;
110 HiiData
->Hii
.NewPack
= HiiNewPack
;
111 HiiData
->Hii
.RemovePack
= HiiRemovePack
;
112 HiiData
->Hii
.FindHandles
= HiiFindHandles
;
113 HiiData
->Hii
.ExportDatabase
= HiiExportDatabase
;
114 HiiData
->Hii
.GetGlyph
= HiiGetGlyph
;
115 HiiData
->Hii
.GetPrimaryLanguages
= HiiGetPrimaryLanguages
;
116 HiiData
->Hii
.GetSecondaryLanguages
= HiiGetSecondaryLanguages
;
117 HiiData
->Hii
.NewString
= HiiNewString
;
118 HiiData
->Hii
.GetString
= HiiGetString
;
119 HiiData
->Hii
.ResetStrings
= HiiResetStrings
;
120 HiiData
->Hii
.TestString
= HiiTestString
;
121 HiiData
->Hii
.GetLine
= HiiGetLine
;
122 HiiData
->Hii
.GetForms
= HiiGetForms
;
123 HiiData
->Hii
.GetDefaultImage
= HiiGetDefaultImage
;
124 HiiData
->Hii
.UpdateForm
= HiiUpdateForm
;
125 HiiData
->Hii
.GetKeyboardLayout
= HiiGetKeyboardLayout
;
126 HiiData
->Hii
.GlyphToBlt
= HiiGlyphToBlt
;
129 // Install protocol interface
132 Status
= gBS
->InstallProtocolInterface (
134 &gEfiHiiProtocolGuid
,
135 EFI_NATIVE_INTERFACE
,
139 ASSERT_EFI_ERROR (Status
);
147 IN EFI_HII_PROTOCOL
*This
,
148 IN OUT UINT16
*HandleBufferLength
,
149 OUT EFI_HII_HANDLE Handle
[1]
154 Determines the handles that are currently active in the database.
162 EFI_HII_HANDLE_DATABASE
*Database
;
163 EFI_HII_DATA
*HiiData
;
167 return EFI_INVALID_PARAMETER
;
170 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
172 Database
= HiiData
->DatabaseHead
;
174 if (Database
== NULL
) {
175 *HandleBufferLength
= 0;
176 return EFI_NOT_FOUND
;
179 for (HandleCount
= 0; Database
!= NULL
; HandleCount
++) {
180 Database
= Database
->NextHandleDatabase
;
183 // Is there a sufficient buffer for the data being passed back?
185 if (*HandleBufferLength
>= (sizeof (EFI_HII_HANDLE
) * HandleCount
)) {
186 Database
= HiiData
->DatabaseHead
;
189 // Copy the Head information
191 if (Database
->Handle
!= 0) {
192 CopyMem (&Handle
[0], &Database
->Handle
, sizeof (EFI_HII_HANDLE
));
193 Database
= Database
->NextHandleDatabase
;
196 // Copy more data if appropriate
198 for (HandleCount
= 1; Database
!= NULL
; HandleCount
++) {
199 CopyMem (&Handle
[HandleCount
], &Database
->Handle
, sizeof (EFI_HII_HANDLE
));
200 Database
= Database
->NextHandleDatabase
;
203 *HandleBufferLength
= (UINT16
) (sizeof (EFI_HII_HANDLE
) * HandleCount
);
207 // Insufficient buffer length
209 *HandleBufferLength
= (UINT16
) (sizeof (EFI_HII_HANDLE
) * HandleCount
);
210 return EFI_BUFFER_TOO_SMALL
;
216 HiiGetPrimaryLanguages (
217 IN EFI_HII_PROTOCOL
*This
,
218 IN EFI_HII_HANDLE Handle
,
219 OUT EFI_STRING
*LanguageString
225 This function allows a program to determine what the primary languages that are supported on a given handle.
234 EFI_HII_PACKAGE_INSTANCE
*PackageInstance
;
235 EFI_HII_PACKAGE_INSTANCE
*StringPackageInstance
;
236 EFI_HII_DATA
*HiiData
;
237 EFI_HII_HANDLE_DATABASE
*HandleDatabase
;
238 EFI_HII_STRING_PACK
*StringPack
;
239 EFI_HII_STRING_PACK
*Location
;
244 return EFI_INVALID_PARAMETER
;
247 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
249 PackageInstance
= NULL
;
251 // Find matching handle in the handle database. Then get the package instance.
253 for (HandleDatabase
= HiiData
->DatabaseHead
;
254 HandleDatabase
!= NULL
;
255 HandleDatabase
= HandleDatabase
->NextHandleDatabase
257 if (Handle
== HandleDatabase
->Handle
) {
258 PackageInstance
= HandleDatabase
->Buffer
;
262 // No handle was found - error condition
264 if (PackageInstance
== NULL
) {
265 return EFI_INVALID_PARAMETER
;
268 ValidatePack (This
, PackageInstance
, &StringPackageInstance
, NULL
);
271 // Based on if there is IFR data in this package instance, determine
272 // what the location is of the beginning of the string data.
274 if (StringPackageInstance
->IfrSize
> 0) {
275 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (&StringPackageInstance
->IfrData
) + StringPackageInstance
->IfrSize
);
277 StringPack
= (EFI_HII_STRING_PACK
*) (&StringPackageInstance
->IfrData
);
280 Location
= StringPack
;
282 // Remember that the string packages are formed into contiguous blocks of language data.
284 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
285 for (Count
= 0; Length
!= 0; Count
= Count
+ 3) {
286 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);
287 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
290 *LanguageString
= AllocateZeroPool (2 * (Count
+ 1));
292 ASSERT (*LanguageString
);
294 StringPack
= (EFI_HII_STRING_PACK
*) Location
;
297 // Copy the 6 bytes to LanguageString - keep concatenating it. Shouldn't we just store uint8's since the ISO
298 // standard defines the lettering as all US English characters anyway? Save a few bytes.
300 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
301 for (Count
= 0; Length
!= 0; Count
= Count
+ 3) {
302 CopyMem (&Token
, &StringPack
->LanguageNameString
, sizeof (RELOFST
));
303 CopyMem (*LanguageString
+ Count
, (VOID
*) ((CHAR8
*) (StringPack
) + Token
), 6);
304 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);
305 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
313 HiiGetSecondaryLanguages (
314 IN EFI_HII_PROTOCOL
*This
,
315 IN EFI_HII_HANDLE Handle
,
316 IN CHAR16
*PrimaryLanguage
,
317 OUT EFI_STRING
*LanguageString
323 This function allows a program to determine which secondary languages are supported
324 on a given handle for a given primary language.
333 EFI_HII_PACKAGE_INSTANCE
*PackageInstance
;
334 EFI_HII_PACKAGE_INSTANCE
*StringPackageInstance
;
335 EFI_HII_DATA
*HiiData
;
336 EFI_HII_HANDLE_DATABASE
*HandleDatabase
;
337 EFI_HII_STRING_PACK
*StringPack
;
342 return EFI_INVALID_PARAMETER
;
345 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
347 // Check numeric value against the head of the database
349 PackageInstance
= NULL
;
350 for (HandleDatabase
= HiiData
->DatabaseHead
;
351 HandleDatabase
!= NULL
;
352 HandleDatabase
= HandleDatabase
->NextHandleDatabase
355 // Match the numeric value with the database entry - if matched, extract PackageInstance
357 if (Handle
== HandleDatabase
->Handle
) {
358 PackageInstance
= HandleDatabase
->Buffer
;
362 // No handle was found - error condition
364 if (PackageInstance
== NULL
) {
365 return EFI_INVALID_PARAMETER
;
368 ValidatePack (This
, PackageInstance
, &StringPackageInstance
, NULL
);
371 // Based on if there is IFR data in this package instance, determine
372 // what the location is of the beginning of the string data.
374 if (StringPackageInstance
->IfrSize
> 0) {
375 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (&StringPackageInstance
->IfrData
) + StringPackageInstance
->IfrSize
);
377 StringPack
= (EFI_HII_STRING_PACK
*) (&StringPackageInstance
->IfrData
);
381 // Remember that the string packages are formed into contiguous blocks of language data.
383 for (; StringPack
->Header
.Length
!= 0;) {
385 // Find the PrimaryLanguage being requested
387 Token
= StringPack
->LanguageNameString
;
388 if (CompareMem ((VOID
*) ((CHAR8
*) (StringPack
) + Token
), PrimaryLanguage
, 3) == 0) {
390 // Now that we found the primary, the secondary languages will follow immediately
391 // or the next character is a NULL if there are no secondary languages. We determine
392 // the number by getting the stringsize based on the StringPack origination + the LanguageNameString
393 // offset + 6 (which is the size of the first 3 letter ISO primary language name). If we get 2, there
394 // are no secondary languages (2 = null-terminator).
396 Count
= StrSize ((VOID
*) ((CHAR8
*) (StringPack
) + Token
+ 6));
398 *LanguageString
= AllocateZeroPool (2 * (Count
+ 1));
400 ASSERT (*LanguageString
);
402 CopyMem (*LanguageString
, (VOID
*) ((CHAR8
*) (StringPack
) + Token
+ 6), Count
);
406 CopyMem (&Length
, &StringPack
->Header
.Length
, sizeof (UINT32
));
407 StringPack
= (EFI_HII_STRING_PACK
*) ((CHAR8
*) (StringPack
) + Length
);