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