[U-Boot] [PATCH 09/28] nios2: change asm-nios2/io.h to compatible with nios2 linux

Thomas Chou thomas at wytron.com.tw
Fri Mar 19 08:43:34 CET 2010


The port address should be mapped to uncached (bypass) io region
before calling these writel()/readl() functions. Similar to the
ioremap() of Linux.

The uncached address mapping is (phyaddr | IO_REGION).
here IO_REGION is
0x80000000 for NOMMU,
0xe0000000 for MMU.

The cache bypass asm macros, ldwio/stwio, are removed. Mixing
physical address and uncached virtual address in the config file
is confusing. We shall use uncached virtual address for all devices
except the main memory (sdram), which should be cached.

The args to writel() is changed to (val,port), which is consistent
with other archs.

Signed-off-by: Thomas Chou <thomas at wytron.com.tw>
---
 include/asm-nios2/io.h |   59 +++++++++++++++++++----------------------------
 1 files changed, 24 insertions(+), 35 deletions(-)

diff --git a/include/asm-nios2/io.h b/include/asm-nios2/io.h
index 01d11ef..11f59ea 100644
--- a/include/asm-nios2/io.h
+++ b/include/asm-nios2/io.h
@@ -58,41 +58,30 @@ static inline phys_addr_t virt_to_phys(void * vaddr)
 	return (phys_addr_t)(vaddr);
 }
 
-extern unsigned char inb (unsigned char *port);
-extern unsigned short inw (unsigned short *port);
-extern unsigned inl (unsigned port);
-
-#define __raw_writeb(v,a)       (*(volatile unsigned char  *)(a) = (v))
-#define __raw_writew(v,a)       (*(volatile unsigned short *)(a) = (v))
-#define __raw_writel(v,a)       (*(volatile unsigned int   *)(a) = (v))
-
-#define __raw_readb(a)          (*(volatile unsigned char  *)(a))
-#define __raw_readw(a)          (*(volatile unsigned short *)(a))
-#define __raw_readl(a)          (*(volatile unsigned int   *)(a))
-
-#define readb(addr)\
-	({unsigned char val;\
-	 asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
-#define readw(addr)\
-	({unsigned short val;\
-	 asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
-#define readl(addr)\
-	({unsigned long val;\
-	 asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
-
-#define writeb(addr,val)\
-	asm volatile ("stbio %1, 0(%0)" : : "r" (addr), "r" (val))
-#define writew(addr,val)\
-	asm volatile ("sthio %1, 0(%0)" : : "r" (addr), "r" (val))
-#define writel(addr,val)\
-	asm volatile ("stwio %1, 0(%0)" : : "r" (addr), "r" (val))
-
-#define inb(addr)	readb(addr)
-#define inw(addr)	readw(addr)
-#define inl(addr)	readl(addr)
-#define outb(addr,val)	writeb(addr,val)
-#define outw(addr,val)	writew(addr,val)
-#define outl(addr,val)	writel(addr,val)
+#define readb(addr) \
+    ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
+#define readw(addr) \
+    ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
+#define readl(addr) \
+    ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
+
+#define writeb(b, addr) (void)((*(volatile unsigned char *) (addr)) = (b))
+#define writew(b, addr) (void)((*(volatile unsigned short *) (addr)) = (b))
+#define writel(b, addr) (void)((*(volatile unsigned int *) (addr)) = (b))
+
+#define __raw_readb readb
+#define __raw_readw readw
+#define __raw_readl readl
+#define __raw_writeb writeb
+#define __raw_writew writew
+#define __raw_writel writel
+
+#define inb(addr)    readb(addr)
+#define inw(addr)    readw(addr)
+#define inl(addr)    readl(addr)
+#define outb(x, addr) ((void) writeb(x, addr))
+#define outw(x, addr) ((void) writew(x, addr))
+#define outl(x, addr) ((void) writel(x, addr))
 
 static inline void insb (unsigned long port, void *dst, unsigned long count)
 {
-- 
1.6.6.1



More information about the U-Boot mailing list