Skip to content

Commit 28f75f9

Browse files
pldrcalexdeucher
authored andcommitted
drm/amdgpu/jpeg: Move parse_cs to amdgpu_jpeg.c
Rename jpeg_v2_dec_ring_parse_cs to amdgpu_jpeg_dec_parse_cs and move it to amdgpu_jpeg.c as it is shared among jpeg versions. Signed-off-by: Sathishkumar S <sathishkumar.sundararaju@amd.com> Reviewed-by: Leo Liu <leo.liu@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 1697398 commit 28f75f9

File tree

10 files changed

+83
-70
lines changed

10 files changed

+83
-70
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,68 @@ void amdgpu_jpeg_print_ip_state(struct amdgpu_ip_block *ip_block, struct drm_pri
539539
drm_printf(p, "\nInactive Instance:JPEG%d\n", i);
540540
}
541541
}
542+
543+
static inline bool amdgpu_jpeg_reg_valid(u32 reg)
544+
{
545+
if (reg < JPEG_REG_RANGE_START || reg > JPEG_REG_RANGE_END ||
546+
(reg >= JPEG_ATOMIC_RANGE_START && reg <= JPEG_ATOMIC_RANGE_END))
547+
return false;
548+
else
549+
return true;
550+
}
551+
552+
/**
553+
* amdgpu_jpeg_dec_parse_cs - command submission parser
554+
*
555+
* @parser: Command submission parser context
556+
* @job: the job to parse
557+
* @ib: the IB to parse
558+
*
559+
* Parse the command stream, return -EINVAL for invalid packet,
560+
* 0 otherwise
561+
*/
562+
563+
int amdgpu_jpeg_dec_parse_cs(struct amdgpu_cs_parser *parser,
564+
struct amdgpu_job *job,
565+
struct amdgpu_ib *ib)
566+
{
567+
u32 i, reg, res, cond, type;
568+
struct amdgpu_device *adev = parser->adev;
569+
570+
for (i = 0; i < ib->length_dw ; i += 2) {
571+
reg = CP_PACKETJ_GET_REG(ib->ptr[i]);
572+
res = CP_PACKETJ_GET_RES(ib->ptr[i]);
573+
cond = CP_PACKETJ_GET_COND(ib->ptr[i]);
574+
type = CP_PACKETJ_GET_TYPE(ib->ptr[i]);
575+
576+
if (res) /* only support 0 at the moment */
577+
return -EINVAL;
578+
579+
switch (type) {
580+
case PACKETJ_TYPE0:
581+
if (cond != PACKETJ_CONDITION_CHECK0 ||
582+
!amdgpu_jpeg_reg_valid(reg)) {
583+
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
584+
return -EINVAL;
585+
}
586+
break;
587+
case PACKETJ_TYPE3:
588+
if (cond != PACKETJ_CONDITION_CHECK3 ||
589+
!amdgpu_jpeg_reg_valid(reg)) {
590+
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
591+
return -EINVAL;
592+
}
593+
break;
594+
case PACKETJ_TYPE6:
595+
if (ib->ptr[i] == CP_PACKETJ_NOP)
596+
continue;
597+
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
598+
return -EINVAL;
599+
default:
600+
dev_err(adev->dev, "Unknown packet type %d !\n", type);
601+
return -EINVAL;
602+
}
603+
}
604+
605+
return 0;
606+
}

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@
2525
#define __AMDGPU_JPEG_H__
2626

2727
#include "amdgpu_ras.h"
28+
#include "amdgpu_cs.h"
2829

2930
#define AMDGPU_MAX_JPEG_INSTANCES 4
3031
#define AMDGPU_MAX_JPEG_RINGS 10
3132
#define AMDGPU_MAX_JPEG_RINGS_4_0_3 8
3233

34+
#define JPEG_REG_RANGE_START 0x4000
35+
#define JPEG_REG_RANGE_END 0x41c2
36+
#define JPEG_ATOMIC_RANGE_START 0x4120
37+
#define JPEG_ATOMIC_RANGE_END 0x412A
38+
39+
3340
#define AMDGPU_JPEG_HARVEST_JPEG0 (1 << 0)
3441
#define AMDGPU_JPEG_HARVEST_JPEG1 (1 << 1)
3542

