Skip to content

Commit fe4263a

Browse files
committed
add kernel 5.0 patch
GPUOpen-LibrariesAndSDKs#24
1 parent 7676858 commit fe4263a

1 file changed

Lines changed: 318 additions & 0 deletions

File tree

24.patch

Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
From 2d4abede2a786beee0bd944ddc8eb677ce8632f6 Mon Sep 17 00:00:00 2001
2+
From: Dominik Csapak <d.csapak@proxmox.com>
3+
Date: Tue, 25 Jun 2019 09:54:52 +0200
4+
Subject: [PATCH] make gim compatible with kernel >= 5.0
5+
6+
kernel 5.0 removed some deprecated timespec/timeval functions
7+
so conditionally convert everything to timespec64
8+
9+
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
10+
---
11+
drv/gim_adapter.c | 38 +++++++++++++++++++++++---------------
12+
drv/gim_adapter.h | 36 +++++++++++++++++++++++++++---------
13+
drv/gim_dma.c | 8 ++++----
14+
drv/gim_irqmgr.c | 8 ++++----
15+
drv/gim_monitor.c | 2 +-
16+
drv/gim_monitor_ioctl.c | 2 +-
17+
drv/gim_monitor_ioctl.h | 2 +-
18+
7 files changed, 61 insertions(+), 35 deletions(-)
19+
20+
diff --git a/drv/gim_adapter.c b/drv/gim_adapter.c
21+
index 45b5207..822da96 100644
22+
--- a/drv/gim_adapter.c
23+
+++ b/drv/gim_adapter.c
24+
@@ -1630,8 +1630,8 @@ static const unsigned int gpu_hang_check_list[GPU_STATUS_SIZE] = {
25+
26+
static int wait_cmd_complete(struct function *func)
27+
{
28+
- struct timespec start_time;
29+
- struct timespec delta_time;
30+
+ struct TIMESPECTYPE start_time;
31+
+ struct TIMESPECTYPE delta_time;
32+
33+
uint32_t time_out = 2; /* 2 seconds */
34+
kcl_type_u8 command;
35+
@@ -1640,7 +1640,7 @@ static int wait_cmd_complete(struct function *func)
36+
uint32_t status;
37+
struct adapter *adapt = func->adapt;
38+
39+
- getnstimeofday(&start_time);
40+
+ GETNSTIMEOFDAY(&start_time);
41+
42+
pci_read_config_dword(adapt->pf.pci_dev, 4, &status);
43+
gim_dbg("Cmd/Status @ 4 = 0x%08x\n", status);
44+
@@ -1677,7 +1677,11 @@ static int wait_cmd_complete(struct function *func)
45+
}
46+
}
47+
48+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
49+
gim_err(" wait_cmd_complete -- time out after %ld.%09ld sec\n",
50+
+#else
51+
+ gim_err(" wait_cmd_complete -- time out after %lld.%09ld sec\n",
52+
+#endif
53+
delta_time.tv_sec, delta_time.tv_nsec);
54+
pci_read_config_byte(adapt->pf.pci_dev,
55+
adapt->gpuiov.pos + PCI_GPUIOV_CMD_CONTROL,
56+
@@ -1748,7 +1752,7 @@ int run_vf(struct function *func)
57+
ret = wait_cmd_complete(func);
58+
59+
/* record time of start to run vf */
60+
- getnstimeofday(&(func->time_log.active_last_tick));
61+
+ GETNSTIMEOFDAY(&(func->time_log.active_last_tick));
62+
63+
if (is_pf) {
64+
uint32_t tlb_control = pf_read_register(adapt,
65+
@@ -1770,7 +1774,7 @@ int idle_vf(struct function *func)
66+
{
67+
int is_pf;
68+
uint32_t status;
69+
- struct timespec tmp;
70+
+ struct TIMESPECTYPE tmp;
71+
struct adapter *adapt;
72+
73+
adapt = func->adapt;
74+
@@ -1795,10 +1799,10 @@ int idle_vf(struct function *func)
75+
76+
/* record current vf active time*/
77+
if (func->time_log.active_last_tick.tv_sec != 0) {
78+
- getnstimeofday(&tmp);
79+
- tmp = timespec_sub(tmp, func->time_log.active_last_tick);
80+
+ GETNSTIMEOFDAY(&tmp);
81+
+ tmp = TIMESPEC_SUB(tmp, func->time_log.active_last_tick);
82+
func->time_log.active_time =
83+
- timespec_add(func->time_log.active_time, tmp);
84+
+ TIMESPEC_ADD(func->time_log.active_time, tmp);
85+
86+
/* clear last tick record, in case of twice idle */
87+
func->time_log.active_last_tick.tv_sec = 0;
88+
@@ -3977,12 +3981,12 @@ void dump_scratch_ram(struct adapter *adapt,
89+
}
90+
}
91+
92+
-struct timespec time_elapsed(struct timespec *ts_start)
93+
+struct TIMESPECTYPE time_elapsed(struct TIMESPECTYPE *ts_start)
94+
{
95+
- struct timespec ts_end;
96+
- struct timespec ts_diff;
97+
+ struct TIMESPECTYPE ts_end;
98+
+ struct TIMESPECTYPE ts_diff;
99+
100+
- getnstimeofday(&ts_end);
101+
+ GETNSTIMEOFDAY(&ts_end);
102+
ts_diff.tv_sec = ts_end.tv_sec - ts_start->tv_sec;
103+
if (ts_start->tv_nsec > ts_end.tv_nsec) {
104+
--ts_diff.tv_sec;
105+
@@ -3998,8 +4002,8 @@ struct timespec time_elapsed(struct timespec *ts_start)
106+
/* If lock available return 1, if can't lock return 0 */
107+
int amd_try_spinlock(spinlock_t *lock, uint32_t usec_timeout)
108+
{
109+
- struct timespec start_time;
110+
- struct timespec elapsed_time;
111+
+ struct TIMESPECTYPE start_time;
112+
+ struct TIMESPECTYPE elapsed_time;
113+
114+
/* check the lock */
115+
if (spin_trylock(lock))
116+
@@ -4008,7 +4012,7 @@ int amd_try_spinlock(spinlock_t *lock, uint32_t usec_timeout)
117+
/* Lock is busy */
118+
gim_warn("Lock is busy\n");
119+
/* Get the current time */
120+
- getnstimeofday(&start_time);
121+
+ GETNSTIMEOFDAY(&start_time);
122+
/* loop checking lock and time until timeout */
123+
elapsed_time.tv_sec = 0;
124+
elapsed_time.tv_nsec = 0;
125+
@@ -4017,7 +4021,11 @@ int amd_try_spinlock(spinlock_t *lock, uint32_t usec_timeout)
126+
if (elapsed_time.tv_nsec > (usec_timeout * 1000))
127+
return 0;
128+
}
129+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
130+
gim_info("Lock was busy but freed after %ld.%9ld sec\n",
131+
+#else
132+
+ gim_info("Lock was busy but freed after %lld.%9ld sec\n",
133+
+#endif
134+
elapsed_time.tv_sec, elapsed_time.tv_nsec);
135+
return 1;
136+
}
137+
diff --git a/drv/gim_adapter.h b/drv/gim_adapter.h
138+
index 2da05ee..570e03c 100644
139+
--- a/drv/gim_adapter.h
140+
+++ b/drv/gim_adapter.h
141+
@@ -28,6 +28,7 @@
142+
#include <linux/timer.h>
143+
#include <linux/hrtimer.h>
144+
#include <linux/workqueue.h>
145+
+#include <linux/version.h>
146+
#include "gim_fb.h"
147+
#include "gim_pci.h"
148+
#include "gim_flr.h"
149+
@@ -99,16 +100,33 @@ union physical_address {
150+
151+
152+
#define MAX_MSG_LEN 64
153+
+
154+
+/* Kernel >= 5.0 removed some old timespec methods */
155+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
156+
+#define TIMESPECTYPE timespec
157+
+#define TIMEVALTYPE timeval
158+
+#define TIMESPEC_ADD(x,y) timespec_add((x),(y))
159+
+#define TIMESPEC_SUB(x,y) timespec_sub((x),(y))
160+
+#define GETNSTIMEOFDAY(x) getnstimeofday(x)
161+
+#else
162+
+#define TIMESPECTYPE timespec64
163+
+#define TIMEVALTYPE timespec64
164+
+#define TIMESPEC_ADD(x,y) timespec64_add((x),(y))
165+
+#define TIMESPEC_SUB(x,y) timespec64_sub((x),(y))
166+
+#define GETNSTIMEOFDAY(x) ktime_get_real_ts64(x)
167+
+#define do_gettimeofday(x) ktime_get_real_ts64(x)
168+
+#endif
169+
+
170+
struct op_time_log {
171+
- struct timeval init_start;
172+
- struct timeval init_end;
173+
- struct timeval finish_start;
174+
- struct timeval finish_end;
175+
+ struct TIMEVALTYPE init_start;
176+
+ struct TIMEVALTYPE init_end;
177+
+ struct TIMEVALTYPE finish_start;
178+
+ struct TIMEVALTYPE finish_end;
179+
int reset_count;
180+
- struct timeval reset_time;
181+
+ struct TIMEVALTYPE reset_time;
182+
/* we need accurate time here*/
183+
- struct timespec active_last_tick;
184+
- struct timespec active_time;
185+
+ struct TIMESPECTYPE active_last_tick;
186+
+ struct TIMESPECTYPE active_time;
187+
};
188+
189+
enum amdgim_option_mode {
190+
@@ -413,7 +431,7 @@ struct adapter {
191+
struct work_task irq_tasks[MAX_VIRTUAL_FUNCTIONS];
192+
int vf_req_gpu_access;
193+
/* the time when a VF enters full access mode*/
194+
- struct timespec start_time;
195+
+ struct TIMESPECTYPE start_time;
196+
/* timeout check timer*/
197+
struct hrtimer timeout_timer;
198+
/* record the last VF id that owns gpu*/
199+
@@ -534,7 +552,7 @@ int gim_sched_reset_vf(struct adapter *adapt,
200+
int command_status);
201+
202+
int gim_sched_reset_gpu(struct adapter *adapt);
203+
-struct timespec time_elapsed(struct timespec *ts_start);
204+
+struct TIMESPECTYPE time_elapsed(struct TIMESPECTYPE *ts_start);
205+
void pause_scheduler(struct adapter *adapt);
206+
void resume_scheduler(struct adapter *adapt);
207+
int get_scheduler_time_interval(struct adapter *adapt, struct function *func);
208+
diff --git a/drv/gim_dma.c b/drv/gim_dma.c
209+
index 75bb72e..421df0c 100644
210+
--- a/drv/gim_dma.c
211+
+++ b/drv/gim_dma.c
212+
@@ -48,11 +48,11 @@ void *map_vf_fb(struct pci_dev *pdev);
213+
*/
214+
static int wait_dma_ready(struct adapter *adapt)
215+
{
216+
- struct timespec start_time;
217+
+ struct TIMESPECTYPE start_time;
218+
unsigned long dma_cntl = 0;
219+
int rc = 0;
220+
221+
- getnstimeofday(&start_time);
222+
+ GETNSTIMEOFDAY(&start_time);
223+
do {
224+
dma_cntl = pf_read_register(adapt, mmCP_DMA_CNTL);
225+
/* DMA has 2 PIO commands in the FIFO
226+
@@ -76,11 +76,11 @@ static int wait_dma_ready(struct adapter *adapt)
227+
*/
228+
static int wait_dma_complete(struct adapter *adapt)
229+
{
230+
- struct timespec start_time;
231+
+ struct TIMESPECTYPE start_time;
232+
unsigned int cp_stat = 0;
233+
int rc = 0;
234+
235+
- getnstimeofday(&start_time);
236+
+ GETNSTIMEOFDAY(&start_time);
237+
do {
238+
cp_stat = pf_read_register(adapt, mmCP_STAT);
239+
} while ((cp_stat & 0x80400000)/* CP_BUSY or DMA_BUSY */
240+
diff --git a/drv/gim_irqmgr.c b/drv/gim_irqmgr.c
241+
index 035d26c..e799f74 100644
242+
--- a/drv/gim_irqmgr.c
243+
+++ b/drv/gim_irqmgr.c
244+
@@ -1488,7 +1488,7 @@ int handle_fullaccess_timeout(struct adapter *adapt)
245+
struct function *func = NULL;
246+
struct function *next_func = NULL;
247+
struct function_list_node *node;
248+
- struct timespec time_diff;
249+
+ struct TIMESPECTYPE time_diff;
250+
unsigned long time_us;
251+
int func_id = 0;
252+
253+
@@ -1664,7 +1664,7 @@ void signal_scheduler(void *pcontext)
254+
/* set the timestamp for full access
255+
* timeout check
256+
*/
257+
- getnstimeofday(&adapt->start_time);
258+
+ GETNSTIMEOFDAY(&adapt->start_time);
259+
/* send SIG_VF_EXCLUSIVE_MMIO to QEMU */
260+
handle_req_gpu_init_access(adapt,
261+
req_gpu_task->func_id, NO_RESET);
262+
@@ -1685,7 +1685,7 @@ void signal_scheduler(void *pcontext)
263+
/* set the timestamp for full access timeout
264+
* check
265+
*/
266+
- getnstimeofday(&adapt->start_time);
267+
+ GETNSTIMEOFDAY(&adapt->start_time);
268+
handle_req_gpu_init_access(adapt,
269+
req_gpu_task->func_id, RESET_REQUEST);
270+
271+
@@ -1717,7 +1717,7 @@ void signal_scheduler(void *pcontext)
272+
/* set the timestamp for full access timeout
273+
* check
274+
*/
275+
- getnstimeofday(&adapt->start_time);
276+
+ GETNSTIMEOFDAY(&adapt->start_time);
277+
/* send SIG_VF_EXCLUSIVE_MMIO to QEMU */
278+
handle_req_gpu_fini_access(adapt,
279+
req_gpu_task->func_id);
280+
diff --git a/drv/gim_monitor.c b/drv/gim_monitor.c
281+
index 0107277..72e0267 100644
282+
--- a/drv/gim_monitor.c
283+
+++ b/drv/gim_monitor.c
284+
@@ -950,7 +950,7 @@ static int amdgim_op_gpuvf_vf(char *param, void *obj, void *result)
285+
unsigned int temp;
286+
unsigned int vf_candidate;
287+
288+
- struct timeval cur_time;
289+
+ struct TIMEVALTYPE cur_time;
290+
struct function *p_func;
291+
struct partition *part;
292+
struct adapter *p_adapter;
293+
diff --git a/drv/gim_monitor_ioctl.c b/drv/gim_monitor_ioctl.c
294+
index cd24c7d..8fba6de 100644
295+
--- a/drv/gim_monitor_ioctl.c
296+
+++ b/drv/gim_monitor_ioctl.c
297+
@@ -54,7 +54,7 @@ char *amdgim_commands[AMDGIM_COMMAND_LEN] = {
298+
299+
void amdgim_mutex_get_lock(struct amdgim_mutex_lock *mutexlock)
300+
{
301+
- struct timeval curr_t;
302+
+ struct TIMEVALTYPE curr_t;
303+
304+
do {
305+
spin_lock(&mutexlock->atom_lock);
306+
diff --git a/drv/gim_monitor_ioctl.h b/drv/gim_monitor_ioctl.h
307+
index 33c9368..65e64ae 100644
308+
--- a/drv/gim_monitor_ioctl.h
309+
+++ b/drv/gim_monitor_ioctl.h
310+
@@ -35,7 +35,7 @@
311+
struct amdgim_mutex_lock {
312+
bool locked;
313+
struct mutex lock_mutex;
314+
- struct timeval timeout_start;
315+
+ struct TIMEVALTYPE timeout_start;
316+
spinlock_t atom_lock;
317+
};
318+

0 commit comments

Comments
 (0)