Skip to content

Commit fb3af1f

Browse files
dhsrivaswilldeacon
authored andcommitted
iommu/amd: Add debugfs support to dump IOMMU command buffer
IOMMU driver sends command to IOMMU hardware via command buffer. In cases where IOMMU hardware fails to process commands in command buffer, dumping it is a valuable input to debug the issue. IOMMU hardware processes command buffer entry at offset equals to the head pointer. Dumping just the entry at the head pointer may not always be useful. The current head may not be pointing to the entry of the command buffer which is causing the issue. IOMMU Hardware may have processed the entry and updated the head pointer. So dumping the entire command buffer gives a broad understanding of what hardware was/is doing. The command buffer dump will have all entries from start to end of the command buffer. Along with that, it will have a head and tail command buffer pointer register dump to facilitate where the IOMMU driver and hardware are in the command buffer for injecting and processing the entries respectively. Command buffer is a per IOMMU data structure. So dumping on per IOMMU basis. eg. -> To get command buffer dump for iommu<x> (say, iommu00) #cat /sys/kernel/debug/iommu/amd/iommu00/cmdbuf 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 4d9c5d5 commit fb3af1f

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,13 @@ struct dev_table_entry {
897897
};
898898
};
899899

900+
/*
901+
* Structure defining one entry in the command buffer
902+
*/
903+
struct iommu_cmd {
904+
u32 data[4];
905+
};
906+
900907
/*
901908
* Structure to sture persistent DTE flags from IVHD
902909
*/

drivers/iommu/amd/debugfs.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,30 @@ static int iommu_capability_show(struct seq_file *m, void *unused)
107107
}
108108
DEFINE_SHOW_STORE_ATTRIBUTE(iommu_capability);
109109

110+
static int iommu_cmdbuf_show(struct seq_file *m, void *unused)
111+
{
112+
struct amd_iommu *iommu = m->private;
113+
struct iommu_cmd *cmd;
114+
unsigned long flag;
115+
u32 head, tail;
116+
int i;
117+
118+
raw_spin_lock_irqsave(&iommu->lock, flag);
119+
head = readl(iommu->mmio_base + MMIO_CMD_HEAD_OFFSET);
120+
tail = readl(iommu->mmio_base + MMIO_CMD_TAIL_OFFSET);
121+
seq_printf(m, "CMD Buffer Head Offset:%d Tail Offset:%d\n",
122+
(head >> 4) & 0x7fff, (tail >> 4) & 0x7fff);
123+
for (i = 0; i < CMD_BUFFER_ENTRIES; i++) {
124+
cmd = (struct iommu_cmd *)(iommu->cmd_buf + i * sizeof(*cmd));
125+
seq_printf(m, "%3d: %08x %08x %08x %08x\n", i, cmd->data[0],
126+
cmd->data[1], cmd->data[2], cmd->data[3]);
127+
}
128+
raw_spin_unlock_irqrestore(&iommu->lock, flag);
129+
130+
return 0;
131+
}
132+
DEFINE_SHOW_ATTRIBUTE(iommu_cmdbuf);
133+
110134
void amd_iommu_debugfs_setup(void)
111135
{
112136
struct amd_iommu *iommu;
@@ -125,5 +149,7 @@ void amd_iommu_debugfs_setup(void)
125149
&iommu_mmio_fops);
126150
debugfs_create_file("capability", 0644, iommu->debugfs, iommu,
127151
&iommu_capability_fops);
152+
debugfs_create_file("cmdbuf", 0444, iommu->debugfs, iommu,
153+
&iommu_cmdbuf_fops);
128154
}
129155
}

drivers/iommu/amd/iommu.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ static const struct iommu_dirty_ops amd_dirty_ops;
6262

6363
int amd_iommu_max_glx_val = -1;
6464

65-
/*
66-
* general struct to manage commands send to an IOMMU
67-
*/
68-
struct iommu_cmd {
69-
u32 data[4];
70-
};
71-
7265
/*
7366
* AMD IOMMU allows up to 2^16 different protection domains. This is a bitmap
7467
* to know which ones are already in use.

0 commit comments

Comments
 (0)