idma64.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Driver for the Intel integrated DMA 64-bit
  3. *
  4. * Copyright (C) 2015 Intel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef __DMA_IDMA64_H__
  11. #define __DMA_IDMA64_H__
  12. #include <linux/device.h>
  13. #include <linux/io.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/types.h>
  16. #include <linux/io-64-nonatomic-lo-hi.h>
  17. #include "virt-dma.h"
  18. /* Channel registers */
  19. #define IDMA64_CH_SAR 0x00 /* Source Address Register */
  20. #define IDMA64_CH_DAR 0x08 /* Destination Address Register */
  21. #define IDMA64_CH_LLP 0x10 /* Linked List Pointer */
  22. #define IDMA64_CH_CTL_LO 0x18 /* Control Register Low */
  23. #define IDMA64_CH_CTL_HI 0x1c /* Control Register High */
  24. #define IDMA64_CH_SSTAT 0x20
  25. #define IDMA64_CH_DSTAT 0x28
  26. #define IDMA64_CH_SSTATAR 0x30
  27. #define IDMA64_CH_DSTATAR 0x38
  28. #define IDMA64_CH_CFG_LO 0x40 /* Configuration Register Low */
  29. #define IDMA64_CH_CFG_HI 0x44 /* Configuration Register High */
  30. #define IDMA64_CH_SGR 0x48
  31. #define IDMA64_CH_DSR 0x50
  32. #define IDMA64_CH_LENGTH 0x58
  33. /* Bitfields in CTL_LO */
  34. #define IDMA64C_CTLL_INT_EN (1 << 0) /* irqs enabled? */
  35. #define IDMA64C_CTLL_DST_WIDTH(x) ((x) << 1) /* bytes per element */
  36. #define IDMA64C_CTLL_SRC_WIDTH(x) ((x) << 4)
  37. #define IDMA64C_CTLL_DST_INC (0 << 8) /* DAR update/not */
  38. #define IDMA64C_CTLL_DST_FIX (1 << 8)
  39. #define IDMA64C_CTLL_SRC_INC (0 << 10) /* SAR update/not */
  40. #define IDMA64C_CTLL_SRC_FIX (1 << 10)
  41. #define IDMA64C_CTLL_DST_MSIZE(x) ((x) << 11) /* burst, #elements */
  42. #define IDMA64C_CTLL_SRC_MSIZE(x) ((x) << 14)
  43. #define IDMA64C_CTLL_FC_M2P (1 << 20) /* mem-to-periph */
  44. #define IDMA64C_CTLL_FC_P2M (2 << 20) /* periph-to-mem */
  45. #define IDMA64C_CTLL_LLP_D_EN (1 << 27) /* dest block chain */
  46. #define IDMA64C_CTLL_LLP_S_EN (1 << 28) /* src block chain */
  47. /* Bitfields in CTL_HI */
  48. #define IDMA64C_CTLH_BLOCK_TS_MASK ((1 << 17) - 1)
  49. #define IDMA64C_CTLH_BLOCK_TS(x) ((x) & IDMA64C_CTLH_BLOCK_TS_MASK)
  50. #define IDMA64C_CTLH_DONE (1 << 17)
  51. /* Bitfields in CFG_LO */
  52. #define IDMA64C_CFGL_DST_BURST_ALIGN (1 << 0) /* dst burst align */
  53. #define IDMA64C_CFGL_SRC_BURST_ALIGN (1 << 1) /* src burst align */
  54. #define IDMA64C_CFGL_CH_SUSP (1 << 8)
  55. #define IDMA64C_CFGL_FIFO_EMPTY (1 << 9)
  56. #define IDMA64C_CFGL_CH_DRAIN (1 << 10) /* drain FIFO */
  57. #define IDMA64C_CFGL_DST_OPT_BL (1 << 20) /* optimize dst burst length */
  58. #define IDMA64C_CFGL_SRC_OPT_BL (1 << 21) /* optimize src burst length */
  59. /* Bitfields in CFG_HI */
  60. #define IDMA64C_CFGH_SRC_PER(x) ((x) << 0) /* src peripheral */
  61. #define IDMA64C_CFGH_DST_PER(x) ((x) << 4) /* dst peripheral */
  62. #define IDMA64C_CFGH_RD_ISSUE_THD(x) ((x) << 8)
  63. #define IDMA64C_CFGH_WR_ISSUE_THD(x) ((x) << 18)
  64. /* Interrupt registers */
  65. #define IDMA64_INT_XFER 0x00
  66. #define IDMA64_INT_BLOCK 0x08
  67. #define IDMA64_INT_SRC_TRAN 0x10
  68. #define IDMA64_INT_DST_TRAN 0x18
  69. #define IDMA64_INT_ERROR 0x20
  70. #define IDMA64_RAW(x) (0x2c0 + IDMA64_INT_##x) /* r */
  71. #define IDMA64_STATUS(x) (0x2e8 + IDMA64_INT_##x) /* r (raw & mask) */
  72. #define IDMA64_MASK(x) (0x310 + IDMA64_INT_##x) /* rw (set = irq enabled) */
  73. #define IDMA64_CLEAR(x) (0x338 + IDMA64_INT_##x) /* w (ack, affects "raw") */
  74. /* Common registers */
  75. #define IDMA64_STATUS_INT 0x360 /* r */
  76. #define IDMA64_CFG 0x398
  77. #define IDMA64_CH_EN 0x3a0
  78. /* Bitfields in CFG */
  79. #define IDMA64_CFG_DMA_EN (1 << 0)
  80. /* Hardware descriptor for Linked LIst transfers */
  81. struct idma64_lli {
  82. u64 sar;
  83. u64 dar;
  84. u64 llp;
  85. u32 ctllo;
  86. u32 ctlhi;
  87. u32 sstat;
  88. u32 dstat;
  89. };
  90. struct idma64_hw_desc {
  91. struct idma64_lli *lli;
  92. dma_addr_t llp;
  93. dma_addr_t phys;
  94. unsigned int len;
  95. };
  96. struct idma64_desc {
  97. struct virt_dma_desc vdesc;
  98. enum dma_transfer_direction direction;
  99. struct idma64_hw_desc *hw;
  100. unsigned int ndesc;
  101. size_t length;
  102. enum dma_status status;
  103. };
  104. static inline struct idma64_desc *to_idma64_desc(struct virt_dma_desc *vdesc)
  105. {
  106. return container_of(vdesc, struct idma64_desc, vdesc);
  107. }
  108. struct idma64_chan {
  109. struct virt_dma_chan vchan;
  110. void __iomem *regs;
  111. /* hardware configuration */
  112. enum dma_transfer_direction direction;
  113. unsigned int mask;
  114. struct dma_slave_config config;
  115. void *pool;
  116. struct idma64_desc *desc;
  117. };
  118. static inline struct idma64_chan *to_idma64_chan(struct dma_chan *chan)
  119. {
  120. return container_of(chan, struct idma64_chan, vchan.chan);
  121. }
  122. #define channel_set_bit(idma64, reg, mask) \
  123. dma_writel(idma64, reg, ((mask) << 8) | (mask))
  124. #define channel_clear_bit(idma64, reg, mask) \
  125. dma_writel(idma64, reg, ((mask) << 8) | 0)
  126. static inline u32 idma64c_readl(struct idma64_chan *idma64c, int offset)
  127. {
  128. return readl(idma64c->regs + offset);
  129. }
  130. static inline void idma64c_writel(struct idma64_chan *idma64c, int offset,
  131. u32 value)
  132. {
  133. writel(value, idma64c->regs + offset);
  134. }
  135. #define channel_readl(idma64c, reg) \
  136. idma64c_readl(idma64c, IDMA64_CH_##reg)
  137. #define channel_writel(idma64c, reg, value) \
  138. idma64c_writel(idma64c, IDMA64_CH_##reg, (value))
  139. static inline u64 idma64c_readq(struct idma64_chan *idma64c, int offset)
  140. {
  141. return lo_hi_readq(idma64c->regs + offset);
  142. }
  143. static inline void idma64c_writeq(struct idma64_chan *idma64c, int offset,
  144. u64 value)
  145. {
  146. lo_hi_writeq(value, idma64c->regs + offset);
  147. }
  148. #define channel_readq(idma64c, reg) \
  149. idma64c_readq(idma64c, IDMA64_CH_##reg)
  150. #define channel_writeq(idma64c, reg, value) \
  151. idma64c_writeq(idma64c, IDMA64_CH_##reg, (value))
  152. struct idma64 {
  153. struct dma_device dma;
  154. void __iomem *regs;
  155. /* channels */
  156. unsigned short all_chan_mask;
  157. struct idma64_chan *chan;
  158. };
  159. static inline struct idma64 *to_idma64(struct dma_device *ddev)
  160. {
  161. return container_of(ddev, struct idma64, dma);
  162. }
  163. static inline u32 idma64_readl(struct idma64 *idma64, int offset)
  164. {
  165. return readl(idma64->regs + offset);
  166. }
  167. static inline void idma64_writel(struct idma64 *idma64, int offset, u32 value)
  168. {
  169. writel(value, idma64->regs + offset);
  170. }
  171. #define dma_readl(idma64, reg) \
  172. idma64_readl(idma64, IDMA64_##reg)
  173. #define dma_writel(idma64, reg, value) \
  174. idma64_writel(idma64, IDMA64_##reg, (value))
  175. /**
  176. * struct idma64_chip - representation of iDMA 64-bit controller hardware
  177. * @dev: struct device of the DMA controller
  178. * @sysdev: struct device of the physical device that does DMA
  179. * @irq: irq line
  180. * @regs: memory mapped I/O space
  181. * @idma64: struct idma64 that is filed by idma64_probe()
  182. */
  183. struct idma64_chip {
  184. struct device *dev;
  185. struct device *sysdev;
  186. int irq;
  187. void __iomem *regs;
  188. struct idma64 *idma64;
  189. };
  190. #endif /* __DMA_IDMA64_H__ */