aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/radeon/r600_cs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/radeon/r600_cs.c')
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c880
1 files changed, 797 insertions, 83 deletions
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index 0d820764f340..c39c1bc13016 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -28,6 +28,7 @@
28#include "drmP.h" 28#include "drmP.h"
29#include "radeon.h" 29#include "radeon.h"
30#include "r600d.h" 30#include "r600d.h"
31#include "r600_reg_safe.h"
31 32
32static int r600_cs_packet_next_reloc_mm(struct radeon_cs_parser *p, 33static int r600_cs_packet_next_reloc_mm(struct radeon_cs_parser *p,
33 struct radeon_cs_reloc **cs_reloc); 34 struct radeon_cs_reloc **cs_reloc);
@@ -35,6 +36,315 @@ static int r600_cs_packet_next_reloc_nomm(struct radeon_cs_parser *p,
35 struct radeon_cs_reloc **cs_reloc); 36 struct radeon_cs_reloc **cs_reloc);
36typedef int (*next_reloc_t)(struct radeon_cs_parser*, struct radeon_cs_reloc**); 37typedef int (*next_reloc_t)(struct radeon_cs_parser*, struct radeon_cs_reloc**);
37static next_reloc_t r600_cs_packet_next_reloc = &r600_cs_packet_next_reloc_mm; 38static next_reloc_t r600_cs_packet_next_reloc = &r600_cs_packet_next_reloc_mm;
39extern void r600_cs_legacy_get_tiling_conf(struct drm_device *dev, u32 *npipes, u32 *nbanks, u32 *group_size);
40
41
42struct r600_cs_track {
43 /* configuration we miror so that we use same code btw kms/ums */
44 u32 group_size;
45 u32 nbanks;
46 u32 npipes;
47 /* value we track */
48 u32 sq_config;
49 u32 nsamples;
50 u32 cb_color_base_last[8];
51 struct radeon_bo *cb_color_bo[8];
52 u32 cb_color_bo_offset[8];
53 struct radeon_bo *cb_color_frag_bo[8];
54 struct radeon_bo *cb_color_tile_bo[8];
55 u32 cb_color_info[8];
56 u32 cb_color_size_idx[8];
57 u32 cb_target_mask;
58 u32 cb_shader_mask;
59 u32 cb_color_size[8];
60 u32 vgt_strmout_en;
61 u32 vgt_strmout_buffer_en;
62 u32 db_depth_control;
63 u32 db_depth_info;
64 u32 db_depth_size_idx;
65 u32 db_depth_view;
66 u32 db_depth_size;
67 u32 db_offset;
68 struct radeon_bo *db_bo;
69};
70
71static inline int r600_bpe_from_format(u32 *bpe, u32 format)
72{
73 switch (format) {
74 case V_038004_COLOR_8:
75 case V_038004_COLOR_4_4:
76 case V_038004_COLOR_3_3_2:
77 case V_038004_FMT_1:
78 *bpe = 1;
79 break;
80 case V_038004_COLOR_16:
81 case V_038004_COLOR_16_FLOAT:
82 case V_038004_COLOR_8_8:
83 case V_038004_COLOR_5_6_5:
84 case V_038004_COLOR_6_5_5:
85 case V_038004_COLOR_1_5_5_5:
86 case V_038004_COLOR_4_4_4_4:
87 case V_038004_COLOR_5_5_5_1:
88 *bpe = 2;
89 break;
90 case V_038004_FMT_8_8_8:
91 *bpe = 3;
92 break;
93 case V_038004_COLOR_32:
94 case V_038004_COLOR_32_FLOAT:
95 case V_038004_COLOR_16_16:
96 case V_038004_COLOR_16_16_FLOAT:
97 case V_038004_COLOR_8_24:
98 case V_038004_COLOR_8_24_FLOAT:
99 case V_038004_COLOR_24_8:
100 case V_038004_COLOR_24_8_FLOAT:
101 case V_038004_COLOR_10_11_11:
102 case V_038004_COLOR_10_11_11_FLOAT:
103 case V_038004_COLOR_11_11_10:
104 case V_038004_COLOR_11_11_10_FLOAT:
105 case V_038004_COLOR_2_10_10_10:
106 case V_038004_COLOR_8_8_8_8:
107 case V_038004_COLOR_10_10_10_2:
108 case V_038004_FMT_5_9_9_9_SHAREDEXP:
109 case V_038004_FMT_32_AS_8:
110 case V_038004_FMT_32_AS_8_8:
111 *bpe = 4;
112 break;
113 case V_038004_COLOR_X24_8_32_FLOAT:
114 case V_038004_COLOR_32_32:
115 case V_038004_COLOR_32_32_FLOAT:
116 case V_038004_COLOR_16_16_16_16:
117 case V_038004_COLOR_16_16_16_16_FLOAT:
118 *bpe = 8;
119 break;
120 case V_038004_FMT_16_16_16:
121 case V_038004_FMT_16_16_16_FLOAT:
122 *bpe = 6;
123 break;
124 case V_038004_FMT_32_32_32:
125 case V_038004_FMT_32_32_32_FLOAT:
126 *bpe = 12;
127 break;
128 case V_038004_COLOR_32_32_32_32:
129 case V_038004_COLOR_32_32_32_32_FLOAT:
130 *bpe = 16;
131 break;
132 case V_038004_FMT_GB_GR:
133 case V_038004_FMT_BG_RG:
134 case V_038004_COLOR_INVALID:
135 *bpe = 16;
136 return -EINVAL;
137 }
138 return 0;
139}
140
141static void r600_cs_track_init(struct r600_cs_track *track)
142{
143 int i;
144
145 /* assume DX9 mode */
146 track->sq_config = DX9_CONSTS;
147 for (i = 0; i < 8; i++) {
148 track->cb_color_base_last[i] = 0;
149 track->cb_color_size[i] = 0;
150 track->cb_color_size_idx[i] = 0;
151 track->cb_color_info[i] = 0;
152 track->cb_color_bo[i] = NULL;
153 track->cb_color_bo_offset[i] = 0xFFFFFFFF;
154 }
155 track->cb_target_mask = 0xFFFFFFFF;
156 track->cb_shader_mask = 0xFFFFFFFF;
157 track->db_bo = NULL;
158 /* assume the biggest format and that htile is enabled */
159 track->db_depth_info = 7 | (1 << 25);
160 track->db_depth_view = 0xFFFFC000;
161 track->db_depth_size = 0xFFFFFFFF;
162 track->db_depth_size_idx = 0;
163 track->db_depth_control = 0xFFFFFFFF;
164}
165
166static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
167{
168 struct r600_cs_track *track = p->track;
169 u32 bpe = 0, pitch, slice_tile_max, size, tmp, height;
170 volatile u32 *ib = p->ib->ptr;
171
172 if (G_0280A0_TILE_MODE(track->cb_color_info[i])) {
173 dev_warn(p->dev, "FMASK or CMASK buffer are not supported by this kernel\n");
174 return -EINVAL;
175 }
176 size = radeon_bo_size(track->cb_color_bo[i]);
177 if (r600_bpe_from_format(&bpe, G_0280A0_FORMAT(track->cb_color_info[i]))) {
178 dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08X)\n",
179 __func__, __LINE__, G_0280A0_FORMAT(track->cb_color_info[i]),
180 i, track->cb_color_info[i]);
181 return -EINVAL;
182 }
183 pitch = (G_028060_PITCH_TILE_MAX(track->cb_color_size[i]) + 1) << 3;
184 slice_tile_max = G_028060_SLICE_TILE_MAX(track->cb_color_size[i]) + 1;
185 if (!pitch) {
186 dev_warn(p->dev, "%s:%d cb pitch (%d) for %d invalid (0x%08X)\n",
187 __func__, __LINE__, pitch, i, track->cb_color_size[i]);
188 return -EINVAL;
189 }
190 height = size / (pitch * bpe);
191 if (height > 8192)
192 height = 8192;
193 switch (G_0280A0_ARRAY_MODE(track->cb_color_info[i])) {
194 case V_0280A0_ARRAY_LINEAR_GENERAL:
195 case V_0280A0_ARRAY_LINEAR_ALIGNED:
196 if (pitch & 0x3f) {
197 dev_warn(p->dev, "%s:%d cb pitch (%d x %d = %d) invalid\n",
198 __func__, __LINE__, pitch, bpe, pitch * bpe);
199 return -EINVAL;
200 }
201 if ((pitch * bpe) & (track->group_size - 1)) {
202 dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
203 __func__, __LINE__, pitch);
204 return -EINVAL;
205 }
206 break;
207 case V_0280A0_ARRAY_1D_TILED_THIN1:
208 if ((pitch * 8 * bpe * track->nsamples) & (track->group_size - 1)) {
209 dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
210 __func__, __LINE__, pitch);
211 return -EINVAL;
212 }
213 height &= ~0x7;
214 if (!height)
215 height = 8;
216 break;
217 case V_0280A0_ARRAY_2D_TILED_THIN1:
218 if (pitch & ((8 * track->nbanks) - 1)) {
219 dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
220 __func__, __LINE__, pitch);
221 return -EINVAL;
222 }
223 tmp = pitch * 8 * bpe * track->nsamples;
224 tmp = tmp / track->nbanks;
225 if (tmp & (track->group_size - 1)) {
226 dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
227 __func__, __LINE__, pitch);
228 return -EINVAL;
229 }
230 height &= ~((16 * track->npipes) - 1);
231 if (!height)
232 height = 16 * track->npipes;
233 break;
234 default:
235 dev_warn(p->dev, "%s invalid tiling %d for %d (0x%08X)\n", __func__,
236 G_0280A0_ARRAY_MODE(track->cb_color_info[i]), i,
237 track->cb_color_info[i]);
238 return -EINVAL;
239 }
240 /* check offset */
241 tmp = height * pitch;
242 if ((tmp + track->cb_color_bo_offset[i]) > radeon_bo_size(track->cb_color_bo[i])) {
243 dev_warn(p->dev, "%s offset[%d] %d to big\n", __func__, i, track->cb_color_bo_offset[i]);
244 return -EINVAL;
245 }
246 /* limit max tile */
247 tmp = (height * pitch) >> 6;
248 if (tmp < slice_tile_max)
249 slice_tile_max = tmp;
250 tmp = S_028060_PITCH_TILE_MAX((pitch >> 3) - 1) |
251 S_028060_SLICE_TILE_MAX(slice_tile_max - 1);
252 ib[track->cb_color_size_idx[i]] = tmp;
253 return 0;
254}
255
256static int r600_cs_track_check(struct radeon_cs_parser *p)
257{
258 struct r600_cs_track *track = p->track;
259 u32 tmp;
260 int r, i;
261 volatile u32 *ib = p->ib->ptr;
262
263 /* on legacy kernel we don't perform advanced check */
264 if (p->rdev == NULL)
265 return 0;
266 /* we don't support out buffer yet */
267 if (track->vgt_strmout_en || track->vgt_strmout_buffer_en) {
268 dev_warn(p->dev, "this kernel doesn't support SMX output buffer\n");
269 return -EINVAL;
270 }
271 /* check that we have a cb for each enabled target, we don't check
272 * shader_mask because it seems mesa isn't always setting it :(
273 */
274 tmp = track->cb_target_mask;
275 for (i = 0; i < 8; i++) {
276 if ((tmp >> (i * 4)) & 0xF) {
277 /* at least one component is enabled */
278 if (track->cb_color_bo[i] == NULL) {
279 dev_warn(p->dev, "%s:%d mask 0x%08X | 0x%08X no cb for %d\n",
280 __func__, __LINE__, track->cb_target_mask, track->cb_shader_mask, i);
281 return -EINVAL;
282 }
283 /* perform rewrite of CB_COLOR[0-7]_SIZE */
284 r = r600_cs_track_validate_cb(p, i);
285 if (r)
286 return r;
287 }
288 }
289 /* Check depth buffer */
290 if (G_028800_STENCIL_ENABLE(track->db_depth_control) ||
291 G_028800_Z_ENABLE(track->db_depth_control)) {
292 u32 nviews, bpe, ntiles;
293 if (track->db_bo == NULL) {
294 dev_warn(p->dev, "z/stencil with no depth buffer\n");
295 return -EINVAL;
296 }
297 if (G_028010_TILE_SURFACE_ENABLE(track->db_depth_info)) {
298 dev_warn(p->dev, "this kernel doesn't support z/stencil htile\n");
299 return -EINVAL;
300 }
301 switch (G_028010_FORMAT(track->db_depth_info)) {
302 case V_028010_DEPTH_16:
303 bpe = 2;
304 break;
305 case V_028010_DEPTH_X8_24:
306 case V_028010_DEPTH_8_24:
307 case V_028010_DEPTH_X8_24_FLOAT:
308 case V_028010_DEPTH_8_24_FLOAT:
309 case V_028010_DEPTH_32_FLOAT:
310 bpe = 4;
311 break;
312 case V_028010_DEPTH_X24_8_32_FLOAT:
313 bpe = 8;
314 break;
315 default:
316 dev_warn(p->dev, "z/stencil with invalid format %d\n", G_028010_FORMAT(track->db_depth_info));
317 return -EINVAL;
318 }
319 if ((track->db_depth_size & 0xFFFFFC00) == 0xFFFFFC00) {
320 if (!track->db_depth_size_idx) {
321 dev_warn(p->dev, "z/stencil buffer size not set\n");
322 return -EINVAL;
323 }
324 printk_once(KERN_WARNING "You have old & broken userspace please consider updating mesa\n");
325 tmp = radeon_bo_size(track->db_bo) - track->db_offset;
326 tmp = (tmp / bpe) >> 6;
327 if (!tmp) {
328 dev_warn(p->dev, "z/stencil buffer too small (0x%08X %d %d %ld)\n",
329 track->db_depth_size, bpe, track->db_offset,
330 radeon_bo_size(track->db_bo));
331 return -EINVAL;
332 }
333 ib[track->db_depth_size_idx] = S_028000_SLICE_TILE_MAX(tmp - 1) | (track->db_depth_size & 0x3FF);
334 } else {
335 ntiles = G_028000_SLICE_TILE_MAX(track->db_depth_size) + 1;
336 nviews = G_028004_SLICE_MAX(track->db_depth_view) + 1;
337 tmp = ntiles * bpe * 64 * nviews;
338 if ((tmp + track->db_offset) > radeon_bo_size(track->db_bo)) {
339 dev_warn(p->dev, "z/stencil buffer too small (0x%08X %d %d %d -> %d have %ld)\n",
340 track->db_depth_size, ntiles, nviews, bpe, tmp + track->db_offset,
341 radeon_bo_size(track->db_bo));
342 return -EINVAL;
343 }
344 }
345 }
346 return 0;
347}
38 348
39/** 349/**
40 * r600_cs_packet_parse() - parse cp packet and point ib index to next packet 350 * r600_cs_packet_parse() - parse cp packet and point ib index to next packet
@@ -170,13 +480,35 @@ static int r600_cs_packet_next_reloc_nomm(struct radeon_cs_parser *p,
170 idx, relocs_chunk->length_dw); 480 idx, relocs_chunk->length_dw);
171 return -EINVAL; 481 return -EINVAL;
172 } 482 }
173 *cs_reloc = &p->relocs[0]; 483 *cs_reloc = p->relocs;
174 (*cs_reloc)->lobj.gpu_offset = (u64)relocs_chunk->kdata[idx + 3] << 32; 484 (*cs_reloc)->lobj.gpu_offset = (u64)relocs_chunk->kdata[idx + 3] << 32;
175 (*cs_reloc)->lobj.gpu_offset |= relocs_chunk->kdata[idx + 0]; 485 (*cs_reloc)->lobj.gpu_offset |= relocs_chunk->kdata[idx + 0];
176 return 0; 486 return 0;
177} 487}
178 488
179/** 489/**
490 * r600_cs_packet_next_is_pkt3_nop() - test if next packet is packet3 nop for reloc
491 * @parser: parser structure holding parsing context.
492 *
493 * Check next packet is relocation packet3, do bo validation and compute
494 * GPU offset using the provided start.
495 **/
496static inline int r600_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p)
497{
498 struct radeon_cs_packet p3reloc;
499 int r;
500
501 r = r600_cs_packet_parse(p, &p3reloc, p->idx);
502 if (r) {
503 return 0;
504 }
505 if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
506 return 0;
507 }
508 return 1;
509}
510
511/**
180 * r600_cs_packet_next_vline() - parse userspace VLINE packet 512 * r600_cs_packet_next_vline() - parse userspace VLINE packet
181 * @parser: parser structure holding parsing context. 513 * @parser: parser structure holding parsing context.
182 * 514 *
@@ -333,10 +665,390 @@ static int r600_cs_parse_packet0(struct radeon_cs_parser *p,
333 return 0; 665 return 0;
334} 666}
335 667
668/**
669 * r600_cs_check_reg() - check if register is authorized or not
670 * @parser: parser structure holding parsing context
671 * @reg: register we are testing
672 * @idx: index into the cs buffer
673 *
674 * This function will test against r600_reg_safe_bm and return 0
675 * if register is safe. If register is not flag as safe this function
676 * will test it against a list of register needind special handling.
677 */
678static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
679{
680 struct r600_cs_track *track = (struct r600_cs_track *)p->track;
681 struct radeon_cs_reloc *reloc;
682 u32 last_reg = ARRAY_SIZE(r600_reg_safe_bm);
683 u32 m, i, tmp, *ib;
684 int r;
685
686 i = (reg >> 7);
687 if (i > last_reg) {
688 dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
689 return -EINVAL;
690 }
691 m = 1 << ((reg >> 2) & 31);
692 if (!(r600_reg_safe_bm[i] & m))
693 return 0;
694 ib = p->ib->ptr;
695 switch (reg) {
696 /* force following reg to 0 in an attemp to disable out buffer
697 * which will need us to better understand how it works to perform
698 * security check on it (Jerome)
699 */
700 case R_0288A8_SQ_ESGS_RING_ITEMSIZE:
701 case R_008C44_SQ_ESGS_RING_SIZE:
702 case R_0288B0_SQ_ESTMP_RING_ITEMSIZE:
703 case R_008C54_SQ_ESTMP_RING_SIZE:
704 case R_0288C0_SQ_FBUF_RING_ITEMSIZE:
705 case R_008C74_SQ_FBUF_RING_SIZE:
706 case R_0288B4_SQ_GSTMP_RING_ITEMSIZE:
707 case R_008C5C_SQ_GSTMP_RING_SIZE:
708 case R_0288AC_SQ_GSVS_RING_ITEMSIZE:
709 case R_008C4C_SQ_GSVS_RING_SIZE:
710 case R_0288BC_SQ_PSTMP_RING_ITEMSIZE:
711 case R_008C6C_SQ_PSTMP_RING_SIZE:
712 case R_0288C4_SQ_REDUC_RING_ITEMSIZE:
713 case R_008C7C_SQ_REDUC_RING_SIZE:
714 case R_0288B8_SQ_VSTMP_RING_ITEMSIZE:
715 case R_008C64_SQ_VSTMP_RING_SIZE:
716 case R_0288C8_SQ_GS_VERT_ITEMSIZE:
717 /* get value to populate the IB don't remove */
718 tmp =radeon_get_ib_value(p, idx);
719 ib[idx] = 0;
720 break;
721 case SQ_CONFIG:
722 track->sq_config = radeon_get_ib_value(p, idx);
723 break;
724 case R_028800_DB_DEPTH_CONTROL:
725 track->db_depth_control = radeon_get_ib_value(p, idx);
726 break;
727 case R_028010_DB_DEPTH_INFO:
728 track->db_depth_info = radeon_get_ib_value(p, idx);
729 break;
730 case R_028004_DB_DEPTH_VIEW:
731 track->db_depth_view = radeon_get_ib_value(p, idx);
732 break;
733 case R_028000_DB_DEPTH_SIZE:
734 track->db_depth_size = radeon_get_ib_value(p, idx);
735 track->db_depth_size_idx = idx;
736 break;
737 case R_028AB0_VGT_STRMOUT_EN:
738 track->vgt_strmout_en = radeon_get_ib_value(p, idx);
739 break;
740 case R_028B20_VGT_STRMOUT_BUFFER_EN:
741 track->vgt_strmout_buffer_en = radeon_get_ib_value(p, idx);
742 break;
743 case R_028238_CB_TARGET_MASK:
744 track->cb_target_mask = radeon_get_ib_value(p, idx);
745 break;
746 case R_02823C_CB_SHADER_MASK:
747 track->cb_shader_mask = radeon_get_ib_value(p, idx);
748 break;
749 case R_028C04_PA_SC_AA_CONFIG:
750 tmp = G_028C04_MSAA_NUM_SAMPLES(radeon_get_ib_value(p, idx));
751 track->nsamples = 1 << tmp;
752 break;
753 case R_0280A0_CB_COLOR0_INFO:
754 case R_0280A4_CB_COLOR1_INFO:
755 case R_0280A8_CB_COLOR2_INFO:
756 case R_0280AC_CB_COLOR3_INFO:
757 case R_0280B0_CB_COLOR4_INFO:
758 case R_0280B4_CB_COLOR5_INFO:
759 case R_0280B8_CB_COLOR6_INFO:
760 case R_0280BC_CB_COLOR7_INFO:
761 tmp = (reg - R_0280A0_CB_COLOR0_INFO) / 4;
762 track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
763 break;
764 case R_028060_CB_COLOR0_SIZE:
765 case R_028064_CB_COLOR1_SIZE:
766 case R_028068_CB_COLOR2_SIZE:
767 case R_02806C_CB_COLOR3_SIZE:
768 case R_028070_CB_COLOR4_SIZE:
769 case R_028074_CB_COLOR5_SIZE:
770 case R_028078_CB_COLOR6_SIZE:
771 case R_02807C_CB_COLOR7_SIZE:
772 tmp = (reg - R_028060_CB_COLOR0_SIZE) / 4;
773 track->cb_color_size[tmp] = radeon_get_ib_value(p, idx);
774 track->cb_color_size_idx[tmp] = idx;
775 break;
776 /* This register were added late, there is userspace
777 * which does provide relocation for those but set
778 * 0 offset. In order to avoid breaking old userspace
779 * we detect this and set address to point to last
780 * CB_COLOR0_BASE, note that if userspace doesn't set
781 * CB_COLOR0_BASE before this register we will report
782 * error. Old userspace always set CB_COLOR0_BASE
783 * before any of this.
784 */
785 case R_0280E0_CB_COLOR0_FRAG:
786 case R_0280E4_CB_COLOR1_FRAG:
787 case R_0280E8_CB_COLOR2_FRAG:
788 case R_0280EC_CB_COLOR3_FRAG:
789 case R_0280F0_CB_COLOR4_FRAG:
790 case R_0280F4_CB_COLOR5_FRAG:
791 case R_0280F8_CB_COLOR6_FRAG:
792 case R_0280FC_CB_COLOR7_FRAG:
793 tmp = (reg - R_0280E0_CB_COLOR0_FRAG) / 4;
794 if (!r600_cs_packet_next_is_pkt3_nop(p)) {
795 if (!track->cb_color_base_last[tmp]) {
796 dev_err(p->dev, "Broken old userspace ? no cb_color0_base supplied before trying to write 0x%08X\n", reg);
797 return -EINVAL;
798 }
799 ib[idx] = track->cb_color_base_last[tmp];
800 printk_once(KERN_WARNING "You have old & broken userspace "
801 "please consider updating mesa & xf86-video-ati\n");
802 track->cb_color_frag_bo[tmp] = track->cb_color_bo[tmp];
803 } else {
804 r = r600_cs_packet_next_reloc(p, &reloc);
805 if (r) {
806 dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
807 return -EINVAL;
808 }
809 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
810 track->cb_color_frag_bo[tmp] = reloc->robj;
811 }
812 break;
813 case R_0280C0_CB_COLOR0_TILE:
814 case R_0280C4_CB_COLOR1_TILE:
815 case R_0280C8_CB_COLOR2_TILE:
816 case R_0280CC_CB_COLOR3_TILE:
817 case R_0280D0_CB_COLOR4_TILE:
818 case R_0280D4_CB_COLOR5_TILE:
819 case R_0280D8_CB_COLOR6_TILE:
820 case R_0280DC_CB_COLOR7_TILE:
821 tmp = (reg - R_0280C0_CB_COLOR0_TILE) / 4;
822 if (!r600_cs_packet_next_is_pkt3_nop(p)) {
823 if (!track->cb_color_base_last[tmp]) {
824 dev_err(p->dev, "Broken old userspace ? no cb_color0_base supplied before trying to write 0x%08X\n", reg);
825 return -EINVAL;
826 }
827 ib[idx] = track->cb_color_base_last[tmp];
828 printk_once(KERN_WARNING "You have old & broken userspace "
829 "please consider updating mesa & xf86-video-ati\n");
830 track->cb_color_tile_bo[tmp] = track->cb_color_bo[tmp];
831 } else {
832 r = r600_cs_packet_next_reloc(p, &reloc);
833 if (r) {
834 dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
835 return -EINVAL;
836 }
837 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
838 track->cb_color_tile_bo[tmp] = reloc->robj;
839 }
840 break;
841 case CB_COLOR0_BASE:
842 case CB_COLOR1_BASE:
843 case CB_COLOR2_BASE:
844 case CB_COLOR3_BASE:
845 case CB_COLOR4_BASE:
846 case CB_COLOR5_BASE:
847 case CB_COLOR6_BASE:
848 case CB_COLOR7_BASE:
849 r = r600_cs_packet_next_reloc(p, &reloc);
850 if (r) {
851 dev_warn(p->dev, "bad SET_CONTEXT_REG "
852 "0x%04X\n", reg);
853 return -EINVAL;
854 }
855 tmp = (reg - CB_COLOR0_BASE) / 4;
856 track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
857 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
858 track->cb_color_base_last[tmp] = ib[idx];
859 track->cb_color_bo[tmp] = reloc->robj;
860 break;
861 case DB_DEPTH_BASE:
862 r = r600_cs_packet_next_reloc(p, &reloc);
863 if (r) {
864 dev_warn(p->dev, "bad SET_CONTEXT_REG "
865 "0x%04X\n", reg);
866 return -EINVAL;
867 }
868 track->db_offset = radeon_get_ib_value(p, idx);
869 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
870 track->db_bo = reloc->robj;
871 break;
872 case DB_HTILE_DATA_BASE:
873 case SQ_PGM_START_FS:
874 case SQ_PGM_START_ES:
875 case SQ_PGM_START_VS:
876 case SQ_PGM_START_GS:
877 case SQ_PGM_START_PS:
878 case SQ_ALU_CONST_CACHE_GS_0:
879 case SQ_ALU_CONST_CACHE_GS_1:
880 case SQ_ALU_CONST_CACHE_GS_2:
881 case SQ_ALU_CONST_CACHE_GS_3:
882 case SQ_ALU_CONST_CACHE_GS_4:
883 case SQ_ALU_CONST_CACHE_GS_5:
884 case SQ_ALU_CONST_CACHE_GS_6:
885 case SQ_ALU_CONST_CACHE_GS_7:
886 case SQ_ALU_CONST_CACHE_GS_8:
887 case SQ_ALU_CONST_CACHE_GS_9:
888 case SQ_ALU_CONST_CACHE_GS_10:
889 case SQ_ALU_CONST_CACHE_GS_11:
890 case SQ_ALU_CONST_CACHE_GS_12:
891 case SQ_ALU_CONST_CACHE_GS_13:
892 case SQ_ALU_CONST_CACHE_GS_14:
893 case SQ_ALU_CONST_CACHE_GS_15:
894 case SQ_ALU_CONST_CACHE_PS_0:
895 case SQ_ALU_CONST_CACHE_PS_1:
896 case SQ_ALU_CONST_CACHE_PS_2:
897 case SQ_ALU_CONST_CACHE_PS_3:
898 case SQ_ALU_CONST_CACHE_PS_4:
899 case SQ_ALU_CONST_CACHE_PS_5:
900 case SQ_ALU_CONST_CACHE_PS_6:
901 case SQ_ALU_CONST_CACHE_PS_7:
902 case SQ_ALU_CONST_CACHE_PS_8:
903 case SQ_ALU_CONST_CACHE_PS_9:
904 case SQ_ALU_CONST_CACHE_PS_10:
905 case SQ_ALU_CONST_CACHE_PS_11:
906 case SQ_ALU_CONST_CACHE_PS_12:
907 case SQ_ALU_CONST_CACHE_PS_13:
908 case SQ_ALU_CONST_CACHE_PS_14:
909 case SQ_ALU_CONST_CACHE_PS_15:
910 case SQ_ALU_CONST_CACHE_VS_0:
911 case SQ_ALU_CONST_CACHE_VS_1:
912 case SQ_ALU_CONST_CACHE_VS_2:
913 case SQ_ALU_CONST_CACHE_VS_3:
914 case SQ_ALU_CONST_CACHE_VS_4:
915 case SQ_ALU_CONST_CACHE_VS_5:
916 case SQ_ALU_CONST_CACHE_VS_6:
917 case SQ_ALU_CONST_CACHE_VS_7:
918 case SQ_ALU_CONST_CACHE_VS_8:
919 case SQ_ALU_CONST_CACHE_VS_9:
920 case SQ_ALU_CONST_CACHE_VS_10:
921 case SQ_ALU_CONST_CACHE_VS_11:
922 case SQ_ALU_CONST_CACHE_VS_12:
923 case SQ_ALU_CONST_CACHE_VS_13:
924 case SQ_ALU_CONST_CACHE_VS_14:
925 case SQ_ALU_CONST_CACHE_VS_15:
926 r = r600_cs_packet_next_reloc(p, &reloc);
927 if (r) {
928 dev_warn(p->dev, "bad SET_CONTEXT_REG "
929 "0x%04X\n", reg);
930 return -EINVAL;
931 }
932 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
933 break;
934 default:
935 dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
936 return -EINVAL;
937 }
938 return 0;
939}
940
941static inline unsigned minify(unsigned size, unsigned levels)
942{
943 size = size >> levels;
944 if (size < 1)
945 size = 1;
946 return size;
947}
948
949static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels,
950 unsigned w0, unsigned h0, unsigned d0, unsigned bpe,
951 unsigned *l0_size, unsigned *mipmap_size)
952{
953 unsigned offset, i, level, face;
954 unsigned width, height, depth, rowstride, size;
955
956 w0 = minify(w0, 0);
957 h0 = minify(h0, 0);
958 d0 = minify(d0, 0);
959 for(i = 0, offset = 0, level = blevel; i < nlevels; i++, level++) {
960 width = minify(w0, i);
961 height = minify(h0, i);
962 depth = minify(d0, i);
963 for(face = 0; face < nfaces; face++) {
964 rowstride = ((width * bpe) + 255) & ~255;
965 size = height * rowstride * depth;
966 offset += size;
967 offset = (offset + 0x1f) & ~0x1f;
968 }
969 }
970 *l0_size = (((w0 * bpe) + 255) & ~255) * h0 * d0;
971 *mipmap_size = offset;
972 if (!blevel)
973 *mipmap_size -= *l0_size;
974 if (!nlevels)
975 *mipmap_size = *l0_size;
976}
977
978/**
979 * r600_check_texture_resource() - check if register is authorized or not
980 * @p: parser structure holding parsing context
981 * @idx: index into the cs buffer
982 * @texture: texture's bo structure
983 * @mipmap: mipmap's bo structure
984 *
985 * This function will check that the resource has valid field and that
986 * the texture and mipmap bo object are big enough to cover this resource.
987 */
988static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
989 struct radeon_bo *texture,
990 struct radeon_bo *mipmap)
991{
992 u32 nfaces, nlevels, blevel, w0, h0, d0, bpe = 0;
993 u32 word0, word1, l0_size, mipmap_size;
994
995 /* on legacy kernel we don't perform advanced check */
996 if (p->rdev == NULL)
997 return 0;
998 word0 = radeon_get_ib_value(p, idx + 0);
999 word1 = radeon_get_ib_value(p, idx + 1);
1000 w0 = G_038000_TEX_WIDTH(word0) + 1;
1001 h0 = G_038004_TEX_HEIGHT(word1) + 1;
1002 d0 = G_038004_TEX_DEPTH(word1);
1003 nfaces = 1;
1004 switch (G_038000_DIM(word0)) {
1005 case V_038000_SQ_TEX_DIM_1D:
1006 case V_038000_SQ_TEX_DIM_2D:
1007 case V_038000_SQ_TEX_DIM_3D:
1008 break;
1009 case V_038000_SQ_TEX_DIM_CUBEMAP:
1010 nfaces = 6;
1011 break;
1012 case V_038000_SQ_TEX_DIM_1D_ARRAY:
1013 case V_038000_SQ_TEX_DIM_2D_ARRAY:
1014 case V_038000_SQ_TEX_DIM_2D_MSAA:
1015 case V_038000_SQ_TEX_DIM_2D_ARRAY_MSAA:
1016 default:
1017 dev_warn(p->dev, "this kernel doesn't support %d texture dim\n", G_038000_DIM(word0));
1018 return -EINVAL;
1019 }
1020 if (r600_bpe_from_format(&bpe, G_038004_DATA_FORMAT(word1))) {
1021 dev_warn(p->dev, "%s:%d texture invalid format %d\n",
1022 __func__, __LINE__, G_038004_DATA_FORMAT(word1));
1023 return -EINVAL;
1024 }
1025 word0 = radeon_get_ib_value(p, idx + 4);
1026 word1 = radeon_get_ib_value(p, idx + 5);
1027 blevel = G_038010_BASE_LEVEL(word0);
1028 nlevels = G_038014_LAST_LEVEL(word1);
1029 r600_texture_size(nfaces, blevel, nlevels, w0, h0, d0, bpe, &l0_size, &mipmap_size);
1030 /* using get ib will give us the offset into the texture bo */
1031 word0 = radeon_get_ib_value(p, idx + 2);
1032 if ((l0_size + word0) > radeon_bo_size(texture)) {
1033 dev_warn(p->dev, "texture bo too small (%d %d %d %d -> %d have %ld)\n",
1034 w0, h0, bpe, word0, l0_size, radeon_bo_size(texture));
1035 return -EINVAL;
1036 }
1037 /* using get ib will give us the offset into the mipmap bo */
1038 word0 = radeon_get_ib_value(p, idx + 3);
1039 if ((mipmap_size + word0) > radeon_bo_size(mipmap)) {
1040 dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n",
1041 w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture));
1042 return -EINVAL;
1043 }
1044 return 0;
1045}
1046
336static int r600_packet3_check(struct radeon_cs_parser *p, 1047static int r600_packet3_check(struct radeon_cs_parser *p,
337 struct radeon_cs_packet *pkt) 1048 struct radeon_cs_packet *pkt)
338{ 1049{
339 struct radeon_cs_reloc *reloc; 1050 struct radeon_cs_reloc *reloc;
1051 struct r600_cs_track *track;
340 volatile u32 *ib; 1052 volatile u32 *ib;
341 unsigned idx; 1053 unsigned idx;
342 unsigned i; 1054 unsigned i;
@@ -344,6 +1056,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
344 int r; 1056 int r;
345 u32 idx_value; 1057 u32 idx_value;
346 1058
1059 track = (struct r600_cs_track *)p->track;
347 ib = p->ib->ptr; 1060 ib = p->ib->ptr;
348 idx = pkt->idx + 1; 1061 idx = pkt->idx + 1;
349 idx_value = radeon_get_ib_value(p, idx); 1062 idx_value = radeon_get_ib_value(p, idx);
@@ -380,12 +1093,22 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
380 } 1093 }
381 ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff); 1094 ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
382 ib[idx+1] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff; 1095 ib[idx+1] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
1096 r = r600_cs_track_check(p);
1097 if (r) {
1098 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
1099 return r;
1100 }
383 break; 1101 break;
384 case PACKET3_DRAW_INDEX_AUTO: 1102 case PACKET3_DRAW_INDEX_AUTO:
385 if (pkt->count != 1) { 1103 if (pkt->count != 1) {
386 DRM_ERROR("bad DRAW_INDEX_AUTO\n"); 1104 DRM_ERROR("bad DRAW_INDEX_AUTO\n");
387 return -EINVAL; 1105 return -EINVAL;
388 } 1106 }
1107 r = r600_cs_track_check(p);
1108 if (r) {
1109 dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
1110 return r;
1111 }
389 break; 1112 break;
390 case PACKET3_DRAW_INDEX_IMMD_BE: 1113 case PACKET3_DRAW_INDEX_IMMD_BE:
391 case PACKET3_DRAW_INDEX_IMMD: 1114 case PACKET3_DRAW_INDEX_IMMD:
@@ -393,6 +1116,11 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
393 DRM_ERROR("bad DRAW_INDEX_IMMD\n"); 1116 DRM_ERROR("bad DRAW_INDEX_IMMD\n");
394 return -EINVAL; 1117 return -EINVAL;
395 } 1118 }
1119 r = r600_cs_track_check(p);
1120 if (r) {
1121 dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
1122 return r;
1123 }
396 break; 1124 break;
397 case PACKET3_WAIT_REG_MEM: 1125 case PACKET3_WAIT_REG_MEM:
398 if (pkt->count != 5) { 1126 if (pkt->count != 5) {
@@ -465,30 +1193,9 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
465 } 1193 }
466 for (i = 0; i < pkt->count; i++) { 1194 for (i = 0; i < pkt->count; i++) {
467 reg = start_reg + (4 * i); 1195 reg = start_reg + (4 * i);
468 switch (reg) { 1196 r = r600_cs_check_reg(p, reg, idx+1+i);
469 case SQ_ESGS_RING_BASE: 1197 if (r)
470 case SQ_GSVS_RING_BASE: 1198 return r;
471 case SQ_ESTMP_RING_BASE:
472 case SQ_GSTMP_RING_BASE:
473 case SQ_VSTMP_RING_BASE:
474 case SQ_PSTMP_RING_BASE:
475 case SQ_FBUF_RING_BASE:
476 case SQ_REDUC_RING_BASE:
477 case SX_MEMORY_EXPORT_BASE:
478 r = r600_cs_packet_next_reloc(p, &reloc);
479 if (r) {
480 DRM_ERROR("bad SET_CONFIG_REG "
481 "0x%04X\n", reg);
482 return -EINVAL;
483 }
484 ib[idx+1+i] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
485 break;
486 case CP_COHER_BASE:
487 /* use PACKET3_SURFACE_SYNC */
488 return -EINVAL;
489 default:
490 break;
491 }
492 } 1199 }
493 break; 1200 break;
494 case PACKET3_SET_CONTEXT_REG: 1201 case PACKET3_SET_CONTEXT_REG:
@@ -502,55 +1209,9 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
502 } 1209 }
503 for (i = 0; i < pkt->count; i++) { 1210 for (i = 0; i < pkt->count; i++) {
504 reg = start_reg + (4 * i); 1211 reg = start_reg + (4 * i);
505 switch (reg) { 1212 r = r600_cs_check_reg(p, reg, idx+1+i);
506 case DB_DEPTH_BASE: 1213 if (r)
507 case DB_HTILE_DATA_BASE: 1214 return r;
508 case CB_COLOR0_BASE:
509 case CB_COLOR1_BASE:
510 case CB_COLOR2_BASE:
511 case CB_COLOR3_BASE:
512 case CB_COLOR4_BASE:
513 case CB_COLOR5_BASE:
514 case CB_COLOR6_BASE:
515 case CB_COLOR7_BASE:
516 case SQ_PGM_START_FS:
517 case SQ_PGM_START_ES:
518 case SQ_PGM_START_VS:
519 case SQ_PGM_START_GS:
520 case SQ_PGM_START_PS:
521 r = r600_cs_packet_next_reloc(p, &reloc);
522 if (r) {
523 DRM_ERROR("bad SET_CONTEXT_REG "
524 "0x%04X\n", reg);
525 return -EINVAL;
526 }
527 ib[idx+1+i] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
528 break;
529 case VGT_DMA_BASE:
530 case VGT_DMA_BASE_HI:
531 /* These should be handled by DRAW_INDEX packet 3 */
532 case VGT_STRMOUT_BASE_OFFSET_0:
533 case VGT_STRMOUT_BASE_OFFSET_1:
534 case VGT_STRMOUT_BASE_OFFSET_2:
535 case VGT_STRMOUT_BASE_OFFSET_3:
536 case VGT_STRMOUT_BASE_OFFSET_HI_0:
537 case VGT_STRMOUT_BASE_OFFSET_HI_1:
538 case VGT_STRMOUT_BASE_OFFSET_HI_2:
539 case VGT_STRMOUT_BASE_OFFSET_HI_3:
540 case VGT_STRMOUT_BUFFER_BASE_0:
541 case VGT_STRMOUT_BUFFER_BASE_1:
542 case VGT_STRMOUT_BUFFER_BASE_2:
543 case VGT_STRMOUT_BUFFER_BASE_3:
544 case VGT_STRMOUT_BUFFER_OFFSET_0:
545 case VGT_STRMOUT_BUFFER_OFFSET_1:
546 case VGT_STRMOUT_BUFFER_OFFSET_2:
547 case VGT_STRMOUT_BUFFER_OFFSET_3:
548 /* These should be handled by STRMOUT_BUFFER packet 3 */
549 DRM_ERROR("bad context reg: 0x%08x\n", reg);
550 return -EINVAL;
551 default:
552 break;
553 }
554 } 1215 }
555 break; 1216 break;
556 case PACKET3_SET_RESOURCE: 1217 case PACKET3_SET_RESOURCE:
@@ -567,6 +1228,9 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
567 return -EINVAL; 1228 return -EINVAL;
568 } 1229 }
569 for (i = 0; i < (pkt->count / 7); i++) { 1230 for (i = 0; i < (pkt->count / 7); i++) {
1231 struct radeon_bo *texture, *mipmap;
1232 u32 size, offset;
1233
570 switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) { 1234 switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) {
571 case SQ_TEX_VTX_VALID_TEXTURE: 1235 case SQ_TEX_VTX_VALID_TEXTURE:
572 /* tex base */ 1236 /* tex base */
@@ -576,6 +1240,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
576 return -EINVAL; 1240 return -EINVAL;
577 } 1241 }
578 ib[idx+1+(i*7)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1242 ib[idx+1+(i*7)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1243 texture = reloc->robj;
579 /* tex mip base */ 1244 /* tex mip base */
580 r = r600_cs_packet_next_reloc(p, &reloc); 1245 r = r600_cs_packet_next_reloc(p, &reloc);
581 if (r) { 1246 if (r) {
@@ -583,6 +1248,11 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
583 return -EINVAL; 1248 return -EINVAL;
584 } 1249 }
585 ib[idx+1+(i*7)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1250 ib[idx+1+(i*7)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1251 mipmap = reloc->robj;
1252 r = r600_check_texture_resource(p, idx+(i*7)+1,
1253 texture, mipmap);
1254 if (r)
1255 return r;
586 break; 1256 break;
587 case SQ_TEX_VTX_VALID_BUFFER: 1257 case SQ_TEX_VTX_VALID_BUFFER:
588 /* vtx base */ 1258 /* vtx base */
@@ -591,6 +1261,13 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
591 DRM_ERROR("bad SET_RESOURCE\n"); 1261 DRM_ERROR("bad SET_RESOURCE\n");
592 return -EINVAL; 1262 return -EINVAL;
593 } 1263 }
1264 offset = radeon_get_ib_value(p, idx+1+(i*7)+0);
1265 size = radeon_get_ib_value(p, idx+1+(i*7)+1);
1266 if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
1267 /* force size to size of the buffer */
1268 dev_warn(p->dev, "vbo resource seems too big for the bo\n");
1269 ib[idx+1+(i*7)+1] = radeon_bo_size(reloc->robj);
1270 }
594 ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff); 1271 ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);
595 ib[idx+1+(i*7)+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff; 1272 ib[idx+1+(i*7)+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
596 break; 1273 break;
@@ -603,13 +1280,15 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
603 } 1280 }
604 break; 1281 break;
605 case PACKET3_SET_ALU_CONST: 1282 case PACKET3_SET_ALU_CONST:
606 start_reg = (idx_value << 2) + PACKET3_SET_ALU_CONST_OFFSET; 1283 if (track->sq_config & DX9_CONSTS) {
607 end_reg = 4 * pkt->count + start_reg - 4; 1284 start_reg = (idx_value << 2) + PACKET3_SET_ALU_CONST_OFFSET;
608 if ((start_reg < PACKET3_SET_ALU_CONST_OFFSET) || 1285 end_reg = 4 * pkt->count + start_reg - 4;
609 (start_reg >= PACKET3_SET_ALU_CONST_END) || 1286 if ((start_reg < PACKET3_SET_ALU_CONST_OFFSET) ||
610 (end_reg >= PACKET3_SET_ALU_CONST_END)) { 1287 (start_reg >= PACKET3_SET_ALU_CONST_END) ||
611 DRM_ERROR("bad SET_ALU_CONST\n"); 1288 (end_reg >= PACKET3_SET_ALU_CONST_END)) {
612 return -EINVAL; 1289 DRM_ERROR("bad SET_ALU_CONST\n");
1290 return -EINVAL;
1291 }
613 } 1292 }
614 break; 1293 break;
615 case PACKET3_SET_BOOL_CONST: 1294 case PACKET3_SET_BOOL_CONST:
@@ -678,11 +1357,31 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
678int r600_cs_parse(struct radeon_cs_parser *p) 1357int r600_cs_parse(struct radeon_cs_parser *p)
679{ 1358{
680 struct radeon_cs_packet pkt; 1359 struct radeon_cs_packet pkt;
1360 struct r600_cs_track *track;
681 int r; 1361 int r;
682 1362
1363 if (p->track == NULL) {
1364 /* initialize tracker, we are in kms */
1365 track = kzalloc(sizeof(*track), GFP_KERNEL);
1366 if (track == NULL)
1367 return -ENOMEM;
1368 r600_cs_track_init(track);
1369 if (p->rdev->family < CHIP_RV770) {
1370 track->npipes = p->rdev->config.r600.tiling_npipes;
1371 track->nbanks = p->rdev->config.r600.tiling_nbanks;
1372 track->group_size = p->rdev->config.r600.tiling_group_size;
1373 } else if (p->rdev->family <= CHIP_RV740) {
1374 track->npipes = p->rdev->config.rv770.tiling_npipes;
1375 track->nbanks = p->rdev->config.rv770.tiling_nbanks;
1376 track->group_size = p->rdev->config.rv770.tiling_group_size;
1377 }
1378 p->track = track;
1379 }
683 do { 1380 do {
684 r = r600_cs_packet_parse(p, &pkt, p->idx); 1381 r = r600_cs_packet_parse(p, &pkt, p->idx);
685 if (r) { 1382 if (r) {
1383 kfree(p->track);
1384 p->track = NULL;
686 return r; 1385 return r;
687 } 1386 }
688 p->idx += pkt.count + 2; 1387 p->idx += pkt.count + 2;
@@ -697,9 +1396,13 @@ int r600_cs_parse(struct radeon_cs_parser *p)
697 break; 1396 break;
698 default: 1397 default:
699 DRM_ERROR("Unknown packet type %d !\n", pkt.type); 1398 DRM_ERROR("Unknown packet type %d !\n", pkt.type);
1399 kfree(p->track);
1400 p->track = NULL;
700 return -EINVAL; 1401 return -EINVAL;
701 } 1402 }
702 if (r) { 1403 if (r) {
1404 kfree(p->track);
1405 p->track = NULL;
703 return r; 1406 return r;
704 } 1407 }
705 } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw); 1408 } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
@@ -709,6 +1412,8 @@ int r600_cs_parse(struct radeon_cs_parser *p)
709 mdelay(1); 1412 mdelay(1);
710 } 1413 }
711#endif 1414#endif
1415 kfree(p->track);
1416 p->track = NULL;
712 return 0; 1417 return 0;
713} 1418}
714 1419
@@ -717,7 +1422,7 @@ static int r600_cs_parser_relocs_legacy(struct radeon_cs_parser *p)
717 if (p->chunk_relocs_idx == -1) { 1422 if (p->chunk_relocs_idx == -1) {
718 return 0; 1423 return 0;
719 } 1424 }
720 p->relocs = kcalloc(1, sizeof(struct radeon_cs_reloc), GFP_KERNEL); 1425 p->relocs = kzalloc(sizeof(struct radeon_cs_reloc), GFP_KERNEL);
721 if (p->relocs == NULL) { 1426 if (p->relocs == NULL) {
722 return -ENOMEM; 1427 return -ENOMEM;
723 } 1428 }
@@ -751,15 +1456,24 @@ int r600_cs_legacy(struct drm_device *dev, void *data, struct drm_file *filp,
751{ 1456{
752 struct radeon_cs_parser parser; 1457 struct radeon_cs_parser parser;
753 struct radeon_cs_chunk *ib_chunk; 1458 struct radeon_cs_chunk *ib_chunk;
754 struct radeon_ib fake_ib; 1459 struct radeon_ib fake_ib;
1460 struct r600_cs_track *track;
755 int r; 1461 int r;
756 1462
1463 /* initialize tracker */
1464 track = kzalloc(sizeof(*track), GFP_KERNEL);
1465 if (track == NULL)
1466 return -ENOMEM;
1467 r600_cs_track_init(track);
1468 r600_cs_legacy_get_tiling_conf(dev, &track->npipes, &track->nbanks, &track->group_size);
757 /* initialize parser */ 1469 /* initialize parser */
758 memset(&parser, 0, sizeof(struct radeon_cs_parser)); 1470 memset(&parser, 0, sizeof(struct radeon_cs_parser));
759 parser.filp = filp; 1471 parser.filp = filp;
1472 parser.dev = &dev->pdev->dev;
760 parser.rdev = NULL; 1473 parser.rdev = NULL;
761 parser.family = family; 1474 parser.family = family;
762 parser.ib = &fake_ib; 1475 parser.ib = &fake_ib;
1476 parser.track = track;
763 fake_ib.ptr = ib; 1477 fake_ib.ptr = ib;
764 r = radeon_cs_parser_init(&parser, data); 1478 r = radeon_cs_parser_init(&parser, data);
765 if (r) { 1479 if (r) {