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