io.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2000-2004 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #ifndef _ASM_SN_IO_H
  9. #define _ASM_SN_IO_H
  10. #include <linux/compiler.h>
  11. #include <asm/intrinsics.h>
  12. extern void * sn_io_addr(unsigned long port) __attribute_const__; /* Forward definition */
  13. extern void __sn_mmiowb(void); /* Forward definition */
  14. extern int num_cnodes;
  15. #define __sn_mf_a() ia64_mfa()
  16. extern void sn_dma_flush(unsigned long);
  17. #define __sn_inb ___sn_inb
  18. #define __sn_inw ___sn_inw
  19. #define __sn_inl ___sn_inl
  20. #define __sn_outb ___sn_outb
  21. #define __sn_outw ___sn_outw
  22. #define __sn_outl ___sn_outl
  23. #define __sn_readb ___sn_readb
  24. #define __sn_readw ___sn_readw
  25. #define __sn_readl ___sn_readl
  26. #define __sn_readq ___sn_readq
  27. #define __sn_readb_relaxed ___sn_readb_relaxed
  28. #define __sn_readw_relaxed ___sn_readw_relaxed
  29. #define __sn_readl_relaxed ___sn_readl_relaxed
  30. #define __sn_readq_relaxed ___sn_readq_relaxed
  31. /*
  32. * Convenience macros for setting/clearing bits using the above accessors
  33. */
  34. #define __sn_setq_relaxed(addr, val) \
  35. writeq((__sn_readq_relaxed(addr) | (val)), (addr))
  36. #define __sn_clrq_relaxed(addr, val) \
  37. writeq((__sn_readq_relaxed(addr) & ~(val)), (addr))
  38. /*
  39. * The following routines are SN Platform specific, called when
  40. * a reference is made to inX/outX set macros. SN Platform
  41. * inX set of macros ensures that Posted DMA writes on the
  42. * Bridge is flushed.
  43. *
  44. * The routines should be self explainatory.
  45. */
  46. static inline unsigned int
  47. ___sn_inb (unsigned long port)
  48. {
  49. volatile unsigned char *addr;
  50. unsigned char ret = -1;
  51. if ((addr = sn_io_addr(port))) {
  52. ret = *addr;
  53. __sn_mf_a();
  54. sn_dma_flush((unsigned long)addr);
  55. }
  56. return ret;
  57. }
  58. static inline unsigned int
  59. ___sn_inw (unsigned long port)
  60. {
  61. volatile unsigned short *addr;
  62. unsigned short ret = -1;
  63. if ((addr = sn_io_addr(port))) {
  64. ret = *addr;
  65. __sn_mf_a();
  66. sn_dma_flush((unsigned long)addr);
  67. }
  68. return ret;
  69. }
  70. static inline unsigned int
  71. ___sn_inl (unsigned long port)
  72. {
  73. volatile unsigned int *addr;
  74. unsigned int ret = -1;
  75. if ((addr = sn_io_addr(port))) {
  76. ret = *addr;
  77. __sn_mf_a();
  78. sn_dma_flush((unsigned long)addr);
  79. }
  80. return ret;
  81. }
  82. static inline void
  83. ___sn_outb (unsigned char val, unsigned long port)
  84. {
  85. volatile unsigned char *addr;
  86. if ((addr = sn_io_addr(port))) {
  87. *addr = val;
  88. __sn_mmiowb();
  89. }
  90. }
  91. static inline void
  92. ___sn_outw (unsigned short val, unsigned long port)
  93. {
  94. volatile unsigned short *addr;
  95. if ((addr = sn_io_addr(port))) {
  96. *addr = val;
  97. __sn_mmiowb();
  98. }
  99. }
  100. static inline void
  101. ___sn_outl (unsigned int val, unsigned long port)
  102. {
  103. volatile unsigned int *addr;
  104. if ((addr = sn_io_addr(port))) {
  105. *addr = val;
  106. __sn_mmiowb();
  107. }
  108. }
  109. /*
  110. * The following routines are SN Platform specific, called when
  111. * a reference is made to readX/writeX set macros. SN Platform
  112. * readX set of macros ensures that Posted DMA writes on the
  113. * Bridge is flushed.
  114. *
  115. * The routines should be self explainatory.
  116. */
  117. static inline unsigned char
  118. ___sn_readb (const volatile void __iomem *addr)
  119. {
  120. unsigned char val;
  121. val = *(volatile unsigned char __force *)addr;
  122. __sn_mf_a();
  123. sn_dma_flush((unsigned long)addr);
  124. return val;
  125. }
  126. static inline unsigned short
  127. ___sn_readw (const volatile void __iomem *addr)
  128. {
  129. unsigned short val;
  130. val = *(volatile unsigned short __force *)addr;
  131. __sn_mf_a();
  132. sn_dma_flush((unsigned long)addr);
  133. return val;
  134. }
  135. static inline unsigned int
  136. ___sn_readl (const volatile void __iomem *addr)
  137. {
  138. unsigned int val;
  139. val = *(volatile unsigned int __force *)addr;
  140. __sn_mf_a();
  141. sn_dma_flush((unsigned long)addr);
  142. return val;
  143. }
  144. static inline unsigned long
  145. ___sn_readq (const volatile void __iomem *addr)
  146. {
  147. unsigned long val;
  148. val = *(volatile unsigned long __force *)addr;
  149. __sn_mf_a();
  150. sn_dma_flush((unsigned long)addr);
  151. return val;
  152. }
  153. /*
  154. * For generic and SN2 kernels, we have a set of fast access
  155. * PIO macros. These macros are provided on SN Platform
  156. * because the normal inX and readX macros perform an
  157. * additional task of flushing Post DMA request on the Bridge.
  158. *
  159. * These routines should be self explainatory.
  160. */
  161. static inline unsigned int
  162. sn_inb_fast (unsigned long port)
  163. {
  164. volatile unsigned char *addr = (unsigned char *)port;
  165. unsigned char ret;
  166. ret = *addr;
  167. __sn_mf_a();
  168. return ret;
  169. }
  170. static inline unsigned int
  171. sn_inw_fast (unsigned long port)
  172. {
  173. volatile unsigned short *addr = (unsigned short *)port;
  174. unsigned short ret;
  175. ret = *addr;
  176. __sn_mf_a();
  177. return ret;
  178. }
  179. static inline unsigned int
  180. sn_inl_fast (unsigned long port)
  181. {
  182. volatile unsigned int *addr = (unsigned int *)port;
  183. unsigned int ret;
  184. ret = *addr;
  185. __sn_mf_a();
  186. return ret;
  187. }
  188. static inline unsigned char
  189. ___sn_readb_relaxed (const volatile void __iomem *addr)
  190. {
  191. return *(volatile unsigned char __force *)addr;
  192. }
  193. static inline unsigned short
  194. ___sn_readw_relaxed (const volatile void __iomem *addr)
  195. {
  196. return *(volatile unsigned short __force *)addr;
  197. }
  198. static inline unsigned int
  199. ___sn_readl_relaxed (const volatile void __iomem *addr)
  200. {
  201. return *(volatile unsigned int __force *) addr;
  202. }
  203. static inline unsigned long
  204. ___sn_readq_relaxed (const volatile void __iomem *addr)
  205. {
  206. return *(volatile unsigned long __force *) addr;
  207. }
  208. struct pci_dev;
  209. static inline int
  210. sn_pci_set_vchan(struct pci_dev *pci_dev, unsigned long *addr, int vchan)
  211. {
  212. if (vchan > 1) {
  213. return -1;
  214. }
  215. if (!(*addr >> 32)) /* Using a mask here would be cleaner */
  216. return 0; /* but this generates better code */
  217. if (vchan == 1) {
  218. /* Set Bit 57 */
  219. *addr |= (1UL << 57);
  220. } else {
  221. /* Clear Bit 57 */
  222. *addr &= ~(1UL << 57);
  223. }
  224. return 0;
  225. }
  226. #endif /* _ASM_SN_IO_H */