MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / include / asm-nios2nommu / io.h
blob73a5c17628a483a2085cf9e7bfa92e0ae66d4d35
1 /*
2 * Copyright (C) 2004, Microtronix Datacom Ltd.
4 * All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
15 * details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifndef __NIOS2_IO_H
24 #define __NIOS2_IO_H
26 #ifdef __KERNEL__
28 #include <linux/kernel.h>
30 #include <asm/page.h> /* IO address mapping routines need this */
31 #include <asm/system.h>
32 #include <asm/unaligned.h>
34 extern void insw(unsigned long port, void *dst, unsigned long count);
35 extern void outsw(unsigned long port, void *src, unsigned long count);
36 extern void insl(unsigned long port, void *dst, unsigned long count);
37 extern void outsl(unsigned long port, void *src, unsigned long count);
39 #define readsb(p,d,l) insb(p,d,l)
40 #define readsw(p,d,l) insw(p,d,l)
41 #define readsl(p,d,l) insl(p,d,l)
42 #define writesb(p,d,l) outsb(p,d,l)
43 #define writesw(p,d,l) outsw(p,d,l)
44 #define writesl(p,d,l) outsl(p,d,l)
45 #ifndef irq_canonicalize
46 #define irq_canonicalize(i) (i)
47 #endif
50 * readX/writeX() are used to access memory mapped devices. On some
51 * architectures the memory mapped IO stuff needs to be accessed
52 * differently. On the Nios architecture, we just read/write the
53 * memory location directly.
56 #define readb(addr) \
57 ({ \
58 unsigned char __res;\
59 __asm__ __volatile__( \
60 "ldbuio %0, 0(%1)" \
61 : "=r"(__res) \
62 : "r" (addr)); \
63 __res; \
66 #define readw(addr) \
67 ({ \
68 unsigned short __res;\
69 __asm__ __volatile__( \
70 "ldhuio %0, 0(%1)" \
71 : "=r"(__res) \
72 : "r" (addr)); \
73 __res; \
76 #define readl(addr) \
77 ({ \
78 unsigned int __res;\
79 __asm__ __volatile__( \
80 "ldwio %0, 0(%1)" \
81 : "=r"(__res) \
82 : "r" (addr)); \
83 __res; \
86 #define writeb(b,addr) \
87 ({ \
88 __asm__ __volatile__( \
89 "stbio %0, 0(%1)" \
90 : : "r"(b), "r" (addr)); \
93 #define writew(b,addr) \
94 ({ \
95 __asm__ __volatile__( \
96 "sthio %0, 0(%1)" \
97 : : "r"(b), "r" (addr)); \
100 #define writel(b,addr) \
101 ({ \
102 __asm__ __volatile__( \
103 "stwio %0, 0(%1)" \
104 : : "r"(b), "r" (addr)); \
107 #define __raw_readb readb
108 #define __raw_readw readw
109 #define __raw_readl readl
110 #define __raw_writeb writeb
111 #define __raw_writew writew
112 #define __raw_writel writel
114 #define mmiowb()
117 * make the short names macros so specific devices
118 * can override them as required
121 #define memset_io(addr,c,len) memset((void *)(((unsigned int)(addr)) | 0x80000000),(c),(len))
122 #define memcpy_fromio(to,from,len) memcpy((to),(void *)(((unsigned int)(from)) | 0x80000000),(len))
123 #define memcpy_toio(to,from,len) memcpy((void *)(((unsigned int)(to)) | 0x80000000),(from),(len))
125 #define inb(addr) readb(addr)
126 #define inw(addr) readw(addr)
127 #define inl(addr) readl(addr)
129 #define outb(x,addr) ((void) writeb(x,addr))
130 #define outw(x,addr) ((void) writew(x,addr))
131 #define outl(x,addr) ((void) writel(x,addr))
133 #define inb_p(addr) inb(addr)
134 #define inw_p(addr) inw(addr)
135 #define inl_p(addr) inl(addr)
137 #define outb_p(x,addr) outb(x,addr)
138 #define outw_p(x,addr) outw(x,addr)
139 #define outl_p(x,addr) outl(x,addr)
143 extern inline void insb(unsigned long port, void *dst, unsigned long count)
145 unsigned char *p=(unsigned char*)dst;
146 while (count--)
147 *p++ = inb(port);
150 /* See arch/niosnommu/io.c for optimized version */
151 extern inline void _insw(unsigned long port, void *dst, unsigned long count)
153 unsigned short *p=(unsigned short*)dst;
154 while (count--)
155 *p++ = inw(port);
158 /* See arch/niosnommu/kernel/io.c for unaligned destination pointer */
159 extern inline void _insl(unsigned long port, void *dst, unsigned long count)
161 unsigned long *p=(unsigned long*)dst;
162 while (count--)
163 *p++ = inl(port);
166 extern inline void outsb(unsigned long port, void *src, unsigned long count)
168 unsigned char *p=(unsigned char*)src;
169 while (count--)
170 outb( *p++, port );
173 /* See arch/niosnommu/io.c for optimized version */
174 extern inline void _outsw(unsigned long port, void *src, unsigned long count)
176 unsigned short *p=(unsigned short*)src;
177 while (count--)
178 outw( *p++, port );
181 /* See arch/niosnommu/kernel/io.c for unaligned source pointer */
182 extern inline void _outsl(unsigned long port, void *src, unsigned long count)
184 unsigned long *p=(unsigned long*)src;
185 while (count--)
186 outl( *p++, port );
191 extern inline void mapioaddr(unsigned long physaddr, unsigned long virt_addr,
192 int bus, int rdonly)
194 return;
197 //vic - copied from m68knommu
199 /* Values for nocacheflag and cmode */
200 #define IOMAP_FULL_CACHING 0
201 #define IOMAP_NOCACHE_SER 1
202 #define IOMAP_NOCACHE_NONSER 2
203 #define IOMAP_WRITETHROUGH 3
205 extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
206 extern void __iounmap(void *addr, unsigned long size);
208 extern inline void *ioremap(unsigned long physaddr, unsigned long size)
210 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
212 extern inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
214 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
216 extern inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
218 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
220 extern inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
222 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
225 extern void iounmap(void *addr);
228 #define IO_SPACE_LIMIT 0xffffffff
230 #define dma_cache_inv(_start,_size) dcache_push(_start,_size)
231 #define dma_cache_wback(_start,_size) dcache_push(_start,_size)
232 #define dma_cache_wback_inv(_start,_size) dcache_push(_start,_size)
234 /* Pages to physical address... */
235 #define page_to_phys(page) page_to_virt(page)
236 #define page_to_bus(page) page_to_virt(page)
238 #define mm_ptov(vaddr) ((void *) (vaddr))
239 #define mm_vtop(vaddr) ((unsigned long) (vaddr))
240 #define phys_to_virt(vaddr) ((void *) (vaddr))
241 #define virt_to_phys(vaddr) ((unsigned long) (vaddr))
243 #define virt_to_bus virt_to_phys
244 #define bus_to_virt phys_to_virt
247 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
248 * access
250 #define xlate_dev_mem_ptr(p) __va(p)
253 * Convert a virtual cached pointer to an uncached pointer
255 #define xlate_dev_kmem_ptr(p) p
257 #endif /* __KERNEL__ */
259 #endif /* !(__NIOS2_IO_H) */