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