MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / include / asm-m68knommu / io_hw_swap.h
blobb573e9fdc2e9df16f3e0438204fe2cc2edf026c1
1 #ifndef _M68K_IO_HW_SWAP_H
2 #define _M68K_IO_HW_SWAP_H
4 /*
5 * swap functions are sometimes needed to interface little-endian hardware
6 */
7 static inline unsigned short _swapw(volatile unsigned short v)
9 return ((v << 8) | (v >> 8));
12 static inline unsigned int _swapl(volatile unsigned long v)
14 return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
18 * readX/writeX() are used to access memory mapped devices. On some
19 * architectures the memory mapped IO stuff needs to be accessed
20 * differently. On the m68k architecture, we just read/write the
21 * memory location directly.
23 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
24 * two accesses to memory, which may be undesireable for some devices.
26 #define readb(addr) \
27 ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
28 #define readw(addr) \
29 ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
30 #define readl(addr) \
31 ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
33 #define writeb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
34 #define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
35 #define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
37 /* There is no difference between I/O and memory on 68k, these are the same */
38 #define inb(addr) \
39 ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
40 #define inw(addr) \
41 ({ unsigned short __v = (*(volatile unsigned short *) (addr)); \
42 _swapw(__v); })
43 #define inl(addr) \
44 ({ unsigned int __v = (*(volatile unsigned int *) (addr)); _swapl(__v); })
46 #define outb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
47 #define outw(b,addr) ((*(volatile unsigned short *) (addr)) = (_swapw(b)))
48 #define outl(b,addr) ((*(volatile unsigned int *) (addr)) = (_swapl(b)))
50 /* FIXME: these need to be optimized. Watch out for byte swapping, they
51 * are used mostly for Intel devices... */
52 #define outsw(addr,buf,len) \
53 ({ unsigned short * __p = (unsigned short *)(buf); \
54 unsigned short * __e = (unsigned short *)(__p) + (len); \
55 while (__p < __e) { \
56 *(volatile unsigned short *)(addr) = *__p++;\
57 } \
60 #define insw(addr,buf,len) \
61 ({ unsigned short * __p = (unsigned short *)(buf); \
62 unsigned short * __e = (unsigned short *)(__p) + (len); \
63 while (__p < __e) { \
64 *(__p++) = *(volatile unsigned short *)(addr); \
65 } \
69 static inline unsigned char get_user_byte_io(const char * addr)
71 register unsigned char _v;
73 __asm__ __volatile__ ("moveb %1,%0":"=dm" (_v):"m" (*addr));
74 return _v;
76 #define inb_p(addr) get_user_byte_io((char *)(addr))
78 static inline void put_user_byte_io(char val,char *addr)
80 __asm__ __volatile__ ("moveb %0,%1"
81 : /* no outputs */
82 :"idm" (val),"m" (*addr)
83 : "memory");
85 #define outb_p(x,addr) put_user_byte_io((x),(char *)(addr))
88 * Change virtual addresses to physical addresses and vv.
89 * These are trivial on the 1:1 Linux/i386 mapping (but if we ever
90 * make the kernel segment mapped at 0, we need to do translation
91 * on the i386 as well)
93 extern unsigned long mm_vtop(unsigned long addr);
94 extern unsigned long mm_ptov(unsigned long addr);
96 extern inline unsigned long virt_to_phys(volatile void * address)
98 return (unsigned long) mm_vtop((unsigned long)address);
101 extern inline void * phys_to_virt(unsigned long address)
103 return (void *) mm_ptov(address);
107 * IO bus memory addresses are also 1:1 with the physical address
109 #define virt_to_bus virt_to_phys
110 #define bus_to_virt phys_to_virt
113 #endif /* _M68K_IO_HW_SWAP_H */