dma.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* $Id: dma.h,v 1.2 1999/04/27 00:46:18 deller Exp $
  2. * linux/include/asm/dma.h: Defines for using and allocating dma channels.
  3. * Written by Hennus Bergman, 1992.
  4. * High DMA channel support & info by Hannu Savolainen
  5. * and John Boyd, Nov. 1992.
  6. * (c) Copyright 2000, Grant Grundler
  7. */
  8. #ifndef _ASM_DMA_H
  9. #define _ASM_DMA_H
  10. #include <linux/config.h>
  11. #include <asm/io.h> /* need byte IO */
  12. #include <asm/system.h>
  13. #define dma_outb outb
  14. #define dma_inb inb
  15. /*
  16. ** DMA_CHUNK_SIZE is used by the SCSI mid-layer to break up
  17. ** (or rather not merge) DMA's into managable chunks.
  18. ** On parisc, this is more of the software/tuning constraint
  19. ** rather than the HW. I/O MMU allocation alogorithms can be
  20. ** faster with smaller size is (to some degree).
  21. */
  22. #define DMA_CHUNK_SIZE (BITS_PER_LONG*PAGE_SIZE)
  23. /* The maximum address that we can perform a DMA transfer to on this platform
  24. ** New dynamic DMA interfaces should obsolete this....
  25. */
  26. #define MAX_DMA_ADDRESS (~0UL)
  27. /*
  28. ** We don't have DMA channels... well V-class does but the
  29. ** Dynamic DMA Mapping interface will support them... right? :^)
  30. ** Note: this is not relevant right now for PA-RISC, but we cannot
  31. ** leave this as undefined because some things (e.g. sound)
  32. ** won't compile :-(
  33. */
  34. #define MAX_DMA_CHANNELS 8
  35. #define DMA_MODE_READ 0x44 /* I/O to memory, no autoinit, increment, single mode */
  36. #define DMA_MODE_WRITE 0x48 /* memory to I/O, no autoinit, increment, single mode */
  37. #define DMA_MODE_CASCADE 0xC0 /* pass thru DREQ->HRQ, DACK<-HLDA only */
  38. #define DMA_AUTOINIT 0x10
  39. /* 8237 DMA controllers */
  40. #define IO_DMA1_BASE 0x00 /* 8 bit slave DMA, channels 0..3 */
  41. #define IO_DMA2_BASE 0xC0 /* 16 bit master DMA, ch 4(=slave input)..7 */
  42. /* DMA controller registers */
  43. #define DMA1_CMD_REG 0x08 /* command register (w) */
  44. #define DMA1_STAT_REG 0x08 /* status register (r) */
  45. #define DMA1_REQ_REG 0x09 /* request register (w) */
  46. #define DMA1_MASK_REG 0x0A /* single-channel mask (w) */
  47. #define DMA1_MODE_REG 0x0B /* mode register (w) */
  48. #define DMA1_CLEAR_FF_REG 0x0C /* clear pointer flip-flop (w) */
  49. #define DMA1_TEMP_REG 0x0D /* Temporary Register (r) */
  50. #define DMA1_RESET_REG 0x0D /* Master Clear (w) */
  51. #define DMA1_CLR_MASK_REG 0x0E /* Clear Mask */
  52. #define DMA1_MASK_ALL_REG 0x0F /* all-channels mask (w) */
  53. #define DMA1_EXT_MODE_REG (0x400 | DMA1_MODE_REG)
  54. #define DMA2_CMD_REG 0xD0 /* command register (w) */
  55. #define DMA2_STAT_REG 0xD0 /* status register (r) */
  56. #define DMA2_REQ_REG 0xD2 /* request register (w) */
  57. #define DMA2_MASK_REG 0xD4 /* single-channel mask (w) */
  58. #define DMA2_MODE_REG 0xD6 /* mode register (w) */
  59. #define DMA2_CLEAR_FF_REG 0xD8 /* clear pointer flip-flop (w) */
  60. #define DMA2_TEMP_REG 0xDA /* Temporary Register (r) */
  61. #define DMA2_RESET_REG 0xDA /* Master Clear (w) */
  62. #define DMA2_CLR_MASK_REG 0xDC /* Clear Mask */
  63. #define DMA2_MASK_ALL_REG 0xDE /* all-channels mask (w) */
  64. #define DMA2_EXT_MODE_REG (0x400 | DMA2_MODE_REG)
  65. extern spinlock_t dma_spin_lock;
  66. static __inline__ unsigned long claim_dma_lock(void)
  67. {
  68. unsigned long flags;
  69. spin_lock_irqsave(&dma_spin_lock, flags);
  70. return flags;
  71. }
  72. static __inline__ void release_dma_lock(unsigned long flags)
  73. {
  74. spin_unlock_irqrestore(&dma_spin_lock, flags);
  75. }
  76. /* Get DMA residue count. After a DMA transfer, this
  77. * should return zero. Reading this while a DMA transfer is
  78. * still in progress will return unpredictable results.
  79. * If called before the channel has been used, it may return 1.
  80. * Otherwise, it returns the number of _bytes_ left to transfer.
  81. *
  82. * Assumes DMA flip-flop is clear.
  83. */
  84. static __inline__ int get_dma_residue(unsigned int dmanr)
  85. {
  86. unsigned int io_port = (dmanr<=3)? ((dmanr&3)<<1) + 1 + IO_DMA1_BASE
  87. : ((dmanr&3)<<2) + 2 + IO_DMA2_BASE;
  88. /* using short to get 16-bit wrap around */
  89. unsigned short count;
  90. count = 1 + dma_inb(io_port);
  91. count += dma_inb(io_port) << 8;
  92. return (dmanr<=3)? count : (count<<1);
  93. }
  94. /* enable/disable a specific DMA channel */
  95. static __inline__ void enable_dma(unsigned int dmanr)
  96. {
  97. #ifdef CONFIG_SUPERIO
  98. if (dmanr<=3)
  99. dma_outb(dmanr, DMA1_MASK_REG);
  100. else
  101. dma_outb(dmanr & 3, DMA2_MASK_REG);
  102. #endif
  103. }
  104. static __inline__ void disable_dma(unsigned int dmanr)
  105. {
  106. #ifdef CONFIG_SUPERIO
  107. if (dmanr<=3)
  108. dma_outb(dmanr | 4, DMA1_MASK_REG);
  109. else
  110. dma_outb((dmanr & 3) | 4, DMA2_MASK_REG);
  111. #endif
  112. }
  113. /* reserve a DMA channel */
  114. #define request_dma(dmanr, device_id) (0)
  115. /* Clear the 'DMA Pointer Flip Flop'.
  116. * Write 0 for LSB/MSB, 1 for MSB/LSB access.
  117. * Use this once to initialize the FF to a known state.
  118. * After that, keep track of it. :-)
  119. * --- In order to do that, the DMA routines below should ---
  120. * --- only be used while holding the DMA lock ! ---
  121. */
  122. static __inline__ void clear_dma_ff(unsigned int dmanr)
  123. {
  124. }
  125. /* set mode (above) for a specific DMA channel */
  126. static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
  127. {
  128. }
  129. /* Set only the page register bits of the transfer address.
  130. * This is used for successive transfers when we know the contents of
  131. * the lower 16 bits of the DMA current address register, but a 64k boundary
  132. * may have been crossed.
  133. */
  134. static __inline__ void set_dma_page(unsigned int dmanr, char pagenr)
  135. {
  136. }
  137. /* Set transfer address & page bits for specific DMA channel.
  138. * Assumes dma flipflop is clear.
  139. */
  140. static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)
  141. {
  142. }
  143. /* Set transfer size (max 64k for DMA1..3, 128k for DMA5..7) for
  144. * a specific DMA channel.
  145. * You must ensure the parameters are valid.
  146. * NOTE: from a manual: "the number of transfers is one more
  147. * than the initial word count"! This is taken into account.
  148. * Assumes dma flip-flop is clear.
  149. * NOTE 2: "count" represents _bytes_ and must be even for channels 5-7.
  150. */
  151. static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
  152. {
  153. }
  154. #define free_dma(dmanr)
  155. #ifdef CONFIG_PCI
  156. extern int isa_dma_bridge_buggy;
  157. #else
  158. #define isa_dma_bridge_buggy (0)
  159. #endif
  160. #endif /* _ASM_DMA_H */