Skip to contentSkip to conversation

introduce ioremap() and dev_ioremap_resource()

RFC In review Antony Pavlov 2 participants 5 messages Dec 18, 2014 – Jan 8, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 introduce ioremap() and dev_ioremap_resource()

The commit

commit 0d7a21334536cb36b3c9b64d868acc55aec41332
Author: Antony Pavlov <[email protected]>
Date: Wed Sep 10 11:42:19 2014 +0400

MIPS: dts: use physical addresses (as Linux does)

With IOMEM() adapted for MIPS we can use physical addresses in device tree reg property.

is premature. Current device tree files unusable on real hardware.
I'M SO SORRY!
The patch was tested on qemu, but qemu malta board is tolerant of using physical addresses for accesing to device. Real hardware can throw an exception in this situation.

Additional physical address to virtual address translation on MIPS is needed.

This commit demonstrate a possible (but not very good) solution. This solution is copied-and-pasted from linux kernel. In linux drivers use devm_ioremap_resource() function, so the patch just replicates similar dev_ioremap_resource() function.

Changing dev_request_mem_region() to dev_ioremap_resource()
is not a very good idea because there are too many dev_request_mem_region() in barebox sources

barebox$ git grep dev_request_mem_region | wc -l 197

moreover dev_ioremap_resource() has the second 'struct resource *res' argument, so additional dev_get_resource() is needed.

Can we insert ioremap() into dev_request_mem_region() directly? (we also can use already existion IOMEM() macro instead of linux' ioremap()).

E.g.

drivers/base/driver.c +0 -0
@@ -330,7 +330,7 @@ void __iomem *dev_request_mem_region(struct device_d

*dev, int num)

        if (IS_ERR(res))
                return ERR_CAST(res);

- return (void __force __iomem *)res->start;
+ return ioremap((phys_t)res->start);
}
EXPORT_SYMBOL(dev_request_mem_region);

---
 arch/arm/include/asm/io.h       |  5 +++++
 arch/mips/include/asm/io.h      |  7 +++++++
 common/resource.c               | 11 +++++++++++
 drivers/serial/serial_ns16550.c |  2 +-
 include/driver.h                |  2 ++
 5 files changed, 26 insertions(+), 1 deletion(-)
arch/arm/include/asm/io.h +5 -0
index ccf1f59..ffe05b6 100644
@@ -5,6 +5,11 @@
 
 #define	IO_SPACE_LIMIT	0
 
+static inline void __iomem *ioremap(phys_addr_t phys_addr)
+{
+        return (void __iomem *)phys_addr;
+}
+
 /*
  * String version of IO memory access ops:
  */
arch/mips/include/asm/io.h +7 -0
index 4832be6..fa0b2d0 100644
@@ -13,9 +13,16 @@
 #include <linux/compiler.h>
 #include <asm/types.h>
 #include <asm/byteorder.h>
+#include <asm/addrspace.h>
 
 #define	IO_SPACE_LIMIT	0
 
