2013-02-21 19:45:36 +04:00
|
|
|
#include <efi.h>
|
|
|
|
#include <efilib.h>
|
|
|
|
|
|
|
|
extern EFI_GUID GraphicsOutputProtocol;
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_modes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
|
|
|
|
{
|
|
|
|
int i, imax;
|
|
|
|
EFI_STATUS rc;
|
|
|
|
|
2018-03-13 22:20:31 +03:00
|
|
|
if (gop->Mode) {
|
|
|
|
imax = gop->Mode->MaxMode;
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"GOP reports MaxMode %d\n", imax);
|
2018-03-13 22:20:31 +03:00
|
|
|
} else {
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"gop->Mode is NULL\n");
|
2018-03-13 22:20:31 +03:00
|
|
|
imax = 1;
|
|
|
|
}
|
2013-02-21 19:45:36 +04:00
|
|
|
|
|
|
|
for (i = 0; i < imax; i++) {
|
|
|
|
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
|
|
|
|
UINTN SizeOfInfo;
|
|
|
|
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo,
|
|
|
|
&info);
|
2021-06-23 23:23:14 +03:00
|
|
|
if (rc == EFI_NOT_STARTED) {
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"gop->QueryMode() returned %r\n", rc);
|
|
|
|
Print(u"Trying to start GOP with SetMode().\n");
|
2013-02-21 19:45:36 +04:00
|
|
|
rc = uefi_call_wrapper(gop->SetMode, 2, gop,
|
2018-03-13 22:20:31 +03:00
|
|
|
gop->Mode ? gop->Mode->Mode : 0);
|
2013-02-21 19:45:36 +04:00
|
|
|
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i,
|
|
|
|
&SizeOfInfo, &info);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR(rc)) {
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"%d: Bad response from QueryMode: %r (%d)\n",
|
2018-03-13 22:20:31 +03:00
|
|
|
i, rc, rc);
|
2013-02-21 19:45:36 +04:00
|
|
|
continue;
|
|
|
|
}
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"%c%d: %dx%d ",
|
2018-03-13 22:20:31 +03:00
|
|
|
(gop->Mode &&
|
|
|
|
CompareMem(info,gop->Mode->Info,sizeof(*info)) == 0
|
|
|
|
) ? '*' : ' ',
|
|
|
|
i, info->HorizontalResolution, info->VerticalResolution);
|
2013-02-21 19:45:36 +04:00
|
|
|
switch(info->PixelFormat) {
|
|
|
|
case PixelRedGreenBlueReserved8BitPerColor:
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"RGBR");
|
2013-02-21 19:45:36 +04:00
|
|
|
break;
|
|
|
|
case PixelBlueGreenRedReserved8BitPerColor:
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"BGRR");
|
2013-02-21 19:45:36 +04:00
|
|
|
break;
|
|
|
|
case PixelBitMask:
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"R:%08x G:%08x B:%08x X:%08x",
|
2013-02-21 19:45:36 +04:00
|
|
|
info->PixelInformation.RedMask,
|
|
|
|
info->PixelInformation.GreenMask,
|
|
|
|
info->PixelInformation.BlueMask,
|
|
|
|
info->PixelInformation.ReservedMask);
|
|
|
|
break;
|
|
|
|
case PixelBltOnly:
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"(blt only)");
|
2013-02-21 19:45:36 +04:00
|
|
|
break;
|
|
|
|
default:
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"(Invalid pixel format)");
|
2013-02-21 19:45:36 +04:00
|
|
|
break;
|
|
|
|
}
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u" pitch %d\n", info->PixelsPerScanLine);
|
2013-02-21 19:45:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static EFI_STATUS
|
|
|
|
SetWatchdog(UINTN seconds)
|
|
|
|
{
|
|
|
|
EFI_STATUS rc;
|
|
|
|
rc = uefi_call_wrapper(BS->SetWatchdogTimer, 4, seconds, 0x1ffff,
|
|
|
|
0, NULL);
|
|
|
|
if (EFI_ERROR(rc)) {
|
|
|
|
CHAR16 Buffer[64];
|
|
|
|
StatusToString(Buffer, rc);
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"Bad response from QueryMode: %s (%d)\n", Buffer, rc);
|
2013-02-21 19:45:36 +04:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
|
|
|
|
{
|
|
|
|
EFI_STATUS rc;
|
|
|
|
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
|
|
|
|
|
|
|
|
InitializeLib(image_handle, systab);
|
|
|
|
|
|
|
|
SetWatchdog(10);
|
|
|
|
|
|
|
|
rc = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop);
|
2018-03-13 22:20:31 +03:00
|
|
|
if (EFI_ERROR(rc)) {
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"Could not locate GOP: %r\n", rc);
|
2013-02-21 19:45:36 +04:00
|
|
|
return rc;
|
2018-03-13 22:20:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gop) {
|
2024-05-30 18:39:00 +03:00
|
|
|
Print(u"LocateProtocol(GOP, &gop) returned %r but GOP is NULL\n", rc);
|
2018-03-13 22:20:31 +03:00
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
2013-02-21 19:45:36 +04:00
|
|
|
|
|
|
|
print_modes(gop);
|
|
|
|
|
|
|
|
SetWatchdog(0);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|