xref: /openbmc/linux/sound/soc/sof/sof-priv.h (revision 015044e9)
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 	/* host read DSP stream data */
205 	int (*ipc_msg_data)(struct snd_sof_dev *sdev,
206 			    struct snd_pcm_substream *substream,
207 			    void *p, size_t sz); /* mandatory */
208 
209 	/* host configure DSP HW parameters */
210 	int (*ipc_pcm_params)(struct snd_sof_dev *sdev,
211 			      struct snd_pcm_substream *substream,
212 			      const struct sof_ipc_pcm_params_reply *reply); /* mandatory */
213 
214 	/* pre/post firmware run */
215 	int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
216 	int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
217 
218 	/* parse platform specific extended manifest, optional */
219 	int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev,
220 					   const struct sof_ext_man_elem_header *hdr);
221 
222 	/* DSP PM */
223 	int (*suspend)(struct snd_sof_dev *sof_dev,
224 		       u32 target_state); /* optional */
225 	int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
226 	int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
227 	int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
228 	int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
229 	int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
230 	int (*set_power_state)(struct snd_sof_dev *sdev,
231 			       const struct sof_dsp_power_state *target_state); /* optional */
232 
233 	/* DSP clocking */
234 	int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
235 
236 	/* debug */
237 	const struct snd_sof_debugfs_map *debug_map; /* optional */
238 	int debug_map_count; /* optional */
239 	void (*dbg_dump)(struct snd_sof_dev *sof_dev,
240 			 u32 flags); /* optional */
241 	void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
242 	int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
243 				       enum snd_sof_fw_blk_type blk_type, u32 offset,
244 				       size_t size, const char *name,
245 				       enum sof_debugfs_access_type access_type); /* optional */
246 
247 	/* host DMA trace initialization */
248 	int (*trace_init)(struct snd_sof_dev *sdev,
249 			  struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */
250 	int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
251 	int (*trace_trigger)(struct snd_sof_dev *sdev,
252 			     int cmd); /* optional */
253 
254 	/* misc */
255 	int (*get_bar_index)(struct snd_sof_dev *sdev,
256 			     u32 type); /* optional */
257 	int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
258 	int (*get_window_offset)(struct snd_sof_dev *sdev,
259 				 u32 id);/* mandatory for common loader code */
260 
261 	/* machine driver ops */
262 	int (*machine_register)(struct snd_sof_dev *sdev,
263 				void *pdata); /* optional */
264 	void (*machine_unregister)(struct snd_sof_dev *sdev,
265 				   void *pdata); /* optional */
266 	struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */
267 	void (*set_mach_params)(struct snd_soc_acpi_mach *mach,
268 				struct snd_sof_dev *sdev); /* optional */
269 
270 	/* IPC client ops */
271 	int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
272 	void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
273 
274 	/* DAI ops */
275 	struct snd_soc_dai_driver *drv;
276 	int num_drv;
277 
278 	/* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
279 	u32 hw_info;
280 
281 	const struct dsp_arch_ops *dsp_arch_ops;
282 };
283 
284 /* DSP architecture specific callbacks for oops and stack dumps */
285 struct dsp_arch_ops {
286 	void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops);
287 	void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops,
288 			  u32 *stack, u32 stack_words);
289 };
290 
291 #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
292 
293 /* FS entry for debug files that can expose DSP memories, registers */
294 struct snd_sof_dfsentry {
295 	size_t size;
296 	size_t buf_data_size;  /* length of buffered data for file read operation */
297 	enum sof_dfsentry_type type;
298 	/*
299 	 * access_type specifies if the
300 	 * memory -> DSP resource (memory, register etc) is always accessible
301 	 * or if it is accessible only when the DSP is in D0.
302 	 */
303 	enum sof_debugfs_access_type access_type;
304 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
305 	char *cache_buf; /* buffer to cache the contents of debugfs memory */
306 #endif
307 	struct snd_sof_dev *sdev;
308 	struct list_head list;  /* list in sdev dfsentry list */
309 	union {
310 		void __iomem *io_mem;
311 		void *buf;
312 	};
313 };
314 
315 /* Debug mapping for any DSP memory or registers that can used for debug */
316 struct snd_sof_debugfs_map {
317 	const char *name;
318 	u32 bar;
319 	u32 offset;
320 	u32 size;
321 	/*
322 	 * access_type specifies if the memory is always accessible
323 	 * or if it is accessible only when the DSP is in D0.
324 	 */
325 	enum sof_debugfs_access_type access_type;
326 };
327 
328 /* mailbox descriptor, used for host <-> DSP IPC */
329 struct snd_sof_mailbox {
330 	u32 offset;
331 	size_t size;
332 };
333 
334 /* IPC message descriptor for host <-> DSP IO */
335 struct snd_sof_ipc_msg {
336 	/* message data */
337 	u32 header;
338 	void *msg_data;
339 	void *reply_data;
340 	size_t msg_size;
341 	size_t reply_size;
342 	int reply_error;
343 
344 	wait_queue_head_t waitq;
345 	bool ipc_complete;
346 };
347 
348 /*
349  * SOF Device Level.
350  */
351 struct snd_sof_dev {
352 	struct device *dev;
353 	spinlock_t ipc_lock;	/* lock for IPC users */
354 	spinlock_t hw_lock;	/* lock for HW IO access */
355 
356 	/*
357 	 * ASoC components. plat_drv fields are set dynamically so
358 	 * can't use const
359 	 */
360 	struct snd_soc_component_driver plat_drv;
361 
362 	/* current DSP power state */
363 	struct sof_dsp_power_state dsp_power_state;
364 	/* mutex to protect the dsp_power_state access */
365 	struct mutex power_state_access;
366 
367 	/* Intended power target of system suspend */
368 	enum sof_system_suspend_state system_suspend_target;
369 
370 	/* DSP firmware boot */
371 	wait_queue_head_t boot_wait;
372 	enum sof_fw_state fw_state;
373 	bool first_boot;
374 
375 	/* work queue in case the probe is implemented in two steps */
376 	struct work_struct probe_work;
377 	bool probe_completed;
378 
379 	/* DSP HW differentiation */
380 	struct snd_sof_pdata *pdata;
381 
382 	/* IPC */
383 	struct snd_sof_ipc *ipc;
384 	struct snd_sof_mailbox dsp_box;		/* DSP initiated IPC */
385 	struct snd_sof_mailbox host_box;	/* Host initiated IPC */
386 	struct snd_sof_mailbox stream_box;	/* Stream position update */
387 	struct snd_sof_mailbox debug_box;	/* Debug info updates */
388 	struct snd_sof_ipc_msg *msg;
389 	int ipc_irq;
390 	u32 next_comp_id; /* monotonic - reset during S3 */
391 
392 	/* memory bases for mmaped DSPs - set by dsp_init() */
393 	void __iomem *bar[SND_SOF_BARS];	/* DSP base address */
394 	int mmio_bar;
395 	int mailbox_bar;
396 	size_t dsp_oops_offset;
397 
398 	/* debug */
399 	struct dentry *debugfs_root;
400 	struct list_head dfsentry_list;
401 	bool dbg_dump_printed;
402 	bool ipc_dump_printed;
403 
404 	/* firmware loader */
405 	struct snd_dma_buffer dmab;
406 	struct snd_dma_buffer dmab_bdl;
407 	struct sof_ipc_fw_ready fw_ready;
408 	struct sof_ipc_fw_version fw_version;
409 	struct sof_ipc_cc_version *cc_version;
410 
411 	/* topology */
412 	struct snd_soc_tplg_ops *tplg_ops;
413 	struct list_head pcm_list;
414 	struct list_head kcontrol_list;
415 	struct list_head widget_list;
416 	struct list_head dai_list;
417 	struct list_head route_list;
418 	struct snd_soc_component *component;
419 	u32 enabled_cores_mask; /* keep track of enabled cores */
420 
421 	/* FW configuration */
422 	struct sof_ipc_window *info_window;
423 
424 	/* IPC timeouts in ms */
425 	int ipc_timeout;
426 	int boot_timeout;
427 
428 	/* DMA for Trace */
429 	struct snd_dma_buffer dmatb;
430 	struct snd_dma_buffer dmatp;
431 	int dma_trace_pages;
432 	wait_queue_head_t trace_sleep;
433 	u32 host_offset;
434 	bool dtrace_is_supported; /* set with Kconfig or module parameter */
435 	bool dtrace_is_enabled;
436 	bool dtrace_error;
437 	bool dtrace_draining;
438 
439 	bool msi_enabled;
440 
441 	/* DSP core context */
442 	u32 num_cores;
443 
444 	/*
445 	 * ref count per core that will be modified during system suspend/resume and during pcm
446 	 * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
447 	 * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
448 	 * sound/core/ when streams are active and during system suspend/resume, streams are
449 	 * already suspended.
450 	 */
451 	int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
452 
453 	/*
454 	 * Used to keep track of registered IPC client devices so that they can
455 	 * be removed when the parent SOF module is removed.
456 	 */
457 	struct list_head ipc_client_list;
458 
459 	/* mutex to protect client list */
460 	struct mutex ipc_client_mutex;
461 
462 	/*
463 	 * Used for tracking the IPC client's RX registration for DSP initiated
464 	 * message handling.
465 	 */
466 	struct list_head ipc_rx_handler_list;
467 
468 	/*
469 	 * Used for tracking the IPC client's registration for DSP state change
470 	 * notification
471 	 */
472 	struct list_head fw_state_handler_list;
473 
474 	/* to protect the ipc_rx_handler_list  and  dsp_state_handler_list list */
475 	struct mutex client_event_handler_mutex;
476 
477 	void *private;			/* core does not touch this */
478 };
479 
480 /*
481  * Device Level.
482  */
483 
484 int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
485 int snd_sof_device_remove(struct device *dev);
486 int snd_sof_device_shutdown(struct device *dev);
487 bool snd_sof_device_probe_completed(struct device *dev);
488 
489 int snd_sof_runtime_suspend(struct device *dev);
490 int snd_sof_runtime_resume(struct device *dev);
491 int snd_sof_runtime_idle(struct device *dev);
492 int snd_sof_resume(struct device *dev);
493 int snd_sof_suspend(struct device *dev);
494 int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
495 int snd_sof_prepare(struct device *dev);
496 void snd_sof_complete(struct device *dev);
497 
498 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
499 
500 /*
501  * Compress support
502  */
503 extern struct snd_compress_ops sof_compressed_ops;
504 
505 /*
506  * Firmware loading.
507  */
508 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
509 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
510 int snd_sof_run_firmware(struct snd_sof_dev *sdev);
511 int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
512 				struct snd_sof_mod_hdr *module);
513 void snd_sof_fw_unload(struct snd_sof_dev *sdev);
514 
515 /*
516  * IPC low level APIs.
517  */
518 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
519 void snd_sof_ipc_free(struct snd_sof_dev *sdev);
520 void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
521 void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
522 void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev);
523 int snd_sof_ipc_stream_pcm_params(struct snd_sof_dev *sdev,
524 				  struct sof_ipc_pcm_params *params);
525 int snd_sof_ipc_valid(struct snd_sof_dev *sdev);
526 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header,
527 		       void *msg_data, size_t msg_bytes, void *reply_data,
528 		       size_t reply_bytes);
529 int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header,
530 			     void *msg_data, size_t msg_bytes,
531 			     void *reply_data, size_t reply_bytes);
532 int sof_ipc_init_msg_memory(struct snd_sof_dev *sdev);
533 static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
534 {
535 	snd_sof_ipc_get_reply(sdev);
536 	snd_sof_ipc_reply(sdev, msg_id);
537 }
538 
539 /*
540  * Trace/debug
541  */
542 int snd_sof_init_trace(struct snd_sof_dev *sdev);
543 void snd_sof_release_trace(struct snd_sof_dev *sdev);
544 void snd_sof_free_trace(struct snd_sof_dev *sdev);
545 int snd_sof_dbg_init(struct snd_sof_dev *sdev);
546 void snd_sof_free_debug(struct snd_sof_dev *sdev);
547 int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
548 			     void *base, size_t size,
549 			     const char *name, mode_t mode);
550 int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
551 			     struct sof_ipc_dma_trace_posn *posn);
552 void snd_sof_trace_notify_for_error(struct snd_sof_dev *sdev);
553 void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
554 			      u32 panic_code, u32 tracep_code, void *oops,
555 			      struct sof_ipc_panic_info *panic_info,
556 			      void *stack, size_t stack_words);
557 int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev);
558 void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev);
559 int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
560 int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
561 		enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
562 		const char *name, enum sof_debugfs_access_type access_type);
563 
564 /*
565  * DSP Architectures.
566  */
567 static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
568 			     void *oops, u32 *stack, u32 stack_words)
569 {
570 		sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level,  oops, stack,
571 						  stack_words);
572 }
573 
574 static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
575 {
576 	if (sof_dsp_arch_ops(sdev)->dsp_oops)
577 		sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops);
578 }
579 
580 extern const struct dsp_arch_ops sof_xtensa_arch_ops;
581 
582 /*
583  * Firmware state tracking
584  */
585 void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
586 
587 /*
588  * Utilities
589  */
590 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
591 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
592 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
593 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
594 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
595 		       void *message, size_t bytes);
596 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
597 		      void *message, size_t bytes);
598 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
599 		    u32 offset, void *src, size_t size);
600 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
601 		   u32 offset, void *dest, size_t size);
602 
603 int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id);
604 
605 int sof_ipc_msg_data(struct snd_sof_dev *sdev,
606 		     struct snd_pcm_substream *substream,
607 		     void *p, size_t sz);
608 int sof_ipc_pcm_params(struct snd_sof_dev *sdev,
609 		       struct snd_pcm_substream *substream,
610 		       const struct sof_ipc_pcm_params_reply *reply);
611 
612 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
613 			struct snd_pcm_substream *substream);
614 int sof_stream_pcm_close(struct snd_sof_dev *sdev,
615 			 struct snd_pcm_substream *substream);
616 
617 int sof_machine_check(struct snd_sof_dev *sdev);
618 
619 /* SOF client support */
620 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
621 int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
622 			    const void *data, size_t size);
623 void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
624 int sof_register_clients(struct snd_sof_dev *sdev);
625 void sof_unregister_clients(struct snd_sof_dev *sdev);
626 void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
627 void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
628 int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
629 int sof_resume_clients(struct snd_sof_dev *sdev);
630 #else /* CONFIG_SND_SOC_SOF_CLIENT */
631 static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
632 					  u32 id, const void *data, size_t size)
633 {
634 	return 0;
635 }
636 
637 static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
638 					     const char *name, u32 id)
639 {
640 }
641 
642 static inline int sof_register_clients(struct snd_sof_dev *sdev)
643 {
644 	return 0;
645 }
646 
647 static inline  void sof_unregister_clients(struct snd_sof_dev *sdev)
648 {
649 }
650 
651 static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
652 {
653 }
654 
655 static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
656 {
657 }
658 
659 static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
660 {
661 	return 0;
662 }
663 
664 static inline int sof_resume_clients(struct snd_sof_dev *sdev)
665 {
666 	return 0;
667 }
668 #endif /* CONFIG_SND_SOC_SOF_CLIENT */
669 
670 #endif
671