[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC v2 2/2] arm,smmu: add support for generic DT bindings


  • To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Brian Woods <brian.woods@xxxxxxxxxx>
  • Date: Tue, 21 Jul 2020 21:00:31 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.60.83) smtp.rcpttodomain=epam.com smtp.mailfrom=xilinx.com; dmarc=bestguesspass action=none header.from=xilinx.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EVUvECXV5L4nQYMNSDz3dm1kjTIFTD5CSE0XcToz2fQ=; b=mp6iMU4TdD/zV4vIBq8NtOTK7UIyadv2mPTRr7XQmv0+KN7afW63Wo83r8AHCjT/g3trQ1RGdDv9QpoGGB0zSP3T0DYDJnhzPlaVM8asARGXHaxg96hbouT5QxzVuH2oVyIjt7ckjvsScNEWctlZTn8LRfDtZ36zsyIdloAtckkkiLINj3sa6cBV1XdU8QPAAV2xaAkxbnYZiwIYP+H9mQDDVlhMwPbmqS2q93SEJ+Wmlb6Rrzrsaniye9zJfBGJ6efiFN92RFNuNQz1DkAaD1HtFSAqkZsB2DMI190wFwdWV84POqXlg6AMopsMw+xNy8egO6MYWmQopPHSjTiUdA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h2f08OYIqR80XD+kfUIXmKKDiMxbomLiJJUOuvbBF6qLawwVhEEfkHdxGKzT2HiUfPEzBjxE/TPuZAitRKhepZX5mKJzHCa4t33a+ngOPtCZ2otRbOe/6/FDTHrVNziqDrdrBXWZDUV9iiIKBnjpLXtwn5dZzOd8J+T71wUORFWYgvWY0fOczoyRsmLGz6TJJY2oQd5alvsf613bfDm6E1AlMCB03hjbMuHnA/lzyzXzA3tDG4Qoln1fCPC0Xht4AUZ2gQnzDsyMHUvUuIVgVPsN3/eKHcR8h1n530rJKcKCiSCOiNGEqUwuqN5XsUZXRKtglm9HHRNi4ZzXyUSGVQ==
  • Cc: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Brian Woods <brian.woods@xxxxxxxxxx>
  • Delivery-date: Wed, 22 Jul 2020 04:01:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Restructure some of the code and add supporting functions for adding
generic device tree (DT) binding support.  This will allow for using
current Linux device trees with just modifying the chosen field to
enable Xen.

Signed-off-by: Brian Woods <brian.woods@xxxxxxxxxx>
---

Just realized that I'm fairly sure I need to do some work on the SMRs.
Other than that though, I think things should be okayish.

v1 -> v2
    - Corrected how reading of DT is done with generic bindings


 xen/drivers/passthrough/arm/smmu.c    | 102 +++++++++++++++++++++++++---------
 xen/drivers/passthrough/device_tree.c |  17 +-----
 2 files changed, 78 insertions(+), 41 deletions(-)

diff --git a/xen/drivers/passthrough/arm/smmu.c 
b/xen/drivers/passthrough/arm/smmu.c
index 7a5c6cd..25c090a 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -251,6 +251,8 @@ struct iommu_group
        atomic_t ref;
 };
 
+static const struct arm_smmu_device *find_smmu(const struct device *dev);
+
 static struct iommu_group *iommu_group_alloc(void)
 {
        struct iommu_group *group = xzalloc(struct iommu_group);
@@ -772,56 +774,104 @@ static int insert_smmu_master(struct arm_smmu_device 
*smmu,
        return 0;
 }
 
-static int register_smmu_master(struct arm_smmu_device *smmu,
-                               struct device *dev,
-                               struct of_phandle_args *masterspec)
+static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu,
+                                        struct device *dev,
+                                        struct iommu_fwspec *fwspec)
 {
-       int i, ret = 0;
+       int i;
        struct arm_smmu_master *master;
+       struct device_node *dev_node = dev_get_dev_node(dev);
 
-       master = find_smmu_master(smmu, masterspec->np);
+       master = find_smmu_master(smmu, dev_node);
        if (master) {
                dev_err(dev,
                        "rejecting multiple registrations for master device 
%s\n",
-                       masterspec->np->name);
+                       dev_node->name);
                return -EBUSY;
        }
 
        master = devm_kzalloc(dev, sizeof(*master), GFP_KERNEL);
        if (!master)
                return -ENOMEM;
-       master->of_node = masterspec->np;
 
-       ret = iommu_fwspec_init(&master->of_node->dev, smmu->dev);
-       if (ret) {
-               kfree(master);
-               return ret;
-       }
-       master->cfg.fwspec = dev_iommu_fwspec_get(&master->of_node->dev);
-
-       /* adding the ids here */
-       ret = iommu_fwspec_add_ids(&masterspec->np->dev,
-                                  masterspec->args,
-                                  masterspec->args_count);
-       if (ret)
-               return ret;
+       master->of_node = dev_node;
+       master->cfg.fwspec = fwspec;
 
        /* Xen: Let Xen know that the device is protected by an SMMU */
