modelist.c 2.5 KB

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