io.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 numionodes;
  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. * The following routines are SN Platform specific, called when
  33. * a reference is made to inX/outX set macros. SN Platform
  34. * inX set of macros ensures that Posted DMA writes on the
  35. * Bridge is flushed.
  36. *
  37. * The routines should be self explainatory.
  38. */
  39. static inline unsigned int
  40. ___sn_inb (unsigned long port)
  41. {
  42. volatile unsigned char *addr;
  43. unsigned char ret = -1;
  44. if ((addr = sn_io_addr(port))) {
  45. ret = *addr;
  46. __sn_mf_a();
  47. sn_dma_flush((unsigned long)addr);
  48. }
  49. return ret;
  50. }
  51. static inline unsigned int
  52. ___sn_inw (unsigned long port)
  53. {
  54. volatile unsigned short *addr;
  55. unsigned short ret = -1;
  56. if ((addr = sn_io_addr(port))) {
  57. ret = *addr;
  58. __sn_mf_a();
  59. sn_dma_flush((unsigned long)addr);
  60. }
  61. return ret;
  62. }
  63. static inline unsigned int
  64. ___sn_inl (unsigned long port)
  65. {
  66. volatile unsigned int *addr;
  67. unsigned int ret = -1;
  68. if ((addr = sn_io_addr(port))) {
  69. ret = *addr;
  70. __sn_mf_a();
  71. sn_dma_flush((unsigned long)addr);
  72. }
  73. return ret;
  74. }
  75. static inline void
  76. ___sn_outb (unsigned char val, unsigned long port)
  77. {
  78. volatile unsigned char *addr;
  79. if ((addr = sn_io_addr(port))) {
  80. *addr = val;
  81. __sn_mmiowb();
  82. }
  83. }
  84. static inline void
  85. ___sn_outw (unsigned short val, unsigned long port)
  86. {
  87. volatile unsigned short *addr;
  88. if ((addr = sn_io_addr(port))) {
  89. *addr = val;
  90. __sn_mmiowb();
  91. }
  92. }
  93. static inline void
  94. ___sn_outl (unsigned int val, unsigned long port)
  95. {
  96. volatile unsigned int *addr;
  97. if ((addr = sn_io_addr(port))) {
  98. *addr = val;
  99. __sn_mmiowb();
  100. }
  101. }
  102. /*
  103. * The following routines are SN Platform specific, called when
  104. * a reference is made to readX/writeX set macros. SN Platform
  105. * readX set of macros ensures that Posted DMA writes on the
  106. * Bridge is flushed.
  107. *
  108. * The routines should be self explainatory.
  109. */
  110. static inline unsigned char
  111. ___sn_readb (const volatile void __iomem *addr)
  112. {
  113. unsigned char val;
  114. val = *(volatile unsigned char __force *)addr;
  115. __sn_mf_a();
  116. sn_dma_flush((unsigned long)addr);
  117. return val;
  118. }
  119. static inline unsigned short
  120. ___sn_readw (const volatile void __iomem *addr)
  121. {
  122. unsigned short val;
  123. val = *(volatile unsigned short __force *)addr;
  124. __sn_mf_a();
  125. sn_dma_flush((unsigned long)addr);
  126. return val;
  127. }
  128. static inline unsigned int
  129. ___sn_readl (const volatile void __iomem *addr)
  130. {
  131. unsigned int val;
  132. val = *(volatile unsigned int __force *)addr;
  133. __sn_mf_a();
  134. sn_dma_flush((unsigned long)addr);
  135. return val;
  136. }
  137. static inline unsigned long
  138. ___sn_readq (const volatile void __iomem *addr)
  139. {
  140. unsigned long val;
  141. val = *(volatile unsigned long __force *)addr;
  142. __sn_mf_a();
  143. sn_dma_flush((unsigned long)addr);
  144. return val;
  145. }
  146. /*
  147. * For generic and SN2 kernels, we have a set of fast access
  148. * PIO macros. These macros are provided on SN Platform
  149. * because the normal inX and readX macros perform an
  150. * additional task of flushing Post DMA request on the Bridge.
  151. *
  152. * These routines should be self explainatory.
  153. */
  154. static inline unsigned int
  155. sn_inb_fast (unsigned long port)
  156. {
  157. volatile unsigned char *addr = (unsigned char *)port;
  158. unsigned char ret;
  159. ret = *addr;
  160. __sn_mf_a();
  161. return ret;
  162. }
  163. static inline unsigned int
  164. sn_inw_fast (unsigned long port)
  165. {
  166. volatile unsigned short *addr = (unsigned short *)port;
  167. unsigned short ret;
  168. ret = *addr;
  169. __sn_mf_a();
  170. return ret;
  171. }
  172. static inline unsigned int
  173. sn_inl_fast (unsigned long port)
  174. {
  175. volatile unsigned int *addr = (unsigned int *)port;
  176. unsigned int ret;
  177. ret = *addr;
  178. __sn_mf_a();
  179. return ret;
  180. }
  181. static inline unsigned char
  182. ___sn_readb_relaxed (const volatile void __iomem *addr)
  183. {
  184. return *(volatile unsigned char __force *)addr;
  185. }
  186. static inline unsigned short
  187. ___sn_readw_relaxed (const volatile void __iomem *addr)
  188. {
  189. return *(volatile unsigned short __force *)addr;
  190. }
  191. static inline unsigned int
  192. ___sn_readl_relaxed (const volatile void __iomem *addr)
  193. {
  194. return *(volatile unsigned int __force *) addr;
  195. }
  196. static inline unsigned long
  197. ___sn_readq_relaxed (const volatile void __iomem *addr)
  198. {
  199. return *(volatile unsigned long __force *) addr;
  200. }
  201. struct pci_dev;
  202. static inline int
  203. sn_pci_set_vchan(struct pci_dev *pci_dev, unsigned long *addr, int vchan)
  204. {
  205. if (vchan > 1) {
  206. return -1;
  207. }
  208. if (!(*addr >> 32)) /* Using a mask here would be cleaner */
  209. return 0; /* but this generates better code */
  210. if (vchan == 1) {
  211. /* Set Bit 57 */
  212. *addr |= (1UL << 57);
  213. } else {
  214. /* Clear Bit 57 */
  215. *addr &= ~(1UL << 57);
  216. }
  217. return 0;
  218. }
  219. #endif /* _ASM_SN_IO_H */