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 struct nvkm_acr_lsfw;
35 
36 #define GPC_MAX 32
37 #define TPC_MAX_PER_GPC 8
38 #define TPC_MAX (GPC_MAX * TPC_MAX_PER_GPC)
39 
40 #define ROP_BCAST(r)      (0x408800 + (r))
41 #define ROP_UNIT(u, r)    (0x410000 + (u) * 0x400 + (r))
42 #define GPC_BCAST(r)      (0x418000 + (r))
43 #define GPC_UNIT(t, r)    (0x500000 + (t) * 0x8000 + (r))
44 #define PPC_UNIT(t, m, r) (0x503000 + (t) * 0x8000 + (m) * 0x200 + (r))
45 #define TPC_UNIT(t, m, r) (0x504000 + (t) * 0x8000 + (m) * 0x800 + (r))
46 
47 struct gf100_gr_zbc_color {
48 	u32 format;
49 	u32 ds[4];
50 	u32 l2[4];
51 };
52 
53 struct gf100_gr_zbc_depth {
54 	u32 format;
55 	u32 ds;
56 	u32 l2;
57 };
58 
59 struct gf100_gr_zbc_stencil {
60 	u32 format;
61 	u32 ds;
62 	u32 l2;
63 };
64 
65 struct gf100_gr {
66 	const struct gf100_gr_func *func;
67 	struct nvkm_gr base;
68 
69 	struct {
70 		struct nvkm_falcon falcon;
71 		struct nvkm_blob inst;
72 		struct nvkm_blob data;
73 
74 		struct mutex mutex;
75 		u32 disable;
76 	} fecs;
77 
78 	struct {
79 		struct nvkm_falcon falcon;
80 		struct nvkm_blob inst;
81 		struct nvkm_blob data;
82 	} gpccs;
83 
84 	bool firmware;
85 
86 	/*
87 	 * Used if the register packs are loaded from NVIDIA fw instead of
88 	 * using hardcoded arrays. To be allocated with vzalloc().
89 	 */
90 	struct gf100_gr_pack *sw_nonctx;
91 	struct gf100_gr_pack *sw_nonctx1;
92 	struct gf100_gr_pack *sw_nonctx2;
93 	struct gf100_gr_pack *sw_nonctx3;
94 	struct gf100_gr_pack *sw_nonctx4;
95 	struct gf100_gr_pack *sw_ctx;
96 	struct gf100_gr_pack *bundle;
97 	struct gf100_gr_pack *bundle_veid;
98 	struct gf100_gr_pack *bundle64;
99 	struct gf100_gr_pack *method;
100 
101 	struct gf100_gr_zbc_color zbc_color[NVKM_LTC_MAX_ZBC_COLOR_CNT];
102 	struct gf100_gr_zbc_depth zbc_depth[NVKM_LTC_MAX_ZBC_DEPTH_CNT];
103 	struct gf100_gr_zbc_stencil zbc_stencil[NVKM_LTC_MAX_ZBC_DEPTH_CNT];
104 
105 	u8 rop_nr;
106 	u8 gpc_nr;
107 	u8 tpc_nr[GPC_MAX];
108 	u8 tpc_max;
109 	u8 tpc_total;
110 	u8 ppc_nr[GPC_MAX];
111 	u8 ppc_mask[GPC_MAX];
112 	u8 ppc_tpc_mask[GPC_MAX][4];
113 	u8 ppc_tpc_nr[GPC_MAX][4];
114 	u8 ppc_tpc_min;
115 	u8 ppc_tpc_max;
116 	u8 ppc_total;
117 
118 	struct nvkm_memory *pagepool;
119 	struct nvkm_memory *bundle_cb;
120 	struct nvkm_memory *attrib_cb;
121 	struct nvkm_memory *unknown;
122 
123 	u8 screen_tile_row_offset;
124 	u8 tile[TPC_MAX];
125 
126 	struct {
127 		u8 gpc;
128 		u8 tpc;
129 	} sm[TPC_MAX];
130 	u8 sm_nr;
131 
132 	u32  size;
133 	u32 *data;
134 	u32 size_zcull;
135 	u32 size_pm;
136 };
137 
138 int gf100_gr_fecs_bind_pointer(struct gf100_gr *, u32 inst);
139 int gf100_gr_fecs_wfi_golden_save(struct gf100_gr *, u32 inst);
140 
141 struct gf100_gr_func_zbc {
142 	void (*clear_color)(struct gf100_gr *, int zbc);
143 	void (*clear_depth)(struct gf100_gr *, int zbc);
144 	int (*stencil_get)(struct gf100_gr *, int format,
145 			   const u32 ds, const u32 l2);
146 	void (*clear_stencil)(struct gf100_gr *, int zbc);
147 };
148 
149 struct gf100_gr_func {
150 	struct nvkm_intr *(*oneinit_intr)(struct gf100_gr *, enum nvkm_intr_type *);
151 	void (*oneinit_tiles)(struct gf100_gr *);
152 	int (*oneinit_sm_id)(struct gf100_gr *);
153 	int (*init)(struct gf100_gr *);
154 	void (*init_419bd8)(struct gf100_gr *);
155 	void (*init_gpc_mmu)(struct gf100_gr *);
156 	void (*init_r405a14)(struct gf100_gr *);
157 	void (*init_bios)(struct gf100_gr *);
158 	void (*init_vsc_stream_master)(struct gf100_gr *);
159 	void (*init_zcull)(struct gf100_gr *);
160 	void (*init_num_active_ltcs)(struct gf100_gr *);
161 	void (*init_rop_active_fbps)(struct gf100_gr *);
162 	void (*init_bios_2)(struct gf100_gr *);
163 	void (*init_swdx_pes_mask)(struct gf100_gr *);
164 	void (*init_fs)(struct gf100_gr *);
165 	void (*init_fecs_exceptions)(struct gf100_gr *);
166 	void (*init_40a790)(struct gf100_gr *);
167 	void (*init_ds_hww_esr_2)(struct gf100_gr *);
168 	void (*init_40601c)(struct gf100_gr *);
169 	void (*init_sked_hww_esr)(struct gf100_gr *);
170 	void (*init_419cc0)(struct gf100_gr *);
171 	void (*init_419eb4)(struct gf100_gr *);
172 	void (*init_419c9c)(struct gf100_gr *);
173 	void (*init_ppc_exceptions)(struct gf100_gr *);
174 	void (*init_tex_hww_esr)(struct gf100_gr *, int gpc, int tpc);
175 	void (*init_504430)(struct gf100_gr *, int gpc, int tpc);
176 	void (*init_shader_exceptions)(struct gf100_gr *, int gpc, int tpc);
177 	void (*init_rop_exceptions)(struct gf100_gr *);
178 	void (*init_exception2)(struct gf100_gr *);
179 	void (*init_400054)(struct gf100_gr *);
180 	void (*init_4188a4)(struct gf100_gr *);
181 	void (*trap_mp)(struct gf100_gr *, int gpc, int tpc);
182 	void (*set_hww_esr_report_mask)(struct gf100_gr *);
183 	const struct gf100_gr_pack *mmio;
184 	struct {
185 		struct gf100_gr_ucode *ucode;
186 		void (*reset)(struct gf100_gr *);
187 	} fecs;
188 	struct {
189 		struct gf100_gr_ucode *ucode;
190 		void (*reset)(struct gf100_gr *);
191 	} gpccs;
192 	int (*rops)(struct gf100_gr *);
193 	int gpc_nr;
194 	int tpc_nr;
195 	int ppc_nr;
196 	const struct gf100_grctx_func *grctx;
197 	const struct nvkm_therm_clkgate_pack *clkgate_pack;
198 	const struct gf100_gr_func_zbc *zbc;
199 	struct nvkm_sclass sclass[];
200 };
201 
202 int gf100_gr_rops(struct gf100_gr *);
203 void gf100_gr_oneinit_tiles(struct gf100_gr *);
204 int gf100_gr_oneinit_sm_id(struct gf100_gr *);
205 int gf100_gr_init(struct gf100_gr *);
206 void gf100_gr_init_vsc_stream_master(struct gf100_gr *);
207 void gf100_gr_init_zcull(struct gf100_gr *);
208 void gf100_gr_init_num_active_ltcs(struct gf100_gr *);
209 void gf100_gr_init_fecs_exceptions(struct gf100_gr *);
210 void gf100_gr_init_40601c(struct gf100_gr *);
211 void gf100_gr_init_419cc0(struct gf100_gr *);
212 void gf100_gr_init_419eb4(struct gf100_gr *);
213 void gf100_gr_init_tex_hww_esr(struct gf100_gr *, int, int);
214 void gf100_gr_init_shader_exceptions(struct gf100_gr *, int, int);
215 void gf100_gr_init_rop_exceptions(struct gf100_gr *);
216 void gf100_gr_init_exception2(struct gf100_gr *);
217 void gf100_gr_init_400054(struct gf100_gr *);
218 void gf100_gr_init_num_tpc_per_gpc(struct gf100_gr *, bool, bool);
219 extern const struct gf100_gr_func_zbc gf100_gr_zbc;
220 void gf100_gr_fecs_reset(struct gf100_gr *);
221 
222 void gf117_gr_init_zcull(struct gf100_gr *);
223 
224 void gk104_gr_init_vsc_stream_master(struct gf100_gr *);
225 void gk104_gr_init_rop_active_fbps(struct gf100_gr *);
226 void gk104_gr_init_ppc_exceptions(struct gf100_gr *);
227 void gk104_gr_init_sked_hww_esr(struct gf100_gr *);
228 
229 void gk110_gr_init_419eb4(struct gf100_gr *);
230 
231 void gm107_gr_init_504430(struct gf100_gr *, int, int);
232 void gm107_gr_init_shader_exceptions(struct gf100_gr *, int, int);
233 void gm107_gr_init_400054(struct gf100_gr *);
234 
235 int gk20a_gr_init(struct gf100_gr *);
236 int gk20a_gr_av_to_init_(struct nvkm_blob *, u8 count, u32 pitch, struct gf100_gr_pack **);
237 int gk20a_gr_av_to_init(struct nvkm_blob *, struct gf100_gr_pack **);
238 int gk20a_gr_aiv_to_init(struct nvkm_blob *, struct gf100_gr_pack **);
239 int gk20a_gr_av_to_method(struct nvkm_blob *, struct gf100_gr_pack **);
240 
241 void gm200_gr_oneinit_tiles(struct gf100_gr *);
242 int gm200_gr_oneinit_sm_id(struct gf100_gr *);
243 int gm200_gr_rops(struct gf100_gr *);
244 void gm200_gr_init_num_active_ltcs(struct gf100_gr *);
245 void gm200_gr_init_ds_hww_esr_2(struct gf100_gr *);
246 
247 void gp100_gr_init_rop_active_fbps(struct gf100_gr *);
248 void gp100_gr_init_fecs_exceptions(struct gf100_gr *);
249 void gp100_gr_init_shader_exceptions(struct gf100_gr *, int, int);
250 void gp100_gr_zbc_clear_color(struct gf100_gr *, int);
251 void gp100_gr_zbc_clear_depth(struct gf100_gr *, int);
252 extern const struct gf100_gr_func_zbc gp100_gr_zbc;
253 
254 void gp102_gr_init_swdx_pes_mask(struct gf100_gr *);
255 extern const struct gf100_gr_func_zbc gp102_gr_zbc;
256 int gp102_gr_zbc_stencil_get(struct gf100_gr *, int, const u32, const u32);
257 void gp102_gr_zbc_clear_stencil(struct gf100_gr *, int);
258 
259 extern const struct gf100_gr_func gp107_gr;
260 
261 int gv100_gr_oneinit_sm_id(struct gf100_gr *);
262 u32 gv100_gr_nonpes_aware_tpc(struct gf100_gr *gr, u32 gpc, u32 tpc);
263 void gv100_gr_init_419bd8(struct gf100_gr *);
264 void gv100_gr_init_504430(struct gf100_gr *, int, int);
265 void gv100_gr_init_shader_exceptions(struct gf100_gr *, int, int);
266 void gv100_gr_init_4188a4(struct gf100_gr *);
267 void gv100_gr_trap_mp(struct gf100_gr *, int, int);
268 
269 int tu102_gr_av_to_init_veid(struct nvkm_blob *, struct gf100_gr_pack **);
270 void tu102_gr_init_zcull(struct gf100_gr *);
271 void tu102_gr_init_fs(struct gf100_gr *);
272 void tu102_gr_init_fecs_exceptions(struct gf100_gr *);
273 
274 #define gf100_gr_chan(p) container_of((p), struct gf100_gr_chan, object)
275 #include <core/object.h>
276 
277 struct gf100_gr_chan {
278 	struct nvkm_object object;
279 	struct gf100_gr *gr;
280 	struct nvkm_vmm *vmm;
281 
282 	struct nvkm_vma *pagepool;
283 	struct nvkm_vma *bundle_cb;
284 	struct nvkm_vma *attrib_cb;
285 	struct nvkm_vma *unknown;
286 
287 	struct nvkm_memory *mmio;
288 	struct nvkm_vma *mmio_vma;
289 	int mmio_nr;
290 };
291 
292 void gf100_gr_ctxctl_debug(struct gf100_gr *);
293 
294 u64  gf100_gr_units(struct nvkm_gr *);
295 void gf100_gr_zbc_init(struct gf100_gr *);
296 
297 extern const struct nvkm_object_func gf100_fermi;
298 
299 struct gf100_gr_init {
300 	u32 addr;
301 	u8  count;
302 	u32 pitch;
303 	u64 data;
304 };
305 
306 struct gf100_gr_pack {
307 	const struct gf100_gr_init *init;
308 	u32 type;
309 };
310 
311 #define pack_for_each_init(init, pack, head)                                   \
312 	for (pack = head; pack && pack->init; pack++)                          \
313 		  for (init = pack->init; init && init->count; init++)
314 
315 struct gf100_gr_ucode {
316 	struct nvkm_blob code;
317 	struct nvkm_blob data;
318 };
319 
320 extern struct gf100_gr_ucode gf100_gr_fecs_ucode;
321 extern struct gf100_gr_ucode gf100_gr_gpccs_ucode;
322 
323 extern struct gf100_gr_ucode gk110_gr_fecs_ucode;
324 extern struct gf100_gr_ucode gk110_gr_gpccs_ucode;
325 
326 int  gf100_gr_wait_idle(struct gf100_gr *);
327 void gf100_gr_mmio(struct gf100_gr *, const struct gf100_gr_pack *);
328 void gf100_gr_icmd(struct gf100_gr *, const struct gf100_gr_pack *);
329 void gf100_gr_mthd(struct gf100_gr *, const struct gf100_gr_pack *);
330 int  gf100_gr_init_ctxctl(struct gf100_gr *);
331 
332 /* register init value lists */
333 
334 extern const struct gf100_gr_init gf100_gr_init_main_0[];
335 extern const struct gf100_gr_init gf100_gr_init_fe_0[];
336 extern const struct gf100_gr_init gf100_gr_init_pri_0[];
337 extern const struct gf100_gr_init gf100_gr_init_rstr2d_0[];
338 extern const struct gf100_gr_init gf100_gr_init_pd_0[];
339 extern const struct gf100_gr_init gf100_gr_init_ds_0[];
340 extern const struct gf100_gr_init gf100_gr_init_scc_0[];
341 extern const struct gf100_gr_init gf100_gr_init_prop_0[];
342 extern const struct gf100_gr_init gf100_gr_init_gpc_unk_0[];
343 extern const struct gf100_gr_init gf100_gr_init_setup_0[];
344 extern const struct gf100_gr_init gf100_gr_init_crstr_0[];
345 extern const struct gf100_gr_init gf100_gr_init_setup_1[];
346 extern const struct gf100_gr_init gf100_gr_init_zcull_0[];
347 extern const struct gf100_gr_init gf100_gr_init_gpm_0[];
348 extern const struct gf100_gr_init gf100_gr_init_gpc_unk_1[];
349 extern const struct gf100_gr_init gf100_gr_init_gcc_0[];
350 extern const struct gf100_gr_init gf100_gr_init_tpccs_0[];
351 extern const struct gf100_gr_init gf100_gr_init_tex_0[];
352 extern const struct gf100_gr_init gf100_gr_init_pe_0[];
353 extern const struct gf100_gr_init gf100_gr_init_l1c_0[];
354 extern const struct gf100_gr_init gf100_gr_init_wwdx_0[];
355 extern const struct gf100_gr_init gf100_gr_init_tpccs_1[];
356 extern const struct gf100_gr_init gf100_gr_init_mpc_0[];
357 extern const struct gf100_gr_init gf100_gr_init_be_0[];
358 extern const struct gf100_gr_init gf100_gr_init_fe_1[];
359 extern const struct gf100_gr_init gf100_gr_init_pe_1[];
360 void gf100_gr_init_gpc_mmu(struct gf100_gr *);
361 void gf100_gr_trap_mp(struct gf100_gr *, int, int);
362 extern const struct nvkm_bitfield gf100_mp_global_error[];
363 extern const struct nvkm_enum gf100_mp_warp_error[];
364 
365 extern const struct gf100_gr_init gf104_gr_init_ds_0[];
366 extern const struct gf100_gr_init gf104_gr_init_tex_0[];
367 extern const struct gf100_gr_init gf104_gr_init_sm_0[];
368 
369 extern const struct gf100_gr_init gf108_gr_init_gpc_unk_0[];
370 extern const struct gf100_gr_init gf108_gr_init_setup_1[];
371 
372 extern const struct gf100_gr_init gf119_gr_init_pd_0[];
373 extern const struct gf100_gr_init gf119_gr_init_ds_0[];
374 extern const struct gf100_gr_init gf119_gr_init_prop_0[];
375 extern const struct gf100_gr_init gf119_gr_init_gpm_0[];
376 extern const struct gf100_gr_init gf119_gr_init_gpc_unk_1[];
377 extern const struct gf100_gr_init gf119_gr_init_tex_0[];
378 extern const struct gf100_gr_init gf119_gr_init_sm_0[];
379 extern const struct gf100_gr_init gf119_gr_init_fe_1[];
380 
381 extern const struct gf100_gr_init gf117_gr_init_pes_0[];
382 extern const struct gf100_gr_init gf117_gr_init_wwdx_0[];
383 extern const struct gf100_gr_init gf117_gr_init_cbm_0[];
384 
385 extern const struct gf100_gr_init gk104_gr_init_main_0[];
386 extern const struct gf100_gr_init gk104_gr_init_gpc_unk_2[];
387 extern const struct gf100_gr_init gk104_gr_init_tpccs_0[];
388 extern const struct gf100_gr_init gk104_gr_init_pe_0[];
389 extern const struct gf100_gr_init gk104_gr_init_be_0[];
390 extern const struct gf100_gr_pack gk104_gr_pack_mmio[];
391 
392 extern const struct gf100_gr_init gk110_gr_init_fe_0[];
393 extern const struct gf100_gr_init gk110_gr_init_ds_0[];
394 extern const struct gf100_gr_init gk110_gr_init_sked_0[];
395 extern const struct gf100_gr_init gk110_gr_init_cwd_0[];
396 extern const struct gf100_gr_init gk110_gr_init_gpc_unk_1[];
397 extern const struct gf100_gr_init gk110_gr_init_tex_0[];
398 extern const struct gf100_gr_init gk110_gr_init_sm_0[];
399 
400 extern const struct gf100_gr_init gk208_gr_init_gpc_unk_0[];
401 
402 extern const struct gf100_gr_init gm107_gr_init_scc_0[];
403 extern const struct gf100_gr_init gm107_gr_init_prop_0[];
404 extern const struct gf100_gr_init gm107_gr_init_setup_1[];
405 extern const struct gf100_gr_init gm107_gr_init_zcull_0[];
406 extern const struct gf100_gr_init gm107_gr_init_gpc_unk_1[];
407 extern const struct gf100_gr_init gm107_gr_init_tex_0[];
408 extern const struct gf100_gr_init gm107_gr_init_l1c_0[];
409 extern const struct gf100_gr_init gm107_gr_init_wwdx_0[];
410 extern const struct gf100_gr_init gm107_gr_init_cbm_0[];
411 void gm107_gr_init_bios(struct gf100_gr *);
412 
413 void gm200_gr_init_gpc_mmu(struct gf100_gr *);
414 
415 struct gf100_gr_fwif {
416 	int version;
417 	int (*load)(struct gf100_gr *, int ver, const struct gf100_gr_fwif *);
418 	const struct gf100_gr_func *func;
419 	const struct nvkm_acr_lsf_func *fecs;
420 	const struct nvkm_acr_lsf_func *gpccs;
421 };
422 
423 int gf100_gr_load(struct gf100_gr *, int, const struct gf100_gr_fwif *);
424 int gf100_gr_nofw(struct gf100_gr *, int, const struct gf100_gr_fwif *);
425 
426 int gk20a_gr_load_sw(struct gf100_gr *, const char *path, int ver);
427 int gk20a_gr_load_net(struct gf100_gr *, const char *, const char *, int,
428 		      int (*)(struct nvkm_blob *, struct gf100_gr_pack **),
429 		      struct gf100_gr_pack **);
430 
431 int gm200_gr_nofw(struct gf100_gr *, int, const struct gf100_gr_fwif *);
432 int gm200_gr_load(struct gf100_gr *, int, const struct gf100_gr_fwif *);
433 extern const struct nvkm_acr_lsf_func gm200_gr_gpccs_acr;
434 extern const struct nvkm_acr_lsf_func gm200_gr_fecs_acr;
435 
436 extern const struct nvkm_acr_lsf_func gm20b_gr_fecs_acr;
437 void gm20b_gr_acr_bld_write(struct nvkm_acr *, u32, struct nvkm_acr_lsfw *);
438 void gm20b_gr_acr_bld_patch(struct nvkm_acr *, u32, s64);
439 
440 extern const struct nvkm_acr_lsf_func gp108_gr_gpccs_acr;
441 extern const struct nvkm_acr_lsf_func gp108_gr_fecs_acr;
442 void gp108_gr_acr_bld_write(struct nvkm_acr *, u32, struct nvkm_acr_lsfw *);
443 void gp108_gr_acr_bld_patch(struct nvkm_acr *, u32, s64);
444 
445 int gf100_gr_new_(const struct gf100_gr_fwif *, struct nvkm_device *, enum nvkm_subdev_type, int,
446 		  struct nvkm_gr **);
447 #endif
448