sst-dsp-priv.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. void __iomem *lpe;
  68. void __iomem *shim;
  69. void __iomem *pci_cfg;
  70. void __iomem *fw_ext;
  71. };
  72. /*
  73. * Audio DSP Mailbox configuration.
  74. */
  75. struct sst_mailbox {
  76. void __iomem *in_base;
  77. void __iomem *out_base;
  78. size_t in_size;
  79. size_t out_size;
  80. };
  81. /*
  82. * Audio DSP memory block types.
  83. */
  84. enum sst_mem_type {
  85. SST_MEM_IRAM = 0,
  86. SST_MEM_DRAM = 1,
  87. SST_MEM_ANY = 2,
  88. SST_MEM_CACHE= 3,
  89. };
  90. /*
  91. * Audio DSP Generic Firmware File.
  92. *
  93. * SST Firmware files can consist of 1..N modules. This generic structure is
  94. * used to manage each firmware file and it's modules regardless of SST firmware
  95. * type. A SST driver may load multiple FW files.
  96. */
  97. struct sst_fw {
  98. struct sst_dsp *dsp;
  99. /* base addresses of FW file data */
  100. dma_addr_t dmable_fw_paddr; /* physical address of fw data */
  101. void *dma_buf; /* virtual address of fw data */
  102. u32 size; /* size of fw data */
  103. /* lists */
  104. struct list_head list; /* DSP list of FW */
  105. struct list_head module_list; /* FW list of modules */
  106. void *private; /* core doesn't touch this */
  107. };
  108. /*
  109. * Audio DSP Generic Module Template.
  110. *
  111. * Used to define and register a new FW module. This data is extracted from
  112. * FW module header information.
  113. */
  114. struct sst_module_template {
  115. u32 id;
  116. u32 entry; /* entry point */
  117. u32 scratch_size;
  118. u32 persistent_size;
  119. };
  120. /*
  121. * Block Allocator - Used to allocate blocks of DSP memory.
  122. */
  123. struct sst_block_allocator {
  124. u32 id;
  125. u32 offset;
  126. int size;
  127. enum sst_mem_type type;
  128. };
  129. /*
  130. * Runtime Module Instance - A module object can be instanciated multiple
  131. * times within the DSP FW.
  132. */
  133. struct sst_module_runtime {
  134. struct sst_dsp *dsp;
  135. int id;
  136. struct sst_module *module; /* parent module we belong too */
  137. u32 persistent_offset; /* private memory offset */
  138. void *private;
  139. struct list_head list;
  140. struct list_head block_list; /* list of blocks used */
  141. };
  142. /*
  143. * Runtime Module Context - The runtime context must be manually stored by the
  144. * driver prior to enter S3 and restored after leaving S3. This should really be
  145. * part of the memory context saved by the enter D3 message IPC ???
  146. */
  147. struct sst_module_runtime_context {
  148. dma_addr_t dma_buffer;
  149. u32 *buffer;
  150. };
  151. /*
  152. * Audio DSP Module State
  153. */
  154. enum sst_module_state {
  155. SST_MODULE_STATE_UNLOADED = 0, /* default state */
  156. SST_MODULE_STATE_LOADED,
  157. SST_MODULE_STATE_INITIALIZED, /* and inactive */
  158. SST_MODULE_STATE_ACTIVE,
  159. };
  160. /*
  161. * Audio DSP Generic Module.
  162. *
  163. * Each Firmware file can consist of 1..N modules. A module can span multiple
  164. * ADSP memory blocks. The simplest FW will be a file with 1 module. A module
  165. * can be instanciated multiple times in the DSP.
  166. */
  167. struct sst_module {
  168. struct sst_dsp *dsp;
  169. struct sst_fw *sst_fw; /* parent FW we belong too */
  170. /* module configuration */
  171. u32 id;
  172. u32 entry; /* module entry point */
  173. s32 offset; /* module offset in firmware file */
  174. u32 size; /* module size */
  175. u32 scratch_size; /* global scratch memory required */
  176. u32 persistent_size; /* private memory required */
  177. enum sst_mem_type type; /* destination memory type */
  178. u32 data_offset; /* offset in ADSP memory space */
  179. void *data; /* module data */
  180. /* runtime */
  181. u32 usage_count; /* can be unloaded if count == 0 */
  182. void *private; /* core doesn't touch this */
  183. /* lists */
  184. struct list_head block_list; /* Module list of blocks in use */
  185. struct list_head list; /* DSP list of modules */
  186. struct list_head list_fw; /* FW list of modules */
  187. struct list_head runtime_list; /* list of runtime module objects*/
  188. /* state */
  189. enum sst_module_state state;
  190. };
  191. /*
  192. * SST Memory Block operations.
  193. */
  194. struct sst_block_ops {
  195. int (*enable)(struct sst_mem_block *block);
  196. int (*disable)(struct sst_mem_block *block);
  197. };
  198. /*
  199. * SST Generic Memory Block.
  200. *
  201. * SST ADP memory has multiple IRAM and DRAM blocks. Some ADSP blocks can be
  202. * power gated.
  203. */
  204. struct sst_mem_block {
  205. struct sst_dsp *dsp;
  206. struct sst_module *module; /* module that uses this block */
  207. /* block config */
  208. u32 offset; /* offset from base */
  209. u32 size; /* block size */
  210. u32 index; /* block index 0..N */
  211. enum sst_mem_type type; /* block memory type IRAM/DRAM */
  212. struct sst_block_ops *ops; /* block operations, if any */
  213. /* block status */
  214. u32 bytes_used; /* bytes in use by modules */
  215. void *private; /* generic core does not touch this */
  216. int users; /* number of modules using this block */
  217. /* block lists */
  218. struct list_head module_list; /* Module list of blocks */
  219. struct list_head list; /* Map list of free/used blocks */
  220. };
  221. /*
  222. * Generic SST Shim Interface.
  223. */
  224. struct sst_dsp {
  225. /* Shared for all platforms */
  226. /* runtime */
  227. struct sst_dsp_device *sst_dev;
  228. spinlock_t spinlock; /* IPC locking */
  229. struct mutex mutex; /* DSP FW lock */
  230. struct device *dev;
  231. struct device *dma_dev;
  232. void *thread_context;
  233. int irq;
  234. u32 id;
  235. /* operations */
  236. struct sst_ops *ops;
  237. /* debug FS */
  238. struct dentry *debugfs_root;
  239. /* base addresses */
  240. struct sst_addr addr;
  241. /* mailbox */
  242. struct sst_mailbox mailbox;
  243. /* HSW/Byt data */
  244. /* list of free and used ADSP memory blocks */
  245. struct list_head used_block_list;
  246. struct list_head free_block_list;
  247. /* SST FW files loaded and their modules */
  248. struct list_head module_list;
  249. struct list_head fw_list;
  250. /* scratch buffer */
  251. struct list_head scratch_block_list;
  252. u32 scratch_offset;
  253. u32 scratch_size;
  254. /* platform data */
  255. struct sst_pdata *pdata;
  256. /* DMA FW loading */
  257. struct sst_dma *dma;
  258. bool fw_use_dma;
  259. /* SKL data */
  260. /* To allocate CL dma buffers */
  261. struct skl_dsp_loader_ops dsp_ops;
  262. struct skl_dsp_fw_ops fw_ops;
  263. int sst_state;
  264. struct skl_cl_dev cl_dev;
  265. u32 intr_status;
  266. const struct firmware *fw;
  267. };
  268. /* Size optimised DRAM/IRAM memcpy */
  269. static inline void sst_dsp_write(struct sst_dsp *sst, void *src,
  270. u32 dest_offset, size_t bytes)
  271. {
  272. sst->ops->ram_write(sst, sst->addr.lpe + dest_offset, src, bytes);
  273. }
  274. static inline void sst_dsp_read(struct sst_dsp *sst, void *dest,
  275. u32 src_offset, size_t bytes)
  276. {
  277. sst->ops->ram_read(sst, dest, sst->addr.lpe + src_offset, bytes);
  278. }
  279. static inline void *sst_dsp_get_thread_context(struct sst_dsp *sst)
  280. {
  281. return sst->thread_context;
  282. }
  283. /* Create/Free FW files - can contain multiple modules */
  284. struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
  285. const struct firmware *fw, void *private);
  286. void sst_fw_free(struct sst_fw *sst_fw);
  287. void sst_fw_free_all(struct sst_dsp *dsp);
  288. int sst_fw_reload(struct sst_fw *sst_fw);
  289. void sst_fw_unload(struct sst_fw *sst_fw);
  290. /* Create/Free firmware modules */
  291. struct sst_module *sst_module_new(struct sst_fw *sst_fw,
  292. struct sst_module_template *template, void *private);
  293. void sst_module_free(struct sst_module *module);
  294. struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id);
  295. int sst_module_alloc_blocks(struct sst_module *module);
  296. int sst_module_free_blocks(struct sst_module *module);
  297. /* Create/Free firmware module runtime instances */
  298. struct sst_module_runtime *sst_module_runtime_new(struct sst_module *module,
  299. int id, void *private);
  300. void sst_module_runtime_free(struct sst_module_runtime *runtime);
  301. struct sst_module_runtime *sst_module_runtime_get_from_id(
  302. struct sst_module *module, u32 id);
  303. int sst_module_runtime_alloc_blocks(struct sst_module_runtime *runtime,
  304. int offset);
  305. int sst_module_runtime_free_blocks(struct sst_module_runtime *runtime);
  306. int sst_module_runtime_save(struct sst_module_runtime *runtime,
  307. struct sst_module_runtime_context *context);
  308. int sst_module_runtime_restore(struct sst_module_runtime *runtime,
  309. struct sst_module_runtime_context *context);
  310. /* generic block allocation */
  311. int sst_alloc_blocks(struct sst_dsp *dsp, struct sst_block_allocator *ba,
  312. struct list_head *block_list);
  313. int sst_free_blocks(struct sst_dsp *dsp, struct list_head *block_list);
  314. /* scratch allocation */
  315. int sst_block_alloc_scratch(struct sst_dsp *dsp);
  316. void sst_block_free_scratch(struct sst_dsp *dsp);
  317. /* Register the DSPs memory blocks - would be nice to read from ACPI */
  318. struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
  319. u32 size, enum sst_mem_type type, struct sst_block_ops *ops, u32 index,
  320. void *private);
  321. void sst_mem_block_unregister_all(struct sst_dsp *dsp);
  322. /* Create/Free DMA resources */
  323. int sst_dma_new(struct sst_dsp *sst);
  324. void sst_dma_free(struct sst_dma *dma);
  325. u32 sst_dsp_get_offset(struct sst_dsp *dsp, u32 offset,
  326. enum sst_mem_type type);
  327. #endif