/** * Initialise EFI environment * * @v image_handle Image handle * @v systab System table * @ret efirc EFI return status code */ EFI_STATUS efi_init ( EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab ) { EFI_BOOT_SERVICES *bs; struct efi_protocol *prot; struct efi_config_table *tab; EFI_STATUS efirc; /* Store image handle and system table pointer for future use */ efi_image_handle = image_handle; efi_systab = systab; /* Sanity checks */ if ( ! systab ) return EFI_NOT_AVAILABLE_YET; if ( ! systab->ConOut ) return EFI_NOT_AVAILABLE_YET; if ( ! systab->BootServices ) { DBGC ( systab, "EFI provided no BootServices entry point\n" ); return EFI_NOT_AVAILABLE_YET; } if ( ! systab->RuntimeServices ) { DBGC ( systab, "EFI provided no RuntimeServices entry " "point\n" ); return EFI_NOT_AVAILABLE_YET; } DBGC ( systab, "EFI handle %p systab %p\n", image_handle, systab ); /* Look up used protocols */ bs = systab->BootServices; for_each_table_entry ( prot, EFI_PROTOCOLS ) { if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL, prot->protocol ) ) == 0 ) { DBGC ( systab, "EFI protocol %s is at %p\n", uuid_ntoa ( &prot->u.uuid ), *(prot->protocol)); } else { DBGC ( systab, "EFI does not provide protocol %s\n", uuid_ntoa ( &prot->u.uuid ) ); /* All protocols are required */ return efirc; } } /* Look up used configuration tables */ for_each_table_entry ( tab, EFI_CONFIG_TABLES ) { if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) { DBGC ( systab, "EFI configuration table %s is at %p\n", uuid_ntoa ( &tab->u.uuid ), *(tab->table) ); } else { DBGC ( systab, "EFI does not provide configuration " "table %s\n", uuid_ntoa ( &tab->u.uuid ) ); if ( tab->required ) return EFI_NOT_AVAILABLE_YET; } } return 0; }
EFI_STATUS EFIAPI OvrLocateProtocol( IN EFI_GUID *Protocol, IN VOID *Registration, OUT VOID **Interface ) { EFI_STATUS Status; VOID *InterfaceIn = *Interface; Status = gOrgBS.LocateProtocol(Protocol, Registration, Interface); PRINT("->LocateProtocol(%s, %p, %p/%p) = %r\n", GuidStr(Protocol), Registration, InterfaceIn, *Interface, Status); return Status; }
EFI_STATUS EFIAPI BootScriptSaveInitialize ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Intialize Boot Script Lib if it has not yet been initialized. Arguments: (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT) Returns: EFI_STATUS always returns EFI_SUCCESS --*/ // GC_TODO: ImageHandle - add argument and description to function comment // GC_TODO: SystemTable - add argument and description to function comment { EFI_STATUS Status; EFI_BOOT_SERVICES *BS; BS = SystemTable->BootServices; Status = BS->LocateProtocol (&gEfiBootScriptSaveGuid, NULL, (VOID **)&mBootScriptSave); if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) { mBootScriptSave = NULL; } return EFI_SUCCESS; }
EFI_STATUS efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE* Xsystab) { EFI_HANDLE handles[128]; EFI_BLOCK_IO *blkio; UINTN i, nparts = sizeof(handles), cols, rows, max_dim, best_mode; EFI_STATUS status; EFI_DEVICE_PATH *devpath; EFI_BOOT_SERVICES *BS; EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL; SIMPLE_TEXT_OUTPUT_INTERFACE *conout = NULL; const char *path = _PATH_LOADER; systab = Xsystab; image = Ximage; BS = systab->BootServices; status = BS->LocateProtocol(&ConsoleControlGUID, NULL, (VOID **)&ConsoleControl); if (status == EFI_SUCCESS) (void)ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenText); /* * Reset the console and find the best text mode. */ conout = systab->ConOut; conout->Reset(conout, TRUE); max_dim = best_mode = 0; for (i = 0; ; i++) { status = conout->QueryMode(conout, i, &cols, &rows); if (EFI_ERROR(status)) break; if (cols * rows > max_dim) { max_dim = cols * rows; best_mode = i; } } if (max_dim > 0) conout->SetMode(conout, best_mode); conout->EnableCursor(conout, TRUE); conout->ClearScreen(conout); printf("\n" ">> FreeBSD EFI boot block\n"); printf(" Loader path: %s\n", path); status = systab->BootServices->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL, &nparts, handles); nparts /= sizeof(handles[0]); for (i = 0; i < nparts; i++) { status = systab->BootServices->HandleProtocol(handles[i], &DevicePathGUID, (void **)&devpath); if (EFI_ERROR(status)) continue; while (!IsDevicePathEnd(NextDevicePathNode(devpath))) devpath = NextDevicePathNode(devpath); status = systab->BootServices->HandleProtocol(handles[i], &BlockIoProtocolGUID, (void **)&blkio); if (EFI_ERROR(status)) continue; if (!blkio->Media->LogicalPartition) continue; if (domount(devpath, blkio, 1) >= 0) break; } if (i == nparts) panic("No bootable partition found"); bootdevhandle = handles[i]; load(path); panic("Load failed"); return EFI_SUCCESS; }
/** * efi_main - The entry point for the EFI application * @image: firmware-allocated handle that identifies the image * @SystemTable: EFI system table */ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systemTable) { EFI_BOOT_SERVICES *bs = systemTable->BootServices; EFI_GRAPHICS_OUTPUT_PROTOCOL *graphicsProtocol; SIMPLE_TEXT_OUTPUT_INTERFACE *conOut = systemTable->ConOut; EFI_EVENT event = systemTable->ConIn->WaitForKey; UINTN index; int i, modeCount; EFI_STATUS status = bs->LocateProtocol(&GraphicsOutputProtocolGUID, NULL, (void**)&graphicsProtocol); if (EFI_ERROR(status) || graphicsProtocol == NULL) { conOut->OutputString(conOut, L"Failed to init gfx!\r\n"); return status; } //Switch to current mode so gfx is started. status = graphicsProtocol->SetMode(graphicsProtocol, graphicsProtocol->Mode->Mode); if (EFI_ERROR(status)) { conOut->OutputString(conOut, L"Failed to set default mode!\r\n"); return status; } conOut->OutputString(conOut, L"Current mode: "); printInt(conOut, graphicsProtocol->Mode->Mode); conOut->OutputString(conOut, L"\r\n"); modeCount = graphicsProtocol->Mode->MaxMode; for (i = 0; i < modeCount; i++) { conOut->OutputString(conOut, L"\r\n"); printInt(conOut, i); conOut->OutputString(conOut, L": "); EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; UINTN SizeOfInfo; status = graphicsProtocol->QueryMode(graphicsProtocol, i, &SizeOfInfo, &info); if (EFI_ERROR(status)) { conOut->OutputString(conOut, L" Failure to query mode: "); printInt(conOut, status); continue; } printInt(conOut, info->HorizontalResolution); conOut->OutputString(conOut, L" x "); printInt(conOut, info->VerticalResolution); switch(info->PixelFormat) { case PixelRedGreenBlueReserved8BitPerColor: conOut->OutputString(conOut, L" RGB(R)"); break; case PixelBlueGreenRedReserved8BitPerColor: conOut->OutputString(conOut, L" BGR(R)"); break; case PixelBitMask: conOut->OutputString(conOut, L" BitMask "); printInt(conOut, info->PixelInformation.RedMask); conOut->OutputString(conOut, L"R "); printInt(conOut, info->PixelInformation.GreenMask); conOut->OutputString(conOut, L"G "); printInt(conOut, info->PixelInformation.BlueMask); conOut->OutputString(conOut, L"B "); printInt(conOut, info->PixelInformation.ReservedMask); conOut->OutputString(conOut, L"Reserved "); break; case PixelBltOnly: conOut->OutputString(conOut, L" (blt only)"); break; default: conOut->OutputString(conOut, L" (Invalid pixel format)"); break; } conOut->OutputString(conOut, L" Pixel per scanline: "); printInt(conOut, info->PixelsPerScanLine); } bs->WaitForEvent(1, &event, &index); return EFI_SUCCESS; }
EFI_STATUS EFIAPI PpmPolicyEntry( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_BOOT_SERVICES *pBS; EFI_MP_SERVICES_PROTOCOL *MpService; EFI_CPUID_REGISTER Cpuid01 = { 0, 0, 0, 0}; EFI_HANDLE Handle; EFI_STATUS Status; UINTN CpuCount; UINT8 CPUMobileFeature; PCH_STEPPING Stepping; pBS = SystemTable->BootServices; // // Set PPM policy structure to known value // pBS->SetMem (&mDxePlatformPpmPolicy, sizeof(PPM_PLATFORM_POLICY_PROTOCOL), 0); // // Find the MpService Protocol // Status = pBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (void **)&MpService ); ASSERT_EFI_ERROR (Status); // // Get processor count from MP service. // Status = MpService->GetNumberOfProcessors (MpService, &CpuCount, NULL); ASSERT_EFI_ERROR (Status); // // Store the CPUID for use by SETUP items. // AsmCpuid (EFI_CPUID_VERSION_INFO, &Cpuid01.RegEax, &Cpuid01.RegEbx, &Cpuid01.RegEcx, &Cpuid01.RegEdx); mDxePlatformPpmPolicy.Revision = PPM_PLATFORM_POLICY_PROTOCOL_REVISION_4; //Read CPU Mobile feature from PLATFORM_ID_MSR MSR(0x17) NOTFB_I_AM_NOT_MOBILE_FUSE_CLIAMC00H Bit 28 //Bit Description: { Disables Mobile features 0 = I am NOT a mobile part 1 = I am a mobile part (default)"} CPUMobileFeature = ((RShiftU64 (AsmReadMsr64(EFI_MSR_IA32_PLATFORM_ID), 28)) & 0x1); if (!EFI_ERROR(Status)) { if (CPUMobileFeature == 1){//CPU mobile feature mDxePlatformPpmPolicy.FunctionEnables.EnableGv = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableCx = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableCxe = ICH_DEVICE_DISABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableTm = ICH_DEVICE_ENABLE; //MaxC7 mDxePlatformPpmPolicy.FunctionEnables.EnableC7 = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableC6 = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableC4 = ICH_DEVICE_ENABLE; }else{//CPU desktop feature mDxePlatformPpmPolicy.FunctionEnables.EnableGv = ICH_DEVICE_DISABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableCx = ICH_DEVICE_DISABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableCxe = ICH_DEVICE_DISABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableTm = ICH_DEVICE_DISABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableC4 = ICH_DEVICE_DISABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableC6 = ICH_DEVICE_DISABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableC7 = ICH_DEVICE_DISABLE; } mDxePlatformPpmPolicy.FunctionEnables.EnableProcHot = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.TStatesEnable = ICH_DEVICE_ENABLE; Stepping = PchStepping(); if (Stepping < PchB3) { // If SoC is B0~B2 Stepping, disable the Turbo mDxePlatformPpmPolicy.FunctionEnables.EnableTurboMode= ICH_DEVICE_DISABLE; } else { mDxePlatformPpmPolicy.FunctionEnables.EnableTurboMode= ICH_DEVICE_ENABLE; } mDxePlatformPpmPolicy.FunctionEnables.EnableTm = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableCMP = ICH_DEVICE_ENABLE; } else { mDxePlatformPpmPolicy.FunctionEnables.EnableGv = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableCx = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableCxe = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableTm = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableProcHot = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableCMP = ICH_DEVICE_DISABLE; mDxePlatformPpmPolicy.FunctionEnables.TStatesEnable = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableTurboMode= ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableC4 = ICH_DEVICE_ENABLE; mDxePlatformPpmPolicy.FunctionEnables.EnableC6 = ICH_DEVICE_ENABLE; } mDxePlatformPpmPolicy.S3RestoreMsrSwSmiNumber = S3_RESTORE_MSR_SW_SMI; Handle = NULL; Status = pBS->InstallMultipleProtocolInterfaces ( &Handle, &gPpmPlatformPolicyProtocolGuid, &mDxePlatformPpmPolicy, NULL ); ASSERT_EFI_ERROR (Status); return EFI_SUCCESS; }