io.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * linux/include/asm-arm/arch-cl7500/io.h
  3. * from linux/include/asm-arm/arch-rpc/io.h
  4. *
  5. * Copyright (C) 1997 Russell King
  6. *
  7. * Modifications:
  8. * 06-Dec-1997 RMK Created.
  9. */
  10. #ifndef __ASM_ARM_ARCH_IO_H
  11. #define __ASM_ARM_ARCH_IO_H
  12. #include <asm/hardware.h>
  13. #define IO_SPACE_LIMIT 0xffffffff
  14. /*
  15. * GCC is totally crap at loading/storing data. We try to persuade it
  16. * to do the right thing by using these whereever possible instead of
  17. * the above.
  18. */
  19. #define __arch_base_getb(b,o) \
  20. ({ \
  21. unsigned int v, r = (b); \
  22. __asm__ __volatile__( \
  23. "ldrb %0, [%1, %2]" \
  24. : "=r" (v) \
  25. : "r" (r), "Ir" (o)); \
  26. v; \
  27. })
  28. #define __arch_base_getl(b,o) \
  29. ({ \
  30. unsigned int v, r = (b); \
  31. __asm__ __volatile__( \
  32. "ldr %0, [%1, %2]" \
  33. : "=r" (v) \
  34. : "r" (r), "Ir" (o)); \
  35. v; \
  36. })
  37. #define __arch_base_putb(v,b,o) \
  38. ({ \
  39. unsigned int r = (b); \
  40. __asm__ __volatile__( \
  41. "strb %0, [%1, %2]" \
  42. : \
  43. : "r" (v), "r" (r), "Ir" (o)); \
  44. })
  45. #define __arch_base_putl(v,b,o) \
  46. ({ \
  47. unsigned int r = (b); \
  48. __asm__ __volatile__( \
  49. "str %0, [%1, %2]" \
  50. : \
  51. : "r" (v), "r" (r), "Ir" (o)); \
  52. })
  53. /*
  54. * We use two different types of addressing - PC style addresses, and ARM
  55. * addresses. PC style accesses the PC hardware with the normal PC IO
  56. * addresses, eg 0x3f8 for serial#1. ARM addresses are 0x80000000+
  57. * and are translated to the start of IO. Note that all addresses are
  58. * shifted left!
  59. */
  60. #define __PORT_PCIO(x) (!((x) & 0x80000000))
  61. /*
  62. * Dynamic IO functions - let the compiler
  63. * optimize the expressions
  64. */
  65. static inline void __outb (unsigned int value, unsigned int port)
  66. {
  67. unsigned long temp;
  68. __asm__ __volatile__(
  69. "tst %2, #0x80000000\n\t"
  70. "mov %0, %4\n\t"
  71. "addeq %0, %0, %3\n\t"
  72. "strb %1, [%0, %2, lsl #2] @ outb"
  73. : "=&r" (temp)
  74. : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  75. : "cc");
  76. }
  77. static inline void __outw (unsigned int value, unsigned int port)
  78. {
  79. unsigned long temp;
  80. __asm__ __volatile__(
  81. "tst %2, #0x80000000\n\t"
  82. "mov %0, %4\n\t"
  83. "addeq %0, %0, %3\n\t"
  84. "str %1, [%0, %2, lsl #2] @ outw"
  85. : "=&r" (temp)
  86. : "r" (value|value<<16), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  87. : "cc");
  88. }
  89. static inline void __outl (unsigned int value, unsigned int port)
  90. {
  91. unsigned long temp;
  92. __asm__ __volatile__(
  93. "tst %2, #0x80000000\n\t"
  94. "mov %0, %4\n\t"
  95. "addeq %0, %0, %3\n\t"
  96. "str %1, [%0, %2, lsl #2] @ outl"
  97. : "=&r" (temp)
  98. : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  99. : "cc");
  100. }
  101. #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
  102. static inline unsigned sz __in##fnsuffix (unsigned int port) \
  103. { \
  104. unsigned long temp, value; \
  105. __asm__ __volatile__( \
  106. "tst %2, #0x80000000\n\t" \
  107. "mov %0, %4\n\t" \
  108. "addeq %0, %0, %3\n\t" \
  109. "ldr" instr " %1, [%0, %2, lsl #2] @ in" #fnsuffix \
  110. : "=&r" (temp), "=r" (value) \
  111. : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
  112. : "cc"); \
  113. return (unsigned sz)value; \
  114. }
  115. static inline unsigned int __ioaddr (unsigned int port) \
  116. { \
  117. if (__PORT_PCIO(port)) \
  118. return (unsigned int)(PCIO_BASE + (port << 2)); \
  119. else \
  120. return (unsigned int)(IO_BASE + (port << 2)); \
  121. }
  122. #define DECLARE_IO(sz,fnsuffix,instr) \
  123. DECLARE_DYN_IN(sz,fnsuffix,instr)
  124. DECLARE_IO(char,b,"b")
  125. DECLARE_IO(short,w,"")
  126. DECLARE_IO(int,l,"")
  127. #undef DECLARE_IO
  128. #undef DECLARE_DYN_IN
  129. /*
  130. * Constant address IO functions
  131. *
  132. * These have to be macros for the 'J' constraint to work -
  133. * +/-4096 immediate operand.
  134. */
  135. #define __outbc(value,port) \
  136. ({ \
  137. if (__PORT_PCIO((port))) \
  138. __asm__ __volatile__( \
  139. "strb %0, [%1, %2] @ outbc" \
  140. : : "r" (value), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  141. else \
  142. __asm__ __volatile__( \
  143. "strb %0, [%1, %2] @ outbc" \
  144. : : "r" (value), "r" (IO_BASE), "r" ((port) << 2)); \
  145. })
  146. #define __inbc(port) \
  147. ({ \
  148. unsigned char result; \
  149. if (__PORT_PCIO((port))) \
  150. __asm__ __volatile__( \
  151. "ldrb %0, [%1, %2] @ inbc" \
  152. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  153. else \
  154. __asm__ __volatile__( \
  155. "ldrb %0, [%1, %2] @ inbc" \
  156. : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
  157. result; \
  158. })
  159. #define __outwc(value,port) \
  160. ({ \
  161. unsigned long v = value; \
  162. if (__PORT_PCIO((port))) \
  163. __asm__ __volatile__( \
  164. "str %0, [%1, %2] @ outwc" \
  165. : : "r" (v|v<<16), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  166. else \
  167. __asm__ __volatile__( \
  168. "str %0, [%1, %2] @ outwc" \
  169. : : "r" (v|v<<16), "r" (IO_BASE), "r" ((port) << 2)); \
  170. })
  171. #define __inwc(port) \
  172. ({ \
  173. unsigned short result; \
  174. if (__PORT_PCIO((port))) \
  175. __asm__ __volatile__( \
  176. "ldr %0, [%1, %2] @ inwc" \
  177. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  178. else \
  179. __asm__ __volatile__( \
  180. "ldr %0, [%1, %2] @ inwc" \
  181. : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
  182. result & 0xffff; \
  183. })
  184. #define __outlc(value,port) \
  185. ({ \
  186. unsigned long v = value; \
  187. if (__PORT_PCIO((port))) \
  188. __asm__ __volatile__( \
  189. "str %0, [%1, %2] @ outlc" \
  190. : : "r" (v), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  191. else \
  192. __asm__ __volatile__( \
  193. "str %0, [%1, %2] @ outlc" \
  194. : : "r" (v), "r" (IO_BASE), "r" ((port) << 2)); \
  195. })
  196. #define __inlc(port) \
  197. ({ \
  198. unsigned long result; \
  199. if (__PORT_PCIO((port))) \
  200. __asm__ __volatile__( \
  201. "ldr %0, [%1, %2] @ inlc" \
  202. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  203. else \
  204. __asm__ __volatile__( \
  205. "ldr %0, [%1, %2] @ inlc" \
  206. : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
  207. result; \
  208. })
  209. #define __ioaddrc(port) \
  210. (__PORT_PCIO((port)) ? PCIO_BASE + ((port) << 2) : IO_BASE + ((port) << 2))
  211. #define inb(p) (__builtin_constant_p((p)) ? __inbc(p) : __inb(p))
  212. #define inw(p) (__builtin_constant_p((p)) ? __inwc(p) : __inw(p))
  213. #define inl(p) (__builtin_constant_p((p)) ? __inlc(p) : __inl(p))
  214. #define outb(v,p) (__builtin_constant_p((p)) ? __outbc(v,p) : __outb(v,p))
  215. #define outw(v,p) (__builtin_constant_p((p)) ? __outwc(v,p) : __outw(v,p))
  216. #define outl(v,p) (__builtin_constant_p((p)) ? __outlc(v,p) : __outl(v,p))
  217. #define __ioaddr(p) (__builtin_constant_p((p)) ? __ioaddr(p) : __ioaddrc(p))
  218. /* the following macro is deprecated */
  219. #define ioaddr(port) __ioaddr((port))
  220. #define insb(p,d,l) __raw_readsb(__ioaddr(p),d,l)
  221. #define insw(p,d,l) __raw_readsw(__ioaddr(p),d,l)
  222. #define outsb(p,d,l) __raw_writesb(__ioaddr(p),d,l)
  223. #define outsw(p,d,l) __raw_writesw(__ioaddr(p),d,l)
  224. /*
  225. * 1:1 mapping for ioremapped regions.
  226. */
  227. #define __mem_pci(x) (x)
  228. #endif