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)
92 + __kernel_long_t tv_sec;
93 + __kernel_suseconds_t tv_usec;
96 +static inline void nv_gettimeofday(struct nv_timeval *tv)
98 #ifdef NV_DO_GETTIMEOFDAY_PRESENT
100 @@ -39,7 +44,7 @@ static inline void nv_gettimeofday(struct timeval *tv)
102 ktime_get_real_ts64(&now);
104 - *tv = (struct timeval) {
105 + *tv = (struct nv_timeval) {
106 .tv_sec = now.tv_sec,
107 .tv_usec = now.tv_nsec/1000,
109 diff --git a/kernel/conftest.sh b/kernel/conftest.sh
110 index ec9e093..463a464 100755
111 --- a/kernel/conftest.sh
112 +++ b/kernel/conftest.sh
113 @@ -1197,6 +1197,22 @@ compile_test() {
114 compile_check_conftest "$CODE" "NV_IOREMAP_CACHE_PRESENT" "" "functions"
119 + # Determine if the ioremap_nocache() function is present.
121 + # Removed by commit 4bdc0d676a64 ("remove ioremap_nocache and
122 + # devm_ioremap_nocache") in v5.6 (2020-01-06)
125 + #include <asm/io.h>
126 + void conftest_ioremap_nocache(void) {
130 + compile_check_conftest "$CODE" "NV_IOREMAP_NOCACHE_PRESENT" "" "functions"
135 # Determine if the ioremap_wc() function is present.
136 @@ -1430,6 +1446,31 @@ compile_test() {
137 compile_check_conftest "$CODE" "NV_SG_ALLOC_TABLE_FROM_PAGES_PRESENT" "" "functions"
142 + #include <linux/proc_fs.h>
143 + int conftest_proc_ops(void) {
144 + return offsetof(struct proc_ops, proc_open);
147 + compile_check_conftest "$CODE" "NV_HAVE_PROC_OPS" "" "types"
150 + ktime_get_raw_ts64)
152 + # Determine if the ktime_get_raw_ts64() function is present.
155 + #include <linux/ktime.h>
156 + int conftest_ktime_get_raw_ts64(void) {
157 + struct timespec64 ts = {0};
159 + ktime_get_raw_ts64(&ts64);
162 + compile_check_conftest "$CODE" "NV_KTIME_GET_RAW_TS64_PRESENT" "" "functions"
167 # Determine if the efi_enabled symbol is present, or if
168 diff --git a/kernel/nvidia-modeset/nvidia-modeset-linux.c b/kernel/nvidia-modeset/nvidia-modeset-linux.c
169 index d42aabb..f0404fb 100644
170 --- a/kernel/nvidia-modeset/nvidia-modeset-linux.c
171 +++ b/kernel/nvidia-modeset/nvidia-modeset-linux.c
172 @@ -216,7 +216,7 @@ void NVKMS_API_CALL nvkms_usleep(NvU64 usec)
174 NvU64 NVKMS_API_CALL nvkms_get_usec(void)
177 + struct nv_timeval tv;
179 nv_gettimeofday(&tv);
181 diff --git a/kernel/nvidia-uvm/uvm_linux.h b/kernel/nvidia-uvm/uvm_linux.h
182 index 8784a82..c256cdb 100644
183 --- a/kernel/nvidia-uvm/uvm_linux.h
184 +++ b/kernel/nvidia-uvm/uvm_linux.h
185 @@ -329,7 +329,16 @@ static inline uint64_t NV_DIV64(uint64_t dividend, uint64_t divisor, uint64_t *r
189 -#if defined(CLOCK_MONOTONIC_RAW)
190 +#if defined(NV_KTIME_GET_RAW_TS64_PRESENT)
191 +static inline NvU64 NV_GETTIME(void)
193 + struct timespec64 ts64 = {0};
195 + ktime_get_raw_ts64(&ts64);
197 + return (ts64.tv_sec * 1000000000ULL + ts64.tv_nsec);
199 +#elif defined(CLOCK_MONOTONIC_RAW)
200 /* Return a nanosecond-precise value */
201 static inline NvU64 NV_GETTIME(void)
203 @@ -345,7 +354,7 @@ static inline NvU64 NV_GETTIME(void)
204 * available non-GPL symbols. */
205 static inline NvU64 NV_GETTIME(void)
207 - struct timeval tv = {0};
208 + struct nv_timeval tv = {0};
210 nv_gettimeofday(&tv);
212 diff --git a/kernel/nvidia/nv-procfs.c b/kernel/nvidia/nv-procfs.c
213 index 5808a88..bc60a08 100644
214 --- a/kernel/nvidia/nv-procfs.c
215 +++ b/kernel/nvidia/nv-procfs.c
216 @@ -414,6 +414,15 @@ done:
217 return ((status < 0) ? status : (int)count);
220 +#if defined(NV_HAVE_PROC_OPS)
221 +static struct proc_ops nv_procfs_registry_fops = {
222 + .proc_open = nv_procfs_open_registry,
223 + .proc_read = seq_read,
224 + .proc_write = nv_procfs_write_file,
225 + .proc_lseek = seq_lseek,
226 + .proc_release = nv_procfs_close_registry,
229 static struct file_operations nv_procfs_registry_fops = {
230 .owner = THIS_MODULE,
231 .open = nv_procfs_open_registry,
232 @@ -422,6 +431,7 @@ static struct file_operations nv_procfs_registry_fops = {
234 .release = nv_procfs_close_registry,
239 * Forwards error to nv_log_error which exposes data to vendor callback
240 @@ -517,12 +527,20 @@ done:
244 +#if defined(NV_HAVE_PROC_OPS)
245 +static struct proc_ops nv_procfs_exercise_error_forwarding_fops = {
246 + .proc_open = nv_procfs_open_exercise_error_forwarding,
247 + .proc_write = nv_procfs_write_file,
248 + .proc_release = nv_procfs_close_exercise_error_forwarding,
251 static struct file_operations nv_procfs_exercise_error_forwarding_fops = {
252 .owner = THIS_MODULE,
253 .open = nv_procfs_open_exercise_error_forwarding,
254 .write = nv_procfs_write_file,
255 .release = nv_procfs_close_exercise_error_forwarding,
260 nv_procfs_read_unbind_lock(
261 @@ -650,6 +668,15 @@ done:
265 +#if defined(NV_HAVE_PROC_OPS)
266 +static struct proc_ops nv_procfs_unbind_lock_fops = {
267 + .proc_open = nv_procfs_open_unbind_lock,
268 + .proc_read = seq_read,
269 + .proc_write = nv_procfs_write_file,
270 + .proc_lseek = seq_lseek,
271 + .proc_release = nv_procfs_close_unbind_lock,
274 static struct file_operations nv_procfs_unbind_lock_fops = {
275 .owner = THIS_MODULE,
276 .open = nv_procfs_open_unbind_lock,
277 @@ -658,6 +685,7 @@ static struct file_operations nv_procfs_unbind_lock_fops = {
279 .release = nv_procfs_close_unbind_lock,
284 nv_procfs_read_text_file(
285 diff --git a/kernel/nvidia/nvidia.Kbuild b/kernel/nvidia/nvidia.Kbuild
286 index 8ae1016..da7f135 100644
287 --- a/kernel/nvidia/nvidia.Kbuild
288 +++ b/kernel/nvidia/nvidia.Kbuild
289 @@ -117,6 +117,7 @@ NV_CONFTEST_FUNCTION_COMPILE_TESTS += on_each_cpu
290 NV_CONFTEST_FUNCTION_COMPILE_TESTS += smp_call_function
291 NV_CONFTEST_FUNCTION_COMPILE_TESTS += acpi_evaluate_integer
292 NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_cache
293 +NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_nocache
294 NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_wc
295 NV_CONFTEST_FUNCTION_COMPILE_TESTS += acpi_walk_namespace
296 NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_domain_nr
297 @@ -169,7 +170,9 @@ NV_CONFTEST_TYPE_COMPILE_TESTS += outer_flush_all
298 NV_CONFTEST_TYPE_COMPILE_TESTS += proc_dir_entry
299 NV_CONFTEST_TYPE_COMPILE_TESTS += scatterlist
300 NV_CONFTEST_TYPE_COMPILE_TESTS += sg_table
301 +NV_CONFTEST_TYPE_COMPILE_TESTS += proc_ops
302 NV_CONFTEST_TYPE_COMPILE_TESTS += file_operations
303 +NV_CONFTEST_TYPE_COMPILE_TESTS += ktime_get_raw_ts64
304 NV_CONFTEST_TYPE_COMPILE_TESTS += vm_operations_struct
305 NV_CONFTEST_TYPE_COMPILE_TESTS += atomic_long_type
306 NV_CONFTEST_TYPE_COMPILE_TESTS += pci_save_state
307 diff --git a/kernel/nvidia/nvlink_linux.c b/kernel/nvidia/nvlink_linux.c
308 index 0014280..537b257 100644
309 --- a/kernel/nvidia/nvlink_linux.c
310 +++ b/kernel/nvidia/nvlink_linux.c
311 @@ -518,8 +518,8 @@ void * NVLINK_API_CALL nvlink_memcpy(void *dest, void *src, NvLength size)
313 static NvBool nv_timer_less_than
315 - const struct timeval *a,
316 - const struct timeval *b
317 + const struct nv_timeval *a,
318 + const struct nv_timeval *b
321 return (a->tv_sec == b->tv_sec) ? (a->tv_usec < b->tv_usec)
322 @@ -528,9 +528,9 @@ static NvBool nv_timer_less_than
324 static void nv_timeradd
326 - const struct timeval *a,
327 - const struct timeval *b,
328 - struct timeval *result
329 + const struct nv_timeval *a,
330 + const struct nv_timeval *b,
331 + struct nv_timeval *result
334 result->tv_sec = a->tv_sec + b->tv_sec;
335 @@ -544,9 +544,9 @@ static void nv_timeradd
337 static void nv_timersub
339 - const struct timeval *a,
340 - const struct timeval *b,
341 - struct timeval *result
342 + const struct nv_timeval *a,
343 + const struct nv_timeval *b,
344 + struct nv_timeval *result
347 result->tv_sec = a->tv_sec - b->tv_sec;
348 @@ -566,7 +566,7 @@ void NVLINK_API_CALL nvlink_sleep(unsigned int ms)
350 unsigned long jiffies;
351 unsigned long mdelay_safe_msec;
352 - struct timeval tm_end, tm_aux;
353 + struct nv_timeval tm_end, tm_aux;
355 nv_gettimeofday(&tm_aux);
357 diff --git a/kernel/nvidia/os-interface.c b/kernel/nvidia/os-interface.c
358 index 344daa8..39d0a19 100644
359 --- a/kernel/nvidia/os-interface.c
360 +++ b/kernel/nvidia/os-interface.c
361 @@ -430,7 +430,7 @@ NV_STATUS NV_API_CALL os_get_current_time(
366 + struct nv_timeval tm;
368 nv_gettimeofday(&tm);
370 @@ -444,9 +444,15 @@ NV_STATUS NV_API_CALL os_get_current_time(
372 void NV_API_CALL os_get_current_tick(NvU64 *nseconds)
374 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0)
375 + struct timespec64 ts;
377 + jiffies_to_timespec64(jiffies, &ts);
381 jiffies_to_timespec(jiffies, &ts);
384 *nseconds = ((NvU64)ts.tv_sec * NSEC_PER_SEC + (NvU64)ts.tv_nsec);
386 @@ -502,7 +508,7 @@ NV_STATUS NV_API_CALL os_delay_us(NvU32 MicroSeconds)
389 #ifdef NV_CHECK_DELAY_ACCURACY
390 - struct timeval tm1, tm2;
391 + struct nv_timeval tm1, tm2;
393 nv_gettimeofday(&tm1);
395 @@ -542,9 +548,9 @@ NV_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
396 unsigned long MicroSeconds;
397 unsigned long jiffies;
398 unsigned long mdelay_safe_msec;
399 - struct timeval tm_end, tm_aux;
400 + struct nv_timeval tm_end, tm_aux;
401 #ifdef NV_CHECK_DELAY_ACCURACY
402 - struct timeval tm_start;
403 + struct nv_timeval tm_start;
406 nv_gettimeofday(&tm_aux);
407 @@ -1926,7 +1932,7 @@ static NV_STATUS NV_API_CALL _os_ipmi_receive_resp
409 struct ipmi_recv_msg *rx_msg;
412 + struct nv_timeval tv;
415 nv_gettimeofday(&tv);