]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/gpu/nvgpu/gk20a/gr_gk20a.h
video: tegra: host: gk20a: reduce gr delays
[sojka/nv-tegra/linux-3.10.git] / drivers / gpu / nvgpu / gk20a / gr_gk20a.h
1 /*
2  * GK20A Graphics Engine
3  *
4  * Copyright (c) 2011-2014, NVIDIA CORPORATION.  All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #ifndef __GR_GK20A_H__
19 #define __GR_GK20A_H__
20
21 #include <linux/slab.h>
22
23 #include "gr_ctx_gk20a.h"
24
25 #define GR_IDLE_CHECK_DEFAULT           10 /* usec */
26 #define GR_IDLE_CHECK_MAX               200 /* usec */
27
28 #define INVALID_SCREEN_TILE_ROW_OFFSET  0xFFFFFFFF
29 #define INVALID_MAX_WAYS                0xFFFFFFFF
30
31 #define GK20A_FECS_UCODE_IMAGE  "fecs.bin"
32 #define GK20A_GPCCS_UCODE_IMAGE "gpccs.bin"
33
34 enum /* global_ctx_buffer */ {
35         CIRCULAR                = 0,
36         PAGEPOOL                = 1,
37         ATTRIBUTE               = 2,
38         CIRCULAR_VPR            = 3,
39         PAGEPOOL_VPR            = 4,
40         ATTRIBUTE_VPR           = 5,
41         GOLDEN_CTX              = 6,
42         PRIV_ACCESS_MAP         = 7,
43         NR_GLOBAL_CTX_BUF       = 8
44 };
45
46 /* either ATTRIBUTE or ATTRIBUTE_VPR maps to ATTRIBUTE_VA */
47 enum  /*global_ctx_buffer_va */ {
48         CIRCULAR_VA             = 0,
49         PAGEPOOL_VA             = 1,
50         ATTRIBUTE_VA            = 2,
51         GOLDEN_CTX_VA           = 3,
52         PRIV_ACCESS_MAP_VA      = 4,
53         NR_GLOBAL_CTX_BUF_VA    = 5
54 };
55
56 enum {
57         WAIT_UCODE_LOOP,
58         WAIT_UCODE_TIMEOUT,
59         WAIT_UCODE_ERROR,
60         WAIT_UCODE_OK
61 };
62
63 enum {
64         GR_IS_UCODE_OP_EQUAL,
65         GR_IS_UCODE_OP_NOT_EQUAL,
66         GR_IS_UCODE_OP_AND,
67         GR_IS_UCODE_OP_LESSER,
68         GR_IS_UCODE_OP_LESSER_EQUAL,
69         GR_IS_UCODE_OP_SKIP
70 };
71
72 enum {
73         eUcodeHandshakeInitComplete = 1,
74         eUcodeHandshakeMethodFinished
75 };
76
77 enum {
78         ELCG_RUN,       /* clk always run, i.e. disable elcg */
79         ELCG_STOP,      /* clk is stopped */
80         ELCG_AUTO       /* clk will run when non-idle, standard elcg mode */
81 };
82
83 enum {
84         BLCG_RUN,       /* clk always run, i.e. disable blcg */
85         BLCG_AUTO       /* clk will run when non-idle, standard blcg mode */
86 };
87
88 #ifndef GR_GO_IDLE_BUNDLE
89 #define GR_GO_IDLE_BUNDLE       0x0000e100 /* --V-B */
90 #endif
91
92 struct gr_channel_map_tlb_entry {
93         u32 curr_ctx;
94         u32 hw_chid;
95 };
96
97 struct gr_zcull_gk20a {
98         u32 aliquot_width;
99         u32 aliquot_height;
100         u32 aliquot_size;
101         u32 total_aliquots;
102
103         u32 width_align_pixels;
104         u32 height_align_pixels;
105         u32 pixel_squares_by_aliquots;
106 };
107
108 struct gr_zcull_info {
109         u32 width_align_pixels;
110         u32 height_align_pixels;
111         u32 pixel_squares_by_aliquots;
112         u32 aliquot_total;
113         u32 region_byte_multiplier;
114         u32 region_header_size;
115         u32 subregion_header_size;
116         u32 subregion_width_align_pixels;
117         u32 subregion_height_align_pixels;
118         u32 subregion_count;
119 };
120
121 #define GK20A_ZBC_COLOR_VALUE_SIZE      4  /* RGBA */
122
123 #define GK20A_STARTOF_ZBC_TABLE         1   /* index zero reserved to indicate "not ZBCd" */
124 #define GK20A_SIZEOF_ZBC_TABLE          16  /* match ltcs_ltss_dstg_zbc_index_address width (4) */
125 #define GK20A_ZBC_TABLE_SIZE            (16 - 1)
126
127 #define GK20A_ZBC_TYPE_INVALID          0
128 #define GK20A_ZBC_TYPE_COLOR            1
129 #define GK20A_ZBC_TYPE_DEPTH            2
130
131 struct zbc_color_table {
132         u32 color_ds[GK20A_ZBC_COLOR_VALUE_SIZE];
133         u32 color_l2[GK20A_ZBC_COLOR_VALUE_SIZE];
134         u32 format;
135         u32 ref_cnt;
136 };
137
138 struct zbc_depth_table {
139         u32 depth;
140         u32 format;
141         u32 ref_cnt;
142 };
143
144 struct zbc_entry {
145         u32 color_ds[GK20A_ZBC_COLOR_VALUE_SIZE];
146         u32 color_l2[GK20A_ZBC_COLOR_VALUE_SIZE];
147         u32 depth;
148         u32 type;       /* color or depth */
149         u32 format;
150 };
151
152 struct zbc_query_params {
153         u32 color_ds[GK20A_ZBC_COLOR_VALUE_SIZE];
154         u32 color_l2[GK20A_ZBC_COLOR_VALUE_SIZE];
155         u32 depth;
156         u32 ref_cnt;
157         u32 format;
158         u32 type;       /* color or depth */
159         u32 index_size; /* [out] size, [in] index */
160 };
161
162 struct gr_gk20a {
163         struct gk20a *g;
164         struct {
165                 bool dynamic;
166
167                 u32 buffer_size;
168                 u32 buffer_total_size;
169
170                 bool golden_image_initialized;
171                 u32 golden_image_size;
172                 u32 *local_golden_image;
173
174                 u32 zcull_ctxsw_image_size;
175
176                 u32 buffer_header_size;
177
178                 u32 priv_access_map_size;
179
180                 struct gr_ucode_gk20a ucode;
181
182                 struct av_list_gk20a  sw_bundle_init;
183                 struct av_list_gk20a  sw_method_init;
184                 struct aiv_list_gk20a sw_ctx_load;
185                 struct av_list_gk20a  sw_non_ctx_load;
186                 struct {
187                         struct aiv_list_gk20a sys;
188                         struct aiv_list_gk20a gpc;
189                         struct aiv_list_gk20a tpc;
190                         struct aiv_list_gk20a zcull_gpc;
191                         struct aiv_list_gk20a ppc;
192                         struct aiv_list_gk20a pm_sys;
193                         struct aiv_list_gk20a pm_gpc;
194                         struct aiv_list_gk20a pm_tpc;
195                 } ctxsw_regs;
196                 int regs_base_index;
197                 bool valid;
198         } ctx_vars;
199
200         struct mutex ctx_mutex; /* protect golden ctx init */
201         struct mutex fecs_mutex; /* protect fecs method */
202
203 #define GR_NETLIST_DYNAMIC      -1
204 #define GR_NETLIST_STATIC_A     'A'
205         int netlist;
206
207         wait_queue_head_t init_wq;
208         int initialized;
209
210         u32 num_fbps;
211
212         u32 comptags_per_cacheline;
213         u32 slices_per_fbp;
214         u32 cacheline_size;
215
216         u32 max_gpc_count;
217         u32 max_fbps_count;
218         u32 max_tpc_per_gpc_count;
219         u32 max_zcull_per_gpc_count;
220         u32 max_tpc_count;
221
222         u32 sys_count;
223         u32 gpc_count;
224         u32 pe_count_per_gpc;
225         u32 ppc_count;
226         u32 *gpc_ppc_count;
227         u32 tpc_count;
228         u32 *gpc_tpc_count;
229         u32 zcb_count;
230         u32 *gpc_zcb_count;
231         u32 *pes_tpc_count[2];
232         u32 *pes_tpc_mask[2];
233         u32 *gpc_skip_mask;
234
235         u32 bundle_cb_default_size;
236         u32 min_gpm_fifo_depth;
237         u32 bundle_cb_token_limit;
238         u32 attrib_cb_default_size;
239         u32 attrib_cb_size;
240         u32 alpha_cb_default_size;
241         u32 alpha_cb_size;
242         u32 timeslice_mode;
243
244         struct gr_ctx_buffer_desc global_ctx_buffer[NR_GLOBAL_CTX_BUF];
245
246         struct mmu_desc mmu_wr_mem;
247         u32 mmu_wr_mem_size;
248         struct mmu_desc mmu_rd_mem;
249         u32 mmu_rd_mem_size;
250
251         u8 *map_tiles;
252         u32 map_tile_count;
253         u32 map_row_offset;
254
255 #define COMP_TAG_LINE_SIZE_SHIFT        (17)    /* one tag covers 128K */
256 #define COMP_TAG_LINE_SIZE              (1 << COMP_TAG_LINE_SIZE_SHIFT)
257
258         u32 max_comptag_mem; /* max memory size (MB) for comptag */
259         struct compbit_store_desc compbit_store;
260         struct gk20a_allocator comp_tags;
261
262         struct gr_zcull_gk20a zcull;
263
264         struct mutex zbc_lock;
265         struct zbc_color_table zbc_col_tbl[GK20A_ZBC_TABLE_SIZE];
266         struct zbc_depth_table zbc_dep_tbl[GK20A_ZBC_TABLE_SIZE];
267
268         s32 max_default_color_index;
269         s32 max_default_depth_index;
270
271         s32 max_used_color_index;
272         s32 max_used_depth_index;
273
274         u32 status_disable_mask;
275
276 #define GR_CHANNEL_MAP_TLB_SIZE         2 /* must of power of 2 */
277         struct gr_channel_map_tlb_entry chid_tlb[GR_CHANNEL_MAP_TLB_SIZE];
278         u32 channel_tlb_flush_index;
279         spinlock_t ch_tlb_lock;
280
281         void (*remove_support)(struct gr_gk20a *gr);
282         bool sw_ready;
283         bool skip_ucode_init;
284 };
285
286 void gk20a_fecs_dump_falcon_stats(struct gk20a *g);
287
288 struct gk20a_ctxsw_ucode_segment {
289         u32 offset;
290         u32 size;
291 };
292
293 struct gk20a_ctxsw_ucode_segments {
294         u32 boot_entry;
295         u32 boot_imem_offset;
296         struct gk20a_ctxsw_ucode_segment boot;
297         struct gk20a_ctxsw_ucode_segment code;
298         struct gk20a_ctxsw_ucode_segment data;
299 };
300
301 struct gk20a_ctxsw_ucode_info {
302         u64 *p_va;
303         struct inst_desc inst_blk_desc;
304         struct surface_mem_desc surface_desc;
305         u64 ucode_gpuva;
306         struct gk20a_ctxsw_ucode_segments fecs;
307         struct gk20a_ctxsw_ucode_segments gpccs;
308 };
309
310 struct gk20a_ctxsw_bootloader_desc {
311         u32 start_offset;
312         u32 size;
313         u32 imem_offset;
314         u32 entry_point;
315 };
316
317 struct gpu_ops;
318 void gk20a_init_gr(struct gk20a *g);
319 void gk20a_init_gr_ops(struct gpu_ops *gops);
320 int gk20a_init_gr_support(struct gk20a *g);
321 int gk20a_gr_reset(struct gk20a *g);
322 void gk20a_gr_wait_initialized(struct gk20a *g);
323
324 int gk20a_init_gr_channel(struct channel_gk20a *ch_gk20a);
325
326 int gr_gk20a_init_ctx_vars(struct gk20a *g, struct gr_gk20a *gr);
327
328 struct nvhost_alloc_obj_ctx_args;
329 struct nvhost_free_obj_ctx_args;
330
331 int gk20a_alloc_obj_ctx(struct channel_gk20a *c,
332                         struct nvhost_alloc_obj_ctx_args *args);
333 int gk20a_free_obj_ctx(struct channel_gk20a *c,
334                         struct nvhost_free_obj_ctx_args *args);
335 void gk20a_free_channel_ctx(struct channel_gk20a *c);
336
337 int gk20a_gr_isr(struct gk20a *g);
338 int gk20a_gr_nonstall_isr(struct gk20a *g);
339
340 /* zcull */
341 u32 gr_gk20a_get_ctxsw_zcull_size(struct gk20a *g, struct gr_gk20a *gr);
342 int gr_gk20a_bind_ctxsw_zcull(struct gk20a *g, struct gr_gk20a *gr,
343                         struct channel_gk20a *c, u64 zcull_va, u32 mode);
344 int gr_gk20a_get_zcull_info(struct gk20a *g, struct gr_gk20a *gr,
345                         struct gr_zcull_info *zcull_params);
346 /* zbc */
347 int gr_gk20a_add_zbc(struct gk20a *g, struct gr_gk20a *gr,
348                         struct zbc_entry *zbc_val);
349 int gr_gk20a_query_zbc(struct gk20a *g, struct gr_gk20a *gr,
350                         struct zbc_query_params *query_params);
351 int gk20a_gr_zbc_set_table(struct gk20a *g, struct gr_gk20a *gr,
352                         struct zbc_entry *zbc_val);
353 int gr_gk20a_load_zbc_default_table(struct gk20a *g, struct gr_gk20a *gr);
354
355 /* pmu */
356 int gr_gk20a_fecs_get_reglist_img_size(struct gk20a *g, u32 *size);
357 int gr_gk20a_fecs_set_reglist_bind_inst(struct gk20a *g, phys_addr_t addr);
358 int gr_gk20a_fecs_set_reglist_virtual_addr(struct gk20a *g, u64 pmu_va);
359
360 void gr_gk20a_init_elcg_mode(struct gk20a *g, u32 mode, u32 engine);
361 void gr_gk20a_init_blcg_mode(struct gk20a *g, u32 mode, u32 engine);
362
363 void gr_gk20a_pmu_save_zbc(struct gk20a *g, u32 entries);
364
365 /* sm */
366 bool gk20a_gr_sm_debugger_attached(struct gk20a *g);
367
368 #define gr_gk20a_elpg_protected_call(g, func) \
369         ({ \
370                 int err = 0; \
371                 if (support_gk20a_pmu()) \
372                         err = gk20a_pmu_disable_elpg(g); \
373                 if (err) return err; \
374                 err = func; \
375                 if (support_gk20a_pmu()) \
376                         gk20a_pmu_enable_elpg(g); \
377                 err; \
378         })
379
380 int gk20a_gr_suspend(struct gk20a *g);
381
382 struct nvhost_dbg_gpu_reg_op;
383 int gr_gk20a_exec_ctx_ops(struct channel_gk20a *ch,
384                           struct nvhost_dbg_gpu_reg_op *ctx_ops, u32 num_ops,
385                           u32 num_ctx_wr_ops, u32 num_ctx_rd_ops);
386 int gr_gk20a_get_ctx_buffer_offsets(struct gk20a *g,
387                                     u32 addr,
388                                     u32 max_offsets,
389                                     u32 *offsets, u32 *offset_addrs,
390                                     u32 *num_offsets,
391                                     bool is_quad, u32 quad);
392 int gr_gk20a_update_smpc_ctxsw_mode(struct gk20a *g,
393                                  struct channel_gk20a *c,
394                                     bool enable_smpc_ctxsw);
395
396 struct channel_ctx_gk20a;
397 int gr_gk20a_ctx_patch_write(struct gk20a *g, struct channel_ctx_gk20a *ch_ctx,
398                                     u32 addr, u32 data, bool patch);
399 int gr_gk20a_ctx_patch_write_begin(struct gk20a *g,
400                                           struct channel_ctx_gk20a *ch_ctx);
401 int gr_gk20a_ctx_patch_write_end(struct gk20a *g,
402                                         struct channel_ctx_gk20a *ch_ctx);
403 void gr_gk20a_commit_global_pagepool(struct gk20a *g,
404                                      struct channel_ctx_gk20a *ch_ctx,
405                                      u64 addr, u32 size, bool patch);
406 void gk20a_gr_set_shader_exceptions(struct gk20a *g, u32 data);
407 void gr_gk20a_enable_hww_exceptions(struct gk20a *g);
408 void gr_gk20a_get_sm_dsm_perf_regs(struct gk20a *g,
409                                    u32 *num_sm_dsm_perf_regs,
410                                    u32 **sm_dsm_perf_regs,
411                                    u32 *perf_register_stride);
412 void gr_gk20a_get_sm_dsm_perf_ctrl_regs(struct gk20a *g,
413                                         u32 *num_sm_dsm_perf_regs,
414                                         u32 **sm_dsm_perf_regs,
415                                         u32 *perf_register_stride);
416 int gr_gk20a_setup_rop_mapping(struct gk20a *g, struct gr_gk20a *gr);
417 #endif /*__GR_GK20A_H__*/