From: Jason Gunthorpe <jgg@nvidia.com>
To: David Airlie <airlied@gmail.com>,
Alyssa Rosenzweig <alyssa@rosenzweig.io>,
Albert Ou <aou@eecs.berkeley.edu>,
asahi@lists.linux.dev, Catalin Marinas <catalin.marinas@arm.com>,
Danilo Krummrich <dakr@redhat.com>,
Daniel Vetter <daniel@ffwll.ch>, Dexuan Cui <decui@microsoft.com>,
devicetree@vger.kernel.org, dmaengine@vger.kernel.org,
dri-devel@lists.freedesktop.org,
David Woodhouse <dwmw2@infradead.org>,
Frank Rowand <frowand.list@gmail.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
iommu@lists.linux.dev, Jon Hunter <jonathanh@nvidia.com>,
Joerg Roedel <joro@8bytes.org>, Karol Herbst <kherbst@redhat.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Laxman Dewangan <ldewangan@nvidia.com>,
Len Brown <lenb@kernel.org>,
linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-hyperv@vger.kernel.org, linux-mips@vger.kernel.org,
linux-riscv@lists.infradead.org,
linux-snps-arc@lists.infradead.org, linux-tegra@vger.kernel.org,
Russell King <linux@armlinux.org.uk>,
Lyude Paul <lyude@redhat.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
nouveau@lists.freedesktop.org,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Sven Peter <sven@svenpeter.dev>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Vineet Gupta <vgupta@kernel.org>, Vinod Koul <vkoul@kernel.org>,
Wei Liu <wei.liu@kernel.org>, Will Deacon <will@kernel.org>
Cc: Lu Baolu <baolu.lu@linux.intel.com>,
Christoph Hellwig <hch@lst.de>,
Jerry Snitselaar <jsnitsel@redhat.com>,
Hector Martin <marcan@marcan.st>, Moritz Fischer <mdf@kernel.org>,
Moritz Fischer <moritzf@google.com>,
patches@lists.linux.dev,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Rob Herring <robh@kernel.org>,
Thierry Reding <thierry.reding@gmail.com>,
Thierry Reding <treding@nvidia.com>
Subject: [PATCH v2 3/7] iommu/of: Use -ENODEV consistently in of_iommu_configure()
Date: Thu, 7 Dec 2023 14:03:10 -0400 [thread overview]
Message-ID: <3-v2-16e4def25ebb+820-iommu_fwspec_p1_jgg@nvidia.com> (raw)
In-Reply-To: <0-v2-16e4def25ebb+820-iommu_fwspec_p1_jgg@nvidia.com>
Instead of returning 1 and trying to handle positive error codes just
stick to the convention of returning -ENODEV. Remove references to ops
from of_iommu_configure(), a NULL ops will already generate an error code.
There is no reason to check dev->bus, if err=0 at this point then the
called configure functions thought there was an iommu and we should try to
probe it. Remove it.
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: Moritz Fischer <moritzf@google.com>
Tested-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/iommu/of_iommu.c | 49 ++++++++++++----------------------------
1 file changed, 15 insertions(+), 34 deletions(-)
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
index c6510d7e7b241b..164317bfb8a81f 100644
--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -17,8 +17,6 @@
#include <linux/slab.h>
#include <linux/fsl/mc.h>
-#define NO_IOMMU 1
-
static int of_iommu_xlate(struct device *dev,
struct of_phandle_args *iommu_spec)
{
@@ -29,7 +27,7 @@ static int of_iommu_xlate(struct device *dev,
ops = iommu_ops_from_fwnode(fwnode);
if ((ops && !ops->of_xlate) ||
!of_device_is_available(iommu_spec->np))
- return NO_IOMMU;
+ return -ENODEV;
ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops);
if (ret)
@@ -61,7 +59,7 @@ static int of_iommu_configure_dev_id(struct device_node *master_np,
"iommu-map-mask", &iommu_spec.np,
iommu_spec.args);
if (err)
- return err == -ENODEV ? NO_IOMMU : err;
+ return err;
err = of_iommu_xlate(dev, &iommu_spec);
of_node_put(iommu_spec.np);
@@ -72,7 +70,7 @@ static int of_iommu_configure_dev(struct device_node *master_np,
struct device *dev)
{
struct of_phandle_args iommu_spec;
- int err = NO_IOMMU, idx = 0;
+ int err = -ENODEV, idx = 0;
while (!of_parse_phandle_with_args(master_np, "iommus",
"#iommu-cells",
@@ -117,9 +115,8 @@ static int of_iommu_configure_device(struct device_node *master_np,
int of_iommu_configure(struct device *dev, struct device_node *master_np,
const u32 *id)
{
- const struct iommu_ops *ops = NULL;
struct iommu_fwspec *fwspec;
- int err = NO_IOMMU;
+ int err;
if (!master_np)
return -ENODEV;
@@ -153,37 +150,21 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
} else {
err = of_iommu_configure_device(master_np, dev, id);
}
-
- /*
- * Two success conditions can be represented by non-negative err here:
- * >0 : there is no IOMMU, or one was unavailable for non-fatal reasons
- * 0 : we found an IOMMU, and dev->fwspec is initialised appropriately
- * <0 : any actual error
- */
- if (!err) {
- /* The fwspec pointer changed, read it again */
- fwspec = dev_iommu_fwspec_get(dev);
- ops = fwspec->ops;
- }
mutex_unlock(&iommu_probe_device_lock);
- /*
- * If we have reason to believe the IOMMU driver missed the initial
- * probe for dev, replay it to get things in order.
- */
- if (!err && dev->bus)
- err = iommu_probe_device(dev);
-
- /* Ignore all other errors apart from EPROBE_DEFER */
- if (err < 0) {
- if (err == -EPROBE_DEFER)
- return err;
- dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
+ if (err == -ENODEV || err == -EPROBE_DEFER)
return err;
- }
- if (!ops)
- return -ENODEV;
+ if (err)
+ goto err_log;
+
+ err = iommu_probe_device(dev);
+ if (err)
+ goto err_log;
return 0;
+
+err_log:
+ dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
+ return err;
}
static enum iommu_resv_type __maybe_unused
--
2.43.0
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
next prev parent reply other threads:[~2023-12-07 18:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-07 18:03 [PATCH v2 0/7] IOMMU related FW parsing cleanup Jason Gunthorpe
2023-12-07 18:03 ` [PATCH v2 1/7] iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops() Jason Gunthorpe
2023-12-07 18:03 ` [PATCH v2 2/7] iommmu/of: Do not return struct iommu_ops from of_iommu_configure() Jason Gunthorpe
2023-12-07 18:03 ` Jason Gunthorpe [this message]
2023-12-07 18:03 ` [PATCH v2 4/7] iommu: Mark dev_iommu_get() with lockdep Jason Gunthorpe
2023-12-07 18:03 ` [PATCH v2 5/7] iommu: Mark dev_iommu_priv_set() with a lockdep Jason Gunthorpe
2023-12-07 18:03 ` [PATCH v2 6/7] acpi: Do not return struct iommu_ops from acpi_iommu_configure_id() Jason Gunthorpe
2023-12-07 18:03 ` [PATCH v2 7/7] iommu/tegra: Use tegra_dev_iommu_get_stream_id() in the remaining places Jason Gunthorpe
2023-12-12 9:19 ` [PATCH v2 0/7] IOMMU related FW parsing cleanup 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=3-v2-16e4def25ebb+820-iommu_fwspec_p1_jgg@nvidia.com \
--to=jgg@nvidia.com \
--cc=airlied@gmail.com \
--cc=alyssa@rosenzweig.io \
--cc=aou@eecs.berkeley.edu \
--cc=asahi@lists.linux.dev \
--cc=baolu.lu@linux.intel.com \
--cc=catalin.marinas@arm.com \
--cc=dakr@redhat.com \
--cc=daniel@ffwll.ch \
--cc=decui@microsoft.com \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=dwmw2@infradead.org \
--cc=frowand.list@gmail.com \
--cc=haiyangz@microsoft.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=jsnitsel@redhat.com \
--cc=kherbst@redhat.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=kys@microsoft.com \
--cc=ldewangan@nvidia.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=linux-tegra@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lyude@redhat.com \
--cc=m.szyprowski@samsung.com \
--cc=marcan@marcan.st \
--cc=mdf@kernel.org \
--cc=moritzf@google.com \
--cc=nouveau@lists.freedesktop.org \
--cc=palmer@dabbelt.com \
--cc=patches@lists.linux.dev \
--cc=paul.walmsley@sifive.com \
--cc=rafael.j.wysocki@intel.com \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=sven@svenpeter.dev \
--cc=thierry.reding@gmail.com \
--cc=treding@nvidia.com \
--cc=tsbogend@alpha.franken.de \
--cc=vgupta@kernel.org \
--cc=vkoul@kernel.org \
--cc=wei.liu@kernel.org \
--cc=will@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).