modelist.c 2.4 KB

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