Message ID | 20220308194704.14061-10-fnu.vikram@xilinx.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | dynamic node programming using overlay dtbo | expand |
> +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; Here we have that the counterpart iommu_add_dt_device returns EINVAL here and... > + > + spin_lock(&dtdevs_lock); > + > + if ( iommu_dt_device_is_assigned_lock(np) ) { > + rc = -EBUSY; > + goto fail; > + } > + > + /* > + * The driver which supports generic IOMMU DT bindings must have > + * these callback implemented. > + */ > + if ( !ops->remove_device ) { > + rc = -EOPNOTSUPP; … here (for !ops->add_device), so I’m wondering if there is a mistake. > + goto fail; > + } > +
Hi Luca, On 3/14/22 10:50 AM, Luca Fancellu wrote: >> +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; > Here we have that the counterpart iommu_add_dt_device returns EINVAL here and... > I add EINVAL here in v1 but Julien suggested to change it ot EOPNOTSUPP. >> + >> + spin_lock(&dtdevs_lock); >> + >> + if ( iommu_dt_device_is_assigned_lock(np) ) { >> + rc = -EBUSY; >> + goto fail; >> + } >> + >> + /* >> + * The driver which supports generic IOMMU DT bindings must have >> + * these callback implemented. >> + */ >> + if ( !ops->remove_device ) { >> + rc = -EOPNOTSUPP; > … here (for !ops->add_device), so I’m wondering if there is a mistake. > >> + goto fail; >> + } >> +
diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 776809a8f2..5cd0b20c77 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -125,6 +125,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_lock(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 b18e7760a2..64871e5cb8 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -215,6 +215,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));
Remove master device from the IOMMU. Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com> --- xen/drivers/passthrough/device_tree.c | 38 +++++++++++++++++++++++++++ xen/include/xen/iommu.h | 2 ++ 2 files changed, 40 insertions(+)