skl-sst-cldma.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Intel Code Loader DMA support
  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 as version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #ifndef SKL_SST_CLDMA_H_
  16. #define SKL_SST_CLDMA_H_
  17. #define FW_CL_STREAM_NUMBER 0x1
  18. #define DMA_ADDRESS_128_BITS_ALIGNMENT 7
  19. #define BDL_ALIGN(x) (x >> DMA_ADDRESS_128_BITS_ALIGNMENT)
  20. #define SKL_ADSPIC_CL_DMA 0x2
  21. #define SKL_ADSPIS_CL_DMA 0x2
  22. #define SKL_CL_DMA_SD_INT_DESC_ERR 0x10 /* Descriptor error interrupt */
  23. #define SKL_CL_DMA_SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
  24. #define SKL_CL_DMA_SD_INT_COMPLETE 0x04 /* Buffer completion interrupt */
  25. /* Intel HD Audio Code Loader DMA Registers */
  26. #define HDA_ADSP_LOADER_BASE 0x80
  27. /* Stream Registers */
  28. #define SKL_ADSP_REG_CL_SD_CTL (HDA_ADSP_LOADER_BASE + 0x00)
  29. #define SKL_ADSP_REG_CL_SD_STS (HDA_ADSP_LOADER_BASE + 0x03)
  30. #define SKL_ADSP_REG_CL_SD_LPIB (HDA_ADSP_LOADER_BASE + 0x04)
  31. #define SKL_ADSP_REG_CL_SD_CBL (HDA_ADSP_LOADER_BASE + 0x08)
  32. #define SKL_ADSP_REG_CL_SD_LVI (HDA_ADSP_LOADER_BASE + 0x0c)
  33. #define SKL_ADSP_REG_CL_SD_FIFOW (HDA_ADSP_LOADER_BASE + 0x0e)
  34. #define SKL_ADSP_REG_CL_SD_FIFOSIZE (HDA_ADSP_LOADER_BASE + 0x10)
  35. #define SKL_ADSP_REG_CL_SD_FORMAT (HDA_ADSP_LOADER_BASE + 0x12)
  36. #define SKL_ADSP_REG_CL_SD_FIFOL (HDA_ADSP_LOADER_BASE + 0x14)
  37. #define SKL_ADSP_REG_CL_SD_BDLPL (HDA_ADSP_LOADER_BASE + 0x18)
  38. #define SKL_ADSP_REG_CL_SD_BDLPU (HDA_ADSP_LOADER_BASE + 0x1c)
  39. /* CL: Software Position Based FIFO Capability Registers */
  40. #define SKL_ADSP_REG_CL_SPBFIFO (HDA_ADSP_LOADER_BASE + 0x20)
  41. #define SKL_ADSP_REG_CL_SPBFIFO_SPBFCH (SKL_ADSP_REG_CL_SPBFIFO + 0x0)
  42. #define SKL_ADSP_REG_CL_SPBFIFO_SPBFCCTL (SKL_ADSP_REG_CL_SPBFIFO + 0x4)
  43. #define SKL_ADSP_REG_CL_SPBFIFO_SPIB (SKL_ADSP_REG_CL_SPBFIFO + 0x8)
  44. #define SKL_ADSP_REG_CL_SPBFIFO_MAXFIFOS (SKL_ADSP_REG_CL_SPBFIFO + 0xc)
  45. /* CL: Stream Descriptor x Control */
  46. /* Stream Reset */
  47. #define CL_SD_CTL_SRST_SHIFT 0
  48. #define CL_SD_CTL_SRST_MASK (1 << CL_SD_CTL_SRST_SHIFT)
  49. #define CL_SD_CTL_SRST(x) \
  50. ((x << CL_SD_CTL_SRST_SHIFT) & CL_SD_CTL_SRST_MASK)
  51. /* Stream Run */
  52. #define CL_SD_CTL_RUN_SHIFT 1
  53. #define CL_SD_CTL_RUN_MASK (1 << CL_SD_CTL_RUN_SHIFT)
  54. #define CL_SD_CTL_RUN(x) \
  55. ((x << CL_SD_CTL_RUN_SHIFT) & CL_SD_CTL_RUN_MASK)
  56. /* Interrupt On Completion Enable */
  57. #define CL_SD_CTL_IOCE_SHIFT 2
  58. #define CL_SD_CTL_IOCE_MASK (1 << CL_SD_CTL_IOCE_SHIFT)
  59. #define CL_SD_CTL_IOCE(x) \
  60. ((x << CL_SD_CTL_IOCE_SHIFT) & CL_SD_CTL_IOCE_MASK)
  61. /* FIFO Error Interrupt Enable */
  62. #define CL_SD_CTL_FEIE_SHIFT 3
  63. #define CL_SD_CTL_FEIE_MASK (1 << CL_SD_CTL_FEIE_SHIFT)
  64. #define CL_SD_CTL_FEIE(x) \
  65. ((x << CL_SD_CTL_FEIE_SHIFT) & CL_SD_CTL_FEIE_MASK)
  66. /* Descriptor Error Interrupt Enable */
  67. #define CL_SD_CTL_DEIE_SHIFT 4
  68. #define CL_SD_CTL_DEIE_MASK (1 << CL_SD_CTL_DEIE_SHIFT)
  69. #define CL_SD_CTL_DEIE(x) \
  70. ((x << CL_SD_CTL_DEIE_SHIFT) & CL_SD_CTL_DEIE_MASK)
  71. /* FIFO Limit Change */
  72. #define CL_SD_CTL_FIFOLC_SHIFT 5
  73. #define CL_SD_CTL_FIFOLC_MASK (1 << CL_SD_CTL_FIFOLC_SHIFT)
  74. #define CL_SD_CTL_FIFOLC(x) \
  75. ((x << CL_SD_CTL_FIFOLC_SHIFT) & CL_SD_CTL_FIFOLC_MASK)
  76. /* Stripe Control */
  77. #define CL_SD_CTL_STRIPE_SHIFT 16
  78. #define CL_SD_CTL_STRIPE_MASK (0x3 << CL_SD_CTL_STRIPE_SHIFT)
  79. #define CL_SD_CTL_STRIPE(x) \
  80. ((x << CL_SD_CTL_STRIPE_SHIFT) & CL_SD_CTL_STRIPE_MASK)
  81. /* Traffic Priority */
  82. #define CL_SD_CTL_TP_SHIFT 18
  83. #define CL_SD_CTL_TP_MASK (1 << CL_SD_CTL_TP_SHIFT)
  84. #define CL_SD_CTL_TP(x) \
  85. ((x << CL_SD_CTL_TP_SHIFT) & CL_SD_CTL_TP_MASK)
  86. /* Bidirectional Direction Control */
  87. #define CL_SD_CTL_DIR_SHIFT 19
  88. #define CL_SD_CTL_DIR_MASK (1 << CL_SD_CTL_DIR_SHIFT)
  89. #define CL_SD_CTL_DIR(x) \
  90. ((x << CL_SD_CTL_DIR_SHIFT) & CL_SD_CTL_DIR_MASK)
  91. /* Stream Number */
  92. #define CL_SD_CTL_STRM_SHIFT 20
  93. #define CL_SD_CTL_STRM_MASK (0xf << CL_SD_CTL_STRM_SHIFT)
  94. #define CL_SD_CTL_STRM(x) \
  95. ((x << CL_SD_CTL_STRM_SHIFT) & CL_SD_CTL_STRM_MASK)
  96. /* CL: Stream Descriptor x Status */
  97. /* Buffer Completion Interrupt Status */
  98. #define CL_SD_STS_BCIS(x) CL_SD_CTL_IOCE(x)
  99. /* FIFO Error */
  100. #define CL_SD_STS_FIFOE(x) CL_SD_CTL_FEIE(x)
  101. /* Descriptor Error */
  102. #define CL_SD_STS_DESE(x) CL_SD_CTL_DEIE(x)
  103. /* FIFO Ready */
  104. #define CL_SD_STS_FIFORDY(x) CL_SD_CTL_FIFOLC(x)
  105. /* CL: Stream Descriptor x Last Valid Index */
  106. #define CL_SD_LVI_SHIFT 0
  107. #define CL_SD_LVI_MASK (0xff << CL_SD_LVI_SHIFT)
  108. #define CL_SD_LVI(x) ((x << CL_SD_LVI_SHIFT) & CL_SD_LVI_MASK)
  109. /* CL: Stream Descriptor x FIFO Eviction Watermark */
  110. #define CL_SD_FIFOW_SHIFT 0
  111. #define CL_SD_FIFOW_MASK (0x7 << CL_SD_FIFOW_SHIFT)
  112. #define CL_SD_FIFOW(x) \
  113. ((x << CL_SD_FIFOW_SHIFT) & CL_SD_FIFOW_MASK)
  114. /* CL: Stream Descriptor x Buffer Descriptor List Pointer Lower Base Address */
  115. /* Protect Bits */
  116. #define CL_SD_BDLPLBA_PROT_SHIFT 0
  117. #define CL_SD_BDLPLBA_PROT_MASK (1 << CL_SD_BDLPLBA_PROT_SHIFT)
  118. #define CL_SD_BDLPLBA_PROT(x) \
  119. ((x << CL_SD_BDLPLBA_PROT_SHIFT) & CL_SD_BDLPLBA_PROT_MASK)
  120. /* Buffer Descriptor List Lower Base Address */
  121. #define CL_SD_BDLPLBA_SHIFT 7
  122. #define CL_SD_BDLPLBA_MASK (0x1ffffff << CL_SD_BDLPLBA_SHIFT)
  123. #define CL_SD_BDLPLBA(x) \
  124. ((BDL_ALIGN(lower_32_bits(x)) << CL_SD_BDLPLBA_SHIFT) & CL_SD_BDLPLBA_MASK)
  125. /* Buffer Descriptor List Upper Base Address */
  126. #define CL_SD_BDLPUBA_SHIFT 0
  127. #define CL_SD_BDLPUBA_MASK (0xffffffff << CL_SD_BDLPUBA_SHIFT)
  128. #define CL_SD_BDLPUBA(x) \
  129. ((upper_32_bits(x) << CL_SD_BDLPUBA_SHIFT) & CL_SD_BDLPUBA_MASK)
  130. /*
  131. * Code Loader - Software Position Based FIFO
  132. * Capability Registers x Software Position Based FIFO Header
  133. */
  134. /* Next Capability Pointer */
  135. #define CL_SPBFIFO_SPBFCH_PTR_SHIFT 0
  136. #define CL_SPBFIFO_SPBFCH_PTR_MASK (0xff << CL_SPBFIFO_SPBFCH_PTR_SHIFT)
  137. #define CL_SPBFIFO_SPBFCH_PTR(x) \
  138. ((x << CL_SPBFIFO_SPBFCH_PTR_SHIFT) & CL_SPBFIFO_SPBFCH_PTR_MASK)
  139. /* Capability Identifier */
  140. #define CL_SPBFIFO_SPBFCH_ID_SHIFT 16
  141. #define CL_SPBFIFO_SPBFCH_ID_MASK (0xfff << CL_SPBFIFO_SPBFCH_ID_SHIFT)
  142. #define CL_SPBFIFO_SPBFCH_ID(x) \
  143. ((x << CL_SPBFIFO_SPBFCH_ID_SHIFT) & CL_SPBFIFO_SPBFCH_ID_MASK)
  144. /* Capability Version */
  145. #define CL_SPBFIFO_SPBFCH_VER_SHIFT 28
  146. #define CL_SPBFIFO_SPBFCH_VER_MASK (0xf << CL_SPBFIFO_SPBFCH_VER_SHIFT)
  147. #define CL_SPBFIFO_SPBFCH_VER(x) \
  148. ((x << CL_SPBFIFO_SPBFCH_VER_SHIFT) & CL_SPBFIFO_SPBFCH_VER_MASK)
  149. /* Software Position in Buffer Enable */
  150. #define CL_SPBFIFO_SPBFCCTL_SPIBE_SHIFT 0
  151. #define CL_SPBFIFO_SPBFCCTL_SPIBE_MASK (1 << CL_SPBFIFO_SPBFCCTL_SPIBE_SHIFT)
  152. #define CL_SPBFIFO_SPBFCCTL_SPIBE(x) \
  153. ((x << CL_SPBFIFO_SPBFCCTL_SPIBE_SHIFT) & CL_SPBFIFO_SPBFCCTL_SPIBE_MASK)
  154. /* SST IPC SKL defines */
  155. #define SKL_WAIT_TIMEOUT 500 /* 500 msec */
  156. #define SKL_MAX_BUFFER_SIZE (32 * PAGE_SIZE)
  157. enum skl_cl_dma_wake_states {
  158. SKL_CL_DMA_STATUS_NONE = 0,
  159. SKL_CL_DMA_BUF_COMPLETE,
  160. SKL_CL_DMA_ERR, /* TODO: Expand the error states */
  161. };
  162. struct sst_dsp;
  163. struct skl_cl_dev_ops {
  164. void (*cl_setup_bdle)(struct sst_dsp *ctx,
  165. struct snd_dma_buffer *dmab_data,
  166. u32 **bdlp, int size, int with_ioc);
  167. void (*cl_setup_controller)(struct sst_dsp *ctx,
  168. struct snd_dma_buffer *dmab_bdl,
  169. unsigned int max_size, u32 page_count);
  170. void (*cl_setup_spb)(struct sst_dsp *ctx,
  171. unsigned int size, bool enable);
  172. void (*cl_cleanup_spb)(struct sst_dsp *ctx);
  173. void (*cl_trigger)(struct sst_dsp *ctx, bool enable);
  174. void (*cl_cleanup_controller)(struct sst_dsp *ctx);
  175. int (*cl_copy_to_dmabuf)(struct sst_dsp *ctx,
  176. const void *bin, u32 size);
  177. void (*cl_stop_dma)(struct sst_dsp *ctx);
  178. };
  179. /**
  180. * skl_cl_dev - holds information for code loader dma transfer
  181. *
  182. * @dmab_data: buffer pointer
  183. * @dmab_bdl: buffer descriptor list
  184. * @bufsize: ring buffer size
  185. * @frags: Last valid buffer descriptor index in the BDL
  186. * @curr_spib_pos: Current position in ring buffer
  187. * @dma_buffer_offset: dma buffer offset
  188. * @ops: operations supported on CL dma
  189. * @wait_queue: wait queue to wake for wake event
  190. * @wake_status: DMA wake status
  191. * @wait_condition: condition to wait on wait queue
  192. * @cl_dma_lock: for synchronized access to cldma
  193. */
  194. struct skl_cl_dev {
  195. struct snd_dma_buffer dmab_data;
  196. struct snd_dma_buffer dmab_bdl;
  197. unsigned int bufsize;
  198. unsigned int frags;
  199. unsigned int curr_spib_pos;
  200. unsigned int dma_buffer_offset;
  201. struct skl_cl_dev_ops ops;
  202. wait_queue_head_t wait_queue;
  203. int wake_status;
  204. bool wait_condition;
  205. };
  206. #endif /* SKL_SST_CLDMA_H_ */