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