git: 504a07fd1deb - main - graphics/nvidia-drm-latest-kmod, graphics/nvidia-drm-latest-kmod-devel: Add new port

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Fri, 17 Oct 2025 16:44:48 UTC
The branch main has been updated by kbowling:

URL: https://cgit.FreeBSD.org/ports/commit/?id=504a07fd1deb20362aefa6d81e39561877827317

commit 504a07fd1deb20362aefa6d81e39561877827317
Author:     Tomoaki AOKI <junchoon@dec.sakura.ne.jp>
AuthorDate: 2025-10-17 16:43:45 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2025-10-17 16:43:45 +0000

    graphics/nvidia-drm-latest-kmod, graphics/nvidia-drm-latest-kmod-devel: Add new port
    
    Add missing graphics/nvidia-drm-latest-kmod and
    graphics/nvidia-drm-latest-kmod-devel which corresponding with
    graphics/drm-latest-kmod.
    
    PR:             290262
    Differential Revision:  https://reviews.freebsd.org/D53128
---
 graphics/Makefile                                  |  2 +
 graphics/nvidia-drm-latest-kmod-devel/Makefile     |  7 +++
 graphics/nvidia-drm-latest-kmod-devel/distinfo     |  5 ++
 graphics/nvidia-drm-latest-kmod/Makefile           | 11 +++++
 graphics/nvidia-drm-latest-kmod/distinfo           |  5 ++
 .../files/20-nvidia-drm-outputclass.conf.in        |  8 ++++
 .../files/extra-patch-nvidia-drm-conftest.h        | 14 ++++++
 .../files/extra-patch-nvidia-drm-freebsd-lkpi.c    | 54 ++++++++++++++++++++++
 .../patch-nvidia-drm-freebsd-lkpi.c-20250918-01    | 47 +++++++++++++++++++
 graphics/nvidia-drm-latest-kmod/pkg-descr          |  3 ++
 graphics/nvidia-drm-latest-kmod/pkg-message        |  8 ++++
 11 files changed, 164 insertions(+)

diff --git a/graphics/Makefile b/graphics/Makefile
index 2bccf42a9ba8..1bc6cbb14a90 100644
--- a/graphics/Makefile
+++ b/graphics/Makefile
@@ -637,6 +637,8 @@
     SUBDIR += nvidia-drm-66-kmod-devel
     SUBDIR += nvidia-drm-kmod
     SUBDIR += nvidia-drm-kmod-devel
+    SUBDIR += nvidia-drm-latest-kmod
+    SUBDIR += nvidia-drm-latest-kmod-devel
     SUBDIR += nvidia-texture-tools
     SUBDIR += ocaml-cairo
     SUBDIR += ocaml-images
