xref: /linux/sound/soc/sof/sof-priv.h (revision cac0b0887e5304bddfda91a4a7106f9328c31318)
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 	struct snd_sof_dev *sdev;
329 	struct list_head list;  /* list in sdev dfsentry list */
330 	union {
331 		void __iomem *io_mem;
332 		void *buf;
333 	};
334 };
335 
336 /* Debug mapping for any DSP memory or registers that can used for debug */
337 struct snd_sof_debugfs_map {
338 	const char *name;
339 	u32 bar;
340 	u32 offset;
341 	u32 size;
342 	/*
343 	 * access_type specifies if the memory is always accessible
344 	 * or if it is accessible only when the DSP is in D0.
345 	 */
346 	enum sof_debugfs_access_type access_type;
347 };
348 
349 /* mailbox descriptor, used for host <-> DSP IPC */
350 struct snd_sof_mailbox {
351 	u32 offset;
352 	size_t size;
353 };
354 
355 /* IPC message descriptor for host <-> DSP IO */
356 struct snd_sof_ipc_msg {
357 	/* message data */
358 	u32 header;
359 	void *msg_data;
360 	void *reply_data;
361 	size_t msg_size;
362 	size_t reply_size;
363 	int reply_error;
364 
365 	wait_queue_head_t waitq;
366 	bool ipc_complete;
367 };
368 
369 /*
370  * SOF Device Level.
371  */
372 struct snd_sof_dev {
373 	struct device *dev;
374 	spinlock_t ipc_lock;	/* lock for IPC users */
375 	spinlock_t hw_lock;	/* lock for HW IO access */
376 
377 	/*
378 	 * ASoC components. plat_drv fields are set dynamically so
379 	 * can't use const
380 	 */
381 	struct snd_soc_component_driver plat_drv;
382 
383 	/* current DSP power state */
384 	struct sof_dsp_power_state dsp_power_state;
385 	/* mutex to protect the dsp_power_state access */
386 	struct mutex power_state_access;
387 
388 	/* Intended power target of system suspend */
389 	enum sof_system_suspend_state system_suspend_target;
390 
391 	/* DSP firmware boot */
392 	wait_queue_head_t boot_wait;
393 	enum sof_fw_state fw_state;
394 	bool first_boot;
395 
396 	/* work queue in case the probe is implemented in two steps */
397 	struct work_struct probe_work;
398 	bool probe_completed;
399 
400 	/* DSP HW differentiation */
401 	struct snd_sof_pdata *pdata;
402 
403 	/* IPC */
404 	struct snd_sof_ipc *ipc;
405 	struct snd_sof_mailbox dsp_box;		/* DSP initiated IPC */
406 	struct snd_sof_mailbox host_box;	/* Host initiated IPC */
407 	struct snd_sof_mailbox stream_box;	/* Stream position update */
408 	struct snd_sof_mailbox debug_box;	/* Debug info updates */
409 	struct snd_sof_ipc_msg *msg;
410 	int ipc_irq;
411 	u32 next_comp_id; /* monotonic - reset during S3 */
412 
413 	/* memory bases for mmaped DSPs - set by dsp_init() */
414 	void __iomem *bar[SND_SOF_BARS];	/* DSP base address */
415 	int mmio_bar;
416 	int mailbox_bar;
417 	size_t dsp_oops_offset;
418 
419 	/* debug */
420 	struct dentry *debugfs_root;
421 	struct list_head dfsentry_list;
422 	bool dbg_dump_printed;
423 	bool ipc_dump_printed;
424 
425 	/* firmware loader */
426 	struct snd_dma_buffer dmab;
427 	struct snd_dma_buffer dmab_bdl;
428 	struct sof_ipc_fw_ready fw_ready;
429 	struct sof_ipc_fw_version fw_version;
430 	struct sof_ipc_cc_version *cc_version;
431 
432 	/* topology */
433 	struct snd_soc_tplg_ops *tplg_ops;
434 	struct list_head pcm_list;
435 	struct list_head kcontrol_list;
436 	struct list_head widget_list;
437 	struct list_head dai_list;
438 	struct list_head route_list;
439 	struct snd_soc_component *component;
440 	u32 enabled_cores_mask; /* keep track of enabled cores */
441 
442 	/* FW configuration */
443 	struct sof_ipc_window *info_window;
444 
445 	/* IPC timeouts in ms */
446 	int ipc_timeout;
447 	int boot_timeout;
448 
449 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
450 	unsigned int extractor_stream_tag;
451 #endif
452 
453 	/* DMA for Trace */
454 	struct snd_dma_buffer dmatb;
455 	struct snd_dma_buffer dmatp;
456 	int dma_trace_pages;
457 	wait_queue_head_t trace_sleep;
458 	u32 host_offset;
459 	bool dtrace_is_supported; /* set with Kconfig or module parameter */
460 	bool dtrace_is_enabled;
461 	bool dtrace_error;
462 	bool dtrace_draining;
463 
464 	bool msi_enabled;
465 
466 	/* DSP core context */
467 	u32 num_cores;
468 
469 	/*
470 	 * ref count per core that will be modified during system suspend/resume and during pcm
471 	 * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
472 	 * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
473 	 * sound/core/ when streams are active and during system suspend/resume, streams are
474 	 * already suspended.
475 	 */
476 	int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
477 
478 	/*
479 	 * Used to keep track of registered IPC client devices so that they can
480 	 * be removed when the parent SOF module is removed.
481 	 */
482 	struct list_head ipc_client_list;
483 
484 	/* mutex to protect client list */
485 	struct mutex ipc_client_mutex;
486 
487 	/*
488 	 * Used for tracking the IPC client's RX registration for DSP initiated
489 	 * message handling.
490 	 */
491 	struct list_head ipc_rx_handler_list;
492 
493 	/*
494 	 * Used for tracking the IPC client's registration for DSP state change
495 	 * notification
496 	 */
497 	struct list_head fw_state_handler_list;
498 
499 	/* to protect the ipc_rx_handler_list  and  dsp_state_handler_list list */
500 	struct mutex client_event_handler_mutex;
501 
502 	void *private;			/* core does not touch this */
503 };
504 
505 /*
506  * Device Level.
507  */
508 
509 int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
510 int snd_sof_device_remove(struct device *dev);
511 int snd_sof_device_shutdown(struct device *dev);
512 bool snd_sof_device_probe_completed(struct device *dev);
513 
514 int snd_sof_runtime_suspend(struct device *dev);
515 int snd_sof_runtime_resume(struct device *dev);
516 int snd_sof_runtime_idle(struct device *dev);
517 int snd_sof_resume(struct device *dev);
518 int snd_sof_suspend(struct device *dev);
519 int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
520 int snd_sof_prepare(struct device *dev);
521 void snd_sof_complete(struct device *dev);
522 
523 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
524 
525 /*
526  * Firmware loading.
527  */
528 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
529 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
530 int snd_sof_run_firmware(struct snd_sof_dev *sdev);
531 int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
532 				struct snd_sof_mod_hdr *module);
533 void snd_sof_fw_unload(struct snd_sof_dev *sdev);
534 
535 /*
536  * IPC low level APIs.
537  */
538 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
539 void snd_sof_ipc_free(struct snd_sof_dev *sdev);
540 void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
541 void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
542 void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev);
543 int snd_sof_ipc_stream_pcm_params(struct snd_sof_dev *sdev,
544 				  struct sof_ipc_pcm_params *params);
545 int snd_sof_ipc_valid(struct snd_sof_dev *sdev);
546 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header,
547 		       void *msg_data, size_t msg_bytes, void *reply_data,
548 		       size_t reply_bytes);
549 int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header,
550 			     void *msg_data, size_t msg_bytes,
551 			     void *reply_data, size_t reply_bytes);
552 int sof_ipc_init_msg_memory(struct snd_sof_dev *sdev);
553 static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
554 {
555 	snd_sof_ipc_get_reply(sdev);
556 	snd_sof_ipc_reply(sdev, msg_id);
557 }
558 
559 /*
560  * Trace/debug
561  */
562 int snd_sof_init_trace(struct snd_sof_dev *sdev);
563 void snd_sof_release_trace(struct snd_sof_dev *sdev);
564 void snd_sof_free_trace(struct snd_sof_dev *sdev);
565 int snd_sof_dbg_init(struct snd_sof_dev *sdev);
566 void snd_sof_free_debug(struct snd_sof_dev *sdev);
567 int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
568 			     void *base, size_t size,
569 			     const char *name, mode_t mode);
570 int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
571 			     struct sof_ipc_dma_trace_posn *posn);
572 void snd_sof_trace_notify_for_error(struct snd_sof_dev *sdev);
573 void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
574 			      u32 panic_code, u32 tracep_code, void *oops,
575 			      struct sof_ipc_panic_info *panic_info,
576 			      void *stack, size_t stack_words);
577 int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev);
578 void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev);
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 
584 /*
585  * DSP Architectures.
586  */
587 static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
588 			     void *oops, u32 *stack, u32 stack_words)
589 {
590 		sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level,  oops, stack,
591 						  stack_words);
592 }
593 
594 static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
595 {
596 	if (sof_dsp_arch_ops(sdev)->dsp_oops)
597 		sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops);
598 }
599 
600 extern const struct dsp_arch_ops sof_xtensa_arch_ops;
601 
602 /*
603  * Firmware state tracking
604  */
605 void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
606 
607 /*
608  * Utilities
609  */
610 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
611 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
612 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
613 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
614 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
615 		       void *message, size_t bytes);
616 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
617 		      void *message, size_t bytes);
618 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
619 		    u32 offset, void *src, size_t size);
620 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
621 		   u32 offset, void *dest, size_t size);
622 
623 int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id);
624 
625 int sof_ipc_msg_data(struct snd_sof_dev *sdev,
626 		     struct snd_pcm_substream *substream,
627 		     void *p, size_t sz);
628 int sof_ipc_pcm_params(struct snd_sof_dev *sdev,
629 		       struct snd_pcm_substream *substream,
630 		       const struct sof_ipc_pcm_params_reply *reply);
631 
632 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
633 			struct snd_pcm_substream *substream);
634 int sof_stream_pcm_close(struct snd_sof_dev *sdev,
635 			 struct snd_pcm_substream *substream);
636 
637 int sof_machine_check(struct snd_sof_dev *sdev);
638 
639 /* SOF client support */
640 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
641 int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
642 			    const void *data, size_t size);
643 void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
644 int sof_register_clients(struct snd_sof_dev *sdev);
645 void sof_unregister_clients(struct snd_sof_dev *sdev);
646 void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
647 void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
648 int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
649 int sof_resume_clients(struct snd_sof_dev *sdev);
650 #else /* CONFIG_SND_SOC_SOF_CLIENT */
651 static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
652 					  u32 id, const void *data, size_t size)
653 {
654 	return 0;
655 }
656 
657 static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
658 					     const char *name, u32 id)
659 {
660 }
661 
662 static inline int sof_register_clients(struct snd_sof_dev *sdev)
663 {
664 	return 0;
665 }
666 
667 static inline  void sof_unregister_clients(struct snd_sof_dev *sdev)
668 {
669 }
670 
671 static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
672 {
673 }
674 
675 static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
676 {
677 }
678 
679 static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
680 {
681 	return 0;
682 }
683 
684 static inline int sof_resume_clients(struct snd_sof_dev *sdev)
685 {
686 	return 0;
687 }
688 #endif /* CONFIG_SND_SOC_SOF_CLIENT */
689 
690 #endif
691