io.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * arch/arm/mach-rpc/include/mach/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. #include <mach/hardware.h>
  16. #define IO_SPACE_LIMIT 0xffffffff
  17. /*
  18. * We use two different types of addressing - PC style addresses, and ARM
  19. * addresses. PC style accesses the PC hardware with the normal PC IO
  20. * addresses, eg 0x3f8 for serial#1. ARM addresses are 0x80000000+
  21. * and are translated to the start of IO. Note that all addresses are
  22. * shifted left!
  23. */
  24. #define __PORT_PCIO(x) (!((x) & 0x80000000))
  25. /*
  26. * Dynamic IO functions.
  27. */
  28. static inline void __outb (unsigned int value, unsigned int port)
  29. {
  30. unsigned long temp;
  31. __asm__ __volatile__(
  32. "tst %2, #0x80000000\n\t"
  33. "mov %0, %4\n\t"
  34. "addeq %0, %0, %3\n\t"
  35. "strb %1, [%0, %2, lsl #2] @ outb"
  36. : "=&r" (temp)
  37. : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  38. : "cc");
  39. }
  40. static inline void __outw (unsigned int value, unsigned int port)
  41. {
  42. unsigned long temp;
  43. __asm__ __volatile__(
  44. "tst %2, #0x80000000\n\t"
  45. "mov %0, %4\n\t"
  46. "addeq %0, %0, %3\n\t"
  47. "str %1, [%0, %2, lsl #2] @ outw"
  48. : "=&r" (temp)
  49. : "r" (value|value<<16), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  50. : "cc");
  51. }
  52. static inline void __outl (unsigned int value, unsigned int port)
  53. {
  54. unsigned long temp;
  55. __asm__ __volatile__(
  56. "tst %2, #0x80000000\n\t"
  57. "mov %0, %4\n\t"
  58. "addeq %0, %0, %3\n\t"
  59. "str %1, [%0, %2, lsl #2] @ outl"
  60. : "=&r" (temp)
  61. : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  62. : "cc");
  63. }
  64. #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
  65. static inline unsigned sz __in##fnsuffix (unsigned int port) \
  66. { \
  67. unsigned long temp, value; \
  68. __asm__ __volatile__( \
  69. "tst %2, #0x80000000\n\t" \
  70. "mov %0, %4\n\t" \
  71. "addeq %0, %0, %3\n\t" \
  72. "ldr" instr " %1, [%0, %2, lsl #2] @ in" #fnsuffix \
  73. : "=&r" (temp), "=r" (value) \
  74. : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
  75. : "cc"); \
  76. return (unsigned sz)value; \
  77. }
  78. static inline void __iomem *__deprecated __ioaddr(unsigned int port)
  79. {
  80. void __iomem *ret;
  81. if (__PORT_PCIO(port))
  82. ret = PCIO_BASE;
  83. else
  84. ret = IO_BASE;
  85. return ret + (port << 2);
  86. }
  87. #define DECLARE_IO(sz,fnsuffix,instr) \
  88. DECLARE_DYN_IN(sz,fnsuffix,instr)
  89. DECLARE_IO(char,b,"b")
  90. DECLARE_IO(short,w,"")
  91. DECLARE_IO(int,l,"")
  92. #undef DECLARE_IO
  93. #undef DECLARE_DYN_IN
  94. /*
  95. * Constant address IO functions
  96. *
  97. * These have to be macros for the 'J' constraint to work -
  98. * +/-4096 immediate operand.
  99. */
  100. #define __outbc(value,port) \
  101. ({ \
  102. if (__PORT_PCIO((port))) \
  103. __asm__ __volatile__( \
  104. "strb %0, [%1, %2] @ outbc" \
  105. : : "r" (value), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  106. else \
  107. __asm__ __volatile__( \
  108. "strb %0, [%1, %2] @ outbc" \
  109. : : "r" (value), "r" (IO_BASE), "r" ((port) << 2)); \
  110. })
  111. #define __inbc(port) \
  112. ({ \
  113. unsigned char result; \
  114. if (__PORT_PCIO((port))) \
  115. __asm__ __volatile__( \
  116. "ldrb %0, [%1, %2] @ inbc" \
  117. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  118. else \
  119. __asm__ __volatile__( \
  120. "ldrb %0, [%1, %2] @ inbc" \
  121. : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
  122. result; \
  123. })
  124. #define __outwc(value,port) \
  125. ({ \
  126. unsigned long __v = value; \
  127. if (__PORT_PCIO((port))) \
  128. __asm__ __volatile__( \
  129. "str %0, [%1, %2] @ outwc" \
  130. : : "r" (__v|__v<<16), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  131. else \
  132. __asm__ __volatile__( \
  133. "str %0, [%1, %2] @ outwc" \
  134. : : "r" (__v|__v<<16), "r" (IO_BASE), "r" ((port) << 2)); \
  135. })
  136. #define __inwc(port) \
  137. ({ \
  138. unsigned short result; \
  139. if (__PORT_PCIO((port))) \
  140. __asm__ __volatile__( \
  141. "ldr %0, [%1, %2] @ inwc" \
  142. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  143. else \
  144. __asm__ __volatile__( \
  145. "ldr %0, [%1, %2] @ inwc" \
  146. : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
  147. result & 0xffff; \
  148. })
  149. #define __outlc(value,port) \
  150. ({ \
  151. unsigned long __v = value; \
  152. if (__PORT_PCIO((port))) \
  153. __asm__ __volatile__( \
  154. "str %0, [%1, %2] @ outlc" \
  155. : : "r" (__v), "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  156. else \
  157. __asm__ __volatile__( \
  158. "str %0, [%1, %2] @ outlc" \
  159. : : "r" (__v), "r" (IO_BASE), "r" ((port) << 2)); \
  160. })
  161. #define __inlc(port) \
  162. ({ \
  163. unsigned long result; \
  164. if (__PORT_PCIO((port))) \
  165. __asm__ __volatile__( \
  166. "ldr %0, [%1, %2] @ inlc" \
  167. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2)); \
  168. else \
  169. __asm__ __volatile__( \
  170. "ldr %0, [%1, %2] @ inlc" \
  171. : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2)); \
  172. result; \
  173. })
  174. #define inb(p) (__builtin_constant_p((p)) ? __inbc(p) : __inb(p))
  175. #define inw(p) (__builtin_constant_p((p)) ? __inwc(p) : __inw(p))
  176. #define inl(p) (__builtin_constant_p((p)) ? __inlc(p) : __inl(p))
  177. #define outb(v,p) (__builtin_constant_p((p)) ? __outbc(v,p) : __outb(v,p))
  178. #define outw(v,p) (__builtin_constant_p((p)) ? __outwc(v,p) : __outw(v,p))
  179. #define outl(v,p) (__builtin_constant_p((p)) ? __outlc(v,p) : __outl(v,p))
  180. /* the following macro is deprecated */
  181. #define ioaddr(port) ((unsigned long)__ioaddr((port)))
  182. #define insb(p,d,l) __raw_readsb(__ioaddr(p),d,l)
  183. #define insw(p,d,l) __raw_readsw(__ioaddr(p),d,l)
  184. #define outsb(p,d,l) __raw_writesb(__ioaddr(p),d,l)
  185. #define outsw(p,d,l) __raw_writesw(__ioaddr(p),d,l)
  186. /*
  187. * 1:1 mapping for ioremapped regions.
  188. */
  189. #define __mem_pci(x) (x)
  190. #endif