Skip to content

Commit 445d85e

Browse files
committed
drm/amdgpu: add debugfs interface for reading MQDs
Provide a debugfs interface to access the MQD. Useful for debugging issues with the CP and MES hardware scheduler. v2: fix missing unreserve/unmap when pos >= size (Alex) Reviewed-by: Christian König <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent b185c31 commit 445d85e

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

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

+59
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,59 @@ static const struct file_operations amdgpu_debugfs_ring_fops = {
509509
.llseek = default_llseek
510510
};
511511

512+
static ssize_t amdgpu_debugfs_mqd_read(struct file *f, char __user *buf,
513+
size_t size, loff_t *pos)
514+
{
515+
struct amdgpu_ring *ring = file_inode(f)->i_private;
516+
volatile u32 *mqd;
517+
int r;
518+
uint32_t value, result;
519+
520+
if (*pos & 3 || size & 3)
521+
return -EINVAL;
522+
523+
result = 0;
524+
525+
r = amdgpu_bo_reserve(ring->mqd_obj, false);
526+
if (unlikely(r != 0))
527+
return r;
528+
529+
r = amdgpu_bo_kmap(ring->mqd_obj, (void **)&mqd);
530+
if (r) {
531+
amdgpu_bo_unreserve(ring->mqd_obj);
532+
return r;
533+
}
534+
535+
while (size) {
536+
if (*pos >= ring->mqd_size)
537+
goto done;
538+
539+
value = mqd[*pos/4];
540+
r = put_user(value, (uint32_t *)buf);
541+
if (r)
542+
goto done;
543+
buf += 4;
544+
result += 4;
545+
size -= 4;
546+
*pos += 4;
547+
}
548+
549+
done:
550+
amdgpu_bo_kunmap(ring->mqd_obj);
551+
mqd = NULL;
552+
amdgpu_bo_unreserve(ring->mqd_obj);
553+
if (r)
554+
return r;
555+
556+
return result;
557+
}
558+
559+
static const struct file_operations amdgpu_debugfs_mqd_fops = {
560+
.owner = THIS_MODULE,
561+
.read = amdgpu_debugfs_mqd_read,
562+
.llseek = default_llseek
563+
};
564+
512565
#endif
513566

514567
void amdgpu_debugfs_ring_init(struct amdgpu_device *adev,
@@ -524,6 +577,12 @@ void amdgpu_debugfs_ring_init(struct amdgpu_device *adev,
524577
&amdgpu_debugfs_ring_fops,
525578
ring->ring_size + 12);
526579

580+
if (ring->mqd_obj) {
581+
sprintf(name, "amdgpu_mqd_%s", ring->name);
582+
debugfs_create_file_size(name, S_IFREG | S_IRUGO, root, ring,
583+
&amdgpu_debugfs_mqd_fops,
584+
ring->mqd_size);
585+
}
527586
#endif
528587
}
529588

0 commit comments

Comments
 (0)