Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _M68KNOMMU_IO_H |
| 2 | #define _M68KNOMMU_IO_H |
| 3 | |
| 4 | #ifdef __KERNEL__ |
| 5 | |
Greg Ungerer | 682137f | 2010-01-13 10:42:05 +1000 | [diff] [blame] | 6 | #include <asm/virtconvert.h> |
Greg Ungerer | f79b859 | 2013-08-02 17:24:38 +1000 | [diff] [blame] | 7 | #include <asm-generic/iomap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | /* |
| 10 | * These are for ISA/PCI shared memory _only_ and should never be used |
| 11 | * on any other type of memory, including Zorro memory. They are meant to |
| 12 | * access the bus in the bus byte order which is little-endian!. |
| 13 | * |
| 14 | * readX/writeX() are used to access memory mapped devices. On some |
| 15 | * architectures the memory mapped IO stuff needs to be accessed |
| 16 | * differently. On the m68k architecture, we just read/write the |
| 17 | * memory location directly. |
| 18 | */ |
| 19 | /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 20 | * two accesses to memory, which may be undesirable for some devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * swap functions are sometimes needed to interface little-endian hardware |
| 25 | */ |
| 26 | static inline unsigned short _swapw(volatile unsigned short v) |
| 27 | { |
| 28 | return ((v << 8) | (v >> 8)); |
| 29 | } |
| 30 | |
| 31 | static inline unsigned int _swapl(volatile unsigned long v) |
| 32 | { |
| 33 | return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24)); |
| 34 | } |
| 35 | |
| 36 | #define readb(addr) \ |
| 37 | ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; }) |
| 38 | #define readw(addr) \ |
| 39 | ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; }) |
| 40 | #define readl(addr) \ |
| 41 | ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; }) |
| 42 | |
| 43 | #define readb_relaxed(addr) readb(addr) |
| 44 | #define readw_relaxed(addr) readw(addr) |
| 45 | #define readl_relaxed(addr) readl(addr) |
| 46 | |
| 47 | #define writeb(b,addr) (void)((*(volatile unsigned char *) (addr)) = (b)) |
| 48 | #define writew(b,addr) (void)((*(volatile unsigned short *) (addr)) = (b)) |
| 49 | #define writel(b,addr) (void)((*(volatile unsigned int *) (addr)) = (b)) |
| 50 | |
| 51 | #define __raw_readb readb |
| 52 | #define __raw_readw readw |
| 53 | #define __raw_readl readl |
| 54 | #define __raw_writeb writeb |
| 55 | #define __raw_writew writew |
| 56 | #define __raw_writel writel |
| 57 | |
| 58 | static inline void io_outsb(unsigned int addr, void *buf, int len) |
| 59 | { |
| 60 | volatile unsigned char *ap = (volatile unsigned char *) addr; |
| 61 | unsigned char *bp = (unsigned char *) buf; |
| 62 | while (len--) |
| 63 | *ap = *bp++; |
| 64 | } |
| 65 | |
| 66 | static inline void io_outsw(unsigned int addr, void *buf, int len) |
| 67 | { |
| 68 | volatile unsigned short *ap = (volatile unsigned short *) addr; |
| 69 | unsigned short *bp = (unsigned short *) buf; |
| 70 | while (len--) |
| 71 | *ap = _swapw(*bp++); |
| 72 | } |
| 73 | |
| 74 | static inline void io_outsl(unsigned int addr, void *buf, int len) |
| 75 | { |
| 76 | volatile unsigned int *ap = (volatile unsigned int *) addr; |
| 77 | unsigned int *bp = (unsigned int *) buf; |
| 78 | while (len--) |
| 79 | *ap = _swapl(*bp++); |
| 80 | } |
| 81 | |
| 82 | static inline void io_insb(unsigned int addr, void *buf, int len) |
| 83 | { |
| 84 | volatile unsigned char *ap = (volatile unsigned char *) addr; |
| 85 | unsigned char *bp = (unsigned char *) buf; |
| 86 | while (len--) |
| 87 | *bp++ = *ap; |
| 88 | } |
| 89 | |
| 90 | static inline void io_insw(unsigned int addr, void *buf, int len) |
| 91 | { |
| 92 | volatile unsigned short *ap = (volatile unsigned short *) addr; |
| 93 | unsigned short *bp = (unsigned short *) buf; |
| 94 | while (len--) |
| 95 | *bp++ = _swapw(*ap); |
| 96 | } |
| 97 | |
| 98 | static inline void io_insl(unsigned int addr, void *buf, int len) |
| 99 | { |
| 100 | volatile unsigned int *ap = (volatile unsigned int *) addr; |
| 101 | unsigned int *bp = (unsigned int *) buf; |
| 102 | while (len--) |
| 103 | *bp++ = _swapl(*ap); |
| 104 | } |
| 105 | |
| 106 | #define mmiowb() |
| 107 | |
| 108 | /* |
| 109 | * make the short names macros so specific devices |
| 110 | * can override them as required |
| 111 | */ |
| 112 | |
| 113 | #define memset_io(a,b,c) memset((void *)(a),(b),(c)) |
| 114 | #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c)) |
| 115 | #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c)) |
| 116 | |
| 117 | #define inb(addr) readb(addr) |
| 118 | #define inw(addr) readw(addr) |
| 119 | #define inl(addr) readl(addr) |
| 120 | #define outb(x,addr) ((void) writeb(x,addr)) |
| 121 | #define outw(x,addr) ((void) writew(x,addr)) |
| 122 | #define outl(x,addr) ((void) writel(x,addr)) |
| 123 | |
| 124 | #define inb_p(addr) inb(addr) |
| 125 | #define inw_p(addr) inw(addr) |
| 126 | #define inl_p(addr) inl(addr) |
| 127 | #define outb_p(x,addr) outb(x,addr) |
| 128 | #define outw_p(x,addr) outw(x,addr) |
| 129 | #define outl_p(x,addr) outl(x,addr) |
| 130 | |
| 131 | #define outsb(a,b,l) io_outsb(a,b,l) |
| 132 | #define outsw(a,b,l) io_outsw(a,b,l) |
| 133 | #define outsl(a,b,l) io_outsl(a,b,l) |
| 134 | |
| 135 | #define insb(a,b,l) io_insb(a,b,l) |
| 136 | #define insw(a,b,l) io_insw(a,b,l) |
| 137 | #define insl(a,b,l) io_insl(a,b,l) |
| 138 | |
Greg Ungerer | fe84c10 | 2009-08-11 16:33:51 +1000 | [diff] [blame] | 139 | #define IO_SPACE_LIMIT 0xffffffff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | |
| 142 | /* Values for nocacheflag and cmode */ |
| 143 | #define IOMAP_FULL_CACHING 0 |
| 144 | #define IOMAP_NOCACHE_SER 1 |
| 145 | #define IOMAP_NOCACHE_NONSER 2 |
| 146 | #define IOMAP_WRITETHROUGH 3 |
| 147 | |
Greg Ungerer | 593732b | 2011-03-28 22:32:05 +1000 | [diff] [blame] | 148 | static inline void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag) |
| 149 | { |
| 150 | return (void *) physaddr; |
| 151 | } |
Greg Ungerer | c514b8b | 2005-11-02 14:42:03 +1000 | [diff] [blame] | 152 | static inline void *ioremap(unsigned long physaddr, unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
| 154 | return __ioremap(physaddr, size, IOMAP_NOCACHE_SER); |
| 155 | } |
Greg Ungerer | c514b8b | 2005-11-02 14:42:03 +1000 | [diff] [blame] | 156 | static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | return __ioremap(physaddr, size, IOMAP_NOCACHE_SER); |
| 159 | } |
Greg Ungerer | c514b8b | 2005-11-02 14:42:03 +1000 | [diff] [blame] | 160 | static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
| 162 | return __ioremap(physaddr, size, IOMAP_WRITETHROUGH); |
| 163 | } |
Greg Ungerer | c514b8b | 2005-11-02 14:42:03 +1000 | [diff] [blame] | 164 | static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
| 166 | return __ioremap(physaddr, size, IOMAP_FULL_CACHING); |
| 167 | } |
| 168 | |
Greg Ungerer | 593732b | 2011-03-28 22:32:05 +1000 | [diff] [blame] | 169 | #define iounmap(addr) do { } while(0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /* |
| 172 | * Convert a physical pointer to a virtual kernel pointer for /dev/mem |
| 173 | * access |
| 174 | */ |
| 175 | #define xlate_dev_mem_ptr(p) __va(p) |
| 176 | |
| 177 | /* |
| 178 | * Convert a virtual cached pointer to an uncached pointer |
| 179 | */ |
| 180 | #define xlate_dev_kmem_ptr(p) p |
| 181 | |
| 182 | #endif /* __KERNEL__ */ |
| 183 | |
| 184 | #endif /* _M68KNOMMU_IO_H */ |