- fix buulding for kernel 5.6
[packages/xorg-driver-video-nvidia-legacy-390xx.git] / kernel-5.6.patch
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)
6  
7  static inline void *nv_ioremap_nocache(NvU64 phys, NvU64 size)
8  {
9 +#if defined(NV_IOREMAP_NOCACHE_PRESENT)
10      void *ptr = ioremap_nocache(phys, size);
11 +#else
12 +    void *ptr = ioremap(phys, size);
13 +#endif
14      if (ptr)
15          NV_MEMDBG_ADD(ptr, size);
16      return ptr;
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
21 @@ -52,6 +52,19 @@
22      })
23  #endif
24  
25 +#if defined(NV_HAVE_PROC_OPS)
26 +#define NV_CREATE_PROC_FILE(filename,parent,__name,__data)               \
27 +   ({                                                                    \
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)                                       \
32 +            mode |= S_IWUSR;                                             \
33 +        __entry = NV_CREATE_PROC_ENTRY(filename, mode, parent, fops,     \
34 +            __data);                                                     \
35 +        __entry;                                                         \
36 +    })
37 +#else
38  #define NV_CREATE_PROC_FILE(filename,parent,__name,__data)               \
39     ({                                                                    \
40          struct proc_dir_entry *__entry;                                  \
41 @@ -63,6 +76,7 @@
42              __data);                                                     \
43          __entry;                                                         \
44      })
45 +#endif
46  
47  /*
48   * proc_mkdir_mode exists in Linux 2.6.9, but isn't exported until Linux 3.0.
49 @@ -104,6 +118,24 @@
50      remove_proc_entry(entry->name, entry->parent);
51  #endif
52  
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                                                    \
58 +    )                                                                         \
59 +    {                                                                         \
60 +        return single_open(filep, nv_procfs_read_##__name,                    \
61 +            NV_PDE_DATA(inode));                                              \
62 +    }                                                                         \
63 +                                                                              \
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,                                    \
69 +    };
70 +#else
71  #define NV_DEFINE_PROCFS_SINGLE_FILE(__name)                                  \
72      static int nv_procfs_open_##__name(                                       \
73          struct inode *inode,                                                  \
74 @@ -121,6 +153,7 @@
75          .llseek     = seq_lseek,                                              \
76          .release    = single_release,                                         \
77      };
78 +#endif
79  
80  #endif  /* CONFIG_PROC_FS */
81  
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
86 @@ -30,7 +30,12 @@
87  #include <linux/ktime.h>
88  #endif
89  
90 -static inline void nv_gettimeofday(struct timeval *tv)
91 +struct nv_timeval {
92 +    __kernel_long_t      tv_sec;
93 +    __kernel_suseconds_t tv_usec;
94 +};
95 +
96 +static inline void nv_gettimeofday(struct nv_timeval *tv)
97  {
98  #ifdef NV_DO_GETTIMEOFDAY_PRESENT
99      do_gettimeofday(tv);
100 @@ -39,7 +44,7 @@ static inline void nv_gettimeofday(struct timeval *tv)
101  
102      ktime_get_real_ts64(&now);
103  
104 -    *tv = (struct timeval) {
105 +    *tv = (struct nv_timeval) {
106          .tv_sec = now.tv_sec,
107          .tv_usec = now.tv_nsec/1000,
108      };
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"
115          ;;
116  
117 +        ioremap_nocache)
118 +            #
119 +            # Determine if the ioremap_nocache() function is present.
120 +            #
121 +            # Removed by commit 4bdc0d676a64 ("remove ioremap_nocache and
122 +            # devm_ioremap_nocache") in v5.6 (2020-01-06)
123 +            #
124 +            CODE="
125 +            #include <asm/io.h>
126 +            void conftest_ioremap_nocache(void) {
127 +                ioremap_nocache();
128 +            }"
129 +
130 +            compile_check_conftest "$CODE" "NV_IOREMAP_NOCACHE_PRESENT" "" "functions"
131 +        ;;
132 +
133          ioremap_wc)
134              #
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"
138          ;;
139  
140 +        proc_ops)
141 +            CODE="
142 +            #include <linux/proc_fs.h>
143 +            int conftest_proc_ops(void) {
144 +                return offsetof(struct proc_ops, proc_open);
145 +            }"
146 +
147 +            compile_check_conftest "$CODE" "NV_HAVE_PROC_OPS" "" "types"
148 +        ;;
149 +
150 +        ktime_get_raw_ts64)
151 +            #
152 +            # Determine if the ktime_get_raw_ts64() function is present.
153 +            #
154 +            CODE="
155 +            #include <linux/ktime.h>
156 +            int conftest_ktime_get_raw_ts64(void) {
157 +                struct timespec64 ts = {0};
158 +
159 +                ktime_get_raw_ts64(&ts64);
160 +            }"
161 +
162 +            compile_check_conftest "$CODE" "NV_KTIME_GET_RAW_TS64_PRESENT" "" "functions"
163 +        ;;
164 +
165          efi_enabled)
166              #
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)
173  
174  NvU64 NVKMS_API_CALL nvkms_get_usec(void)
175  {
176 -    struct timeval tv;
177 +    struct nv_timeval tv;
178  
179      nv_gettimeofday(&tv);
180  
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
186  }
187  #endif
188  
189 -#if defined(CLOCK_MONOTONIC_RAW)
190 +#if defined(NV_KTIME_GET_RAW_TS64_PRESENT)
191 +static inline NvU64 NV_GETTIME(void)
192 +{
193 +    struct timespec64 ts64 = {0};
194 +
195 +    ktime_get_raw_ts64(&ts64);
196 +
197 +    return (ts64.tv_sec * 1000000000ULL + ts64.tv_nsec);
198 +}
199 +#elif defined(CLOCK_MONOTONIC_RAW)
200  /* Return a nanosecond-precise value */
201  static inline NvU64 NV_GETTIME(void)
202  {
203 @@ -345,7 +354,7 @@ static inline NvU64 NV_GETTIME(void)
204   * available non-GPL symbols. */
205  static inline NvU64 NV_GETTIME(void)
206  {
207 -    struct timeval tv = {0};
208 +    struct nv_timeval tv = {0};
209  
210      nv_gettimeofday(&tv);
211  
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);
218  }
219  
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,
227 +};
228 +#else
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 = {
233      .llseek  = seq_lseek,
234      .release = nv_procfs_close_registry,
235  };
236 +#endif
237  
238  /*
239   * Forwards error to nv_log_error which exposes data to vendor callback
240 @@ -517,12 +527,20 @@ done:
241      return status;
242  }
243  
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,
249 +};
250 +#else
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,
256  };
257 +#endif
258  
259  static int
260  nv_procfs_read_unbind_lock(
261 @@ -650,6 +668,15 @@ done:
262      return rc;
263  }
264  
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,
272 +};
273 +#else
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 = {
278      .llseek  = seq_lseek,
279      .release = nv_procfs_close_unbind_lock,
280  };
281 +#endif
282  
283  static int
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)
312  
313  static NvBool nv_timer_less_than
314  (
315 -    const struct timeval *a,
316 -    const struct timeval *b
317 +    const struct nv_timeval *a,
318 +    const struct nv_timeval *b
319  )
320  {
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
323  
324  static void nv_timeradd
325  (
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
332  )
333  {
334      result->tv_sec = a->tv_sec + b->tv_sec;
335 @@ -544,9 +544,9 @@ static void nv_timeradd
336  
337  static void nv_timersub
338  (
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
345  )
346  {
347      result->tv_sec = a->tv_sec - b->tv_sec;
348 @@ -566,7 +566,7 @@ void NVLINK_API_CALL nvlink_sleep(unsigned int ms)
349      unsigned long us;
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;
354  
355      nv_gettimeofday(&tm_aux);
356  
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(
362      NvU32 *useconds
363  )
364  {
365 -    struct timeval tm;
366 +    struct nv_timeval tm;
367  
368      nv_gettimeofday(&tm);
369  
370 @@ -444,9 +444,15 @@ NV_STATUS NV_API_CALL os_get_current_time(
371  
372  void NV_API_CALL os_get_current_tick(NvU64 *nseconds)
373  {
374 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0)
375 +    struct timespec64 ts;
376 +
377 +    jiffies_to_timespec64(jiffies, &ts);
378 +#else
379      struct timespec ts;
380  
381      jiffies_to_timespec(jiffies, &ts);
382 +#endif
383  
384      *nseconds = ((NvU64)ts.tv_sec * NSEC_PER_SEC + (NvU64)ts.tv_nsec);
385  }
386 @@ -502,7 +508,7 @@ NV_STATUS NV_API_CALL os_delay_us(NvU32 MicroSeconds)
387      unsigned long usec;
388  
389  #ifdef NV_CHECK_DELAY_ACCURACY
390 -    struct timeval tm1, tm2;
391 +    struct nv_timeval tm1, tm2;
392  
393      nv_gettimeofday(&tm1);
394  #endif
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;
404  #endif
405  
406      nv_gettimeofday(&tm_aux);
407 @@ -1926,7 +1932,7 @@ static NV_STATUS NV_API_CALL _os_ipmi_receive_resp
408  {
409      struct ipmi_recv_msg    *rx_msg;
410      int                     err_no;
411 -    struct timeval          tv;
412 +    struct nv_timeval          tv;
413      NvU64                   start_time;
414  
415      nv_gettimeofday(&tv);
This page took 0.168232 seconds and 3 git commands to generate.