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

[XEN][PATCH v6 11/19] xen/iommu: Introduce iommu_remove_dt_device()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 2 May 2023 16:36:42 -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=rIRy40Pphy3puPxLyarufMzgZUdXxhJqsOpQVvIQDWY=; b=hUh4Ds6KIjy/4l/tB4nJ3FwOgDFMEgiZmqb4yxVATYO+IOx+kG3xHZS8zilSoIVmBglcIUo6LhW8N0KL+ZE66jVfkv6sI4Ei+3us6nzoco9EAKtcuK3sFkpvZwkdFRncjFHPfWEbAj9dH4fRhCiwmjM+HqHgsDkvQhOl2UFtFm5QxluZsBkNmu9QetIzLlQ77P0p3Tumwv613ZgUCs+gAubxx/yQiYTvYWcXJw3BiYiTM9kHFNkdGJYydGQcTMviMfyfSViCujx29GugZbQ2twaF4jbnYsBIWP84S2dICBi7p7hwqPwN0rt1AoDgDjLDJ1hxf6atjmg9BbgDWeV8Kg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lnzedPcLVf9AgNtKSrsWnxlj8wg/n0b35HQajSB8VeMk4/pP7cndeadLyZowOcl2cp8NM5Php0iB6EEijSr27Gcr6oW5YxBvmLqan8hePFHoBA5z8xdMPfKDTamtWJK6IpxtnoDCI9SeL+WK7LJTuFWhKNAIRL+NdnJ0FBQ/cQyBL8XbJIUfuBHGHgrlwky19/krsIwZ9Skv1eUOqyI1tdoS/SIGj21ZpfUacUZRD4ipLXElLbe4+FHqUPd47hstrCmvywKSfZHcubZ15rpdxhjTXVTD4X5T3SiSuexWs5l5ITZkTiXtg8e+NkVOv6HoD202Y8xKvgoADEnXjVu7kQ==
  • Cc: <sstabellini@xxxxxxxxxx>, <vikram.garhwal@xxxxxxx>, <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Tue, 02 May 2023 23:37:59 +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>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
---
 xen/drivers/passthrough/device_tree.c | 41 +++++++++++++++++++++++++++
 xen/include/xen/iommu.h               |  2 ++
 2 files changed, 43 insertions(+)

diff --git a/xen/drivers/passthrough/device_tree.c 
b/xen/drivers/passthrough/device_tree.c
index f3867ef1a6..46f9080c8f 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -125,6 +125,47 @@ 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 this
+     * callback implemented.
+     */
+    if ( !ops->remove_device )
+    {
+        rc = -EOPNOTSUPP;
+        goto fail;
+    }
+
+    /*
+     * Remove master device from the IOMMU if latter is present and available.
+     * The driver is responsible for removing is_protected flag.
+     */
+    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 76add226ec..6ba8d73966 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -219,6 +219,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®.