Skip to contentSkip to conversation

RFC: Fix big endian MMIO primitives.

PATCH Applied Krzysztof Halasa 2 participants 5 messages May 5, 2012 – May 7, 2012

lore
Share & tools
lore
#0 lore raw

cpu_read*() and cpu_wrire*() are precisely equal to __raw_read*() and __raw_write*().

Striving for correctness we can replace all those __raw_*() with cpu_*() as that's exactly what the former ones do. Also we can change read*() and write*() into explicit leXX_*(). Both changes could affect porting from Linux, though.

include/io.h +6 -15
index 39b5e61..8d885de 100644
@@ -4,20 +4,11 @@
 #include <asm/io.h>
 
 /* cpu_read/cpu_write: cpu native io accessors */
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define cpu_readb(a)		readb(a)
-#define cpu_readw(a)		in_be16(a)
-#define cpu_readl(a)		in_be32(a)
-#define cpu_writeb(v, a)	writeb((v), (a))
-#define cpu_writew(v, a)	out_be16((a), (v))
-#define cpu_writel(v, a)	out_be32((a), (v))
-#else
-#define cpu_readb(a)		readb(a)
-#define cpu_readw(a)		readw(a)
-#define cpu_readl(a)		readl(a)
-#define cpu_writeb(v, a)	writeb((v), (a))
-#define cpu_writew(v, a)	writew((v), (a))
-#define cpu_writel(v, a)	writel((v), (a))
-#endif
+#define cpu_readb(a)		__raw_readb(a)
+#define cpu_readw(a)		__raw_readw(a)
+#define cpu_readl(a)		__raw_readl(a)
+#define cpu_writeb(v, a)	__raw_writeb((v), (a))
+#define cpu_writew(v, a)	__raw_writew((v), (a))
+#define cpu_writel(v, a)	__raw_writel((v), (a))
 
 #endif /* __IO_H */

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

#1 lore raw
Quoted 7 lines · Krzysztof Halasa

cpu_read*() and cpu_wrire*() are precisely equal to __raw_read*() and __raw_write*().

Striving for correctness we can replace all those __raw_*() with cpu_*() as that's exactly what the former ones do. Also we can change read*() and write*() into explicit leXX_*(). Both changes could affect porting from Linux, though.

Maybe we should rather use the __raw_* variants in the cfi driver aswell which is the only user of the functions below. For some reason I believed that the __raw_* variants also do little endian accesses which is wrong.
I don't like the naming of the __raw_* variants very much as the underscores and 'raw' suggests that these are internal functions which one should rather not use, but in fact these are the correct functions in most SoC (non PCI) drivers. Anyway, since Linux has this functions we should use them aswell, everything else probably leads to more confusion.

Sascha

Quoted 39 lines
include/io.h +6 -15
index 39b5e61..8d885de 100644
@@ -4,20 +4,11 @@
 #include <asm/io.h>
 
 /* cpu_read/cpu_write: cpu native io accessors */
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define cpu_readb(a)		readb(a)
-#define cpu_readw(a)		in_be16(a)
-#define cpu_readl(a)		in_be32(a)
-#define cpu_writeb(v, a)	writeb((v), (a))
-#define cpu_writew(v, a)	out_be16((a), (v))
-#define cpu_writel(v, a)	out_be32((a), (v))
-#else
-#define cpu_readb(a)		readb(a)
-#define cpu_readw(a)		readw(a)
-#define cpu_readl(a)		readl(a)
-#define cpu_writeb(v, a)	writeb((v), (a))
-#define cpu_writew(v, a)	writew((v), (a))
-#define cpu_writel(v, a)	writel((v), (a))
-#endif
+#define cpu_readb(a)		__raw_readb(a)
+#define cpu_readw(a)		__raw_readw(a)
+#define cpu_readl(a)		__raw_readl(a)
+#define cpu_writeb(v, a)	__raw_writeb((v), (a))
+#define cpu_writew(v, a)	__raw_writew((v), (a))
+#define cpu_writel(v, a)	__raw_writel((v), (a))
 
 #endif /* __IO_H */

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

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 2 lines · Sascha Hauer

