fix a kmap leak in virtio_console
[linux/fpc-iii.git] / arch / m32r / platforms / m32700ut / io.c
blob6862586e58dbd11cc019be6db550c7eb679866be
1 /*
2 * linux/arch/m32r/platforms/m32700ut/io.c
4 * Typical I/O routines for M32700UT board.
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Takeo Takahashi
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file "COPYING" in the main directory of this
11 * archive for more details.
14 #include <asm/m32r.h>
15 #include <asm/page.h>
16 #include <asm/io.h>
17 #include <asm/byteorder.h>
19 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
20 #include <linux/types.h>
22 #define M32R_PCC_IOMAP_SIZE 0x1000
24 #define M32R_PCC_IOSTART0 0x1000
25 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
27 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
28 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
29 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
30 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
31 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
33 #define PORT2ADDR(port) _port2addr(port)
34 #define PORT2ADDR_USB(port) _port2addr_usb(port)
36 static inline void *_port2addr(unsigned long port)
38 return (void *)(port | NONCACHE_OFFSET);
41 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
42 static inline void *__port2addr_ata(unsigned long port)
44 static int dummy_reg;
46 switch (port) {
47 case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET);
48 case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET);
49 case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET);
50 case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET);
51 case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET);
52 case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET);
53 case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET);
54 case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET);
55 case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET);
56 default: return (void *)&dummy_reg;
59 #endif
62 * M32700UT-LAN is located in the extended bus space
63 * from 0x10000000 to 0x13ffffff on physical address.
64 * The base address of LAN controller(LAN91C111) is 0x300.
66 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
67 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
68 static inline void *_port2addr_ne(unsigned long port)
70 return (void *)(port + 0x10000000);
72 static inline void *_port2addr_usb(unsigned long port)
74 return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
77 static inline void delay(void)
79 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
83 * NIC I/O function
86 #define PORT2ADDR_NE(port) _port2addr_ne(port)
88 static inline unsigned char _ne_inb(void *portp)
90 return *(volatile unsigned char *)portp;
93 static inline unsigned short _ne_inw(void *portp)
95 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
98 static inline void _ne_insb(void *portp, void *addr, unsigned long count)
100 unsigned char *buf = (unsigned char *)addr;
102 while (count--)
103 *buf++ = _ne_inb(portp);
106 static inline void _ne_outb(unsigned char b, void *portp)
108 *(volatile unsigned char *)portp = b;
111 static inline void _ne_outw(unsigned short w, void *portp)
113 *(volatile unsigned short *)portp = cpu_to_le16(w);
116 unsigned char _inb(unsigned long port)
118 if (port >= LAN_IOSTART && port < LAN_IOEND)
119 return _ne_inb(PORT2ADDR_NE(port));
121 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
122 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
123 return *(volatile unsigned char *)__port2addr_ata(port);
125 #endif
126 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
127 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
128 unsigned char b;
129 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
130 return b;
131 } else
132 #endif
134 return *(volatile unsigned char *)PORT2ADDR(port);
137 unsigned short _inw(unsigned long port)
139 if (port >= LAN_IOSTART && port < LAN_IOEND)
140 return _ne_inw(PORT2ADDR_NE(port));
141 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
142 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
143 return *(volatile unsigned short *)__port2addr_ata(port);
145 #endif
146 #if defined(CONFIG_USB)
147 else if(port >= 0x340 && port < 0x3a0)
148 return *(volatile unsigned short *)PORT2ADDR_USB(port);
149 #endif
150 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
151 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
152 unsigned short w;
153 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
154 return w;
155 } else
156 #endif
157 return *(volatile unsigned short *)PORT2ADDR(port);
160 unsigned long _inl(unsigned long port)
162 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
163 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
164 unsigned long l;
165 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
166 return l;
167 } else
168 #endif
169 return *(volatile unsigned long *)PORT2ADDR(port);
172 unsigned char _inb_p(unsigned long port)
174 unsigned char v = _inb(port);
175 delay();
176 return (v);
179 unsigned short _inw_p(unsigned long port)
181 unsigned short v = _inw(port);
182 delay();
183 return (v);
186 unsigned long _inl_p(unsigned long port)
188 unsigned long v = _inl(port);
189 delay();
190 return (v);
193 void _outb(unsigned char b, unsigned long port)
195 if (port >= LAN_IOSTART && port < LAN_IOEND)
196 _ne_outb(b, PORT2ADDR_NE(port));
197 else
198 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
199 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
200 *(volatile unsigned char *)__port2addr_ata(port) = b;
201 } else
202 #endif
203 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
204 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
205 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
206 } else
207 #endif
208 *(volatile unsigned char *)PORT2ADDR(port) = b;
211 void _outw(unsigned short w, unsigned long port)
213 if (port >= LAN_IOSTART && port < LAN_IOEND)
214 _ne_outw(w, PORT2ADDR_NE(port));
215 else
216 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
217 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
218 *(volatile unsigned short *)__port2addr_ata(port) = w;
219 } else
220 #endif
221 #if defined(CONFIG_USB)
222 if(port >= 0x340 && port < 0x3a0)
223 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
224 else
225 #endif
226 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
227 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
228 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
229 } else
230 #endif
231 *(volatile unsigned short *)PORT2ADDR(port) = w;
234 void _outl(unsigned long l, unsigned long port)
236 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
237 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
238 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
239 } else
240 #endif
241 *(volatile unsigned long *)PORT2ADDR(port) = l;
244 void _outb_p(unsigned char b, unsigned long port)
246 _outb(b, port);
247 delay();
250 void _outw_p(unsigned short w, unsigned long port)
252 _outw(w, port);
253 delay();
256 void _outl_p(unsigned long l, unsigned long port)
258 _outl(l, port);
259 delay();
262 void _insb(unsigned int port, void *addr, unsigned long count)
264 if (port >= LAN_IOSTART && port < LAN_IOEND)
265 _ne_insb(PORT2ADDR_NE(port), addr, count);
266 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
267 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
268 unsigned char *buf = addr;
269 unsigned char *portp = __port2addr_ata(port);
270 while (count--)
271 *buf++ = *(volatile unsigned char *)portp;
273 #endif
274 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
275 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
276 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
277 count, 1);
279 #endif
280 else {
281 unsigned char *buf = addr;
282 unsigned char *portp = PORT2ADDR(port);
283 while (count--)
284 *buf++ = *(volatile unsigned char *)portp;
288 void _insw(unsigned int port, void *addr, unsigned long count)
290 unsigned short *buf = addr;
291 unsigned short *portp;
293 if (port >= LAN_IOSTART && port < LAN_IOEND) {
295 * This portion is only used by smc91111.c to read data
296 * from the DATA_REG. Do not swap the data.
298 portp = PORT2ADDR_NE(port);
299 while (count--)
300 *buf++ = *(volatile unsigned short *)portp;
301 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
302 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
303 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
304 count, 1);
305 #endif
306 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
307 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
308 portp = __port2addr_ata(port);
309 while (count--)
310 *buf++ = *(volatile unsigned short *)portp;
311 #endif
312 } else {
313 portp = PORT2ADDR(port);
314 while (count--)
315 *buf++ = *(volatile unsigned short *)portp;
319 void _insl(unsigned int port, void *addr, unsigned long count)
321 unsigned long *buf = addr;
322 unsigned long *portp;
324 portp = PORT2ADDR(port);
325 while (count--)
326 *buf++ = *(volatile unsigned long *)portp;
329 void _outsb(unsigned int port, const void *addr, unsigned long count)
331 const unsigned char *buf = addr;
332 unsigned char *portp;
334 if (port >= LAN_IOSTART && port < LAN_IOEND) {
335 portp = PORT2ADDR_NE(port);
336 while (count--)
337 _ne_outb(*buf++, portp);
338 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
339 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
340 portp = __port2addr_ata(port);
341 while (count--)
342 *(volatile unsigned char *)portp = *buf++;
343 #endif
344 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
345 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
346 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
347 count, 1);
348 #endif
349 } else {
350 portp = PORT2ADDR(port);
351 while (count--)
352 *(volatile unsigned char *)portp = *buf++;
356 void _outsw(unsigned int port, const void *addr, unsigned long count)
358 const unsigned short *buf = addr;
359 unsigned short *portp;
361 if (port >= LAN_IOSTART && port < LAN_IOEND) {
363 * This portion is only used by smc91111.c to write data
364 * into the DATA_REG. Do not swap the data.
366 portp = PORT2ADDR_NE(port);
367 while (count--)
368 *(volatile unsigned short *)portp = *buf++;
369 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
370 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
371 portp = __port2addr_ata(port);
372 while (count--)
373 *(volatile unsigned short *)portp = *buf++;
374 #endif
375 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
376 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
377 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
378 count, 1);
379 #endif
380 } else {
381 portp = PORT2ADDR(port);
382 while (count--)
383 *(volatile unsigned short *)portp = *buf++;
387 void _outsl(unsigned int port, const void *addr, unsigned long count)
389 const unsigned long *buf = addr;
390 unsigned char *portp;
392 portp = PORT2ADDR(port);
393 while (count--)
394 *(volatile unsigned long *)portp = *buf++;