io.h 6.8 KB

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