io.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * arch/arm/mach-s3c2410/include/mach/io.h
  4. * from arch/arm/mach-rpc/include/mach/io.h
  5. *
  6. * Copyright (C) 1997 Russell King
  7. * (C) 2003 Simtec Electronics
  8. */
  9. #ifndef __ASM_ARM_ARCH_IO_H
  10. #define __ASM_ARM_ARCH_IO_H
  11. #include <mach/hardware.h>
  12. #define IO_SPACE_LIMIT 0xffffffff
  13. /*
  14. * We use two different types of addressing - PC style addresses, and ARM
  15. * addresses. PC style accesses the PC hardware with the normal PC IO
  16. * addresses, eg 0x3f8 for serial#1. ARM addresses are above A28
  17. * and are translated to the start of IO. Note that all addresses are
  18. * not shifted left!
  19. */
  20. #define __PORT_PCIO(x) ((x) < (1<<28))
  21. #define PCIO_BASE (S3C24XX_VA_ISA_WORD)
  22. #define PCIO_BASE_b (S3C24XX_VA_ISA_BYTE)
  23. #define PCIO_BASE_w (S3C24XX_VA_ISA_WORD)
  24. #define PCIO_BASE_l (S3C24XX_VA_ISA_WORD)
  25. /*
  26. * Dynamic IO functions - let the compiler
  27. * optimize the expressions
  28. */
  29. #define DECLARE_DYN_OUT(sz,fnsuffix,instr) \
  30. static inline void __out##fnsuffix (unsigned int val, unsigned int port) \
  31. { \
  32. unsigned long temp; \
  33. __asm__ __volatile__( \
  34. "cmp %2, #(1<<28)\n\t" \
  35. "mov %0, %2\n\t" \
  36. "addcc %0, %0, %3\n\t" \
  37. "str" instr " %1, [%0, #0 ] @ out" #fnsuffix \
  38. : "=&r" (temp) \
  39. : "r" (val), "r" (port), "Ir" (PCIO_BASE_##fnsuffix) \
  40. : "cc"); \
  41. }
  42. #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
  43. static inline unsigned sz __in##fnsuffix (unsigned int port) \
  44. { \
  45. unsigned long temp, value; \
  46. __asm__ __volatile__( \
  47. "cmp %2, #(1<<28)\n\t" \
  48. "mov %0, %2\n\t" \
  49. "addcc %0, %0, %3\n\t" \
  50. "ldr" instr " %1, [%0, #0 ] @ in" #fnsuffix \
  51. : "=&r" (temp), "=r" (value) \
  52. : "r" (port), "Ir" (PCIO_BASE_##fnsuffix) \
  53. : "cc"); \
  54. return (unsigned sz)value; \
  55. }
  56. static inline void __iomem *__ioaddr (unsigned long port)
  57. {
  58. return __PORT_PCIO(port) ? (PCIO_BASE + port) : (void __iomem *)port;
  59. }
  60. #define DECLARE_IO(sz,fnsuffix,instr) \
  61. DECLARE_DYN_IN(sz,fnsuffix,instr) \
  62. DECLARE_DYN_OUT(sz,fnsuffix,instr)
  63. DECLARE_IO(char,b,"b")
  64. DECLARE_IO(short,w,"h")
  65. DECLARE_IO(int,l,"")
  66. #undef DECLARE_IO
  67. #undef DECLARE_DYN_IN
  68. /*
  69. * Constant address IO functions
  70. *
  71. * These have to be macros for the 'J' constraint to work -
  72. * +/-4096 immediate operand.
  73. */
  74. #define __outbc(value,port) \
  75. ({ \
  76. if (__PORT_PCIO((port))) \
  77. __asm__ __volatile__( \
  78. "strb %0, [%1, %2] @ outbc" \
  79. : : "r" (value), "r" (PCIO_BASE), "Jr" ((port))); \
  80. else \
  81. __asm__ __volatile__( \
  82. "strb %0, [%1, #0] @ outbc" \
  83. : : "r" (value), "r" ((port))); \
  84. })
  85. #define __inbc(port) \
  86. ({ \
  87. unsigned char result; \
  88. if (__PORT_PCIO((port))) \
  89. __asm__ __volatile__( \
  90. "ldrb %0, [%1, %2] @ inbc" \
  91. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port))); \
  92. else \
  93. __asm__ __volatile__( \
  94. "ldrb %0, [%1, #0] @ inbc" \
  95. : "=r" (result) : "r" ((port))); \
  96. result; \
  97. })
  98. #define __outwc(value,port) \
  99. ({ \
  100. unsigned long v = value; \
  101. if (__PORT_PCIO((port))) { \
  102. if ((port) < 256 && (port) > -256) \
  103. __asm__ __volatile__( \
  104. "strh %0, [%1, %2] @ outwc" \
  105. : : "r" (v), "r" (PCIO_BASE), "Jr" ((port))); \
  106. else if ((port) > 0) \
  107. __asm__ __volatile__( \
  108. "strh %0, [%1, %2] @ outwc" \
  109. : : "r" (v), \
  110. "r" (PCIO_BASE + ((port) & ~0xff)), \
  111. "Jr" (((port) & 0xff))); \
  112. else \
  113. __asm__ __volatile__( \
  114. "strh %0, [%1, #0] @ outwc" \
  115. : : "r" (v), \
  116. "r" (PCIO_BASE + (port))); \
  117. } else \
  118. __asm__ __volatile__( \
  119. "strh %0, [%1, #0] @ outwc" \
  120. : : "r" (v), "r" ((port))); \
  121. })
  122. #define __inwc(port) \
  123. ({ \
  124. unsigned short result; \
  125. if (__PORT_PCIO((port))) { \
  126. if ((port) < 256 && (port) > -256 ) \
  127. __asm__ __volatile__( \
  128. "ldrh %0, [%1, %2] @ inwc" \
  129. : "=r" (result) \
  130. : "r" (PCIO_BASE), \
  131. "Jr" ((port))); \
  132. else if ((port) > 0) \
  133. __asm__ __volatile__( \
  134. "ldrh %0, [%1, %2] @ inwc" \
  135. : "=r" (result) \
  136. : "r" (PCIO_BASE + ((port) & ~0xff)), \
  137. "Jr" (((port) & 0xff))); \
  138. else \
  139. __asm__ __volatile__( \
  140. "ldrh %0, [%1, #0] @ inwc" \
  141. : "=r" (result) \
  142. : "r" (PCIO_BASE + ((port)))); \
  143. } else \
  144. __asm__ __volatile__( \
  145. "ldrh %0, [%1, #0] @ inwc" \
  146. : "=r" (result) : "r" ((port))); \
  147. result; \
  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))); \
  156. else \
  157. __asm__ __volatile__( \
  158. "str %0, [%1, #0] @ outlc" \
  159. : : "r" (v), "r" ((port))); \
  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))); \
  168. else \
  169. __asm__ __volatile__( \
  170. "ldr %0, [%1, #0] @ inlc" \
  171. : "=r" (result) : "r" ((port))); \
  172. result; \
  173. })
  174. #define __ioaddrc(port) ((__PORT_PCIO(port) ? PCIO_BASE + (port) : (void __iomem *)0 + (port)))
  175. #define inb(p) (__builtin_constant_p((p)) ? __inbc(p) : __inb(p))
  176. #define inw(p) (__builtin_constant_p((p)) ? __inwc(p) : __inw(p))
  177. #define inl(p) (__builtin_constant_p((p)) ? __inlc(p) : __inl(p))
  178. #define outb(v,p) (__builtin_constant_p((p)) ? __outbc(v,p) : __outb(v,p))
  179. #define outw(v,p) (__builtin_constant_p((p)) ? __outwc(v,p) : __outw(v,p))
  180. #define outl(v,p) (__builtin_constant_p((p)) ? __outlc(v,p) : __outl(v,p))
  181. #define __ioaddr(p) (__builtin_constant_p((p)) ? __ioaddr(p) : __ioaddrc(p))
  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 insl(p,d,l) __raw_readsl(__ioaddr(p),d,l)
  185. #define outsb(p,d,l) __raw_writesb(__ioaddr(p),d,l)
  186. #define outsw(p,d,l) __raw_writesw(__ioaddr(p),d,l)
  187. #define outsl(p,d,l) __raw_writesl(__ioaddr(p),d,l)
  188. #endif