Skip to content

Commit 1729dd3

Browse files
agd5fairlied
authored andcommitted
drm/radeon/kms: r600 CS parser fixes
- buffer offsets in the base regs are 256b aligned so shift properly when comparing, fixed by Andre Maasikas - mipmap size was calculated wrong when nlevel=0 - texture bo offsets were used after the bo base address was added - vertex resource size register is size - 1, not size Signed-off-by: Alex Deucher <[email protected]> Cc: Andre Maasikas <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
1 parent 43861f7 commit 1729dd3

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

drivers/gpu/drm/radeon/r600_cs.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
174174
dev_warn(p->dev, "FMASK or CMASK buffer are not supported by this kernel\n");
175175
return -EINVAL;
176176
}
177-
size = radeon_bo_size(track->cb_color_bo[i]);
177+
size = radeon_bo_size(track->cb_color_bo[i]) - track->cb_color_bo_offset[i];
178178
if (r600_bpe_from_format(&bpe, G_0280A0_FORMAT(track->cb_color_info[i]))) {
179179
dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08X)\n",
180180
__func__, __LINE__, G_0280A0_FORMAT(track->cb_color_info[i]),
@@ -938,7 +938,7 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
938938
return -EINVAL;
939939
}
940940
tmp = (reg - CB_COLOR0_BASE) / 4;
941-
track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
941+
track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8;
942942
ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
943943
track->cb_color_base_last[tmp] = ib[idx];
944944
track->cb_color_bo[tmp] = reloc->robj;
@@ -950,7 +950,7 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
950950
"0x%04X\n", reg);
951951
return -EINVAL;
952952
}
953-
track->db_offset = radeon_get_ib_value(p, idx);
953+
track->db_offset = radeon_get_ib_value(p, idx) << 8;
954954
ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
955955
track->db_bo = reloc->robj;
956956
break;
@@ -1055,10 +1055,10 @@ static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels
10551055
}
10561056
*l0_size = ALIGN((w0 * bpe), pitch_align) * h0 * d0;
10571057
*mipmap_size = offset;
1058-
if (!blevel)
1059-
*mipmap_size -= *l0_size;
10601058
if (!nlevels)
10611059
*mipmap_size = *l0_size;
1060+
if (!blevel)
1061+
*mipmap_size -= *l0_size;
10621062
}
10631063

10641064
/**
@@ -1165,14 +1165,14 @@ static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 i
11651165
(pitch_align * bpe),
11661166
&l0_size, &mipmap_size);
11671167
/* using get ib will give us the offset into the texture bo */
1168-
word0 = radeon_get_ib_value(p, idx + 2);
1168+
word0 = radeon_get_ib_value(p, idx + 2) << 8;
11691169
if ((l0_size + word0) > radeon_bo_size(texture)) {
11701170
dev_warn(p->dev, "texture bo too small (%d %d %d %d -> %d have %ld)\n",
11711171
w0, h0, bpe, word0, l0_size, radeon_bo_size(texture));
11721172
return -EINVAL;
11731173
}
11741174
/* using get ib will give us the offset into the mipmap bo */
1175-
word0 = radeon_get_ib_value(p, idx + 3);
1175+
word0 = radeon_get_ib_value(p, idx + 3) << 8;
11761176
if ((mipmap_size + word0) > radeon_bo_size(mipmap)) {
11771177
dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n",
11781178
w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture));
@@ -1366,7 +1366,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
13661366
}
13671367
for (i = 0; i < (pkt->count / 7); i++) {
13681368
struct radeon_bo *texture, *mipmap;
1369-
u32 size, offset;
1369+
u32 size, offset, base_offset, mip_offset;
13701370

13711371
switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) {
13721372
case SQ_TEX_VTX_VALID_TEXTURE:
@@ -1376,7 +1376,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
13761376
DRM_ERROR("bad SET_RESOURCE\n");
13771377
return -EINVAL;
13781378
}
1379-
ib[idx+1+(i*7)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1379+
base_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
13801380
if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
13811381
ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1);
13821382
else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
@@ -1388,12 +1388,14 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
13881388
DRM_ERROR("bad SET_RESOURCE\n");
13891389
return -EINVAL;
13901390
}
1391-
ib[idx+1+(i*7)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1391+
mip_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
13921392
mipmap = reloc->robj;
13931393
r = r600_check_texture_resource(p, idx+(i*7)+1,
13941394
texture, mipmap, reloc->lobj.tiling_flags);
13951395
if (r)
13961396
return r;
1397+
ib[idx+1+(i*7)+2] += base_offset;
1398+
ib[idx+1+(i*7)+3] += mip_offset;
13971399
break;
13981400
case SQ_TEX_VTX_VALID_BUFFER:
13991401
/* vtx base */
@@ -1403,10 +1405,11 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
14031405
return -EINVAL;
14041406
}
14051407
offset = radeon_get_ib_value(p, idx+1+(i*7)+0);
1406-
size = radeon_get_ib_value(p, idx+1+(i*7)+1);
1408+
size = radeon_get_ib_value(p, idx+1+(i*7)+1) + 1;
14071409
if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
14081410
/* force size to size of the buffer */
1409-
dev_warn(p->dev, "vbo resource seems too big for the bo\n");
1411+
dev_warn(p->dev, "vbo resource seems too big (%d) for the bo (%ld)\n",
1412+
size + offset, radeon_bo_size(reloc->robj));
14101413
ib[idx+1+(i*7)+1] = radeon_bo_size(reloc->robj);
14111414
}
14121415
ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);

0 commit comments

Comments
 (0)