aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlija Hadzic <ihadzic@research.bell-labs.com>2013-01-02 18:27:41 -0500
committerAlex Deucher <alexander.deucher@amd.com>2013-01-31 16:24:42 -0500
commitc38f34b53e74dec4e58fef0c895d9e6df7da1190 (patch)
tree0e1cd86a565d02cf7d4bb73a09869a4296ea2241
parent4db013110cd3da05e4cf7e1119468817709cb9db (diff)
drm/radeon: use common cs packet parse function
We now have a common radeon_cs_packet_parse function that is good for all ASICs. Hook it up and eliminate ASIC-specific versions. 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>
-rw-r--r--drivers/gpu/drm/radeon/evergreen_cs.c57
-rw-r--r--drivers/gpu/drm/radeon/r100.c55
-rw-r--r--drivers/gpu/drm/radeon/r300.c2
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c59
-rw-r--r--drivers/gpu/drm/radeon/radeon.h4
5 files changed, 20 insertions, 157 deletions
diff --git a/drivers/gpu/drm/radeon/evergreen_cs.c b/drivers/gpu/drm/radeon/evergreen_cs.c
index 7a445666e71f..1ba4ca38f4f9 100644
--- a/drivers/gpu/drm/radeon/evergreen_cs.c
+++ b/drivers/gpu/drm/radeon/evergreen_cs.c
@@ -1009,53 +1009,6 @@ static int evergreen_cs_track_check(struct radeon_cs_parser *p)
1009} 1009}
1010 1010
1011/** 1011/**
1012 * evergreen_cs_packet_parse() - parse cp packet and point ib index to next packet
1013 * @parser: parser structure holding parsing context.
1014 * @pkt: where to store packet informations
1015 *
1016 * Assume that chunk_ib_index is properly set. Will return -EINVAL
1017 * if packet is bigger than remaining ib size. or if packets is unknown.
1018 **/
1019static int evergreen_cs_packet_parse(struct radeon_cs_parser *p,
1020 struct radeon_cs_packet *pkt,
1021 unsigned idx)
1022{
1023 struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
1024 uint32_t header;
1025
1026 if (idx >= ib_chunk->length_dw) {
1027 DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
1028 idx, ib_chunk->length_dw);
1029 return -EINVAL;
1030 }
1031 header = radeon_get_ib_value(p, idx);
1032 pkt->idx = idx;
1033 pkt->type = CP_PACKET_GET_TYPE(header);
1034 pkt->count = CP_PACKET_GET_COUNT(header);
1035 pkt->one_reg_wr = 0;
1036 switch (pkt->type) {
1037 case PACKET_TYPE0:
1038 pkt->reg = CP_PACKET0_GET_REG(header);
1039 break;
1040 case PACKET_TYPE3:
1041 pkt->opcode = CP_PACKET3_GET_OPCODE(header);
1042 break;
1043 case PACKET_TYPE2:
1044 pkt->count = -1;
1045 break;
1046 default:
1047 DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
1048 return -EINVAL;
1049 }
1050 if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
1051 DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
1052 pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
1053 return -EINVAL;
1054 }
1055 return 0;
1056}
1057
1058/**
1059 * evergreen_cs_packet_next_reloc() - parse next packet which should be reloc packet3 1012 * evergreen_cs_packet_next_reloc() - parse next packet which should be reloc packet3
1060 * @parser: parser structure holding parsing context. 1013 * @parser: parser structure holding parsing context.
1061 * @data: pointer to relocation data 1014 * @data: pointer to relocation data
@@ -1080,7 +1033,7 @@ static int evergreen_cs_packet_next_reloc(struct radeon_cs_parser *p,
1080 } 1033 }
1081 *cs_reloc = NULL; 1034 *cs_reloc = NULL;
1082 relocs_chunk = &p->chunks[p->chunk_relocs_idx]; 1035 relocs_chunk = &p->chunks[p->chunk_relocs_idx];
1083 r = evergreen_cs_packet_parse(p, &p3reloc, p->idx); 1036 r = radeon_cs_packet_parse(p, &p3reloc, p->idx);
1084 if (r) { 1037 if (r) {
1085 return r; 1038 return r;
1086 } 1039 }
@@ -1112,7 +1065,7 @@ static bool evergreen_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p)
1112 struct radeon_cs_packet p3reloc; 1065 struct radeon_cs_packet p3reloc;
1113 int r; 1066 int r;
1114 1067
1115 r = evergreen_cs_packet_parse(p, &p3reloc, p->idx); 1068 r = radeon_cs_packet_parse(p, &p3reloc, p->idx);
1116 if (r) { 1069 if (r) {
1117 return false; 1070 return false;
1118 } 1071 }
@@ -1150,7 +1103,7 @@ static int evergreen_cs_packet_parse_vline(struct radeon_cs_parser *p)
1150 ib = p->ib.ptr; 1103 ib = p->ib.ptr;
1151 1104
1152 /* parse the WAIT_REG_MEM */ 1105 /* parse the WAIT_REG_MEM */
1153 r = evergreen_cs_packet_parse(p, &wait_reg_mem, p->idx); 1106 r = radeon_cs_packet_parse(p, &wait_reg_mem, p->idx);
1154 if (r) 1107 if (r)
1155 return r; 1108 return r;
1156 1109
@@ -1183,7 +1136,7 @@ static int evergreen_cs_packet_parse_vline(struct radeon_cs_parser *p)
1183 } 1136 }
1184 1137
1185 /* jump over the NOP */ 1138 /* jump over the NOP */
1186 r = evergreen_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2); 1139 r = radeon_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2);
1187 if (r) 1140 if (r)
1188 return r; 1141 return r;
1189 1142
@@ -2819,7 +2772,7 @@ int evergreen_cs_parse(struct radeon_cs_parser *p)
2819 p->track = track; 2772 p->track = track;
2820 } 2773 }
2821 do { 2774 do {
2822 r = evergreen_cs_packet_parse(p, &pkt, p->idx); 2775 r = radeon_cs_packet_parse(p, &pkt, p->idx);
2823 if (r) { 2776 if (r) {
2824 kfree(p->track); 2777 kfree(p->track);
2825 p->track = NULL; 2778 p->track = NULL;
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 40c0318b1eef..7842447da4fb 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -1370,53 +1370,6 @@ void r100_cs_dump_packet(struct radeon_cs_parser *p,
1370} 1370}
1371 1371
1372/** 1372/**
1373 * r100_cs_packet_parse() - parse cp packet and point ib index to next packet
1374 * @parser: parser structure holding parsing context.
1375 * @pkt: where to store packet informations
1376 *
1377 * Assume that chunk_ib_index is properly set. Will return -EINVAL
1378 * if packet is bigger than remaining ib size. or if packets is unknown.
1379 **/
1380int r100_cs_packet_parse(struct radeon_cs_parser *p,
1381 struct radeon_cs_packet *pkt,
1382 unsigned idx)
1383{
1384 struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
1385 uint32_t header;
1386
1387 if (idx >= ib_chunk->length_dw) {
1388 DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
1389 idx, ib_chunk->length_dw);
1390 return -EINVAL;
1391 }
1392 header = radeon_get_ib_value(p, idx);
1393 pkt->idx = idx;
1394 pkt->type = CP_PACKET_GET_TYPE(header);
1395 pkt->count = CP_PACKET_GET_COUNT(header);
1396 switch (pkt->type) {
1397 case PACKET_TYPE0:
1398 pkt->reg = CP_PACKET0_GET_REG(header);
1399 pkt->one_reg_wr = CP_PACKET0_GET_ONE_REG_WR(header);
1400 break;
1401 case PACKET_TYPE3:
1402 pkt->opcode = CP_PACKET3_GET_OPCODE(header);
1403 break;
1404 case PACKET_TYPE2:
1405 pkt->count = -1;
1406 break;
1407 default:
1408 DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
1409 return -EINVAL;
1410 }
1411 if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
1412 DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
1413 pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
1414 return -EINVAL;
1415 }
1416 return 0;
1417}
1418
1419/**
1420 * r100_cs_packet_next_vline() - parse userspace VLINE packet 1373 * r100_cs_packet_next_vline() - parse userspace VLINE packet
1421 * @parser: parser structure holding parsing context. 1374 * @parser: parser structure holding parsing context.
1422 * 1375 *
@@ -1444,7 +1397,7 @@ int r100_cs_packet_parse_vline(struct radeon_cs_parser *p)
1444 ib = p->ib.ptr; 1397 ib = p->ib.ptr;
1445 1398
1446 /* parse the wait until */ 1399 /* parse the wait until */
1447 r = r100_cs_packet_parse(p, &waitreloc, p->idx); 1400 r = radeon_cs_packet_parse(p, &waitreloc, p->idx);
1448 if (r) 1401 if (r)
1449 return r; 1402 return r;
1450 1403
@@ -1461,7 +1414,7 @@ int r100_cs_packet_parse_vline(struct radeon_cs_parser *p)
1461 } 1414 }
1462 1415
1463 /* jump over the NOP */ 1416 /* jump over the NOP */
1464 r = r100_cs_packet_parse(p, &p3reloc, p->idx + waitreloc.count + 2); 1417 r = radeon_cs_packet_parse(p, &p3reloc, p->idx + waitreloc.count + 2);
1465 if (r) 1418 if (r)
1466 return r; 1419 return r;
1467 1420
@@ -1531,7 +1484,7 @@ int r100_cs_packet_next_reloc(struct radeon_cs_parser *p,
1531 } 1484 }
1532 *cs_reloc = NULL; 1485 *cs_reloc = NULL;
1533 relocs_chunk = &p->chunks[p->chunk_relocs_idx]; 1486 relocs_chunk = &p->chunks[p->chunk_relocs_idx];
1534 r = r100_cs_packet_parse(p, &p3reloc, p->idx); 1487 r = radeon_cs_packet_parse(p, &p3reloc, p->idx);
1535 if (r) { 1488 if (r) {
1536 return r; 1489 return r;
1537 } 1490 }
@@ -2100,7 +2053,7 @@ int r100_cs_parse(struct radeon_cs_parser *p)
2100 r100_cs_track_clear(p->rdev, track); 2053 r100_cs_track_clear(p->rdev, track);
2101 p->track = track; 2054 p->track = track;
2102 do { 2055 do {
2103 r = r100_cs_packet_parse(p, &pkt, p->idx); 2056 r = radeon_cs_packet_parse(p, &pkt, p->idx);
2104 if (r) { 2057 if (r) {
2105 return r; 2058 return r;
2106 } 2059 }
diff --git a/drivers/gpu/drm/radeon/r300.c b/drivers/gpu/drm/radeon/r300.c
index d0ba6023a1f8..34ca46e46347 100644
--- a/drivers/gpu/drm/radeon/r300.c
+++ b/drivers/gpu/drm/radeon/r300.c
@@ -1257,7 +1257,7 @@ int r300_cs_parse(struct radeon_cs_parser *p)
1257 r100_cs_track_clear(p->rdev, track); 1257 r100_cs_track_clear(p->rdev, track);
1258 p->track = track; 1258 p->track = track;
1259 do { 1259 do {
1260 r = r100_cs_packet_parse(p, &pkt, p->idx); 1260 r = radeon_cs_packet_parse(p, &pkt, p->idx);
1261 if (r) { 1261 if (r) {
1262 return r; 1262 return r;
1263 } 1263 }
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index 69ec24ab8d63..3870bf8c1bc7 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -784,53 +784,6 @@ static int r600_cs_track_check(struct radeon_cs_parser *p)
784} 784}
785 785
786/** 786/**
787 * r600_cs_packet_parse() - parse cp packet and point ib index to next packet
788 * @parser: parser structure holding parsing context.
789 * @pkt: where to store packet informations
790 *
791 * Assume that chunk_ib_index is properly set. Will return -EINVAL
792 * if packet is bigger than remaining ib size. or if packets is unknown.
793 **/
794static int r600_cs_packet_parse(struct radeon_cs_parser *p,
795 struct radeon_cs_packet *pkt,
796 unsigned idx)
797{
798 struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
799 uint32_t header;
800
801 if (idx >= ib_chunk->length_dw) {
802 DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
803 idx, ib_chunk->length_dw);
804 return -EINVAL;
805 }
806 header = radeon_get_ib_value(p, idx);
807 pkt->idx = idx;
808 pkt->type = CP_PACKET_GET_TYPE(header);
809 pkt->count = CP_PACKET_GET_COUNT(header);
810 pkt->one_reg_wr = 0;
811 switch (pkt->type) {
812 case PACKET_TYPE0:
813 pkt->reg = CP_PACKET0_GET_REG(header);
814 break;
815 case PACKET_TYPE3:
816 pkt->opcode = CP_PACKET3_GET_OPCODE(header);
817 break;
818 case PACKET_TYPE2:
819 pkt->count = -1;
820 break;
821 default:
822 DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
823 return -EINVAL;
824 }
825 if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
826 DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
827 pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
828 return -EINVAL;
829 }
830 return 0;
831}
832
833/**
834 * r600_cs_packet_next_reloc_mm() - parse next packet which should be reloc packet3 787 * r600_cs_packet_next_reloc_mm() - parse next packet which should be reloc packet3
835 * @parser: parser structure holding parsing context. 788 * @parser: parser structure holding parsing context.
836 * @data: pointer to relocation data 789 * @data: pointer to relocation data
@@ -855,7 +808,7 @@ static int r600_cs_packet_next_reloc_mm(struct radeon_cs_parser *p,
855 } 808 }
856 *cs_reloc = NULL; 809 *cs_reloc = NULL;
857 relocs_chunk = &p->chunks[p->chunk_relocs_idx]; 810 relocs_chunk = &p->chunks[p->chunk_relocs_idx];
858 r = r600_cs_packet_parse(p, &p3reloc, p->idx); 811 r = radeon_cs_packet_parse(p, &p3reloc, p->idx);
859 if (r) { 812 if (r) {
860 return r; 813 return r;
861 } 814 }
@@ -901,7 +854,7 @@ static int r600_cs_packet_next_reloc_nomm(struct radeon_cs_parser *p,
901 } 854 }
902 *cs_reloc = NULL; 855 *cs_reloc = NULL;
903 relocs_chunk = &p->chunks[p->chunk_relocs_idx]; 856 relocs_chunk = &p->chunks[p->chunk_relocs_idx];
904 r = r600_cs_packet_parse(p, &p3reloc, p->idx); 857 r = radeon_cs_packet_parse(p, &p3reloc, p->idx);
905 if (r) { 858 if (r) {
906 return r; 859 return r;
907 } 860 }
@@ -935,7 +888,7 @@ static int r600_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p)
935 struct radeon_cs_packet p3reloc; 888 struct radeon_cs_packet p3reloc;
936 int r; 889 int r;
937 890
938 r = r600_cs_packet_parse(p, &p3reloc, p->idx); 891 r = radeon_cs_packet_parse(p, &p3reloc, p->idx);
939 if (r) { 892 if (r) {
940 return 0; 893 return 0;
941 } 894 }
@@ -973,7 +926,7 @@ static int r600_cs_packet_parse_vline(struct radeon_cs_parser *p)
973 ib = p->ib.ptr; 926 ib = p->ib.ptr;
974 927
975 /* parse the WAIT_REG_MEM */ 928 /* parse the WAIT_REG_MEM */
976 r = r600_cs_packet_parse(p, &wait_reg_mem, p->idx); 929 r = radeon_cs_packet_parse(p, &wait_reg_mem, p->idx);
977 if (r) 930 if (r)
978 return r; 931 return r;
979 932
@@ -1006,7 +959,7 @@ static int r600_cs_packet_parse_vline(struct radeon_cs_parser *p)
1006 } 959 }
1007 960
1008 /* jump over the NOP */ 961 /* jump over the NOP */
1009 r = r600_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2); 962 r = radeon_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2);
1010 if (r) 963 if (r)
1011 return r; 964 return r;
1012 965
@@ -2410,7 +2363,7 @@ int r600_cs_parse(struct radeon_cs_parser *p)
2410 p->track = track; 2363 p->track = track;
2411 } 2364 }
2412 do { 2365 do {
2413 r = r600_cs_packet_parse(p, &pkt, p->idx); 2366 r = radeon_cs_packet_parse(p, &pkt, p->idx);
2414 if (r) { 2367 if (r) {
2415 kfree(p->track); 2368 kfree(p->track);
2416 p->track = NULL; 2369 p->track = NULL;
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index a08f657329a0..b8d1c5c0c2c6 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -1972,6 +1972,10 @@ static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
1972static inline void radeon_acpi_fini(struct radeon_device *rdev) { } 1972static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
1973#endif 1973#endif
1974 1974
1975int radeon_cs_packet_parse(struct radeon_cs_parser *p,
1976 struct radeon_cs_packet *pkt,
1977 unsigned idx);
1978
1975#include "radeon_object.h" 1979#include "radeon_object.h"
1976 1980
1977#endif 1981#endif