From: Joerg Roedel <joro@8bytes.org>
To: iommu@lists.linux-foundation.org
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Hanjun Guo <hanjun.guo@linaro.org>,
Sudeep Holla <sudeep.holla@arm.com>,
Joerg Roedel <joro@8bytes.org>,
jroedel@suse.de, Robin Murphy <robin.murphy@arm.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] iommu: Consolitate ->add/remove_device() calls
Date: Tue, 11 Dec 2018 16:05:11 +0100 [thread overview]
Message-ID: <20181211150513.15161-3-joro@8bytes.org> (raw)
In-Reply-To: <20181211150513.15161-1-joro@8bytes.org>
From: Joerg Roedel <jroedel@suse.de>
Put them into separate functions and call those where the
plain ops have been called before.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 51 +++++++++++++++++++++----------------------
include/linux/iommu.h | 3 +++
2 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index edbdf5d6962c..1e8f4e0c9198 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -110,6 +110,23 @@ void iommu_device_unregister(struct iommu_device *iommu)
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,
unsigned type);
static int __iommu_attach_device(struct iommu_domain *domain,
@@ -1117,16 +1134,7 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
static int add_iommu_group(struct device *dev, void *data)
{
- struct iommu_callback_data *cb = data;
- 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);
+ int ret = iommu_probe_device(dev);
/*
* We ignore -ENODEV errors for now, as they just mean that the
@@ -1141,11 +1149,7 @@ static int add_iommu_group(struct device *dev, void *data)
static int remove_iommu_group(struct device *dev, void *data)
{
- struct iommu_callback_data *cb = data;
- const struct iommu_ops *ops = cb->ops;
-
- if (ops->remove_device && dev->iommu_group)
- ops->remove_device(dev);
+ iommu_release_device(dev);
return 0;
}
@@ -1153,27 +1157,22 @@ static int remove_iommu_group(struct device *dev, void *data)
static int iommu_bus_notifier(struct notifier_block *nb,
unsigned long action, void *data)
{
+ unsigned long group_action = 0;
struct device *dev = data;
- const struct iommu_ops *ops = dev->bus->iommu_ops;
struct iommu_group *group;
- unsigned long group_action = 0;
/*
* ADD/DEL call into iommu driver ops if provided, which may
* result in ADD/DEL notifiers to group->notifier
*/
if (action == BUS_NOTIFY_ADD_DEVICE) {
- if (ops->add_device) {
- int ret;
+ int ret;
- ret = ops->add_device(dev);
- return (ret) ? NOTIFY_DONE : NOTIFY_OK;
- }
+ ret = iommu_probe_device(dev);
+ return (ret) ? NOTIFY_DONE : NOTIFY_OK;
} else if (action == BUS_NOTIFY_REMOVED_DEVICE) {
- if (ops->remove_device && dev->iommu_group) {
- ops->remove_device(dev);
- return 0;
- }
+ iommu_release_device(dev);
+ return NOTIFY_OK;
}
/*
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index a1d28f42cb77..cb36f32cd3c2 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -398,6 +398,9 @@ void iommu_fwspec_free(struct device *dev);
int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids);
const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode);
+int iommu_probe_device(struct device *dev);
+void iommu_release_device(struct device *dev);
+
#else /* CONFIG_IOMMU_API */
struct iommu_ops {};
--
2.17.1
next prev parent reply other threads:[~2018-12-11 15:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-11 15:05 [PATCH 0/4 v2] Consolidate iommu_ops->add/remove_device() calls Joerg Roedel
2018-12-11 15:05 ` [PATCH 1/4] iommu/sysfs: Rename iommu_release_device() Joerg Roedel
2018-12-11 15:05 ` Joerg Roedel [this message]
2018-12-11 15:05 ` [PATCH 3/4] iommu/of: Don't call iommu_ops->add_device directly Joerg Roedel
2018-12-19 9:54 ` Marek Szyprowski
2018-12-19 14:34 ` Joerg Roedel
2018-12-19 14:53 ` Marek Szyprowski
2018-12-20 9:13 ` Joerg Roedel
2018-12-20 15:42 ` Geert Uytterhoeven
2019-01-11 10:23 ` Joerg Roedel
[not found] ` <20181211150513.15161-1-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-12-11 15:05 ` [PATCH 4/4] ACPI/IORT: " Joerg Roedel
[not found] ` <20181211150513.15161-5-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-12-17 9:40 ` Hanjun Guo
-- strict thread matches above, loose matches on Subject: below --
2018-12-05 14:36 [PATCH 0/4] Consolitate iommu_ops->add/remove_device() calls Joerg Roedel
2018-12-05 14:36 ` [PATCH 2/4] iommu: Consolitate ->add/remove_device() calls Joerg Roedel
[not found] ` <20181205143646.4876-3-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-12-05 14:54 ` Christoph Hellwig
2018-12-05 15:14 ` Joerg Roedel
2018-12-05 18:20 ` Robin Murphy
2018-12-06 15:47 ` Joerg Roedel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181211150513.15161-3-joro@8bytes.org \
--to=joro@8bytes.org \
--cc=hanjun.guo@linaro.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jroedel@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=robin.murphy@arm.com \
--cc=sudeep.holla@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox