diff mbox

asm-generic/io.h: reorder funtions to form logical groups

Message ID 20140719125937.GA18566@ravnborg.org (mailing list archive)
State New, archived
Headers show

Commit Message

Sam Ravnborg July 19, 2014, 12:59 p.m. UTC
From 929c64c1aaf378b767e0ed89826b6bb12449df15 Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <sam@ravnborg.org>
Date: Sat, 19 Jul 2014 14:47:43 +0200
Subject: [PATCH] asm-generic/io.h: reorder funtions to form logical groups

Reoder the functions so the various functions are grouped
according to how they access memoy.
For example __raw_{read,write}* are now all grouped.

The benefit of this grouping is that one can easier find all
IO accessors of one type.
To do so a few more #ifdef CONFIG_64BIT had to be used.

Add a small boiler plate comment for some of the groups to
better let them stand out.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---

Hi Thierry.

This is my attempt to bring some order into io.h
with respect to the order the functions are defined in.

In a follow-up mail I also said we should delete the _p variants
of some methods but I then learned they are for slow IO access.
So these I have left as is.

And introducing static inline for all functions that are pure macro
substitution is also left out for now.

Please consider if you will take this as a follow-on patch.

	Sam

 include/asm-generic/io.h | 126 +++++++++++++++++++++++++++--------------------
 1 file changed, 73 insertions(+), 53 deletions(-)

Comments

Thierry Reding Aug. 1, 2014, 2:09 p.m. UTC | #1
On Sat, Jul 19, 2014 at 02:59:37PM +0200, Sam Ravnborg wrote:
> From 929c64c1aaf378b767e0ed89826b6bb12449df15 Mon Sep 17 00:00:00 2001
> From: Sam Ravnborg <sam@ravnborg.org>
> Date: Sat, 19 Jul 2014 14:47:43 +0200
> Subject: [PATCH] asm-generic/io.h: reorder funtions to form logical groups
> 
> Reoder the functions so the various functions are grouped
> according to how they access memoy.
> For example __raw_{read,write}* are now all grouped.
> 
> The benefit of this grouping is that one can easier find all
> IO accessors of one type.
> To do so a few more #ifdef CONFIG_64BIT had to be used.
> 
> Add a small boiler plate comment for some of the groups to
> better let them stand out.
> 
> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
> ---
> 
> Hi Thierry.
> 
> This is my attempt to bring some order into io.h
> with respect to the order the functions are defined in.
> 
> In a follow-up mail I also said we should delete the _p variants
> of some methods but I then learned they are for slow IO access.
> So these I have left as is.
> 
> And introducing static inline for all functions that are pure macro
> substitution is also left out for now.
> 
> Please consider if you will take this as a follow-on patch.

Just a short update on this: I've pulled your patch into my series and
then thought I'd make a last pass over these and send out a new version
but then I started noticing a few more things that I thought I could
quickly clean up as well. One thing led to another and I'm now up to
double the number of patches. I still think it's worth doing, but
unfortunately it's become somewhat more complicated since it now touches
a couple more architectures and even some drivers (/dev/mem (!) and
sunzilog).

I'm almost through sorting out the remaining issues I think, but it'll
take me another couple of days to rebase and squash patches and run some
build tests to verify that things don't break somewhere in the middle.

Oh, by the way: would you prefer that I keep your patch separate or
shall I just squash it into the one that has the major asm-generic/io.h
cleanup?

Thierry
Sam Ravnborg Aug. 1, 2014, 10:42 p.m. UTC | #2
> 
> Oh, by the way: would you prefer that I keep your patch separate or
> shall I just squash it into the one that has the major asm-generic/io.h
> cleanup?
Do whatever is the most convinient for you.
And do not bother with any attribution and such for such a simple patch.

	Sam
diff mbox

Patch

diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index b2ea16b..5c84db4 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -24,10 +24,10 @@ 
 #define mmiowb() do {} while (0)
 #endif
 
-/*****************************************************************************/
 /*
- * readX/writeX() are used to access memory mapped devices. On some
- * architectures the memory mapped IO stuff needs to be accessed
+ * raw_{read,write}{b,w,l,q} access memory in native endian.
+ *
+ * On some architectures the memory mapped IO stuff needs to be accessed
  * differently. On the simple architectures, we just read/write the
  * memory location directly.
  */
@@ -55,25 +55,16 @@  static inline u32 __raw_readl(const volatile void __iomem *addr)
 }
 #endif
 
-#ifndef readb
-#define readb __raw_readb
-#endif
-
-#ifndef readw
-#define readw readw
-static inline u16 readw(const volatile void __iomem *addr)
+#ifdef CONFIG_64BIT
+#ifndef __raw_readq
+#define __raw_readq __raw_readq
+static inline u64 __raw_readq(const volatile void __iomem *addr)
 {
-	return __le16_to_cpu(__raw_readw(addr));
+	return *(const volatile u64 __force *) addr;
 }
 #endif
+#endif /* CONFIG_64BIT */
 
-#ifndef readl
-#define readl readl
-static inline u32 readl(const volatile void __iomem *addr)
-{
-	return __le32_to_cpu(__raw_readl(addr));
-}
-#endif
 
 #ifndef __raw_writeb
 #define __raw_writeb __raw_writeb
