io.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * linux/include/asm-arm/arch-shark/io.h
  3. *
  4. * by Alexander Schulz
  5. *
  6. * derived from:
  7. * linux/include/asm-arm/arch-ebsa110/io.h
  8. * Copyright (C) 1997,1998 Russell King
  9. */
  10. #ifndef __ASM_ARM_ARCH_IO_H
  11. #define __ASM_ARM_ARCH_IO_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 0x80000000+
  17. * and are translated to the start of IO.
  18. */
  19. #define __PORT_PCIO(x) (!((x) & 0x80000000))
  20. /*
  21. * Dynamic IO functions - let the compiler
  22. * optimize the expressions
  23. */
  24. #define DECLARE_DYN_OUT(fnsuffix,instr) \
  25. static inline void __out##fnsuffix (unsigned int value, unsigned int port) \
  26. { \
  27. unsigned long temp; \
  28. __asm__ __volatile__( \
  29. "tst %2, #0x80000000\n\t" \
  30. "mov %0, %4\n\t" \
  31. "addeq %0, %0, %3\n\t" \
  32. "str" instr " %1, [%0, %2] @ out" #fnsuffix \
  33. : "=&r" (temp) \
  34. : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
  35. : "cc"); \
  36. }
  37. #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
  38. static inline unsigned sz __in##fnsuffix (unsigned int port) \
  39. { \
  40. unsigned long temp, value; \
  41. __asm__ __volatile__( \
  42. "tst %2, #0x80000000\n\t" \
  43. "mov %0, %4\n\t" \
  44. "addeq %0, %0, %3\n\t" \
  45. "ldr" instr " %1, [%0, %2] @ in" #fnsuffix \
  46. : "=&r" (temp), "=r" (value) \
  47. : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
  48. : "cc"); \
  49. return (unsigned sz)value; \
  50. }
  51. static inline unsigned int __ioaddr (unsigned int port) \
  52. { \
  53. if (__PORT_PCIO(port)) \
  54. return (unsigned int)(PCIO_BASE + (port)); \
  55. else \
  56. return (unsigned int)(IO_BASE + (port)); \
  57. }
  58. #define DECLARE_IO(sz,fnsuffix,instr) \
  59. DECLARE_DYN_OUT(fnsuffix,instr) \
  60. DECLARE_DYN_IN(sz,fnsuffix,instr)
  61. DECLARE_IO(char,b,"b")
  62. DECLARE_IO(short,w,"h")
  63. DECLARE_IO(long,l,"")
  64. #undef DECLARE_IO
  65. #undef DECLARE_DYN_OUT
  66. #undef DECLARE_DYN_IN
  67. /*
  68. * Constant address IO functions
  69. *
  70. * These have to be macros for the 'J' constraint to work -
  71. * +/-4096 immediate operand.
  72. */
  73. #define __outbc(value,port) \
  74. ({ \
  75. if (__PORT_PCIO((port))) \
  76. __asm__ __volatile__( \
  77. "strb %0, [%1, %2] @ outbc" \
  78. : : "r" (value), "r" (PCIO_BASE), "Jr" (port)); \
  79. else \
  80. __asm__ __volatile__( \
  81. "strb %0, [%1, %2] @ outbc" \
  82. : : "r" (value), "r" (IO_BASE), "r" (port)); \
  83. })
  84. #define __inbc(port) \
  85. ({ \
  86. unsigned char result; \
  87. if (__PORT_PCIO((port))) \
  88. __asm__ __volatile__( \
  89. "ldrb %0, [%1, %2] @ inbc" \
  90. : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
  91. else \
  92. __asm__ __volatile__( \
  93. "ldrb %0, [%1, %2] @ inbc" \
  94. : "=r" (result) : "r" (IO_BASE), "r" (port)); \
  95. result; \
  96. })
  97. #define __outwc(value,port) \
  98. ({ \
  99. unsigned long v = value; \
  100. if (__PORT_PCIO((port))) \
  101. __asm__ __volatile__( \
  102. "strh %0, [%1, %2] @ outwc" \
  103. : : "r" (v|v<<16), "r" (PCIO_BASE), "Jr" (port)); \
  104. else \
  105. __asm__ __volatile__( \
  106. "strh %0, [%1, %2] @ outwc" \
  107. : : "r" (v|v<<16), "r" (IO_BASE), "r" (port)); \
  108. })
  109. #define __inwc(port) \
  110. ({ \
  111. unsigned short result; \
  112. if (__PORT_PCIO((port))) \
  113. __asm__ __volatile__( \
  114. "ldrh %0, [%1, %2] @ inwc" \
  115. : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
  116. else \
  117. __asm__ __volatile__( \
  118. "ldrh %0, [%1, %2] @ inwc" \
  119. : "=r" (result) : "r" (IO_BASE), "r" (port)); \
  120. result & 0xffff; \
  121. })
  122. #define __outlc(value,port) \
  123. ({ \
  124. unsigned long v = value; \
  125. if (__PORT_PCIO((port))) \
  126. __asm__ __volatile__( \
  127. "str %0, [%1, %2] @ outlc" \
  128. : : "r" (v), "r" (PCIO_BASE), "Jr" (port)); \
  129. else \
  130. __asm__ __volatile__( \
  131. "str %0, [%1, %2] @ outlc" \
  132. : : "r" (v), "r" (IO_BASE), "r" (port)); \
  133. })
  134. #define __inlc(port) \
  135. ({ \
  136. unsigned long result; \
  137. if (__PORT_PCIO((port))) \
  138. __asm__ __volatile__( \
  139. "ldr %0, [%1, %2] @ inlc" \
  140. : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
  141. else \
  142. __asm__ __volatile__( \
  143. "ldr %0, [%1, %2] @ inlc" \
  144. : "=r" (result) : "r" (IO_BASE), "r" (port)); \
  145. result; \
  146. })
  147. #define __ioaddrc(port) \
  148. ({ \
  149. unsigned long addr; \
  150. if (__PORT_PCIO((port))) \
  151. addr = PCIO_BASE + (port); \
  152. else \
  153. addr = IO_BASE + (port); \
  154. addr; \
  155. })
  156. #define __mem_pci(addr) (addr)
  157. #define inb(p) (__builtin_constant_p((p)) ? __inbc(p) : __inb(p))
  158. #define inw(p) (__builtin_constant_p((p)) ? __inwc(p) : __inw(p))
  159. #define inl(p) (__builtin_constant_p((p)) ? __inlc(p) : __inl(p))
  160. #define outb(v,p) (__builtin_constant_p((p)) ? __outbc(v,p) : __outb(v,p))
  161. #define outw(v,p) (__builtin_constant_p((p)) ? __outwc(v,p) : __outw(v,p))
  162. #define outl(v,p) (__builtin_constant_p((p)) ? __outlc(v,p) : __outl(v,p))
  163. /*
  164. * Translated address IO functions
  165. *
  166. * IO address has already been translated to a virtual address
  167. */
  168. #define outb_t(v,p) \
  169. (*(volatile unsigned char *)(p) = (v))
  170. #define inb_t(p) \
  171. (*(volatile unsigned char *)(p))
  172. #define outl_t(v,p) \
  173. (*(volatile unsigned long *)(p) = (v))
  174. #define inl_t(p) \
  175. (*(volatile unsigned long *)(p))
  176. #endif