aboutsummaryrefslogtreecommitdiff
path: root/graphics/nvidia-drm-61-kmod
diff options
context:
space:
mode:
authorAustin Shafer <ashafer@badland.io>2024-03-18 15:14:23 +0000
committerGleb Popov <arrowd@FreeBSD.org>2024-03-18 15:24:47 +0000
commit0d98f3a7607fc1fb304cecffbebf94ad889af940 (patch)
treed32b213ab248578df341e5eae233c600127a467b /graphics/nvidia-drm-61-kmod
parent5a3fceb399bfd277f135791e2f0eef87f2478963 (diff)
downloadports-0d98f3a7607fc1fb304cecffbebf94ad889af940.tar.gz
ports-0d98f3a7607fc1fb304cecffbebf94ad889af940.zip
graphics/nvidia-drm-kmod: fix build depends and linuxkpi registration
This fixes an issue where linuxkpi/DRM compatibility was not being correctly detected, causing sway to not work. The conftest.sh script checks the installed kernel modules for symbol presence, but on package builders drm.ko was not being installed due to being in RUN_DEPENDS instead of BUILD_DEPENDS. This also fixes a panic in sway when an external monitor is plugged into a prime laptop. This uses linux_pci_attach_device when possible to actually register everything needed for the pci dev, instead of just filling in the bare miniumum. Differential Revision: https://reviews.freebsd.org/D44308
Diffstat (limited to 'graphics/nvidia-drm-61-kmod')
-rw-r--r--graphics/nvidia-drm-61-kmod/Makefile2
-rw-r--r--graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-freebsd-lkpi.c46
2 files changed, 47 insertions, 1 deletions
diff --git a/graphics/nvidia-drm-61-kmod/Makefile b/graphics/nvidia-drm-61-kmod/Makefile
index 1a4fa5236a4d..0dd1d477b474 100644
--- a/graphics/nvidia-drm-61-kmod/Makefile
+++ b/graphics/nvidia-drm-61-kmod/Makefile
@@ -1,6 +1,8 @@
PORTNAME= nvidia-drm-61-kmod
+PORTREVISION= 1
CATEGORIES= graphics
+BUILD_DEPENDS+= ${KMODDIR}/drm.ko:graphics/drm-61-kmod
RUN_DEPENDS+= ${KMODDIR}/drm.ko:graphics/drm-61-kmod
CONFLICTS_INSTALL= nvidia-drm-510-kmod nvidia-drm-515-kmod
diff --git a/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-freebsd-lkpi.c b/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-freebsd-lkpi.c
index 6fc6285876f2..807e95effe74 100644
--- a/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-freebsd-lkpi.c
+++ b/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-freebsd-lkpi.c
@@ -1,6 +1,50 @@
--- nvidia-drm-freebsd-lkpi.c.orig 2024-02-22 01:03:15 UTC
+++ nvidia-drm-freebsd-lkpi.c
-@@ -148,7 +148,6 @@ MODULE_DEPEND(nvidia_drm, linuxkpi, 1, 1, 1);
+@@ -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);