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