ctxgm200.c 4.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * Copyright 2015 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs <bskeggs@redhat.com>
 */
#include "ctxgf100.h"

/*******************************************************************************
 * PGRAPH context implementation
 ******************************************************************************/

30
void
31
gm200_grctx_generate_405b60(struct gf100_gr *gr)
32
{
33
	struct nvkm_device *device = gr->base.engine.subdev.device;
B
Ben Skeggs 已提交
34 35
	const u32 dist_nr = DIV_ROUND_UP(gr->tpc_total, 4);
	u32 dist[TPC_MAX / 4] = {};
36 37 38 39
	u32 gpcs[GPC_MAX] = {};
	u8  tpcnr[GPC_MAX];
	int tpc, gpc, i;

B
Ben Skeggs 已提交
40
	memcpy(tpcnr, gr->tpc_nr, sizeof(gr->tpc_nr));
41 42 43 44 45

	/* won't result in the same distribution as the binary driver where
	 * some of the gpcs have more tpcs than others, but this shall do
	 * for the moment.  the code for earlier gpus has this issue too.
	 */
B
Ben Skeggs 已提交
46
	for (gpc = -1, i = 0; i < gr->tpc_total; i++) {
47
		do {
B
Ben Skeggs 已提交
48
			gpc = (gpc + 1) % gr->gpc_nr;
49
		} while(!tpcnr[gpc]);
B
Ben Skeggs 已提交
50
		tpc = gr->tpc_nr[gpc] - tpcnr[gpc]--;
51 52 53 54 55 56

		dist[i / 4] |= ((gpc << 4) | tpc) << ((i % 4) * 8);
		gpcs[gpc] |= i << (tpc * 8);
	}

	for (i = 0; i < dist_nr; i++)
57
		nvkm_wr32(device, 0x405b60 + (i * 4), dist[i]);
B
Ben Skeggs 已提交
58
	for (i = 0; i < gr->gpc_nr; i++)
59
		nvkm_wr32(device, 0x405ba0 + (i * 4), gpcs[i]);
60 61
}

62 63 64 65 66 67
void
gm200_grctx_generate_r406500(struct gf100_gr *gr)
{
	nvkm_wr32(gr->base.engine.subdev.device, 0x406500, 0x00000000);
}

68
static void
69
gm200_grctx_generate_main(struct gf100_gr *gr, struct gf100_grctx *info)
70
{
71
	struct nvkm_device *device = gr->base.engine.subdev.device;
72
	const struct gf100_grctx_func *grctx = gr->func->grctx;
73
	u32 idle_timeout, tmp;
74 75
	int i;

76
	gf100_gr_mmio(gr, gr->fuc_sw_ctx);
77

78
	idle_timeout = nvkm_mask(device, 0x404154, 0xffffffff, 0x00000000);
79

80 81 82 83
	grctx->bundle(info);
	grctx->pagepool(info);
	grctx->attrib(info);
	grctx->unkn(gr);
84

85
	gf100_grctx_generate_floorsweep(gr);
86

87
	nvkm_wr32(device, 0x405b00, (gr->tpc_total << 8) | gr->gpc_nr);
88

B
Ben Skeggs 已提交
89 90
	for (tmp = 0, i = 0; i < gr->gpc_nr; i++)
		tmp |= ((1 << gr->tpc_nr[i]) - 1) << (i * 4);
91
	nvkm_wr32(device, 0x4041c4, tmp);
92

93
	gm200_grctx_generate_405b60(gr);
94

95
	gf100_gr_icmd(gr, gr->fuc_bundle);
96
	nvkm_wr32(device, 0x404154, idle_timeout);
97
	gf100_gr_mthd(gr, gr->fuc_method);
98

99 100
	nvkm_mask(device, 0x418e94, 0xffffffff, 0xc4230000);
	nvkm_mask(device, 0x418e4c, 0xffffffff, 0x70000000);
101 102
}

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
void
gm200_grctx_generate_dist_skip_table(struct gf100_gr *gr)
{
	struct nvkm_device *device = gr->base.engine.subdev.device;
	u32 data[8] = {};
	int gpc, ppc, i;

	for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
		for (ppc = 0; ppc < gr->ppc_nr[gpc]; ppc++) {
			u8 ppc_tpcs = gr->ppc_tpc_nr[gpc][ppc];
			u8 ppc_tpcm = gr->ppc_tpc_mask[gpc][ppc];
			while (ppc_tpcs-- > gr->ppc_tpc_min)
				ppc_tpcm &= ppc_tpcm - 1;
			ppc_tpcm ^= gr->ppc_tpc_mask[gpc][ppc];
			((u8 *)data)[gpc] |= ppc_tpcm;
		}
	}

	for (i = 0; i < ARRAY_SIZE(data); i++)
		nvkm_wr32(device, 0x4064d0 + (i * 0x04), data[i]);
}

125
const struct gf100_grctx_func
126 127
gm200_grctx = {
	.main  = gm200_grctx_generate_main,
128 129 130 131 132 133 134 135 136 137 138 139
	.unkn  = gk104_grctx_generate_unkn,
	.bundle = gm107_grctx_generate_bundle,
	.bundle_size = 0x3000,
	.bundle_min_gpm_fifo_depth = 0x180,
	.bundle_token_limit = 0x780,
	.pagepool = gm107_grctx_generate_pagepool,
	.pagepool_size = 0x20000,
	.attrib = gm107_grctx_generate_attrib,
	.attrib_nr_max = 0x600,
	.attrib_nr = 0x400,
	.alpha_nr_max = 0x1800,
	.alpha_nr = 0x1000,
140
	.sm_id = gm107_grctx_generate_sm_id,
141
	.rop_mapping = gf117_grctx_generate_rop_mapping,
142
	.dist_skip_table = gm200_grctx_generate_dist_skip_table,
143
	.r406500 = gm200_grctx_generate_r406500,
144
};