Skip to content

Commit 470516c

Browse files
davidwuAMDalexdeucher
authored andcommitted
drm/amd/amdgpu: command submission parser for JPEG
Add JPEG IB command parser to ensure registers in the command are within the JPEG IP block. Reviewed-by: Alex Deucher <[email protected]> Signed-off-by: David (Ming Qiang) Wu <[email protected]> Signed-off-by: Alex Deucher <[email protected]> (cherry picked from commit a7f670d) Cc: [email protected]
1 parent 4246b10 commit 470516c

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,9 @@ static int amdgpu_cs_patch_ibs(struct amdgpu_cs_parser *p,
10571057
r = amdgpu_ring_parse_cs(ring, p, job, ib);
10581058
if (r)
10591059
return r;
1060+
1061+
if (ib->sa_bo)
1062+
ib->gpu_addr = amdgpu_sa_bo_gpu_addr(ib->sa_bo);
10601063
} else {
10611064
ib->ptr = (uint32_t *)kptr;
10621065
r = amdgpu_ring_patch_cs_in_place(ring, p, job, ib);

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "amdgpu.h"
2525
#include "amdgpu_jpeg.h"
26+
#include "amdgpu_cs.h"
2627
#include "soc15.h"
2728
#include "soc15d.h"
2829
#include "jpeg_v4_0_3.h"
@@ -782,7 +783,11 @@ void jpeg_v4_0_3_dec_ring_emit_ib(struct amdgpu_ring *ring,
782783

783784
amdgpu_ring_write(ring, PACKETJ(regUVD_LMI_JRBC_IB_VMID_INTERNAL_OFFSET,
784785
0, 0, PACKETJ_TYPE0));
785-
amdgpu_ring_write(ring, (vmid | (vmid << 4) | (vmid << 8)));
786+
787+
if (ring->funcs->parse_cs)
788+
amdgpu_ring_write(ring, 0);
789+
else
790+
amdgpu_ring_write(ring, (vmid | (vmid << 4) | (vmid << 8)));
786791

787792
amdgpu_ring_write(ring, PACKETJ(regUVD_LMI_JPEG_VMID_INTERNAL_OFFSET,
788793
0, 0, PACKETJ_TYPE0));
@@ -1084,6 +1089,7 @@ static const struct amdgpu_ring_funcs jpeg_v4_0_3_dec_ring_vm_funcs = {
10841089
.get_rptr = jpeg_v4_0_3_dec_ring_get_rptr,
10851090
.get_wptr = jpeg_v4_0_3_dec_ring_get_wptr,
10861091
.set_wptr = jpeg_v4_0_3_dec_ring_set_wptr,
1092+
.parse_cs = jpeg_v4_0_3_dec_ring_parse_cs,
10871093
.emit_frame_size =
10881094
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
10891095
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +
@@ -1248,3 +1254,56 @@ static void jpeg_v4_0_3_set_ras_funcs(struct amdgpu_device *adev)
12481254
{
12491255
adev->jpeg.ras = &jpeg_v4_0_3_ras;
12501256
}
1257+
1258+
/**
1259+
* jpeg_v4_0_3_dec_ring_parse_cs - command submission parser
1260+
*
1261+
* @parser: Command submission parser context
1262+
* @job: the job to parse
1263+
* @ib: the IB to parse
1264+
*
1265+
* Parse the command stream, return -EINVAL for invalid packet,
1266+
* 0 otherwise
1267+
*/
1268+
int jpeg_v4_0_3_dec_ring_parse_cs(struct amdgpu_cs_parser *parser,
1269+
struct amdgpu_job *job,
1270+
struct amdgpu_ib *ib)
1271+
{
1272+
uint32_t i, reg, res, cond, type;
1273+
struct amdgpu_device *adev = parser->adev;
1274+
1275+
for (i = 0; i < ib->length_dw ; i += 2) {
1276+
reg = CP_PACKETJ_GET_REG(ib->ptr[i]);
1277+
res = CP_PACKETJ_GET_RES(ib->ptr[i]);
1278+
cond = CP_PACKETJ_GET_COND(ib->ptr[i]);
1279+
type = CP_PACKETJ_GET_TYPE(ib->ptr[i]);
1280+
1281+
if (res) /* only support 0 at the moment */
1282+
return -EINVAL;
1283+
1284+
switch (type) {
1285+
case PACKETJ_TYPE0:
1286+
if (cond != PACKETJ_CONDITION_CHECK0 || reg < JPEG_REG_RANGE_START || reg > JPEG_REG_RANGE_END) {
1287+
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
1288+
return -EINVAL;
1289+
}
1290+
break;
1291+
case PACKETJ_TYPE3:
1292+
if (cond != PACKETJ_CONDITION_CHECK3 || reg < JPEG_REG_RANGE_START || reg > JPEG_REG_RANGE_END) {
1293+
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
1294+
return -EINVAL;
1295+
}
1296+
break;
1297+
case PACKETJ_TYPE6:
1298+
if (ib->ptr[i] == CP_PACKETJ_NOP)
1299+
continue;
1300+
dev_err(adev->dev, "Invalid packet [0x%08x]!\n", ib->ptr[i]);
1301+
return -EINVAL;
1302+
default:
1303+
dev_err(adev->dev, "Unknown packet type %d !\n", type);
1304+
return -EINVAL;
1305+
}
1306+
}
1307+
1308+
return 0;
1309+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646

4747
#define JRBC_DEC_EXTERNAL_REG_WRITE_ADDR 0x18000
4848

49+
#define JPEG_REG_RANGE_START 0x4000
50+
#define JPEG_REG_RANGE_END 0x41c2
51+
4952
extern const struct amdgpu_ip_block_version jpeg_v4_0_3_ip_block;
5053

5154
void jpeg_v4_0_3_dec_ring_emit_ib(struct amdgpu_ring *ring,
@@ -62,5 +65,7 @@ void jpeg_v4_0_3_dec_ring_insert_end(struct amdgpu_ring *ring);
6265
void jpeg_v4_0_3_dec_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
6366
void jpeg_v4_0_3_dec_ring_emit_reg_wait(struct amdgpu_ring *ring, uint32_t reg,
6467
uint32_t val, uint32_t mask);
65-
68+
int jpeg_v4_0_3_dec_ring_parse_cs(struct amdgpu_cs_parser *parser,
69+
struct amdgpu_job *job,
70+
struct amdgpu_ib *ib);
6671
#endif /* __JPEG_V4_0_3_H__ */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ static const struct amdgpu_ring_funcs jpeg_v5_0_0_dec_ring_vm_funcs = {
646646
.get_rptr = jpeg_v5_0_0_dec_ring_get_rptr,
647647
.get_wptr = jpeg_v5_0_0_dec_ring_get_wptr,
648648
.set_wptr = jpeg_v5_0_0_dec_ring_set_wptr,
649+
.parse_cs = jpeg_v4_0_3_dec_ring_parse_cs,
649650
.emit_frame_size =
650651
SOC15_FLUSH_GPU_TLB_NUM_WREG * 6 +
651652
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 8 +

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
((cond & 0xF) << 24) | \
7777
((type & 0xF) << 28))
7878

79+
#define CP_PACKETJ_NOP 0x60000000
80+
#define CP_PACKETJ_GET_REG(x) ((x) & 0x3FFFF)
81+
#define CP_PACKETJ_GET_RES(x) (((x) >> 18) & 0x3F)
82+
#define CP_PACKETJ_GET_COND(x) (((x) >> 24) & 0xF)
83+
#define CP_PACKETJ_GET_TYPE(x) (((x) >> 28) & 0xF)
84+
7985
/* Packet 3 types */
8086
#define PACKET3_NOP 0x10
8187
#define PACKET3_SET_BASE 0x11

0 commit comments

Comments
 (0)