aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/radeon/radeon_cs.c
diff options
context:
space:
mode:
authorIlija Hadzic <ihadzic@research.bell-labs.com>2013-01-02 18:27:40 -0500
committerAlex Deucher <alexander.deucher@amd.com>2013-01-31 16:24:41 -0500
commit4db013110cd3da05e4cf7e1119468817709cb9db (patch)
tree83879ac01d8890bd9d7cbefc2334638fe7022fb8 /drivers/gpu/drm/radeon/radeon_cs.c
parent66b3543ef38216bdaf529a207fb495c500eb98be (diff)
drm/radeon: implement common cs packet parse function
CS packet parse functions have a lot of in common across all ASICs. Implement a common function and take care of small differences between families inside the function. This patch is a prep for major refactoring and consolidation of CS parsing code. Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com> Reviewed-by: Marek Olšák <maraeo@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/radeon/radeon_cs.c')
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index 0a23589e3d40..7355a3613e23 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -642,3 +642,56 @@ u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
642 idx_value = ibc->kpage[new_page][pg_offset/4]; 642 idx_value = ibc->kpage[new_page][pg_offset/4];
643 return idx_value; 643 return idx_value;
644} 644}
645
646/**
647 * radeon_cs_packet_parse() - parse cp packet and point ib index to next packet
648 * @parser: parser structure holding parsing context.
649 * @pkt: where to store packet information
650 *
651 * Assume that chunk_ib_index is properly set. Will return -EINVAL
652 * if packet is bigger than remaining ib size. or if packets is unknown.
653 **/
654int radeon_cs_packet_parse(struct radeon_cs_parser *p,
655 struct radeon_cs_packet *pkt,
656 unsigned idx)
657{
658 struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
659 struct radeon_device *rdev = p->rdev;
660 uint32_t header;
661
662 if (idx >= ib_chunk->length_dw) {
663 DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
664 idx, ib_chunk->length_dw);
665 return -EINVAL;
666 }
667 header = radeon_get_ib_value(p, idx);
668 pkt->idx = idx;
669 pkt->type = RADEON_CP_PACKET_GET_TYPE(header);
670 pkt->count = RADEON_CP_PACKET_GET_COUNT(header);
671 pkt->one_reg_wr = 0;
672 switch (pkt->type) {
673 case RADEON_PACKET_TYPE0:
674 if (rdev->family < CHIP_R600) {
675 pkt->reg = R100_CP_PACKET0_GET_REG(header);
676 pkt->one_reg_wr =
677 RADEON_CP_PACKET0_GET_ONE_REG_WR(header);
678 } else
679 pkt->reg = R600_CP_PACKET0_GET_REG(header);
680 break;
681 case RADEON_PACKET_TYPE3:
682 pkt->opcode = RADEON_CP_PACKET3_GET_OPCODE(header);
683 break;
684 case RADEON_PACKET_TYPE2:
685 pkt->count = -1;
686 break;
687 default:
688 DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
689 return -EINVAL;
690 }
691 if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
692 DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
693 pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
694 return -EINVAL;
695 }
696 return 0;
697}