11573Srgrimes/* 21573Srgrimes * Copyright 2016 Red Hat Inc. 31573Srgrimes * 41573Srgrimes * Permission is hereby granted, free of charge, to any person obtaining a 51573Srgrimes * copy of this software and associated documentation files (the "Software"), 61573Srgrimes * to deal in the Software without restriction, including without limitation 71573Srgrimes * the rights to use, copy, modify, merge, publish, distribute, sublicense, 81573Srgrimes * and/or sell copies of the Software, and to permit persons to whom the 91573Srgrimes * Software is furnished to do so, subject to the following conditions: 101573Srgrimes * 111573Srgrimes * The above copyright notice and this permission notice shall be included in 121573Srgrimes * all copies or substantial portions of the Software. 131573Srgrimes * 141573Srgrimes * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 151573Srgrimes * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 161573Srgrimes * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 171573Srgrimes * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 181573Srgrimes * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 191573Srgrimes * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 201573Srgrimes * OTHER DEALINGS IN THE SOFTWARE. 211573Srgrimes * 221573Srgrimes * Authors: Ben Skeggs <bskeggs@redhat.com> 231573Srgrimes */ 241573Srgrimes#include "ctxgf100.h" 251573Srgrimes 261573Srgrimes#include <subdev/fb.h> 271573Srgrimes 281573Srgrimes/******************************************************************************* 291573Srgrimes * PGRAPH context implementation 301573Srgrimes ******************************************************************************/ 311573Srgrimes 321573Srgrimesvoid 331573Srgrimesgp100_grctx_generate_pagepool(struct gf100_gr_chan *chan, u64 addr) 341573Srgrimes{ 351573Srgrimes gf100_grctx_patch_wr32(chan, 0x40800c, addr >> 8); 361573Srgrimes gf100_grctx_patch_wr32(chan, 0x408010, 0x8007d800); 371573Srgrimes gf100_grctx_patch_wr32(chan, 0x419004, addr >> 8); 381573Srgrimes gf100_grctx_patch_wr32(chan, 0x419008, 0x00000000); 3911659Sphk} 401573Srgrimes 411573Srgrimesstatic void 421573Srgrimesgp100_grctx_generate_attrib(struct gf100_gr_chan *chan) 431573Srgrimes{ 4411659Sphk struct gf100_gr *gr = chan->gr; 451573Srgrimes const struct gf100_grctx_func *grctx = gr->func->grctx; 461573Srgrimes const u32 alpha = grctx->alpha_nr; 471573Srgrimes const u32 attrib = grctx->attrib_nr; 488870Srgrimes const int max_batches = 0xffff; 491573Srgrimes u32 size = grctx->alpha_nr_max * gr->tpc_total; 501573Srgrimes u32 ao = 0; 511573Srgrimes u32 bo = ao + size; 521573Srgrimes int gpc, ppc, n = 0; 5311659Sphk 5411659Sphk gf100_grctx_patch_wr32(chan, 0x405830, attrib); 5511659Sphk gf100_grctx_patch_wr32(chan, 0x40585c, alpha); 5611659Sphk gf100_grctx_patch_wr32(chan, 0x4064c4, ((alpha / 4) << 16) | max_batches); 571573Srgrimes 581573Srgrimes for (gpc = 0; gpc < gr->gpc_nr; gpc++) { 591573Srgrimes for (ppc = 0; ppc < gr->func->ppc_nr; ppc++, n++) { 601573Srgrimes const u32 as = alpha * gr->ppc_tpc_nr[gpc][ppc]; 611573Srgrimes const u32 bs = attrib * gr->ppc_tpc_max; 621573Srgrimes const u32 u = 0x418ea0 + (n * 0x04); 631573Srgrimes const u32 o = PPC_UNIT(gpc, ppc, 0); 6411659Sphk 6511659Sphk if (!(gr->ppc_mask[gpc] & (1 << ppc))) 6611659Sphk continue; 6711659Sphk 681573Srgrimes gf100_grctx_patch_wr32(chan, o + 0xc0, bs); 691573Srgrimes gf100_grctx_patch_wr32(chan, o + 0xf4, bo); 701573Srgrimes gf100_grctx_patch_wr32(chan, o + 0xf0, bs); 711573Srgrimes bo += grctx->attrib_nr_max * gr->ppc_tpc_max; 721573Srgrimes gf100_grctx_patch_wr32(chan, o + 0xe4, as); 731573Srgrimes gf100_grctx_patch_wr32(chan, o + 0xf8, ao); 741573Srgrimes ao += grctx->alpha_nr_max * gr->ppc_tpc_nr[gpc][ppc]; 751573Srgrimes gf100_grctx_patch_wr32(chan, u, bs); 761573Srgrimes } 771573Srgrimes } 781573Srgrimes 7911659Sphk gf100_grctx_patch_wr32(chan, 0x418eec, 0x00000000); 8011659Sphk gf100_grctx_patch_wr32(chan, 0x41befc, 0x00000000); 8111659Sphk} 8211659Sphk 831573Srgrimesvoid 841573Srgrimesgp100_grctx_generate_attrib_cb(struct gf100_gr_chan *chan, u64 addr, u32 size) 851573Srgrimes{ 861573Srgrimes gm107_grctx_generate_attrib_cb(chan, addr, size); 871573Srgrimes 881573Srgrimes gf100_grctx_patch_wr32(chan, 0x419b00, 0x00000000 | addr >> 12); 891573Srgrimes gf100_grctx_patch_wr32(chan, 0x419b04, 0x80000000 | size >> 7); 9011659Sphk} 9111659Sphk 9211659Sphkstatic u32 9311659Sphkgp100_grctx_generate_attrib_cb_size(struct gf100_gr *gr) 941573Srgrimes{ 951573Srgrimes const struct gf100_grctx_func *grctx = gr->func->grctx; 961573Srgrimes u32 size = grctx->alpha_nr_max * gr->tpc_total; 971573Srgrimes int gpc; 981573Srgrimes 991573Srgrimes for (gpc = 0; gpc < gr->gpc_nr; gpc++) 1001573Srgrimes size += grctx->attrib_nr_max * gr->func->ppc_nr * gr->ppc_tpc_max; 101 102 return ((size * 0x20) + 128) & ~127; 103} 104 105void 106gp100_grctx_generate_smid_config(struct gf100_gr *gr) 107{ 108 struct nvkm_device *device = gr->base.engine.subdev.device; 109 const u32 dist_nr = DIV_ROUND_UP(gr->tpc_total, 4); 110 u32 dist[TPC_MAX / 4] = {}, gpcs[16] = {}; 111 u8 sm, i; 112 113 for (sm = 0; sm < gr->sm_nr; sm++) { 114 const u8 gpc = gr->sm[sm].gpc; 115 const u8 tpc = gr->sm[sm].tpc; 116 dist[sm / 4] |= ((gpc << 4) | tpc) << ((sm % 4) * 8); 117 gpcs[gpc + (gr->func->gpc_nr * (tpc / 4))] |= sm << ((tpc % 4) * 8); 118 } 119 120 for (i = 0; i < dist_nr; i++) 121 nvkm_wr32(device, 0x405b60 + (i * 4), dist[i]); 122 for (i = 0; i < ARRAY_SIZE(gpcs); i++) 123 nvkm_wr32(device, 0x405ba0 + (i * 4), gpcs[i]); 124} 125 126const struct gf100_grctx_func 127gp100_grctx = { 128 .main = gf100_grctx_generate_main, 129 .unkn = gk104_grctx_generate_unkn, 130 .bundle = gm107_grctx_generate_bundle, 131 .bundle_size = 0x3000, 132 .bundle_min_gpm_fifo_depth = 0x180, 133 .bundle_token_limit = 0x1080, 134 .pagepool = gp100_grctx_generate_pagepool, 135 .pagepool_size = 0x20000, 136 .attrib_cb_size = gp100_grctx_generate_attrib_cb_size, 137 .attrib_cb = gp100_grctx_generate_attrib_cb, 138 .attrib = gp100_grctx_generate_attrib, 139 .attrib_nr_max = 0x660, 140 .attrib_nr = 0x440, 141 .alpha_nr_max = 0xc00, 142 .alpha_nr = 0x800, 143 .sm_id = gm107_grctx_generate_sm_id, 144 .rop_mapping = gf117_grctx_generate_rop_mapping, 145 .dist_skip_table = gm200_grctx_generate_dist_skip_table, 146 .r406500 = gm200_grctx_generate_r406500, 147 .gpc_tpc_nr = gk104_grctx_generate_gpc_tpc_nr, 148 .tpc_mask = gm200_grctx_generate_tpc_mask, 149 .smid_config = gp100_grctx_generate_smid_config, 150 .r419a3c = gm200_grctx_generate_r419a3c, 151}; 152