From: Gary R Hook <gary.hook@amd.com>
To: iommu@lists.linux-foundation.org
Cc: joro@8bytes.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/5] iommu/amd - Expose the active IOMMU device table entries
Date: Thu, 08 Mar 2018 18:51:19 -0600 [thread overview]
Message-ID: <152055667969.63229.11784633364919979184.stgit@sosxen2.amd.com> (raw)
In-Reply-To: <152055660594.63229.5131049527614494130.stgit@sosxen2.amd.com>
Add a debugfs entry to dump the active device table entries from
the IOMMU's table. Active is determined by non-default values
in the first and second long words of the DTE. Aside from IOMMU
devices, this output should list every device reported by lspci.
Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
drivers/iommu/amd_iommu_debugfs.c | 64 +++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/drivers/iommu/amd_iommu_debugfs.c b/drivers/iommu/amd_iommu_debugfs.c
index 79945ce1199d..c4e071f7a5b9 100644
--- a/drivers/iommu/amd_iommu_debugfs.c
+++ b/drivers/iommu/amd_iommu_debugfs.c
@@ -81,9 +81,66 @@ static const struct file_operations amd_iommu_debugfs_dtecount_ops = {
.write = NULL,
};
+#define MAX_PCI_ID 0xFFFF
+
+#define PRINTDTE(i) OSCNPRINTF("%02x:%02x:%x - %016llx %016llx %016llx %016llx\n", \
+ PCI_BUS_NUM(i), PCI_SLOT(i), PCI_FUNC(i), \
+ amd_iommu_dev_table[i].data[0], \
+ amd_iommu_dev_table[i].data[1], \
+ amd_iommu_dev_table[i].data[2], \
+ amd_iommu_dev_table[i].data[3]);
+
+static ssize_t amd_iommu_debugfs_dte_read(struct file *filp,
+ char __user *ubuf,
+ size_t count, loff_t *offp)
+{
+ struct amd_iommu *iommu = filp->private_data;
+ unsigned int obuflen;
+ unsigned int oboff = 0;
+ unsigned int istart, iend;
+ ssize_t ret;
+ u32 i, n;
+ char *obuf;
+
+ if (!iommu)
+ return 0;
+
+ /* Count the number of valid entries in the device table */
+ istart = 0;
+ iend = MAX_PCI_ID;
+ n = amd_iommu_count_valid_dtes(istart, iend);
+ obuflen = n * 80;
+
+ obuf = kmalloc(OBUFLEN, GFP_KERNEL);
+ if (!obuf)
+ return -ENOMEM;
+
+ for (i = istart ; i <= iend ; i++)
+ if ((amd_iommu_dev_table[i].data[0] ^ 0x3)
+ || amd_iommu_dev_table[i].data[1])
+ oboff += PRINTDTE(i);
+
+ ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+ kfree(obuf);
+
+ return ret;
+}
+
+static const struct file_operations amd_iommu_debugfs_dte_ops = {
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read = amd_iommu_debugfs_dte_read,
+ .write = NULL,
+};
+
static char readmetext[] =
+"devicetable Print active entries in the device table\n"
"count Count of active devices\n"
"verbose Provide additional descriptive text\n"
+"\n"
+" Dumping the Device Table\n"
+"The device table is scanned for entries that appear to be active. The\n"
+"default range is from 0 to 0xFFFF, and only active entries will be reported\n"
"\n";
static ssize_t amd_iommu_debugfs_readme_read(struct file *filp,
@@ -134,6 +191,13 @@ void amd_iommu_debugfs_setup(struct amd_iommu *iommu)
if (!d_verbose)
goto err;
+ /* Device Table Entries */
+ d_dte = debugfs_create_file("devicetable", 0400,
+ iommu->debugfs_instance, iommu,
+ &amd_iommu_debugfs_dte_ops);
+ if (!d_dte)
+ goto err;
+
d_dte = debugfs_create_file("count", 0400,
iommu->debugfs_instance, iommu,
&amd_iommu_debugfs_dtecount_ops);
next prev parent reply other threads:[~2018-03-09 0:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-09 0:50 [PATCH v2 0/5] Add debugfs info for the AMD IOMMU Gary R Hook
2018-03-09 0:50 ` [PATCH v2 1/5] iommu/amd - Add debugfs support Gary R Hook
2018-03-13 17:16 ` Andy Shevchenko
2018-03-13 18:54 ` Gary R Hook
2018-03-13 20:23 ` Andy Shevchenko
2018-03-14 15:24 ` Gary R Hook
2018-03-14 15:29 ` Andy Shevchenko
2018-03-14 22:23 ` Gary R Hook
2018-03-09 0:50 ` [PATCH v2 2/5] iommu/amd - Add a 'verbose' switch for IOMMU debugfs Gary R Hook
2018-03-09 0:51 ` [PATCH v2 3/5] iommu/amd - Add a README variable for the " Gary R Hook
2018-03-09 0:51 ` Gary R Hook [this message]
2018-03-09 0:51 ` [PATCH v2 5/5] iommu/amd - Add a debugfs entry to specify a IOMMU device table entry Gary R Hook
2018-03-13 17:20 ` Andy Shevchenko
2018-03-13 18:54 ` Gary R Hook
2018-03-13 20:56 ` Andy Shevchenko
2018-03-14 15:24 ` Gary R Hook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=152055667969.63229.11784633364919979184.stgit@sosxen2.amd.com \
--to=gary.hook@amd.com \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).