1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_CHAN_H__
3 #define __NVKM_CHAN_H__
4 #include <engine/fifo.h>
5 struct nvkm_dmaobj;
6 struct nvkm_engn;
7 struct nvkm_runl;
8 
9 extern const struct nvkm_event_func nvkm_chan_event;
10 
11 struct nvkm_cctx {
12 	struct nvkm_vctx *vctx;
13 	refcount_t refs;
14 	refcount_t uses;
15 
16 	struct list_head head;
17 };
18 
19 struct nvkm_chan_func {
20 	int (*id_get)(struct nvkm_chan *, struct nvkm_memory *userd, u64 ouserd);
21 	void (*id_put)(struct nvkm_chan *);
22 
23 	const struct nvkm_chan_func_inst {
24 		u32 size;
25 		bool zero;
26 		bool vmm;
27 	} *inst;
28 
29 	const struct nvkm_chan_func_userd {
30 		int bar;
31 		u32 base;
32 		u32 size;
33 		void (*clear)(struct nvkm_chan *);
34 	} *userd;
35 
36 	const struct nvkm_chan_func_ramfc {
37 		const struct nvkm_ramfc_layout {
38 			unsigned bits:6;
39 			unsigned ctxs:5;
40 			unsigned ctxp:8;
41 			unsigned regs:5;
42 			unsigned regp;
43 		} *layout;
44 		int (*write)(struct nvkm_chan *, u64 offset, u64 length, u32 devm, bool priv);
45 		void (*clear)(struct nvkm_chan *);
46 		bool ctxdma;
47 		u32 devm;
48 		bool priv;
49 	} *ramfc;
50 
51 	void (*bind)(struct nvkm_chan *);
52 	void (*unbind)(struct nvkm_chan *);
53 	void (*start)(struct nvkm_chan *);
54 	void (*stop)(struct nvkm_chan *);
55 	void (*preempt)(struct nvkm_chan *);
56 	u32 (*doorbell_handle)(struct nvkm_chan *);
57 };
58 
59 int nvkm_chan_new_(const struct nvkm_chan_func *, struct nvkm_runl *, int runq, struct nvkm_cgrp *,
60 		   const char *name, bool priv, u32 devm, struct nvkm_vmm *, struct nvkm_dmaobj *,
61 		   u64 offset, u64 length, struct nvkm_memory *userd, u64 userd_bar1,
62 		   struct nvkm_chan **);
63 void nvkm_chan_del(struct nvkm_chan **);
64 void nvkm_chan_allow(struct nvkm_chan *);
65 void nvkm_chan_block(struct nvkm_chan *);
66 void nvkm_chan_error(struct nvkm_chan *, bool preempt);
67 void nvkm_chan_insert(struct nvkm_chan *);
68 void nvkm_chan_remove(struct nvkm_chan *, bool preempt);
69 void nvkm_chan_remove_locked(struct nvkm_chan *);
70 int nvkm_chan_preempt(struct nvkm_chan *, bool wait);
71 int nvkm_chan_preempt_locked(struct nvkm_chan *, bool wait);
72 int nvkm_chan_cctx_get(struct nvkm_chan *, struct nvkm_engn *, struct nvkm_cctx **,
73 		       struct nvkm_client * /*TODO: remove need for this */);
74 void nvkm_chan_cctx_put(struct nvkm_chan *, struct nvkm_cctx **);
75 void nvkm_chan_cctx_bind(struct nvkm_chan *, struct nvkm_engn *, struct nvkm_cctx *);
76 
77 #define CHAN_PRCLI(c,l,p,f,a...) CGRP_PRINT((c)->cgrp, l, p, "%04x:[%s]"f, (c)->id, (c)->name, ##a)
78 #define CHAN_PRINT(c,l,p,f,a...) CGRP_PRINT((c)->cgrp, l, p, "%04x:"f, (c)->id, ##a)
79 #define CHAN_ERROR(c,f,a...) CHAN_PRCLI((c), ERROR,    err, " "f"\n", ##a)
80 #define CHAN_TRACE(c,f,a...) CHAN_PRINT((c), TRACE,   info, " "f"\n", ##a)
81 #endif
82