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