1*530d68baSNigel Croxon /*++ 2*530d68baSNigel Croxon 3*530d68baSNigel Croxon Copyright (c) 1998 Intel Corporation 4*530d68baSNigel Croxon 5*530d68baSNigel Croxon Module Name: 6*530d68baSNigel Croxon 7*530d68baSNigel Croxon 8*530d68baSNigel Croxon Abstract: 9*530d68baSNigel Croxon 10*530d68baSNigel Croxon 11*530d68baSNigel Croxon 12*530d68baSNigel Croxon 13*530d68baSNigel Croxon Revision History 14*530d68baSNigel Croxon 15*530d68baSNigel Croxon --*/ 16*530d68baSNigel Croxon 17*530d68baSNigel Croxon #include "lib.h" 18*530d68baSNigel Croxon 19*530d68baSNigel Croxon VOID 20*530d68baSNigel Croxon EFIDebugVariable ( 21*530d68baSNigel Croxon VOID 22*530d68baSNigel Croxon ); 23*530d68baSNigel Croxon 24*530d68baSNigel Croxon VOID 25*530d68baSNigel Croxon InitializeLib ( 26*530d68baSNigel Croxon IN EFI_HANDLE ImageHandle, 27*530d68baSNigel Croxon IN EFI_SYSTEM_TABLE *SystemTable 28*530d68baSNigel Croxon ) 29*530d68baSNigel Croxon /*++ 30*530d68baSNigel Croxon 31*530d68baSNigel Croxon Routine Description: 32*530d68baSNigel Croxon 33*530d68baSNigel Croxon Initializes EFI library for use 34*530d68baSNigel Croxon 35*530d68baSNigel Croxon Arguments: 36*530d68baSNigel Croxon 37*530d68baSNigel Croxon Firmware's EFI system table 38*530d68baSNigel Croxon 39*530d68baSNigel Croxon Returns: 40*530d68baSNigel Croxon 41*530d68baSNigel Croxon None 42*530d68baSNigel Croxon 43*530d68baSNigel Croxon --*/ 44*530d68baSNigel Croxon { 45*530d68baSNigel Croxon EFI_LOADED_IMAGE *LoadedImage; 46*530d68baSNigel Croxon EFI_STATUS Status; 47*530d68baSNigel Croxon CHAR8 *LangCode; 48*530d68baSNigel Croxon 49*530d68baSNigel Croxon if (!LibInitialized) { 50*530d68baSNigel Croxon LibInitialized = TRUE; 51*530d68baSNigel Croxon LibFwInstance = FALSE; 52*530d68baSNigel Croxon 53*530d68baSNigel Croxon // 54*530d68baSNigel Croxon // Set up global pointer to the system table, boot services table, 55*530d68baSNigel Croxon // and runtime services table 56*530d68baSNigel Croxon // 57*530d68baSNigel Croxon 58*530d68baSNigel Croxon ST = SystemTable; 59*530d68baSNigel Croxon BS = SystemTable->BootServices; 60*530d68baSNigel Croxon RT = SystemTable->RuntimeServices; 61*530d68baSNigel Croxon // ASSERT (CheckCrc(0, &ST->Hdr)); 62*530d68baSNigel Croxon // ASSERT (CheckCrc(0, &BS->Hdr)); 63*530d68baSNigel Croxon // ASSERT (CheckCrc(0, &RT->Hdr)); 64*530d68baSNigel Croxon 65*530d68baSNigel Croxon 66*530d68baSNigel Croxon // 67*530d68baSNigel Croxon // Initialize pool allocation type 68*530d68baSNigel Croxon // 69*530d68baSNigel Croxon 70*530d68baSNigel Croxon if (ImageHandle) { 71*530d68baSNigel Croxon Status = uefi_call_wrapper( 72*530d68baSNigel Croxon BS->HandleProtocol, 73*530d68baSNigel Croxon 3, 74*530d68baSNigel Croxon ImageHandle, 75*530d68baSNigel Croxon &LoadedImageProtocol, 76*530d68baSNigel Croxon (VOID*)&LoadedImage 77*530d68baSNigel Croxon ); 78*530d68baSNigel Croxon 79*530d68baSNigel Croxon if (!EFI_ERROR(Status)) { 80*530d68baSNigel Croxon PoolAllocationType = LoadedImage->ImageDataType; 81*530d68baSNigel Croxon } 82*530d68baSNigel Croxon 83*530d68baSNigel Croxon EFIDebugVariable (); 84*530d68baSNigel Croxon } 85*530d68baSNigel Croxon 86*530d68baSNigel Croxon // 87*530d68baSNigel Croxon // Initialize Guid table 88*530d68baSNigel Croxon // 89*530d68baSNigel Croxon 90*530d68baSNigel Croxon InitializeGuid(); 91*530d68baSNigel Croxon 92*530d68baSNigel Croxon InitializeLibPlatform(ImageHandle,SystemTable); 93*530d68baSNigel Croxon } 94*530d68baSNigel Croxon 95*530d68baSNigel Croxon // 96*530d68baSNigel Croxon // 97*530d68baSNigel Croxon // 98*530d68baSNigel Croxon 99*530d68baSNigel Croxon if (ImageHandle && UnicodeInterface == &LibStubUnicodeInterface) { 100*530d68baSNigel Croxon LangCode = LibGetVariable (VarLanguage, &EfiGlobalVariable); 101*530d68baSNigel Croxon InitializeUnicodeSupport (LangCode); 102*530d68baSNigel Croxon if (LangCode) { 103*530d68baSNigel Croxon FreePool (LangCode); 104*530d68baSNigel Croxon } 105*530d68baSNigel Croxon } 106*530d68baSNigel Croxon } 107*530d68baSNigel Croxon 108*530d68baSNigel Croxon VOID 109*530d68baSNigel Croxon InitializeUnicodeSupport ( 110*530d68baSNigel Croxon CHAR8 *LangCode 111*530d68baSNigel Croxon ) 112*530d68baSNigel Croxon { 113*530d68baSNigel Croxon EFI_UNICODE_COLLATION_INTERFACE *Ui; 114*530d68baSNigel Croxon EFI_STATUS Status; 115*530d68baSNigel Croxon CHAR8 *Languages; 116*530d68baSNigel Croxon UINTN Index, Position, Length; 117*530d68baSNigel Croxon UINTN NoHandles; 118*530d68baSNigel Croxon EFI_HANDLE *Handles; 119*530d68baSNigel Croxon 120*530d68baSNigel Croxon // 121*530d68baSNigel Croxon // If we don't know it, lookup the current language code 122*530d68baSNigel Croxon // 123*530d68baSNigel Croxon 124*530d68baSNigel Croxon LibLocateHandle (ByProtocol, &UnicodeCollationProtocol, NULL, &NoHandles, &Handles); 125*530d68baSNigel Croxon if (!LangCode || !NoHandles) { 126*530d68baSNigel Croxon goto Done; 127*530d68baSNigel Croxon } 128*530d68baSNigel Croxon 129*530d68baSNigel Croxon // 130*530d68baSNigel Croxon // Check all driver's for a matching language code 131*530d68baSNigel Croxon // 132*530d68baSNigel Croxon 133*530d68baSNigel Croxon for (Index=0; Index < NoHandles; Index++) { 134*530d68baSNigel Croxon Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handles[Index], &UnicodeCollationProtocol, (VOID*)&Ui); 135*530d68baSNigel Croxon if (EFI_ERROR(Status)) { 136*530d68baSNigel Croxon continue; 137*530d68baSNigel Croxon } 138*530d68baSNigel Croxon 139*530d68baSNigel Croxon // 140*530d68baSNigel Croxon // Check for a matching language code 141*530d68baSNigel Croxon // 142*530d68baSNigel Croxon 143*530d68baSNigel Croxon Languages = Ui->SupportedLanguages; 144*530d68baSNigel Croxon Length = strlena(Languages); 145*530d68baSNigel Croxon for (Position=0; Position < Length; Position += ISO_639_2_ENTRY_SIZE) { 146*530d68baSNigel Croxon 147*530d68baSNigel Croxon // 148*530d68baSNigel Croxon // If this code matches, use this driver 149*530d68baSNigel Croxon // 150*530d68baSNigel Croxon 151*530d68baSNigel Croxon if (CompareMem (Languages+Position, LangCode, ISO_639_2_ENTRY_SIZE) == 0) { 152*530d68baSNigel Croxon UnicodeInterface = Ui; 153*530d68baSNigel Croxon goto Done; 154*530d68baSNigel Croxon } 155*530d68baSNigel Croxon } 156*530d68baSNigel Croxon } 157*530d68baSNigel Croxon 158*530d68baSNigel Croxon Done: 159*530d68baSNigel Croxon // 160*530d68baSNigel Croxon // Cleanup 161*530d68baSNigel Croxon // 162*530d68baSNigel Croxon 163*530d68baSNigel Croxon if (Handles) { 164*530d68baSNigel Croxon FreePool (Handles); 165*530d68baSNigel Croxon } 166*530d68baSNigel Croxon } 167*530d68baSNigel Croxon 168*530d68baSNigel Croxon VOID 169*530d68baSNigel Croxon EFIDebugVariable ( 170*530d68baSNigel Croxon VOID 171*530d68baSNigel Croxon ) 172*530d68baSNigel Croxon { 173*530d68baSNigel Croxon EFI_STATUS Status; 174*530d68baSNigel Croxon UINT32 Attributes; 175*530d68baSNigel Croxon UINTN DataSize; 176*530d68baSNigel Croxon UINTN NewEFIDebug; 177*530d68baSNigel Croxon 178*530d68baSNigel Croxon DataSize = sizeof(EFIDebug); 179*530d68baSNigel Croxon Status = uefi_call_wrapper(RT->GetVariable, 5, L"EFIDebug", &EfiGlobalVariable, &Attributes, &DataSize, &NewEFIDebug); 180*530d68baSNigel Croxon if (!EFI_ERROR(Status)) { 181*530d68baSNigel Croxon EFIDebug = NewEFIDebug; 182*530d68baSNigel Croxon } 183*530d68baSNigel Croxon } 184