Commit cc5aed44 authored by Joerg Roedel's avatar Joerg Roedel

iommu: Consolitate ->add/remove_device() calls

Put them into separate functions and call those where the
plain ops have been called before.
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 6954cf9b
...@@ -111,6 +111,23 @@ void iommu_device_unregister(struct iommu_device *iommu) ...@@ -111,6 +111,23 @@ void iommu_device_unregister(struct iommu_device *iommu)
spin_unlock(&iommu_device_lock); spin_unlock(&iommu_device_lock);
} }
int iommu_probe_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
WARN_ON(dev->iommu_group);
return ops->add_device(dev);
}
void iommu_release_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
if (dev->iommu_group)
ops->remove_device(dev);
}
static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
unsigned type); unsigned type);
static int __iommu_attach_device(struct iommu_domain *domain, static int __iommu_attach_device(struct iommu_domain *domain,
...@@ -1118,16 +1135,7 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) ...@@ -1118,16 +1135,7 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
static int add_iommu_group(struct device *dev, void *data) static int add_iommu_group(struct device *dev, void *data)
{ {
struct iommu_callback_data *cb = data; int ret = iommu_probe_device(dev);
const struct iommu_ops *ops = cb->ops;
int ret;
if (!ops->add_device)
return 0;
WARN_ON(dev->iommu_group);
ret = ops->add_device(dev);
/* /*
* We ignore -ENODEV errors for now, as they just mean that the * We ignore -ENODEV errors for now, as they just mean that the
...@@ -1142,11 +1150,7 @@ static int add_iommu_group(struct device *dev, void *data) ...@@ -1142,11 +1150,7 @@ static int add_iommu_group(struct device *dev, void *data)
static int remove_iommu_group(struct device *dev, void *data) static int remove_iommu_group(struct device *dev, void *data)
{ {
struct iommu_callback_data *cb = data; iommu_release_device(dev);
const struct iommu_ops *ops = cb->ops;
if (ops->remove_device && dev->iommu_group)
ops->remove_device(dev);
return 0; return 0;
} }
...@@ -1154,27 +1158,22 @@ static int remove_iommu_group(struct device *dev, void *data) ...@@ -1154,27 +1158,22 @@ static int remove_iommu_group(struct device *dev, void *data)
static int iommu_bus_notifier(struct notifier_block *nb, static int iommu_bus_notifier(struct notifier_block *nb,
unsigned long action, void *data) unsigned long action, void *data)
{ {
unsigned long group_action = 0;
struct device *dev = data; struct device *dev = data;
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct iommu_group *group; struct iommu_group *group;
unsigned long group_action = 0;
/* /*
* ADD/DEL call into iommu driver ops if provided, which may * ADD/DEL call into iommu driver ops if provided, which may
* result in ADD/DEL notifiers to group->notifier * result in ADD/DEL notifiers to group->notifier
*/ */
if (action == BUS_NOTIFY_ADD_DEVICE) { if (action == BUS_NOTIFY_ADD_DEVICE) {
if (ops->add_device) {
int ret; int ret;
ret = ops->add_device(dev); ret = iommu_probe_device(dev);
return (ret) ? NOTIFY_DONE : NOTIFY_OK; return (ret) ? NOTIFY_DONE : NOTIFY_OK;
}
} else if (action == BUS_NOTIFY_REMOVED_DEVICE) { } else if (action == BUS_NOTIFY_REMOVED_DEVICE) {
if (ops->remove_device && dev->iommu_group) { iommu_release_device(dev);
ops->remove_device(dev); return NOTIFY_OK;
return 0;
}
} }
/* /*
......
...@@ -409,6 +409,9 @@ static inline void dev_iommu_fwspec_set(struct device *dev, ...@@ -409,6 +409,9 @@ static inline void dev_iommu_fwspec_set(struct device *dev,
dev->iommu_fwspec = fwspec; dev->iommu_fwspec = fwspec;
} }
int iommu_probe_device(struct device *dev);
void iommu_release_device(struct device *dev);
#else /* CONFIG_IOMMU_API */ #else /* CONFIG_IOMMU_API */
struct iommu_ops {}; struct iommu_ops {};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment