io.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. /*
  19. * The A? revisions of the IXP2000s assert byte lanes for PCI I/O
  20. * transactions the other way round (MEM transactions don't have this
  21. * issue), so if we want to support those models, we need to override
  22. * the standard I/O functions.
  23. *
  24. * B0 and later have a bit that can be set to 1 to get the proper
  25. * behavior for I/O transactions, which then allows us to use the
  26. * standard I/O functions. This is what we do if the user does not
  27. * explicitly ask for support for pre-B0.
  28. */
  29. #ifdef CONFIG_IXP2000_SUPPORT_BROKEN_PCI_IO
  30. #define ___io(p) ((void __iomem *)((p)+IXP2000_PCI_IO_VIRT_BASE))
  31. #define alignb(addr) (void __iomem *)((unsigned long)(addr) ^ 3)
  32. #define alignw(addr) (void __iomem *)((unsigned long)(addr) ^ 2)
  33. #define outb(v,p) __raw_writeb((v),alignb(___io(p)))
  34. #define outw(v,p) __raw_writew((v),alignw(___io(p)))
  35. #define outl(v,p) __raw_writel((v),___io(p))
  36. #define inb(p) ({ unsigned int __v = __raw_readb(alignb(___io(p))); __v; })
  37. #define inw(p) \
  38. ({ unsigned int __v = (__raw_readw(alignw(___io(p)))); __v; })
  39. #define inl(p) \
  40. ({ unsigned int __v = (__raw_readl(___io(p))); __v; })
  41. #define outsb(p,d,l) __raw_writesb(alignb(___io(p)),d,l)
  42. #define outsw(p,d,l) __raw_writesw(alignw(___io(p)),d,l)
  43. #define outsl(p,d,l) __raw_writesl(___io(p),d,l)
  44. #define insb(p,d,l) __raw_readsb(alignb(___io(p)),d,l)
  45. #define insw(p,d,l) __raw_readsw(alignw(___io(p)),d,l)
  46. #define insl(p,d,l) __raw_readsl(___io(p),d,l)
  47. #define __is_io_address(p) ((((unsigned long)(p)) & ~(IXP2000_PCI_IO_SIZE - 1)) == IXP2000_PCI_IO_VIRT_BASE)
  48. #define ioread8(p) \
  49. ({ \
  50. unsigned int __v; \
  51. \
  52. if (__is_io_address(p)) { \
  53. __v = __raw_readb(alignb(p)); \
  54. } else { \
  55. __v = __raw_readb(p); \
  56. } \
  57. \
  58. __v; \
  59. }) \
  60. #define ioread16(p) \
  61. ({ \
  62. unsigned int __v; \
  63. \
  64. if (__is_io_address(p)) { \
  65. __v = __raw_readw(alignw(p)); \
  66. } else { \
  67. __v = le16_to_cpu(__raw_readw(p)); \
  68. } \
  69. \
  70. __v; \
  71. })
  72. #define ioread32(p) \
  73. ({ \
  74. unsigned int __v; \
  75. \
  76. if (__is_io_address(p)) { \
  77. __v = __raw_readl(p); \
  78. } else { \
  79. __v = le32_to_cpu(__raw_readl(p)); \
  80. } \
  81. \
  82. __v; \
  83. })
  84. #define iowrite8(v,p) \
  85. ({ \
  86. if (__is_io_address(p)) { \
  87. __raw_writeb((v), alignb(p)); \
  88. } else { \
  89. __raw_writeb((v), p); \
  90. } \
  91. })
  92. #define iowrite16(v,p) \
  93. ({ \
  94. if (__is_io_address(p)) { \
  95. __raw_writew((v), alignw(p)); \
  96. } else { \
  97. __raw_writew(cpu_to_le16(v), p); \
  98. } \
  99. })
  100. #define iowrite32(v,p) \
  101. ({ \
  102. if (__is_io_address(p)) { \
  103. __raw_writel((v), p); \
  104. } else { \
  105. __raw_writel(cpu_to_le32(v), p); \
  106. } \
  107. })
  108. #define ioport_map(port, nr) ___io(port)
  109. #define ioport_unmap(addr)
  110. #else
  111. #define __io(p) ((void __iomem *)((p)+IXP2000_PCI_IO_VIRT_BASE))
  112. #endif
  113. #ifdef CONFIG_ARCH_IXDP2X01
  114. /*
  115. * This is an ugly hack but the CS8900 on the 2x01's does not sit in any sort
  116. * of "I/O space" and is just direct mapped into a 32-bit-only addressable
  117. * bus. The address space for this bus is such that we can't really easily
  118. * make it contiguous to the PCI I/O address range, and it also does not
  119. * need swapping like PCI addresses do (IXDP2x01 is a BE platform).
  120. * B/C of this we can't use the standard in/out functions and need to
  121. * runtime check if the incoming address is a PCI address or for
  122. * the CS89x0.
  123. */
  124. #undef inw
  125. #undef outw
  126. #undef insw
  127. #undef outsw
  128. #include <asm/mach-types.h>
  129. static inline void insw(u32 ptr, void *buf, int length)
  130. {
  131. register volatile u32 *port = (volatile u32 *)ptr;
  132. /*
  133. * Is this cycle meant for the CS8900?
  134. */
  135. if ((machine_is_ixdp2401() || machine_is_ixdp2801()) &&
  136. (((u32)port >= (u32)IXDP2X01_CS8900_VIRT_BASE) &&
  137. ((u32)port <= (u32)IXDP2X01_CS8900_VIRT_END))) {
  138. u8 *buf8 = (u8*)buf;
  139. register u32 tmp32;
  140. do {
  141. tmp32 = *port;
  142. *buf8++ = (u8)tmp32;
  143. *buf8++ = (u8)(tmp32 >> 8);
  144. } while(--length);
  145. return;
  146. }
  147. __raw_readsw(alignw(___io(ptr)),buf,length);
  148. }
  149. static inline void outsw(u32 ptr, void *buf, int length)
  150. {
  151. register volatile u32 *port = (volatile u32 *)ptr;
  152. /*
  153. * Is this cycle meant for the CS8900?
  154. */
  155. if ((machine_is_ixdp2401() || machine_is_ixdp2801()) &&
  156. (((u32)port >= (u32)IXDP2X01_CS8900_VIRT_BASE) &&
  157. ((u32)port <= (u32)IXDP2X01_CS8900_VIRT_END))) {
  158. register u32 tmp32;
  159. u8 *buf8 = (u8*)buf;
  160. do {
  161. tmp32 = *buf8++;
  162. tmp32 |= (*buf8++) << 8;
  163. *port = tmp32;
  164. } while(--length);
  165. return;
  166. }
  167. __raw_writesw(alignw(___io(ptr)),buf,length);
  168. }
  169. static inline u16 inw(u32 ptr)
  170. {
  171. register volatile u32 *port = (volatile u32 *)ptr;
  172. /*
  173. * Is this cycle meant for the CS8900?
  174. */
  175. if ((machine_is_ixdp2401() || machine_is_ixdp2801()) &&
  176. (((u32)port >= (u32)IXDP2X01_CS8900_VIRT_BASE) &&
  177. ((u32)port <= (u32)IXDP2X01_CS8900_VIRT_END))) {
  178. return (u16)(*port);
  179. }
  180. return __raw_readw(alignw(___io(ptr)));
  181. }
  182. static inline void outw(u16 value, u32 ptr)
  183. {
  184. register volatile u32 *port = (volatile u32 *)ptr;
  185. if ((machine_is_ixdp2401() || machine_is_ixdp2801()) &&
  186. (((u32)port >= (u32)IXDP2X01_CS8900_VIRT_BASE) &&
  187. ((u32)port <= (u32)IXDP2X01_CS8900_VIRT_END))) {
  188. *port = value;
  189. return;
  190. }
  191. __raw_writew((value),alignw(___io(ptr)));
  192. }
  193. #endif /* IXDP2x01 */
  194. #endif