Skip to content

Commit 4d9c5d5

Browse files
dhsrivaswilldeacon
authored andcommitted
iommu/amd: Add debugfs support to dump IOMMU Capability registers
IOMMU Capability registers defines capabilities of IOMMU and information needed for initialising MMIO registers and device table. This is useful to dump these registers for debugging IOMMU related issues. e.g. -> To get capability registers value at offset 0x10 for iommu<x> (say, iommu00) # echo "0x10" > /sys/kernel/debug/iommu/amd/iommu00/capability # cat /sys/kernel/debug/iommu/amd/iommu00/capability 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-4-dheerajkumar.srivastava@amd.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 7a4ee41 commit 4d9c5d5

2 files changed

Lines changed: 53 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
@@ -796,6 +796,7 @@ struct amd_iommu {
796796
/* DebugFS Info */
797797
struct dentry *debugfs;
798798
int dbg_mmio_offset;
799+
int dbg_cap_offset;
799800
#endif
800801

801802
/* IOPF support */

drivers/iommu/amd/debugfs.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,55 @@ static int iommu_mmio_show(struct seq_file *m, void *unused)
5858
}
5959
DEFINE_SHOW_STORE_ATTRIBUTE(iommu_mmio);
6060

61+
static ssize_t iommu_capability_write(struct file *filp, const char __user *ubuf,
62+
size_t cnt, loff_t *ppos)
63+
{
64+
struct seq_file *m = filp->private_data;
65+
struct amd_iommu *iommu = m->private;
66+
int ret;
67+
68+
iommu->dbg_cap_offset = -1;
69+
70+
if (cnt > OFS_IN_SZ)
71+
return -EINVAL;
72+
73+
ret = kstrtou32_from_user(ubuf, cnt, 0, &iommu->dbg_cap_offset);
74+
if (ret)
75+
return ret;
76+
77+
/* Capability register at offset 0x14 is the last IOMMU capability register. */
78+
if (iommu->dbg_cap_offset > 0x14) {
79+
iommu->dbg_cap_offset = -1;
80+
return -EINVAL;
81+
}
82+
83+
return cnt;
84+
}
85+
86+
static int iommu_capability_show(struct seq_file *m, void *unused)
87+
{
88+
struct amd_iommu *iommu = m->private;
89+
u32 value;
90+
int err;
91+
92+
if (iommu->dbg_cap_offset < 0) {
93+
seq_puts(m, "Please provide capability register's offset in the range [0x00 - 0x14]\n");
94+
return 0;
95+
}
96+
97+
err = pci_read_config_dword(iommu->dev, iommu->cap_ptr + iommu->dbg_cap_offset, &value);
98+
if (err) {
99+
seq_printf(m, "Not able to read capability register at 0x%x\n",
100+
iommu->dbg_cap_offset);
101+
return 0;
102+
}
103+
104+
seq_printf(m, "Offset:0x%x Value:0x%08x\n", iommu->dbg_cap_offset, value);
105+
106+
return 0;
107+
}
108+
DEFINE_SHOW_STORE_ATTRIBUTE(iommu_capability);
109+
61110
void amd_iommu_debugfs_setup(void)
62111
{
63112
struct amd_iommu *iommu;
@@ -67,11 +116,14 @@ void amd_iommu_debugfs_setup(void)
67116

68117
for_each_iommu(iommu) {
69118
iommu->dbg_mmio_offset = -1;
119+
iommu->dbg_cap_offset = -1;
70120

71121
snprintf(name, MAX_NAME_LEN, "iommu%02d", iommu->index);
72122
iommu->debugfs = debugfs_create_dir(name, amd_iommu_debugfs);
73123

74124
debugfs_create_file("mmio", 0644, iommu->debugfs, iommu,
75125
&iommu_mmio_fops);
126+
debugfs_create_file("capability", 0644, iommu->debugfs, iommu,
127+
&iommu_capability_fops);
76128
}
77129
}

0 commit comments

Comments
 (0)