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

[XEN][PATCH v5 10/17] xen/iommu: Introduce iommu_remove_dt_device()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 11 Apr 2023 12:16:29 -0700
  • 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=gLWShZkghSoju5aCTSrHjPTktEFI3gdZrQ2ShX60hx0=; b=ZzvG+mK/iy4AgUZDTYFPIQYPZO+KAPqS1wjw2S3ySjkMCrDPW/p7P0Pb9tYbfao7N2wXlSB+GOhajUT1r93LBMrYMaOStDb2tWPzI1R0WOlD2uNAFRdBX/nd4IY8s/4ELcLxSCcTfOUBOWR8olwMUeKCZ12nCKQlN2Z/0tPfdDw05IlQHVJA5ojUFqjObsvOzDxxicj2mBS9V+asAN7T7vGq1+42BEvVUnrPd3H8jN/pln2atHXnmNF6xB57s6Oz0oW80KFunQ8oA34qGYuswx/4ZWg52NjAa/27D57vY+zFiyoq9ZOx5T/F1ZoYLY9KF5aDQg10Mv/Dn3cK+QCDVQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mc7+AWllmzix4mhii1U8rnfn6L8ASn96uvHv2soW2G7oS/3cPcG/WPHUuDLB+gHbOMNpDcX5jRXZqCgLhpusyEg1R0n+mz/yllTm5QaeY4RI32zVz4/gYMdFKTJKM1aSfofl01QwWJ60BIb5tzqUHYHmw2+LokFw44QIaOMTEccm+xh/MP4D6Mr2c0WftqUjLDtMZuFXUbW1dP573ft+kB+iOw8Uec9EU+SgqOkjEmleM400hkhMhM1xTVs1yzcTwh8cv/23Fibu5oHI/h5g6ToYlPm1PWlzi/cXlBbGWYHRZTJ4Et9UEnxpUwGWGtm91S/vxOibgh5Reu43WmfIUA==
  • Cc: <sstabellini@xxxxxxxxxx>, Vikram Garhwal <vikram.garhwal@xxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Tue, 11 Apr 2023 19:20:15 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Remove master device from the IOMMU. This will be helpful when removing the
overlay nodes using dynamic programming during run time.

Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
---
 xen/drivers/passthrough/device_tree.c | 38 +++++++++++++++++++++++++++
 xen/include/xen/iommu.h               |  2 ++
 2 files changed, 40 insertions(+)

diff --git a/xen/drivers/passthrough/device_tree.c 
b/xen/drivers/passthrough/device_tree.c
index 457df333a0..a77a217f3d 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -126,6 +126,44 @@ 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;
+
+    if ( !ops )
+        return -EOPNOTSUPP;
+
+    spin_lock(&dtdevs_lock);
+
+    if ( iommu_dt_device_is_assigned_locked(np) )
+    {
+        rc = -EBUSY;
+        goto fail;
+    }
+
+    /*
+     * The driver which supports generic IOMMU DT bindings must have
+     * these callback implemented.
+     */
+    if ( !ops->remove_device )
+    {
+        rc = -EOPNOTSUPP;
+        goto fail;
+    }
+
+    /* Remove master device from the IOMMU if latter is present and available. 
*/
+    rc = ops->remove_device(0, dev);
+
+    if ( !rc )
+        iommu_fwspec_free(dev);
+
+fail:
+    spin_unlock(&dtdevs_lock);
+    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 405db59971..079c06321e 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -218,6 +218,8 @@ int iommu_deassign_dt_device(struct domain *d, struct 
dt_device_node *dev);
 int iommu_dt_domain_init(struct domain *d);
 int iommu_release_dt_devices(struct domain *d);
 
+int iommu_remove_dt_device(struct dt_device_node *np);
+
 /*
  * Helper to add master device to the IOMMU using generic IOMMU DT bindings.
  *
-- 
2.17.1




 


Rackspace

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