* [PATCH v2 1/5] Documentation: devres: add missing entry for devm_platform_ioremap_resource()
2019-10-02 16:25 [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource() Bartosz Golaszewski
@ 2019-10-02 16:25 ` Bartosz Golaszewski
2019-10-02 16:25 ` [PATCH v2 2/5] lib: devres: prepare devm_ioremap_resource() for more variants Bartosz Golaszewski
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2019-10-02 16:25 UTC (permalink / raw)
To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki, Arnd Bergmann
Cc: linux-doc, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
devm_platform_ioremap_resource() should be documented in devres.rst.
Add the missing entry.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
Documentation/driver-api/driver-model/devres.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index a100bef54952..8e3087662daf 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -316,6 +316,7 @@ IOMAP
devm_ioremap_nocache()
devm_ioremap_wc()
devm_ioremap_resource() : checks resource, requests memory region, ioremaps
+ devm_platform_ioremap_resource() : calls devm_ioremap_resource() for platform device
devm_iounmap()
pcim_iomap()
pcim_iomap_regions() : do request_region() and iomap() on multiple BARs
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/5] lib: devres: prepare devm_ioremap_resource() for more variants
2019-10-02 16:25 [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource() Bartosz Golaszewski
2019-10-02 16:25 ` [PATCH v2 1/5] Documentation: devres: add missing entry for devm_platform_ioremap_resource() Bartosz Golaszewski
@ 2019-10-02 16:25 ` Bartosz Golaszewski
2019-10-02 16:25 ` [PATCH v2 3/5] lib: devres: provide devm_ioremap_resource_wc() Bartosz Golaszewski
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2019-10-02 16:25 UTC (permalink / raw)
To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki, Arnd Bergmann
Cc: linux-doc, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
We want to add the write-combined variant of devm_ioremap_resource().
Let's first implement __devm_ioremap_resource() which takes
an additional argument type. The types are the same as for
__devm_ioremap(). The existing devm_ioremap_resource() now simply
calls __devm_ioremap_resource() with regular DEVM_IOREMAP type.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
lib/devres.c | 47 +++++++++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 20 deletions(-)
diff --git a/lib/devres.c b/lib/devres.c
index 6a0e9bd6524a..a14c727128c1 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -114,25 +114,9 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
}
EXPORT_SYMBOL(devm_iounmap);
-/**
- * devm_ioremap_resource() - check, request region, and ioremap resource
- * @dev: generic device to handle the resource for
- * @res: resource to be handled
- *
- * Checks that a resource is a valid memory region, requests the memory
- * region and ioremaps it. All operations are managed and will be undone
- * on driver detach.
- *
- * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
- * on failure. Usage example:
- *
- * res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- * base = devm_ioremap_resource(&pdev->dev, res);
- * if (IS_ERR(base))
- * return PTR_ERR(base);
- */
-void __iomem *devm_ioremap_resource(struct device *dev,
- const struct resource *res)
+static void __iomem *
+__devm_ioremap_resource(struct device *dev, const struct resource *res,
+ enum devm_ioremap_type type)
{
resource_size_t size;
void __iomem *dest_ptr;
@@ -151,7 +135,7 @@ void __iomem *devm_ioremap_resource(struct device *dev,
return IOMEM_ERR_PTR(-EBUSY);
}
- dest_ptr = devm_ioremap(dev, res->start, size);
+ dest_ptr = __devm_ioremap(dev, res->start, size, type);
if (!dest_ptr) {
dev_err(dev, "ioremap failed for resource %pR\n", res);
devm_release_mem_region(dev, res->start, size);
@@ -160,6 +144,29 @@ void __iomem *devm_ioremap_resource(struct device *dev,
return dest_ptr;
}
+
+/**
+ * devm_ioremap_resource() - check, request region, and ioremap resource
+ * @dev: generic device to handle the resource for
+ * @res: resource to be handled
+ *
+ * Checks that a resource is a valid memory region, requests the memory
+ * region and ioremaps it. All operations are managed and will be undone
+ * on driver detach.
+ *
+ * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
+ * on failure. Usage example:
+ *
+ * res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ * base = devm_ioremap_resource(&pdev->dev, res);
+ * if (IS_ERR(base))
+ * return PTR_ERR(base);
+ */
+void __iomem *devm_ioremap_resource(struct device *dev,
+ const struct resource *res)
+{
+ return __devm_ioremap_resource(dev, res, DEVM_IOREMAP);
+}
EXPORT_SYMBOL(devm_ioremap_resource);
/*
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/5] lib: devres: provide devm_ioremap_resource_wc()
2019-10-02 16:25 [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource() Bartosz Golaszewski
2019-10-02 16:25 ` [PATCH v2 1/5] Documentation: devres: add missing entry for devm_platform_ioremap_resource() Bartosz Golaszewski
2019-10-02 16:25 ` [PATCH v2 2/5] lib: devres: prepare devm_ioremap_resource() for more variants Bartosz Golaszewski
@ 2019-10-02 16:25 ` Bartosz Golaszewski
2019-10-02 16:25 ` [PATCH v2 4/5] drivers: platform: provide devm_platform_ioremap_resource_wc() Bartosz Golaszewski
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2019-10-02 16:25 UTC (permalink / raw)
To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki, Arnd Bergmann
Cc: linux-doc, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Provide a variant of devm_ioremap_resource() for write-combined ioremap.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
Documentation/driver-api/driver-model/devres.rst | 1 +
include/linux/device.h | 2 ++
lib/devres.c | 15 +++++++++++++++
3 files changed, 18 insertions(+)
diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index 8e3087662daf..e605bb9df6e1 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -316,6 +316,7 @@ IOMAP
devm_ioremap_nocache()
devm_ioremap_wc()
devm_ioremap_resource() : checks resource, requests memory region, ioremaps
+ devm_ioremap_resource_wc()
devm_platform_ioremap_resource() : calls devm_ioremap_resource() for platform device
devm_iounmap()
pcim_iomap()
diff --git a/include/linux/device.h b/include/linux/device.h
index 297239a08bb7..1f4aaf2d4b2a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -946,6 +946,8 @@ extern void devm_free_pages(struct device *dev, unsigned long addr);
void __iomem *devm_ioremap_resource(struct device *dev,
const struct resource *res);
+void __iomem *devm_ioremap_resource_wc(struct device *dev,
+ const struct resource *res);
void __iomem *devm_of_iomap(struct device *dev,
struct device_node *node, int index,
diff --git a/lib/devres.c b/lib/devres.c
index a14c727128c1..97fb44e5b4d6 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -169,6 +169,21 @@ void __iomem *devm_ioremap_resource(struct device *dev,
}
EXPORT_SYMBOL(devm_ioremap_resource);
+/**
+ * devm_ioremap_resource_wc() - write-combined variant of
+ * devm_ioremap_resource()
+ * @dev: generic device to handle the resource for
+ * @res: resource to be handled
+ *
+ * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
+ * on failure. Usage example:
+ */
+void __iomem *devm_ioremap_resource_wc(struct device *dev,
+ const struct resource *res)
+{
+ return __devm_ioremap_resource(dev, res, DEVM_IOREMAP_WC);
+}
+
/*
* devm_of_iomap - Requests a resource and maps the memory mapped IO
* for a given device_node managed by a given device
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/5] drivers: platform: provide devm_platform_ioremap_resource_wc()
2019-10-02 16:25 [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource() Bartosz Golaszewski
` (2 preceding siblings ...)
2019-10-02 16:25 ` [PATCH v2 3/5] lib: devres: provide devm_ioremap_resource_wc() Bartosz Golaszewski
@ 2019-10-02 16:25 ` Bartosz Golaszewski
2019-10-02 16:25 ` [PATCH v2 5/5] misc: sram: use devm_platform_ioremap_resource_wc() Bartosz Golaszewski
2019-10-06 5:40 ` [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource() Bartosz Golaszewski
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2019-10-02 16:25 UTC (permalink / raw)
To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki, Arnd Bergmann
Cc: linux-doc, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Provide a write-combined variant of devm_platform_ioremap_resource().
While at it: in order not to duplicate code - pass the resource
retrieved by platform_get_resource() directly to the appropriate
devm_ioremap_resource() variant.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
.../driver-api/driver-model/devres.rst | 1 +
drivers/base/platform.c | 27 +++++++++++++++----
include/linux/platform_device.h | 3 +++
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index e605bb9df6e1..480b78ca3871 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -318,6 +318,7 @@ IOMAP
devm_ioremap_resource() : checks resource, requests memory region, ioremaps
devm_ioremap_resource_wc()
devm_platform_ioremap_resource() : calls devm_ioremap_resource() for platform device
+ devm_platform_ioremap_resource_wc()
devm_iounmap()
pcim_iomap()
pcim_iomap_regions() : do request_region() and iomap() on multiple BARs
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index b6c6c7d97d5b..8fdf3eb23bda 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -60,6 +60,7 @@ struct resource *platform_get_resource(struct platform_device *dev,
}
EXPORT_SYMBOL_GPL(platform_get_resource);
+#ifdef CONFIG_HAS_IOMEM
/**
* devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
* device
@@ -68,16 +69,32 @@ EXPORT_SYMBOL_GPL(platform_get_resource);
* resource management
* @index: resource index
*/
-#ifdef CONFIG_HAS_IOMEM
void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
unsigned int index)
{
- struct resource *res;
-
- res = platform_get_resource(pdev, IORESOURCE_MEM, index);
- return devm_ioremap_resource(&pdev->dev, res);
+ return devm_ioremap_resource(&pdev->dev,
+ platform_get_resource(pdev,
+ IORESOURCE_MEM,
+ index));
}
EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
+
+/**
+ * devm_platform_ioremap_resource_wc - write-combined variant of
+ * devm_platform_ioremap_resource()
+ *
+ * @pdev: platform device to use both for memory resource lookup as well as
+ * resource management
+ * @index: resource index
+ */
+void __iomem *devm_platform_ioremap_resource_wc(struct platform_device *pdev,
+ unsigned int index)
+{
+ return devm_ioremap_resource_wc(&pdev->dev,
+ platform_get_resource(pdev,
+ IORESOURCE_MEM,
+ index));
+}
#endif /* CONFIG_HAS_IOMEM */
static int __platform_get_irq(struct platform_device *dev, unsigned int num)
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 1b5cec067533..83930790c701 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -57,6 +57,9 @@ platform_find_device_by_driver(struct device *start,
extern void __iomem *
devm_platform_ioremap_resource(struct platform_device *pdev,
unsigned int index);
+extern void __iomem *
+devm_platform_ioremap_resource_wc(struct platform_device *pdev,
+ unsigned int index);
extern int platform_get_irq(struct platform_device *, unsigned int);
extern int platform_get_irq_optional(struct platform_device *, unsigned int);
extern int platform_irq_count(struct platform_device *);
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 5/5] misc: sram: use devm_platform_ioremap_resource_wc()
2019-10-02 16:25 [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource() Bartosz Golaszewski
` (3 preceding siblings ...)
2019-10-02 16:25 ` [PATCH v2 4/5] drivers: platform: provide devm_platform_ioremap_resource_wc() Bartosz Golaszewski
@ 2019-10-02 16:25 ` Bartosz Golaszewski
2019-10-06 5:40 ` [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource() Bartosz Golaszewski
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2019-10-02 16:25 UTC (permalink / raw)
To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki, Arnd Bergmann
Cc: linux-doc, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Use the new devm_platform_ioremap_resource_wc() helper instead of
devm_ioremap_wc() combinded with a call to platform_get_resource().
Also use devm_platform_ioremap_resource() where applicable.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/misc/sram.c | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index f30448bf3a63..6c1a23cb3e8c 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -340,8 +340,6 @@ static const struct of_device_id sram_dt_ids[] = {
static int sram_probe(struct platform_device *pdev)
{
struct sram_dev *sram;
- struct resource *res;
- size_t size;
int ret;
int (*init_func)(void);
@@ -351,25 +349,14 @@ static int sram_probe(struct platform_device *pdev)
sram->dev = &pdev->dev;
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res) {
- dev_err(sram->dev, "found no memory resource\n");
- return -EINVAL;
- }
-
- size = resource_size(res);
-
- if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) {
- dev_err(sram->dev, "could not request region for resource\n");
- return -EBUSY;
- }
-
if (of_property_read_bool(pdev->dev.of_node, "no-memory-wc"))
- sram->virt_base = devm_ioremap(sram->dev, res->start, size);
+ sram->virt_base = devm_platform_ioremap_resource(pdev, 0);
else
- sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
- if (!sram->virt_base)
- return -ENOMEM;
+ sram->virt_base = devm_platform_ioremap_resource_wc(pdev, 0);
+ if (IS_ERR(sram->virt_base)) {
+ dev_err(&pdev->dev, "could not map SRAM registers\n");
+ return PTR_ERR(sram->virt_base);
+ }
sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
NUMA_NO_NODE, NULL);
@@ -382,7 +369,8 @@ static int sram_probe(struct platform_device *pdev)
else
clk_prepare_enable(sram->clk);
- ret = sram_reserve_regions(sram, res);
+ ret = sram_reserve_regions(sram,
+ platform_get_resource(pdev, IORESOURCE_MEM, 0));
if (ret)
goto err_disable_clk;
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource()
2019-10-02 16:25 [PATCH v2 0/5] drivers: add a new variant of devm_platform_ioremap_resource() Bartosz Golaszewski
` (4 preceding siblings ...)
2019-10-02 16:25 ` [PATCH v2 5/5] misc: sram: use devm_platform_ioremap_resource_wc() Bartosz Golaszewski
@ 2019-10-06 5:40 ` Bartosz Golaszewski
5 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2019-10-06 5:40 UTC (permalink / raw)
To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki, Arnd Bergmann
Cc: linux-doc, Linux Kernel Mailing List, Bartosz Golaszewski
śr., 2 paź 2019 o 18:25 Bartosz Golaszewski <brgl@bgdev.pl> napisał(a):
>
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> The new devm_platform_ioremap_resource() helper has now been widely
> adopted and used in many drivers. Users of the write-combined ioremap()
> variants could benefit from the same code shrinkage. This series provides
> a write-combined version of devm_platform_ioremap_resource() and uses it in a
> relevant driver with the assumption that - just like was the case
> previously - a coccinelle script will be developed to ease the transition
> for others.
>
> v1 -> v2:
> - dropped everything related to nocache ioremap as this is going away
>
> Bartosz Golaszewski (5):
> Documentation: devres: add missing entry for
> devm_platform_ioremap_resource()
> lib: devres: prepare devm_ioremap_resource() for more variants
> lib: devres: provide devm_ioremap_resource_wc()
> drivers: platform: provide devm_platform_ioremap_resource_wc()
> misc: sram: use devm_platform_ioremap_resource_wc()
>
> .../driver-api/driver-model/devres.rst | 3 +
> drivers/base/platform.c | 27 ++++++--
> drivers/misc/sram.c | 28 +++------
> include/linux/device.h | 2 +
> include/linux/platform_device.h | 3 +
> lib/devres.c | 62 +++++++++++++------
> 6 files changed, 80 insertions(+), 45 deletions(-)
>
> --
> 2.23.0
>
Superseded by v3 which adds another variant that might be useful.
Bart
^ permalink raw reply [flat|nested] 7+ messages in thread