xref: /linux/sound/soc/sof/sof-priv.h (revision 6e9548cdb30e5d6724236dd7b89a79a270751485)
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 <liam.r.girdwood@linux.intel.com>
9  */
10 
11 #ifndef __SOUND_SOC_SOF_PRIV_H
12 #define __SOUND_SOC_SOF_PRIV_H
13 
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>
22 
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
29 							*/
30 #define SOF_DBG_DYNAMIC_PIPELINES_ENABLE	BIT(4) /* 0: use static pipelines
31 							* 1: use dynamic pipelines
32 							*/
33 #define SOF_DBG_DISABLE_MULTICORE		BIT(5) /* schedule all pipelines/widgets
34 							* on primary core
35 							*/
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
39 							*/
40 
41 /* Flag definitions used for controlling the DSP dump behavior */
42 #define SOF_DBG_DUMP_REGS		BIT(0)
43 #define SOF_DBG_DUMP_MBOX		BIT(1)
44 #define SOF_DBG_DUMP_TEXT		BIT(2)
45 #define SOF_DBG_DUMP_PCI		BIT(3)
46 /* Output this dump (at the DEBUG level) only when SOF_DBG_PRINT_ALL_DUMPS is set */
47 #define SOF_DBG_DUMP_OPTIONAL		BIT(4)
48 
49 /* global debug state set by SOF_DBG_ flags */
50 bool sof_debug_check_flag(int mask);
51 
52 /* max BARs mmaped devices can use */
53 #define SND_SOF_BARS	8
54 
55 /* time in ms for runtime suspend delay */
56 #define SND_SOF_SUSPEND_DELAY_MS	2000
57 
58 /* DMA buffer size for trace */
59 #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16)
60 
61 #define SOF_IPC_DSP_REPLY		0
62 #define SOF_IPC_HOST_REPLY		1
63 
64 /* convenience constructor for DAI driver streams */
65 #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \
66 	{.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \
67 	 .rates = srates, .formats = sfmt}
68 
69 #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
70 	SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
71 
72 /* So far the primary core on all DSPs has ID 0 */
73 #define SOF_DSP_PRIMARY_CORE 0
74 
75 /* max number of DSP cores */
76 #define SOF_MAX_DSP_NUM_CORES 8
77 
78 struct sof_dsp_power_state {
79 	u32 state;
80 	u32 substate; /* platform-specific */
81 };
82 
83 /* System suspend target state */
84 enum sof_system_suspend_state {
85 	SOF_SUSPEND_NONE = 0,
86 	SOF_SUSPEND_S0IX,
87 	SOF_SUSPEND_S3,
88 };
89 
90 enum sof_dfsentry_type {
91 	SOF_DFSENTRY_TYPE_IOMEM = 0,
92 	SOF_DFSENTRY_TYPE_BUF,
93 };
94 
95 enum sof_debugfs_access_type {
96 	SOF_DEBUGFS_ACCESS_ALWAYS = 0,
97 	SOF_DEBUGFS_ACCESS_D0_ONLY,
98 };
99 
100 struct snd_sof_dev;
101 struct snd_sof_ipc_msg;
102 struct snd_sof_ipc;
103 struct snd_sof_debugfs_map;
104 struct snd_soc_tplg_ops;
105 struct snd_soc_component;
106 struct snd_sof_pdata;
107 
108 /*
109  * SOF DSP HW abstraction operations.
110  * Used to abstract DSP HW architecture and any IO busses between host CPU
111  * and DSP device(s).
112  */
113 struct snd_sof_dsp_ops {
114 
115 	/* probe/remove/shutdown */
116 	int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
117 	int (*remove)(struct snd_sof_dev *sof_dev); /* optional */
118 	int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */
119 
120 	/* DSP core boot / reset */
121 	int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */
122 	int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */
123 	int (*reset)(struct snd_sof_dev *sof_dev); /* optional */
124 	int (*core_get)(struct snd_sof_dev *sof_dev, int core); /* optional */
125 	int (*core_put)(struct snd_sof_dev *sof_dev, int core); /* optional */
126 
127 	/*
128 	 * Register IO: only used by respective drivers themselves,
129 	 * TODO: consider removing these operations and calling respective
130 	 * implementations directly
131 	 */
132 	void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
133 		      u32 value); /* optional */
134 	u32 (*read)(struct snd_sof_dev *sof_dev,
135 		    void __iomem *addr); /* optional */
136 	void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
137 			u64 value); /* optional */
138 	u64 (*read64)(struct snd_sof_dev *sof_dev,
139 		      void __iomem *addr); /* optional */
140 
141 	/* memcpy IO */
142 	int (*block_read)(struct snd_sof_dev *sof_dev,
143 			  enum snd_sof_fw_blk_type type, u32 offset,
144 			  void *dest, size_t size); /* mandatory */
145 	int (*block_write)(struct snd_sof_dev *sof_dev,
146 			   enum snd_sof_fw_blk_type type, u32 offset,
147 			   void *src, size_t size); /* mandatory */
148 
149 	/* Mailbox IO */
150 	void (*mailbox_read)(struct snd_sof_dev *sof_dev,
151 			     u32 offset, void *dest,
152 			     size_t size); /* optional */
153 	void (*mailbox_write)(struct snd_sof_dev *sof_dev,
154 			      u32 offset, void *src,
155 			      size_t size); /* optional */
156 
157 	/* doorbell */
158 	irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
159 	irqreturn_t (*irq_thread)(int irq, void *context); /* optional */
160 
161 	/* ipc */
162 	int (*send_msg)(struct snd_sof_dev *sof_dev,
163 			struct snd_sof_ipc_msg *msg); /* mandatory */
164 
165 	/* FW loading */
166 	int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
167 	int (*load_module)(struct snd_sof_dev *sof_dev,
168 			   struct snd_sof_mod_hdr *hdr); /* optional */
169 	/*
170 	 * FW ready checks for ABI compatibility and creates
171 	 * memory windows at first boot
172 	 */
173 	int (*fw_ready)(struct snd_sof_dev *sdev, u32 msg_id); /* mandatory */
174 
175 	/* connect pcm substream to a host stream */
176 	int (*pcm_open)(struct snd_sof_dev *sdev,
177 			struct snd_pcm_substream *substream); /* optional */
178 	/* disconnect pcm substream to a host stream */
179 	int (*pcm_close)(struct snd_sof_dev *sdev,
180 			 struct snd_pcm_substream *substream); /* optional */
181 
182 	/* host stream hw params */
183 	int (*pcm_hw_params)(struct snd_sof_dev *sdev,
184 			     struct snd_pcm_substream *substream,
185 			     struct snd_pcm_hw_params *params,
186 			     struct sof_ipc_stream_params *ipc_params); /* optional */
187 
188 	/* host stream hw_free */
189 	int (*pcm_hw_free)(struct snd_sof_dev *sdev,
190 			   struct snd_pcm_substream *substream); /* optional */
191 
192 	/* host stream trigger */
193 	int (*pcm_trigger)(struct snd_sof_dev *sdev,
194 			   struct snd_pcm_substream *substream,
195 			   int cmd); /* optional */
196 
197 	/* host stream pointer */
198 	snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
199 					 struct snd_pcm_substream *substream); /* optional */
200 
201 	/* pcm ack */
202 	int (*pcm_ack)(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream); /* optional */
203 
204 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
205 	/* Except for probe_pointer, all probe ops are mandatory */
206 	int (*probe_assign)(struct snd_sof_dev *sdev,
207 			struct snd_compr_stream *cstream,
208 			struct snd_soc_dai *dai); /* mandatory */
209 	int (*probe_free)(struct snd_sof_dev *sdev,
210 			struct snd_compr_stream *cstream,
211 			struct snd_soc_dai *dai); /* mandatory */
212 	int (*probe_set_params)(struct snd_sof_dev *sdev,
213 			struct snd_compr_stream *cstream,
214 			struct snd_compr_params *params,
215 			struct snd_soc_dai *dai); /* mandatory */
216 	int (*probe_trigger)(struct snd_sof_dev *sdev,
217 			struct snd_compr_stream *cstream, int cmd,
218 			struct snd_soc_dai *dai); /* mandatory */
219 	int (*probe_pointer)(struct snd_sof_dev *sdev,
220 			struct snd_compr_stream *cstream,
221 			struct snd_compr_tstamp *tstamp,
222 			struct snd_soc_dai *dai); /* optional */
223 #endif
224 
225 	/* host read DSP stream data */
226 	int (*ipc_msg_data)(struct snd_sof_dev *sdev,
227 			    struct snd_pcm_substream *substream,
228 			    void *p, size_t sz); /* mandatory */
229 
230 	/* host configure DSP HW parameters */
231 	int (*ipc_pcm_params)(struct snd_sof_dev *sdev,
232 			      struct snd_pcm_substream *substream,
233 			      const struct sof_ipc_pcm_params_reply *reply); /* mandatory */
234 
235 	/* pre/post firmware run */
236 	int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
237 	int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
238 
239 	/* parse platform specific extended manifest, optional */
240 	int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev,
241 					   const struct sof_ext_man_elem_header *hdr);
242 
243 	/* DSP PM */
244 	int (*suspend)(struct snd_sof_dev *sof_dev,
245 		       u32 target_state); /* optional */
246 	int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
247 	int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
248 	int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
249 	int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
250 	int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
251 	int (*set_power_state)(struct snd_sof_dev *sdev,
252 			       const struct sof_dsp_power_state *target_state); /* optional */
253 
254 	/* DSP clocking */
255 	int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
256 
257 	/* debug */
258 	const struct snd_sof_debugfs_map *debug_map; /* optional */
259 	int debug_map_count; /* optional */
260 	void (*dbg_dump)(struct snd_sof_dev *sof_dev,
261 			 u32 flags); /* optional */
262 	void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
263 	int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
264 				       enum snd_sof_fw_blk_type blk_type, u32 offset,
265 				       size_t size, const char *name,
266 				       enum sof_debugfs_access_type access_type); /* optional */
267 
268 	/* host DMA trace initialization */
269 	int (*trace_init)(struct snd_sof_dev *sdev,
270 			  struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */
271 	int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
272 	int (*trace_trigger)(struct snd_sof_dev *sdev,
273 			     int cmd); /* optional */
274 
275 	/* misc */
276 	int (*get_bar_index)(struct snd_sof_dev *sdev,
277 			     u32 type); /* optional */
278 	int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
279 	int (*get_window_offset)(struct snd_sof_dev *sdev,
280 				 u32 id);/* mandatory for common loader code */
281 
282 	/* machine driver ops */
283 	int (*machine_register)(struct snd_sof_dev *sdev,
284 				void *pdata); /* optional */
285 	void (*machine_unregister)(struct snd_sof_dev *sdev,
286 				   void *pdata); /* optional */
287 	struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */
288 	void (*set_mach_params)(struct snd_soc_acpi_mach *mach,
289 				struct snd_sof_dev *sdev); /* optional */
290 
291 	/* IPC client ops */
292 	int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
293 	void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
294 
295 	/* DAI ops */
296 	struct snd_soc_dai_driver *drv;
297 	int num_drv;
298 
299 	/* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
300 	u32 hw_info;
301 
302 	const struct dsp_arch_ops *dsp_arch_ops;
303 };
304 
305 /* DSP architecture specific callbacks for oops and stack dumps */
306 struct dsp_arch_ops {
307 	void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops);
308 	void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops,
309 			  u32 *stack, u32 stack_words);
310 };
311 
312 #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
313 
314 /* FS entry for debug files that can expose DSP memories, registers */
315 struct snd_sof_dfsentry {
316 	size_t size;
317 	size_t buf_data_size;  /* length of buffered data for file read operation */
318 	enum sof_dfsentry_type type;
319 	/*
320 	 * access_type specifies if the
321 	 * memory -> DSP resource (memory, register etc) is always accessible
322 	 * or if it is accessible only when the DSP is in D0.
323 	 */
324 	enum sof_debugfs_access_type access_type;
325 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
326 	char *cache_buf; /* buffer to cache the contents of debugfs memory */
327 #endif
328 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_MSG_INJECTOR)
329 	void *msg_inject_tx;
330 	void *msg_inject_rx;
331 #endif
332 	struct snd_sof_dev *sdev;
333 	struct list_head list;  /* list in sdev dfsentry list */
334 	union {
335 		void __iomem *io_mem;
336 		void *buf;
337 	};
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 
353 /* mailbox descriptor, used for host <-> DSP IPC */
354 struct snd_sof_mailbox {
355 	u32 offset;
356 	size_t size;
357 };
358 
359 /* IPC message descriptor for host <-> DSP IO */
360 struct snd_sof_ipc_msg {
361 	/* message data */
362 	u32 header;
363 	void *msg_data;
364 	void *reply_data;
365 	size_t msg_size;
366 	size_t reply_size;
367 	int reply_error;
368 
369 	wait_queue_head_t waitq;
370 	bool ipc_complete;
371 };
372 
373 /*
374  * SOF Device Level.
375  */
376 struct snd_sof_dev {
377 	struct device *dev;
378 	spinlock_t ipc_lock;	/* lock for IPC users */
379 	spinlock_t hw_lock;	/* lock for HW IO access */
380 
381 	/*
382 	 * ASoC components. plat_drv fields are set dynamically so
383 	 * can't use const
384 	 */
385 	struct snd_soc_component_driver plat_drv;
386 
387 	/* current DSP power state */
388 	struct sof_dsp_power_state dsp_power_state;
389 	/* mutex to protect the dsp_power_state access */
390 	struct mutex power_state_access;
391 
392 	/* Intended power target of system suspend */
393 	enum sof_system_suspend_state system_suspend_target;
394 
395 	/* DSP firmware boot */
396 	wait_queue_head_t boot_wait;
397 	enum sof_fw_state fw_state;
398 	bool first_boot;
399 
400 	/* work queue in case the probe is implemented in two steps */
401 	struct work_struct probe_work;
402 	bool probe_completed;
403 
404 	/* DSP HW differentiation */
405 	struct snd_sof_pdata *pdata;
406 
407 	/* IPC */
408 	struct snd_sof_ipc *ipc;
409 	struct snd_sof_mailbox dsp_box;		/* DSP initiated IPC */
410 	struct snd_sof_mailbox host_box;	/* Host initiated IPC */
411 	struct snd_sof_mailbox stream_box;	/* Stream position update */
412 	struct snd_sof_mailbox debug_box;	/* Debug info updates */
413 	struct snd_sof_ipc_msg *msg;
414 	int ipc_irq;
415 	u32 next_comp_id; /* monotonic - reset during S3 */
416 
417 	/* memory bases for mmaped DSPs - set by dsp_init() */
418 	void __iomem *bar[SND_SOF_BARS];	/* DSP base address */
419 	int mmio_bar;
420 	int mailbox_bar;
421 	size_t dsp_oops_offset;
422 
423 	/* debug */
424 	struct dentry *debugfs_root;
425 	struct list_head dfsentry_list;
426 	bool dbg_dump_printed;
427 	bool ipc_dump_printed;
428 
429 	/* firmware loader */
430 	struct snd_dma_buffer dmab;
431 	struct snd_dma_buffer dmab_bdl;
432 	struct sof_ipc_fw_ready fw_ready;
433 	struct sof_ipc_fw_version fw_version;
434 	struct sof_ipc_cc_version *cc_version;
435 
436 	/* topology */
437 	struct snd_soc_tplg_ops *tplg_ops;
438 	struct list_head pcm_list;
439 	struct list_head kcontrol_list;
440 	struct list_head widget_list;
441 	struct list_head dai_list;
442 	struct list_head route_list;
443 	struct snd_soc_component *component;
444 	u32 enabled_cores_mask; /* keep track of enabled cores */
445 
446 	/* FW configuration */
447 	struct sof_ipc_window *info_window;
448 
449 	/* IPC timeouts in ms */
450 	int ipc_timeout;
451 	int boot_timeout;
452 
453 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
454 	unsigned int extractor_stream_tag;
455 #endif
456 
457 	/* DMA for Trace */
458 	struct snd_dma_buffer dmatb;
459 	struct snd_dma_buffer dmatp;
460 	int dma_trace_pages;
461 	wait_queue_head_t trace_sleep;
462 	u32 host_offset;
463 	bool dtrace_is_supported; /* set with Kconfig or module parameter */
464 	bool dtrace_is_enabled;
465 	bool dtrace_error;
466 	bool dtrace_draining;
467 
468 	bool msi_enabled;
469 
470 	/* DSP core context */
471 	u32 num_cores;
472 
473 	/*
474 	 * ref count per core that will be modified during system suspend/resume and during pcm
475 	 * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
476 	 * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
477 	 * sound/core/ when streams are active and during system suspend/resume, streams are
478 	 * already suspended.
479 	 */
480 	int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
481 
482 	/*
483 	 * Used to keep track of registered IPC client devices so that they can
484 	 * be removed when the parent SOF module is removed.
485 	 */
486 	struct list_head ipc_client_list;
487 
488 	/* mutex to protect client list */
489 	struct mutex ipc_client_mutex;
490 
491 	/*
492 	 * Used for tracking the IPC client's RX registration for DSP initiated
493 	 * message handling.
494 	 */
495 	struct list_head ipc_rx_handler_list;
496 
497 	/*
498 	 * Used for tracking the IPC client's registration for DSP state change
499 	 * notification
500 	 */
501 	struct list_head fw_state_handler_list;
502 
503 	/* to protect the ipc_rx_handler_list  and  dsp_state_handler_list list */
504 	struct mutex client_event_handler_mutex;
505 
506 	void *private;			/* core does not touch this */
507 };
508 
509 /*
510  * Device Level.
511  */
512 
513 int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
514 int snd_sof_device_remove(struct device *dev);
515 int snd_sof_device_shutdown(struct device *dev);
516 bool snd_sof_device_probe_completed(struct device *dev);
517 
518 int snd_sof_runtime_suspend(struct device *dev);
519 int snd_sof_runtime_resume(struct device *dev);
520 int snd_sof_runtime_idle(struct device *dev);
521 int snd_sof_resume(struct device *dev);
522 int snd_sof_suspend(struct device *dev);
523 int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
524 int snd_sof_prepare(struct device *dev);
525 void snd_sof_complete(struct device *dev);
526 
527 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
528 
529 /*
530  * Firmware loading.
531  */
532 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
533 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
534 int snd_sof_run_firmware(struct snd_sof_dev *sdev);
535 int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
536 				struct snd_sof_mod_hdr *module);
537 void snd_sof_fw_unload(struct snd_sof_dev *sdev);
538 
539 /*
540  * IPC low level APIs.
541  */
542 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
543 void snd_sof_ipc_free(struct snd_sof_dev *sdev);
544 void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
545 void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
546 void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev);
547 int snd_sof_ipc_stream_pcm_params(struct snd_sof_dev *sdev,
548 				  struct sof_ipc_pcm_params *params);
549 int snd_sof_ipc_valid(struct snd_sof_dev *sdev);
550 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header,
551 		       void *msg_data, size_t msg_bytes, void *reply_data,
552 		       size_t reply_bytes);
553 int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header,
554 			     void *msg_data, size_t msg_bytes,
555 			     void *reply_data, size_t reply_bytes);
556 int sof_ipc_init_msg_memory(struct snd_sof_dev *sdev);
557 static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
558 {
559 	snd_sof_ipc_get_reply(sdev);
560 	snd_sof_ipc_reply(sdev, msg_id);
561 }
562 
563 /*
564  * Trace/debug
565  */
566 int snd_sof_init_trace(struct snd_sof_dev *sdev);
567 void snd_sof_release_trace(struct snd_sof_dev *sdev);
568 void snd_sof_free_trace(struct snd_sof_dev *sdev);
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 int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
575 			     struct sof_ipc_dma_trace_posn *posn);
576 void snd_sof_trace_notify_for_error(struct snd_sof_dev *sdev);
577 void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
578 			      u32 panic_code, u32 tracep_code, void *oops,
579 			      struct sof_ipc_panic_info *panic_info,
580 			      void *stack, size_t stack_words);
581 int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev);
582 void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev);
583 int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
584 int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
585 		enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
586 		const char *name, enum sof_debugfs_access_type access_type);
587 
588 /*
589  * DSP Architectures.
590  */
591 static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
592 			     void *oops, u32 *stack, u32 stack_words)
593 {
594 		sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level,  oops, stack,
595 						  stack_words);
596 }
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 
604 extern const struct dsp_arch_ops sof_xtensa_arch_ops;
605 
606 /*
607  * Firmware state tracking
608  */
609 void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
610 
611 /*
612  * Utilities
613  */
614 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
615 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
616 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
617 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
618 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
619 		       void *message, size_t bytes);
620 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
621 		      void *message, size_t bytes);
622 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
623 		    u32 offset, void *src, size_t size);
624 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
625 		   u32 offset, void *dest, size_t size);
626 
627 int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id);
628 
629 int sof_ipc_msg_data(struct snd_sof_dev *sdev,
630 		     struct snd_pcm_substream *substream,
631 		     void *p, size_t sz);
632 int sof_ipc_pcm_params(struct snd_sof_dev *sdev,
633 		       struct snd_pcm_substream *substream,
634 		       const struct sof_ipc_pcm_params_reply *reply);
635 
636 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
637 			struct snd_pcm_substream *substream);
638 int sof_stream_pcm_close(struct snd_sof_dev *sdev,
639 			 struct snd_pcm_substream *substream);
640 
641 int sof_machine_check(struct snd_sof_dev *sdev);
642 
643 /* SOF client support */
644 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
645 int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
646 			    const void *data, size_t size);
647 void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
648 int sof_register_clients(struct snd_sof_dev *sdev);
649 void sof_unregister_clients(struct snd_sof_dev *sdev);
650 void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
651 void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
652 int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
653 int sof_resume_clients(struct snd_sof_dev *sdev);
654 #else /* CONFIG_SND_SOC_SOF_CLIENT */
655 static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
656 					  u32 id, const void *data, size_t size)
657 {
658 	return 0;
659 }
660 
661 static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
662 					     const char *name, u32 id)
663 {
664 }
665 
666 static inline int sof_register_clients(struct snd_sof_dev *sdev)
667 {
668 	return 0;
669 }
670 
671 static inline  void sof_unregister_clients(struct snd_sof_dev *sdev)
672 {
673 }
674 
675 static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
676 {
677 }
678 
679 static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
680 {
681 }
682 
683 static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
684 {
685 	return 0;
686 }
687 
688 static inline int sof_resume_clients(struct snd_sof_dev *sdev)
689 {
690 	return 0;
691 }
692 #endif /* CONFIG_SND_SOC_SOF_CLIENT */
693 
694 #endif
695