xref: /openbmc/linux/drivers/gpu/drm/lima/lima_sched.h (revision 15e3ae36)
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 xarray deps;
18 	unsigned long last_dep;
19 
20 	struct lima_bo **bos;
21 	int num_bos;
22 
23 	bool recoverable;
24 	struct lima_bo *heap;
25 
26 	/* pipe fence */
27 	struct dma_fence *fence;
28 };
29 
30 struct lima_sched_context {
31 	struct drm_sched_entity base;
32 };
33 
34 #define LIMA_SCHED_PIPE_MAX_MMU       8
35 #define LIMA_SCHED_PIPE_MAX_L2_CACHE  2
36 #define LIMA_SCHED_PIPE_MAX_PROCESSOR 8
37 
38 struct lima_ip;
39 
40 struct lima_sched_pipe {
41 	struct drm_gpu_scheduler base;
42 
43 	u64 fence_context;
44 	u32 fence_seqno;
45 	spinlock_t fence_lock;
46 
47 	struct lima_sched_task *current_task;
48 	struct lima_vm *current_vm;
49 
50 	struct lima_ip *mmu[LIMA_SCHED_PIPE_MAX_MMU];
51 	int num_mmu;
52 
53 	struct lima_ip *l2_cache[LIMA_SCHED_PIPE_MAX_L2_CACHE];
54 	int num_l2_cache;
55 
56 	struct lima_ip *processor[LIMA_SCHED_PIPE_MAX_PROCESSOR];
57 	int num_processor;
58 
59 	struct lima_ip *bcast_processor;
60 	struct lima_ip *bcast_mmu;
61 
62 	u32 done;
63 	bool error;
64 	atomic_t task;
65 
66 	int frame_size;
67 	struct kmem_cache *task_slab;
68 
69 	int (*task_validate)(struct lima_sched_pipe *pipe, struct lima_sched_task *task);
70 	void (*task_run)(struct lima_sched_pipe *pipe, struct lima_sched_task *task);
71 	void (*task_fini)(struct lima_sched_pipe *pipe);
72 	void (*task_error)(struct lima_sched_pipe *pipe);
73 	void (*task_mmu_error)(struct lima_sched_pipe *pipe);
74 	int (*task_recover)(struct lima_sched_pipe *pipe);
75 
76 	struct work_struct recover_work;
77 };
78 
79 int lima_sched_task_init(struct lima_sched_task *task,
80 			 struct lima_sched_context *context,
81 			 struct lima_bo **bos, int num_bos,
82 			 struct lima_vm *vm);
83 void lima_sched_task_fini(struct lima_sched_task *task);
84 
85 int lima_sched_context_init(struct lima_sched_pipe *pipe,
86 			    struct lima_sched_context *context,
87 			    atomic_t *guilty);
88 void lima_sched_context_fini(struct lima_sched_pipe *pipe,
89 			     struct lima_sched_context *context);
90 struct dma_fence *lima_sched_context_queue_task(struct lima_sched_context *context,
91 						struct lima_sched_task *task);
92 
93 int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name);
94 void lima_sched_pipe_fini(struct lima_sched_pipe *pipe);
95 void lima_sched_pipe_task_done(struct lima_sched_pipe *pipe);
96 
97 static inline void lima_sched_pipe_mmu_error(struct lima_sched_pipe *pipe)
98 {
99 	pipe->error = true;
100 	pipe->task_mmu_error(pipe);
101 }
102 
103 int lima_sched_slab_init(void);
104 void lima_sched_slab_fini(void);
105 
106 #endif
107