1 /* $NetBSD: modelist.c,v 1.1.1.3 2021/09/30 18:50:09 jmcneill Exp $ */ 2 3 #include <efi.h> 4 #include <efilib.h> 5 6 extern EFI_GUID GraphicsOutputProtocol; 7 8 static void 9 print_modes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) 10 { 11 int i, imax; 12 EFI_STATUS rc; 13 14 if (gop->Mode) { 15 imax = gop->Mode->MaxMode; 16 Print(L"GOP reports MaxMode %d\n", imax); 17 } else { 18 Print(L"gop->Mode is NULL\n"); 19 imax = 1; 20 } 21 22 for (i = 0; i < imax; i++) { 23 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; 24 UINTN SizeOfInfo; 25 rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo, 26 &info); 27 if (rc == EFI_NOT_STARTED) { 28 Print(L"gop->QueryMode() returned %r\n", rc); 29 Print(L"Trying to start GOP with SetMode().\n"); 30 rc = uefi_call_wrapper(gop->SetMode, 2, gop, 31 gop->Mode ? gop->Mode->Mode : 0); 32 rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, 33 &SizeOfInfo, &info); 34 } 35 36 if (EFI_ERROR(rc)) { 37 Print(L"%d: Bad response from QueryMode: %r (%d)\n", 38 i, rc, rc); 39 continue; 40 } 41 Print(L"%c%d: %dx%d ", 42 (gop->Mode && 43 CompareMem(info,gop->Mode->Info,sizeof(*info)) == 0 44 ) ? '*' : ' ', 45 i, info->HorizontalResolution, info->VerticalResolution); 46 switch(info->PixelFormat) { 47 case PixelRedGreenBlueReserved8BitPerColor: 48 Print(L"RGBR"); 49 break; 50 case PixelBlueGreenRedReserved8BitPerColor: 51 Print(L"BGRR"); 52 break; 53 case PixelBitMask: 54 Print(L"R:%08x G:%08x B:%08x X:%08x", 55 info->PixelInformation.RedMask, 56 info->PixelInformation.GreenMask, 57 info->PixelInformation.BlueMask, 58 info->PixelInformation.ReservedMask); 59 break; 60 case PixelBltOnly: 61 Print(L"(blt only)"); 62 break; 63 default: 64 Print(L"(Invalid pixel format)"); 65 break; 66 } 67 Print(L" pitch %d\n", info->PixelsPerScanLine); 68 } 69 } 70 71 static EFI_STATUS 72 SetWatchdog(UINTN seconds) 73 { 74 EFI_STATUS rc; 75 rc = uefi_call_wrapper(BS->SetWatchdogTimer, 4, seconds, 0x1ffff, 76 0, NULL); 77 if (EFI_ERROR(rc)) { 78 CHAR16 Buffer[64]; 79 StatusToString(Buffer, rc); 80 Print(L"Bad response from QueryMode: %s (%d)\n", Buffer, rc); 81 } 82 return rc; 83 } 84 85 EFI_STATUS 86 efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab) 87 { 88 EFI_STATUS rc; 89 EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; 90 91 InitializeLib(image_handle, systab); 92 93 SetWatchdog(10); 94 95 rc = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop); 96 if (EFI_ERROR(rc)) { 97 Print(L"Could not locate GOP: %r\n", rc); 98 return rc; 99 } 100 101 if (!gop) { 102 Print(L"LocateProtocol(GOP, &gop) returned %r but GOP is NULL\n", rc); 103 return EFI_UNSUPPORTED; 104 } 105 106 print_modes(gop); 107 108 SetWatchdog(0); 109 return EFI_SUCCESS; 110 } 111