From: Wei Chen <Wei.Chen@arm.com>
To: xen-devel@lists.xen.org
Cc: sstabellini@kernel.org, wei.chen@arm.com, steve.capper@arm.com,
Kaly.Xin@arm.com, julien.grall@arm.com, nd@arm.com
Subject: [PATCH 2/2] xen/arm: smmu: Parse generic iommu binding for PCI devices
Date: Fri, 30 Jun 2017 11:23:07 +0800 [thread overview]
Message-ID: <1498792987-29934-3-git-send-email-Wei.Chen@arm.com> (raw)
In-Reply-To: <1498792987-29934-1-git-send-email-Wei.Chen@arm.com>
The legacy smmu binding will be deprecated in favour of the generic
"iommus" binding. So we need a new helper to parse generic iommu
bindings. When the system detects the SMMU is using generic iommu
binding, this helper will be called when this platform device is
assiged to a guest.
This patch is based on Linux of_iommu.c:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/iommu/of_iommu.c
The commit id is:
2a0c57545a291f257cd231b1c4b18285b84608d8
Signed-off-by: Wei Chen <Wei.Chen@arm.com>
---
xen/drivers/passthrough/arm/smmu.c | 73 ++++++++++++++++++++++++++++++++++++--
1 file changed, 71 insertions(+), 2 deletions(-)
diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index 25f2207..50ff997 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -2750,7 +2750,72 @@ static int arm_smmu_platform_iommu_init(struct device *dev)
return 0;
}
-static int arm_smmu_xen_add_device(u8 devfn, struct device*dev)
+/*
+ * Currently, we haven't supported PCI device on ARM. So this is the
+ * temporary function to get device node of pci bridge device for
+ * function verification only
+ */
+static struct device_node *pci_get_bridge_device_node(struct device *dev)
+{
+ struct device_node *dt_dev;
+ const char *type_str;
+
+ dt_for_each_device_node(dt_host, dt_dev) {
+ /* Return the first pci bridge device node simply */
+ if (!dt_property_read_string(dt_dev, "device_type", &type_str) &&
+ !strcmp(type_str, "pci"))
+ return dt_dev;
+ }
+
+ return NULL;
+}
+
+#define PCI_DEVID(bus, devfn) ((((u16)(bus)) << 8) | (devfn))
+
+static int arm_smmu_pci_iommu_init(struct device *dev, u8 devfn)
+{
+ struct device_node *bridge_np;
+ struct of_phandle_args iommu_spec;
+ struct pci_dev *pdev = to_pci_dev(dev);
+ int ret;
+
+ bridge_np = pci_get_bridge_device_node(dev);
+ if (!bridge_np) {
+ dev_err(dev, "Cloud not find the pci bridge device node!\n");
+ return -ENODEV;
+ }
+
+ /*
+ * Start by tracing the RID alias down the PCI topology as
+ * far as the host bridge whose OF node we have...
+ * (we're not even attempting to handle multi-alias devices yet)
+ */
+ iommu_spec.args_count = 1;
+ iommu_spec.np = bridge_np;
+ ret = __arm_smmu_get_pci_sid(pdev, PCI_DEVID(pdev->bus, devfn),
+ &iommu_spec.args[0]);
+ if (ret) {
+ dev_err(dev, "Get pci requester ID failed, err=%d!\n", ret);
+ return ret;
+ }
+
+ /*
+ * ...then find out what that becomes once it escapes the PCI
+ * bus into the system beyond, and which IOMMU it ends up at.
+ */
+ iommu_spec.np = NULL;
+ ret = dt_pci_map_rid(bridge_np, iommu_spec.args[0], "iommu-map",
+ "iommu-map-mask", &iommu_spec.np,
+ iommu_spec.args);
+ if (ret) {
+ dev_err(dev, "Do pci map rid failed, err=%d\n", ret);
+ return ret;
+ }
+
+ return arm_smmu_of_xlate(dev, &iommu_spec);
+}
+
+static int arm_smmu_xen_add_device(u8 devfn, struct device *dev)
{
int ret;
@@ -2760,7 +2825,11 @@ static int arm_smmu_xen_add_device(u8 devfn, struct device*dev)
* register Master IDs while this function had been invoked.
*/
if (using_generic_binding) {
- ret = arm_smmu_platform_iommu_init(dev);
+ if (dev_is_pci(dev))
+ ret = arm_smmu_pci_iommu_init(dev, devfn);
+ else
+ ret = arm_smmu_platform_iommu_init(dev);
+
if (ret)
return ret;
}
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-06-30 3:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-30 3:23 [PATCH 0/2] Add support parse PCI iommu bindings for Xen SMMU Wei Chen
2017-06-30 3:23 ` [PATCH 1/2] xen: devicetree: Introduce a helper to translate PCI requester ID Wei Chen
2017-07-06 20:26 ` Stefano Stabellini
2017-07-07 5:50 ` Wei Chen
2017-06-30 3:23 ` Wei Chen [this message]
2017-07-06 21:05 ` [PATCH 2/2] xen/arm: smmu: Parse generic iommu binding for PCI devices Stefano Stabellini
2017-07-07 6:06 ` Wei Chen
2017-07-07 7:16 ` Julien Grall
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=1498792987-29934-3-git-send-email-Wei.Chen@arm.com \
--to=wei.chen@arm.com \
--cc=Kaly.Xin@arm.com \
--cc=julien.grall@arm.com \
--cc=nd@arm.com \
--cc=sstabellini@kernel.org \
--cc=steve.capper@arm.com \
--cc=xen-devel@lists.xen.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).