blob: f2e5c545c973d2b2e973f85fd3451749113271d0 [file] [log] [blame]
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001/*
2 * Copyright 2010 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
28#include "drmP.h"
29#include "radeon.h"
30#include "evergreend.h"
31#include "evergreen_reg_safe.h"
Alex Deucherc175ca92011-03-02 20:07:37 -050032#include "cayman_reg_safe.h"
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040033
Jerome Glisse285484e2011-12-16 17:03:42 -050034#define MAX(a,b) (((a)>(b))?(a):(b))
35#define MIN(a,b) (((a)<(b))?(a):(b))
36
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040037static int evergreen_cs_packet_next_reloc(struct radeon_cs_parser *p,
38 struct radeon_cs_reloc **cs_reloc);
39
40struct evergreen_cs_track {
41 u32 group_size;
42 u32 nbanks;
43 u32 npipes;
Alex Deucherf3a71df2011-11-28 14:49:28 -050044 u32 row_size;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040045 /* value we track */
Marek Olšák747e42a102012-03-19 03:09:36 +010046 u32 nsamples; /* unused */
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040047 struct radeon_bo *cb_color_bo[12];
48 u32 cb_color_bo_offset[12];
Marek Olšák747e42a102012-03-19 03:09:36 +010049 struct radeon_bo *cb_color_fmask_bo[8]; /* unused */
50 struct radeon_bo *cb_color_cmask_bo[8]; /* unused */
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040051 u32 cb_color_info[12];
52 u32 cb_color_view[12];
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040053 u32 cb_color_pitch[12];
54 u32 cb_color_slice[12];
Jerome Glissed2609872012-06-09 10:57:41 -040055 u32 cb_color_slice_idx[12];
Jerome Glisse285484e2011-12-16 17:03:42 -050056 u32 cb_color_attrib[12];
Marek Olšák747e42a102012-03-19 03:09:36 +010057 u32 cb_color_cmask_slice[8];/* unused */
58 u32 cb_color_fmask_slice[8];/* unused */
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040059 u32 cb_target_mask;
Marek Olšák747e42a102012-03-19 03:09:36 +010060 u32 cb_shader_mask; /* unused */
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040061 u32 vgt_strmout_config;
62 u32 vgt_strmout_buffer_config;
Marek Olšákdd220a02012-01-27 12:17:59 -050063 struct radeon_bo *vgt_strmout_bo[4];
Marek Olšákdd220a02012-01-27 12:17:59 -050064 u32 vgt_strmout_bo_offset[4];
65 u32 vgt_strmout_size[4];
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040066 u32 db_depth_control;
67 u32 db_depth_view;
Jerome Glisse285484e2011-12-16 17:03:42 -050068 u32 db_depth_slice;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040069 u32 db_depth_size;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040070 u32 db_z_info;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040071 u32 db_z_read_offset;
72 u32 db_z_write_offset;
73 struct radeon_bo *db_z_read_bo;
74 struct radeon_bo *db_z_write_bo;
75 u32 db_s_info;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040076 u32 db_s_read_offset;
77 u32 db_s_write_offset;
78 struct radeon_bo *db_s_read_bo;
79 struct radeon_bo *db_s_write_bo;
Marek Olšák779923b2012-03-08 00:56:00 +010080 bool sx_misc_kill_all_prims;
Marek Olšák30838572012-03-19 03:09:35 +010081 bool cb_dirty;
82 bool db_dirty;
83 bool streamout_dirty;
Jerome Glisse88f50c82012-03-21 19:18:21 -040084 u32 htile_offset;
85 u32 htile_surface;
86 struct radeon_bo *htile_bo;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -040087};
88
Alex Deucherf3a71df2011-11-28 14:49:28 -050089static u32 evergreen_cs_get_aray_mode(u32 tiling_flags)
90{
91 if (tiling_flags & RADEON_TILING_MACRO)
92 return ARRAY_2D_TILED_THIN1;
93 else if (tiling_flags & RADEON_TILING_MICRO)
94 return ARRAY_1D_TILED_THIN1;
95 else
96 return ARRAY_LINEAR_GENERAL;
97}
98
99static u32 evergreen_cs_get_num_banks(u32 nbanks)
100{
101 switch (nbanks) {
102 case 2:
103 return ADDR_SURF_2_BANK;
104 case 4:
105 return ADDR_SURF_4_BANK;
106 case 8:
107 default:
108 return ADDR_SURF_8_BANK;
109 case 16:
110 return ADDR_SURF_16_BANK;
111 }
112}
113
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400114static void evergreen_cs_track_init(struct evergreen_cs_track *track)
115{
116 int i;
117
118 for (i = 0; i < 8; i++) {
119 track->cb_color_fmask_bo[i] = NULL;
120 track->cb_color_cmask_bo[i] = NULL;
121 track->cb_color_cmask_slice[i] = 0;
122 track->cb_color_fmask_slice[i] = 0;
123 }
124
125 for (i = 0; i < 12; i++) {
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400126 track->cb_color_bo[i] = NULL;
127 track->cb_color_bo_offset[i] = 0xFFFFFFFF;
128 track->cb_color_info[i] = 0;
Jerome Glisse285484e2011-12-16 17:03:42 -0500129 track->cb_color_view[i] = 0xFFFFFFFF;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400130 track->cb_color_pitch[i] = 0;
Jerome Glissed2609872012-06-09 10:57:41 -0400131 track->cb_color_slice[i] = 0xfffffff;
132 track->cb_color_slice_idx[i] = 0;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400133 }
134 track->cb_target_mask = 0xFFFFFFFF;
135 track->cb_shader_mask = 0xFFFFFFFF;
Marek Olšák30838572012-03-19 03:09:35 +0100136 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400137
Jerome Glissed2609872012-06-09 10:57:41 -0400138 track->db_depth_slice = 0xffffffff;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400139 track->db_depth_view = 0xFFFFC000;
140 track->db_depth_size = 0xFFFFFFFF;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400141 track->db_depth_control = 0xFFFFFFFF;
142 track->db_z_info = 0xFFFFFFFF;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400143 track->db_z_read_offset = 0xFFFFFFFF;
144 track->db_z_write_offset = 0xFFFFFFFF;
145 track->db_z_read_bo = NULL;
146 track->db_z_write_bo = NULL;
147 track->db_s_info = 0xFFFFFFFF;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400148 track->db_s_read_offset = 0xFFFFFFFF;
149 track->db_s_write_offset = 0xFFFFFFFF;
150 track->db_s_read_bo = NULL;
151 track->db_s_write_bo = NULL;
Marek Olšák30838572012-03-19 03:09:35 +0100152 track->db_dirty = true;
Jerome Glisse88f50c82012-03-21 19:18:21 -0400153 track->htile_bo = NULL;
154 track->htile_offset = 0xFFFFFFFF;
155 track->htile_surface = 0;
Marek Olšákdd220a02012-01-27 12:17:59 -0500156
157 for (i = 0; i < 4; i++) {
158 track->vgt_strmout_size[i] = 0;
159 track->vgt_strmout_bo[i] = NULL;
160 track->vgt_strmout_bo_offset[i] = 0xFFFFFFFF;
Marek Olšákdd220a02012-01-27 12:17:59 -0500161 }
Marek Olšák30838572012-03-19 03:09:35 +0100162 track->streamout_dirty = true;
Marek Olšák779923b2012-03-08 00:56:00 +0100163 track->sx_misc_kill_all_prims = false;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400164}
165
Jerome Glisse285484e2011-12-16 17:03:42 -0500166struct eg_surface {
167 /* value gathered from cs */
168 unsigned nbx;
169 unsigned nby;
170 unsigned format;
171 unsigned mode;
172 unsigned nbanks;
173 unsigned bankw;
174 unsigned bankh;
175 unsigned tsplit;
176 unsigned mtilea;
177 unsigned nsamples;
178 /* output value */
179 unsigned bpe;
180 unsigned layer_size;
181 unsigned palign;
182 unsigned halign;
183 unsigned long base_align;
184};
185
186static int evergreen_surface_check_linear(struct radeon_cs_parser *p,
187 struct eg_surface *surf,
188 const char *prefix)
189{
190 surf->layer_size = surf->nbx * surf->nby * surf->bpe * surf->nsamples;
191 surf->base_align = surf->bpe;
192 surf->palign = 1;
193 surf->halign = 1;
194 return 0;
195}
196
197static int evergreen_surface_check_linear_aligned(struct radeon_cs_parser *p,
198 struct eg_surface *surf,
199 const char *prefix)
200{
201 struct evergreen_cs_track *track = p->track;
202 unsigned palign;
203
204 palign = MAX(64, track->group_size / surf->bpe);
205 surf->layer_size = surf->nbx * surf->nby * surf->bpe * surf->nsamples;
206 surf->base_align = track->group_size;
207 surf->palign = palign;
208 surf->halign = 1;
209 if (surf->nbx & (palign - 1)) {
210 if (prefix) {
211 dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
212 __func__, __LINE__, prefix, surf->nbx, palign);
213 }
214 return -EINVAL;
215 }
216 return 0;
217}
218
219static int evergreen_surface_check_1d(struct radeon_cs_parser *p,
220 struct eg_surface *surf,
221 const char *prefix)
222{
223 struct evergreen_cs_track *track = p->track;
224 unsigned palign;
225
226 palign = track->group_size / (8 * surf->bpe * surf->nsamples);
227 palign = MAX(8, palign);
228 surf->layer_size = surf->nbx * surf->nby * surf->bpe;
229 surf->base_align = track->group_size;
230 surf->palign = palign;
231 surf->halign = 8;
232 if ((surf->nbx & (palign - 1))) {
233 if (prefix) {
234 dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d (%d %d %d)\n",
235 __func__, __LINE__, prefix, surf->nbx, palign,
236 track->group_size, surf->bpe, surf->nsamples);
237 }
238 return -EINVAL;
239 }
240 if ((surf->nby & (8 - 1))) {
241 if (prefix) {
242 dev_warn(p->dev, "%s:%d %s height %d invalid must be aligned with 8\n",
243 __func__, __LINE__, prefix, surf->nby);
244 }
245 return -EINVAL;
246 }
247 return 0;
248}
249
250static int evergreen_surface_check_2d(struct radeon_cs_parser *p,
251 struct eg_surface *surf,
252 const char *prefix)
253{
254 struct evergreen_cs_track *track = p->track;
255 unsigned palign, halign, tileb, slice_pt;
Jerome Glissed2609872012-06-09 10:57:41 -0400256 unsigned mtile_pr, mtile_ps, mtileb;
Jerome Glisse285484e2011-12-16 17:03:42 -0500257
258 tileb = 64 * surf->bpe * surf->nsamples;
Jerome Glisse285484e2011-12-16 17:03:42 -0500259 slice_pt = 1;
260 if (tileb > surf->tsplit) {
261 slice_pt = tileb / surf->tsplit;
262 }
263 tileb = tileb / slice_pt;
264 /* macro tile width & height */
265 palign = (8 * surf->bankw * track->npipes) * surf->mtilea;
266 halign = (8 * surf->bankh * surf->nbanks) / surf->mtilea;
Jerome Glissed2609872012-06-09 10:57:41 -0400267 mtileb = (palign / 8) * (halign / 8) * tileb;;
268 mtile_pr = surf->nbx / palign;
269 mtile_ps = (mtile_pr * surf->nby) / halign;
270 surf->layer_size = mtile_ps * mtileb * slice_pt;
Jerome Glisse285484e2011-12-16 17:03:42 -0500271 surf->base_align = (palign / 8) * (halign / 8) * tileb;
272 surf->palign = palign;
273 surf->halign = halign;
274
275 if ((surf->nbx & (palign - 1))) {
276 if (prefix) {
277 dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
278 __func__, __LINE__, prefix, surf->nbx, palign);
279 }
280 return -EINVAL;
281 }
282 if ((surf->nby & (halign - 1))) {
283 if (prefix) {
284 dev_warn(p->dev, "%s:%d %s height %d invalid must be aligned with %d\n",
285 __func__, __LINE__, prefix, surf->nby, halign);
286 }
287 return -EINVAL;
288 }
289
290 return 0;
291}
292
293static int evergreen_surface_check(struct radeon_cs_parser *p,
294 struct eg_surface *surf,
295 const char *prefix)
296{
297 /* some common value computed here */
298 surf->bpe = r600_fmt_get_blocksize(surf->format);
299
300 switch (surf->mode) {
301 case ARRAY_LINEAR_GENERAL:
302 return evergreen_surface_check_linear(p, surf, prefix);
303 case ARRAY_LINEAR_ALIGNED:
304 return evergreen_surface_check_linear_aligned(p, surf, prefix);
305 case ARRAY_1D_TILED_THIN1:
306 return evergreen_surface_check_1d(p, surf, prefix);
307 case ARRAY_2D_TILED_THIN1:
308 return evergreen_surface_check_2d(p, surf, prefix);
309 default:
Marek Olšák7df7c542012-03-19 03:09:32 +0100310 dev_warn(p->dev, "%s:%d %s invalid array mode %d\n",
311 __func__, __LINE__, prefix, surf->mode);
Jerome Glisse285484e2011-12-16 17:03:42 -0500312 return -EINVAL;
313 }
314 return -EINVAL;
315}
316
317static int evergreen_surface_value_conv_check(struct radeon_cs_parser *p,
318 struct eg_surface *surf,
319 const char *prefix)
320{
321 switch (surf->mode) {
322 case ARRAY_2D_TILED_THIN1:
323 break;
324 case ARRAY_LINEAR_GENERAL:
325 case ARRAY_LINEAR_ALIGNED:
326 case ARRAY_1D_TILED_THIN1:
327 return 0;
328 default:
Marek Olšák7df7c542012-03-19 03:09:32 +0100329 dev_warn(p->dev, "%s:%d %s invalid array mode %d\n",
330 __func__, __LINE__, prefix, surf->mode);
Jerome Glisse285484e2011-12-16 17:03:42 -0500331 return -EINVAL;
332 }
333
334 switch (surf->nbanks) {
335 case 0: surf->nbanks = 2; break;
336 case 1: surf->nbanks = 4; break;
337 case 2: surf->nbanks = 8; break;
338 case 3: surf->nbanks = 16; break;
339 default:
340 dev_warn(p->dev, "%s:%d %s invalid number of banks %d\n",
341 __func__, __LINE__, prefix, surf->nbanks);
342 return -EINVAL;
343 }
344 switch (surf->bankw) {
345 case 0: surf->bankw = 1; break;
346 case 1: surf->bankw = 2; break;
347 case 2: surf->bankw = 4; break;
348 case 3: surf->bankw = 8; break;
349 default:
350 dev_warn(p->dev, "%s:%d %s invalid bankw %d\n",
351 __func__, __LINE__, prefix, surf->bankw);
352 return -EINVAL;
353 }
354 switch (surf->bankh) {
355 case 0: surf->bankh = 1; break;
356 case 1: surf->bankh = 2; break;
357 case 2: surf->bankh = 4; break;
358 case 3: surf->bankh = 8; break;
359 default:
360 dev_warn(p->dev, "%s:%d %s invalid bankh %d\n",
361 __func__, __LINE__, prefix, surf->bankh);
362 return -EINVAL;
363 }
364 switch (surf->mtilea) {
365 case 0: surf->mtilea = 1; break;
366 case 1: surf->mtilea = 2; break;
367 case 2: surf->mtilea = 4; break;
368 case 3: surf->mtilea = 8; break;
369 default:
370 dev_warn(p->dev, "%s:%d %s invalid macro tile aspect %d\n",
371 __func__, __LINE__, prefix, surf->mtilea);
372 return -EINVAL;
373 }
374 switch (surf->tsplit) {
375 case 0: surf->tsplit = 64; break;
376 case 1: surf->tsplit = 128; break;
377 case 2: surf->tsplit = 256; break;
378 case 3: surf->tsplit = 512; break;
379 case 4: surf->tsplit = 1024; break;
380 case 5: surf->tsplit = 2048; break;
381 case 6: surf->tsplit = 4096; break;
382 default:
383 dev_warn(p->dev, "%s:%d %s invalid tile split %d\n",
384 __func__, __LINE__, prefix, surf->tsplit);
385 return -EINVAL;
386 }
387 return 0;
388}
389
390static int evergreen_cs_track_validate_cb(struct radeon_cs_parser *p, unsigned id)
391{
392 struct evergreen_cs_track *track = p->track;
393 struct eg_surface surf;
394 unsigned pitch, slice, mslice;
395 unsigned long offset;
396 int r;
397
398 mslice = G_028C6C_SLICE_MAX(track->cb_color_view[id]) + 1;
399 pitch = track->cb_color_pitch[id];
400 slice = track->cb_color_slice[id];
401 surf.nbx = (pitch + 1) * 8;
402 surf.nby = ((slice + 1) * 64) / surf.nbx;
403 surf.mode = G_028C70_ARRAY_MODE(track->cb_color_info[id]);
404 surf.format = G_028C70_FORMAT(track->cb_color_info[id]);
405 surf.tsplit = G_028C74_TILE_SPLIT(track->cb_color_attrib[id]);
406 surf.nbanks = G_028C74_NUM_BANKS(track->cb_color_attrib[id]);
407 surf.bankw = G_028C74_BANK_WIDTH(track->cb_color_attrib[id]);
408 surf.bankh = G_028C74_BANK_HEIGHT(track->cb_color_attrib[id]);
409 surf.mtilea = G_028C74_MACRO_TILE_ASPECT(track->cb_color_attrib[id]);
410 surf.nsamples = 1;
411
412 if (!r600_fmt_is_valid_color(surf.format)) {
413 dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08x)\n",
414 __func__, __LINE__, surf.format,
415 id, track->cb_color_info[id]);
416 return -EINVAL;
417 }
418
419 r = evergreen_surface_value_conv_check(p, &surf, "cb");
420 if (r) {
421 return r;
422 }
423
424 r = evergreen_surface_check(p, &surf, "cb");
425 if (r) {
426 dev_warn(p->dev, "%s:%d cb[%d] invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
427 __func__, __LINE__, id, track->cb_color_pitch[id],
428 track->cb_color_slice[id], track->cb_color_attrib[id],
429 track->cb_color_info[id]);
430 return r;
431 }
432
433 offset = track->cb_color_bo_offset[id] << 8;
434 if (offset & (surf.base_align - 1)) {
435 dev_warn(p->dev, "%s:%d cb[%d] bo base %ld not aligned with %ld\n",
436 __func__, __LINE__, id, offset, surf.base_align);
437 return -EINVAL;
438 }
439
440 offset += surf.layer_size * mslice;
441 if (offset > radeon_bo_size(track->cb_color_bo[id])) {
Jerome Glissed2609872012-06-09 10:57:41 -0400442 /* old ddx are broken they allocate bo with w*h*bpp but
443 * program slice with ALIGN(h, 8), catch this and patch
444 * command stream.
445 */
446 if (!surf.mode) {
447 volatile u32 *ib = p->ib.ptr;
448 unsigned long tmp, nby, bsize, size, min = 0;
449
450 /* find the height the ddx wants */
451 if (surf.nby > 8) {
452 min = surf.nby - 8;
453 }
454 bsize = radeon_bo_size(track->cb_color_bo[id]);
455 tmp = track->cb_color_bo_offset[id] << 8;
456 for (nby = surf.nby; nby > min; nby--) {
457 size = nby * surf.nbx * surf.bpe * surf.nsamples;
458 if ((tmp + size * mslice) <= bsize) {
459 break;
460 }
461 }
462 if (nby > min) {
463 surf.nby = nby;
464 slice = ((nby * surf.nbx) / 64) - 1;
465 if (!evergreen_surface_check(p, &surf, "cb")) {
466 /* check if this one works */
467 tmp += surf.layer_size * mslice;
468 if (tmp <= bsize) {
469 ib[track->cb_color_slice_idx[id]] = slice;
470 goto old_ddx_ok;
471 }
472 }
473 }
474 }
Jerome Glisse285484e2011-12-16 17:03:42 -0500475 dev_warn(p->dev, "%s:%d cb[%d] bo too small (layer size %d, "
476 "offset %d, max layer %d, bo size %ld, slice %d)\n",
477 __func__, __LINE__, id, surf.layer_size,
478 track->cb_color_bo_offset[id] << 8, mslice,
479 radeon_bo_size(track->cb_color_bo[id]), slice);
480 dev_warn(p->dev, "%s:%d problematic surf: (%d %d) (%d %d %d %d %d %d %d)\n",
481 __func__, __LINE__, surf.nbx, surf.nby,
482 surf.mode, surf.bpe, surf.nsamples,
483 surf.bankw, surf.bankh,
484 surf.tsplit, surf.mtilea);
485 return -EINVAL;
486 }
Jerome Glissed2609872012-06-09 10:57:41 -0400487old_ddx_ok:
Jerome Glisse285484e2011-12-16 17:03:42 -0500488
489 return 0;
490}
491
Jerome Glisse88f50c82012-03-21 19:18:21 -0400492static int evergreen_cs_track_validate_htile(struct radeon_cs_parser *p,
493 unsigned nbx, unsigned nby)
494{
495 struct evergreen_cs_track *track = p->track;
496 unsigned long size;
497
498 if (track->htile_bo == NULL) {
499 dev_warn(p->dev, "%s:%d htile enabled without htile surface 0x%08x\n",
500 __func__, __LINE__, track->db_z_info);
501 return -EINVAL;
502 }
503
504 if (G_028ABC_LINEAR(track->htile_surface)) {
505 /* pitch must be 16 htiles aligned == 16 * 8 pixel aligned */
506 nbx = round_up(nbx, 16 * 8);
507 /* height is npipes htiles aligned == npipes * 8 pixel aligned */
508 nby = round_up(nby, track->npipes * 8);
509 } else {
510 switch (track->npipes) {
511 case 8:
512 nbx = round_up(nbx, 64 * 8);
513 nby = round_up(nby, 64 * 8);
514 break;
515 case 4:
516 nbx = round_up(nbx, 64 * 8);
517 nby = round_up(nby, 32 * 8);
518 break;
519 case 2:
520 nbx = round_up(nbx, 32 * 8);
521 nby = round_up(nby, 32 * 8);
522 break;
523 case 1:
524 nbx = round_up(nbx, 32 * 8);
525 nby = round_up(nby, 16 * 8);
526 break;
527 default:
528 dev_warn(p->dev, "%s:%d invalid num pipes %d\n",
529 __func__, __LINE__, track->npipes);
530 return -EINVAL;
531 }
532 }
533 /* compute number of htile */
534 nbx = nbx / 8;
535 nby = nby / 8;
536 size = nbx * nby * 4;
537 size += track->htile_offset;
538
539 if (size > radeon_bo_size(track->htile_bo)) {
540 dev_warn(p->dev, "%s:%d htile surface too small %ld for %ld (%d %d)\n",
541 __func__, __LINE__, radeon_bo_size(track->htile_bo),
542 size, nbx, nby);
543 return -EINVAL;
544 }
545 return 0;
546}
547
Jerome Glisse285484e2011-12-16 17:03:42 -0500548static int evergreen_cs_track_validate_stencil(struct radeon_cs_parser *p)
549{
550 struct evergreen_cs_track *track = p->track;
551 struct eg_surface surf;
552 unsigned pitch, slice, mslice;
553 unsigned long offset;
554 int r;
555
556 mslice = G_028008_SLICE_MAX(track->db_depth_view) + 1;
557 pitch = G_028058_PITCH_TILE_MAX(track->db_depth_size);
558 slice = track->db_depth_slice;
559 surf.nbx = (pitch + 1) * 8;
560 surf.nby = ((slice + 1) * 64) / surf.nbx;
561 surf.mode = G_028040_ARRAY_MODE(track->db_z_info);
562 surf.format = G_028044_FORMAT(track->db_s_info);
563 surf.tsplit = G_028044_TILE_SPLIT(track->db_s_info);
564 surf.nbanks = G_028040_NUM_BANKS(track->db_z_info);
565 surf.bankw = G_028040_BANK_WIDTH(track->db_z_info);
566 surf.bankh = G_028040_BANK_HEIGHT(track->db_z_info);
567 surf.mtilea = G_028040_MACRO_TILE_ASPECT(track->db_z_info);
568 surf.nsamples = 1;
569
570 if (surf.format != 1) {
571 dev_warn(p->dev, "%s:%d stencil invalid format %d\n",
572 __func__, __LINE__, surf.format);
573 return -EINVAL;
574 }
575 /* replace by color format so we can use same code */
576 surf.format = V_028C70_COLOR_8;
577
578 r = evergreen_surface_value_conv_check(p, &surf, "stencil");
579 if (r) {
580 return r;
581 }
582
583 r = evergreen_surface_check(p, &surf, NULL);
584 if (r) {
585 /* old userspace doesn't compute proper depth/stencil alignment
586 * check that alignment against a bigger byte per elements and
587 * only report if that alignment is wrong too.
588 */
589 surf.format = V_028C70_COLOR_8_8_8_8;
590 r = evergreen_surface_check(p, &surf, "stencil");
591 if (r) {
592 dev_warn(p->dev, "%s:%d stencil invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
593 __func__, __LINE__, track->db_depth_size,
594 track->db_depth_slice, track->db_s_info, track->db_z_info);
595 }
596 return r;
597 }
598
599 offset = track->db_s_read_offset << 8;
600 if (offset & (surf.base_align - 1)) {
601 dev_warn(p->dev, "%s:%d stencil read bo base %ld not aligned with %ld\n",
602 __func__, __LINE__, offset, surf.base_align);
603 return -EINVAL;
604 }
605 offset += surf.layer_size * mslice;
606 if (offset > radeon_bo_size(track->db_s_read_bo)) {
607 dev_warn(p->dev, "%s:%d stencil read bo too small (layer size %d, "
608 "offset %ld, max layer %d, bo size %ld)\n",
609 __func__, __LINE__, surf.layer_size,
610 (unsigned long)track->db_s_read_offset << 8, mslice,
611 radeon_bo_size(track->db_s_read_bo));
612 dev_warn(p->dev, "%s:%d stencil invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
613 __func__, __LINE__, track->db_depth_size,
614 track->db_depth_slice, track->db_s_info, track->db_z_info);
615 return -EINVAL;
616 }
617
618 offset = track->db_s_write_offset << 8;
619 if (offset & (surf.base_align - 1)) {
620 dev_warn(p->dev, "%s:%d stencil write bo base %ld not aligned with %ld\n",
621 __func__, __LINE__, offset, surf.base_align);
622 return -EINVAL;
623 }
624 offset += surf.layer_size * mslice;
625 if (offset > radeon_bo_size(track->db_s_write_bo)) {
626 dev_warn(p->dev, "%s:%d stencil write bo too small (layer size %d, "
627 "offset %ld, max layer %d, bo size %ld)\n",
628 __func__, __LINE__, surf.layer_size,
629 (unsigned long)track->db_s_write_offset << 8, mslice,
630 radeon_bo_size(track->db_s_write_bo));
631 return -EINVAL;
632 }
633
Jerome Glisse88f50c82012-03-21 19:18:21 -0400634 /* hyperz */
635 if (G_028040_TILE_SURFACE_ENABLE(track->db_z_info)) {
636 r = evergreen_cs_track_validate_htile(p, surf.nbx, surf.nby);
637 if (r) {
638 return r;
639 }
640 }
641
Jerome Glisse285484e2011-12-16 17:03:42 -0500642 return 0;
643}
644
645static int evergreen_cs_track_validate_depth(struct radeon_cs_parser *p)
646{
647 struct evergreen_cs_track *track = p->track;
648 struct eg_surface surf;
649 unsigned pitch, slice, mslice;
650 unsigned long offset;
651 int r;
652
653 mslice = G_028008_SLICE_MAX(track->db_depth_view) + 1;
654 pitch = G_028058_PITCH_TILE_MAX(track->db_depth_size);
655 slice = track->db_depth_slice;
656 surf.nbx = (pitch + 1) * 8;
657 surf.nby = ((slice + 1) * 64) / surf.nbx;
658 surf.mode = G_028040_ARRAY_MODE(track->db_z_info);
659 surf.format = G_028040_FORMAT(track->db_z_info);
660 surf.tsplit = G_028040_TILE_SPLIT(track->db_z_info);
661 surf.nbanks = G_028040_NUM_BANKS(track->db_z_info);
662 surf.bankw = G_028040_BANK_WIDTH(track->db_z_info);
663 surf.bankh = G_028040_BANK_HEIGHT(track->db_z_info);
664 surf.mtilea = G_028040_MACRO_TILE_ASPECT(track->db_z_info);
665 surf.nsamples = 1;
666
667 switch (surf.format) {
668 case V_028040_Z_16:
669 surf.format = V_028C70_COLOR_16;
670 break;
671 case V_028040_Z_24:
672 case V_028040_Z_32_FLOAT:
673 surf.format = V_028C70_COLOR_8_8_8_8;
674 break;
675 default:
676 dev_warn(p->dev, "%s:%d depth invalid format %d\n",
677 __func__, __LINE__, surf.format);
678 return -EINVAL;
679 }
680
681 r = evergreen_surface_value_conv_check(p, &surf, "depth");
682 if (r) {
683 dev_warn(p->dev, "%s:%d depth invalid (0x%08x 0x%08x 0x%08x)\n",
684 __func__, __LINE__, track->db_depth_size,
685 track->db_depth_slice, track->db_z_info);
686 return r;
687 }
688
689 r = evergreen_surface_check(p, &surf, "depth");
690 if (r) {
691 dev_warn(p->dev, "%s:%d depth invalid (0x%08x 0x%08x 0x%08x)\n",
692 __func__, __LINE__, track->db_depth_size,
693 track->db_depth_slice, track->db_z_info);
694 return r;
695 }
696
697 offset = track->db_z_read_offset << 8;
698 if (offset & (surf.base_align - 1)) {
699 dev_warn(p->dev, "%s:%d stencil read bo base %ld not aligned with %ld\n",
700 __func__, __LINE__, offset, surf.base_align);
701 return -EINVAL;
702 }
703 offset += surf.layer_size * mslice;
704 if (offset > radeon_bo_size(track->db_z_read_bo)) {
705 dev_warn(p->dev, "%s:%d depth read bo too small (layer size %d, "
706 "offset %ld, max layer %d, bo size %ld)\n",
707 __func__, __LINE__, surf.layer_size,
708 (unsigned long)track->db_z_read_offset << 8, mslice,
709 radeon_bo_size(track->db_z_read_bo));
710 return -EINVAL;
711 }
712
713 offset = track->db_z_write_offset << 8;
714 if (offset & (surf.base_align - 1)) {
715 dev_warn(p->dev, "%s:%d stencil write bo base %ld not aligned with %ld\n",
716 __func__, __LINE__, offset, surf.base_align);
717 return -EINVAL;
718 }
719 offset += surf.layer_size * mslice;
720 if (offset > radeon_bo_size(track->db_z_write_bo)) {
721 dev_warn(p->dev, "%s:%d depth write bo too small (layer size %d, "
722 "offset %ld, max layer %d, bo size %ld)\n",
723 __func__, __LINE__, surf.layer_size,
724 (unsigned long)track->db_z_write_offset << 8, mslice,
725 radeon_bo_size(track->db_z_write_bo));
726 return -EINVAL;
727 }
728
Jerome Glisse88f50c82012-03-21 19:18:21 -0400729 /* hyperz */
730 if (G_028040_TILE_SURFACE_ENABLE(track->db_z_info)) {
731 r = evergreen_cs_track_validate_htile(p, surf.nbx, surf.nby);
732 if (r) {
733 return r;
734 }
735 }
736
Jerome Glisse285484e2011-12-16 17:03:42 -0500737 return 0;
738}
739
740static int evergreen_cs_track_validate_texture(struct radeon_cs_parser *p,
741 struct radeon_bo *texture,
742 struct radeon_bo *mipmap,
743 unsigned idx)
744{
745 struct eg_surface surf;
746 unsigned long toffset, moffset;
747 unsigned dim, llevel, mslice, width, height, depth, i;
Dan Carpenter42b923b2012-02-14 10:38:11 +0300748 u32 texdw[8];
Jerome Glisse285484e2011-12-16 17:03:42 -0500749 int r;
750
751 texdw[0] = radeon_get_ib_value(p, idx + 0);
752 texdw[1] = radeon_get_ib_value(p, idx + 1);
753 texdw[2] = radeon_get_ib_value(p, idx + 2);
754 texdw[3] = radeon_get_ib_value(p, idx + 3);
755 texdw[4] = radeon_get_ib_value(p, idx + 4);
756 texdw[5] = radeon_get_ib_value(p, idx + 5);
757 texdw[6] = radeon_get_ib_value(p, idx + 6);
758 texdw[7] = radeon_get_ib_value(p, idx + 7);
759 dim = G_030000_DIM(texdw[0]);
760 llevel = G_030014_LAST_LEVEL(texdw[5]);
761 mslice = G_030014_LAST_ARRAY(texdw[5]) + 1;
762 width = G_030000_TEX_WIDTH(texdw[0]) + 1;
763 height = G_030004_TEX_HEIGHT(texdw[1]) + 1;
764 depth = G_030004_TEX_DEPTH(texdw[1]) + 1;
765 surf.format = G_03001C_DATA_FORMAT(texdw[7]);
766 surf.nbx = (G_030000_PITCH(texdw[0]) + 1) * 8;
767 surf.nbx = r600_fmt_get_nblocksx(surf.format, surf.nbx);
768 surf.nby = r600_fmt_get_nblocksy(surf.format, height);
769 surf.mode = G_030004_ARRAY_MODE(texdw[1]);
770 surf.tsplit = G_030018_TILE_SPLIT(texdw[6]);
771 surf.nbanks = G_03001C_NUM_BANKS(texdw[7]);
772 surf.bankw = G_03001C_BANK_WIDTH(texdw[7]);
773 surf.bankh = G_03001C_BANK_HEIGHT(texdw[7]);
774 surf.mtilea = G_03001C_MACRO_TILE_ASPECT(texdw[7]);
775 surf.nsamples = 1;
776 toffset = texdw[2] << 8;
777 moffset = texdw[3] << 8;
778
779 if (!r600_fmt_is_valid_texture(surf.format, p->family)) {
780 dev_warn(p->dev, "%s:%d texture invalid format %d\n",
781 __func__, __LINE__, surf.format);
782 return -EINVAL;
783 }
784 switch (dim) {
785 case V_030000_SQ_TEX_DIM_1D:
786 case V_030000_SQ_TEX_DIM_2D:
787 case V_030000_SQ_TEX_DIM_CUBEMAP:
788 case V_030000_SQ_TEX_DIM_1D_ARRAY:
789 case V_030000_SQ_TEX_DIM_2D_ARRAY:
790 depth = 1;
791 case V_030000_SQ_TEX_DIM_3D:
792 break;
793 default:
794 dev_warn(p->dev, "%s:%d texture invalid dimension %d\n",
795 __func__, __LINE__, dim);
796 return -EINVAL;
797 }
798
799 r = evergreen_surface_value_conv_check(p, &surf, "texture");
800 if (r) {
801 return r;
802 }
803
804 /* align height */
805 evergreen_surface_check(p, &surf, NULL);
806 surf.nby = ALIGN(surf.nby, surf.halign);
807
808 r = evergreen_surface_check(p, &surf, "texture");
809 if (r) {
810 dev_warn(p->dev, "%s:%d texture invalid 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
811 __func__, __LINE__, texdw[0], texdw[1], texdw[4],
812 texdw[5], texdw[6], texdw[7]);
813 return r;
814 }
815
816 /* check texture size */
817 if (toffset & (surf.base_align - 1)) {
818 dev_warn(p->dev, "%s:%d texture bo base %ld not aligned with %ld\n",
819 __func__, __LINE__, toffset, surf.base_align);
820 return -EINVAL;
821 }
822 if (moffset & (surf.base_align - 1)) {
823 dev_warn(p->dev, "%s:%d mipmap bo base %ld not aligned with %ld\n",
824 __func__, __LINE__, moffset, surf.base_align);
825 return -EINVAL;
826 }
827 if (dim == SQ_TEX_DIM_3D) {
828 toffset += surf.layer_size * depth;
829 } else {
830 toffset += surf.layer_size * mslice;
831 }
832 if (toffset > radeon_bo_size(texture)) {
833 dev_warn(p->dev, "%s:%d texture bo too small (layer size %d, "
834 "offset %ld, max layer %d, depth %d, bo size %ld) (%d %d)\n",
835 __func__, __LINE__, surf.layer_size,
836 (unsigned long)texdw[2] << 8, mslice,
837 depth, radeon_bo_size(texture),
838 surf.nbx, surf.nby);
839 return -EINVAL;
840 }
841
842 /* check mipmap size */
843 for (i = 1; i <= llevel; i++) {
844 unsigned w, h, d;
845
846 w = r600_mip_minify(width, i);
847 h = r600_mip_minify(height, i);
848 d = r600_mip_minify(depth, i);
849 surf.nbx = r600_fmt_get_nblocksx(surf.format, w);
850 surf.nby = r600_fmt_get_nblocksy(surf.format, h);
851
852 switch (surf.mode) {
853 case ARRAY_2D_TILED_THIN1:
854 if (surf.nbx < surf.palign || surf.nby < surf.halign) {
855 surf.mode = ARRAY_1D_TILED_THIN1;
856 }
857 /* recompute alignment */
858 evergreen_surface_check(p, &surf, NULL);
859 break;
860 case ARRAY_LINEAR_GENERAL:
861 case ARRAY_LINEAR_ALIGNED:
862 case ARRAY_1D_TILED_THIN1:
863 break;
864 default:
865 dev_warn(p->dev, "%s:%d invalid array mode %d\n",
866 __func__, __LINE__, surf.mode);
867 return -EINVAL;
868 }
869 surf.nbx = ALIGN(surf.nbx, surf.palign);
870 surf.nby = ALIGN(surf.nby, surf.halign);
871
872 r = evergreen_surface_check(p, &surf, "mipmap");
873 if (r) {
874 return r;
875 }
876
877 if (dim == SQ_TEX_DIM_3D) {
878 moffset += surf.layer_size * d;
879 } else {
880 moffset += surf.layer_size * mslice;
881 }
882 if (moffset > radeon_bo_size(mipmap)) {
883 dev_warn(p->dev, "%s:%d mipmap [%d] bo too small (layer size %d, "
884 "offset %ld, coffset %ld, max layer %d, depth %d, "
885 "bo size %ld) level0 (%d %d %d)\n",
886 __func__, __LINE__, i, surf.layer_size,
887 (unsigned long)texdw[3] << 8, moffset, mslice,
888 d, radeon_bo_size(mipmap),
889 width, height, depth);
890 dev_warn(p->dev, "%s:%d problematic surf: (%d %d) (%d %d %d %d %d %d %d)\n",
891 __func__, __LINE__, surf.nbx, surf.nby,
892 surf.mode, surf.bpe, surf.nsamples,
893 surf.bankw, surf.bankh,
894 surf.tsplit, surf.mtilea);
895 return -EINVAL;
896 }
897 }
898
899 return 0;
900}
901
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400902static int evergreen_cs_track_check(struct radeon_cs_parser *p)
903{
904 struct evergreen_cs_track *track = p->track;
Marek Olšák7e9fa5f2012-03-19 03:09:34 +0100905 unsigned tmp, i;
Jerome Glisse285484e2011-12-16 17:03:42 -0500906 int r;
Marek Olšák7e9fa5f2012-03-19 03:09:34 +0100907 unsigned buffer_mask = 0;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400908
Marek Olšákdd220a02012-01-27 12:17:59 -0500909 /* check streamout */
Marek Olšák30838572012-03-19 03:09:35 +0100910 if (track->streamout_dirty && track->vgt_strmout_config) {
Marek Olšák7e9fa5f2012-03-19 03:09:34 +0100911 for (i = 0; i < 4; i++) {
912 if (track->vgt_strmout_config & (1 << i)) {
913 buffer_mask |= (track->vgt_strmout_buffer_config >> (i * 4)) & 0xf;
914 }
915 }
916
917 for (i = 0; i < 4; i++) {
918 if (buffer_mask & (1 << i)) {
919 if (track->vgt_strmout_bo[i]) {
920 u64 offset = (u64)track->vgt_strmout_bo_offset[i] +
921 (u64)track->vgt_strmout_size[i];
922 if (offset > radeon_bo_size(track->vgt_strmout_bo[i])) {
923 DRM_ERROR("streamout %d bo too small: 0x%llx, 0x%lx\n",
924 i, offset,
925 radeon_bo_size(track->vgt_strmout_bo[i]));
Marek Olšákdd220a02012-01-27 12:17:59 -0500926 return -EINVAL;
927 }
Marek Olšák7e9fa5f2012-03-19 03:09:34 +0100928 } else {
929 dev_warn(p->dev, "No buffer for streamout %d\n", i);
930 return -EINVAL;
Marek Olšákdd220a02012-01-27 12:17:59 -0500931 }
932 }
933 }
Marek Olšák30838572012-03-19 03:09:35 +0100934 track->streamout_dirty = false;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400935 }
936
Marek Olšák779923b2012-03-08 00:56:00 +0100937 if (track->sx_misc_kill_all_prims)
938 return 0;
939
Jerome Glisse285484e2011-12-16 17:03:42 -0500940 /* check that we have a cb for each enabled target
941 */
Marek Olšák30838572012-03-19 03:09:35 +0100942 if (track->cb_dirty) {
943 tmp = track->cb_target_mask;
944 for (i = 0; i < 8; i++) {
945 if ((tmp >> (i * 4)) & 0xF) {
946 /* at least one component is enabled */
947 if (track->cb_color_bo[i] == NULL) {
948 dev_warn(p->dev, "%s:%d mask 0x%08X | 0x%08X no cb for %d\n",
949 __func__, __LINE__, track->cb_target_mask, track->cb_shader_mask, i);
950 return -EINVAL;
951 }
952 /* check cb */
953 r = evergreen_cs_track_validate_cb(p, i);
954 if (r) {
955 return r;
956 }
Jerome Glisse285484e2011-12-16 17:03:42 -0500957 }
958 }
Marek Olšák30838572012-03-19 03:09:35 +0100959 track->cb_dirty = false;
Jerome Glisse285484e2011-12-16 17:03:42 -0500960 }
961
Marek Olšák30838572012-03-19 03:09:35 +0100962 if (track->db_dirty) {
963 /* Check stencil buffer */
Marek Olšák0f457e42012-07-29 16:24:57 +0200964 if (G_028044_FORMAT(track->db_s_info) != V_028044_STENCIL_INVALID &&
965 G_028800_STENCIL_ENABLE(track->db_depth_control)) {
Marek Olšák30838572012-03-19 03:09:35 +0100966 r = evergreen_cs_track_validate_stencil(p);
967 if (r)
968 return r;
969 }
970 /* Check depth buffer */
Marek Olšák0f457e42012-07-29 16:24:57 +0200971 if (G_028040_FORMAT(track->db_z_info) != V_028040_Z_INVALID &&
972 G_028800_Z_ENABLE(track->db_depth_control)) {
Marek Olšák30838572012-03-19 03:09:35 +0100973 r = evergreen_cs_track_validate_depth(p);
974 if (r)
975 return r;
976 }
977 track->db_dirty = false;
Jerome Glisse285484e2011-12-16 17:03:42 -0500978 }
979
Alex Deuchercb5fcbd2010-05-28 19:01:35 -0400980 return 0;
981}
982
983/**
984 * evergreen_cs_packet_parse() - parse cp packet and point ib index to next packet
985 * @parser: parser structure holding parsing context.
986 * @pkt: where to store packet informations
987 *
988 * Assume that chunk_ib_index is properly set. Will return -EINVAL
989 * if packet is bigger than remaining ib size. or if packets is unknown.
990 **/
991int evergreen_cs_packet_parse(struct radeon_cs_parser *p,
992 struct radeon_cs_packet *pkt,
993 unsigned idx)
994{
995 struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
996 uint32_t header;
997
998 if (idx >= ib_chunk->length_dw) {
999 DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
1000 idx, ib_chunk->length_dw);
1001 return -EINVAL;
1002 }
1003 header = radeon_get_ib_value(p, idx);
1004 pkt->idx = idx;
1005 pkt->type = CP_PACKET_GET_TYPE(header);
1006 pkt->count = CP_PACKET_GET_COUNT(header);
1007 pkt->one_reg_wr = 0;
1008 switch (pkt->type) {
1009 case PACKET_TYPE0:
1010 pkt->reg = CP_PACKET0_GET_REG(header);
1011 break;
1012 case PACKET_TYPE3:
1013 pkt->opcode = CP_PACKET3_GET_OPCODE(header);
1014 break;
1015 case PACKET_TYPE2:
1016 pkt->count = -1;
1017 break;
1018 default:
1019 DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
1020 return -EINVAL;
1021 }
1022 if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
1023 DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
1024 pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
1025 return -EINVAL;
1026 }
1027 return 0;
1028}
1029
1030/**
1031 * evergreen_cs_packet_next_reloc() - parse next packet which should be reloc packet3
1032 * @parser: parser structure holding parsing context.
1033 * @data: pointer to relocation data
1034 * @offset_start: starting offset
1035 * @offset_mask: offset mask (to align start offset on)
1036 * @reloc: reloc informations
1037 *
1038 * Check next packet is relocation packet3, do bo validation and compute
1039 * GPU offset using the provided start.
1040 **/
1041static int evergreen_cs_packet_next_reloc(struct radeon_cs_parser *p,
1042 struct radeon_cs_reloc **cs_reloc)
1043{
1044 struct radeon_cs_chunk *relocs_chunk;
1045 struct radeon_cs_packet p3reloc;
1046 unsigned idx;
1047 int r;
1048
1049 if (p->chunk_relocs_idx == -1) {
1050 DRM_ERROR("No relocation chunk !\n");
1051 return -EINVAL;
1052 }
1053 *cs_reloc = NULL;
1054 relocs_chunk = &p->chunks[p->chunk_relocs_idx];
1055 r = evergreen_cs_packet_parse(p, &p3reloc, p->idx);
1056 if (r) {
1057 return r;
1058 }
1059 p->idx += p3reloc.count + 2;
1060 if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
1061 DRM_ERROR("No packet3 for relocation for packet at %d.\n",
1062 p3reloc.idx);
1063 return -EINVAL;
1064 }
1065 idx = radeon_get_ib_value(p, p3reloc.idx + 1);
1066 if (idx >= relocs_chunk->length_dw) {
1067 DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
1068 idx, relocs_chunk->length_dw);
1069 return -EINVAL;
1070 }
1071 /* FIXME: we assume reloc size is 4 dwords */
1072 *cs_reloc = p->relocs_ptr[(idx / 4)];
1073 return 0;
1074}
1075
1076/**
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001077 * evergreen_cs_packet_next_vline() - parse userspace VLINE packet
1078 * @parser: parser structure holding parsing context.
1079 *
1080 * Userspace sends a special sequence for VLINE waits.
1081 * PACKET0 - VLINE_START_END + value
1082 * PACKET3 - WAIT_REG_MEM poll vline status reg
1083 * RELOC (P3) - crtc_id in reloc.
1084 *
1085 * This function parses this and relocates the VLINE START END
1086 * and WAIT_REG_MEM packets to the correct crtc.
1087 * It also detects a switched off crtc and nulls out the
1088 * wait in that case.
1089 */
1090static int evergreen_cs_packet_parse_vline(struct radeon_cs_parser *p)
1091{
1092 struct drm_mode_object *obj;
1093 struct drm_crtc *crtc;
1094 struct radeon_crtc *radeon_crtc;
1095 struct radeon_cs_packet p3reloc, wait_reg_mem;
1096 int crtc_id;
1097 int r;
1098 uint32_t header, h_idx, reg, wait_reg_mem_info;
1099 volatile uint32_t *ib;
1100
Jerome Glissef2e39222012-05-09 15:35:02 +02001101 ib = p->ib.ptr;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001102
1103 /* parse the WAIT_REG_MEM */
1104 r = evergreen_cs_packet_parse(p, &wait_reg_mem, p->idx);
1105 if (r)
1106 return r;
1107
1108 /* check its a WAIT_REG_MEM */
1109 if (wait_reg_mem.type != PACKET_TYPE3 ||
1110 wait_reg_mem.opcode != PACKET3_WAIT_REG_MEM) {
1111 DRM_ERROR("vline wait missing WAIT_REG_MEM segment\n");
Paul Bollea3a88a62011-03-16 22:10:06 +01001112 return -EINVAL;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001113 }
1114
1115 wait_reg_mem_info = radeon_get_ib_value(p, wait_reg_mem.idx + 1);
1116 /* bit 4 is reg (0) or mem (1) */
1117 if (wait_reg_mem_info & 0x10) {
1118 DRM_ERROR("vline WAIT_REG_MEM waiting on MEM rather than REG\n");
Paul Bollea3a88a62011-03-16 22:10:06 +01001119 return -EINVAL;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001120 }
1121 /* waiting for value to be equal */
1122 if ((wait_reg_mem_info & 0x7) != 0x3) {
1123 DRM_ERROR("vline WAIT_REG_MEM function not equal\n");
Paul Bollea3a88a62011-03-16 22:10:06 +01001124 return -EINVAL;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001125 }
1126 if ((radeon_get_ib_value(p, wait_reg_mem.idx + 2) << 2) != EVERGREEN_VLINE_STATUS) {
1127 DRM_ERROR("vline WAIT_REG_MEM bad reg\n");
Paul Bollea3a88a62011-03-16 22:10:06 +01001128 return -EINVAL;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001129 }
1130
1131 if (radeon_get_ib_value(p, wait_reg_mem.idx + 5) != EVERGREEN_VLINE_STAT) {
1132 DRM_ERROR("vline WAIT_REG_MEM bad bit mask\n");
Paul Bollea3a88a62011-03-16 22:10:06 +01001133 return -EINVAL;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001134 }
1135
1136 /* jump over the NOP */
1137 r = evergreen_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2);
1138 if (r)
1139 return r;
1140
1141 h_idx = p->idx - 2;
1142 p->idx += wait_reg_mem.count + 2;
1143 p->idx += p3reloc.count + 2;
1144
1145 header = radeon_get_ib_value(p, h_idx);
1146 crtc_id = radeon_get_ib_value(p, h_idx + 2 + 7 + 1);
1147 reg = CP_PACKET0_GET_REG(header);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001148 obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
1149 if (!obj) {
1150 DRM_ERROR("cannot find crtc %d\n", crtc_id);
Paul Bollea3a88a62011-03-16 22:10:06 +01001151 return -EINVAL;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001152 }
1153 crtc = obj_to_crtc(obj);
1154 radeon_crtc = to_radeon_crtc(crtc);
1155 crtc_id = radeon_crtc->crtc_id;
1156
1157 if (!crtc->enabled) {
1158 /* if the CRTC isn't enabled - we need to nop out the WAIT_REG_MEM */
1159 ib[h_idx + 2] = PACKET2(0);
1160 ib[h_idx + 3] = PACKET2(0);
1161 ib[h_idx + 4] = PACKET2(0);
1162 ib[h_idx + 5] = PACKET2(0);
1163 ib[h_idx + 6] = PACKET2(0);
1164 ib[h_idx + 7] = PACKET2(0);
1165 ib[h_idx + 8] = PACKET2(0);
1166 } else {
1167 switch (reg) {
1168 case EVERGREEN_VLINE_START_END:
1169 header &= ~R600_CP_PACKET0_REG_MASK;
1170 header |= (EVERGREEN_VLINE_START_END + radeon_crtc->crtc_offset) >> 2;
1171 ib[h_idx] = header;
1172 ib[h_idx + 4] = (EVERGREEN_VLINE_STATUS + radeon_crtc->crtc_offset) >> 2;
1173 break;
1174 default:
1175 DRM_ERROR("unknown crtc reloc\n");
Paul Bollea3a88a62011-03-16 22:10:06 +01001176 return -EINVAL;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001177 }
1178 }
Paul Bollea3a88a62011-03-16 22:10:06 +01001179 return 0;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001180}
1181
1182static int evergreen_packet0_check(struct radeon_cs_parser *p,
1183 struct radeon_cs_packet *pkt,
1184 unsigned idx, unsigned reg)
1185{
1186 int r;
1187
1188 switch (reg) {
1189 case EVERGREEN_VLINE_START_END:
1190 r = evergreen_cs_packet_parse_vline(p);
1191 if (r) {
1192 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1193 idx, reg);
1194 return r;
1195 }
1196 break;
1197 default:
1198 printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
1199 reg, idx);
1200 return -EINVAL;
1201 }
1202 return 0;
1203}
1204
1205static int evergreen_cs_parse_packet0(struct radeon_cs_parser *p,
1206 struct radeon_cs_packet *pkt)
1207{
1208 unsigned reg, i;
1209 unsigned idx;
1210 int r;
1211
1212 idx = pkt->idx + 1;
1213 reg = pkt->reg;
1214 for (i = 0; i <= pkt->count; i++, idx++, reg += 4) {
1215 r = evergreen_packet0_check(p, pkt, idx, reg);
1216 if (r) {
1217 return r;
1218 }
1219 }
1220 return 0;
1221}
1222
1223/**
1224 * evergreen_cs_check_reg() - check if register is authorized or not
1225 * @parser: parser structure holding parsing context
1226 * @reg: register we are testing
1227 * @idx: index into the cs buffer
1228 *
1229 * This function will test against evergreen_reg_safe_bm and return 0
1230 * if register is safe. If register is not flag as safe this function
1231 * will test it against a list of register needind special handling.
1232 */
Andi Kleen488479e2011-10-13 16:08:41 -07001233static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001234{
1235 struct evergreen_cs_track *track = (struct evergreen_cs_track *)p->track;
1236 struct radeon_cs_reloc *reloc;
Alex Deucherc175ca92011-03-02 20:07:37 -05001237 u32 last_reg;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001238 u32 m, i, tmp, *ib;
1239 int r;
1240
Alex Deucherc175ca92011-03-02 20:07:37 -05001241 if (p->rdev->family >= CHIP_CAYMAN)
1242 last_reg = ARRAY_SIZE(cayman_reg_safe_bm);
1243 else
1244 last_reg = ARRAY_SIZE(evergreen_reg_safe_bm);
1245
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001246 i = (reg >> 7);
Dan Carpenter88498832011-07-27 09:53:40 +00001247 if (i >= last_reg) {
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001248 dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
1249 return -EINVAL;
1250 }
1251 m = 1 << ((reg >> 2) & 31);
Alex Deucherc175ca92011-03-02 20:07:37 -05001252 if (p->rdev->family >= CHIP_CAYMAN) {
1253 if (!(cayman_reg_safe_bm[i] & m))
1254 return 0;
1255 } else {
1256 if (!(evergreen_reg_safe_bm[i] & m))
1257 return 0;
1258 }
Jerome Glissef2e39222012-05-09 15:35:02 +02001259 ib = p->ib.ptr;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001260 switch (reg) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001261 /* force following reg to 0 in an attempt to disable out buffer
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001262 * which will need us to better understand how it works to perform
1263 * security check on it (Jerome)
1264 */
1265 case SQ_ESGS_RING_SIZE:
1266 case SQ_GSVS_RING_SIZE:
1267 case SQ_ESTMP_RING_SIZE:
1268 case SQ_GSTMP_RING_SIZE:
1269 case SQ_HSTMP_RING_SIZE:
1270 case SQ_LSTMP_RING_SIZE:
1271 case SQ_PSTMP_RING_SIZE:
1272 case SQ_VSTMP_RING_SIZE:
1273 case SQ_ESGS_RING_ITEMSIZE:
1274 case SQ_ESTMP_RING_ITEMSIZE:
1275 case SQ_GSTMP_RING_ITEMSIZE:
1276 case SQ_GSVS_RING_ITEMSIZE:
1277 case SQ_GS_VERT_ITEMSIZE:
1278 case SQ_GS_VERT_ITEMSIZE_1:
1279 case SQ_GS_VERT_ITEMSIZE_2:
1280 case SQ_GS_VERT_ITEMSIZE_3:
1281 case SQ_GSVS_RING_OFFSET_1:
1282 case SQ_GSVS_RING_OFFSET_2:
1283 case SQ_GSVS_RING_OFFSET_3:
1284 case SQ_HSTMP_RING_ITEMSIZE:
1285 case SQ_LSTMP_RING_ITEMSIZE:
1286 case SQ_PSTMP_RING_ITEMSIZE:
1287 case SQ_VSTMP_RING_ITEMSIZE:
1288 case VGT_TF_RING_SIZE:
1289 /* get value to populate the IB don't remove */
Alex Deucher8aa75002011-03-02 20:07:40 -05001290 /*tmp =radeon_get_ib_value(p, idx);
1291 ib[idx] = 0;*/
1292 break;
1293 case SQ_ESGS_RING_BASE:
1294 case SQ_GSVS_RING_BASE:
1295 case SQ_ESTMP_RING_BASE:
1296 case SQ_GSTMP_RING_BASE:
1297 case SQ_HSTMP_RING_BASE:
1298 case SQ_LSTMP_RING_BASE:
1299 case SQ_PSTMP_RING_BASE:
1300 case SQ_VSTMP_RING_BASE:
1301 r = evergreen_cs_packet_next_reloc(p, &reloc);
1302 if (r) {
1303 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1304 "0x%04X\n", reg);
1305 return -EINVAL;
1306 }
1307 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001308 break;
1309 case DB_DEPTH_CONTROL:
1310 track->db_depth_control = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001311 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001312 break;
Alex Deucherc175ca92011-03-02 20:07:37 -05001313 case CAYMAN_DB_EQAA:
1314 if (p->rdev->family < CHIP_CAYMAN) {
1315 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1316 "0x%04X\n", reg);
1317 return -EINVAL;
1318 }
1319 break;
1320 case CAYMAN_DB_DEPTH_INFO:
1321 if (p->rdev->family < CHIP_CAYMAN) {
1322 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1323 "0x%04X\n", reg);
1324 return -EINVAL;
1325 }
1326 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001327 case DB_Z_INFO:
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001328 track->db_z_info = radeon_get_ib_value(p, idx);
Jerome Glisse721604a2012-01-05 22:11:05 -05001329 if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
Marek Olšáke70f2242011-10-25 01:38:45 +02001330 r = evergreen_cs_packet_next_reloc(p, &reloc);
1331 if (r) {
1332 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1333 "0x%04X\n", reg);
1334 return -EINVAL;
1335 }
1336 ib[idx] &= ~Z_ARRAY_MODE(0xf);
1337 track->db_z_info &= ~Z_ARRAY_MODE(0xf);
Alex Deucherf3a71df2011-11-28 14:49:28 -05001338 ib[idx] |= Z_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
1339 track->db_z_info |= Z_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
Marek Olšáke70f2242011-10-25 01:38:45 +02001340 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
Jerome Glisse285484e2011-12-16 17:03:42 -05001341 unsigned bankw, bankh, mtaspect, tile_split;
1342
1343 evergreen_tiling_fields(reloc->lobj.tiling_flags,
1344 &bankw, &bankh, &mtaspect,
1345 &tile_split);
Alex Deucherf3a71df2011-11-28 14:49:28 -05001346 ib[idx] |= DB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
Jerome Glisse285484e2011-12-16 17:03:42 -05001347 ib[idx] |= DB_TILE_SPLIT(tile_split) |
1348 DB_BANK_WIDTH(bankw) |
1349 DB_BANK_HEIGHT(bankh) |
1350 DB_MACRO_TILE_ASPECT(mtaspect);
Marek Olšáke70f2242011-10-25 01:38:45 +02001351 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001352 }
Marek Olšák30838572012-03-19 03:09:35 +01001353 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001354 break;
1355 case DB_STENCIL_INFO:
1356 track->db_s_info = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001357 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001358 break;
1359 case DB_DEPTH_VIEW:
1360 track->db_depth_view = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001361 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001362 break;
1363 case DB_DEPTH_SIZE:
1364 track->db_depth_size = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001365 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001366 break;
Jerome Glisse285484e2011-12-16 17:03:42 -05001367 case R_02805C_DB_DEPTH_SLICE:
1368 track->db_depth_slice = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001369 track->db_dirty = true;
Jerome Glisse285484e2011-12-16 17:03:42 -05001370 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001371 case DB_Z_READ_BASE:
1372 r = evergreen_cs_packet_next_reloc(p, &reloc);
1373 if (r) {
1374 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1375 "0x%04X\n", reg);
1376 return -EINVAL;
1377 }
1378 track->db_z_read_offset = radeon_get_ib_value(p, idx);
1379 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1380 track->db_z_read_bo = reloc->robj;
Marek Olšák30838572012-03-19 03:09:35 +01001381 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001382 break;
1383 case DB_Z_WRITE_BASE:
1384 r = evergreen_cs_packet_next_reloc(p, &reloc);
1385 if (r) {
1386 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1387 "0x%04X\n", reg);
1388 return -EINVAL;
1389 }
1390 track->db_z_write_offset = radeon_get_ib_value(p, idx);
1391 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1392 track->db_z_write_bo = reloc->robj;
Marek Olšák30838572012-03-19 03:09:35 +01001393 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001394 break;
1395 case DB_STENCIL_READ_BASE:
1396 r = evergreen_cs_packet_next_reloc(p, &reloc);
1397 if (r) {
1398 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1399 "0x%04X\n", reg);
1400 return -EINVAL;
1401 }
1402 track->db_s_read_offset = radeon_get_ib_value(p, idx);
1403 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1404 track->db_s_read_bo = reloc->robj;
Marek Olšák30838572012-03-19 03:09:35 +01001405 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001406 break;
1407 case DB_STENCIL_WRITE_BASE:
1408 r = evergreen_cs_packet_next_reloc(p, &reloc);
1409 if (r) {
1410 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1411 "0x%04X\n", reg);
1412 return -EINVAL;
1413 }
1414 track->db_s_write_offset = radeon_get_ib_value(p, idx);
1415 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1416 track->db_s_write_bo = reloc->robj;
Marek Olšák30838572012-03-19 03:09:35 +01001417 track->db_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001418 break;
1419 case VGT_STRMOUT_CONFIG:
1420 track->vgt_strmout_config = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001421 track->streamout_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001422 break;
1423 case VGT_STRMOUT_BUFFER_CONFIG:
1424 track->vgt_strmout_buffer_config = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001425 track->streamout_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001426 break;
Marek Olšákdd220a02012-01-27 12:17:59 -05001427 case VGT_STRMOUT_BUFFER_BASE_0:
1428 case VGT_STRMOUT_BUFFER_BASE_1:
1429 case VGT_STRMOUT_BUFFER_BASE_2:
1430 case VGT_STRMOUT_BUFFER_BASE_3:
1431 r = evergreen_cs_packet_next_reloc(p, &reloc);
1432 if (r) {
1433 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1434 "0x%04X\n", reg);
1435 return -EINVAL;
1436 }
1437 tmp = (reg - VGT_STRMOUT_BUFFER_BASE_0) / 16;
1438 track->vgt_strmout_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8;
1439 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1440 track->vgt_strmout_bo[tmp] = reloc->robj;
Marek Olšák30838572012-03-19 03:09:35 +01001441 track->streamout_dirty = true;
Marek Olšákdd220a02012-01-27 12:17:59 -05001442 break;
1443 case VGT_STRMOUT_BUFFER_SIZE_0:
1444 case VGT_STRMOUT_BUFFER_SIZE_1:
1445 case VGT_STRMOUT_BUFFER_SIZE_2:
1446 case VGT_STRMOUT_BUFFER_SIZE_3:
1447 tmp = (reg - VGT_STRMOUT_BUFFER_SIZE_0) / 16;
1448 /* size in register is DWs, convert to bytes */
1449 track->vgt_strmout_size[tmp] = radeon_get_ib_value(p, idx) * 4;
Marek Olšák30838572012-03-19 03:09:35 +01001450 track->streamout_dirty = true;
Marek Olšákdd220a02012-01-27 12:17:59 -05001451 break;
1452 case CP_COHER_BASE:
1453 r = evergreen_cs_packet_next_reloc(p, &reloc);
1454 if (r) {
1455 dev_warn(p->dev, "missing reloc for CP_COHER_BASE "
1456 "0x%04X\n", reg);
1457 return -EINVAL;
1458 }
1459 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001460 case CB_TARGET_MASK:
1461 track->cb_target_mask = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001462 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001463 break;
1464 case CB_SHADER_MASK:
1465 track->cb_shader_mask = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001466 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001467 break;
1468 case PA_SC_AA_CONFIG:
Alex Deucherc175ca92011-03-02 20:07:37 -05001469 if (p->rdev->family >= CHIP_CAYMAN) {
1470 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1471 "0x%04X\n", reg);
1472 return -EINVAL;
1473 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001474 tmp = radeon_get_ib_value(p, idx) & MSAA_NUM_SAMPLES_MASK;
1475 track->nsamples = 1 << tmp;
1476 break;
Alex Deucherc175ca92011-03-02 20:07:37 -05001477 case CAYMAN_PA_SC_AA_CONFIG:
1478 if (p->rdev->family < CHIP_CAYMAN) {
1479 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1480 "0x%04X\n", reg);
1481 return -EINVAL;
1482 }
1483 tmp = radeon_get_ib_value(p, idx) & CAYMAN_MSAA_NUM_SAMPLES_MASK;
1484 track->nsamples = 1 << tmp;
1485 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001486 case CB_COLOR0_VIEW:
1487 case CB_COLOR1_VIEW:
1488 case CB_COLOR2_VIEW:
1489 case CB_COLOR3_VIEW:
1490 case CB_COLOR4_VIEW:
1491 case CB_COLOR5_VIEW:
1492 case CB_COLOR6_VIEW:
1493 case CB_COLOR7_VIEW:
1494 tmp = (reg - CB_COLOR0_VIEW) / 0x3c;
1495 track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001496 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001497 break;
1498 case CB_COLOR8_VIEW:
1499 case CB_COLOR9_VIEW:
1500 case CB_COLOR10_VIEW:
1501 case CB_COLOR11_VIEW:
1502 tmp = ((reg - CB_COLOR8_VIEW) / 0x1c) + 8;
1503 track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001504 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001505 break;
1506 case CB_COLOR0_INFO:
1507 case CB_COLOR1_INFO:
1508 case CB_COLOR2_INFO:
1509 case CB_COLOR3_INFO:
1510 case CB_COLOR4_INFO:
1511 case CB_COLOR5_INFO:
1512 case CB_COLOR6_INFO:
1513 case CB_COLOR7_INFO:
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001514 tmp = (reg - CB_COLOR0_INFO) / 0x3c;
1515 track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
Jerome Glisse721604a2012-01-05 22:11:05 -05001516 if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
Marek Olšáke70f2242011-10-25 01:38:45 +02001517 r = evergreen_cs_packet_next_reloc(p, &reloc);
1518 if (r) {
1519 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1520 "0x%04X\n", reg);
1521 return -EINVAL;
1522 }
Alex Deucherf3a71df2011-11-28 14:49:28 -05001523 ib[idx] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
1524 track->cb_color_info[tmp] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001525 }
Marek Olšák30838572012-03-19 03:09:35 +01001526 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001527 break;
1528 case CB_COLOR8_INFO:
1529 case CB_COLOR9_INFO:
1530 case CB_COLOR10_INFO:
1531 case CB_COLOR11_INFO:
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001532 tmp = ((reg - CB_COLOR8_INFO) / 0x1c) + 8;
1533 track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
Jerome Glisse721604a2012-01-05 22:11:05 -05001534 if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
Marek Olšáke70f2242011-10-25 01:38:45 +02001535 r = evergreen_cs_packet_next_reloc(p, &reloc);
1536 if (r) {
1537 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1538 "0x%04X\n", reg);
1539 return -EINVAL;
1540 }
Alex Deucherf3a71df2011-11-28 14:49:28 -05001541 ib[idx] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
1542 track->cb_color_info[tmp] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001543 }
Marek Olšák30838572012-03-19 03:09:35 +01001544 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001545 break;
1546 case CB_COLOR0_PITCH:
1547 case CB_COLOR1_PITCH:
1548 case CB_COLOR2_PITCH:
1549 case CB_COLOR3_PITCH:
1550 case CB_COLOR4_PITCH:
1551 case CB_COLOR5_PITCH:
1552 case CB_COLOR6_PITCH:
1553 case CB_COLOR7_PITCH:
1554 tmp = (reg - CB_COLOR0_PITCH) / 0x3c;
1555 track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001556 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001557 break;
1558 case CB_COLOR8_PITCH:
1559 case CB_COLOR9_PITCH:
1560 case CB_COLOR10_PITCH:
1561 case CB_COLOR11_PITCH:
1562 tmp = ((reg - CB_COLOR8_PITCH) / 0x1c) + 8;
1563 track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
Marek Olšák30838572012-03-19 03:09:35 +01001564 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001565 break;
1566 case CB_COLOR0_SLICE:
1567 case CB_COLOR1_SLICE:
1568 case CB_COLOR2_SLICE:
1569 case CB_COLOR3_SLICE:
1570 case CB_COLOR4_SLICE:
1571 case CB_COLOR5_SLICE:
1572 case CB_COLOR6_SLICE:
1573 case CB_COLOR7_SLICE:
1574 tmp = (reg - CB_COLOR0_SLICE) / 0x3c;
1575 track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
Jerome Glissed2609872012-06-09 10:57:41 -04001576 track->cb_color_slice_idx[tmp] = idx;
Marek Olšák30838572012-03-19 03:09:35 +01001577 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001578 break;
1579 case CB_COLOR8_SLICE:
1580 case CB_COLOR9_SLICE:
1581 case CB_COLOR10_SLICE:
1582 case CB_COLOR11_SLICE:
1583 tmp = ((reg - CB_COLOR8_SLICE) / 0x1c) + 8;
1584 track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
Jerome Glissed2609872012-06-09 10:57:41 -04001585 track->cb_color_slice_idx[tmp] = idx;
Marek Olšák30838572012-03-19 03:09:35 +01001586 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001587 break;
1588 case CB_COLOR0_ATTRIB:
1589 case CB_COLOR1_ATTRIB:
1590 case CB_COLOR2_ATTRIB:
1591 case CB_COLOR3_ATTRIB:
1592 case CB_COLOR4_ATTRIB:
1593 case CB_COLOR5_ATTRIB:
1594 case CB_COLOR6_ATTRIB:
1595 case CB_COLOR7_ATTRIB:
Jerome Glisse285484e2011-12-16 17:03:42 -05001596 r = evergreen_cs_packet_next_reloc(p, &reloc);
1597 if (r) {
1598 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1599 "0x%04X\n", reg);
1600 return -EINVAL;
1601 }
1602 if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
1603 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
1604 unsigned bankw, bankh, mtaspect, tile_split;
1605
1606 evergreen_tiling_fields(reloc->lobj.tiling_flags,
1607 &bankw, &bankh, &mtaspect,
1608 &tile_split);
1609 ib[idx] |= CB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
1610 ib[idx] |= CB_TILE_SPLIT(tile_split) |
1611 CB_BANK_WIDTH(bankw) |
1612 CB_BANK_HEIGHT(bankh) |
1613 CB_MACRO_TILE_ASPECT(mtaspect);
1614 }
1615 }
1616 tmp = ((reg - CB_COLOR0_ATTRIB) / 0x3c);
1617 track->cb_color_attrib[tmp] = ib[idx];
Marek Olšák30838572012-03-19 03:09:35 +01001618 track->cb_dirty = true;
Jerome Glisse285484e2011-12-16 17:03:42 -05001619 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001620 case CB_COLOR8_ATTRIB:
1621 case CB_COLOR9_ATTRIB:
1622 case CB_COLOR10_ATTRIB:
1623 case CB_COLOR11_ATTRIB:
Alex Deucherf3a71df2011-11-28 14:49:28 -05001624 r = evergreen_cs_packet_next_reloc(p, &reloc);
1625 if (r) {
1626 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1627 "0x%04X\n", reg);
1628 return -EINVAL;
1629 }
Jerome Glisse285484e2011-12-16 17:03:42 -05001630 if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
1631 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
1632 unsigned bankw, bankh, mtaspect, tile_split;
1633
1634 evergreen_tiling_fields(reloc->lobj.tiling_flags,
1635 &bankw, &bankh, &mtaspect,
1636 &tile_split);
1637 ib[idx] |= CB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
1638 ib[idx] |= CB_TILE_SPLIT(tile_split) |
1639 CB_BANK_WIDTH(bankw) |
1640 CB_BANK_HEIGHT(bankh) |
1641 CB_MACRO_TILE_ASPECT(mtaspect);
1642 }
Alex Deucherf3a71df2011-11-28 14:49:28 -05001643 }
Jerome Glisse285484e2011-12-16 17:03:42 -05001644 tmp = ((reg - CB_COLOR8_ATTRIB) / 0x1c) + 8;
1645 track->cb_color_attrib[tmp] = ib[idx];
Marek Olšák30838572012-03-19 03:09:35 +01001646 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001647 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001648 case CB_COLOR0_FMASK:
1649 case CB_COLOR1_FMASK:
1650 case CB_COLOR2_FMASK:
1651 case CB_COLOR3_FMASK:
1652 case CB_COLOR4_FMASK:
1653 case CB_COLOR5_FMASK:
1654 case CB_COLOR6_FMASK:
1655 case CB_COLOR7_FMASK:
1656 tmp = (reg - CB_COLOR0_FMASK) / 0x3c;
1657 r = evergreen_cs_packet_next_reloc(p, &reloc);
1658 if (r) {
1659 dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
1660 return -EINVAL;
1661 }
1662 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1663 track->cb_color_fmask_bo[tmp] = reloc->robj;
1664 break;
1665 case CB_COLOR0_CMASK:
1666 case CB_COLOR1_CMASK:
1667 case CB_COLOR2_CMASK:
1668 case CB_COLOR3_CMASK:
1669 case CB_COLOR4_CMASK:
1670 case CB_COLOR5_CMASK:
1671 case CB_COLOR6_CMASK:
1672 case CB_COLOR7_CMASK:
1673 tmp = (reg - CB_COLOR0_CMASK) / 0x3c;
1674 r = evergreen_cs_packet_next_reloc(p, &reloc);
1675 if (r) {
1676 dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
1677 return -EINVAL;
1678 }
1679 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1680 track->cb_color_cmask_bo[tmp] = reloc->robj;
1681 break;
1682 case CB_COLOR0_FMASK_SLICE:
1683 case CB_COLOR1_FMASK_SLICE:
1684 case CB_COLOR2_FMASK_SLICE:
1685 case CB_COLOR3_FMASK_SLICE:
1686 case CB_COLOR4_FMASK_SLICE:
1687 case CB_COLOR5_FMASK_SLICE:
1688 case CB_COLOR6_FMASK_SLICE:
1689 case CB_COLOR7_FMASK_SLICE:
1690 tmp = (reg - CB_COLOR0_FMASK_SLICE) / 0x3c;
1691 track->cb_color_fmask_slice[tmp] = radeon_get_ib_value(p, idx);
1692 break;
1693 case CB_COLOR0_CMASK_SLICE:
1694 case CB_COLOR1_CMASK_SLICE:
1695 case CB_COLOR2_CMASK_SLICE:
1696 case CB_COLOR3_CMASK_SLICE:
1697 case CB_COLOR4_CMASK_SLICE:
1698 case CB_COLOR5_CMASK_SLICE:
1699 case CB_COLOR6_CMASK_SLICE:
1700 case CB_COLOR7_CMASK_SLICE:
1701 tmp = (reg - CB_COLOR0_CMASK_SLICE) / 0x3c;
1702 track->cb_color_cmask_slice[tmp] = radeon_get_ib_value(p, idx);
1703 break;
1704 case CB_COLOR0_BASE:
1705 case CB_COLOR1_BASE:
1706 case CB_COLOR2_BASE:
1707 case CB_COLOR3_BASE:
1708 case CB_COLOR4_BASE:
1709 case CB_COLOR5_BASE:
1710 case CB_COLOR6_BASE:
1711 case CB_COLOR7_BASE:
1712 r = evergreen_cs_packet_next_reloc(p, &reloc);
1713 if (r) {
1714 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1715 "0x%04X\n", reg);
1716 return -EINVAL;
1717 }
1718 tmp = (reg - CB_COLOR0_BASE) / 0x3c;
1719 track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
1720 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001721 track->cb_color_bo[tmp] = reloc->robj;
Marek Olšák30838572012-03-19 03:09:35 +01001722 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001723 break;
1724 case CB_COLOR8_BASE:
1725 case CB_COLOR9_BASE:
1726 case CB_COLOR10_BASE:
1727 case CB_COLOR11_BASE:
1728 r = evergreen_cs_packet_next_reloc(p, &reloc);
1729 if (r) {
1730 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1731 "0x%04X\n", reg);
1732 return -EINVAL;
1733 }
1734 tmp = ((reg - CB_COLOR8_BASE) / 0x1c) + 8;
1735 track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
1736 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001737 track->cb_color_bo[tmp] = reloc->robj;
Marek Olšák30838572012-03-19 03:09:35 +01001738 track->cb_dirty = true;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001739 break;
Jerome Glisse88f50c82012-03-21 19:18:21 -04001740 case DB_HTILE_DATA_BASE:
1741 r = evergreen_cs_packet_next_reloc(p, &reloc);
1742 if (r) {
1743 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1744 "0x%04X\n", reg);
1745 return -EINVAL;
1746 }
1747 track->htile_offset = radeon_get_ib_value(p, idx);
1748 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1749 track->htile_bo = reloc->robj;
1750 track->db_dirty = true;
1751 break;
1752 case DB_HTILE_SURFACE:
1753 /* 8x8 only */
1754 track->htile_surface = radeon_get_ib_value(p, idx);
1755 track->db_dirty = true;
1756 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001757 case CB_IMMED0_BASE:
1758 case CB_IMMED1_BASE:
1759 case CB_IMMED2_BASE:
1760 case CB_IMMED3_BASE:
1761 case CB_IMMED4_BASE:
1762 case CB_IMMED5_BASE:
1763 case CB_IMMED6_BASE:
1764 case CB_IMMED7_BASE:
1765 case CB_IMMED8_BASE:
1766 case CB_IMMED9_BASE:
1767 case CB_IMMED10_BASE:
1768 case CB_IMMED11_BASE:
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001769 case SQ_PGM_START_FS:
1770 case SQ_PGM_START_ES:
1771 case SQ_PGM_START_VS:
1772 case SQ_PGM_START_GS:
1773 case SQ_PGM_START_PS:
1774 case SQ_PGM_START_HS:
1775 case SQ_PGM_START_LS:
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001776 case SQ_CONST_MEM_BASE:
1777 case SQ_ALU_CONST_CACHE_GS_0:
1778 case SQ_ALU_CONST_CACHE_GS_1:
1779 case SQ_ALU_CONST_CACHE_GS_2:
1780 case SQ_ALU_CONST_CACHE_GS_3:
1781 case SQ_ALU_CONST_CACHE_GS_4:
1782 case SQ_ALU_CONST_CACHE_GS_5:
1783 case SQ_ALU_CONST_CACHE_GS_6:
1784 case SQ_ALU_CONST_CACHE_GS_7:
1785 case SQ_ALU_CONST_CACHE_GS_8:
1786 case SQ_ALU_CONST_CACHE_GS_9:
1787 case SQ_ALU_CONST_CACHE_GS_10:
1788 case SQ_ALU_CONST_CACHE_GS_11:
1789 case SQ_ALU_CONST_CACHE_GS_12:
1790 case SQ_ALU_CONST_CACHE_GS_13:
1791 case SQ_ALU_CONST_CACHE_GS_14:
1792 case SQ_ALU_CONST_CACHE_GS_15:
1793 case SQ_ALU_CONST_CACHE_PS_0:
1794 case SQ_ALU_CONST_CACHE_PS_1:
1795 case SQ_ALU_CONST_CACHE_PS_2:
1796 case SQ_ALU_CONST_CACHE_PS_3:
1797 case SQ_ALU_CONST_CACHE_PS_4:
1798 case SQ_ALU_CONST_CACHE_PS_5:
1799 case SQ_ALU_CONST_CACHE_PS_6:
1800 case SQ_ALU_CONST_CACHE_PS_7:
1801 case SQ_ALU_CONST_CACHE_PS_8:
1802 case SQ_ALU_CONST_CACHE_PS_9:
1803 case SQ_ALU_CONST_CACHE_PS_10:
1804 case SQ_ALU_CONST_CACHE_PS_11:
1805 case SQ_ALU_CONST_CACHE_PS_12:
1806 case SQ_ALU_CONST_CACHE_PS_13:
1807 case SQ_ALU_CONST_CACHE_PS_14:
1808 case SQ_ALU_CONST_CACHE_PS_15:
1809 case SQ_ALU_CONST_CACHE_VS_0:
1810 case SQ_ALU_CONST_CACHE_VS_1:
1811 case SQ_ALU_CONST_CACHE_VS_2:
1812 case SQ_ALU_CONST_CACHE_VS_3:
1813 case SQ_ALU_CONST_CACHE_VS_4:
1814 case SQ_ALU_CONST_CACHE_VS_5:
1815 case SQ_ALU_CONST_CACHE_VS_6:
1816 case SQ_ALU_CONST_CACHE_VS_7:
1817 case SQ_ALU_CONST_CACHE_VS_8:
1818 case SQ_ALU_CONST_CACHE_VS_9:
1819 case SQ_ALU_CONST_CACHE_VS_10:
1820 case SQ_ALU_CONST_CACHE_VS_11:
1821 case SQ_ALU_CONST_CACHE_VS_12:
1822 case SQ_ALU_CONST_CACHE_VS_13:
1823 case SQ_ALU_CONST_CACHE_VS_14:
1824 case SQ_ALU_CONST_CACHE_VS_15:
1825 case SQ_ALU_CONST_CACHE_HS_0:
1826 case SQ_ALU_CONST_CACHE_HS_1:
1827 case SQ_ALU_CONST_CACHE_HS_2:
1828 case SQ_ALU_CONST_CACHE_HS_3:
1829 case SQ_ALU_CONST_CACHE_HS_4:
1830 case SQ_ALU_CONST_CACHE_HS_5:
1831 case SQ_ALU_CONST_CACHE_HS_6:
1832 case SQ_ALU_CONST_CACHE_HS_7:
1833 case SQ_ALU_CONST_CACHE_HS_8:
1834 case SQ_ALU_CONST_CACHE_HS_9:
1835 case SQ_ALU_CONST_CACHE_HS_10:
1836 case SQ_ALU_CONST_CACHE_HS_11:
1837 case SQ_ALU_CONST_CACHE_HS_12:
1838 case SQ_ALU_CONST_CACHE_HS_13:
1839 case SQ_ALU_CONST_CACHE_HS_14:
1840 case SQ_ALU_CONST_CACHE_HS_15:
1841 case SQ_ALU_CONST_CACHE_LS_0:
1842 case SQ_ALU_CONST_CACHE_LS_1:
1843 case SQ_ALU_CONST_CACHE_LS_2:
1844 case SQ_ALU_CONST_CACHE_LS_3:
1845 case SQ_ALU_CONST_CACHE_LS_4:
1846 case SQ_ALU_CONST_CACHE_LS_5:
1847 case SQ_ALU_CONST_CACHE_LS_6:
1848 case SQ_ALU_CONST_CACHE_LS_7:
1849 case SQ_ALU_CONST_CACHE_LS_8:
1850 case SQ_ALU_CONST_CACHE_LS_9:
1851 case SQ_ALU_CONST_CACHE_LS_10:
1852 case SQ_ALU_CONST_CACHE_LS_11:
1853 case SQ_ALU_CONST_CACHE_LS_12:
1854 case SQ_ALU_CONST_CACHE_LS_13:
1855 case SQ_ALU_CONST_CACHE_LS_14:
1856 case SQ_ALU_CONST_CACHE_LS_15:
1857 r = evergreen_cs_packet_next_reloc(p, &reloc);
1858 if (r) {
1859 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1860 "0x%04X\n", reg);
1861 return -EINVAL;
1862 }
1863 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1864 break;
Alex Deucher033b5652011-06-08 15:26:45 -04001865 case SX_MEMORY_EXPORT_BASE:
1866 if (p->rdev->family >= CHIP_CAYMAN) {
1867 dev_warn(p->dev, "bad SET_CONFIG_REG "
1868 "0x%04X\n", reg);
1869 return -EINVAL;
1870 }
1871 r = evergreen_cs_packet_next_reloc(p, &reloc);
1872 if (r) {
1873 dev_warn(p->dev, "bad SET_CONFIG_REG "
1874 "0x%04X\n", reg);
1875 return -EINVAL;
1876 }
1877 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1878 break;
1879 case CAYMAN_SX_SCATTER_EXPORT_BASE:
1880 if (p->rdev->family < CHIP_CAYMAN) {
1881 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1882 "0x%04X\n", reg);
1883 return -EINVAL;
1884 }
1885 r = evergreen_cs_packet_next_reloc(p, &reloc);
1886 if (r) {
1887 dev_warn(p->dev, "bad SET_CONTEXT_REG "
1888 "0x%04X\n", reg);
1889 return -EINVAL;
1890 }
1891 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1892 break;
Marek Olšák779923b2012-03-08 00:56:00 +01001893 case SX_MISC:
1894 track->sx_misc_kill_all_prims = (radeon_get_ib_value(p, idx) & 0x1) != 0;
1895 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001896 default:
1897 dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
1898 return -EINVAL;
1899 }
1900 return 0;
1901}
1902
Marek Olšákdd220a02012-01-27 12:17:59 -05001903static bool evergreen_is_safe_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
1904{
1905 u32 last_reg, m, i;
1906
1907 if (p->rdev->family >= CHIP_CAYMAN)
1908 last_reg = ARRAY_SIZE(cayman_reg_safe_bm);
1909 else
1910 last_reg = ARRAY_SIZE(evergreen_reg_safe_bm);
1911
1912 i = (reg >> 7);
1913 if (i >= last_reg) {
1914 dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
1915 return false;
1916 }
1917 m = 1 << ((reg >> 2) & 31);
1918 if (p->rdev->family >= CHIP_CAYMAN) {
1919 if (!(cayman_reg_safe_bm[i] & m))
1920 return true;
1921 } else {
1922 if (!(evergreen_reg_safe_bm[i] & m))
1923 return true;
1924 }
1925 dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
1926 return false;
1927}
1928
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001929static int evergreen_packet3_check(struct radeon_cs_parser *p,
1930 struct radeon_cs_packet *pkt)
1931{
1932 struct radeon_cs_reloc *reloc;
1933 struct evergreen_cs_track *track;
1934 volatile u32 *ib;
1935 unsigned idx;
1936 unsigned i;
1937 unsigned start_reg, end_reg, reg;
1938 int r;
1939 u32 idx_value;
1940
1941 track = (struct evergreen_cs_track *)p->track;
Jerome Glissef2e39222012-05-09 15:35:02 +02001942 ib = p->ib.ptr;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001943 idx = pkt->idx + 1;
1944 idx_value = radeon_get_ib_value(p, idx);
1945
1946 switch (pkt->opcode) {
Dave Airlie2a19cac2011-02-28 16:11:48 +10001947 case PACKET3_SET_PREDICATION:
1948 {
1949 int pred_op;
1950 int tmp;
Marek Olšák78857132012-03-19 03:09:33 +01001951 uint64_t offset;
1952
Dave Airlie2a19cac2011-02-28 16:11:48 +10001953 if (pkt->count != 1) {
1954 DRM_ERROR("bad SET PREDICATION\n");
1955 return -EINVAL;
1956 }
1957
1958 tmp = radeon_get_ib_value(p, idx + 1);
1959 pred_op = (tmp >> 16) & 0x7;
1960
1961 /* for the clear predicate operation */
1962 if (pred_op == 0)
1963 return 0;
1964
1965 if (pred_op > 2) {
1966 DRM_ERROR("bad SET PREDICATION operation %d\n", pred_op);
1967 return -EINVAL;
1968 }
1969
1970 r = evergreen_cs_packet_next_reloc(p, &reloc);
1971 if (r) {
1972 DRM_ERROR("bad SET PREDICATION\n");
1973 return -EINVAL;
1974 }
1975
Marek Olšák78857132012-03-19 03:09:33 +01001976 offset = reloc->lobj.gpu_offset +
1977 (idx_value & 0xfffffff0) +
1978 ((u64)(tmp & 0xff) << 32);
1979
1980 ib[idx + 0] = offset;
1981 ib[idx + 1] = (tmp & 0xffffff00) | (upper_32_bits(offset) & 0xff);
Dave Airlie2a19cac2011-02-28 16:11:48 +10001982 }
1983 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04001984 case PACKET3_CONTEXT_CONTROL:
1985 if (pkt->count != 1) {
1986 DRM_ERROR("bad CONTEXT_CONTROL\n");
1987 return -EINVAL;
1988 }
1989 break;
1990 case PACKET3_INDEX_TYPE:
1991 case PACKET3_NUM_INSTANCES:
1992 case PACKET3_CLEAR_STATE:
1993 if (pkt->count) {
1994 DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
1995 return -EINVAL;
1996 }
1997 break;
Alex Deucherc175ca92011-03-02 20:07:37 -05001998 case CAYMAN_PACKET3_DEALLOC_STATE:
1999 if (p->rdev->family < CHIP_CAYMAN) {
2000 DRM_ERROR("bad PACKET3_DEALLOC_STATE\n");
2001 return -EINVAL;
2002 }
2003 if (pkt->count) {
2004 DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
2005 return -EINVAL;
2006 }
2007 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002008 case PACKET3_INDEX_BASE:
Marek Olšák78857132012-03-19 03:09:33 +01002009 {
2010 uint64_t offset;
2011
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002012 if (pkt->count != 1) {
2013 DRM_ERROR("bad INDEX_BASE\n");
2014 return -EINVAL;
2015 }
2016 r = evergreen_cs_packet_next_reloc(p, &reloc);
2017 if (r) {
2018 DRM_ERROR("bad INDEX_BASE\n");
2019 return -EINVAL;
2020 }
Marek Olšák78857132012-03-19 03:09:33 +01002021
2022 offset = reloc->lobj.gpu_offset +
2023 idx_value +
2024 ((u64)(radeon_get_ib_value(p, idx+1) & 0xff) << 32);
2025
2026 ib[idx+0] = offset;
2027 ib[idx+1] = upper_32_bits(offset) & 0xff;
2028
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002029 r = evergreen_cs_track_check(p);
2030 if (r) {
2031 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
2032 return r;
2033 }
2034 break;
Marek Olšák78857132012-03-19 03:09:33 +01002035 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002036 case PACKET3_DRAW_INDEX:
Marek Olšák78857132012-03-19 03:09:33 +01002037 {
2038 uint64_t offset;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002039 if (pkt->count != 3) {
2040 DRM_ERROR("bad DRAW_INDEX\n");
2041 return -EINVAL;
2042 }
2043 r = evergreen_cs_packet_next_reloc(p, &reloc);
2044 if (r) {
2045 DRM_ERROR("bad DRAW_INDEX\n");
2046 return -EINVAL;
2047 }
Marek Olšák78857132012-03-19 03:09:33 +01002048
2049 offset = reloc->lobj.gpu_offset +
2050 idx_value +
2051 ((u64)(radeon_get_ib_value(p, idx+1) & 0xff) << 32);
2052
2053 ib[idx+0] = offset;
2054 ib[idx+1] = upper_32_bits(offset) & 0xff;
2055
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002056 r = evergreen_cs_track_check(p);
2057 if (r) {
2058 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
2059 return r;
2060 }
2061 break;
Marek Olšák78857132012-03-19 03:09:33 +01002062 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002063 case PACKET3_DRAW_INDEX_2:
Marek Olšák78857132012-03-19 03:09:33 +01002064 {
2065 uint64_t offset;
2066
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002067 if (pkt->count != 4) {
2068 DRM_ERROR("bad DRAW_INDEX_2\n");
2069 return -EINVAL;
2070 }
2071 r = evergreen_cs_packet_next_reloc(p, &reloc);
2072 if (r) {
2073 DRM_ERROR("bad DRAW_INDEX_2\n");
2074 return -EINVAL;
2075 }
Marek Olšák78857132012-03-19 03:09:33 +01002076
2077 offset = reloc->lobj.gpu_offset +
2078 radeon_get_ib_value(p, idx+1) +
2079 ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
2080
2081 ib[idx+1] = offset;
2082 ib[idx+2] = upper_32_bits(offset) & 0xff;
2083
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002084 r = evergreen_cs_track_check(p);
2085 if (r) {
2086 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
2087 return r;
2088 }
2089 break;
Marek Olšák78857132012-03-19 03:09:33 +01002090 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002091 case PACKET3_DRAW_INDEX_AUTO:
2092 if (pkt->count != 1) {
2093 DRM_ERROR("bad DRAW_INDEX_AUTO\n");
2094 return -EINVAL;
2095 }
2096 r = evergreen_cs_track_check(p);
2097 if (r) {
2098 dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
2099 return r;
2100 }
2101 break;
2102 case PACKET3_DRAW_INDEX_MULTI_AUTO:
2103 if (pkt->count != 2) {
2104 DRM_ERROR("bad DRAW_INDEX_MULTI_AUTO\n");
2105 return -EINVAL;
2106 }
2107 r = evergreen_cs_track_check(p);
2108 if (r) {
2109 dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
2110 return r;
2111 }
2112 break;
2113 case PACKET3_DRAW_INDEX_IMMD:
2114 if (pkt->count < 2) {
2115 DRM_ERROR("bad DRAW_INDEX_IMMD\n");
2116 return -EINVAL;
2117 }
2118 r = evergreen_cs_track_check(p);
2119 if (r) {
2120 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
2121 return r;
2122 }
2123 break;
2124 case PACKET3_DRAW_INDEX_OFFSET:
2125 if (pkt->count != 2) {
2126 DRM_ERROR("bad DRAW_INDEX_OFFSET\n");
2127 return -EINVAL;
2128 }
2129 r = evergreen_cs_track_check(p);
2130 if (r) {
2131 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
2132 return r;
2133 }
2134 break;
2135 case PACKET3_DRAW_INDEX_OFFSET_2:
2136 if (pkt->count != 3) {
2137 DRM_ERROR("bad DRAW_INDEX_OFFSET_2\n");
2138 return -EINVAL;
2139 }
2140 r = evergreen_cs_track_check(p);
2141 if (r) {
2142 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
2143 return r;
2144 }
2145 break;
Alex Deucher033b5652011-06-08 15:26:45 -04002146 case PACKET3_DISPATCH_DIRECT:
2147 if (pkt->count != 3) {
2148 DRM_ERROR("bad DISPATCH_DIRECT\n");
2149 return -EINVAL;
2150 }
2151 r = evergreen_cs_track_check(p);
2152 if (r) {
2153 dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
2154 return r;
2155 }
2156 break;
2157 case PACKET3_DISPATCH_INDIRECT:
2158 if (pkt->count != 1) {
2159 DRM_ERROR("bad DISPATCH_INDIRECT\n");
2160 return -EINVAL;
2161 }
2162 r = evergreen_cs_packet_next_reloc(p, &reloc);
2163 if (r) {
2164 DRM_ERROR("bad DISPATCH_INDIRECT\n");
2165 return -EINVAL;
2166 }
2167 ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
2168 r = evergreen_cs_track_check(p);
2169 if (r) {
2170 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
2171 return r;
2172 }
2173 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002174 case PACKET3_WAIT_REG_MEM:
2175 if (pkt->count != 5) {
2176 DRM_ERROR("bad WAIT_REG_MEM\n");
2177 return -EINVAL;
2178 }
2179 /* bit 4 is reg (0) or mem (1) */
2180 if (idx_value & 0x10) {
Marek Olšák78857132012-03-19 03:09:33 +01002181 uint64_t offset;
2182
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002183 r = evergreen_cs_packet_next_reloc(p, &reloc);
2184 if (r) {
2185 DRM_ERROR("bad WAIT_REG_MEM\n");
2186 return -EINVAL;
2187 }
Marek Olšák78857132012-03-19 03:09:33 +01002188
2189 offset = reloc->lobj.gpu_offset +
2190 (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
2191 ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
2192
2193 ib[idx+1] = (ib[idx+1] & 0x3) | (offset & 0xfffffffc);
2194 ib[idx+2] = upper_32_bits(offset) & 0xff;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002195 }
2196 break;
2197 case PACKET3_SURFACE_SYNC:
2198 if (pkt->count != 3) {
2199 DRM_ERROR("bad SURFACE_SYNC\n");
2200 return -EINVAL;
2201 }
2202 /* 0xffffffff/0x0 is flush all cache flag */
2203 if (radeon_get_ib_value(p, idx + 1) != 0xffffffff ||
2204 radeon_get_ib_value(p, idx + 2) != 0) {
2205 r = evergreen_cs_packet_next_reloc(p, &reloc);
2206 if (r) {
2207 DRM_ERROR("bad SURFACE_SYNC\n");
2208 return -EINVAL;
2209 }
2210 ib[idx+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
2211 }
2212 break;
2213 case PACKET3_EVENT_WRITE:
2214 if (pkt->count != 2 && pkt->count != 0) {
2215 DRM_ERROR("bad EVENT_WRITE\n");
2216 return -EINVAL;
2217 }
2218 if (pkt->count) {
Marek Olšák78857132012-03-19 03:09:33 +01002219 uint64_t offset;
2220
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002221 r = evergreen_cs_packet_next_reloc(p, &reloc);
2222 if (r) {
2223 DRM_ERROR("bad EVENT_WRITE\n");
2224 return -EINVAL;
2225 }
Marek Olšák78857132012-03-19 03:09:33 +01002226 offset = reloc->lobj.gpu_offset +
2227 (radeon_get_ib_value(p, idx+1) & 0xfffffff8) +
2228 ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
2229
2230 ib[idx+1] = offset & 0xfffffff8;
2231 ib[idx+2] = upper_32_bits(offset) & 0xff;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002232 }
2233 break;
2234 case PACKET3_EVENT_WRITE_EOP:
Marek Olšák78857132012-03-19 03:09:33 +01002235 {
2236 uint64_t offset;
2237
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002238 if (pkt->count != 4) {
2239 DRM_ERROR("bad EVENT_WRITE_EOP\n");
2240 return -EINVAL;
2241 }
2242 r = evergreen_cs_packet_next_reloc(p, &reloc);
2243 if (r) {
2244 DRM_ERROR("bad EVENT_WRITE_EOP\n");
2245 return -EINVAL;
2246 }
Marek Olšák78857132012-03-19 03:09:33 +01002247
2248 offset = reloc->lobj.gpu_offset +
2249 (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
2250 ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
2251
2252 ib[idx+1] = offset & 0xfffffffc;
2253 ib[idx+2] = (ib[idx+2] & 0xffffff00) | (upper_32_bits(offset) & 0xff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002254 break;
Marek Olšák78857132012-03-19 03:09:33 +01002255 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002256 case PACKET3_EVENT_WRITE_EOS:
Marek Olšák78857132012-03-19 03:09:33 +01002257 {
2258 uint64_t offset;
2259
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002260 if (pkt->count != 3) {
2261 DRM_ERROR("bad EVENT_WRITE_EOS\n");
2262 return -EINVAL;
2263 }
2264 r = evergreen_cs_packet_next_reloc(p, &reloc);
2265 if (r) {
2266 DRM_ERROR("bad EVENT_WRITE_EOS\n");
2267 return -EINVAL;
2268 }
Marek Olšák78857132012-03-19 03:09:33 +01002269
2270 offset = reloc->lobj.gpu_offset +
2271 (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
2272 ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
2273
2274 ib[idx+1] = offset & 0xfffffffc;
2275 ib[idx+2] = (ib[idx+2] & 0xffffff00) | (upper_32_bits(offset) & 0xff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002276 break;
Marek Olšák78857132012-03-19 03:09:33 +01002277 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002278 case PACKET3_SET_CONFIG_REG:
2279 start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
2280 end_reg = 4 * pkt->count + start_reg - 4;
2281 if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
2282 (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
2283 (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
2284 DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
2285 return -EINVAL;
2286 }
2287 for (i = 0; i < pkt->count; i++) {
2288 reg = start_reg + (4 * i);
2289 r = evergreen_cs_check_reg(p, reg, idx+1+i);
2290 if (r)
2291 return r;
2292 }
2293 break;
2294 case PACKET3_SET_CONTEXT_REG:
2295 start_reg = (idx_value << 2) + PACKET3_SET_CONTEXT_REG_START;
2296 end_reg = 4 * pkt->count + start_reg - 4;
2297 if ((start_reg < PACKET3_SET_CONTEXT_REG_START) ||
2298 (start_reg >= PACKET3_SET_CONTEXT_REG_END) ||
2299 (end_reg >= PACKET3_SET_CONTEXT_REG_END)) {
2300 DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
2301 return -EINVAL;
2302 }
2303 for (i = 0; i < pkt->count; i++) {
2304 reg = start_reg + (4 * i);
2305 r = evergreen_cs_check_reg(p, reg, idx+1+i);
2306 if (r)
2307 return r;
2308 }
2309 break;
2310 case PACKET3_SET_RESOURCE:
2311 if (pkt->count % 8) {
2312 DRM_ERROR("bad SET_RESOURCE\n");
2313 return -EINVAL;
2314 }
2315 start_reg = (idx_value << 2) + PACKET3_SET_RESOURCE_START;
2316 end_reg = 4 * pkt->count + start_reg - 4;
2317 if ((start_reg < PACKET3_SET_RESOURCE_START) ||
2318 (start_reg >= PACKET3_SET_RESOURCE_END) ||
2319 (end_reg >= PACKET3_SET_RESOURCE_END)) {
2320 DRM_ERROR("bad SET_RESOURCE\n");
2321 return -EINVAL;
2322 }
2323 for (i = 0; i < (pkt->count / 8); i++) {
2324 struct radeon_bo *texture, *mipmap;
Jerome Glisse285484e2011-12-16 17:03:42 -05002325 u32 toffset, moffset;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002326 u32 size, offset;
2327
2328 switch (G__SQ_CONSTANT_TYPE(radeon_get_ib_value(p, idx+1+(i*8)+7))) {
2329 case SQ_TEX_VTX_VALID_TEXTURE:
2330 /* tex base */
2331 r = evergreen_cs_packet_next_reloc(p, &reloc);
2332 if (r) {
2333 DRM_ERROR("bad SET_RESOURCE (tex)\n");
2334 return -EINVAL;
2335 }
Jerome Glisse721604a2012-01-05 22:11:05 -05002336 if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
Alex Deucherf3a71df2011-11-28 14:49:28 -05002337 ib[idx+1+(i*8)+1] |=
2338 TEX_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
2339 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
Jerome Glisse285484e2011-12-16 17:03:42 -05002340 unsigned bankw, bankh, mtaspect, tile_split;
2341
2342 evergreen_tiling_fields(reloc->lobj.tiling_flags,
2343 &bankw, &bankh, &mtaspect,
2344 &tile_split);
2345 ib[idx+1+(i*8)+6] |= TEX_TILE_SPLIT(tile_split);
Alex Deucherf3a71df2011-11-28 14:49:28 -05002346 ib[idx+1+(i*8)+7] |=
Jerome Glisse285484e2011-12-16 17:03:42 -05002347 TEX_BANK_WIDTH(bankw) |
2348 TEX_BANK_HEIGHT(bankh) |
2349 MACRO_TILE_ASPECT(mtaspect) |
Alex Deucherf3a71df2011-11-28 14:49:28 -05002350 TEX_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
2351 }
Marek Olšáke70f2242011-10-25 01:38:45 +02002352 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002353 texture = reloc->robj;
Jerome Glisse285484e2011-12-16 17:03:42 -05002354 toffset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002355 /* tex mip base */
2356 r = evergreen_cs_packet_next_reloc(p, &reloc);
2357 if (r) {
2358 DRM_ERROR("bad SET_RESOURCE (tex)\n");
2359 return -EINVAL;
2360 }
Jerome Glisse285484e2011-12-16 17:03:42 -05002361 moffset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002362 mipmap = reloc->robj;
Jerome Glisse285484e2011-12-16 17:03:42 -05002363 r = evergreen_cs_track_validate_texture(p, texture, mipmap, idx+1+(i*8));
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002364 if (r)
2365 return r;
Jerome Glisse285484e2011-12-16 17:03:42 -05002366 ib[idx+1+(i*8)+2] += toffset;
2367 ib[idx+1+(i*8)+3] += moffset;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002368 break;
2369 case SQ_TEX_VTX_VALID_BUFFER:
Marek Olšák78857132012-03-19 03:09:33 +01002370 {
2371 uint64_t offset64;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002372 /* vtx base */
2373 r = evergreen_cs_packet_next_reloc(p, &reloc);
2374 if (r) {
2375 DRM_ERROR("bad SET_RESOURCE (vtx)\n");
2376 return -EINVAL;
2377 }
2378 offset = radeon_get_ib_value(p, idx+1+(i*8)+0);
2379 size = radeon_get_ib_value(p, idx+1+(i*8)+1);
2380 if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
2381 /* force size to size of the buffer */
2382 dev_warn(p->dev, "vbo resource seems too big for the bo\n");
Marek Olšák78857132012-03-19 03:09:33 +01002383 ib[idx+1+(i*8)+1] = radeon_bo_size(reloc->robj) - offset;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002384 }
Marek Olšák78857132012-03-19 03:09:33 +01002385
2386 offset64 = reloc->lobj.gpu_offset + offset;
2387 ib[idx+1+(i*8)+0] = offset64;
2388 ib[idx+1+(i*8)+2] = (ib[idx+1+(i*8)+2] & 0xffffff00) |
2389 (upper_32_bits(offset64) & 0xff);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002390 break;
Marek Olšák78857132012-03-19 03:09:33 +01002391 }
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002392 case SQ_TEX_VTX_INVALID_TEXTURE:
2393 case SQ_TEX_VTX_INVALID_BUFFER:
2394 default:
2395 DRM_ERROR("bad SET_RESOURCE\n");
2396 return -EINVAL;
2397 }
2398 }
2399 break;
2400 case PACKET3_SET_ALU_CONST:
2401 /* XXX fix me ALU const buffers only */
2402 break;
2403 case PACKET3_SET_BOOL_CONST:
2404 start_reg = (idx_value << 2) + PACKET3_SET_BOOL_CONST_START;
2405 end_reg = 4 * pkt->count + start_reg - 4;
2406 if ((start_reg < PACKET3_SET_BOOL_CONST_START) ||
2407 (start_reg >= PACKET3_SET_BOOL_CONST_END) ||
2408 (end_reg >= PACKET3_SET_BOOL_CONST_END)) {
2409 DRM_ERROR("bad SET_BOOL_CONST\n");
2410 return -EINVAL;
2411 }
2412 break;
2413 case PACKET3_SET_LOOP_CONST:
2414 start_reg = (idx_value << 2) + PACKET3_SET_LOOP_CONST_START;
2415 end_reg = 4 * pkt->count + start_reg - 4;
2416 if ((start_reg < PACKET3_SET_LOOP_CONST_START) ||
2417 (start_reg >= PACKET3_SET_LOOP_CONST_END) ||
2418 (end_reg >= PACKET3_SET_LOOP_CONST_END)) {
2419 DRM_ERROR("bad SET_LOOP_CONST\n");
2420 return -EINVAL;
2421 }
2422 break;
2423 case PACKET3_SET_CTL_CONST:
2424 start_reg = (idx_value << 2) + PACKET3_SET_CTL_CONST_START;
2425 end_reg = 4 * pkt->count + start_reg - 4;
2426 if ((start_reg < PACKET3_SET_CTL_CONST_START) ||
2427 (start_reg >= PACKET3_SET_CTL_CONST_END) ||
2428 (end_reg >= PACKET3_SET_CTL_CONST_END)) {
2429 DRM_ERROR("bad SET_CTL_CONST\n");
2430 return -EINVAL;
2431 }
2432 break;
2433 case PACKET3_SET_SAMPLER:
2434 if (pkt->count % 3) {
2435 DRM_ERROR("bad SET_SAMPLER\n");
2436 return -EINVAL;
2437 }
2438 start_reg = (idx_value << 2) + PACKET3_SET_SAMPLER_START;
2439 end_reg = 4 * pkt->count + start_reg - 4;
2440 if ((start_reg < PACKET3_SET_SAMPLER_START) ||
2441 (start_reg >= PACKET3_SET_SAMPLER_END) ||
2442 (end_reg >= PACKET3_SET_SAMPLER_END)) {
2443 DRM_ERROR("bad SET_SAMPLER\n");
2444 return -EINVAL;
2445 }
2446 break;
Marek Olšákdd220a02012-01-27 12:17:59 -05002447 case PACKET3_STRMOUT_BUFFER_UPDATE:
2448 if (pkt->count != 4) {
2449 DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (invalid count)\n");
2450 return -EINVAL;
2451 }
2452 /* Updating memory at DST_ADDRESS. */
2453 if (idx_value & 0x1) {
2454 u64 offset;
2455 r = evergreen_cs_packet_next_reloc(p, &reloc);
2456 if (r) {
2457 DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (missing dst reloc)\n");
2458 return -EINVAL;
2459 }
2460 offset = radeon_get_ib_value(p, idx+1);
2461 offset += ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
2462 if ((offset + 4) > radeon_bo_size(reloc->robj)) {
2463 DRM_ERROR("bad STRMOUT_BUFFER_UPDATE dst bo too small: 0x%llx, 0x%lx\n",
2464 offset + 4, radeon_bo_size(reloc->robj));
2465 return -EINVAL;
2466 }
Marek Olšák78857132012-03-19 03:09:33 +01002467 offset += reloc->lobj.gpu_offset;
2468 ib[idx+1] = offset;
2469 ib[idx+2] = upper_32_bits(offset) & 0xff;
Marek Olšákdd220a02012-01-27 12:17:59 -05002470 }
2471 /* Reading data from SRC_ADDRESS. */
2472 if (((idx_value >> 1) & 0x3) == 2) {
2473 u64 offset;
2474 r = evergreen_cs_packet_next_reloc(p, &reloc);
2475 if (r) {
2476 DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (missing src reloc)\n");
2477 return -EINVAL;
2478 }
2479 offset = radeon_get_ib_value(p, idx+3);
2480 offset += ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
2481 if ((offset + 4) > radeon_bo_size(reloc->robj)) {
2482 DRM_ERROR("bad STRMOUT_BUFFER_UPDATE src bo too small: 0x%llx, 0x%lx\n",
2483 offset + 4, radeon_bo_size(reloc->robj));
2484 return -EINVAL;
2485 }
Marek Olšák78857132012-03-19 03:09:33 +01002486 offset += reloc->lobj.gpu_offset;
2487 ib[idx+3] = offset;
2488 ib[idx+4] = upper_32_bits(offset) & 0xff;
Marek Olšákdd220a02012-01-27 12:17:59 -05002489 }
2490 break;
2491 case PACKET3_COPY_DW:
2492 if (pkt->count != 4) {
2493 DRM_ERROR("bad COPY_DW (invalid count)\n");
2494 return -EINVAL;
2495 }
2496 if (idx_value & 0x1) {
2497 u64 offset;
2498 /* SRC is memory. */
2499 r = evergreen_cs_packet_next_reloc(p, &reloc);
2500 if (r) {
2501 DRM_ERROR("bad COPY_DW (missing src reloc)\n");
2502 return -EINVAL;
2503 }
2504 offset = radeon_get_ib_value(p, idx+1);
2505 offset += ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
2506 if ((offset + 4) > radeon_bo_size(reloc->robj)) {
2507 DRM_ERROR("bad COPY_DW src bo too small: 0x%llx, 0x%lx\n",
2508 offset + 4, radeon_bo_size(reloc->robj));
2509 return -EINVAL;
2510 }
Marek Olšák78857132012-03-19 03:09:33 +01002511 offset += reloc->lobj.gpu_offset;
2512 ib[idx+1] = offset;
2513 ib[idx+2] = upper_32_bits(offset) & 0xff;
Marek Olšákdd220a02012-01-27 12:17:59 -05002514 } else {
2515 /* SRC is a reg. */
2516 reg = radeon_get_ib_value(p, idx+1) << 2;
2517 if (!evergreen_is_safe_reg(p, reg, idx+1))
2518 return -EINVAL;
2519 }
2520 if (idx_value & 0x2) {
2521 u64 offset;
2522 /* DST is memory. */
2523 r = evergreen_cs_packet_next_reloc(p, &reloc);
2524 if (r) {
2525 DRM_ERROR("bad COPY_DW (missing dst reloc)\n");
2526 return -EINVAL;
2527 }
2528 offset = radeon_get_ib_value(p, idx+3);
2529 offset += ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
2530 if ((offset + 4) > radeon_bo_size(reloc->robj)) {
2531 DRM_ERROR("bad COPY_DW dst bo too small: 0x%llx, 0x%lx\n",
2532 offset + 4, radeon_bo_size(reloc->robj));
2533 return -EINVAL;
2534 }
Marek Olšák78857132012-03-19 03:09:33 +01002535 offset += reloc->lobj.gpu_offset;
2536 ib[idx+3] = offset;
2537 ib[idx+4] = upper_32_bits(offset) & 0xff;
Marek Olšákdd220a02012-01-27 12:17:59 -05002538 } else {
2539 /* DST is a reg. */
2540 reg = radeon_get_ib_value(p, idx+3) << 2;
2541 if (!evergreen_is_safe_reg(p, reg, idx+3))
2542 return -EINVAL;
2543 }
2544 break;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002545 case PACKET3_NOP:
2546 break;
2547 default:
2548 DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
2549 return -EINVAL;
2550 }
2551 return 0;
2552}
2553
2554int evergreen_cs_parse(struct radeon_cs_parser *p)
2555{
2556 struct radeon_cs_packet pkt;
2557 struct evergreen_cs_track *track;
Alex Deucherf3a71df2011-11-28 14:49:28 -05002558 u32 tmp;
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002559 int r;
2560
2561 if (p->track == NULL) {
2562 /* initialize tracker, we are in kms */
2563 track = kzalloc(sizeof(*track), GFP_KERNEL);
2564 if (track == NULL)
2565 return -ENOMEM;
2566 evergreen_cs_track_init(track);
Alex Deucherf3a71df2011-11-28 14:49:28 -05002567 if (p->rdev->family >= CHIP_CAYMAN)
2568 tmp = p->rdev->config.cayman.tile_config;
2569 else
2570 tmp = p->rdev->config.evergreen.tile_config;
2571
2572 switch (tmp & 0xf) {
2573 case 0:
2574 track->npipes = 1;
2575 break;
2576 case 1:
2577 default:
2578 track->npipes = 2;
2579 break;
2580 case 2:
2581 track->npipes = 4;
2582 break;
2583 case 3:
2584 track->npipes = 8;
2585 break;
2586 }
2587
2588 switch ((tmp & 0xf0) >> 4) {
2589 case 0:
2590 track->nbanks = 4;
2591 break;
2592 case 1:
2593 default:
2594 track->nbanks = 8;
2595 break;
2596 case 2:
2597 track->nbanks = 16;
2598 break;
2599 }
2600
2601 switch ((tmp & 0xf00) >> 8) {
2602 case 0:
2603 track->group_size = 256;
2604 break;
2605 case 1:
2606 default:
2607 track->group_size = 512;
2608 break;
2609 }
2610
2611 switch ((tmp & 0xf000) >> 12) {
2612 case 0:
2613 track->row_size = 1;
2614 break;
2615 case 1:
2616 default:
2617 track->row_size = 2;
2618 break;
2619 case 2:
2620 track->row_size = 4;
2621 break;
2622 }
2623
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002624 p->track = track;
2625 }
2626 do {
2627 r = evergreen_cs_packet_parse(p, &pkt, p->idx);
2628 if (r) {
2629 kfree(p->track);
2630 p->track = NULL;
2631 return r;
2632 }
2633 p->idx += pkt.count + 2;
2634 switch (pkt.type) {
2635 case PACKET_TYPE0:
2636 r = evergreen_cs_parse_packet0(p, &pkt);
2637 break;
2638 case PACKET_TYPE2:
2639 break;
2640 case PACKET_TYPE3:
2641 r = evergreen_packet3_check(p, &pkt);
2642 break;
2643 default:
2644 DRM_ERROR("Unknown packet type %d !\n", pkt.type);
2645 kfree(p->track);
2646 p->track = NULL;
2647 return -EINVAL;
2648 }
2649 if (r) {
2650 kfree(p->track);
2651 p->track = NULL;
2652 return r;
2653 }
2654 } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
2655#if 0
Jerome Glissef2e39222012-05-09 15:35:02 +02002656 for (r = 0; r < p->ib.length_dw; r++) {
2657 printk(KERN_INFO "%05d 0x%08X\n", r, p->ib.ptr[r]);
Alex Deuchercb5fcbd2010-05-28 19:01:35 -04002658 mdelay(1);
2659 }
2660#endif
2661 kfree(p->track);
2662 p->track = NULL;
2663 return 0;
2664}
2665
Jerome Glisse721604a2012-01-05 22:11:05 -05002666/* vm parser */
2667static bool evergreen_vm_reg_valid(u32 reg)
2668{
2669 /* context regs are fine */
2670 if (reg >= 0x28000)
2671 return true;
2672
2673 /* check config regs */
2674 switch (reg) {
2675 case GRBM_GFX_INDEX:
2676 case VGT_VTX_VECT_EJECT_REG:
2677 case VGT_CACHE_INVALIDATION:
2678 case VGT_GS_VERTEX_REUSE:
2679 case VGT_PRIMITIVE_TYPE:
2680 case VGT_INDEX_TYPE:
2681 case VGT_NUM_INDICES:
2682 case VGT_NUM_INSTANCES:
2683 case VGT_COMPUTE_DIM_X:
2684 case VGT_COMPUTE_DIM_Y:
2685 case VGT_COMPUTE_DIM_Z:
2686 case VGT_COMPUTE_START_X:
2687 case VGT_COMPUTE_START_Y:
2688 case VGT_COMPUTE_START_Z:
2689 case VGT_COMPUTE_INDEX:
2690 case VGT_COMPUTE_THREAD_GROUP_SIZE:
2691 case VGT_HS_OFFCHIP_PARAM:
2692 case PA_CL_ENHANCE:
2693 case PA_SU_LINE_STIPPLE_VALUE:
2694 case PA_SC_LINE_STIPPLE_STATE:
2695 case PA_SC_ENHANCE:
2696 case SQ_DYN_GPR_CNTL_PS_FLUSH_REQ:
2697 case SQ_DYN_GPR_SIMD_LOCK_EN:
2698 case SQ_CONFIG:
2699 case SQ_GPR_RESOURCE_MGMT_1:
2700 case SQ_GLOBAL_GPR_RESOURCE_MGMT_1:
2701 case SQ_GLOBAL_GPR_RESOURCE_MGMT_2:
2702 case SQ_CONST_MEM_BASE:
2703 case SQ_STATIC_THREAD_MGMT_1:
2704 case SQ_STATIC_THREAD_MGMT_2:
2705 case SQ_STATIC_THREAD_MGMT_3:
2706 case SPI_CONFIG_CNTL:
2707 case SPI_CONFIG_CNTL_1:
2708 case TA_CNTL_AUX:
2709 case DB_DEBUG:
2710 case DB_DEBUG2:
2711 case DB_DEBUG3:
2712 case DB_DEBUG4:
2713 case DB_WATERMARKS:
2714 case TD_PS_BORDER_COLOR_INDEX:
2715 case TD_PS_BORDER_COLOR_RED:
2716 case TD_PS_BORDER_COLOR_GREEN:
2717 case TD_PS_BORDER_COLOR_BLUE:
2718 case TD_PS_BORDER_COLOR_ALPHA:
2719 case TD_VS_BORDER_COLOR_INDEX:
2720 case TD_VS_BORDER_COLOR_RED:
2721 case TD_VS_BORDER_COLOR_GREEN:
2722 case TD_VS_BORDER_COLOR_BLUE:
2723 case TD_VS_BORDER_COLOR_ALPHA:
2724 case TD_GS_BORDER_COLOR_INDEX:
2725 case TD_GS_BORDER_COLOR_RED:
2726 case TD_GS_BORDER_COLOR_GREEN:
2727 case TD_GS_BORDER_COLOR_BLUE:
2728 case TD_GS_BORDER_COLOR_ALPHA:
2729 case TD_HS_BORDER_COLOR_INDEX:
2730 case TD_HS_BORDER_COLOR_RED:
2731 case TD_HS_BORDER_COLOR_GREEN:
2732 case TD_HS_BORDER_COLOR_BLUE:
2733 case TD_HS_BORDER_COLOR_ALPHA:
2734 case TD_LS_BORDER_COLOR_INDEX:
2735 case TD_LS_BORDER_COLOR_RED:
2736 case TD_LS_BORDER_COLOR_GREEN:
2737 case TD_LS_BORDER_COLOR_BLUE:
2738 case TD_LS_BORDER_COLOR_ALPHA:
2739 case TD_CS_BORDER_COLOR_INDEX:
2740 case TD_CS_BORDER_COLOR_RED:
2741 case TD_CS_BORDER_COLOR_GREEN:
2742 case TD_CS_BORDER_COLOR_BLUE:
2743 case TD_CS_BORDER_COLOR_ALPHA:
2744 case SQ_ESGS_RING_SIZE:
2745 case SQ_GSVS_RING_SIZE:
2746 case SQ_ESTMP_RING_SIZE:
2747 case SQ_GSTMP_RING_SIZE:
2748 case SQ_HSTMP_RING_SIZE:
2749 case SQ_LSTMP_RING_SIZE:
2750 case SQ_PSTMP_RING_SIZE:
2751 case SQ_VSTMP_RING_SIZE:
2752 case SQ_ESGS_RING_ITEMSIZE:
2753 case SQ_ESTMP_RING_ITEMSIZE:
2754 case SQ_GSTMP_RING_ITEMSIZE:
2755 case SQ_GSVS_RING_ITEMSIZE:
2756 case SQ_GS_VERT_ITEMSIZE:
2757 case SQ_GS_VERT_ITEMSIZE_1:
2758 case SQ_GS_VERT_ITEMSIZE_2:
2759 case SQ_GS_VERT_ITEMSIZE_3:
2760 case SQ_GSVS_RING_OFFSET_1:
2761 case SQ_GSVS_RING_OFFSET_2:
2762 case SQ_GSVS_RING_OFFSET_3:
2763 case SQ_HSTMP_RING_ITEMSIZE:
2764 case SQ_LSTMP_RING_ITEMSIZE:
2765 case SQ_PSTMP_RING_ITEMSIZE:
2766 case SQ_VSTMP_RING_ITEMSIZE:
2767 case VGT_TF_RING_SIZE:
2768 case SQ_ESGS_RING_BASE:
2769 case SQ_GSVS_RING_BASE:
2770 case SQ_ESTMP_RING_BASE:
2771 case SQ_GSTMP_RING_BASE:
2772 case SQ_HSTMP_RING_BASE:
2773 case SQ_LSTMP_RING_BASE:
2774 case SQ_PSTMP_RING_BASE:
2775 case SQ_VSTMP_RING_BASE:
2776 case CAYMAN_VGT_OFFCHIP_LDS_BASE:
2777 case CAYMAN_SQ_EX_ALLOC_TABLE_SLOTS:
2778 return true;
2779 default:
2780 return false;
2781 }
2782}
2783
2784static int evergreen_vm_packet3_check(struct radeon_device *rdev,
2785 u32 *ib, struct radeon_cs_packet *pkt)
2786{
2787 u32 idx = pkt->idx + 1;
2788 u32 idx_value = ib[idx];
2789 u32 start_reg, end_reg, reg, i;
2790
2791 switch (pkt->opcode) {
2792 case PACKET3_NOP:
2793 case PACKET3_SET_BASE:
2794 case PACKET3_CLEAR_STATE:
2795 case PACKET3_INDEX_BUFFER_SIZE:
2796 case PACKET3_DISPATCH_DIRECT:
2797 case PACKET3_DISPATCH_INDIRECT:
2798 case PACKET3_MODE_CONTROL:
2799 case PACKET3_SET_PREDICATION:
2800 case PACKET3_COND_EXEC:
2801 case PACKET3_PRED_EXEC:
2802 case PACKET3_DRAW_INDIRECT:
2803 case PACKET3_DRAW_INDEX_INDIRECT:
2804 case PACKET3_INDEX_BASE:
2805 case PACKET3_DRAW_INDEX_2:
2806 case PACKET3_CONTEXT_CONTROL:
2807 case PACKET3_DRAW_INDEX_OFFSET:
2808 case PACKET3_INDEX_TYPE:
2809 case PACKET3_DRAW_INDEX:
2810 case PACKET3_DRAW_INDEX_AUTO:
2811 case PACKET3_DRAW_INDEX_IMMD:
2812 case PACKET3_NUM_INSTANCES:
2813 case PACKET3_DRAW_INDEX_MULTI_AUTO:
2814 case PACKET3_STRMOUT_BUFFER_UPDATE:
2815 case PACKET3_DRAW_INDEX_OFFSET_2:
2816 case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
2817 case PACKET3_MPEG_INDEX:
2818 case PACKET3_WAIT_REG_MEM:
2819 case PACKET3_MEM_WRITE:
2820 case PACKET3_SURFACE_SYNC:
2821 case PACKET3_EVENT_WRITE:
2822 case PACKET3_EVENT_WRITE_EOP:
2823 case PACKET3_EVENT_WRITE_EOS:
2824 case PACKET3_SET_CONTEXT_REG:
2825 case PACKET3_SET_BOOL_CONST:
2826 case PACKET3_SET_LOOP_CONST:
2827 case PACKET3_SET_RESOURCE:
2828 case PACKET3_SET_SAMPLER:
2829 case PACKET3_SET_CTL_CONST:
2830 case PACKET3_SET_RESOURCE_OFFSET:
2831 case PACKET3_SET_CONTEXT_REG_INDIRECT:
2832 case PACKET3_SET_RESOURCE_INDIRECT:
2833 case CAYMAN_PACKET3_DEALLOC_STATE:
2834 break;
2835 case PACKET3_COND_WRITE:
2836 if (idx_value & 0x100) {
2837 reg = ib[idx + 5] * 4;
2838 if (!evergreen_vm_reg_valid(reg))
2839 return -EINVAL;
2840 }
2841 break;
2842 case PACKET3_COPY_DW:
2843 if (idx_value & 0x2) {
2844 reg = ib[idx + 3] * 4;
2845 if (!evergreen_vm_reg_valid(reg))
2846 return -EINVAL;
2847 }
2848 break;
2849 case PACKET3_SET_CONFIG_REG:
2850 start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
2851 end_reg = 4 * pkt->count + start_reg - 4;
2852 if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
2853 (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
2854 (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
2855 DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
2856 return -EINVAL;
2857 }
2858 for (i = 0; i < pkt->count; i++) {
2859 reg = start_reg + (4 * i);
2860 if (!evergreen_vm_reg_valid(reg))
2861 return -EINVAL;
2862 }
2863 break;
2864 default:
2865 return -EINVAL;
2866 }
2867 return 0;
2868}
2869
2870int evergreen_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
2871{
2872 int ret = 0;
2873 u32 idx = 0;
2874 struct radeon_cs_packet pkt;
2875
2876 do {
2877 pkt.idx = idx;
2878 pkt.type = CP_PACKET_GET_TYPE(ib->ptr[idx]);
2879 pkt.count = CP_PACKET_GET_COUNT(ib->ptr[idx]);
2880 pkt.one_reg_wr = 0;
2881 switch (pkt.type) {
2882 case PACKET_TYPE0:
2883 dev_err(rdev->dev, "Packet0 not allowed!\n");
2884 ret = -EINVAL;
2885 break;
2886 case PACKET_TYPE2:
Alex Deucher0b41da62012-01-12 15:42:37 -05002887 idx += 1;
Jerome Glisse721604a2012-01-05 22:11:05 -05002888 break;
2889 case PACKET_TYPE3:
2890 pkt.opcode = CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
2891 ret = evergreen_vm_packet3_check(rdev, ib->ptr, &pkt);
Alex Deucher0b41da62012-01-12 15:42:37 -05002892 idx += pkt.count + 2;
Jerome Glisse721604a2012-01-05 22:11:05 -05002893 break;
2894 default:
2895 dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
2896 ret = -EINVAL;
2897 break;
2898 }
2899 if (ret)
2900 break;
Jerome Glisse721604a2012-01-05 22:11:05 -05002901 } while (idx < ib->length_dw);
2902
2903 return ret;
2904}