sst-dsp-priv.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. struct sst_mem_block;
  23. struct sst_module;
  24. struct sst_fw;
  25. /*
  26. * DSP Operations exported by platform Audio DSP driver.
  27. */
  28. struct sst_ops {
  29. /* DSP core boot / reset */
  30. void (*boot)(struct sst_dsp *);
  31. void (*reset)(struct sst_dsp *);
  32. /* Shim IO */
  33. void (*write)(void __iomem *addr, u32 offset, u32 value);
  34. u32 (*read)(void __iomem *addr, u32 offset);
  35. void (*write64)(void __iomem *addr, u32 offset, u64 value);
  36. u64 (*read64)(void __iomem *addr, u32 offset);
  37. /* DSP I/DRAM IO */
  38. void (*ram_read)(struct sst_dsp *sst, void *dest, void __iomem *src,
  39. size_t bytes);
  40. void (*ram_write)(struct sst_dsp *sst, void __iomem *dest, void *src,
  41. size_t bytes);
  42. void (*dump)(struct sst_dsp *);
  43. /* IRQ handlers */
  44. irqreturn_t (*irq_handler)(int irq, void *context);
  45. /* SST init and free */
  46. int (*init)(struct sst_dsp *sst, struct sst_pdata *pdata);
  47. void (*free)(struct sst_dsp *sst);
  48. /* FW module parser/loader */
  49. int (*parse_fw)(struct sst_fw *sst_fw);
  50. };
  51. /*
  52. * Audio DSP memory offsets and addresses.
  53. */
  54. struct sst_addr {
  55. u32 lpe_base;
  56. u32 shim_offset;
  57. u32 iram_offset;
  58. u32 dram_offset;
  59. void __iomem *lpe;
  60. void __iomem *shim;
  61. void __iomem *pci_cfg;
  62. void __iomem *fw_ext;
  63. };
  64. /*
  65. * Audio DSP Mailbox configuration.
  66. */
  67. struct sst_mailbox {
  68. void __iomem *in_base;
  69. void __iomem *out_base;
  70. size_t in_size;
  71. size_t out_size;
  72. };
  73. /*
  74. * Audio DSP Firmware data types.
  75. */
  76. enum sst_data_type {
  77. SST_DATA_M = 0, /* module block data */
  78. SST_DATA_P = 1, /* peristant data (text, data) */
  79. SST_DATA_S = 2, /* scratch data (usually buffers) */
  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 data.
  110. *
  111. * This is used to dsecribe any sections of persistent (text and data) and
  112. * scratch (buffers) of module data in ADSP memory space.
  113. */
  114. struct sst_module_data {
  115. enum sst_mem_type type; /* destination memory type */
  116. enum sst_data_type data_type; /* type of module data */
  117. u32 size; /* size in bytes */
  118. int32_t offset; /* offset in FW file */
  119. u32 data_offset; /* offset in ADSP memory space */
  120. void *data; /* module data */
  121. };
  122. /*
  123. * Audio DSP Generic Module Template.
  124. *
  125. * Used to define and register a new FW module. This data is extracted from
  126. * FW module header information.
  127. */
  128. struct sst_module_template {
  129. u32 id;
  130. u32 entry; /* entry point */
  131. struct sst_module_data s; /* scratch data */
  132. struct sst_module_data p; /* peristant data */
  133. };
  134. /*
  135. * Audio DSP Generic Module.
  136. *
  137. * Each Firmware file can consist of 1..N modules. A module can span multiple
  138. * ADSP memory blocks. The simplest FW will be a file with 1 module.
  139. */
  140. struct sst_module {
  141. struct sst_dsp *dsp;
  142. struct sst_fw *sst_fw; /* parent FW we belong too */
  143. /* module configuration */
  144. u32 id;
  145. u32 entry; /* module entry point */
  146. u32 offset; /* module offset in firmware file */
  147. u32 size; /* module size */
  148. struct sst_module_data s; /* scratch data */
  149. struct sst_module_data p; /* peristant data */
  150. /* runtime */
  151. u32 usage_count; /* can be unloaded if count == 0 */
  152. void *private; /* core doesn't touch this */
  153. /* lists */
  154. struct list_head block_list; /* Module list of blocks in use */
  155. struct list_head list; /* DSP list of modules */
  156. struct list_head list_fw; /* FW list of modules */
  157. };
  158. /*
  159. * SST Memory Block operations.
  160. */
  161. struct sst_block_ops {
  162. int (*enable)(struct sst_mem_block *block);
  163. int (*disable)(struct sst_mem_block *block);
  164. };
  165. /*
  166. * SST Generic Memory Block.
  167. *
  168. * SST ADP memory has multiple IRAM and DRAM blocks. Some ADSP blocks can be
  169. * power gated.
  170. */
  171. struct sst_mem_block {
  172. struct sst_dsp *dsp;
  173. struct sst_module *module; /* module that uses this block */
  174. /* block config */
  175. u32 offset; /* offset from base */
  176. u32 size; /* block size */
  177. u32 index; /* block index 0..N */
  178. enum sst_mem_type type; /* block memory type IRAM/DRAM */
  179. struct sst_block_ops *ops; /* block operations, if any */
  180. /* block status */
  181. enum sst_data_type data_type; /* data type held in this block */
  182. u32 bytes_used; /* bytes in use by modules */
  183. void *private; /* generic core does not touch this */
  184. int users; /* number of modules using this block */
  185. /* block lists */
  186. struct list_head module_list; /* Module list of blocks */
  187. struct list_head list; /* Map list of free/used blocks */
  188. };
  189. /*
  190. * Generic SST Shim Interface.
  191. */
  192. struct sst_dsp {
  193. /* runtime */
  194. struct sst_dsp_device *sst_dev;
  195. spinlock_t spinlock; /* IPC locking */
  196. struct mutex mutex; /* DSP FW lock */
  197. struct device *dev;
  198. struct device *dma_dev;
  199. void *thread_context;
  200. int irq;
  201. u32 id;
  202. /* list of free and used ADSP memory blocks */
  203. struct list_head used_block_list;
  204. struct list_head free_block_list;
  205. /* operations */
  206. struct sst_ops *ops;
  207. /* debug FS */
  208. struct dentry *debugfs_root;
  209. /* base addresses */
  210. struct sst_addr addr;
  211. /* mailbox */
  212. struct sst_mailbox mailbox;
  213. /* SST FW files loaded and their modules */
  214. struct list_head module_list;
  215. struct list_head fw_list;
  216. /* platform data */
  217. struct sst_pdata *pdata;
  218. /* DMA FW loading */
  219. struct sst_dma *dma;
  220. bool fw_use_dma;
  221. };
  222. /* Size optimised DRAM/IRAM memcpy */
  223. static inline void sst_dsp_write(struct sst_dsp *sst, void *src,
  224. u32 dest_offset, size_t bytes)
  225. {
  226. sst->ops->ram_write(sst, sst->addr.lpe + dest_offset, src, bytes);
  227. }
  228. static inline void sst_dsp_read(struct sst_dsp *sst, void *dest,
  229. u32 src_offset, size_t bytes)
  230. {
  231. sst->ops->ram_read(sst, dest, sst->addr.lpe + src_offset, bytes);
  232. }
  233. static inline void *sst_dsp_get_thread_context(struct sst_dsp *sst)
  234. {
  235. return sst->thread_context;
  236. }
  237. /* Create/Free FW files - can contain multiple modules */
  238. struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
  239. const struct firmware *fw, void *private);
  240. void sst_fw_free(struct sst_fw *sst_fw);
  241. void sst_fw_free_all(struct sst_dsp *dsp);
  242. int sst_fw_reload(struct sst_fw *sst_fw);
  243. void sst_fw_unload(struct sst_fw *sst_fw);
  244. /* Create/Free firmware modules */
  245. struct sst_module *sst_module_new(struct sst_fw *sst_fw,
  246. struct sst_module_template *template, void *private);
  247. void sst_module_free(struct sst_module *sst_module);
  248. int sst_module_insert(struct sst_module *sst_module);
  249. int sst_module_remove(struct sst_module *sst_module);
  250. int sst_module_insert_fixed_block(struct sst_module *module,
  251. struct sst_module_data *data);
  252. struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id);
  253. /* allocate/free pesistent/scratch memory regions managed by drv */
  254. struct sst_module *sst_mem_block_alloc_scratch(struct sst_dsp *dsp);
  255. void sst_mem_block_free_scratch(struct sst_dsp *dsp,
  256. struct sst_module *scratch);
  257. int sst_block_module_remove(struct sst_module *module);
  258. /* Register the DSPs memory blocks - would be nice to read from ACPI */
  259. struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
  260. u32 size, enum sst_mem_type type, struct sst_block_ops *ops, u32 index,
  261. void *private);
  262. void sst_mem_block_unregister_all(struct sst_dsp *dsp);
  263. #endif