git: 010b19127cc8 - main - x11/nvidia-driver: Fix bug that switching to the terminal wasn't possible

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Mon, 16 Jan 2023 06:38:34 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=010b19127cc848d585ab515ea2db29796b441929

commit 010b19127cc848d585ab515ea2db29796b441929
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2023-01-16 06:35:56 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2023-01-16 06:38:30 +0000

    x11/nvidia-driver: Fix bug that switching to the terminal wasn't possible
    
    Tested with NVidia RTX 2060 on FreeBSD 13.1 STABLE.
    
    PR:             213912
    Approved by:    danfe@ (maintainer's timeout; 18 days)
---
 x11/nvidia-driver/Makefile                         |  2 +-
 .../files/patch-src_nvidia_nvidia__os.c            | 34 ++++++++++++++++++++++
 x11/nvidia-driver/pkg-message                      | 10 +++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/x11/nvidia-driver/Makefile b/x11/nvidia-driver/Makefile
index 0225c71a0268..44ad13ae53a3 100644
--- a/x11/nvidia-driver/Makefile
+++ b/x11/nvidia-driver/Makefile
@@ -15,7 +15,7 @@
 PORTNAME?=	nvidia-driver
 DISTVERSION?=	510.60.02
 # Always try to set PORTREVISION as it can be overridden by the slave ports
-PORTREVISION?=	0
+PORTREVISION?=	1
 CATEGORIES=	x11
 MASTER_SITES=	NVIDIA/XFree86/FreeBSD-${ARCH_SUFX}/${DISTVERSION}
 DISTNAME=	NVIDIA-FreeBSD-${ARCH_SUFX}-${DISTVERSION}
diff --git a/x11/nvidia-driver/files/patch-src_nvidia_nvidia__os.c b/x11/nvidia-driver/files/patch-src_nvidia_nvidia__os.c
new file mode 100644
index 000000000000..42ab3ffa2d9d
--- /dev/null
+++ b/x11/nvidia-driver/files/patch-src_nvidia_nvidia__os.c
@@ -0,0 +1,34 @@
+- vbe framebuffer mode adjustment that enables switch back and forth to the black terminal
+- from https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=213912#c17
+
+--- src/nvidia/nvidia_os.c.orig	2022-12-27 22:31:44 UTC
++++ src/nvidia/nvidia_os.c
+@@ -789,6 +789,28 @@ void NV_API_CALL os_get_screen_info(
+             *pFbPitch = efifb->fb_stride * (bpp / NBBY);
+             return;
+         }
++
++        const struct vbe_fb *vbefb =
++            (const struct vbe_fb *)preload_search_info(kmdp, MODINFO_METADATA |
++                                                             MODINFOMD_VBE_FB);
++
++        /* Make sure base address is mapped to GPU BAR */
++        if ((vbefb != NULL) &&
++            ((vbefb->fb_addr == consoleBar1Address) ||
++             (vbefb->fb_addr == consoleBar2Address)))
++        {
++            int depth = fls(vbefb->fb_mask_red | vbefb->fb_mask_green |
++                            vbefb->fb_mask_blue | vbefb->fb_mask_reserved);
++            int bpp = roundup2(depth, NBBY);
++
++            *pPhysicalAddress = vbefb->fb_addr;
++            *pFbWidth = vbefb->fb_width;
++            *pFbHeight = vbefb->fb_height;
++            *pFbDepth = depth;
++            /* fb_stride is in pixels. Convert to bytes */
++            *pFbPitch = vbefb->fb_stride * (bpp / NBBY);
++            return;
++        }
+     }
+     {
+         const sc_softc_t *sc = sc_get_softc(0, SC_KERNEL_CONSOLE);
diff --git a/x11/nvidia-driver/pkg-message b/x11/nvidia-driver/pkg-message
new file mode 100644
index 000000000000..3751893d1775
--- /dev/null
+++ b/x11/nvidia-driver/pkg-message
@@ -0,0 +1,10 @@
+[
+{ type: install
+  message: <<EOM
+Please add the line
+vbe_max_resolution="720p"
+to /boot/loader.conf to put vt into the vbe framebuffer mode that would
+allow terminals to work simultaneously with graphics.
+EOM
+}
+]