mca_dma.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #ifndef _ASM_X86_MCA_DMA_H
  2. #define _ASM_X86_MCA_DMA_H
  3. #include <asm/io.h>
  4. #include <linux/ioport.h>
  5. /*
  6. * Microchannel specific DMA stuff. DMA on an MCA machine is fairly similar to
  7. * standard PC dma, but it certainly has its quirks. DMA register addresses
  8. * are in a different place and there are some added functions. Most of this
  9. * should be pretty obvious on inspection. Note that the user must divide
  10. * count by 2 when using 16-bit dma; that is not handled by these functions.
  11. *
  12. * Ramen Noodles are yummy.
  13. *
  14. * 1998 Tymm Twillman <tymm@computer.org>
  15. */
  16. /*
  17. * Registers that are used by the DMA controller; FN is the function register
  18. * (tell the controller what to do) and EXE is the execution register (how
  19. * to do it)
  20. */
  21. #define MCA_DMA_REG_FN 0x18
  22. #define MCA_DMA_REG_EXE 0x1A
  23. /*
  24. * Functions that the DMA controller can do
  25. */
  26. #define MCA_DMA_FN_SET_IO 0x00
  27. #define MCA_DMA_FN_SET_ADDR 0x20
  28. #define MCA_DMA_FN_GET_ADDR 0x30
  29. #define MCA_DMA_FN_SET_COUNT 0x40
  30. #define MCA_DMA_FN_GET_COUNT 0x50
  31. #define MCA_DMA_FN_GET_STATUS 0x60
  32. #define MCA_DMA_FN_SET_MODE 0x70
  33. #define MCA_DMA_FN_SET_ARBUS 0x80
  34. #define MCA_DMA_FN_MASK 0x90
  35. #define MCA_DMA_FN_RESET_MASK 0xA0
  36. #define MCA_DMA_FN_MASTER_CLEAR 0xD0
  37. /*
  38. * Modes (used by setting MCA_DMA_FN_MODE in the function register)
  39. *
  40. * Note that the MODE_READ is read from memory (write to device), and
  41. * MODE_WRITE is vice-versa.
  42. */
  43. #define MCA_DMA_MODE_XFER 0x04 /* read by default */
  44. #define MCA_DMA_MODE_READ 0x04 /* same as XFER */
  45. #define MCA_DMA_MODE_WRITE 0x08 /* OR with MODE_XFER to use */
  46. #define MCA_DMA_MODE_IO 0x01 /* DMA from IO register */
  47. #define MCA_DMA_MODE_16 0x40 /* 16 bit xfers */
  48. /**
  49. * mca_enable_dma - channel to enable DMA on
  50. * @dmanr: DMA channel
  51. *
  52. * Enable the MCA bus DMA on a channel. This can be called from
  53. * IRQ context.
  54. */
  55. static inline void mca_enable_dma(unsigned int dmanr)
  56. {
  57. outb(MCA_DMA_FN_RESET_MASK | dmanr, MCA_DMA_REG_FN);
  58. }
  59. /**
  60. * mca_disble_dma - channel to disable DMA on
  61. * @dmanr: DMA channel
  62. *
  63. * Enable the MCA bus DMA on a channel. This can be called from
  64. * IRQ context.
  65. */
  66. static inline void mca_disable_dma(unsigned int dmanr)
  67. {
  68. outb(MCA_DMA_FN_MASK | dmanr, MCA_DMA_REG_FN);
  69. }
  70. /**
  71. * mca_set_dma_addr - load a 24bit DMA address
  72. * @dmanr: DMA channel
  73. * @a: 24bit bus address
  74. *
  75. * Load the address register in the DMA controller. This has a 24bit
  76. * limitation (16Mb).
  77. */
  78. static inline void mca_set_dma_addr(unsigned int dmanr, unsigned int a)
  79. {
  80. outb(MCA_DMA_FN_SET_ADDR | dmanr, MCA_DMA_REG_FN);
  81. outb(a & 0xff, MCA_DMA_REG_EXE);
  82. outb((a >> 8) & 0xff, MCA_DMA_REG_EXE);
  83. outb((a >> 16) & 0xff, MCA_DMA_REG_EXE);
  84. }
  85. /**
  86. * mca_get_dma_addr - load a 24bit DMA address
  87. * @dmanr: DMA channel
  88. *
  89. * Read the address register in the DMA controller. This has a 24bit
  90. * limitation (16Mb). The return is a bus address.
  91. */
  92. static inline unsigned int mca_get_dma_addr(unsigned int dmanr)
  93. {
  94. unsigned int addr;
  95. outb(MCA_DMA_FN_GET_ADDR | dmanr, MCA_DMA_REG_FN);
  96. addr = inb(MCA_DMA_REG_EXE);
  97. addr |= inb(MCA_DMA_REG_EXE) << 8;
  98. addr |= inb(MCA_DMA_REG_EXE) << 16;
  99. return addr;
  100. }
  101. /**
  102. * mca_set_dma_count - load a 16bit transfer count
  103. * @dmanr: DMA channel
  104. * @count: count
  105. *
  106. * Set the DMA count for this channel. This can be up to 64Kbytes.
  107. * Setting a count of zero will not do what you expect.
  108. */
  109. static inline void mca_set_dma_count(unsigned int dmanr, unsigned int count)
  110. {
  111. count--; /* transfers one more than count -- correct for this */
  112. outb(MCA_DMA_FN_SET_COUNT | dmanr, MCA_DMA_REG_FN);
  113. outb(count & 0xff, MCA_DMA_REG_EXE);
  114. outb((count >> 8) & 0xff, MCA_DMA_REG_EXE);
  115. }
  116. /**
  117. * mca_get_dma_residue - get the remaining bytes to transfer
  118. * @dmanr: DMA channel
  119. *
  120. * This function returns the number of bytes left to transfer
  121. * on this DMA channel.
  122. */
  123. static inline unsigned int mca_get_dma_residue(unsigned int dmanr)
  124. {
  125. unsigned short count;
  126. outb(MCA_DMA_FN_GET_COUNT | dmanr, MCA_DMA_REG_FN);
  127. count = 1 + inb(MCA_DMA_REG_EXE);
  128. count += inb(MCA_DMA_REG_EXE) << 8;
  129. return count;
  130. }
  131. /**
  132. * mca_set_dma_io - set the port for an I/O transfer
  133. * @dmanr: DMA channel
  134. * @io_addr: an I/O port number
  135. *
  136. * Unlike the ISA bus DMA controllers the DMA on MCA bus can transfer
  137. * with an I/O port target.
  138. */
  139. static inline void mca_set_dma_io(unsigned int dmanr, unsigned int io_addr)
  140. {
  141. /*
  142. * DMA from a port address -- set the io address
  143. */
  144. outb(MCA_DMA_FN_SET_IO | dmanr, MCA_DMA_REG_FN);
  145. outb(io_addr & 0xff, MCA_DMA_REG_EXE);
  146. outb((io_addr >> 8) & 0xff, MCA_DMA_REG_EXE);
  147. }
  148. /**
  149. * mca_set_dma_mode - set the DMA mode
  150. * @dmanr: DMA channel
  151. * @mode: mode to set
  152. *
  153. * The DMA controller supports several modes. The mode values you can
  154. * set are-
  155. *
  156. * %MCA_DMA_MODE_READ when reading from the DMA device.
  157. *
  158. * %MCA_DMA_MODE_WRITE to writing to the DMA device.
  159. *
  160. * %MCA_DMA_MODE_IO to do DMA to or from an I/O port.
  161. *
  162. * %MCA_DMA_MODE_16 to do 16bit transfers.
  163. */
  164. static inline void mca_set_dma_mode(unsigned int dmanr, unsigned int mode)
  165. {
  166. outb(MCA_DMA_FN_SET_MODE | dmanr, MCA_DMA_REG_FN);
  167. outb(mode, MCA_DMA_REG_EXE);
  168. }
  169. #endif /* _ASM_X86_MCA_DMA_H */