xref: /linux/drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.h (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
1 #ifndef __NVKM_RUNL_H__
2 #define __NVKM_RUNL_H__
3 #include <core/intr.h>
4 struct nvkm_cctx;
5 struct nvkm_cgrp;
6 struct nvkm_chan;
7 struct nvkm_memory;
8 struct nvkm_object;
9 struct nvkm_vctx;
10 enum nvkm_subdev_type;
11 
12 struct nvkm_engn {
13 	const struct nvkm_engn_func {
14 		bool (*chsw)(struct nvkm_engn *);
15 		int (*cxid)(struct nvkm_engn *, bool *cgid);
16 		void (*mmu_fault_trigger)(struct nvkm_engn *);
17 		bool (*mmu_fault_triggered)(struct nvkm_engn *);
18 		int (*ctor)(struct nvkm_engn *, struct nvkm_vctx *);
19 		void (*bind)(struct nvkm_engn *, struct nvkm_cctx *, struct nvkm_chan *);
20 		int (*ramht_add)(struct nvkm_engn *, struct nvkm_object *, struct nvkm_chan *);
21 		void (*ramht_del)(struct nvkm_chan *, int hash);
22 	} *func;
23 	struct nvkm_runl *runl;
24 	int id;
25 
26 	struct nvkm_engine *engine;
27 
28 	int fault;
29 
30 	struct list_head head;
31 };
32 
33 #define ENGN_PRINT(e,l,p,f,a...)                                                           \
34 	RUNL_PRINT((e)->runl, l, p, "%02d[%8s]:"f, (e)->id, (e)->engine->subdev.name, ##a)
35 #define ENGN_DEBUG(e,f,a...) ENGN_PRINT((e), DEBUG,   info, " "f"\n", ##a)
36 
37 struct nvkm_runl {
38 	const struct nvkm_runl_func {
39 		void (*init)(struct nvkm_runl *);
40 		void (*fini)(struct nvkm_runl *);
41 		int runqs;
42 		u8 size;
43 		int (*update)(struct nvkm_runl *);
44 		void (*insert_cgrp)(struct nvkm_cgrp *, struct nvkm_memory *, u64 offset);
45 		void (*insert_chan)(struct nvkm_chan *, struct nvkm_memory *, u64 offset);
46 		void (*commit)(struct nvkm_runl *, struct nvkm_memory *, u32 start, int count);
47 		int (*wait)(struct nvkm_runl *);
48 		bool (*pending)(struct nvkm_runl *);
49 		void (*block)(struct nvkm_runl *, u32 engm);
50 		void (*allow)(struct nvkm_runl *, u32 engm);
51 		void (*fault_clear)(struct nvkm_runl *);
52 		void (*preempt)(struct nvkm_runl *);
53 		bool (*preempt_pending)(struct nvkm_runl *);
54 	} *func;
55 	struct nvkm_fifo *fifo;
56 	int id;
57 	u32 addr;
58 	u32 chan;
59 	u16 doorbell;
60 
61 	struct nvkm_chid *cgid;
62 #define NVKM_CHAN_EVENT_ERRORED BIT(0)
63 	struct nvkm_chid *chid;
64 
65 	struct list_head engns;
66 
67 	struct nvkm_runq *runq[2];
68 	int runq_nr;
69 
70 	struct nvkm_inth inth;
71 
72 	struct list_head cgrps;
73 	int cgrp_nr;
74 	int chan_nr;
75 	atomic_t changed;
76 	struct nvkm_memory *mem;
77 	u32 offset;
78 	struct mutex mutex;
79 
80 	int blocked;
81 
82 	struct work_struct work;
83 	atomic_t rc_triggered;
84 	atomic_t rc_pending;
85 
86 	struct list_head head;
87 };
88 
89 struct nvkm_runl *nvkm_runl_new(struct nvkm_fifo *, int runi, u32 addr, int id_nr);
90 struct nvkm_runl *nvkm_runl_get(struct nvkm_fifo *, int runi, u32 addr);
91 struct nvkm_engn *nvkm_runl_add(struct nvkm_runl *, int engi, const struct nvkm_engn_func *,
92 				enum nvkm_subdev_type, int inst);
93 void nvkm_runl_del(struct nvkm_runl *);
94 void nvkm_runl_fini(struct nvkm_runl *);
95 void nvkm_runl_block(struct nvkm_runl *);
96 void nvkm_runl_allow(struct nvkm_runl *);
97 void nvkm_runl_update_locked(struct nvkm_runl *, bool wait);
98 bool nvkm_runl_update_pending(struct nvkm_runl *);
99 int nvkm_runl_preempt_wait(struct nvkm_runl *);
100 
101 void nvkm_runl_rc_engn(struct nvkm_runl *, struct nvkm_engn *);
102 void nvkm_runl_rc_cgrp(struct nvkm_cgrp *);
103 
104 struct nvkm_cgrp *nvkm_runl_cgrp_get_cgid(struct nvkm_runl *, int cgid, unsigned long *irqflags);
105 struct nvkm_chan *nvkm_runl_chan_get_chid(struct nvkm_runl *, int chid, unsigned long *irqflags);
106 struct nvkm_chan *nvkm_runl_chan_get_inst(struct nvkm_runl *, u64 inst, unsigned long *irqflags);
107 
108 #define nvkm_runl_find_engn(engn,runl,cond) nvkm_list_find(engn, &(runl)->engns, head, (cond))
109 
110 #define nvkm_runl_first(fifo) list_first_entry(&(fifo)->runls, struct nvkm_runl, head)
111 #define nvkm_runl_foreach(runl,fifo) list_for_each_entry((runl), &(fifo)->runls, head)
112 #define nvkm_runl_foreach_cond(runl,fifo,cond) nvkm_list_foreach(runl, &(fifo)->runls, head, (cond))
113 #define nvkm_runl_foreach_engn(engn,runl) list_for_each_entry((engn), &(runl)->engns, head)
114 #define nvkm_runl_foreach_engn_cond(engn,runl,cond) \
115 	nvkm_list_foreach(engn, &(runl)->engns, head, (cond))
116 #define nvkm_runl_foreach_cgrp(cgrp,runl) list_for_each_entry((cgrp), &(runl)->cgrps, head)
117 #define nvkm_runl_foreach_cgrp_safe(cgrp,gtmp,runl) \
118 	list_for_each_entry_safe((cgrp), (gtmp), &(runl)->cgrps, head)
119 
120 #define RUNL_PRINT(r,l,p,f,a...)                                                          \
121 	nvkm_printk__(&(r)->fifo->engine.subdev, NV_DBG_##l, p, "%06x:"f, (r)->addr, ##a)
122 #define RUNL_ERROR(r,f,a...) RUNL_PRINT((r), ERROR,    err, " "f"\n", ##a)
123 #define RUNL_DEBUG(r,f,a...) RUNL_PRINT((r), DEBUG,   info, " "f"\n", ##a)
124 #define RUNL_TRACE(r,f,a...) RUNL_PRINT((r), TRACE,   info, " "f"\n", ##a)
125 #endif
126