sof-priv.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
  2. /*
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * Copyright(c) 2018 Intel Corporation
  7. *
  8. * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
  9. */
  10. #ifndef __SOUND_SOC_SOF_PRIV_H
  11. #define __SOUND_SOC_SOF_PRIV_H
  12. #include <linux/device.h>
  13. #include <sound/hdaudio.h>
  14. #include <sound/sof.h>
  15. #include <sound/sof/info.h>
  16. #include <sound/sof/pm.h>
  17. #include <sound/sof/trace.h>
  18. #include <uapi/sound/sof/fw.h>
  19. #include <sound/sof/ext_manifest.h>
  20. struct snd_sof_pcm_stream;
  21. /* Flag definitions used in sof_core_debug (sof_debug module parameter) */
  22. #define SOF_DBG_ENABLE_TRACE BIT(0)
  23. #define SOF_DBG_RETAIN_CTX BIT(1) /* prevent DSP D3 on FW exception */
  24. #define SOF_DBG_VERIFY_TPLG BIT(2) /* verify topology during load */
  25. #define SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE BIT(3) /* 0: use topology token
  26. * 1: override topology
  27. */
  28. #define SOF_DBG_DYNAMIC_PIPELINES_ENABLE BIT(4) /* 0: use static pipelines
  29. * 1: use dynamic pipelines
  30. */
  31. #define SOF_DBG_DISABLE_MULTICORE BIT(5) /* schedule all pipelines/widgets
  32. * on primary core
  33. */
  34. #define SOF_DBG_PRINT_ALL_DUMPS BIT(6) /* Print all ipc and dsp dumps */
  35. #define SOF_DBG_IGNORE_D3_PERSISTENT BIT(7) /* ignore the DSP D3 persistent capability
  36. * and always download firmware upon D3 exit
  37. */
  38. #define SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS BIT(8) /* print DMA position updates
  39. * in dmesg logs
  40. */
  41. #define SOF_DBG_PRINT_IPC_SUCCESS_LOGS BIT(9) /* print IPC success
  42. * in dmesg logs
  43. */
  44. #define SOF_DBG_FORCE_NOCODEC BIT(10) /* ignore all codec-related
  45. * configurations
  46. */
  47. #define SOF_DBG_DUMP_IPC_MESSAGE_PAYLOAD BIT(11) /* On top of the IPC message header
  48. * dump the message payload also
  49. */
  50. #define SOF_DBG_DSPLESS_MODE BIT(15) /* Do not initialize and use the DSP */
  51. /* Flag definitions used for controlling the DSP dump behavior */
  52. #define SOF_DBG_DUMP_REGS BIT(0)
  53. #define SOF_DBG_DUMP_MBOX BIT(1)
  54. #define SOF_DBG_DUMP_TEXT BIT(2)
  55. #define SOF_DBG_DUMP_PCI BIT(3)
  56. /* Output this dump (at the DEBUG level) only when SOF_DBG_PRINT_ALL_DUMPS is set */
  57. #define SOF_DBG_DUMP_OPTIONAL BIT(4)
  58. /* global debug state set by SOF_DBG_ flags */
  59. bool sof_debug_check_flag(int mask);
  60. /* max BARs mmaped devices can use */
  61. #define SND_SOF_BARS 8
  62. /* time in ms for runtime suspend delay */
  63. #define SND_SOF_SUSPEND_DELAY_MS 2000
  64. /* DMA buffer size for trace */
  65. #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16)
  66. #define SOF_IPC_DSP_REPLY 0
  67. #define SOF_IPC_HOST_REPLY 1
  68. /* convenience constructor for DAI driver streams */
  69. #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \
  70. {.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \
  71. .rates = srates, .formats = sfmt}
  72. #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
  73. SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
  74. /* So far the primary core on all DSPs has ID 0 */
  75. #define SOF_DSP_PRIMARY_CORE 0
  76. /* max number of DSP cores */
  77. #define SOF_MAX_DSP_NUM_CORES 8
  78. struct sof_dsp_power_state {
  79. u32 state;
  80. u32 substate; /* platform-specific */
  81. };
  82. /* System suspend target state */
  83. enum sof_system_suspend_state {
  84. SOF_SUSPEND_NONE = 0,
  85. SOF_SUSPEND_S0IX,
  86. SOF_SUSPEND_S3,
  87. SOF_SUSPEND_S4,
  88. SOF_SUSPEND_S5,
  89. };
  90. enum sof_dfsentry_type {
  91. SOF_DFSENTRY_TYPE_IOMEM = 0,
  92. SOF_DFSENTRY_TYPE_BUF,
  93. };
  94. enum sof_debugfs_access_type {
  95. SOF_DEBUGFS_ACCESS_ALWAYS = 0,
  96. SOF_DEBUGFS_ACCESS_D0_ONLY,
  97. };
  98. struct sof_compr_stream {
  99. u64 copied_total;
  100. u32 sampling_rate;
  101. u16 channels;
  102. u16 sample_container_bytes;
  103. size_t posn_offset;
  104. };
  105. struct snd_sof_dev;
  106. struct snd_sof_ipc_msg;
  107. struct snd_sof_ipc;
  108. struct snd_sof_debugfs_map;
  109. struct snd_soc_tplg_ops;
  110. struct snd_soc_component;
  111. struct snd_sof_pdata;
  112. /**
  113. * struct snd_sof_platform_stream_params - platform dependent stream parameters
  114. * @phy_addr: Platform dependent address to be used, if @use_phy_addr
  115. * is true
  116. * @stream_tag: Stream tag to use
  117. * @use_phy_addr: Use the provided @phy_addr for configuration
  118. * @no_ipc_position: Disable position update IPC from firmware
  119. * @cont_update_posn: Continuous position update.
  120. */
  121. struct snd_sof_platform_stream_params {
  122. u32 phy_addr;
  123. u16 stream_tag;
  124. bool use_phy_address;
  125. bool no_ipc_position;
  126. bool cont_update_posn;
  127. };
  128. /**
  129. * struct sof_firmware - Container struct for SOF firmware
  130. * @fw: Pointer to the firmware
  131. * @payload_offset: Offset of the data within the loaded firmware image to be
  132. * loaded to the DSP (skipping for example ext_manifest section)
  133. */
  134. struct sof_firmware {
  135. const struct firmware *fw;
  136. u32 payload_offset;
  137. };
  138. enum sof_dai_access {
  139. SOF_DAI_DSP_ACCESS, /* access from DSP only */
  140. SOF_DAI_HOST_ACCESS, /* access from host only */
  141. SOF_DAI_ACCESS_NUM
  142. };
  143. /*
  144. * SOF DSP HW abstraction operations.
  145. * Used to abstract DSP HW architecture and any IO busses between host CPU
  146. * and DSP device(s).
  147. */
  148. struct snd_sof_dsp_ops {
  149. /* probe/remove/shutdown */
  150. int (*probe_early)(struct snd_sof_dev *sof_dev); /* optional */
  151. int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
  152. void (*remove)(struct snd_sof_dev *sof_dev); /* optional */
  153. void (*remove_late)(struct snd_sof_dev *sof_dev); /* optional */
  154. int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */
  155. /* DSP core boot / reset */
  156. int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */
  157. int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */
  158. int (*reset)(struct snd_sof_dev *sof_dev); /* optional */
  159. int (*core_get)(struct snd_sof_dev *sof_dev, int core); /* optional */
  160. int (*core_put)(struct snd_sof_dev *sof_dev, int core); /* optional */
  161. /*
  162. * Register IO: only used by respective drivers themselves,
  163. * TODO: consider removing these operations and calling respective
  164. * implementations directly
  165. */
  166. void (*write8)(struct snd_sof_dev *sof_dev, void __iomem *addr,
  167. u8 value); /* optional */
  168. u8 (*read8)(struct snd_sof_dev *sof_dev,
  169. void __iomem *addr); /* optional */
  170. void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
  171. u32 value); /* optional */
  172. u32 (*read)(struct snd_sof_dev *sof_dev,
  173. void __iomem *addr); /* optional */
  174. void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
  175. u64 value); /* optional */
  176. u64 (*read64)(struct snd_sof_dev *sof_dev,
  177. void __iomem *addr); /* optional */
  178. /* memcpy IO */
  179. int (*block_read)(struct snd_sof_dev *sof_dev,
  180. enum snd_sof_fw_blk_type type, u32 offset,
  181. void *dest, size_t size); /* mandatory */
  182. int (*block_write)(struct snd_sof_dev *sof_dev,
  183. enum snd_sof_fw_blk_type type, u32 offset,
  184. void *src, size_t size); /* mandatory */
  185. /* Mailbox IO */
  186. void (*mailbox_read)(struct snd_sof_dev *sof_dev,
  187. u32 offset, void *dest,
  188. size_t size); /* optional */
  189. void (*mailbox_write)(struct snd_sof_dev *sof_dev,
  190. u32 offset, void *src,
  191. size_t size); /* optional */
  192. /* doorbell */
  193. irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
  194. irqreturn_t (*irq_thread)(int irq, void *context); /* optional */
  195. /* ipc */
  196. int (*send_msg)(struct snd_sof_dev *sof_dev,
  197. struct snd_sof_ipc_msg *msg); /* mandatory */
  198. /* FW loading */
  199. int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
  200. int (*load_module)(struct snd_sof_dev *sof_dev,
  201. struct snd_sof_mod_hdr *hdr); /* optional */
  202. /* connect pcm substream to a host stream */
  203. int (*pcm_open)(struct snd_sof_dev *sdev,
  204. struct snd_pcm_substream *substream); /* optional */
  205. /* disconnect pcm substream to a host stream */
  206. int (*pcm_close)(struct snd_sof_dev *sdev,
  207. struct snd_pcm_substream *substream); /* optional */
  208. /* host stream hw params */
  209. int (*pcm_hw_params)(struct snd_sof_dev *sdev,
  210. struct snd_pcm_substream *substream,
  211. struct snd_pcm_hw_params *params,
  212. struct snd_sof_platform_stream_params *platform_params); /* optional */
  213. /* host stream hw_free */
  214. int (*pcm_hw_free)(struct snd_sof_dev *sdev,
  215. struct snd_pcm_substream *substream); /* optional */
  216. /* host stream trigger */
  217. int (*pcm_trigger)(struct snd_sof_dev *sdev,
  218. struct snd_pcm_substream *substream,
  219. int cmd); /* optional */
  220. /* host stream pointer */
  221. snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
  222. struct snd_pcm_substream *substream); /* optional */
  223. /* pcm ack */
  224. int (*pcm_ack)(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream); /* optional */
  225. /*
  226. * optional callback to retrieve the number of frames left/arrived from/to
  227. * the DSP on the DAI side (link/codec/DMIC/etc).
  228. *
  229. * The callback is used when the firmware does not provide this information
  230. * via the shared SRAM window and it can be retrieved by host.
  231. */
  232. u64 (*get_dai_frame_counter)(struct snd_sof_dev *sdev,
  233. struct snd_soc_component *component,
  234. struct snd_pcm_substream *substream); /* optional */
  235. /*
  236. * Optional callback to retrieve the number of bytes left/arrived from/to
  237. * the DSP on the host side (bytes between host ALSA buffer and DSP).
  238. *
  239. * The callback is needed for ALSA delay reporting.
  240. */
  241. u64 (*get_host_byte_counter)(struct snd_sof_dev *sdev,
  242. struct snd_soc_component *component,
  243. struct snd_pcm_substream *substream); /* optional */
  244. /* host read DSP stream data */
  245. int (*ipc_msg_data)(struct snd_sof_dev *sdev,
  246. struct snd_sof_pcm_stream *sps,
  247. void *p, size_t sz); /* mandatory */
  248. /* host side configuration of the stream's data offset in stream mailbox area */
  249. int (*set_stream_data_offset)(struct snd_sof_dev *sdev,
  250. struct snd_sof_pcm_stream *sps,
  251. size_t posn_offset); /* optional */
  252. /* pre/post firmware run */
  253. int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
  254. int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
  255. /* parse platform specific extended manifest, optional */
  256. int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev,
  257. const struct sof_ext_man_elem_header *hdr);
  258. /* DSP PM */
  259. int (*suspend)(struct snd_sof_dev *sof_dev,
  260. u32 target_state); /* optional */
  261. int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
  262. int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
  263. int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
  264. int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
  265. int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
  266. int (*set_power_state)(struct snd_sof_dev *sdev,
  267. const struct sof_dsp_power_state *target_state); /* optional */
  268. /* DSP clocking */
  269. int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
  270. /* debug */
  271. const struct snd_sof_debugfs_map *debug_map; /* optional */
  272. int debug_map_count; /* optional */
  273. void (*dbg_dump)(struct snd_sof_dev *sof_dev,
  274. u32 flags); /* optional */
  275. void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
  276. int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
  277. enum snd_sof_fw_blk_type blk_type, u32 offset,
  278. size_t size, const char *name,
  279. enum sof_debugfs_access_type access_type); /* optional */
  280. /* host DMA trace (IPC3) */
  281. int (*trace_init)(struct snd_sof_dev *sdev,
  282. struct snd_dma_buffer *dmatb,
  283. struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */
  284. int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
  285. int (*trace_trigger)(struct snd_sof_dev *sdev,
  286. int cmd); /* optional */
  287. /* misc */
  288. int (*get_bar_index)(struct snd_sof_dev *sdev,
  289. u32 type); /* optional */
  290. int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
  291. int (*get_window_offset)(struct snd_sof_dev *sdev,
  292. u32 id);/* mandatory for common loader code */
  293. /* machine driver ops */
  294. int (*machine_register)(struct snd_sof_dev *sdev,
  295. void *pdata); /* optional */
  296. void (*machine_unregister)(struct snd_sof_dev *sdev,
  297. void *pdata); /* optional */
  298. struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */
  299. void (*set_mach_params)(struct snd_soc_acpi_mach *mach,
  300. struct snd_sof_dev *sdev); /* optional */
  301. /* IPC client ops */
  302. int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
  303. void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
  304. /* DAI ops */
  305. struct snd_soc_dai_driver *drv;
  306. int num_drv;
  307. bool (*is_chain_dma_supported)(struct snd_sof_dev *sdev, u32 dai_type); /* optional */
  308. /* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
  309. u32 hw_info;
  310. const struct dsp_arch_ops *dsp_arch_ops;
  311. };
  312. /* DSP architecture specific callbacks for oops and stack dumps */
  313. struct dsp_arch_ops {
  314. void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops);
  315. void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops,
  316. u32 *stack, u32 stack_words);
  317. };
  318. #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
  319. /* FS entry for debug files that can expose DSP memories, registers */
  320. struct snd_sof_dfsentry {
  321. size_t size;
  322. size_t buf_data_size; /* length of buffered data for file read operation */
  323. enum sof_dfsentry_type type;
  324. /*
  325. * access_type specifies if the
  326. * memory -> DSP resource (memory, register etc) is always accessible
  327. * or if it is accessible only when the DSP is in D0.
  328. */
  329. enum sof_debugfs_access_type access_type;
  330. #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
  331. char *cache_buf; /* buffer to cache the contents of debugfs memory */
  332. #endif
  333. struct snd_sof_dev *sdev;
  334. struct list_head list; /* list in sdev dfsentry list */
  335. union {
  336. void __iomem *io_mem;
  337. void *buf;
  338. };
  339. };
  340. /* Debug mapping for any DSP memory or registers that can used for debug */
  341. struct snd_sof_debugfs_map {
  342. const char *name;
  343. u32 bar;
  344. u32 offset;
  345. u32 size;
  346. /*
  347. * access_type specifies if the memory is always accessible
  348. * or if it is accessible only when the DSP is in D0.
  349. */
  350. enum sof_debugfs_access_type access_type;
  351. };
  352. /* mailbox descriptor, used for host <-> DSP IPC */
  353. struct snd_sof_mailbox {
  354. size_t size;
  355. u32 offset;
  356. };
  357. /* IPC message descriptor for host <-> DSP IO */
  358. struct snd_sof_ipc_msg {
  359. /* message data */
  360. void *msg_data;
  361. void *reply_data;
  362. size_t msg_size;
  363. size_t reply_size;
  364. int reply_error;
  365. bool ipc_complete;
  366. wait_queue_head_t waitq;
  367. /* notification, firmware initiated messages */
  368. void *rx_data;
  369. };
  370. /**
  371. * struct sof_ipc_fw_tracing_ops - IPC-specific firmware tracing ops
  372. * @init: Function pointer for initialization of the tracing
  373. * @free: Optional function pointer for freeing of the tracing
  374. * @fw_crashed: Optional function pointer to notify the tracing of a firmware crash
  375. * @suspend: Function pointer for system/runtime suspend
  376. * @resume: Function pointer for system/runtime resume
  377. */
  378. struct sof_ipc_fw_tracing_ops {
  379. int (*init)(struct snd_sof_dev *sdev);
  380. void (*free)(struct snd_sof_dev *sdev);
  381. void (*fw_crashed)(struct snd_sof_dev *sdev);
  382. void (*suspend)(struct snd_sof_dev *sdev, pm_message_t pm_state);
  383. int (*resume)(struct snd_sof_dev *sdev);
  384. };
  385. /**
  386. * struct sof_ipc_pm_ops - IPC-specific PM ops
  387. * @ctx_save: Optional function pointer for context save
  388. * @ctx_restore: Optional function pointer for context restore
  389. * @set_core_state: Optional function pointer for turning on/off a DSP core
  390. * @set_pm_gate: Optional function pointer for pm gate settings
  391. */
  392. struct sof_ipc_pm_ops {
  393. int (*ctx_save)(struct snd_sof_dev *sdev);
  394. int (*ctx_restore)(struct snd_sof_dev *sdev);
  395. int (*set_core_state)(struct snd_sof_dev *sdev, int core_idx, bool on);
  396. int (*set_pm_gate)(struct snd_sof_dev *sdev, u32 flags);
  397. };
  398. /**
  399. * struct sof_ipc_fw_loader_ops - IPC/FW-specific loader ops
  400. * @validate: Function pointer for validating the firmware image
  401. * @parse_ext_manifest: Function pointer for parsing the manifest of the firmware
  402. * @load_fw_to_dsp: Optional function pointer for loading the firmware to the
  403. * DSP.
  404. * The function implements generic, hardware independent way
  405. * of loading the initial firmware and its modules (if any).
  406. */
  407. struct sof_ipc_fw_loader_ops {
  408. int (*validate)(struct snd_sof_dev *sdev);
  409. size_t (*parse_ext_manifest)(struct snd_sof_dev *sdev);
  410. int (*load_fw_to_dsp)(struct snd_sof_dev *sdev);
  411. };
  412. struct sof_ipc_tplg_ops;
  413. struct sof_ipc_pcm_ops;
  414. /**
  415. * struct sof_ipc_ops - IPC-specific ops
  416. * @tplg: Pointer to IPC-specific topology ops
  417. * @pm: Pointer to PM ops
  418. * @pcm: Pointer to PCM ops
  419. * @fw_loader: Pointer to Firmware Loader ops
  420. * @fw_tracing: Optional pointer to Firmware tracing ops
  421. *
  422. * @init: Optional pointer for IPC related initialization
  423. * @exit: Optional pointer for IPC related cleanup
  424. * @post_fw_boot: Optional pointer to execute IPC related tasks after firmware
  425. * boot.
  426. *
  427. * @tx_msg: Function pointer for sending a 'short' IPC message
  428. * @set_get_data: Function pointer for set/get data ('large' IPC message). This
  429. * function may split up the 'large' message and use the @tx_msg
  430. * path to transfer individual chunks, or use other means to transfer
  431. * the message.
  432. * @get_reply: Function pointer for fetching the reply to
  433. * sdev->ipc->msg.reply_data
  434. * @rx_msg: Function pointer for handling a received message
  435. *
  436. * Note: both @tx_msg and @set_get_data considered as TX functions and they are
  437. * serialized for the duration of the instructed transfer. A large message sent
  438. * via @set_get_data is a single transfer even if at the hardware level it is
  439. * handled with multiple chunks.
  440. */
  441. struct sof_ipc_ops {
  442. const struct sof_ipc_tplg_ops *tplg;
  443. const struct sof_ipc_pm_ops *pm;
  444. const struct sof_ipc_pcm_ops *pcm;
  445. const struct sof_ipc_fw_loader_ops *fw_loader;
  446. const struct sof_ipc_fw_tracing_ops *fw_tracing;
  447. int (*init)(struct snd_sof_dev *sdev);
  448. void (*exit)(struct snd_sof_dev *sdev);
  449. int (*post_fw_boot)(struct snd_sof_dev *sdev);
  450. int (*tx_msg)(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
  451. void *reply_data, size_t reply_bytes, bool no_pm);
  452. int (*set_get_data)(struct snd_sof_dev *sdev, void *data, size_t data_bytes,
  453. bool set);
  454. int (*get_reply)(struct snd_sof_dev *sdev);
  455. void (*rx_msg)(struct snd_sof_dev *sdev);
  456. };
  457. /* SOF generic IPC data */
  458. struct snd_sof_ipc {
  459. struct snd_sof_dev *sdev;
  460. /* protects messages and the disable flag */
  461. struct mutex tx_mutex;
  462. /* disables further sending of ipc's */
  463. bool disable_ipc_tx;
  464. /* Maximum allowed size of a single IPC message/reply */
  465. size_t max_payload_size;
  466. struct snd_sof_ipc_msg msg;
  467. /* IPC ops based on version */
  468. const struct sof_ipc_ops *ops;
  469. };
  470. /* Helper to retrieve the IPC ops */
  471. #define sof_ipc_get_ops(sdev, ops_name) \
  472. (((sdev)->ipc && (sdev)->ipc->ops) ? (sdev)->ipc->ops->ops_name : NULL)
  473. /*
  474. * SOF Device Level.
  475. */
  476. struct snd_sof_dev {
  477. struct device *dev;
  478. spinlock_t ipc_lock; /* lock for IPC users */
  479. spinlock_t hw_lock; /* lock for HW IO access */
  480. /*
  481. * When true the DSP is not used.
  482. * It is set under the following condition:
  483. * User sets the SOF_DBG_DSPLESS_MODE flag in sof_debug module parameter
  484. * and
  485. * the platform advertises that it can support such mode
  486. * pdata->desc->dspless_mode_supported is true.
  487. */
  488. bool dspless_mode_selected;
  489. /* Main, Base firmware image */
  490. struct sof_firmware basefw;
  491. /*
  492. * ASoC components. plat_drv fields are set dynamically so
  493. * can't use const
  494. */
  495. struct snd_soc_component_driver plat_drv;
  496. /* current DSP power state */
  497. struct sof_dsp_power_state dsp_power_state;
  498. /* mutex to protect the dsp_power_state access */
  499. struct mutex power_state_access;
  500. /* Intended power target of system suspend */
  501. enum sof_system_suspend_state system_suspend_target;
  502. /* DSP firmware boot */
  503. wait_queue_head_t boot_wait;
  504. enum sof_fw_state fw_state;
  505. bool first_boot;
  506. /* work queue in case the probe is implemented in two steps */
  507. struct work_struct probe_work;
  508. bool probe_completed;
  509. /* DSP HW differentiation */
  510. struct snd_sof_pdata *pdata;
  511. /* IPC */
  512. struct snd_sof_ipc *ipc;
  513. struct snd_sof_mailbox fw_info_box; /* FW shared memory */
  514. struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */
  515. struct snd_sof_mailbox host_box; /* Host initiated IPC */
  516. struct snd_sof_mailbox stream_box; /* Stream position update */
  517. struct snd_sof_mailbox debug_box; /* Debug info updates */
  518. struct snd_sof_ipc_msg *msg;
  519. int ipc_irq;
  520. u32 next_comp_id; /* monotonic - reset during S3 */
  521. /* memory bases for mmaped DSPs - set by dsp_init() */
  522. void __iomem *bar[SND_SOF_BARS]; /* DSP base address */
  523. int mmio_bar;
  524. int mailbox_bar;
  525. size_t dsp_oops_offset;
  526. /* debug */
  527. struct dentry *debugfs_root;
  528. struct list_head dfsentry_list;
  529. bool dbg_dump_printed;
  530. bool ipc_dump_printed;
  531. bool d3_prevented; /* runtime pm use count incremented to prevent context lost */
  532. /* firmware loader */
  533. struct sof_ipc_fw_ready fw_ready;
  534. struct sof_ipc_fw_version fw_version;
  535. struct sof_ipc_cc_version *cc_version;
  536. /* topology */
  537. struct snd_soc_tplg_ops *tplg_ops;
  538. struct list_head pcm_list;
  539. struct list_head kcontrol_list;
  540. struct list_head widget_list;
  541. struct list_head pipeline_list;
  542. struct list_head dai_list;
  543. struct list_head dai_link_list;
  544. struct list_head route_list;
  545. struct snd_soc_component *component;
  546. u32 enabled_cores_mask; /* keep track of enabled cores */
  547. bool led_present;
  548. /* FW configuration */
  549. struct sof_ipc_window *info_window;
  550. /* IPC timeouts in ms */
  551. int ipc_timeout;
  552. int boot_timeout;
  553. /* firmwre tracing */
  554. bool fw_trace_is_supported; /* set with Kconfig or module parameter */
  555. void *fw_trace_data; /* private data used by firmware tracing implementation */
  556. bool msi_enabled;
  557. /* DSP core context */
  558. u32 num_cores;
  559. /*
  560. * ref count per core that will be modified during system suspend/resume and during pcm
  561. * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
  562. * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
  563. * sound/core/ when streams are active and during system suspend/resume, streams are
  564. * already suspended.
  565. */
  566. int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
  567. /*
  568. * Used to keep track of registered IPC client devices so that they can
  569. * be removed when the parent SOF module is removed.
  570. */
  571. struct list_head ipc_client_list;
  572. /* mutex to protect client list */
  573. struct mutex ipc_client_mutex;
  574. /*
  575. * Used for tracking the IPC client's RX registration for DSP initiated
  576. * message handling.
  577. */
  578. struct list_head ipc_rx_handler_list;
  579. /*
  580. * Used for tracking the IPC client's registration for DSP state change
  581. * notification
  582. */
  583. struct list_head fw_state_handler_list;
  584. /* to protect the ipc_rx_handler_list and dsp_state_handler_list list */
  585. struct mutex client_event_handler_mutex;
  586. /* quirks to override topology values */
  587. bool mclk_id_override;
  588. u16 mclk_id_quirk; /* same size as in IPC3 definitions */
  589. void *private; /* core does not touch this */
  590. };
  591. /*
  592. * Device Level.
  593. */
  594. int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
  595. int snd_sof_device_remove(struct device *dev);
  596. int snd_sof_device_shutdown(struct device *dev);
  597. bool snd_sof_device_probe_completed(struct device *dev);
  598. int snd_sof_runtime_suspend(struct device *dev);
  599. int snd_sof_runtime_resume(struct device *dev);
  600. int snd_sof_runtime_idle(struct device *dev);
  601. int snd_sof_resume(struct device *dev);
  602. int snd_sof_suspend(struct device *dev);
  603. int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
  604. int snd_sof_prepare(struct device *dev);
  605. void snd_sof_complete(struct device *dev);
  606. void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
  607. /*
  608. * Compress support
  609. */
  610. extern struct snd_compress_ops sof_compressed_ops;
  611. /*
  612. * Firmware (firmware, libraries, topologies) file location
  613. */
  614. int sof_create_ipc_file_profile(struct snd_sof_dev *sdev,
  615. struct sof_loadable_file_profile *base_profile,
  616. struct sof_loadable_file_profile *out_profile);
  617. /*
  618. * Firmware loading.
  619. */
  620. int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
  621. int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
  622. int snd_sof_run_firmware(struct snd_sof_dev *sdev);
  623. void snd_sof_fw_unload(struct snd_sof_dev *sdev);
  624. /*
  625. * IPC low level APIs.
  626. */
  627. struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
  628. void snd_sof_ipc_free(struct snd_sof_dev *sdev);
  629. void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
  630. void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
  631. static inline void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
  632. {
  633. sdev->ipc->ops->rx_msg(sdev);
  634. }
  635. int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
  636. void *reply_data, size_t reply_bytes);
  637. static inline int sof_ipc_tx_message_no_reply(struct snd_sof_ipc *ipc, void *msg_data,
  638. size_t msg_bytes)
  639. {
  640. return sof_ipc_tx_message(ipc, msg_data, msg_bytes, NULL, 0);
  641. }
  642. int sof_ipc_set_get_data(struct snd_sof_ipc *ipc, void *msg_data,
  643. size_t msg_bytes, bool set);
  644. int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
  645. void *reply_data, size_t reply_bytes);
  646. static inline int sof_ipc_tx_message_no_pm_no_reply(struct snd_sof_ipc *ipc, void *msg_data,
  647. size_t msg_bytes)
  648. {
  649. return sof_ipc_tx_message_no_pm(ipc, msg_data, msg_bytes, NULL, 0);
  650. }
  651. int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
  652. size_t reply_bytes);
  653. static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
  654. {
  655. snd_sof_ipc_get_reply(sdev);
  656. snd_sof_ipc_reply(sdev, msg_id);
  657. }
  658. /*
  659. * Trace/debug
  660. */
  661. int snd_sof_dbg_init(struct snd_sof_dev *sdev);
  662. void snd_sof_free_debug(struct snd_sof_dev *sdev);
  663. int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
  664. void *base, size_t size,
  665. const char *name, mode_t mode);
  666. void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
  667. u32 panic_code, u32 tracep_code, void *oops,
  668. struct sof_ipc_panic_info *panic_info,
  669. void *stack, size_t stack_words);
  670. void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev, const char *msg);
  671. int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
  672. int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
  673. enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
  674. const char *name, enum sof_debugfs_access_type access_type);
  675. /* Firmware tracing */
  676. int sof_fw_trace_init(struct snd_sof_dev *sdev);
  677. void sof_fw_trace_free(struct snd_sof_dev *sdev);
  678. void sof_fw_trace_fw_crashed(struct snd_sof_dev *sdev);
  679. void sof_fw_trace_suspend(struct snd_sof_dev *sdev, pm_message_t pm_state);
  680. int sof_fw_trace_resume(struct snd_sof_dev *sdev);
  681. /*
  682. * DSP Architectures.
  683. */
  684. static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
  685. void *oops, u32 *stack, u32 stack_words)
  686. {
  687. sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level, oops, stack,
  688. stack_words);
  689. }
  690. static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
  691. {
  692. if (sof_dsp_arch_ops(sdev)->dsp_oops)
  693. sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops);
  694. }
  695. extern const struct dsp_arch_ops sof_xtensa_arch_ops;
  696. /*
  697. * Firmware state tracking
  698. */
  699. void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
  700. /*
  701. * Utilities
  702. */
  703. void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
  704. void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
  705. u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
  706. u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
  707. void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
  708. void *message, size_t bytes);
  709. void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
  710. void *message, size_t bytes);
  711. int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
  712. u32 offset, void *src, size_t size);
  713. int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
  714. u32 offset, void *dest, size_t size);
  715. int sof_ipc_msg_data(struct snd_sof_dev *sdev,
  716. struct snd_sof_pcm_stream *sps,
  717. void *p, size_t sz);
  718. int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
  719. struct snd_sof_pcm_stream *sps,
  720. size_t posn_offset);
  721. int sof_stream_pcm_open(struct snd_sof_dev *sdev,
  722. struct snd_pcm_substream *substream);
  723. int sof_stream_pcm_close(struct snd_sof_dev *sdev,
  724. struct snd_pcm_substream *substream);
  725. /* SOF client support */
  726. #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
  727. int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
  728. const void *data, size_t size);
  729. void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
  730. int sof_register_clients(struct snd_sof_dev *sdev);
  731. void sof_unregister_clients(struct snd_sof_dev *sdev);
  732. void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
  733. void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
  734. int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
  735. int sof_resume_clients(struct snd_sof_dev *sdev);
  736. #else /* CONFIG_SND_SOC_SOF_CLIENT */
  737. static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
  738. u32 id, const void *data, size_t size)
  739. {
  740. return 0;
  741. }
  742. static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
  743. const char *name, u32 id)
  744. {
  745. }
  746. static inline int sof_register_clients(struct snd_sof_dev *sdev)
  747. {
  748. return 0;
  749. }
  750. static inline void sof_unregister_clients(struct snd_sof_dev *sdev)
  751. {
  752. }
  753. static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
  754. {
  755. }
  756. static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
  757. {
  758. }
  759. static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
  760. {
  761. return 0;
  762. }
  763. static inline int sof_resume_clients(struct snd_sof_dev *sdev)
  764. {
  765. return 0;
  766. }
  767. #endif /* CONFIG_SND_SOC_SOF_CLIENT */
  768. /* Main ops for IPC implementations */
  769. extern const struct sof_ipc_ops ipc3_ops;
  770. extern const struct sof_ipc_ops ipc4_ops;
  771. #endif