1 /*
2  * Copyright 2010 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24 #ifndef __GF100_GR_H__
25 #define __GF100_GR_H__
26 #define gf100_gr(p) container_of((p), struct gf100_gr, base)
27 #include "priv.h"
28 
29 #include <core/gpuobj.h>
30 #include <subdev/ltc.h>
31 #include <subdev/mmu.h>
32 #include <engine/falcon.h>
33 
34 #define GPC_MAX 32
35 #define TPC_MAX_PER_GPC 8
36 #define TPC_MAX (GPC_MAX * TPC_MAX_PER_GPC)
37 
38 #define ROP_BCAST(r)      (0x408800 + (r))
39 #define ROP_UNIT(u, r)    (0x410000 + (u) * 0x400 + (r))
40 #define GPC_BCAST(r)      (0x418000 + (r))
41 #define GPC_UNIT(t, r)    (0x500000 + (t) * 0x8000 + (r))
42 #define PPC_UNIT(t, m, r) (0x503000 + (t) * 0x8000 + (m) * 0x200 + (r))
43 #define TPC_UNIT(t, m, r) (0x504000 + (t) * 0x8000 + (m) * 0x800 + (r))
44 
45 struct gf100_gr_data {
46 	u32 size;
47 	u32 align;
48 	u32 access;
49 };
50 
51 struct gf100_gr_mmio {
52 	u32 addr;
53 	u32 data;
54 	u32 shift;
55 	int buffer;
56 };
57 
58 struct gf100_gr_fuc {
59 	u32 *data;
60 	u32  size;
61 };
62 
63 struct gf100_gr_zbc_color {
64 	u32 format;
65 	u32 ds[4];
66 	u32 l2[4];
67 };
68 
69 struct gf100_gr_zbc_depth {
70 	u32 format;
71 	u32 ds;
72 	u32 l2;
73 };
74 
75 struct gf100_gr {
76 	const struct gf100_gr_func *func;
77 	struct nvkm_gr base;
78 
79 	struct nvkm_falcon *fecs;
80 	struct nvkm_falcon *gpccs;
81 	struct gf100_gr_fuc fuc409c;
82 	struct gf100_gr_fuc fuc409d;
83 	struct gf100_gr_fuc fuc41ac;
84 	struct gf100_gr_fuc fuc41ad;
85 	bool firmware;
86 
87 	/*
88 	 * Used if the register packs are loaded from NVIDIA fw instead of
89 	 * using hardcoded arrays. To be allocated with vzalloc().
90 	 */
91 	struct gf100_gr_pack *fuc_sw_nonctx;
92 	struct gf100_gr_pack *fuc_sw_ctx;
93 	struct gf100_gr_pack *fuc_bundle;
94 	struct gf100_gr_pack *fuc_method;
95 
96 	struct gf100_gr_zbc_color zbc_color[NVKM_LTC_MAX_ZBC_CNT];
97 	struct gf100_gr_zbc_depth zbc_depth[NVKM_LTC_MAX_ZBC_CNT];
98 
99 	u8 rop_nr;
100 	u8 gpc_nr;
101 	u8 tpc_nr[GPC_MAX];
102 	u8 tpc_total;
103 	u8 ppc_nr[GPC_MAX];
104 	u8 ppc_mask[GPC_MAX];
105 	u8 ppc_tpc_nr[GPC_MAX][4];
106 
107 	struct gf100_gr_data mmio_data[4];
108 	struct gf100_gr_mmio mmio_list[4096/8];
109 	u32  size;
110 	u32 *data;
111 
112 	u8 screen_tile_row_offset;
113 };
114 
115 int gf100_gr_ctor(const struct gf100_gr_func *, struct nvkm_device *,
116 		  int, struct gf100_gr *);
117 int gf100_gr_new_(const struct gf100_gr_func *, struct nvkm_device *,
118 		  int, struct nvkm_gr **);
119 void *gf100_gr_dtor(struct nvkm_gr *);
120 
121 struct gf100_gr_func {
122 	void (*dtor)(struct gf100_gr *);
123 	int (*init)(struct gf100_gr *);
124 	void (*init_gpc_mmu)(struct gf100_gr *);
125 	void (*init_rop_active_fbps)(struct gf100_gr *);
126 	void (*init_ppc_exceptions)(struct gf100_gr *);
127 	void (*init_swdx_pes_mask)(struct gf100_gr *);
128 	void (*set_hww_esr_report_mask)(struct gf100_gr *);
129 	const struct gf100_gr_pack *mmio;
130 	struct {
131 		struct gf100_gr_ucode *ucode;
132 	} fecs;
133 	struct {
134 		struct gf100_gr_ucode *ucode;
135 	} gpccs;
136 	int (*rops)(struct gf100_gr *);
137 	int ppc_nr;
138 	const struct gf100_grctx_func *grctx;
139 	struct nvkm_sclass sclass[];
140 };
141 
142 int gf100_gr_init(struct gf100_gr *);
143 int gf100_gr_rops(struct gf100_gr *);
144 
145 int gk104_gr_init(struct gf100_gr *);
146 void gk104_gr_init_rop_active_fbps(struct gf100_gr *);
147 void gk104_gr_init_ppc_exceptions(struct gf100_gr *);
148 
149 int gk20a_gr_init(struct gf100_gr *);
150 
151 int gm200_gr_init(struct gf100_gr *);
152 int gm200_gr_rops(struct gf100_gr *);
153 
154 int gp100_gr_init(struct gf100_gr *);
155 void gp100_gr_init_rop_active_fbps(struct gf100_gr *);
156 
157 #define gf100_gr_chan(p) container_of((p), struct gf100_gr_chan, object)
158 
159 struct gf100_gr_chan {
160 	struct nvkm_object object;
161 	struct gf100_gr *gr;
162 
163 	struct nvkm_memory *mmio;
164 	struct nvkm_vma mmio_vma;
165 	int mmio_nr;
166 
167 	struct {
168 		struct nvkm_memory *mem;
169 		struct nvkm_vma vma;
170 	} data[4];
171 };
172 
173 void gf100_gr_ctxctl_debug(struct gf100_gr *);
174 
175 void gf100_gr_dtor_fw(struct gf100_gr_fuc *);
176 int  gf100_gr_ctor_fw(struct gf100_gr *, const char *,
177 		      struct gf100_gr_fuc *);
178 u64  gf100_gr_units(struct nvkm_gr *);
179 void gf100_gr_zbc_init(struct gf100_gr *);
180 
181 extern const struct nvkm_object_func gf100_fermi;
182 
183 struct gf100_gr_init {
184 	u32 addr;
185 	u8  count;
186 	u8  pitch;
187 	u32 data;
188 };
189 
190 struct gf100_gr_pack {
191 	const struct gf100_gr_init *init;
192 	u32 type;
193 };
194 
195 #define pack_for_each_init(init, pack, head)                                   \
196 	for (pack = head; pack && pack->init; pack++)                          \
197 		  for (init = pack->init; init && init->count; init++)
198 
199 struct gf100_gr_ucode {
200 	struct gf100_gr_fuc code;
201 	struct gf100_gr_fuc data;
202 };
203 
204 extern struct gf100_gr_ucode gf100_gr_fecs_ucode;
205 extern struct gf100_gr_ucode gf100_gr_gpccs_ucode;
206 
207 extern struct gf100_gr_ucode gk110_gr_fecs_ucode;
208 extern struct gf100_gr_ucode gk110_gr_gpccs_ucode;
209 
210 int  gf100_gr_wait_idle(struct gf100_gr *);
211 void gf100_gr_mmio(struct gf100_gr *, const struct gf100_gr_pack *);
212 void gf100_gr_icmd(struct gf100_gr *, const struct gf100_gr_pack *);
213 void gf100_gr_mthd(struct gf100_gr *, const struct gf100_gr_pack *);
214 int  gf100_gr_init_ctxctl(struct gf100_gr *);
215 
216 /* external bundles loading functions */
217 int gk20a_gr_av_to_init(struct gf100_gr *, const char *,
218 			struct gf100_gr_pack **);
219 int gk20a_gr_aiv_to_init(struct gf100_gr *, const char *,
220 			 struct gf100_gr_pack **);
221 int gk20a_gr_av_to_method(struct gf100_gr *, const char *,
222 			  struct gf100_gr_pack **);
223 
224 int gm200_gr_new_(const struct gf100_gr_func *, struct nvkm_device *, int,
225 		  struct nvkm_gr **);
226 
227 /* register init value lists */
228 
229 extern const struct gf100_gr_init gf100_gr_init_main_0[];
230 extern const struct gf100_gr_init gf100_gr_init_fe_0[];
231 extern const struct gf100_gr_init gf100_gr_init_pri_0[];
232 extern const struct gf100_gr_init gf100_gr_init_rstr2d_0[];
233 extern const struct gf100_gr_init gf100_gr_init_pd_0[];
234 extern const struct gf100_gr_init gf100_gr_init_ds_0[];
235 extern const struct gf100_gr_init gf100_gr_init_scc_0[];
236 extern const struct gf100_gr_init gf100_gr_init_prop_0[];
237 extern const struct gf100_gr_init gf100_gr_init_gpc_unk_0[];
238 extern const struct gf100_gr_init gf100_gr_init_setup_0[];
239 extern const struct gf100_gr_init gf100_gr_init_crstr_0[];
240 extern const struct gf100_gr_init gf100_gr_init_setup_1[];
241 extern const struct gf100_gr_init gf100_gr_init_zcull_0[];
242 extern const struct gf100_gr_init gf100_gr_init_gpm_0[];
243 extern const struct gf100_gr_init gf100_gr_init_gpc_unk_1[];
244 extern const struct gf100_gr_init gf100_gr_init_gcc_0[];
245 extern const struct gf100_gr_init gf100_gr_init_tpccs_0[];
246 extern const struct gf100_gr_init gf100_gr_init_tex_0[];
247 extern const struct gf100_gr_init gf100_gr_init_pe_0[];
248 extern const struct gf100_gr_init gf100_gr_init_l1c_0[];
249 extern const struct gf100_gr_init gf100_gr_init_wwdx_0[];
250 extern const struct gf100_gr_init gf100_gr_init_tpccs_1[];
251 extern const struct gf100_gr_init gf100_gr_init_mpc_0[];
252 extern const struct gf100_gr_init gf100_gr_init_be_0[];
253 extern const struct gf100_gr_init gf100_gr_init_fe_1[];
254 extern const struct gf100_gr_init gf100_gr_init_pe_1[];
255 
256 extern const struct gf100_gr_init gf104_gr_init_ds_0[];
257 extern const struct gf100_gr_init gf104_gr_init_tex_0[];
258 extern const struct gf100_gr_init gf104_gr_init_sm_0[];
259 
260 extern const struct gf100_gr_init gf108_gr_init_gpc_unk_0[];
261 extern const struct gf100_gr_init gf108_gr_init_setup_1[];
262 
263 extern const struct gf100_gr_init gf119_gr_init_pd_0[];
264 extern const struct gf100_gr_init gf119_gr_init_ds_0[];
265 extern const struct gf100_gr_init gf119_gr_init_prop_0[];
266 extern const struct gf100_gr_init gf119_gr_init_gpm_0[];
267 extern const struct gf100_gr_init gf119_gr_init_gpc_unk_1[];
268 extern const struct gf100_gr_init gf119_gr_init_tex_0[];
269 extern const struct gf100_gr_init gf119_gr_init_sm_0[];
270 extern const struct gf100_gr_init gf119_gr_init_fe_1[];
271 
272 extern const struct gf100_gr_init gf117_gr_init_pes_0[];
273 extern const struct gf100_gr_init gf117_gr_init_wwdx_0[];
274 extern const struct gf100_gr_init gf117_gr_init_cbm_0[];
275 
276 extern const struct gf100_gr_init gk104_gr_init_main_0[];
277 extern const struct gf100_gr_init gk104_gr_init_tpccs_0[];
278 extern const struct gf100_gr_init gk104_gr_init_pe_0[];
279 extern const struct gf100_gr_init gk104_gr_init_be_0[];
280 extern const struct gf100_gr_pack gk104_gr_pack_mmio[];
281 
282 extern const struct gf100_gr_init gk110_gr_init_fe_0[];
283 extern const struct gf100_gr_init gk110_gr_init_ds_0[];
284 extern const struct gf100_gr_init gk110_gr_init_sked_0[];
285 extern const struct gf100_gr_init gk110_gr_init_cwd_0[];
286 extern const struct gf100_gr_init gk110_gr_init_gpc_unk_1[];
287 extern const struct gf100_gr_init gk110_gr_init_tex_0[];
288 extern const struct gf100_gr_init gk110_gr_init_sm_0[];
289 
290 extern const struct gf100_gr_init gk208_gr_init_gpc_unk_0[];
291 
292 extern const struct gf100_gr_init gm107_gr_init_scc_0[];
293 extern const struct gf100_gr_init gm107_gr_init_prop_0[];
294 extern const struct gf100_gr_init gm107_gr_init_setup_1[];
295 extern const struct gf100_gr_init gm107_gr_init_zcull_0[];
296 extern const struct gf100_gr_init gm107_gr_init_gpc_unk_1[];
297 extern const struct gf100_gr_init gm107_gr_init_tex_0[];
298 extern const struct gf100_gr_init gm107_gr_init_l1c_0[];
299 extern const struct gf100_gr_init gm107_gr_init_wwdx_0[];
300 extern const struct gf100_gr_init gm107_gr_init_cbm_0[];
301 void gm107_gr_init_bios(struct gf100_gr *);
302 
303 void gm200_gr_init_gpc_mmu(struct gf100_gr *);
304 #endif
305