]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/UcOnUc2Thunk/UcOnUc2Thunk.c
Add missing Type 35 support and correct SmbiosFldMiscType13 implementation.
[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 - 2010, Intel Corporation. All rights reserved.<BR>
13 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 #include <Library/BaseMemoryLib.h>
34 #include <Library/LanguageLib.h>
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 UC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '_')
153
154 typedef struct {
155 UINT32 Signature;
156 EFI_UNICODE_COLLATION_PROTOCOL Uc;
157 EFI_UNICODE_COLLATION_PROTOCOL *Uc2;
158 } UC_PRIVATE_DATA;
159
160 #define UC_PRIVATE_DATA_FROM_THIS(a) CR (a, UC_PRIVATE_DATA, Uc, UC_PRIVATE_DATA_SIGNATURE)
161
162 //
163 // Firmware Volume Protocol template
164 //
165 EFI_EVENT mUcRegistration;
166
167 UC_PRIVATE_DATA gUCPrivateDataTemplate = {
168 UC_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 This notification function is invoked when an instance of the
186 EFI_UNICODE_COLLATION_PROTOCOL2 is produced. It installs another instance of the
187 EFI_UNICODE_COLLATION_PROTOCOL on the same handle.
188
189 @param Event The event that occured
190 @param Context Context of event. Not used in this nofication function.
191
192 **/
193 VOID
194 EFIAPI
195 Uc2NotificationEvent (
196 IN EFI_EVENT Event,
197 IN VOID *Context
198 )
199 {
200 EFI_STATUS Status;
201 UINTN BufferSize;
202 EFI_HANDLE Handle;
203 UC_PRIVATE_DATA *Private;
204 EFI_UNICODE_COLLATION_PROTOCOL *Uc2;
205
206 while (TRUE) {
207 BufferSize = sizeof (Handle);
208 Status = gBS->LocateHandle (
209 ByRegisterNotify,
210 &gEfiUnicodeCollation2ProtocolGuid,
211 mUcRegistration,
212 &BufferSize,
213 &Handle
214 );
215 if (EFI_ERROR (Status)) {
216 //
217 // Exit Path of While Loop....
218 //
219 break;
220 }
221
222 //
223 // Skip this handle if the Firmware Volume Protocol is already installed
224 //
225 Status = gBS->HandleProtocol (
226 Handle,
227 &gEfiUnicodeCollationProtocolGuid,
228 (VOID **)&Uc2
229 );
230 if (!EFI_ERROR (Status)) {
231 continue;
232 }
233
234 //
235 // Allocate private data structure
236 //
237 Private = AllocateCopyPool (sizeof (UC_PRIVATE_DATA), &gUCPrivateDataTemplate);
238 if (Private == NULL) {
239 continue;
240 }
241
242 //
243 // Retrieve the UC Protocol
244 //
245 Status = gBS->HandleProtocol (
246 Handle,
247 &gEfiUnicodeCollation2ProtocolGuid,
248 (VOID **)&Private->Uc2
249 );
250 ASSERT_EFI_ERROR (Status);
251
252 //
253 // Fill in rest of private data structure
254 //
255 Private->Uc.SupportedLanguages = ConvertLanguagesRfc4646ToIso639 (Private->Uc2->SupportedLanguages);
256
257 if (Private->Uc.SupportedLanguages != NULL) {
258
259 //
260 // Install Firmware Volume Protocol onto same handle
261 //
262 Status = gBS->InstallMultipleProtocolInterfaces (
263 &Handle,
264 &gEfiUnicodeCollationProtocolGuid,
265 &Private->Uc,
266 NULL
267 );
268 ASSERT_EFI_ERROR (Status);
269 }
270 }
271 }
272
273
274 /**
275 The user Entry Point for DXE driver. The user code starts with this function
276 as the real entry point for the image goes into a library that calls this
277 function.
278
279 @param[in] ImageHandle The firmware allocated handle for the EFI image.
280 @param[in] SystemTable A pointer to the EFI System Table.
281
282 @retval EFI_SUCCESS The entry point is executed successfully.
283 @retval other Some error occurs when executing this entry point.
284
285 **/
286 EFI_STATUS
287 EFIAPI
288 InitializeUC (
289 IN EFI_HANDLE ImageHandle,
290 IN EFI_SYSTEM_TABLE *SystemTable
291 )
292 {
293 EfiCreateProtocolNotifyEvent (
294 &gEfiUnicodeCollation2ProtocolGuid,
295 TPL_CALLBACK,
296 Uc2NotificationEvent,
297 NULL,
298 &mUcRegistration
299 );
300 return EFI_SUCCESS;
301 }
302
303
304 /**
305 Performs a case-insensitive comparison of two Null-terminated Unicode
306 strings.
307
308 @param This Protocol instance pointer.
309 @param Str1 A pointer to a Null-terminated Unicode string.
310 @param Str2 A pointer to a Null-terminated Unicode string.
311
312 @retval 0 Str1 is equivalent to Str2
313 @retval > 0 Str1 is lexically greater than Str2
314 @retval < 0 Str1 is lexically less than Str2
315
316 **/
317 INTN
318 EFIAPI
319 StriColl (
320 IN EFI_UNICODE_COLLATION_PROTOCOL *This,
321 IN CHAR16 *Str1,
322 IN CHAR16 *Str2
323 )
324 {
325 UC_PRIVATE_DATA *Private;
326
327 Private = UC_PRIVATE_DATA_FROM_THIS (This);
328
329 return Private->Uc2->StriColl (Private->Uc2, Str1, Str2);
330 }
331
332
333 /**
334 Converts all the Unicode characters in a Null-terminated Unicode string to
335 lower case Unicode characters.
336
337 @param This Protocol instance pointer.
338 @param Str A pointer to a Null-terminated Unicode string.
339
340 **/
341 VOID
342 EFIAPI
343 StrLwr (
344 IN EFI_UNICODE_COLLATION_PROTOCOL *This,
345 IN OUT CHAR16 *Str
346 )
347 {
348 UC_PRIVATE_DATA *Private;
349
350 Private = UC_PRIVATE_DATA_FROM_THIS (This);
351
352 Private->Uc2->StrLwr (Private->Uc2, Str);
353 }
354
355
356 /**
357 Converts all the Unicode characters in a Null-terminated Unicode string to upper
358 case Unicode characters.
359
360 @param This Protocol instance pointer.
361 @param Str A pointer to a Null-terminated Unicode string.
362
363 **/
364 VOID
365 EFIAPI
366 StrUpr (
367 IN EFI_UNICODE_COLLATION_PROTOCOL *This,
368 IN OUT CHAR16 *Str
369 )
370 {
371 UC_PRIVATE_DATA *Private;
372
373 Private = UC_PRIVATE_DATA_FROM_THIS (This);
374
375 Private->Uc2->StrUpr (Private->Uc2, Str);
376 }
377
378 /**
379 Performs a case-insensitive comparison of a Null-terminated Unicode
380 pattern string and a Null-terminated Unicode string.
381
382 @param This Protocol instance pointer.
383 @param String A pointer to a Null-terminated Unicode string.
384 @param Pattern A pointer to a Null-terminated Unicode pattern string.
385
386 @retval TRUE Pattern was found in String.
387 @retval FALSE Pattern was not found in String.
388
389 **/
390 BOOLEAN
391 EFIAPI
392 MetaiMatch (
393 IN EFI_UNICODE_COLLATION_PROTOCOL *This,
394 IN CHAR16 *String,
395 IN CHAR16 *Pattern
396 )
397 {
398 UC_PRIVATE_DATA *Private;
399
400 Private = UC_PRIVATE_DATA_FROM_THIS (This);
401
402 return Private->Uc2->MetaiMatch (Private->Uc2, String, Pattern);
403 }
404
405
406 /**
407 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated
408 Unicode string.
409
410 @param This Protocol instance pointer.
411 @param FatSize The size of the string Fat in bytes.
412 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
413 name using an OEM character set.
414 @param String A pointer to a Null-terminated Unicode string. The string must
415 be preallocated to hold FatSize Unicode characters.
416
417 **/
418 VOID
419 EFIAPI
420 FatToStr (
421 IN EFI_UNICODE_COLLATION_PROTOCOL *This,
422 IN UINTN FatSize,
423 IN CHAR8 *Fat,
424 OUT CHAR16 *String
425 )
426 {
427 UC_PRIVATE_DATA *Private;
428
429 Private = UC_PRIVATE_DATA_FROM_THIS (This);
430
431 Private->Uc2->FatToStr (Private->Uc2, FatSize, Fat, String);
432 }
433
434
435 /**
436 Converts a Null-terminated Unicode string to legal characters in a FAT
437 filename using an OEM character set.
438
439 @param This Protocol instance pointer.
440 @param String A pointer to a Null-terminated Unicode string. The string must
441 be preallocated to hold FatSize Unicode characters.
442 @param FatSize The size of the string Fat in bytes.
443 @param Fat A pointer to a Null-terminated string that contains an 8.3 file
444 name using an OEM character set.
445
446 @retval TRUE Fat is a Long File Name
447 @retval FALSE Fat is an 8.3 file name
448
449 **/
450 BOOLEAN
451 EFIAPI
452 StrToFat (
453 IN EFI_UNICODE_COLLATION_PROTOCOL *This,
454 IN CHAR16 *String,
455 IN UINTN FatSize,
456 OUT CHAR8 *Fat
457 )
458 {
459 UC_PRIVATE_DATA *Private;
460
461 Private = UC_PRIVATE_DATA_FROM_THIS (This);
462
463 return Private->Uc2->StrToFat (Private->Uc2, String, FatSize, Fat);
464 }
465