]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/Uc2ToUcThunk/Uc2ToUcThunk.c
Add in Uc2ToUcThunk module.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / Uc2ToUcThunk / Uc2ToUcThunk.c
CommitLineData
03e6b4b2 1/** @file\r
2Module produce UC2 on top of UC.\r
3\r
4UEFI 2.1 specification supersedes Inte's EFI Specification 1.10.\r
5EFI_UNICODE_COLLATION_PROTOCOL defined in Inte's EFI Specification 1.10 is replaced by\r
6EFI_UNICODE_COLLATION_PROTOCOL in UEFI 2.1.\r
7This module produces UC2 on top of UC. This module is used on platform when both of\r
8these two conditions are true:\r
91) EFI 1.10 module producing UC present\r
102) And the rest of modules on the platform consume UC2\r
11\r
12Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
13All rights reserved. This program and the accompanying materials\r
14are licensed and made available under the terms and conditions of the BSD License\r
15which accompanies this distribution. The full text of the license may be found at\r
16http://opensource.org/licenses/bsd-license.php\r
17\r
18THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
19WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
20Module Name:\r
21\r
22**/\r
23\r
24#include <PiDxe.h>\r
25#include <Protocol/UnicodeCollation.h>\r
26#include <Library/BaseLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/UefiBootServicesTableLib.h>\r
29#include <Library/UefiDriverEntryPoint.h>\r
30#include <Library/UefiLib.h>\r
31#include <Library/MemoryAllocationLib.h>\r
32#include <Library/HiiLib.h>\r
33\r
34\r
35\r
36/**\r
37 Performs a case-insensitive comparison of two Null-terminated Unicode \r
38 strings.\r
39\r
40 @param This Protocol instance pointer.\r
41 @param Str1 A pointer to a Null-terminated Unicode string.\r
42 @param Str2 A pointer to a Null-terminated Unicode string.\r
43\r
44 @retval 0 Str1 is equivalent to Str2\r
45 @retval > 0 Str1 is lexically greater than Str2\r
46 @retval < 0 Str1 is lexically less than Str2\r
47\r
48**/\r
49INTN\r
50EFIAPI\r
51StriColl (\r
52 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
53 IN CHAR16 *Str1,\r
54 IN CHAR16 *Str2\r
55 )\r
56;\r
57\r
58/**\r
59 Converts all the Unicode characters in a Null-terminated Unicode string to \r
60 lower case Unicode characters.\r
61\r
62 @param This Protocol instance pointer.\r
63 @param Str A pointer to a Null-terminated Unicode string.\r
64\r
65**/\r
66VOID\r
67EFIAPI\r
68StrLwr (\r
69 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
70 IN OUT CHAR16 *Str\r
71 )\r
72;\r
73\r
74/**\r
75 Converts all the Unicode characters in a Null-terminated Unicode string to upper\r
76 case Unicode characters.\r
77\r
78 @param This Protocol instance pointer.\r
79 @param Str A pointer to a Null-terminated Unicode string.\r
80\r
81**/\r
82VOID\r
83EFIAPI\r
84StrUpr (\r
85 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
86 IN OUT CHAR16 *Str\r
87 )\r
88;\r
89\r
90/**\r
91 Performs a case-insensitive comparison of a Null-terminated Unicode \r
92 pattern string and a Null-terminated Unicode string.\r
93\r
94 @param This Protocol instance pointer.\r
95 @param String A pointer to a Null-terminated Unicode string.\r
96 @param Pattern A pointer to a Null-terminated Unicode pattern string.\r
97\r
98 @retval TRUE Pattern was found in String.\r
99 @retval FALSE Pattern was not found in String.\r
100\r
101**/\r
102BOOLEAN\r
103EFIAPI\r
104MetaiMatch (\r
105 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
106 IN CHAR16 *String,\r
107 IN CHAR16 *Pattern\r
108 )\r
109;\r
110\r
111/**\r
112 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r
113 Unicode string.\r
114\r
115 @param This Protocol instance pointer.\r
116 @param FatSize The size of the string Fat in bytes.\r
117 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
118 name using an OEM character set.\r
119 @param String A pointer to a Null-terminated Unicode string. The string must\r
120 be preallocated to hold FatSize Unicode characters.\r
121\r
122**/\r
123VOID\r
124EFIAPI\r
125FatToStr (\r
126 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
127 IN UINTN FatSize,\r
128 IN CHAR8 *Fat,\r
129 OUT CHAR16 *String\r
130 )\r
131;\r
132\r
133/**\r
134 Converts a Null-terminated Unicode string to legal characters in a FAT \r
135 filename using an OEM character set. \r
136\r
137 @param This Protocol instance pointer.\r
138 @param String A pointer to a Null-terminated Unicode string. The string must\r
139 be preallocated to hold FatSize Unicode characters.\r
140 @param FatSize The size of the string Fat in bytes.\r
141 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
142 name using an OEM character set.\r
143\r
144 @retval TRUE Fat is a Long File Name\r
145 @retval FALSE Fat is an 8.3 file name\r
146\r
147**/\r
148BOOLEAN\r
149EFIAPI\r
150StrToFat (\r
151 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
152 IN CHAR16 *String,\r
153 IN UINTN FatSize,\r
154 OUT CHAR8 *Fat\r
155 )\r
156;\r
157\r
158#define UC2_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('_', 'U', 'C', '2')\r
159\r
160typedef struct {\r
161 UINT32 Signature;\r
162 EFI_UNICODE_COLLATION_PROTOCOL UC2;\r
163 EFI_UNICODE_COLLATION_PROTOCOL *UC;\r
164} UC2_PRIVATE_DATA;\r
165\r
166#define UC2_PRIVATE_DATA_FROM_THIS(a) CR (a, UC2_PRIVATE_DATA, UC, UC2_PRIVATE_DATA_SIGNATURE)\r
167\r
168//\r
169// Firmware Volume Protocol template\r
170//\r
171EFI_EVENT mUc2Registration;\r
172\r
173UC2_PRIVATE_DATA gUC2PrivateDataTemplate = {\r
174 UC2_PRIVATE_DATA_SIGNATURE,\r
175 {\r
176 StriColl,\r
177 MetaiMatch,\r
178 StrLwr,\r
179 StrUpr,\r
180 FatToStr,\r
181 StrToFat,\r
182 NULL\r
183 },\r
184 NULL\r
185};\r
186\r
187//\r
188// Module globals\r
189//\r
190\r
191VOID\r
192EFIAPI\r
193Uc2NotificationEvent (\r
194 IN EFI_EVENT Event,\r
195 IN VOID *Context\r
196 )\r
197{\r
198 EFI_STATUS Status;\r
199 UINTN BufferSize;\r
200 EFI_HANDLE Handle;\r
201 UC2_PRIVATE_DATA *Private;\r
202 EFI_UNICODE_COLLATION_PROTOCOL *Uc2;\r
203\r
204 while (TRUE) {\r
205 BufferSize = sizeof (Handle);\r
206 Status = gBS->LocateHandle (\r
207 ByRegisterNotify,\r
208 &gEfiUnicodeCollationProtocolGuid,\r
209 mUc2Registration,\r
210 &BufferSize,\r
211 &Handle\r
212 );\r
213 if (EFI_ERROR (Status)) {\r
214 //\r
215 // Exit Path of While Loop....\r
216 //\r
217 break;\r
218 }\r
219\r
220 //\r
221 // Skip this handle if the Firmware Volume Protocol is already installed\r
222 //\r
223 Status = gBS->HandleProtocol (\r
224 Handle,\r
225 &gEfiUnicodeCollation2ProtocolGuid,\r
226 (VOID **)&Uc2\r
227 );\r
228 if (!EFI_ERROR (Status)) {\r
229 continue;\r
230 }\r
231\r
232 //\r
233 // Allocate private data structure\r
234 //\r
235 Private = AllocateCopyPool (sizeof (UC2_PRIVATE_DATA), &gUC2PrivateDataTemplate);\r
236 if (Private == NULL) {\r
237 continue;\r
238 }\r
239\r
240 //\r
241 // Retrieve the UC Protocol\r
242 //\r
243 Status = gBS->HandleProtocol (\r
244 Handle,\r
245 &gEfiUnicodeCollationProtocolGuid,\r
246 (VOID **)&Private->UC\r
247 );\r
248 ASSERT_EFI_ERROR (Status);\r
249\r
250 //\r
251 // Fill in rest of private data structure\r
252 //\r
253 Private->UC2.SupportedLanguages = AllocateZeroPool (RFC_3066_ENTRY_SIZE);\r
254 Status = ConvertIso639LanguageToRfc3066Language (Private->UC->SupportedLanguages ,Private->UC2.SupportedLanguages);\r
255\r
256 if (!EFI_ERROR (Status)) {\r
257\r
258 //\r
259 // Install Firmware Volume Protocol onto same handle\r
260 //\r
261 Status = gBS->InstallMultipleProtocolInterfaces (\r
262 &Handle,\r
263 &gEfiUnicodeCollation2ProtocolGuid,\r
264 &Private->UC2,\r
265 NULL\r
266 );\r
267 ASSERT_EFI_ERROR (Status);\r
268 }\r
269 }\r
270}\r
271\r
272\r
273/**\r
274 The user Entry Point for DXE driver. The user code starts with this function\r
275 as the real entry point for the image goes into a library that calls this \r
276 function.\r
277\r
278 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
279 @param[in] SystemTable A pointer to the EFI System Table.\r
280 \r
281 @retval EFI_SUCCESS The entry point is executed successfully.\r
282 @retval other Some error occurs when executing this entry point.\r
283\r
284**/\r
285EFI_STATUS\r
286EFIAPI\r
287InitializeUC2 (\r
288 IN EFI_HANDLE ImageHandle,\r
289 IN EFI_SYSTEM_TABLE *SystemTable\r
290 )\r
291{\r
292 EfiCreateProtocolNotifyEvent (\r
293 &gEfiUnicodeCollationProtocolGuid,\r
294 TPL_CALLBACK,\r
295 Uc2NotificationEvent,\r
296 NULL,\r
297 &mUc2Registration\r
298 );\r
299 return EFI_SUCCESS;\r
300}\r
301\r
302\r
303/**\r
304 Performs a case-insensitive comparison of two Null-terminated Unicode \r
305 strings.\r
306\r
307 @param This Protocol instance pointer.\r
308 @param Str1 A pointer to a Null-terminated Unicode string.\r
309 @param Str2 A pointer to a Null-terminated Unicode string.\r
310\r
311 @retval 0 Str1 is equivalent to Str2\r
312 @retval > 0 Str1 is lexically greater than Str2\r
313 @retval < 0 Str1 is lexically less than Str2\r
314\r
315**/\r
316INTN\r
317EFIAPI\r
318StriColl (\r
319 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
320 IN CHAR16 *Str1,\r
321 IN CHAR16 *Str2\r
322 )\r
323{\r
324 UC2_PRIVATE_DATA *Private;\r
325 \r
326 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
327 \r
328 return Private->UC->StriColl (Private->UC, Str1, Str2);\r
329}\r
330\r
331\r
332/**\r
333 Converts all the Unicode characters in a Null-terminated Unicode string to \r
334 lower case Unicode characters.\r
335\r
336 @param This Protocol instance pointer.\r
337 @param Str A pointer to a Null-terminated Unicode string.\r
338\r
339**/\r
340VOID\r
341EFIAPI\r
342StrLwr (\r
343 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
344 IN OUT CHAR16 *Str\r
345 )\r
346{\r
347 UC2_PRIVATE_DATA *Private;\r
348 \r
349 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
350 \r
351 Private->UC->StrLwr (Private->UC, Str);\r
352}\r
353\r
354\r
355/**\r
356 Converts all the Unicode characters in a Null-terminated Unicode string to upper\r
357 case Unicode characters.\r
358\r
359 @param This Protocol instance pointer.\r
360 @param Str A pointer to a Null-terminated Unicode string.\r
361\r
362**/\r
363VOID\r
364EFIAPI\r
365StrUpr (\r
366 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
367 IN OUT CHAR16 *Str\r
368 )\r
369{\r
370 UC2_PRIVATE_DATA *Private;\r
371 \r
372 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
373 \r
374 Private->UC->StrUpr (Private->UC, Str);\r
375}\r
376\r
377/**\r
378 Performs a case-insensitive comparison of a Null-terminated Unicode \r
379 pattern string and a Null-terminated Unicode string.\r
380\r
381 @param This Protocol instance pointer.\r
382 @param String A pointer to a Null-terminated Unicode string.\r
383 @param Pattern A pointer to a Null-terminated Unicode pattern string.\r
384\r
385 @retval TRUE Pattern was found in String.\r
386 @retval FALSE Pattern was not found in String.\r
387\r
388**/\r
389BOOLEAN\r
390EFIAPI\r
391MetaiMatch (\r
392 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
393 IN CHAR16 *String,\r
394 IN CHAR16 *Pattern\r
395 )\r
396{\r
397 UC2_PRIVATE_DATA *Private;\r
398 \r
399 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
400 \r
401 return Private->UC->MetaiMatch (Private->UC, String, Pattern);\r
402}\r
403\r
404\r
405/**\r
406 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r
407 Unicode string.\r
408\r
409 @param This Protocol instance pointer.\r
410 @param FatSize The size of the string Fat in bytes.\r
411 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
412 name using an OEM character set.\r
413 @param String A pointer to a Null-terminated Unicode string. The string must\r
414 be preallocated to hold FatSize Unicode characters.\r
415\r
416**/\r
417VOID\r
418EFIAPI\r
419FatToStr (\r
420 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
421 IN UINTN FatSize,\r
422 IN CHAR8 *Fat,\r
423 OUT CHAR16 *String\r
424 )\r
425{\r
426 UC2_PRIVATE_DATA *Private;\r
427 \r
428 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
429 \r
430 Private->UC->FatToStr (Private->UC, FatSize, Fat, String);\r
431}\r
432\r
433\r
434/**\r
435 Converts a Null-terminated Unicode string to legal characters in a FAT \r
436 filename using an OEM character set. \r
437\r
438 @param This Protocol instance pointer.\r
439 @param String A pointer to a Null-terminated Unicode string. The string must\r
440 be preallocated to hold FatSize Unicode characters.\r
441 @param FatSize The size of the string Fat in bytes.\r
442 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
443 name using an OEM character set.\r
444\r
445 @retval TRUE Fat is a Long File Name\r
446 @retval FALSE Fat is an 8.3 file name\r
447\r
448**/\r
449BOOLEAN\r
450EFIAPI\r
451StrToFat (\r
452 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
453 IN CHAR16 *String,\r
454 IN UINTN FatSize,\r
455 OUT CHAR8 *Fat\r
456 )\r
457{\r
458 UC2_PRIVATE_DATA *Private;\r
459 \r
460 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
461 \r
462 return Private->UC->StrToFat (Private->UC, String, FatSize, Fat);\r
463}\r
464\r