@@ -170,5 +177,8 @@ int amdgpu_jpeg_reg_dump_init(struct amdgpu_device *adev,
170177
const struct amdgpu_hwip_reg_entry *reg, u32 count);
171178
void amdgpu_jpeg_dump_ip_state(struct amdgpu_ip_block *ip_block);
172179
void amdgpu_jpeg_print_ip_state(struct amdgpu_ip_block *ip_block, struct drm_printer *p);
180+
int amdgpu_jpeg_dec_parse_cs(struct amdgpu_cs_parser *parser,
181+
struct amdgpu_job *job,
182+
struct amdgpu_ib *ib);
173183

174184
#endif /*__AMDGPU_JPEG_H__*/

drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "amdgpu.h"
2525
#include "amdgpu_jpeg.h"
26-
#include "amdgpu_cs.h"
2726
#include "amdgpu_pm.h"
2827
#include "soc15.h"
2928
#include "soc15d.h"
@@ -806,7 +805,7 @@ static const struct amdgpu_ring_funcs jpeg_v2_0_dec_ring_vm_funcs = {
806805
.get_rptr = jpeg_v2_0_dec_ring_get_rptr,
807806
.get_wptr = jpeg_v2_0_dec_ring_get_wptr,
808807
.set_wptr = jpeg_v2_0_dec_ring_set_wptr,
809-
.parse_cs = jpeg_v2_dec_ring_parse_cs,
808+
.parse_cs = amdgpu_jpeg_dec_parse_cs,
810809
.emit_frame_size =
811810
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
812811
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +
@@ -854,58 +853,3 @@ const struct amdgpu_ip_block_version jpeg_v2_0_ip_block = {
854853
.rev = 0,
855854
.funcs = &jpeg_v2_0_ip_funcs,
856855
};
857-
858-
/**
859-
* jpeg_v2_dec_ring_parse_cs - command submission parser
860-
*
861-
* @parser: Command submission parser context
862-
* @job: the job to parse
863-
* @ib: the IB to parse
864-
*
865-
* Parse the command stream, return -EINVAL for invalid packet,
866-
* 0 otherwise
867-
*/
868-
int jpeg_v2_dec_ring_parse_cs(struct amdgpu_cs_parser *parser,
869-
struct amdgpu_job *job,
870-
struct amdgpu_ib *ib)
871-
{
872-
u32 i, reg, res, cond, type;
873-
struct amdgpu_device *adev = parser->adev;
874-
875-
for (i = 0; i < ib->length_dw ; i += 2) {
876-
reg = CP_PACKETJ_GET_REG(ib->ptr[i]);
877-
res = CP_PACKETJ_GET_RES(ib->ptr[i]);
878-
cond = CP_PACKETJ_GET_COND(ib->ptr[i]);
879-
type = CP_PACKETJ_GET_TYPE(ib->ptr[i]);
880-
881-
if (res) /* only support 0 at the moment */
882-
return -EINVAL;
883-
884-
switch (type) {
885-
case PACKETJ_TYPE0:
886-
if (cond != PACKETJ_CONDITION_CHECK0 || reg < JPEG_REG_RANGE_START ||
887-
reg > JPEG_REG_RANGE_END) {
888-
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
889-
return -EINVAL;
890-
}
891-
break;
892-
case PACKETJ_TYPE3:
893-
if (cond != PACKETJ_CONDITION_CHECK3 || reg < JPEG_REG_RANGE_START ||
894-
reg > JPEG_REG_RANGE_END) {
895-
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
896-
return -EINVAL;
897-
}
898-
break;
899-
case PACKETJ_TYPE6:
900-
if (ib->ptr[i] == CP_PACKETJ_NOP)
901-
continue;
902-
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
903-
return -EINVAL;
904-
default:
905-
dev_err(adev->dev, "Unknown packet type %d !\n", type);
906-
return -EINVAL;
907-
}
908-
}
909-
910-
return 0;
911-
}

drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545

4646
#define JRBC_DEC_EXTERNAL_REG_WRITE_ADDR 0x18000
4747

48-
#define JPEG_REG_RANGE_START 0x4000
49-
#define JPEG_REG_RANGE_END 0x41c2
50-
5148
void jpeg_v2_0_dec_ring_insert_start(struct amdgpu_ring *ring);
5249
void jpeg_v2_0_dec_ring_insert_end(struct amdgpu_ring *ring);
5350
void jpeg_v2_0_dec_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
@@ -60,9 +57,6 @@ void jpeg_v2_0_dec_ring_emit_vm_flush(struct amdgpu_ring *ring,
6057
unsigned vmid, uint64_t pd_addr);
6158
void jpeg_v2_0_dec_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
6259
void jpeg_v2_0_dec_ring_nop(struct amdgpu_ring *ring, uint32_t count);
63-
int jpeg_v2_dec_ring_parse_cs(struct amdgpu_cs_parser *parser,
64-
struct amdgpu_job *job,
65-
struct amdgpu_ib *ib);
6660

6761
extern const struct amdgpu_ip_block_version jpeg_v2_0_ip_block;
6862

drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ static const struct amdgpu_ring_funcs jpeg_v2_5_dec_ring_vm_funcs = {
696696
.get_rptr = jpeg_v2_5_dec_ring_get_rptr,
697697
.get_wptr = jpeg_v2_5_dec_ring_get_wptr,
698698
.set_wptr = jpeg_v2_5_dec_ring_set_wptr,
699-
.parse_cs = jpeg_v2_dec_ring_parse_cs,
699+
.parse_cs = amdgpu_jpeg_dec_parse_cs,
700700
.emit_frame_size =
701701
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
702702
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +
@@ -727,7 +727,7 @@ static const struct amdgpu_ring_funcs jpeg_v2_6_dec_ring_vm_funcs = {
727727
.get_rptr = jpeg_v2_5_dec_ring_get_rptr,
728728
.get_wptr = jpeg_v2_5_dec_ring_get_wptr,
729729
.set_wptr = jpeg_v2_5_dec_ring_set_wptr,
730-
.parse_cs = jpeg_v2_dec_ring_parse_cs,
730+
.parse_cs = amdgpu_jpeg_dec_parse_cs,
731731
.emit_frame_size =
732732
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
733733
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +

drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ static const struct amdgpu_ring_funcs jpeg_v3_0_dec_ring_vm_funcs = {
597597
.get_rptr = jpeg_v3_0_dec_ring_get_rptr,
598598
.get_wptr = jpeg_v3_0_dec_ring_get_wptr,
599599
.set_wptr = jpeg_v3_0_dec_ring_set_wptr,
600-
.parse_cs = jpeg_v2_dec_ring_parse_cs,
600+
.parse_cs = amdgpu_jpeg_dec_parse_cs,
601601
.emit_frame_size =
602602
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
603603
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +

drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ static const struct amdgpu_ring_funcs jpeg_v4_0_dec_ring_vm_funcs = {
762762
.get_rptr = jpeg_v4_0_dec_ring_get_rptr,
763763
.get_wptr = jpeg_v4_0_dec_ring_get_wptr,
764764
.set_wptr = jpeg_v4_0_dec_ring_set_wptr,
765-
.parse_cs = jpeg_v2_dec_ring_parse_cs,
765+
.parse_cs = amdgpu_jpeg_dec_parse_cs,
766766
.emit_frame_size =
767767
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
768768
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +

drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ static const struct amdgpu_ring_funcs jpeg_v4_0_3_dec_ring_vm_funcs = {
11771177
.get_rptr = jpeg_v4_0_3_dec_ring_get_rptr,
11781178
.get_wptr = jpeg_v4_0_3_dec_ring_get_wptr,
11791179
.set_wptr = jpeg_v4_0_3_dec_ring_set_wptr,
1180-
.parse_cs = jpeg_v2_dec_ring_parse_cs,
1180+
.parse_cs = amdgpu_jpeg_dec_parse_cs,
11811181
.emit_frame_size =
11821182
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
11831183
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +

drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ static const struct amdgpu_ring_funcs jpeg_v4_0_5_dec_ring_vm_funcs = {
807807
.get_rptr = jpeg_v4_0_5_dec_ring_get_rptr,
808808
.get_wptr = jpeg_v4_0_5_dec_ring_get_wptr,
809809
.set_wptr = jpeg_v4_0_5_dec_ring_set_wptr,
810-
.parse_cs = jpeg_v2_dec_ring_parse_cs,
810+
.parse_cs = amdgpu_jpeg_dec_parse_cs,
811811
.emit_frame_size =
812812
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
813813
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +

drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ static const struct amdgpu_ring_funcs jpeg_v5_0_0_dec_ring_vm_funcs = {
683683
.get_rptr = jpeg_v5_0_0_dec_ring_get_rptr,
684684
.get_wptr = jpeg_v5_0_0_dec_ring_get_wptr,
685685
.set_wptr = jpeg_v5_0_0_dec_ring_set_wptr,
686-
.parse_cs = jpeg_v2_dec_ring_parse_cs,
686+
.parse_cs = amdgpu_jpeg_dec_parse_cs,
687687
.emit_frame_size =
688688
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
689689
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +

0 commit comments

Comments
 (0)