1214152Sed/*	$NetBSD: nouveau_nvkm_engine_gr_ctxtu102.c,v 1.2 2021/12/18 23:45:36 riastradh Exp $	*/
2214152Sed
3214152Sed/*
4214152Sed * Copyright 2019 Red Hat Inc.
5222656Sed *
6222656Sed * Permission is hereby granted, free of charge, to any person obtaining a
7214152Sed * copy of this software and associated documentation files (the "Software"),
8214152Sed * to deal in the Software without restriction, including without limitation
9214152Sed * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10214152Sed * and/or sell copies of the Software, and to permit persons to whom the
11214152Sed * Software is furnished to do so, subject to the following conditions:
12214152Sed *
13214152Sed * The above copyright notice and this permission notice shall be included in
14214152Sed * all copies or substantial portions of the Software.
15214152Sed *
16214152Sed * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17214152Sed * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18214152Sed * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19214152Sed * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20214152Sed * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21214152Sed * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22214152Sed * OTHER DEALINGS IN THE SOFTWARE.
23214152Sed */
24214152Sed#include <sys/cdefs.h>
25214152Sed__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_gr_ctxtu102.c,v 1.2 2021/12/18 23:45:36 riastradh Exp $");
26214152Sed
27214152Sed#include "ctxgf100.h"
28214152Sed
29214152Sedstatic void
30214152Sedtu102_grctx_generate_r419c0c(struct gf100_gr *gr)
31214152Sed{
32214152Sed	struct nvkm_device *device = gr->base.engine.subdev.device;
33214152Sed	nvkm_mask(device, 0x419c0c, 0x80000000, 0x80000000);
34214152Sed	nvkm_mask(device, 0x40584c, 0x00000008, 0x00000000);
35214152Sed	nvkm_mask(device, 0x400080, 0x00000000, 0x00000000);
36214152Sed}
37214152Sed
38214152Sedstatic void
39214152Sedtu102_grctx_generate_sm_id(struct gf100_gr *gr, int gpc, int tpc, int sm)
40214152Sed{
41229135Sed	struct nvkm_device *device = gr->base.engine.subdev.device;
42214152Sed	nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x608), sm);
43214152Sed	nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x088), sm);
44214152Sed}
45214152Sed
46214152Sedstatic const struct gf100_gr_init
47214152Sedtu102_grctx_init_unknown_bundle_init_0[] = {
48214152Sed	{ 0x00001000,  1, 0x00000001, 0x00000004 },
49214152Sed	{ 0x00002020, 64, 0x00000001, 0x00000000 },
50214152Sed	{ 0x0001e100,  1, 0x00000001, 0x00000001 },
51214152Sed	{}
52214152Sed};
53214152Sed
54214152Sedstatic const struct gf100_gr_pack
55214152Sedtu102_grctx_pack_sw_veid_bundle_init[] = {
56214152Sed	{ gv100_grctx_init_sw_veid_bundle_init_0 },
57214152Sed	{ tu102_grctx_init_unknown_bundle_init_0 },
58214152Sed	{}
59214152Sed};
60214152Sed
61214152Sedstatic void
62214152Sedtu102_grctx_generate_attrib(struct gf100_grctx *info)
63214152Sed{
64214152Sed	const u64 size = 0x80000; /*XXX: educated guess */
65214152Sed	const int s = 8;
66214152Sed	const int b = mmio_vram(info, size, (1 << s), true);
67214152Sed
68214152Sed	gv100_grctx_generate_attrib(info);
69239138Sandrew
70222656Sed	mmio_refn(info, 0x408070, 0x00000000, s, b);
71214152Sed	mmio_wr32(info, 0x408074, size >> s); /*XXX: guess */
72214152Sed	mmio_refn(info, 0x419034, 0x00000000, s, b);
73214152Sed	mmio_wr32(info, 0x408078, 0x00000000);
74214152Sed}
75214152Sed
76214152Sedconst struct gf100_grctx_func
77214152Sedtu102_grctx = {
78214152Sed	.unkn88c = gv100_grctx_unkn88c,
79214152Sed	.main = gf100_grctx_generate_main,
80214152Sed	.unkn = gv100_grctx_generate_unkn,
81214152Sed	.sw_veid_bundle_init = tu102_grctx_pack_sw_veid_bundle_init,
82214152Sed	.bundle = gm107_grctx_generate_bundle,
83214152Sed	.bundle_size = 0x3000,
84214152Sed	.bundle_min_gpm_fifo_depth = 0x180,
85214152Sed	.bundle_token_limit = 0xa80,
86214152Sed	.pagepool = gp100_grctx_generate_pagepool,
87214152Sed	.pagepool_size = 0x20000,
88214152Sed	.attrib = tu102_grctx_generate_attrib,
89214152Sed	.attrib_nr_max = 0x800,
90214152Sed	.attrib_nr = 0x700,
91214152Sed	.alpha_nr_max = 0xc00,
92214152Sed	.alpha_nr = 0x800,
93214152Sed	.gfxp_nr = 0xfa8,
94214152Sed	.sm_id = tu102_grctx_generate_sm_id,
95214152Sed	.skip_pd_num_tpc_per_gpc = true,
96214152Sed	.rop_mapping = gv100_grctx_generate_rop_mapping,
97214152Sed	.r406500 = gm200_grctx_generate_r406500,
98214152Sed	.r400088 = gv100_grctx_generate_r400088,
99214152Sed	.r419c0c = tu102_grctx_generate_r419c0c,
100214152Sed};
101214152Sed