mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 16/19] driver: make dev_platform_ioremap_resource() device-managed
Date: Wed, 28 Oct 2026 10:14:50 +0100	[thread overview]
Message-ID: <20261028092442.3300753-17-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20261028092442.3300753-1-a.fatoum@pengutronix.de>

From: Ahmad Fatoum <a.fatoum@barebox.org>

Unlike devm_platform_ioremap_resource() in Linux, the barebox stand-in
never releases its region. Most users call clk_get() or regulator_get()
after it, so a deferred probe leaves the region requested and the retry
fails with -EBUSY.

Implement it on top of devm_request_mem_resource() and move it out of
line to devres.c.

Assisted-by: Claude:opus-5-1m
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/base/devres.c  | 32 ++++++++++++++++++++++++++++++++
 include/linux/device.h | 11 +----------
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index efc810a8898f..f68b8e7b6590 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -7,6 +7,7 @@
 
 #include <barebox.h>
 #include <driver.h>
+#include <io.h>
 #include <dma.h>
 #include <talloc.h>
 #include <xfuncs.h>
@@ -204,3 +205,34 @@ struct resource *devm_request_mem_resource(struct device *dev, int num)
 	return res;
 }
 EXPORT_SYMBOL(devm_request_mem_resource);
+
+/**
+ * dev_platform_ioremap_resource() - request and map resource 'num' for a device
+ * @dev: device to request the memory resource for
+ * @num: index of the memory resource
+ *
+ * barebox maps everything outside the RAM banks suitably for MMIO, so this
+ * only requests the device-managed region.
+ *
+ * Return: a pointer to the registers or an ERR_PTR() on failure.
+ */
+void __iomem *dev_platform_ioremap_resource(struct device *dev, int num)
+{
+	struct resource *res;
+
+	res = devm_request_mem_resource(dev, num);
+	if (IS_ERR(res))
+		return IOMEM_ERR_PTR(PTR_ERR(res));
+
+	/* As everything is mapped 1:1 by default, drivers on unlucky
+	 * platforms can end up successfully requesting memory, but
+	 * getting a base address that looks like an error pointer.
+	 * Let's warn loudly about this case, as these drivers
+	 * should be using devm_request_mem_resource instead.
+	 */
+	if (WARN_ON(IS_ERR_VALUE(res->start)))
+		return IOMEM_ERR_PTR(-EINVAL);
+
+	return IOMEM(res->start);
+}
+EXPORT_SYMBOL(dev_platform_ioremap_resource);
diff --git a/include/linux/device.h b/include/linux/device.h
index 9b14bc74fef6..2b33580cd573 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -146,16 +146,7 @@ static inline int devm_add_action_or_reset(struct device *dev,
 #define driver_unregister unregister_driver
 
 
-static inline void __iomem *dev_platform_ioremap_resource(struct device *dev,
-							  int resource)
-{
-	/*
-	 * barebox maps everything outside the RAM banks suitably for MMIO,
-	 * so we don't need to do anything besides requesting the regions
-	 * and can leave the memory attributes unchanged.
-	 */
-	return dev_request_mem_region(dev, resource);
-}
+void __iomem *dev_platform_ioremap_resource(struct device *dev, int num);
 
 static inline void __iomem *devm_ioremap(struct device *dev,
 					 resource_size_t start,
-- 
2.47.3




  parent reply	other threads:[~2026-10-28  9:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28  9:14 [PATCH 00/19] driver: add devm_ support Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 01/19] commands: devunbind: refuse to unbind devices that were never bound Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 02/19] commands: devunbind: don't poison the active list entry Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 03/19] talloc: remove unused talloc_steal() and talloc_steal_children() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 04/19] talloc: free children in a loop Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 05/19] talloc: add support for destructors Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 06/19] test: self: talloc: add destructor tests Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 07/19] talloc: add talloc_run_destructors() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 08/19] mfd: pca9450: don't free device-managed memory in probe error path Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 09/19] video: backlight-pwm: allocate brightness levels with devm_kcalloc Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 10/19] driver: implement devm_ allocation helpers on top of talloc Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 11/19] devres: Provide kmalloc_obj*-style API for devm_kmalloc Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 12/19] memory: atmel-ebi: use generic devm_kzalloc() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 13/19] driver: add devm_add_action() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 14/19] test: self: add devm_ selftest Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 15/19] driver: add devm_request_mem_resource() Ahmad Fatoum
2026-10-28  9:14 ` Ahmad Fatoum [this message]
2026-10-28  9:14 ` [PATCH 17/19] treewide: rename dev_platform_ioremap_resource() to devm_platform_ioremap_resource() Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 18/19] driver: make dev_platform_get_and_ioremap_resource() device-managed Ahmad Fatoum
2026-10-28  9:14 ` [PATCH 19/19] serial: stm32: request the registers with devm_request_mem_resource() Ahmad Fatoum

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=20261028092442.3300753-17-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.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