1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
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.
6 * Copyright(c) 2018 Intel Corporation. All rights reserved.
8 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
11 #ifndef __SOUND_SOC_SOF_PRIV_H
12 #define __SOUND_SOC_SOF_PRIV_H
14 #include <linux/device.h>
15 #include <sound/hdaudio.h>
16 #include <sound/sof.h>
17 #include <sound/sof/info.h>
18 #include <sound/sof/pm.h>
19 #include <sound/sof/trace.h>
20 #include <uapi/sound/sof/fw.h>
21 #include <sound/sof/ext_manifest.h>
23 /* Flag definitions used in sof_core_debug (sof_debug module parameter) */
24 #define SOF_DBG_ENABLE_TRACE BIT(0)
25 #define SOF_DBG_RETAIN_CTX BIT(1) /* prevent DSP D3 on FW exception */
26 #define SOF_DBG_VERIFY_TPLG BIT(2) /* verify topology during load */
27 #define SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE BIT(3) /* 0: use topology token
28 * 1: override topology
30 #define SOF_DBG_DYNAMIC_PIPELINES_ENABLE BIT(4) /* 0: use static pipelines
31 * 1: use dynamic pipelines
33 #define SOF_DBG_DISABLE_MULTICORE BIT(5) /* schedule all pipelines/widgets
36 #define SOF_DBG_PRINT_ALL_DUMPS BIT(6) /* Print all ipc and dsp dumps */
37 #define SOF_DBG_IGNORE_D3_PERSISTENT BIT(7) /* ignore the DSP D3 persistent capability
38 * and always download firmware upon D3 exit
40 #define SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS BIT(8) /* print DMA position updates
43 #define SOF_DBG_PRINT_IPC_SUCCESS_LOGS BIT(9) /* print IPC success
47 /* Flag definitions used for controlling the DSP dump behavior */
48 #define SOF_DBG_DUMP_REGS BIT(0)
49 #define SOF_DBG_DUMP_MBOX BIT(1)
50 #define SOF_DBG_DUMP_TEXT BIT(2)
51 #define SOF_DBG_DUMP_PCI BIT(3)
52 /* Output this dump (at the DEBUG level) only when SOF_DBG_PRINT_ALL_DUMPS is set */
53 #define SOF_DBG_DUMP_OPTIONAL BIT(4)
55 /* global debug state set by SOF_DBG_ flags */
56 bool sof_debug_check_flag(int mask);
58 /* max BARs mmaped devices can use */
59 #define SND_SOF_BARS 8
61 /* time in ms for runtime suspend delay */
62 #define SND_SOF_SUSPEND_DELAY_MS 2000
64 /* DMA buffer size for trace */
65 #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16)
67 #define SOF_IPC_DSP_REPLY 0
68 #define SOF_IPC_HOST_REPLY 1
70 /* convenience constructor for DAI driver streams */
71 #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \
72 {.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \
73 .rates = srates, .formats = sfmt}
75 #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
76 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
78 /* So far the primary core on all DSPs has ID 0 */
79 #define SOF_DSP_PRIMARY_CORE 0
81 /* max number of DSP cores */
82 #define SOF_MAX_DSP_NUM_CORES 8
84 struct sof_dsp_power_state {
86 u32 substate; /* platform-specific */
89 /* System suspend target state */
90 enum sof_system_suspend_state {
98 enum sof_dfsentry_type {
99 SOF_DFSENTRY_TYPE_IOMEM = 0,
100 SOF_DFSENTRY_TYPE_BUF,
103 enum sof_debugfs_access_type {
104 SOF_DEBUGFS_ACCESS_ALWAYS = 0,
105 SOF_DEBUGFS_ACCESS_D0_ONLY,
108 struct sof_compr_stream {
112 u16 sample_container_bytes;
116 struct snd_sof_ipc_msg;
118 struct snd_sof_debugfs_map;
119 struct snd_soc_tplg_ops;
120 struct snd_soc_component;
121 struct snd_sof_pdata;
124 * struct snd_sof_platform_stream_params - platform dependent stream parameters
125 * @stream_tag: Stream tag to use
126 * @use_phy_addr: Use the provided @phy_addr for configuration
127 * @phy_addr: Platform dependent address to be used, if @use_phy_addr
129 * @no_ipc_position: Disable position update IPC from firmware
131 struct snd_sof_platform_stream_params {
133 bool use_phy_address;
135 bool no_ipc_position;
136 bool cont_update_posn;
140 * struct sof_firmware - Container struct for SOF firmware
141 * @fw: Pointer to the firmware
142 * @payload_offset: Offset of the data within the loaded firmware image to be
143 * loaded to the DSP (skipping for example ext_manifest section)
145 struct sof_firmware {
146 const struct firmware *fw;
151 * SOF DSP HW abstraction operations.
152 * Used to abstract DSP HW architecture and any IO busses between host CPU
155 struct snd_sof_dsp_ops {
157 /* probe/remove/shutdown */
158 int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
159 int (*remove)(struct snd_sof_dev *sof_dev); /* optional */
160 int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */
162 /* DSP core boot / reset */
163 int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */
164 int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */
165 int (*reset)(struct snd_sof_dev *sof_dev); /* optional */
166 int (*core_get)(struct snd_sof_dev *sof_dev, int core); /* optional */
167 int (*core_put)(struct snd_sof_dev *sof_dev, int core); /* optional */
170 * Register IO: only used by respective drivers themselves,
171 * TODO: consider removing these operations and calling respective
172 * implementations directly
174 void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
175 u32 value); /* optional */
176 u32 (*read)(struct snd_sof_dev *sof_dev,
177 void __iomem *addr); /* optional */
178 void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
179 u64 value); /* optional */
180 u64 (*read64)(struct snd_sof_dev *sof_dev,
181 void __iomem *addr); /* optional */
184 int (*block_read)(struct snd_sof_dev *sof_dev,
185 enum snd_sof_fw_blk_type type, u32 offset,
186 void *dest, size_t size); /* mandatory */
187 int (*block_write)(struct snd_sof_dev *sof_dev,
188 enum snd_sof_fw_blk_type type, u32 offset,
189 void *src, size_t size); /* mandatory */
192 void (*mailbox_read)(struct snd_sof_dev *sof_dev,
193 u32 offset, void *dest,
194 size_t size); /* optional */
195 void (*mailbox_write)(struct snd_sof_dev *sof_dev,
196 u32 offset, void *src,
197 size_t size); /* optional */
200 irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
201 irqreturn_t (*irq_thread)(int irq, void *context); /* optional */
204 int (*send_msg)(struct snd_sof_dev *sof_dev,
205 struct snd_sof_ipc_msg *msg); /* mandatory */
208 int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
209 int (*load_module)(struct snd_sof_dev *sof_dev,
210 struct snd_sof_mod_hdr *hdr); /* optional */
212 /* connect pcm substream to a host stream */
213 int (*pcm_open)(struct snd_sof_dev *sdev,
214 struct snd_pcm_substream *substream); /* optional */
215 /* disconnect pcm substream to a host stream */
216 int (*pcm_close)(struct snd_sof_dev *sdev,
217 struct snd_pcm_substream *substream); /* optional */
219 /* host stream hw params */
220 int (*pcm_hw_params)(struct snd_sof_dev *sdev,
221 struct snd_pcm_substream *substream,
222 struct snd_pcm_hw_params *params,
223 struct snd_sof_platform_stream_params *platform_params); /* optional */
225 /* host stream hw_free */
226 int (*pcm_hw_free)(struct snd_sof_dev *sdev,
227 struct snd_pcm_substream *substream); /* optional */
229 /* host stream trigger */
230 int (*pcm_trigger)(struct snd_sof_dev *sdev,
231 struct snd_pcm_substream *substream,
232 int cmd); /* optional */
234 /* host stream pointer */
235 snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
236 struct snd_pcm_substream *substream); /* optional */
239 int (*pcm_ack)(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream); /* optional */
241 /* host read DSP stream data */
242 int (*ipc_msg_data)(struct snd_sof_dev *sdev,
243 struct snd_pcm_substream *substream,
244 void *p, size_t sz); /* mandatory */
246 /* host side configuration of the stream's data offset in stream mailbox area */
247 int (*set_stream_data_offset)(struct snd_sof_dev *sdev,
248 struct snd_pcm_substream *substream,
249 size_t posn_offset); /* optional */
251 /* pre/post firmware run */
252 int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
253 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);
260 int (*suspend)(struct snd_sof_dev *sof_dev,
261 u32 target_state); /* optional */
262 int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
263 int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
264 int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
265 int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
266 int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
267 int (*set_power_state)(struct snd_sof_dev *sdev,
268 const struct sof_dsp_power_state *target_state); /* optional */
271 int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
274 const struct snd_sof_debugfs_map *debug_map; /* optional */
275 int debug_map_count; /* optional */
276 void (*dbg_dump)(struct snd_sof_dev *sof_dev,
277 u32 flags); /* optional */
278 void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
279 int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
280 enum snd_sof_fw_blk_type blk_type, u32 offset,
281 size_t size, const char *name,
282 enum sof_debugfs_access_type access_type); /* optional */
284 /* host DMA trace (IPC3) */
285 int (*trace_init)(struct snd_sof_dev *sdev,
286 struct snd_dma_buffer *dmatb,
287 struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */
288 int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
289 int (*trace_trigger)(struct snd_sof_dev *sdev,
290 int cmd); /* optional */
293 int (*get_bar_index)(struct snd_sof_dev *sdev,
294 u32 type); /* optional */
295 int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
296 int (*get_window_offset)(struct snd_sof_dev *sdev,
297 u32 id);/* mandatory for common loader code */
299 /* machine driver ops */
300 int (*machine_register)(struct snd_sof_dev *sdev,
301 void *pdata); /* optional */
302 void (*machine_unregister)(struct snd_sof_dev *sdev,
303 void *pdata); /* optional */
304 struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */
305 void (*set_mach_params)(struct snd_soc_acpi_mach *mach,
306 struct snd_sof_dev *sdev); /* optional */
309 int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
310 void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
313 struct snd_soc_dai_driver *drv;
316 /* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
319 const struct dsp_arch_ops *dsp_arch_ops;
322 /* DSP architecture specific callbacks for oops and stack dumps */
323 struct dsp_arch_ops {
324 void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops);
325 void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops,
326 u32 *stack, u32 stack_words);
329 #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
331 /* FS entry for debug files that can expose DSP memories, registers */
332 struct snd_sof_dfsentry {
334 size_t buf_data_size; /* length of buffered data for file read operation */
335 enum sof_dfsentry_type type;
337 * access_type specifies if the
338 * memory -> DSP resource (memory, register etc) is always accessible
339 * or if it is accessible only when the DSP is in D0.
341 enum sof_debugfs_access_type access_type;
342 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
343 char *cache_buf; /* buffer to cache the contents of debugfs memory */
345 struct snd_sof_dev *sdev;
346 struct list_head list; /* list in sdev dfsentry list */
348 void __iomem *io_mem;
353 /* Debug mapping for any DSP memory or registers that can used for debug */
354 struct snd_sof_debugfs_map {
360 * access_type specifies if the memory is always accessible
361 * or if it is accessible only when the DSP is in D0.
363 enum sof_debugfs_access_type access_type;
366 /* mailbox descriptor, used for host <-> DSP IPC */
367 struct snd_sof_mailbox {
372 /* IPC message descriptor for host <-> DSP IO */
373 struct snd_sof_ipc_msg {
381 /* notification, firmware initiated messages */
384 wait_queue_head_t waitq;
389 * struct sof_ipc_fw_tracing_ops - IPC-specific firmware tracing ops
390 * @init: Function pointer for initialization of the tracing
391 * @free: Optional function pointer for freeing of the tracing
392 * @fw_crashed: Optional function pointer to notify the tracing of a firmware crash
393 * @suspend: Function pointer for system/runtime suspend
394 * @resume: Function pointer for system/runtime resume
396 struct sof_ipc_fw_tracing_ops {
397 int (*init)(struct snd_sof_dev *sdev);
398 void (*free)(struct snd_sof_dev *sdev);
399 void (*fw_crashed)(struct snd_sof_dev *sdev);
400 void (*suspend)(struct snd_sof_dev *sdev, pm_message_t pm_state);
401 int (*resume)(struct snd_sof_dev *sdev);
405 * struct sof_ipc_pm_ops - IPC-specific PM ops
406 * @ctx_save: Optional function pointer for context save
407 * @ctx_restore: Optional function pointer for context restore
408 * @set_core_state: Optional function pointer for turning on/off a DSP core
410 struct sof_ipc_pm_ops {
411 int (*ctx_save)(struct snd_sof_dev *sdev);
412 int (*ctx_restore)(struct snd_sof_dev *sdev);
413 int (*set_core_state)(struct snd_sof_dev *sdev, int core_idx, bool on);
417 * struct sof_ipc_fw_loader_ops - IPC/FW-specific loader ops
418 * @validate: Function pointer for validating the firmware image
419 * @parse_ext_manifest: Function pointer for parsing the manifest of the firmware
420 * @load_fw_to_dsp: Optional function pointer for loading the firmware to the
422 * The function implements generic, hardware independent way
423 * of loading the initial firmware and its modules (if any).
424 * @query_fw_configuration: Optional function pointer to query information and
425 * configuration from the booted firmware.
426 * Executed after the first successful firmware boot.
428 struct sof_ipc_fw_loader_ops {
429 int (*validate)(struct snd_sof_dev *sdev);
430 size_t (*parse_ext_manifest)(struct snd_sof_dev *sdev);
431 int (*load_fw_to_dsp)(struct snd_sof_dev *sdev);
432 int (*query_fw_configuration)(struct snd_sof_dev *sdev);
435 struct sof_ipc_tplg_ops;
436 struct sof_ipc_pcm_ops;
439 * struct sof_ipc_ops - IPC-specific ops
440 * @tplg: Pointer to IPC-specific topology ops
441 * @pm: Pointer to PM ops
442 * @pcm: Pointer to PCM ops
443 * @fw_loader: Pointer to Firmware Loader ops
444 * @fw_tracing: Pointer to Firmware tracing ops
446 * @tx_msg: Function pointer for sending a 'short' IPC message
447 * @set_get_data: Function pointer for set/get data ('large' IPC message). This
448 * function may split up the 'large' message and use the @tx_msg
449 * path to transfer individual chunks, or use other means to transfer
451 * @get_reply: Function pointer for fetching the reply to
452 * sdev->ipc->msg.reply_data
453 * @rx_msg: Function pointer for handling a received message
455 * Note: both @tx_msg and @set_get_data considered as TX functions and they are
456 * serialized for the duration of the instructed transfer. A large message sent
457 * via @set_get_data is a single transfer even if at the hardware level it is
458 * handled with multiple chunks.
461 const struct sof_ipc_tplg_ops *tplg;
462 const struct sof_ipc_pm_ops *pm;
463 const struct sof_ipc_pcm_ops *pcm;
464 const struct sof_ipc_fw_loader_ops *fw_loader;
465 const struct sof_ipc_fw_tracing_ops *fw_tracing;
467 int (*tx_msg)(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
468 void *reply_data, size_t reply_bytes, bool no_pm);
469 int (*set_get_data)(struct snd_sof_dev *sdev, void *data, size_t data_bytes,
471 int (*get_reply)(struct snd_sof_dev *sdev);
472 void (*rx_msg)(struct snd_sof_dev *sdev);
475 /* SOF generic IPC data */
477 struct snd_sof_dev *sdev;
479 /* protects messages and the disable flag */
480 struct mutex tx_mutex;
481 /* disables further sending of ipc's */
484 /* Maximum allowed size of a single IPC message/reply */
485 size_t max_payload_size;
487 struct snd_sof_ipc_msg msg;
489 /* IPC ops based on version */
490 const struct sof_ipc_ops *ops;
498 spinlock_t ipc_lock; /* lock for IPC users */
499 spinlock_t hw_lock; /* lock for HW IO access */
501 /* Main, Base firmware image */
502 struct sof_firmware basefw;
505 * ASoC components. plat_drv fields are set dynamically so
508 struct snd_soc_component_driver plat_drv;
510 /* current DSP power state */
511 struct sof_dsp_power_state dsp_power_state;
512 /* mutex to protect the dsp_power_state access */
513 struct mutex power_state_access;
515 /* Intended power target of system suspend */
516 enum sof_system_suspend_state system_suspend_target;
518 /* DSP firmware boot */
519 wait_queue_head_t boot_wait;
520 enum sof_fw_state fw_state;
523 /* work queue in case the probe is implemented in two steps */
524 struct work_struct probe_work;
525 bool probe_completed;
527 /* DSP HW differentiation */
528 struct snd_sof_pdata *pdata;
531 struct snd_sof_ipc *ipc;
532 struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */
533 struct snd_sof_mailbox host_box; /* Host initiated IPC */
534 struct snd_sof_mailbox stream_box; /* Stream position update */
535 struct snd_sof_mailbox debug_box; /* Debug info updates */
536 struct snd_sof_ipc_msg *msg;
538 u32 next_comp_id; /* monotonic - reset during S3 */
540 /* memory bases for mmaped DSPs - set by dsp_init() */
541 void __iomem *bar[SND_SOF_BARS]; /* DSP base address */
544 size_t dsp_oops_offset;
547 struct dentry *debugfs_root;
548 struct list_head dfsentry_list;
549 bool dbg_dump_printed;
550 bool ipc_dump_printed;
552 /* firmware loader */
553 struct sof_ipc_fw_ready fw_ready;
554 struct sof_ipc_fw_version fw_version;
555 struct sof_ipc_cc_version *cc_version;
558 struct snd_soc_tplg_ops *tplg_ops;
559 struct list_head pcm_list;
560 struct list_head kcontrol_list;
561 struct list_head widget_list;
562 struct list_head dai_list;
563 struct list_head dai_link_list;
564 struct list_head route_list;
565 struct snd_soc_component *component;
566 u32 enabled_cores_mask; /* keep track of enabled cores */
569 /* FW configuration */
570 struct sof_ipc_window *info_window;
572 /* IPC timeouts in ms */
576 /* firmwre tracing */
577 bool fw_trace_is_supported; /* set with Kconfig or module parameter */
578 void *fw_trace_data; /* private data used by firmware tracing implementation */
582 /* DSP core context */
586 * ref count per core that will be modified during system suspend/resume and during pcm
587 * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
588 * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
589 * sound/core/ when streams are active and during system suspend/resume, streams are
592 int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
595 * Used to keep track of registered IPC client devices so that they can
596 * be removed when the parent SOF module is removed.
598 struct list_head ipc_client_list;
600 /* mutex to protect client list */
601 struct mutex ipc_client_mutex;
604 * Used for tracking the IPC client's RX registration for DSP initiated
607 struct list_head ipc_rx_handler_list;
610 * Used for tracking the IPC client's registration for DSP state change
613 struct list_head fw_state_handler_list;
615 /* to protect the ipc_rx_handler_list and dsp_state_handler_list list */
616 struct mutex client_event_handler_mutex;
618 /* quirks to override topology values */
619 bool mclk_id_override;
620 u16 mclk_id_quirk; /* same size as in IPC3 definitions */
622 void *private; /* core does not touch this */
629 int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
630 int snd_sof_device_remove(struct device *dev);
631 int snd_sof_device_shutdown(struct device *dev);
632 bool snd_sof_device_probe_completed(struct device *dev);
634 int snd_sof_runtime_suspend(struct device *dev);
635 int snd_sof_runtime_resume(struct device *dev);
636 int snd_sof_runtime_idle(struct device *dev);
637 int snd_sof_resume(struct device *dev);
638 int snd_sof_suspend(struct device *dev);
639 int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
640 int snd_sof_prepare(struct device *dev);
641 void snd_sof_complete(struct device *dev);
643 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
648 extern struct snd_compress_ops sof_compressed_ops;
653 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
654 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
655 int snd_sof_run_firmware(struct snd_sof_dev *sdev);
656 void snd_sof_fw_unload(struct snd_sof_dev *sdev);
659 * IPC low level APIs.
661 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
662 void snd_sof_ipc_free(struct snd_sof_dev *sdev);
663 void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
664 void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
665 static inline void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
667 sdev->ipc->ops->rx_msg(sdev);
669 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
670 void *reply_data, size_t reply_bytes);
671 int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
672 void *reply_data, size_t reply_bytes);
673 int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
676 static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
678 snd_sof_ipc_get_reply(sdev);
679 snd_sof_ipc_reply(sdev, msg_id);
685 int snd_sof_dbg_init(struct snd_sof_dev *sdev);
686 void snd_sof_free_debug(struct snd_sof_dev *sdev);
687 int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
688 void *base, size_t size,
689 const char *name, mode_t mode);
690 void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
691 u32 panic_code, u32 tracep_code, void *oops,
692 struct sof_ipc_panic_info *panic_info,
693 void *stack, size_t stack_words);
694 void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev, const char *msg);
695 int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
696 int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
697 enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
698 const char *name, enum sof_debugfs_access_type access_type);
699 /* Firmware tracing */
700 int sof_fw_trace_init(struct snd_sof_dev *sdev);
701 void sof_fw_trace_free(struct snd_sof_dev *sdev);
702 void sof_fw_trace_fw_crashed(struct snd_sof_dev *sdev);
703 void sof_fw_trace_suspend(struct snd_sof_dev *sdev, pm_message_t pm_state);
704 int sof_fw_trace_resume(struct snd_sof_dev *sdev);
709 static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
710 void *oops, u32 *stack, u32 stack_words)
712 sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level, oops, stack,
716 static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
718 if (sof_dsp_arch_ops(sdev)->dsp_oops)
719 sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops);
722 extern const struct dsp_arch_ops sof_xtensa_arch_ops;
725 * Firmware state tracking
727 void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
732 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
733 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
734 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
735 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
736 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
737 void *message, size_t bytes);
738 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
739 void *message, size_t bytes);
740 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
741 u32 offset, void *src, size_t size);
742 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
743 u32 offset, void *dest, size_t size);
745 int sof_ipc_msg_data(struct snd_sof_dev *sdev,
746 struct snd_pcm_substream *substream,
748 int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
749 struct snd_pcm_substream *substream,
752 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
753 struct snd_pcm_substream *substream);
754 int sof_stream_pcm_close(struct snd_sof_dev *sdev,
755 struct snd_pcm_substream *substream);
757 int sof_machine_check(struct snd_sof_dev *sdev);
759 /* SOF client support */
760 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
761 int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
762 const void *data, size_t size);
763 void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
764 int sof_register_clients(struct snd_sof_dev *sdev);
765 void sof_unregister_clients(struct snd_sof_dev *sdev);
766 void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
767 void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
768 int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
769 int sof_resume_clients(struct snd_sof_dev *sdev);
770 #else /* CONFIG_SND_SOC_SOF_CLIENT */
771 static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
772 u32 id, const void *data, size_t size)
777 static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
778 const char *name, u32 id)
782 static inline int sof_register_clients(struct snd_sof_dev *sdev)
787 static inline void sof_unregister_clients(struct snd_sof_dev *sdev)
791 static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
795 static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
799 static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
804 static inline int sof_resume_clients(struct snd_sof_dev *sdev)
808 #endif /* CONFIG_SND_SOC_SOF_CLIENT */
810 /* Main ops for IPC implementations */
811 extern const struct sof_ipc_ops ipc3_ops;
812 extern const struct sof_ipc_ops ipc4_ops;