[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / m32r / kernel / io_mappi.c
blob85688ffb52f93cd632041419c3634babc33e0b77
1 /*
2 * linux/arch/m32r/kernel/io_mappi.c
4 * Typical I/O routines for Mappi board.
6 * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto
8 */
10 #include <linux/config.h>
11 #include <asm/m32r.h>
12 #include <asm/page.h>
13 #include <asm/io.h>
14 #include <asm/byteorder.h>
16 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
17 #include <linux/types.h>
19 #define M32R_PCC_IOMAP_SIZE 0x1000
21 #define M32R_PCC_IOSTART0 0x1000
22 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
23 #define M32R_PCC_IOSTART1 0x2000
24 #define M32R_PCC_IOEND1 (M32R_PCC_IOSTART1 + M32R_PCC_IOMAP_SIZE - 1)
26 extern void pcc_ioread(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite(int, unsigned long, void *, size_t, size_t, int);
28 #endif /* CONFIG_PCMCIA && CONFIG_M32R_PCC */
30 #define PORT2ADDR(port) _port2addr(port)
32 static inline void *_port2addr(unsigned long port)
34 return (void *)(port + NONCACHE_OFFSET);
37 static inline void *_port2addr_ne(unsigned long port)
39 return (void *)((port<<1) + NONCACHE_OFFSET + 0x0C000000);
42 static inline void delay(void)
44 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
48 * NIC I/O function
51 #define PORT2ADDR_NE(port) _port2addr_ne(port)
53 static inline unsigned char _ne_inb(void *portp)
55 return (unsigned char) *(volatile unsigned short *)portp;
58 static inline unsigned short _ne_inw(void *portp)
60 unsigned short tmp;
62 tmp = *(volatile unsigned short *)portp;
63 return le16_to_cpu(tmp);
66 static inline void _ne_outb(unsigned char b, void *portp)
68 *(volatile unsigned short *)portp = (unsigned short)b;
71 static inline void _ne_outw(unsigned short w, void *portp)
73 *(volatile unsigned short *)portp = cpu_to_le16(w);
76 unsigned char _inb(unsigned long port)
78 if (port >= 0x300 && port < 0x320)
79 return _ne_inb(PORT2ADDR_NE(port));
80 else
81 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
82 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
83 unsigned char b;
84 pcc_ioread(0, port, &b, sizeof(b), 1, 0);
85 return b;
86 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
87 unsigned char b;
88 pcc_ioread(1, port, &b, sizeof(b), 1, 0);
89 return b;
90 } else
91 #endif
93 return *(volatile unsigned char *)PORT2ADDR(port);
96 unsigned short _inw(unsigned long port)
98 if (port >= 0x300 && port < 0x320)
99 return _ne_inw(PORT2ADDR_NE(port));
100 else
101 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
102 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
103 unsigned short w;
104 pcc_ioread(0, port, &w, sizeof(w), 1, 0);
105 return w;
106 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
107 unsigned short w;
108 pcc_ioread(1, port, &w, sizeof(w), 1, 0);
109 return w;
110 } else
111 #endif
112 return *(volatile unsigned short *)PORT2ADDR(port);
115 unsigned long _inl(unsigned long port)
117 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
118 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
119 unsigned long l;
120 pcc_ioread(0, port, &l, sizeof(l), 1, 0);
121 return l;
122 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
123 unsigned short l;
124 pcc_ioread(1, port, &l, sizeof(l), 1, 0);
125 return l;
126 } else
127 #endif
128 return *(volatile unsigned long *)PORT2ADDR(port);
131 unsigned char _inb_p(unsigned long port)
133 unsigned char v;
135 if (port >= 0x300 && port < 0x320)
136 v = _ne_inb(PORT2ADDR_NE(port));
137 else
138 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
139 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
140 unsigned char b;
141 pcc_ioread(0, port, &b, sizeof(b), 1, 0);
142 return b;
143 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
144 unsigned char b;
145 pcc_ioread(1, port, &b, sizeof(b), 1, 0);
146 return b;
147 } else
148 #endif
149 v = *(volatile unsigned char *)PORT2ADDR(port);
151 delay();
152 return (v);
155 unsigned short _inw_p(unsigned long port)
157 unsigned short v;
159 if (port >= 0x300 && port < 0x320)
160 v = _ne_inw(PORT2ADDR_NE(port));
161 else
162 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
163 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
164 unsigned short w;
165 pcc_ioread(0, port, &w, sizeof(w), 1, 0);
166 return w;
167 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
168 unsigned short w;
169 pcc_ioread(1, port, &w, sizeof(w), 1, 0);
170 return w;
171 } else
172 #endif
173 v = *(volatile unsigned short *)PORT2ADDR(port);
175 delay();
176 return (v);
179 unsigned long _inl_p(unsigned long port)
181 unsigned long v;
183 v = *(volatile unsigned long *)PORT2ADDR(port);
184 delay();
185 return (v);
188 void _outb(unsigned char b, unsigned long port)
190 if (port >= 0x300 && port < 0x320)
191 _ne_outb(b, PORT2ADDR_NE(port));
192 else
193 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
194 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
195 pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
196 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
197 pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
198 } else
199 #endif
200 *(volatile unsigned char *)PORT2ADDR(port) = b;
203 void _outw(unsigned short w, unsigned long port)
205 if (port >= 0x300 && port < 0x320)
206 _ne_outw(w, PORT2ADDR_NE(port));
207 else
208 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
209 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
210 pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
211 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
212 pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
213 } else
214 #endif
215 *(volatile unsigned short *)PORT2ADDR(port) = w;
218 void _outl(unsigned long l, unsigned long port)
220 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
221 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
222 pcc_iowrite(0, port, &l, sizeof(l), 1, 0);
223 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
224 pcc_iowrite(1, port, &l, sizeof(l), 1, 0);
225 } else
226 #endif
227 *(volatile unsigned long *)PORT2ADDR(port) = l;
230 void _outb_p(unsigned char b, unsigned long port)
232 if (port >= 0x300 && port < 0x320)
233 _ne_outb(b, PORT2ADDR_NE(port));
234 else
235 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
236 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
237 pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
238 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
239 pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
240 } else
241 #endif
242 *(volatile unsigned char *)PORT2ADDR(port) = b;
244 delay();
247 void _outw_p(unsigned short w, unsigned long port)
249 if (port >= 0x300 && port < 0x320)
250 _ne_outw(w, PORT2ADDR_NE(port));
251 else
252 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
253 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
254 pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
255 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
256 pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
257 } else
258 #endif
259 *(volatile unsigned short *)PORT2ADDR(port) = w;
261 delay();
264 void _outl_p(unsigned long l, unsigned long port)
266 *(volatile unsigned long *)PORT2ADDR(port) = l;
267 delay();
270 void _insb(unsigned int port, void *addr, unsigned long count)
272 unsigned short *buf = addr;
273 unsigned short *portp;
275 if (port >= 0x300 && port < 0x320){
276 portp = PORT2ADDR_NE(port);
277 while (count--)
278 *buf++ = *(volatile unsigned char *)portp;
279 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
280 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
281 pcc_ioread(0, port, (void *)addr, sizeof(unsigned char),
282 count, 1);
283 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
284 pcc_ioread(1, port, (void *)addr, sizeof(unsigned char),
285 count, 1);
286 #endif
287 } else {
288 portp = PORT2ADDR(port);
289 while (count--)
290 *buf++ = *(volatile unsigned char *)portp;
294 void _insw(unsigned int port, void *addr, unsigned long count)
296 unsigned short *buf = addr;
297 unsigned short *portp;
299 if (port >= 0x300 && port < 0x320) {
300 portp = PORT2ADDR_NE(port);
301 while (count--)
302 *buf++ = _ne_inw(portp);
303 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
304 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
305 pcc_ioread(0, port, (void *)addr, sizeof(unsigned short),
306 count, 1);
307 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
308 pcc_ioread(1, port, (void *)addr, sizeof(unsigned short),
309 count, 1);
310 #endif
311 } else {
312 portp = PORT2ADDR(port);
313 while (count--)
314 *buf++ = *(volatile unsigned short *)portp;
318 void _insl(unsigned int port, void *addr, unsigned long count)
320 unsigned long *buf = addr;
321 unsigned long *portp;
323 portp = PORT2ADDR(port);
324 while (count--)
325 *buf++ = *(volatile unsigned long *)portp;
328 void _outsb(unsigned int port, const void *addr, unsigned long count)
330 const unsigned char *buf = addr;
331 unsigned char *portp;
333 if (port >= 0x300 && port < 0x320) {
334 portp = PORT2ADDR_NE(port);
335 while (count--)
336 _ne_outb(*buf++, portp);
337 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
338 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
339 pcc_iowrite(0, port, (void *)addr, sizeof(unsigned char),
340 count, 1);
341 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
342 pcc_iowrite(1, port, (void *)addr, sizeof(unsigned char),
343 count, 1);
344 #endif
345 } else {
346 portp = PORT2ADDR(port);
347 while (count--)
348 *(volatile unsigned char *)portp = *buf++;
352 void _outsw(unsigned int port, const void *addr, unsigned long count)
354 const unsigned short *buf = addr;
355 unsigned short *portp;
357 if (port >= 0x300 && port < 0x320) {
358 portp = PORT2ADDR_NE(port);
359 while (count--)
360 _ne_outw(*buf++, portp);
361 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
362 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
363 pcc_iowrite(0, port, (void *)addr, sizeof(unsigned short),
364 count, 1);
365 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
366 pcc_iowrite(1, port, (void *)addr, sizeof(unsigned short),
367 count, 1);
368 #endif
369 } else {
370 portp = PORT2ADDR(port);
371 while (count--)
372 *(volatile unsigned short *)portp = *buf++;
376 void _outsl(unsigned int port, const void *addr, unsigned long count)
378 const unsigned long *buf = addr;
379 unsigned char *portp;
381 portp = PORT2ADDR(port);
382 while (count--)
383 *(volatile unsigned long *)portp = *buf++;