[IA64] Add __read_mostly support for IA64
[linux-2.6/zen-sources.git] / arch / arm / mach-ebsa110 / io.c
blobc648bfb676a100fbcf67d4791884305af3f6d716
1 /*
2 * linux/arch/arm/mach-ebsa110/isamem.c
4 * Copyright (C) 2001 Russell King
6 * Perform "ISA" memory and IO accesses. The EBSA110 has some "peculiarities"
7 * in the way it handles accesses to odd IO ports on 16-bit devices. These
8 * devices have their D0-D15 lines connected to the processors D0-D15 lines.
9 * Since they expect all byte IO operations to be performed on D0-D7, and the
10 * StrongARM expects to transfer the byte to these odd addresses on D8-D15,
11 * we must use a trick to get the required behaviour.
13 * The trick employed here is to use long word stores to odd address -1. The
14 * glue logic picks this up as a "trick" access, and asserts the LSB of the
15 * peripherals address bus, thereby accessing the odd IO port. Meanwhile, the
16 * StrongARM transfers its data on D0-D7 as expected.
18 * Things get more interesting on the pass-1 EBSA110 - the PCMCIA controller
19 * wiring was screwed in such a way that it had limited memory space access.
20 * Luckily, the work-around for this is not too horrible. See
21 * __isamem_convert_addr for the details.
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/types.h>
27 #include <asm/hardware.h>
28 #include <asm/io.h>
29 #include <asm/page.h>
31 static void __iomem *__isamem_convert_addr(void __iomem *addr)
33 u32 ret, a = (u32 __force) addr;
36 * The PCMCIA controller is wired up as follows:
37 * +---------+---------+---------+---------+---------+---------+
38 * PCMCIA | 2 2 2 2 | 1 1 1 1 | 1 1 1 1 | 1 1 | | |
39 * | 3 2 1 0 | 9 8 7 6 | 5 4 3 2 | 1 0 9 8 | 7 6 5 4 | 3 2 1 0 |
40 * +---------+---------+---------+---------+---------+---------+
41 * CPU | 2 2 2 2 | 2 1 1 1 | 1 1 1 1 | 1 1 1 | | |
42 * | 4 3 2 1 | 0 9 9 8 | 7 6 5 4 | 3 2 0 9 | 8 7 6 5 | 4 3 2 x |
43 * +---------+---------+---------+---------+---------+---------+
45 * This means that we can access PCMCIA regions as follows:
46 * 0x*10000 -> 0x*1ffff
47 * 0x*70000 -> 0x*7ffff
48 * 0x*90000 -> 0x*9ffff
49 * 0x*f0000 -> 0x*fffff
51 ret = (a & 0xf803fe) << 1;
52 ret |= (a & 0x03fc00) << 2;
54 ret += 0xe8000000;
56 if ((a & 0x20000) == (a & 0x40000) >> 1)
57 return (void __iomem *)ret;
59 BUG();
60 return NULL;
64 * read[bwl] and write[bwl]
66 u8 __readb(void __iomem *addr)
68 void __iomem *a = __isamem_convert_addr(addr);
69 u32 ret;
71 if ((unsigned long)addr & 1)
72 ret = __raw_readl(a);
73 else
74 ret = __raw_readb(a);
75 return ret;
78 u16 __readw(void __iomem *addr)
80 void __iomem *a = __isamem_convert_addr(addr);
82 if ((unsigned long)addr & 1)
83 BUG();
85 return __raw_readw(a);
88 u32 __readl(void __iomem *addr)
90 void __iomem *a = __isamem_convert_addr(addr);
91 u32 ret;
93 if ((unsigned long)addr & 3)
94 BUG();
96 ret = __raw_readw(a);
97 ret |= __raw_readw(a + 4) << 16;
98 return ret;
101 EXPORT_SYMBOL(__readb);
102 EXPORT_SYMBOL(__readw);
103 EXPORT_SYMBOL(__readl);
105 void __writeb(u8 val, void __iomem *addr)
107 void __iomem *a = __isamem_convert_addr(addr);
109 if ((unsigned long)addr & 1)
110 __raw_writel(val, a);
111 else
112 __raw_writeb(val, a);
115 void __writew(u16 val, void __iomem *addr)
117 void __iomem *a = __isamem_convert_addr(addr);
119 if ((unsigned long)addr & 1)
120 BUG();
122 __raw_writew(val, a);
125 void __writel(u32 val, void __iomem *addr)
127 void __iomem *a = __isamem_convert_addr(addr);
129 if ((unsigned long)addr & 3)
130 BUG();
132 __raw_writew(val, a);
133 __raw_writew(val >> 16, a + 4);
136 EXPORT_SYMBOL(__writeb);
137 EXPORT_SYMBOL(__writew);
138 EXPORT_SYMBOL(__writel);
140 #define SUPERIO_PORT(p) \
141 (((p) >> 3) == (0x3f8 >> 3) || \
142 ((p) >> 3) == (0x2f8 >> 3) || \
143 ((p) >> 3) == (0x378 >> 3))
146 * We're addressing an 8 or 16-bit peripheral which tranfers
147 * odd addresses on the low ISA byte lane.
149 u8 __inb8(unsigned int port)
151 u32 ret;
154 * The SuperIO registers use sane addressing techniques...
156 if (SUPERIO_PORT(port))
157 ret = __raw_readb((void __iomem *)ISAIO_BASE + (port << 2));
158 else {
159 void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
162 * Shame nothing else does
164 if (port & 1)
165 ret = __raw_readl(a);
166 else
167 ret = __raw_readb(a);
169 return ret;
173 * We're addressing a 16-bit peripheral which transfers odd
174 * addresses on the high ISA byte lane.
176 u8 __inb16(unsigned int port)
178 unsigned int offset;
181 * The SuperIO registers use sane addressing techniques...
183 if (SUPERIO_PORT(port))
184 offset = port << 2;
185 else
186 offset = (port & ~1) << 1 | (port & 1);
188 return __raw_readb((void __iomem *)ISAIO_BASE + offset);
191 u16 __inw(unsigned int port)
193 unsigned int offset;
196 * The SuperIO registers use sane addressing techniques...
198 if (SUPERIO_PORT(port))
199 offset = port << 2;
200 else {
201 offset = port << 1;
202 BUG_ON(port & 1);
204 return __raw_readw((void __iomem *)ISAIO_BASE + offset);
208 * Fake a 32-bit read with two 16-bit reads. Needed for 3c589.
210 u32 __inl(unsigned int port)
212 void __iomem *a;
214 if (SUPERIO_PORT(port) || port & 3)
215 BUG();
217 a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
219 return __raw_readw(a) | __raw_readw(a + 4) << 16;
222 EXPORT_SYMBOL(__inb8);
223 EXPORT_SYMBOL(__inb16);
224 EXPORT_SYMBOL(__inw);
225 EXPORT_SYMBOL(__inl);
227 void __outb8(u8 val, unsigned int port)
230 * The SuperIO registers use sane addressing techniques...
232 if (SUPERIO_PORT(port))
233 __raw_writeb(val, (void __iomem *)ISAIO_BASE + (port << 2));
234 else {
235 void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
238 * Shame nothing else does
240 if (port & 1)
241 __raw_writel(val, a);
242 else
243 __raw_writeb(val, a);
247 void __outb16(u8 val, unsigned int port)
249 unsigned int offset;
252 * The SuperIO registers use sane addressing techniques...
254 if (SUPERIO_PORT(port))
255 offset = port << 2;
256 else
257 offset = (port & ~1) << 1 | (port & 1);
259 __raw_writeb(val, (void __iomem *)ISAIO_BASE + offset);
262 void __outw(u16 val, unsigned int port)
264 unsigned int offset;
267 * The SuperIO registers use sane addressing techniques...
269 if (SUPERIO_PORT(port))
270 offset = port << 2;
271 else {
272 offset = port << 1;
273 BUG_ON(port & 1);
275 __raw_writew(val, (void __iomem *)ISAIO_BASE + offset);
278 void __outl(u32 val, unsigned int port)
280 BUG();
283 EXPORT_SYMBOL(__outb8);
284 EXPORT_SYMBOL(__outb16);
285 EXPORT_SYMBOL(__outw);
286 EXPORT_SYMBOL(__outl);
288 void outsb(unsigned int port, const void *from, int len)
290 u32 off;
292 if (SUPERIO_PORT(port))
293 off = port << 2;
294 else {
295 off = (port & ~1) << 1;
296 if (port & 1)
297 BUG();
300 __raw_writesb((void __iomem *)ISAIO_BASE + off, from, len);
303 void insb(unsigned int port, void *from, int len)
305 u32 off;
307 if (SUPERIO_PORT(port))
308 off = port << 2;
309 else {
310 off = (port & ~1) << 1;
311 if (port & 1)
312 BUG();
315 __raw_readsb((void __iomem *)ISAIO_BASE + off, from, len);
318 EXPORT_SYMBOL(outsb);
319 EXPORT_SYMBOL(insb);
321 void outsw(unsigned int port, const void *from, int len)
323 u32 off;
325 if (SUPERIO_PORT(port))
326 off = port << 2;
327 else {
328 off = (port & ~1) << 1;
329 if (port & 1)
330 BUG();
333 __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len);
336 void insw(unsigned int port, void *from, int len)
338 u32 off;
340 if (SUPERIO_PORT(port))
341 off = port << 2;
342 else {
343 off = (port & ~1) << 1;
344 if (port & 1)
345 BUG();
348 __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len);
351 EXPORT_SYMBOL(outsw);
352 EXPORT_SYMBOL(insw);
355 * We implement these as 16-bit insw/outsw, mainly for
356 * 3c589 cards.
358 void outsl(unsigned int port, const void *from, int len)
360 u32 off = port << 1;
362 if (SUPERIO_PORT(port) || port & 3)
363 BUG();
365 __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len << 1);
368 void insl(unsigned int port, void *from, int len)
370 u32 off = port << 1;
372 if (SUPERIO_PORT(port) || port & 3)
373 BUG();
375 __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len << 1);
378 EXPORT_SYMBOL(outsl);
379 EXPORT_SYMBOL(insl);