summarylogtreecommitdiffstats
path: root/kernel-5.0.patch
blob: 9ae00f75c619d965d66311fbbd62c7d556cbb79c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
From 0b4e74ba61c50aefa16a4bafac3a60799eab7a20 Mon Sep 17 00:00:00 2001
From: Alberto Milone <alberto.milone@canonical.com>
Date: Fri, 15 Feb 2019 14:43:21 +0100
Subject: [PATCH 1/1] Add support for Linux 5.0

---
 Makefile               |  2 ++
 conftest.sh            | 33 +++++++++++++++++++++++++++++++++
 nv-drm.c               | 12 +++++++++++-
 nv-time.h              | 24 ++++++++++++++++++++++++
 os-interface.c         | 13 +++++++------
 uvm/Makefile           |  1 +
 uvm/nvidia_uvm_linux.h |  1 +
 uvm/nvidia_uvm_lite.c  |  4 ++--
 8 files changed, 81 insertions(+), 9 deletions(-)
 create mode 100644 nv-time.h

diff --git a/Makefile b/Makefile
index 8ac3c1a..1959dce 100644
--- a/Makefile
+++ b/Makefile
@@ -147,6 +147,8 @@ COMPILE_TESTS = \
 	vm_fault_present \
 	vm_fault_has_address \
 	drm_driver_unload_has_int_return_type \
+	drm_gem_object_get \
+	do_gettimeofday \
 	drm_legacy_pci_init \
 	timer_setup
 #
diff --git a/conftest.sh b/conftest.sh
index 64d75a1..fb0bf60 100755
--- a/conftest.sh
+++ b/conftest.sh
@@ -168,6 +168,7 @@ test_headers() {
     FILES="$FILES linux/sched/task.h"
     FILES="$FILES xen/ioemu.h"
     FILES="$FILES linux/fence.h"
+    FILES="$FILES linux/ktime.h"
 
     FILES_ARCH="$FILES_ARCH asm/set_memory.h"
 
@@ -1971,6 +1972,38 @@ compile_test() {
             compile_check_conftest "$CODE" "NV_DRM_DRIVER_UNLOAD_HAS_INT_RETURN_TYPE" "" "types"
         ;;
 
+        drm_gem_object_get)
+            #
+            # Determine if the function drm_gem_object_get() is present.
+            #
+            CODE="
+            #include <drm/drmP.h>
+            #if defined(NV_DRM_DRM_GEM_H_PRESENT)
+            #include <drm/drm_gem.h>
+            #endif
+            void conftest_drm_gem_object_get(void) {
+                drm_gem_object_get();
+            }"
+
+            compile_check_conftest "$CODE" "NV_DRM_GEM_OBJECT_GET_PRESENT" "" "functions"
+        ;;
+
+        do_gettimeofday)
+            #
+            # Determine if the function do_gettimeofday() is present.
+            #
+            CODE="
+            #include <linux/time.h>
+            #if defined(NV_LINUX_KTIME_H_PRESENT)
+            #include <linux/ktime.h>
+            #endif
+            void conftest_do_gettimeofday(void) {
+                do_gettimeofday();
+            }"
+
+            compile_check_conftest "$CODE" "NV_DO_GETTIMEOFDAY_PRESENT" "" "functions"
+        ;;
+
         drm_legacy_pci_init)
             #
             # Determine if drm_legacy_pci_init() is present. drm_pci_init() was
diff --git a/nv-drm.c b/nv-drm.c
index 0eb72e4..1c968de 100644
--- a/nv-drm.c
+++ b/nv-drm.c
@@ -37,6 +37,16 @@ struct nv_gem_object {
     struct page **pages;
 };
 
