HID: picolcd: sanity check report size in raw_event() callback
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / nouveau / core / engine / graph / nve4.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
25 #include "nvc0.h"
26 #include "ctxnvc0.h"
27
28 /*******************************************************************************
29  * Graphics object classes
30  ******************************************************************************/
31
32 static struct nouveau_oclass
33 nve4_graph_sclass[] = {
34         { 0x902d, &nouveau_object_ofuncs },
35         { 0xa040, &nouveau_object_ofuncs },
36         { 0xa097, &nouveau_object_ofuncs },
37         { 0xa0c0, &nouveau_object_ofuncs },
38         {}
39 };
40
41 /*******************************************************************************
42  * PGRAPH register lists
43  ******************************************************************************/
44
45 const struct nvc0_graph_init
46 nve4_graph_init_main_0[] = {
47         { 0x400080,   1, 0x04, 0x003083c2 },
48         { 0x400088,   1, 0x04, 0x0001ffe7 },
49         { 0x40008c,   1, 0x04, 0x00000000 },
50         { 0x400090,   1, 0x04, 0x00000030 },
51         { 0x40013c,   1, 0x04, 0x003901f7 },
52         { 0x400140,   1, 0x04, 0x00000100 },
53         { 0x400144,   1, 0x04, 0x00000000 },
54         { 0x400148,   1, 0x04, 0x00000110 },
55         { 0x400138,   1, 0x04, 0x00000000 },
56         { 0x400130,   2, 0x04, 0x00000000 },
57         { 0x400124,   1, 0x04, 0x00000002 },
58         {}
59 };
60
61 static const struct nvc0_graph_init
62 nve4_graph_init_ds_0[] = {
63         { 0x405844,   1, 0x04, 0x00ffffff },
64         { 0x405850,   1, 0x04, 0x00000000 },
65         { 0x405900,   1, 0x04, 0x0000ff34 },
66         { 0x405908,   1, 0x04, 0x00000000 },
67         { 0x405928,   2, 0x04, 0x00000000 },
68         {}
69 };
70
71 static const struct nvc0_graph_init
72 nve4_graph_init_sked_0[] = {
73         { 0x407010,   1, 0x04, 0x00000000 },
74         {}
75 };
76
77 static const struct nvc0_graph_init
78 nve4_graph_init_cwd_0[] = {
79         { 0x405b50,   1, 0x04, 0x00000000 },
80         {}
81 };
82
83 static const struct nvc0_graph_init
84 nve4_graph_init_gpc_unk_1[] = {
85         { 0x418d00,   1, 0x04, 0x00000000 },
86         { 0x418d28,   2, 0x04, 0x00000000 },
87         { 0x418f00,   1, 0x04, 0x00000000 },
88         { 0x418f08,   1, 0x04, 0x00000000 },
89         { 0x418f20,   2, 0x04, 0x00000000 },
90         { 0x418e00,   1, 0x04, 0x00000060 },
91         { 0x418e08,   1, 0x04, 0x00000000 },
92         { 0x418e1c,   2, 0x04, 0x00000000 },
93         {}
94 };
95
96 const struct nvc0_graph_init
97 nve4_graph_init_tpccs_0[] = {
98         { 0x419d0c,   1, 0x04, 0x00000000 },
99         { 0x419d10,   1, 0x04, 0x00000014 },
100         {}
101 };
102
103 const struct nvc0_graph_init
104 nve4_graph_init_pe_0[] = {
105         { 0x41980c,   1, 0x04, 0x00000010 },
106         { 0x419844,   1, 0x04, 0x00000000 },
107         { 0x419850,   1, 0x04, 0x00000004 },
108         { 0x419854,   2, 0x04, 0x00000000 },
109         {}
110 };
111
112 static const struct nvc0_graph_init
113 nve4_graph_init_l1c_0[] = {
114         { 0x419c98,   1, 0x04, 0x00000000 },
115         { 0x419ca8,   1, 0x04, 0x00000000 },
116         { 0x419cb0,   1, 0x04, 0x01000000 },
117         { 0x419cb4,   1, 0x04, 0x00000000 },
118         { 0x419cb8,   1, 0x04, 0x00b08bea },
119         { 0x419c84,   1, 0x04, 0x00010384 },
120         { 0x419cbc,   1, 0x04, 0x28137646 },
121         { 0x419cc0,   2, 0x04, 0x00000000 },
122         { 0x419c80,   1, 0x04, 0x00020232 },
123         {}
124 };
125
126 static const struct nvc0_graph_init
127 nve4_graph_init_sm_0[] = {
128         { 0x419e00,   1, 0x04, 0x00000000 },
129         { 0x419ea0,   1, 0x04, 0x00000000 },
130         { 0x419ee4,   1, 0x04, 0x00000000 },
131         { 0x419ea4,   1, 0x04, 0x00000100 },
132         { 0x419ea8,   1, 0x04, 0x00000000 },
133         { 0x419eb4,   4, 0x04, 0x00000000 },
134         { 0x419edc,   1, 0x04, 0x00000000 },
135         { 0x419f00,   1, 0x04, 0x00000000 },
136         { 0x419f74,   1, 0x04, 0x00000555 },
137         {}
138 };
139
140 const struct nvc0_graph_init
141 nve4_graph_init_be_0[] = {
142         { 0x40880c,   1, 0x04, 0x00000000 },
143         { 0x408850,   1, 0x04, 0x00000004 },
144         { 0x408910,   9, 0x04, 0x00000000 },
145         { 0x408950,   1, 0x04, 0x00000000 },
146         { 0x408954,   1, 0x04, 0x0000ffff },
147         { 0x408958,   1, 0x04, 0x00000034 },
148         { 0x408984,   1, 0x04, 0x00000000 },
149         { 0x408988,   1, 0x04, 0x08040201 },
150         { 0x40898c,   1, 0x04, 0x80402010 },
151         {}
152 };
153
154 const struct nvc0_graph_pack
155 nve4_graph_pack_mmio[] = {
156         { nve4_graph_init_main_0 },
157         { nvc0_graph_init_fe_0 },
158         { nvc0_graph_init_pri_0 },
159         { nvc0_graph_init_rstr2d_0 },
160         { nvd9_graph_init_pd_0 },
161         { nve4_graph_init_ds_0 },
162         { nvc0_graph_init_scc_0 },
163         { nve4_graph_init_sked_0 },
164         { nve4_graph_init_cwd_0 },
165         { nvd9_graph_init_prop_0 },
166         { nvc1_graph_init_gpc_unk_0 },
167         { nvc0_graph_init_setup_0 },
168         { nvc0_graph_init_crstr_0 },
169         { nvc1_graph_init_setup_1 },
170         { nvc0_graph_init_zcull_0 },
171         { nvd9_graph_init_gpm_0 },
172         { nve4_graph_init_gpc_unk_1 },
173         { nvc0_graph_init_gcc_0 },
174         { nve4_graph_init_tpccs_0 },
175         { nvd9_graph_init_tex_0 },
176         { nve4_graph_init_pe_0 },
177         { nve4_graph_init_l1c_0 },
178         { nvc0_graph_init_mpc_0 },
179         { nve4_graph_init_sm_0 },
180         { nvd7_graph_init_pes_0 },
181         { nvd7_graph_init_wwdx_0 },
182         { nvd7_graph_init_cbm_0 },
183         { nve4_graph_init_be_0 },
184         { nvc0_graph_init_fe_1 },
185         {}
186 };
187
188 /*******************************************************************************
189  * PGRAPH engine/subdev functions
190  ******************************************************************************/
191
192 int
193 nve4_graph_fini(struct nouveau_object *object, bool suspend)
194 {
195         struct nvc0_graph_priv *priv = (void *)object;
196
197         /*XXX: this is a nasty hack to power on gr on certain boards
198          *     where it's disabled by therm, somehow.  ideally it'd
199          *     be nice to know when we should be doing this, and why,
200          *     but, it's yet to be determined.  for now we test for
201          *     the particular mmio error that occurs in the situation,
202          *     and then bash therm in the way nvidia do.
203          */
204         nv_mask(priv, 0x000200, 0x08001000, 0x08001000);
205         nv_rd32(priv, 0x000200);
206         if (nv_rd32(priv, 0x400700) == 0xbadf1000) {
207                 nv_mask(priv, 0x000200, 0x08001000, 0x00000000);
208                 nv_rd32(priv, 0x000200);
209                 nv_mask(priv, 0x020004, 0xc0000000, 0x40000000);
210         }
211
212         return nouveau_graph_fini(&priv->base, suspend);
213 }
214
215 int
216 nve4_graph_init(struct nouveau_object *object)
217 {
218         struct nvc0_graph_oclass *oclass = (void *)object->oclass;
219         struct nvc0_graph_priv *priv = (void *)object;
220         const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, priv->tpc_total);
221         u32 data[TPC_MAX / 8] = {};
222         u8  tpcnr[GPC_MAX];
223         int gpc, tpc, rop;
224         int ret, i;
225
226         ret = nouveau_graph_init(&priv->base);
227         if (ret)
228                 return ret;
229
230         nv_wr32(priv, GPC_BCAST(0x0880), 0x00000000);
231         nv_wr32(priv, GPC_BCAST(0x08a4), 0x00000000);
232         nv_wr32(priv, GPC_BCAST(0x0888), 0x00000000);
233         nv_wr32(priv, GPC_BCAST(0x088c), 0x00000000);
234         nv_wr32(priv, GPC_BCAST(0x0890), 0x00000000);
235         nv_wr32(priv, GPC_BCAST(0x0894), 0x00000000);
236         nv_wr32(priv, GPC_BCAST(0x08b4), priv->unk4188b4->addr >> 8);
237         nv_wr32(priv, GPC_BCAST(0x08b8), priv->unk4188b8->addr >> 8);
238
239         nvc0_graph_mmio(priv, oclass->mmio);
240
241         nv_wr32(priv, GPC_UNIT(0, 0x3018), 0x00000001);
242
243         memset(data, 0x00, sizeof(data));
244         memcpy(tpcnr, priv->tpc_nr, sizeof(priv->tpc_nr));
245         for (i = 0, gpc = -1; i < priv->tpc_total; i++) {
246                 do {
247                         gpc = (gpc + 1) % priv->gpc_nr;
248                 } while (!tpcnr[gpc]);
249                 tpc = priv->tpc_nr[gpc] - tpcnr[gpc]--;
250
251                 data[i / 8] |= tpc << ((i % 8) * 4);
252         }
253
254         nv_wr32(priv, GPC_BCAST(0x0980), data[0]);
255         nv_wr32(priv, GPC_BCAST(0x0984), data[1]);
256         nv_wr32(priv, GPC_BCAST(0x0988), data[2]);
257         nv_wr32(priv, GPC_BCAST(0x098c), data[3]);
258
259         for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
260                 nv_wr32(priv, GPC_UNIT(gpc, 0x0914),
261                         priv->magic_not_rop_nr << 8 | priv->tpc_nr[gpc]);
262                 nv_wr32(priv, GPC_UNIT(gpc, 0x0910), 0x00040000 |
263                         priv->tpc_total);
264                 nv_wr32(priv, GPC_UNIT(gpc, 0x0918), magicgpc918);
265         }
266
267         nv_wr32(priv, GPC_BCAST(0x3fd4), magicgpc918);
268         nv_wr32(priv, GPC_BCAST(0x08ac), nv_rd32(priv, 0x100800));
269
270         nv_wr32(priv, 0x400500, 0x00010001);
271
272         nv_wr32(priv, 0x400100, 0xffffffff);
273         nv_wr32(priv, 0x40013c, 0xffffffff);
274
275         nv_wr32(priv, 0x409ffc, 0x00000000);
276         nv_wr32(priv, 0x409c14, 0x00003e3e);
277         nv_wr32(priv, 0x409c24, 0x000f0001);
278         nv_wr32(priv, 0x404000, 0xc0000000);
279         nv_wr32(priv, 0x404600, 0xc0000000);
280         nv_wr32(priv, 0x408030, 0xc0000000);
281         nv_wr32(priv, 0x404490, 0xc0000000);
282         nv_wr32(priv, 0x406018, 0xc0000000);
283         nv_wr32(priv, 0x407020, 0x40000000);
284         nv_wr32(priv, 0x405840, 0xc0000000);
285         nv_wr32(priv, 0x405844, 0x00ffffff);
286         nv_mask(priv, 0x419cc0, 0x00000008, 0x00000008);
287         nv_mask(priv, 0x419eb4, 0x00001000, 0x00001000);
288
289         for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
290                 nv_wr32(priv, GPC_UNIT(gpc, 0x3038), 0xc0000000);
291                 nv_wr32(priv, GPC_UNIT(gpc, 0x0420), 0xc0000000);
292                 nv_wr32(priv, GPC_UNIT(gpc, 0x0900), 0xc0000000);
293                 nv_wr32(priv, GPC_UNIT(gpc, 0x1028), 0xc0000000);
294                 nv_wr32(priv, GPC_UNIT(gpc, 0x0824), 0xc0000000);
295                 for (tpc = 0; tpc < priv->tpc_nr[gpc]; tpc++) {
296                         nv_wr32(priv, TPC_UNIT(gpc, tpc, 0x508), 0xffffffff);
297                         nv_wr32(priv, TPC_UNIT(gpc, tpc, 0x50c), 0xffffffff);
298                         nv_wr32(priv, TPC_UNIT(gpc, tpc, 0x224), 0xc0000000);
299                         nv_wr32(priv, TPC_UNIT(gpc, tpc, 0x48c), 0xc0000000);
300                         nv_wr32(priv, TPC_UNIT(gpc, tpc, 0x084), 0xc0000000);
301                         nv_wr32(priv, TPC_UNIT(gpc, tpc, 0x644), 0x001ffffe);
302                         nv_wr32(priv, TPC_UNIT(gpc, tpc, 0x64c), 0x0000000f);
303                 }
304                 nv_wr32(priv, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
305                 nv_wr32(priv, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
306         }
307
308         for (rop = 0; rop < priv->rop_nr; rop++) {
309                 nv_wr32(priv, ROP_UNIT(rop, 0x144), 0xc0000000);
310                 nv_wr32(priv, ROP_UNIT(rop, 0x070), 0xc0000000);
311                 nv_wr32(priv, ROP_UNIT(rop, 0x204), 0xffffffff);
312                 nv_wr32(priv, ROP_UNIT(rop, 0x208), 0xffffffff);
313         }
314
315         nv_wr32(priv, 0x400108, 0xffffffff);
316         nv_wr32(priv, 0x400138, 0xffffffff);
317         nv_wr32(priv, 0x400118, 0xffffffff);
318         nv_wr32(priv, 0x400130, 0xffffffff);
319         nv_wr32(priv, 0x40011c, 0xffffffff);
320         nv_wr32(priv, 0x400134, 0xffffffff);
321
322         nv_wr32(priv, 0x400054, 0x34ce3464);
323         return nvc0_graph_init_ctxctl(priv);
324 }
325
326 #include "fuc/hubnve0.fuc.h"
327
328 static struct nvc0_graph_ucode
329 nve4_graph_fecs_ucode = {
330         .code.data = nve0_grhub_code,
331         .code.size = sizeof(nve0_grhub_code),
332         .data.data = nve0_grhub_data,
333         .data.size = sizeof(nve0_grhub_data),
334 };
335
336 #include "fuc/gpcnve0.fuc.h"
337
338 static struct nvc0_graph_ucode
339 nve4_graph_gpccs_ucode = {
340         .code.data = nve0_grgpc_code,
341         .code.size = sizeof(nve0_grgpc_code),
342         .data.data = nve0_grgpc_data,
343         .data.size = sizeof(nve0_grgpc_data),
344 };
345
346 struct nouveau_oclass *
347 nve4_graph_oclass = &(struct nvc0_graph_oclass) {
348         .base.handle = NV_ENGINE(GR, 0xe4),
349         .base.ofuncs = &(struct nouveau_ofuncs) {
350                 .ctor = nvc0_graph_ctor,
351                 .dtor = nvc0_graph_dtor,
352                 .init = nve4_graph_init,
353                 .fini = nve4_graph_fini,
354         },
355         .cclass = &nve4_grctx_oclass,
356         .sclass = nve4_graph_sclass,
357         .mmio = nve4_graph_pack_mmio,
358         .fecs.ucode = &nve4_graph_fecs_ucode,
359         .gpccs.ucode = &nve4_graph_gpccs_ucode,
360 }.base;