nsp_io.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. NinjaSCSI I/O funtions
  3. By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
  4. This software may be used and distributed according to the terms of
  5. the GNU General Public License.
  6. */
  7. /* $Id: nsp_io.h,v 1.3 2003/08/04 21:15:26 elca Exp $ */
  8. #ifndef __NSP_IO_H__
  9. #define __NSP_IO_H__
  10. static inline void nsp_write(unsigned int base,
  11. unsigned int index,
  12. unsigned char val);
  13. static inline unsigned char nsp_read(unsigned int base,
  14. unsigned int index);
  15. static inline void nsp_index_write(unsigned int BaseAddr,
  16. unsigned int Register,
  17. unsigned char Value);
  18. static inline unsigned char nsp_index_read(unsigned int BaseAddr,
  19. unsigned int Register);
  20. /*******************************************************************
  21. * Basic IO
  22. */
  23. static inline void nsp_write(unsigned int base,
  24. unsigned int index,
  25. unsigned char val)
  26. {
  27. outb(val, (base + index));
  28. }
  29. static inline unsigned char nsp_read(unsigned int base,
  30. unsigned int index)
  31. {
  32. return inb(base + index);
  33. }
  34. /**********************************************************************
  35. * Indexed IO
  36. */
  37. static inline unsigned char nsp_index_read(unsigned int BaseAddr,
  38. unsigned int Register)
  39. {
  40. outb(Register, BaseAddr + INDEXREG);
  41. return inb(BaseAddr + DATAREG);
  42. }
  43. static inline void nsp_index_write(unsigned int BaseAddr,
  44. unsigned int Register,
  45. unsigned char Value)
  46. {
  47. outb(Register, BaseAddr + INDEXREG);
  48. outb(Value, BaseAddr + DATAREG);
  49. }
  50. /*********************************************************************
  51. * fifo func
  52. */
  53. /* read 8 bit FIFO */
  54. static inline void nsp_multi_read_1(unsigned int BaseAddr,
  55. unsigned int Register,
  56. void *buf,
  57. unsigned long count)
  58. {
  59. insb(BaseAddr + Register, buf, count);
  60. }
  61. static inline void nsp_fifo8_read(unsigned int base,
  62. void *buf,
  63. unsigned long count)
  64. {
  65. /*nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx", buf, count);*/
  66. nsp_multi_read_1(base, FIFODATA, buf, count);
  67. }
  68. /*--------------------------------------------------------------*/
  69. /* read 16 bit FIFO */
  70. static inline void nsp_multi_read_2(unsigned int BaseAddr,
  71. unsigned int Register,
  72. void *buf,
  73. unsigned long count)
  74. {
  75. insw(BaseAddr + Register, buf, count);
  76. }
  77. static inline void nsp_fifo16_read(unsigned int base,
  78. void *buf,
  79. unsigned long count)
  80. {
  81. //nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx*2", buf, count);
  82. nsp_multi_read_2(base, FIFODATA, buf, count);
  83. }
  84. /*--------------------------------------------------------------*/
  85. /* read 32bit FIFO */
  86. static inline void nsp_multi_read_4(unsigned int BaseAddr,
  87. unsigned int Register,
  88. void *buf,
  89. unsigned long count)
  90. {
  91. insl(BaseAddr + Register, buf, count);
  92. }
  93. static inline void nsp_fifo32_read(unsigned int base,
  94. void *buf,
  95. unsigned long count)
  96. {
  97. //nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx*4", buf, count);
  98. nsp_multi_read_4(base, FIFODATA, buf, count);
  99. }
  100. /*----------------------------------------------------------*/
  101. /* write 8bit FIFO */
  102. static inline void nsp_multi_write_1(unsigned int BaseAddr,
  103. unsigned int Register,
  104. void *buf,
  105. unsigned long count)
  106. {
  107. outsb(BaseAddr + Register, buf, count);
  108. }
  109. static inline void nsp_fifo8_write(unsigned int base,
  110. void *buf,
  111. unsigned long count)
  112. {
  113. nsp_multi_write_1(base, FIFODATA, buf, count);
  114. }
  115. /*---------------------------------------------------------*/
  116. /* write 16bit FIFO */
  117. static inline void nsp_multi_write_2(unsigned int BaseAddr,
  118. unsigned int Register,
  119. void *buf,
  120. unsigned long count)
  121. {
  122. outsw(BaseAddr + Register, buf, count);
  123. }
  124. static inline void nsp_fifo16_write(unsigned int base,
  125. void *buf,
  126. unsigned long count)
  127. {
  128. nsp_multi_write_2(base, FIFODATA, buf, count);
  129. }
  130. /*---------------------------------------------------------*/
  131. /* write 32bit FIFO */
  132. static inline void nsp_multi_write_4(unsigned int BaseAddr,
  133. unsigned int Register,
  134. void *buf,
  135. unsigned long count)
  136. {
  137. outsl(BaseAddr + Register, buf, count);
  138. }
  139. static inline void nsp_fifo32_write(unsigned int base,
  140. void *buf,
  141. unsigned long count)
  142. {
  143. nsp_multi_write_4(base, FIFODATA, buf, count);
  144. }
  145. /*====================================================================*/
  146. static inline void nsp_mmio_write(unsigned long base,
  147. unsigned int index,
  148. unsigned char val)
  149. {
  150. unsigned char *ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + index);
  151. writeb(val, ptr);
  152. }
  153. static inline unsigned char nsp_mmio_read(unsigned long base,
  154. unsigned int index)
  155. {
  156. unsigned char *ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + index);
  157. return readb(ptr);
  158. }
  159. /*-----------*/
  160. static inline unsigned char nsp_mmio_index_read(unsigned long base,
  161. unsigned int reg)
  162. {
  163. unsigned char *index_ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + INDEXREG);
  164. unsigned char *data_ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + DATAREG);
  165. writeb((unsigned char)reg, index_ptr);
  166. return readb(data_ptr);
  167. }
  168. static inline void nsp_mmio_index_write(unsigned long base,
  169. unsigned int reg,
  170. unsigned char val)
  171. {
  172. unsigned char *index_ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + INDEXREG);
  173. unsigned char *data_ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + DATAREG);
  174. writeb((unsigned char)reg, index_ptr);
  175. writeb(val, data_ptr);
  176. }
  177. /* read 32bit FIFO */
  178. static inline void nsp_mmio_multi_read_4(unsigned long base,
  179. unsigned int Register,
  180. void *buf,
  181. unsigned long count)
  182. {
  183. unsigned long *ptr = (unsigned long *)(base + Register);
  184. unsigned long *tmp = (unsigned long *)buf;
  185. int i;
  186. //nsp_dbg(NSP_DEBUG_DATA_IO, "base 0x%0lx ptr 0x%p",base,ptr);
  187. for (i = 0; i < count; i++) {
  188. *tmp = readl(ptr);
  189. //nsp_dbg(NSP_DEBUG_DATA_IO, "<%d,%p,%p,%lx>", i, ptr, tmp, *tmp);
  190. tmp++;
  191. }
  192. }
  193. static inline void nsp_mmio_fifo32_read(unsigned int base,
  194. void *buf,
  195. unsigned long count)
  196. {
  197. //nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx*4", buf, count);
  198. nsp_mmio_multi_read_4(base, FIFODATA, buf, count);
  199. }
  200. static inline void nsp_mmio_multi_write_4(unsigned long base,
  201. unsigned int Register,
  202. void *buf,
  203. unsigned long count)
  204. {
  205. unsigned long *ptr = (unsigned long *)(base + Register);
  206. unsigned long *tmp = (unsigned long *)buf;
  207. int i;
  208. //nsp_dbg(NSP_DEBUG_DATA_IO, "base 0x%0lx ptr 0x%p",base,ptr);
  209. for (i = 0; i < count; i++) {
  210. writel(*tmp, ptr);
  211. //nsp_dbg(NSP_DEBUG_DATA_IO, "<%d,%p,%p,%lx>", i, ptr, tmp, *tmp);
  212. tmp++;
  213. }
  214. }
  215. static inline void nsp_mmio_fifo32_write(unsigned int base,
  216. void *buf,
  217. unsigned long count)
  218. {
  219. //nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx*4", buf, count);
  220. nsp_mmio_multi_write_4(base, FIFODATA, buf, count);
  221. }
  222. #endif
  223. /* end */