2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
28 #include <linux/kernel.h>
32 #include "r600_reg_safe.h"
34 static int r600_cs_packet_next_reloc_mm(struct radeon_cs_parser
*p
,
35 struct radeon_cs_reloc
**cs_reloc
);
36 static int r600_cs_packet_next_reloc_nomm(struct radeon_cs_parser
*p
,
37 struct radeon_cs_reloc
**cs_reloc
);
38 typedef int (*next_reloc_t
)(struct radeon_cs_parser
*, struct radeon_cs_reloc
**);
39 static next_reloc_t r600_cs_packet_next_reloc
= &r600_cs_packet_next_reloc_mm
;
40 extern void r600_cs_legacy_get_tiling_conf(struct drm_device
*dev
, u32
*npipes
, u32
*nbanks
, u32
*group_size
);
43 struct r600_cs_track
{
44 /* configuration we miror so that we use same code btw kms/ums */
51 u32 cb_color_base_last
[8];
52 struct radeon_bo
*cb_color_bo
[8];
53 u64 cb_color_bo_mc
[8];
54 u32 cb_color_bo_offset
[8];
55 struct radeon_bo
*cb_color_frag_bo
[8];
56 struct radeon_bo
*cb_color_tile_bo
[8];
58 u32 cb_color_size_idx
[8];
63 u32 vgt_strmout_buffer_en
;
66 u32 db_depth_size_idx
;
70 struct radeon_bo
*db_bo
;
74 #define FMT_8_BIT(fmt, vc) [fmt] = { 1, 1, 1, vc, CHIP_R600 }
75 #define FMT_16_BIT(fmt, vc) [fmt] = { 1, 1, 2, vc, CHIP_R600 }
76 #define FMT_24_BIT(fmt) [fmt] = { 1, 1, 3, 0, CHIP_R600 }
77 #define FMT_32_BIT(fmt, vc) [fmt] = { 1, 1, 4, vc, CHIP_R600 }
78 #define FMT_48_BIT(fmt) [fmt] = { 1, 1, 6, 0, CHIP_R600 }
79 #define FMT_64_BIT(fmt, vc) [fmt] = { 1, 1, 8, vc, CHIP_R600 }
80 #define FMT_96_BIT(fmt) [fmt] = { 1, 1, 12, 0, CHIP_R600 }
81 #define FMT_128_BIT(fmt, vc) [fmt] = { 1, 1, 16,vc, CHIP_R600 }
88 enum radeon_family min_family
;
91 static const struct gpu_formats color_formats_table
[] = {
93 FMT_8_BIT(V_038004_COLOR_8
, 1),
94 FMT_8_BIT(V_038004_COLOR_4_4
, 1),
95 FMT_8_BIT(V_038004_COLOR_3_3_2
, 1),
96 FMT_8_BIT(V_038004_FMT_1
, 0),
99 FMT_16_BIT(V_038004_COLOR_16
, 1),
100 FMT_16_BIT(V_038004_COLOR_16_FLOAT
, 1),
101 FMT_16_BIT(V_038004_COLOR_8_8
, 1),
102 FMT_16_BIT(V_038004_COLOR_5_6_5
, 1),
103 FMT_16_BIT(V_038004_COLOR_6_5_5
, 1),
104 FMT_16_BIT(V_038004_COLOR_1_5_5_5
, 1),
105 FMT_16_BIT(V_038004_COLOR_4_4_4_4
, 1),
106 FMT_16_BIT(V_038004_COLOR_5_5_5_1
, 1),
109 FMT_24_BIT(V_038004_FMT_8_8_8
),
112 FMT_32_BIT(V_038004_COLOR_32
, 1),
113 FMT_32_BIT(V_038004_COLOR_32_FLOAT
, 1),
114 FMT_32_BIT(V_038004_COLOR_16_16
, 1),
115 FMT_32_BIT(V_038004_COLOR_16_16_FLOAT
, 1),
116 FMT_32_BIT(V_038004_COLOR_8_24
, 1),
117 FMT_32_BIT(V_038004_COLOR_8_24_FLOAT
, 1),
118 FMT_32_BIT(V_038004_COLOR_24_8
, 1),
119 FMT_32_BIT(V_038004_COLOR_24_8_FLOAT
, 1),
120 FMT_32_BIT(V_038004_COLOR_10_11_11
, 1),
121 FMT_32_BIT(V_038004_COLOR_10_11_11_FLOAT
, 1),
122 FMT_32_BIT(V_038004_COLOR_11_11_10
, 1),
123 FMT_32_BIT(V_038004_COLOR_11_11_10_FLOAT
, 1),
124 FMT_32_BIT(V_038004_COLOR_2_10_10_10
, 1),
125 FMT_32_BIT(V_038004_COLOR_8_8_8_8
, 1),
126 FMT_32_BIT(V_038004_COLOR_10_10_10_2
, 1),
127 FMT_32_BIT(V_038004_FMT_5_9_9_9_SHAREDEXP
, 0),
128 FMT_32_BIT(V_038004_FMT_32_AS_8
, 0),
129 FMT_32_BIT(V_038004_FMT_32_AS_8_8
, 0),
132 FMT_48_BIT(V_038004_FMT_16_16_16
),
133 FMT_48_BIT(V_038004_FMT_16_16_16_FLOAT
),
136 FMT_64_BIT(V_038004_COLOR_X24_8_32_FLOAT
, 1),
137 FMT_64_BIT(V_038004_COLOR_32_32
, 1),
138 FMT_64_BIT(V_038004_COLOR_32_32_FLOAT
, 1),
139 FMT_64_BIT(V_038004_COLOR_16_16_16_16
, 1),
140 FMT_64_BIT(V_038004_COLOR_16_16_16_16_FLOAT
, 1),
142 FMT_96_BIT(V_038004_FMT_32_32_32
),
143 FMT_96_BIT(V_038004_FMT_32_32_32_FLOAT
),
146 FMT_128_BIT(V_038004_COLOR_32_32_32_32
, 1),
147 FMT_128_BIT(V_038004_COLOR_32_32_32_32_FLOAT
, 1),
149 [V_038004_FMT_GB_GR
] = { 2, 1, 4, 0 },
150 [V_038004_FMT_BG_RG
] = { 2, 1, 4, 0 },
152 /* block compressed formats */
153 [V_038004_FMT_BC1
] = { 4, 4, 8, 0 },
154 [V_038004_FMT_BC2
] = { 4, 4, 16, 0 },
155 [V_038004_FMT_BC3
] = { 4, 4, 16, 0 },
156 [V_038004_FMT_BC4
] = { 4, 4, 8, 0 },
157 [V_038004_FMT_BC5
] = { 4, 4, 16, 0},
158 [V_038004_FMT_BC6
] = { 4, 4, 16, 0, CHIP_CEDAR
}, /* Evergreen-only */
159 [V_038004_FMT_BC7
] = { 4, 4, 16, 0, CHIP_CEDAR
}, /* Evergreen-only */
161 /* The other Evergreen formats */
162 [V_038004_FMT_32_AS_32_32_32_32
] = { 1, 1, 4, 0, CHIP_CEDAR
},
165 static inline bool fmt_is_valid_color(u32 format
)
167 if (format
>= ARRAY_SIZE(color_formats_table
))
170 if (color_formats_table
[format
].valid_color
)
176 static inline bool fmt_is_valid_texture(u32 format
, enum radeon_family family
)
178 if (format
>= ARRAY_SIZE(color_formats_table
))
181 if (family
< color_formats_table
[format
].min_family
)
184 if (color_formats_table
[format
].blockwidth
> 0)
190 static inline int fmt_get_blocksize(u32 format
)
192 if (format
>= ARRAY_SIZE(color_formats_table
))
195 return color_formats_table
[format
].blocksize
;
198 static inline int fmt_get_nblocksx(u32 format
, u32 w
)
202 if (format
>= ARRAY_SIZE(color_formats_table
))
205 bw
= color_formats_table
[format
].blockwidth
;
209 return (w
+ bw
- 1) / bw
;
212 static inline int fmt_get_nblocksy(u32 format
, u32 h
)
216 if (format
>= ARRAY_SIZE(color_formats_table
))
219 bh
= color_formats_table
[format
].blockheight
;
223 return (h
+ bh
- 1) / bh
;
226 static inline int r600_bpe_from_format(u32
*bpe
, u32 format
)
230 if (format
>= ARRAY_SIZE(color_formats_table
))
233 res
= color_formats_table
[format
].blocksize
;
245 struct array_mode_checker
{
254 /* returns alignment in pixels for pitch/height/depth and bytes for base */
255 static inline int r600_get_array_mode_alignment(struct array_mode_checker
*values
,
263 u32 macro_tile_width
= values
->nbanks
;
264 u32 macro_tile_height
= values
->npipes
;
265 u32 tile_bytes
= tile_width
* tile_height
* values
->blocksize
* values
->nsamples
;
266 u32 macro_tile_bytes
= macro_tile_width
* macro_tile_height
* tile_bytes
;
268 switch (values
->array_mode
) {
269 case ARRAY_LINEAR_GENERAL
:
270 /* technically tile_width/_height for pitch/height */
271 *pitch_align
= 1; /* tile_width */
272 *height_align
= 1; /* tile_height */
276 case ARRAY_LINEAR_ALIGNED
:
277 *pitch_align
= max((u32
)64, (u32
)(values
->group_size
/ values
->blocksize
));
278 *height_align
= tile_height
;
280 *base_align
= values
->group_size
;
282 case ARRAY_1D_TILED_THIN1
:
283 *pitch_align
= max((u32
)tile_width
,
284 (u32
)(values
->group_size
/
285 (tile_height
* values
->blocksize
* values
->nsamples
)));
286 *height_align
= tile_height
;
288 *base_align
= values
->group_size
;
290 case ARRAY_2D_TILED_THIN1
:
291 *pitch_align
= max((u32
)macro_tile_width
,
292 (u32
)(((values
->group_size
/ tile_height
) /
293 (values
->blocksize
* values
->nsamples
)) *
294 values
->nbanks
)) * tile_width
;
295 *height_align
= macro_tile_height
* tile_height
;
297 *base_align
= max(macro_tile_bytes
,
298 (*pitch_align
) * values
->blocksize
* (*height_align
) * values
->nsamples
);
307 static void r600_cs_track_init(struct r600_cs_track
*track
)
311 /* assume DX9 mode */
312 track
->sq_config
= DX9_CONSTS
;
313 for (i
= 0; i
< 8; i
++) {
314 track
->cb_color_base_last
[i
] = 0;
315 track
->cb_color_size
[i
] = 0;
316 track
->cb_color_size_idx
[i
] = 0;
317 track
->cb_color_info
[i
] = 0;
318 track
->cb_color_bo
[i
] = NULL
;
319 track
->cb_color_bo_offset
[i
] = 0xFFFFFFFF;
320 track
->cb_color_bo_mc
[i
] = 0xFFFFFFFF;
322 track
->cb_target_mask
= 0xFFFFFFFF;
323 track
->cb_shader_mask
= 0xFFFFFFFF;
325 track
->db_bo_mc
= 0xFFFFFFFF;
326 /* assume the biggest format and that htile is enabled */
327 track
->db_depth_info
= 7 | (1 << 25);
328 track
->db_depth_view
= 0xFFFFC000;
329 track
->db_depth_size
= 0xFFFFFFFF;
330 track
->db_depth_size_idx
= 0;
331 track
->db_depth_control
= 0xFFFFFFFF;
334 static inline int r600_cs_track_validate_cb(struct radeon_cs_parser
*p
, int i
)
336 struct r600_cs_track
*track
= p
->track
;
337 u32 slice_tile_max
, size
, tmp
;
338 u32 height
, height_align
, pitch
, pitch_align
, depth_align
;
339 u64 base_offset
, base_align
;
340 struct array_mode_checker array_check
;
341 volatile u32
*ib
= p
->ib
->ptr
;
344 if (G_0280A0_TILE_MODE(track
->cb_color_info
[i
])) {
345 dev_warn(p
->dev
, "FMASK or CMASK buffer are not supported by this kernel\n");
348 size
= radeon_bo_size(track
->cb_color_bo
[i
]) - track
->cb_color_bo_offset
[i
];
349 format
= G_0280A0_FORMAT(track
->cb_color_info
[i
]);
350 if (!fmt_is_valid_color(format
)) {
351 dev_warn(p
->dev
, "%s:%d cb invalid format %d for %d (0x%08X)\n",
352 __func__
, __LINE__
, format
,
353 i
, track
->cb_color_info
[i
]);
356 /* pitch in pixels */
357 pitch
= (G_028060_PITCH_TILE_MAX(track
->cb_color_size
[i
]) + 1) * 8;
358 slice_tile_max
= G_028060_SLICE_TILE_MAX(track
->cb_color_size
[i
]) + 1;
359 slice_tile_max
*= 64;
360 height
= slice_tile_max
/ pitch
;
363 array_mode
= G_0280A0_ARRAY_MODE(track
->cb_color_info
[i
]);
365 base_offset
= track
->cb_color_bo_mc
[i
] + track
->cb_color_bo_offset
[i
];
366 array_check
.array_mode
= array_mode
;
367 array_check
.group_size
= track
->group_size
;
368 array_check
.nbanks
= track
->nbanks
;
369 array_check
.npipes
= track
->npipes
;
370 array_check
.nsamples
= track
->nsamples
;
371 array_check
.blocksize
= fmt_get_blocksize(format
);
372 if (r600_get_array_mode_alignment(&array_check
,
373 &pitch_align
, &height_align
, &depth_align
, &base_align
)) {
374 dev_warn(p
->dev
, "%s invalid tiling %d for %d (0x%08X)\n", __func__
,
375 G_0280A0_ARRAY_MODE(track
->cb_color_info
[i
]), i
,
376 track
->cb_color_info
[i
]);
379 switch (array_mode
) {
380 case V_0280A0_ARRAY_LINEAR_GENERAL
:
382 case V_0280A0_ARRAY_LINEAR_ALIGNED
:
384 case V_0280A0_ARRAY_1D_TILED_THIN1
:
385 /* avoid breaking userspace */
389 case V_0280A0_ARRAY_2D_TILED_THIN1
:
392 dev_warn(p
->dev
, "%s invalid tiling %d for %d (0x%08X)\n", __func__
,
393 G_0280A0_ARRAY_MODE(track
->cb_color_info
[i
]), i
,
394 track
->cb_color_info
[i
]);
398 if (!IS_ALIGNED(pitch
, pitch_align
)) {
399 dev_warn(p
->dev
, "%s:%d cb pitch (%d, 0x%x, %d) invalid\n",
400 __func__
, __LINE__
, pitch
, pitch_align
, array_mode
);
403 if (!IS_ALIGNED(height
, height_align
)) {
404 dev_warn(p
->dev
, "%s:%d cb height (%d, 0x%x, %d) invalid\n",
405 __func__
, __LINE__
, height
, height_align
, array_mode
);
408 if (!IS_ALIGNED(base_offset
, base_align
)) {
409 dev_warn(p
->dev
, "%s offset[%d] 0x%llx 0x%llx, %d not aligned\n", __func__
, i
,
410 base_offset
, base_align
, array_mode
);
415 tmp
= fmt_get_nblocksy(format
, height
) * fmt_get_nblocksx(format
, pitch
) * fmt_get_blocksize(format
);
416 if ((tmp
+ track
->cb_color_bo_offset
[i
]) > radeon_bo_size(track
->cb_color_bo
[i
])) {
417 if (array_mode
== V_0280A0_ARRAY_LINEAR_GENERAL
) {
418 /* the initial DDX does bad things with the CB size occasionally */
419 /* it rounds up height too far for slice tile max but the BO is smaller */
420 /* r600c,g also seem to flush at bad times in some apps resulting in
421 * bogus values here. So for linear just allow anything to avoid breaking
425 dev_warn(p
->dev
, "%s offset[%d] %d %d %d %lu too big\n", __func__
, i
,
427 track
->cb_color_bo_offset
[i
], tmp
,
428 radeon_bo_size(track
->cb_color_bo
[i
]));
433 tmp
= (height
* pitch
) >> 6;
434 if (tmp
< slice_tile_max
)
435 slice_tile_max
= tmp
;
436 tmp
= S_028060_PITCH_TILE_MAX((pitch
/ 8) - 1) |
437 S_028060_SLICE_TILE_MAX(slice_tile_max
- 1);
438 ib
[track
->cb_color_size_idx
[i
]] = tmp
;
442 static int r600_cs_track_check(struct radeon_cs_parser
*p
)
444 struct r600_cs_track
*track
= p
->track
;
447 volatile u32
*ib
= p
->ib
->ptr
;
449 /* on legacy kernel we don't perform advanced check */
452 /* we don't support out buffer yet */
453 if (track
->vgt_strmout_en
|| track
->vgt_strmout_buffer_en
) {
454 dev_warn(p
->dev
, "this kernel doesn't support SMX output buffer\n");
457 /* check that we have a cb for each enabled target, we don't check
458 * shader_mask because it seems mesa isn't always setting it :(
460 tmp
= track
->cb_target_mask
;
461 for (i
= 0; i
< 8; i
++) {
462 if ((tmp
>> (i
* 4)) & 0xF) {
463 /* at least one component is enabled */
464 if (track
->cb_color_bo
[i
] == NULL
) {
465 dev_warn(p
->dev
, "%s:%d mask 0x%08X | 0x%08X no cb for %d\n",
466 __func__
, __LINE__
, track
->cb_target_mask
, track
->cb_shader_mask
, i
);
469 /* perform rewrite of CB_COLOR[0-7]_SIZE */
470 r
= r600_cs_track_validate_cb(p
, i
);
475 /* Check depth buffer */
476 if (G_028800_STENCIL_ENABLE(track
->db_depth_control
) ||
477 G_028800_Z_ENABLE(track
->db_depth_control
)) {
478 u32 nviews
, bpe
, ntiles
, size
, slice_tile_max
;
479 u32 height
, height_align
, pitch
, pitch_align
, depth_align
;
480 u64 base_offset
, base_align
;
481 struct array_mode_checker array_check
;
484 if (track
->db_bo
== NULL
) {
485 dev_warn(p
->dev
, "z/stencil with no depth buffer\n");
488 if (G_028010_TILE_SURFACE_ENABLE(track
->db_depth_info
)) {
489 dev_warn(p
->dev
, "this kernel doesn't support z/stencil htile\n");
492 switch (G_028010_FORMAT(track
->db_depth_info
)) {
493 case V_028010_DEPTH_16
:
496 case V_028010_DEPTH_X8_24
:
497 case V_028010_DEPTH_8_24
:
498 case V_028010_DEPTH_X8_24_FLOAT
:
499 case V_028010_DEPTH_8_24_FLOAT
:
500 case V_028010_DEPTH_32_FLOAT
:
503 case V_028010_DEPTH_X24_8_32_FLOAT
:
507 dev_warn(p
->dev
, "z/stencil with invalid format %d\n", G_028010_FORMAT(track
->db_depth_info
));
510 if ((track
->db_depth_size
& 0xFFFFFC00) == 0xFFFFFC00) {
511 if (!track
->db_depth_size_idx
) {
512 dev_warn(p
->dev
, "z/stencil buffer size not set\n");
515 tmp
= radeon_bo_size(track
->db_bo
) - track
->db_offset
;
516 tmp
= (tmp
/ bpe
) >> 6;
518 dev_warn(p
->dev
, "z/stencil buffer too small (0x%08X %d %d %ld)\n",
519 track
->db_depth_size
, bpe
, track
->db_offset
,
520 radeon_bo_size(track
->db_bo
));
523 ib
[track
->db_depth_size_idx
] = S_028000_SLICE_TILE_MAX(tmp
- 1) | (track
->db_depth_size
& 0x3FF);
525 size
= radeon_bo_size(track
->db_bo
);
526 /* pitch in pixels */
527 pitch
= (G_028000_PITCH_TILE_MAX(track
->db_depth_size
) + 1) * 8;
528 slice_tile_max
= G_028000_SLICE_TILE_MAX(track
->db_depth_size
) + 1;
529 slice_tile_max
*= 64;
530 height
= slice_tile_max
/ pitch
;
533 base_offset
= track
->db_bo_mc
+ track
->db_offset
;
534 array_mode
= G_028010_ARRAY_MODE(track
->db_depth_info
);
535 array_check
.array_mode
= array_mode
;
536 array_check
.group_size
= track
->group_size
;
537 array_check
.nbanks
= track
->nbanks
;
538 array_check
.npipes
= track
->npipes
;
539 array_check
.nsamples
= track
->nsamples
;
540 array_check
.blocksize
= bpe
;
541 if (r600_get_array_mode_alignment(&array_check
,
542 &pitch_align
, &height_align
, &depth_align
, &base_align
)) {
543 dev_warn(p
->dev
, "%s invalid tiling %d (0x%08X)\n", __func__
,
544 G_028010_ARRAY_MODE(track
->db_depth_info
),
545 track
->db_depth_info
);
548 switch (array_mode
) {
549 case V_028010_ARRAY_1D_TILED_THIN1
:
550 /* don't break userspace */
553 case V_028010_ARRAY_2D_TILED_THIN1
:
556 dev_warn(p
->dev
, "%s invalid tiling %d (0x%08X)\n", __func__
,
557 G_028010_ARRAY_MODE(track
->db_depth_info
),
558 track
->db_depth_info
);
562 if (!IS_ALIGNED(pitch
, pitch_align
)) {
563 dev_warn(p
->dev
, "%s:%d db pitch (%d, 0x%x, %d) invalid\n",
564 __func__
, __LINE__
, pitch
, pitch_align
, array_mode
);
567 if (!IS_ALIGNED(height
, height_align
)) {
568 dev_warn(p
->dev
, "%s:%d db height (%d, 0x%x, %d) invalid\n",
569 __func__
, __LINE__
, height
, height_align
, array_mode
);
572 if (!IS_ALIGNED(base_offset
, base_align
)) {
573 dev_warn(p
->dev
, "%s offset[%d] 0x%llx, 0x%llx, %d not aligned\n", __func__
, i
,
574 base_offset
, base_align
, array_mode
);
578 ntiles
= G_028000_SLICE_TILE_MAX(track
->db_depth_size
) + 1;
579 nviews
= G_028004_SLICE_MAX(track
->db_depth_view
) + 1;
580 tmp
= ntiles
* bpe
* 64 * nviews
;
581 if ((tmp
+ track
->db_offset
) > radeon_bo_size(track
->db_bo
)) {
582 dev_warn(p
->dev
, "z/stencil buffer (%d) too small (0x%08X %d %d %d -> %u have %lu)\n",
584 track
->db_depth_size
, ntiles
, nviews
, bpe
, tmp
+ track
->db_offset
,
585 radeon_bo_size(track
->db_bo
));
594 * r600_cs_packet_parse() - parse cp packet and point ib index to next packet
595 * @parser: parser structure holding parsing context.
596 * @pkt: where to store packet informations
598 * Assume that chunk_ib_index is properly set. Will return -EINVAL
599 * if packet is bigger than remaining ib size. or if packets is unknown.
601 int r600_cs_packet_parse(struct radeon_cs_parser
*p
,
602 struct radeon_cs_packet
*pkt
,
605 struct radeon_cs_chunk
*ib_chunk
= &p
->chunks
[p
->chunk_ib_idx
];
608 if (idx
>= ib_chunk
->length_dw
) {
609 DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
610 idx
, ib_chunk
->length_dw
);
613 header
= radeon_get_ib_value(p
, idx
);
615 pkt
->type
= CP_PACKET_GET_TYPE(header
);
616 pkt
->count
= CP_PACKET_GET_COUNT(header
);
620 pkt
->reg
= CP_PACKET0_GET_REG(header
);
623 pkt
->opcode
= CP_PACKET3_GET_OPCODE(header
);
629 DRM_ERROR("Unknown packet type %d at %d !\n", pkt
->type
, idx
);
632 if ((pkt
->count
+ 1 + pkt
->idx
) >= ib_chunk
->length_dw
) {
633 DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
634 pkt
->idx
, pkt
->type
, pkt
->count
, ib_chunk
->length_dw
);
641 * r600_cs_packet_next_reloc_mm() - parse next packet which should be reloc packet3
642 * @parser: parser structure holding parsing context.
643 * @data: pointer to relocation data
644 * @offset_start: starting offset
645 * @offset_mask: offset mask (to align start offset on)
646 * @reloc: reloc informations
648 * Check next packet is relocation packet3, do bo validation and compute
649 * GPU offset using the provided start.
651 static int r600_cs_packet_next_reloc_mm(struct radeon_cs_parser
*p
,
652 struct radeon_cs_reloc
**cs_reloc
)
654 struct radeon_cs_chunk
*relocs_chunk
;
655 struct radeon_cs_packet p3reloc
;
659 if (p
->chunk_relocs_idx
== -1) {
660 DRM_ERROR("No relocation chunk !\n");
664 relocs_chunk
= &p
->chunks
[p
->chunk_relocs_idx
];
665 r
= r600_cs_packet_parse(p
, &p3reloc
, p
->idx
);
669 p
->idx
+= p3reloc
.count
+ 2;
670 if (p3reloc
.type
!= PACKET_TYPE3
|| p3reloc
.opcode
!= PACKET3_NOP
) {
671 DRM_ERROR("No packet3 for relocation for packet at %d.\n",
675 idx
= radeon_get_ib_value(p
, p3reloc
.idx
+ 1);
676 if (idx
>= relocs_chunk
->length_dw
) {
677 DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
678 idx
, relocs_chunk
->length_dw
);
681 /* FIXME: we assume reloc size is 4 dwords */
682 *cs_reloc
= p
->relocs_ptr
[(idx
/ 4)];
687 * r600_cs_packet_next_reloc_nomm() - parse next packet which should be reloc packet3
688 * @parser: parser structure holding parsing context.
689 * @data: pointer to relocation data
690 * @offset_start: starting offset
691 * @offset_mask: offset mask (to align start offset on)
692 * @reloc: reloc informations
694 * Check next packet is relocation packet3, do bo validation and compute
695 * GPU offset using the provided start.
697 static int r600_cs_packet_next_reloc_nomm(struct radeon_cs_parser
*p
,
698 struct radeon_cs_reloc
**cs_reloc
)
700 struct radeon_cs_chunk
*relocs_chunk
;
701 struct radeon_cs_packet p3reloc
;
705 if (p
->chunk_relocs_idx
== -1) {
706 DRM_ERROR("No relocation chunk !\n");
710 relocs_chunk
= &p
->chunks
[p
->chunk_relocs_idx
];
711 r
= r600_cs_packet_parse(p
, &p3reloc
, p
->idx
);
715 p
->idx
+= p3reloc
.count
+ 2;
716 if (p3reloc
.type
!= PACKET_TYPE3
|| p3reloc
.opcode
!= PACKET3_NOP
) {
717 DRM_ERROR("No packet3 for relocation for packet at %d.\n",
721 idx
= radeon_get_ib_value(p
, p3reloc
.idx
+ 1);
722 if (idx
>= relocs_chunk
->length_dw
) {
723 DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
724 idx
, relocs_chunk
->length_dw
);
727 *cs_reloc
= p
->relocs
;
728 (*cs_reloc
)->lobj
.gpu_offset
= (u64
)relocs_chunk
->kdata
[idx
+ 3] << 32;
729 (*cs_reloc
)->lobj
.gpu_offset
|= relocs_chunk
->kdata
[idx
+ 0];
734 * r600_cs_packet_next_is_pkt3_nop() - test if next packet is packet3 nop for reloc
735 * @parser: parser structure holding parsing context.
737 * Check next packet is relocation packet3, do bo validation and compute
738 * GPU offset using the provided start.
740 static inline int r600_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser
*p
)
742 struct radeon_cs_packet p3reloc
;
745 r
= r600_cs_packet_parse(p
, &p3reloc
, p
->idx
);
749 if (p3reloc
.type
!= PACKET_TYPE3
|| p3reloc
.opcode
!= PACKET3_NOP
) {
756 * r600_cs_packet_next_vline() - parse userspace VLINE packet
757 * @parser: parser structure holding parsing context.
759 * Userspace sends a special sequence for VLINE waits.
760 * PACKET0 - VLINE_START_END + value
761 * PACKET3 - WAIT_REG_MEM poll vline status reg
762 * RELOC (P3) - crtc_id in reloc.
764 * This function parses this and relocates the VLINE START END
765 * and WAIT_REG_MEM packets to the correct crtc.
766 * It also detects a switched off crtc and nulls out the
769 static int r600_cs_packet_parse_vline(struct radeon_cs_parser
*p
)
771 struct drm_mode_object
*obj
;
772 struct drm_crtc
*crtc
;
773 struct radeon_crtc
*radeon_crtc
;
774 struct radeon_cs_packet p3reloc
, wait_reg_mem
;
777 uint32_t header
, h_idx
, reg
, wait_reg_mem_info
;
778 volatile uint32_t *ib
;
782 /* parse the WAIT_REG_MEM */
783 r
= r600_cs_packet_parse(p
, &wait_reg_mem
, p
->idx
);
787 /* check its a WAIT_REG_MEM */
788 if (wait_reg_mem
.type
!= PACKET_TYPE3
||
789 wait_reg_mem
.opcode
!= PACKET3_WAIT_REG_MEM
) {
790 DRM_ERROR("vline wait missing WAIT_REG_MEM segment\n");
794 wait_reg_mem_info
= radeon_get_ib_value(p
, wait_reg_mem
.idx
+ 1);
795 /* bit 4 is reg (0) or mem (1) */
796 if (wait_reg_mem_info
& 0x10) {
797 DRM_ERROR("vline WAIT_REG_MEM waiting on MEM rather than REG\n");
800 /* waiting for value to be equal */
801 if ((wait_reg_mem_info
& 0x7) != 0x3) {
802 DRM_ERROR("vline WAIT_REG_MEM function not equal\n");
805 if ((radeon_get_ib_value(p
, wait_reg_mem
.idx
+ 2) << 2) != AVIVO_D1MODE_VLINE_STATUS
) {
806 DRM_ERROR("vline WAIT_REG_MEM bad reg\n");
810 if (radeon_get_ib_value(p
, wait_reg_mem
.idx
+ 5) != AVIVO_D1MODE_VLINE_STAT
) {
811 DRM_ERROR("vline WAIT_REG_MEM bad bit mask\n");
815 /* jump over the NOP */
816 r
= r600_cs_packet_parse(p
, &p3reloc
, p
->idx
+ wait_reg_mem
.count
+ 2);
821 p
->idx
+= wait_reg_mem
.count
+ 2;
822 p
->idx
+= p3reloc
.count
+ 2;
824 header
= radeon_get_ib_value(p
, h_idx
);
825 crtc_id
= radeon_get_ib_value(p
, h_idx
+ 2 + 7 + 1);
826 reg
= CP_PACKET0_GET_REG(header
);
828 obj
= drm_mode_object_find(p
->rdev
->ddev
, crtc_id
, DRM_MODE_OBJECT_CRTC
);
830 DRM_ERROR("cannot find crtc %d\n", crtc_id
);
833 crtc
= obj_to_crtc(obj
);
834 radeon_crtc
= to_radeon_crtc(crtc
);
835 crtc_id
= radeon_crtc
->crtc_id
;
837 if (!crtc
->enabled
) {
838 /* if the CRTC isn't enabled - we need to nop out the WAIT_REG_MEM */
839 ib
[h_idx
+ 2] = PACKET2(0);
840 ib
[h_idx
+ 3] = PACKET2(0);
841 ib
[h_idx
+ 4] = PACKET2(0);
842 ib
[h_idx
+ 5] = PACKET2(0);
843 ib
[h_idx
+ 6] = PACKET2(0);
844 ib
[h_idx
+ 7] = PACKET2(0);
845 ib
[h_idx
+ 8] = PACKET2(0);
846 } else if (crtc_id
== 1) {
848 case AVIVO_D1MODE_VLINE_START_END
:
849 header
&= ~R600_CP_PACKET0_REG_MASK
;
850 header
|= AVIVO_D2MODE_VLINE_START_END
>> 2;
853 DRM_ERROR("unknown crtc reloc\n");
857 ib
[h_idx
+ 4] = AVIVO_D2MODE_VLINE_STATUS
>> 2;
863 static int r600_packet0_check(struct radeon_cs_parser
*p
,
864 struct radeon_cs_packet
*pkt
,
865 unsigned idx
, unsigned reg
)
870 case AVIVO_D1MODE_VLINE_START_END
:
871 r
= r600_cs_packet_parse_vline(p
);
873 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
879 printk(KERN_ERR
"Forbidden register 0x%04X in cs at %d\n",
886 static int r600_cs_parse_packet0(struct radeon_cs_parser
*p
,
887 struct radeon_cs_packet
*pkt
)
895 for (i
= 0; i
<= pkt
->count
; i
++, idx
++, reg
+= 4) {
896 r
= r600_packet0_check(p
, pkt
, idx
, reg
);
905 * r600_cs_check_reg() - check if register is authorized or not
906 * @parser: parser structure holding parsing context
907 * @reg: register we are testing
908 * @idx: index into the cs buffer
910 * This function will test against r600_reg_safe_bm and return 0
911 * if register is safe. If register is not flag as safe this function
912 * will test it against a list of register needind special handling.
914 static inline int r600_cs_check_reg(struct radeon_cs_parser
*p
, u32 reg
, u32 idx
)
916 struct r600_cs_track
*track
= (struct r600_cs_track
*)p
->track
;
917 struct radeon_cs_reloc
*reloc
;
922 if (i
>= ARRAY_SIZE(r600_reg_safe_bm
)) {
923 dev_warn(p
->dev
, "forbidden register 0x%08x at %d\n", reg
, idx
);
926 m
= 1 << ((reg
>> 2) & 31);
927 if (!(r600_reg_safe_bm
[i
] & m
))
931 /* force following reg to 0 in an attempt to disable out buffer
932 * which will need us to better understand how it works to perform
933 * security check on it (Jerome)
935 case R_0288A8_SQ_ESGS_RING_ITEMSIZE
:
936 case R_008C44_SQ_ESGS_RING_SIZE
:
937 case R_0288B0_SQ_ESTMP_RING_ITEMSIZE
:
938 case R_008C54_SQ_ESTMP_RING_SIZE
:
939 case R_0288C0_SQ_FBUF_RING_ITEMSIZE
:
940 case R_008C74_SQ_FBUF_RING_SIZE
:
941 case R_0288B4_SQ_GSTMP_RING_ITEMSIZE
:
942 case R_008C5C_SQ_GSTMP_RING_SIZE
:
943 case R_0288AC_SQ_GSVS_RING_ITEMSIZE
:
944 case R_008C4C_SQ_GSVS_RING_SIZE
:
945 case R_0288BC_SQ_PSTMP_RING_ITEMSIZE
:
946 case R_008C6C_SQ_PSTMP_RING_SIZE
:
947 case R_0288C4_SQ_REDUC_RING_ITEMSIZE
:
948 case R_008C7C_SQ_REDUC_RING_SIZE
:
949 case R_0288B8_SQ_VSTMP_RING_ITEMSIZE
:
950 case R_008C64_SQ_VSTMP_RING_SIZE
:
951 case R_0288C8_SQ_GS_VERT_ITEMSIZE
:
952 /* get value to populate the IB don't remove */
953 tmp
=radeon_get_ib_value(p
, idx
);
957 track
->sq_config
= radeon_get_ib_value(p
, idx
);
959 case R_028800_DB_DEPTH_CONTROL
:
960 track
->db_depth_control
= radeon_get_ib_value(p
, idx
);
962 case R_028010_DB_DEPTH_INFO
:
963 if (r600_cs_packet_next_is_pkt3_nop(p
)) {
964 r
= r600_cs_packet_next_reloc(p
, &reloc
);
966 dev_warn(p
->dev
, "bad SET_CONTEXT_REG "
970 track
->db_depth_info
= radeon_get_ib_value(p
, idx
);
971 ib
[idx
] &= C_028010_ARRAY_MODE
;
972 track
->db_depth_info
&= C_028010_ARRAY_MODE
;
973 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MACRO
) {
974 ib
[idx
] |= S_028010_ARRAY_MODE(V_028010_ARRAY_2D_TILED_THIN1
);
975 track
->db_depth_info
|= S_028010_ARRAY_MODE(V_028010_ARRAY_2D_TILED_THIN1
);
977 ib
[idx
] |= S_028010_ARRAY_MODE(V_028010_ARRAY_1D_TILED_THIN1
);
978 track
->db_depth_info
|= S_028010_ARRAY_MODE(V_028010_ARRAY_1D_TILED_THIN1
);
981 track
->db_depth_info
= radeon_get_ib_value(p
, idx
);
983 case R_028004_DB_DEPTH_VIEW
:
984 track
->db_depth_view
= radeon_get_ib_value(p
, idx
);
986 case R_028000_DB_DEPTH_SIZE
:
987 track
->db_depth_size
= radeon_get_ib_value(p
, idx
);
988 track
->db_depth_size_idx
= idx
;
990 case R_028AB0_VGT_STRMOUT_EN
:
991 track
->vgt_strmout_en
= radeon_get_ib_value(p
, idx
);
993 case R_028B20_VGT_STRMOUT_BUFFER_EN
:
994 track
->vgt_strmout_buffer_en
= radeon_get_ib_value(p
, idx
);
996 case R_028238_CB_TARGET_MASK
:
997 track
->cb_target_mask
= radeon_get_ib_value(p
, idx
);
999 case R_02823C_CB_SHADER_MASK
:
1000 track
->cb_shader_mask
= radeon_get_ib_value(p
, idx
);
1002 case R_028C04_PA_SC_AA_CONFIG
:
1003 tmp
= G_028C04_MSAA_NUM_SAMPLES(radeon_get_ib_value(p
, idx
));
1004 track
->nsamples
= 1 << tmp
;
1006 case R_0280A0_CB_COLOR0_INFO
:
1007 case R_0280A4_CB_COLOR1_INFO
:
1008 case R_0280A8_CB_COLOR2_INFO
:
1009 case R_0280AC_CB_COLOR3_INFO
:
1010 case R_0280B0_CB_COLOR4_INFO
:
1011 case R_0280B4_CB_COLOR5_INFO
:
1012 case R_0280B8_CB_COLOR6_INFO
:
1013 case R_0280BC_CB_COLOR7_INFO
:
1014 if (r600_cs_packet_next_is_pkt3_nop(p
)) {
1015 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1017 dev_err(p
->dev
, "bad SET_CONTEXT_REG 0x%04X\n", reg
);
1020 tmp
= (reg
- R_0280A0_CB_COLOR0_INFO
) / 4;
1021 track
->cb_color_info
[tmp
] = radeon_get_ib_value(p
, idx
);
1022 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MACRO
) {
1023 ib
[idx
] |= S_0280A0_ARRAY_MODE(V_0280A0_ARRAY_2D_TILED_THIN1
);
1024 track
->cb_color_info
[tmp
] |= S_0280A0_ARRAY_MODE(V_0280A0_ARRAY_2D_TILED_THIN1
);
1025 } else if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MICRO
) {
1026 ib
[idx
] |= S_0280A0_ARRAY_MODE(V_0280A0_ARRAY_1D_TILED_THIN1
);
1027 track
->cb_color_info
[tmp
] |= S_0280A0_ARRAY_MODE(V_0280A0_ARRAY_1D_TILED_THIN1
);
1030 tmp
= (reg
- R_0280A0_CB_COLOR0_INFO
) / 4;
1031 track
->cb_color_info
[tmp
] = radeon_get_ib_value(p
, idx
);
1034 case R_028060_CB_COLOR0_SIZE
:
1035 case R_028064_CB_COLOR1_SIZE
:
1036 case R_028068_CB_COLOR2_SIZE
:
1037 case R_02806C_CB_COLOR3_SIZE
:
1038 case R_028070_CB_COLOR4_SIZE
:
1039 case R_028074_CB_COLOR5_SIZE
:
1040 case R_028078_CB_COLOR6_SIZE
:
1041 case R_02807C_CB_COLOR7_SIZE
:
1042 tmp
= (reg
- R_028060_CB_COLOR0_SIZE
) / 4;
1043 track
->cb_color_size
[tmp
] = radeon_get_ib_value(p
, idx
);
1044 track
->cb_color_size_idx
[tmp
] = idx
;
1046 /* This register were added late, there is userspace
1047 * which does provide relocation for those but set
1048 * 0 offset. In order to avoid breaking old userspace
1049 * we detect this and set address to point to last
1050 * CB_COLOR0_BASE, note that if userspace doesn't set
1051 * CB_COLOR0_BASE before this register we will report
1052 * error. Old userspace always set CB_COLOR0_BASE
1053 * before any of this.
1055 case R_0280E0_CB_COLOR0_FRAG
:
1056 case R_0280E4_CB_COLOR1_FRAG
:
1057 case R_0280E8_CB_COLOR2_FRAG
:
1058 case R_0280EC_CB_COLOR3_FRAG
:
1059 case R_0280F0_CB_COLOR4_FRAG
:
1060 case R_0280F4_CB_COLOR5_FRAG
:
1061 case R_0280F8_CB_COLOR6_FRAG
:
1062 case R_0280FC_CB_COLOR7_FRAG
:
1063 tmp
= (reg
- R_0280E0_CB_COLOR0_FRAG
) / 4;
1064 if (!r600_cs_packet_next_is_pkt3_nop(p
)) {
1065 if (!track
->cb_color_base_last
[tmp
]) {
1066 dev_err(p
->dev
, "Broken old userspace ? no cb_color0_base supplied before trying to write 0x%08X\n", reg
);
1069 ib
[idx
] = track
->cb_color_base_last
[tmp
];
1070 track
->cb_color_frag_bo
[tmp
] = track
->cb_color_bo
[tmp
];
1072 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1074 dev_err(p
->dev
, "bad SET_CONTEXT_REG 0x%04X\n", reg
);
1077 ib
[idx
] += (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1078 track
->cb_color_frag_bo
[tmp
] = reloc
->robj
;
1081 case R_0280C0_CB_COLOR0_TILE
:
1082 case R_0280C4_CB_COLOR1_TILE
:
1083 case R_0280C8_CB_COLOR2_TILE
:
1084 case R_0280CC_CB_COLOR3_TILE
:
1085 case R_0280D0_CB_COLOR4_TILE
:
1086 case R_0280D4_CB_COLOR5_TILE
:
1087 case R_0280D8_CB_COLOR6_TILE
:
1088 case R_0280DC_CB_COLOR7_TILE
:
1089 tmp
= (reg
- R_0280C0_CB_COLOR0_TILE
) / 4;
1090 if (!r600_cs_packet_next_is_pkt3_nop(p
)) {
1091 if (!track
->cb_color_base_last
[tmp
]) {
1092 dev_err(p
->dev
, "Broken old userspace ? no cb_color0_base supplied before trying to write 0x%08X\n", reg
);
1095 ib
[idx
] = track
->cb_color_base_last
[tmp
];
1096 track
->cb_color_tile_bo
[tmp
] = track
->cb_color_bo
[tmp
];
1098 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1100 dev_err(p
->dev
, "bad SET_CONTEXT_REG 0x%04X\n", reg
);
1103 ib
[idx
] += (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1104 track
->cb_color_tile_bo
[tmp
] = reloc
->robj
;
1107 case CB_COLOR0_BASE
:
1108 case CB_COLOR1_BASE
:
1109 case CB_COLOR2_BASE
:
1110 case CB_COLOR3_BASE
:
1111 case CB_COLOR4_BASE
:
1112 case CB_COLOR5_BASE
:
1113 case CB_COLOR6_BASE
:
1114 case CB_COLOR7_BASE
:
1115 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1117 dev_warn(p
->dev
, "bad SET_CONTEXT_REG "
1121 tmp
= (reg
- CB_COLOR0_BASE
) / 4;
1122 track
->cb_color_bo_offset
[tmp
] = radeon_get_ib_value(p
, idx
) << 8;
1123 ib
[idx
] += (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1124 track
->cb_color_base_last
[tmp
] = ib
[idx
];
1125 track
->cb_color_bo
[tmp
] = reloc
->robj
;
1126 track
->cb_color_bo_mc
[tmp
] = reloc
->lobj
.gpu_offset
;
1129 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1131 dev_warn(p
->dev
, "bad SET_CONTEXT_REG "
1135 track
->db_offset
= radeon_get_ib_value(p
, idx
) << 8;
1136 ib
[idx
] += (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1137 track
->db_bo
= reloc
->robj
;
1138 track
->db_bo_mc
= reloc
->lobj
.gpu_offset
;
1140 case DB_HTILE_DATA_BASE
:
1141 case SQ_PGM_START_FS
:
1142 case SQ_PGM_START_ES
:
1143 case SQ_PGM_START_VS
:
1144 case SQ_PGM_START_GS
:
1145 case SQ_PGM_START_PS
:
1146 case SQ_ALU_CONST_CACHE_GS_0
:
1147 case SQ_ALU_CONST_CACHE_GS_1
:
1148 case SQ_ALU_CONST_CACHE_GS_2
:
1149 case SQ_ALU_CONST_CACHE_GS_3
:
1150 case SQ_ALU_CONST_CACHE_GS_4
:
1151 case SQ_ALU_CONST_CACHE_GS_5
:
1152 case SQ_ALU_CONST_CACHE_GS_6
:
1153 case SQ_ALU_CONST_CACHE_GS_7
:
1154 case SQ_ALU_CONST_CACHE_GS_8
:
1155 case SQ_ALU_CONST_CACHE_GS_9
:
1156 case SQ_ALU_CONST_CACHE_GS_10
:
1157 case SQ_ALU_CONST_CACHE_GS_11
:
1158 case SQ_ALU_CONST_CACHE_GS_12
:
1159 case SQ_ALU_CONST_CACHE_GS_13
:
1160 case SQ_ALU_CONST_CACHE_GS_14
:
1161 case SQ_ALU_CONST_CACHE_GS_15
:
1162 case SQ_ALU_CONST_CACHE_PS_0
:
1163 case SQ_ALU_CONST_CACHE_PS_1
:
1164 case SQ_ALU_CONST_CACHE_PS_2
:
1165 case SQ_ALU_CONST_CACHE_PS_3
:
1166 case SQ_ALU_CONST_CACHE_PS_4
:
1167 case SQ_ALU_CONST_CACHE_PS_5
:
1168 case SQ_ALU_CONST_CACHE_PS_6
:
1169 case SQ_ALU_CONST_CACHE_PS_7
:
1170 case SQ_ALU_CONST_CACHE_PS_8
:
1171 case SQ_ALU_CONST_CACHE_PS_9
:
1172 case SQ_ALU_CONST_CACHE_PS_10
:
1173 case SQ_ALU_CONST_CACHE_PS_11
:
1174 case SQ_ALU_CONST_CACHE_PS_12
:
1175 case SQ_ALU_CONST_CACHE_PS_13
:
1176 case SQ_ALU_CONST_CACHE_PS_14
:
1177 case SQ_ALU_CONST_CACHE_PS_15
:
1178 case SQ_ALU_CONST_CACHE_VS_0
:
1179 case SQ_ALU_CONST_CACHE_VS_1
:
1180 case SQ_ALU_CONST_CACHE_VS_2
:
1181 case SQ_ALU_CONST_CACHE_VS_3
:
1182 case SQ_ALU_CONST_CACHE_VS_4
:
1183 case SQ_ALU_CONST_CACHE_VS_5
:
1184 case SQ_ALU_CONST_CACHE_VS_6
:
1185 case SQ_ALU_CONST_CACHE_VS_7
:
1186 case SQ_ALU_CONST_CACHE_VS_8
:
1187 case SQ_ALU_CONST_CACHE_VS_9
:
1188 case SQ_ALU_CONST_CACHE_VS_10
:
1189 case SQ_ALU_CONST_CACHE_VS_11
:
1190 case SQ_ALU_CONST_CACHE_VS_12
:
1191 case SQ_ALU_CONST_CACHE_VS_13
:
1192 case SQ_ALU_CONST_CACHE_VS_14
:
1193 case SQ_ALU_CONST_CACHE_VS_15
:
1194 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1196 dev_warn(p
->dev
, "bad SET_CONTEXT_REG "
1200 ib
[idx
] += (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1202 case SX_MEMORY_EXPORT_BASE
:
1203 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1205 dev_warn(p
->dev
, "bad SET_CONFIG_REG "
1209 ib
[idx
] += (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1212 dev_warn(p
->dev
, "forbidden register 0x%08x at %d\n", reg
, idx
);
1218 static inline unsigned mip_minify(unsigned size
, unsigned level
)
1222 val
= max(1U, size
>> level
);
1224 val
= roundup_pow_of_two(val
);
1228 static void r600_texture_size(unsigned nfaces
, unsigned blevel
, unsigned llevel
,
1229 unsigned w0
, unsigned h0
, unsigned d0
, unsigned format
,
1230 unsigned block_align
, unsigned height_align
, unsigned base_align
,
1231 unsigned *l0_size
, unsigned *mipmap_size
)
1233 unsigned offset
, i
, level
;
1234 unsigned width
, height
, depth
, size
;
1237 unsigned nlevels
= llevel
- blevel
+ 1;
1240 blocksize
= fmt_get_blocksize(format
);
1242 w0
= mip_minify(w0
, 0);
1243 h0
= mip_minify(h0
, 0);
1244 d0
= mip_minify(d0
, 0);
1245 for(i
= 0, offset
= 0, level
= blevel
; i
< nlevels
; i
++, level
++) {
1246 width
= mip_minify(w0
, i
);
1247 nbx
= fmt_get_nblocksx(format
, width
);
1249 nbx
= round_up(nbx
, block_align
);
1251 height
= mip_minify(h0
, i
);
1252 nby
= fmt_get_nblocksy(format
, height
);
1253 nby
= round_up(nby
, height_align
);
1255 depth
= mip_minify(d0
, i
);
1257 size
= nbx
* nby
* blocksize
;
1266 if (i
== 0 || i
== 1)
1267 offset
= round_up(offset
, base_align
);
1271 *mipmap_size
= offset
;
1273 *mipmap_size
= *l0_size
;
1275 *mipmap_size
-= *l0_size
;
1279 * r600_check_texture_resource() - check if register is authorized or not
1280 * @p: parser structure holding parsing context
1281 * @idx: index into the cs buffer
1282 * @texture: texture's bo structure
1283 * @mipmap: mipmap's bo structure
1285 * This function will check that the resource has valid field and that
1286 * the texture and mipmap bo object are big enough to cover this resource.
1288 static inline int r600_check_texture_resource(struct radeon_cs_parser
*p
, u32 idx
,
1289 struct radeon_bo
*texture
,
1290 struct radeon_bo
*mipmap
,
1295 struct r600_cs_track
*track
= p
->track
;
1296 u32 nfaces
, llevel
, blevel
, w0
, h0
, d0
;
1297 u32 word0
, word1
, l0_size
, mipmap_size
, word2
, word3
;
1298 u32 height_align
, pitch
, pitch_align
, depth_align
;
1299 u32 array
, barray
, larray
;
1301 struct array_mode_checker array_check
;
1304 /* on legacy kernel we don't perform advanced check */
1305 if (p
->rdev
== NULL
)
1308 /* convert to bytes */
1312 word0
= radeon_get_ib_value(p
, idx
+ 0);
1313 if (tiling_flags
& RADEON_TILING_MACRO
)
1314 word0
|= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1
);
1315 else if (tiling_flags
& RADEON_TILING_MICRO
)
1316 word0
|= S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1
);
1317 word1
= radeon_get_ib_value(p
, idx
+ 1);
1318 w0
= G_038000_TEX_WIDTH(word0
) + 1;
1319 h0
= G_038004_TEX_HEIGHT(word1
) + 1;
1320 d0
= G_038004_TEX_DEPTH(word1
);
1322 switch (G_038000_DIM(word0
)) {
1323 case V_038000_SQ_TEX_DIM_1D
:
1324 case V_038000_SQ_TEX_DIM_2D
:
1325 case V_038000_SQ_TEX_DIM_3D
:
1327 case V_038000_SQ_TEX_DIM_CUBEMAP
:
1328 if (p
->family
>= CHIP_RV770
)
1333 case V_038000_SQ_TEX_DIM_1D_ARRAY
:
1334 case V_038000_SQ_TEX_DIM_2D_ARRAY
:
1337 case V_038000_SQ_TEX_DIM_2D_MSAA
:
1338 case V_038000_SQ_TEX_DIM_2D_ARRAY_MSAA
:
1340 dev_warn(p
->dev
, "this kernel doesn't support %d texture dim\n", G_038000_DIM(word0
));
1343 format
= G_038004_DATA_FORMAT(word1
);
1344 if (!fmt_is_valid_texture(format
, p
->family
)) {
1345 dev_warn(p
->dev
, "%s:%d texture invalid format %d\n",
1346 __func__
, __LINE__
, format
);
1350 /* pitch in texels */
1351 pitch
= (G_038000_PITCH(word0
) + 1) * 8;
1352 array_check
.array_mode
= G_038000_TILE_MODE(word0
);
1353 array_check
.group_size
= track
->group_size
;
1354 array_check
.nbanks
= track
->nbanks
;
1355 array_check
.npipes
= track
->npipes
;
1356 array_check
.nsamples
= 1;
1357 array_check
.blocksize
= fmt_get_blocksize(format
);
1358 if (r600_get_array_mode_alignment(&array_check
,
1359 &pitch_align
, &height_align
, &depth_align
, &base_align
)) {
1360 dev_warn(p
->dev
, "%s:%d tex array mode (%d) invalid\n",
1361 __func__
, __LINE__
, G_038000_TILE_MODE(word0
));
1365 /* XXX check height as well... */
1367 if (!IS_ALIGNED(pitch
, pitch_align
)) {
1368 dev_warn(p
->dev
, "%s:%d tex pitch (%d, 0x%x, %d) invalid\n",
1369 __func__
, __LINE__
, pitch
, pitch_align
, G_038000_TILE_MODE(word0
));
1372 if (!IS_ALIGNED(base_offset
, base_align
)) {
1373 dev_warn(p
->dev
, "%s:%d tex base offset (0x%llx, 0x%llx, %d) invalid\n",
1374 __func__
, __LINE__
, base_offset
, base_align
, G_038000_TILE_MODE(word0
));
1377 if (!IS_ALIGNED(mip_offset
, base_align
)) {
1378 dev_warn(p
->dev
, "%s:%d tex mip offset (0x%llx, 0x%llx, %d) invalid\n",
1379 __func__
, __LINE__
, mip_offset
, base_align
, G_038000_TILE_MODE(word0
));
1383 word2
= radeon_get_ib_value(p
, idx
+ 2) << 8;
1384 word3
= radeon_get_ib_value(p
, idx
+ 3) << 8;
1386 word0
= radeon_get_ib_value(p
, idx
+ 4);
1387 word1
= radeon_get_ib_value(p
, idx
+ 5);
1388 blevel
= G_038010_BASE_LEVEL(word0
);
1389 llevel
= G_038014_LAST_LEVEL(word1
);
1391 barray
= G_038014_BASE_ARRAY(word1
);
1392 larray
= G_038014_LAST_ARRAY(word1
);
1394 nfaces
= larray
- barray
+ 1;
1396 r600_texture_size(nfaces
, blevel
, llevel
, w0
, h0
, d0
, format
,
1397 pitch_align
, height_align
, base_align
,
1398 &l0_size
, &mipmap_size
);
1399 /* using get ib will give us the offset into the texture bo */
1400 if ((l0_size
+ word2
) > radeon_bo_size(texture
)) {
1401 dev_warn(p
->dev
, "texture bo too small (%d %d %d %d -> %d have %ld)\n",
1402 w0
, h0
, format
, word2
, l0_size
, radeon_bo_size(texture
));
1403 dev_warn(p
->dev
, "alignments %d %d %d %lld\n", pitch
, pitch_align
, height_align
, base_align
);
1406 /* using get ib will give us the offset into the mipmap bo */
1407 word3
= radeon_get_ib_value(p
, idx
+ 3) << 8;
1408 if ((mipmap_size
+ word3
) > radeon_bo_size(mipmap
)) {
1409 /*dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n",
1410 w0, h0, format, blevel, nlevels, word3, mipmap_size, radeon_bo_size(texture));*/
1415 static int r600_packet3_check(struct radeon_cs_parser
*p
,
1416 struct radeon_cs_packet
*pkt
)
1418 struct radeon_cs_reloc
*reloc
;
1419 struct r600_cs_track
*track
;
1423 unsigned start_reg
, end_reg
, reg
;
1427 track
= (struct r600_cs_track
*)p
->track
;
1430 idx_value
= radeon_get_ib_value(p
, idx
);
1432 switch (pkt
->opcode
) {
1433 case PACKET3_SET_PREDICATION
:
1437 if (pkt
->count
!= 1) {
1438 DRM_ERROR("bad SET PREDICATION\n");
1442 tmp
= radeon_get_ib_value(p
, idx
+ 1);
1443 pred_op
= (tmp
>> 16) & 0x7;
1445 /* for the clear predicate operation */
1450 DRM_ERROR("bad SET PREDICATION operation %d\n", pred_op
);
1454 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1456 DRM_ERROR("bad SET PREDICATION\n");
1460 ib
[idx
+ 0] = idx_value
+ (u32
)(reloc
->lobj
.gpu_offset
& 0xffffffff);
1461 ib
[idx
+ 1] = tmp
+ (upper_32_bits(reloc
->lobj
.gpu_offset
) & 0xff);
1465 case PACKET3_START_3D_CMDBUF
:
1466 if (p
->family
>= CHIP_RV770
|| pkt
->count
) {
1467 DRM_ERROR("bad START_3D\n");
1471 case PACKET3_CONTEXT_CONTROL
:
1472 if (pkt
->count
!= 1) {
1473 DRM_ERROR("bad CONTEXT_CONTROL\n");
1477 case PACKET3_INDEX_TYPE
:
1478 case PACKET3_NUM_INSTANCES
:
1480 DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES\n");
1484 case PACKET3_DRAW_INDEX
:
1485 if (pkt
->count
!= 3) {
1486 DRM_ERROR("bad DRAW_INDEX\n");
1489 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1491 DRM_ERROR("bad DRAW_INDEX\n");
1494 ib
[idx
+0] = idx_value
+ (u32
)(reloc
->lobj
.gpu_offset
& 0xffffffff);
1495 ib
[idx
+1] += upper_32_bits(reloc
->lobj
.gpu_offset
) & 0xff;
1496 r
= r600_cs_track_check(p
);
1498 dev_warn(p
->dev
, "%s:%d invalid cmd stream\n", __func__
, __LINE__
);
1502 case PACKET3_DRAW_INDEX_AUTO
:
1503 if (pkt
->count
!= 1) {
1504 DRM_ERROR("bad DRAW_INDEX_AUTO\n");
1507 r
= r600_cs_track_check(p
);
1509 dev_warn(p
->dev
, "%s:%d invalid cmd stream %d\n", __func__
, __LINE__
, idx
);
1513 case PACKET3_DRAW_INDEX_IMMD_BE
:
1514 case PACKET3_DRAW_INDEX_IMMD
:
1515 if (pkt
->count
< 2) {
1516 DRM_ERROR("bad DRAW_INDEX_IMMD\n");
1519 r
= r600_cs_track_check(p
);
1521 dev_warn(p
->dev
, "%s:%d invalid cmd stream\n", __func__
, __LINE__
);
1525 case PACKET3_WAIT_REG_MEM
:
1526 if (pkt
->count
!= 5) {
1527 DRM_ERROR("bad WAIT_REG_MEM\n");
1530 /* bit 4 is reg (0) or mem (1) */
1531 if (idx_value
& 0x10) {
1532 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1534 DRM_ERROR("bad WAIT_REG_MEM\n");
1537 ib
[idx
+1] += (u32
)(reloc
->lobj
.gpu_offset
& 0xffffffff);
1538 ib
[idx
+2] += upper_32_bits(reloc
->lobj
.gpu_offset
) & 0xff;
1541 case PACKET3_SURFACE_SYNC
:
1542 if (pkt
->count
!= 3) {
1543 DRM_ERROR("bad SURFACE_SYNC\n");
1546 /* 0xffffffff/0x0 is flush all cache flag */
1547 if (radeon_get_ib_value(p
, idx
+ 1) != 0xffffffff ||
1548 radeon_get_ib_value(p
, idx
+ 2) != 0) {
1549 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1551 DRM_ERROR("bad SURFACE_SYNC\n");
1554 ib
[idx
+2] += (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1557 case PACKET3_EVENT_WRITE
:
1558 if (pkt
->count
!= 2 && pkt
->count
!= 0) {
1559 DRM_ERROR("bad EVENT_WRITE\n");
1563 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1565 DRM_ERROR("bad EVENT_WRITE\n");
1568 ib
[idx
+1] += (u32
)(reloc
->lobj
.gpu_offset
& 0xffffffff);
1569 ib
[idx
+2] += upper_32_bits(reloc
->lobj
.gpu_offset
) & 0xff;
1572 case PACKET3_EVENT_WRITE_EOP
:
1573 if (pkt
->count
!= 4) {
1574 DRM_ERROR("bad EVENT_WRITE_EOP\n");
1577 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1579 DRM_ERROR("bad EVENT_WRITE\n");
1582 ib
[idx
+1] += (u32
)(reloc
->lobj
.gpu_offset
& 0xffffffff);
1583 ib
[idx
+2] += upper_32_bits(reloc
->lobj
.gpu_offset
) & 0xff;
1585 case PACKET3_SET_CONFIG_REG
:
1586 start_reg
= (idx_value
<< 2) + PACKET3_SET_CONFIG_REG_OFFSET
;
1587 end_reg
= 4 * pkt
->count
+ start_reg
- 4;
1588 if ((start_reg
< PACKET3_SET_CONFIG_REG_OFFSET
) ||
1589 (start_reg
>= PACKET3_SET_CONFIG_REG_END
) ||
1590 (end_reg
>= PACKET3_SET_CONFIG_REG_END
)) {
1591 DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
1594 for (i
= 0; i
< pkt
->count
; i
++) {
1595 reg
= start_reg
+ (4 * i
);
1596 r
= r600_cs_check_reg(p
, reg
, idx
+1+i
);
1601 case PACKET3_SET_CONTEXT_REG
:
1602 start_reg
= (idx_value
<< 2) + PACKET3_SET_CONTEXT_REG_OFFSET
;
1603 end_reg
= 4 * pkt
->count
+ start_reg
- 4;
1604 if ((start_reg
< PACKET3_SET_CONTEXT_REG_OFFSET
) ||
1605 (start_reg
>= PACKET3_SET_CONTEXT_REG_END
) ||
1606 (end_reg
>= PACKET3_SET_CONTEXT_REG_END
)) {
1607 DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
1610 for (i
= 0; i
< pkt
->count
; i
++) {
1611 reg
= start_reg
+ (4 * i
);
1612 r
= r600_cs_check_reg(p
, reg
, idx
+1+i
);
1617 case PACKET3_SET_RESOURCE
:
1618 if (pkt
->count
% 7) {
1619 DRM_ERROR("bad SET_RESOURCE\n");
1622 start_reg
= (idx_value
<< 2) + PACKET3_SET_RESOURCE_OFFSET
;
1623 end_reg
= 4 * pkt
->count
+ start_reg
- 4;
1624 if ((start_reg
< PACKET3_SET_RESOURCE_OFFSET
) ||
1625 (start_reg
>= PACKET3_SET_RESOURCE_END
) ||
1626 (end_reg
>= PACKET3_SET_RESOURCE_END
)) {
1627 DRM_ERROR("bad SET_RESOURCE\n");
1630 for (i
= 0; i
< (pkt
->count
/ 7); i
++) {
1631 struct radeon_bo
*texture
, *mipmap
;
1632 u32 size
, offset
, base_offset
, mip_offset
;
1634 switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p
, idx
+(i
*7)+6+1))) {
1635 case SQ_TEX_VTX_VALID_TEXTURE
:
1637 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1639 DRM_ERROR("bad SET_RESOURCE\n");
1642 base_offset
= (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1643 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MACRO
)
1644 ib
[idx
+1+(i
*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1
);
1645 else if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MICRO
)
1646 ib
[idx
+1+(i
*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1
);
1647 texture
= reloc
->robj
;
1649 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1651 DRM_ERROR("bad SET_RESOURCE\n");
1654 mip_offset
= (u32
)((reloc
->lobj
.gpu_offset
>> 8) & 0xffffffff);
1655 mipmap
= reloc
->robj
;
1656 r
= r600_check_texture_resource(p
, idx
+(i
*7)+1,
1658 base_offset
+ radeon_get_ib_value(p
, idx
+1+(i
*7)+2),
1659 mip_offset
+ radeon_get_ib_value(p
, idx
+1+(i
*7)+3),
1660 reloc
->lobj
.tiling_flags
);
1663 ib
[idx
+1+(i
*7)+2] += base_offset
;
1664 ib
[idx
+1+(i
*7)+3] += mip_offset
;
1666 case SQ_TEX_VTX_VALID_BUFFER
:
1668 r
= r600_cs_packet_next_reloc(p
, &reloc
);
1670 DRM_ERROR("bad SET_RESOURCE\n");
1673 offset
= radeon_get_ib_value(p
, idx
+1+(i
*7)+0);
1674 size
= radeon_get_ib_value(p
, idx
+1+(i
*7)+1) + 1;
1675 if (p
->rdev
&& (size
+ offset
) > radeon_bo_size(reloc
->robj
)) {
1676 /* force size to size of the buffer */
1677 dev_warn(p
->dev
, "vbo resource seems too big (%d) for the bo (%ld)\n",
1678 size
+ offset
, radeon_bo_size(reloc
->robj
));
1679 ib
[idx
+1+(i
*7)+1] = radeon_bo_size(reloc
->robj
);
1681 ib
[idx
+1+(i
*7)+0] += (u32
)((reloc
->lobj
.gpu_offset
) & 0xffffffff);
1682 ib
[idx
+1+(i
*7)+2] += upper_32_bits(reloc
->lobj
.gpu_offset
) & 0xff;
1684 case SQ_TEX_VTX_INVALID_TEXTURE
:
1685 case SQ_TEX_VTX_INVALID_BUFFER
:
1687 DRM_ERROR("bad SET_RESOURCE\n");
1692 case PACKET3_SET_ALU_CONST
:
1693 if (track
->sq_config
& DX9_CONSTS
) {
1694 start_reg
= (idx_value
<< 2) + PACKET3_SET_ALU_CONST_OFFSET
;
1695 end_reg
= 4 * pkt
->count
+ start_reg
- 4;
1696 if ((start_reg
< PACKET3_SET_ALU_CONST_OFFSET
) ||
1697 (start_reg
>= PACKET3_SET_ALU_CONST_END
) ||
1698 (end_reg
>= PACKET3_SET_ALU_CONST_END
)) {
1699 DRM_ERROR("bad SET_ALU_CONST\n");
1704 case PACKET3_SET_BOOL_CONST
:
1705 start_reg
= (idx_value
<< 2) + PACKET3_SET_BOOL_CONST_OFFSET
;
1706 end_reg
= 4 * pkt
->count
+ start_reg
- 4;
1707 if ((start_reg
< PACKET3_SET_BOOL_CONST_OFFSET
) ||
1708 (start_reg
>= PACKET3_SET_BOOL_CONST_END
) ||
1709 (end_reg
>= PACKET3_SET_BOOL_CONST_END
)) {
1710 DRM_ERROR("bad SET_BOOL_CONST\n");
1714 case PACKET3_SET_LOOP_CONST
:
1715 start_reg
= (idx_value
<< 2) + PACKET3_SET_LOOP_CONST_OFFSET
;
1716 end_reg
= 4 * pkt
->count
+ start_reg
- 4;
1717 if ((start_reg
< PACKET3_SET_LOOP_CONST_OFFSET
) ||
1718 (start_reg
>= PACKET3_SET_LOOP_CONST_END
) ||
1719 (end_reg
>= PACKET3_SET_LOOP_CONST_END
)) {
1720 DRM_ERROR("bad SET_LOOP_CONST\n");
1724 case PACKET3_SET_CTL_CONST
:
1725 start_reg
= (idx_value
<< 2) + PACKET3_SET_CTL_CONST_OFFSET
;
1726 end_reg
= 4 * pkt
->count
+ start_reg
- 4;
1727 if ((start_reg
< PACKET3_SET_CTL_CONST_OFFSET
) ||
1728 (start_reg
>= PACKET3_SET_CTL_CONST_END
) ||
1729 (end_reg
>= PACKET3_SET_CTL_CONST_END
)) {
1730 DRM_ERROR("bad SET_CTL_CONST\n");
1734 case PACKET3_SET_SAMPLER
:
1735 if (pkt
->count
% 3) {
1736 DRM_ERROR("bad SET_SAMPLER\n");
1739 start_reg
= (idx_value
<< 2) + PACKET3_SET_SAMPLER_OFFSET
;
1740 end_reg
= 4 * pkt
->count
+ start_reg
- 4;
1741 if ((start_reg
< PACKET3_SET_SAMPLER_OFFSET
) ||
1742 (start_reg
>= PACKET3_SET_SAMPLER_END
) ||
1743 (end_reg
>= PACKET3_SET_SAMPLER_END
)) {
1744 DRM_ERROR("bad SET_SAMPLER\n");
1748 case PACKET3_SURFACE_BASE_UPDATE
:
1749 if (p
->family
>= CHIP_RV770
|| p
->family
== CHIP_R600
) {
1750 DRM_ERROR("bad SURFACE_BASE_UPDATE\n");
1754 DRM_ERROR("bad SURFACE_BASE_UPDATE\n");
1761 DRM_ERROR("Packet3 opcode %x not supported\n", pkt
->opcode
);
1767 int r600_cs_parse(struct radeon_cs_parser
*p
)
1769 struct radeon_cs_packet pkt
;
1770 struct r600_cs_track
*track
;
1773 if (p
->track
== NULL
) {
1774 /* initialize tracker, we are in kms */
1775 track
= kzalloc(sizeof(*track
), GFP_KERNEL
);
1778 r600_cs_track_init(track
);
1779 if (p
->rdev
->family
< CHIP_RV770
) {
1780 track
->npipes
= p
->rdev
->config
.r600
.tiling_npipes
;
1781 track
->nbanks
= p
->rdev
->config
.r600
.tiling_nbanks
;
1782 track
->group_size
= p
->rdev
->config
.r600
.tiling_group_size
;
1783 } else if (p
->rdev
->family
<= CHIP_RV740
) {
1784 track
->npipes
= p
->rdev
->config
.rv770
.tiling_npipes
;
1785 track
->nbanks
= p
->rdev
->config
.rv770
.tiling_nbanks
;
1786 track
->group_size
= p
->rdev
->config
.rv770
.tiling_group_size
;
1791 r
= r600_cs_packet_parse(p
, &pkt
, p
->idx
);
1797 p
->idx
+= pkt
.count
+ 2;
1800 r
= r600_cs_parse_packet0(p
, &pkt
);
1805 r
= r600_packet3_check(p
, &pkt
);
1808 DRM_ERROR("Unknown packet type %d !\n", pkt
.type
);
1818 } while (p
->idx
< p
->chunks
[p
->chunk_ib_idx
].length_dw
);
1820 for (r
= 0; r
< p
->ib
->length_dw
; r
++) {
1821 printk(KERN_INFO
"%05d 0x%08X\n", r
, p
->ib
->ptr
[r
]);
1830 static int r600_cs_parser_relocs_legacy(struct radeon_cs_parser
*p
)
1832 if (p
->chunk_relocs_idx
== -1) {
1835 p
->relocs
= kzalloc(sizeof(struct radeon_cs_reloc
), GFP_KERNEL
);
1836 if (p
->relocs
== NULL
) {
1843 * cs_parser_fini() - clean parser states
1844 * @parser: parser structure holding parsing context.
1845 * @error: error number
1847 * If error is set than unvalidate buffer, otherwise just free memory
1848 * used by parsing context.
1850 static void r600_cs_parser_fini(struct radeon_cs_parser
*parser
, int error
)
1854 kfree(parser
->relocs
);
1855 for (i
= 0; i
< parser
->nchunks
; i
++) {
1856 kfree(parser
->chunks
[i
].kdata
);
1857 kfree(parser
->chunks
[i
].kpage
[0]);
1858 kfree(parser
->chunks
[i
].kpage
[1]);
1860 kfree(parser
->chunks
);
1861 kfree(parser
->chunks_array
);
1864 int r600_cs_legacy(struct drm_device
*dev
, void *data
, struct drm_file
*filp
,
1865 unsigned family
, u32
*ib
, int *l
)
1867 struct radeon_cs_parser parser
;
1868 struct radeon_cs_chunk
*ib_chunk
;
1869 struct radeon_ib fake_ib
;
1870 struct r600_cs_track
*track
;
1873 /* initialize tracker */
1874 track
= kzalloc(sizeof(*track
), GFP_KERNEL
);
1877 r600_cs_track_init(track
);
1878 r600_cs_legacy_get_tiling_conf(dev
, &track
->npipes
, &track
->nbanks
, &track
->group_size
);
1879 /* initialize parser */
1880 memset(&parser
, 0, sizeof(struct radeon_cs_parser
));
1882 parser
.dev
= &dev
->pdev
->dev
;
1884 parser
.family
= family
;
1885 parser
.ib
= &fake_ib
;
1886 parser
.track
= track
;
1888 r
= radeon_cs_parser_init(&parser
, data
);
1890 DRM_ERROR("Failed to initialize parser !\n");
1891 r600_cs_parser_fini(&parser
, r
);
1894 r
= r600_cs_parser_relocs_legacy(&parser
);
1896 DRM_ERROR("Failed to parse relocation !\n");
1897 r600_cs_parser_fini(&parser
, r
);
1900 /* Copy the packet into the IB, the parser will read from the
1901 * input memory (cached) and write to the IB (which can be
1903 ib_chunk
= &parser
.chunks
[parser
.chunk_ib_idx
];
1904 parser
.ib
->length_dw
= ib_chunk
->length_dw
;
1905 *l
= parser
.ib
->length_dw
;
1906 r
= r600_cs_parse(&parser
);
1908 DRM_ERROR("Invalid command stream !\n");
1909 r600_cs_parser_fini(&parser
, r
);
1912 r
= radeon_cs_finish_pages(&parser
);
1914 DRM_ERROR("Invalid command stream !\n");
1915 r600_cs_parser_fini(&parser
, r
);
1918 r600_cs_parser_fini(&parser
, r
);
1922 void r600_cs_legacy_init(void)
1924 r600_cs_packet_next_reloc
= &r600_cs_packet_next_reloc_nomm
;