2 * linux/include/asm-arm/arch-rpc/io.h
4 * Copyright (C) 1997 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 * 06-Dec-1997 RMK Created.
13 #ifndef __ASM_ARM_ARCH_IO_H
14 #define __ASM_ARM_ARCH_IO_H
16 #define IO_SPACE_LIMIT 0xffffffff
19 * GCC is totally crap at loading/storing data. We try to persuade it
20 * to do the right thing by using these whereever possible instead of
23 #define __arch_base_getb(b,o) \
25 unsigned int __v, __r = (b); \
26 __asm__ __volatile__( \
29 : "r" (__r), "Ir" (o)); \
33 #define __arch_base_getl(b,o) \
35 unsigned int __v, __r = (b); \
36 __asm__ __volatile__( \
39 : "r" (__r), "Ir" (o)); \
43 #define __arch_base_putb(v,b,o) \
45 unsigned int __r = (b); \
46 __asm__ __volatile__( \
49 : "r" (v), "r" (__r), "Ir" (o));\
52 #define __arch_base_putl(v,b,o) \
54 unsigned int __r = (b); \
55 __asm__ __volatile__( \
58 : "r" (v), "r" (__r), "Ir" (o));\
62 * We use two different types of addressing - PC style addresses, and ARM
63 * addresses. PC style accesses the PC hardware with the normal PC IO
64 * addresses, eg 0x3f8 for serial#1. ARM addresses are 0x80000000+
65 * and are translated to the start of IO. Note that all addresses are
68 #define __PORT_PCIO(x) (!((x) & 0x80000000))
71 * Dynamic IO functions.
73 static inline void __outb (unsigned int value
, unsigned int port
)
77 "tst %2, #0x80000000\n\t"
79 "addeq %0, %0, %3\n\t"
80 "strb %1, [%0, %2, lsl #2] @ outb"
82 : "r" (value
), "r" (port
), "Ir" (PCIO_BASE
- IO_BASE
), "Ir" (IO_BASE
)
86 static inline void __outw (unsigned int value
, unsigned int port
)
90 "tst %2, #0x80000000\n\t"
92 "addeq %0, %0, %3\n\t"
93 "str %1, [%0, %2, lsl #2] @ outw"
95 : "r" (value
|value
<<16), "r" (port
), "Ir" (PCIO_BASE
- IO_BASE
), "Ir" (IO_BASE
)
99 static inline void __outl (unsigned int value
, unsigned int port
)
102 __asm__
__volatile__(
103 "tst %2, #0x80000000\n\t"
105 "addeq %0, %0, %3\n\t"
106 "str %1, [%0, %2, lsl #2] @ outl"
108 : "r" (value
), "r" (port
), "Ir" (PCIO_BASE
- IO_BASE
), "Ir" (IO_BASE
)
112 #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
113 static inline unsigned sz __in##fnsuffix (unsigned int port) \
115 unsigned long temp, value; \
116 __asm__ __volatile__( \
117 "tst %2, #0x80000000\n\t" \
119 "addeq %0, %0, %3\n\t" \
120 "ldr" instr " %1, [%0, %2, lsl #2] @ in" #fnsuffix \
121 : "=&r" (temp), "=r" (value) \
122 : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
124 return (unsigned sz)value; \
127 static inline void __iomem
*__ioaddr(unsigned int port
)
130 if (__PORT_PCIO(port
))
134 return ret
+ (port
<< 2);
137 #define DECLARE_IO(sz,fnsuffix,instr) \
138 DECLARE_DYN_IN(sz,fnsuffix,instr)
140 DECLARE_IO(char,b
,"b")
141 DECLARE_IO(short,w
,"")
145 #undef DECLARE_DYN_IN
148 * Constant address IO functions
150 * These have to be macros for the 'J' constraint to work -
151 * +/-4096 immediate operand.
153 #define __outbc(value,port) \
155 if (__PORT_PCIO((port))) \
156 __asm__ __volatile__( \
157 "strb %0, [%1, %2] @ outbc" \
158 : : "r" (value), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
160 __asm__ __volatile__( \
161 "strb %0, [%1, %2] @ outbc" \
162 : : "r" (value), "r" (IO_BASE), "r" ((port) << 2)); \
165 #define __inbc(port) \
167 unsigned char result; \
168 if (__PORT_PCIO((port))) \
169 __asm__ __volatile__( \
170 "ldrb %0, [%1, %2] @ inbc" \
171 : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
173 __asm__ __volatile__( \
174 "ldrb %0, [%1, %2] @ inbc" \
175 : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
179 #define __outwc(value,port) \
181 unsigned long __v = value; \
182 if (__PORT_PCIO((port))) \
183 __asm__ __volatile__( \
184 "str %0, [%1, %2] @ outwc" \
185 : : "r" (__v|__v<<16), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
187 __asm__ __volatile__( \
188 "str %0, [%1, %2] @ outwc" \
189 : : "r" (__v|__v<<16), "r" (IO_BASE), "r" ((port) << 2)); \
192 #define __inwc(port) \
194 unsigned short result; \
195 if (__PORT_PCIO((port))) \
196 __asm__ __volatile__( \
197 "ldr %0, [%1, %2] @ inwc" \
198 : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
200 __asm__ __volatile__( \
201 "ldr %0, [%1, %2] @ inwc" \
202 : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
206 #define __outlc(value,port) \
208 unsigned long __v = value; \
209 if (__PORT_PCIO((port))) \
210 __asm__ __volatile__( \
211 "str %0, [%1, %2] @ outlc" \
212 : : "r" (__v), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
214 __asm__ __volatile__( \
215 "str %0, [%1, %2] @ outlc" \
216 : : "r" (__v), "r" (IO_BASE), "r" ((port) << 2)); \
219 #define __inlc(port) \
221 unsigned long result; \
222 if (__PORT_PCIO((port))) \
223 __asm__ __volatile__( \
224 "ldr %0, [%1, %2] @ inlc" \
225 : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
227 __asm__ __volatile__( \
228 "ldr %0, [%1, %2] @ inlc" \
229 : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
233 #define __ioaddrc(port) \
234 ((__PORT_PCIO(port) ? PCIO_BASE : IO_BASE) + ((port) << 2))
236 #define inb(p) (__builtin_constant_p((p)) ? __inbc(p) : __inb(p))
237 #define inw(p) (__builtin_constant_p((p)) ? __inwc(p) : __inw(p))
238 #define inl(p) (__builtin_constant_p((p)) ? __inlc(p) : __inl(p))
239 #define outb(v,p) (__builtin_constant_p((p)) ? __outbc(v,p) : __outb(v,p))
240 #define outw(v,p) (__builtin_constant_p((p)) ? __outwc(v,p) : __outw(v,p))
241 #define outl(v,p) (__builtin_constant_p((p)) ? __outlc(v,p) : __outl(v,p))
242 #define __ioaddr(p) (__builtin_constant_p((p)) ? __ioaddr(p) : __ioaddrc(p))
243 /* the following macro is deprecated */
244 #define ioaddr(port) ((unsigned long)__ioaddr((port)))
246 #define insb(p,d,l) __raw_readsb(__ioaddr(p),d,l)
247 #define insw(p,d,l) __raw_readsw(__ioaddr(p),d,l)
249 #define outsb(p,d,l) __raw_writesb(__ioaddr(p),d,l)
250 #define outsw(p,d,l) __raw_writesw(__ioaddr(p),d,l)
253 * 1:1 mapping for ioremapped regions.
255 #define __mem_pci(x) (x)