Skip to content

Commit 7a4ee41

Browse files
dhsrivaswilldeacon
authored andcommitted
iommu/amd: Add debugfs support to dump IOMMU MMIO registers
Analyzing IOMMU MMIO registers gives a view of what IOMMU is configured with on the system and is helpful to debug issues with IOMMU. eg. -> To get mmio registers value at offset 0x18 for iommu<x> (say, iommu00) # echo "0x18" > /sys/kernel/debug/iommu/amd/iommu00/mmio # cat /sys/kernel/debug/iommu/amd/iommu00/mmio Signed-off-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> Link: https://lore.kernel.org/r/20250702093804.849-3-dheerajkumar.srivastava@amd.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent ad48b1d commit 7a4ee41

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ struct amd_iommu {
795795
#ifdef CONFIG_AMD_IOMMU_DEBUGFS
796796
/* DebugFS Info */
797797
struct dentry *debugfs;
798+
int dbg_mmio_offset;
798799
#endif
799800

800801
/* IOPF support */

drivers/iommu/amd/debugfs.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,48 @@
1515
static struct dentry *amd_iommu_debugfs;
1616

1717
#define MAX_NAME_LEN 20
18+
#define OFS_IN_SZ 8
19+
20+
static ssize_t iommu_mmio_write(struct file *filp, const char __user *ubuf,
21+
size_t cnt, loff_t *ppos)
22+
{
23+
struct seq_file *m = filp->private_data;
24+
struct amd_iommu *iommu = m->private;
25+
int ret;
26+
27+
iommu->dbg_mmio_offset = -1;
28+
29+
if (cnt > OFS_IN_SZ)
30+
return -EINVAL;
31+
32+
ret = kstrtou32_from_user(ubuf, cnt, 0, &iommu->dbg_mmio_offset);
33+
if (ret)
34+
return ret;
35+
36+
if (iommu->dbg_mmio_offset > iommu->mmio_phys_end - 4) {
37+
iommu->dbg_mmio_offset = -1;
38+
return -EINVAL;
39+
}
40+
41+
return cnt;
42+
}
43+
44+
static int iommu_mmio_show(struct seq_file *m, void *unused)
45+
{
46+
struct amd_iommu *iommu = m->private;
47+
u64 value;
48+
49+
if (iommu->dbg_mmio_offset < 0) {
50+
seq_puts(m, "Please provide mmio register's offset\n");
51+
return 0;
52+
}
53+
54+
value = readq(iommu->mmio_base + iommu->dbg_mmio_offset);
55+
seq_printf(m, "Offset:0x%x Value:0x%016llx\n", iommu->dbg_mmio_offset, value);
56+
57+
return 0;
58+
}
59+
DEFINE_SHOW_STORE_ATTRIBUTE(iommu_mmio);
1860

1961
void amd_iommu_debugfs_setup(void)
2062
{
@@ -24,7 +66,12 @@ void amd_iommu_debugfs_setup(void)
2466
amd_iommu_debugfs = debugfs_create_dir("amd", iommu_debugfs_dir);
2567

2668
for_each_iommu(iommu) {
69+
iommu->dbg_mmio_offset = -1;
70+
2771
snprintf(name, MAX_NAME_LEN, "iommu%02d", iommu->index);
2872
iommu->debugfs = debugfs_create_dir(name, amd_iommu_debugfs);
73+
74+
debugfs_create_file("mmio", 0644, iommu->debugfs, iommu,
75+
&iommu_mmio_fops);
2976
}
3077
}

0 commit comments

Comments
 (0)