1 diff --git a/kernel/common/inc/nv-linux.h b/kernel/common/inc/nv-linux.h
2 index 85041c2..ac5bb95 100644
3 --- a/kernel/common/inc/nv-linux.h
4 +++ b/kernel/common/inc/nv-linux.h
5 @@ -553,7 +553,11 @@ static inline void *nv_ioremap(NvU64 phys, NvU64 size)
7 static inline void *nv_ioremap_nocache(NvU64 phys, NvU64 size)
9 +#if defined(NV_IOREMAP_NOCACHE_PRESENT)
10 void *ptr = ioremap_nocache(phys, size);
12 + void *ptr = ioremap(phys, size);
15 NV_MEMDBG_ADD(ptr, size);
17 diff --git a/kernel/common/inc/nv-procfs.h b/kernel/common/inc/nv-procfs.h
18 index 3c812ea..e57c4f9 100644
19 --- a/kernel/common/inc/nv-procfs.h
20 +++ b/kernel/common/inc/nv-procfs.h
25 +#if defined(NV_HAVE_PROC_OPS)
26 +#define NV_CREATE_PROC_FILE(filename,parent,__name,__data) \
28 + struct proc_dir_entry *__entry; \
29 + int mode = (S_IFREG | S_IRUGO); \
30 + const struct proc_ops *fops = &nv_procfs_##__name##_fops; \
31 + if (fops->proc_write != 0) \
33 + __entry = NV_CREATE_PROC_ENTRY(filename, mode, parent, fops, \
38 #define NV_CREATE_PROC_FILE(filename,parent,__name,__data) \
40 struct proc_dir_entry *__entry; \
48 * proc_mkdir_mode exists in Linux 2.6.9, but isn't exported until Linux 3.0.
50 remove_proc_entry(entry->name, entry->parent);
53 +#if defined(NV_HAVE_PROC_OPS)
54 +#define NV_DEFINE_PROCFS_SINGLE_FILE(__name) \
55 + static int nv_procfs_open_##__name( \
56 + struct inode *inode, \
57 + struct file *filep \
60 + return single_open(filep, nv_procfs_read_##__name, \
61 + NV_PDE_DATA(inode)); \
64 + static const struct proc_ops nv_procfs_##__name##_fops = { \
65 + .proc_open = nv_procfs_open_##__name, \
66 + .proc_read = seq_read, \
67 + .proc_lseek = seq_lseek, \
68 + .proc_release = single_release, \
71 #define NV_DEFINE_PROCFS_SINGLE_FILE(__name) \
72 static int nv_procfs_open_##__name( \
73 struct inode *inode, \
75 .llseek = seq_lseek, \
76 .release = single_release, \
80 #endif /* CONFIG_PROC_FS */
82 diff --git a/kernel/common/inc/nv-time.h b/kernel/common/inc/nv-time.h
83 index 2c799c9..0206062 100644
84 --- a/kernel/common/inc/nv-time.h
85 +++ b/kernel/common/inc/nv-time.h
87 #include <linux/ktime.h>
90 -static inline void nv_gettimeofday(struct timeval *tv)
91 +#include <linux/version.h>
92 +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
93 +#define nv_timeval timeval
96 + __kernel_long_t tv_sec;
97 + __kernel_suseconds_t tv_usec;
101 +static inline void nv_gettimeofday(struct nv_timeval *tv)
103 #ifdef NV_DO_GETTIMEOFDAY_PRESENT
105 @@ -39,7 +44,7 @@ static inline void nv_gettimeofday(struct timeval *tv)
107 ktime_get_real_ts64(&now);
109 - *tv = (struct timeval) {
110 + *tv = (struct nv_timeval) {
111 .tv_sec = now.tv_sec,
112 .tv_usec = now.tv_nsec/1000,
114 diff --git a/kernel/conftest.sh b/kernel/conftest.sh
115 index ec9e093..463a464 100755
116 --- a/kernel/conftest.sh
117 +++ b/kernel/conftest.sh
118 @@ -1197,6 +1197,22 @@ compile_test() {
119 compile_check_conftest "$CODE" "NV_IOREMAP_CACHE_PRESENT" "" "functions"
124 + # Determine if the ioremap_nocache() function is present.
126 + # Removed by commit 4bdc0d676a64 ("remove ioremap_nocache and
127 + # devm_ioremap_nocache") in v5.6 (2020-01-06)
130 + #include <asm/io.h>
131 + void conftest_ioremap_nocache(void) {
135 + compile_check_conftest "$CODE" "NV_IOREMAP_NOCACHE_PRESENT" "" "functions"
140 # Determine if the ioremap_wc() function is present.
141 @@ -1430,6 +1446,29 @@ compile_test() {
142 compile_check_conftest "$CODE" "NV_SG_ALLOC_TABLE_FROM_PAGES_PRESENT" "" "functions"
147 + #include <linux/proc_fs.h>
148 + int conftest_proc_ops(void) {
149 + return offsetof(struct proc_ops, proc_open);
152 + compile_check_conftest "$CODE" "NV_HAVE_PROC_OPS" "" "types"
155 + ktime_get_raw_ts64)
157 + # Determine if the ktime_get_raw_ts64() function is present.
160 + #include <linux/ktime.h>
161 + int conftest_ktime_get_raw_ts64(void) {
162 + ktime_get_raw_ts64();
165 + compile_check_conftest "$CODE" "NV_KTIME_GET_RAW_TS64_PRESENT" "" "functions"
170 # Determine if the efi_enabled symbol is present, or if
171 diff --git a/kernel/nvidia-modeset/nvidia-modeset-linux.c b/kernel/nvidia-modeset/nvidia-modeset-linux.c
172 index d42aabb..f0404fb 100644
173 --- a/kernel/nvidia-modeset/nvidia-modeset-linux.c
174 +++ b/kernel/nvidia-modeset/nvidia-modeset-linux.c
175 @@ -216,7 +216,7 @@ void NVKMS_API_CALL nvkms_usleep(NvU64 usec)
177 NvU64 NVKMS_API_CALL nvkms_get_usec(void)
180 + struct nv_timeval tv;
182 nv_gettimeofday(&tv);
184 diff --git a/kernel/nvidia-uvm/uvm_linux.h b/kernel/nvidia-uvm/uvm_linux.h
185 index 8784a82..c256cdb 100644
186 --- a/kernel/nvidia-uvm/uvm_linux.h
187 +++ b/kernel/nvidia-uvm/uvm_linux.h
188 @@ -329,7 +329,16 @@ static inline uint64_t NV_DIV64(uint64_t dividend, uint64_t divisor, uint64_t *r
192 -#if defined(CLOCK_MONOTONIC_RAW)
193 +#if defined(NV_KTIME_GET_RAW_TS64_PRESENT)
194 +static inline NvU64 NV_GETTIME(void)
196 + struct timespec64 ts64 = {0};
198 + ktime_get_raw_ts64(&ts64);
200 + return (ts64.tv_sec * 1000000000ULL + ts64.tv_nsec);
202 +#elif defined(CLOCK_MONOTONIC_RAW)
203 /* Return a nanosecond-precise value */
204 static inline NvU64 NV_GETTIME(void)
206 @@ -345,7 +354,7 @@ static inline NvU64 NV_GETTIME(void)
207 * available non-GPL symbols. */
208 static inline NvU64 NV_GETTIME(void)
210 - struct timeval tv = {0};
211 + struct nv_timeval tv = {0};
213 nv_gettimeofday(&tv);
215 diff --git a/kernel/nvidia/nv-procfs.c b/kernel/nvidia/nv-procfs.c
216 index 5808a88..bc60a08 100644
217 --- a/kernel/nvidia/nv-procfs.c
218 +++ b/kernel/nvidia/nv-procfs.c
219 @@ -414,6 +414,15 @@ done:
220 return ((status < 0) ? status : (int)count);
223 +#if defined(NV_HAVE_PROC_OPS)
224 +static struct proc_ops nv_procfs_registry_fops = {
225 + .proc_open = nv_procfs_open_registry,
226 + .proc_read = seq_read,
227 + .proc_write = nv_procfs_write_file,
228 + .proc_lseek = seq_lseek,
229 + .proc_release = nv_procfs_close_registry,
232 static struct file_operations nv_procfs_registry_fops = {
233 .owner = THIS_MODULE,
234 .open = nv_procfs_open_registry,
235 @@ -422,6 +431,7 @@ static struct file_operations nv_procfs_registry_fops = {
237 .release = nv_procfs_close_registry,
242 * Forwards error to nv_log_error which exposes data to vendor callback
243 @@ -517,12 +527,20 @@ done:
247 +#if defined(NV_HAVE_PROC_OPS)
248 +static struct proc_ops nv_procfs_exercise_error_forwarding_fops = {
249 + .proc_open = nv_procfs_open_exercise_error_forwarding,
250 + .proc_write = nv_procfs_write_file,
251 + .proc_release = nv_procfs_close_exercise_error_forwarding,
254 static struct file_operations nv_procfs_exercise_error_forwarding_fops = {
255 .owner = THIS_MODULE,
256 .open = nv_procfs_open_exercise_error_forwarding,
257 .write = nv_procfs_write_file,
258 .release = nv_procfs_close_exercise_error_forwarding,
263 nv_procfs_read_unbind_lock(
264 @@ -650,6 +668,15 @@ done:
268 +#if defined(NV_HAVE_PROC_OPS)
269 +static struct proc_ops nv_procfs_unbind_lock_fops = {
270 + .proc_open = nv_procfs_open_unbind_lock,
271 + .proc_read = seq_read,
272 + .proc_write = nv_procfs_write_file,
273 + .proc_lseek = seq_lseek,
274 + .proc_release = nv_procfs_close_unbind_lock,
277 static struct file_operations nv_procfs_unbind_lock_fops = {
278 .owner = THIS_MODULE,
279 .open = nv_procfs_open_unbind_lock,
280 @@ -658,6 +685,7 @@ static struct file_operations nv_procfs_unbind_lock_fops = {
282 .release = nv_procfs_close_unbind_lock,
287 nv_procfs_read_text_file(
288 diff --git a/kernel/nvidia/nvidia.Kbuild b/kernel/nvidia/nvidia.Kbuild
289 index 8ae1016..da7f135 100644
290 --- a/kernel/nvidia/nvidia.Kbuild
291 +++ b/kernel/nvidia/nvidia.Kbuild
292 @@ -117,6 +117,7 @@ NV_CONFTEST_FUNCTION_COMPILE_TESTS += on_each_cpu
293 NV_CONFTEST_FUNCTION_COMPILE_TESTS += smp_call_function
294 NV_CONFTEST_FUNCTION_COMPILE_TESTS += acpi_evaluate_integer
295 NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_cache
296 +NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_nocache
297 NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_wc
298 NV_CONFTEST_FUNCTION_COMPILE_TESTS += acpi_walk_namespace
299 NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_domain_nr
300 @@ -169,7 +170,9 @@ NV_CONFTEST_TYPE_COMPILE_TESTS += outer_flush_all
301 NV_CONFTEST_TYPE_COMPILE_TESTS += proc_dir_entry
302 NV_CONFTEST_TYPE_COMPILE_TESTS += scatterlist
303 NV_CONFTEST_TYPE_COMPILE_TESTS += sg_table
304 +NV_CONFTEST_TYPE_COMPILE_TESTS += proc_ops
305 NV_CONFTEST_TYPE_COMPILE_TESTS += file_operations
306 +NV_CONFTEST_TYPE_COMPILE_TESTS += ktime_get_raw_ts64
307 NV_CONFTEST_TYPE_COMPILE_TESTS += vm_operations_struct
308 NV_CONFTEST_TYPE_COMPILE_TESTS += atomic_long_type
309 NV_CONFTEST_TYPE_COMPILE_TESTS += pci_save_state
310 diff --git a/kernel/nvidia/nvlink_linux.c b/kernel/nvidia/nvlink_linux.c
311 index 0014280..537b257 100644
312 --- a/kernel/nvidia/nvlink_linux.c
313 +++ b/kernel/nvidia/nvlink_linux.c
314 @@ -518,8 +518,8 @@ void * NVLINK_API_CALL nvlink_memcpy(void *dest, void *src, NvLength size)
316 static NvBool nv_timer_less_than
318 - const struct timeval *a,
319 - const struct timeval *b
320 + const struct nv_timeval *a,
321 + const struct nv_timeval *b
324 return (a->tv_sec == b->tv_sec) ? (a->tv_usec < b->tv_usec)
325 @@ -528,9 +528,9 @@ static NvBool nv_timer_less_than
327 static void nv_timeradd
329 - const struct timeval *a,
330 - const struct timeval *b,
331 - struct timeval *result
332 + const struct nv_timeval *a,
333 + const struct nv_timeval *b,
334 + struct nv_timeval *result
337 result->tv_sec = a->tv_sec + b->tv_sec;
338 @@ -544,9 +544,9 @@ static void nv_timeradd
340 static void nv_timersub
342 - const struct timeval *a,
343 - const struct timeval *b,
344 - struct timeval *result
345 + const struct nv_timeval *a,
346 + const struct nv_timeval *b,
347 + struct nv_timeval *result
350 result->tv_sec = a->tv_sec - b->tv_sec;
351 @@ -566,7 +566,7 @@ void NVLINK_API_CALL nvlink_sleep(unsigned int ms)
353 unsigned long jiffies;
354 unsigned long mdelay_safe_msec;
355 - struct timeval tm_end, tm_aux;
356 + struct nv_timeval tm_end, tm_aux;
358 nv_gettimeofday(&tm_aux);
360 diff --git a/kernel/nvidia/os-interface.c b/kernel/nvidia/os-interface.c
361 index 344daa8..39d0a19 100644
362 --- a/kernel/nvidia/os-interface.c
363 +++ b/kernel/nvidia/os-interface.c
364 @@ -430,7 +430,7 @@ NV_STATUS NV_API_CALL os_get_current_time(
369 + struct nv_timeval tm;
371 nv_gettimeofday(&tm);
373 @@ -444,9 +444,15 @@ NV_STATUS NV_API_CALL os_get_current_time(
375 void NV_API_CALL os_get_current_tick(NvU64 *nseconds)
377 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0)
378 + struct timespec64 ts;
380 + jiffies_to_timespec64(jiffies, &ts);
384 jiffies_to_timespec(jiffies, &ts);
387 *nseconds = ((NvU64)ts.tv_sec * NSEC_PER_SEC + (NvU64)ts.tv_nsec);
389 @@ -502,7 +508,7 @@ NV_STATUS NV_API_CALL os_delay_us(NvU32 MicroSeconds)
392 #ifdef NV_CHECK_DELAY_ACCURACY
393 - struct timeval tm1, tm2;
394 + struct nv_timeval tm1, tm2;
396 nv_gettimeofday(&tm1);
398 @@ -542,9 +548,9 @@ NV_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
399 unsigned long MicroSeconds;
400 unsigned long jiffies;
401 unsigned long mdelay_safe_msec;
402 - struct timeval tm_end, tm_aux;
403 + struct nv_timeval tm_end, tm_aux;
404 #ifdef NV_CHECK_DELAY_ACCURACY
405 - struct timeval tm_start;
406 + struct nv_timeval tm_start;
409 nv_gettimeofday(&tm_aux);
410 @@ -1926,7 +1932,7 @@ static NV_STATUS NV_API_CALL _os_ipmi_receive_resp
412 struct ipmi_recv_msg *rx_msg;
415 + struct nv_timeval tv;
418 nv_gettimeofday(&tv);