Link Here
|
1 |
--- src/nvidia-modeset/nvidia-modeset-freebsd.c.orig 2018-08-21 23:09:28 UTC |
2 |
+++ src/nvidia-modeset/nvidia-modeset-freebsd.c |
3 |
@@ -26,6 +26,7 @@ |
4 |
#include <sys/file.h> |
5 |
#include <sys/proc.h> |
6 |
#include <sys/stack.h> |
7 |
+#include <sys/sysproto.h> |
8 |
|
9 |
#include "nvkms-ioctl.h" |
10 |
#include "nvidia-modeset-os-interface.h" |
11 |
@@ -48,6 +49,7 @@ |
12 |
#include "machine/../linux32/linux32_proto.h" |
13 |
#endif |
14 |
#include <compat/linux/linux_ioctl.h> |
15 |
+ #include <compat/linux/linux_util.h> |
16 |
#endif |
17 |
|
18 |
|
19 |
@@ -250,7 +252,7 @@ struct nvkms_ref_ptr { |
20 |
|
21 |
struct nvkms_ref_ptr* NVKMS_API_CALL nvkms_alloc_ref_ptr(void *ptr) |
22 |
{ |
23 |
- struct nvkms_ref_ptr *ref_ptr = nvkms_alloc(sizeof(*ref_ptr), NV_FALSE); |
24 |
+ struct nvkms_ref_ptr *ref_ptr = nvkms_alloc(sizeof(*ref_ptr), NV_TRUE); |
25 |
if (ref_ptr) { |
26 |
mtx_init(&ref_ptr->lock, "nvkms-ref-ptr-lock", NULL, MTX_SPIN); |
27 |
// The ref_ptr owner counts as a reference on the ref_ptr itself. |
28 |
@@ -867,33 +869,31 @@ static int nvkms_poll( |
29 |
*************************************************************************/ |
30 |
|
31 |
#if defined(NVKMS_SUPPORT_LINUX_COMPAT) |
32 |
+static struct linux_device_handler nvkms_linux_device_handler = { |
33 |
+ .bsd_driver_name = "nvidia-modeset", |
34 |
+ .linux_driver_name = "nvidia-modeset", |
35 |
+ .bsd_device_name = "nvidia-modeset", |
36 |
+ .linux_device_name = "nvidia-modeset", |
37 |
+ .linux_major = 195, |
38 |
+ .linux_minor = 254, |
39 |
+ .linux_char_device = 1 |
40 |
+}; |
41 |
|
42 |
static int nvkms_linux_ioctl_function( |
43 |
struct thread *td, |
44 |
struct linux_ioctl_args *args |
45 |
) |
46 |
{ |
47 |
- struct file *fp; |
48 |
- int status; |
49 |
- u_long cmd; |
50 |
+ static const uint32_t dir[4] = { IOC_VOID, IOC_IN, IOC_OUT, IOC_INOUT }; |
51 |
|
52 |
-#if NV_FGET_HAS_CAP_RIGHTS_T_ARG |
53 |
- cap_rights_t rights; |
54 |
- status = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp); |
55 |
-#else |
56 |
- status = fget(td, args->fd, &fp); |
57 |
-#endif |
58 |
- |
59 |
- if (status != 0) { |
60 |
- return status; |
61 |
+ if ((args->cmd & (1<<29)) != 0) { |
62 |
+ /* FreeBSD has only 13 bits to encode the size. */ |
63 |
+ printf("nvidia: pid %d (%s): ioctl cmd=0x%x size too large\n", |
64 |
+ (int)td->td_proc->p_pid, td->td_proc->p_comm, args->cmd); |
65 |
+ return (EINVAL); |
66 |
} |
67 |
- |
68 |
- cmd = args->cmd; |
69 |
- |
70 |
- status = fo_ioctl(fp, cmd, (caddr_t)args->arg, td->td_ucred, td); |
71 |
- fdrop(fp, td); |
72 |
- |
73 |
- return status; |
74 |
+ args->cmd = (args->cmd & ~IOC_DIRMASK) | dir[args->cmd >> 30]; |
75 |
+ return (sys_ioctl(td, (struct ioctl_args *)args)); |
76 |
} |
77 |
|
78 |
#define NVKMS_LINUX_IOCTL_MIN _IOC(0, NVKMS_IOCTL_MAGIC, NVKMS_IOCTL_CMD, 0) |
79 |
@@ -909,6 +909,7 @@ static struct linux_ioctl_handler nvkms_linux_ioctl_ha |
80 |
static void nvkms_linux_compat_load(void) |
81 |
{ |
82 |
#if defined(NVKMS_SUPPORT_LINUX_COMPAT) |
83 |
+ linux_device_register_handler(&nvkms_linux_device_handler); |
84 |
linux_ioctl_register_handler(&nvkms_linux_ioctl_handler); |
85 |
#endif |
86 |
} |
87 |
@@ -917,6 +918,7 @@ static void nvkms_linux_compat_unload(void) |
88 |
{ |
89 |
#if defined(NVKMS_SUPPORT_LINUX_COMPAT) |
90 |
linux_ioctl_unregister_handler(&nvkms_linux_ioctl_handler); |
91 |
+ linux_device_unregister_handler(&nvkms_linux_device_handler); |
92 |
#endif |
93 |
} |
94 |
|
95 |
@@ -1100,4 +1102,9 @@ MODULE_DEPEND(nvidia_modeset, /* module |
96 |
MODULE_DEPEND(nvidia_modeset, /* module name */ |
97 |
linux, /* prerequisite module */ |
98 |
1, 1, 1); /* vmin, vpref, vmax */ |
99 |
+#if defined(NVCPU_X86_64) |
100 |
+MODULE_DEPEND(nvidia_modeset, /* module name */ |
101 |
+ linux_common, /* prerequisite module */ |
102 |
+ 1, 1, 1); /* vmin, vpref, vmax */ |
103 |
+#endif |
104 |
#endif |