Skip to content

Commit b484577

Browse files
dhsrivaswilldeacon
authored andcommitted
iommu/amd: Add debugfs support to dump device table
IOMMU uses device table data structure to get per-device information for DMA remapping, interrupt remapping, and other functionalities. It's a valuable data structure to visualize for debugging issues related to IOMMU. eg. -> To dump device table entry for a particular device #echo 0000:c4:00.0 > /sys/kernel/debug/iommu/amd/devid #cat /sys/kernel/debug/iommu/amd/devtbl or #echo c4:00.0 > /sys/kernel/debug/iommu/amd/devid #cat /sys/kernel/debug/iommu/amd/devtbl Signed-off-by: Dheeraj Kumar Srivastava <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 2e98940 commit b484577

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

drivers/iommu/amd/debugfs.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,53 @@ static int devid_show(struct seq_file *m, void *unused)
208208
}
209209
DEFINE_SHOW_STORE_ATTRIBUTE(devid);
210210

211+
static void dump_dte(struct seq_file *m, struct amd_iommu_pci_seg *pci_seg, u16 devid)
212+
{
213+
struct dev_table_entry *dev_table;
214+
struct amd_iommu *iommu;
215+
216+
iommu = pci_seg->rlookup_table[devid];
217+
if (!iommu)
218+
return;
219+
220+
dev_table = get_dev_table(iommu);
221+
if (!dev_table) {
222+
seq_puts(m, "Device table not found");
223+
return;
224+
}
225+
226+
seq_printf(m, "%-12s %16s %16s %16s %16s iommu\n", "DeviceId",
227+
"QWORD[3]", "QWORD[2]", "QWORD[1]", "QWORD[0]");
228+
seq_printf(m, "%04x:%02x:%02x.%x ", pci_seg->id, PCI_BUS_NUM(devid),
229+
PCI_SLOT(devid), PCI_FUNC(devid));
230+
for (int i = 3; i >= 0; --i)
231+
seq_printf(m, "%016llx ", dev_table[devid].data[i]);
232+
seq_printf(m, "iommu%d\n", iommu->index);
233+
}
234+
235+
static int iommu_devtbl_show(struct seq_file *m, void *unused)
236+
{
237+
struct amd_iommu_pci_seg *pci_seg;
238+
u16 seg, devid;
239+
240+
if (sbdf < 0) {
241+
seq_puts(m, "Enter a valid device ID to 'devid' file\n");
242+
return 0;
243+
}
244+
seg = PCI_SBDF_TO_SEGID(sbdf);
245+
devid = PCI_SBDF_TO_DEVID(sbdf);
246+
247+
for_each_pci_segment(pci_seg) {
248+
if (pci_seg->id != seg)
249+
continue;
250+
dump_dte(m, pci_seg, devid);
251+
break;
252+
}
253+
254+
return 0;
255+
}
256+
DEFINE_SHOW_ATTRIBUTE(iommu_devtbl);
257+
211258
void amd_iommu_debugfs_setup(void)
212259
{
213260
struct amd_iommu *iommu;
@@ -232,4 +279,6 @@ void amd_iommu_debugfs_setup(void)
232279

233280
debugfs_create_file("devid", 0644, amd_iommu_debugfs, NULL,
234281
&devid_fops);
282+
debugfs_create_file("devtbl", 0444, amd_iommu_debugfs, NULL,
283+
&iommu_devtbl_fops);
235284
}

0 commit comments

Comments
 (0)