]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.c
Add in some features for the thunk layer:
[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
18
19 EFI_HII_THUNK_PRIVATE_DATA HiiThunkPrivateDataTempate = {
20 {//Signature
21 EFI_HII_THUNK_DRIVER_DATA_SIGNATURE
22 },
23 {//Handle
24 (EFI_HANDLE) NULL
25 },
26 { //Hii
27 HiiNewPack,
28 HiiRemovePack,
29 HiiFindHandles,
30 HiiExportDatabase,
31
32 HiiTestString,
33 HiiGetGlyph,
34 HiiGlyphToBlt,
35
36 HiiNewString,
37 HiiGetPrimaryLanguages,
38 HiiGetSecondaryLanguages,
39 HiiGetString,
40 HiiResetStrings,
41 HiiGetLine,
42 HiiGetForms,
43 HiiGetDefaultImage,
44 HiiUpdateForm,
45
46 HiiGetKeyboardLayout
47 },
48 { //StaticHiiHandle
49 //The FRAMEWORK_EFI_HII_HANDLE starts from 1
50 // and increase upwords untill reach 2^(sizeof (FRAMEWORK_EFI_HII_HANDLE)) - 1.
51 // The code will assert to prevent overflow.
52 (FRAMEWORK_EFI_HII_HANDLE) 1
53 },
54 {
55 NULL, NULL //HiiHandleLinkList
56 },
57 };
58
59 CONST EFI_HII_DATABASE_PROTOCOL *mUefiHiiDatabaseProtocol;
60 CONST EFI_HII_FONT_PROTOCOL *mUefiHiiFontProtocol;
61 CONST EFI_HII_IMAGE_PROTOCOL *mUefiHiiImageProtocol;
62 CONST EFI_HII_STRING_PROTOCOL *mUefiStringProtocol;
63 CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *mUefiConfigRoutingProtocol;
64
65
66 EFI_STATUS
67 EFIAPI
68 InitializeHiiDatabase (
69 IN EFI_HANDLE ImageHandle,
70 IN EFI_SYSTEM_TABLE *SystemTable
71 )
72 /*++
73
74 Routine Description:
75 Initialize HII Database
76
77 Arguments:
78 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
79
80 Returns:
81 EFI_SUCCESS - Setup loaded.
82 other - Setup Error
83
84 --*/
85 {
86 EFI_HII_THUNK_PRIVATE_DATA *HiiData;
87 EFI_HANDLE Handle;
88 EFI_STATUS Status;
89
90 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiProtocolGuid);
91
92 HiiData = AllocateCopyPool (sizeof (EFI_HII_THUNK_PRIVATE_DATA), &HiiThunkPrivateDataTempate);
93 ASSERT (HiiData != NULL);
94 InitializeListHead (&HiiData->HiiThunkHandleMappingDBListHead);
95
96 Status = gBS->LocateProtocol (
97 &gEfiHiiDatabaseProtocolGuid,
98 NULL,
99 (VOID **) &mUefiHiiDatabaseProtocol
100 );
101 ASSERT_EFI_ERROR (Status);
102
103 Status = gBS->LocateProtocol (
104 &gEfiHiiFontProtocolGuid,
105 NULL,
106 (VOID **) &mUefiHiiFontProtocol
107 );
108 ASSERT_EFI_ERROR (Status);
109
110 Status = gBS->LocateProtocol (
111 &gEfiHiiImageProtocolGuid,
112 NULL,
113 (VOID **) &mUefiHiiImageProtocol
114 );
115 ASSERT_EFI_ERROR (Status);
116
117 Status = gBS->LocateProtocol (
118 &gEfiHiiStringProtocolGuid,
119 NULL,
120 (VOID **) &mUefiStringProtocol
121 );
122 ASSERT_EFI_ERROR (Status);
123
124 Status = gBS->LocateProtocol (
125 &gEfiHiiConfigRoutingProtocolGuid,
126 NULL,
127 (VOID **) &mUefiConfigRoutingProtocol
128 );
129 ASSERT_EFI_ERROR (Status);
130
131 //
132 // Install protocol interface
133 //
134 Handle = NULL;
135 Status = gBS->InstallProtocolInterface (
136 &HiiData->Handle,
137 &gEfiHiiProtocolGuid,
138 EFI_NATIVE_INTERFACE,
139 (VOID *) &HiiData->Hii
140 );
141 ASSERT_EFI_ERROR (Status);
142
143 return Status;
144 }
145
146 EFI_STATUS
147 EFIAPI
148 HiiFindHandles (
149 IN EFI_HII_PROTOCOL *This,
150 IN OUT UINT16 *HandleBufferLength,
151 OUT FRAMEWORK_EFI_HII_HANDLE Handle[1]
152 )
153 /*++
154
155 Routine Description:
156 Determines the handles that are currently active in the database.
157
158 Arguments:
159
160 Returns:
161
162 --*/
163 {
164 ASSERT (FALSE);
165 return EFI_SUCCESS;
166 }
167
168 EFI_STATUS
169 EFIAPI
170 HiiGetPrimaryLanguages (
171 IN EFI_HII_PROTOCOL *This,
172 IN FRAMEWORK_EFI_HII_HANDLE Handle,
173 OUT EFI_STRING *LanguageString
174 )
175 /*++
176
177 Routine Description:
178
179 This function allows a program to determine what the primary languages that are supported on a given handle.
180
181 Arguments:
182
183 Returns:
184
185 --*/
186 {
187 EFI_HII_THUNK_PRIVATE_DATA *Private;
188 EFI_HII_HANDLE UefiHiiHandle;
189 CHAR8 *AsciiLanguageCodes;
190 CHAR16 *UnicodeLanguageCodes;
191
192 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
193
194
195
196 UefiHiiHandle = FrameworkHiiHandleToUefiHiiHandle (Private, Handle);
197 if (UefiHiiHandle == NULL) {
198 return EFI_INVALID_PARAMETER;
199 }
200
201 AsciiLanguageCodes = HiiLibGetSupportedLanguages (UefiHiiHandle);
202
203 if (AsciiLanguageCodes == NULL) {
204 return EFI_INVALID_PARAMETER;
205 }
206
207 UnicodeLanguageCodes = AllocateZeroPool (AsciiStrSize (AsciiLanguageCodes) * sizeof (CHAR16));
208 if (UnicodeLanguageCodes == NULL) {
209 return EFI_OUT_OF_RESOURCES;
210 }
211
212 //
213 // The language returned is in RFC 3066 format.
214 //
215 *LanguageString = AsciiStrToUnicodeStr (AsciiLanguageCodes, UnicodeLanguageCodes);
216
217 return EFI_SUCCESS;
218 }
219
220 EFI_STATUS
221 EFIAPI
222 HiiGetSecondaryLanguages (
223 IN EFI_HII_PROTOCOL *This,
224 IN FRAMEWORK_EFI_HII_HANDLE Handle,
225 IN CHAR16 *PrimaryLanguage,
226 OUT EFI_STRING *LanguageString
227 )
228 /*++
229
230 Routine Description:
231
232 This function allows a program to determine which secondary languages are supported
233 on a given handle for a given primary language.
234
235 Arguments:
236
237 Returns:
238
239 --*/
240 {
241 EFI_HII_THUNK_PRIVATE_DATA *Private;
242 EFI_HII_HANDLE UefiHiiHandle;
243 CHAR8 *AsciiPrimaryLanguage;
244 CHAR8 *AsciiLanguageCodes;
245 CHAR16 *UnicodeLanguageCodes;
246
247 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
248
249
250
251 UefiHiiHandle = FrameworkHiiHandleToUefiHiiHandle (Private, Handle);
252 if (UefiHiiHandle == NULL) {
253 return EFI_INVALID_PARAMETER;
254 }
255
256 AsciiPrimaryLanguage = AllocateZeroPool (StrLen (PrimaryLanguage) + 1);
257
258 UnicodeStrToAsciiStr (PrimaryLanguage, AsciiPrimaryLanguage);
259
260 AsciiLanguageCodes = HiiLibGetSupportedSecondaryLanguages (UefiHiiHandle, AsciiPrimaryLanguage);
261
262 if (AsciiLanguageCodes == NULL) {
263 return EFI_INVALID_PARAMETER;
264 }
265
266 UnicodeLanguageCodes = AllocateZeroPool (AsciiStrSize (AsciiLanguageCodes) * sizeof (CHAR16));
267 if (UnicodeLanguageCodes == NULL) {
268 return EFI_OUT_OF_RESOURCES;
269 }
270
271 //
272 // The language returned is in RFC 3066 format.
273 //
274 *LanguageString = AsciiStrToUnicodeStr (AsciiLanguageCodes, UnicodeLanguageCodes);
275
276 return EFI_SUCCESS;
277 }
278
279