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