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