1 /* SPDX-License-Identifier: MIT */
2 #ifndef __GK104_FIFO_H__
3 #define __GK104_FIFO_H__
4 #define gk104_fifo(p) container_of((p), struct gk104_fifo, base)
5 #include "priv.h"
6 struct nvkm_fifo_cgrp;
7 
8 #include <core/enum.h>
9 #include <subdev/mmu.h>
10 
11 struct gk104_fifo_chan;
12 struct gk104_fifo {
13 	const struct gk104_fifo_func *func;
14 	struct nvkm_fifo base;
15 
16 	struct {
17 		struct work_struct work;
18 		u32 engm;
19 		u32 runm;
20 	} recover;
21 
22 	int pbdma_nr;
23 
24 	struct {
25 		struct nvkm_engine *engine;
26 		int runl;
27 		int pbid;
28 	} engine[16];
29 	int engine_nr;
30 
31 	struct {
32 		struct nvkm_memory *mem[2];
33 		int next;
34 		wait_queue_head_t wait;
35 		struct list_head cgrp;
36 		struct list_head chan;
37 		u32 engm;
38 		u32 engm_sw;
39 	} runlist[16];
40 	int runlist_nr;
41 
42 	struct {
43 		struct nvkm_memory *mem;
44 		struct nvkm_vma *bar;
45 	} user;
46 };
47 
48 struct gk104_fifo_func {
49 	struct {
50 		void (*fault)(struct nvkm_fifo *, int unit);
51 	} intr;
52 
53 	const struct gk104_fifo_pbdma_func {
54 		int (*nr)(struct gk104_fifo *);
55 		void (*init)(struct gk104_fifo *);
56 		void (*init_timeout)(struct gk104_fifo *);
57 	} *pbdma;
58 
59 	struct {
60 		const struct nvkm_enum *access;
61 		const struct nvkm_enum *engine;
62 		const struct nvkm_enum *reason;
63 		const struct nvkm_enum *hubclient;
64 		const struct nvkm_enum *gpcclient;
65 	} fault;
66 
67 	const struct gk104_fifo_runlist_func {
68 		u8 size;
69 		void (*cgrp)(struct nvkm_fifo_cgrp *,
70 			     struct nvkm_memory *, u32 offset);
71 		void (*chan)(struct gk104_fifo_chan *,
72 			     struct nvkm_memory *, u32 offset);
73 		void (*commit)(struct gk104_fifo *, int runl,
74 			       struct nvkm_memory *, int entries);
75 	} *runlist;
76 
77 	struct gk104_fifo_user_user {
78 		struct nvkm_sclass user;
79 		int (*ctor)(const struct nvkm_oclass *, void *, u32,
80 			    struct nvkm_object **);
81 	} user;
82 
83 	struct gk104_fifo_chan_user {
84 		struct nvkm_sclass user;
85 		int (*ctor)(struct gk104_fifo *, const struct nvkm_oclass *,
86 			    void *, u32, struct nvkm_object **);
87 	} chan;
88 	bool cgrp_force;
89 };
90 
91 struct gk104_fifo_engine_status {
92 	bool busy;
93 	bool faulted;
94 	bool chsw;
95 	bool save;
96 	bool load;
97 	struct {
98 		bool tsg;
99 		u32 id;
100 	} prev, next, *chan;
101 };
102 
103 int gk104_fifo_new_(const struct gk104_fifo_func *, struct nvkm_device *, enum nvkm_subdev_type,
104 		    int index, int nr, struct nvkm_fifo **);
105 void gk104_fifo_runlist_insert(struct gk104_fifo *, struct gk104_fifo_chan *);
106 void gk104_fifo_runlist_remove(struct gk104_fifo *, struct gk104_fifo_chan *);
107 void gk104_fifo_runlist_update(struct gk104_fifo *, int runl);
108 void gk104_fifo_engine_status(struct gk104_fifo *fifo, int engn,
109 			      struct gk104_fifo_engine_status *status);
110 void gk104_fifo_intr_bind(struct gk104_fifo *fifo);
111 void gk104_fifo_intr_chsw(struct gk104_fifo *fifo);
112 void gk104_fifo_intr_dropped_fault(struct gk104_fifo *fifo);
113 void gk104_fifo_intr_pbdma_0(struct gk104_fifo *fifo, int unit);
114 void gk104_fifo_intr_pbdma_1(struct gk104_fifo *fifo, int unit);
115 void gk104_fifo_intr_runlist(struct gk104_fifo *fifo);
116 void gk104_fifo_intr_engine(struct gk104_fifo *fifo);
117 void *gk104_fifo_dtor(struct nvkm_fifo *base);
118 int gk104_fifo_oneinit(struct nvkm_fifo *base);
119 int gk104_fifo_info(struct nvkm_fifo *base, u64 mthd, u64 *data);
120 void gk104_fifo_init(struct nvkm_fifo *base);
121 void gk104_fifo_fini(struct nvkm_fifo *base);
122 int gk104_fifo_class_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,
123 			 void *argv, u32 argc, struct nvkm_object **pobject);
124 int gk104_fifo_class_get(struct nvkm_fifo *base, int index,
125 			 struct nvkm_oclass *oclass);
126 void gk104_fifo_uevent_fini(struct nvkm_fifo *fifo);
127 void gk104_fifo_uevent_init(struct nvkm_fifo *fifo);
128 
129 extern const struct gk104_fifo_pbdma_func gk104_fifo_pbdma;
130 int gk104_fifo_pbdma_nr(struct gk104_fifo *);
131 void gk104_fifo_pbdma_init(struct gk104_fifo *);
132 extern const struct nvkm_enum gk104_fifo_fault_access[];
133 extern const struct nvkm_enum gk104_fifo_fault_engine[];
134 extern const struct nvkm_enum gk104_fifo_fault_reason[];
135 extern const struct nvkm_enum gk104_fifo_fault_hubclient[];
136 extern const struct nvkm_enum gk104_fifo_fault_gpcclient[];
137 extern const struct gk104_fifo_runlist_func gk104_fifo_runlist;
138 void gk104_fifo_runlist_chan(struct gk104_fifo_chan *,
139 			     struct nvkm_memory *, u32);
140 void gk104_fifo_runlist_commit(struct gk104_fifo *, int runl,
141 			       struct nvkm_memory *, int);
142 
143 extern const struct gk104_fifo_runlist_func gk110_fifo_runlist;
144 void gk110_fifo_runlist_cgrp(struct nvkm_fifo_cgrp *,
145 			     struct nvkm_memory *, u32);
146 
147 extern const struct gk104_fifo_pbdma_func gk208_fifo_pbdma;
148 void gk208_fifo_pbdma_init_timeout(struct gk104_fifo *);
149 
150 void gm107_fifo_intr_fault(struct nvkm_fifo *, int);
151 extern const struct nvkm_enum gm107_fifo_fault_engine[];
152 extern const struct gk104_fifo_runlist_func gm107_fifo_runlist;
153 
154 extern const struct gk104_fifo_pbdma_func gm200_fifo_pbdma;
155 int gm200_fifo_pbdma_nr(struct gk104_fifo *);
156 
157 void gp100_fifo_intr_fault(struct nvkm_fifo *, int);
158 extern const struct nvkm_enum gp100_fifo_fault_engine[];
159 
160 extern const struct nvkm_enum gv100_fifo_fault_access[];
161 extern const struct nvkm_enum gv100_fifo_fault_reason[];
162 extern const struct nvkm_enum gv100_fifo_fault_hubclient[];
163 extern const struct nvkm_enum gv100_fifo_fault_gpcclient[];
164 void gv100_fifo_runlist_cgrp(struct nvkm_fifo_cgrp *,
165 			     struct nvkm_memory *, u32);
166 void gv100_fifo_runlist_chan(struct gk104_fifo_chan *,
167 			     struct nvkm_memory *, u32);
168 #endif
169