40 #include <asm/unaligned.h>
42 #define R300_SIMULTANEOUS_CLIPRECTS 4
46 static const int r300_cliprect_cntl[4] = {
65 nr = cmdbuf->
nbox -
n;
69 DRM_DEBUG(
"%i cliprects\n", nr);
75 for (i = 0; i <
nr; ++
i) {
77 (&box, &cmdbuf->
boxes[n + i],
sizeof(box))) {
78 DRM_ERROR(
"copy cliprect faulted\n");
159 static u8 r300_reg_flags[0x10000 >> 2];
166 memset(r300_reg_flags, 0, 0x10000 >> 2);
167 #define ADD_RANGE_MARK(reg, count,mark) \
168 for(i=((reg)>>2);i<((reg)>>2)+(count);i++)\
169 r300_reg_flags[i]|=(mark);
172 #define MARK_CHECK_OFFSET 2
174 #define ADD_RANGE(reg, count) ADD_RANGE_MARK(reg, count, MARK_SAFE)
286 for (i = (reg >> 2); i < (reg >> 2) + count; i++)
287 if (r300_reg_flags[i] != MARK_SAFE)
308 if ((sz > 64) || (sz < 0)) {
309 DRM_ERROR(
"Cannot emit more than 64 values at a time (reg=%04x sz=%d)\n",
314 for (i = 0; i < sz; i++) {
315 switch (r300_reg_flags[(reg >> 2) + i]) {
319 value = drm_buffer_pointer_to_dword(cmdbuf->
buffer, i);
320 if (!radeon_check_offset(dev_priv, *value)) {
321 DRM_ERROR(
"Offset failed range check (reg=%04x sz=%d)\n",
327 DRM_ERROR(
"Register %04x failed check as flag=%02x\n",
328 reg + i * 4, r300_reg_flags[(reg >> 2) + i]);
361 if (sz * 4 > drm_buffer_unprocessed(cmdbuf->
buffer))
364 if (reg + sz * 4 >= 0x10000) {
365 DRM_ERROR(
"No such registers in hardware reg=%04x sz=%d\n", reg,
370 if (r300_check_range(reg, sz)) {
372 return r300_emit_carefully_checked_packet0(dev_priv, cmdbuf,
398 sz = header.
vpu.count;
399 addr = (header.
vpu.adrhi << 8) | header.
vpu.adrlo;
403 if (sz * 16 > drm_buffer_unprocessed(cmdbuf->
buffer))
442 if (8 * 4 > drm_buffer_unprocessed(cmdbuf->
buffer))
469 #define MAX_ARRAY_PACKET 64
477 DRM_ERROR(
"Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
484 drm_buffer_advance(cmdbuf->
buffer, 4);
486 narrays = *(
u32 *)drm_buffer_pointer_to_dword(cmdbuf->
buffer, 0);
489 while ((k < narrays) && (i < (count + 1))) {
491 data = drm_buffer_pointer_to_dword(cmdbuf->
buffer, i);
492 if (!radeon_check_offset(dev_priv, *data)) {
494 (
"Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
503 data = drm_buffer_pointer_to_dword(cmdbuf->
buffer, i);
504 if (!radeon_check_offset(dev_priv, *data)) {
506 (
"Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
514 if ((k != narrays) || (i != (count + 1))) {
516 (
"Malformed 3D_LOAD_VBPNTR packet (k=%d i=%d narrays=%d count+1=%d).\n",
517 k, i, narrays, count + 1);
534 u32 *
cmd = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 0);
543 u32 *cmd1 = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 1);
547 u32 *cmd2 = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 2);
548 offset = *cmd2 << 10;
549 ret = !radeon_check_offset(dev_priv, offset);
551 DRM_ERROR(
"Invalid bitblt first offset is %08X\n", offset);
558 u32 *cmd3 = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 3);
559 offset = *cmd3 << 10;
560 ret = !radeon_check_offset(dev_priv, offset);
562 DRM_ERROR(
"Invalid bitblt second offset is %08X\n", offset);
579 u32 *cmd = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 0);
580 u32 *cmd1 = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 1);
587 expected_count = *cmd1 >> 16;
589 expected_count = (expected_count+1)/2;
591 if (count && count != expected_count) {
592 DRM_ERROR(
"3D_DRAW_INDX_2: packet size %i, expected %i\n",
593 count, expected_count);
603 u32 *cmd1, *cmd2, *cmd3;
605 if (drm_buffer_unprocessed(cmdbuf->
buffer)
606 < 4*4 +
sizeof(stack_header)) {
607 DRM_ERROR(
"3D_DRAW_INDX_2: expect subsequent INDX_BUFFER, but stream is too short.\n");
612 sizeof(stack_header), &stack_header);
614 cmd = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 0);
615 cmd1 = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 1);
616 cmd2 = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 2);
617 cmd3 = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 3);
622 DRM_ERROR(
"3D_DRAW_INDX_2: expect subsequent INDX_BUFFER.\n");
626 if ((*cmd1 & 0x8000ffff) != 0x80000810) {
627 DRM_ERROR(
"Invalid indx_buffer reg address %08X\n",
631 if (!radeon_check_offset(dev_priv, *cmd2)) {
632 DRM_ERROR(
"Invalid indx_buffer offset is %08X\n",
636 if (*cmd3 != expected_count) {
637 DRM_ERROR(
"INDX_BUFFER: buffer size %i, expected %i\n",
638 *cmd3, expected_count);
657 if (4 > drm_buffer_unprocessed(cmdbuf->
buffer))
664 header = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 0);
667 if ((*header >> 30) != 0x3) {
668 DRM_ERROR(
"Not a packet3 header (0x%08x)\n", *header);
672 count = (*header >> 16) & 0x3fff;
675 if ((count + 2) * 4 > drm_buffer_unprocessed(cmdbuf->
buffer)) {
677 (
"Expected packet3 of length %d but have only %d bytes left\n",
678 (count + 2) * 4, drm_buffer_unprocessed(cmdbuf->
buffer));
683 switch (*header & 0xff00) {
685 return r300_emit_3d_load_vbpntr(dev_priv, cmdbuf, *header);
688 return r300_emit_bitblt_multi(dev_priv, cmdbuf);
691 DRM_ERROR(
"packet3 INDX_BUFFER without preceding 3D_DRAW_INDX_2 is illegal.\n");
705 return r300_emit_draw_indx_2(dev_priv, cmdbuf);
711 DRM_ERROR(
"Unknown packet3 header (0x%08x)\n", *header);
732 int orig_iter = cmdbuf->
buffer->iterator;
740 ret = r300_emit_cliprects(dev_priv, cmdbuf, n);
744 cmdbuf->
buffer->iterator = orig_iter;
747 switch (header.
packet3.packet) {
749 DRM_DEBUG(
"R300_CMD_PACKET3_CLEAR\n");
750 ret = r300_emit_clear(dev_priv, cmdbuf);
752 DRM_ERROR(
"r300_emit_clear failed\n");
758 DRM_DEBUG(
"R300_CMD_PACKET3_RAW\n");
759 ret = r300_emit_raw_packet3(dev_priv, cmdbuf);
761 DRM_ERROR(
"r300_emit_raw_packet3 failed\n");
767 DRM_ERROR(
"bad packet3 type %i at byte %d\n",
769 cmdbuf->
buffer->iterator - (
int)
sizeof(header));
774 }
while (n < cmdbuf->nbox);
795 uint32_t cache_z, cache_3d, cache_2d;
849 static void r300_discard_buffer(
struct drm_device *
dev,
struct drm_master *master,
struct drm_buf *
buf)
865 if (!header.
wait.flags)
870 switch(header.
wait.flags) {
905 u32 i, *buf_idx, h_pending;
910 if (drm_buffer_unprocessed(cmdbuf->
buffer) <
911 (
sizeof(
u64) + header.
scratch.n_bufs *
sizeof(*buf_idx))) {
922 sizeof(stack_ptr_addr), &stack_ptr_addr);
925 for (i=0; i < header.
scratch.n_bufs; i++) {
926 buf_idx = drm_buffer_pointer_to_dword(cmdbuf->
buffer, 0);
935 ref_age_base + *buf_idx + 1,
949 drm_buffer_advance(cmdbuf->
buffer,
sizeof(*buf_idx));
978 addr = ((header.
r500fp.adrhi_flags & 1) << 8) | header.
r500fp.adrlo;
983 addr |= (type << 16);
984 addr |= (isclamp << 17);
986 stride = type ? 4 : 6;
988 DRM_DEBUG(
"r500fp %d %d type: %d\n", sz, addr, type);
991 if (sz * stride * 4 > drm_buffer_unprocessed(cmdbuf->
buffer))
1011 struct drm_file *file_priv,
1016 struct drm_device_dma *
dma = dev->dma;
1018 int emit_dispatch_age = 0;
1024 r300_pacify(dev_priv);
1027 ret = r300_emit_cliprects(dev_priv, cmdbuf, 0);
1032 while (drm_buffer_unprocessed(cmdbuf->
buffer)
1038 sizeof(stack_header), &stack_header);
1040 switch (header->
header.cmd_type) {
1042 DRM_DEBUG(
"R300_CMD_PACKET0\n");
1043 ret = r300_emit_packet0(dev_priv, cmdbuf, *header);
1045 DRM_ERROR(
"r300_emit_packet0 failed\n");
1051 DRM_DEBUG(
"R300_CMD_VPU\n");
1052 ret = r300_emit_vpu(dev_priv, cmdbuf, *header);
1054 DRM_ERROR(
"r300_emit_vpu failed\n");
1060 DRM_DEBUG(
"R300_CMD_PACKET3\n");
1061 ret = r300_emit_packet3(dev_priv, cmdbuf, *header);
1063 DRM_ERROR(
"r300_emit_packet3 failed\n");
1069 DRM_DEBUG(
"R300_CMD_END3D\n");
1085 r300_pacify(dev_priv);
1090 DRM_DEBUG(
"R300_CMD_CP_DELAY\n");
1096 for (i = 0; i < header->
delay.count; i++)
1103 DRM_DEBUG(
"RADEON_CMD_DMA_DISCARD\n");
1104 idx = header->
dma.buf_idx;
1105 if (idx < 0 || idx >= dma->buf_count) {
1106 DRM_ERROR(
"buffer index %d (of %d max)\n",
1107 idx, dma->buf_count - 1);
1112 buf = dma->buflist[
idx];
1113 if (buf->file_priv != file_priv || buf->pending) {
1114 DRM_ERROR(
"bad buffer %p %p %d\n",
1115 buf->file_priv, file_priv,
1121 emit_dispatch_age = 1;
1122 r300_discard_buffer(dev, file_priv->master, buf);
1126 DRM_DEBUG(
"R300_CMD_WAIT\n");
1127 r300_cmd_wait(dev_priv, *header);
1131 DRM_DEBUG(
"R300_CMD_SCRATCH\n");
1132 ret = r300_scratch(dev_priv, cmdbuf, *header);
1134 DRM_ERROR(
"r300_scratch failed\n");
1141 DRM_ERROR(
"Calling r500 command on r300 card\n");
1145 DRM_DEBUG(
"R300_CMD_R500FP\n");
1146 ret = r300_emit_r500fp(dev_priv, cmdbuf, *header);
1148 DRM_ERROR(
"r300_emit_r500fp failed\n");
1153 DRM_ERROR(
"bad cmd_type %i at byte %d\n",
1155 cmdbuf->
buffer->iterator - (
int)
sizeof(*header));
1164 r300_pacify(dev_priv);
1172 if (emit_dispatch_age) {