@@ -128,6 +128,50 @@ 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 ( !iommu_enabled )
+ return 1;
+
+ 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();
@@ -233,6 +233,7 @@ int iommu_add_dt_device(struct dt_device_node *np);
int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
+int iommu_remove_dt_device(struct dt_device_node *np);
#endif /* HAS_DEVICE_TREE */
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@amd.com> --- Changes from v7: Add check if IOMMU is enabled. Fix indentation of fail. --- --- xen/drivers/passthrough/device_tree.c | 44 +++++++++++++++++++++++++++ xen/include/xen/iommu.h | 1 + 2 files changed, 45 insertions(+)