- fix building for kernel 5.6
[packages/xorg-driver-video-nvidia.git] / kernel-5.6.patch
CommitLineData
89bd3fac
JR
1diff --git a/kernel/common/inc/nv-procfs.h b/kernel/common/inc/nv-procfs.h
2index 8b53f86..4c5aceb 100644
3--- a/kernel/common/inc/nv-procfs.h
4+++ b/kernel/common/inc/nv-procfs.h
5@@ -28,6 +28,18 @@
6
7 #define IS_EXERCISE_ERROR_FORWARDING_ENABLED() (EXERCISE_ERROR_FORWARDING)
8
9+#if defined(NV_HAVE_PROC_OPS)
10+#define NV_CREATE_PROC_FILE(filename,parent,__name,__data) \
11+ ({ \
12+ struct proc_dir_entry *__entry; \
13+ int mode = (S_IFREG | S_IRUGO); \
14+ const struct proc_ops *fops = &nv_procfs_##__name##_fops; \
15+ if (fops->proc_write != 0) \
16+ mode |= S_IWUSR; \
17+ __entry = proc_create_data(filename, mode, parent, fops, __data);\
18+ __entry; \
19+ })
20+#else
21 #define NV_CREATE_PROC_FILE(filename,parent,__name,__data) \
22 ({ \
23 struct proc_dir_entry *__entry; \
24@@ -38,6 +50,7 @@
25 __entry = proc_create_data(filename, mode, parent, fops, __data);\
26 __entry; \
27 })
28+#endif
29
30 /*
31 * proc_mkdir_mode exists in Linux 2.6.9, but isn't exported until Linux 3.0.
32@@ -77,6 +90,44 @@
33 remove_proc_entry(entry->name, entry->parent);
34 #endif
35
36+#if defined(NV_HAVE_PROC_OPS)
37+#define NV_DEFINE_SINGLE_PROCFS_FILE(name, open_callback, close_callback) \
38+ static int nv_procfs_open_##name( \
39+ struct inode *inode, \
40+ struct file *filep \
41+ ) \
42+ { \
43+ int ret; \
44+ ret = single_open(filep, nv_procfs_read_##name, \
45+ NV_PDE_DATA(inode)); \
46+ if (ret < 0) \
47+ { \
48+ return ret; \
49+ } \
50+ ret = open_callback(); \
51+ if (ret < 0) \
52+ { \
53+ single_release(inode, filep); \
54+ } \
55+ return ret; \
56+ } \
57+ \
58+ static int nv_procfs_release_##name( \
59+ struct inode *inode, \
60+ struct file *filep \
61+ ) \
62+ { \
63+ close_callback(); \
64+ return single_release(inode, filep); \
65+ } \
66+ \
67+ static const struct proc_ops nv_procfs_##name##_fops = { \
68+ .proc_open = nv_procfs_open_##name, \
69+ .proc_read = seq_read, \
70+ .proc_lseek = seq_lseek, \
71+ .proc_release = nv_procfs_release_##name, \
72+ };
73+#else
74 #define NV_DEFINE_SINGLE_PROCFS_FILE(name, open_callback, close_callback) \
75 static int nv_procfs_open_##name( \
76 struct inode *inode, \
77@@ -114,6 +165,7 @@
78 .llseek = seq_lseek, \
79 .release = nv_procfs_release_##name, \
80 };
81+#endif
82
83 #endif /* CONFIG_PROC_FS */
84
85diff --git a/kernel/common/inc/nv-time.h b/kernel/common/inc/nv-time.h
86index 968b873..f03c7b0 100644
87--- a/kernel/common/inc/nv-time.h
88+++ b/kernel/common/inc/nv-time.h
89@@ -27,7 +27,17 @@
90
91 #include <linux/ktime.h>
92
93-static inline void nv_gettimeofday(struct timeval *tv)
94+#include <linux/version.h>
95+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
96+#define nv_timeval timeval
97+#else
98+struct nv_timeval {
99+ __kernel_long_t tv_sec;
100+ __kernel_suseconds_t tv_usec;
101+};
102+#endif
103+
104+static inline void nv_gettimeofday(struct nv_timeval *tv)
105 {
106 #ifdef NV_DO_GETTIMEOFDAY_PRESENT
107 do_gettimeofday(tv);
108@@ -36,7 +41,7 @@ static inline void nv_gettimeofday(struct timeval *tv)
109
110 ktime_get_real_ts64(&now);
111
112- *tv = (struct timeval) {
113+ *tv = (struct nv_timeval) {
114 .tv_sec = now.tv_sec,
115 .tv_usec = now.tv_nsec/1000,
116 };
117diff --git a/kernel/conftest.sh b/kernel/conftest.sh
118index 57d85a4..4eb703f 100755
119--- a/kernel/conftest.sh
120+++ b/kernel/conftest.sh
121@@ -806,6 +806,42 @@ compile_test() {
122 compile_check_conftest "$CODE" "NV_FILE_OPERATIONS_HAS_IOCTL" "" "types"
123 ;;
124
125+ proc_ops)
126+ CODE="
127+ #include <linux/proc_fs.h>
128+ int conftest_proc_ops(void) {
129+ return offsetof(struct proc_ops, proc_open);
130+ }"
131+
132+ compile_check_conftest "$CODE" "NV_HAVE_PROC_OPS" "" "types"
133+ ;;
134+
135+ ktime_get_raw_ts64)
136+ #
137+ # Determine if the ktime_get_raw_ts64() function is present.
138+ #
139+ CODE="
140+ #include <linux/ktime.h>
141+ int conftest_ktime_get_raw_ts64(void) {
142+ ktime_get_raw_ts64();
143+ }"
144+
145+ compile_check_conftest "$CODE" "NV_KTIME_GET_RAW_TS64_PRESENT" "" "functions"
146+ ;;
147+
148+ ktime_get_real_ts64)
149+ #
150+ # Determine if the ktime_get_real_ts64() function is present.
151+ #
152+ CODE="
153+ #include <linux/ktime.h>
154+ int conftest_ktime_get_raw_ts64(void) {
155+ ktime_get_real_ts64();
156+ }"
157+
158+ compile_check_conftest "$CODE" "NV_KTIME_GET_REAL_TS64_PRESENT" "" "functions"
159+ ;;
160+
161 sg_alloc_table)
162 #
163 # sg_alloc_table_from_pages added by commit efc42bc98058
164diff --git a/kernel/nvidia-modeset/nvidia-modeset-linux.c b/kernel/nvidia-modeset/nvidia-modeset-linux.c
165index 0ca2c7d..8902143 100644
166--- a/kernel/nvidia-modeset/nvidia-modeset-linux.c
167+++ b/kernel/nvidia-modeset/nvidia-modeset-linux.c
168@@ -266,7 +266,7 @@ void NVKMS_API_CALL nvkms_usleep(NvU64 usec)
169
170 NvU64 NVKMS_API_CALL nvkms_get_usec(void)
171 {
172- struct timeval tv;
173+ struct nv_timeval tv;
174
175 nv_gettimeofday(&tv);
176
177diff --git a/kernel/nvidia-uvm/uvm_linux.h b/kernel/nvidia-uvm/uvm_linux.h
178index 30a9dea..1a20eff 100644
179--- a/kernel/nvidia-uvm/uvm_linux.h
180+++ b/kernel/nvidia-uvm/uvm_linux.h
181@@ -301,7 +301,16 @@ static inline uint64_t NV_DIV64(uint64_t dividend, uint64_t divisor, uint64_t *r
182 }
183 #endif
184
185-#if defined(CLOCK_MONOTONIC_RAW)
186+#if defined(NV_KTIME_GET_RAW_TS64_PRESENT)
187+static inline NvU64 NV_GETTIME(void)
188+{
189+ struct timespec64 ts;
190+
191+ ktime_get_raw_ts64(&ts);
192+
193+ return (ts.tv_sec * 1000000000ULL + ts.tv_nsec);
194+}
195+#elif defined(CLOCK_MONOTONIC_RAW)
196 /* Return a nanosecond-precise value */
197 static inline NvU64 NV_GETTIME(void)
198 {
199@@ -317,7 +326,7 @@ static inline NvU64 NV_GETTIME(void)
200 * available non-GPL symbols. */
201 static inline NvU64 NV_GETTIME(void)
202 {
203- struct timeval tv = {0};
204+ struct nv_timeval tv = {0};
205
206 nv_gettimeofday(&tv);
207
208diff --git a/kernel/nvidia/linux_nvswitch.c b/kernel/nvidia/linux_nvswitch.c
209index 1d2c1bc..0a0b4e8 100644
210--- a/kernel/nvidia/linux_nvswitch.c
211+++ b/kernel/nvidia/linux_nvswitch.c
212@@ -1578,10 +1578,17 @@ nvswitch_os_get_platform_time
213 void
214 )
215 {
216+#if defined(NV_KTIME_GET_REAL_TS64_PRESENT)
217+ struct timespec64 ts64;
218+
219+ ktime_get_real_ts64(&ts64);
220+ return ((NvU64)(ts64.tv_sec * NSEC_PER_SEC) + ts64.tv_nsec);
221+#else
222 struct timespec ts;
223
224 getnstimeofday(&ts);
225 return ((NvU64) timespec_to_ns(&ts));
226+#endif
227 }
228
229 void
230diff --git a/kernel/nvidia/nv-procfs.c b/kernel/nvidia/nv-procfs.c
231index 064d727..a7308d3 100644
232--- a/kernel/nvidia/nv-procfs.c
233+++ b/kernel/nvidia/nv-procfs.c
234@@ -452,6 +452,15 @@ done:
235 return ((status < 0) ? status : (int)count);
236 }
237
238+#if defined(NV_HAVE_PROC_OPS)
239+static struct proc_ops nv_procfs_registry_fops = {
240+ .proc_open = nv_procfs_open_registry,
241+ .proc_read = seq_read,
242+ .proc_write = nv_procfs_write_file,
243+ .proc_lseek = seq_lseek,
244+ .proc_release = nv_procfs_close_registry,
245+};
246+#else
247 static struct file_operations nv_procfs_registry_fops = {
248 .owner = THIS_MODULE,
249 .open = nv_procfs_open_registry,
250@@ -460,6 +469,7 @@ static struct file_operations nv_procfs_registry_fops = {
251 .llseek = seq_lseek,
252 .release = nv_procfs_close_registry,
253 };
254+#endif
255
256 #if defined(CONFIG_PM)
257 static int
258@@ -531,6 +541,15 @@ nv_procfs_open_suspend_depth(
259 return single_open(file, nv_procfs_show_suspend_depth, NULL);
260 }
261
262+#if defined(NV_HAVE_PROC_OPS)
263+static struct proc_ops nv_procfs_suspend_depth_fops = {
264+ .proc_open = nv_procfs_open_suspend_depth,
265+ .proc_read = seq_read,
266+ .proc_write = nv_procfs_write_suspend_depth,
267+ .proc_lseek = seq_lseek,
268+ .proc_release = single_release
269+};
270+#else
271 static struct file_operations nv_procfs_suspend_depth_fops = {
272 .owner = THIS_MODULE,
273 .open = nv_procfs_open_suspend_depth,
274@@ -539,6 +558,7 @@ static struct file_operations nv_procfs_suspend_depth_fops = {
275 .llseek = seq_lseek,
276 .release = single_release
277 };
278+#endif
279
280 static int
281 nv_procfs_show_suspend(
282@@ -613,6 +633,15 @@ nv_procfs_open_suspend(
283 return single_open(file, nv_procfs_show_suspend, NULL);
284 }
285
286+#if defined(NV_HAVE_PROC_OPS)
287+static struct proc_ops nv_procfs_suspend_fops = {
288+ .proc_open = nv_procfs_open_suspend,
289+ .proc_read = seq_read,
290+ .proc_write = nv_procfs_write_suspend,
291+ .proc_lseek = seq_lseek,
292+ .proc_release = single_release
293+};
294+#else
295 static struct file_operations nv_procfs_suspend_fops = {
296 .owner = THIS_MODULE,
297 .open = nv_procfs_open_suspend,
298@@ -622,6 +651,7 @@ static struct file_operations nv_procfs_suspend_fops = {
299 .release = single_release
300 };
301 #endif
302+#endif
303
304 /*
305 * Forwards error to nv_log_error which exposes data to vendor callback
306@@ -724,12 +754,20 @@ done:
307 return status;
308 }
309
310+#if defined(NV_HAVE_PROC_OPS)
311+static struct proc_ops nv_procfs_exercise_error_forwarding_fops = {
312+ .proc_open = nv_procfs_open_exercise_error_forwarding,
313+ .proc_write = nv_procfs_write_file,
314+ .proc_release = nv_procfs_close_exercise_error_forwarding,
315+};
316+#else
317 static struct file_operations nv_procfs_exercise_error_forwarding_fops = {
318 .owner = THIS_MODULE,
319 .open = nv_procfs_open_exercise_error_forwarding,
320 .write = nv_procfs_write_file,
321 .release = nv_procfs_close_exercise_error_forwarding,
322 };
323+#endif
324
325 static int
326 nv_procfs_read_unbind_lock(
327@@ -851,6 +889,15 @@ done:
328 return rc;
329 }
330
331+#if defined(NV_HAVE_PROC_OPS)
332+static struct proc_ops nv_procfs_unbind_lock_fops = {
333+ .proc_open = nv_procfs_open_unbind_lock,
334+ .proc_read = seq_read,
335+ .proc_write = nv_procfs_write_file,
336+ .proc_lseek = seq_lseek,
337+ .proc_release = nv_procfs_close_unbind_lock,
338+};
339+#else
340 static struct file_operations nv_procfs_unbind_lock_fops = {
341 .owner = THIS_MODULE,
342 .open = nv_procfs_open_unbind_lock,
343@@ -859,6 +906,7 @@ static struct file_operations nv_procfs_unbind_lock_fops = {
344 .llseek = seq_lseek,
345 .release = nv_procfs_close_unbind_lock,
346 };
347+#endif
348
349 static const char*
350 numa_status_describe(nv_numa_status_t state)
351@@ -1187,6 +1235,22 @@ done:
352 return retval;
353 }
354
355+#if defined(NV_HAVE_PROC_OPS)
356+static const struct proc_ops nv_procfs_numa_status_fops = {
357+ .proc_open = nv_procfs_open_numa_status,
358+ .proc_read = seq_read,
359+ .proc_write = nv_procfs_write_file,
360+ .proc_lseek = seq_lseek,
361+ .proc_release = nv_procfs_close_numa_status,
362+};
363+
364+static const struct proc_ops nv_procfs_offline_pages_fops = {
365+ .proc_open = nv_procfs_open_offline_pages,
366+ .proc_read = seq_read,
367+ .proc_lseek = seq_lseek,
368+ .proc_release = nv_procfs_close_offline_pages,
369+};
370+#else
371 static const struct file_operations nv_procfs_numa_status_fops = {
372 .owner = THIS_MODULE,
373 .open = nv_procfs_open_numa_status,
374@@ -1203,6 +1267,7 @@ static const struct file_operations nv_procfs_offline_pages_fops = {
375 .llseek = seq_lseek,
376 .release = nv_procfs_close_offline_pages,
377 };
378+#endif
379
380 static int
381 nv_procfs_read_text_file(
382diff --git a/kernel/nvidia/nvidia.Kbuild b/kernel/nvidia/nvidia.Kbuild
383index 5ec3e65..339a757 100644
384--- a/kernel/nvidia/nvidia.Kbuild
385+++ b/kernel/nvidia/nvidia.Kbuild
386@@ -150,6 +150,9 @@ NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_swiotlb_dma_ops
387 NV_CONFTEST_TYPE_COMPILE_TESTS += acpi_op_remove
388 NV_CONFTEST_TYPE_COMPILE_TESTS += outer_flush_all
389 NV_CONFTEST_TYPE_COMPILE_TESTS += file_operations
390+NV_CONFTEST_TYPE_COMPILE_TESTS += proc_ops
391+NV_CONFTEST_TYPE_COMPILE_TESTS += ktime_get_raw_ts64
392+NV_CONFTEST_TYPE_COMPILE_TESTS += ktime_get_real_ts64
393 NV_CONFTEST_TYPE_COMPILE_TESTS += file_inode
394 NV_CONFTEST_TYPE_COMPILE_TESTS += kuid_t
395 NV_CONFTEST_TYPE_COMPILE_TESTS += dma_ops
396diff --git a/kernel/nvidia/nvlink_linux.c b/kernel/nvidia/nvlink_linux.c
397index c84b36a..54fe244 100644
398--- a/kernel/nvidia/nvlink_linux.c
399+++ b/kernel/nvidia/nvlink_linux.c
400@@ -513,8 +513,8 @@ int NVLINK_API_CALL nvlink_memcmp(const void *s1, const void *s2, NvLength size)
401
402 static NvBool nv_timer_less_than
403 (
404- const struct timeval *a,
405- const struct timeval *b
406+ const struct nv_timeval *a,
407+ const struct nv_timeval *b
408 )
409 {
410 return (a->tv_sec == b->tv_sec) ? (a->tv_usec < b->tv_usec)
411@@ -523,9 +523,9 @@ static NvBool nv_timer_less_than
412
413 static void nv_timeradd
414 (
415- const struct timeval *a,
416- const struct timeval *b,
417- struct timeval *result
418+ const struct nv_timeval *a,
419+ const struct nv_timeval *b,
420+ struct nv_timeval *result
421 )
422 {
423 result->tv_sec = a->tv_sec + b->tv_sec;
424@@ -539,9 +539,9 @@ static void nv_timeradd
425
426 static void nv_timersub
427 (
428- const struct timeval *a,
429- const struct timeval *b,
430- struct timeval *result
431+ const struct nv_timeval *a,
432+ const struct nv_timeval *b,
433+ struct nv_timeval *result
434 )
435 {
436 result->tv_sec = a->tv_sec - b->tv_sec;
437@@ -561,7 +561,7 @@ void NVLINK_API_CALL nvlink_sleep(unsigned int ms)
438 unsigned long us;
439 unsigned long jiffies;
440 unsigned long mdelay_safe_msec;
441- struct timeval tm_end, tm_aux;
442+ struct nv_timeval tm_end, tm_aux;
443
444 nv_gettimeofday(&tm_aux);
445
446diff --git a/kernel/nvidia/os-interface.c b/kernel/nvidia/os-interface.c
447index 07f1b77..239be58 100644
448--- a/kernel/nvidia/os-interface.c
449+++ b/kernel/nvidia/os-interface.c
450@@ -463,7 +463,7 @@ NV_STATUS NV_API_CALL os_get_current_time(
451 NvU32 *useconds
452 )
453 {
454- struct timeval tm;
455+ struct nv_timeval tm;
456
457 nv_gettimeofday(&tm);
458
459@@ -477,9 +477,15 @@ NV_STATUS NV_API_CALL os_get_current_time(
460
461 void NV_API_CALL os_get_current_tick(NvU64 *nseconds)
462 {
463+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0)
464+ struct timespec64 ts;
465+
466+ jiffies_to_timespec64(jiffies, &ts);
467+#else
468 struct timespec ts;
469
470 jiffies_to_timespec(jiffies, &ts);
471+#endif
472
473 *nseconds = ((NvU64)ts.tv_sec * NSEC_PER_SEC + (NvU64)ts.tv_nsec);
474 }
475@@ -549,7 +555,7 @@ NV_STATUS NV_API_CALL os_delay_us(NvU32 MicroSeconds)
476 unsigned long usec;
477
478 #ifdef NV_CHECK_DELAY_ACCURACY
479- struct timeval tm1, tm2;
480+ struct nv_timeval tm1, tm2;
481
482 nv_gettimeofday(&tm1);
483 #endif
484@@ -589,9 +595,9 @@ NV_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
485 unsigned long MicroSeconds;
486 unsigned long jiffies;
487 unsigned long mdelay_safe_msec;
488- struct timeval tm_end, tm_aux;
489+ struct nv_timeval tm_end, tm_aux;
490 #ifdef NV_CHECK_DELAY_ACCURACY
491- struct timeval tm_start;
492+ struct nv_timeval tm_start;
493 #endif
494
495 nv_gettimeofday(&tm_aux);
496@@ -1954,7 +1960,7 @@ static NV_STATUS NV_API_CALL _os_ipmi_receive_resp
497 {
498 struct ipmi_recv_msg *rx_msg;
499 int err_no;
500- struct timeval tv;
501+ struct nv_timeval tv;
502 NvU64 start_time;
503
504 nv_gettimeofday(&tv);
This page took 0.146071 seconds and 4 git commands to generate.