cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

gf100.h (14456B)


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