dma.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #ifndef __ASM_ARM_DMA_H
  2. #define __ASM_ARM_DMA_H
  3. typedef unsigned int dmach_t;
  4. #include <linux/config.h>
  5. #include <linux/spinlock.h>
  6. #include <asm/system.h>
  7. #include <asm/memory.h>
  8. #include <asm/scatterlist.h>
  9. // FIXME - do we really need this? arm26 cant do 'proper' DMA
  10. typedef struct dma_struct dma_t;
  11. typedef unsigned int dmamode_t;
  12. struct dma_ops {
  13. int (*request)(dmach_t, dma_t *); /* optional */
  14. void (*free)(dmach_t, dma_t *); /* optional */
  15. void (*enable)(dmach_t, dma_t *); /* mandatory */
  16. void (*disable)(dmach_t, dma_t *); /* mandatory */
  17. int (*residue)(dmach_t, dma_t *); /* optional */
  18. int (*setspeed)(dmach_t, dma_t *, int); /* optional */
  19. char *type;
  20. };
  21. struct dma_struct {
  22. struct scatterlist buf; /* single DMA */
  23. int sgcount; /* number of DMA SG */
  24. struct scatterlist *sg; /* DMA Scatter-Gather List */
  25. unsigned int active:1; /* Transfer active */
  26. unsigned int invalid:1; /* Address/Count changed */
  27. unsigned int using_sg:1; /* using scatter list? */
  28. dmamode_t dma_mode; /* DMA mode */
  29. int speed; /* DMA speed */
  30. unsigned int lock; /* Device is allocated */
  31. const char *device_id; /* Device name */
  32. unsigned int dma_base; /* Controller base address */
  33. int dma_irq; /* Controller IRQ */
  34. int state; /* Controller state */
  35. struct scatterlist cur_sg; /* Current controller buffer */
  36. struct dma_ops *d_ops;
  37. };
  38. /* Prototype: void arch_dma_init(dma)
  39. * Purpose : Initialise architecture specific DMA
  40. * Params : dma - pointer to array of DMA structures
  41. */
  42. extern void arch_dma_init(dma_t *dma);
  43. extern void isa_init_dma(dma_t *dma);
  44. #define MAX_DMA_ADDRESS 0x03000000
  45. #define MAX_DMA_CHANNELS 3
  46. /* ARC */
  47. #define DMA_VIRTUAL_FLOPPY0 0
  48. #define DMA_VIRTUAL_FLOPPY1 1
  49. #define DMA_VIRTUAL_SOUND 2
  50. /* A5K */
  51. #define DMA_FLOPPY 0
  52. /*
  53. * DMA modes
  54. */
  55. #define DMA_MODE_MASK 3
  56. #define DMA_MODE_READ 0
  57. #define DMA_MODE_WRITE 1
  58. #define DMA_MODE_CASCADE 2
  59. #define DMA_AUTOINIT 4
  60. extern spinlock_t dma_spin_lock;
  61. static inline unsigned long claim_dma_lock(void)
  62. {
  63. unsigned long flags;
  64. spin_lock_irqsave(&dma_spin_lock, flags);
  65. return flags;
  66. }
  67. static inline void release_dma_lock(unsigned long flags)
  68. {
  69. spin_unlock_irqrestore(&dma_spin_lock, flags);
  70. }
  71. /* Clear the 'DMA Pointer Flip Flop'.
  72. * Write 0 for LSB/MSB, 1 for MSB/LSB access.
  73. */
  74. #define clear_dma_ff(channel)
  75. /* Set only the page register bits of the transfer address.
  76. *
  77. * NOTE: This is an architecture specific function, and should
  78. * be hidden from the drivers
  79. */
  80. extern void set_dma_page(dmach_t channel, char pagenr);
  81. /* Request a DMA channel
  82. *
  83. * Some architectures may need to do allocate an interrupt
  84. */
  85. extern int request_dma(dmach_t channel, const char * device_id);
  86. /* Free a DMA channel
  87. *
  88. * Some architectures may need to do free an interrupt
  89. */
  90. extern void free_dma(dmach_t channel);
  91. /* Enable DMA for this channel
  92. *
  93. * On some architectures, this may have other side effects like
  94. * enabling an interrupt and setting the DMA registers.
  95. */
  96. extern void enable_dma(dmach_t channel);
  97. /* Disable DMA for this channel
  98. *
  99. * On some architectures, this may have other side effects like
  100. * disabling an interrupt or whatever.
  101. */
  102. extern void disable_dma(dmach_t channel);
  103. /* Test whether the specified channel has an active DMA transfer
  104. */
  105. extern int dma_channel_active(dmach_t channel);
  106. /* Set the DMA scatter gather list for this channel
  107. *
  108. * This should not be called if a DMA channel is enabled,
  109. * especially since some DMA architectures don't update the
  110. * DMA address immediately, but defer it to the enable_dma().
  111. */
  112. extern void set_dma_sg(dmach_t channel, struct scatterlist *sg, int nr_sg);
  113. /* Set the DMA address for this channel
  114. *
  115. * This should not be called if a DMA channel is enabled,
  116. * especially since some DMA architectures don't update the
  117. * DMA address immediately, but defer it to the enable_dma().
  118. */
  119. extern void set_dma_addr(dmach_t channel, unsigned long physaddr);
  120. /* Set the DMA byte count for this channel
  121. *
  122. * This should not be called if a DMA channel is enabled,
  123. * especially since some DMA architectures don't update the
  124. * DMA count immediately, but defer it to the enable_dma().
  125. */
  126. extern void set_dma_count(dmach_t channel, unsigned long count);
  127. /* Set the transfer direction for this channel
  128. *
  129. * This should not be called if a DMA channel is enabled,
  130. * especially since some DMA architectures don't update the
  131. * DMA transfer direction immediately, but defer it to the
  132. * enable_dma().
  133. */
  134. extern void set_dma_mode(dmach_t channel, dmamode_t mode);
  135. /* Set the transfer speed for this channel
  136. */
  137. extern void set_dma_speed(dmach_t channel, int cycle_ns);
  138. /* Get DMA residue count. After a DMA transfer, this
  139. * should return zero. Reading this while a DMA transfer is
  140. * still in progress will return unpredictable results.
  141. * If called before the channel has been used, it may return 1.
  142. * Otherwise, it returns the number of _bytes_ left to transfer.
  143. */
  144. extern int get_dma_residue(dmach_t channel);
  145. #ifndef NO_DMA
  146. #define NO_DMA 255
  147. #endif
  148. #endif /* _ARM_DMA_H */