skl-sst-dsp.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Skylake SST DSP Support
  4. *
  5. * Copyright (C) 2014-15, Intel Corporation.
  6. */
  7. #ifndef __SKL_SST_DSP_H__
  8. #define __SKL_SST_DSP_H__
  9. #include <linux/interrupt.h>
  10. #include <linux/uuid.h>
  11. #include <linux/firmware.h>
  12. #include <sound/memalloc.h>
  13. #include "skl-sst-cldma.h"
  14. struct sst_dsp;
  15. struct sst_dsp_device;
  16. struct skl_lib_info;
  17. struct skl_dev;
  18. /* Intel HD Audio General DSP Registers */
  19. #define SKL_ADSP_GEN_BASE 0x0
  20. #define SKL_ADSP_REG_ADSPCS (SKL_ADSP_GEN_BASE + 0x04)
  21. #define SKL_ADSP_REG_ADSPIC (SKL_ADSP_GEN_BASE + 0x08)
  22. #define SKL_ADSP_REG_ADSPIS (SKL_ADSP_GEN_BASE + 0x0C)
  23. #define SKL_ADSP_REG_ADSPIC2 (SKL_ADSP_GEN_BASE + 0x10)
  24. #define SKL_ADSP_REG_ADSPIS2 (SKL_ADSP_GEN_BASE + 0x14)
  25. /* Intel HD Audio Inter-Processor Communication Registers */
  26. #define SKL_ADSP_IPC_BASE 0x40
  27. #define SKL_ADSP_REG_HIPCT (SKL_ADSP_IPC_BASE + 0x00)
  28. #define SKL_ADSP_REG_HIPCTE (SKL_ADSP_IPC_BASE + 0x04)
  29. #define SKL_ADSP_REG_HIPCI (SKL_ADSP_IPC_BASE + 0x08)
  30. #define SKL_ADSP_REG_HIPCIE (SKL_ADSP_IPC_BASE + 0x0C)
  31. #define SKL_ADSP_REG_HIPCCTL (SKL_ADSP_IPC_BASE + 0x10)
  32. /* HIPCI */
  33. #define SKL_ADSP_REG_HIPCI_BUSY BIT(31)
  34. /* HIPCIE */
  35. #define SKL_ADSP_REG_HIPCIE_DONE BIT(30)
  36. /* HIPCCTL */
  37. #define SKL_ADSP_REG_HIPCCTL_DONE BIT(1)
  38. #define SKL_ADSP_REG_HIPCCTL_BUSY BIT(0)
  39. /* HIPCT */
  40. #define SKL_ADSP_REG_HIPCT_BUSY BIT(31)
  41. /* FW base IDs */
  42. #define SKL_INSTANCE_ID 0
  43. #define SKL_BASE_FW_MODULE_ID 0
  44. /* Intel HD Audio SRAM Window 1 */
  45. #define SKL_ADSP_SRAM1_BASE 0xA000
  46. #define SKL_ADSP_MMIO_LEN 0x10000
  47. #define SKL_ADSP_W0_STAT_SZ 0x1000
  48. #define SKL_ADSP_W0_UP_SZ 0x1000
  49. #define SKL_ADSP_W1_SZ 0x1000
  50. #define SKL_FW_STS_MASK 0xf
  51. #define SKL_FW_INIT 0x1
  52. #define SKL_FW_RFW_START 0xf
  53. #define BXT_FW_ROM_INIT_RETRY 3
  54. #define BXT_INIT_TIMEOUT 300
  55. #define SKL_ADSPIC_IPC 1
  56. #define SKL_ADSPIS_IPC 1
  57. /* Core ID of core0 */
  58. #define SKL_DSP_CORE0_ID 0
  59. /* Mask for a given core index, c = 0.. number of supported cores - 1 */
  60. #define SKL_DSP_CORE_MASK(c) BIT(c)
  61. /*
  62. * Core 0 mask = SKL_DSP_CORE_MASK(0); Defined separately
  63. * since Core0 is primary core and it is used often
  64. */
  65. #define SKL_DSP_CORE0_MASK BIT(0)
  66. /*
  67. * Mask for a given number of cores
  68. * nc = number of supported cores
  69. */
  70. #define SKL_DSP_CORES_MASK(nc) GENMASK((nc - 1), 0)
  71. /* ADSPCS - Audio DSP Control & Status */
  72. /*
  73. * Core Reset - asserted high
  74. * CRST Mask for a given core mask pattern, cm
  75. */
  76. #define SKL_ADSPCS_CRST_SHIFT 0
  77. #define SKL_ADSPCS_CRST_MASK(cm) ((cm) << SKL_ADSPCS_CRST_SHIFT)
  78. /*
  79. * Core run/stall - when set to '1' core is stalled
  80. * CSTALL Mask for a given core mask pattern, cm
  81. */
  82. #define SKL_ADSPCS_CSTALL_SHIFT 8
  83. #define SKL_ADSPCS_CSTALL_MASK(cm) ((cm) << SKL_ADSPCS_CSTALL_SHIFT)
  84. /*
  85. * Set Power Active - when set to '1' turn cores on
  86. * SPA Mask for a given core mask pattern, cm
  87. */
  88. #define SKL_ADSPCS_SPA_SHIFT 16
  89. #define SKL_ADSPCS_SPA_MASK(cm) ((cm) << SKL_ADSPCS_SPA_SHIFT)
  90. /*
  91. * Current Power Active - power status of cores, set by hardware
  92. * CPA Mask for a given core mask pattern, cm
  93. */
  94. #define SKL_ADSPCS_CPA_SHIFT 24
  95. #define SKL_ADSPCS_CPA_MASK(cm) ((cm) << SKL_ADSPCS_CPA_SHIFT)
  96. /* DSP Core state */
  97. enum skl_dsp_states {
  98. SKL_DSP_RUNNING = 1,
  99. /* Running in D0i3 state; can be in streaming or non-streaming D0i3 */
  100. SKL_DSP_RUNNING_D0I3, /* Running in D0i3 state*/
  101. SKL_DSP_RESET,
  102. };
  103. /* D0i3 substates */
  104. enum skl_dsp_d0i3_states {
  105. SKL_DSP_D0I3_NONE = -1, /* No D0i3 */
  106. SKL_DSP_D0I3_NON_STREAMING = 0,
  107. SKL_DSP_D0I3_STREAMING = 1,
  108. };
  109. struct skl_dsp_fw_ops {
  110. int (*load_fw)(struct sst_dsp *ctx);
  111. /* FW module parser/loader */
  112. int (*load_library)(struct sst_dsp *ctx,
  113. struct skl_lib_info *linfo, int lib_count);
  114. int (*parse_fw)(struct sst_dsp *ctx);
  115. int (*set_state_D0)(struct sst_dsp *ctx, unsigned int core_id);
  116. int (*set_state_D3)(struct sst_dsp *ctx, unsigned int core_id);
  117. int (*set_state_D0i3)(struct sst_dsp *ctx);
  118. int (*set_state_D0i0)(struct sst_dsp *ctx);
  119. unsigned int (*get_fw_errcode)(struct sst_dsp *ctx);
  120. int (*load_mod)(struct sst_dsp *ctx, u16 mod_id, u8 *mod_name);
  121. int (*unload_mod)(struct sst_dsp *ctx, u16 mod_id);
  122. };
  123. struct skl_dsp_loader_ops {
  124. int stream_tag;
  125. int (*alloc_dma_buf)(struct device *dev,
  126. struct snd_dma_buffer *dmab, size_t size);
  127. int (*free_dma_buf)(struct device *dev,
  128. struct snd_dma_buffer *dmab);
  129. int (*prepare)(struct device *dev, unsigned int format,
  130. unsigned int byte_size,
  131. struct snd_dma_buffer *bufp);
  132. int (*trigger)(struct device *dev, bool start, int stream_tag);
  133. int (*cleanup)(struct device *dev, struct snd_dma_buffer *dmab,
  134. int stream_tag);
  135. };
  136. #define MAX_INSTANCE_BUFF 2
  137. struct uuid_module {
  138. guid_t uuid;
  139. int id;
  140. int is_loadable;
  141. int max_instance;
  142. u64 pvt_id[MAX_INSTANCE_BUFF];
  143. int *instance_id;
  144. struct list_head list;
  145. };
  146. struct skl_load_module_info {
  147. u16 mod_id;
  148. const struct firmware *fw;
  149. };
  150. struct skl_module_table {
  151. struct skl_load_module_info *mod_info;
  152. unsigned int usage_cnt;
  153. struct list_head list;
  154. };
  155. void skl_cldma_process_intr(struct sst_dsp *ctx);
  156. void skl_cldma_int_disable(struct sst_dsp *ctx);
  157. int skl_cldma_prepare(struct sst_dsp *ctx);
  158. int skl_cldma_wait_interruptible(struct sst_dsp *ctx);
  159. void skl_dsp_set_state_locked(struct sst_dsp *ctx, int state);
  160. struct sst_dsp *skl_dsp_ctx_init(struct device *dev,
  161. struct sst_dsp_device *sst_dev, int irq);
  162. int skl_dsp_acquire_irq(struct sst_dsp *sst);
  163. bool is_skl_dsp_running(struct sst_dsp *ctx);
  164. unsigned int skl_dsp_get_enabled_cores(struct sst_dsp *ctx);
  165. void skl_dsp_init_core_state(struct sst_dsp *ctx);
  166. int skl_dsp_enable_core(struct sst_dsp *ctx, unsigned int core_mask);
  167. int skl_dsp_disable_core(struct sst_dsp *ctx, unsigned int core_mask);
  168. int skl_dsp_core_power_up(struct sst_dsp *ctx, unsigned int core_mask);
  169. int skl_dsp_core_power_down(struct sst_dsp *ctx, unsigned int core_mask);
  170. int skl_dsp_core_unset_reset_state(struct sst_dsp *ctx,
  171. unsigned int core_mask);
  172. int skl_dsp_start_core(struct sst_dsp *ctx, unsigned int core_mask);
  173. irqreturn_t skl_dsp_sst_interrupt(int irq, void *dev_id);
  174. int skl_dsp_wake(struct sst_dsp *ctx);
  175. int skl_dsp_sleep(struct sst_dsp *ctx);
  176. void skl_dsp_free(struct sst_dsp *dsp);
  177. int skl_dsp_get_core(struct sst_dsp *ctx, unsigned int core_id);
  178. int skl_dsp_put_core(struct sst_dsp *ctx, unsigned int core_id);
  179. int skl_dsp_boot(struct sst_dsp *ctx);
  180. int skl_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
  181. const char *fw_name, struct skl_dsp_loader_ops dsp_ops,
  182. struct skl_dev **dsp);
  183. int bxt_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
  184. const char *fw_name, struct skl_dsp_loader_ops dsp_ops,
  185. struct skl_dev **dsp);
  186. int skl_sst_init_fw(struct device *dev, struct skl_dev *skl);
  187. int bxt_sst_init_fw(struct device *dev, struct skl_dev *skl);
  188. void skl_sst_dsp_cleanup(struct device *dev, struct skl_dev *skl);
  189. void bxt_sst_dsp_cleanup(struct device *dev, struct skl_dev *skl);
  190. int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
  191. unsigned int offset, int index);
  192. int skl_get_pvt_id(struct skl_dev *skl, guid_t *uuid_mod, int instance_id);
  193. int skl_put_pvt_id(struct skl_dev *skl, guid_t *uuid_mod, int *pvt_id);
  194. int skl_get_pvt_instance_id_map(struct skl_dev *skl,
  195. int module_id, int instance_id);
  196. void skl_freeup_uuid_list(struct skl_dev *skl);
  197. int skl_dsp_strip_extended_manifest(struct firmware *fw);
  198. void skl_dsp_set_astate_cfg(struct skl_dev *skl, u32 cnt, void *data);
  199. int skl_sst_ctx_init(struct device *dev, int irq, const char *fw_name,
  200. struct skl_dsp_loader_ops dsp_ops, struct skl_dev **dsp,
  201. struct sst_dsp_device *skl_dev);
  202. int skl_prepare_lib_load(struct skl_dev *skl, struct skl_lib_info *linfo,
  203. struct firmware *stripped_fw,
  204. unsigned int hdr_offset, int index);
  205. void skl_release_library(struct skl_lib_info *linfo, int lib_count);
  206. #endif /*__SKL_SST_DSP_H__*/