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

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 6 Dec 2022 22:15:27 -0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.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=SvjprfsFjT2q+G0BBsMISOBPht18qx5Ov6rcUISgUjE=; b=U4/akz42Wqp+igCe0Vw2nCKK4JFqhGrpcVfR2U+G9LN7PtAgq3PIM51tDoKcVSVRHylp+yyoDhCteBs61CpwYs+NkTDPm8lrw4A32tvYa1mdAOvZfjjFTebbJJI28WAGq3Ab0FFdPQllzRUepKFtF26uUQmAlVcAhyvfTS8JGHGpDNybeN26rpqG6THnTpaydJq/5QPC2pDCPFj9Rb0Y5KhnAfy9anktIdAwYIk/0+6/IqyGx6IiFPl43Nw21WjyRqjZNQzu2ijEQyHMDsgHM0fCTEQ7WxGipfuh4F70nuVVNE/eDhM3RGhW+AgTAvSYPZkOZGpn1wE7ex5i1fgLeA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nlh/fb8KJ7GauHf27g/W1ggiylT5IKHq9ctZy/cvm4a9T6X03EeypBBbjXzRIa8NF/9h9MfEaf01leui1z5GZPs3V81p24O9lCsQAEjwRtrQK3bRPda9ibF+V/Y92JdnSkcEKQGjn+148/P9HgdrELY0vDE9yTci4hpg04dV14qIf3xA8MMFsgqEJqUOxnCoeh/NhCQ+wj1jRx9XJTW3QZqFHTQdlJl8gSuMjZDs17stclpGmZ9GmM1tq0LLi7Ia5wZZRX0Fc/nFvml/IAYAAsVULOVQCYMsgxja40e4sji9RkK2n5Ujddznz+LSVxDyC+WwH/MRvXuo4UQIFQTQ9Q==
  • Cc: <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>, <vikram.garhwal@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 07 Dec 2022 06:17:17 +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 <vikram.garhwal@xxxxxxx>
Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>
---
 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 0a514821b3..14e15f1bc6 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;
@@ -2858,6 +2913,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,
     .assign_device = arm_smmu_assign_dev,
-- 
2.17.1




 


Rackspace

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