7 * These are for ISA/PCI shared memory _only_ and should never be used
8 * on any other type of memory, including Zorro memory. They are meant to
9 * access the bus in the bus byte order which is little-endian!.
11 * readX/writeX() are used to access memory mapped devices. On some
12 * architectures the memory mapped IO stuff needs to be accessed
13 * differently. On the m68k architecture, we just read/write the
14 * memory location directly.
16 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
17 * two accesses to memory, which may be undesirable for some devices.
21 * swap functions are sometimes needed to interface little-endian hardware
24 static inline unsigned short _swapw(volatile unsigned short v)
26 #ifndef H8300_IO_NOSWAP
29 __asm__("xor.b %w0,%x0\n\t"
40 static inline unsigned long _swapl(volatile unsigned long v)
42 #ifndef H8300_IO_NOSWAP
45 __asm__("xor.b %w0,%x0\n\t"
63 ({ u8 __v = *(volatile u8 *)((uintptr_t)(addr) & 0x00ffffff); __v; })
66 ({ u16 __v = *(volatile u16 *)((uintptr_t)(addr) & 0x00ffffff); __v; })
69 ({ u32 __v = *(volatile u32 *)((uintptr_t)(addr) & 0x00ffffff); __v; })
71 #define writeb(b, addr) (void)((*(volatile u8 *) \
72 ((uintptr_t)(addr) & 0x00ffffff)) = (b))
74 #define writew(b, addr) (void)((*(volatile u16 *) \
75 ((uintptr_t)(addr) & 0x00ffffff)) = (b))
77 #define writel(b, addr) (void)((*(volatile u32 *) \
78 ((uintptr_t)(addr) & 0x00ffffff)) = (b))
80 #define readb_relaxed(addr) readb(addr)
81 #define readw_relaxed(addr) readw(addr)
82 #define readl_relaxed(addr) readl(addr)
83 #define writeb_relaxed(b, addr) writeb(b, addr)
84 #define writew_relaxed(b, addr) writew(b, addr)
85 #define writel_relaxed(b, addr) writel(b, addr)
87 #define __raw_readb readb
88 #define __raw_readw readw
89 #define __raw_readl readl
90 #define __raw_writeb writeb
91 #define __raw_writew writew
92 #define __raw_writel writel
94 #if defined(CONFIG_H83069)
95 #define ABWCR 0xFEE020
96 #elif defined(CONFIG_H8S2678)
97 #define ABWCR 0xFFFEC0
100 static inline int h8300_buswidth(unsigned int addr)
102 return (*(volatile u8 *)ABWCR & (1 << ((addr >> 21) & 7))) == 0;
105 static inline void io_outsb(unsigned int addr, const void *buf, int len)
107 volatile unsigned char *ap_b = (volatile unsigned char *) addr;
108 volatile unsigned short *ap_w = (volatile unsigned short *) addr;
109 unsigned char *bp = (unsigned char *) buf;
111 if (h8300_buswidth(addr) && (addr & 1)) {
120 static inline void io_outsw(unsigned int addr, const void *buf, int len)
122 volatile unsigned short *ap = (volatile unsigned short *) addr;
123 unsigned short *bp = (unsigned short *) buf;
129 static inline void io_outsl(unsigned int addr, const void *buf, int len)
131 volatile unsigned long *ap = (volatile unsigned long *) addr;
132 unsigned long *bp = (unsigned long *) buf;
138 static inline void io_outsw_noswap(unsigned int addr, const void *buf, int len)
140 volatile unsigned short *ap = (volatile unsigned short *) addr;
141 unsigned short *bp = (unsigned short *) buf;
147 static inline void io_outsl_noswap(unsigned int addr, const void *buf, int len)
149 volatile unsigned long *ap = (volatile unsigned long *) addr;
150 unsigned long *bp = (unsigned long *) buf;
156 static inline void io_insb(unsigned int addr, void *buf, int len)
158 volatile unsigned char *ap_b;
159 volatile unsigned short *ap_w;
160 unsigned char *bp = (unsigned char *) buf;
162 if (h8300_buswidth(addr)) {
163 ap_w = (volatile unsigned short *)(addr & ~1);
165 *bp++ = *ap_w & 0xff;
167 ap_b = (volatile unsigned char *)addr;
173 static inline void io_insw(unsigned int addr, void *buf, int len)
175 volatile unsigned short *ap = (volatile unsigned short *) addr;
176 unsigned short *bp = (unsigned short *) buf;
182 static inline void io_insl(unsigned int addr, void *buf, int len)
184 volatile unsigned long *ap = (volatile unsigned long *) addr;
185 unsigned long *bp = (unsigned long *) buf;
191 static inline void io_insw_noswap(unsigned int addr, void *buf, int len)
193 volatile unsigned short *ap = (volatile unsigned short *) addr;
194 unsigned short *bp = (unsigned short *) buf;
200 static inline void io_insl_noswap(unsigned int addr, void *buf, int len)
202 volatile unsigned long *ap = (volatile unsigned long *) addr;
203 unsigned long *bp = (unsigned long *) buf;
210 * make the short names macros so specific devices
211 * can override them as required
214 #define memset_io(a, b, c) memset((void *)(a), (b), (c))
215 #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
216 #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
220 #define inb(addr) ((h8300_buswidth(addr)) ? \
221 readw((addr) & ~1) & 0xff:readb(addr))
222 #define inw(addr) _swapw(readw(addr))
223 #define inl(addr) _swapl(readl(addr))
224 #define outb(x, addr) ((void)((h8300_buswidth(addr) && \
226 writew(x, (addr) & ~1) : writeb(x, addr)))
227 #define outw(x, addr) ((void) writew(_swapw(x), addr))
228 #define outl(x, addr) ((void) writel(_swapl(x), addr))
230 #define inb_p(addr) inb(addr)
231 #define inw_p(addr) inw(addr)
232 #define inl_p(addr) inl(addr)
233 #define outb_p(x, addr) outb(x, addr)
234 #define outw_p(x, addr) outw(x, addr)
235 #define outl_p(x, addr) outl(x, addr)
237 #define outsb(a, b, l) io_outsb(a, b, l)
238 #define outsw(a, b, l) io_outsw(a, b, l)
239 #define outsl(a, b, l) io_outsl(a, b, l)
241 #define insb(a, b, l) io_insb(a, b, l)
242 #define insw(a, b, l) io_insw(a, b, l)
243 #define insl(a, b, l) io_insl(a, b, l)
245 #define ioread8(a) __raw_readb(a)
246 #define ioread16(a) __raw_readw(a)
247 #define ioread32(a) __raw_readl(a)
249 #define iowrite8(v, a) __raw_writeb((v), (a))
250 #define iowrite16(v, a) __raw_writew((v), (a))
251 #define iowrite32(v, a) __raw_writel((v), (a))
252 #define IO_SPACE_LIMIT 0xffffff
255 /* Values for nocacheflag and cmode */
256 #define IOMAP_FULL_CACHING 0
257 #define IOMAP_NOCACHE_SER 1
258 #define IOMAP_NOCACHE_NONSER 2
259 #define IOMAP_WRITETHROUGH 3
261 extern void *__ioremap(unsigned long physaddr, unsigned long size,
263 extern void __iounmap(void *addr, unsigned long size);
265 static inline void *ioremap(unsigned long physaddr, unsigned long size)
267 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
269 static inline void *ioremap_nocache(unsigned long physaddr,
272 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
274 static inline void *ioremap_writethrough(unsigned long physaddr,
277 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
279 static inline void *ioremap_fullcache(unsigned long physaddr,
282 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
285 extern void iounmap(void *addr);
287 /* H8/300 internal I/O functions */
288 static inline unsigned char ctrl_inb(unsigned long addr)
290 return *(volatile unsigned char *)addr;
293 static inline unsigned short ctrl_inw(unsigned long addr)
295 return *(volatile unsigned short *)addr;
298 static inline unsigned long ctrl_inl(unsigned long addr)
300 return *(volatile unsigned long *)addr;
303 static inline void ctrl_outb(unsigned char b, unsigned long addr)
305 *(volatile unsigned char *)addr = b;
308 static inline void ctrl_outw(unsigned short b, unsigned long addr)
310 *(volatile unsigned short *)addr = b;
313 static inline void ctrl_outl(unsigned long b, unsigned long addr)
315 *(volatile unsigned long *)addr = b;
318 static inline void ctrl_bclr(int b, unsigned long addr)
320 if (__builtin_constant_p(b))
322 case 0: __asm__("bclr #0,@%0" : : "m"(addr)); break;
323 case 1: __asm__("bclr #1,@%0" : : "m"(addr)); break;
324 case 2: __asm__("bclr #2,@%0" : : "m"(addr)); break;
325 case 3: __asm__("bclr #3,@%0" : : "m"(addr)); break;
326 case 4: __asm__("bclr #4,@%0" : : "m"(addr)); break;
327 case 5: __asm__("bclr #5,@%0" : : "m"(addr)); break;
328 case 6: __asm__("bclr #6,@%0" : : "m"(addr)); break;
329 case 7: __asm__("bclr #7,@%0" : : "m"(addr)); break;
332 __asm__("bclr %w0,@%1" : : "r"(b), "m"(addr));
335 static inline void ctrl_bset(int b, unsigned long addr)
337 if (__builtin_constant_p(b))
339 case 0: __asm__("bset #0,@%0" : : "m"(addr)); break;
340 case 1: __asm__("bset #1,@%0" : : "m"(addr)); break;
341 case 2: __asm__("bset #2,@%0" : : "m"(addr)); break;
342 case 3: __asm__("bset #3,@%0" : : "m"(addr)); break;
343 case 4: __asm__("bset #4,@%0" : : "m"(addr)); break;
344 case 5: __asm__("bset #5,@%0" : : "m"(addr)); break;
345 case 6: __asm__("bset #6,@%0" : : "m"(addr)); break;
346 case 7: __asm__("bset #7,@%0" : : "m"(addr)); break;
349 __asm__("bset %w0,@%1" : : "r"(b), "m"(addr));
353 * Macros used for converting between virtual and physical mappings.
355 #define phys_to_virt(vaddr) ((void *) (vaddr))
356 #define virt_to_phys(vaddr) ((unsigned long) (vaddr))
358 #define virt_to_bus virt_to_phys
359 #define bus_to_virt phys_to_virt
361 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
364 #define xlate_dev_mem_ptr(p) __va(p)
367 * Convert a virtual cached pointer to an uncached pointer
369 #define xlate_dev_kmem_ptr(p) (p)
371 #endif /* __KERNEL__ */
373 #endif /* _H8300_IO_H */