]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/Uc2OnUcThunk/Uc2OnUcThunk.c
EdkCompatibilityPkg: Fix some typos of "according"
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / Uc2OnUcThunk / Uc2OnUcThunk.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
4f077902 12Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
584d5652 13This program and the accompanying materials\r
03e6b4b2 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
ad5a96ab 33#include <Library/BaseMemoryLib.h>\r
7c9d25ae 34#include <Library/LanguageLib.h>\r
ad5a96ab 35\r
03e6b4b2 36/**\r
4f077902 37 Performs a case-insensitive comparison of two Null-terminated strings.\r
03e6b4b2 38\r
39 @param This Protocol instance pointer.\r
4f077902
SZ
40 @param Str1 A pointer to a Null-terminated string.\r
41 @param Str2 A pointer to a Null-terminated string.\r
03e6b4b2 42\r
43 @retval 0 Str1 is equivalent to Str2\r
44 @retval > 0 Str1 is lexically greater than Str2\r
45 @retval < 0 Str1 is lexically less than Str2\r
46\r
47**/\r
48INTN\r
49EFIAPI\r
50StriColl (\r
51 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
52 IN CHAR16 *Str1,\r
53 IN CHAR16 *Str2\r
e00e1d46 54 );\r
03e6b4b2 55\r
56/**\r
4f077902
SZ
57 Converts all the characters in a Null-terminated string to \r
58 lower case characters.\r
03e6b4b2 59\r
60 @param This Protocol instance pointer.\r
4f077902 61 @param Str A pointer to a Null-terminated string.\r
03e6b4b2 62\r
63**/\r
64VOID\r
65EFIAPI\r
66StrLwr (\r
67 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
68 IN OUT CHAR16 *Str\r
e00e1d46 69 );\r
03e6b4b2 70\r
71/**\r
4f077902
SZ
72 Converts all the characters in a Null-terminated string to upper\r
73 case characters.\r
03e6b4b2 74\r
75 @param This Protocol instance pointer.\r
4f077902 76 @param Str A pointer to a Null-terminated string.\r
03e6b4b2 77\r
78**/\r
79VOID\r
80EFIAPI\r
81StrUpr (\r
82 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
83 IN OUT CHAR16 *Str\r
e00e1d46 84 );\r
03e6b4b2 85\r
86/**\r
4f077902
SZ
87 Performs a case-insensitive comparison of a Null-terminated\r
88 pattern string and a Null-terminated string.\r
03e6b4b2 89\r
90 @param This Protocol instance pointer.\r
4f077902
SZ
91 @param String A pointer to a Null-terminated string.\r
92 @param Pattern A pointer to a Null-terminated pattern string.\r
03e6b4b2 93\r
94 @retval TRUE Pattern was found in String.\r
95 @retval FALSE Pattern was not found in String.\r
96\r
97**/\r
98BOOLEAN\r
99EFIAPI\r
100MetaiMatch (\r
101 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
102 IN CHAR16 *String,\r
103 IN CHAR16 *Pattern\r
e00e1d46 104 );\r
03e6b4b2 105\r
106/**\r
4f077902 107 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.\r
03e6b4b2 108\r
109 @param This Protocol instance pointer.\r
110 @param FatSize The size of the string Fat in bytes.\r
111 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
112 name using an OEM character set.\r
4f077902
SZ
113 @param String A pointer to a Null-terminated string. The string must\r
114 be preallocated to hold FatSize characters.\r
03e6b4b2 115\r
116**/\r
117VOID\r
118EFIAPI\r
119FatToStr (\r
120 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
121 IN UINTN FatSize,\r
122 IN CHAR8 *Fat,\r
123 OUT CHAR16 *String\r
e00e1d46 124 );\r
03e6b4b2 125\r
126/**\r
4f077902 127 Converts a Null-terminated string to legal characters in a FAT \r
03e6b4b2 128 filename using an OEM character set. \r
129\r
130 @param This Protocol instance pointer.\r
4f077902
SZ
131 @param String A pointer to a Null-terminated string. The string must\r
132 be preallocated to hold FatSize characters.\r
03e6b4b2 133 @param FatSize The size of the string Fat in bytes.\r
134 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
135 name using an OEM character set.\r
136\r
137 @retval TRUE Fat is a Long File Name\r
138 @retval FALSE Fat is an 8.3 file name\r
139\r
140**/\r
141BOOLEAN\r
142EFIAPI\r
143StrToFat (\r
144 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
145 IN CHAR16 *String,\r
146 IN UINTN FatSize,\r
147 OUT CHAR8 *Fat\r
e00e1d46 148 );\r
03e6b4b2 149\r
a3a83173 150#define UC2_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '2')\r
03e6b4b2 151\r
152typedef struct {\r
153 UINT32 Signature;\r
26a76fbc
LG
154 EFI_UNICODE_COLLATION_PROTOCOL Uc2;\r
155 EFI_UNICODE_COLLATION_PROTOCOL *Uc;\r
03e6b4b2 156} UC2_PRIVATE_DATA;\r
157\r
26a76fbc 158#define UC2_PRIVATE_DATA_FROM_THIS(a) CR (a, UC2_PRIVATE_DATA, Uc2, UC2_PRIVATE_DATA_SIGNATURE)\r
03e6b4b2 159\r
160//\r
161// Firmware Volume Protocol template\r
162//\r
163EFI_EVENT mUc2Registration;\r
164\r
165UC2_PRIVATE_DATA gUC2PrivateDataTemplate = {\r
166 UC2_PRIVATE_DATA_SIGNATURE,\r
167 {\r
168 StriColl,\r
169 MetaiMatch,\r
170 StrLwr,\r
171 StrUpr,\r
172 FatToStr,\r
173 StrToFat,\r
174 NULL\r
175 },\r
176 NULL\r
177};\r
178\r
179//\r
180// Module globals\r
181//\r
26a76fbc
LG
182/**\r
183 This notification function is invoked when an instance of the\r
184 EFI_UNICODE_COLLATION_PROTOCOL is produced. It installs another instance of the\r
185 EFI_UNICODE_COLLATION_PROTOCOL2 on the same handle.\r
186\r
187 @param Event The event that occured\r
188 @param Context Context of event. Not used in this nofication function.\r
03e6b4b2 189\r
26a76fbc 190**/\r
03e6b4b2 191VOID\r
192EFIAPI\r
cd289975 193UcNotificationEvent (\r
03e6b4b2 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
26a76fbc 246 (VOID **)&Private->Uc\r
03e6b4b2 247 );\r
248 ASSERT_EFI_ERROR (Status);\r
249\r
250 //\r
251 // Fill in rest of private data structure\r
252 //\r
26a76fbc
LG
253 Private->Uc2.SupportedLanguages = ConvertLanguagesIso639ToRfc4646 (Private->Uc->SupportedLanguages);\r
254 if (Private->Uc2.SupportedLanguages != NULL) {\r
03e6b4b2 255\r
256 //\r
26a76fbc 257 // Install UC2 Protocol onto same handle\r
03e6b4b2 258 //\r
259 Status = gBS->InstallMultipleProtocolInterfaces (\r
260 &Handle,\r
261 &gEfiUnicodeCollation2ProtocolGuid,\r
26a76fbc 262 &Private->Uc2,\r
03e6b4b2 263 NULL\r
264 );\r
265 ASSERT_EFI_ERROR (Status);\r
266 }\r
267 }\r
268}\r
269\r
270\r
271/**\r
272 The user Entry Point for DXE driver. The user code starts with this function\r
273 as the real entry point for the image goes into a library that calls this \r
274 function.\r
275\r
276 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
277 @param[in] SystemTable A pointer to the EFI System Table.\r
278 \r
279 @retval EFI_SUCCESS The entry point is executed successfully.\r
280 @retval other Some error occurs when executing this entry point.\r
281\r
282**/\r
283EFI_STATUS\r
284EFIAPI\r
285InitializeUC2 (\r
286 IN EFI_HANDLE ImageHandle,\r
287 IN EFI_SYSTEM_TABLE *SystemTable\r
288 )\r
289{\r
290 EfiCreateProtocolNotifyEvent (\r
291 &gEfiUnicodeCollationProtocolGuid,\r
292 TPL_CALLBACK,\r
cd289975 293 UcNotificationEvent,\r
03e6b4b2 294 NULL,\r
295 &mUc2Registration\r
296 );\r
297 return EFI_SUCCESS;\r
298}\r
299\r
300\r
301/**\r
4f077902 302 Performs a case-insensitive comparison of two Null-terminated strings.\r
03e6b4b2 303\r
304 @param This Protocol instance pointer.\r
4f077902
SZ
305 @param Str1 A pointer to a Null-terminated string.\r
306 @param Str2 A pointer to a Null-terminated string.\r
03e6b4b2 307\r
308 @retval 0 Str1 is equivalent to Str2\r
309 @retval > 0 Str1 is lexically greater than Str2\r
310 @retval < 0 Str1 is lexically less than Str2\r
311\r
312**/\r
313INTN\r
314EFIAPI\r
315StriColl (\r
316 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
317 IN CHAR16 *Str1,\r
318 IN CHAR16 *Str2\r
319 )\r
320{\r
321 UC2_PRIVATE_DATA *Private;\r
322 \r
323 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
324 \r
26a76fbc 325 return Private->Uc->StriColl (Private->Uc, Str1, Str2);\r
03e6b4b2 326}\r
327\r
328\r
329/**\r
4f077902
SZ
330 Converts all the characters in a Null-terminated string to \r
331 lower case characters.\r
03e6b4b2 332\r
333 @param This Protocol instance pointer.\r
4f077902 334 @param Str A pointer to a Null-terminated string.\r
03e6b4b2 335\r
336**/\r
337VOID\r
338EFIAPI\r
339StrLwr (\r
340 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
341 IN OUT CHAR16 *Str\r
342 )\r
343{\r
344 UC2_PRIVATE_DATA *Private;\r
345 \r
346 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
347 \r
26a76fbc 348 Private->Uc->StrLwr (Private->Uc, Str);\r
03e6b4b2 349}\r
350\r
351\r
352/**\r
4f077902
SZ
353 Converts all the characters in a Null-terminated string to upper\r
354 case characters.\r
03e6b4b2 355\r
356 @param This Protocol instance pointer.\r
4f077902 357 @param Str A pointer to a Null-terminated string.\r
03e6b4b2 358\r
359**/\r
360VOID\r
361EFIAPI\r
362StrUpr (\r
363 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
364 IN OUT CHAR16 *Str\r
365 )\r
366{\r
367 UC2_PRIVATE_DATA *Private;\r
368 \r
369 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
370 \r
26a76fbc 371 Private->Uc->StrUpr (Private->Uc, Str);\r
03e6b4b2 372}\r
373\r
374/**\r
4f077902
SZ
375 Performs a case-insensitive comparison of a Null-terminated\r
376 pattern string and a Null-terminated string.\r
03e6b4b2 377\r
378 @param This Protocol instance pointer.\r
4f077902
SZ
379 @param String A pointer to a Null-terminated string.\r
380 @param Pattern A pointer to a Null-terminated pattern string.\r
03e6b4b2 381\r
382 @retval TRUE Pattern was found in String.\r
383 @retval FALSE Pattern was not found in String.\r
384\r
385**/\r
386BOOLEAN\r
387EFIAPI\r
388MetaiMatch (\r
389 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
390 IN CHAR16 *String,\r
391 IN CHAR16 *Pattern\r
392 )\r
393{\r
394 UC2_PRIVATE_DATA *Private;\r
395 \r
396 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
397 \r
26a76fbc 398 return Private->Uc->MetaiMatch (Private->Uc, String, Pattern);\r
03e6b4b2 399}\r
400\r
401\r
402/**\r
4f077902 403 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.\r
03e6b4b2 404\r
405 @param This Protocol instance pointer.\r
406 @param FatSize The size of the string Fat in bytes.\r
407 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
4f077902
SZ
408 name using an 8-bit OEM character set.\r
409 @param String A pointer to a Null-terminated string. The string must\r
410 be preallocated to hold FatSize characters.\r
03e6b4b2 411\r
412**/\r
413VOID\r
414EFIAPI\r
415FatToStr (\r
416 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
417 IN UINTN FatSize,\r
418 IN CHAR8 *Fat,\r
419 OUT CHAR16 *String\r
420 )\r
421{\r
422 UC2_PRIVATE_DATA *Private;\r
423 \r
424 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
425 \r
26a76fbc 426 Private->Uc->FatToStr (Private->Uc, FatSize, Fat, String);\r
03e6b4b2 427}\r
428\r
429\r
430/**\r
4f077902 431 Converts a Null-terminated string to legal characters in a FAT \r
03e6b4b2 432 filename using an OEM character set. \r
433\r
434 @param This Protocol instance pointer.\r
4f077902
SZ
435 @param String A pointer to a Null-terminated string. The string must\r
436 be preallocated to hold FatSize characters.\r
03e6b4b2 437 @param FatSize The size of the string Fat in bytes.\r
438 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
439 name using an OEM character set.\r
440\r
441 @retval TRUE Fat is a Long File Name\r
442 @retval FALSE Fat is an 8.3 file name\r
443\r
444**/\r
445BOOLEAN\r
446EFIAPI\r
447StrToFat (\r
448 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
449 IN CHAR16 *String,\r
450 IN UINTN FatSize,\r
451 OUT CHAR8 *Fat\r
452 )\r
453{\r
454 UC2_PRIVATE_DATA *Private;\r
455 \r
456 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
457 \r
26a76fbc 458 return Private->Uc->StrToFat (Private->Uc, String, FatSize, Fat);\r
03e6b4b2 459}\r
460\r