sst-dsp-priv.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * Intel Smart Sound Technology
  3. *
  4. * Copyright (C) 2013, Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef __SOUND_SOC_SST_DSP_PRIV_H
  17. #define __SOUND_SOC_SST_DSP_PRIV_H
  18. #include <linux/kernel.h>
  19. #include <linux/types.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/firmware.h>
  22. #include "../skylake/skl-sst-dsp.h"
  23. struct sst_mem_block;
  24. struct sst_module;
  25. struct sst_fw;
  26. /* do we need to remove or keep */
  27. #define DSP_DRAM_ADDR_OFFSET 0x400000
  28. /*
  29. * DSP Operations exported by platform Audio DSP driver.
  30. */
  31. struct sst_ops {
  32. /* DSP core boot / reset */
  33. void (*boot)(struct sst_dsp *);
  34. void (*reset)(struct sst_dsp *);
  35. int (*wake)(struct sst_dsp *);
  36. void (*sleep)(struct sst_dsp *);
  37. void (*stall)(struct sst_dsp *);
  38. /* Shim IO */
  39. void (*write)(void __iomem *addr, u32 offset, u32 value);
  40. u32 (*read)(void __iomem *addr, u32 offset);
  41. void (*write64)(void __iomem *addr, u32 offset, u64 value);
  42. u64 (*read64)(void __iomem *addr, u32 offset);
  43. /* DSP I/DRAM IO */
  44. void (*ram_read)(struct sst_dsp *sst, void *dest, void __iomem *src,
  45. size_t bytes);
  46. void (*ram_write)(struct sst_dsp *sst, void __iomem *dest, void *src,
  47. size_t bytes);
  48. void (*dump)(struct sst_dsp *);
  49. /* IRQ handlers */
  50. irqreturn_t (*irq_handler)(int irq, void *context);
  51. /* SST init and free */
  52. int (*init)(struct sst_dsp *sst, struct sst_pdata *pdata);
  53. void (*free)(struct sst_dsp *sst);
  54. /* FW module parser/loader */
  55. int (*parse_fw)(struct sst_fw *sst_fw);
  56. };
  57. /*
  58. * Audio DSP memory offsets and addresses.
  59. */
  60. struct sst_addr {
  61. u32 lpe_base;
  62. u32 shim_offset;
  63. u32 iram_offset;
  64. u32 dram_offset;
  65. u32 dsp_iram_offset;
  66. u32 dsp_dram_offset;
  67. u32 sram0_base;
  68. u32 sram1_base;
  69. u32 w0_stat_sz;
  70. u32 w0_up_sz;
  71. void __iomem *lpe;
  72. void __iomem *shim;
  73. void __iomem *pci_cfg;
  74. void __iomem *fw_ext;
  75. };
  76. /*
  77. * Audio DSP Mailbox configuration.
  78. */
  79. struct sst_mailbox {
  80. void __iomem *in_base;
  81. void __iomem *out_base;
  82. size_t in_size;
  83. size_t out_size;
  84. };
  85. /*
  86. * Audio DSP memory block types.
  87. */
  88. enum sst_mem_type {
  89. SST_MEM_IRAM = 0,
  90. SST_MEM_DRAM = 1,
  91. SST_MEM_ANY = 2,
  92. SST_MEM_CACHE= 3,
  93. };
  94. /*
  95. * Audio DSP Generic Firmware File.
  96. *
  97. * SST Firmware files can consist of 1..N modules. This generic structure is
  98. * used to manage each firmware file and it's modules regardless of SST firmware
  99. * type. A SST driver may load multiple FW files.
  100. */
  101. struct sst_fw {
  102. struct sst_dsp *dsp;
  103. /* base addresses of FW file data */
  104. dma_addr_t dmable_fw_paddr; /* physical address of fw data */
  105. void *dma_buf; /* virtual address of fw data */
  106. u32 size; /* size of fw data */
  107. /* lists */
  108. struct list_head list; /* DSP list of FW */
  109. struct list_head module_list; /* FW list of modules */
  110. void *private; /* core doesn't touch this */
  111. };
  112. /*
  113. * Audio DSP Generic Module Template.
  114. *
  115. * Used to define and register a new FW module. This data is extracted from
  116. * FW module header information.
  117. */
  118. struct sst_module_template {
  119. u32 id;
  120. u32 entry; /* entry point */
  121. u32 scratch_size;
  122. u32 persistent_size;
  123. };
  124. /*
  125. * Block Allocator - Used to allocate blocks of DSP memory.
  126. */
  127. struct sst_block_allocator {
  128. u32 id;
  129. u32 offset;
  130. int size;
  131. enum sst_mem_type type;
  132. };
  133. /*
  134. * Runtime Module Instance - A module object can be instantiated multiple
  135. * times within the DSP FW.
  136. */
  137. struct sst_module_runtime {
  138. struct sst_dsp *dsp;
  139. int id;
  140. struct sst_module *module; /* parent module we belong too */
  141. u32 persistent_offset; /* private memory offset */
  142. void *private;
  143. struct list_head list;
  144. struct list_head block_list; /* list of blocks used */
  145. };
  146. /*
  147. * Runtime Module Context - The runtime context must be manually stored by the
  148. * driver prior to enter S3 and restored after leaving S3. This should really be
  149. * part of the memory context saved by the enter D3 message IPC ???
  150. */
  151. struct sst_module_runtime_context {
  152. dma_addr_t dma_buffer;
  153. u32 *buffer;
  154. };
  155. /*
  156. * Audio DSP Module State
  157. */
  158. enum sst_module_state {
  159. SST_MODULE_STATE_UNLOADED = 0, /* default state */
  160. SST_MODULE_STATE_LOADED,
  161. SST_MODULE_STATE_INITIALIZED, /* and inactive */
  162. SST_MODULE_STATE_ACTIVE,
  163. };
  164. /*
  165. * Audio DSP Generic Module.
  166. *
  167. * Each Firmware file can consist of 1..N modules. A module can span multiple
  168. * ADSP memory blocks. The simplest FW will be a file with 1 module. A module
  169. * can be instantiated multiple times in the DSP.
  170. */
  171. struct sst_module {
  172. struct sst_dsp *dsp;
  173. struct sst_fw *sst_fw; /* parent FW we belong too */
  174. /* module configuration */
  175. u32 id;
  176. u32 entry; /* module entry point */
  177. s32 offset; /* module offset in firmware file */
  178. u32 size; /* module size */
  179. u32 scratch_size; /* global scratch memory required */
  180. u32 persistent_size; /* private memory required */
  181. enum sst_mem_type type; /* destination memory type */
  182. u32 data_offset; /* offset in ADSP memory space */
  183. void *data; /* module data */
  184. /* runtime */
  185. u32 usage_count; /* can be unloaded if count == 0 */
  186. void *private; /* core doesn't touch this */
  187. /* lists */
  188. struct list_head block_list; /* Module list of blocks in use */
  189. struct list_head list; /* DSP list of modules */
  190. struct list_head list_fw; /* FW list of modules */
  191. struct list_head runtime_list; /* list of runtime module objects*/
  192. /* state */
  193. enum sst_module_state state;
  194. };
  195. /*
  196. * SST Memory Block operations.
  197. */
  198. struct sst_block_ops {
  199. int (*enable)(struct sst_mem_block *block);
  200. int (*disable)(struct sst_mem_block *block);
  201. };
  202. /*
  203. * SST Generic Memory Block.
  204. *
  205. * SST ADP memory has multiple IRAM and DRAM blocks. Some ADSP blocks can be
  206. * power gated.
  207. */
  208. struct sst_mem_block {
  209. struct sst_dsp *dsp;
  210. struct sst_module *module; /* module that uses this block */
  211. /* block config */
  212. u32 offset; /* offset from base */
  213. u32 size; /* block size */
  214. u32 index; /* block index 0..N */
  215. enum sst_mem_type type; /* block memory type IRAM/DRAM */
  216. const struct sst_block_ops *ops;/* block operations, if any */
  217. /* block status */
  218. u32 bytes_used; /* bytes in use by modules */
  219. void *private; /* generic core does not touch this */
  220. int users; /* number of modules using this block */
  221. /* block lists */
  222. struct list_head module_list; /* Module list of blocks */
  223. struct list_head list; /* Map list of free/used blocks */
  224. };
  225. /*
  226. * Generic SST Shim Interface.
  227. */
  228. struct sst_dsp {
  229. /* Shared for all platforms */
  230. /* runtime */
  231. struct sst_dsp_device *sst_dev;
  232. spinlock_t spinlock; /* IPC locking */
  233. struct mutex mutex; /* DSP FW lock */
  234. struct device *dev;
  235. struct device *dma_dev;
  236. void *thread_context;
  237. int irq;
  238. u32 id;
  239. /* operations */
  240. struct sst_ops *ops;
  241. /* debug FS */
  242. struct dentry *debugfs_root;
  243. /* base addresses */
  244. struct sst_addr addr;
  245. /* mailbox */
  246. struct sst_mailbox mailbox;
  247. /* HSW/Byt data */
  248. /* list of free and used ADSP memory blocks */
  249. struct list_head used_block_list;
  250. struct list_head free_block_list;
  251. /* SST FW files loaded and their modules */
  252. struct list_head module_list;
  253. struct list_head fw_list;
  254. /* scratch buffer */
  255. struct list_head scratch_block_list;
  256. u32 scratch_offset;
  257. u32 scratch_size;
  258. /* platform data */
  259. struct sst_pdata *pdata;
  260. /* DMA FW loading */
  261. struct sst_dma *dma;
  262. bool fw_use_dma;
  263. /* SKL data */
  264. const char *fw_name;
  265. /* To allocate CL dma buffers */
  266. struct skl_dsp_loader_ops dsp_ops;
  267. struct skl_dsp_fw_ops fw_ops;
  268. int sst_state;
  269. struct skl_cl_dev cl_dev;
  270. u32 intr_status;
  271. const struct firmware *fw;
  272. struct snd_dma_buffer dmab;
  273. };
  274. /* Size optimised DRAM/IRAM memcpy */
  275. static inline void sst_dsp_write(struct sst_dsp *sst, void *src,
  276. u32 dest_offset, size_t bytes)
  277. {
  278. sst->ops->ram_write(sst, sst->addr.lpe + dest_offset, src, bytes);
  279. }
  280. static inline void sst_dsp_read(struct sst_dsp *sst, void *dest,
  281. u32 src_offset, size_t bytes)
  282. {
  283. sst->ops->ram_read(sst, dest, sst->addr.lpe + src_offset, bytes);
  284. }
  285. static inline void *sst_dsp_get_thread_context(struct sst_dsp *sst)
  286. {
  287. return sst->thread_context;
  288. }
  289. /* Create/Free FW files - can contain multiple modules */
  290. struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
  291. const struct firmware *fw, void *private);
  292. void sst_fw_free(struct sst_fw *sst_fw);
  293. void sst_fw_free_all(struct sst_dsp *dsp);
  294. int sst_fw_reload(struct sst_fw *sst_fw);
  295. void sst_fw_unload(struct sst_fw *sst_fw);
  296. /* Create/Free firmware modules */
  297. struct sst_module *sst_module_new(struct sst_fw *sst_fw,
  298. struct sst_module_template *template, void *private);
  299. void sst_module_free(struct sst_module *module);
  300. struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id);
  301. int sst_module_alloc_blocks(struct sst_module *module);
  302. int sst_module_free_blocks(struct sst_module *module);
  303. /* Create/Free firmware module runtime instances */
  304. struct sst_module_runtime *sst_module_runtime_new(struct sst_module *module,
  305. int id, void *private);
  306. void sst_module_runtime_free(struct sst_module_runtime *runtime);
  307. struct sst_module_runtime *sst_module_runtime_get_from_id(
  308. struct sst_module *module, u32 id);
  309. int sst_module_runtime_alloc_blocks(struct sst_module_runtime *runtime,
  310. int offset);
  311. int sst_module_runtime_free_blocks(struct sst_module_runtime *runtime);
  312. int sst_module_runtime_save(struct sst_module_runtime *runtime,
  313. struct sst_module_runtime_context *context);
  314. int sst_module_runtime_restore(struct sst_module_runtime *runtime,
  315. struct sst_module_runtime_context *context);
  316. /* generic block allocation */
  317. int sst_alloc_blocks(struct sst_dsp *dsp, struct sst_block_allocator *ba,
  318. struct list_head *block_list);
  319. int sst_free_blocks(struct sst_dsp *dsp, struct list_head *block_list);
  320. /* scratch allocation */
  321. int sst_block_alloc_scratch(struct sst_dsp *dsp);
  322. void sst_block_free_scratch(struct sst_dsp *dsp);
  323. /* Register the DSPs memory blocks - would be nice to read from ACPI */
  324. struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
  325. u32 size, enum sst_mem_type type, const struct sst_block_ops *ops,
  326. u32 index, void *private);
  327. void sst_mem_block_unregister_all(struct sst_dsp *dsp);
  328. u32 sst_dsp_get_offset(struct sst_dsp *dsp, u32 offset,
  329. enum sst_mem_type type);
  330. #endif