From owner-dev-commits-src-main@freebsd.org Sat Jan 16 23:30:02 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 40A1E4EF544; Sat, 16 Jan 2021 23:30:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DJDmV1KNQz3HKq; Sat, 16 Jan 2021 23:30:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1A49617993; Sat, 16 Jan 2021 23:30:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10GNU1dl094004; Sat, 16 Jan 2021 23:30:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10GNU15Y094001; Sat, 16 Jan 2021 23:30:01 GMT (envelope-from git) Date: Sat, 16 Jan 2021 23:30:01 GMT Message-Id: <202101162330.10GNU15Y094001@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Toomas Soome Subject: git: ef698fabe428 - main - loader.efi: handle multiple gop instances MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ef698fabe42827bad43bf046143ef26e47d57514 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Jan 2021 23:30:02 -0000 The branch main has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=ef698fabe42827bad43bf046143ef26e47d57514 commit ef698fabe42827bad43bf046143ef26e47d57514 Author: Toomas Soome AuthorDate: 2021-01-16 17:51:23 +0000 Commit: Toomas Soome CommitDate: 2021-01-16 23:29:35 +0000 loader.efi: handle multiple gop instances Some systems may provide multiple GOP instances and not all are bound to hardware. The current loader is picking up the first GOP, which may not be usable. Instead we load the GOP handle array, and test every handle to have registered ConOut protocol. If ConOut is present, we can use this GOP handle to open GOP protocol. --- stand/efi/loader/framebuffer.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/stand/efi/loader/framebuffer.c b/stand/efi/loader/framebuffer.c index a2bd054e16dc..1650f7da8760 100644 --- a/stand/efi/loader/framebuffer.c +++ b/stand/efi/loader/framebuffer.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include "bootstrap.h" #include "framebuffer.h" +EFI_GUID conout_guid = EFI_CONSOLE_OUT_DEVICE_GUID; EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; static EFI_GUID pciio_guid = EFI_PCI_IO_PROTOCOL_GUID; static EFI_GUID uga_guid = EFI_UGA_DRAW_PROTOCOL_GUID; @@ -466,6 +467,8 @@ efifb_from_uga(struct efi_fb *efifb, EFI_UGA_DRAW_PROTOCOL *uga) int efi_find_framebuffer(teken_gfx_t *gfx_state) { + EFI_HANDLE h, *hlist; + UINTN nhandles, i, hsize; struct efi_fb efifb; EFI_GRAPHICS_OUTPUT *gop; EFI_UGA_DRAW_PROTOCOL *uga; @@ -474,7 +477,39 @@ efi_find_framebuffer(teken_gfx_t *gfx_state) gfx_state->tg_fb_type = FB_TEXT; - status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop); + hsize = 0; + status = BS->LocateHandle(ByProtocol, &gop_guid, NULL, &hsize, hlist); + if (status == EFI_BUFFER_TOO_SMALL) { + hlist = malloc(hsize); + if (hlist == NULL) + return (ENOMEM); + status = BS->LocateHandle(ByProtocol, &gop_guid, NULL, &hsize, + hlist); + if (EFI_ERROR(status)) + free(hlist); + } + if (EFI_ERROR(status)) + return (efi_status_to_errno(status)); + + nhandles = hsize / sizeof(*hlist); + + /* + * Search for ConOut protocol, if not found, use first handle. + */ + h = *hlist; + for (i = 0; i < nhandles; i++) { + void *dummy = NULL; + + status = OpenProtocolByHandle(hlist[i], &conout_guid, &dummy); + if (status == EFI_SUCCESS) { + h = hlist[i]; + break; + } + } + + status = OpenProtocolByHandle(h, &gop_guid, (void **)&gop); + free(hlist); + if (status == EFI_SUCCESS) { gfx_state->tg_fb_type = FB_GOP; gfx_state->tg_private = gop;