1 /* 2 * Copyright 2016 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 <bskeggs@redhat.com> 23 */ 24 #include "ctxgf100.h" 25 26 #include <subdev/fb.h> 27 28 /******************************************************************************* 29 * PGRAPH context implementation 30 ******************************************************************************/ 31 32 void 33 gp102_grctx_generate_attrib(struct gf100_grctx *info) 34 { 35 struct gf100_gr *gr = info->gr; 36 const struct gf100_grctx_func *grctx = gr->func->grctx; 37 const u32 alpha = grctx->alpha_nr; 38 const u32 attrib = grctx->attrib_nr; 39 const u32 pertpc = 0x20 * (grctx->attrib_nr_max + grctx->alpha_nr_max); 40 const u32 size = roundup(gr->tpc_total * pertpc, 0x80); 41 const int s = 12; 42 const int b = mmio_vram(info, size, (1 << s), false); 43 const int max_batches = 0xffff; 44 u32 ao = 0; 45 u32 bo = ao + grctx->alpha_nr_max * gr->tpc_total; 46 int gpc, ppc, n = 0; 47 48 mmio_refn(info, 0x418810, 0x80000000, s, b); 49 mmio_refn(info, 0x419848, 0x10000000, s, b); 50 mmio_refn(info, 0x419c2c, 0x10000000, s, b); 51 mmio_refn(info, 0x419b00, 0x00000000, s, b); 52 mmio_wr32(info, 0x419b04, 0x80000000 | size >> 7); 53 mmio_wr32(info, 0x405830, attrib); 54 mmio_wr32(info, 0x40585c, alpha); 55 mmio_wr32(info, 0x4064c4, ((alpha / 4) << 16) | max_batches); 56 57 for (gpc = 0; gpc < gr->gpc_nr; gpc++) { 58 for (ppc = 0; ppc < gr->ppc_nr[gpc]; ppc++, n++) { 59 const u32 as = alpha * gr->ppc_tpc_nr[gpc][ppc]; 60 const u32 bs = attrib * gr->ppc_tpc_nr[gpc][ppc]; 61 const u32 u = 0x418ea0 + (n * 0x04); 62 const u32 o = PPC_UNIT(gpc, ppc, 0); 63 const u32 p = GPC_UNIT(gpc, 0xc44 + (ppc * 4)); 64 if (!(gr->ppc_mask[gpc] & (1 << ppc))) 65 continue; 66 mmio_wr32(info, o + 0xc0, bs); 67 mmio_wr32(info, p, bs); 68 mmio_wr32(info, o + 0xf4, bo); 69 mmio_wr32(info, o + 0xf0, bs); 70 bo += grctx->attrib_nr_max * gr->ppc_tpc_nr[gpc][ppc]; 71 mmio_wr32(info, o + 0xe4, as); 72 mmio_wr32(info, o + 0xf8, ao); 73 ao += grctx->alpha_nr_max * gr->ppc_tpc_nr[gpc][ppc]; 74 mmio_wr32(info, u, bs); 75 } 76 } 77 78 mmio_wr32(info, 0x4181e4, 0x00000100); 79 mmio_wr32(info, 0x41befc, 0x00000100); 80 } 81 82 const struct gf100_grctx_func 83 gp102_grctx = { 84 .main = gp100_grctx_generate_main, 85 .unkn = gk104_grctx_generate_unkn, 86 .bundle = gm107_grctx_generate_bundle, 87 .bundle_size = 0x3000, 88 .bundle_min_gpm_fifo_depth = 0x180, 89 .bundle_token_limit = 0x900, 90 .pagepool = gp100_grctx_generate_pagepool, 91 .pagepool_size = 0x20000, 92 .attrib = gp102_grctx_generate_attrib, 93 .attrib_nr_max = 0x5d4, 94 .attrib_nr = 0x320, 95 .alpha_nr_max = 0xc00, 96 .alpha_nr = 0x800, 97 }; 98