@@ -99,27 +90,42 @@  static inline void __raw_writel(u32 b, volatile void __iomem *addr)
 }
 #endif
 
-#ifndef writeb
-#define writeb __raw_writeb
+#ifdef CONFIG_64BIT
+#ifndef __raw_writeq
+#define __raw_writeq __raw_writeq
+static inline void __raw_writeq(u64 b, volatile void __iomem *addr)
+{
+	*(volatile u64 __force *) addr = b;
+}
 #endif
+#endif /* CONFIG_64BIT */
 
-#ifndef writew
-#define writew(b,addr) __raw_writew(__cpu_to_le16(b),addr)
+
+/*
+ * {read,write}{b,w,l,q} access little endian memory
+ * and return result in native endian
+ */
+#ifndef readb
+#define readb __raw_readb
 #endif
 
-#ifndef writel
-#define writel(b,addr) __raw_writel(__cpu_to_le32(b),addr)
+#ifndef readw
+#define readw readw
+static inline u16 readw(const volatile void __iomem *addr)
+{
+	return __le16_to_cpu(__raw_readw(addr));
+}
 #endif
 
-#ifdef CONFIG_64BIT
-#ifndef __raw_readq
-#define __raw_readq __raw_readq
-static inline u64 __raw_readq(const volatile void __iomem *addr)
+#ifndef readl
+#define readl readl
+static inline u32 readl(const volatile void __iomem *addr)
 {
-	return *(const volatile u64 __force *) addr;
+	return __le32_to_cpu(__raw_readl(addr));
 }
 #endif
 
+#ifdef CONFIG_64BIT
 #ifndef readq
 #define readq readq
 static inline u64 readq(const volatile void __iomem *addr)
@@ -127,20 +133,31 @@  static inline u64 readq(const volatile void __iomem *addr)
 	return __le64_to_cpu(__raw_readq(addr));
 }
 #endif
+#endif /* CONFIG_64BIT */
 
-#ifndef __raw_writeq
-#define __raw_writeq __raw_writeq
-static inline void __raw_writeq(u64 b, volatile void __iomem *addr)
-{
-	*(volatile u64 __force *) addr = b;
-}
+
+#ifndef writeb
+#define writeb __raw_writeb
+#endif
+
+#ifndef writew
+#define writew(b,addr) __raw_writew(__cpu_to_le16(b),addr)
+#endif
+
+#ifndef writel
+#define writel(b,addr) __raw_writel(__cpu_to_le32(b),addr)
 #endif
 
+#ifdef CONFIG_64BIT
 #ifndef writeq
 #define writeq(b, addr) __raw_writeq(__cpu_to_le64(b), addr)
 #endif
 #endif /* CONFIG_64BIT */
 
+
+/*
+ * {read,write}s{b,w,l.q}b access native memory in chunks specified by count
+ */
 #ifndef readsb
 #define readsb readsb
 static inline void readsb(const void __iomem *addr, void *buffer, int count)
@@ -183,6 +200,23 @@  static inline void readsl(const void __iomem *addr, void *buffer, int count)
 }
 #endif
 
+#ifdef CONFIG_64BIT
+#ifndef readsq
+#define readsq readsq
+static inline void readsq(const void __iomem *addr, void *buffer, int count)
+{
+	if (count) {
+		u64 *buf = buffer;
+		do {
+			u64 x = __raw_readq(addr);
+			*buf++ = x;
+		} while (--count);
+	}
+}
+#endif
+#endif /* CONFIG_64BIT */
+
+
 #ifndef writesb
 #define writesb writesb
 static inline void writesb(void __iomem *addr, const void *buffer, int count)
@@ -223,20 +257,6 @@  static inline void writesl(void __iomem *addr, const void *buffer, int count)
 #endif
 
 #ifdef CONFIG_64BIT
-#ifndef readsq
-#define readsq readsq
-static inline void readsq(const void __iomem *addr, void *buffer, int count)
-{
-	if (count) {
-		u64 *buf = buffer;
-		do {
-			u64 x = __raw_readq(addr);
-			*buf++ = x;
-		} while (--count);
-	}
-}
-#endif
-
 #ifndef writesq
 #define writesq writesq
 static inline void writesq(void __iomem *addr, const void *buffer, int count)
@@ -356,6 +376,10 @@  static inline void outl(u32 b, unsigned long addr)
 #define ioread16(addr)		readw(addr)
 #define ioread32(addr)		readl(addr)
 
+#define iowrite8(v, addr)	writeb((v), (addr))
+#define iowrite16(v, addr)	writew((v), (addr))
+#define iowrite32(v, addr)	writel((v), (addr))
+
 #ifndef ioread16be
 #define ioread16be(addr)	__be16_to_cpu(__raw_readw(addr))
 #endif
@@ -364,10 +388,6 @@  static inline void outl(u32 b, unsigned long addr)
 #define ioread32be(addr)	__be32_to_cpu(__raw_readl(addr))
 #endif
 
-#define iowrite8(v, addr)	writeb((v), (addr))
-#define iowrite16(v, addr)	writew((v), (addr))
-#define iowrite32(v, addr)	writel((v), (addr))
-
 #ifndef iowrite16be
 #define iowrite16be(v, addr)	__raw_writew(__cpu_to_be16(v), addr)
 #endif