54cbd57c06e8d2a6e7cf317eb41230a10606a9dd
[platform/kernel/u-boot.git] / include / asm-nios2 / io.h
1 /*
2  * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3  * Scott McNutt <smcnutt@psyent.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #ifndef __ASM_NIOS2_IO_H_
25 #define __ASM_NIOS2_IO_H_
26
27 static inline void sync(void)
28 {
29         __asm__ __volatile__ ("sync" : : : "memory");
30 }
31
32 extern unsigned char inb (unsigned char *port);
33 extern unsigned short inw (unsigned short *port);
34 extern unsigned inl (unsigned port);
35
36 #define __raw_writeb(v,a)       (*(volatile unsigned char  *)(a) = (v))
37 #define __raw_writew(v,a)       (*(volatile unsigned short *)(a) = (v))
38 #define __raw_writel(v,a)       (*(volatile unsigned int   *)(a) = (v))
39
40 #define __raw_readb(a)          (*(volatile unsigned char  *)(a))
41 #define __raw_readw(a)          (*(volatile unsigned short *)(a))
42 #define __raw_readl(a)          (*(volatile unsigned int   *)(a))
43
44 #define readb(addr)\
45         ({unsigned char val;\
46          asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
47 #define readw(addr)\
48         ({unsigned short val;\
49          asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
50 #define readl(addr)\
51         ({unsigned long val;\
52          asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
53
54 #define writeb(addr,val)\
55         asm volatile ("stbio %1, 0(%0)" : : "r" (addr), "r" (val))
56 #define writew(addr,val)\
57         asm volatile ("sthio %1, 0(%0)" : : "r" (addr), "r" (val))
58 #define writel(addr,val)\
59         asm volatile ("stwio %1, 0(%0)" : : "r" (addr), "r" (val))
60
61 #define inb(addr)       readb(addr)
62 #define inw(addr)       readw(addr)
63 #define inl(addr)       readl(addr)
64 #define outb(addr,val)  writeb(addr,val)
65 #define outw(addr,val)  writew(addr,val)
66 #define outl(addr,val)  writel(addr,val)
67
68 static inline void insb (unsigned long port, void *dst, unsigned long count)
69 {
70         unsigned char *p = dst;
71         while (count--) *p++ = inb (port);
72 }
73 static inline void insw (unsigned long port, void *dst, unsigned long count)
74 {
75         unsigned short *p = dst;
76         while (count--) *p++ = inw (port);
77 }
78 static inline void insl (unsigned long port, void *dst, unsigned long count)
79 {
80         unsigned long *p = dst;
81         while (count--) *p++ = inl (port);
82 }
83
84 static inline void outsb (unsigned long port, const void *src, unsigned long count)
85 {
86         const unsigned char *p = src;
87         while (count--) outb (*p++, port);
88 }
89
90 static inline void outsw (unsigned long port, const void *src, unsigned long count)
91 {
92         const unsigned short *p = src;
93         while (count--) outw (*p++, port);
94 }
95 static inline void outsl (unsigned long port, const void *src, unsigned long count)
96 {
97         const unsigned long *p = src;
98         while (count--) outl (*p++, port);
99 }
100
101 #endif /* __ASM_NIOS2_IO_H_ */