Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-ixp4xx/include/mach/io.h |
| 3 | * |
| 4 | * Author: Deepak Saxena <dsaxena@plexity.net> |
| 5 | * |
| 6 | * Copyright (C) 2002-2005 MontaVista Software, Inc. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __ASM_ARM_ARCH_IO_H |
| 14 | #define __ASM_ARM_ARCH_IO_H |
| 15 | |
| 16 | #include <linux/bitops.h> |
| 17 | |
| 18 | #include <mach/hardware.h> |
| 19 | |
Mikael Pettersson | dee2b90 | 2009-08-09 21:21:57 +0200 | [diff] [blame] | 20 | #define IO_SPACE_LIMIT 0x0000ffff |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 21 | |
| 22 | extern int (*ixp4xx_pci_read)(u32 addr, u32 cmd, u32* data); |
| 23 | extern int ixp4xx_pci_write(u32 addr, u32 cmd, u32 data); |
| 24 | |
| 25 | |
| 26 | /* |
| 27 | * IXP4xx provides two methods of accessing PCI memory space: |
| 28 | * |
| 29 | * 1) A direct mapped window from 0x48000000 to 0x4bffffff (64MB). |
| 30 | * To access PCI via this space, we simply ioremap() the BAR |
| 31 | * into the kernel and we can use the standard read[bwl]/write[bwl] |
| 32 | * macros. This is the preffered method due to speed but it |
| 33 | * limits the system to just 64MB of PCI memory. This can be |
| 34 | * problamatic if using video cards and other memory-heavy |
| 35 | * targets. |
| 36 | * |
| 37 | * 2) If > 64MB of memory space is required, the IXP4xx can be configured |
| 38 | * to use indirect registers to access PCI (as we do below for I/O |
| 39 | * transactions). This allows for up to 128MB (0x48000000 to 0x4fffffff) |
| 40 | * of memory on the bus. The disadvantage of this is that every |
| 41 | * PCI access requires three local register accesses plus a spinlock, |
| 42 | * but in some cases the performance hit is acceptable. In addition, |
| 43 | * you cannot mmap() PCI devices in this case. |
| 44 | * |
| 45 | */ |
| 46 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 47 | |
| 48 | #define __mem_pci(a) (a) |
| 49 | |
| 50 | #else |
| 51 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 52 | /* |
| 53 | * In the case of using indirect PCI, we simply return the actual PCI |
| 54 | * address and our read/write implementation use that to drive the |
| 55 | * access registers. If something outside of PCI is ioremap'd, we |
| 56 | * fallback to the default. |
| 57 | */ |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 58 | |
| 59 | static inline int is_pci_memory(u32 addr) |
| 60 | { |
| 61 | return (addr >= PCIBIOS_MIN_MEM) && (addr <= 0x4FFFFFFF); |
| 62 | } |
| 63 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 64 | static inline void __iomem * __indirect_ioremap(unsigned long addr, size_t size, |
| 65 | unsigned int mtype) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 66 | { |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 67 | if (!is_pci_memory(addr)) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 68 | return __arm_ioremap(addr, size, mtype); |
| 69 | |
| 70 | return (void __iomem *)addr; |
| 71 | } |
| 72 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 73 | static inline void __indirect_iounmap(void __iomem *addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 74 | { |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 75 | if (!is_pci_memory((__force u32)addr)) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 76 | __iounmap(addr); |
| 77 | } |
| 78 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 79 | #define __arch_ioremap(a, s, f) __indirect_ioremap(a, s, f) |
| 80 | #define __arch_iounmap(a) __indirect_iounmap(a) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 81 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 82 | #define writeb(v, p) __indirect_writeb(v, p) |
| 83 | #define writew(v, p) __indirect_writew(v, p) |
| 84 | #define writel(v, p) __indirect_writel(v, p) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 85 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 86 | #define writesb(p, v, l) __indirect_writesb(p, v, l) |
| 87 | #define writesw(p, v, l) __indirect_writesw(p, v, l) |
| 88 | #define writesl(p, v, l) __indirect_writesl(p, v, l) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 89 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 90 | #define readb(p) __indirect_readb(p) |
| 91 | #define readw(p) __indirect_readw(p) |
| 92 | #define readl(p) __indirect_readl(p) |
| 93 | |
| 94 | #define readsb(p, v, l) __indirect_readsb(p, v, l) |
| 95 | #define readsw(p, v, l) __indirect_readsw(p, v, l) |
| 96 | #define readsl(p, v, l) __indirect_readsl(p, v, l) |
| 97 | |
| 98 | static inline void __indirect_writeb(u8 value, volatile void __iomem *p) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 99 | { |
| 100 | u32 addr = (u32)p; |
| 101 | u32 n, byte_enables, data; |
| 102 | |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 103 | if (!is_pci_memory(addr)) { |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 104 | __raw_writeb(value, addr); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | n = addr % 4; |
| 109 | byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL; |
| 110 | data = value << (8*n); |
| 111 | ixp4xx_pci_write(addr, byte_enables | NP_CMD_MEMWRITE, data); |
| 112 | } |
| 113 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 114 | static inline void __indirect_writesb(volatile void __iomem *bus_addr, |
| 115 | const u8 *vaddr, int count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 116 | { |
| 117 | while (count--) |
| 118 | writeb(*vaddr++, bus_addr); |
| 119 | } |
| 120 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 121 | static inline void __indirect_writew(u16 value, volatile void __iomem *p) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 122 | { |
| 123 | u32 addr = (u32)p; |
| 124 | u32 n, byte_enables, data; |
| 125 | |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 126 | if (!is_pci_memory(addr)) { |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 127 | __raw_writew(value, addr); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | n = addr % 4; |
| 132 | byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL; |
| 133 | data = value << (8*n); |
| 134 | ixp4xx_pci_write(addr, byte_enables | NP_CMD_MEMWRITE, data); |
| 135 | } |
| 136 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 137 | static inline void __indirect_writesw(volatile void __iomem *bus_addr, |
| 138 | const u16 *vaddr, int count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 139 | { |
| 140 | while (count--) |
| 141 | writew(*vaddr++, bus_addr); |
| 142 | } |
| 143 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 144 | static inline void __indirect_writel(u32 value, volatile void __iomem *p) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 145 | { |
| 146 | u32 addr = (__force u32)p; |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 147 | |
| 148 | if (!is_pci_memory(addr)) { |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 149 | __raw_writel(value, p); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | ixp4xx_pci_write(addr, NP_CMD_MEMWRITE, value); |
| 154 | } |
| 155 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 156 | static inline void __indirect_writesl(volatile void __iomem *bus_addr, |
| 157 | const u32 *vaddr, int count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 158 | { |
| 159 | while (count--) |
| 160 | writel(*vaddr++, bus_addr); |
| 161 | } |
| 162 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 163 | static inline unsigned char __indirect_readb(const volatile void __iomem *p) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 164 | { |
| 165 | u32 addr = (u32)p; |
| 166 | u32 n, byte_enables, data; |
| 167 | |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 168 | if (!is_pci_memory(addr)) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 169 | return __raw_readb(addr); |
| 170 | |
| 171 | n = addr % 4; |
| 172 | byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL; |
| 173 | if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_MEMREAD, &data)) |
| 174 | return 0xff; |
| 175 | |
| 176 | return data >> (8*n); |
| 177 | } |
| 178 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 179 | static inline void __indirect_readsb(const volatile void __iomem *bus_addr, |
| 180 | u8 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 181 | { |
| 182 | while (count--) |
| 183 | *vaddr++ = readb(bus_addr); |
| 184 | } |
| 185 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 186 | static inline unsigned short __indirect_readw(const volatile void __iomem *p) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 187 | { |
| 188 | u32 addr = (u32)p; |
| 189 | u32 n, byte_enables, data; |
| 190 | |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 191 | if (!is_pci_memory(addr)) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 192 | return __raw_readw(addr); |
| 193 | |
| 194 | n = addr % 4; |
| 195 | byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL; |
| 196 | if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_MEMREAD, &data)) |
| 197 | return 0xffff; |
| 198 | |
| 199 | return data>>(8*n); |
| 200 | } |
| 201 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 202 | static inline void __indirect_readsw(const volatile void __iomem *bus_addr, |
| 203 | u16 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 204 | { |
| 205 | while (count--) |
| 206 | *vaddr++ = readw(bus_addr); |
| 207 | } |
| 208 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 209 | static inline unsigned long __indirect_readl(const volatile void __iomem *p) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 210 | { |
| 211 | u32 addr = (__force u32)p; |
| 212 | u32 data; |
| 213 | |
Krzysztof Hałasa | cba3622 | 2009-11-15 01:25:06 +0100 | [diff] [blame^] | 214 | if (!is_pci_memory(addr)) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 215 | return __raw_readl(p); |
| 216 | |
| 217 | if (ixp4xx_pci_read(addr, NP_CMD_MEMREAD, &data)) |
| 218 | return 0xffffffff; |
| 219 | |
| 220 | return data; |
| 221 | } |
| 222 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 223 | static inline void __indirect_readsl(const volatile void __iomem *bus_addr, |
| 224 | u32 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 225 | { |
| 226 | while (count--) |
| 227 | *vaddr++ = readl(bus_addr); |
| 228 | } |
| 229 | |
| 230 | |
| 231 | /* |
| 232 | * We can use the built-in functions b/c they end up calling writeb/readb |
| 233 | */ |
| 234 | #define memset_io(c,v,l) _memset_io((c),(v),(l)) |
| 235 | #define memcpy_fromio(a,c,l) _memcpy_fromio((a),(c),(l)) |
| 236 | #define memcpy_toio(c,a,l) _memcpy_toio((c),(a),(l)) |
| 237 | |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 238 | #endif /* CONFIG_IXP4XX_INDIRECT_PCI */ |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 239 | |
| 240 | #ifndef CONFIG_PCI |
| 241 | |
Russell King | 0560cf5 | 2008-11-30 11:45:54 +0000 | [diff] [blame] | 242 | #define __io(v) __typesafe_io(v) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 243 | |
| 244 | #else |
| 245 | |
| 246 | /* |
| 247 | * IXP4xx does not have a transparent cpu -> PCI I/O translation |
| 248 | * window. Instead, it has a set of registers that must be tweaked |
| 249 | * with the proper byte lanes, command types, and address for the |
| 250 | * transaction. This means that we need to override the default |
| 251 | * I/O functions. |
| 252 | */ |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 253 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 254 | static inline void outb(u8 value, u32 addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 255 | { |
| 256 | u32 n, byte_enables, data; |
| 257 | n = addr % 4; |
| 258 | byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL; |
| 259 | data = value << (8*n); |
| 260 | ixp4xx_pci_write(addr, byte_enables | NP_CMD_IOWRITE, data); |
| 261 | } |
| 262 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 263 | static inline void outsb(u32 io_addr, const u8 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 264 | { |
| 265 | while (count--) |
| 266 | outb(*vaddr++, io_addr); |
| 267 | } |
| 268 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 269 | static inline void outw(u16 value, u32 addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 270 | { |
| 271 | u32 n, byte_enables, data; |
| 272 | n = addr % 4; |
| 273 | byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL; |
| 274 | data = value << (8*n); |
| 275 | ixp4xx_pci_write(addr, byte_enables | NP_CMD_IOWRITE, data); |
| 276 | } |
| 277 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 278 | static inline void outsw(u32 io_addr, const u16 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 279 | { |
| 280 | while (count--) |
| 281 | outw(cpu_to_le16(*vaddr++), io_addr); |
| 282 | } |
| 283 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 284 | static inline void outl(u32 value, u32 addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 285 | { |
| 286 | ixp4xx_pci_write(addr, NP_CMD_IOWRITE, value); |
| 287 | } |
| 288 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 289 | static inline void outsl(u32 io_addr, const u32 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 290 | { |
| 291 | while (count--) |
Krzysztof Hałasa | 9f2c949 | 2009-11-11 00:21:48 +0100 | [diff] [blame] | 292 | outl(cpu_to_le32(*vaddr++), io_addr); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 293 | } |
| 294 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 295 | static inline u8 inb(u32 addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 296 | { |
| 297 | u32 n, byte_enables, data; |
| 298 | n = addr % 4; |
| 299 | byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL; |
| 300 | if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_IOREAD, &data)) |
| 301 | return 0xff; |
| 302 | |
| 303 | return data >> (8*n); |
| 304 | } |
| 305 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 306 | static inline void insb(u32 io_addr, u8 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 307 | { |
| 308 | while (count--) |
| 309 | *vaddr++ = inb(io_addr); |
| 310 | } |
| 311 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 312 | static inline u16 inw(u32 addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 313 | { |
| 314 | u32 n, byte_enables, data; |
| 315 | n = addr % 4; |
| 316 | byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL; |
| 317 | if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_IOREAD, &data)) |
| 318 | return 0xffff; |
| 319 | |
| 320 | return data>>(8*n); |
| 321 | } |
| 322 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 323 | static inline void insw(u32 io_addr, u16 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 324 | { |
| 325 | while (count--) |
| 326 | *vaddr++ = le16_to_cpu(inw(io_addr)); |
| 327 | } |
| 328 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 329 | static inline u32 inl(u32 addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 330 | { |
| 331 | u32 data; |
| 332 | if (ixp4xx_pci_read(addr, NP_CMD_IOREAD, &data)) |
| 333 | return 0xffffffff; |
| 334 | |
| 335 | return data; |
| 336 | } |
| 337 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 338 | static inline void insl(u32 io_addr, u32 *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 339 | { |
| 340 | while (count--) |
Krzysztof Hałasa | 9f2c949 | 2009-11-11 00:21:48 +0100 | [diff] [blame] | 341 | *vaddr++ = le32_to_cpu(inl(io_addr)); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | #define PIO_OFFSET 0x10000UL |
| 345 | #define PIO_MASK 0x0ffffUL |
| 346 | |
| 347 | #define __is_io_address(p) (((unsigned long)p >= PIO_OFFSET) && \ |
| 348 | ((unsigned long)p <= (PIO_MASK + PIO_OFFSET))) |
Krzysztof Hałasa | 9f2c949 | 2009-11-11 00:21:48 +0100 | [diff] [blame] | 349 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 350 | #define ioread8(p) ioread8(p) |
| 351 | static inline unsigned int ioread8(const void __iomem *addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 352 | { |
| 353 | unsigned long port = (unsigned long __force)addr; |
| 354 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 355 | return (unsigned int)inb(port & PIO_MASK); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 356 | else |
| 357 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 358 | return (unsigned int)__raw_readb(port); |
| 359 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 360 | return (unsigned int)__indirect_readb(addr); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 361 | #endif |
| 362 | } |
| 363 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 364 | #define ioread8_rep(p, v, c) ioread8_rep(p, v, c) |
| 365 | static inline void ioread8_rep(const void __iomem *addr, void *vaddr, u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 366 | { |
| 367 | unsigned long port = (unsigned long __force)addr; |
| 368 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 369 | insb(port & PIO_MASK, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 370 | else |
| 371 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 372 | __raw_readsb(addr, vaddr, count); |
| 373 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 374 | __indirect_readsb(addr, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 375 | #endif |
| 376 | } |
| 377 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 378 | #define ioread16(p) ioread16(p) |
| 379 | static inline unsigned int ioread16(const void __iomem *addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 380 | { |
| 381 | unsigned long port = (unsigned long __force)addr; |
| 382 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 383 | return (unsigned int)inw(port & PIO_MASK); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 384 | else |
| 385 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 386 | return le16_to_cpu(__raw_readw((u32)port)); |
| 387 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 388 | return (unsigned int)__indirect_readw(addr); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 389 | #endif |
| 390 | } |
| 391 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 392 | #define ioread16_rep(p, v, c) ioread16_rep(p, v, c) |
| 393 | static inline void ioread16_rep(const void __iomem *addr, void *vaddr, |
| 394 | u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 395 | { |
| 396 | unsigned long port = (unsigned long __force)addr; |
| 397 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 398 | insw(port & PIO_MASK, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 399 | else |
| 400 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 401 | __raw_readsw(addr, vaddr, count); |
| 402 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 403 | __indirect_readsw(addr, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 404 | #endif |
| 405 | } |
| 406 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 407 | #define ioread32(p) ioread32(p) |
| 408 | static inline unsigned int ioread32(const void __iomem *addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 409 | { |
| 410 | unsigned long port = (unsigned long __force)addr; |
| 411 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 412 | return (unsigned int)inl(port & PIO_MASK); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 413 | else { |
| 414 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 415 | return le32_to_cpu((__force __le32)__raw_readl(addr)); |
| 416 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 417 | return (unsigned int)__indirect_readl(addr); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 418 | #endif |
| 419 | } |
| 420 | } |
| 421 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 422 | #define ioread32_rep(p, v, c) ioread32_rep(p, v, c) |
| 423 | static inline void ioread32_rep(const void __iomem *addr, void *vaddr, |
| 424 | u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 425 | { |
| 426 | unsigned long port = (unsigned long __force)addr; |
| 427 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 428 | insl(port & PIO_MASK, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 429 | else |
| 430 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 431 | __raw_readsl(addr, vaddr, count); |
| 432 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 433 | __indirect_readsl(addr, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 434 | #endif |
| 435 | } |
| 436 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 437 | #define iowrite8(v, p) iowrite8(v, p) |
| 438 | static inline void iowrite8(u8 value, void __iomem *addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 439 | { |
| 440 | unsigned long port = (unsigned long __force)addr; |
| 441 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 442 | outb(value, port & PIO_MASK); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 443 | else |
| 444 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 445 | __raw_writeb(value, port); |
| 446 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 447 | __indirect_writeb(value, addr); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 448 | #endif |
| 449 | } |
| 450 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 451 | #define iowrite8_rep(p, v, c) iowrite8_rep(p, v, c) |
| 452 | static inline void iowrite8_rep(void __iomem *addr, const void *vaddr, |
| 453 | u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 454 | { |
| 455 | unsigned long port = (unsigned long __force)addr; |
| 456 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 457 | outsb(port & PIO_MASK, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 458 | else |
| 459 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 460 | __raw_writesb(addr, vaddr, count); |
| 461 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 462 | __indirect_writesb(addr, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 463 | #endif |
| 464 | } |
| 465 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 466 | #define iowrite16(v, p) iowrite16(v, p) |
| 467 | static inline void iowrite16(u16 value, void __iomem *addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 468 | { |
| 469 | unsigned long port = (unsigned long __force)addr; |
| 470 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 471 | outw(value, port & PIO_MASK); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 472 | else |
| 473 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 474 | __raw_writew(cpu_to_le16(value), addr); |
| 475 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 476 | __indirect_writew(value, addr); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 477 | #endif |
| 478 | } |
| 479 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 480 | #define iowrite16_rep(p, v, c) iowrite16_rep(p, v, c) |
| 481 | static inline void iowrite16_rep(void __iomem *addr, const void *vaddr, |
| 482 | u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 483 | { |
| 484 | unsigned long port = (unsigned long __force)addr; |
| 485 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 486 | outsw(port & PIO_MASK, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 487 | else |
| 488 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 489 | __raw_writesw(addr, vaddr, count); |
| 490 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 491 | __indirect_writesw(addr, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 492 | #endif |
| 493 | } |
| 494 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 495 | #define iowrite32(v, p) iowrite32(v, p) |
| 496 | static inline void iowrite32(u32 value, void __iomem *addr) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 497 | { |
| 498 | unsigned long port = (unsigned long __force)addr; |
| 499 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 500 | outl(value, port & PIO_MASK); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 501 | else |
| 502 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 503 | __raw_writel((u32 __force)cpu_to_le32(value), addr); |
| 504 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 505 | __indirect_writel(value, addr); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 506 | #endif |
| 507 | } |
| 508 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 509 | #define iowrite32_rep(p, v, c) iowrite32_rep(p, v, c) |
| 510 | static inline void iowrite32_rep(void __iomem *addr, const void *vaddr, |
| 511 | u32 count) |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 512 | { |
| 513 | unsigned long port = (unsigned long __force)addr; |
| 514 | if (__is_io_address(port)) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 515 | outsl(port & PIO_MASK, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 516 | else |
| 517 | #ifndef CONFIG_IXP4XX_INDIRECT_PCI |
| 518 | __raw_writesl(addr, vaddr, count); |
| 519 | #else |
Krzysztof Hałasa | 28f85cd | 2009-11-14 19:44:44 +0100 | [diff] [blame] | 520 | __indirect_writesl(addr, vaddr, count); |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 521 | #endif |
| 522 | } |
| 523 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 524 | #define ioport_map(port, nr) ((void __iomem*)(port + PIO_OFFSET)) |
| 525 | #define ioport_unmap(addr) |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 526 | #endif /* CONFIG_PCI */ |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 527 | |
Krzysztof Hałasa | 58e570d | 2009-11-14 22:55:42 +0100 | [diff] [blame] | 528 | #endif /* __ASM_ARM_ARCH_IO_H */ |