c7f2344
From cd8986077a785053abee62a3faf0708759625f7a Mon Sep 17 00:00:00 2001
c7f2344
From: Peter Jones <pjones@redhat.com>
c7f2344
Date: Fri, 10 Sep 2010 16:04:38 -0400
c7f2344
Subject: [PATCH] Add "modelist" test app.
c7f2344
c7f2344
This lists video modes the GOP driver is showing us.
c7f2344
---
c7f2344
 apps/Makefile   |    2 +-
c7f2344
 apps/modelist.c |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
c7f2344
 2 files changed, 87 insertions(+), 1 deletions(-)
c7f2344
 create mode 100644 apps/modelist.c
c7f2344
c7f2344
diff --git a/apps/Makefile b/apps/Makefile
c7f2344
index 2baf64d..6b50e4f 100644
c7f2344
--- a/apps/Makefile
c7f2344
+++ b/apps/Makefile
c7f2344
@@ -38,7 +38,7 @@ LDFLAGS		+= -T $(LDSCRIPT) -shared -Bsymbolic -L../lib -L../gnuefi $(CRTOBJS)
c7f2344
 LOADLIBES	= -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
c7f2344
 FORMAT		= efi-app-$(ARCH)
c7f2344
 
c7f2344
-TARGETS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi printenv.efi t7.efi route80h.efi
c7f2344
+TARGETS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi printenv.efi t7.efi route80h.efi modelist.efi
c7f2344
 
c7f2344
 all:	$(TARGETS)
c7f2344
 
c7f2344
diff --git a/apps/modelist.c b/apps/modelist.c
c7f2344
new file mode 100644
c7f2344
index 0000000..0f6e75d
c7f2344
--- /dev/null
c7f2344
+++ b/apps/modelist.c
c7f2344
@@ -0,0 +1,86 @@
c7f2344
+#include <efi.h>
c7f2344
+#include <efilib.h>
c7f2344
+
c7f2344
+extern EFI_GUID GraphicsOutputProtocol;
c7f2344
+
c7f2344
+static void
c7f2344
+print_modes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
c7f2344
+{
c7f2344
+	int i, imax;
c7f2344
+	EFI_STATUS rc;
c7f2344
+
c7f2344
+	imax = gop->Mode->MaxMode;
c7f2344
+
c7f2344
+	Print(L"GOP reports MaxMode %d\n", imax);
c7f2344
+	for (i = 0; i < imax; i++) {
c7f2344
+		EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
c7f2344
+		UINTN SizeOfInfo;
c7f2344
+		rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo,
c7f2344
+					&info;;
c7f2344
+		if (EFI_ERROR(rc)) {
c7f2344
+			CHAR16 Buffer[64];
c7f2344
+			StatusToString(Buffer, rc);
c7f2344
+			Print(L"%d: Bad response from QueryMode: %s (%d)\n",
c7f2344
+				i, Buffer, rc);
c7f2344
+			continue;
c7f2344
+		}
c7f2344
+		Print(L"%d: %dx%d ", i, info->HorizontalResolution,
c7f2344
+			info->VerticalResolution);
c7f2344
+		switch(info->PixelFormat) {
c7f2344
+			case PixelRedGreenBlueReserved8BitPerColor:
c7f2344
+				Print(L"RGBR");
c7f2344
+				break;
c7f2344
+			case PixelBlueGreenRedReserved8BitPerColor:
c7f2344
+				Print(L"BGRR");
c7f2344
+				break;
c7f2344
+			case PixelBitMask:
c7f2344
+				Print(L"R:%08x G:%08x B:%08x X:%08x",
c7f2344
+					info->PixelInformation.RedMask,
c7f2344
+					info->PixelInformation.GreenMask,
c7f2344
+					info->PixelInformation.BlueMask,
c7f2344
+					info->PixelInformation.ReservedMask);
c7f2344
+				break;
c7f2344
+			case PixelBltOnly:
c7f2344
+				Print(L"(blt only)");
c7f2344
+				break;
c7f2344
+			default:
c7f2344
+				Print(L"(Invalid pixel format)");
c7f2344
+				break;
c7f2344
+		}
c7f2344
+		Print(L" pitch %d\n", info->PixelsPerScanLine);
c7f2344
+	}
c7f2344
+}
c7f2344
+
c7f2344
+static EFI_STATUS
c7f2344
+SetWatchdog(UINTN seconds)
c7f2344
+{
c7f2344
+	EFI_STATUS rc;
c7f2344
+	rc = uefi_call_wrapper(BS->SetWatchdogTimer, 4, seconds, 0x1ffff,
c7f2344
+				0, NULL);
c7f2344
+	if (EFI_ERROR(rc)) {
c7f2344
+		CHAR16 Buffer[64];
c7f2344
+		StatusToString(Buffer, rc);
c7f2344
+		Print(L"Bad response from QueryMode: %s (%d)\n", Buffer, rc);
c7f2344
+	}
c7f2344
+	return rc;
c7f2344
+}
c7f2344
+
c7f2344
+EFI_STATUS
c7f2344
+efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
c7f2344
+{
c7f2344
+	EFI_STATUS rc;
c7f2344
+	EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
c7f2344
+
c7f2344
+	InitializeLib(image_handle, systab);
c7f2344
+
c7f2344
+	SetWatchdog(10);
c7f2344
+
c7f2344
+	rc = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop);
c7f2344
+	if (EFI_ERROR(rc))
c7f2344
+		return rc;
c7f2344
+
c7f2344
+	print_modes(gop);
c7f2344
+
c7f2344
+	SetWatchdog(0);
c7f2344
+	return EFI_SUCCESS;
c7f2344
+}
c7f2344
-- 
c7f2344
1.7.2.3
c7f2344