Maybe we should rather use the __raw_* variants in the cfi driver aswell which is the only user of the functions below.

We can do that for the sake of compatibility with Linux.

Quoted 9 lines

For some reason I
believed that the __raw_* variants also do little endian accesses which is wrong.
I don't like the naming of the __raw_* variants very much as the underscores and 'raw' suggests that these are internal functions which one should rather not use, but in fact these are the correct functions in most SoC (non PCI) drivers. Anyway, since Linux has this functions we should use them aswell, everything else probably leads to more confusion.

I don't know.

I would rename:
__raw_* -> cpu_*() as they are just plain and simple accessors with native endianness.

readl() and friends -> le32_readl() etc.
The 'l' is somewhat redundant, the size is already determined by '32' (and 16, 8). Maybe le32_read() or read_le32()?

Your call. We can just limit this renaming to cpu_* -> __raw_*.

To be honest, I would like this stuff renamed in Linux as well. Perhaps some day.

Signature · 6 lines
Krzysztof Halasa

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
Quoted 27 lines · Krzysztof Halasa
Quoted 2 lines · Sascha Hauer

Maybe we should rather use the __raw_* variants in the cfi driver aswell which is the only user of the functions below.

We can do that for the sake of compatibility with Linux.

Quoted 9 lines

For some reason I
believed that the __raw_* variants also do little endian accesses which is wrong.
I don't like the naming of the __raw_* variants very much as the underscores and 'raw' suggests that these are internal functions which one should rather not use, but in fact these are the correct functions in most SoC (non PCI) drivers. Anyway, since Linux has this functions we should use them aswell, everything else probably leads to more confusion.

I don't know.

I would rename:
__raw_* -> cpu_*() as they are just plain and simple accessors with native endianness.

readl() and friends -> le32_readl() etc.
The 'l' is somewhat redundant, the size is already determined by '32' (and 16, 8). Maybe le32_read() or read_le32()?

Quoted 5 lines

Your call. We can just limit this renaming to cpu_* -> __raw_*.

To be honest, I would like this stuff renamed in Linux as well. Perhaps some day.

I tend to take your patch as is. The cpu_* accessors have a clear meaning and don't conflict with anything in Linux, so why not just have them around. Anyway, I'll sleep over it before applying it.

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
Applied
#4 lore raw
In reply to Krzysztof Halasa
Quoted 9 lines · Krzysztof Halasa

cpu_read*() and cpu_wrire*() are precisely equal to __raw_read*() and __raw_write*().

Striving for correctness we can replace all those __raw_*() with cpu_*() as that's exactly what the former ones do. Also we can change read*() and write*() into explicit leXX_*(). Both changes could affect porting from Linux, though.

Applied, thanks

Sascha

Quoted 37 lines
include/io.h +6 -15
index 39b5e61..8d885de 100644
@@ -4,20 +4,11 @@
 #include <asm/io.h>
 
 /* cpu_read/cpu_write: cpu native io accessors */
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define cpu_readb(a)		readb(a)
-#define cpu_readw(a)		in_be16(a)
-#define cpu_readl(a)		in_be32(a)
-#define cpu_writeb(v, a)	writeb((v), (a))
-#define cpu_writew(v, a)	out_be16((a), (v))
-#define cpu_writel(v, a)	out_be32((a), (v))
-#else
-#define cpu_readb(a)		readb(a)
-#define cpu_readw(a)		readw(a)
-#define cpu_readl(a)		readl(a)
-#define cpu_writeb(v, a)	writeb((v), (a))
-#define cpu_writew(v, a)	writew((v), (a))
-#define cpu_writel(v, a)	writel((v), (a))
-#endif
+#define cpu_readb(a)		__raw_readb(a)
+#define cpu_readw(a)		__raw_readw(a)
+#define cpu_readl(a)		__raw_readl(a)
+#define cpu_writeb(v, a)	__raw_writeb((v), (a))
+#define cpu_writew(v, a)	__raw_writew((v), (a))
+#define cpu_writel(v, a)	__raw_writel((v), (a))
 
 #endif /* __IO_H */

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

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