dma.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_ARM_DMA_H
  3. #define __ASM_ARM_DMA_H
  4. /*
  5. * This is the maximum virtual address which can be DMA'd from.
  6. */
  7. #ifndef CONFIG_ZONE_DMA
  8. #define MAX_DMA_ADDRESS 0xffffffffUL
  9. #else
  10. #define MAX_DMA_ADDRESS ({ \
  11. extern phys_addr_t arm_dma_zone_size; \
  12. arm_dma_zone_size && arm_dma_zone_size < (0x100000000ULL - PAGE_OFFSET) ? \
  13. (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; })
  14. #endif
  15. #ifdef CONFIG_ISA_DMA_API
  16. /*
  17. * This is used to support drivers written for the x86 ISA DMA API.
  18. * It should not be re-used except for that purpose.
  19. */
  20. #include <linux/spinlock.h>
  21. #include <linux/scatterlist.h>
  22. #include <mach/isa-dma.h>
  23. /*
  24. * The DMA modes reflect the settings for the ISA DMA controller
  25. */
  26. #define DMA_MODE_MASK 0xcc
  27. #define DMA_MODE_READ 0x44
  28. #define DMA_MODE_WRITE 0x48
  29. #define DMA_MODE_CASCADE 0xc0
  30. #define DMA_AUTOINIT 0x10
  31. extern raw_spinlock_t dma_spin_lock;
  32. static inline unsigned long claim_dma_lock(void)
  33. {
  34. unsigned long flags;
  35. raw_spin_lock_irqsave(&dma_spin_lock, flags);
  36. return flags;
  37. }
  38. static inline void release_dma_lock(unsigned long flags)
  39. {
  40. raw_spin_unlock_irqrestore(&dma_spin_lock, flags);
  41. }
  42. /* Clear the 'DMA Pointer Flip Flop'.
  43. * Write 0 for LSB/MSB, 1 for MSB/LSB access.
  44. */
  45. #define clear_dma_ff(chan)
  46. /* Set only the page register bits of the transfer address.
  47. *
  48. * NOTE: This is an architecture specific function, and should
  49. * be hidden from the drivers
  50. */
  51. extern void set_dma_page(unsigned int chan, char pagenr);
  52. /* Request a DMA channel
  53. *
  54. * Some architectures may need to do allocate an interrupt
  55. */
  56. extern int request_dma(unsigned int chan, const char * device_id);
  57. /* Free a DMA channel
  58. *
  59. * Some architectures may need to do free an interrupt
  60. */
  61. extern void free_dma(unsigned int chan);
  62. /* Enable DMA for this channel
  63. *
  64. * On some architectures, this may have other side effects like
  65. * enabling an interrupt and setting the DMA registers.
  66. */
  67. extern void enable_dma(unsigned int chan);
  68. /* Disable DMA for this channel
  69. *
  70. * On some architectures, this may have other side effects like
  71. * disabling an interrupt or whatever.
  72. */
  73. extern void disable_dma(unsigned int chan);
  74. /* Test whether the specified channel has an active DMA transfer
  75. */
  76. extern int dma_channel_active(unsigned int chan);
  77. /* Set the DMA scatter gather list for this channel
  78. *
  79. * This should not be called if a DMA channel is enabled,
  80. * especially since some DMA architectures don't update the
  81. * DMA address immediately, but defer it to the enable_dma().
  82. */
  83. extern void set_dma_sg(unsigned int chan, struct scatterlist *sg, int nr_sg);
  84. /* Set the DMA address for this channel
  85. *
  86. * This should not be called if a DMA channel is enabled,
  87. * especially since some DMA architectures don't update the
  88. * DMA address immediately, but defer it to the enable_dma().
  89. */
  90. extern void __set_dma_addr(unsigned int chan, void *addr);
  91. #define set_dma_addr(chan, addr) \
  92. __set_dma_addr(chan, (void *)isa_bus_to_virt(addr))
  93. /* Set the DMA byte count for this channel
  94. *
  95. * This should not be called if a DMA channel is enabled,
  96. * especially since some DMA architectures don't update the
  97. * DMA count immediately, but defer it to the enable_dma().
  98. */
  99. extern void set_dma_count(unsigned int chan, unsigned long count);
  100. /* Set the transfer direction for this channel
  101. *
  102. * This should not be called if a DMA channel is enabled,
  103. * especially since some DMA architectures don't update the
  104. * DMA transfer direction immediately, but defer it to the
  105. * enable_dma().
  106. */
  107. extern void set_dma_mode(unsigned int chan, unsigned int mode);
  108. /* Set the transfer speed for this channel
  109. */
  110. extern void set_dma_speed(unsigned int chan, int cycle_ns);
  111. /* Get DMA residue count. After a DMA transfer, this
  112. * should return zero. Reading this while a DMA transfer is
  113. * still in progress will return unpredictable results.
  114. * If called before the channel has been used, it may return 1.
  115. * Otherwise, it returns the number of _bytes_ left to transfer.
  116. */
  117. extern int get_dma_residue(unsigned int chan);
  118. #ifndef NO_DMA
  119. #define NO_DMA 255
  120. #endif
  121. #endif /* CONFIG_ISA_DMA_API */
  122. #endif /* __ASM_ARM_DMA_H */