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 	const struct nvkm_chan_func_inst {
21 		u32 size;
22 		bool zero;
23 		bool vmm;
24 	} *inst;
25 
26 	const struct nvkm_chan_func_userd {
27 		int bar;
28 		u32 base;
29 		u32 size;
30 		void (*clear)(struct nvkm_chan *);
31 	} *userd;
32 
33 	const struct nvkm_chan_func_ramfc {
34 		const struct nvkm_ramfc_layout {
35 			unsigned bits:6;
36 			unsigned ctxs:5;
37 			unsigned ctxp:8;
38 			unsigned regs:5;
39 			unsigned regp;
40 		} *layout;
41 		int (*write)(struct nvkm_chan *, u64 offset, u64 length, u32 devm, bool priv);
42 		void (*clear)(struct nvkm_chan *);
43 		bool ctxdma;
44 		u32 devm;
45 		bool priv;
46 	} *ramfc;
47 
48 	void (*bind)(struct nvkm_chan *);
49 	void (*unbind)(struct nvkm_chan *);
50 	void (*start)(struct nvkm_chan *);
51 	void (*stop)(struct nvkm_chan *);
52 	void (*preempt)(struct nvkm_chan *);
53 	u32 (*doorbell_handle)(struct nvkm_chan *);
54 };
55 
56 int nvkm_chan_new_(const struct nvkm_chan_func *, struct nvkm_runl *, int runq, struct nvkm_cgrp *,
57 		   const char *name, bool priv, u32 devm, struct nvkm_vmm *, struct nvkm_dmaobj *,
58 		   u64 offset, u64 length, struct nvkm_memory *userd, u64 userd_bar1,
59 		   struct nvkm_chan **);
60 void nvkm_chan_del(struct nvkm_chan **);
61 void nvkm_chan_allow(struct nvkm_chan *);
62 void nvkm_chan_block(struct nvkm_chan *);
63 void nvkm_chan_error(struct nvkm_chan *, bool preempt);
64 void nvkm_chan_insert(struct nvkm_chan *);
65 void nvkm_chan_remove(struct nvkm_chan *, bool preempt);
66 void nvkm_chan_remove_locked(struct nvkm_chan *);
67 int nvkm_chan_preempt(struct nvkm_chan *, bool wait);
68 int nvkm_chan_preempt_locked(struct nvkm_chan *, bool wait);
69 int nvkm_chan_cctx_get(struct nvkm_chan *, struct nvkm_engn *, struct nvkm_cctx **,
70 		       struct nvkm_client * /*TODO: remove need for this */);
71 void nvkm_chan_cctx_put(struct nvkm_chan *, struct nvkm_cctx **);
72 void nvkm_chan_cctx_bind(struct nvkm_chan *, struct nvkm_engn *, struct nvkm_cctx *);
73 
74 #define CHAN_PRCLI(c,l,p,f,a...) CGRP_PRINT((c)->cgrp, l, p, "%04x:[%s]"f, (c)->id, (c)->name, ##a)
75 #define CHAN_PRINT(c,l,p,f,a...) CGRP_PRINT((c)->cgrp, l, p, "%04x:"f, (c)->id, ##a)
76 #define CHAN_ERROR(c,f,a...) CHAN_PRCLI((c), ERROR,    err, " "f"\n", ##a)
77 #define CHAN_TRACE(c,f,a...) CHAN_PRINT((c), TRACE,   info, " "f"\n", ##a)
78 #endif
79