xref: /openbmc/linux/sound/soc/sof/sof-priv.h (revision e8254a8e)
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 #define SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS	BIT(8) /* print DMA position updates
41 							* in dmesg logs
42 							*/
43 #define SOF_DBG_PRINT_IPC_SUCCESS_LOGS		BIT(9) /* print IPC success
44 							* in dmesg logs
45 							*/
46 #define SOF_DBG_FORCE_NOCODEC			BIT(10) /* ignore all codec-related
47 							 * configurations
48 							 */
49 
50 /* Flag definitions used for controlling the DSP dump behavior */
51 #define SOF_DBG_DUMP_REGS		BIT(0)
52 #define SOF_DBG_DUMP_MBOX		BIT(1)
53 #define SOF_DBG_DUMP_TEXT		BIT(2)
54 #define SOF_DBG_DUMP_PCI		BIT(3)
55 /* Output this dump (at the DEBUG level) only when SOF_DBG_PRINT_ALL_DUMPS is set */
56 #define SOF_DBG_DUMP_OPTIONAL		BIT(4)
57 
58 /* global debug state set by SOF_DBG_ flags */
59 bool sof_debug_check_flag(int mask);
60 
61 /* max BARs mmaped devices can use */
62 #define SND_SOF_BARS	8
63 
64 /* time in ms for runtime suspend delay */
65 #define SND_SOF_SUSPEND_DELAY_MS	2000
66 
67 /* DMA buffer size for trace */
68 #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16)
69 
70 #define SOF_IPC_DSP_REPLY		0
71 #define SOF_IPC_HOST_REPLY		1
72 
73 /* convenience constructor for DAI driver streams */
74 #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \
75 	{.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \
76 	 .rates = srates, .formats = sfmt}
77 
78 #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
79 	SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
80 
81 /* So far the primary core on all DSPs has ID 0 */
82 #define SOF_DSP_PRIMARY_CORE 0
83 
84 /* max number of DSP cores */
85 #define SOF_MAX_DSP_NUM_CORES 8
86 
87 struct sof_dsp_power_state {
88 	u32 state;
89 	u32 substate; /* platform-specific */
90 };
91 
92 /* System suspend target state */
93 enum sof_system_suspend_state {
94 	SOF_SUSPEND_NONE = 0,
95 	SOF_SUSPEND_S0IX,
96 	SOF_SUSPEND_S3,
97 	SOF_SUSPEND_S4,
98 	SOF_SUSPEND_S5,
99 };
100 
101 enum sof_dfsentry_type {
102 	SOF_DFSENTRY_TYPE_IOMEM = 0,
103 	SOF_DFSENTRY_TYPE_BUF,
104 };
105 
106 enum sof_debugfs_access_type {
107 	SOF_DEBUGFS_ACCESS_ALWAYS = 0,
108 	SOF_DEBUGFS_ACCESS_D0_ONLY,
109 };
110 
111 struct sof_compr_stream {
112 	u64 copied_total;
113 	u32 sampling_rate;
114 	u16 channels;
115 	u16 sample_container_bytes;
116 };
117 
118 struct snd_sof_dev;
119 struct snd_sof_ipc_msg;
120 struct snd_sof_ipc;
121 struct snd_sof_debugfs_map;
122 struct snd_soc_tplg_ops;
123 struct snd_soc_component;
124 struct snd_sof_pdata;
125 
126 /**
127  * struct snd_sof_platform_stream_params - platform dependent stream parameters
128  * @stream_tag:		Stream tag to use
129  * @use_phy_addr:	Use the provided @phy_addr for configuration
130  * @phy_addr:		Platform dependent address to be used, if  @use_phy_addr
131  *			is true
132  * @no_ipc_position:	Disable position update IPC from firmware
133  */
134 struct snd_sof_platform_stream_params {
135 	u16 stream_tag;
136 	bool use_phy_address;
137 	u32 phy_addr;
138 	bool no_ipc_position;
139 	bool cont_update_posn;
140 };
141 
142 /**
143  * struct sof_firmware - Container struct for SOF firmware
144  * @fw:			Pointer to the firmware
145  * @payload_offset:	Offset of the data within the loaded firmware image to be
146  *			loaded to the DSP (skipping for example ext_manifest section)
147  */
148 struct sof_firmware {
149 	const struct firmware *fw;
150 	u32 payload_offset;
151 };
152 
153 /*
154  * SOF DSP HW abstraction operations.
155  * Used to abstract DSP HW architecture and any IO busses between host CPU
156  * and DSP device(s).
157  */
158 struct snd_sof_dsp_ops {
159 
160 	/* probe/remove/shutdown */
161 	int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
162 	int (*remove)(struct snd_sof_dev *sof_dev); /* optional */
163 	int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */
164 
165 	/* DSP core boot / reset */
166 	int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */
167 	int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */
168 	int (*reset)(struct snd_sof_dev *sof_dev); /* optional */
169 	int (*core_get)(struct snd_sof_dev *sof_dev, int core); /* optional */
170 	int (*core_put)(struct snd_sof_dev *sof_dev, int core); /* optional */
171 
172 	/*
173 	 * Register IO: only used by respective drivers themselves,
174 	 * TODO: consider removing these operations and calling respective
175 	 * implementations directly
176 	 */
177 	void (*write8)(struct snd_sof_dev *sof_dev, void __iomem *addr,
178 		       u8 value); /* optional */
179 	u8 (*read8)(struct snd_sof_dev *sof_dev,
180 		    void __iomem *addr); /* optional */
181 	void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
182 		      u32 value); /* optional */
183 	u32 (*read)(struct snd_sof_dev *sof_dev,
184 		    void __iomem *addr); /* optional */
185 	void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
186 			u64 value); /* optional */
187 	u64 (*read64)(struct snd_sof_dev *sof_dev,
188 		      void __iomem *addr); /* optional */
189 
190 	/* memcpy IO */
191 	int (*block_read)(struct snd_sof_dev *sof_dev,
192 			  enum snd_sof_fw_blk_type type, u32 offset,
193 			  void *dest, size_t size); /* mandatory */
194 	int (*block_write)(struct snd_sof_dev *sof_dev,
195 			   enum snd_sof_fw_blk_type type, u32 offset,
196 			   void *src, size_t size); /* mandatory */
197 
198 	/* Mailbox IO */
199 	void (*mailbox_read)(struct snd_sof_dev *sof_dev,
200 			     u32 offset, void *dest,
201 			     size_t size); /* optional */
202 	void (*mailbox_write)(struct snd_sof_dev *sof_dev,
203 			      u32 offset, void *src,
204 			      size_t size); /* optional */
205 
206 	/* doorbell */
207 	irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
208 	irqreturn_t (*irq_thread)(int irq, void *context); /* optional */
209 
210 	/* ipc */
211 	int (*send_msg)(struct snd_sof_dev *sof_dev,
212 			struct snd_sof_ipc_msg *msg); /* mandatory */
213 
214 	/* FW loading */
215 	int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
216 	int (*load_module)(struct snd_sof_dev *sof_dev,
217 			   struct snd_sof_mod_hdr *hdr); /* optional */
218 
219 	/* connect pcm substream to a host stream */
220 	int (*pcm_open)(struct snd_sof_dev *sdev,
221 			struct snd_pcm_substream *substream); /* optional */
222 	/* disconnect pcm substream to a host stream */
223 	int (*pcm_close)(struct snd_sof_dev *sdev,
224 			 struct snd_pcm_substream *substream); /* optional */
225 
226 	/* host stream hw params */
227 	int (*pcm_hw_params)(struct snd_sof_dev *sdev,
228 			     struct snd_pcm_substream *substream,
229 			     struct snd_pcm_hw_params *params,
230 			     struct snd_sof_platform_stream_params *platform_params); /* optional */
231 
232 	/* host stream hw_free */
233 	int (*pcm_hw_free)(struct snd_sof_dev *sdev,
234 			   struct snd_pcm_substream *substream); /* optional */
235 
236 	/* host stream trigger */
237 	int (*pcm_trigger)(struct snd_sof_dev *sdev,
238 			   struct snd_pcm_substream *substream,
239 			   int cmd); /* optional */
240 
241 	/* host stream pointer */
242 	snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
243 					 struct snd_pcm_substream *substream); /* optional */
244 
245 	/* pcm ack */
246 	int (*pcm_ack)(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream); /* optional */
247 
248 	/* host read DSP stream data */
249 	int (*ipc_msg_data)(struct snd_sof_dev *sdev,
250 			    struct snd_pcm_substream *substream,
251 			    void *p, size_t sz); /* mandatory */
252 
253 	/* host side configuration of the stream's data offset in stream mailbox area */
254 	int (*set_stream_data_offset)(struct snd_sof_dev *sdev,
255 				      struct snd_pcm_substream *substream,
256 				      size_t posn_offset); /* optional */
257 
258 	/* pre/post firmware run */
259 	int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
260 	int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
261 
262 	/* parse platform specific extended manifest, optional */
263 	int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev,
264 					   const struct sof_ext_man_elem_header *hdr);
265 
266 	/* DSP PM */
267 	int (*suspend)(struct snd_sof_dev *sof_dev,
268 		       u32 target_state); /* optional */
269 	int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
270 	int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
271 	int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
272 	int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
273 	int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
274 	int (*set_power_state)(struct snd_sof_dev *sdev,
275 			       const struct sof_dsp_power_state *target_state); /* optional */
276 
277 	/* DSP clocking */
278 	int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
279 
280 	/* debug */
281 	const struct snd_sof_debugfs_map *debug_map; /* optional */
282 	int debug_map_count; /* optional */
283 	void (*dbg_dump)(struct snd_sof_dev *sof_dev,
284 			 u32 flags); /* optional */
285 	void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
286 	int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
287 				       enum snd_sof_fw_blk_type blk_type, u32 offset,
288 				       size_t size, const char *name,
289 				       enum sof_debugfs_access_type access_type); /* optional */
290 
291 	/* host DMA trace (IPC3) */
292 	int (*trace_init)(struct snd_sof_dev *sdev,
293 			  struct snd_dma_buffer *dmatb,
294 			  struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */
295 	int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
296 	int (*trace_trigger)(struct snd_sof_dev *sdev,
297 			     int cmd); /* optional */
298 
299 	/* misc */
300 	int (*get_bar_index)(struct snd_sof_dev *sdev,
301 			     u32 type); /* optional */
302 	int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
303 	int (*get_window_offset)(struct snd_sof_dev *sdev,
304 				 u32 id);/* mandatory for common loader code */
305 
306 	/* machine driver ops */
307 	int (*machine_register)(struct snd_sof_dev *sdev,
308 				void *pdata); /* optional */
309 	void (*machine_unregister)(struct snd_sof_dev *sdev,
310 				   void *pdata); /* optional */
311 	struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */
312 	void (*set_mach_params)(struct snd_soc_acpi_mach *mach,
313 				struct snd_sof_dev *sdev); /* optional */
314 
315 	/* IPC client ops */
316 	int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
317 	void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
318 
319 	/* DAI ops */
320 	struct snd_soc_dai_driver *drv;
321 	int num_drv;
322 
323 	/* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
324 	u32 hw_info;
325 
326 	const struct dsp_arch_ops *dsp_arch_ops;
327 };
328 
329 /* DSP architecture specific callbacks for oops and stack dumps */
330 struct dsp_arch_ops {
331 	void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops);
332 	void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops,
333 			  u32 *stack, u32 stack_words);
334 };
335 
336 #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
337 
338 /* FS entry for debug files that can expose DSP memories, registers */
339 struct snd_sof_dfsentry {
340 	size_t size;
341 	size_t buf_data_size;  /* length of buffered data for file read operation */
342 	enum sof_dfsentry_type type;
343 	/*
344 	 * access_type specifies if the
345 	 * memory -> DSP resource (memory, register etc) is always accessible
346 	 * or if it is accessible only when the DSP is in D0.
347 	 */
348 	enum sof_debugfs_access_type access_type;
349 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
350 	char *cache_buf; /* buffer to cache the contents of debugfs memory */
351 #endif
352 	struct snd_sof_dev *sdev;
353 	struct list_head list;  /* list in sdev dfsentry list */
354 	union {
355 		void __iomem *io_mem;
356 		void *buf;
357 	};
358 };
359 
360 /* Debug mapping for any DSP memory or registers that can used for debug */
361 struct snd_sof_debugfs_map {
362 	const char *name;
363 	u32 bar;
364 	u32 offset;
365 	u32 size;
366 	/*
367 	 * access_type specifies if the memory is always accessible
368 	 * or if it is accessible only when the DSP is in D0.
369 	 */
370 	enum sof_debugfs_access_type access_type;
371 };
372 
373 /* mailbox descriptor, used for host <-> DSP IPC */
374 struct snd_sof_mailbox {
375 	u32 offset;
376 	size_t size;
377 };
378 
379 /* IPC message descriptor for host <-> DSP IO */
380 struct snd_sof_ipc_msg {
381 	/* message data */
382 	void *msg_data;
383 	void *reply_data;
384 	size_t msg_size;
385 	size_t reply_size;
386 	int reply_error;
387 
388 	/* notification, firmware initiated messages */
389 	void *rx_data;
390 
391 	wait_queue_head_t waitq;
392 	bool ipc_complete;
393 };
394 
395 /**
396  * struct sof_ipc_fw_tracing_ops - IPC-specific firmware tracing ops
397  * @init:	Function pointer for initialization of the tracing
398  * @free:	Optional function pointer for freeing of the tracing
399  * @fw_crashed:	Optional function pointer to notify the tracing of a firmware crash
400  * @suspend:	Function pointer for system/runtime suspend
401  * @resume:	Function pointer for system/runtime resume
402  */
403 struct sof_ipc_fw_tracing_ops {
404 	int (*init)(struct snd_sof_dev *sdev);
405 	void (*free)(struct snd_sof_dev *sdev);
406 	void (*fw_crashed)(struct snd_sof_dev *sdev);
407 	void (*suspend)(struct snd_sof_dev *sdev, pm_message_t pm_state);
408 	int (*resume)(struct snd_sof_dev *sdev);
409 };
410 
411 /**
412  * struct sof_ipc_pm_ops - IPC-specific PM ops
413  * @ctx_save:		Optional function pointer for context save
414  * @ctx_restore:	Optional function pointer for context restore
415  * @set_core_state:	Optional function pointer for turning on/off a DSP core
416  */
417 struct sof_ipc_pm_ops {
418 	int (*ctx_save)(struct snd_sof_dev *sdev);
419 	int (*ctx_restore)(struct snd_sof_dev *sdev);
420 	int (*set_core_state)(struct snd_sof_dev *sdev, int core_idx, bool on);
421 };
422 
423 /**
424  * struct sof_ipc_fw_loader_ops - IPC/FW-specific loader ops
425  * @validate:		Function pointer for validating the firmware image
426  * @parse_ext_manifest:	Function pointer for parsing the manifest of the firmware
427  * @load_fw_to_dsp:	Optional function pointer for loading the firmware to the
428  *			DSP.
429  *			The function implements generic, hardware independent way
430  *			of loading the initial firmware and its modules (if any).
431  */
432 struct sof_ipc_fw_loader_ops {
433 	int (*validate)(struct snd_sof_dev *sdev);
434 	size_t (*parse_ext_manifest)(struct snd_sof_dev *sdev);
435 	int (*load_fw_to_dsp)(struct snd_sof_dev *sdev);
436 };
437 
438 struct sof_ipc_tplg_ops;
439 struct sof_ipc_pcm_ops;
440 
441 /**
442  * struct sof_ipc_ops - IPC-specific ops
443  * @tplg:	Pointer to IPC-specific topology ops
444  * @pm:		Pointer to PM ops
445  * @pcm:	Pointer to PCM ops
446  * @fw_loader:	Pointer to Firmware Loader ops
447  * @fw_tracing:	Pointer to Firmware tracing ops
448  *
449  * @init:	Optional pointer for IPC related initialization
450  * @exit:	Optional pointer for IPC related cleanup
451  * @post_fw_boot: Optional pointer to execute IPC related tasks after firmware
452  *		boot.
453  *
454  * @tx_msg:	Function pointer for sending a 'short' IPC message
455  * @set_get_data: Function pointer for set/get data ('large' IPC message). This
456  *		function may split up the 'large' message and use the @tx_msg
457  *		path to transfer individual chunks, or use other means to transfer
458  *		the message.
459  * @get_reply:	Function pointer for fetching the reply to
460  *		sdev->ipc->msg.reply_data
461  * @rx_msg:	Function pointer for handling a received message
462  *
463  * Note: both @tx_msg and @set_get_data considered as TX functions and they are
464  * serialized for the duration of the instructed transfer. A large message sent
465  * via @set_get_data is a single transfer even if at the hardware level it is
466  * handled with multiple chunks.
467  */
468 struct sof_ipc_ops {
469 	const struct sof_ipc_tplg_ops *tplg;
470 	const struct sof_ipc_pm_ops *pm;
471 	const struct sof_ipc_pcm_ops *pcm;
472 	const struct sof_ipc_fw_loader_ops *fw_loader;
473 	const struct sof_ipc_fw_tracing_ops *fw_tracing;
474 
475 	int (*init)(struct snd_sof_dev *sdev);
476 	void (*exit)(struct snd_sof_dev *sdev);
477 	int (*post_fw_boot)(struct snd_sof_dev *sdev);
478 
479 	int (*tx_msg)(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
480 		      void *reply_data, size_t reply_bytes, bool no_pm);
481 	int (*set_get_data)(struct snd_sof_dev *sdev, void *data, size_t data_bytes,
482 			    bool set);
483 	int (*get_reply)(struct snd_sof_dev *sdev);
484 	void (*rx_msg)(struct snd_sof_dev *sdev);
485 };
486 
487 /* SOF generic IPC data */
488 struct snd_sof_ipc {
489 	struct snd_sof_dev *sdev;
490 
491 	/* protects messages and the disable flag */
492 	struct mutex tx_mutex;
493 	/* disables further sending of ipc's */
494 	bool disable_ipc_tx;
495 
496 	/* Maximum allowed size of a single IPC message/reply */
497 	size_t max_payload_size;
498 
499 	struct snd_sof_ipc_msg msg;
500 
501 	/* IPC ops based on version */
502 	const struct sof_ipc_ops *ops;
503 };
504 
505 /*
506  * SOF Device Level.
507  */
508 struct snd_sof_dev {
509 	struct device *dev;
510 	spinlock_t ipc_lock;	/* lock for IPC users */
511 	spinlock_t hw_lock;	/* lock for HW IO access */
512 
513 	/* Main, Base firmware image */
514 	struct sof_firmware basefw;
515 
516 	/*
517 	 * ASoC components. plat_drv fields are set dynamically so
518 	 * can't use const
519 	 */
520 	struct snd_soc_component_driver plat_drv;
521 
522 	/* current DSP power state */
523 	struct sof_dsp_power_state dsp_power_state;
524 	/* mutex to protect the dsp_power_state access */
525 	struct mutex power_state_access;
526 
527 	/* Intended power target of system suspend */
528 	enum sof_system_suspend_state system_suspend_target;
529 
530 	/* DSP firmware boot */
531 	wait_queue_head_t boot_wait;
532 	enum sof_fw_state fw_state;
533 	bool first_boot;
534 
535 	/* work queue in case the probe is implemented in two steps */
536 	struct work_struct probe_work;
537 	bool probe_completed;
538 
539 	/* DSP HW differentiation */
540 	struct snd_sof_pdata *pdata;
541 
542 	/* IPC */
543 	struct snd_sof_ipc *ipc;
544 	struct snd_sof_mailbox dsp_box;		/* DSP initiated IPC */
545 	struct snd_sof_mailbox host_box;	/* Host initiated IPC */
546 	struct snd_sof_mailbox stream_box;	/* Stream position update */
547 	struct snd_sof_mailbox debug_box;	/* Debug info updates */
548 	struct snd_sof_ipc_msg *msg;
549 	int ipc_irq;
550 	u32 next_comp_id; /* monotonic - reset during S3 */
551 
552 	/* memory bases for mmaped DSPs - set by dsp_init() */
553 	void __iomem *bar[SND_SOF_BARS];	/* DSP base address */
554 	int mmio_bar;
555 	int mailbox_bar;
556 	size_t dsp_oops_offset;
557 
558 	/* debug */
559 	struct dentry *debugfs_root;
560 	struct list_head dfsentry_list;
561 	bool dbg_dump_printed;
562 	bool ipc_dump_printed;
563 
564 	/* firmware loader */
565 	struct sof_ipc_fw_ready fw_ready;
566 	struct sof_ipc_fw_version fw_version;
567 	struct sof_ipc_cc_version *cc_version;
568 
569 	/* topology */
570 	struct snd_soc_tplg_ops *tplg_ops;
571 	struct list_head pcm_list;
572 	struct list_head kcontrol_list;
573 	struct list_head widget_list;
574 	struct list_head dai_list;
575 	struct list_head dai_link_list;
576 	struct list_head route_list;
577 	struct snd_soc_component *component;
578 	u32 enabled_cores_mask; /* keep track of enabled cores */
579 	bool led_present;
580 
581 	/* FW configuration */
582 	struct sof_ipc_window *info_window;
583 
584 	/* IPC timeouts in ms */
585 	int ipc_timeout;
586 	int boot_timeout;
587 
588 	/* firmwre tracing */
589 	bool fw_trace_is_supported; /* set with Kconfig or module parameter */
590 	void *fw_trace_data; /* private data used by firmware tracing implementation */
591 
592 	bool msi_enabled;
593 
594 	/* DSP core context */
595 	u32 num_cores;
596 
597 	/*
598 	 * ref count per core that will be modified during system suspend/resume and during pcm
599 	 * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
600 	 * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
601 	 * sound/core/ when streams are active and during system suspend/resume, streams are
602 	 * already suspended.
603 	 */
604 	int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
605 
606 	/*
607 	 * Used to keep track of registered IPC client devices so that they can
608 	 * be removed when the parent SOF module is removed.
609 	 */
610 	struct list_head ipc_client_list;
611 
612 	/* mutex to protect client list */
613 	struct mutex ipc_client_mutex;
614 
615 	/*
616 	 * Used for tracking the IPC client's RX registration for DSP initiated
617 	 * message handling.
618 	 */
619 	struct list_head ipc_rx_handler_list;
620 
621 	/*
622 	 * Used for tracking the IPC client's registration for DSP state change
623 	 * notification
624 	 */
625 	struct list_head fw_state_handler_list;
626 
627 	/* to protect the ipc_rx_handler_list  and  dsp_state_handler_list list */
628 	struct mutex client_event_handler_mutex;
629 
630 	/* quirks to override topology values */
631 	bool mclk_id_override;
632 	u16  mclk_id_quirk; /* same size as in IPC3 definitions */
633 
634 	void *private;			/* core does not touch this */
635 };
636 
637 /*
638  * Device Level.
639  */
640 
641 int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
642 int snd_sof_device_remove(struct device *dev);
643 int snd_sof_device_shutdown(struct device *dev);
644 bool snd_sof_device_probe_completed(struct device *dev);
645 
646 int snd_sof_runtime_suspend(struct device *dev);
647 int snd_sof_runtime_resume(struct device *dev);
648 int snd_sof_runtime_idle(struct device *dev);
649 int snd_sof_resume(struct device *dev);
650 int snd_sof_suspend(struct device *dev);
651 int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
652 int snd_sof_prepare(struct device *dev);
653 void snd_sof_complete(struct device *dev);
654 
655 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
656 
657 /*
658  * Compress support
659  */
660 extern struct snd_compress_ops sof_compressed_ops;
661 
662 /*
663  * Firmware loading.
664  */
665 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
666 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
667 int snd_sof_run_firmware(struct snd_sof_dev *sdev);
668 void snd_sof_fw_unload(struct snd_sof_dev *sdev);
669 
670 /*
671  * IPC low level APIs.
672  */
673 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
674 void snd_sof_ipc_free(struct snd_sof_dev *sdev);
675 void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
676 void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
677 static inline void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
678 {
679 	sdev->ipc->ops->rx_msg(sdev);
680 }
681 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
682 		       void *reply_data, size_t reply_bytes);
683 int sof_ipc_set_get_data(struct snd_sof_ipc *ipc, void *msg_data,
684 			 size_t msg_bytes, bool set);
685 int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
686 			     void *reply_data, size_t reply_bytes);
687 int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
688 		     size_t reply_bytes);
689 
690 static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
691 {
692 	snd_sof_ipc_get_reply(sdev);
693 	snd_sof_ipc_reply(sdev, msg_id);
694 }
695 
696 /*
697  * Trace/debug
698  */
699 int snd_sof_dbg_init(struct snd_sof_dev *sdev);
700 void snd_sof_free_debug(struct snd_sof_dev *sdev);
701 int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
702 			     void *base, size_t size,
703 			     const char *name, mode_t mode);
704 void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
705 			      u32 panic_code, u32 tracep_code, void *oops,
706 			      struct sof_ipc_panic_info *panic_info,
707 			      void *stack, size_t stack_words);
708 void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev, const char *msg);
709 int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
710 int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
711 		enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
712 		const char *name, enum sof_debugfs_access_type access_type);
713 /* Firmware tracing */
714 int sof_fw_trace_init(struct snd_sof_dev *sdev);
715 void sof_fw_trace_free(struct snd_sof_dev *sdev);
716 void sof_fw_trace_fw_crashed(struct snd_sof_dev *sdev);
717 void sof_fw_trace_suspend(struct snd_sof_dev *sdev, pm_message_t pm_state);
718 int sof_fw_trace_resume(struct snd_sof_dev *sdev);
719 
720 /*
721  * DSP Architectures.
722  */
723 static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
724 			     void *oops, u32 *stack, u32 stack_words)
725 {
726 		sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level,  oops, stack,
727 						  stack_words);
728 }
729 
730 static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
731 {
732 	if (sof_dsp_arch_ops(sdev)->dsp_oops)
733 		sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops);
734 }
735 
736 extern const struct dsp_arch_ops sof_xtensa_arch_ops;
737 
738 /*
739  * Firmware state tracking
740  */
741 void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
742 
743 /*
744  * Utilities
745  */
746 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
747 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
748 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
749 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
750 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
751 		       void *message, size_t bytes);
752 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
753 		      void *message, size_t bytes);
754 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
755 		    u32 offset, void *src, size_t size);
756 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
757 		   u32 offset, void *dest, size_t size);
758 
759 int sof_ipc_msg_data(struct snd_sof_dev *sdev,
760 		     struct snd_pcm_substream *substream,
761 		     void *p, size_t sz);
762 int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
763 			       struct snd_pcm_substream *substream,
764 			       size_t posn_offset);
765 
766 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
767 			struct snd_pcm_substream *substream);
768 int sof_stream_pcm_close(struct snd_sof_dev *sdev,
769 			 struct snd_pcm_substream *substream);
770 
771 int sof_machine_check(struct snd_sof_dev *sdev);
772 
773 /* SOF client support */
774 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
775 int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
776 			    const void *data, size_t size);
777 void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
778 int sof_register_clients(struct snd_sof_dev *sdev);
779 void sof_unregister_clients(struct snd_sof_dev *sdev);
780 void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
781 void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
782 int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
783 int sof_resume_clients(struct snd_sof_dev *sdev);
784 #else /* CONFIG_SND_SOC_SOF_CLIENT */
785 static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
786 					  u32 id, const void *data, size_t size)
787 {
788 	return 0;
789 }
790 
791 static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
792 					     const char *name, u32 id)
793 {
794 }
795 
796 static inline int sof_register_clients(struct snd_sof_dev *sdev)
797 {
798 	return 0;
799 }
800 
801 static inline  void sof_unregister_clients(struct snd_sof_dev *sdev)
802 {
803 }
804 
805 static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
806 {
807 }
808 
809 static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
810 {
811 }
812 
813 static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
814 {
815 	return 0;
816 }
817 
818 static inline int sof_resume_clients(struct snd_sof_dev *sdev)
819 {
820 	return 0;
821 }
822 #endif /* CONFIG_SND_SOC_SOF_CLIENT */
823 
824 /* Main ops for IPC implementations */
825 extern const struct sof_ipc_ops ipc3_ops;
826 extern const struct sof_ipc_ops ipc4_ops;
827 
828 #endif
829