+static inline void __iomem *ioremap(phys_t phys_addr)
+{
+	return (void __iomem *)
+                               (unsigned long)CKSEG1ADDR(phys_addr);
+}
+
 /*****************************************************************************/
 /*
  * readX/writeX() are used to access memory mapped devices. On some
common/resource.c +11 -0
index e4bbe15..79960fd 100644
@@ -128,6 +128,17 @@ struct resource *request_iomem_region(const char *name,
 	return __request_region(&iomem_resource, name, start, end);
 }
 
+void __iomem *dev_ioremap_resource(struct device_d *dev, struct resource *res)
+{
+	struct resource *r;
+
+	r = request_iomem_region(dev_name(dev), res->start, res->end);
+	if (IS_ERR(r))
+		return ERR_CAST(r);
+
+	return ioremap(res->start);
+}
+
 /* The root resource for the whole io-mapped io space */
 struct resource ioport_resource = {
 	.start = 0,
drivers/serial/serial_ns16550.c +1 -1
index 8f2e93f..0e9e0f3 100644
@@ -325,7 +325,7 @@ static int ns16550_init_iomem(struct device_d *dev, struct ns16550_priv *priv)
 	if (IS_ERR(res))
 		return PTR_ERR(res);
 
-	priv->mmiobase = dev_request_mem_region(dev, 0);
+	priv->mmiobase = dev_ioremap_resource(dev, res);
 	if (IS_ERR(priv->mmiobase))
 		return PTR_ERR(priv->mmiobase);
 
include/driver.h +2 -0
index 53e1000..4fc1b63 100644
@@ -206,6 +206,8 @@ void *dev_get_mem_region(struct device_d *dev, int num);
  */
 void __iomem *dev_request_mem_region(struct device_d *dev, int num);
 
+void __iomem *dev_ioremap_resource(struct device_d *dev, struct resource *res);
+
 struct device_d *device_alloc(const char *devname, int id);
 
 int device_add_resources(struct device_d *dev, const struct resource *res, int num);
Signature · 7 lines
2.1.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 28 lines · Antony Pavlov

The commit

commit 0d7a21334536cb36b3c9b64d868acc55aec41332
Author: Antony Pavlov <[email protected]>
Date: Wed Sep 10 11:42:19 2014 +0400

MIPS: dts: use physical addresses (as Linux does)

With IOMEM() adapted for MIPS we can use physical addresses in device tree reg property.

is premature. Current device tree files unusable on real hardware.
I'M SO SORRY!
The patch was tested on qemu, but qemu malta board is tolerant of using physical addresses for accesing to device. Real hardware can throw an exception in this situation.

Additional physical address to virtual address translation on MIPS is needed.

This commit demonstrate a possible (but not very good) solution. This solution is copied-and-pasted from linux kernel. In linux drivers use devm_ioremap_resource() function, so the patch just replicates similar dev_ioremap_resource() function.

Changing dev_request_mem_region() to dev_ioremap_resource()
is not a very good idea because there are too many dev_request_mem_region() in barebox sources

Quoted 8 lines

barebox$ git grep dev_request_mem_region | wc -l 197

moreover dev_ioremap_resource() has the second 'struct resource *res' argument, so additional dev_get_resource() is needed.

Can we insert ioremap() into dev_request_mem_region() directly? (we also can use already existion IOMEM() macro instead of linux' ioremap()).

I'm not sure if it's a good idea to put that behind some standard lookingioremap() call, because its behaviour is not standard.

I'm also fine with adding some

#ifdef CONFIG_MIPS
	return mips_iomem(res->start);
#else
	return (void __force __iomem *)res->start;

#endif

At least this makes explicit that MIPS has a very special handling.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
Quoted 43 lines · On Fri, 19 Dec 2014 07:45:42 +0100 Sascha Hauer <[email protected]> wrote:
Quoted 28 lines · Antony Pavlov

The commit

commit 0d7a21334536cb36b3c9b64d868acc55aec41332
Author: Antony Pavlov <[email protected]>
Date: Wed Sep 10 11:42:19 2014 +0400

MIPS: dts: use physical addresses (as Linux does)

With IOMEM() adapted for MIPS we can use physical addresses in device tree reg property.

is premature. Current device tree files unusable on real hardware.
I'M SO SORRY!
The patch was tested on qemu, but qemu malta board is tolerant of using physical addresses for accesing to device. Real hardware can throw an exception in this situation.

Additional physical address to virtual address translation on MIPS is needed.

This commit demonstrate a possible (but not very good) solution. This solution is copied-and-pasted from linux kernel. In linux drivers use devm_ioremap_resource() function, so the patch just replicates similar dev_ioremap_resource() function.

Changing dev_request_mem_region() to dev_ioremap_resource()
is not a very good idea because there are too many dev_request_mem_region() in barebox sources

Quoted 8 lines

barebox$ git grep dev_request_mem_region | wc -l 197

moreover dev_ioremap_resource() has the second 'struct resource *res' argument, so additional dev_get_resource() is needed.

Can we insert ioremap() into dev_request_mem_region() directly? (we also can use already existion IOMEM() macro instead of linux' ioremap()).

I'm not sure if it's a good idea to put that behind some standard lookingioremap() call, because its behaviour is not standard.

I'm also fine with adding some

Quoted 7 lines
#ifdef CONFIG_MIPS
	return mips_iomem(res->start);
#else
	return (void __force __iomem *)res->start;

#endif

At least this makes explicit that MIPS has a very special handling.

We already have this in include/common.h

#if defined(CONFIG_MIPS)
#include <asm/addrspace.h>

#define IOMEM(addr) ((void __force __iomem *)CKSEG1ADDR(addr)) #else
#define IOMEM(addr) ((void __force __iomem *)(addr)) #endif

So can I use just

    return IOMEM(res->start);

in dev_request_mem_region()?

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw
Quoted 30 lines · Antony Pavlov

On Fri, 19 Dec 2014 07:45:42 +0100

Quoted 11 lines
Quoted 5 lines

moreover dev_ioremap_resource() has the second 'struct resource *res' argument, so additional dev_get_resource() is needed.

Can we insert ioremap() into dev_request_mem_region() directly? (we also can use already existion IOMEM() macro instead of linux' ioremap()).

I'm not sure if it's a good idea to put that behind some standard lookingioremap() call, because its behaviour is not standard.

I'm also fine with adding some

Quoted 7 lines
#ifdef CONFIG_MIPS
	return mips_iomem(res->start);
#else
	return (void __force __iomem *)res->start;

#endif

At least this makes explicit that MIPS has a very special handling.

We already have this in include/common.h

#if defined(CONFIG_MIPS)
#include <asm/addrspace.h>

#define IOMEM(addr) ((void __force __iomem *)CKSEG1ADDR(addr)) #else
#define IOMEM(addr) ((void __force __iomem *)(addr)) #endif

Quoted 5 lines

So can I use just

    return IOMEM(res->start);

in dev_request_mem_region()?

Yes, nice. That's the right solution then.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw
Quoted 31 lines · On Sat, 20 Dec 2014 08:05:42 +0100 Sascha Hauer <[email protected]> wrote:
Quoted 30 lines · Antony Pavlov

On Fri, 19 Dec 2014 07:45:42 +0100

Quoted 11 lines
Quoted 5 lines

moreover dev_ioremap_resource() has the second 'struct resource *res' argument, so additional dev_get_resource() is needed.

Can we insert ioremap() into dev_request_mem_region() directly? (we also can use already existion IOMEM() macro instead of linux' ioremap()).

I'm not sure if it's a good idea to put that behind some standard lookingioremap() call, because its behaviour is not standard.

I'm also fine with adding some

Quoted 7 lines
#ifdef CONFIG_MIPS
	return mips_iomem(res->start);
#else
	return (void __force __iomem *)res->start;

#endif

At least this makes explicit that MIPS has a very special handling.

We already have this in include/common.h

#if defined(CONFIG_MIPS)
#include <asm/addrspace.h>

#define IOMEM(addr) ((void __force __iomem *)CKSEG1ADDR(addr)) #else
#define IOMEM(addr) ((void __force __iomem *)(addr)) #endif

Quoted 7 lines
Quoted 5 lines

So can I use just

    return IOMEM(res->start);

in dev_request_mem_region()?

Yes, nice. That's the right solution then.

Sascha! Just now all device-tree enabled MIPS boards are broken. Please hold over barebox 2015.01 release till dev_request_mem_region() fix; I'll send the patch in several hours (I want check it on several MIPS board).

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox