summaryrefslogtreecommitdiff
path: root/x11/nvidia-driver/files/extra-patch-src-nvidia_dev.c.in
blob: a38bb8f28f9256411ddab912bf27c71d7af5055b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--- src/%%NVSRC%%/nvidia_dev.c.orig	2017-09-14 20:46:30 UTC
+++ src/%%NVSRC%%/nvidia_dev.c
@@ -13,6 +13,12 @@
 #include "nv.h"
 #include "nv-freebsd.h"
 
+#ifdef NV_SUPPORT_LINUX_COMPAT /* (COMPAT_LINUX || COMPAT_LINUX32) */
+#include <compat/linux/linux_util.h>
+
+extern const char nvidia_driver_name[];
+#endif
+
 static d_open_t  nvidia_dev_open;
 static void nvidia_dev_dtor(void *arg);
 static d_ioctl_t nvidia_dev_ioctl;
@@ -162,6 +168,18 @@ static int nvidia_dev_mmap_single(
 
 int nvidia_dev_attach(struct nvidia_softc *sc)
 {
+#ifdef NV_SUPPORT_LINUX_COMPAT
+    struct linux_device_handler nvidia_dev_linux_handler = {
+        .bsd_driver_name = __DECONST(char *, nvidia_driver_name),
+        .linux_driver_name = __DECONST(char *, nvidia_driver_name),
+        .bsd_device_name = NULL,
+        .linux_device_name = NULL,
+        .linux_major = NV_MAJOR_DEVICE_NUMBER,
+        .linux_minor = device_get_unit(sc->dev),
+        .linux_char_device = 1
+    };
+#endif
+
     sc->cdev = make_dev(&nvidia_dev_cdevsw,
             device_get_unit(sc->dev),
             UID_ROOT, GID_WHEEL, 0666,
@@ -172,11 +190,31 @@ int nvidia_dev_attach(struct nvidia_softc *sc)
 
     sc->cdev->si_drv1 = sc;
 
+#ifdef NV_SUPPORT_LINUX_COMPAT
+    nvidia_dev_linux_handler.bsd_device_name = sc->cdev->si_name;
+    nvidia_dev_linux_handler.linux_device_name = sc->cdev->si_name;
+    (void)linux_device_register_handler(&nvidia_dev_linux_handler);
+#endif
+
     return 0;
 }
 
 int nvidia_dev_detach(struct nvidia_softc *sc)
 {
+#ifdef NV_SUPPORT_LINUX_COMPAT
+    struct linux_device_handler nvidia_dev_linux_handler = {
+        .bsd_driver_name = __DECONST(char *, nvidia_driver_name),
+        .linux_driver_name = __DECONST(char *, nvidia_driver_name),
+        .bsd_device_name = sc->cdev->si_name,
+        .linux_device_name = sc->cdev->si_name,
+        .linux_major = NV_MAJOR_DEVICE_NUMBER,
+        .linux_minor = device_get_unit(sc->dev),
+        .linux_char_device = 1
+    };
+
+    (void)linux_device_unregister_handler(&nvidia_dev_linux_handler);
+#endif
+
     destroy_dev(sc->cdev);
     return 0;
 }