Skip to content

Commit c738479

Browse files
tstellarAMDgregkh
authored andcommitted
drm/radeon/si: Add support for CP DMA to CS checker for compute v2
commit e5b9e75 upstream. Also add a new RADEON_INFO query to check that CP DMA packets are supported on the compute ring. CP DMA has been supported since the 3.8 kernel, but due to an oversight we forgot to teach the CS checker that the CP DMA packet was legal for the compute ring on Southern Islands GPUs. This patch fixes a bug where the radeon driver will incorrectly reject a legal CP DMA packet from user space. I would like to have the patch backported to stable so that we don't have to require Mesa users to use a bleeding edge kernel in order to take advantage of this feature which is already present in the stable kernels (3.8 and newer). v2: - Don't bump kms version, so this patch can be backported to stable kernels. Signed-off-by: Tom Stellard <thomas.stellard@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5c6ece5 commit c738479

3 files changed

Lines changed: 66 additions & 45 deletions

File tree

‎drivers/gpu/drm/radeon/radeon_kms.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
414414
value = rdev->config.si.tile_mode_array;
415415
value_size = sizeof(uint32_t)*32;
416416
break;
417+
case RADEON_INFO_SI_CP_DMA_COMPUTE:
418+
*value = 1;
419+
break;
417420
default:
418421
DRM_DEBUG_KMS("Invalid request %d\n", info->request);
419422
return -EINVAL;

‎drivers/gpu/drm/radeon/si.c‎

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,13 +3796,64 @@ static int si_vm_packet3_ce_check(struct radeon_device *rdev,
37963796
return 0;
37973797
}
37983798

3799+
static int si_vm_packet3_cp_dma_check(u32 *ib, u32 idx)
3800+
{
3801+
u32 start_reg, reg, i;
3802+
u32 command = ib[idx + 4];
3803+
u32 info = ib[idx + 1];
3804+
u32 idx_value = ib[idx];
3805+
if (command & PACKET3_CP_DMA_CMD_SAS) {
3806+
/* src address space is register */
3807+
if (((info & 0x60000000) >> 29) == 0) {
3808+
start_reg = idx_value << 2;
3809+
if (command & PACKET3_CP_DMA_CMD_SAIC) {
3810+
reg = start_reg;
3811+
if (!si_vm_reg_valid(reg)) {
3812+
DRM_ERROR("CP DMA Bad SRC register\n");
3813+
return -EINVAL;
3814+
}
3815+
} else {
3816+
for (i = 0; i < (command & 0x1fffff); i++) {
3817+
reg = start_reg + (4 * i);
3818+
if (!si_vm_reg_valid(reg)) {
3819+
DRM_ERROR("CP DMA Bad SRC register\n");
3820+
return -EINVAL;
3821+
}
3822+
}
3823+
}
3824+
}
3825+
}
3826+
if (command & PACKET3_CP_DMA_CMD_DAS) {
3827+
/* dst address space is register */
3828+
if (((info & 0x00300000) >> 20) == 0) {
3829+
start_reg = ib[idx + 2];
3830+
if (command & PACKET3_CP_DMA_CMD_DAIC) {
3831+
reg = start_reg;
3832+
if (!si_vm_reg_valid(reg)) {
3833+
DRM_ERROR("CP DMA Bad DST register\n");
3834+
return -EINVAL;
3835+
}
3836+
} else {
3837+
for (i = 0; i < (command & 0x1fffff); i++) {
3838+
reg = start_reg + (4 * i);
3839+
if (!si_vm_reg_valid(reg)) {
3840+
DRM_ERROR("CP DMA Bad DST register\n");
3841+
return -EINVAL;
3842+
}
3843+
}
3844+
}
3845+
}
3846+
}
3847+
return 0;
3848+
}
3849+
37993850
static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
38003851
u32 *ib, struct radeon_cs_packet *pkt)
38013852
{
3853+
int r;
38023854
u32 idx = pkt->idx + 1;
38033855
u32 idx_value = ib[idx];
38043856
u32 start_reg, end_reg, reg, i;
3805-
u32 command, info;
38063857

38073858
switch (pkt->opcode) {
38083859
case PACKET3_NOP:
@@ -3903,50 +3954,9 @@ static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
39033954
}
39043955
break;
39053956
case PACKET3_CP_DMA:
3906-
command = ib[idx + 4];
3907-
info = ib[idx + 1];
3908-
if (command & PACKET3_CP_DMA_CMD_SAS) {
3909-
/* src address space is register */
3910-
if (((info & 0x60000000) >> 29) == 0) {
3911-
start_reg = idx_value << 2;
3912-
if (command & PACKET3_CP_DMA_CMD_SAIC) {
3913-
reg = start_reg;
3914-
if (!si_vm_reg_valid(reg)) {
3915-
DRM_ERROR("CP DMA Bad SRC register\n");
3916-
return -EINVAL;
3917-
}
3918-
} else {
3919-
for (i = 0; i < (command & 0x1fffff); i++) {
3920-
reg = start_reg + (4 * i);
3921-
if (!si_vm_reg_valid(reg)) {
3922-
DRM_ERROR("CP DMA Bad SRC register\n");
3923-
return -EINVAL;
3924-
}
3925-
}
3926-
}
3927-
}
3928-
}
3929-
if (command & PACKET3_CP_DMA_CMD_DAS) {
3930-
/* dst address space is register */
3931-
if (((info & 0x00300000) >> 20) == 0) {
3932-
start_reg = ib[idx + 2];
3933-
if (command & PACKET3_CP_DMA_CMD_DAIC) {
3934-
reg = start_reg;
3935-
if (!si_vm_reg_valid(reg)) {
3936-
DRM_ERROR("CP DMA Bad DST register\n");
3937-
return -EINVAL;
3938-
}
3939-
} else {
3940-
for (i = 0; i < (command & 0x1fffff); i++) {
3941-
reg = start_reg + (4 * i);
3942-
if (!si_vm_reg_valid(reg)) {
3943-
DRM_ERROR("CP DMA Bad DST register\n");
3944-
return -EINVAL;
3945-
}
3946-
}
3947-
}
3948-
}
3949-
}
3957+
r = si_vm_packet3_cp_dma_check(ib, idx);
3958+
if (r)
3959+
return r;
39503960
break;
39513961
default:
39523962
DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
@@ -3958,6 +3968,7 @@ static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
39583968
static int si_vm_packet3_compute_check(struct radeon_device *rdev,
39593969
u32 *ib, struct radeon_cs_packet *pkt)
39603970
{
3971+
int r;
39613972
u32 idx = pkt->idx + 1;
39623973
u32 idx_value = ib[idx];
39633974
u32 start_reg, reg, i;
@@ -4030,6 +4041,11 @@ static int si_vm_packet3_compute_check(struct radeon_device *rdev,
40304041
return -EINVAL;
40314042
}
40324043
break;
4044+
case PACKET3_CP_DMA:
4045+
r = si_vm_packet3_cp_dma_check(ib, idx);
4046+
if (r)
4047+
return r;
4048+
break;
40334049
default:
40344050
DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
40354051
return -EINVAL;

‎include/uapi/drm/radeon_drm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,8 @@ struct drm_radeon_cs {
979979
#define RADEON_INFO_RING_WORKING 0x15
980980
/* SI tile mode array */
981981
#define RADEON_INFO_SI_TILE_MODE_ARRAY 0x16
982+
/* query if CP DMA is supported on the compute ring */
983+
#define RADEON_INFO_SI_CP_DMA_COMPUTE 0x17
982984

983985

984986
struct drm_radeon_info {

0 commit comments

Comments
 (0)