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

[XEN][RFC PATCH 08/13] xen/iommu: Introduce iommu_remove_dt_devices function


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
  • Date: Wed, 1 Sep 2021 23:05:58 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) 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; bh=EVas2kXYqY8J1i69hD1pnLTQnzKqbS4jKsdjLz6x97c=; b=baGfgKv6wfpslNLcyv4rKCbR3vhTEl/V+OdFy+IgivH9xZIn3/bMExf23cMh7y5/jpnd9xauUSY+AQopw3w2txn1uXKketaIOsJ9OE96cbKG8aOyLa+/RvbFZ33Uoa7wfbcWnx3buXcylsfn7L8sElihGqZIUKiUn+imUsnMxQcuvuTBjh1wWN6YaOXhpaCkf2vvWBC0PXRpMOd5b1OwiUMgmRyVdYf2DpvDx325qbPUsd2ZieSnwbQp6m/NYoDF90spKygJvB4ITpEYVyGH8hwE4+3SlbWGxcCjRbVdCNbrnCuFGFQk50cJvNXa6LFZxpPRXK7uYgoB2G1ntl4guA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PwWMyGPlBKtFHj1zM/gtcQiLwDgH+yShnsoTOJSsSbOnxUVjkYii203fAKF2tfN3J0iRBuAX9wx2as5wSlKlDt7V+FZrd5iC0gVGQmYWWG6l1u2+ald2Ldc28FAhqxaxOqHB95/lLOX0PQ6w9Uf+eziftZfbnhPOZPC4nlsOK8vd6eHFz2IGUuP2CYDoC7lqInZ7kIp9FnGC+b2SqJCkMEoYcQjlpokiCL4h7ppC7IrStudyGvXuVfRJ1OuYls8OmMwPwoS/unmsvEVPgF+rhyFN00spTN9ZDa1lN8WsIyt7iDsLSrm/KNbWnGNkaRbrpvr2JtRAxwcQcOOwNzZZpA==
  • Cc: <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>, Vikram Garhwal <fnu.vikram@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Paul Durrant <paul@xxxxxxx>
  • Delivery-date: Thu, 02 Sep 2021 06:51:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

iommu_remove_dt_device function is introduced for supporting dynamic programming
i.e. adding and removing a node during runtime. When user removes the device
node, iommu_remove_dt_device() removes the device entry from smmu-masters too
using following steps:
    1. Find if SMMU master exists for the device node.
    2. Remove the SMMU master.

Signed-off-by: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
---
 xen/drivers/passthrough/arm/smmu.c    | 53 +++++++++++++++++++++++++++++++++++
 xen/drivers/passthrough/device_tree.c | 30 ++++++++++++++++++++
 xen/include/xen/iommu.h               |  2 ++
 3 files changed, 85 insertions(+)

diff --git a/xen/drivers/passthrough/arm/smmu.c 
b/xen/drivers/passthrough/arm/smmu.c
index c9dfc4c..7b615bc 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -816,6 +816,17 @@ static int insert_smmu_master(struct arm_smmu_device *smmu,
        return 0;
 }
 
+static int remove_smmu_master(struct arm_smmu_device *smmu,
+                             struct arm_smmu_master *master)
+{
+       if (!(smmu->masters.rb_node))
+               return -ENOENT;
+
+       rb_erase(&master->node, &smmu->masters);
+
+       return 0;
+}
+
 static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu,
                                         struct device *dev,
                                         struct iommu_fwspec *fwspec)
@@ -853,6 +864,31 @@ static int arm_smmu_dt_add_device_legacy(struct 
arm_smmu_device *smmu,
        return insert_smmu_master(smmu, master);
 }
 
+static int arm_smmu_dt_remove_device_legacy(struct arm_smmu_device *smmu,
+                                        struct device *dev)
+{
+       struct arm_smmu_master *master;
+       struct device_node *dev_node = dev_get_dev_node(dev);
+       int ret;
+
+       master = find_smmu_master(smmu, dev_node);
+       if (master == NULL) {
+               dev_err(dev,
+                       "No registrations found for master device %s\n",
+                       dev_node->name);
+               return -EINVAL;
+       }
+
+       ret = remove_smmu_master(smmu, master);
+
+       if (ret)
+               return ret;
+
+       master->of_node = NULL;
+       kfree(master);
+       return 0;
+}
+
 static int register_smmu_master(struct arm_smmu_device *smmu,
                                struct device *dev,
                                struct of_phandle_args *masterspec)
@@ -876,6 +912,22 @@ static int register_smmu_master(struct arm_smmu_device 
*smmu,
                                             fwspec);
 }
 
+static int arm_smmu_dt_remove_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 = find_smmu(fwspec->iommu_dev);
+       if (smmu == NULL)
+               return -ENXIO;
+
+       return arm_smmu_dt_remove_device_legacy(smmu, dev);
+}
+
 static int arm_smmu_dt_add_device_generic(u8 devfn, struct device *dev)
 {
        struct arm_smmu_device *smmu;
@@ -2876,6 +2928,7 @@ 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,
+    .remove_device = arm_smmu_dt_remove_device_generic,
     .teardown = arm_smmu_iommu_domain_teardown,
     .iotlb_flush = arm_smmu_iotlb_flush,
     .iotlb_flush_all = arm_smmu_iotlb_flush_all,
diff --git a/xen/drivers/passthrough/device_tree.c 
b/xen/drivers/passthrough/device_tree.c
index 98f2aa0..37f4945 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -127,6 +127,36 @@ int iommu_release_dt_devices(struct domain *d)
     return 0;
 }
 
+int iommu_remove_dt_device(struct dt_device_node *np)
+{
+    const struct iommu_ops *ops = iommu_get_ops();
+    struct device *dev = dt_to_dev(np);
+    int rc = 1;
+
+    if ( !ops )
+        return -EINVAL;
+
+    if ( iommu_dt_device_is_assigned(np) )
+        return -EPERM;
+
+    /*
+     * The driver which supports generic IOMMU DT bindings must have
+     * these callback implemented.
+     */
+    if ( !ops->remove_device )
+        return -EINVAL;
+
+    /*
+     * Remove master device from the IOMMU if latter is present and available.
+     */
+    rc = ops->remove_device(0, dev);
+
+    if ( rc == 0 )
+        iommu_fwspec_free(dev);
+
+    return rc;
+}
+
 int iommu_add_dt_device(struct dt_device_node *np)
 {
     const struct iommu_ops *ops = iommu_get_ops();
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 6b2cdff..c4d5d12 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -215,6 +215,8 @@ int iommu_release_dt_devices(struct domain *d);
  */
 int iommu_add_dt_device(struct dt_device_node *np);
 
+int iommu_remove_dt_device(struct dt_device_node *np);
+
 int iommu_do_dt_domctl(struct xen_domctl *, struct domain *,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
 
-- 
2.7.4




 


Rackspace

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