]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/asm-arm/arch-shark/io.h
Linux-2.6.12-rc2
[mirror_ubuntu-bionic-kernel.git] / include / asm-arm / arch-shark / io.h
1 /*
2 * linux/include/asm-arm/arch-shark/io.h
3 *
4 * by Alexander Schulz
5 *
6 * derived from:
7 * linux/include/asm-arm/arch-ebsa110/io.h
8 * Copyright (C) 1997,1998 Russell King
9 */
10
11 #ifndef __ASM_ARM_ARCH_IO_H
12 #define __ASM_ARM_ARCH_IO_H
13
14 #define IO_SPACE_LIMIT 0xffffffff
15
16 /*
17 * We use two different types of addressing - PC style addresses, and ARM
18 * addresses. PC style accesses the PC hardware with the normal PC IO
19 * addresses, eg 0x3f8 for serial#1. ARM addresses are 0x80000000+
20 * and are translated to the start of IO.
21 */
22 #define __PORT_PCIO(x) (!((x) & 0x80000000))
23
24 /*
25 * Dynamic IO functions - let the compiler
26 * optimize the expressions
27 */
28 #define DECLARE_DYN_OUT(fnsuffix,instr) \
29 static inline void __out##fnsuffix (unsigned int value, unsigned int port) \
30 { \
31 unsigned long temp; \
32 __asm__ __volatile__( \
33 "tst %2, #0x80000000\n\t" \
34 "mov %0, %4\n\t" \
35 "addeq %0, %0, %3\n\t" \
36 "str" instr " %1, [%0, %2] @ out" #fnsuffix \
37 : "=&r" (temp) \
38 : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
39 : "cc"); \
40 }
41
42 #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
43 static inline unsigned sz __in##fnsuffix (unsigned int port) \
44 { \
45 unsigned long temp, value; \
46 __asm__ __volatile__( \
47 "tst %2, #0x80000000\n\t" \
48 "mov %0, %4\n\t" \
49 "addeq %0, %0, %3\n\t" \
50 "ldr" instr " %1, [%0, %2] @ in" #fnsuffix \
51 : "=&r" (temp), "=r" (value) \
52 : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
53 : "cc"); \
54 return (unsigned sz)value; \
55 }
56
57 static inline unsigned int __ioaddr (unsigned int port) \
58 { \
59 if (__PORT_PCIO(port)) \
60 return (unsigned int)(PCIO_BASE + (port)); \
61 else \
62 return (unsigned int)(IO_BASE + (port)); \
63 }
64
65 #define DECLARE_IO(sz,fnsuffix,instr) \
66 DECLARE_DYN_OUT(fnsuffix,instr) \
67 DECLARE_DYN_IN(sz,fnsuffix,instr)
68
69 DECLARE_IO(char,b,"b")
70 DECLARE_IO(short,w,"h")
71 DECLARE_IO(long,l,"")
72
73 #undef DECLARE_IO
74 #undef DECLARE_DYN_OUT
75 #undef DECLARE_DYN_IN
76
77 /*
78 * Constant address IO functions
79 *
80 * These have to be macros for the 'J' constraint to work -
81 * +/-4096 immediate operand.
82 */
83 #define __outbc(value,port) \
84 ({ \
85 if (__PORT_PCIO((port))) \
86 __asm__ __volatile__( \
87 "strb %0, [%1, %2] @ outbc" \
88 : : "r" (value), "r" (PCIO_BASE), "Jr" (port)); \
89 else \
90 __asm__ __volatile__( \
91 "strb %0, [%1, %2] @ outbc" \
92 : : "r" (value), "r" (IO_BASE), "r" (port)); \
93 })
94
95 #define __inbc(port) \
96 ({ \
97 unsigned char result; \
98 if (__PORT_PCIO((port))) \
99 __asm__ __volatile__( \
100 "ldrb %0, [%1, %2] @ inbc" \
101 : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
102 else \
103 __asm__ __volatile__( \
104 "ldrb %0, [%1, %2] @ inbc" \
105 : "=r" (result) : "r" (IO_BASE), "r" (port)); \
106 result; \
107 })
108
109 #define __outwc(value,port) \
110 ({ \
111 unsigned long v = value; \
112 if (__PORT_PCIO((port))) \
113 __asm__ __volatile__( \
114 "strh %0, [%1, %2] @ outwc" \
115 : : "r" (v|v<<16), "r" (PCIO_BASE), "Jr" (port)); \
116 else \
117 __asm__ __volatile__( \
118 "strh %0, [%1, %2] @ outwc" \
119 : : "r" (v|v<<16), "r" (IO_BASE), "r" (port)); \
120 })
121
122 #define __inwc(port) \
123 ({ \
124 unsigned short result; \
125 if (__PORT_PCIO((port))) \
126 __asm__ __volatile__( \
127 "ldrh %0, [%1, %2] @ inwc" \
128 : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
129 else \
130 __asm__ __volatile__( \
131 "ldrh %0, [%1, %2] @ inwc" \
132 : "=r" (result) : "r" (IO_BASE), "r" (port)); \
133 result & 0xffff; \
134 })
135
136 #define __outlc(value,port) \
137 ({ \
138 unsigned long v = value; \
139 if (__PORT_PCIO((port))) \
140 __asm__ __volatile__( \
141 "str %0, [%1, %2] @ outlc" \
142 : : "r" (v), "r" (PCIO_BASE), "Jr" (port)); \
143 else \
144 __asm__ __volatile__( \
145 "str %0, [%1, %2] @ outlc" \
146 : : "r" (v), "r" (IO_BASE), "r" (port)); \
147 })
148
149 #define __inlc(port) \
150 ({ \
151 unsigned long result; \
152 if (__PORT_PCIO((port))) \
153 __asm__ __volatile__( \
154 "ldr %0, [%1, %2] @ inlc" \
155 : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
156 else \
157 __asm__ __volatile__( \
158 "ldr %0, [%1, %2] @ inlc" \
159 : "=r" (result) : "r" (IO_BASE), "r" (port)); \
160 result; \
161 })
162
163 #define __ioaddrc(port) \
164 ({ \
165 unsigned long addr; \
166 if (__PORT_PCIO((port))) \
167 addr = PCIO_BASE + (port); \
168 else \
169 addr = IO_BASE + (port); \
170 addr; \
171 })
172
173 #define __mem_pci(addr) (addr)
174
175 #define inb(p) (__builtin_constant_p((p)) ? __inbc(p) : __inb(p))
176 #define inw(p) (__builtin_constant_p((p)) ? __inwc(p) : __inw(p))
177 #define inl(p) (__builtin_constant_p((p)) ? __inlc(p) : __inl(p))
178 #define outb(v,p) (__builtin_constant_p((p)) ? __outbc(v,p) : __outb(v,p))
179 #define outw(v,p) (__builtin_constant_p((p)) ? __outwc(v,p) : __outw(v,p))
180 #define outl(v,p) (__builtin_constant_p((p)) ? __outlc(v,p) : __outl(v,p))
181
182 /*
183 * Translated address IO functions
184 *
185 * IO address has already been translated to a virtual address
186 */
187 #define outb_t(v,p) \
188 (*(volatile unsigned char *)(p) = (v))
189
190 #define inb_t(p) \
191 (*(volatile unsigned char *)(p))
192
193 #define outl_t(v,p) \
194 (*(volatile unsigned long *)(p) = (v))
195
196 #define inl_t(p) \
197 (*(volatile unsigned long *)(p))
198
199 #endif