sh: Move arch/sh64/lib to arch/sh/lib64.
[linux-2.6/libata-dev.git] / arch / sh / lib64 / io.c
bloba3f3a2b8e25ba3af6eb39b0a764c75cb0678d61d
1 /*
2 * Copyright (C) 2000 David J. Mckay (david.mckay@st.com)
4 * May be copied or modified under the terms of the GNU General Public
5 * License. See linux/COPYING for more information.
7 * This file contains the I/O routines for use on the overdrive board
9 */
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/delay.h>
14 #include <linux/module.h>
15 #include <asm/system.h>
16 #include <asm/processor.h>
17 #include <asm/io.h>
19 /* Now for the string version of these functions */
20 void outsb(unsigned long port, const void *addr, unsigned long count)
22 int i;
23 unsigned char *p = (unsigned char *) addr;
25 for (i = 0; i < count; i++, p++) {
26 outb(*p, port);
29 EXPORT_SYMBOL(outsb);
31 void insb(unsigned long port, void *addr, unsigned long count)
33 int i;
34 unsigned char *p = (unsigned char *) addr;
36 for (i = 0; i < count; i++, p++) {
37 *p = inb(port);
40 EXPORT_SYMBOL(insb);
42 /* For the 16 and 32 bit string functions, we have to worry about alignment.
43 * The SH does not do unaligned accesses, so we have to read as bytes and
44 * then write as a word or dword.
45 * This can be optimised a lot more, especially in the case where the data
46 * is aligned
49 void outsw(unsigned long port, const void *addr, unsigned long count)
51 int i;
52 unsigned short tmp;
53 unsigned char *p = (unsigned char *) addr;
55 for (i = 0; i < count; i++, p += 2) {
56 tmp = (*p) | ((*(p + 1)) << 8);
57 outw(tmp, port);
60 EXPORT_SYMBOL(outsw);
62 void insw(unsigned long port, void *addr, unsigned long count)
64 int i;
65 unsigned short tmp;
66 unsigned char *p = (unsigned char *) addr;
68 for (i = 0; i < count; i++, p += 2) {
69 tmp = inw(port);
70 p[0] = tmp & 0xff;
71 p[1] = (tmp >> 8) & 0xff;
74 EXPORT_SYMBOL(insw);
76 void outsl(unsigned long port, const void *addr, unsigned long count)
78 int i;
79 unsigned tmp;
80 unsigned char *p = (unsigned char *) addr;
82 for (i = 0; i < count; i++, p += 4) {
83 tmp = (*p) | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) |
84 ((*(p + 3)) << 24);
85 outl(tmp, port);
88 EXPORT_SYMBOL(outsl);
90 void insl(unsigned long port, void *addr, unsigned long count)
92 int i;
93 unsigned tmp;
94 unsigned char *p = (unsigned char *) addr;
96 for (i = 0; i < count; i++, p += 4) {
97 tmp = inl(port);
98 p[0] = tmp & 0xff;
99 p[1] = (tmp >> 8) & 0xff;
100 p[2] = (tmp >> 16) & 0xff;
101 p[3] = (tmp >> 24) & 0xff;
105 EXPORT_SYMBOL(insl);
107 void memcpy_toio(void __iomem *to, const void *from, long count)
109 unsigned char *p = (unsigned char *) from;
111 while (count) {
112 count--;
113 writeb(*p++, to++);
116 EXPORT_SYMBOL(memcpy_toio);
118 void memcpy_fromio(void *to, void __iomem *from, long count)
120 int i;
121 unsigned char *p = (unsigned char *) to;
123 for (i = 0; i < count; i++) {
124 p[i] = readb(from);
125 from++;
128 EXPORT_SYMBOL(memcpy_fromio);