Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[MIPS] Make I/O helpers more customizable 1. Move ioswab*() and __mem_ioswab*() to mangle-port.h. This gets rid of CONFIG_SGI_IP22 from include/asm-mips/io.h. 2. Pass a virtual address to *ioswab*(). Then we can provide mach-specific *ioswab*() and can do every evil thing based on its argument. It could be useful on machines which have regions with different endian conversion scheme. 3. Call __swizzle_addr*() _after_ adding mips_io_port_base. This unifies the meaning of the argument of __swizzle_addr*() (always virtual address). Then mach-specific __swizzle_addr*() can do every evil thing based on the argument. Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Atsushi Nemoto and committed by
Ralf Baechle
a8433137 c1449c8f

+66 -57
+12 -57
include/asm-mips/io.h
··· 40 40 * hardware. An example use would be for flash memory that's used for 41 41 * execute in place. 42 42 */ 43 - # define __raw_ioswabb(x) (x) 44 - # define __raw_ioswabw(x) (x) 45 - # define __raw_ioswabl(x) (x) 46 - # define __raw_ioswabq(x) (x) 47 - # define ____raw_ioswabq(x) (x) 43 + # define __raw_ioswabb(a,x) (x) 44 + # define __raw_ioswabw(a,x) (x) 45 + # define __raw_ioswabl(a,x) (x) 46 + # define __raw_ioswabq(a,x) (x) 47 + # define ____raw_ioswabq(a,x) (x) 48 48 49 - /* 50 - * Sane hardware offers swapping of PCI/ISA I/O space accesses in hardware; 51 - * less sane hardware forces software to fiddle with this... 52 - * 53 - * Regardless, if the host bus endianness mismatches that of PCI/ISA, then 54 - * you can't have the numerical value of data and byte addresses within 55 - * multibyte quantities both preserved at the same time. Hence two 56 - * variations of functions: non-prefixed ones that preserve the value 57 - * and prefixed ones that preserve byte addresses. The latters are 58 - * typically used for moving raw data between a peripheral and memory (cf. 59 - * string I/O functions), hence the "__mem_" prefix. 60 - */ 61 - #if defined(CONFIG_SWAP_IO_SPACE) 62 - 63 - # define ioswabb(x) (x) 64 - # define __mem_ioswabb(x) (x) 65 - # ifdef CONFIG_SGI_IP22 66 - /* 67 - * IP22 seems braindead enough to swap 16bits values in hardware, but 68 - * not 32bits. Go figure... Can't tell without documentation. 69 - */ 70 - # define ioswabw(x) (x) 71 - # define __mem_ioswabw(x) le16_to_cpu(x) 72 - # else 73 - # define ioswabw(x) le16_to_cpu(x) 74 - # define __mem_ioswabw(x) (x) 75 - # endif 76 - # define ioswabl(x) le32_to_cpu(x) 77 - # define __mem_ioswabl(x) (x) 78 - # define ioswabq(x) le64_to_cpu(x) 79 - # define __mem_ioswabq(x) (x) 80 - 81 - #else 82 - 83 - # define ioswabb(x) (x) 84 - # define __mem_ioswabb(x) (x) 85 - # define ioswabw(x) (x) 86 - # define __mem_ioswabw(x) cpu_to_le16(x) 87 - # define ioswabl(x) (x) 88 - # define __mem_ioswabl(x) cpu_to_le32(x) 89 - # define ioswabq(x) (x) 90 - # define __mem_ioswabq(x) cpu_to_le32(x) 91 - 92 - #endif 49 + /* ioswab[bwlq], __mem_ioswab[bwlq] are defined in mangle-port.h */ 93 50 94 51 #define IO_SPACE_LIMIT 0xffff 95 52 ··· 303 346 \ 304 347 __mem = (void *)__swizzle_addr_##bwlq((unsigned long)(mem)); \ 305 348 \ 306 - __val = pfx##ioswab##bwlq(val); \ 349 + __val = pfx##ioswab##bwlq(__mem, val); \ 307 350 \ 308 351 if (sizeof(type) != sizeof(u64) || sizeof(u64) == sizeof(long)) \ 309 352 *__mem = __val; \ ··· 358 401 BUG(); \ 359 402 } \ 360 403 \ 361 - return pfx##ioswab##bwlq(__val); \ 404 + return pfx##ioswab##bwlq(__mem, __val); \ 362 405 } 363 406 364 407 #define __BUILD_IOPORT_SINGLE(pfx, bwlq, type, p, slow) \ ··· 368 411 volatile type *__addr; \ 369 412 type __val; \ 370 413 \ 371 - port = __swizzle_addr_##bwlq(port); \ 372 - __addr = (void *)(mips_io_port_base + port); \ 414 + __addr = (void *)__swizzle_addr_##bwlq(mips_io_port_base + port); \ 373 415 \ 374 - __val = pfx##ioswab##bwlq(val); \ 416 + __val = pfx##ioswab##bwlq(__addr, val); \ 375 417 \ 376 418 /* Really, we want this to be atomic */ \ 377 419 BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long)); \ ··· 384 428 volatile type *__addr; \ 385 429 type __val; \ 386 430 \ 387 - port = __swizzle_addr_##bwlq(port); \ 388 - __addr = (void *)(mips_io_port_base + port); \ 431 + __addr = (void *)__swizzle_addr_##bwlq(mips_io_port_base + port); \ 389 432 \ 390 433 BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long)); \ 391 434 \ 392 435 __val = *__addr; \ 393 436 slow; \ 394 437 \ 395 - return pfx##ioswab##bwlq(__val); \ 438 + return pfx##ioswab##bwlq(__addr, __val); \ 396 439 } 397 440 398 441 #define __BUILD_MEMORY_PFX(bus, bwlq, type) \
+36
include/asm-mips/mach-generic/mangle-port.h
··· 13 13 #define __swizzle_addr_l(port) (port) 14 14 #define __swizzle_addr_q(port) (port) 15 15 16 + /* 17 + * Sane hardware offers swapping of PCI/ISA I/O space accesses in hardware; 18 + * less sane hardware forces software to fiddle with this... 19 + * 20 + * Regardless, if the host bus endianness mismatches that of PCI/ISA, then 21 + * you can't have the numerical value of data and byte addresses within 22 + * multibyte quantities both preserved at the same time. Hence two 23 + * variations of functions: non-prefixed ones that preserve the value 24 + * and prefixed ones that preserve byte addresses. The latters are 25 + * typically used for moving raw data between a peripheral and memory (cf. 26 + * string I/O functions), hence the "__mem_" prefix. 27 + */ 28 + #if defined(CONFIG_SWAP_IO_SPACE) 29 + 30 + # define ioswabb(a,x) (x) 31 + # define __mem_ioswabb(a,x) (x) 32 + # define ioswabw(a,x) le16_to_cpu(x) 33 + # define __mem_ioswabw(a,x) (x) 34 + # define ioswabl(a,x) le32_to_cpu(x) 35 + # define __mem_ioswabl(a,x) (x) 36 + # define ioswabq(a,x) le64_to_cpu(x) 37 + # define __mem_ioswabq(a,x) (x) 38 + 39 + #else 40 + 41 + # define ioswabb(a,x) (x) 42 + # define __mem_ioswabb(a,x) (x) 43 + # define ioswabw(a,x) (x) 44 + # define __mem_ioswabw(a,x) cpu_to_le16(x) 45 + # define ioswabl(a,x) (x) 46 + # define __mem_ioswabl(a,x) cpu_to_le32(x) 47 + # define ioswabq(a,x) (x) 48 + # define __mem_ioswabq(a,x) cpu_to_le32(x) 49 + 50 + #endif 51 + 16 52 #endif /* __ASM_MACH_GENERIC_MANGLE_PORT_H */
+9
include/asm-mips/mach-ip27/mangle-port.h
··· 13 13 #define __swizzle_addr_l(port) (port) 14 14 #define __swizzle_addr_q(port) (port) 15 15 16 + # define ioswabb(a,x) (x) 17 + # define __mem_ioswabb(a,x) (x) 18 + # define ioswabw(a,x) (x) 19 + # define __mem_ioswabw(a,x) cpu_to_le16(x) 20 + # define ioswabl(a,x) (x) 21 + # define __mem_ioswabl(a,x) cpu_to_le32(x) 22 + # define ioswabq(a,x) (x) 23 + # define __mem_ioswabq(a,x) cpu_to_le32(x) 24 + 16 25 #endif /* __ASM_MACH_IP27_MANGLE_PORT_H */
+9
include/asm-mips/mach-ip32/mangle-port.h
··· 14 14 #define __swizzle_addr_l(port) (port) 15 15 #define __swizzle_addr_q(port) (port) 16 16 17 + # define ioswabb(a,x) (x) 18 + # define __mem_ioswabb(a,x) (x) 19 + # define ioswabw(a,x) (x) 20 + # define __mem_ioswabw(a,x) cpu_to_le16(x) 21 + # define ioswabl(a,x) (x) 22 + # define __mem_ioswabl(a,x) cpu_to_le32(x) 23 + # define ioswabq(a,x) (x) 24 + # define __mem_ioswabq(a,x) cpu_to_le32(x) 25 + 17 26 #endif /* __ASM_MACH_IP32_MANGLE_PORT_H */