xref: /linux/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.h (revision fd7d598270724cc787982ea48bbe17ad383a8b7f)
1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_CGRP_H__
3 #define __NVKM_CGRP_H__
4 #include <core/os.h>
5 struct nvkm_chan;
6 struct nvkm_client;
7 
8 struct nvkm_vctx {
9 	struct nvkm_ectx *ectx;
10 	struct nvkm_vmm *vmm;
11 	refcount_t refs;
12 
13 	struct nvkm_gpuobj *inst;
14 	struct nvkm_vma *vma;
15 
16 	struct list_head head;
17 };
18 
19 struct nvkm_ectx {
20 	struct nvkm_engn *engn;
21 	refcount_t refs;
22 	refcount_t uses;
23 
24 	struct nvkm_object *object;
25 
26 	struct list_head head;
27 };
28 
29 struct nvkm_cgrp {
30 	const struct nvkm_cgrp_func {
31 		void (*preempt)(struct nvkm_cgrp *);
32 	} *func;
33 	char name[64];
34 	struct nvkm_runl *runl;
35 	struct nvkm_vmm *vmm;
36 	bool hw;
37 	int id;
38 	struct kref kref;
39 
40 	struct list_head chans;
41 	int chan_nr;
42 
43 	spinlock_t lock; /* protects irq handler channel (group) lookup */
44 
45 	struct list_head ectxs;
46 	struct list_head vctxs;
47 	struct mutex mutex;
48 
49 #define NVKM_CGRP_RC_NONE    0
50 #define NVKM_CGRP_RC_PENDING 1
51 #define NVKM_CGRP_RC_RUNNING 2
52 	atomic_t rc;
53 
54 	struct list_head head;
55 };
56 
57 int nvkm_cgrp_new(struct nvkm_runl *, const char *name, struct nvkm_vmm *, bool hw,
58 		  struct nvkm_cgrp **);
59 struct nvkm_cgrp *nvkm_cgrp_ref(struct nvkm_cgrp *);
60 void nvkm_cgrp_unref(struct nvkm_cgrp **);
61 int nvkm_cgrp_vctx_get(struct nvkm_cgrp *, struct nvkm_engn *, struct nvkm_chan *,
62 		       struct nvkm_vctx **, struct nvkm_client *);
63 void nvkm_cgrp_vctx_put(struct nvkm_cgrp *, struct nvkm_vctx **);
64 
65 void nvkm_cgrp_put(struct nvkm_cgrp **, unsigned long irqflags);
66 
67 #define nvkm_cgrp_foreach_chan(chan,cgrp) list_for_each_entry((chan), &(cgrp)->chans, head)
68 #define nvkm_cgrp_foreach_chan_safe(chan,ctmp,cgrp) \
69 	list_for_each_entry_safe((chan), (ctmp), &(cgrp)->chans, head)
70 
71 #define CGRP_PRCLI(c,l,p,f,a...) RUNL_PRINT((c)->runl, l, p, "%04x:[%s]"f, (c)->id, (c)->name, ##a)
72 #define CGRP_PRINT(c,l,p,f,a...) RUNL_PRINT((c)->runl, l, p, "%04x:"f, (c)->id, ##a)
73 #define CGRP_ERROR(c,f,a...) CGRP_PRCLI((c), ERROR,    err, " "f"\n", ##a)
74 #define CGRP_TRACE(c,f,a...) CGRP_PRINT((c), TRACE,   info, " "f"\n", ##a)
75 #endif
76