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

[XEN][RFC PATCH v3 06/14] xen/smmu: Add remove_device callback for smmu_iommu ops


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
  • Date: Tue, 8 Mar 2022 11:46:56 -0800
  • 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W7qfG/E62ZPUQLKP3CMDSNtZWZYJXpDeF3V5RfWzOVc=; b=k7MyJrWg39HGU/4vZC1XRjnzJWQDtBTJiqfAHhEgMqanlqk2bY0ypKeQVHzNcmRm0WtKWUzp8wGDMF53NFQqhnlXglR3sZFIwXhHUmc+SwEaP6rg36rPp9T359o9q10FxeI8ABKCrCbJ3GVBEE6l3Iy7sTFPEz7fmMYengLI1Nc+WjLbIP+O5DLSOBf2EqyenmsiRGPquhAuQ7OLnW99aPqry9bOCX0A3v6Lf8YmkPpUAL23kj38IgiCjPgCuZ28y1loAm3RT6E8ix9xcS073rThqEjaZz6AWvTXIgqqVU4oC2HmpEX8afN+O0WZvur73AdAxYaWW+qrgEDT7JSNmA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=evO+N4/NqQj5VI5dAlaM6O4Yo2tX0jJQ8SDjFtHSF8I+OiR2/+vGinMiMDYOgWI4qZ//eg2wjwblNMzG06946MDLv00u3JZ74N6gu3F5lyOGjjVGe/r/gC9+IrkvdsrE2CSgxQGigWcodanRl8w3AZ5hBvyzjZAVtOxQPsHh7uPo89e/kCSvJ5N+7enyhmw80IPl2v8h6CXNo1KxsmCaYYzVIxjW/nilXLx/oMTExKnOAQxc7/y9r4haqHE+pFvfGOMxASYjx2fJV2KeOhi9SdV72dznYBfHsxR3cJq4xad5CURst/TPjl2MbulRR0hnNWKiKaZ6p7BrH09931Sgkg==
  • Cc: <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>, <bertrand.marquis@xxxxxxx>, <volodymyr_babchuk@xxxxxxxx>, Vikram Garhwal <fnu.vikram@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 08 Mar 2022 19:47:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add remove_device callback for removing the device entry from smmu-master 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 | 56 ++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/xen/drivers/passthrough/arm/smmu.c 
b/xen/drivers/passthrough/arm/smmu.c
index b186c28dff..8b3b8b9850 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -816,6 +816,19 @@ 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) {
+               ASSERT_UNREACHABLE();
+               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 +866,32 @@ 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;
+
+       dev_node->is_protected = false;
+
+       kfree(master);
+       return 0;
+}
+
 static int register_smmu_master(struct arm_smmu_device *smmu,
                                struct device *dev,
                                struct of_phandle_args *masterspec)
@@ -876,6 +915,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;
@@ -2861,6 +2916,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = {
     .init = arm_smmu_iommu_domain_init,
     .hwdom_init = arch_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,
-- 
2.17.1




 


Rackspace

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