From e425501ea7af0e2cf0397b46bf65f9275f2a5659 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Fri, 25 Mar 2022 17:02:48 +0300 Subject: main: locate graphics output protocol --- UefiMonitorTest/UefiMonitorTest.c | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'UefiMonitorTest') diff --git a/UefiMonitorTest/UefiMonitorTest.c b/UefiMonitorTest/UefiMonitorTest.c index f7c9f04..7cdff88 100644 --- a/UefiMonitorTest/UefiMonitorTest.c +++ b/UefiMonitorTest/UefiMonitorTest.c @@ -10,6 +10,45 @@ #include +STATIC +EFI_GRAPHICS_OUTPUT_PROTOCOL * +GetGraphicsOutputProtocol ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeInfo; + UINTN SizeOfInfo; + + Status = gBS->LocateProtocol ( + &gEfiGraphicsOutputProtocolGuid, + NULL, + (VOID **)&Gop + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to locate GOP\n")); + return NULL; + } + + Status = Gop->QueryMode ( + Gop, + (Gop->Mode == NULL) ? 0 : Gop->Mode->Mode, + &SizeOfInfo, + &ModeInfo + ); + if (Status == EFI_NOT_STARTED) { + Status = Gop->SetMode (Gop, 0); + } + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to get native mode\n")); + return NULL; + } + + // TODO: free ModeInfo + return Gop; +} + EFI_STATUS EFIAPI UefiMain ( @@ -17,5 +56,13 @@ UefiMain ( IN EFI_SYSTEM_TABLE *SystemTable ) { + EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; + + Gop = GetGraphicsOutputProtocol (); + if (Gop == NULL) { + Print (L"Error: Getting a Graphical Output Protocol is failed\n"); + return EFI_NOT_FOUND; + } + return EFI_SUCCESS; } -- cgit v1.2.3-18-g5258