diff --git a/graphics/nvidia-drm-latest-kmod-devel/Makefile b/graphics/nvidia-drm-latest-kmod-devel/Makefile
new file mode 100644
index 000000000000..c1a2360b4868
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod-devel/Makefile
@@ -0,0 +1,7 @@
+NVIDIA_DISTVERSION?=	580.95.05
+# Explicitly set PORTREVISION as it can be overridden by the master port
+PORTREVISION=	0
+MASTERDIR=	${.CURDIR}/../nvidia-drm-latest-kmod
+PKGNAMESUFFIX=	-devel
+
+.include "${MASTERDIR}/Makefile"
diff --git a/graphics/nvidia-drm-latest-kmod-devel/distinfo b/graphics/nvidia-drm-latest-kmod-devel/distinfo
new file mode 100644
index 000000000000..c41cc13ddae4
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod-devel/distinfo
@@ -0,0 +1,5 @@
+TIMESTAMP = 1760509612
+SHA256 (NVIDIA-FreeBSD-x86_64-580.95.05.tar.xz) = 6ce64e84ede8b8a3e7c1579e9d08d53e2da9dd50590b398d9a816adc6a00f160
+SIZE (NVIDIA-FreeBSD-x86_64-580.95.05.tar.xz) = 288883876
+SHA256 (freebsd-drm-kmod-drm_v6.9_GH0.tar.gz) = a7599c2124e1fb65a270d5195d8592b0f69d0702a23938b73d097c079501129e
+SIZE (freebsd-drm-kmod-drm_v6.9_GH0.tar.gz) = 41511351
diff --git a/graphics/nvidia-drm-latest-kmod/Makefile b/graphics/nvidia-drm-latest-kmod/Makefile
new file mode 100644
index 000000000000..b721ea027606
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod/Makefile
@@ -0,0 +1,11 @@
+PORTNAME=	nvidia-drm-latest-kmod
+PORTREVISION=	0
+CATEGORIES=	graphics
+
+RUN_DEPENDS+=	${KMODDIR}/drm.ko:graphics/drm-latest-kmod
+CONFLICTS_INSTALL=	nvidia-drm-510-kmod* nvidia-drm-515-kmod* nvidia-drm-61-kmod* nvidia-drm-66-kmod*
+
+.include "${.CURDIR}/../drm-latest-kmod/Makefile.version"
+.include "${.CURDIR}/../nvidia-drm-kmod/Makefile.common"
+
+.include <bsd.port.mk>
diff --git a/graphics/nvidia-drm-latest-kmod/distinfo b/graphics/nvidia-drm-latest-kmod/distinfo
new file mode 100644
index 000000000000..82e957ff888b
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod/distinfo
@@ -0,0 +1,5 @@
+TIMESTAMP = 1760509263
+SHA256 (NVIDIA-FreeBSD-x86_64-580.95.05.tar.xz) = 6ce64e84ede8b8a3e7c1579e9d08d53e2da9dd50590b398d9a816adc6a00f160
+SIZE (NVIDIA-FreeBSD-x86_64-580.95.05.tar.xz) = 288883876
+SHA256 (freebsd-drm-kmod-drm_v6.9_GH0.tar.gz) = a7599c2124e1fb65a270d5195d8592b0f69d0702a23938b73d097c079501129e
+SIZE (freebsd-drm-kmod-drm_v6.9_GH0.tar.gz) = 41511351
diff --git a/graphics/nvidia-drm-latest-kmod/files/20-nvidia-drm-outputclass.conf.in b/graphics/nvidia-drm-latest-kmod/files/20-nvidia-drm-outputclass.conf.in
new file mode 100644
index 000000000000..15496138f63a
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod/files/20-nvidia-drm-outputclass.conf.in
@@ -0,0 +1,8 @@
+Section "OutputClass"
+    Identifier "nvidia"
+    MatchDriver "nvidia-drm"
+    Driver "nvidia"
+    Option "PrimaryGPU" "yes"
+    ModulePath "%%LOCALBASE%%/lib/nvidia/xorg"
+    ModulePath "%%LOCALBASE%%/lib/xorg/modules"
+EndSection
diff --git a/graphics/nvidia-drm-latest-kmod/files/extra-patch-nvidia-drm-conftest.h b/graphics/nvidia-drm-latest-kmod/files/extra-patch-nvidia-drm-conftest.h
new file mode 100644
index 000000000000..2c0524341c4d
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod/files/extra-patch-nvidia-drm-conftest.h
@@ -0,0 +1,14 @@
+--- nvidia-drm-conftest.h.orig	2024-02-22 01:03:15 UTC
++++ nvidia-drm-conftest.h
+@@ -85,7 +85,11 @@
+ 
+ /* For nv_drm_gem_prime_force_fence_signal */
+ #ifndef spin_is_locked
++#if ((__FreeBSD_version >= 1500000) && (__FreeBSD_version < 1500018)) || (__FreeBSD_version < 1401501)
+ #define spin_is_locked(lock) mtx_owned(lock.m)
++#else
++#define spin_is_locked(lock) mtx_owned(lock)
++#endif
+ #endif
+ 
+ #ifndef rwsem_is_locked
diff --git a/graphics/nvidia-drm-latest-kmod/files/extra-patch-nvidia-drm-freebsd-lkpi.c b/graphics/nvidia-drm-latest-kmod/files/extra-patch-nvidia-drm-freebsd-lkpi.c
new file mode 100644
index 000000000000..807e95effe74
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod/files/extra-patch-nvidia-drm-freebsd-lkpi.c
@@ -0,0 +1,54 @@
+--- nvidia-drm-freebsd-lkpi.c.orig	2024-02-22 01:03:15 UTC
++++ nvidia-drm-freebsd-lkpi.c
+@@ -115,6 +115,7 @@ int nv_drm_probe_devices(void)
+      * by the native nvidia.ko by using our devclass.
+      */
+     for (int i = 0; i < NV_MAX_DEVICES; i++) {
++        struct pci_dev *pdev;
+         nv_gpu_info_t gpu_info;
+         struct nvidia_softc *sc = devclass_get_softc(nvidia_devclass, i);
+         if (!sc) {
+@@ -124,11 +125,33 @@ int nv_drm_probe_devices(void)
+         nv_state_t *nv = sc->nv_state;
+ 
+         /*
++         * Set the ivars for this device if they are not already populated. This
++         * is the bus specific data, and linuxkpi will try to use it.
++         */
++        if (!device_get_ivars(sc->dev)) {
++            device_t parent = device_get_parent(sc->dev);
++            struct pci_devinfo *dinfo = device_get_ivars(parent);
++            device_set_ivars(sc->dev, dinfo);
++        }
++
++        /*
+          * Now we have the state (which gives us the device_t), but what nvidia-drm
+          * wants is a pci_dev suitable for use with linuxkpi code. We can use
+-         * lkpinew_pci_dev to fill in a pci_dev struct,
++         * lkpinew_pci_dev to fill in a pci_dev struct, or linux_pci_attach on more
++         * recent kernels (introduced by 253dbe7487705).
+          */
+-        struct pci_dev *pdev = lkpinew_pci_dev(sc->dev);
++#if __FreeBSD_version < 1300093
++        pdev = lkpinew_pci_dev(sc->dev);
++#else
++        pdev = malloc(sizeof(*pdev), M_DEVBUF, M_WAITOK|M_ZERO);
++        if (!pdev) {
++            return -ENOMEM;
++        }
++
++        if (linux_pci_attach_device(sc->dev, NULL, NULL, pdev)) {
++            return -ENOMEM;
++        }
++#endif
+         nv_lkpi_pci_devs[i] = pdev;
+ 
+         gpu_info.gpu_id = nv->gpu_id;
+@@ -148,7 +171,6 @@ MODULE_DEPEND(nvidia_drm, linuxkpi, 1, 1, 1);
+ LKPI_DRIVER_MODULE(nvidia_drm, nv_drm_init, nv_drm_exit);
+ LKPI_PNP_INFO(pci, nvidia_drm, nv_module_device_table);
+ MODULE_DEPEND(nvidia_drm, linuxkpi, 1, 1, 1);
+-MODULE_DEPEND(nvidia_drm, linuxkpi_gplv2, 1, 1, 1);
+ MODULE_DEPEND(nvidia_drm, drmn, 2, 2, 2);
+ MODULE_DEPEND(nvidia_drm, dmabuf, 1, 1, 1);
+ MODULE_DEPEND(nvidia_drm, nvidia, 1, 1, 1);
diff --git a/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-freebsd-lkpi.c-20250918-01 b/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-freebsd-lkpi.c-20250918-01
new file mode 100644
index 000000000000..c703950a0c88
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-freebsd-lkpi.c-20250918-01
@@ -0,0 +1,47 @@
+--- nvidia-drm-freebsd-lkpi.c.orig	2025-08-27 17:59:14 UTC
++++ nvidia-drm-freebsd-lkpi.c
+@@ -104,6 +104,35 @@ lkpinew_pci_dev(device_t dev)
+  * FreeBSD linuxkpi based loading support code.
+  *************************************************************************/
+ 
++static int
++dummy_nv_pci_probe(struct pci_dev *pci_dev __unused,
++    const struct pci_device_id *id_table __unused)
++{
++	return (0);
++}
++
++static void
++dummy_nv_pci_remove(struct pci_dev *pci_dev __unused)
++{
++}
++
++static void
++dummy_nv_pci_shutdown(struct pci_dev *pci_dev __unused)
++{
++}
++
++struct pci_driver nv_pci_driver = {
++	.name =		"drmn",
++	.id_table =	nv_pci_table,
++	.probe =	dummy_nv_pci_probe,
++	.remove =	dummy_nv_pci_remove,
++	.shutdown =	dummy_nv_pci_shutdown,
++#if defined(__FreeBSD__)
++	/* FreeBSD internal/specifc. */
++	.isdrm =	true,
++#endif
++};
++
+ static struct pci_dev *nv_lkpi_pci_devs[NV_MAX_DEVICES];
+ 
+ int nv_drm_probe_devices(void)
+@@ -153,7 +182,7 @@ int nv_drm_probe_devices(void)
+             return -ENOMEM;
+         }
+ 
+-        if (linux_pci_attach_device(sc->dev, NULL, NULL, pdev)) {
++        if (linux_pci_attach_device(sc->dev, &nv_pci_driver, NULL, pdev)) {
+             NV_DRM_LOG_ERR("Failed to attach linuxkpi PCI device");
+             free(pdev, M_DEVBUF);
+             return -ENOMEM;
diff --git a/graphics/nvidia-drm-latest-kmod/pkg-descr b/graphics/nvidia-drm-latest-kmod/pkg-descr
new file mode 100644
index 000000000000..7a6433279b02
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod/pkg-descr
@@ -0,0 +1,3 @@
+FreeBSD port of Linux's nvidia-drm.ko Kernel module.
+
+This version is compatible with drm.ko 6.9.
diff --git a/graphics/nvidia-drm-latest-kmod/pkg-message b/graphics/nvidia-drm-latest-kmod/pkg-message
new file mode 100644
index 000000000000..c2440d5580aa
--- /dev/null
+++ b/graphics/nvidia-drm-latest-kmod/pkg-message
@@ -0,0 +1,8 @@
+Modesetting must be enabled to use nvidia-drm.ko for graphics. This can be done
+by setting the modeset sysctl, the equivalent of the modeset kernel parameter
+on Linux.
+
+hw.nvidiadrm.modeset=1
+
+This must be set before loading nvidia-drm.ko, most easily done by placing the
+above in /boot/loader.conf.