2 * linux/include/asm-arm/arch-rpc/io.h
4 * Copyright (C) 1997 Russell King
7 * 06-Dec-1997 RMK Created.
9 #ifndef __ASM_ARM_ARCH_IO_H
10 #define __ASM_ARM_ARCH_IO_H
13 * This architecture does not require any delayed IO, and
14 * has the constant-optimised IO
19 * We use two different types of addressing - PC style addresses, and ARM
20 * addresses. PC style accesses the PC hardware with the normal PC IO
21 * addresses, eg 0x3f8 for serial#1. ARM addresses are 0x80000000+
22 * and are translated to the start of IO. Note that all addresses are
25 #define __PORT_PCIO(x) (!((x) & 0x80000000))
28 * Dynamic IO functions - let the compiler
29 * optimize the expressions
31 #define DECLARE_DYN_OUT(fnsuffix,instr) \
32 extern __inline__ void __out##fnsuffix (unsigned int value, unsigned int port) \
35 __asm__ __volatile__( \
36 "tst %2, #0x80000000\n\t" \
38 "addeq %0, %0, %3\n\t" \
39 "str" ##instr## " %1, [%0, %2, lsl #2] @ out"###fnsuffix \
41 : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
45 #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
46 extern __inline__ unsigned sz __in##fnsuffix (unsigned int port) \
48 unsigned long temp, value; \
49 __asm__ __volatile__( \
50 "tst %2, #0x80000000\n\t" \
52 "addeq %0, %0, %3\n\t" \
53 "ldr" ##instr## " %1, [%0, %2, lsl #2] @ in"###fnsuffix \
54 : "=&r" (temp), "=r" (value) \
55 : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
57 return (unsigned sz)value; \
60 extern __inline__
unsigned int __ioaddr (unsigned int port
) \
62 if (__PORT_PCIO(port
)) \
63 return (unsigned int)(PCIO_BASE
+ (port
<< 2)); \
65 return (unsigned int)(IO_BASE
+ (port
<< 2)); \
68 #define DECLARE_IO(sz,fnsuffix,instr) \
69 DECLARE_DYN_OUT(fnsuffix,instr) \
70 DECLARE_DYN_IN(sz,fnsuffix,instr)
72 DECLARE_IO(char,b
,"b")
73 DECLARE_IO(short,w
,"")
77 #undef DECLARE_DYN_OUT
81 * Constant address IO functions
83 * These have to be macros for the 'J' constraint to work -
84 * +/-4096 immediate operand.
86 #define __outbc(value,port) \
88 if (__PORT_PCIO((port))) \
89 __asm__ __volatile__( \
90 "strb %0, [%1, %2] @ outbc" \
91 : : "r" (value), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
93 __asm__ __volatile__( \
94 "strb %0, [%1, %2] @ outbc" \
95 : : "r" (value), "r" (IO_BASE), "r" ((port) << 2)); \
98 #define __inbc(port) \
100 unsigned char result; \
101 if (__PORT_PCIO((port))) \
102 __asm__ __volatile__( \
103 "ldrb %0, [%1, %2] @ inbc" \
104 : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
106 __asm__ __volatile__( \
107 "ldrb %0, [%1, %2] @ inbc" \
108 : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
112 #define __outwc(value,port) \
114 unsigned long v = value; \
115 if (__PORT_PCIO((port))) \
116 __asm__ __volatile__( \
117 "str %0, [%1, %2] @ outwc" \
118 : : "r" (v|v<<16), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
120 __asm__ __volatile__( \
121 "str %0, [%1, %2] @ outwc" \
122 : : "r" (v|v<<16), "r" (IO_BASE), "r" ((port) << 2)); \
125 #define __inwc(port) \
127 unsigned short result; \
128 if (__PORT_PCIO((port))) \
129 __asm__ __volatile__( \
130 "ldr %0, [%1, %2] @ inwc" \
131 : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
133 __asm__ __volatile__( \
134 "ldr %0, [%1, %2] @ inwc" \
135 : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
139 #define __outlc(value,port) \
141 unsigned long v = value; \
142 if (__PORT_PCIO((port))) \
143 __asm__ __volatile__( \
144 "str %0, [%1, %2] @ outlc" \
145 : : "r" (v), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
147 __asm__ __volatile__( \
148 "str %0, [%1, %2] @ outlc" \
149 : : "r" (v), "r" (IO_BASE), "r" ((port) << 2)); \
152 #define __inlc(port) \
154 unsigned long result; \
155 if (__PORT_PCIO((port))) \
156 __asm__ __volatile__( \
157 "ldr %0, [%1, %2] @ inlc" \
158 : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
160 __asm__ __volatile__( \
161 "ldr %0, [%1, %2] @ inlc" \
162 : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
166 #define __ioaddrc(port) \
167 (__PORT_PCIO((port)) ? PCIO_BASE + ((port) << 2) : IO_BASE + ((port) << 2))
170 * Translated address IO functions
172 * IO address has already been translated to a virtual address
174 #define outb_t(v,p) \
175 (*(volatile unsigned char *)(p) = (v))
178 (*(volatile unsigned char *)(p))
180 #define outl_t(v,p) \
181 (*(volatile unsigned long *)(p) = (v))
184 (*(volatile unsigned long *)(p))