+static inline void
+nv_drm_gem_object_unreference_unlocked(struct nv_gem_object *nv_gem)
+{
+#if defined(NV_DRM_GEM_OBJECT_GET_PRESENT)
+    drm_gem_object_put_unlocked(&nv_gem->base);
+#else
+    drm_gem_object_unreference_unlocked(&nv_gem->base);
+#endif
+}
+
 static int nv_drm_load(
     struct drm_device *dev,
     unsigned long flags
@@ -252,7 +262,7 @@ RM_STATUS NV_API_CALL nv_alloc_os_descriptor_handle(
         goto done;
     }
 
-    drm_gem_object_unreference_unlocked(&nv_obj->base);
+    nv_drm_gem_object_unreference_unlocked(nv_obj);
 
     status = RM_OK;
 
diff --git a/nv-time.h b/nv-time.h
new file mode 100644
index 0000000..cc828aa
--- /dev/null
+++ b/nv-time.h
@@ -0,0 +1,24 @@
+#ifndef __NV_TIME_H__
+#define __NV_TIME_H__
+
+#include "conftest.h"
+#include <linux/time.h>
+
+#if defined(NV_LINUX_KTIME_H_PRESENT)
+#include <linux/ktime.h>
+#endif
+
+static inline void nv_gettimeofday(struct timeval *tv)
+{
+#ifdef NV_DO_GETTIMEOFDAY_PRESENT
+    do_gettimeofday(tv);
+#else
+    struct timespec64 now;
+
+    ktime_get_real_ts64(&now);
+    tv->tv_sec = now.tv_sec;
+    tv->tv_usec = now.tv_nsec/1000;
+#endif
+}
+
+#endif
diff --git a/os-interface.c b/os-interface.c
index 7e3d362..7190b26 100644
--- a/os-interface.c
+++ b/os-interface.c
@@ -13,6 +13,7 @@
 
 #include "os-interface.h"
 #include "nv-linux.h"
+#include "nv-time.h"
 
 RM_STATUS NV_API_CALL os_disable_console_access(void)
 {
@@ -440,7 +441,7 @@ RM_STATUS NV_API_CALL os_get_current_time(
 {
     struct timeval tm;
 
-    do_gettimeofday(&tm);
+    nv_gettimeofday(&tm);
 
     *seconds = tm.tv_sec;
     *useconds = tm.tv_usec;
@@ -475,7 +476,7 @@ RM_STATUS NV_API_CALL os_delay_us(NvU32 MicroSeconds)
 #ifdef NV_CHECK_DELAY_ACCURACY
     struct timeval tm1, tm2;
 
-    do_gettimeofday(&tm1);
+    nv_gettimeofday(&tm1);
 #endif
 
     if (in_irq() && (MicroSeconds > NV_MAX_ISR_DELAY_US))
@@ -490,7 +491,7 @@ RM_STATUS NV_API_CALL os_delay_us(NvU32 MicroSeconds)
         udelay(usec);
 
 #ifdef NV_CHECK_DELAY_ACCURACY
-    do_gettimeofday(&tm2);
+    nv_gettimeofday(&tm2);
     nv_printf(NV_DBG_ERRORS, "NVRM: osDelayUs %d: 0x%x 0x%x\n",
         MicroSeconds, tm2.tv_sec - tm1.tv_sec, tm2.tv_usec - tm1.tv_usec);
 #endif
@@ -518,7 +519,7 @@ RM_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
     struct timeval tm_start;
 #endif
 
-    do_gettimeofday(&tm_aux);
+    nv_gettimeofday(&tm_aux);
 #ifdef NV_CHECK_DELAY_ACCURACY
     tm_start = tm_aux;
 #endif
@@ -552,7 +553,7 @@ RM_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
         do
         {
             schedule_timeout(jiffies);
-            do_gettimeofday(&tm_aux);
+            nv_gettimeofday(&tm_aux);
             if (NV_TIMERCMP(&tm_aux, &tm_end, <))
             {
                 NV_TIMERSUB(&tm_end, &tm_aux, &tm_aux);
@@ -574,7 +575,7 @@ RM_STATUS NV_API_CALL os_delay(NvU32 MilliSeconds)
         udelay(MicroSeconds);
     }
 #ifdef NV_CHECK_DELAY_ACCURACY
-    do_gettimeofday(&tm_aux);
+    nv_gettimeofday(&tm_aux);
     timersub(&tm_aux, &tm_start, &tm_aux);
     nv_printf(NV_DBG_ERRORS, "NVRM: osDelay %dmsec: %d.%06dsec\n",
         MilliSeconds, tm_aux.tv_sec, tm_aux.tv_usec);
diff --git a/uvm/Makefile b/uvm/Makefile
index 42ad927..5c7b466 100644
--- a/uvm/Makefile
+++ b/uvm/Makefile
@@ -171,6 +171,7 @@ COMPILE_TESTS = \
 	kbasename \
 	fatal_signal_pending \
 	kuid_t \
+	do_gettimeofday \
 	vm_fault_has_address
 
 MODULE_NAME:= nvidia-uvm
diff --git a/uvm/nvidia_uvm_linux.h b/uvm/nvidia_uvm_linux.h
index 1625209..1edb620 100644
--- a/uvm/nvidia_uvm_linux.h
+++ b/uvm/nvidia_uvm_linux.h
@@ -146,6 +146,7 @@
 #include <linux/interrupt.h>        /* tasklets, interrupt helpers      */
 #include <linux/timer.h>
 #include <linux/time.h>             /* do_gettimeofday()*/
+#include "nv-time.h"
 
 #include <asm/div64.h>              /* do_div()                         */
 #if defined(NV_ASM_SYSTEM_H_PRESENT)
diff --git a/uvm/nvidia_uvm_lite.c b/uvm/nvidia_uvm_lite.c
index 119c93a..33b8d4b 100644
--- a/uvm/nvidia_uvm_lite.c
+++ b/uvm/nvidia_uvm_lite.c
@@ -2019,7 +2019,7 @@ static RM_STATUS _check_ecc_errors(UvmGpuMigrationTracking *pMigTracker,
     {
         if (!!(rmInterruptSet) && !bEccIncomingError)
         {
-            do_gettimeofday(&eccErrorStartTime);
+            nv_gettimeofday(&eccErrorStartTime);
             _set_timeout_in_usec(&eccErrorStartTime, &eccTimeout,
                                  UVM_ECC_ERR_TIMEOUT_USEC);
 
@@ -2051,7 +2051,7 @@ static RM_STATUS _check_ecc_errors(UvmGpuMigrationTracking *pMigTracker,
         //
         if (!!(rmInterruptSet) && (eccErrorStartTime.tv_usec != 0))
         {
-            do_gettimeofday(&eccErrorCurrentTime);
+            nv_gettimeofday(&eccErrorCurrentTime);
             if ((eccErrorCurrentTime.tv_sec > eccTimeout.tv_sec) ||
                 ((eccErrorCurrentTime.tv_sec == eccTimeout.tv_sec) &&
                 (eccErrorCurrentTime.tv_usec >= eccTimeout.tv_usec)))
-- 
2.19.1