Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / gpu / drm / nouveau / nvkm / engine / gr / ctxgk104.c
1 /*
2  * Copyright 2013 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 #include <subdev/mc.h>
28
29 /*******************************************************************************
30  * PGRAPH context register lists
31  ******************************************************************************/
32
33 static const struct gf100_gr_init
34 gk104_grctx_init_icmd_0[] = {
35         { 0x001000,   1, 0x01, 0x00000004 },
36         { 0x000039,   3, 0x01, 0x00000000 },
37         { 0x0000a9,   1, 0x01, 0x0000ffff },
38         { 0x000038,   1, 0x01, 0x0fac6881 },
39         { 0x00003d,   1, 0x01, 0x00000001 },
40         { 0x0000e8,   8, 0x01, 0x00000400 },
41         { 0x000078,   8, 0x01, 0x00000300 },
42         { 0x000050,   1, 0x01, 0x00000011 },
43         { 0x000058,   8, 0x01, 0x00000008 },
44         { 0x000208,   8, 0x01, 0x00000001 },
45         { 0x000081,   1, 0x01, 0x00000001 },
46         { 0x000085,   1, 0x01, 0x00000004 },
47         { 0x000088,   1, 0x01, 0x00000400 },
48         { 0x000090,   1, 0x01, 0x00000300 },
49         { 0x000098,   1, 0x01, 0x00001001 },
50         { 0x0000e3,   1, 0x01, 0x00000001 },
51         { 0x0000da,   1, 0x01, 0x00000001 },
52         { 0x0000f8,   1, 0x01, 0x00000003 },
53         { 0x0000fa,   1, 0x01, 0x00000001 },
54         { 0x00009f,   4, 0x01, 0x0000ffff },
55         { 0x0000b1,   1, 0x01, 0x00000001 },
56         { 0x0000ad,   1, 0x01, 0x0000013e },
57         { 0x0000e1,   1, 0x01, 0x00000010 },
58         { 0x000290,  16, 0x01, 0x00000000 },
59         { 0x0003b0,  16, 0x01, 0x00000000 },
60         { 0x0002a0,  16, 0x01, 0x00000000 },
61         { 0x000420,  16, 0x01, 0x00000000 },
62         { 0x0002b0,  16, 0x01, 0x00000000 },
63         { 0x000430,  16, 0x01, 0x00000000 },
64         { 0x0002c0,  16, 0x01, 0x00000000 },
65         { 0x0004d0,  16, 0x01, 0x00000000 },
66         { 0x000720,  16, 0x01, 0x00000000 },
67         { 0x0008c0,  16, 0x01, 0x00000000 },
68         { 0x000890,  16, 0x01, 0x00000000 },
69         { 0x0008e0,  16, 0x01, 0x00000000 },
70         { 0x0008a0,  16, 0x01, 0x00000000 },
71         { 0x0008f0,  16, 0x01, 0x00000000 },
72         { 0x00094c,   1, 0x01, 0x000000ff },
73         { 0x00094d,   1, 0x01, 0xffffffff },
74         { 0x00094e,   1, 0x01, 0x00000002 },
75         { 0x0002ec,   1, 0x01, 0x00000001 },
76         { 0x000303,   1, 0x01, 0x00000001 },
77         { 0x0002e6,   1, 0x01, 0x00000001 },
78         { 0x000466,   1, 0x01, 0x00000052 },
79         { 0x000301,   1, 0x01, 0x3f800000 },
80         { 0x000304,   1, 0x01, 0x30201000 },
81         { 0x000305,   1, 0x01, 0x70605040 },
82         { 0x000306,   1, 0x01, 0xb8a89888 },
83         { 0x000307,   1, 0x01, 0xf8e8d8c8 },
84         { 0x00030a,   1, 0x01, 0x00ffff00 },
85         { 0x00030b,   1, 0x01, 0x0000001a },
86         { 0x00030c,   1, 0x01, 0x00000001 },
87         { 0x000318,   1, 0x01, 0x00000001 },
88         { 0x000340,   1, 0x01, 0x00000000 },
89         { 0x000375,   1, 0x01, 0x00000001 },
90         { 0x00037d,   1, 0x01, 0x00000006 },
91         { 0x0003a0,   1, 0x01, 0x00000002 },
92         { 0x0003aa,   1, 0x01, 0x00000001 },
93         { 0x0003a9,   1, 0x01, 0x00000001 },
94         { 0x000380,   1, 0x01, 0x00000001 },
95         { 0x000383,   1, 0x01, 0x00000011 },
96         { 0x000360,   1, 0x01, 0x00000040 },
97         { 0x000366,   2, 0x01, 0x00000000 },
98         { 0x000368,   1, 0x01, 0x00000fff },
99         { 0x000370,   2, 0x01, 0x00000000 },
100         { 0x000372,   1, 0x01, 0x000fffff },
101         { 0x00037a,   1, 0x01, 0x00000012 },
102         { 0x000619,   1, 0x01, 0x00000003 },
103         { 0x000811,   1, 0x01, 0x00000003 },
104         { 0x000812,   1, 0x01, 0x00000004 },
105         { 0x000813,   1, 0x01, 0x00000006 },
106         { 0x000814,   1, 0x01, 0x00000008 },
107         { 0x000815,   1, 0x01, 0x0000000b },
108         { 0x000800,   6, 0x01, 0x00000001 },
109         { 0x000632,   1, 0x01, 0x00000001 },
110         { 0x000633,   1, 0x01, 0x00000002 },
111         { 0x000634,   1, 0x01, 0x00000003 },
112         { 0x000635,   1, 0x01, 0x00000004 },
113         { 0x000654,   1, 0x01, 0x3f800000 },
114         { 0x000657,   1, 0x01, 0x3f800000 },
115         { 0x000655,   2, 0x01, 0x3f800000 },
116         { 0x0006cd,   1, 0x01, 0x3f800000 },
117         { 0x0007f5,   1, 0x01, 0x3f800000 },
118         { 0x0007dc,   1, 0x01, 0x39291909 },
119         { 0x0007dd,   1, 0x01, 0x79695949 },
120         { 0x0007de,   1, 0x01, 0xb9a99989 },
121         { 0x0007df,   1, 0x01, 0xf9e9d9c9 },
122         { 0x0007e8,   1, 0x01, 0x00003210 },
123         { 0x0007e9,   1, 0x01, 0x00007654 },
124         { 0x0007ea,   1, 0x01, 0x00000098 },
125         { 0x0007ec,   1, 0x01, 0x39291909 },
126         { 0x0007ed,   1, 0x01, 0x79695949 },
127         { 0x0007ee,   1, 0x01, 0xb9a99989 },
128         { 0x0007ef,   1, 0x01, 0xf9e9d9c9 },
129         { 0x0007f0,   1, 0x01, 0x00003210 },
130         { 0x0007f1,   1, 0x01, 0x00007654 },
131         { 0x0007f2,   1, 0x01, 0x00000098 },
132         { 0x0005a5,   1, 0x01, 0x00000001 },
133         { 0x000980, 128, 0x01, 0x00000000 },
134         { 0x000468,   1, 0x01, 0x00000004 },
135         { 0x00046c,   1, 0x01, 0x00000001 },
136         { 0x000470,  96, 0x01, 0x00000000 },
137         { 0x000510,  16, 0x01, 0x3f800000 },
138         { 0x000520,   1, 0x01, 0x000002b6 },
139         { 0x000529,   1, 0x01, 0x00000001 },
140         { 0x000530,  16, 0x01, 0xffff0000 },
141         { 0x000585,   1, 0x01, 0x0000003f },
142         { 0x000576,   1, 0x01, 0x00000003 },
143         { 0x00057b,   1, 0x01, 0x00000059 },
144         { 0x000586,   1, 0x01, 0x00000040 },
145         { 0x000582,   2, 0x01, 0x00000080 },
146         { 0x0005c2,   1, 0x01, 0x00000001 },
147         { 0x000638,   2, 0x01, 0x00000001 },
148         { 0x00063a,   1, 0x01, 0x00000002 },
149         { 0x00063b,   2, 0x01, 0x00000001 },
150         { 0x00063d,   1, 0x01, 0x00000002 },
151         { 0x00063e,   1, 0x01, 0x00000001 },
152         { 0x0008b8,   8, 0x01, 0x00000001 },
153         { 0x000900,   8, 0x01, 0x00000001 },
154         { 0x000908,   8, 0x01, 0x00000002 },
155         { 0x000910,  16, 0x01, 0x00000001 },
156         { 0x000920,   8, 0x01, 0x00000002 },
157         { 0x000928,   8, 0x01, 0x00000001 },
158         { 0x000648,   9, 0x01, 0x00000001 },
159         { 0x000658,   1, 0x01, 0x0000000f },
160         { 0x0007ff,   1, 0x01, 0x0000000a },
161         { 0x00066a,   1, 0x01, 0x40000000 },
162         { 0x00066b,   1, 0x01, 0x10000000 },
163         { 0x00066c,   2, 0x01, 0xffff0000 },
164         { 0x0007af,   2, 0x01, 0x00000008 },
165         { 0x0007f6,   1, 0x01, 0x00000001 },
166         { 0x0006b2,   1, 0x01, 0x00000055 },
167         { 0x0007ad,   1, 0x01, 0x00000003 },
168         { 0x000937,   1, 0x01, 0x00000001 },
169         { 0x000971,   1, 0x01, 0x00000008 },
170         { 0x000972,   1, 0x01, 0x00000040 },
171         { 0x000973,   1, 0x01, 0x0000012c },
172         { 0x00097c,   1, 0x01, 0x00000040 },
173         { 0x000979,   1, 0x01, 0x00000003 },
174         { 0x000975,   1, 0x01, 0x00000020 },
175         { 0x000976,   1, 0x01, 0x00000001 },
176         { 0x000977,   1, 0x01, 0x00000020 },
177         { 0x000978,   1, 0x01, 0x00000001 },
178         { 0x000957,   1, 0x01, 0x00000003 },
179         { 0x00095e,   1, 0x01, 0x20164010 },
180         { 0x00095f,   1, 0x01, 0x00000020 },
181         { 0x00097d,   1, 0x01, 0x00000020 },
182         { 0x000683,   1, 0x01, 0x00000006 },
183         { 0x000685,   1, 0x01, 0x003fffff },
184         { 0x000687,   1, 0x01, 0x003fffff },
185         { 0x0006a0,   1, 0x01, 0x00000005 },
186         { 0x000840,   1, 0x01, 0x00400008 },
187         { 0x000841,   1, 0x01, 0x08000080 },
188         { 0x000842,   1, 0x01, 0x00400008 },
189         { 0x000843,   1, 0x01, 0x08000080 },
190         { 0x0006aa,   1, 0x01, 0x00000001 },
191         { 0x0006ab,   1, 0x01, 0x00000002 },
192         { 0x0006ac,   1, 0x01, 0x00000080 },
193         { 0x0006ad,   2, 0x01, 0x00000100 },
194         { 0x0006b1,   1, 0x01, 0x00000011 },
195         { 0x0006bb,   1, 0x01, 0x000000cf },
196         { 0x0006ce,   1, 0x01, 0x2a712488 },
197         { 0x000739,   1, 0x01, 0x4085c000 },
198         { 0x00073a,   1, 0x01, 0x00000080 },
199         { 0x000786,   1, 0x01, 0x80000100 },
200         { 0x00073c,   1, 0x01, 0x00010100 },
201         { 0x00073d,   1, 0x01, 0x02800000 },
202         { 0x000787,   1, 0x01, 0x000000cf },
203         { 0x00078c,   1, 0x01, 0x00000008 },
204         { 0x000792,   1, 0x01, 0x00000001 },
205         { 0x000794,   3, 0x01, 0x00000001 },
206         { 0x000797,   1, 0x01, 0x000000cf },
207         { 0x000836,   1, 0x01, 0x00000001 },
208         { 0x00079a,   1, 0x01, 0x00000002 },
209         { 0x000833,   1, 0x01, 0x04444480 },
210         { 0x0007a1,   1, 0x01, 0x00000001 },
211         { 0x0007a3,   3, 0x01, 0x00000001 },
212         { 0x000831,   1, 0x01, 0x00000004 },
213         { 0x000b07,   1, 0x01, 0x00000002 },
214         { 0x000b08,   2, 0x01, 0x00000100 },
215         { 0x000b0a,   1, 0x01, 0x00000001 },
216         { 0x000a04,   1, 0x01, 0x000000ff },
217         { 0x000a0b,   1, 0x01, 0x00000040 },
218         { 0x00097f,   1, 0x01, 0x00000100 },
219         { 0x000a02,   1, 0x01, 0x00000001 },
220         { 0x000809,   1, 0x01, 0x00000007 },
221         { 0x00c221,   1, 0x01, 0x00000040 },
222         { 0x00c1b0,   8, 0x01, 0x0000000f },
223         { 0x00c1b8,   1, 0x01, 0x0fac6881 },
224         { 0x00c1b9,   1, 0x01, 0x00fac688 },
225         { 0x00c401,   1, 0x01, 0x00000001 },
226         { 0x00c402,   1, 0x01, 0x00010001 },
227         { 0x00c403,   2, 0x01, 0x00000001 },
228         { 0x00c40e,   1, 0x01, 0x00000020 },
229         { 0x00c500,   1, 0x01, 0x00000003 },
230         { 0x01e100,   1, 0x01, 0x00000001 },
231         { 0x001000,   1, 0x01, 0x00000002 },
232         { 0x0006aa,   1, 0x01, 0x00000001 },
233         { 0x0006ad,   2, 0x01, 0x00000100 },
234         { 0x0006b1,   1, 0x01, 0x00000011 },
235         { 0x00078c,   1, 0x01, 0x00000008 },
236         { 0x000792,   1, 0x01, 0x00000001 },
237         { 0x000794,   3, 0x01, 0x00000001 },
238         { 0x000797,   1, 0x01, 0x000000cf },
239         { 0x00079a,   1, 0x01, 0x00000002 },
240         { 0x000833,   1, 0x01, 0x04444480 },
241         { 0x0007a1,   1, 0x01, 0x00000001 },
242         { 0x0007a3,   3, 0x01, 0x00000001 },
243         { 0x000831,   1, 0x01, 0x00000004 },
244         { 0x01e100,   1, 0x01, 0x00000001 },
245         { 0x001000,   1, 0x01, 0x00000008 },
246         { 0x000039,   3, 0x01, 0x00000000 },
247         { 0x000380,   1, 0x01, 0x00000001 },
248         { 0x000366,   2, 0x01, 0x00000000 },
249         { 0x000368,   1, 0x01, 0x00000fff },
250         { 0x000370,   2, 0x01, 0x00000000 },
251         { 0x000372,   1, 0x01, 0x000fffff },
252         { 0x000813,   1, 0x01, 0x00000006 },
253         { 0x000814,   1, 0x01, 0x00000008 },
254         { 0x000957,   1, 0x01, 0x00000003 },
255         { 0x000b07,   1, 0x01, 0x00000002 },
256         { 0x000b08,   2, 0x01, 0x00000100 },
257         { 0x000b0a,   1, 0x01, 0x00000001 },
258         { 0x000a04,   1, 0x01, 0x000000ff },
259         { 0x00097f,   1, 0x01, 0x00000100 },
260         { 0x000a02,   1, 0x01, 0x00000001 },
261         { 0x000809,   1, 0x01, 0x00000007 },
262         { 0x00c221,   1, 0x01, 0x00000040 },
263         { 0x00c401,   1, 0x01, 0x00000001 },
264         { 0x00c402,   1, 0x01, 0x00010001 },
265         { 0x00c403,   2, 0x01, 0x00000001 },
266         { 0x00c40e,   1, 0x01, 0x00000020 },
267         { 0x00c500,   1, 0x01, 0x00000003 },
268         { 0x01e100,   1, 0x01, 0x00000001 },
269         { 0x001000,   1, 0x01, 0x00000001 },
270         { 0x000b07,   1, 0x01, 0x00000002 },
271         { 0x000b08,   2, 0x01, 0x00000100 },
272         { 0x000b0a,   1, 0x01, 0x00000001 },
273         { 0x01e100,   1, 0x01, 0x00000001 },
274         {}
275 };
276
277 const struct gf100_gr_pack
278 gk104_grctx_pack_icmd[] = {
279         { gk104_grctx_init_icmd_0 },
280         {}
281 };
282
283 const struct gf100_gr_init
284 gk104_grctx_init_a097_0[] = {
285         { 0x000800,   8, 0x40, 0x00000000 },
286         { 0x000804,   8, 0x40, 0x00000000 },
287         { 0x000808,   8, 0x40, 0x00000400 },
288         { 0x00080c,   8, 0x40, 0x00000300 },
289         { 0x000810,   1, 0x04, 0x000000cf },
290         { 0x000850,   7, 0x40, 0x00000000 },
291         { 0x000814,   8, 0x40, 0x00000040 },
292         { 0x000818,   8, 0x40, 0x00000001 },
293         { 0x00081c,   8, 0x40, 0x00000000 },
294         { 0x000820,   8, 0x40, 0x00000000 },
295         { 0x001c00,  16, 0x10, 0x00000000 },
296         { 0x001c04,  16, 0x10, 0x00000000 },
297         { 0x001c08,  16, 0x10, 0x00000000 },
298         { 0x001c0c,  16, 0x10, 0x00000000 },
299         { 0x001d00,  16, 0x10, 0x00000000 },
300         { 0x001d04,  16, 0x10, 0x00000000 },
301         { 0x001d08,  16, 0x10, 0x00000000 },
302         { 0x001d0c,  16, 0x10, 0x00000000 },
303         { 0x001f00,  16, 0x08, 0x00000000 },
304         { 0x001f04,  16, 0x08, 0x00000000 },
305         { 0x001f80,  16, 0x08, 0x00000000 },
306         { 0x001f84,  16, 0x08, 0x00000000 },
307         { 0x002000,   1, 0x04, 0x00000000 },
308         { 0x002040,   1, 0x04, 0x00000011 },
309         { 0x002080,   1, 0x04, 0x00000020 },
310         { 0x0020c0,   1, 0x04, 0x00000030 },
311         { 0x002100,   1, 0x04, 0x00000040 },
312         { 0x002140,   1, 0x04, 0x00000051 },
313         { 0x00200c,   6, 0x40, 0x00000001 },
314         { 0x002010,   1, 0x04, 0x00000000 },
315         { 0x002050,   1, 0x04, 0x00000000 },
316         { 0x002090,   1, 0x04, 0x00000001 },
317         { 0x0020d0,   1, 0x04, 0x00000002 },
318         { 0x002110,   1, 0x04, 0x00000003 },
319         { 0x002150,   1, 0x04, 0x00000004 },
320         { 0x000380,   4, 0x20, 0x00000000 },
321         { 0x000384,   4, 0x20, 0x00000000 },
322         { 0x000388,   4, 0x20, 0x00000000 },
323         { 0x00038c,   4, 0x20, 0x00000000 },
324         { 0x000700,   4, 0x10, 0x00000000 },
325         { 0x000704,   4, 0x10, 0x00000000 },
326         { 0x000708,   4, 0x10, 0x00000000 },
327         { 0x002800, 128, 0x04, 0x00000000 },
328         { 0x000a00,  16, 0x20, 0x00000000 },
329         { 0x000a04,  16, 0x20, 0x00000000 },
330         { 0x000a08,  16, 0x20, 0x00000000 },
331         { 0x000a0c,  16, 0x20, 0x00000000 },
332         { 0x000a10,  16, 0x20, 0x00000000 },
333         { 0x000a14,  16, 0x20, 0x00000000 },
334         { 0x000c00,  16, 0x10, 0x00000000 },
335         { 0x000c04,  16, 0x10, 0x00000000 },
336         { 0x000c08,  16, 0x10, 0x00000000 },
337         { 0x000c0c,  16, 0x10, 0x3f800000 },
338         { 0x000d00,   8, 0x08, 0xffff0000 },
339         { 0x000d04,   8, 0x08, 0xffff0000 },
340         { 0x000e00,  16, 0x10, 0x00000000 },
341         { 0x000e04,  16, 0x10, 0xffff0000 },
342         { 0x000e08,  16, 0x10, 0xffff0000 },
343         { 0x000d40,   4, 0x08, 0x00000000 },
344         { 0x000d44,   4, 0x08, 0x00000000 },
345         { 0x001e00,   8, 0x20, 0x00000001 },
346         { 0x001e04,   8, 0x20, 0x00000001 },
347         { 0x001e08,   8, 0x20, 0x00000002 },
348         { 0x001e0c,   8, 0x20, 0x00000001 },
349         { 0x001e10,   8, 0x20, 0x00000001 },
350         { 0x001e14,   8, 0x20, 0x00000002 },
351         { 0x001e18,   8, 0x20, 0x00000001 },
352         { 0x003400, 128, 0x04, 0x00000000 },
353         { 0x00030c,   1, 0x04, 0x00000001 },
354         { 0x001944,   1, 0x04, 0x00000000 },
355         { 0x001514,   1, 0x04, 0x00000000 },
356         { 0x000d68,   1, 0x04, 0x0000ffff },
357         { 0x00121c,   1, 0x04, 0x0fac6881 },
358         { 0x000fac,   1, 0x04, 0x00000001 },
359         { 0x001538,   1, 0x04, 0x00000001 },
360         { 0x000fe0,   2, 0x04, 0x00000000 },
361         { 0x000fe8,   1, 0x04, 0x00000014 },
362         { 0x000fec,   1, 0x04, 0x00000040 },
363         { 0x000ff0,   1, 0x04, 0x00000000 },
364         { 0x00179c,   1, 0x04, 0x00000000 },
365         { 0x001228,   1, 0x04, 0x00000400 },
366         { 0x00122c,   1, 0x04, 0x00000300 },
367         { 0x001230,   1, 0x04, 0x00010001 },
368         { 0x0007f8,   1, 0x04, 0x00000000 },
369         { 0x0015b4,   1, 0x04, 0x00000001 },
370         { 0x0015cc,   1, 0x04, 0x00000000 },
371         { 0x001534,   1, 0x04, 0x00000000 },
372         { 0x000fb0,   1, 0x04, 0x00000000 },
373         { 0x0015d0,   1, 0x04, 0x00000000 },
374         { 0x00153c,   1, 0x04, 0x00000000 },
375         { 0x0016b4,   1, 0x04, 0x00000003 },
376         { 0x000fbc,   4, 0x04, 0x0000ffff },
377         { 0x000df8,   2, 0x04, 0x00000000 },
378         { 0x001948,   1, 0x04, 0x00000000 },
379         { 0x001970,   1, 0x04, 0x00000001 },
380         { 0x00161c,   1, 0x04, 0x000009f0 },
381         { 0x000dcc,   1, 0x04, 0x00000010 },
382         { 0x00163c,   1, 0x04, 0x00000000 },
383         { 0x0015e4,   1, 0x04, 0x00000000 },
384         { 0x001160,  32, 0x04, 0x25e00040 },
385         { 0x001880,  32, 0x04, 0x00000000 },
386         { 0x000f84,   2, 0x04, 0x00000000 },
387         { 0x0017c8,   2, 0x04, 0x00000000 },
388         { 0x0017d0,   1, 0x04, 0x000000ff },
389         { 0x0017d4,   1, 0x04, 0xffffffff },
390         { 0x0017d8,   1, 0x04, 0x00000002 },
391         { 0x0017dc,   1, 0x04, 0x00000000 },
392         { 0x0015f4,   2, 0x04, 0x00000000 },
393         { 0x001434,   2, 0x04, 0x00000000 },
394         { 0x000d74,   1, 0x04, 0x00000000 },
395         { 0x000dec,   1, 0x04, 0x00000001 },
396         { 0x0013a4,   1, 0x04, 0x00000000 },
397         { 0x001318,   1, 0x04, 0x00000001 },
398         { 0x001644,   1, 0x04, 0x00000000 },
399         { 0x000748,   1, 0x04, 0x00000000 },
400         { 0x000de8,   1, 0x04, 0x00000000 },
401         { 0x001648,   1, 0x04, 0x00000000 },
402         { 0x0012a4,   1, 0x04, 0x00000000 },
403         { 0x001120,   4, 0x04, 0x00000000 },
404         { 0x001118,   1, 0x04, 0x00000000 },
405         { 0x00164c,   1, 0x04, 0x00000000 },
406         { 0x001658,   1, 0x04, 0x00000000 },
407         { 0x001910,   1, 0x04, 0x00000290 },
408         { 0x001518,   1, 0x04, 0x00000000 },
409         { 0x00165c,   1, 0x04, 0x00000001 },
410         { 0x001520,   1, 0x04, 0x00000000 },
411         { 0x001604,   1, 0x04, 0x00000000 },
412         { 0x001570,   1, 0x04, 0x00000000 },
413         { 0x0013b0,   2, 0x04, 0x3f800000 },
414         { 0x00020c,   1, 0x04, 0x00000000 },
415         { 0x001670,   1, 0x04, 0x30201000 },
416         { 0x001674,   1, 0x04, 0x70605040 },
417         { 0x001678,   1, 0x04, 0xb8a89888 },
418         { 0x00167c,   1, 0x04, 0xf8e8d8c8 },
419         { 0x00166c,   1, 0x04, 0x00000000 },
420         { 0x001680,   1, 0x04, 0x00ffff00 },
421         { 0x0012d0,   1, 0x04, 0x00000003 },
422         { 0x0012d4,   1, 0x04, 0x00000002 },
423         { 0x001684,   2, 0x04, 0x00000000 },
424         { 0x000dac,   2, 0x04, 0x00001b02 },
425         { 0x000db4,   1, 0x04, 0x00000000 },
426         { 0x00168c,   1, 0x04, 0x00000000 },
427         { 0x0015bc,   1, 0x04, 0x00000000 },
428         { 0x00156c,   1, 0x04, 0x00000000 },
429         { 0x00187c,   1, 0x04, 0x00000000 },
430         { 0x001110,   1, 0x04, 0x00000001 },
431         { 0x000dc0,   3, 0x04, 0x00000000 },
432         { 0x001234,   1, 0x04, 0x00000000 },
433         { 0x001690,   1, 0x04, 0x00000000 },
434         { 0x0012ac,   1, 0x04, 0x00000001 },
435         { 0x000790,   5, 0x04, 0x00000000 },
436         { 0x00077c,   1, 0x04, 0x00000000 },
437         { 0x001000,   1, 0x04, 0x00000010 },
438         { 0x0010fc,   1, 0x04, 0x00000000 },
439         { 0x001290,   1, 0x04, 0x00000000 },
440         { 0x000218,   1, 0x04, 0x00000010 },
441         { 0x0012d8,   1, 0x04, 0x00000000 },
442         { 0x0012dc,   1, 0x04, 0x00000010 },
443         { 0x000d94,   1, 0x04, 0x00000001 },
444         { 0x00155c,   2, 0x04, 0x00000000 },
445         { 0x001564,   1, 0x04, 0x00000fff },
446         { 0x001574,   2, 0x04, 0x00000000 },
447         { 0x00157c,   1, 0x04, 0x000fffff },
448         { 0x001354,   1, 0x04, 0x00000000 },
449         { 0x001610,   1, 0x04, 0x00000012 },
450         { 0x001608,   2, 0x04, 0x00000000 },
451         { 0x00260c,   1, 0x04, 0x00000000 },
452         { 0x0007ac,   1, 0x04, 0x00000000 },
453         { 0x00162c,   1, 0x04, 0x00000003 },
454         { 0x000210,   1, 0x04, 0x00000000 },
455         { 0x000320,   1, 0x04, 0x00000000 },
456         { 0x000324,   6, 0x04, 0x3f800000 },
457         { 0x000750,   1, 0x04, 0x00000000 },
458         { 0x000760,   1, 0x04, 0x39291909 },
459         { 0x000764,   1, 0x04, 0x79695949 },
460         { 0x000768,   1, 0x04, 0xb9a99989 },
461         { 0x00076c,   1, 0x04, 0xf9e9d9c9 },
462         { 0x000770,   1, 0x04, 0x30201000 },
463         { 0x000774,   1, 0x04, 0x70605040 },
464         { 0x000778,   1, 0x04, 0x00009080 },
465         { 0x000780,   1, 0x04, 0x39291909 },
466         { 0x000784,   1, 0x04, 0x79695949 },
467         { 0x000788,   1, 0x04, 0xb9a99989 },
468         { 0x00078c,   1, 0x04, 0xf9e9d9c9 },
469         { 0x0007d0,   1, 0x04, 0x30201000 },
470         { 0x0007d4,   1, 0x04, 0x70605040 },
471         { 0x0007d8,   1, 0x04, 0x00009080 },
472         { 0x00037c,   1, 0x04, 0x00000001 },
473         { 0x000740,   2, 0x04, 0x00000000 },
474         { 0x002600,   1, 0x04, 0x00000000 },
475         { 0x001918,   1, 0x04, 0x00000000 },
476         { 0x00191c,   1, 0x04, 0x00000900 },
477         { 0x001920,   1, 0x04, 0x00000405 },
478         { 0x001308,   1, 0x04, 0x00000001 },
479         { 0x001924,   1, 0x04, 0x00000000 },
480         { 0x0013ac,   1, 0x04, 0x00000000 },
481         { 0x00192c,   1, 0x04, 0x00000001 },
482         { 0x00193c,   1, 0x04, 0x00002c1c },
483         { 0x000d7c,   1, 0x04, 0x00000000 },
484         { 0x000f8c,   1, 0x04, 0x00000000 },
485         { 0x0002c0,   1, 0x04, 0x00000001 },
486         { 0x001510,   1, 0x04, 0x00000000 },
487         { 0x001940,   1, 0x04, 0x00000000 },
488         { 0x000ff4,   2, 0x04, 0x00000000 },
489         { 0x00194c,   2, 0x04, 0x00000000 },
490         { 0x001968,   1, 0x04, 0x00000000 },
491         { 0x001590,   1, 0x04, 0x0000003f },
492         { 0x0007e8,   4, 0x04, 0x00000000 },
493         { 0x00196c,   1, 0x04, 0x00000011 },
494         { 0x0002e4,   1, 0x04, 0x0000b001 },
495         { 0x00036c,   2, 0x04, 0x00000000 },
496         { 0x00197c,   1, 0x04, 0x00000000 },
497         { 0x000fcc,   2, 0x04, 0x00000000 },
498         { 0x0002d8,   1, 0x04, 0x00000040 },
499         { 0x001980,   1, 0x04, 0x00000080 },
500         { 0x001504,   1, 0x04, 0x00000080 },
501         { 0x001984,   1, 0x04, 0x00000000 },
502         { 0x000300,   1, 0x04, 0x00000001 },
503         { 0x0013a8,   1, 0x04, 0x00000000 },
504         { 0x0012ec,   1, 0x04, 0x00000000 },
505         { 0x001310,   1, 0x04, 0x00000000 },
506         { 0x001314,   1, 0x04, 0x00000001 },
507         { 0x001380,   1, 0x04, 0x00000000 },
508         { 0x001384,   4, 0x04, 0x00000001 },
509         { 0x001394,   1, 0x04, 0x00000000 },
510         { 0x00139c,   1, 0x04, 0x00000000 },
511         { 0x001398,   1, 0x04, 0x00000000 },
512         { 0x001594,   1, 0x04, 0x00000000 },
513         { 0x001598,   4, 0x04, 0x00000001 },
514         { 0x000f54,   3, 0x04, 0x00000000 },
515         { 0x0019bc,   1, 0x04, 0x00000000 },
516         { 0x000f9c,   2, 0x04, 0x00000000 },
517         { 0x0012cc,   1, 0x04, 0x00000000 },
518         { 0x0012e8,   1, 0x04, 0x00000000 },
519         { 0x00130c,   1, 0x04, 0x00000001 },
520         { 0x001360,   8, 0x04, 0x00000000 },
521         { 0x00133c,   2, 0x04, 0x00000001 },
522         { 0x001344,   1, 0x04, 0x00000002 },
523         { 0x001348,   2, 0x04, 0x00000001 },
524         { 0x001350,   1, 0x04, 0x00000002 },
525         { 0x001358,   1, 0x04, 0x00000001 },
526         { 0x0012e4,   1, 0x04, 0x00000000 },
527         { 0x00131c,   4, 0x04, 0x00000000 },
528         { 0x0019c0,   1, 0x04, 0x00000000 },
529         { 0x001140,   1, 0x04, 0x00000000 },
530         { 0x0019c4,   1, 0x04, 0x00000000 },
531         { 0x0019c8,   1, 0x04, 0x00001500 },
532         { 0x00135c,   1, 0x04, 0x00000000 },
533         { 0x000f90,   1, 0x04, 0x00000000 },
534         { 0x0019e0,   8, 0x04, 0x00000001 },
535         { 0x0019cc,   1, 0x04, 0x00000001 },
536         { 0x0015b8,   1, 0x04, 0x00000000 },
537         { 0x001a00,   1, 0x04, 0x00001111 },
538         { 0x001a04,   7, 0x04, 0x00000000 },
539         { 0x000d6c,   2, 0x04, 0xffff0000 },
540         { 0x0010f8,   1, 0x04, 0x00001010 },
541         { 0x000d80,   5, 0x04, 0x00000000 },
542         { 0x000da0,   1, 0x04, 0x00000000 },
543         { 0x0007a4,   2, 0x04, 0x00000000 },
544         { 0x001508,   1, 0x04, 0x80000000 },
545         { 0x00150c,   1, 0x04, 0x40000000 },
546         { 0x001668,   1, 0x04, 0x00000000 },
547         { 0x000318,   2, 0x04, 0x00000008 },
548         { 0x000d9c,   1, 0x04, 0x00000001 },
549         { 0x000374,   1, 0x04, 0x00000000 },
550         { 0x000378,   1, 0x04, 0x00000020 },
551         { 0x0007dc,   1, 0x04, 0x00000000 },
552         { 0x00074c,   1, 0x04, 0x00000055 },
553         { 0x001420,   1, 0x04, 0x00000003 },
554         { 0x0017bc,   2, 0x04, 0x00000000 },
555         { 0x0017c4,   1, 0x04, 0x00000001 },
556         { 0x001008,   1, 0x04, 0x00000008 },
557         { 0x00100c,   1, 0x04, 0x00000040 },
558         { 0x001010,   1, 0x04, 0x0000012c },
559         { 0x000d60,   1, 0x04, 0x00000040 },
560         { 0x00075c,   1, 0x04, 0x00000003 },
561         { 0x001018,   1, 0x04, 0x00000020 },
562         { 0x00101c,   1, 0x04, 0x00000001 },
563         { 0x001020,   1, 0x04, 0x00000020 },
564         { 0x001024,   1, 0x04, 0x00000001 },
565         { 0x001444,   3, 0x04, 0x00000000 },
566         { 0x000360,   1, 0x04, 0x20164010 },
567         { 0x000364,   1, 0x04, 0x00000020 },
568         { 0x000368,   1, 0x04, 0x00000000 },
569         { 0x000de4,   1, 0x04, 0x00000000 },
570         { 0x000204,   1, 0x04, 0x00000006 },
571         { 0x000208,   1, 0x04, 0x00000000 },
572         { 0x0002cc,   2, 0x04, 0x003fffff },
573         { 0x001220,   1, 0x04, 0x00000005 },
574         { 0x000fdc,   1, 0x04, 0x00000000 },
575         { 0x000f98,   1, 0x04, 0x00400008 },
576         { 0x001284,   1, 0x04, 0x08000080 },
577         { 0x001450,   1, 0x04, 0x00400008 },
578         { 0x001454,   1, 0x04, 0x08000080 },
579         { 0x000214,   1, 0x04, 0x00000000 },
580         {}
581 };
582
583 static const struct gf100_gr_pack
584 gk104_grctx_pack_mthd[] = {
585         { gk104_grctx_init_a097_0, 0xa097 },
586         { gf100_grctx_init_902d_0, 0x902d },
587         {}
588 };
589
590 static const struct gf100_gr_init
591 gk104_grctx_init_fe_0[] = {
592         { 0x404010,   5, 0x04, 0x00000000 },
593         { 0x404024,   1, 0x04, 0x0000e000 },
594         { 0x404028,   1, 0x04, 0x00000000 },
595         { 0x4040a8,   8, 0x04, 0x00000000 },
596         { 0x4040c8,   1, 0x04, 0xf800008f },
597         { 0x4040d0,   6, 0x04, 0x00000000 },
598         { 0x4040e8,   1, 0x04, 0x00001000 },
599         { 0x4040f8,   1, 0x04, 0x00000000 },
600         { 0x404130,   2, 0x04, 0x00000000 },
601         { 0x404138,   1, 0x04, 0x20000040 },
602         { 0x404150,   1, 0x04, 0x0000002e },
603         { 0x404154,   1, 0x04, 0x00000400 },
604         { 0x404158,   1, 0x04, 0x00000200 },
605         { 0x404164,   1, 0x04, 0x00000055 },
606         { 0x4041a0,   4, 0x04, 0x00000000 },
607         { 0x404200,   4, 0x04, 0x00000000 },
608         {}
609 };
610
611 const struct gf100_gr_init
612 gk104_grctx_init_memfmt_0[] = {
613         { 0x404604,   1, 0x04, 0x00000014 },
614         { 0x404608,   1, 0x04, 0x00000000 },
615         { 0x40460c,   1, 0x04, 0x00003fff },
616         { 0x404610,   1, 0x04, 0x00000100 },
617         { 0x404618,   4, 0x04, 0x00000000 },
618         { 0x40462c,   2, 0x04, 0x00000000 },
619         { 0x404640,   1, 0x04, 0x00000000 },
620         { 0x404654,   1, 0x04, 0x00000000 },
621         { 0x404660,   1, 0x04, 0x00000000 },
622         { 0x404678,   1, 0x04, 0x00000000 },
623         { 0x40467c,   1, 0x04, 0x00000002 },
624         { 0x404680,   8, 0x04, 0x00000000 },
625         { 0x4046a0,   1, 0x04, 0x007f0080 },
626         { 0x4046a4,   8, 0x04, 0x00000000 },
627         { 0x4046c8,   3, 0x04, 0x00000000 },
628         { 0x404700,   3, 0x04, 0x00000000 },
629         { 0x404718,   7, 0x04, 0x00000000 },
630         { 0x404734,   1, 0x04, 0x00000100 },
631         { 0x404738,   2, 0x04, 0x00000000 },
632         { 0x404744,   2, 0x04, 0x00000000 },
633         { 0x404754,   1, 0x04, 0x00000000 },
634         {}
635 };
636
637 const struct gf100_gr_init
638 gk104_grctx_init_ds_0[] = {
639         { 0x405800,   1, 0x04, 0x0f8000bf },
640         { 0x405830,   1, 0x04, 0x02180648 },
641         { 0x405834,   1, 0x04, 0x08000000 },
642         { 0x405838,   1, 0x04, 0x00000000 },
643         { 0x405854,   1, 0x04, 0x00000000 },
644         { 0x405870,   4, 0x04, 0x00000001 },
645         { 0x405a00,   2, 0x04, 0x00000000 },
646         { 0x405a18,   1, 0x04, 0x00000000 },
647         {}
648 };
649
650 static const struct gf100_gr_init
651 gk104_grctx_init_cwd_0[] = {
652         { 0x405b00,   1, 0x04, 0x00000000 },
653         { 0x405b10,   1, 0x04, 0x00001000 },
654         {}
655 };
656
657 static const struct gf100_gr_init
658 gk104_grctx_init_pd_0[] = {
659         { 0x406020,   1, 0x04, 0x004103c1 },
660         { 0x406028,   4, 0x04, 0x00000001 },
661         { 0x4064a8,   1, 0x04, 0x00000000 },
662         { 0x4064ac,   1, 0x04, 0x00003fff },
663         { 0x4064b4,   2, 0x04, 0x00000000 },
664         { 0x4064c0,   1, 0x04, 0x801a00f0 },
665         { 0x4064c4,   1, 0x04, 0x0192ffff },
666         { 0x4064c8,   1, 0x04, 0x01800600 },
667         { 0x4064cc,   9, 0x04, 0x00000000 },
668         { 0x4064fc,   1, 0x04, 0x0000022a },
669         {}
670 };
671
672 static const struct gf100_gr_init
673 gk104_grctx_init_sked_0[] = {
674         { 0x407040,   1, 0x04, 0x00000000 },
675         {}
676 };
677
678 const struct gf100_gr_init
679 gk104_grctx_init_scc_0[] = {
680         { 0x408000,   2, 0x04, 0x00000000 },
681         { 0x408008,   1, 0x04, 0x00000030 },
682         { 0x40800c,   2, 0x04, 0x00000000 },
683         { 0x408014,   1, 0x04, 0x00000069 },
684         { 0x408018,   1, 0x04, 0xe100e100 },
685         { 0x408064,   1, 0x04, 0x00000000 },
686         {}
687 };
688
689 static const struct gf100_gr_init
690 gk104_grctx_init_be_0[] = {
691         { 0x408800,   1, 0x04, 0x02802a3c },
692         { 0x408804,   1, 0x04, 0x00000040 },
693         { 0x408808,   1, 0x04, 0x1043e005 },
694         { 0x408840,   1, 0x04, 0x0000000b },
695         { 0x408900,   1, 0x04, 0x3080b801 },
696         { 0x408904,   1, 0x04, 0x62000001 },
697         { 0x408908,   1, 0x04, 0x00c8102f },
698         { 0x408980,   1, 0x04, 0x0000011d },
699         {}
700 };
701
702 const struct gf100_gr_pack
703 gk104_grctx_pack_hub[] = {
704         { gf100_grctx_init_main_0 },
705         { gk104_grctx_init_fe_0 },
706         { gf100_grctx_init_pri_0 },
707         { gk104_grctx_init_memfmt_0 },
708         { gk104_grctx_init_ds_0 },
709         { gk104_grctx_init_cwd_0 },
710         { gk104_grctx_init_pd_0 },
711         { gk104_grctx_init_sked_0 },
712         { gf100_grctx_init_rstr2d_0 },
713         { gk104_grctx_init_scc_0 },
714         { gk104_grctx_init_be_0 },
715         {}
716 };
717
718 static const struct gf100_gr_init
719 gk104_grctx_init_setup_0[] = {
720         { 0x418800,   1, 0x04, 0x7006860a },
721         { 0x418808,   3, 0x04, 0x00000000 },
722         { 0x418828,   1, 0x04, 0x00000044 },
723         { 0x418830,   1, 0x04, 0x10000001 },
724         { 0x4188d8,   1, 0x04, 0x00000008 },
725         { 0x4188e0,   1, 0x04, 0x01000000 },
726         { 0x4188e8,   5, 0x04, 0x00000000 },
727         { 0x4188fc,   1, 0x04, 0x20100018 },
728         {}
729 };
730
731 const struct gf100_gr_init
732 gk104_grctx_init_gpm_0[] = {
733         { 0x418c08,   1, 0x04, 0x00000001 },
734         { 0x418c10,   8, 0x04, 0x00000000 },
735         { 0x418c40,   1, 0x04, 0xffffffff },
736         { 0x418c6c,   1, 0x04, 0x00000001 },
737         { 0x418c80,   1, 0x04, 0x20200004 },
738         { 0x418c8c,   1, 0x04, 0x00000001 },
739         {}
740 };
741
742 const struct gf100_gr_pack
743 gk104_grctx_pack_gpc[] = {
744         { gf100_grctx_init_gpc_unk_0 },
745         { gf119_grctx_init_prop_0 },
746         { gf119_grctx_init_gpc_unk_1 },
747         { gk104_grctx_init_setup_0 },
748         { gf100_grctx_init_zcull_0 },
749         { gf119_grctx_init_crstr_0 },
750         { gk104_grctx_init_gpm_0 },
751         { gf100_grctx_init_gcc_0 },
752         {}
753 };
754
755 static const struct gf100_gr_init
756 gk104_grctx_init_tex_0[] = {
757         { 0x419a00,   1, 0x04, 0x000000f0 },
758         { 0x419a04,   1, 0x04, 0x00000001 },
759         { 0x419a08,   1, 0x04, 0x00000021 },
760         { 0x419a0c,   1, 0x04, 0x00020000 },
761         { 0x419a10,   1, 0x04, 0x00000000 },
762         { 0x419a14,   1, 0x04, 0x00000200 },
763         { 0x419a1c,   1, 0x04, 0x0000c000 },
764         { 0x419a20,   1, 0x04, 0x00000800 },
765         { 0x419a30,   1, 0x04, 0x00000001 },
766         { 0x419ac4,   1, 0x04, 0x0037f440 },
767         {}
768 };
769
770 static const struct gf100_gr_init
771 gk104_grctx_init_mpc_0[] = {
772         { 0x419c00,   1, 0x04, 0x0000000a },
773         { 0x419c04,   1, 0x04, 0x80000006 },
774         { 0x419c08,   1, 0x04, 0x00000002 },
775         { 0x419c20,   1, 0x04, 0x00000000 },
776         { 0x419c24,   1, 0x04, 0x00084210 },
777         { 0x419c28,   1, 0x04, 0x3efbefbe },
778         {}
779 };
780
781 static const struct gf100_gr_init
782 gk104_grctx_init_l1c_0[] = {
783         { 0x419ce8,   1, 0x04, 0x00000000 },
784         { 0x419cf4,   1, 0x04, 0x00003203 },
785         {}
786 };
787
788 static const struct gf100_gr_init
789 gk104_grctx_init_sm_0[] = {
790         { 0x419e04,   3, 0x04, 0x00000000 },
791         { 0x419e10,   1, 0x04, 0x00000402 },
792         { 0x419e44,   1, 0x04, 0x0013eff2 },
793         { 0x419e48,   1, 0x04, 0x00000000 },
794         { 0x419e4c,   1, 0x04, 0x0000007f },
795         { 0x419e50,  19, 0x04, 0x00000000 },
796         { 0x419eac,   1, 0x04, 0x00001f8f },
797         { 0x419eb0,   1, 0x04, 0x00000d3f },
798         { 0x419ec8,   1, 0x04, 0x0001304f },
799         { 0x419f30,   8, 0x04, 0x00000000 },
800         { 0x419f58,   1, 0x04, 0x00000000 },
801         { 0x419f70,   1, 0x04, 0x00000000 },
802         { 0x419f78,   1, 0x04, 0x0000000b },
803         { 0x419f7c,   1, 0x04, 0x0000027c },
804         {}
805 };
806
807 const struct gf100_gr_pack
808 gk104_grctx_pack_tpc[] = {
809         { gf117_grctx_init_pe_0 },
810         { gk104_grctx_init_tex_0 },
811         { gk104_grctx_init_mpc_0 },
812         { gk104_grctx_init_l1c_0 },
813         { gk104_grctx_init_sm_0 },
814         {}
815 };
816
817 const struct gf100_gr_init
818 gk104_grctx_init_pes_0[] = {
819         { 0x41be24,   1, 0x04, 0x00000006 },
820         {}
821 };
822
823 static const struct gf100_gr_init
824 gk104_grctx_init_cbm_0[] = {
825         { 0x41bec0,   1, 0x04, 0x12180000 },
826         { 0x41bec4,   1, 0x04, 0x00037f7f },
827         { 0x41bee4,   1, 0x04, 0x06480430 },
828         {}
829 };
830
831 const struct gf100_gr_pack
832 gk104_grctx_pack_ppc[] = {
833         { gk104_grctx_init_pes_0 },
834         { gk104_grctx_init_cbm_0 },
835         { gf117_grctx_init_wwdx_0 },
836         {}
837 };
838
839 /*******************************************************************************
840  * PGRAPH context implementation
841  ******************************************************************************/
842
843 void
844 gk104_grctx_generate_bundle(struct gf100_grctx *info)
845 {
846         const struct gf100_grctx_oclass *impl = gf100_grctx_impl(info->priv);
847         const u32 state_limit = min(impl->bundle_min_gpm_fifo_depth,
848                                     impl->bundle_size / 0x20);
849         const u32 token_limit = impl->bundle_token_limit;
850         const u32 access = NV_MEM_ACCESS_RW | NV_MEM_ACCESS_SYS;
851         const int s = 8;
852         const int b = mmio_vram(info, impl->bundle_size, (1 << s), access);
853         mmio_refn(info, 0x408004, 0x00000000, s, b);
854         mmio_wr32(info, 0x408008, 0x80000000 | (impl->bundle_size >> s));
855         mmio_refn(info, 0x418808, 0x00000000, s, b);
856         mmio_wr32(info, 0x41880c, 0x80000000 | (impl->bundle_size >> s));
857         mmio_wr32(info, 0x4064c8, (state_limit << 16) | token_limit);
858 }
859
860 void
861 gk104_grctx_generate_pagepool(struct gf100_grctx *info)
862 {
863         const struct gf100_grctx_oclass *impl = gf100_grctx_impl(info->priv);
864         const u32 access = NV_MEM_ACCESS_RW | NV_MEM_ACCESS_SYS;
865         const int s = 8;
866         const int b = mmio_vram(info, impl->pagepool_size, (1 << s), access);
867         mmio_refn(info, 0x40800c, 0x00000000, s, b);
868         mmio_wr32(info, 0x408010, 0x80000000);
869         mmio_refn(info, 0x419004, 0x00000000, s, b);
870         mmio_wr32(info, 0x419008, 0x00000000);
871         mmio_wr32(info, 0x4064cc, 0x80000000);
872 }
873
874 void
875 gk104_grctx_generate_unkn(struct gf100_gr_priv *priv)
876 {
877         nv_mask(priv, 0x418c6c, 0x00000001, 0x00000001);
878         nv_mask(priv, 0x41980c, 0x00000010, 0x00000010);
879         nv_mask(priv, 0x41be08, 0x00000004, 0x00000004);
880         nv_mask(priv, 0x4064c0, 0x80000000, 0x80000000);
881         nv_mask(priv, 0x405800, 0x08000000, 0x08000000);
882         nv_mask(priv, 0x419c00, 0x00000008, 0x00000008);
883 }
884
885 void
886 gk104_grctx_generate_r418bb8(struct gf100_gr_priv *priv)
887 {
888         u32 data[6] = {}, data2[2] = {};
889         u8  tpcnr[GPC_MAX];
890         u8  shift, ntpcv;
891         int gpc, tpc, i;
892
893         /* calculate first set of magics */
894         memcpy(tpcnr, priv->tpc_nr, sizeof(priv->tpc_nr));
895
896         gpc = -1;
897         for (tpc = 0; tpc < priv->tpc_total; tpc++) {
898                 do {
899                         gpc = (gpc + 1) % priv->gpc_nr;
900                 } while (!tpcnr[gpc]);
901                 tpcnr[gpc]--;
902
903                 data[tpc / 6] |= gpc << ((tpc % 6) * 5);
904         }
905
906         for (; tpc < 32; tpc++)
907                 data[tpc / 6] |= 7 << ((tpc % 6) * 5);
908
909         /* and the second... */
910         shift = 0;
911         ntpcv = priv->tpc_total;
912         while (!(ntpcv & (1 << 4))) {
913                 ntpcv <<= 1;
914                 shift++;
915         }
916
917         data2[0]  = (ntpcv << 16);
918         data2[0] |= (shift << 21);
919         data2[0] |= (((1 << (0 + 5)) % ntpcv) << 24);
920         for (i = 1; i < 7; i++)
921                 data2[1] |= ((1 << (i + 5)) % ntpcv) << ((i - 1) * 5);
922
923         /* GPC_BROADCAST */
924         nv_wr32(priv, 0x418bb8, (priv->tpc_total << 8) |
925                                  priv->magic_not_rop_nr);
926         for (i = 0; i < 6; i++)
927                 nv_wr32(priv, 0x418b08 + (i * 4), data[i]);
928
929         /* GPC_BROADCAST.TP_BROADCAST */
930         nv_wr32(priv, 0x41bfd0, (priv->tpc_total << 8) |
931                                  priv->magic_not_rop_nr | data2[0]);
932         nv_wr32(priv, 0x41bfe4, data2[1]);
933         for (i = 0; i < 6; i++)
934                 nv_wr32(priv, 0x41bf00 + (i * 4), data[i]);
935
936         /* UNK78xx */
937         nv_wr32(priv, 0x4078bc, (priv->tpc_total << 8) |
938                                  priv->magic_not_rop_nr);
939         for (i = 0; i < 6; i++)
940                 nv_wr32(priv, 0x40780c + (i * 4), data[i]);
941 }
942
943 void
944 gk104_grctx_generate_rop_active_fbps(struct gf100_gr_priv *priv)
945 {
946         const u32 fbp_count = nv_rd32(priv, 0x120074);
947         nv_mask(priv, 0x408850, 0x0000000f, fbp_count); /* zrop */
948         nv_mask(priv, 0x408958, 0x0000000f, fbp_count); /* crop */
949 }
950
951 void
952 gk104_grctx_generate_main(struct gf100_gr_priv *priv, struct gf100_grctx *info)
953 {
954         struct gf100_grctx_oclass *oclass = (void *)nv_engine(priv)->cclass;
955         int i;
956
957         nvkm_mc(priv)->unk260(nvkm_mc(priv), 0);
958
959         gf100_gr_mmio(priv, oclass->hub);
960         gf100_gr_mmio(priv, oclass->gpc);
961         gf100_gr_mmio(priv, oclass->zcull);
962         gf100_gr_mmio(priv, oclass->tpc);
963         gf100_gr_mmio(priv, oclass->ppc);
964
965         nv_wr32(priv, 0x404154, 0x00000000);
966
967         oclass->bundle(info);
968         oclass->pagepool(info);
969         oclass->attrib(info);
970         oclass->unkn(priv);
971
972         gf100_grctx_generate_tpcid(priv);
973         gf100_grctx_generate_r406028(priv);
974         gk104_grctx_generate_r418bb8(priv);
975         gf100_grctx_generate_r406800(priv);
976
977         for (i = 0; i < 8; i++)
978                 nv_wr32(priv, 0x4064d0 + (i * 0x04), 0x00000000);
979
980         nv_wr32(priv, 0x405b00, (priv->tpc_total << 8) | priv->gpc_nr);
981         gk104_grctx_generate_rop_active_fbps(priv);
982         nv_mask(priv, 0x419f78, 0x00000001, 0x00000000);
983
984         gf100_gr_icmd(priv, oclass->icmd);
985         nv_wr32(priv, 0x404154, 0x00000400);
986         gf100_gr_mthd(priv, oclass->mthd);
987         nvkm_mc(priv)->unk260(nvkm_mc(priv), 1);
988
989         nv_mask(priv, 0x418800, 0x00200000, 0x00200000);
990         nv_mask(priv, 0x41be10, 0x00800000, 0x00800000);
991 }
992
993 struct nvkm_oclass *
994 gk104_grctx_oclass = &(struct gf100_grctx_oclass) {
995         .base.handle = NV_ENGCTX(GR, 0xe4),
996         .base.ofuncs = &(struct nvkm_ofuncs) {
997                 .ctor = gf100_gr_context_ctor,
998                 .dtor = gf100_gr_context_dtor,
999                 .init = _nvkm_gr_context_init,
1000                 .fini = _nvkm_gr_context_fini,
1001                 .rd32 = _nvkm_gr_context_rd32,
1002                 .wr32 = _nvkm_gr_context_wr32,
1003         },
1004         .main  = gk104_grctx_generate_main,
1005         .unkn  = gk104_grctx_generate_unkn,
1006         .hub   = gk104_grctx_pack_hub,
1007         .gpc   = gk104_grctx_pack_gpc,
1008         .zcull = gf100_grctx_pack_zcull,
1009         .tpc   = gk104_grctx_pack_tpc,
1010         .ppc   = gk104_grctx_pack_ppc,
1011         .icmd  = gk104_grctx_pack_icmd,
1012         .mthd  = gk104_grctx_pack_mthd,
1013         .bundle = gk104_grctx_generate_bundle,
1014         .bundle_size = 0x3000,
1015         .bundle_min_gpm_fifo_depth = 0x180,
1016         .bundle_token_limit = 0x600,
1017         .pagepool = gk104_grctx_generate_pagepool,
1018         .pagepool_size = 0x8000,
1019         .attrib = gf117_grctx_generate_attrib,
1020         .attrib_nr_max = 0x324,
1021         .attrib_nr = 0x218,
1022         .alpha_nr_max = 0x7ff,
1023         .alpha_nr = 0x648,
1024 }.base;