GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / alpha / kernel / io.c
blob17f7c089ce98c66058da8347fa93d1632e86aa16
1 /*
2 * Alpha IO and memory functions.
3 */
5 #include <linux/kernel.h>
6 #include <linux/types.h>
7 #include <linux/string.h>
8 #include <linux/module.h>
9 #include <asm/io.h>
11 /* Out-of-line versions of the i/o routines that redirect into the
12 platform-specific version. Note that "platform-specific" may mean
13 "generic", which bumps through the machine vector. */
15 unsigned int
16 ioread8(void __iomem *addr)
18 unsigned int ret = IO_CONCAT(__IO_PREFIX,ioread8)(addr);
19 mb();
20 return ret;
23 unsigned int ioread16(void __iomem *addr)
25 unsigned int ret = IO_CONCAT(__IO_PREFIX,ioread16)(addr);
26 mb();
27 return ret;
30 unsigned int ioread32(void __iomem *addr)
32 unsigned int ret = IO_CONCAT(__IO_PREFIX,ioread32)(addr);
33 mb();
34 return ret;
37 void iowrite8(u8 b, void __iomem *addr)
39 IO_CONCAT(__IO_PREFIX,iowrite8)(b, addr);
40 mb();
43 void iowrite16(u16 b, void __iomem *addr)
45 IO_CONCAT(__IO_PREFIX,iowrite16)(b, addr);
46 mb();
49 void iowrite32(u32 b, void __iomem *addr)
51 IO_CONCAT(__IO_PREFIX,iowrite32)(b, addr);
52 mb();
55 EXPORT_SYMBOL(ioread8);
56 EXPORT_SYMBOL(ioread16);
57 EXPORT_SYMBOL(ioread32);
58 EXPORT_SYMBOL(iowrite8);
59 EXPORT_SYMBOL(iowrite16);
60 EXPORT_SYMBOL(iowrite32);
62 u8 inb(unsigned long port)
64 return ioread8(ioport_map(port, 1));
67 u16 inw(unsigned long port)
69 return ioread16(ioport_map(port, 2));
72 u32 inl(unsigned long port)
74 return ioread32(ioport_map(port, 4));
77 void outb(u8 b, unsigned long port)
79 iowrite8(b, ioport_map(port, 1));
82 void outw(u16 b, unsigned long port)
84 iowrite16(b, ioport_map(port, 2));
87 void outl(u32 b, unsigned long port)
89 iowrite32(b, ioport_map(port, 4));
92 EXPORT_SYMBOL(inb);
93 EXPORT_SYMBOL(inw);
94 EXPORT_SYMBOL(inl);
95 EXPORT_SYMBOL(outb);
96 EXPORT_SYMBOL(outw);
97 EXPORT_SYMBOL(outl);
99 u8 __raw_readb(const volatile void __iomem *addr)
101 return IO_CONCAT(__IO_PREFIX,readb)(addr);
104 u16 __raw_readw(const volatile void __iomem *addr)
106 return IO_CONCAT(__IO_PREFIX,readw)(addr);
109 u32 __raw_readl(const volatile void __iomem *addr)
111 return IO_CONCAT(__IO_PREFIX,readl)(addr);
114 u64 __raw_readq(const volatile void __iomem *addr)
116 return IO_CONCAT(__IO_PREFIX,readq)(addr);
119 void __raw_writeb(u8 b, volatile void __iomem *addr)
121 IO_CONCAT(__IO_PREFIX,writeb)(b, addr);
124 void __raw_writew(u16 b, volatile void __iomem *addr)
126 IO_CONCAT(__IO_PREFIX,writew)(b, addr);
129 void __raw_writel(u32 b, volatile void __iomem *addr)
131 IO_CONCAT(__IO_PREFIX,writel)(b, addr);
134 void __raw_writeq(u64 b, volatile void __iomem *addr)
136 IO_CONCAT(__IO_PREFIX,writeq)(b, addr);
139 EXPORT_SYMBOL(__raw_readb);
140 EXPORT_SYMBOL(__raw_readw);
141 EXPORT_SYMBOL(__raw_readl);
142 EXPORT_SYMBOL(__raw_readq);
143 EXPORT_SYMBOL(__raw_writeb);
144 EXPORT_SYMBOL(__raw_writew);
145 EXPORT_SYMBOL(__raw_writel);
146 EXPORT_SYMBOL(__raw_writeq);
148 u8 readb(const volatile void __iomem *addr)
150 u8 ret = __raw_readb(addr);
151 mb();
152 return ret;
155 u16 readw(const volatile void __iomem *addr)
157 u16 ret = __raw_readw(addr);
158 mb();
159 return ret;
162 u32 readl(const volatile void __iomem *addr)
164 u32 ret = __raw_readl(addr);
165 mb();
166 return ret;
169 u64 readq(const volatile void __iomem *addr)
171 u64 ret = __raw_readq(addr);
172 mb();
173 return ret;
176 void writeb(u8 b, volatile void __iomem *addr)
178 __raw_writeb(b, addr);
179 mb();
182 void writew(u16 b, volatile void __iomem *addr)
184 __raw_writew(b, addr);
185 mb();
188 void writel(u32 b, volatile void __iomem *addr)
190 __raw_writel(b, addr);
191 mb();
194 void writeq(u64 b, volatile void __iomem *addr)
196 __raw_writeq(b, addr);
197 mb();
200 EXPORT_SYMBOL(readb);
201 EXPORT_SYMBOL(readw);
202 EXPORT_SYMBOL(readl);
203 EXPORT_SYMBOL(readq);
204 EXPORT_SYMBOL(writeb);
205 EXPORT_SYMBOL(writew);
206 EXPORT_SYMBOL(writel);
207 EXPORT_SYMBOL(writeq);
211 * Read COUNT 8-bit bytes from port PORT into memory starting at SRC.
213 void ioread8_rep(void __iomem *port, void *dst, unsigned long count)
215 while ((unsigned long)dst & 0x3) {
216 if (!count)
217 return;
218 count--;
219 *(unsigned char *)dst = ioread8(port);
220 dst += 1;
223 while (count >= 4) {
224 unsigned int w;
225 count -= 4;
226 w = ioread8(port);
227 w |= ioread8(port) << 8;
228 w |= ioread8(port) << 16;
229 w |= ioread8(port) << 24;
230 *(unsigned int *)dst = w;
231 dst += 4;
234 while (count) {
235 --count;
236 *(unsigned char *)dst = ioread8(port);
237 dst += 1;
241 void insb(unsigned long port, void *dst, unsigned long count)
243 ioread8_rep(ioport_map(port, 1), dst, count);
246 EXPORT_SYMBOL(ioread8_rep);
247 EXPORT_SYMBOL(insb);
250 * Read COUNT 16-bit words from port PORT into memory starting at
251 * SRC. SRC must be at least short aligned. This is used by the
252 * IDE driver to read disk sectors. Performance is important, but
253 * the interfaces seems to be slow: just using the inlined version
254 * of the inw() breaks things.
256 void ioread16_rep(void __iomem *port, void *dst, unsigned long count)
258 if (unlikely((unsigned long)dst & 0x3)) {
259 if (!count)
260 return;
261 BUG_ON((unsigned long)dst & 0x1);
262 count--;
263 *(unsigned short *)dst = ioread16(port);
264 dst += 2;
267 while (count >= 2) {
268 unsigned int w;
269 count -= 2;
270 w = ioread16(port);
271 w |= ioread16(port) << 16;
272 *(unsigned int *)dst = w;
273 dst += 4;
276 if (count) {
277 *(unsigned short*)dst = ioread16(port);
281 void insw(unsigned long port, void *dst, unsigned long count)
283 ioread16_rep(ioport_map(port, 2), dst, count);
286 EXPORT_SYMBOL(ioread16_rep);
287 EXPORT_SYMBOL(insw);
291 * Read COUNT 32-bit words from port PORT into memory starting at
292 * SRC. Now works with any alignment in SRC. Performance is important,
293 * but the interfaces seems to be slow: just using the inlined version
294 * of the inl() breaks things.
296 void ioread32_rep(void __iomem *port, void *dst, unsigned long count)
298 if (unlikely((unsigned long)dst & 0x3)) {
299 while (count--) {
300 struct S { int x __attribute__((packed)); };
301 ((struct S *)dst)->x = ioread32(port);
302 dst += 4;
304 } else {
305 /* Buffer 32-bit aligned. */
306 while (count--) {
307 *(unsigned int *)dst = ioread32(port);
308 dst += 4;
313 void insl(unsigned long port, void *dst, unsigned long count)
315 ioread32_rep(ioport_map(port, 4), dst, count);
318 EXPORT_SYMBOL(ioread32_rep);
319 EXPORT_SYMBOL(insl);
323 * Like insb but in the opposite direction.
324 * Don't worry as much about doing aligned memory transfers:
325 * doing byte reads the "slow" way isn't nearly as slow as
326 * doing byte writes the slow way (no r-m-w cycle).
328 void iowrite8_rep(void __iomem *port, const void *xsrc, unsigned long count)
330 const unsigned char *src = xsrc;
331 while (count--)
332 iowrite8(*src++, port);
335 void outsb(unsigned long port, const void *src, unsigned long count)
337 iowrite8_rep(ioport_map(port, 1), src, count);
340 EXPORT_SYMBOL(iowrite8_rep);
341 EXPORT_SYMBOL(outsb);
345 * Like insw but in the opposite direction. This is used by the IDE
346 * driver to write disk sectors. Performance is important, but the
347 * interfaces seems to be slow: just using the inlined version of the
348 * outw() breaks things.
350 void iowrite16_rep(void __iomem *port, const void *src, unsigned long count)
352 if (unlikely((unsigned long)src & 0x3)) {
353 if (!count)
354 return;
355 BUG_ON((unsigned long)src & 0x1);
356 iowrite16(*(unsigned short *)src, port);
357 src += 2;
358 --count;
361 while (count >= 2) {
362 unsigned int w;
363 count -= 2;
364 w = *(unsigned int *)src;
365 src += 4;
366 iowrite16(w >> 0, port);
367 iowrite16(w >> 16, port);
370 if (count) {
371 iowrite16(*(unsigned short *)src, port);
375 void outsw(unsigned long port, const void *src, unsigned long count)
377 iowrite16_rep(ioport_map(port, 2), src, count);
380 EXPORT_SYMBOL(iowrite16_rep);
381 EXPORT_SYMBOL(outsw);
385 * Like insl but in the opposite direction. This is used by the IDE
386 * driver to write disk sectors. Works with any alignment in SRC.
387 * Performance is important, but the interfaces seems to be slow:
388 * just using the inlined version of the outl() breaks things.
390 void iowrite32_rep(void __iomem *port, const void *src, unsigned long count)
392 if (unlikely((unsigned long)src & 0x3)) {
393 while (count--) {
394 struct S { int x __attribute__((packed)); };
395 iowrite32(((struct S *)src)->x, port);
396 src += 4;
398 } else {
399 /* Buffer 32-bit aligned. */
400 while (count--) {
401 iowrite32(*(unsigned int *)src, port);
402 src += 4;
407 void outsl(unsigned long port, const void *src, unsigned long count)
409 iowrite32_rep(ioport_map(port, 4), src, count);
412 EXPORT_SYMBOL(iowrite32_rep);
413 EXPORT_SYMBOL(outsl);
417 * Copy data from IO memory space to "real" memory space.
418 * This needs to be optimized.
420 void memcpy_fromio(void *to, const volatile void __iomem *from, long count)
422 /* Optimize co-aligned transfers. Everything else gets handled
423 a byte at a time. */
425 if (count >= 8 && ((u64)to & 7) == ((u64)from & 7)) {
426 count -= 8;
427 do {
428 *(u64 *)to = __raw_readq(from);
429 count -= 8;
430 to += 8;
431 from += 8;
432 } while (count >= 0);
433 count += 8;
436 if (count >= 4 && ((u64)to & 3) == ((u64)from & 3)) {
437 count -= 4;
438 do {
439 *(u32 *)to = __raw_readl(from);
440 count -= 4;
441 to += 4;
442 from += 4;
443 } while (count >= 0);
444 count += 4;
447 if (count >= 2 && ((u64)to & 1) == ((u64)from & 1)) {
448 count -= 2;
449 do {
450 *(u16 *)to = __raw_readw(from);
451 count -= 2;
452 to += 2;
453 from += 2;
454 } while (count >= 0);
455 count += 2;
458 while (count > 0) {
459 *(u8 *) to = __raw_readb(from);
460 count--;
461 to++;
462 from++;
464 mb();
467 EXPORT_SYMBOL(memcpy_fromio);
471 * Copy data from "real" memory space to IO memory space.
472 * This needs to be optimized.
474 void memcpy_toio(volatile void __iomem *to, const void *from, long count)
476 /* Optimize co-aligned transfers. Everything else gets handled
477 a byte at a time. */
479 if (count >= 8 && ((u64)to & 7) == ((u64)from & 7)) {
480 count -= 8;
481 do {
482 __raw_writeq(*(const u64 *)from, to);
483 count -= 8;
484 to += 8;
485 from += 8;
486 } while (count >= 0);
487 count += 8;
490 if (count >= 4 && ((u64)to & 3) == ((u64)from & 3)) {
491 count -= 4;
492 do {
493 __raw_writel(*(const u32 *)from, to);
494 count -= 4;
495 to += 4;
496 from += 4;
497 } while (count >= 0);
498 count += 4;
501 if (count >= 2 && ((u64)to & 1) == ((u64)from & 1)) {
502 count -= 2;
503 do {
504 __raw_writew(*(const u16 *)from, to);
505 count -= 2;
506 to += 2;
507 from += 2;
508 } while (count >= 0);
509 count += 2;
512 while (count > 0) {
513 __raw_writeb(*(const u8 *) from, to);
514 count--;
515 to++;
516 from++;
518 mb();
521 EXPORT_SYMBOL(memcpy_toio);
525 * "memset" on IO memory space.
527 void _memset_c_io(volatile void __iomem *to, unsigned long c, long count)
529 /* Handle any initial odd byte */
530 if (count > 0 && ((u64)to & 1)) {
531 __raw_writeb(c, to);
532 to++;
533 count--;
536 /* Handle any initial odd halfword */
537 if (count >= 2 && ((u64)to & 2)) {
538 __raw_writew(c, to);
539 to += 2;
540 count -= 2;
543 /* Handle any initial odd word */
544 if (count >= 4 && ((u64)to & 4)) {
545 __raw_writel(c, to);
546 to += 4;
547 count -= 4;
550 /* Handle all full-sized quadwords: we're aligned
551 (or have a small count) */
552 count -= 8;
553 if (count >= 0) {
554 do {
555 __raw_writeq(c, to);
556 to += 8;
557 count -= 8;
558 } while (count >= 0);
560 count += 8;
562 /* The tail is word-aligned if we still have count >= 4 */
563 if (count >= 4) {
564 __raw_writel(c, to);
565 to += 4;
566 count -= 4;
569 /* The tail is half-word aligned if we have count >= 2 */
570 if (count >= 2) {
571 __raw_writew(c, to);
572 to += 2;
573 count -= 2;
576 /* And finally, one last byte.. */
577 if (count) {
578 __raw_writeb(c, to);
580 mb();
583 EXPORT_SYMBOL(_memset_c_io);
585 /* A version of memcpy used by the vga console routines to move data around
586 arbitrarily between screen and main memory. */
588 void
589 scr_memcpyw(u16 *d, const u16 *s, unsigned int count)
591 const u16 __iomem *ios = (const u16 __iomem *) s;
592 u16 __iomem *iod = (u16 __iomem *) d;
593 int s_isio = __is_ioaddr(s);
594 int d_isio = __is_ioaddr(d);
596 if (s_isio) {
597 if (d_isio) {
599 count /= 2;
600 while (count--) {
601 u16 tmp = __raw_readw(ios++);
602 __raw_writew(tmp, iod++);
605 else
606 memcpy_fromio(d, ios, count);
607 } else {
608 if (d_isio)
609 memcpy_toio(iod, s, count);
610 else
611 memcpy(d, s, count);
615 EXPORT_SYMBOL(scr_memcpyw);
617 void __iomem *ioport_map(unsigned long port, unsigned int size)
619 return IO_CONCAT(__IO_PREFIX,ioportmap) (port);
622 void ioport_unmap(void __iomem *addr)
626 EXPORT_SYMBOL(ioport_map);
627 EXPORT_SYMBOL(ioport_unmap);