Merge tag 'drm-intel-next-2019-04-17' of git://anongit.freedesktop.org/drm/drm-intel...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / lima / lima_sched.h
1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /* Copyright 2017-2019 Qiang Yu <yuq825@gmail.com> */
3
4 #ifndef __LIMA_SCHED_H__
5 #define __LIMA_SCHED_H__
6
7 #include <drm/gpu_scheduler.h>
8
9 struct lima_vm;
10
11 struct lima_sched_task {
12         struct drm_sched_job base;
13
14         struct lima_vm *vm;
15         void *frame;
16
17         struct dma_fence **dep;
18         int num_dep;
19         int max_dep;
20
21         struct lima_bo **bos;
22         int num_bos;
23
24         /* pipe fence */
25         struct dma_fence *fence;
26 };
27
28 struct lima_sched_context {
29         struct drm_sched_entity base;
30 };
31
32 #define LIMA_SCHED_PIPE_MAX_MMU       8
33 #define LIMA_SCHED_PIPE_MAX_L2_CACHE  2
34 #define LIMA_SCHED_PIPE_MAX_PROCESSOR 8
35
36 struct lima_ip;
37
38 struct lima_sched_pipe {
39         struct drm_gpu_scheduler base;
40
41         u64 fence_context;
42         u32 fence_seqno;
43         spinlock_t fence_lock;
44
45         struct lima_sched_task *current_task;
46         struct lima_vm *current_vm;
47
48         struct lima_ip *mmu[LIMA_SCHED_PIPE_MAX_MMU];
49         int num_mmu;
50
51         struct lima_ip *l2_cache[LIMA_SCHED_PIPE_MAX_L2_CACHE];
52         int num_l2_cache;
53
54         struct lima_ip *processor[LIMA_SCHED_PIPE_MAX_PROCESSOR];
55         int num_processor;
56
57         struct lima_ip *bcast_processor;
58         struct lima_ip *bcast_mmu;
59
60         u32 done;
61         bool error;
62         atomic_t task;
63
64         int frame_size;
65         struct kmem_cache *task_slab;
66
67         int (*task_validate)(struct lima_sched_pipe *pipe, struct lima_sched_task *task);
68         void (*task_run)(struct lima_sched_pipe *pipe, struct lima_sched_task *task);
69         void (*task_fini)(struct lima_sched_pipe *pipe);
70         void (*task_error)(struct lima_sched_pipe *pipe);
71         void (*task_mmu_error)(struct lima_sched_pipe *pipe);
72
73         struct work_struct error_work;
74 };
75
76 int lima_sched_task_init(struct lima_sched_task *task,
77                          struct lima_sched_context *context,
78                          struct lima_bo **bos, int num_bos,
79                          struct lima_vm *vm);
80 void lima_sched_task_fini(struct lima_sched_task *task);
81 int lima_sched_task_add_dep(struct lima_sched_task *task, struct dma_fence *fence);
82
83 int lima_sched_context_init(struct lima_sched_pipe *pipe,
84                             struct lima_sched_context *context,
85                             atomic_t *guilty);
86 void lima_sched_context_fini(struct lima_sched_pipe *pipe,
87                              struct lima_sched_context *context);
88 struct dma_fence *lima_sched_context_queue_task(struct lima_sched_context *context,
89                                                 struct lima_sched_task *task);
90
91 int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name);
92 void lima_sched_pipe_fini(struct lima_sched_pipe *pipe);
93 void lima_sched_pipe_task_done(struct lima_sched_pipe *pipe);
94
95 static inline void lima_sched_pipe_mmu_error(struct lima_sched_pipe *pipe)
96 {
97         pipe->error = true;
98         pipe->task_mmu_error(pipe);
99 }
100
101 int lima_sched_slab_init(void);
102 void lima_sched_slab_fini(void);
103
104 #endif