Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / nouveau / nvkm / engine / gr / gk208.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 "gf100.h"
25 #include "ctxgf100.h"
26
27 #include <subdev/timer.h>
28
29 #include <nvif/class.h>
30
31 /*******************************************************************************
32  * Graphics object classes
33  ******************************************************************************/
34
35 static struct nvkm_oclass
36 gk208_gr_sclass[] = {
37         { 0x902d, &nvkm_object_ofuncs },
38         { 0xa140, &nvkm_object_ofuncs },
39         { KEPLER_B, &gf100_fermi_ofuncs },
40         { 0xa1c0, &nvkm_object_ofuncs },
41         {}
42 };
43
44 /*******************************************************************************
45  * PGRAPH register lists
46  ******************************************************************************/
47
48 static const struct gf100_gr_init
49 gk208_gr_init_main_0[] = {
50         { 0x400080,   1, 0x04, 0x003083c2 },
51         { 0x400088,   1, 0x04, 0x0001bfe7 },
52         { 0x40008c,   1, 0x04, 0x00000000 },
53         { 0x400090,   1, 0x04, 0x00000030 },
54         { 0x40013c,   1, 0x04, 0x003901f7 },
55         { 0x400140,   1, 0x04, 0x00000100 },
56         { 0x400144,   1, 0x04, 0x00000000 },
57         { 0x400148,   1, 0x04, 0x00000110 },
58         { 0x400138,   1, 0x04, 0x00000000 },
59         { 0x400130,   2, 0x04, 0x00000000 },
60         { 0x400124,   1, 0x04, 0x00000002 },
61         {}
62 };
63
64 static const struct gf100_gr_init
65 gk208_gr_init_ds_0[] = {
66         { 0x405844,   1, 0x04, 0x00ffffff },
67         { 0x405850,   1, 0x04, 0x00000000 },
68         { 0x405900,   1, 0x04, 0x00000000 },
69         { 0x405908,   1, 0x04, 0x00000000 },
70         { 0x405928,   2, 0x04, 0x00000000 },
71         {}
72 };
73
74 const struct gf100_gr_init
75 gk208_gr_init_gpc_unk_0[] = {
76         { 0x418604,   1, 0x04, 0x00000000 },
77         { 0x418680,   1, 0x04, 0x00000000 },
78         { 0x418714,   1, 0x04, 0x00000000 },
79         { 0x418384,   2, 0x04, 0x00000000 },
80         {}
81 };
82
83 static const struct gf100_gr_init
84 gk208_gr_init_setup_1[] = {
85         { 0x4188c8,   2, 0x04, 0x00000000 },
86         { 0x4188d0,   1, 0x04, 0x00010000 },
87         { 0x4188d4,   1, 0x04, 0x00000201 },
88         {}
89 };
90
91 static const struct gf100_gr_init
92 gk208_gr_init_tex_0[] = {
93         { 0x419ab0,   1, 0x04, 0x00000000 },
94         { 0x419ac8,   1, 0x04, 0x00000000 },
95         { 0x419ab8,   1, 0x04, 0x000000e7 },
96         { 0x419abc,   2, 0x04, 0x00000000 },
97         { 0x419ab4,   1, 0x04, 0x00000000 },
98         { 0x419aa8,   2, 0x04, 0x00000000 },
99         {}
100 };
101
102 static const struct gf100_gr_init
103 gk208_gr_init_l1c_0[] = {
104         { 0x419c98,   1, 0x04, 0x00000000 },
105         { 0x419ca8,   1, 0x04, 0x00000000 },
106         { 0x419cb0,   1, 0x04, 0x01000000 },
107         { 0x419cb4,   1, 0x04, 0x00000000 },
108         { 0x419cb8,   1, 0x04, 0x00b08bea },
109         { 0x419c84,   1, 0x04, 0x00010384 },
110         { 0x419cbc,   1, 0x04, 0x281b3646 },
111         { 0x419cc0,   2, 0x04, 0x00000000 },
112         { 0x419c80,   1, 0x04, 0x00000230 },
113         { 0x419ccc,   2, 0x04, 0x00000000 },
114         {}
115 };
116
117 static const struct gf100_gr_pack
118 gk208_gr_pack_mmio[] = {
119         { gk208_gr_init_main_0 },
120         { gk110_gr_init_fe_0 },
121         { gf100_gr_init_pri_0 },
122         { gf100_gr_init_rstr2d_0 },
123         { gf119_gr_init_pd_0 },
124         { gk208_gr_init_ds_0 },
125         { gf100_gr_init_scc_0 },
126         { gk110_gr_init_sked_0 },
127         { gk110_gr_init_cwd_0 },
128         { gf119_gr_init_prop_0 },
129         { gk208_gr_init_gpc_unk_0 },
130         { gf100_gr_init_setup_0 },
131         { gf100_gr_init_crstr_0 },
132         { gk208_gr_init_setup_1 },
133         { gf100_gr_init_zcull_0 },
134         { gf119_gr_init_gpm_0 },
135         { gk110_gr_init_gpc_unk_1 },
136         { gf100_gr_init_gcc_0 },
137         { gk104_gr_init_tpccs_0 },
138         { gk208_gr_init_tex_0 },
139         { gk104_gr_init_pe_0 },
140         { gk208_gr_init_l1c_0 },
141         { gf100_gr_init_mpc_0 },
142         { gk110_gr_init_sm_0 },
143         { gf117_gr_init_pes_0 },
144         { gf117_gr_init_wwdx_0 },
145         { gf117_gr_init_cbm_0 },
146         { gk104_gr_init_be_0 },
147         { gf100_gr_init_fe_1 },
148         {}
149 };
150
151 /*******************************************************************************
152  * PGRAPH engine/subdev functions
153  ******************************************************************************/
154
155 static int
156 gk208_gr_fini(struct nvkm_object *object, bool suspend)
157 {
158         struct gf100_gr_priv *priv = (void *)object;
159         static const struct {
160                 u32 addr;
161                 u32 data;
162         } magic[] = {
163                 { 0x020520, 0xfffffffc },
164                 { 0x020524, 0xfffffffe },
165                 { 0x020524, 0xfffffffc },
166                 { 0x020524, 0xfffffff8 },
167                 { 0x020524, 0xffffffe0 },
168                 { 0x020530, 0xfffffffe },
169                 { 0x02052c, 0xfffffffa },
170                 { 0x02052c, 0xfffffff0 },
171                 { 0x02052c, 0xffffffc0 },
172                 { 0x02052c, 0xffffff00 },
173                 { 0x02052c, 0xfffffc00 },
174                 { 0x02052c, 0xfffcfc00 },
175                 { 0x02052c, 0xfff0fc00 },
176                 { 0x02052c, 0xff80fc00 },
177                 { 0x020528, 0xfffffffe },
178                 { 0x020528, 0xfffffffc },
179         };
180         int i;
181
182         nv_mask(priv, 0x000200, 0x08001000, 0x00000000);
183         nv_mask(priv, 0x0206b4, 0x00000000, 0x00000000);
184         for (i = 0; i < ARRAY_SIZE(magic); i++) {
185                 nv_wr32(priv, magic[i].addr, magic[i].data);
186                 nv_wait(priv, magic[i].addr, 0x80000000, 0x00000000);
187         }
188
189         return nvkm_gr_fini(&priv->base, suspend);
190 }
191
192 #include "fuc/hubgk208.fuc5.h"
193
194 static struct gf100_gr_ucode
195 gk208_gr_fecs_ucode = {
196         .code.data = gk208_grhub_code,
197         .code.size = sizeof(gk208_grhub_code),
198         .data.data = gk208_grhub_data,
199         .data.size = sizeof(gk208_grhub_data),
200 };
201
202 #include "fuc/gpcgk208.fuc5.h"
203
204 static struct gf100_gr_ucode
205 gk208_gr_gpccs_ucode = {
206         .code.data = gk208_grgpc_code,
207         .code.size = sizeof(gk208_grgpc_code),
208         .data.data = gk208_grgpc_data,
209         .data.size = sizeof(gk208_grgpc_data),
210 };
211
212 struct nvkm_oclass *
213 gk208_gr_oclass = &(struct gf100_gr_oclass) {
214         .base.handle = NV_ENGINE(GR, 0x08),
215         .base.ofuncs = &(struct nvkm_ofuncs) {
216                 .ctor = gf100_gr_ctor,
217                 .dtor = gf100_gr_dtor,
218                 .init = gk104_gr_init,
219                 .fini = gk208_gr_fini,
220         },
221         .cclass = &gk208_grctx_oclass,
222         .sclass =  gk208_gr_sclass,
223         .mmio = gk208_gr_pack_mmio,
224         .fecs.ucode = &gk208_gr_fecs_ucode,
225         .gpccs.ucode = &gk208_gr_gpccs_ucode,
226         .ppc_nr = 1,
227 }.base;