-       dt_device_set_protected(masterspec->np);
+       dt_device_set_protected(dev_node);
 
        if (!(smmu->features & ARM_SMMU_FEAT_STREAM_MATCH)) {
-               for (i = 0; i < master->cfg.fwspec->num_ids; ++i) {
-                       if (masterspec->args[i] >= smmu->num_mapping_groups) {
+               for (i = 0; i < fwspec->num_ids; ++i) {
+                       if (fwspec->ids[i] >= smmu->num_mapping_groups) {
                                dev_err(dev,
                                        "stream ID for master device %s greater 
than maximum allowed (%d)\n",
-                                       masterspec->np->name, 
smmu->num_mapping_groups);
+                                       dev_node->name, 
smmu->num_mapping_groups);
                                return -ERANGE;
                        }
                }
        }
+
        return insert_smmu_master(smmu, master);
 }
 
+static int arm_smmu_dt_add_device_generic(u8 devfn, struct device *dev)
+{
+       struct arm_smmu_device *smmu;
+       struct iommu_fwspec *fwspec;
+
+       fwspec = dev_iommu_fwspec_get(dev);
+       if (fwspec == NULL)
+               return -ENXIO;
+
+       smmu = (struct arm_smmu_device *) find_smmu(fwspec->iommu_dev);
+       if (smmu == NULL)
+               return -ENXIO;
+
+       return arm_smmu_dt_add_device_legacy(smmu, dev, fwspec);
+}
+
+static int arm_smmu_dt_xlate_generic(struct device *dev,
+                                   const struct of_phandle_args *spec)
+{
+       uint32_t mask, fwid = 0;
+
+       if (spec->args_count > 0)
+               fwid |= ((SMR_ID_MASK << SMR_ID_SHIFT) & spec->args[0]) >> 
SMR_ID_SHIFT;
+
+       if (spec->args_count > 1)
+               fwid |= ((SMR_MASK_MASK << SMR_MASK_SHIFT) & spec->args[1]) >> 
SMR_MASK_SHIFT;
+       else if (!of_property_read_u32(spec->np, "stream-match-mask", &mask))
+               fwid |= ((SMR_MASK_MASK << SMR_MASK_SHIFT) & mask) >> 
SMR_MASK_SHIFT;
+
+       return iommu_fwspec_add_ids(dev,
+                                   &fwid,
+                                   1);
+}
+
+static int register_smmu_master(struct arm_smmu_device *smmu,
+                               struct device *dev,
+                               struct of_phandle_args *masterspec)
+{
+       int ret = 0;
+       struct iommu_fwspec *fwspec;
+
+       ret = iommu_fwspec_init(&masterspec->np->dev, smmu->dev);
+       if (ret)
+               return ret;
+
+       fwspec = dev_iommu_fwspec_get(&masterspec->np->dev);
+
+       ret = iommu_fwspec_add_ids(&masterspec->np->dev,
+                                  masterspec->args,
+                                  masterspec->args_count);
+       if (ret)
+               return ret;
+
+       return arm_smmu_dt_add_device_legacy(smmu,
+                                            &masterspec->np->dev,
+                                            fwspec);
+}
+
 static struct arm_smmu_device *find_smmu_for_device(struct device *dev)
 {
        struct arm_smmu_device *smmu;
@@ -2743,6 +2793,7 @@ static void arm_smmu_iommu_domain_teardown(struct domain 
*d)
 static const struct iommu_ops arm_smmu_iommu_ops = {
     .init = arm_smmu_iommu_domain_init,
     .hwdom_init = arm_smmu_iommu_hwdom_init,
+    .add_device = arm_smmu_dt_add_device_generic,
     .teardown = arm_smmu_iommu_domain_teardown,
     .iotlb_flush = arm_smmu_iotlb_flush,
     .iotlb_flush_all = arm_smmu_iotlb_flush_all,
@@ -2750,9 +2801,10 @@ static const struct iommu_ops arm_smmu_iommu_ops = {
     .reassign_device = arm_smmu_reassign_dev,
     .map_page = arm_iommu_map_page,
     .unmap_page = arm_iommu_unmap_page,
+    .dt_xlate = arm_smmu_dt_xlate_generic,
 };
 
-static __init const struct arm_smmu_device *find_smmu(const struct device *dev)
+static const struct arm_smmu_device *find_smmu(const struct device *dev)
 {
        struct arm_smmu_device *smmu;
        bool found = false;
diff --git a/xen/drivers/passthrough/device_tree.c 
b/xen/drivers/passthrough/device_tree.c
index acf6b62..dd9cf65 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -158,22 +158,7 @@ int iommu_add_dt_device(struct dt_device_node *np)
          * these callback implemented.
          */
         if ( !ops->add_device || !ops->dt_xlate )
-        {
-            /*
-             * Some Device Trees may expose both legacy SMMU and generic
-             * IOMMU bindings together. However, the SMMU driver is only
-             * supporting the former and will protect them during the
-             * initialization. So we need to skip them and not return
-             * error here.
-             *
-             * XXX: This can be dropped when the SMMU is able to deal
-             * with generic bindings.
-             */
-            if ( dt_device_is_protected(np) )
-                return 0;
-            else
-                return -EINVAL;
-        }
+            return -EINVAL;
 
         if ( !dt_device_is_available(iommu_spec.np) )
             break;
-- 
2.7.4




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.