90c70e777dffb142a500cf0a74be31294fd6857b
[cascardo/linux.git] / drivers / gpu / drm / nouveau / nvkm / engine / gr / gf100.h
1 /*
2  * Copyright 2010 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
23  */
24 #ifndef __GF100_GR_H__
25 #define __GF100_GR_H__
26 #define gf100_gr(p) container_of((p), struct gf100_gr, base)
27 #include "priv.h"
28
29 #include <core/gpuobj.h>
30 #include <subdev/ltc.h>
31 #include <subdev/mmu.h>
32
33 #define GPC_MAX 32
34 #define TPC_MAX_PER_GPC 8
35 #define TPC_MAX (GPC_MAX * TPC_MAX_PER_GPC)
36
37 #define ROP_BCAST(r)      (0x408800 + (r))
38 #define ROP_UNIT(u, r)    (0x410000 + (u) * 0x400 + (r))
39 #define GPC_BCAST(r)      (0x418000 + (r))
40 #define GPC_UNIT(t, r)    (0x500000 + (t) * 0x8000 + (r))
41 #define PPC_UNIT(t, m, r) (0x503000 + (t) * 0x8000 + (m) * 0x200 + (r))
42 #define TPC_UNIT(t, m, r) (0x504000 + (t) * 0x8000 + (m) * 0x800 + (r))
43
44 struct gf100_gr_data {
45         u32 size;
46         u32 align;
47         u32 access;
48 };
49
50 struct gf100_gr_mmio {
51         u32 addr;
52         u32 data;
53         u32 shift;
54         int buffer;
55 };
56
57 struct gf100_gr_fuc {
58         u32 *data;
59         u32  size;
60 };
61
62 struct gf100_gr_zbc_color {
63         u32 format;
64         u32 ds[4];
65         u32 l2[4];
66 };
67
68 struct gf100_gr_zbc_depth {
69         u32 format;
70         u32 ds;
71         u32 l2;
72 };
73
74 struct gf100_gr {
75         const struct gf100_gr_func *func;
76         struct nvkm_gr base;
77
78         struct gf100_gr_fuc fuc409c;
79         struct gf100_gr_fuc fuc409d;
80         struct gf100_gr_fuc fuc41ac;
81         struct gf100_gr_fuc fuc41ad;
82         bool firmware;
83
84         /*
85          * Used if the register packs are loaded from NVIDIA fw instead of
86          * using hardcoded arrays. To be allocated with vzalloc().
87          */
88         struct gf100_gr_pack *fuc_sw_nonctx;
89         struct gf100_gr_pack *fuc_sw_ctx;
90         struct gf100_gr_pack *fuc_bundle;
91         struct gf100_gr_pack *fuc_method;
92
93         struct gf100_gr_zbc_color zbc_color[NVKM_LTC_MAX_ZBC_CNT];
94         struct gf100_gr_zbc_depth zbc_depth[NVKM_LTC_MAX_ZBC_CNT];
95
96         u8 rop_nr;
97         u8 gpc_nr;
98         u8 tpc_nr[GPC_MAX];
99         u8 tpc_total;
100         u8 ppc_nr[GPC_MAX];
101         u8 ppc_mask[GPC_MAX];
102         u8 ppc_tpc_nr[GPC_MAX][4];
103
104         struct gf100_gr_data mmio_data[4];
105         struct gf100_gr_mmio mmio_list[4096/8];
106         u32  size;
107         u32 *data;
108
109         u8 screen_tile_row_offset;
110 };
111
112 int gf100_gr_ctor(const struct gf100_gr_func *, struct nvkm_device *,
113                   int, struct gf100_gr *);
114 int gf100_gr_new_(const struct gf100_gr_func *, struct nvkm_device *,
115                   int, struct nvkm_gr **);
116 void *gf100_gr_dtor(struct nvkm_gr *);
117
118 struct gf100_gr_func {
119         void (*dtor)(struct gf100_gr *);
120         int (*init)(struct gf100_gr *);
121         void (*init_gpc_mmu)(struct gf100_gr *);
122         void (*set_hww_esr_report_mask)(struct gf100_gr *);
123         const struct gf100_gr_pack *mmio;
124         struct {
125                 struct gf100_gr_ucode *ucode;
126         } fecs;
127         struct {
128                 struct gf100_gr_ucode *ucode;
129         } gpccs;
130         int (*rops)(struct gf100_gr *);
131         int ppc_nr;
132         const struct gf100_grctx_func *grctx;
133         struct nvkm_sclass sclass[];
134 };
135
136 int gf100_gr_init(struct gf100_gr *);
137 int gf100_gr_rops(struct gf100_gr *);
138
139 int gk104_gr_init(struct gf100_gr *);
140
141 int gk20a_gr_init(struct gf100_gr *);
142
143 int gm200_gr_init(struct gf100_gr *);
144 int gm200_gr_rops(struct gf100_gr *);
145
146 #define gf100_gr_chan(p) container_of((p), struct gf100_gr_chan, object)
147
148 struct gf100_gr_chan {
149         struct nvkm_object object;
150         struct gf100_gr *gr;
151
152         struct nvkm_memory *mmio;
153         struct nvkm_vma mmio_vma;
154         int mmio_nr;
155
156         struct {
157                 struct nvkm_memory *mem;
158                 struct nvkm_vma vma;
159         } data[4];
160 };
161
162 void gf100_gr_ctxctl_debug(struct gf100_gr *);
163
164 void gf100_gr_dtor_fw(struct gf100_gr_fuc *);
165 int  gf100_gr_ctor_fw(struct gf100_gr *, const char *,
166                       struct gf100_gr_fuc *);
167 u64  gf100_gr_units(struct nvkm_gr *);
168 void gf100_gr_zbc_init(struct gf100_gr *);
169
170 extern const struct nvkm_object_func gf100_fermi;
171
172 struct gf100_gr_init {
173         u32 addr;
174         u8  count;
175         u8  pitch;
176         u32 data;
177 };
178
179 struct gf100_gr_pack {
180         const struct gf100_gr_init *init;
181         u32 type;
182 };
183
184 #define pack_for_each_init(init, pack, head)                                   \
185         for (pack = head; pack && pack->init; pack++)                          \
186                   for (init = pack->init; init && init->count; init++)
187
188 struct gf100_gr_ucode {
189         struct gf100_gr_fuc code;
190         struct gf100_gr_fuc data;
191 };
192
193 extern struct gf100_gr_ucode gf100_gr_fecs_ucode;
194 extern struct gf100_gr_ucode gf100_gr_gpccs_ucode;
195
196 extern struct gf100_gr_ucode gk110_gr_fecs_ucode;
197 extern struct gf100_gr_ucode gk110_gr_gpccs_ucode;
198
199 int  gf100_gr_wait_idle(struct gf100_gr *);
200 void gf100_gr_mmio(struct gf100_gr *, const struct gf100_gr_pack *);
201 void gf100_gr_icmd(struct gf100_gr *, const struct gf100_gr_pack *);
202 void gf100_gr_mthd(struct gf100_gr *, const struct gf100_gr_pack *);
203 int  gf100_gr_init_ctxctl(struct gf100_gr *);
204
205 /* external bundles loading functions */
206 int gk20a_gr_av_to_init(struct gf100_gr *, const char *,
207                         struct gf100_gr_pack **);
208 int gk20a_gr_aiv_to_init(struct gf100_gr *, const char *,
209                          struct gf100_gr_pack **);
210 int gk20a_gr_av_to_method(struct gf100_gr *, const char *,
211                           struct gf100_gr_pack **);
212
213 int gm200_gr_new_(const struct gf100_gr_func *, struct nvkm_device *, int,
214                   struct nvkm_gr **);
215
216 /* register init value lists */
217
218 extern const struct gf100_gr_init gf100_gr_init_main_0[];
219 extern const struct gf100_gr_init gf100_gr_init_fe_0[];
220 extern const struct gf100_gr_init gf100_gr_init_pri_0[];
221 extern const struct gf100_gr_init gf100_gr_init_rstr2d_0[];
222 extern const struct gf100_gr_init gf100_gr_init_pd_0[];
223 extern const struct gf100_gr_init gf100_gr_init_ds_0[];
224 extern const struct gf100_gr_init gf100_gr_init_scc_0[];
225 extern const struct gf100_gr_init gf100_gr_init_prop_0[];
226 extern const struct gf100_gr_init gf100_gr_init_gpc_unk_0[];
227 extern const struct gf100_gr_init gf100_gr_init_setup_0[];
228 extern const struct gf100_gr_init gf100_gr_init_crstr_0[];
229 extern const struct gf100_gr_init gf100_gr_init_setup_1[];
230 extern const struct gf100_gr_init gf100_gr_init_zcull_0[];
231 extern const struct gf100_gr_init gf100_gr_init_gpm_0[];
232 extern const struct gf100_gr_init gf100_gr_init_gpc_unk_1[];
233 extern const struct gf100_gr_init gf100_gr_init_gcc_0[];
234 extern const struct gf100_gr_init gf100_gr_init_tpccs_0[];
235 extern const struct gf100_gr_init gf100_gr_init_tex_0[];
236 extern const struct gf100_gr_init gf100_gr_init_pe_0[];
237 extern const struct gf100_gr_init gf100_gr_init_l1c_0[];
238 extern const struct gf100_gr_init gf100_gr_init_wwdx_0[];
239 extern const struct gf100_gr_init gf100_gr_init_tpccs_1[];
240 extern const struct gf100_gr_init gf100_gr_init_mpc_0[];
241 extern const struct gf100_gr_init gf100_gr_init_be_0[];
242 extern const struct gf100_gr_init gf100_gr_init_fe_1[];
243 extern const struct gf100_gr_init gf100_gr_init_pe_1[];
244
245 extern const struct gf100_gr_init gf104_gr_init_ds_0[];
246 extern const struct gf100_gr_init gf104_gr_init_tex_0[];
247 extern const struct gf100_gr_init gf104_gr_init_sm_0[];
248
249 extern const struct gf100_gr_init gf108_gr_init_gpc_unk_0[];
250 extern const struct gf100_gr_init gf108_gr_init_setup_1[];
251
252 extern const struct gf100_gr_init gf119_gr_init_pd_0[];
253 extern const struct gf100_gr_init gf119_gr_init_ds_0[];
254 extern const struct gf100_gr_init gf119_gr_init_prop_0[];
255 extern const struct gf100_gr_init gf119_gr_init_gpm_0[];
256 extern const struct gf100_gr_init gf119_gr_init_gpc_unk_1[];
257 extern const struct gf100_gr_init gf119_gr_init_tex_0[];
258 extern const struct gf100_gr_init gf119_gr_init_sm_0[];
259 extern const struct gf100_gr_init gf119_gr_init_fe_1[];
260
261 extern const struct gf100_gr_init gf117_gr_init_pes_0[];
262 extern const struct gf100_gr_init gf117_gr_init_wwdx_0[];
263 extern const struct gf100_gr_init gf117_gr_init_cbm_0[];
264
265 extern const struct gf100_gr_init gk104_gr_init_main_0[];
266 extern const struct gf100_gr_init gk104_gr_init_tpccs_0[];
267 extern const struct gf100_gr_init gk104_gr_init_pe_0[];
268 extern const struct gf100_gr_init gk104_gr_init_be_0[];
269 extern const struct gf100_gr_pack gk104_gr_pack_mmio[];
270
271 extern const struct gf100_gr_init gk110_gr_init_fe_0[];
272 extern const struct gf100_gr_init gk110_gr_init_ds_0[];
273 extern const struct gf100_gr_init gk110_gr_init_sked_0[];
274 extern const struct gf100_gr_init gk110_gr_init_cwd_0[];
275 extern const struct gf100_gr_init gk110_gr_init_gpc_unk_1[];
276 extern const struct gf100_gr_init gk110_gr_init_tex_0[];
277 extern const struct gf100_gr_init gk110_gr_init_sm_0[];
278
279 extern const struct gf100_gr_init gk208_gr_init_gpc_unk_0[];
280
281 extern const struct gf100_gr_init gm107_gr_init_scc_0[];
282 extern const struct gf100_gr_init gm107_gr_init_prop_0[];
283 extern const struct gf100_gr_init gm107_gr_init_setup_1[];
284 extern const struct gf100_gr_init gm107_gr_init_zcull_0[];
285 extern const struct gf100_gr_init gm107_gr_init_gpc_unk_1[];
286 extern const struct gf100_gr_init gm107_gr_init_tex_0[];
287 extern const struct gf100_gr_init gm107_gr_init_l1c_0[];
288 extern const struct gf100_gr_init gm107_gr_init_wwdx_0[];
289 extern const struct gf100_gr_init gm107_gr_init_cbm_0[];
290 void gm107_gr_init_bios(struct gf100_gr *);
291 #endif