io.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * linux/include/asm-arm/arch-ixp2000/io.h
  3. *
  4. * Original Author: Naeem M Afzal <naeem.m.afzal@intel.com>
  5. * Maintainer: Deepak Saxena <dsaxena@plexity.net>
  6. *
  7. * Copyright (C) 2002 Intel Corp.
  8. * Copyrgiht (C) 2003-2004 MontaVista Software, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #ifndef __ASM_ARM_ARCH_IO_H
  15. #define __ASM_ARM_ARCH_IO_H
  16. #define IO_SPACE_LIMIT 0xffffffff
  17. #define __mem_pci(a) (a)
  18. #define ___io(p) ((void __iomem *)((p)+IXP2000_PCI_IO_VIRT_BASE))
  19. /*
  20. * The IXP2400 before revision B0 asserts byte lanes for PCI I/O
  21. * transactions the other way round (MEM transactions don't have this
  22. * issue), so we need to override the standard functions. B0 and later
  23. * have a bit that can be set to 1 to get the 'proper' behavior, but
  24. * since that isn't available on the A? revisions we just keep doing
  25. * things manually.
  26. */
  27. #define alignb(addr) (void __iomem *)((unsigned long)(addr) ^ 3)
  28. #define alignw(addr) (void __iomem *)((unsigned long)(addr) ^ 2)
  29. #define outb(v,p) __raw_writeb((v),alignb(___io(p)))
  30. #define outw(v,p) __raw_writew((v),alignw(___io(p)))
  31. #define outl(v,p) __raw_writel((v),___io(p))
  32. #define inb(p) ({ unsigned int __v = __raw_readb(alignb(___io(p))); __v; })
  33. #define inw(p) \
  34. ({ unsigned int __v = (__raw_readw(alignw(___io(p)))); __v; })
  35. #define inl(p) \
  36. ({ unsigned int __v = (__raw_readl(___io(p))); __v; })
  37. #define outsb(p,d,l) __raw_writesb(alignb(___io(p)),d,l)
  38. #define outsw(p,d,l) __raw_writesw(alignw(___io(p)),d,l)
  39. #define outsl(p,d,l) __raw_writesl(___io(p),d,l)
  40. #define insb(p,d,l) __raw_readsb(alignb(___io(p)),d,l)
  41. #define insw(p,d,l) __raw_readsw(alignw(___io(p)),d,l)
  42. #define insl(p,d,l) __raw_readsl(___io(p),d,l)
  43. #define __is_io_address(p) ((((unsigned long)(p)) & ~(IXP2000_PCI_IO_SIZE - 1)) == IXP2000_PCI_IO_VIRT_BASE)
  44. #define ioread8(p) \
  45. ({ \
  46. unsigned int __v; \
  47. \
  48. if (__is_io_address(p)) { \
  49. __v = __raw_readb(alignb(p)); \
  50. } else { \
  51. __v = __raw_readb(p); \
  52. } \
  53. \
  54. __v; \
  55. }) \
  56. #define ioread16(p) \
  57. ({ \
  58. unsigned int __v; \
  59. \
  60. if (__is_io_address(p)) { \
  61. __v = __raw_readw(alignw(p)); \
  62. } else { \
  63. __v = le16_to_cpu(__raw_readw(p)); \
  64. } \
  65. \
  66. __v; \
  67. })
  68. #define ioread32(p) \
  69. ({ \
  70. unsigned int __v; \
  71. \
  72. if (__is_io_address(p)) { \
  73. __v = __raw_readl(p); \
  74. } else { \
  75. __v = le32_to_cpu(__raw_readl(p)); \
  76. } \
  77. \
  78. __v; \
  79. })
  80. #define iowrite8(v,p) \
  81. ({ \
  82. if (__is_io_address(p)) { \
  83. __raw_writeb((v), alignb(p)); \
  84. } else { \
  85. __raw_writeb((v), p); \
  86. } \
  87. })
  88. #define iowrite16(v,p) \
  89. ({ \
  90. if (__is_io_address(p)) { \
  91. __raw_writew((v), alignw(p)); \
  92. } else { \
  93. __raw_writew(cpu_to_le16(v), p); \
  94. } \
  95. })
  96. #define iowrite32(v,p) \
  97. ({ \
  98. if (__is_io_address(p)) { \
  99. __raw_writel((v), p); \
  100. } else { \
  101. __raw_writel(cpu_to_le32(v), p); \
  102. } \
  103. })
  104. #define ioport_map(port, nr) ___io(port)
  105. #define ioport_unmap(addr)
  106. #ifdef CONFIG_ARCH_IXDP2X01
  107. /*
  108. * This is an ugly hack but the CS8900 on the 2x01's does not sit in any sort
  109. * of "I/O space" and is just direct mapped into a 32-bit-only addressable
  110. * bus. The address space for this bus is such that we can't really easily
  111. * make it contiguous to the PCI I/O address range, and it also does not
  112. * need swapping like PCI addresses do (IXDP2x01 is a BE platform).
  113. * B/C of this we can't use the standard in/out functions and need to
  114. * runtime check if the incoming address is a PCI address or for
  115. * the CS89x0.
  116. */
  117. #undef inw
  118. #undef outw
  119. #undef insw
  120. #undef outsw
  121. #include <asm/mach-types.h>
  122. static inline void insw(u32 ptr, void *buf, int length)
  123. {
  124. register volatile u32 *port = (volatile u32 *)ptr;
  125. /*
  126. * Is this cycle meant for the CS8900?
  127. */
  128. if ((machine_is_ixdp2401() || machine_is_ixdp2801()) &&
  129. (((u32)port >= (u32)IXDP2X01_CS8900_VIRT_BASE) &&
  130. ((u32)port <= (u32)IXDP2X01_CS8900_VIRT_END))) {
  131. u8 *buf8 = (u8*)buf;
  132. register u32 tmp32;
  133. do {
  134. tmp32 = *port;
  135. *buf8++ = (u8)tmp32;
  136. *buf8++ = (u8)(tmp32 >> 8);
  137. } while(--length);
  138. return;
  139. }
  140. __raw_readsw(alignw(___io(ptr)),buf,length);
  141. }
  142. static inline void outsw(u32 ptr, void *buf, int length)
  143. {
  144. register volatile u32 *port = (volatile u32 *)ptr;
  145. /*
  146. * Is this cycle meant for the CS8900?
  147. */
  148. if ((machine_is_ixdp2401() || machine_is_ixdp2801()) &&
  149. (((u32)port >= (u32)IXDP2X01_CS8900_VIRT_BASE) &&
  150. ((u32)port <= (u32)IXDP2X01_CS8900_VIRT_END))) {
  151. register u32 tmp32;
  152. u8 *buf8 = (u8*)buf;
  153. do {
  154. tmp32 = *buf8++;
  155. tmp32 |= (*buf8++) << 8;
  156. *port = tmp32;
  157. } while(--length);
  158. return;
  159. }
  160. __raw_writesw(alignw(___io(ptr)),buf,length);
  161. }
  162. static inline u16 inw(u32 ptr)
  163. {
  164. register volatile u32 *port = (volatile u32 *)ptr;
  165. /*
  166. * Is this cycle meant for the CS8900?
  167. */
  168. if ((machine_is_ixdp2401() || machine_is_ixdp2801()) &&
  169. (((u32)port >= (u32)IXDP2X01_CS8900_VIRT_BASE) &&
  170. ((u32)port <= (u32)IXDP2X01_CS8900_VIRT_END))) {
  171. return (u16)(*port);
  172. }
  173. return __raw_readw(alignw(___io(ptr)));
  174. }
  175. static inline void outw(u16 value, u32 ptr)
  176. {
  177. register volatile u32 *port = (volatile u32 *)ptr;
  178. if ((machine_is_ixdp2401() || machine_is_ixdp2801()) &&
  179. (((u32)port >= (u32)IXDP2X01_CS8900_VIRT_BASE) &&
  180. ((u32)port <= (u32)IXDP2X01_CS8900_VIRT_END))) {
  181. *port = value;
  182. return;
  183. }
  184. __raw_writew((value),alignw(___io(ptr)));
  185. }
  186. #endif /* IXDP2x01 */
  187. #endif