1 #ifndef _M68K_IO_HW_SWAP_H
2 #define _M68K_IO_HW_SWAP_H
5 * swap functions are sometimes needed to interface little-endian hardware
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.
27 ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
29 ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
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 */
39 ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
41 ({ unsigned short __v = (*(volatile unsigned short *) (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); \
56 *(volatile unsigned short *)(addr) = *__p++;\
60 #define insw(addr,buf,len) \
61 ({ unsigned short * __p = (unsigned short *)(buf); \
62 unsigned short * __e = (unsigned short *)(__p) + (len); \
64 *(__p++) = *(volatile unsigned short *)(addr); \
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
));
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"
82 :"idm" (val
),"m" (*addr
)
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 */