1424321beSBen Skeggs /*
2424321beSBen Skeggs * Copyright 2016 Red Hat Inc.
3424321beSBen Skeggs *
4424321beSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5424321beSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6424321beSBen Skeggs * to deal in the Software without restriction, including without limitation
7424321beSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8424321beSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9424321beSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10424321beSBen Skeggs *
11424321beSBen Skeggs * The above copyright notice and this permission notice shall be included in
12424321beSBen Skeggs * all copies or substantial portions of the Software.
13424321beSBen Skeggs *
14424321beSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15424321beSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16424321beSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17424321beSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18424321beSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19424321beSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20424321beSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21424321beSBen Skeggs *
22424321beSBen Skeggs * Authors: Ben Skeggs <bskeggs@redhat.com>
23424321beSBen Skeggs */
24424321beSBen Skeggs #include "gf100.h"
25424321beSBen Skeggs #include "ctxgf100.h"
26424321beSBen Skeggs
27424321beSBen Skeggs #include <nvif/class.h>
28424321beSBen Skeggs
29*c4bdac75SBen Skeggs void
gp102_gr_zbc_clear_stencil(struct gf100_gr * gr,int zbc)304b2c71edSBen Skeggs gp102_gr_zbc_clear_stencil(struct gf100_gr *gr, int zbc)
314b2c71edSBen Skeggs {
324b2c71edSBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
334b2c71edSBen Skeggs const int znum = zbc - 1;
344b2c71edSBen Skeggs const u32 zoff = znum * 4;
354b2c71edSBen Skeggs
364b2c71edSBen Skeggs if (gr->zbc_stencil[zbc].format)
374b2c71edSBen Skeggs nvkm_wr32(device, 0x41815c + zoff, gr->zbc_stencil[zbc].ds);
384b2c71edSBen Skeggs nvkm_mask(device, 0x418198 + ((znum / 4) * 4),
394b2c71edSBen Skeggs 0x0000007f << ((znum % 4) * 7),
404b2c71edSBen Skeggs gr->zbc_stencil[zbc].format << ((znum % 4) * 7));
414b2c71edSBen Skeggs }
424b2c71edSBen Skeggs
43*c4bdac75SBen Skeggs int
gp102_gr_zbc_stencil_get(struct gf100_gr * gr,int format,const u32 ds,const u32 l2)444b2c71edSBen Skeggs gp102_gr_zbc_stencil_get(struct gf100_gr *gr, int format,
454b2c71edSBen Skeggs const u32 ds, const u32 l2)
464b2c71edSBen Skeggs {
474b2c71edSBen Skeggs struct nvkm_ltc *ltc = gr->base.engine.subdev.device->ltc;
484b2c71edSBen Skeggs int zbc = -ENOSPC, i;
494b2c71edSBen Skeggs
504500031fSBen Skeggs for (i = ltc->zbc_depth_min; i <= ltc->zbc_depth_max; i++) {
514b2c71edSBen Skeggs if (gr->zbc_stencil[i].format) {
524b2c71edSBen Skeggs if (gr->zbc_stencil[i].format != format)
534b2c71edSBen Skeggs continue;
544b2c71edSBen Skeggs if (gr->zbc_stencil[i].ds != ds)
554b2c71edSBen Skeggs continue;
564b2c71edSBen Skeggs if (gr->zbc_stencil[i].l2 != l2) {
574b2c71edSBen Skeggs WARN_ON(1);
584b2c71edSBen Skeggs return -EINVAL;
594b2c71edSBen Skeggs }
604b2c71edSBen Skeggs return i;
614b2c71edSBen Skeggs } else {
624b2c71edSBen Skeggs zbc = (zbc < 0) ? i : zbc;
634b2c71edSBen Skeggs }
644b2c71edSBen Skeggs }
654b2c71edSBen Skeggs
664b2c71edSBen Skeggs if (zbc < 0)
674b2c71edSBen Skeggs return zbc;
684b2c71edSBen Skeggs
694b2c71edSBen Skeggs gr->zbc_stencil[zbc].format = format;
704b2c71edSBen Skeggs gr->zbc_stencil[zbc].ds = ds;
714b2c71edSBen Skeggs gr->zbc_stencil[zbc].l2 = l2;
724b2c71edSBen Skeggs nvkm_ltc_zbc_stencil_get(ltc, zbc, l2);
734b2c71edSBen Skeggs gr->func->zbc->clear_stencil(gr, zbc);
744b2c71edSBen Skeggs return zbc;
754b2c71edSBen Skeggs }
764b2c71edSBen Skeggs
774b2c71edSBen Skeggs const struct gf100_gr_func_zbc
784b2c71edSBen Skeggs gp102_gr_zbc = {
794b2c71edSBen Skeggs .clear_color = gp100_gr_zbc_clear_color,
804b2c71edSBen Skeggs .clear_depth = gp100_gr_zbc_clear_depth,
814b2c71edSBen Skeggs .stencil_get = gp102_gr_zbc_stencil_get,
824b2c71edSBen Skeggs .clear_stencil = gp102_gr_zbc_clear_stencil,
834b2c71edSBen Skeggs };
844b2c71edSBen Skeggs
85b2c4ef70SBen Skeggs void
gp102_gr_init_swdx_pes_mask(struct gf100_gr * gr)86424321beSBen Skeggs gp102_gr_init_swdx_pes_mask(struct gf100_gr *gr)
87424321beSBen Skeggs {
88424321beSBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
89424321beSBen Skeggs u32 mask = 0, data, gpc;
90424321beSBen Skeggs
91424321beSBen Skeggs for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
92424321beSBen Skeggs data = nvkm_rd32(device, GPC_UNIT(gpc, 0x0c50)) & 0x0000000f;
93424321beSBen Skeggs mask |= data << (gpc * 4);
94424321beSBen Skeggs }
95424321beSBen Skeggs
96424321beSBen Skeggs nvkm_wr32(device, 0x4181d0, mask);
97424321beSBen Skeggs }
98424321beSBen Skeggs
99424321beSBen Skeggs static const struct gf100_gr_func
100424321beSBen Skeggs gp102_gr = {
1015f6474a4SBen Skeggs .oneinit_tiles = gm200_gr_oneinit_tiles,
102068cae74SBen Skeggs .oneinit_sm_id = gm200_gr_oneinit_sm_id,
103525230cbSBen Skeggs .init = gf100_gr_init,
104424321beSBen Skeggs .init_gpc_mmu = gm200_gr_init_gpc_mmu,
1052fe5ff63SBen Skeggs .init_vsc_stream_master = gk104_gr_init_vsc_stream_master,
10602917aa3SBen Skeggs .init_zcull = gf117_gr_init_zcull,
107bfd27f39SBen Skeggs .init_num_active_ltcs = gm200_gr_init_num_active_ltcs,
108424321beSBen Skeggs .init_rop_active_fbps = gp100_gr_init_rop_active_fbps,
109424321beSBen Skeggs .init_swdx_pes_mask = gp102_gr_init_swdx_pes_mask,
1102585a1b1SBen Skeggs .init_fecs_exceptions = gp100_gr_init_fecs_exceptions,
1113ac72e98SBen Skeggs .init_ds_hww_esr_2 = gm200_gr_init_ds_hww_esr_2,
1120a5b9730SBen Skeggs .init_sked_hww_esr = gk104_gr_init_sked_hww_esr,
1130feab025SBen Skeggs .init_419cc0 = gf100_gr_init_419cc0,
114dff30dbdSBen Skeggs .init_ppc_exceptions = gk104_gr_init_ppc_exceptions,
115f3ef80c0SBen Skeggs .init_tex_hww_esr = gf100_gr_init_tex_hww_esr,
116ab4d49a3SBen Skeggs .init_504430 = gm107_gr_init_504430,
1174615e9b4SBen Skeggs .init_shader_exceptions = gp100_gr_init_shader_exceptions,
118b6d93fa7SBen Skeggs .init_rop_exceptions = gf100_gr_init_rop_exceptions,
1191a344688SBen Skeggs .init_exception2 = gf100_gr_init_exception2,
1205c05a589SBen Skeggs .trap_mp = gf100_gr_trap_mp,
121be99d041SBen Skeggs .fecs.reset = gf100_gr_fecs_reset,
122424321beSBen Skeggs .rops = gm200_gr_rops,
123fc360764SBen Skeggs .gpc_nr = 6,
124fc360764SBen Skeggs .tpc_nr = 5,
125424321beSBen Skeggs .ppc_nr = 3,
126424321beSBen Skeggs .grctx = &gp102_grctx,
1274b2c71edSBen Skeggs .zbc = &gp102_gr_zbc,
128424321beSBen Skeggs .sclass = {
129424321beSBen Skeggs { -1, -1, FERMI_TWOD_A },
130424321beSBen Skeggs { -1, -1, KEPLER_INLINE_TO_MEMORY_B },
131424321beSBen Skeggs { -1, -1, PASCAL_B, &gf100_fermi },
132424321beSBen Skeggs { -1, -1, PASCAL_COMPUTE_B },
133424321beSBen Skeggs {}
134424321beSBen Skeggs }
135424321beSBen Skeggs };
136424321beSBen Skeggs
137ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/fecs_bl.bin");
138ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/fecs_inst.bin");
139ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/fecs_data.bin");
140ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/fecs_sig.bin");
141ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/gpccs_bl.bin");
142ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/gpccs_inst.bin");
143ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/gpccs_data.bin");
144ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/gpccs_sig.bin");
145ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/sw_ctx.bin");
146ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/sw_nonctx.bin");
147ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/sw_bundle_init.bin");
148ef16dc27SBen Skeggs MODULE_FIRMWARE("nvidia/gp102/gr/sw_method_init.bin");
149ef16dc27SBen Skeggs
150ef16dc27SBen Skeggs static const struct gf100_gr_fwif
151ef16dc27SBen Skeggs gp102_gr_fwif[] = {
152ef16dc27SBen Skeggs { 0, gm200_gr_load, &gp102_gr, &gm200_gr_fecs_acr, &gm200_gr_gpccs_acr },
153b9c246adSBen Skeggs { -1, gm200_gr_nofw },
154ef16dc27SBen Skeggs {}
155ef16dc27SBen Skeggs };
156ef16dc27SBen Skeggs
157424321beSBen Skeggs int
gp102_gr_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_gr ** pgr)158864d37c3SBen Skeggs gp102_gr_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_gr **pgr)
159424321beSBen Skeggs {
160864d37c3SBen Skeggs return gf100_gr_new_(gp102_gr_fwif, device, type, inst, pgr);
161424321beSBen Skeggs }
162