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