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