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

[XEN][RFC PATCH v4 09/16] xen/iommu: Introduce iommu_remove_dt_device()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 6 Dec 2022 22:18:08 -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=+LUe0w+LpO5tERWdII/zFZViW4K+Jr8pdOMefoNdmlg=; b=JOgLJWRc3AmI2MK9NkKY+TaK9mhNFrQTGJ8DZc6KAgm4nVhB4b96u0EPU/2YiqPmGdOsfVTm0fQRKujUSLBy/TV0PUS3FdHpRDQ48JaZxsH4MVd31c1LvoS1GtyLohkeyaukvDJiLWE4wxD2TMUPnjXrGzWEv+xrvRqB83AbOHu2VjA6sd7nCLEQLexyPzNgHfRjsNoIKLN0RF0Yk10wOABV2tpqrXzh2bgVPuIhGLqcXnCX/y1PkGSyFGsVOY5pl+1ufWmpMN6PAtO4v57qGLg7zxsXXqzIau4wDzNhaRiZjDsJSvejGFdG5xKPP6pSN3bcbQ9AHDjWeJmDKiNx8Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jzyVu5um2w5rSj+rvsgptU6As5+M7Tzp/dIcujowhLL8k17tzNCZ42D9oyja8PLzP1u69wMlfAmXXmYx1hzrjLF8xIdiA+xYI64kBz59CB7DG5o+VKgKSzacLivwPJM61vrrhJGmqjGXDZMme4Q3+uxYm/FED+NELi5+MniGL+ZWUjOIcpmwRIn2cjhOPBJTPqlrRbI3Fe5sjCAz+F5uqxv7AVjvsUYhYKbkJujJmx1dN3q54gf6TNx05zmcUWfuTzL51PL36tWuRhD7tq5Z9GkQz14rHJYPvPMD5vgAKZ+2N8jkJHbfpHP6ch7yuEQpvh5RxokCZqru8oFPxwlJcQ==
  • Cc: <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>, <vikram.garhwal@xxxxxxx>, <Luca.Fancellu@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 07 Dec 2022 06:18:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Remove master device from the IOMMU.

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..a8ba0b0d17 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 == 0 )
+        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 4f22fc1bed..1b36c0419d 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -225,6 +225,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.17.1




 


Rackspace

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