1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
4 #ifndef __LIMA_SCHED_H__
5 #define __LIMA_SCHED_H__
7 #include <drm/gpu_scheduler.h>
8 #include <linux/list.h>
9 #include <linux/xarray.h>
14 struct lima_sched_error_task {
15 struct list_head list;
20 struct lima_sched_task {
21 struct drm_sched_job base;
33 struct dma_fence *fence;
36 struct lima_sched_context {
37 struct drm_sched_entity base;
40 #define LIMA_SCHED_PIPE_MAX_MMU 8
41 #define LIMA_SCHED_PIPE_MAX_L2_CACHE 2
42 #define LIMA_SCHED_PIPE_MAX_PROCESSOR 8
46 struct lima_sched_pipe {
47 struct drm_gpu_scheduler base;
51 spinlock_t fence_lock;
53 struct lima_device *ldev;
55 struct lima_sched_task *current_task;
56 struct lima_vm *current_vm;
58 struct lima_ip *mmu[LIMA_SCHED_PIPE_MAX_MMU];
61 struct lima_ip *l2_cache[LIMA_SCHED_PIPE_MAX_L2_CACHE];
64 struct lima_ip *processor[LIMA_SCHED_PIPE_MAX_PROCESSOR];
67 struct lima_ip *bcast_processor;
68 struct lima_ip *bcast_mmu;
75 struct kmem_cache *task_slab;
77 int (*task_validate)(struct lima_sched_pipe *pipe, struct lima_sched_task *task);
78 void (*task_run)(struct lima_sched_pipe *pipe, struct lima_sched_task *task);
79 void (*task_fini)(struct lima_sched_pipe *pipe);
80 void (*task_error)(struct lima_sched_pipe *pipe);
81 void (*task_mmu_error)(struct lima_sched_pipe *pipe);
82 int (*task_recover)(struct lima_sched_pipe *pipe);
83 void (*task_mask_irq)(struct lima_sched_pipe *pipe);
85 struct work_struct recover_work;
88 int lima_sched_task_init(struct lima_sched_task *task,
89 struct lima_sched_context *context,
90 struct lima_bo **bos, int num_bos,
92 void lima_sched_task_fini(struct lima_sched_task *task);
94 int lima_sched_context_init(struct lima_sched_pipe *pipe,
95 struct lima_sched_context *context);
96 void lima_sched_context_fini(struct lima_sched_pipe *pipe,
97 struct lima_sched_context *context);
98 struct dma_fence *lima_sched_context_queue_task(struct lima_sched_task *task);
100 int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name);
101 void lima_sched_pipe_fini(struct lima_sched_pipe *pipe);
102 void lima_sched_pipe_task_done(struct lima_sched_pipe *pipe);
104 static inline void lima_sched_pipe_mmu_error(struct lima_sched_pipe *pipe)
107 pipe->task_mmu_error(pipe);
110 int lima_sched_slab_init(void);
111 void lima_sched_slab_fini(void);