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