sof-priv.h 26 KB

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