diff mbox

[U-Boot,v2] nds32: asm/io.h: add __iormb __iowmb and inline io support

Message ID 1319540590-28395-1-git-send-email-macpaul@andestech.com
State Accepted
Commit a53ef5e4bac750d0e84cd2b79f9f7855382b561d
Delegated to: Macpaul Lin
Headers show

Commit Message

Macpaul Lin Oct. 25, 2011, 11:03 a.m. UTC
1. This patch add required __iormb and __iowmb to io.h.
   This also fix some misbehavior to periphal drivers.
   This io.h has been fixed with referencing arm/include/asm/io.h.
2. This patch replaced macro writeb and readb into inline function.

Signed-off-by: Macpaul Lin <macpaul@andestech.com>
---
Changes for v2:
  - translate writeb macro into inline function.

 arch/nds32/include/asm/io.h |   72 +++++++++++++++++++++++++++++++------------
 1 files changed, 52 insertions(+), 20 deletions(-)

Comments

Macpaul Lin Nov. 1, 2011, 4:37 a.m. UTC | #1
Hi Macpaul,

2011/10/25 Macpaul Lin <macpaul@andestech.com>:
> 1. This patch add required __iormb and __iowmb to io.h.
>   This also fix some misbehavior to periphal drivers.
>   This io.h has been fixed with referencing arm/include/asm/io.h.
> 2. This patch replaced macro writeb and readb into inline function.
>
> Signed-off-by: Macpaul Lin <macpaul@andestech.com>
> ---
> Changes for v2:
>  - translate writeb macro into inline function.
>
>  arch/nds32/include/asm/io.h |   72 +++++++++++++++++++++++++++++++------------
>  1 files changed, 52 insertions(+), 20 deletions(-)
>

Applied to u-boot-nds32/master, thanks.

Best regards,
Macpaul Lin
diff mbox

Patch

diff --git a/arch/nds32/include/asm/io.h b/arch/nds32/include/asm/io.h
index 2504c2b..2c105f7 100644
--- a/arch/nds32/include/asm/io.h
+++ b/arch/nds32/include/asm/io.h
@@ -98,13 +98,59 @@  extern void __raw_readsl(unsigned int addr, void *data, int longlen);
 #define __raw_readw(a)			__arch_getw(a)
 #define __raw_readl(a)			__arch_getl(a)
 
-#define writeb(v, a)			__arch_putb(v, a)
-#define writew(v, a)			__arch_putw(v, a)
-#define writel(v, a)			__arch_putl(v, a)
+/*
+ * TODO: The kernel offers some more advanced versions of barriers, it might
+ * have some advantages to use them instead of the simple one here.
+ */
+#define dmb()		__asm__ __volatile__ ("" : : : "memory")
+#define __iormb()	dmb()
+#define __iowmb()	dmb()
+
+static inline void writeb(unsigned char val, unsigned char *addr)
+{
+	__iowmb();
+	__arch_putb(val, addr);
+}
+
+static inline void writew(unsigned short val, unsigned short *addr)
+{
+	__iowmb();
+	__arch_putw(val, addr);
+
+}
+
+static inline void writel(unsigned int val, unsigned int *addr)
+{
+	__iowmb();
+	__arch_putl(val, addr);
+}
+
+static inline unsigned char readb(unsigned char *addr)
+{
+	u8	val;
 
-#define readb(a)			__arch_getb(a)
-#define readw(a)			__arch_getw(a)
-#define readl(a)			__arch_getl(a)
+	val = __arch_getb(addr);
+	__iormb();
+	return val;
+}
+
+static inline unsigned short readw(unsigned short *addr)
+{
+	u16	val;
+
+	val = __arch_getw(addr);
+	__iormb();
+	return val;
+}
+
+static inline unsigned int readl(unsigned int *addr)
+{
+	u32	val;
+
+	val = __arch_getl(addr);
+	__iormb();
+	return val;
+}
 
 /*
  * The compiler seems to be incapable of optimising constants
@@ -338,20 +384,6 @@  check_signature(unsigned long io_addr, const unsigned char *signature,
 out:
 	return retval;
 }
-
-#elif !defined(readb)
-
-#define readb(addr)			(__readwrite_bug("readb"), 0)
-#define readw(addr)			(__readwrite_bug("readw"), 0)
-#define readl(addr)			(__readwrite_bug("readl"), 0)
-#define writeb(v, addr)			__readwrite_bug("writeb")
-#define writew(v, addr)			__readwrite_bug("writew")
-#define writel(v, addr)			__readwrite_bug("writel")
-
-#define eth_io_copy_and_sum(a, b, c, d)	__readwrite_bug("eth_io_copy_and_sum")
-
-#define check_signature(io, sig, len)	(0)
-
 #endif	/* __mem_pci */
 
 /*