19ec28052SBen Skeggs /*
29ec28052SBen Skeggs * Copyright 2015 Red Hat Inc.
39ec28052SBen Skeggs *
49ec28052SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
59ec28052SBen Skeggs * copy of this software and associated documentation files (the "Software"),
69ec28052SBen Skeggs * to deal in the Software without restriction, including without limitation
79ec28052SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89ec28052SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
99ec28052SBen Skeggs * Software is furnished to do so, subject to the following conditions:
109ec28052SBen Skeggs *
119ec28052SBen Skeggs * The above copyright notice and this permission notice shall be included in
129ec28052SBen Skeggs * all copies or substantial portions of the Software.
139ec28052SBen Skeggs *
149ec28052SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
159ec28052SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
169ec28052SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
179ec28052SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
189ec28052SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
199ec28052SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
209ec28052SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
219ec28052SBen Skeggs *
229ec28052SBen Skeggs * Authors: Ben Skeggs <bskeggs@redhat.com>
239ec28052SBen Skeggs */
249ec28052SBen Skeggs #include "ctxgf100.h"
259ec28052SBen Skeggs
269ec28052SBen Skeggs /*******************************************************************************
279ec28052SBen Skeggs * PGRAPH context implementation
289ec28052SBen Skeggs ******************************************************************************/
299ec28052SBen Skeggs
308d56fc48SBen Skeggs void
gm200_grctx_generate_r419a3c(struct gf100_gr * gr)318d56fc48SBen Skeggs gm200_grctx_generate_r419a3c(struct gf100_gr *gr)
328d56fc48SBen Skeggs {
338d56fc48SBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
348d56fc48SBen Skeggs nvkm_mask(device, 0x419a3c, 0x00000014, 0x00000000);
358d56fc48SBen Skeggs }
368d56fc48SBen Skeggs
37c2592adeSBen Skeggs static void
gm200_grctx_generate_r418e94(struct gf100_gr * gr)38c2592adeSBen Skeggs gm200_grctx_generate_r418e94(struct gf100_gr *gr)
39c2592adeSBen Skeggs {
40c2592adeSBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
41c2592adeSBen Skeggs nvkm_mask(device, 0x418e94, 0xffffffff, 0xc4230000);
42c2592adeSBen Skeggs nvkm_mask(device, 0x418e4c, 0xffffffff, 0x70000000);
43c2592adeSBen Skeggs }
44c2592adeSBen Skeggs
459ec28052SBen Skeggs void
gm200_grctx_generate_smid_config(struct gf100_gr * gr)46fc360764SBen Skeggs gm200_grctx_generate_smid_config(struct gf100_gr *gr)
479ec28052SBen Skeggs {
489ec28052SBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
499ec28052SBen Skeggs const u32 dist_nr = DIV_ROUND_UP(gr->tpc_total, 4);
509ec28052SBen Skeggs u32 dist[TPC_MAX / 4] = {};
519ec28052SBen Skeggs u32 gpcs[GPC_MAX] = {};
52068cae74SBen Skeggs u8 sm, i;
539ec28052SBen Skeggs
54068cae74SBen Skeggs for (sm = 0; sm < gr->sm_nr; sm++) {
55068cae74SBen Skeggs const u8 gpc = gr->sm[sm].gpc;
56068cae74SBen Skeggs const u8 tpc = gr->sm[sm].tpc;
57068cae74SBen Skeggs dist[sm / 4] |= ((gpc << 4) | tpc) << ((sm % 4) * 8);
58068cae74SBen Skeggs gpcs[gpc] |= sm << (tpc * 8);
599ec28052SBen Skeggs }
609ec28052SBen Skeggs
619ec28052SBen Skeggs for (i = 0; i < dist_nr; i++)
629ec28052SBen Skeggs nvkm_wr32(device, 0x405b60 + (i * 4), dist[i]);
639ec28052SBen Skeggs for (i = 0; i < gr->gpc_nr; i++)
649ec28052SBen Skeggs nvkm_wr32(device, 0x405ba0 + (i * 4), gpcs[i]);
659ec28052SBen Skeggs }
669ec28052SBen Skeggs
67e7163b19SBen Skeggs void
gm200_grctx_generate_tpc_mask(struct gf100_gr * gr)68fc360764SBen Skeggs gm200_grctx_generate_tpc_mask(struct gf100_gr *gr)
69fc360764SBen Skeggs {
70fc360764SBen Skeggs u32 tmp, i;
71fc360764SBen Skeggs for (tmp = 0, i = 0; i < gr->gpc_nr; i++)
72fc360764SBen Skeggs tmp |= ((1 << gr->tpc_nr[i]) - 1) << (i * gr->func->tpc_nr);
73fc360764SBen Skeggs nvkm_wr32(gr->base.engine.subdev.device, 0x4041c4, tmp);
74fc360764SBen Skeggs }
75fc360764SBen Skeggs
76fc360764SBen Skeggs void
gm200_grctx_generate_r406500(struct gf100_gr * gr)77e7163b19SBen Skeggs gm200_grctx_generate_r406500(struct gf100_gr *gr)
78e7163b19SBen Skeggs {
79e7163b19SBen Skeggs nvkm_wr32(gr->base.engine.subdev.device, 0x406500, 0x00000000);
80e7163b19SBen Skeggs }
81e7163b19SBen Skeggs
8260770fa2SBen Skeggs void
gm200_grctx_generate_dist_skip_table(struct gf100_gr * gr)8360770fa2SBen Skeggs gm200_grctx_generate_dist_skip_table(struct gf100_gr *gr)
8460770fa2SBen Skeggs {
8560770fa2SBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
8660770fa2SBen Skeggs u32 data[8] = {};
8760770fa2SBen Skeggs int gpc, ppc, i;
8860770fa2SBen Skeggs
8960770fa2SBen Skeggs for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
90*0c520ad4SBen Skeggs for (ppc = 0; ppc < gr->func->ppc_nr; ppc++) {
9160770fa2SBen Skeggs u8 ppc_tpcs = gr->ppc_tpc_nr[gpc][ppc];
9260770fa2SBen Skeggs u8 ppc_tpcm = gr->ppc_tpc_mask[gpc][ppc];
9360770fa2SBen Skeggs while (ppc_tpcs-- > gr->ppc_tpc_min)
9460770fa2SBen Skeggs ppc_tpcm &= ppc_tpcm - 1;
9560770fa2SBen Skeggs ppc_tpcm ^= gr->ppc_tpc_mask[gpc][ppc];
9660770fa2SBen Skeggs ((u8 *)data)[gpc] |= ppc_tpcm;
9760770fa2SBen Skeggs }
9860770fa2SBen Skeggs }
9960770fa2SBen Skeggs
10060770fa2SBen Skeggs for (i = 0; i < ARRAY_SIZE(data); i++)
10160770fa2SBen Skeggs nvkm_wr32(device, 0x4064d0 + (i * 0x04), data[i]);
10260770fa2SBen Skeggs }
10360770fa2SBen Skeggs
1049ec28052SBen Skeggs const struct gf100_grctx_func
1059ec28052SBen Skeggs gm200_grctx = {
106201ed6f6SBen Skeggs .main = gf100_grctx_generate_main,
1079ec28052SBen Skeggs .unkn = gk104_grctx_generate_unkn,
1089ec28052SBen Skeggs .bundle = gm107_grctx_generate_bundle,
1099ec28052SBen Skeggs .bundle_size = 0x3000,
1109ec28052SBen Skeggs .bundle_min_gpm_fifo_depth = 0x180,
1119ec28052SBen Skeggs .bundle_token_limit = 0x780,
1129ec28052SBen Skeggs .pagepool = gm107_grctx_generate_pagepool,
1139ec28052SBen Skeggs .pagepool_size = 0x20000,
11478a43c7eSBen Skeggs .attrib_cb_size = gf100_grctx_generate_attrib_cb_size,
11578a43c7eSBen Skeggs .attrib_cb = gm107_grctx_generate_attrib_cb,
1169ec28052SBen Skeggs .attrib = gm107_grctx_generate_attrib,
1179ec28052SBen Skeggs .attrib_nr_max = 0x600,
1189ec28052SBen Skeggs .attrib_nr = 0x400,
1199ec28052SBen Skeggs .alpha_nr_max = 0x1800,
1209ec28052SBen Skeggs .alpha_nr = 0x1000,
121fc740f54SBen Skeggs .sm_id = gm107_grctx_generate_sm_id,
122ff209c23SBen Skeggs .rop_mapping = gf117_grctx_generate_rop_mapping,
12360770fa2SBen Skeggs .dist_skip_table = gm200_grctx_generate_dist_skip_table,
124e7163b19SBen Skeggs .r406500 = gm200_grctx_generate_r406500,
12560c0264aSBen Skeggs .gpc_tpc_nr = gk104_grctx_generate_gpc_tpc_nr,
126fc360764SBen Skeggs .tpc_mask = gm200_grctx_generate_tpc_mask,
127fc360764SBen Skeggs .smid_config = gm200_grctx_generate_smid_config,
128c2592adeSBen Skeggs .r418e94 = gm200_grctx_generate_r418e94,
1298d56fc48SBen Skeggs .r419a3c = gm200_grctx_generate_r419a3c,
1309ec28052SBen Skeggs };
131