diff options
Diffstat (limited to 'memtestEDK/Memtest/GraphicsOutput/GraphicsOutputProtocol.c')
-rw-r--r-- | memtestEDK/Memtest/GraphicsOutput/GraphicsOutputProtocol.c | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/memtestEDK/Memtest/GraphicsOutput/GraphicsOutputProtocol.c b/memtestEDK/Memtest/GraphicsOutput/GraphicsOutputProtocol.c new file mode 100644 index 0000000..e2e661b --- /dev/null +++ b/memtestEDK/Memtest/GraphicsOutput/GraphicsOutputProtocol.c @@ -0,0 +1,160 @@ +#include <stdio.h> + +#include <stdint.h> +#include <Uefi.h> +#include <Library/UefiLib.h> +#include <Library/UefiApplicationEntryPoint.h> + + + +static int +memcmp(const void *s1, const void *s2, UINTN n) +{ + const unsigned char *c1 = s1, *c2 = s2; + int d = 0; + + if (!s1 && !s2) + return 0; + if (s1 && !s2) + return 1; + if (!s1 && s2) + return -1; + + while (n--) { + d = (int)*c1++ - (int)*c2++; + if (d) + break; + } + + return d; +} + +EFI_STATUS +PrintGOP(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) +{ + int i, imax; + EFI_STATUS Status; + + imax = gop->Mode->MaxMode; + + Print(L"GOP reports MaxMode %d\n", imax); + + for (i = 0; i < imax; i++) { + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; + UINTN SizeOfInfo; + + Status = gop->QueryMode(gop, i, &SizeOfInfo, &Info); + if (EFI_ERROR(Status) && Status == EFI_NOT_STARTED) { + gop->SetMode(gop, gop->Mode->Mode); + Status = gop->QueryMode(gop, i, &SizeOfInfo, &Info); + } + + if (EFI_ERROR(Status)) { + Print(L"ERROR: Bad response from QueryMode: %d\n", Status); + continue; + } + Print(L"%c%d: %dx%d ", memcmp(Info,gop->Mode->Info,sizeof(*Info)) == 0 ? '*' : ' ', i, + Info->HorizontalResolution, + Info->VerticalResolution); + switch(Info->PixelFormat) { + case PixelRedGreenBlueReserved8BitPerColor: + Print(L"RGBRerserved"); + break; + case PixelBlueGreenRedReserved8BitPerColor: + Print(L"BGRReserved"); + break; + case PixelBitMask: + Print(L"Red:%08x Green:%08x Blue:%08x Reserved:%08x", + Info->PixelInformation.RedMask, + Info->PixelInformation.GreenMask, + Info->PixelInformation.BlueMask, + Info->PixelInformation.ReservedMask); + break; + case PixelBltOnly: + Print(L"(blt only)"); + break; + default: + Print(L"(Invalid pixel format)"); + break; + } + Print(L" Pixels %d\n", Info->PixelsPerScanLine); + } + Print(L"\n"); + + return EFI_SUCCESS; +} + + +EFI_STATUS +CheckGOP(BOOLEAN Verbose, IN EFI_SYSTEM_TABLE *gST, IN EFI_BOOT_SERVICES *gBS) +{ + EFI_HANDLE *HandleBuffer = NULL; + UINTN HandleCount = 0; + EFI_STATUS Status = EFI_SUCCESS; + EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; + + + // get from ConsoleOutHandle? + Status = gBS->HandleProtocol( gST->ConsoleOutHandle, + &gEfiGraphicsOutputProtocolGuid, + (VOID **) &Gop); + if (EFI_ERROR (Status)) { + Print(L"No GOP handle found via HandleProtocol\n"); + } else { + Print(L"GOP handle found via HandleProtocol\n"); + if (Verbose) + PrintGOP(Gop); + } + + // try locating directly + Status = gBS->LocateProtocol( &gEfiGraphicsOutputProtocolGuid, + NULL, + (VOID **) &Gop); + if (EFI_ERROR(Status) || Gop == NULL) { + Print(L"No GOP handle found via LocateProtocol\n"); + } else { + Print(L"Found GOP handle via LocateProtocol\n"); + if (Verbose) + PrintGOP(Gop); + } + + // try locating by handle + Status = gBS->LocateHandleBuffer( ByProtocol, + &gEfiGraphicsOutputProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer); + if (EFI_ERROR (Status)) { + Print(L"No GOP handles found via LocateHandleBuffer\n"); + } else { + Print(L"Found %d GOP handles via LocateHandleBuffer\n", HandleCount); + for (int i = 0; i < HandleCount; i++) { + Status = gBS->HandleProtocol( HandleBuffer[i], + &gEfiGraphicsOutputProtocolGuid, + (VOID*) &Gop); + if (!EFI_ERROR (Status)) { + if (Verbose) + PrintGOP(Gop); + } + } + gBS->FreePool(HandleBuffer); + } + + Print(L"\n"); + + return Status; +} + +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + + CheckGOP(TRUE, SystemTable, SystemTable->BootServices); + + return EFI_SUCCESS; + +}
\ No newline at end of file |