git: 76cbf7864063 - stable/13 - loader.efi: Do not use as frame buffer BLT-only GOPs.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Thu, 23 Dec 2021 04:02:17 UTC
The branch stable/13 has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=76cbf786406311b7d89db0b725f9cd0c890e54e4

commit 76cbf786406311b7d89db0b725f9cd0c890e54e4
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2021-12-16 16:44:34 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2021-12-23 04:02:11 +0000

    loader.efi: Do not use as frame buffer BLT-only GOPs.
    
    Kernel needs physical frame buffer address and size, which Block
    Transfer-only Graphics Output Protocol instances do not have.
    
    Some recent ASUS boards like PRIME Z690M-PLUS D4 and PRIME H570-Plus
    report two GOPs, out of which the second one support ConOut protocol,
    that made it preferable, but is BLT-only, that made console unusable.
    
    Discussed with: tsoome (previous version)
    MFC after:      1 week
    
    (cherry picked from commit 02732f945ed2ec2b4fd03421923720608b28a615)
---
 stand/efi/loader/framebuffer.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/stand/efi/loader/framebuffer.c b/stand/efi/loader/framebuffer.c
index adb9dfb62cee..b62ed17d3d29 100644
--- a/stand/efi/loader/framebuffer.c
+++ b/stand/efi/loader/framebuffer.c
@@ -567,21 +567,33 @@ efi_find_framebuffer(teken_gfx_t *gfx_state)
 	/*
 	 * Search for ConOut protocol, if not found, use first handle.
 	 */
-	gop_handle = *hlist;
+	gop_handle = NULL;
 	for (i = 0; i < nhandles; i++) {
-		void *dummy = NULL;
+		EFI_GRAPHICS_OUTPUT *tgop;
+		void *dummy;
+
+		status = OpenProtocolByHandle(hlist[i], &gop_guid, (void **)&tgop);
+		if (status != EFI_SUCCESS)
+			continue;
+
+		if (tgop->Mode->Info->PixelFormat == PixelBltOnly ||
+		    tgop->Mode->Info->PixelFormat >= PixelFormatMax)
+			continue;
 
 		status = OpenProtocolByHandle(hlist[i], &conout_guid, &dummy);
 		if (status == EFI_SUCCESS) {
 			gop_handle = hlist[i];
+			gop = tgop;
 			break;
+		} else if (gop_handle == NULL) {
+			gop_handle = hlist[i];
+			gop = tgop;
 		}
 	}
 
-	status = OpenProtocolByHandle(gop_handle, &gop_guid, (void **)&gop);
 	free(hlist);
 
-	if (status == EFI_SUCCESS) {
+	if (gop_handle != NULL) {
 		gfx_state->tg_fb_type = FB_GOP;
 		gfx_state->tg_private = gop;
 		if (edid_info == NULL)