2 * Copyright (C) 2004, Microtronix Datacom Ltd.
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
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.
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)
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.
59 __asm__ __volatile__( \
68 unsigned short __res;\
69 __asm__ __volatile__( \
79 __asm__ __volatile__( \
86 #define writeb(b,addr) \
88 __asm__ __volatile__( \
90 : : "r"(b), "r" (addr)); \
93 #define writew(b,addr) \
95 __asm__ __volatile__( \
97 : : "r"(b), "r" (addr)); \
100 #define writel(b,addr) \
102 __asm__ __volatile__( \
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
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
;
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
;
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
;
166 extern inline void outsb(unsigned long port
, void *src
, unsigned long count
)
168 unsigned char *p
=(unsigned char*)src
;
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
;
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
;
191 extern inline void mapioaddr(unsigned long physaddr
, unsigned long virt_addr
,
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
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) */