xref: /linux/drivers/gpu/drm/lima/lima_sched.h (revision e721d1cc8101a26fba22dc9a62309522e15bd0c7)
1a1d2a633SQiang Yu /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2a1d2a633SQiang Yu /* Copyright 2017-2019 Qiang Yu <yuq825@gmail.com> */
3a1d2a633SQiang Yu 
4a1d2a633SQiang Yu #ifndef __LIMA_SCHED_H__
5a1d2a633SQiang Yu #define __LIMA_SCHED_H__
6a1d2a633SQiang Yu 
7a1d2a633SQiang Yu #include <drm/gpu_scheduler.h>
8b78edd46SQiang Yu #include <linux/list.h>
97f60c4b9SQiang Yu #include <linux/xarray.h>
10a1d2a633SQiang Yu 
1119969707SMartin Blumenstingl struct lima_device;
12a1d2a633SQiang Yu struct lima_vm;
13a1d2a633SQiang Yu 
14b78edd46SQiang Yu struct lima_sched_error_task {
15b78edd46SQiang Yu 	struct list_head list;
16b78edd46SQiang Yu 	void *data;
17b78edd46SQiang Yu 	u32 size;
18b78edd46SQiang Yu };
19b78edd46SQiang Yu 
20a1d2a633SQiang Yu struct lima_sched_task {
21a1d2a633SQiang Yu 	struct drm_sched_job base;
22a1d2a633SQiang Yu 
23a1d2a633SQiang Yu 	struct lima_vm *vm;
24a1d2a633SQiang Yu 	void *frame;
25a1d2a633SQiang Yu 
26a1d2a633SQiang Yu 	struct lima_bo **bos;
27a1d2a633SQiang Yu 	int num_bos;
28a1d2a633SQiang Yu 
292081e8dcSQiang Yu 	bool recoverable;
302081e8dcSQiang Yu 	struct lima_bo *heap;
312081e8dcSQiang Yu 
32a1d2a633SQiang Yu 	/* pipe fence */
33a1d2a633SQiang Yu 	struct dma_fence *fence;
34a1d2a633SQiang Yu };
35a1d2a633SQiang Yu 
36a1d2a633SQiang Yu struct lima_sched_context {
37a1d2a633SQiang Yu 	struct drm_sched_entity base;
38a1d2a633SQiang Yu };
39a1d2a633SQiang Yu 
40a1d2a633SQiang Yu #define LIMA_SCHED_PIPE_MAX_MMU       8
41a1d2a633SQiang Yu #define LIMA_SCHED_PIPE_MAX_L2_CACHE  2
42a1d2a633SQiang Yu #define LIMA_SCHED_PIPE_MAX_PROCESSOR 8
43a1d2a633SQiang Yu 
44a1d2a633SQiang Yu struct lima_ip;
45a1d2a633SQiang Yu 
46a1d2a633SQiang Yu struct lima_sched_pipe {
47a1d2a633SQiang Yu 	struct drm_gpu_scheduler base;
48a1d2a633SQiang Yu 
49a1d2a633SQiang Yu 	u64 fence_context;
50a1d2a633SQiang Yu 	u32 fence_seqno;
51a1d2a633SQiang Yu 	spinlock_t fence_lock;
52a1d2a633SQiang Yu 
5319969707SMartin Blumenstingl 	struct lima_device *ldev;
5419969707SMartin Blumenstingl 
55a1d2a633SQiang Yu 	struct lima_sched_task *current_task;
56a1d2a633SQiang Yu 	struct lima_vm *current_vm;
57a1d2a633SQiang Yu 
58a1d2a633SQiang Yu 	struct lima_ip *mmu[LIMA_SCHED_PIPE_MAX_MMU];
59a1d2a633SQiang Yu 	int num_mmu;
60a1d2a633SQiang Yu 
61a1d2a633SQiang Yu 	struct lima_ip *l2_cache[LIMA_SCHED_PIPE_MAX_L2_CACHE];
62a1d2a633SQiang Yu 	int num_l2_cache;
63a1d2a633SQiang Yu 
64a1d2a633SQiang Yu 	struct lima_ip *processor[LIMA_SCHED_PIPE_MAX_PROCESSOR];
65a1d2a633SQiang Yu 	int num_processor;
66a1d2a633SQiang Yu 
67a1d2a633SQiang Yu 	struct lima_ip *bcast_processor;
68a1d2a633SQiang Yu 	struct lima_ip *bcast_mmu;
69a1d2a633SQiang Yu 
70a1d2a633SQiang Yu 	u32 done;
71a1d2a633SQiang Yu 	bool error;
72a1d2a633SQiang Yu 	atomic_t task;
73a1d2a633SQiang Yu 
74a1d2a633SQiang Yu 	int frame_size;
75a1d2a633SQiang Yu 	struct kmem_cache *task_slab;
76a1d2a633SQiang Yu 
77a1d2a633SQiang Yu 	int (*task_validate)(struct lima_sched_pipe *pipe, struct lima_sched_task *task);
78a1d2a633SQiang Yu 	void (*task_run)(struct lima_sched_pipe *pipe, struct lima_sched_task *task);
79a1d2a633SQiang Yu 	void (*task_fini)(struct lima_sched_pipe *pipe);
80a1d2a633SQiang Yu 	void (*task_error)(struct lima_sched_pipe *pipe);
81a1d2a633SQiang Yu 	void (*task_mmu_error)(struct lima_sched_pipe *pipe);
822081e8dcSQiang Yu 	int (*task_recover)(struct lima_sched_pipe *pipe);
832081e8dcSQiang Yu 
842081e8dcSQiang Yu 	struct work_struct recover_work;
85a1d2a633SQiang Yu };
86a1d2a633SQiang Yu 
87a1d2a633SQiang Yu int lima_sched_task_init(struct lima_sched_task *task,
88a1d2a633SQiang Yu 			 struct lima_sched_context *context,
89a1d2a633SQiang Yu 			 struct lima_bo **bos, int num_bos,
90a1d2a633SQiang Yu 			 struct lima_vm *vm);
91a1d2a633SQiang Yu void lima_sched_task_fini(struct lima_sched_task *task);
92a1d2a633SQiang Yu 
93a1d2a633SQiang Yu int lima_sched_context_init(struct lima_sched_pipe *pipe,
94*e721d1ccSErico Nunes 			    struct lima_sched_context *context);
95a1d2a633SQiang Yu void lima_sched_context_fini(struct lima_sched_pipe *pipe,
96a1d2a633SQiang Yu 			     struct lima_sched_context *context);
970e10e9a1SDaniel Vetter struct dma_fence *lima_sched_context_queue_task(struct lima_sched_task *task);
98a1d2a633SQiang Yu 
99a1d2a633SQiang Yu int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name);
100a1d2a633SQiang Yu void lima_sched_pipe_fini(struct lima_sched_pipe *pipe);
101a1d2a633SQiang Yu void lima_sched_pipe_task_done(struct lima_sched_pipe *pipe);
102a1d2a633SQiang Yu 
103a1d2a633SQiang Yu static inline void lima_sched_pipe_mmu_error(struct lima_sched_pipe *pipe)
104a1d2a633SQiang Yu {
105a1d2a633SQiang Yu 	pipe->error = true;
106a1d2a633SQiang Yu 	pipe->task_mmu_error(pipe);
107a1d2a633SQiang Yu }
108a1d2a633SQiang Yu 
109a1d2a633SQiang Yu int lima_sched_slab_init(void);
110a1d2a633SQiang Yu void lima_sched_slab_fini(void);
111a1d2a633SQiang Yu 
112a1d2a633SQiang Yu #endif
113