6 #include <linux/config.h>
7 #include <asm/virtconvert.h>
9 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
10 #include <asm/regs306x.h>
11 #elif defined(CONFIG_H8S2678)
12 #include <asm/regs267x.h>
14 #error UNKNOWN CPU TYPE
19 * These are for ISA/PCI shared memory _only_ and should never be used
20 * on any other type of memory, including Zorro memory. They are meant to
21 * access the bus in the bus byte order which is little-endian!.
23 * readX/writeX() are used to access memory mapped devices. On some
24 * architectures the memory mapped IO stuff needs to be accessed
25 * differently. On the m68k architecture, we just read/write the
26 * memory location directly.
28 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
29 * two accesses to memory, which may be undesireable for some devices.
33 * swap functions are sometimes needed to interface little-endian hardware
39 * 020325 Added some #define's for the COBRA5272 board
43 static inline unsigned short _swapw(volatile unsigned short v)
45 return ((v << 8) | (v >> 8));
48 static inline unsigned int _swapl(volatile unsigned long v)
50 return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
54 ({ unsigned char __v = (*(volatile unsigned char *) ((addr) & 0x00ffffff)); __v; })
56 ({ unsigned short __v = (*(volatile unsigned short *) ((addr) & 0x00ffffff)); __v; })
58 ({ unsigned int __v = (*(volatile unsigned int *) ((addr) & 0x00ffffff)); __v; })
60 #define writeb(b,addr) (void)((*(volatile unsigned char *) ((addr) & 0x00ffffff)) = (b))
61 #define writew(b,addr) (void)((*(volatile unsigned short *) ((addr) & 0x00ffffff)) = (b))
62 #define writel(b,addr) (void)((*(volatile unsigned int *) ((addr) & 0x00ffffff)) = (b))
63 #define readb_relaxed(addr) readb(addr)
64 #define readw_relaxed(addr) readw(addr)
65 #define readl_relaxed(addr) readl(addr)
67 #define __raw_readb readb
68 #define __raw_readw readw
69 #define __raw_readl readl
70 #define __raw_writeb writeb
71 #define __raw_writew writew
72 #define __raw_writel writel
74 static inline int h8300_buswidth(unsigned int addr)
76 return (*(volatile unsigned char *)ABWCR & (1 << ((addr >> 21) & 7))) == 0;
79 static inline void io_outsb(unsigned int addr, void *buf, int len)
81 volatile unsigned char *ap_b = (volatile unsigned char *) addr;
82 volatile unsigned short *ap_w = (volatile unsigned short *) addr;
83 unsigned char *bp = (unsigned char *) buf;
85 if(h8300_buswidth(addr) && (addr & 1)) {
94 static inline void io_outsw(unsigned int addr, void *buf, int len)
96 volatile unsigned short *ap = (volatile unsigned short *) addr;
97 unsigned short *bp = (unsigned short *) buf;
102 static inline void io_outsl(unsigned int addr, void *buf, int len)
104 volatile unsigned int *ap = (volatile unsigned int *) addr;
105 unsigned int *bp = (unsigned int *) buf;
110 static inline void io_insb(unsigned int addr, void *buf, int len)
112 volatile unsigned char *ap;
113 unsigned char *bp = (unsigned char *) buf;
115 if(h8300_buswidth(addr))
116 ap = (volatile unsigned char *)(addr ^ 1);
118 ap = (volatile unsigned char *)addr;
123 static inline void io_insw(unsigned int addr, void *buf, int len)
125 volatile unsigned short *ap = (volatile unsigned short *) addr;
126 unsigned short *bp = (unsigned short *) buf;
131 static inline void io_insl(unsigned int addr, void *buf, int len)
133 volatile unsigned int *ap = (volatile unsigned int *) addr;
134 unsigned int *bp = (unsigned int *) buf;
140 * make the short names macros so specific devices
141 * can override them as required
144 #define memset_io(a,b,c) memset((void *)(a),(b),(c))
145 #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
146 #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
148 #define inb(addr) ((h8300_buswidth(addr))?readb((addr) ^ 1) & 0xff:readb(addr))
149 #define inw(addr) _swapw(readw(addr))
150 #define inl(addr) _swapl(readl(addr))
151 #define outb(x,addr) ((void)((h8300_buswidth(addr) && ((addr) & 1))?writew(x,addr):writeb(x,addr)))
152 #define outw(x,addr) ((void) writew(_swapw(x),addr))
153 #define outl(x,addr) ((void) writel(_swapl(x),addr))
155 #define inb_p(addr) inb(addr)
156 #define inw_p(addr) inw(addr)
157 #define inl_p(addr) inl(addr)
158 #define outb_p(x,addr) outb(x,addr)
159 #define outw_p(x,addr) outw(x,addr)
160 #define outl_p(x,addr) outl(x,addr)
162 #define outsb(a,b,l) io_outsb(a,b,l)
163 #define outsw(a,b,l) io_outsw(a,b,l)
164 #define outsl(a,b,l) io_outsl(a,b,l)
166 #define insb(a,b,l) io_insb(a,b,l)
167 #define insw(a,b,l) io_insw(a,b,l)
168 #define insl(a,b,l) io_insl(a,b,l)
170 #define IO_SPACE_LIMIT 0xffffff
173 /* Values for nocacheflag and cmode */
174 #define IOMAP_FULL_CACHING 0
175 #define IOMAP_NOCACHE_SER 1
176 #define IOMAP_NOCACHE_NONSER 2
177 #define IOMAP_WRITETHROUGH 3
179 extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
180 extern void __iounmap(void *addr, unsigned long size);
182 static inline void *ioremap(unsigned long physaddr, unsigned long size)
184 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
186 static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
188 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
190 static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
192 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
194 static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
196 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
199 extern void iounmap(void *addr);
203 #define dma_cache_inv(_start,_size) do { } while (0)
204 #define dma_cache_wback(_start,_size) do { } while (0)
205 #define dma_cache_wback_inv(_start,_size) do { } while (0)
207 /* H8/300 internal I/O functions */
208 static __inline__ unsigned char ctrl_inb(unsigned long addr)
210 return *(volatile unsigned char*)addr;
213 static __inline__ unsigned short ctrl_inw(unsigned long addr)
215 return *(volatile unsigned short*)addr;
218 static __inline__ unsigned int ctrl_inl(unsigned long addr)
220 return *(volatile unsigned long*)addr;
223 static __inline__ void ctrl_outb(unsigned char b, unsigned long addr)
225 *(volatile unsigned char*)addr = b;
228 static __inline__ void ctrl_outw(unsigned short b, unsigned long addr)
230 *(volatile unsigned short*)addr = b;
233 static __inline__ void ctrl_outl(unsigned int b, unsigned long addr)
235 *(volatile unsigned long*)addr = b;
238 /* Pages to physical address... */
239 #define page_to_phys(page) ((page - mem_map) << PAGE_SHIFT)
240 #define page_to_bus(page) ((page - mem_map) << PAGE_SHIFT)
243 * Macros used for converting between virtual and physical mappings.
245 #define mm_ptov(vaddr) ((void *) (vaddr))
246 #define mm_vtop(vaddr) ((unsigned long) (vaddr))
247 #define phys_to_virt(vaddr) ((void *) (vaddr))
248 #define virt_to_phys(vaddr) ((unsigned long) (vaddr))
250 #define virt_to_bus virt_to_phys
251 #define bus_to_virt phys_to_virt
253 #endif /* __KERNEL__ */
255 #endif /* _H8300_IO_H */