Home | History | Annotate | Line # | Download | only in gr
      1 /*	$NetBSD: gf100.h,v 1.3 2021/12/18 23:45:36 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2010 Red Hat Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in
     14  * all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  * OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  * Authors: Ben Skeggs
     25  */
     26 #ifndef __GF100_GR_H__
     27 #define __GF100_GR_H__
     28 #define gf100_gr(p) container_of((p), struct gf100_gr, base)
     29 #include "priv.h"
     30 
     31 #include <core/gpuobj.h>
     32 #include <subdev/ltc.h>
     33 #include <subdev/mmu.h>
     34 #include <engine/falcon.h>
     35 
     36 struct nvkm_acr_lsfw;
     37 
     38 #define GPC_MAX 32
     39 #define TPC_MAX_PER_GPC 8
     40 #define TPC_MAX (GPC_MAX * TPC_MAX_PER_GPC)
     41 
     42 #define ROP_BCAST(r)      (0x408800 + (r))
     43 #define ROP_UNIT(u, r)    (0x410000 + (u) * 0x400 + (r))
     44 #define GPC_BCAST(r)      (0x418000 + (r))
     45 #define GPC_UNIT(t, r)    (0x500000 + (t) * 0x8000 + (r))
     46 #define PPC_UNIT(t, m, r) (0x503000 + (t) * 0x8000 + (m) * 0x200 + (r))
     47 #define TPC_UNIT(t, m, r) (0x504000 + (t) * 0x8000 + (m) * 0x800 + (r))
     48 
     49 struct gf100_gr_data {
     50 	u32 size;
     51 	u32 align;
     52 	bool priv;
     53 };
     54 
     55 struct gf100_gr_mmio {
     56 	u32 addr;
     57 	u32 data;
     58 	u32 shift;
     59 	int buffer;
     60 };
     61 
     62 struct gf100_gr_zbc_color {
     63 	u32 format;
     64 	u32 ds[4];
     65 	u32 l2[4];
     66 };
     67 
     68 struct gf100_gr_zbc_depth {
     69 	u32 format;
     70 	u32 ds;
     71 	u32 l2;
     72 };
     73 
     74 struct gf100_gr_zbc_stencil {
     75 	u32 format;
     76 	u32 ds;
     77 	u32 l2;
     78 };
     79 
     80 struct gf100_gr {
     81 	const struct gf100_gr_func *func;
     82 	struct nvkm_gr base;
     83 
     84 	struct {
     85 		struct nvkm_falcon falcon;
     86 		struct nvkm_blob inst;
     87 		struct nvkm_blob data;
     88 
     89 		struct mutex mutex;
     90 		u32 disable;
     91 	} fecs;
     92 
     93 	struct {
     94 		struct nvkm_falcon falcon;
     95 		struct nvkm_blob inst;
     96 		struct nvkm_blob data;
     97 	} gpccs;
     98 
     99 	bool firmware;
    100 
    101 	/*
    102 	 * Used if the register packs are loaded from NVIDIA fw instead of
    103 	 * using hardcoded arrays. To be allocated with vzalloc().
    104 	 */
    105 	struct gf100_gr_pack *sw_nonctx;
    106 	struct gf100_gr_pack *sw_ctx;
    107 	struct gf100_gr_pack *bundle;
    108 	struct gf100_gr_pack *method;
    109 
    110 	struct gf100_gr_zbc_color zbc_color[NVKM_LTC_MAX_ZBC_CNT];
    111 	struct gf100_gr_zbc_depth zbc_depth[NVKM_LTC_MAX_ZBC_CNT];
    112 	struct gf100_gr_zbc_stencil zbc_stencil[NVKM_LTC_MAX_ZBC_CNT];
    113 
    114 	u8 rop_nr;
    115 	u8 gpc_nr;
    116 	u8 tpc_nr[GPC_MAX];
    117 	u8 tpc_max;
    118 	u8 tpc_total;
    119 	u8 ppc_nr[GPC_MAX];
    120 	u8 ppc_mask[GPC_MAX];
    121 	u8 ppc_tpc_mask[GPC_MAX][4];
    122 	u8 ppc_tpc_nr[GPC_MAX][4];
    123 	u8 ppc_tpc_min;
    124 	u8 ppc_tpc_max;
    125 
    126 	u8 screen_tile_row_offset;
    127 	u8 tile[TPC_MAX];
    128 
    129 	struct {
    130 		u8 gpc;
    131 		u8 tpc;
    132 	} sm[TPC_MAX];
    133 	u8 sm_nr;
    134 
    135 	struct gf100_gr_data mmio_data[4];
    136 	struct gf100_gr_mmio mmio_list[4096/8];
    137 	u32  size;
    138 	u32 *data;
    139 	u32 size_zcull;
    140 	u32 size_pm;
    141 };
    142 
    143 int gf100_gr_fecs_bind_pointer(struct gf100_gr *, u32 inst);
    144 
    145 struct gf100_gr_func_zbc {
    146 	void (*clear_color)(struct gf100_gr *, int zbc);
    147 	void (*clear_depth)(struct gf100_gr *, int zbc);
    148 	int (*stencil_get)(struct gf100_gr *, int format,
    149 			   const u32 ds, const u32 l2);
    150 	void (*clear_stencil)(struct gf100_gr *, int zbc);
    151 };
    152 
    153 struct gf100_gr_func {
    154 	void (*oneinit_tiles)(struct gf100_gr *);
    155 	void (*oneinit_sm_id)(struct gf100_gr *);
    156 	int (*init)(struct gf100_gr *);
    157 	void (*init_419bd8)(struct gf100_gr *);
    158 	void (*init_gpc_mmu)(struct gf100_gr *);
    159 	void (*init_r405a14)(struct gf100_gr *);
    160 	void (*init_bios)(struct gf100_gr *);
    161 	void (*init_vsc_stream_master)(struct gf100_gr *);
    162 	void (*init_zcull)(struct gf100_gr *);
    163 	void (*init_num_active_ltcs)(struct gf100_gr *);
    164 	void (*init_rop_active_fbps)(struct gf100_gr *);
    165 	void (*init_bios_2)(struct gf100_gr *);
    166 	void (*init_swdx_pes_mask)(struct gf100_gr *);
    167 	void (*init_fs)(struct gf100_gr *);
    168 	void (*init_fecs_exceptions)(struct gf100_gr *);
    169 	void (*init_ds_hww_esr_2)(struct gf100_gr *);
    170 	void (*init_40601c)(struct gf100_gr *);
    171 	void (*init_sked_hww_esr)(struct gf100_gr *);
    172 	void (*init_419cc0)(struct gf100_gr *);
    173 	void (*init_419eb4)(struct gf100_gr *);
    174 	void (*init_419c9c)(struct gf100_gr *);
    175 	void (*init_ppc_exceptions)(struct gf100_gr *);
    176 	void (*init_tex_hww_esr)(struct gf100_gr *, int gpc, int tpc);
    177 	void (*init_504430)(struct gf100_gr *, int gpc, int tpc);
    178 	void (*init_shader_exceptions)(struct gf100_gr *, int gpc, int tpc);
    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 	} fecs;
    187 	struct {
    188 		struct gf100_gr_ucode *ucode;
    189 	} gpccs;
    190 	int (*rops)(struct gf100_gr *);
    191 	int gpc_nr;
    192 	int tpc_nr;
    193 	int ppc_nr;
    194 	const struct gf100_grctx_func *grctx;
    195 	const struct nvkm_therm_clkgate_pack *clkgate_pack;
    196 	const struct gf100_gr_func_zbc *zbc;
    197 	struct nvkm_sclass sclass[];
    198 };
    199 
    200 int gf100_gr_rops(struct gf100_gr *);
    201 void gf100_gr_oneinit_tiles(struct gf100_gr *);
    202 void gf100_gr_oneinit_sm_id(struct gf100_gr *);
    203 int gf100_gr_init(struct gf100_gr *);
    204 void gf100_gr_init_vsc_stream_master(struct gf100_gr *);
    205 void gf100_gr_init_zcull(struct gf100_gr *);
    206 void gf100_gr_init_num_active_ltcs(struct gf100_gr *);
    207 void gf100_gr_init_fecs_exceptions(struct gf100_gr *);
    208 void gf100_gr_init_40601c(struct gf100_gr *);
    209 void gf100_gr_init_419cc0(struct gf100_gr *);
    210 void gf100_gr_init_419eb4(struct gf100_gr *);
    211 void gf100_gr_init_tex_hww_esr(struct gf100_gr *, int, int);
    212 void gf100_gr_init_shader_exceptions(struct gf100_gr *, int, int);
    213 void gf100_gr_init_400054(struct gf100_gr *);
    214 void gf100_gr_init_num_tpc_per_gpc(struct gf100_gr *, bool, bool);
    215 extern const struct gf100_gr_func_zbc gf100_gr_zbc;
    216 
    217 void gf117_gr_init_zcull(struct gf100_gr *);
    218 
    219 void gk104_gr_init_vsc_stream_master(struct gf100_gr *);
    220 void gk104_gr_init_rop_active_fbps(struct gf100_gr *);
    221 void gk104_gr_init_ppc_exceptions(struct gf100_gr *);
    222 void gk104_gr_init_sked_hww_esr(struct gf100_gr *);
    223 
    224 void gk110_gr_init_419eb4(struct gf100_gr *);
    225 
    226 void gm107_gr_init_504430(struct gf100_gr *, int, int);
    227 void gm107_gr_init_shader_exceptions(struct gf100_gr *, int, int);
    228 void gm107_gr_init_400054(struct gf100_gr *);
    229 
    230 int gk20a_gr_init(struct gf100_gr *);
    231 
    232 void gm200_gr_oneinit_tiles(struct gf100_gr *);
    233 void gm200_gr_oneinit_sm_id(struct gf100_gr *);
    234 int gm200_gr_rops(struct gf100_gr *);
    235 void gm200_gr_init_num_active_ltcs(struct gf100_gr *);
    236 void gm200_gr_init_ds_hww_esr_2(struct gf100_gr *);
    237 
    238 void gp100_gr_init_rop_active_fbps(struct gf100_gr *);
    239 void gp100_gr_init_fecs_exceptions(struct gf100_gr *);
    240 void gp100_gr_init_shader_exceptions(struct gf100_gr *, int, int);
    241 void gp100_gr_zbc_clear_color(struct gf100_gr *, int);
    242 void gp100_gr_zbc_clear_depth(struct gf100_gr *, int);
    243 extern const struct gf100_gr_func_zbc gp100_gr_zbc;
    244 
    245 void gp102_gr_init_swdx_pes_mask(struct gf100_gr *);
    246 extern const struct gf100_gr_func_zbc gp102_gr_zbc;
    247 
    248 extern const struct gf100_gr_func gp107_gr;
    249 
    250 void gv100_gr_init_419bd8(struct gf100_gr *);
    251 void gv100_gr_init_504430(struct gf100_gr *, int, int);
    252 void gv100_gr_init_shader_exceptions(struct gf100_gr *, int, int);
    253 void gv100_gr_trap_mp(struct gf100_gr *, int, int);
    254 
    255 #define gf100_gr_chan(p) container_of((p), struct gf100_gr_chan, object)
    256 #include <core/object.h>
    257 
    258 struct gf100_gr_chan {
    259 	struct nvkm_object object;
    260 	struct gf100_gr *gr;
    261 	struct nvkm_vmm *vmm;
    262 
    263 	struct nvkm_memory *mmio;
    264 	struct nvkm_vma *mmio_vma;
    265 	int mmio_nr;
    266 
    267 	struct {
    268 		struct nvkm_memory *mem;
    269 		struct nvkm_vma *vma;
    270 	} data[4];
    271 };
    272 
    273 void gf100_gr_ctxctl_debug(struct gf100_gr *);
    274 
    275 u64  gf100_gr_units(struct nvkm_gr *);
    276 void gf100_gr_zbc_init(struct gf100_gr *);
    277 
    278 extern const struct nvkm_object_func gf100_fermi;
    279 
    280 struct gf100_gr_init {
    281 	u32 addr;
    282 	u8  count;
    283 	u32 pitch;
    284 	u32 data;
    285 };
    286 
    287 struct gf100_gr_pack {
    288 	const struct gf100_gr_init *init;
    289 	u32 type;
    290 };
    291 
    292 #define pack_for_each_init(init, pack, head)                                   \
    293 	for (pack = head; pack && pack->init; pack++)                          \
    294 		  for (init = pack->init; init && init->count; init++)
    295 
    296 struct gf100_gr_ucode {
    297 	struct nvkm_blob code;
    298 	struct nvkm_blob data;
    299 };
    300 
    301 extern struct gf100_gr_ucode gf100_gr_fecs_ucode;
    302 extern struct gf100_gr_ucode gf100_gr_gpccs_ucode;
    303 
    304 extern struct gf100_gr_ucode gk110_gr_fecs_ucode;
    305 extern struct gf100_gr_ucode gk110_gr_gpccs_ucode;
    306 
    307 int  gf100_gr_wait_idle(struct gf100_gr *);
    308 void gf100_gr_mmio(struct gf100_gr *, const struct gf100_gr_pack *);
    309 void gf100_gr_icmd(struct gf100_gr *, const struct gf100_gr_pack *);
    310 void gf100_gr_mthd(struct gf100_gr *, const struct gf100_gr_pack *);
    311 int  gf100_gr_init_ctxctl(struct gf100_gr *);
    312 
    313 /* register init value lists */
    314 
    315 extern const struct gf100_gr_init gf100_gr_init_main_0[];
    316 extern const struct gf100_gr_init gf100_gr_init_fe_0[];
    317 extern const struct gf100_gr_init gf100_gr_init_pri_0[];
    318 extern const struct gf100_gr_init gf100_gr_init_rstr2d_0[];
    319 extern const struct gf100_gr_init gf100_gr_init_pd_0[];
    320 extern const struct gf100_gr_init gf100_gr_init_ds_0[];
    321 extern const struct gf100_gr_init gf100_gr_init_scc_0[];
    322 extern const struct gf100_gr_init gf100_gr_init_prop_0[];
    323 extern const struct gf100_gr_init gf100_gr_init_gpc_unk_0[];
    324 extern const struct gf100_gr_init gf100_gr_init_setup_0[];
    325 extern const struct gf100_gr_init gf100_gr_init_crstr_0[];
    326 extern const struct gf100_gr_init gf100_gr_init_setup_1[];
    327 extern const struct gf100_gr_init gf100_gr_init_zcull_0[];
    328 extern const struct gf100_gr_init gf100_gr_init_gpm_0[];
    329 extern const struct gf100_gr_init gf100_gr_init_gpc_unk_1[];
    330 extern const struct gf100_gr_init gf100_gr_init_gcc_0[];
    331 extern const struct gf100_gr_init gf100_gr_init_tpccs_0[];
    332 extern const struct gf100_gr_init gf100_gr_init_tex_0[];
    333 extern const struct gf100_gr_init gf100_gr_init_pe_0[];
    334 extern const struct gf100_gr_init gf100_gr_init_l1c_0[];
    335 extern const struct gf100_gr_init gf100_gr_init_wwdx_0[];
    336 extern const struct gf100_gr_init gf100_gr_init_tpccs_1[];
    337 extern const struct gf100_gr_init gf100_gr_init_mpc_0[];
    338 extern const struct gf100_gr_init gf100_gr_init_be_0[];
    339 extern const struct gf100_gr_init gf100_gr_init_fe_1[];
    340 extern const struct gf100_gr_init gf100_gr_init_pe_1[];
    341 void gf100_gr_init_gpc_mmu(struct gf100_gr *);
    342 void gf100_gr_trap_mp(struct gf100_gr *, int, int);
    343 extern const struct nvkm_bitfield gf100_mp_global_error[];
    344 extern const struct nvkm_enum gf100_mp_warp_error[];
    345 
    346 extern const struct gf100_gr_init gf104_gr_init_ds_0[];
    347 extern const struct gf100_gr_init gf104_gr_init_tex_0[];
    348 extern const struct gf100_gr_init gf104_gr_init_sm_0[];
    349 
    350 extern const struct gf100_gr_init gf108_gr_init_gpc_unk_0[];
    351 extern const struct gf100_gr_init gf108_gr_init_setup_1[];
    352 
    353 extern const struct gf100_gr_init gf119_gr_init_pd_0[];
    354 extern const struct gf100_gr_init gf119_gr_init_ds_0[];
    355 extern const struct gf100_gr_init gf119_gr_init_prop_0[];
    356 extern const struct gf100_gr_init gf119_gr_init_gpm_0[];
    357 extern const struct gf100_gr_init gf119_gr_init_gpc_unk_1[];
    358 extern const struct gf100_gr_init gf119_gr_init_tex_0[];
    359 extern const struct gf100_gr_init gf119_gr_init_sm_0[];
    360 extern const struct gf100_gr_init gf119_gr_init_fe_1[];
    361 
    362 extern const struct gf100_gr_init gf117_gr_init_pes_0[];
    363 extern const struct gf100_gr_init gf117_gr_init_wwdx_0[];
    364 extern const struct gf100_gr_init gf117_gr_init_cbm_0[];
    365 
    366 extern const struct gf100_gr_init gk104_gr_init_main_0[];
    367 extern const struct gf100_gr_init gk104_gr_init_gpc_unk_2[];
    368 extern const struct gf100_gr_init gk104_gr_init_tpccs_0[];
    369 extern const struct gf100_gr_init gk104_gr_init_pe_0[];
    370 extern const struct gf100_gr_init gk104_gr_init_be_0[];
    371 extern const struct gf100_gr_pack gk104_gr_pack_mmio[];
    372 
    373 extern const struct gf100_gr_init gk110_gr_init_fe_0[];
    374 extern const struct gf100_gr_init gk110_gr_init_ds_0[];
    375 extern const struct gf100_gr_init gk110_gr_init_sked_0[];
    376 extern const struct gf100_gr_init gk110_gr_init_cwd_0[];
    377 extern const struct gf100_gr_init gk110_gr_init_gpc_unk_1[];
    378 extern const struct gf100_gr_init gk110_gr_init_tex_0[];
    379 extern const struct gf100_gr_init gk110_gr_init_sm_0[];
    380 
    381 extern const struct gf100_gr_init gk208_gr_init_gpc_unk_0[];
    382 
    383 extern const struct gf100_gr_init gm107_gr_init_scc_0[];
    384 extern const struct gf100_gr_init gm107_gr_init_prop_0[];
    385 extern const struct gf100_gr_init gm107_gr_init_setup_1[];
    386 extern const struct gf100_gr_init gm107_gr_init_zcull_0[];
    387 extern const struct gf100_gr_init gm107_gr_init_gpc_unk_1[];
    388 extern const struct gf100_gr_init gm107_gr_init_tex_0[];
    389 extern const struct gf100_gr_init gm107_gr_init_l1c_0[];
    390 extern const struct gf100_gr_init gm107_gr_init_wwdx_0[];
    391 extern const struct gf100_gr_init gm107_gr_init_cbm_0[];
    392 void gm107_gr_init_bios(struct gf100_gr *);
    393 
    394 void gm200_gr_init_gpc_mmu(struct gf100_gr *);
    395 
    396 struct gf100_gr_fwif {
    397 	int version;
    398 	int (*load)(struct gf100_gr *, int ver, const struct gf100_gr_fwif *);
    399 	const struct gf100_gr_func *func;
    400 	const struct nvkm_acr_lsf_func *fecs;
    401 	const struct nvkm_acr_lsf_func *gpccs;
    402 };
    403 
    404 int gf100_gr_load(struct gf100_gr *, int, const struct gf100_gr_fwif *);
    405 int gf100_gr_nofw(struct gf100_gr *, int, const struct gf100_gr_fwif *);
    406 
    407 int gk20a_gr_load_sw(struct gf100_gr *, const char *path, int ver);
    408 
    409 int gm200_gr_load(struct gf100_gr *, int, const struct gf100_gr_fwif *);
    410 extern const struct nvkm_acr_lsf_func gm200_gr_gpccs_acr;
    411 extern const struct nvkm_acr_lsf_func gm200_gr_fecs_acr;
    412 
    413 extern const struct nvkm_acr_lsf_func gm20b_gr_fecs_acr;
    414 void gm20b_gr_acr_bld_write(struct nvkm_acr *, u32, struct nvkm_acr_lsfw *);
    415 void gm20b_gr_acr_bld_patch(struct nvkm_acr *, u32, s64);
    416 
    417 extern const struct nvkm_acr_lsf_func gp108_gr_gpccs_acr;
    418 extern const struct nvkm_acr_lsf_func gp108_gr_fecs_acr;
    419 
    420 int gf100_gr_new_(const struct gf100_gr_fwif *, struct nvkm_device *, int,
    421 		  struct nvkm_gr **);
    422 #endif
    423