xref: /openbmc/linux/sound/soc/sof/sof-priv.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1e149ca29SPierre-Louis Bossart /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2c16211d6SLiam Girdwood /*
3c16211d6SLiam Girdwood  * This file is provided under a dual BSD/GPLv2 license.  When using or
4c16211d6SLiam Girdwood  * redistributing this file, you may do so under either license.
5c16211d6SLiam Girdwood  *
6c16211d6SLiam Girdwood  * Copyright(c) 2018 Intel Corporation. All rights reserved.
7c16211d6SLiam Girdwood  *
8c16211d6SLiam Girdwood  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9c16211d6SLiam Girdwood  */
10c16211d6SLiam Girdwood 
11c16211d6SLiam Girdwood #ifndef __SOUND_SOC_SOF_PRIV_H
12c16211d6SLiam Girdwood #define __SOUND_SOC_SOF_PRIV_H
13c16211d6SLiam Girdwood 
14c16211d6SLiam Girdwood #include <linux/device.h>
15c16211d6SLiam Girdwood #include <sound/hdaudio.h>
16c16211d6SLiam Girdwood #include <sound/sof.h>
17c16211d6SLiam Girdwood #include <sound/sof/info.h>
18c16211d6SLiam Girdwood #include <sound/sof/pm.h>
19c16211d6SLiam Girdwood #include <sound/sof/trace.h>
20c16211d6SLiam Girdwood #include <uapi/sound/sof/fw.h>
21e984f3efSFred Oh #include <sound/sof/ext_manifest.h>
22c16211d6SLiam Girdwood 
231b905942SDaniel Baluta struct snd_sof_pcm_stream;
241b905942SDaniel Baluta 
25beb6ade1SPeter Ujfalusi /* Flag definitions used in sof_core_debug (sof_debug module parameter) */
262ab4c50fSPierre-Louis Bossart #define SOF_DBG_ENABLE_TRACE	BIT(0)
27fbfa22ecSRanjani Sridharan #define SOF_DBG_RETAIN_CTX	BIT(1)	/* prevent DSP D3 on FW exception */
28c0e7969cSRanjani Sridharan #define SOF_DBG_VERIFY_TPLG	BIT(2) /* verify topology during load */
29ea6bfbbeSPierre-Louis Bossart #define SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE	BIT(3) /* 0: use topology token
30ea6bfbbeSPierre-Louis Bossart 							* 1: override topology
31ea6bfbbeSPierre-Louis Bossart 							*/
32ea6bfbbeSPierre-Louis Bossart #define SOF_DBG_DYNAMIC_PIPELINES_ENABLE	BIT(4) /* 0: use static pipelines
33ea6bfbbeSPierre-Louis Bossart 							* 1: use dynamic pipelines
34ea6bfbbeSPierre-Louis Bossart 							*/
351539c8c5SPierre-Louis Bossart #define SOF_DBG_DISABLE_MULTICORE		BIT(5) /* schedule all pipelines/widgets
361539c8c5SPierre-Louis Bossart 							* on primary core
371539c8c5SPierre-Louis Bossart 							*/
389ff90859SPeter Ujfalusi #define SOF_DBG_PRINT_ALL_DUMPS		BIT(6) /* Print all ipc and dsp dumps */
39d7a8fbd1SKeyon Jie #define SOF_DBG_IGNORE_D3_PERSISTENT		BIT(7) /* ignore the DSP D3 persistent capability
40d7a8fbd1SKeyon Jie 							* and always download firmware upon D3 exit
41d7a8fbd1SKeyon Jie 							*/
42f7309dbeSPierre-Louis Bossart #define SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS	BIT(8) /* print DMA position updates
43f7309dbeSPierre-Louis Bossart 							* in dmesg logs
44f7309dbeSPierre-Louis Bossart 							*/
45f7309dbeSPierre-Louis Bossart #define SOF_DBG_PRINT_IPC_SUCCESS_LOGS		BIT(9) /* print IPC success
46f7309dbeSPierre-Louis Bossart 							* in dmesg logs
47f7309dbeSPierre-Louis Bossart 							*/
484bd1adb8SPierre-Louis Bossart #define SOF_DBG_FORCE_NOCODEC			BIT(10) /* ignore all codec-related
494bd1adb8SPierre-Louis Bossart 							 * configurations
504bd1adb8SPierre-Louis Bossart 							 */
5159611370SPeter Ujfalusi #define SOF_DBG_DUMP_IPC_MESSAGE_PAYLOAD	BIT(11) /* On top of the IPC message header
52fbfa22ecSRanjani Sridharan 							 * dump the message payload also
53beb6ade1SPeter Ujfalusi 							 */
54fbfa22ecSRanjani Sridharan #define SOF_DBG_DSPLESS_MODE			BIT(15) /* Do not initialize and use the DSP */
55fbfa22ecSRanjani Sridharan 
56fbfa22ecSRanjani Sridharan /* Flag definitions used for controlling the DSP dump behavior */
57fbfa22ecSRanjani Sridharan #define SOF_DBG_DUMP_REGS		BIT(0)
58beb6ade1SPeter Ujfalusi #define SOF_DBG_DUMP_MBOX		BIT(1)
59beb6ade1SPeter Ujfalusi #define SOF_DBG_DUMP_TEXT		BIT(2)
60c16211d6SLiam Girdwood #define SOF_DBG_DUMP_PCI		BIT(3)
612ab4c50fSPierre-Louis Bossart /* Output this dump (at the DEBUG level) only when SOF_DBG_PRINT_ALL_DUMPS is set */
62f902b21aSPeter Ujfalusi #define SOF_DBG_DUMP_OPTIONAL		BIT(4)
632ab4c50fSPierre-Louis Bossart 
64c16211d6SLiam Girdwood /* global debug state set by SOF_DBG_ flags */
65c16211d6SLiam Girdwood bool sof_debug_check_flag(int mask);
66c16211d6SLiam Girdwood 
67c16211d6SLiam Girdwood /* max BARs mmaped devices can use */
68c16211d6SLiam Girdwood #define SND_SOF_BARS	8
69c16211d6SLiam Girdwood 
70c16211d6SLiam Girdwood /* time in ms for runtime suspend delay */
71c16211d6SLiam Girdwood #define SND_SOF_SUSPEND_DELAY_MS	2000
72c16211d6SLiam Girdwood 
73c16211d6SLiam Girdwood /* DMA buffer size for trace */
74c16211d6SLiam Girdwood #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16)
75c16211d6SLiam Girdwood 
76c16211d6SLiam Girdwood #define SOF_IPC_DSP_REPLY		0
77c16211d6SLiam Girdwood #define SOF_IPC_HOST_REPLY		1
78c16211d6SLiam Girdwood 
79c16211d6SLiam Girdwood /* convenience constructor for DAI driver streams */
80c16211d6SLiam Girdwood #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \
81c16211d6SLiam Girdwood 	{.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \
82c16211d6SLiam Girdwood 	 .rates = srates, .formats = sfmt}
83c16211d6SLiam Girdwood 
840dcdf842SGuennadi Liakhovetski #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
850dcdf842SGuennadi Liakhovetski 	SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
860dcdf842SGuennadi Liakhovetski 
875974f684SRanjani Sridharan /* So far the primary core on all DSPs has ID 0 */
885974f684SRanjani Sridharan #define SOF_DSP_PRIMARY_CORE 0
895974f684SRanjani Sridharan 
9061e285caSRanjani Sridharan /* max number of DSP cores */
9161e285caSRanjani Sridharan #define SOF_MAX_DSP_NUM_CORES 8
9261e285caSRanjani Sridharan 
934c19030cSKeyon Jie struct sof_dsp_power_state {
944c19030cSKeyon Jie 	u32 state;
95043ae13bSRanjani Sridharan 	u32 substate; /* platform-specific */
96043ae13bSRanjani Sridharan };
97043ae13bSRanjani Sridharan 
98043ae13bSRanjani Sridharan /* System suspend target state */
99043ae13bSRanjani Sridharan enum sof_system_suspend_state {
1007a5974e0SPierre-Louis Bossart 	SOF_SUSPEND_NONE = 0,
1017a5974e0SPierre-Louis Bossart 	SOF_SUSPEND_S0IX,
102043ae13bSRanjani Sridharan 	SOF_SUSPEND_S3,
103043ae13bSRanjani Sridharan 	SOF_SUSPEND_S4,
10407e833b4SPeter Ujfalusi 	SOF_SUSPEND_S5,
10507e833b4SPeter Ujfalusi };
10607e833b4SPeter Ujfalusi 
10707e833b4SPeter Ujfalusi enum sof_dfsentry_type {
10807e833b4SPeter Ujfalusi 	SOF_DFSENTRY_TYPE_IOMEM = 0,
10907e833b4SPeter Ujfalusi 	SOF_DFSENTRY_TYPE_BUF,
11007e833b4SPeter Ujfalusi };
11107e833b4SPeter Ujfalusi 
11207e833b4SPeter Ujfalusi enum sof_debugfs_access_type {
11307e833b4SPeter Ujfalusi 	SOF_DEBUGFS_ACCESS_ALWAYS = 0,
114e3091f0aSDaniel Baluta 	SOF_DEBUGFS_ACCESS_D0_ONLY,
115e3091f0aSDaniel Baluta };
116e3091f0aSDaniel Baluta 
1173ccbe688SLaurentiu Mihalcea struct sof_compr_stream {
1183ccbe688SLaurentiu Mihalcea 	u64 copied_total;
119090349a9SDaniel Baluta 	u32 sampling_rate;
120e3091f0aSDaniel Baluta 	u16 channels;
121e3091f0aSDaniel Baluta 	u16 sample_container_bytes;
122c16211d6SLiam Girdwood 	size_t posn_offset;
123c16211d6SLiam Girdwood };
124c16211d6SLiam Girdwood 
125c16211d6SLiam Girdwood struct snd_sof_dev;
126c16211d6SLiam Girdwood struct snd_sof_ipc_msg;
127c16211d6SLiam Girdwood struct snd_sof_ipc;
128c16211d6SLiam Girdwood struct snd_sof_debugfs_map;
129c16211d6SLiam Girdwood struct snd_soc_tplg_ops;
13031f60a0cSPeter Ujfalusi struct snd_soc_component;
13131f60a0cSPeter Ujfalusi struct snd_sof_pdata;
13231f60a0cSPeter Ujfalusi 
13331f60a0cSPeter Ujfalusi /**
13431f60a0cSPeter Ujfalusi  * struct snd_sof_platform_stream_params - platform dependent stream parameters
13531f60a0cSPeter Ujfalusi  * @stream_tag:		Stream tag to use
13631f60a0cSPeter Ujfalusi  * @use_phy_addr:	Use the provided @phy_addr for configuration
13731f60a0cSPeter Ujfalusi  * @phy_addr:		Platform dependent address to be used, if  @use_phy_addr
13831f60a0cSPeter Ujfalusi  *			is true
13931f60a0cSPeter Ujfalusi  * @no_ipc_position:	Disable position update IPC from firmware
14031f60a0cSPeter Ujfalusi  */
14131f60a0cSPeter Ujfalusi struct snd_sof_platform_stream_params {
14231f60a0cSPeter Ujfalusi 	u16 stream_tag;
143d95610a1SYC Hung 	bool use_phy_address;
14431f60a0cSPeter Ujfalusi 	u32 phy_addr;
14531f60a0cSPeter Ujfalusi 	bool no_ipc_position;
1464f373ccfSPeter Ujfalusi 	bool cont_update_posn;
1474f373ccfSPeter Ujfalusi };
1484f373ccfSPeter Ujfalusi 
1494f373ccfSPeter Ujfalusi /**
1504f373ccfSPeter Ujfalusi  * struct sof_firmware - Container struct for SOF firmware
1514f373ccfSPeter Ujfalusi  * @fw:			Pointer to the firmware
1524f373ccfSPeter Ujfalusi  * @payload_offset:	Offset of the data within the loaded firmware image to be
1534f373ccfSPeter Ujfalusi  *			loaded to the DSP (skipping for example ext_manifest section)
1544f373ccfSPeter Ujfalusi  */
1554f373ccfSPeter Ujfalusi struct sof_firmware {
1564f373ccfSPeter Ujfalusi 	const struct firmware *fw;
157c16211d6SLiam Girdwood 	u32 payload_offset;
158c16211d6SLiam Girdwood };
159c16211d6SLiam Girdwood 
160c16211d6SLiam Girdwood /*
161c16211d6SLiam Girdwood  * SOF DSP HW abstraction operations.
162c16211d6SLiam Girdwood  * Used to abstract DSP HW architecture and any IO busses between host CPU
163c16211d6SLiam Girdwood  * and DSP device(s).
1647edb3051SKeyon Jie  */
165c16211d6SLiam Girdwood struct snd_sof_dsp_ops {
166c16211d6SLiam Girdwood 
1677edb3051SKeyon Jie 	/* probe/remove/shutdown */
168c16211d6SLiam Girdwood 	int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
169c16211d6SLiam Girdwood 	int (*remove)(struct snd_sof_dev *sof_dev); /* optional */
170c16211d6SLiam Girdwood 	int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */
171a70eb708SFred Oh 
172c16211d6SLiam Girdwood 	/* DSP core boot / reset */
173c414d5dfSRanjani Sridharan 	int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */
174c414d5dfSRanjani Sridharan 	int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */
175c16211d6SLiam Girdwood 	int (*reset)(struct snd_sof_dev *sof_dev); /* optional */
176c16211d6SLiam Girdwood 	int (*core_get)(struct snd_sof_dev *sof_dev, int core); /* optional */
177c16211d6SLiam Girdwood 	int (*core_put)(struct snd_sof_dev *sof_dev, int core); /* optional */
178c16211d6SLiam Girdwood 
179c16211d6SLiam Girdwood 	/*
180c16211d6SLiam Girdwood 	 * Register IO: only used by respective drivers themselves,
181f8fbf0dcSPierre-Louis Bossart 	 * TODO: consider removing these operations and calling respective
18274fe0c4dSPierre-Louis Bossart 	 * implementations directly
183f8fbf0dcSPierre-Louis Bossart 	 */
18474fe0c4dSPierre-Louis Bossart 	void (*write8)(struct snd_sof_dev *sof_dev, void __iomem *addr,
185c16211d6SLiam Girdwood 		       u8 value); /* optional */
186c16211d6SLiam Girdwood 	u8 (*read8)(struct snd_sof_dev *sof_dev,
187c16211d6SLiam Girdwood 		    void __iomem *addr); /* optional */
188c16211d6SLiam Girdwood 	void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
189c16211d6SLiam Girdwood 		      u32 value); /* optional */
190c16211d6SLiam Girdwood 	u32 (*read)(struct snd_sof_dev *sof_dev,
191c16211d6SLiam Girdwood 		    void __iomem *addr); /* optional */
192c16211d6SLiam Girdwood 	void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
193c16211d6SLiam Girdwood 			u64 value); /* optional */
194c16211d6SLiam Girdwood 	u64 (*read64)(struct snd_sof_dev *sof_dev,
1954624bb2fSPeter Ujfalusi 		      void __iomem *addr); /* optional */
1964624bb2fSPeter Ujfalusi 
1974624bb2fSPeter Ujfalusi 	/* memcpy IO */
1984624bb2fSPeter Ujfalusi 	int (*block_read)(struct snd_sof_dev *sof_dev,
1994624bb2fSPeter Ujfalusi 			  enum snd_sof_fw_blk_type type, u32 offset,
2004624bb2fSPeter Ujfalusi 			  void *dest, size_t size); /* mandatory */
201c16211d6SLiam Girdwood 	int (*block_write)(struct snd_sof_dev *sof_dev,
202f71f59ddSDaniel Baluta 			   enum snd_sof_fw_blk_type type, u32 offset,
203f71f59ddSDaniel Baluta 			   void *src, size_t size); /* mandatory */
204f71f59ddSDaniel Baluta 
205f71f59ddSDaniel Baluta 	/* Mailbox IO */
206f71f59ddSDaniel Baluta 	void (*mailbox_read)(struct snd_sof_dev *sof_dev,
207f71f59ddSDaniel Baluta 			     u32 offset, void *dest,
208f71f59ddSDaniel Baluta 			     size_t size); /* optional */
209f71f59ddSDaniel Baluta 	void (*mailbox_write)(struct snd_sof_dev *sof_dev,
210c16211d6SLiam Girdwood 			      u32 offset, void *src,
211c16211d6SLiam Girdwood 			      size_t size); /* optional */
212c16211d6SLiam Girdwood 
213c16211d6SLiam Girdwood 	/* doorbell */
214c16211d6SLiam Girdwood 	irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
215c16211d6SLiam Girdwood 	irqreturn_t (*irq_thread)(int irq, void *context); /* optional */
216c16211d6SLiam Girdwood 
217c16211d6SLiam Girdwood 	/* ipc */
218c16211d6SLiam Girdwood 	int (*send_msg)(struct snd_sof_dev *sof_dev,
219c16211d6SLiam Girdwood 			struct snd_sof_ipc_msg *msg); /* mandatory */
220c16211d6SLiam Girdwood 
221c16211d6SLiam Girdwood 	/* FW loading */
222c16211d6SLiam Girdwood 	int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
223c16211d6SLiam Girdwood 	int (*load_module)(struct snd_sof_dev *sof_dev,
224c16211d6SLiam Girdwood 			   struct snd_sof_mod_hdr *hdr); /* optional */
225c16211d6SLiam Girdwood 
226c16211d6SLiam Girdwood 	/* connect pcm substream to a host stream */
227c16211d6SLiam Girdwood 	int (*pcm_open)(struct snd_sof_dev *sdev,
228c16211d6SLiam Girdwood 			struct snd_pcm_substream *substream); /* optional */
229c16211d6SLiam Girdwood 	/* disconnect pcm substream to a host stream */
230c16211d6SLiam Girdwood 	int (*pcm_close)(struct snd_sof_dev *sdev,
231c16211d6SLiam Girdwood 			 struct snd_pcm_substream *substream); /* optional */
232c16211d6SLiam Girdwood 
233c16211d6SLiam Girdwood 	/* host stream hw params */
23431f60a0cSPeter Ujfalusi 	int (*pcm_hw_params)(struct snd_sof_dev *sdev,
235c16211d6SLiam Girdwood 			     struct snd_pcm_substream *substream,
23693146bc2SRanjani Sridharan 			     struct snd_pcm_hw_params *params,
23793146bc2SRanjani Sridharan 			     struct snd_sof_platform_stream_params *platform_params); /* optional */
23893146bc2SRanjani Sridharan 
23993146bc2SRanjani Sridharan 	/* host stream hw_free */
240c16211d6SLiam Girdwood 	int (*pcm_hw_free)(struct snd_sof_dev *sdev,
241c16211d6SLiam Girdwood 			   struct snd_pcm_substream *substream); /* optional */
242c16211d6SLiam Girdwood 
243c16211d6SLiam Girdwood 	/* host stream trigger */
244c16211d6SLiam Girdwood 	int (*pcm_trigger)(struct snd_sof_dev *sdev,
245c16211d6SLiam Girdwood 			   struct snd_pcm_substream *substream,
246c16211d6SLiam Girdwood 			   int cmd); /* optional */
247c16211d6SLiam Girdwood 
248c16211d6SLiam Girdwood 	/* host stream pointer */
2494a39ea3fSRanjani Sridharan 	snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
2504a39ea3fSRanjani Sridharan 					 struct snd_pcm_substream *substream); /* optional */
2514a39ea3fSRanjani Sridharan 
2527f956297SRander Wang 	/* pcm ack */
2537f956297SRander Wang 	int (*pcm_ack)(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream); /* optional */
2547f956297SRander Wang 
2557f956297SRander Wang 	/*
2567f956297SRander Wang 	 * optional callback to retrieve the link DMA position for the substream
2577f956297SRander Wang 	 * when the position is not reported in the shared SRAM windows but
2587f956297SRander Wang 	 * instead from a host-accessible hardware counter.
2597f956297SRander Wang 	 */
2607f956297SRander Wang 	u64 (*get_stream_position)(struct snd_sof_dev *sdev,
261c16211d6SLiam Girdwood 				   struct snd_soc_component *component,
2626a0ba071SGuennadi Liakhovetski 				   struct snd_pcm_substream *substream); /* optional */
2631b905942SDaniel Baluta 
264c16211d6SLiam Girdwood 	/* host read DSP stream data */
265c16211d6SLiam Girdwood 	int (*ipc_msg_data)(struct snd_sof_dev *sdev,
266757ce810SPeter Ujfalusi 			    struct snd_sof_pcm_stream *sps,
267757ce810SPeter Ujfalusi 			    void *p, size_t sz); /* mandatory */
268249f186dSDaniel Baluta 
269757ce810SPeter Ujfalusi 	/* host side configuration of the stream's data offset in stream mailbox area */
270757ce810SPeter Ujfalusi 	int (*set_stream_data_offset)(struct snd_sof_dev *sdev,
271c16211d6SLiam Girdwood 				      struct snd_sof_pcm_stream *sps,
272c16211d6SLiam Girdwood 				      size_t posn_offset); /* optional */
273c16211d6SLiam Girdwood 
274c16211d6SLiam Girdwood 	/* pre/post firmware run */
275e984f3efSFred Oh 	int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
276e984f3efSFred Oh 	int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
277e984f3efSFred Oh 
278e984f3efSFred Oh 	/* parse platform specific extended manifest, optional */
279c16211d6SLiam Girdwood 	int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev,
28061e285caSRanjani Sridharan 					   const struct sof_ext_man_elem_header *hdr);
28161e285caSRanjani Sridharan 
282c16211d6SLiam Girdwood 	/* DSP PM */
2831c38c922SFred Oh 	int (*suspend)(struct snd_sof_dev *sof_dev,
284c16211d6SLiam Girdwood 		       u32 target_state); /* optional */
28562fde977SKai Vehmanen 	int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
2867077a07aSRanjani Sridharan 	int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
287e8f112d8SKeyon Jie 	int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
28861e285caSRanjani Sridharan 	int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
289c16211d6SLiam Girdwood 	int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
290c16211d6SLiam Girdwood 	int (*set_power_state)(struct snd_sof_dev *sdev,
291c16211d6SLiam Girdwood 			       const struct sof_dsp_power_state *target_state); /* optional */
292c16211d6SLiam Girdwood 
293c16211d6SLiam Girdwood 	/* DSP clocking */
294c16211d6SLiam Girdwood 	int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
295c16211d6SLiam Girdwood 
296c16211d6SLiam Girdwood 	/* debug */
297c16211d6SLiam Girdwood 	const struct snd_sof_debugfs_map *debug_map; /* optional */
2985e4a27fdSPan Xiuli 	int debug_map_count; /* optional */
29907e833b4SPeter Ujfalusi 	void (*dbg_dump)(struct snd_sof_dev *sof_dev,
30007e833b4SPeter Ujfalusi 			 u32 flags); /* optional */
30107e833b4SPeter Ujfalusi 	void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
30207e833b4SPeter Ujfalusi 	int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
303c16211d6SLiam Girdwood 				       enum snd_sof_fw_blk_type blk_type, u32 offset,
3044b49cbd1SPeter Ujfalusi 				       size_t size, const char *name,
305c16211d6SLiam Girdwood 				       enum sof_debugfs_access_type access_type); /* optional */
3064b49cbd1SPeter Ujfalusi 
307bab05b50SPeter Ujfalusi 	/* host DMA trace (IPC3) */
308c16211d6SLiam Girdwood 	int (*trace_init)(struct snd_sof_dev *sdev,
309c16211d6SLiam Girdwood 			  struct snd_dma_buffer *dmatb,
310c16211d6SLiam Girdwood 			  struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */
311c16211d6SLiam Girdwood 	int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
312ce8234a6SDaniel Baluta 	int (*trace_trigger)(struct snd_sof_dev *sdev,
313ce8234a6SDaniel Baluta 			     int cmd); /* optional */
314ce8234a6SDaniel Baluta 
315bb9c93f5SDaniel Baluta 	/* misc */
316e17422cdSDaniel Baluta 	int (*get_bar_index)(struct snd_sof_dev *sdev,
317e17422cdSDaniel Baluta 			     u32 type); /* optional */
318bb9c93f5SDaniel Baluta 	int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
319285880a2SDaniel Baluta 	int (*get_window_offset)(struct snd_sof_dev *sdev,
320285880a2SDaniel Baluta 				 u32 id);/* mandatory for common loader code */
321285880a2SDaniel Baluta 
322285880a2SDaniel Baluta 	/* machine driver ops */
323285880a2SDaniel Baluta 	int (*machine_register)(struct snd_sof_dev *sdev,
324cb515f10SGuennadi Liakhovetski 				void *pdata); /* optional */
325cb515f10SGuennadi Liakhovetski 	void (*machine_unregister)(struct snd_sof_dev *sdev,
32617e9d6b0SPierre-Louis Bossart 				   void *pdata); /* optional */
327285880a2SDaniel Baluta 	struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */
3286955d951SPeter Ujfalusi 	void (*set_mach_params)(struct snd_soc_acpi_mach *mach,
3296955d951SPeter Ujfalusi 				struct snd_sof_dev *sdev); /* optional */
3306955d951SPeter Ujfalusi 
3316955d951SPeter Ujfalusi 	/* IPC client ops */
332c16211d6SLiam Girdwood 	int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
333c16211d6SLiam Girdwood 	void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
334c16211d6SLiam Girdwood 
33527e322faSPierre-Louis Bossart 	/* DAI ops */
33627e322faSPierre-Louis Bossart 	struct snd_soc_dai_driver *drv;
33727e322faSPierre-Louis Bossart 	int num_drv;
3380f501c7cSPierre-Louis Bossart 
3390ed66cb7SPeter Ujfalusi 	/* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
340c16211d6SLiam Girdwood 	u32 hw_info;
341c16211d6SLiam Girdwood 
342c16211d6SLiam Girdwood 	const struct dsp_arch_ops *dsp_arch_ops;
3430ed66cb7SPeter Ujfalusi };
344b9f0bfd1SPeter Ujfalusi 
345b9f0bfd1SPeter Ujfalusi /* DSP architecture specific callbacks for oops and stack dumps */
346c16211d6SLiam Girdwood struct dsp_arch_ops {
347c16211d6SLiam Girdwood 	void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops);
348c16211d6SLiam Girdwood 	void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops,
3490ed66cb7SPeter Ujfalusi 			  u32 *stack, u32 stack_words);
350c16211d6SLiam Girdwood };
351c16211d6SLiam Girdwood 
352c16211d6SLiam Girdwood #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
353c16211d6SLiam Girdwood 
3545b10b629SKarol Trzcinski /* FS entry for debug files that can expose DSP memories, registers */
355c16211d6SLiam Girdwood struct snd_sof_dfsentry {
356c16211d6SLiam Girdwood 	size_t size;
357c16211d6SLiam Girdwood 	size_t buf_data_size;  /* length of buffered data for file read operation */
358c16211d6SLiam Girdwood 	enum sof_dfsentry_type type;
359c16211d6SLiam Girdwood 	/*
360c16211d6SLiam Girdwood 	 * access_type specifies if the
361c16211d6SLiam Girdwood 	 * memory -> DSP resource (memory, register etc) is always accessible
3626e9548cdSRanjani Sridharan 	 * or if it is accessible only when the DSP is in D0.
363c16211d6SLiam Girdwood 	 */
364c16211d6SLiam Girdwood 	enum sof_debugfs_access_type access_type;
365c16211d6SLiam Girdwood #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
366c16211d6SLiam Girdwood 	char *cache_buf; /* buffer to cache the contents of debugfs memory */
367c16211d6SLiam Girdwood #endif
368c16211d6SLiam Girdwood 	struct snd_sof_dev *sdev;
369c16211d6SLiam Girdwood 	struct list_head list;  /* list in sdev dfsentry list */
370c16211d6SLiam Girdwood 	union {
371c16211d6SLiam Girdwood 		void __iomem *io_mem;
372c16211d6SLiam Girdwood 		void *buf;
373c16211d6SLiam Girdwood 	};
374c16211d6SLiam Girdwood };
375c16211d6SLiam Girdwood 
376c16211d6SLiam Girdwood /* Debug mapping for any DSP memory or registers that can used for debug */
377c16211d6SLiam Girdwood struct snd_sof_debugfs_map {
378c16211d6SLiam Girdwood 	const char *name;
379c16211d6SLiam Girdwood 	u32 bar;
380c16211d6SLiam Girdwood 	u32 offset;
381c16211d6SLiam Girdwood 	u32 size;
382c16211d6SLiam Girdwood 	/*
383c16211d6SLiam Girdwood 	 * access_type specifies if the memory is always accessible
384c16211d6SLiam Girdwood 	 * or if it is accessible only when the DSP is in D0.
385c16211d6SLiam Girdwood 	 */
386c16211d6SLiam Girdwood 	enum sof_debugfs_access_type access_type;
387c16211d6SLiam Girdwood };
388c16211d6SLiam Girdwood 
389c16211d6SLiam Girdwood /* mailbox descriptor, used for host <-> DSP IPC */
390c16211d6SLiam Girdwood struct snd_sof_mailbox {
391c16211d6SLiam Girdwood 	u32 offset;
392c16211d6SLiam Girdwood 	size_t size;
393c16211d6SLiam Girdwood };
394c16211d6SLiam Girdwood 
395c16211d6SLiam Girdwood /* IPC message descriptor for host <-> DSP IO */
396c16211d6SLiam Girdwood struct snd_sof_ipc_msg {
397c16211d6SLiam Girdwood 	/* message data */
398c16211d6SLiam Girdwood 	void *msg_data;
399c16211d6SLiam Girdwood 	void *reply_data;
400c16211d6SLiam Girdwood 	size_t msg_size;
40184c2dca3SPeter Ujfalusi 	size_t reply_size;
40284c2dca3SPeter Ujfalusi 	int reply_error;
40384c2dca3SPeter Ujfalusi 
404c16211d6SLiam Girdwood 	/* notification, firmware initiated messages */
405c16211d6SLiam Girdwood 	void *rx_data;
406c16211d6SLiam Girdwood 
407c16211d6SLiam Girdwood 	wait_queue_head_t waitq;
408657774acSRanjani Sridharan 	bool ipc_complete;
4090cfbaee2SPeter Ujfalusi };
4100cfbaee2SPeter Ujfalusi 
4110cfbaee2SPeter Ujfalusi /**
4120cfbaee2SPeter Ujfalusi  * struct sof_ipc_fw_tracing_ops - IPC-specific firmware tracing ops
4130cfbaee2SPeter Ujfalusi  * @init:	Function pointer for initialization of the tracing
4140cfbaee2SPeter Ujfalusi  * @free:	Optional function pointer for freeing of the tracing
4150cfbaee2SPeter Ujfalusi  * @fw_crashed:	Optional function pointer to notify the tracing of a firmware crash
4160cfbaee2SPeter Ujfalusi  * @suspend:	Function pointer for system/runtime suspend
4170cfbaee2SPeter Ujfalusi  * @resume:	Function pointer for system/runtime resume
4180cfbaee2SPeter Ujfalusi  */
4190cfbaee2SPeter Ujfalusi struct sof_ipc_fw_tracing_ops {
4200cfbaee2SPeter Ujfalusi 	int (*init)(struct snd_sof_dev *sdev);
4210cfbaee2SPeter Ujfalusi 	void (*free)(struct snd_sof_dev *sdev);
4220cfbaee2SPeter Ujfalusi 	void (*fw_crashed)(struct snd_sof_dev *sdev);
4230cfbaee2SPeter Ujfalusi 	void (*suspend)(struct snd_sof_dev *sdev, pm_message_t pm_state);
4240cfbaee2SPeter Ujfalusi 	int (*resume)(struct snd_sof_dev *sdev);
425657774acSRanjani Sridharan };
42603f69725SPeter Ujfalusi 
42703f69725SPeter Ujfalusi /**
428b41252d8SPeter Ujfalusi  * struct sof_ipc_pm_ops - IPC-specific PM ops
429167ca6a4SRander Wang  * @ctx_save:		Optional function pointer for context save
430657774acSRanjani Sridharan  * @ctx_restore:	Optional function pointer for context restore
431657774acSRanjani Sridharan  * @set_core_state:	Optional function pointer for turning on/off a DSP core
432657774acSRanjani Sridharan  * @set_pm_gate:	Optional function pointer for pm gate settings
433657774acSRanjani Sridharan  */
434b41252d8SPeter Ujfalusi struct sof_ipc_pm_ops {
435167ca6a4SRander Wang 	int (*ctx_save)(struct snd_sof_dev *sdev);
436657774acSRanjani Sridharan 	int (*ctx_restore)(struct snd_sof_dev *sdev);
437657774acSRanjani Sridharan 	int (*set_core_state)(struct snd_sof_dev *sdev, int core_idx, bool on);
43861bafd1cSPeter Ujfalusi 	int (*set_pm_gate)(struct snd_sof_dev *sdev, u32 flags);
43961bafd1cSPeter Ujfalusi };
44061bafd1cSPeter Ujfalusi 
44161bafd1cSPeter Ujfalusi /**
44261bafd1cSPeter Ujfalusi  * struct sof_ipc_fw_loader_ops - IPC/FW-specific loader ops
44361bafd1cSPeter Ujfalusi  * @validate:		Function pointer for validating the firmware image
44461bafd1cSPeter Ujfalusi  * @parse_ext_manifest:	Function pointer for parsing the manifest of the firmware
44561bafd1cSPeter Ujfalusi  * @load_fw_to_dsp:	Optional function pointer for loading the firmware to the
44661bafd1cSPeter Ujfalusi  *			DSP.
44761bafd1cSPeter Ujfalusi  *			The function implements generic, hardware independent way
44861bafd1cSPeter Ujfalusi  *			of loading the initial firmware and its modules (if any).
44961bafd1cSPeter Ujfalusi  */
45061bafd1cSPeter Ujfalusi struct sof_ipc_fw_loader_ops {
45161bafd1cSPeter Ujfalusi 	int (*validate)(struct snd_sof_dev *sdev);
45261bafd1cSPeter Ujfalusi 	size_t (*parse_ext_manifest)(struct snd_sof_dev *sdev);
453226abb75SRanjani Sridharan 	int (*load_fw_to_dsp)(struct snd_sof_dev *sdev);
454967885eeSRanjani Sridharan };
455226abb75SRanjani Sridharan 
456226abb75SRanjani Sridharan struct sof_ipc_tplg_ops;
457226abb75SRanjani Sridharan struct sof_ipc_pcm_ops;
458226abb75SRanjani Sridharan 
459657774acSRanjani Sridharan /**
460967885eeSRanjani Sridharan  * struct sof_ipc_ops - IPC-specific ops
46161bafd1cSPeter Ujfalusi  * @tplg:	Pointer to IPC-specific topology ops
4621cf79c34SPeter Ujfalusi  * @pm:		Pointer to PM ops
46325e77672SPeter Ujfalusi  * @pcm:	Pointer to PCM ops
464aa23b375SPeter Ujfalusi  * @fw_loader:	Pointer to Firmware Loader ops
465aa23b375SPeter Ujfalusi  * @fw_tracing:	Optional pointer to Firmware tracing ops
466cbb984b6SPeter Ujfalusi  *
467cbb984b6SPeter Ujfalusi  * @init:	Optional pointer for IPC related initialization
468aa23b375SPeter Ujfalusi  * @exit:	Optional pointer for IPC related cleanup
46925e77672SPeter Ujfalusi  * @post_fw_boot: Optional pointer to execute IPC related tasks after firmware
47025e77672SPeter Ujfalusi  *		boot.
47125e77672SPeter Ujfalusi  *
47225e77672SPeter Ujfalusi  * @tx_msg:	Function pointer for sending a 'short' IPC message
47325e77672SPeter Ujfalusi  * @set_get_data: Function pointer for set/get data ('large' IPC message). This
47425e77672SPeter Ujfalusi  *		function may split up the 'large' message and use the @tx_msg
47525e77672SPeter Ujfalusi  *		path to transfer individual chunks, or use other means to transfer
47625e77672SPeter Ujfalusi  *		the message.
47725e77672SPeter Ujfalusi  * @get_reply:	Function pointer for fetching the reply to
47825e77672SPeter Ujfalusi  *		sdev->ipc->msg.reply_data
47925e77672SPeter Ujfalusi  * @rx_msg:	Function pointer for handling a received message
48025e77672SPeter Ujfalusi  *
48125e77672SPeter Ujfalusi  * Note: both @tx_msg and @set_get_data considered as TX functions and they are
482226abb75SRanjani Sridharan  * serialized for the duration of the instructed transfer. A large message sent
483226abb75SRanjani Sridharan  * via @set_get_data is a single transfer even if at the hardware level it is
484226abb75SRanjani Sridharan  * handled with multiple chunks.
485657774acSRanjani Sridharan  */
486967885eeSRanjani Sridharan struct sof_ipc_ops {
48761bafd1cSPeter Ujfalusi 	const struct sof_ipc_tplg_ops *tplg;
4880cfbaee2SPeter Ujfalusi 	const struct sof_ipc_pm_ops *pm;
48925e77672SPeter Ujfalusi 	const struct sof_ipc_pcm_ops *pcm;
490aa23b375SPeter Ujfalusi 	const struct sof_ipc_fw_loader_ops *fw_loader;
491aa23b375SPeter Ujfalusi 	const struct sof_ipc_fw_tracing_ops *fw_tracing;
492cbb984b6SPeter Ujfalusi 
493aa23b375SPeter Ujfalusi 	int (*init)(struct snd_sof_dev *sdev);
49425e77672SPeter Ujfalusi 	void (*exit)(struct snd_sof_dev *sdev);
49525e77672SPeter Ujfalusi 	int (*post_fw_boot)(struct snd_sof_dev *sdev);
49625e77672SPeter Ujfalusi 
49725e77672SPeter Ujfalusi 	int (*tx_msg)(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
49825e77672SPeter Ujfalusi 		      void *reply_data, size_t reply_bytes, bool no_pm);
49925e77672SPeter Ujfalusi 	int (*set_get_data)(struct snd_sof_dev *sdev, void *data, size_t data_bytes,
500226abb75SRanjani Sridharan 			    bool set);
501226abb75SRanjani Sridharan 	int (*get_reply)(struct snd_sof_dev *sdev);
502f535880bSRander Wang 	void (*rx_msg)(struct snd_sof_dev *sdev);
503f535880bSRander Wang };
504f535880bSRander Wang 
505f535880bSRander Wang /* SOF generic IPC data */
506f535880bSRander Wang struct snd_sof_ipc {
507f535880bSRander Wang 	struct snd_sof_dev *sdev;
508f535880bSRander Wang 
509f535880bSRander Wang 	/* protects messages and the disable flag */
510f535880bSRander Wang 	struct mutex tx_mutex;
511a3e6b369SPeter Ujfalusi 	/* disables further sending of ipc's */
512a3e6b369SPeter Ujfalusi 	bool disable_ipc_tx;
513a3e6b369SPeter Ujfalusi 
514f535880bSRander Wang 	/* Maximum allowed size of a single IPC message/reply */
515226abb75SRanjani Sridharan 	size_t max_payload_size;
516226abb75SRanjani Sridharan 
517226abb75SRanjani Sridharan 	struct snd_sof_ipc_msg msg;
518f535880bSRander Wang 
519f535880bSRander Wang 	/* IPC ops based on version */
520caf0f466SPeter Ujfalusi 	const struct sof_ipc_ops *ops;
521caf0f466SPeter Ujfalusi };
522caf0f466SPeter Ujfalusi 
523caf0f466SPeter Ujfalusi /* Helper to retrieve the IPC ops */
524c16211d6SLiam Girdwood #define sof_ipc_get_ops(sdev, ops_name)		\
525c16211d6SLiam Girdwood 		(((sdev)->ipc && (sdev)->ipc->ops) ? (sdev)->ipc->ops->ops_name : NULL)
526c16211d6SLiam Girdwood 
527c16211d6SLiam Girdwood /*
528c16211d6SLiam Girdwood  * SOF Device Level.
529c16211d6SLiam Girdwood  */
530c16211d6SLiam Girdwood struct snd_sof_dev {
531c16211d6SLiam Girdwood 	struct device *dev;
53259611370SPeter Ujfalusi 	spinlock_t ipc_lock;	/* lock for IPC users */
53359611370SPeter Ujfalusi 	spinlock_t hw_lock;	/* lock for HW IO access */
53459611370SPeter Ujfalusi 
53559611370SPeter Ujfalusi 	/*
53659611370SPeter Ujfalusi 	 * When true the DSP is not used.
53759611370SPeter Ujfalusi 	 * It is set under the following condition:
53859611370SPeter Ujfalusi 	 * User sets the SOF_DBG_DSPLESS_MODE flag in sof_debug module parameter
53959611370SPeter Ujfalusi 	 * and
54059611370SPeter Ujfalusi 	 * the platform advertises that it can support such mode
54159611370SPeter Ujfalusi 	 * pdata->desc->dspless_mode_supported is true.
5424f373ccfSPeter Ujfalusi 	 */
5434f373ccfSPeter Ujfalusi 	bool dspless_mode_selected;
5444f373ccfSPeter Ujfalusi 
545c16211d6SLiam Girdwood 	/* Main, Base firmware image */
546c16211d6SLiam Girdwood 	struct sof_firmware basefw;
547c16211d6SLiam Girdwood 
548c16211d6SLiam Girdwood 	/*
549c16211d6SLiam Girdwood 	 * ASoC components. plat_drv fields are set dynamically so
550c16211d6SLiam Girdwood 	 * can't use const
55161e285caSRanjani Sridharan 	 */
55261e285caSRanjani Sridharan 	struct snd_soc_component_driver plat_drv;
5538b66d7c5SKeyon Jie 
5548b66d7c5SKeyon Jie 	/* current DSP power state */
555043ae13bSRanjani Sridharan 	struct sof_dsp_power_state dsp_power_state;
556043ae13bSRanjani Sridharan 	/* mutex to protect the dsp_power_state access */
557043ae13bSRanjani Sridharan 	struct mutex power_state_access;
5584c19030cSKeyon Jie 
559c16211d6SLiam Girdwood 	/* Intended power target of system suspend */
560c16211d6SLiam Girdwood 	enum sof_system_suspend_state system_suspend_target;
561d41607d3SPeter Ujfalusi 
562f738d815SGuennadi Liakhovetski 	/* DSP firmware boot */
563c16211d6SLiam Girdwood 	wait_queue_head_t boot_wait;
564c16211d6SLiam Girdwood 	enum sof_fw_state fw_state;
565c16211d6SLiam Girdwood 	bool first_boot;
566271d9373SKai Vehmanen 
567c16211d6SLiam Girdwood 	/* work queue in case the probe is implemented in two steps */
568c16211d6SLiam Girdwood 	struct work_struct probe_work;
569c16211d6SLiam Girdwood 	bool probe_completed;
570c16211d6SLiam Girdwood 
571c16211d6SLiam Girdwood 	/* DSP HW differentiation */
572c16211d6SLiam Girdwood 	struct snd_sof_pdata *pdata;
5734700bfb2SRander Wang 
574c16211d6SLiam Girdwood 	/* IPC */
575c16211d6SLiam Girdwood 	struct snd_sof_ipc *ipc;
576c16211d6SLiam Girdwood 	struct snd_sof_mailbox fw_info_box;	/* FW shared memory */
577e17b7389SIulian Olaru 	struct snd_sof_mailbox dsp_box;		/* DSP initiated IPC */
578c16211d6SLiam Girdwood 	struct snd_sof_mailbox host_box;	/* Host initiated IPC */
579c16211d6SLiam Girdwood 	struct snd_sof_mailbox stream_box;	/* Stream position update */
580c16211d6SLiam Girdwood 	struct snd_sof_mailbox debug_box;	/* Debug info updates */
581c16211d6SLiam Girdwood 	struct snd_sof_ipc_msg *msg;
582c16211d6SLiam Girdwood 	int ipc_irq;
583c16211d6SLiam Girdwood 	u32 next_comp_id; /* monotonic - reset during S3 */
584c16211d6SLiam Girdwood 
585c16211d6SLiam Girdwood 	/* memory bases for mmaped DSPs - set by dsp_init() */
586c16211d6SLiam Girdwood 	void __iomem *bar[SND_SOF_BARS];	/* DSP base address */
587c16211d6SLiam Girdwood 	int mmio_bar;
588c16211d6SLiam Girdwood 	int mailbox_bar;
589c16211d6SLiam Girdwood 	size_t dsp_oops_offset;
590c16211d6SLiam Girdwood 
5919ff90859SPeter Ujfalusi 	/* debug */
5929ff90859SPeter Ujfalusi 	struct dentry *debugfs_root;
593c16211d6SLiam Girdwood 	struct list_head dfsentry_list;
594c16211d6SLiam Girdwood 	bool dbg_dump_printed;
595c16211d6SLiam Girdwood 	bool ipc_dump_printed;
596c16211d6SLiam Girdwood 
59759283959SKarol Trzcinski 	/* firmware loader */
598c16211d6SLiam Girdwood 	struct sof_ipc_fw_ready fw_ready;
599c16211d6SLiam Girdwood 	struct sof_ipc_fw_version fw_version;
600c16211d6SLiam Girdwood 	struct sof_ipc_cc_version *cc_version;
601c16211d6SLiam Girdwood 
602c16211d6SLiam Girdwood 	/* topology */
603c16211d6SLiam Girdwood 	struct snd_soc_tplg_ops *tplg_ops;
6049c04363dSRanjani Sridharan 	struct list_head pcm_list;
605c16211d6SLiam Girdwood 	struct list_head kcontrol_list;
6060af0f463SRanjani Sridharan 	struct list_head widget_list;
607c16211d6SLiam Girdwood 	struct list_head pipeline_list;
608c16211d6SLiam Girdwood 	struct list_head dai_list;
609c16211d6SLiam Girdwood 	struct list_head dai_link_list;
6109b014266SJaroslav Kysela 	struct list_head route_list;
611c16211d6SLiam Girdwood 	struct snd_soc_component *component;
612c16211d6SLiam Girdwood 	u32 enabled_cores_mask; /* keep track of enabled cores */
613c16211d6SLiam Girdwood 	bool led_present;
614c16211d6SLiam Girdwood 
615c16211d6SLiam Girdwood 	/* FW configuration */
616c16211d6SLiam Girdwood 	struct sof_ipc_window *info_window;
617c16211d6SLiam Girdwood 
618c16211d6SLiam Girdwood 	/* IPC timeouts in ms */
61925b17da6SPeter Ujfalusi 	int ipc_timeout;
62025b17da6SPeter Ujfalusi 	int boot_timeout;
62108341b27SPeter Ujfalusi 
62225b17da6SPeter Ujfalusi 	/* firmwre tracing */
623672ff5e3SGuennadi Liakhovetski 	bool fw_trace_is_supported; /* set with Kconfig or module parameter */
624c16211d6SLiam Girdwood 	void *fw_trace_data; /* private data used by firmware tracing implementation */
6255974f684SRanjani Sridharan 
6265974f684SRanjani Sridharan 	bool msi_enabled;
6275974f684SRanjani Sridharan 
6285974f684SRanjani Sridharan 	/* DSP core context */
6295974f684SRanjani Sridharan 	u32 num_cores;
6305974f684SRanjani Sridharan 
6315974f684SRanjani Sridharan 	/*
6325974f684SRanjani Sridharan 	 * ref count per core that will be modified during system suspend/resume and during pcm
6335974f684SRanjani Sridharan 	 * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
6345974f684SRanjani Sridharan 	 * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
6355974f684SRanjani Sridharan 	 * sound/core/ when streams are active and during system suspend/resume, streams are
6365974f684SRanjani Sridharan 	 * already suspended.
6376955d951SPeter Ujfalusi 	 */
6386955d951SPeter Ujfalusi 	int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
6396955d951SPeter Ujfalusi 
6406955d951SPeter Ujfalusi 	/*
6416955d951SPeter Ujfalusi 	 * Used to keep track of registered IPC client devices so that they can
6426955d951SPeter Ujfalusi 	 * be removed when the parent SOF module is removed.
6436955d951SPeter Ujfalusi 	 */
6446955d951SPeter Ujfalusi 	struct list_head ipc_client_list;
6456955d951SPeter Ujfalusi 
6466955d951SPeter Ujfalusi 	/* mutex to protect client list */
6476955d951SPeter Ujfalusi 	struct mutex ipc_client_mutex;
6486955d951SPeter Ujfalusi 
6496955d951SPeter Ujfalusi 	/*
6506955d951SPeter Ujfalusi 	 * Used for tracking the IPC client's RX registration for DSP initiated
6516955d951SPeter Ujfalusi 	 * message handling.
6526955d951SPeter Ujfalusi 	 */
6536955d951SPeter Ujfalusi 	struct list_head ipc_rx_handler_list;
6546955d951SPeter Ujfalusi 
6556955d951SPeter Ujfalusi 	/*
6566955d951SPeter Ujfalusi 	 * Used for tracking the IPC client's registration for DSP state change
6576955d951SPeter Ujfalusi 	 * notification
6586955d951SPeter Ujfalusi 	 */
6596955d951SPeter Ujfalusi 	struct list_head fw_state_handler_list;
6606955d951SPeter Ujfalusi 
661d136949dSPierre-Louis Bossart 	/* to protect the ipc_rx_handler_list  and  dsp_state_handler_list list */
662d136949dSPierre-Louis Bossart 	struct mutex client_event_handler_mutex;
663d136949dSPierre-Louis Bossart 
664d136949dSPierre-Louis Bossart 	/* quirks to override topology values */
665c16211d6SLiam Girdwood 	bool mclk_id_override;
666c16211d6SLiam Girdwood 	u16  mclk_id_quirk; /* same size as in IPC3 definitions */
667c16211d6SLiam Girdwood 
668c16211d6SLiam Girdwood 	void *private;			/* core does not touch this */
669c16211d6SLiam Girdwood };
670c16211d6SLiam Girdwood 
671c16211d6SLiam Girdwood /*
672c16211d6SLiam Girdwood  * Device Level.
673c16211d6SLiam Girdwood  */
6747edb3051SKeyon Jie 
675271d9373SKai Vehmanen int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
676c16211d6SLiam Girdwood int snd_sof_device_remove(struct device *dev);
677c16211d6SLiam Girdwood int snd_sof_device_shutdown(struct device *dev);
678c16211d6SLiam Girdwood bool snd_sof_device_probe_completed(struct device *dev);
67962fde977SKai Vehmanen 
680c16211d6SLiam Girdwood int snd_sof_runtime_suspend(struct device *dev);
681c16211d6SLiam Girdwood int snd_sof_runtime_resume(struct device *dev);
6823541aef1SMarcin Rajwa int snd_sof_runtime_idle(struct device *dev);
6830b50b3b1SKeyon Jie int snd_sof_resume(struct device *dev);
6840b50b3b1SKeyon Jie int snd_sof_suspend(struct device *dev);
685c16211d6SLiam Girdwood int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
686c16211d6SLiam Girdwood int snd_sof_prepare(struct device *dev);
687c16211d6SLiam Girdwood void snd_sof_complete(struct device *dev);
688c16211d6SLiam Girdwood 
68929990588SPeter Ujfalusi void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
69029990588SPeter Ujfalusi 
69129990588SPeter Ujfalusi /*
69229990588SPeter Ujfalusi  * Compress support
69329990588SPeter Ujfalusi  */
694c16211d6SLiam Girdwood extern struct snd_compress_ops sof_compressed_ops;
695c16211d6SLiam Girdwood 
696c16211d6SLiam Girdwood /*
697c16211d6SLiam Girdwood  * Firmware loading.
698c16211d6SLiam Girdwood  */
699c16211d6SLiam Girdwood int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
700c16211d6SLiam Girdwood int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
701c16211d6SLiam Girdwood int snd_sof_run_firmware(struct snd_sof_dev *sdev);
702c16211d6SLiam Girdwood void snd_sof_fw_unload(struct snd_sof_dev *sdev);
703c16211d6SLiam Girdwood 
704c16211d6SLiam Girdwood /*
705c16211d6SLiam Girdwood  * IPC low level APIs.
7068ae77801SPeter Ujfalusi  */
707d7a1ed26SRanjani Sridharan struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
7082f1f5a43SPeter Ujfalusi void snd_sof_ipc_free(struct snd_sof_dev *sdev);
7092f1f5a43SPeter Ujfalusi void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
7102f1f5a43SPeter Ujfalusi void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
snd_sof_ipc_msgs_rx(struct snd_sof_dev * sdev)7112f1f5a43SPeter Ujfalusi static inline void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
7122a51c0f8SPeter Ujfalusi {
7132a51c0f8SPeter Ujfalusi 	sdev->ipc->ops->rx_msg(sdev);
714*ccb541a0SCurtis Malainey }
715*ccb541a0SCurtis Malainey int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
716*ccb541a0SCurtis Malainey 		       void *reply_data, size_t reply_bytes);
sof_ipc_tx_message_no_reply(struct snd_sof_ipc * ipc,void * msg_data,size_t msg_bytes)717*ccb541a0SCurtis Malainey static inline int sof_ipc_tx_message_no_reply(struct snd_sof_ipc *ipc, void *msg_data,
718*ccb541a0SCurtis Malainey 					      size_t msg_bytes)
719d8bc54a5SJyri Sarha {
720d8bc54a5SJyri Sarha 	return sof_ipc_tx_message(ipc, msg_data, msg_bytes, NULL, 0);
7212a51c0f8SPeter Ujfalusi }
72263e51fd3SRanjani Sridharan int sof_ipc_set_get_data(struct snd_sof_ipc *ipc, void *msg_data,
723*ccb541a0SCurtis Malainey 			 size_t msg_bytes, bool set);
724*ccb541a0SCurtis Malainey int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
725*ccb541a0SCurtis Malainey 			     void *reply_data, size_t reply_bytes);
sof_ipc_tx_message_no_pm_no_reply(struct snd_sof_ipc * ipc,void * msg_data,size_t msg_bytes)726*ccb541a0SCurtis Malainey static inline int sof_ipc_tx_message_no_pm_no_reply(struct snd_sof_ipc *ipc, void *msg_data,
727*ccb541a0SCurtis Malainey 						    size_t msg_bytes)
728b4dcafe4SPeter Ujfalusi {
729b4dcafe4SPeter Ujfalusi 	return sof_ipc_tx_message_no_pm(ipc, msg_data, msg_bytes, NULL, 0);
73019faf9eeSPeter Ujfalusi }
7318ae77801SPeter Ujfalusi int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
7328ae77801SPeter Ujfalusi 		     size_t reply_bytes);
7338ae77801SPeter Ujfalusi 
snd_sof_ipc_process_reply(struct snd_sof_dev * sdev,u32 msg_id)7348ae77801SPeter Ujfalusi static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
7358ae77801SPeter Ujfalusi {
736c16211d6SLiam Girdwood 	snd_sof_ipc_get_reply(sdev);
737c16211d6SLiam Girdwood 	snd_sof_ipc_reply(sdev, msg_id);
738c16211d6SLiam Girdwood }
739c16211d6SLiam Girdwood 
740c16211d6SLiam Girdwood /*
741c16211d6SLiam Girdwood  * Trace/debug
742c16211d6SLiam Girdwood  */
743c16211d6SLiam Girdwood int snd_sof_dbg_init(struct snd_sof_dev *sdev);
7445c9714f6SRanjani Sridharan void snd_sof_free_debug(struct snd_sof_dev *sdev);
7454995ffceSPeter Ujfalusi int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
7464995ffceSPeter Ujfalusi 			     void *base, size_t size,
747c16211d6SLiam Girdwood 			     const char *name, mode_t mode);
748c16211d6SLiam Girdwood void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
749145cb4e7SPeter Ujfalusi 			      u32 panic_code, u32 tracep_code, void *oops,
7505b10b629SKarol Trzcinski 			      struct sof_ipc_panic_info *panic_info,
75107e833b4SPeter Ujfalusi 			      void *stack, size_t stack_words);
75207e833b4SPeter Ujfalusi void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev, const char *msg);
75307e833b4SPeter Ujfalusi int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
7541dedbe4fSPeter Ujfalusi int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
7551dedbe4fSPeter Ujfalusi 		enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
7561dedbe4fSPeter Ujfalusi 		const char *name, enum sof_debugfs_access_type access_type);
7571dedbe4fSPeter Ujfalusi /* Firmware tracing */
7581dedbe4fSPeter Ujfalusi int sof_fw_trace_init(struct snd_sof_dev *sdev);
7591dedbe4fSPeter Ujfalusi void sof_fw_trace_free(struct snd_sof_dev *sdev);
760c16211d6SLiam Girdwood void sof_fw_trace_fw_crashed(struct snd_sof_dev *sdev);
761c16211d6SLiam Girdwood void sof_fw_trace_suspend(struct snd_sof_dev *sdev, pm_message_t pm_state);
762c16211d6SLiam Girdwood int sof_fw_trace_resume(struct snd_sof_dev *sdev);
763c16211d6SLiam Girdwood 
764b9f0bfd1SPeter Ujfalusi /*
765b9f0bfd1SPeter Ujfalusi  * DSP Architectures.
766c16211d6SLiam Girdwood  */
sof_stack(struct snd_sof_dev * sdev,const char * level,void * oops,u32 * stack,u32 stack_words)767b9f0bfd1SPeter Ujfalusi static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
768b9f0bfd1SPeter Ujfalusi 			     void *oops, u32 *stack, u32 stack_words)
769c16211d6SLiam Girdwood {
770c16211d6SLiam Girdwood 		sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level,  oops, stack,
771b9f0bfd1SPeter Ujfalusi 						  stack_words);
772c16211d6SLiam Girdwood }
7730ed66cb7SPeter Ujfalusi 
sof_oops(struct snd_sof_dev * sdev,const char * level,void * oops)774b9f0bfd1SPeter Ujfalusi static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
775c16211d6SLiam Girdwood {
776c16211d6SLiam Girdwood 	if (sof_dsp_arch_ops(sdev)->dsp_oops)
7770ed66cb7SPeter Ujfalusi 		sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops);
778c16211d6SLiam Girdwood }
779c16211d6SLiam Girdwood 
78058a5c9a4SPeter Ujfalusi extern const struct dsp_arch_ops sof_xtensa_arch_ops;
78158a5c9a4SPeter Ujfalusi 
7826955d951SPeter Ujfalusi /*
78358a5c9a4SPeter Ujfalusi  * Firmware state tracking
78458a5c9a4SPeter Ujfalusi  */
785c16211d6SLiam Girdwood void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
786c16211d6SLiam Girdwood 
787c16211d6SLiam Girdwood /*
788c16211d6SLiam Girdwood  * Utilities
789c16211d6SLiam Girdwood  */
790c16211d6SLiam Girdwood void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
791c16211d6SLiam Girdwood void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
792c16211d6SLiam Girdwood u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
793c16211d6SLiam Girdwood u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
794c16211d6SLiam Girdwood void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
7954624bb2fSPeter Ujfalusi 		       void *message, size_t bytes);
7964624bb2fSPeter Ujfalusi void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
7974624bb2fSPeter Ujfalusi 		      void *message, size_t bytes);
7984624bb2fSPeter Ujfalusi int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
799c16211d6SLiam Girdwood 		    u32 offset, void *src, size_t size);
80097e22cbdSBud Liviu-Alexandru int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
8011b905942SDaniel Baluta 		   u32 offset, void *dest, size_t size);
802c16211d6SLiam Girdwood 
8039a0a809aSPeter Ujfalusi int sof_ipc_msg_data(struct snd_sof_dev *sdev,
804249f186dSDaniel Baluta 		     struct snd_sof_pcm_stream *sps,
8059a0a809aSPeter Ujfalusi 		     void *p, size_t sz);
806c16211d6SLiam Girdwood int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
80797e22cbdSBud Liviu-Alexandru 			       struct snd_sof_pcm_stream *sps,
808c16211d6SLiam Girdwood 			       size_t posn_offset);
80997e22cbdSBud Liviu-Alexandru 
810c16211d6SLiam Girdwood int sof_stream_pcm_open(struct snd_sof_dev *sdev,
811c16211d6SLiam Girdwood 			struct snd_pcm_substream *substream);
812285880a2SDaniel Baluta int sof_stream_pcm_close(struct snd_sof_dev *sdev,
8136955d951SPeter Ujfalusi 			 struct snd_pcm_substream *substream);
8146955d951SPeter Ujfalusi 
8156955d951SPeter Ujfalusi int sof_machine_check(struct snd_sof_dev *sdev);
8166955d951SPeter Ujfalusi 
8176955d951SPeter Ujfalusi /* SOF client support */
8186955d951SPeter Ujfalusi #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
8196955d951SPeter Ujfalusi int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
8206955d951SPeter Ujfalusi 			    const void *data, size_t size);
8216955d951SPeter Ujfalusi void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
8226955d951SPeter Ujfalusi int sof_register_clients(struct snd_sof_dev *sdev);
8231069967aSPeter Ujfalusi void sof_unregister_clients(struct snd_sof_dev *sdev);
8241069967aSPeter Ujfalusi void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
8256955d951SPeter Ujfalusi void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
8266955d951SPeter Ujfalusi int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
8276955d951SPeter Ujfalusi int sof_resume_clients(struct snd_sof_dev *sdev);
8286955d951SPeter Ujfalusi #else /* CONFIG_SND_SOC_SOF_CLIENT */
sof_client_dev_register(struct snd_sof_dev * sdev,const char * name,u32 id,const void * data,size_t size)8296955d951SPeter Ujfalusi static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
8306955d951SPeter Ujfalusi 					  u32 id, const void *data, size_t size)
8316955d951SPeter Ujfalusi {
8326955d951SPeter Ujfalusi 	return 0;
8336955d951SPeter Ujfalusi }
8346955d951SPeter Ujfalusi 
sof_client_dev_unregister(struct snd_sof_dev * sdev,const char * name,u32 id)8356955d951SPeter Ujfalusi static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
8366955d951SPeter Ujfalusi 					     const char *name, u32 id)
8376955d951SPeter Ujfalusi {
8386955d951SPeter Ujfalusi }
8396955d951SPeter Ujfalusi 
sof_register_clients(struct snd_sof_dev * sdev)8406955d951SPeter Ujfalusi static inline int sof_register_clients(struct snd_sof_dev *sdev)
8416955d951SPeter Ujfalusi {
8426955d951SPeter Ujfalusi 	return 0;
8436955d951SPeter Ujfalusi }
8446955d951SPeter Ujfalusi 
sof_unregister_clients(struct snd_sof_dev * sdev)8456955d951SPeter Ujfalusi static inline  void sof_unregister_clients(struct snd_sof_dev *sdev)
8466955d951SPeter Ujfalusi {
8476955d951SPeter Ujfalusi }
8486955d951SPeter Ujfalusi 
sof_client_ipc_rx_dispatcher(struct snd_sof_dev * sdev,void * msg_buf)8496955d951SPeter Ujfalusi static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
8506955d951SPeter Ujfalusi {
8516955d951SPeter Ujfalusi }
8526955d951SPeter Ujfalusi 
sof_client_fw_state_dispatcher(struct snd_sof_dev * sdev)8531069967aSPeter Ujfalusi static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
8541069967aSPeter Ujfalusi {
8551069967aSPeter Ujfalusi }
8561069967aSPeter Ujfalusi 
sof_suspend_clients(struct snd_sof_dev * sdev,pm_message_t state)8571069967aSPeter Ujfalusi static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
8581069967aSPeter Ujfalusi {
8591069967aSPeter Ujfalusi 	return 0;
8601069967aSPeter Ujfalusi }
8611069967aSPeter Ujfalusi 
sof_resume_clients(struct snd_sof_dev * sdev)8621069967aSPeter Ujfalusi static inline int sof_resume_clients(struct snd_sof_dev *sdev)
8636955d951SPeter Ujfalusi {
8646955d951SPeter Ujfalusi 	return 0;
865f80beaf6SPeter Ujfalusi }
866f80beaf6SPeter Ujfalusi #endif /* CONFIG_SND_SOC_SOF_CLIENT */
867ceb89accSPeter Ujfalusi 
868f80beaf6SPeter Ujfalusi /* Main ops for IPC implementations */
869c16211d6SLiam Girdwood extern const struct sof_ipc_ops ipc3_ops;
870 extern const struct sof_ipc_ops ipc4_ops;
871 
872 #endif
873