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 *
6293ad281SPierre-Louis Bossart * Copyright(c) 2018 Intel Corporation
7c16211d6SLiam Girdwood *
8c16211d6SLiam Girdwood * Author: Liam Girdwood <[email protected]>
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 */
51d498a3bdSPeter Ujfalusi #define SOF_DBG_DUMP_IPC_MESSAGE_PAYLOAD BIT(11) /* On top of the IPC message header
52d498a3bdSPeter Ujfalusi * dump the message payload also
53d498a3bdSPeter Ujfalusi */
5459611370SPeter Ujfalusi #define SOF_DBG_DSPLESS_MODE BIT(15) /* Do not initialize and use the DSP */
55fbfa22ecSRanjani Sridharan
56beb6ade1SPeter Ujfalusi /* Flag definitions used for controlling the DSP dump behavior */
57fbfa22ecSRanjani Sridharan #define SOF_DBG_DUMP_REGS BIT(0)
58fbfa22ecSRanjani Sridharan #define SOF_DBG_DUMP_MBOX BIT(1)
59fbfa22ecSRanjani Sridharan #define SOF_DBG_DUMP_TEXT BIT(2)
60fbfa22ecSRanjani Sridharan #define SOF_DBG_DUMP_PCI BIT(3)
61beb6ade1SPeter Ujfalusi /* Output this dump (at the DEBUG level) only when SOF_DBG_PRINT_ALL_DUMPS is set */
62beb6ade1SPeter Ujfalusi #define SOF_DBG_DUMP_OPTIONAL BIT(4)
63c16211d6SLiam Girdwood
642ab4c50fSPierre-Louis Bossart /* global debug state set by SOF_DBG_ flags */
65f902b21aSPeter Ujfalusi bool sof_debug_check_flag(int mask);
662ab4c50fSPierre-Louis Bossart
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
790dcdf842SGuennadi Liakhovetski /* So far the primary core on all DSPs has ID 0 */
800dcdf842SGuennadi Liakhovetski #define SOF_DSP_PRIMARY_CORE 0
810dcdf842SGuennadi Liakhovetski
825974f684SRanjani Sridharan /* max number of DSP cores */
835974f684SRanjani Sridharan #define SOF_MAX_DSP_NUM_CORES 8
845974f684SRanjani Sridharan
8561e285caSRanjani Sridharan struct sof_dsp_power_state {
8661e285caSRanjani Sridharan u32 state;
8761e285caSRanjani Sridharan u32 substate; /* platform-specific */
884c19030cSKeyon Jie };
894c19030cSKeyon Jie
90043ae13bSRanjani Sridharan /* System suspend target state */
91043ae13bSRanjani Sridharan enum sof_system_suspend_state {
92043ae13bSRanjani Sridharan SOF_SUSPEND_NONE = 0,
93043ae13bSRanjani Sridharan SOF_SUSPEND_S0IX,
94043ae13bSRanjani Sridharan SOF_SUSPEND_S3,
957a5974e0SPierre-Louis Bossart SOF_SUSPEND_S4,
967a5974e0SPierre-Louis Bossart SOF_SUSPEND_S5,
97043ae13bSRanjani Sridharan };
98043ae13bSRanjani Sridharan
9907e833b4SPeter Ujfalusi enum sof_dfsentry_type {
10007e833b4SPeter Ujfalusi SOF_DFSENTRY_TYPE_IOMEM = 0,
10107e833b4SPeter Ujfalusi SOF_DFSENTRY_TYPE_BUF,
10207e833b4SPeter Ujfalusi };
10307e833b4SPeter Ujfalusi
10407e833b4SPeter Ujfalusi enum sof_debugfs_access_type {
10507e833b4SPeter Ujfalusi SOF_DEBUGFS_ACCESS_ALWAYS = 0,
10607e833b4SPeter Ujfalusi SOF_DEBUGFS_ACCESS_D0_ONLY,
10707e833b4SPeter Ujfalusi };
10807e833b4SPeter Ujfalusi
109e3091f0aSDaniel Baluta struct sof_compr_stream {
110e3091f0aSDaniel Baluta u64 copied_total;
111e3091f0aSDaniel Baluta u32 sampling_rate;
1123ccbe688SLaurentiu Mihalcea u16 channels;
1133ccbe688SLaurentiu Mihalcea u16 sample_container_bytes;
114090349a9SDaniel Baluta size_t posn_offset;
115e3091f0aSDaniel Baluta };
116e3091f0aSDaniel Baluta
117c16211d6SLiam Girdwood struct snd_sof_dev;
118c16211d6SLiam Girdwood struct snd_sof_ipc_msg;
119c16211d6SLiam Girdwood struct snd_sof_ipc;
120c16211d6SLiam Girdwood struct snd_sof_debugfs_map;
121c16211d6SLiam Girdwood struct snd_soc_tplg_ops;
122c16211d6SLiam Girdwood struct snd_soc_component;
123c16211d6SLiam Girdwood struct snd_sof_pdata;
124c16211d6SLiam Girdwood
12531f60a0cSPeter Ujfalusi /**
12631f60a0cSPeter Ujfalusi * struct snd_sof_platform_stream_params - platform dependent stream parameters
12731f60a0cSPeter Ujfalusi * @phy_addr: Platform dependent address to be used, if @use_phy_addr
12831f60a0cSPeter Ujfalusi * is true
129cac88e96SPierre-Louis Bossart * @stream_tag: Stream tag to use
130cac88e96SPierre-Louis Bossart * @use_phy_addr: Use the provided @phy_addr for configuration
13131f60a0cSPeter Ujfalusi * @no_ipc_position: Disable position update IPC from firmware
132cac88e96SPierre-Louis Bossart * @cont_update_posn: Continuous position update.
13331f60a0cSPeter Ujfalusi */
13431f60a0cSPeter Ujfalusi struct snd_sof_platform_stream_params {
135cac88e96SPierre-Louis Bossart u32 phy_addr;
13631f60a0cSPeter Ujfalusi u16 stream_tag;
13731f60a0cSPeter Ujfalusi bool use_phy_address;
13831f60a0cSPeter Ujfalusi bool no_ipc_position;
139d95610a1SYC Hung bool cont_update_posn;
14031f60a0cSPeter Ujfalusi };
14131f60a0cSPeter Ujfalusi
1424f373ccfSPeter Ujfalusi /**
1434f373ccfSPeter Ujfalusi * struct sof_firmware - Container struct for SOF firmware
1444f373ccfSPeter Ujfalusi * @fw: Pointer to the firmware
1454f373ccfSPeter Ujfalusi * @payload_offset: Offset of the data within the loaded firmware image to be
1464f373ccfSPeter Ujfalusi * loaded to the DSP (skipping for example ext_manifest section)
1474f373ccfSPeter Ujfalusi */
1484f373ccfSPeter Ujfalusi struct sof_firmware {
1494f373ccfSPeter Ujfalusi const struct firmware *fw;
1504f373ccfSPeter Ujfalusi u32 payload_offset;
1514f373ccfSPeter Ujfalusi };
1524f373ccfSPeter Ujfalusi
153d69f9ecbSPierre-Louis Bossart enum sof_dai_access {
154d69f9ecbSPierre-Louis Bossart SOF_DAI_DSP_ACCESS, /* access from DSP only */
155d69f9ecbSPierre-Louis Bossart SOF_DAI_HOST_ACCESS, /* access from host only */
156d69f9ecbSPierre-Louis Bossart
157d69f9ecbSPierre-Louis Bossart SOF_DAI_ACCESS_NUM
158d69f9ecbSPierre-Louis Bossart };
159d69f9ecbSPierre-Louis Bossart
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).
164c16211d6SLiam Girdwood */
165c16211d6SLiam Girdwood struct snd_sof_dsp_ops {
166c16211d6SLiam Girdwood
1677edb3051SKeyon Jie /* probe/remove/shutdown */
16817baaa1fSPierre-Louis Bossart int (*probe_early)(struct snd_sof_dev *sof_dev); /* optional */
169c16211d6SLiam Girdwood int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
170e4d09de3SPierre-Louis Bossart void (*remove)(struct snd_sof_dev *sof_dev); /* optional */
171264aeb99STakashi Iwai void (*remove_late)(struct snd_sof_dev *sof_dev); /* optional */
1727edb3051SKeyon Jie int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */
173c16211d6SLiam Girdwood
174c16211d6SLiam Girdwood /* DSP core boot / reset */
175c16211d6SLiam Girdwood int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */
176a70eb708SFred Oh int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */
177c16211d6SLiam Girdwood int (*reset)(struct snd_sof_dev *sof_dev); /* optional */
178c414d5dfSRanjani Sridharan int (*core_get)(struct snd_sof_dev *sof_dev, int core); /* optional */
179c414d5dfSRanjani Sridharan int (*core_put)(struct snd_sof_dev *sof_dev, int core); /* optional */
180c16211d6SLiam Girdwood
181c16211d6SLiam Girdwood /*
182c16211d6SLiam Girdwood * Register IO: only used by respective drivers themselves,
183c16211d6SLiam Girdwood * TODO: consider removing these operations and calling respective
184c16211d6SLiam Girdwood * implementations directly
185c16211d6SLiam Girdwood */
186f8fbf0dcSPierre-Louis Bossart void (*write8)(struct snd_sof_dev *sof_dev, void __iomem *addr,
18774fe0c4dSPierre-Louis Bossart u8 value); /* optional */
188f8fbf0dcSPierre-Louis Bossart u8 (*read8)(struct snd_sof_dev *sof_dev,
18974fe0c4dSPierre-Louis Bossart void __iomem *addr); /* optional */
190c16211d6SLiam Girdwood void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
191c16211d6SLiam Girdwood u32 value); /* optional */
192c16211d6SLiam Girdwood u32 (*read)(struct snd_sof_dev *sof_dev,
193c16211d6SLiam Girdwood void __iomem *addr); /* optional */
194c16211d6SLiam Girdwood void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
195c16211d6SLiam Girdwood u64 value); /* optional */
196c16211d6SLiam Girdwood u64 (*read64)(struct snd_sof_dev *sof_dev,
197c16211d6SLiam Girdwood void __iomem *addr); /* optional */
198c16211d6SLiam Girdwood
199c16211d6SLiam Girdwood /* memcpy IO */
2004624bb2fSPeter Ujfalusi int (*block_read)(struct snd_sof_dev *sof_dev,
2014624bb2fSPeter Ujfalusi enum snd_sof_fw_blk_type type, u32 offset,
2024624bb2fSPeter Ujfalusi void *dest, size_t size); /* mandatory */
2034624bb2fSPeter Ujfalusi int (*block_write)(struct snd_sof_dev *sof_dev,
2044624bb2fSPeter Ujfalusi enum snd_sof_fw_blk_type type, u32 offset,
2054624bb2fSPeter Ujfalusi void *src, size_t size); /* mandatory */
206c16211d6SLiam Girdwood
207f71f59ddSDaniel Baluta /* Mailbox IO */
208f71f59ddSDaniel Baluta void (*mailbox_read)(struct snd_sof_dev *sof_dev,
209f71f59ddSDaniel Baluta u32 offset, void *dest,
210f71f59ddSDaniel Baluta size_t size); /* optional */
211f71f59ddSDaniel Baluta void (*mailbox_write)(struct snd_sof_dev *sof_dev,
212f71f59ddSDaniel Baluta u32 offset, void *src,
213f71f59ddSDaniel Baluta size_t size); /* optional */
214f71f59ddSDaniel Baluta
215c16211d6SLiam Girdwood /* doorbell */
216c16211d6SLiam Girdwood irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
217c16211d6SLiam Girdwood irqreturn_t (*irq_thread)(int irq, void *context); /* optional */
218c16211d6SLiam Girdwood
219c16211d6SLiam Girdwood /* ipc */
220c16211d6SLiam Girdwood int (*send_msg)(struct snd_sof_dev *sof_dev,
221c16211d6SLiam Girdwood struct snd_sof_ipc_msg *msg); /* mandatory */
222c16211d6SLiam Girdwood
223c16211d6SLiam Girdwood /* FW loading */
224c16211d6SLiam Girdwood int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
225c16211d6SLiam Girdwood int (*load_module)(struct snd_sof_dev *sof_dev,
226c16211d6SLiam Girdwood struct snd_sof_mod_hdr *hdr); /* optional */
227c16211d6SLiam Girdwood
228c16211d6SLiam Girdwood /* connect pcm substream to a host stream */
229c16211d6SLiam Girdwood int (*pcm_open)(struct snd_sof_dev *sdev,
230c16211d6SLiam Girdwood struct snd_pcm_substream *substream); /* optional */
231c16211d6SLiam Girdwood /* disconnect pcm substream to a host stream */
232c16211d6SLiam Girdwood int (*pcm_close)(struct snd_sof_dev *sdev,
233c16211d6SLiam Girdwood struct snd_pcm_substream *substream); /* optional */
234c16211d6SLiam Girdwood
235c16211d6SLiam Girdwood /* host stream hw params */
236c16211d6SLiam Girdwood int (*pcm_hw_params)(struct snd_sof_dev *sdev,
237c16211d6SLiam Girdwood struct snd_pcm_substream *substream,
238c16211d6SLiam Girdwood struct snd_pcm_hw_params *params,
23931f60a0cSPeter Ujfalusi struct snd_sof_platform_stream_params *platform_params); /* optional */
240c16211d6SLiam Girdwood
24193146bc2SRanjani Sridharan /* host stream hw_free */
24293146bc2SRanjani Sridharan int (*pcm_hw_free)(struct snd_sof_dev *sdev,
24393146bc2SRanjani Sridharan struct snd_pcm_substream *substream); /* optional */
24493146bc2SRanjani Sridharan
245c16211d6SLiam Girdwood /* host stream trigger */
246c16211d6SLiam Girdwood int (*pcm_trigger)(struct snd_sof_dev *sdev,
247c16211d6SLiam Girdwood struct snd_pcm_substream *substream,
248c16211d6SLiam Girdwood int cmd); /* optional */
249c16211d6SLiam Girdwood
250c16211d6SLiam Girdwood /* host stream pointer */
251c16211d6SLiam Girdwood snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
252c16211d6SLiam Girdwood struct snd_pcm_substream *substream); /* optional */
253c16211d6SLiam Girdwood
2544a39ea3fSRanjani Sridharan /* pcm ack */
2554a39ea3fSRanjani Sridharan int (*pcm_ack)(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream); /* optional */
2564a39ea3fSRanjani Sridharan
2577f956297SRander Wang /*
258ce2faa9aSPeter Ujfalusi * optional callback to retrieve the number of frames left/arrived from/to
259ce2faa9aSPeter Ujfalusi * the DSP on the DAI side (link/codec/DMIC/etc).
260ce2faa9aSPeter Ujfalusi *
261ce2faa9aSPeter Ujfalusi * The callback is used when the firmware does not provide this information
262ce2faa9aSPeter Ujfalusi * via the shared SRAM window and it can be retrieved by host.
263ce2faa9aSPeter Ujfalusi */
264ce2faa9aSPeter Ujfalusi u64 (*get_dai_frame_counter)(struct snd_sof_dev *sdev,
265ce2faa9aSPeter Ujfalusi struct snd_soc_component *component,
266ce2faa9aSPeter Ujfalusi struct snd_pcm_substream *substream); /* optional */
267ce2faa9aSPeter Ujfalusi
268ce2faa9aSPeter Ujfalusi /*
269ce2faa9aSPeter Ujfalusi * Optional callback to retrieve the number of bytes left/arrived from/to
270ce2faa9aSPeter Ujfalusi * the DSP on the host side (bytes between host ALSA buffer and DSP).
271ce2faa9aSPeter Ujfalusi *
272ce2faa9aSPeter Ujfalusi * The callback is needed for ALSA delay reporting.
273ce2faa9aSPeter Ujfalusi */
274ce2faa9aSPeter Ujfalusi u64 (*get_host_byte_counter)(struct snd_sof_dev *sdev,
275ce2faa9aSPeter Ujfalusi struct snd_soc_component *component,
276ce2faa9aSPeter Ujfalusi struct snd_pcm_substream *substream); /* optional */
277ce2faa9aSPeter Ujfalusi
278c16211d6SLiam Girdwood /* host read DSP stream data */
2796a0ba071SGuennadi Liakhovetski int (*ipc_msg_data)(struct snd_sof_dev *sdev,
2801b905942SDaniel Baluta struct snd_sof_pcm_stream *sps,
281c16211d6SLiam Girdwood void *p, size_t sz); /* mandatory */
282c16211d6SLiam Girdwood
283757ce810SPeter Ujfalusi /* host side configuration of the stream's data offset in stream mailbox area */
284757ce810SPeter Ujfalusi int (*set_stream_data_offset)(struct snd_sof_dev *sdev,
285249f186dSDaniel Baluta struct snd_sof_pcm_stream *sps,
286757ce810SPeter Ujfalusi size_t posn_offset); /* optional */
287757ce810SPeter Ujfalusi
288c16211d6SLiam Girdwood /* pre/post firmware run */
289c16211d6SLiam Girdwood int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
290c16211d6SLiam Girdwood int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
291c16211d6SLiam Girdwood
292e984f3efSFred Oh /* parse platform specific extended manifest, optional */
293e984f3efSFred Oh int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev,
294e984f3efSFred Oh const struct sof_ext_man_elem_header *hdr);
295e984f3efSFred Oh
296c16211d6SLiam Girdwood /* DSP PM */
29761e285caSRanjani Sridharan int (*suspend)(struct snd_sof_dev *sof_dev,
29861e285caSRanjani Sridharan u32 target_state); /* optional */
299c16211d6SLiam Girdwood int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
3001c38c922SFred Oh int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
301c16211d6SLiam Girdwood int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
30262fde977SKai Vehmanen int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
3037077a07aSRanjani Sridharan int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
304e8f112d8SKeyon Jie int (*set_power_state)(struct snd_sof_dev *sdev,
30561e285caSRanjani Sridharan const struct sof_dsp_power_state *target_state); /* optional */
306c16211d6SLiam Girdwood
307c16211d6SLiam Girdwood /* DSP clocking */
308c16211d6SLiam Girdwood int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
309c16211d6SLiam Girdwood
310c16211d6SLiam Girdwood /* debug */
311c16211d6SLiam Girdwood const struct snd_sof_debugfs_map *debug_map; /* optional */
312c16211d6SLiam Girdwood int debug_map_count; /* optional */
313c16211d6SLiam Girdwood void (*dbg_dump)(struct snd_sof_dev *sof_dev,
314c16211d6SLiam Girdwood u32 flags); /* optional */
3155e4a27fdSPan Xiuli void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
31607e833b4SPeter Ujfalusi int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
31707e833b4SPeter Ujfalusi enum snd_sof_fw_blk_type blk_type, u32 offset,
31807e833b4SPeter Ujfalusi size_t size, const char *name,
31907e833b4SPeter Ujfalusi enum sof_debugfs_access_type access_type); /* optional */
320c16211d6SLiam Girdwood
3214b49cbd1SPeter Ujfalusi /* host DMA trace (IPC3) */
322c16211d6SLiam Girdwood int (*trace_init)(struct snd_sof_dev *sdev,
3234b49cbd1SPeter Ujfalusi struct snd_dma_buffer *dmatb,
324bab05b50SPeter Ujfalusi struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */
325c16211d6SLiam Girdwood int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
326c16211d6SLiam Girdwood int (*trace_trigger)(struct snd_sof_dev *sdev,
327c16211d6SLiam Girdwood int cmd); /* optional */
328c16211d6SLiam Girdwood
329ce8234a6SDaniel Baluta /* misc */
330ce8234a6SDaniel Baluta int (*get_bar_index)(struct snd_sof_dev *sdev,
331ce8234a6SDaniel Baluta u32 type); /* optional */
332bb9c93f5SDaniel Baluta int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
333e17422cdSDaniel Baluta int (*get_window_offset)(struct snd_sof_dev *sdev,
334e17422cdSDaniel Baluta u32 id);/* mandatory for common loader code */
335bb9c93f5SDaniel Baluta
336285880a2SDaniel Baluta /* machine driver ops */
337285880a2SDaniel Baluta int (*machine_register)(struct snd_sof_dev *sdev,
338285880a2SDaniel Baluta void *pdata); /* optional */
339285880a2SDaniel Baluta void (*machine_unregister)(struct snd_sof_dev *sdev,
340285880a2SDaniel Baluta void *pdata); /* optional */
341cb515f10SGuennadi Liakhovetski struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */
342cb515f10SGuennadi Liakhovetski void (*set_mach_params)(struct snd_soc_acpi_mach *mach,
34317e9d6b0SPierre-Louis Bossart struct snd_sof_dev *sdev); /* optional */
344285880a2SDaniel Baluta
3456955d951SPeter Ujfalusi /* IPC client ops */
3466955d951SPeter Ujfalusi int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
3476955d951SPeter Ujfalusi void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
3486955d951SPeter Ujfalusi
349c16211d6SLiam Girdwood /* DAI ops */
350c16211d6SLiam Girdwood struct snd_soc_dai_driver *drv;
351c16211d6SLiam Girdwood int num_drv;
35227e322faSPierre-Louis Bossart
353ba91d091SPierre-Louis Bossart bool (*is_chain_dma_supported)(struct snd_sof_dev *sdev, u32 dai_type); /* optional */
354ba91d091SPierre-Louis Bossart
35527e322faSPierre-Louis Bossart /* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
35627e322faSPierre-Louis Bossart u32 hw_info;
3570f501c7cSPierre-Louis Bossart
3580ed66cb7SPeter Ujfalusi const struct dsp_arch_ops *dsp_arch_ops;
359c16211d6SLiam Girdwood };
360c16211d6SLiam Girdwood
361c16211d6SLiam Girdwood /* DSP architecture specific callbacks for oops and stack dumps */
3620ed66cb7SPeter Ujfalusi struct dsp_arch_ops {
363b9f0bfd1SPeter Ujfalusi void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops);
364b9f0bfd1SPeter Ujfalusi void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops,
365c16211d6SLiam Girdwood u32 *stack, u32 stack_words);
366c16211d6SLiam Girdwood };
367c16211d6SLiam Girdwood
3680ed66cb7SPeter Ujfalusi #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
369c16211d6SLiam Girdwood
370c16211d6SLiam Girdwood /* FS entry for debug files that can expose DSP memories, registers */
371c16211d6SLiam Girdwood struct snd_sof_dfsentry {
372c16211d6SLiam Girdwood size_t size;
3735b10b629SKarol Trzcinski size_t buf_data_size; /* length of buffered data for file read operation */
374c16211d6SLiam Girdwood enum sof_dfsentry_type type;
375c16211d6SLiam Girdwood /*
376c16211d6SLiam Girdwood * access_type specifies if the
377c16211d6SLiam Girdwood * memory -> DSP resource (memory, register etc) is always accessible
378c16211d6SLiam Girdwood * or if it is accessible only when the DSP is in D0.
379c16211d6SLiam Girdwood */
380c16211d6SLiam Girdwood enum sof_debugfs_access_type access_type;
3816e9548cdSRanjani Sridharan #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
382c16211d6SLiam Girdwood char *cache_buf; /* buffer to cache the contents of debugfs memory */
383c16211d6SLiam Girdwood #endif
384c16211d6SLiam Girdwood struct snd_sof_dev *sdev;
385c16211d6SLiam Girdwood struct list_head list; /* list in sdev dfsentry list */
386c16211d6SLiam Girdwood union {
387c16211d6SLiam Girdwood void __iomem *io_mem;
388c16211d6SLiam Girdwood void *buf;
389c16211d6SLiam Girdwood };
390c16211d6SLiam Girdwood };
391c16211d6SLiam Girdwood
392c16211d6SLiam Girdwood /* Debug mapping for any DSP memory or registers that can used for debug */
393c16211d6SLiam Girdwood struct snd_sof_debugfs_map {
394c16211d6SLiam Girdwood const char *name;
395c16211d6SLiam Girdwood u32 bar;
396c16211d6SLiam Girdwood u32 offset;
397c16211d6SLiam Girdwood u32 size;
398c16211d6SLiam Girdwood /*
399c16211d6SLiam Girdwood * access_type specifies if the memory is always accessible
400c16211d6SLiam Girdwood * or if it is accessible only when the DSP is in D0.
401c16211d6SLiam Girdwood */
402c16211d6SLiam Girdwood enum sof_debugfs_access_type access_type;
403c16211d6SLiam Girdwood };
404c16211d6SLiam Girdwood
405c16211d6SLiam Girdwood /* mailbox descriptor, used for host <-> DSP IPC */
406c16211d6SLiam Girdwood struct snd_sof_mailbox {
407c16211d6SLiam Girdwood size_t size;
408e9e7eeafSPierre-Louis Bossart u32 offset;
409c16211d6SLiam Girdwood };
410c16211d6SLiam Girdwood
411c16211d6SLiam Girdwood /* IPC message descriptor for host <-> DSP IO */
412c16211d6SLiam Girdwood struct snd_sof_ipc_msg {
413c16211d6SLiam Girdwood /* message data */
414c16211d6SLiam Girdwood void *msg_data;
415c16211d6SLiam Girdwood void *reply_data;
416c16211d6SLiam Girdwood size_t msg_size;
417c16211d6SLiam Girdwood size_t reply_size;
418c16211d6SLiam Girdwood int reply_error;
419c16211d6SLiam Girdwood
420*5a4413d0SPierre-Louis Bossart bool ipc_complete;
42184c2dca3SPeter Ujfalusi
422c16211d6SLiam Girdwood wait_queue_head_t waitq;
423*5a4413d0SPierre-Louis Bossart
424*5a4413d0SPierre-Louis Bossart /* notification, firmware initiated messages */
425*5a4413d0SPierre-Louis Bossart void *rx_data;
426c16211d6SLiam Girdwood };
427c16211d6SLiam Girdwood
428657774acSRanjani Sridharan /**
4290cfbaee2SPeter Ujfalusi * struct sof_ipc_fw_tracing_ops - IPC-specific firmware tracing ops
4300cfbaee2SPeter Ujfalusi * @init: Function pointer for initialization of the tracing
4310cfbaee2SPeter Ujfalusi * @free: Optional function pointer for freeing of the tracing
4320cfbaee2SPeter Ujfalusi * @fw_crashed: Optional function pointer to notify the tracing of a firmware crash
4330cfbaee2SPeter Ujfalusi * @suspend: Function pointer for system/runtime suspend
4340cfbaee2SPeter Ujfalusi * @resume: Function pointer for system/runtime resume
4350cfbaee2SPeter Ujfalusi */
4360cfbaee2SPeter Ujfalusi struct sof_ipc_fw_tracing_ops {
4370cfbaee2SPeter Ujfalusi int (*init)(struct snd_sof_dev *sdev);
4380cfbaee2SPeter Ujfalusi void (*free)(struct snd_sof_dev *sdev);
4390cfbaee2SPeter Ujfalusi void (*fw_crashed)(struct snd_sof_dev *sdev);
4400cfbaee2SPeter Ujfalusi void (*suspend)(struct snd_sof_dev *sdev, pm_message_t pm_state);
4410cfbaee2SPeter Ujfalusi int (*resume)(struct snd_sof_dev *sdev);
4420cfbaee2SPeter Ujfalusi };
4430cfbaee2SPeter Ujfalusi
4440cfbaee2SPeter Ujfalusi /**
445657774acSRanjani Sridharan * struct sof_ipc_pm_ops - IPC-specific PM ops
44603f69725SPeter Ujfalusi * @ctx_save: Optional function pointer for context save
44703f69725SPeter Ujfalusi * @ctx_restore: Optional function pointer for context restore
448b41252d8SPeter Ujfalusi * @set_core_state: Optional function pointer for turning on/off a DSP core
449167ca6a4SRander Wang * @set_pm_gate: Optional function pointer for pm gate settings
450657774acSRanjani Sridharan */
451657774acSRanjani Sridharan struct sof_ipc_pm_ops {
452657774acSRanjani Sridharan int (*ctx_save)(struct snd_sof_dev *sdev);
453657774acSRanjani Sridharan int (*ctx_restore)(struct snd_sof_dev *sdev);
454b41252d8SPeter Ujfalusi int (*set_core_state)(struct snd_sof_dev *sdev, int core_idx, bool on);
455167ca6a4SRander Wang int (*set_pm_gate)(struct snd_sof_dev *sdev, u32 flags);
456657774acSRanjani Sridharan };
457657774acSRanjani Sridharan
45861bafd1cSPeter Ujfalusi /**
45961bafd1cSPeter Ujfalusi * struct sof_ipc_fw_loader_ops - IPC/FW-specific loader ops
46061bafd1cSPeter Ujfalusi * @validate: Function pointer for validating the firmware image
46161bafd1cSPeter Ujfalusi * @parse_ext_manifest: Function pointer for parsing the manifest of the firmware
46261bafd1cSPeter Ujfalusi * @load_fw_to_dsp: Optional function pointer for loading the firmware to the
46361bafd1cSPeter Ujfalusi * DSP.
46461bafd1cSPeter Ujfalusi * The function implements generic, hardware independent way
46561bafd1cSPeter Ujfalusi * of loading the initial firmware and its modules (if any).
46661bafd1cSPeter Ujfalusi */
46761bafd1cSPeter Ujfalusi struct sof_ipc_fw_loader_ops {
46861bafd1cSPeter Ujfalusi int (*validate)(struct snd_sof_dev *sdev);
46961bafd1cSPeter Ujfalusi size_t (*parse_ext_manifest)(struct snd_sof_dev *sdev);
47061bafd1cSPeter Ujfalusi int (*load_fw_to_dsp)(struct snd_sof_dev *sdev);
47161bafd1cSPeter Ujfalusi };
47261bafd1cSPeter Ujfalusi
473226abb75SRanjani Sridharan struct sof_ipc_tplg_ops;
474967885eeSRanjani Sridharan struct sof_ipc_pcm_ops;
475226abb75SRanjani Sridharan
476226abb75SRanjani Sridharan /**
477226abb75SRanjani Sridharan * struct sof_ipc_ops - IPC-specific ops
478226abb75SRanjani Sridharan * @tplg: Pointer to IPC-specific topology ops
479657774acSRanjani Sridharan * @pm: Pointer to PM ops
480967885eeSRanjani Sridharan * @pcm: Pointer to PCM ops
48161bafd1cSPeter Ujfalusi * @fw_loader: Pointer to Firmware Loader ops
4821cf79c34SPeter Ujfalusi * @fw_tracing: Optional pointer to Firmware tracing ops
48325e77672SPeter Ujfalusi *
484aa23b375SPeter Ujfalusi * @init: Optional pointer for IPC related initialization
485aa23b375SPeter Ujfalusi * @exit: Optional pointer for IPC related cleanup
486cbb984b6SPeter Ujfalusi * @post_fw_boot: Optional pointer to execute IPC related tasks after firmware
487cbb984b6SPeter Ujfalusi * boot.
488aa23b375SPeter Ujfalusi *
48925e77672SPeter Ujfalusi * @tx_msg: Function pointer for sending a 'short' IPC message
49025e77672SPeter Ujfalusi * @set_get_data: Function pointer for set/get data ('large' IPC message). This
49125e77672SPeter Ujfalusi * function may split up the 'large' message and use the @tx_msg
49225e77672SPeter Ujfalusi * path to transfer individual chunks, or use other means to transfer
49325e77672SPeter Ujfalusi * the message.
49425e77672SPeter Ujfalusi * @get_reply: Function pointer for fetching the reply to
49525e77672SPeter Ujfalusi * sdev->ipc->msg.reply_data
49625e77672SPeter Ujfalusi * @rx_msg: Function pointer for handling a received message
49725e77672SPeter Ujfalusi *
49825e77672SPeter Ujfalusi * Note: both @tx_msg and @set_get_data considered as TX functions and they are
49925e77672SPeter Ujfalusi * serialized for the duration of the instructed transfer. A large message sent
50025e77672SPeter Ujfalusi * via @set_get_data is a single transfer even if at the hardware level it is
50125e77672SPeter Ujfalusi * handled with multiple chunks.
502226abb75SRanjani Sridharan */
503226abb75SRanjani Sridharan struct sof_ipc_ops {
504226abb75SRanjani Sridharan const struct sof_ipc_tplg_ops *tplg;
505657774acSRanjani Sridharan const struct sof_ipc_pm_ops *pm;
506967885eeSRanjani Sridharan const struct sof_ipc_pcm_ops *pcm;
50761bafd1cSPeter Ujfalusi const struct sof_ipc_fw_loader_ops *fw_loader;
5080cfbaee2SPeter Ujfalusi const struct sof_ipc_fw_tracing_ops *fw_tracing;
50925e77672SPeter Ujfalusi
510aa23b375SPeter Ujfalusi int (*init)(struct snd_sof_dev *sdev);
511aa23b375SPeter Ujfalusi void (*exit)(struct snd_sof_dev *sdev);
512cbb984b6SPeter Ujfalusi int (*post_fw_boot)(struct snd_sof_dev *sdev);
513aa23b375SPeter Ujfalusi
51425e77672SPeter Ujfalusi int (*tx_msg)(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
51525e77672SPeter Ujfalusi void *reply_data, size_t reply_bytes, bool no_pm);
51625e77672SPeter Ujfalusi int (*set_get_data)(struct snd_sof_dev *sdev, void *data, size_t data_bytes,
51725e77672SPeter Ujfalusi bool set);
51825e77672SPeter Ujfalusi int (*get_reply)(struct snd_sof_dev *sdev);
51925e77672SPeter Ujfalusi void (*rx_msg)(struct snd_sof_dev *sdev);
520226abb75SRanjani Sridharan };
521226abb75SRanjani Sridharan
522f535880bSRander Wang /* SOF generic IPC data */
523f535880bSRander Wang struct snd_sof_ipc {
524f535880bSRander Wang struct snd_sof_dev *sdev;
525f535880bSRander Wang
526f535880bSRander Wang /* protects messages and the disable flag */
527f535880bSRander Wang struct mutex tx_mutex;
528f535880bSRander Wang /* disables further sending of ipc's */
529f535880bSRander Wang bool disable_ipc_tx;
530f535880bSRander Wang
531a3e6b369SPeter Ujfalusi /* Maximum allowed size of a single IPC message/reply */
532a3e6b369SPeter Ujfalusi size_t max_payload_size;
533a3e6b369SPeter Ujfalusi
534f535880bSRander Wang struct snd_sof_ipc_msg msg;
535226abb75SRanjani Sridharan
536226abb75SRanjani Sridharan /* IPC ops based on version */
537226abb75SRanjani Sridharan const struct sof_ipc_ops *ops;
538f535880bSRander Wang };
539f535880bSRander Wang
540caf0f466SPeter Ujfalusi /* Helper to retrieve the IPC ops */
541caf0f466SPeter Ujfalusi #define sof_ipc_get_ops(sdev, ops_name) \
542caf0f466SPeter Ujfalusi (((sdev)->ipc && (sdev)->ipc->ops) ? (sdev)->ipc->ops->ops_name : NULL)
543caf0f466SPeter Ujfalusi
544c16211d6SLiam Girdwood /*
545c16211d6SLiam Girdwood * SOF Device Level.
546c16211d6SLiam Girdwood */
547c16211d6SLiam Girdwood struct snd_sof_dev {
548c16211d6SLiam Girdwood struct device *dev;
549c16211d6SLiam Girdwood spinlock_t ipc_lock; /* lock for IPC users */
550c16211d6SLiam Girdwood spinlock_t hw_lock; /* lock for HW IO access */
551c16211d6SLiam Girdwood
55259611370SPeter Ujfalusi /*
55359611370SPeter Ujfalusi * When true the DSP is not used.
55459611370SPeter Ujfalusi * It is set under the following condition:
55559611370SPeter Ujfalusi * User sets the SOF_DBG_DSPLESS_MODE flag in sof_debug module parameter
55659611370SPeter Ujfalusi * and
55759611370SPeter Ujfalusi * the platform advertises that it can support such mode
55859611370SPeter Ujfalusi * pdata->desc->dspless_mode_supported is true.
55959611370SPeter Ujfalusi */
56059611370SPeter Ujfalusi bool dspless_mode_selected;
56159611370SPeter Ujfalusi
5624f373ccfSPeter Ujfalusi /* Main, Base firmware image */
5634f373ccfSPeter Ujfalusi struct sof_firmware basefw;
5644f373ccfSPeter Ujfalusi
565c16211d6SLiam Girdwood /*
566c16211d6SLiam Girdwood * ASoC components. plat_drv fields are set dynamically so
567c16211d6SLiam Girdwood * can't use const
568c16211d6SLiam Girdwood */
569c16211d6SLiam Girdwood struct snd_soc_component_driver plat_drv;
570c16211d6SLiam Girdwood
57161e285caSRanjani Sridharan /* current DSP power state */
57261e285caSRanjani Sridharan struct sof_dsp_power_state dsp_power_state;
5738b66d7c5SKeyon Jie /* mutex to protect the dsp_power_state access */
5748b66d7c5SKeyon Jie struct mutex power_state_access;
575043ae13bSRanjani Sridharan
576043ae13bSRanjani Sridharan /* Intended power target of system suspend */
577043ae13bSRanjani Sridharan enum sof_system_suspend_state system_suspend_target;
5784c19030cSKeyon Jie
579c16211d6SLiam Girdwood /* DSP firmware boot */
580c16211d6SLiam Girdwood wait_queue_head_t boot_wait;
581d41607d3SPeter Ujfalusi enum sof_fw_state fw_state;
582f738d815SGuennadi Liakhovetski bool first_boot;
583c16211d6SLiam Girdwood
584c16211d6SLiam Girdwood /* work queue in case the probe is implemented in two steps */
585c16211d6SLiam Girdwood struct work_struct probe_work;
586271d9373SKai Vehmanen bool probe_completed;
587c16211d6SLiam Girdwood
588c16211d6SLiam Girdwood /* DSP HW differentiation */
589c16211d6SLiam Girdwood struct snd_sof_pdata *pdata;
590c16211d6SLiam Girdwood
591c16211d6SLiam Girdwood /* IPC */
592c16211d6SLiam Girdwood struct snd_sof_ipc *ipc;
5934700bfb2SRander Wang struct snd_sof_mailbox fw_info_box; /* FW shared memory */
594c16211d6SLiam Girdwood struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */
595c16211d6SLiam Girdwood struct snd_sof_mailbox host_box; /* Host initiated IPC */
596c16211d6SLiam Girdwood struct snd_sof_mailbox stream_box; /* Stream position update */
597e17b7389SIulian Olaru struct snd_sof_mailbox debug_box; /* Debug info updates */
598c16211d6SLiam Girdwood struct snd_sof_ipc_msg *msg;
599c16211d6SLiam Girdwood int ipc_irq;
600c16211d6SLiam Girdwood u32 next_comp_id; /* monotonic - reset during S3 */
601c16211d6SLiam Girdwood
602c16211d6SLiam Girdwood /* memory bases for mmaped DSPs - set by dsp_init() */
603c16211d6SLiam Girdwood void __iomem *bar[SND_SOF_BARS]; /* DSP base address */
604c16211d6SLiam Girdwood int mmio_bar;
605c16211d6SLiam Girdwood int mailbox_bar;
606c16211d6SLiam Girdwood size_t dsp_oops_offset;
607c16211d6SLiam Girdwood
608c16211d6SLiam Girdwood /* debug */
609c16211d6SLiam Girdwood struct dentry *debugfs_root;
610c16211d6SLiam Girdwood struct list_head dfsentry_list;
6119ff90859SPeter Ujfalusi bool dbg_dump_printed;
6129ff90859SPeter Ujfalusi bool ipc_dump_printed;
613b30289e7SPeter Ujfalusi bool d3_prevented; /* runtime pm use count incremented to prevent context lost */
614c16211d6SLiam Girdwood
615c16211d6SLiam Girdwood /* firmware loader */
616c16211d6SLiam Girdwood struct sof_ipc_fw_ready fw_ready;
617c16211d6SLiam Girdwood struct sof_ipc_fw_version fw_version;
61859283959SKarol Trzcinski struct sof_ipc_cc_version *cc_version;
619c16211d6SLiam Girdwood
620c16211d6SLiam Girdwood /* topology */
621c16211d6SLiam Girdwood struct snd_soc_tplg_ops *tplg_ops;
622c16211d6SLiam Girdwood struct list_head pcm_list;
623c16211d6SLiam Girdwood struct list_head kcontrol_list;
624c16211d6SLiam Girdwood struct list_head widget_list;
6259c04363dSRanjani Sridharan struct list_head pipeline_list;
626c16211d6SLiam Girdwood struct list_head dai_list;
6270af0f463SRanjani Sridharan struct list_head dai_link_list;
628c16211d6SLiam Girdwood struct list_head route_list;
629c16211d6SLiam Girdwood struct snd_soc_component *component;
630c16211d6SLiam Girdwood u32 enabled_cores_mask; /* keep track of enabled cores */
6319b014266SJaroslav Kysela bool led_present;
632c16211d6SLiam Girdwood
633c16211d6SLiam Girdwood /* FW configuration */
634c16211d6SLiam Girdwood struct sof_ipc_window *info_window;
635c16211d6SLiam Girdwood
636c16211d6SLiam Girdwood /* IPC timeouts in ms */
637c16211d6SLiam Girdwood int ipc_timeout;
638c16211d6SLiam Girdwood int boot_timeout;
639c16211d6SLiam Girdwood
64025b17da6SPeter Ujfalusi /* firmwre tracing */
64125b17da6SPeter Ujfalusi bool fw_trace_is_supported; /* set with Kconfig or module parameter */
64208341b27SPeter Ujfalusi void *fw_trace_data; /* private data used by firmware tracing implementation */
64325b17da6SPeter Ujfalusi
644672ff5e3SGuennadi Liakhovetski bool msi_enabled;
645c16211d6SLiam Girdwood
6465974f684SRanjani Sridharan /* DSP core context */
6475974f684SRanjani Sridharan u32 num_cores;
6485974f684SRanjani Sridharan
6495974f684SRanjani Sridharan /*
6505974f684SRanjani Sridharan * ref count per core that will be modified during system suspend/resume and during pcm
6515974f684SRanjani Sridharan * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
6525974f684SRanjani Sridharan * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
6535974f684SRanjani Sridharan * sound/core/ when streams are active and during system suspend/resume, streams are
6545974f684SRanjani Sridharan * already suspended.
6555974f684SRanjani Sridharan */
6565974f684SRanjani Sridharan int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
6575974f684SRanjani Sridharan
6586955d951SPeter Ujfalusi /*
6596955d951SPeter Ujfalusi * Used to keep track of registered IPC client devices so that they can
6606955d951SPeter Ujfalusi * be removed when the parent SOF module is removed.
6616955d951SPeter Ujfalusi */
6626955d951SPeter Ujfalusi struct list_head ipc_client_list;
6636955d951SPeter Ujfalusi
6646955d951SPeter Ujfalusi /* mutex to protect client list */
6656955d951SPeter Ujfalusi struct mutex ipc_client_mutex;
6666955d951SPeter Ujfalusi
6676955d951SPeter Ujfalusi /*
6686955d951SPeter Ujfalusi * Used for tracking the IPC client's RX registration for DSP initiated
6696955d951SPeter Ujfalusi * message handling.
6706955d951SPeter Ujfalusi */
6716955d951SPeter Ujfalusi struct list_head ipc_rx_handler_list;
6726955d951SPeter Ujfalusi
6736955d951SPeter Ujfalusi /*
6746955d951SPeter Ujfalusi * Used for tracking the IPC client's registration for DSP state change
6756955d951SPeter Ujfalusi * notification
6766955d951SPeter Ujfalusi */
6776955d951SPeter Ujfalusi struct list_head fw_state_handler_list;
6786955d951SPeter Ujfalusi
6796955d951SPeter Ujfalusi /* to protect the ipc_rx_handler_list and dsp_state_handler_list list */
6806955d951SPeter Ujfalusi struct mutex client_event_handler_mutex;
6816955d951SPeter Ujfalusi
682d136949dSPierre-Louis Bossart /* quirks to override topology values */
683d136949dSPierre-Louis Bossart bool mclk_id_override;
684d136949dSPierre-Louis Bossart u16 mclk_id_quirk; /* same size as in IPC3 definitions */
685d136949dSPierre-Louis Bossart
686c16211d6SLiam Girdwood void *private; /* core does not touch this */
687c16211d6SLiam Girdwood };
688c16211d6SLiam Girdwood
689c16211d6SLiam Girdwood /*
690c16211d6SLiam Girdwood * Device Level.
691c16211d6SLiam Girdwood */
692c16211d6SLiam Girdwood
693c16211d6SLiam Girdwood int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
694c16211d6SLiam Girdwood int snd_sof_device_remove(struct device *dev);
6957edb3051SKeyon Jie int snd_sof_device_shutdown(struct device *dev);
696271d9373SKai Vehmanen bool snd_sof_device_probe_completed(struct device *dev);
697c16211d6SLiam Girdwood
698c16211d6SLiam Girdwood int snd_sof_runtime_suspend(struct device *dev);
699c16211d6SLiam Girdwood int snd_sof_runtime_resume(struct device *dev);
70062fde977SKai Vehmanen int snd_sof_runtime_idle(struct device *dev);
701c16211d6SLiam Girdwood int snd_sof_resume(struct device *dev);
702c16211d6SLiam Girdwood int snd_sof_suspend(struct device *dev);
7033541aef1SMarcin Rajwa int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
7040b50b3b1SKeyon Jie int snd_sof_prepare(struct device *dev);
7050b50b3b1SKeyon Jie void snd_sof_complete(struct device *dev);
706c16211d6SLiam Girdwood
707c16211d6SLiam Girdwood void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
708c16211d6SLiam Girdwood
709c16211d6SLiam Girdwood /*
71029990588SPeter Ujfalusi * Compress support
71129990588SPeter Ujfalusi */
71229990588SPeter Ujfalusi extern struct snd_compress_ops sof_compressed_ops;
71329990588SPeter Ujfalusi
71429990588SPeter Ujfalusi /*
715b1a4ee9fSPeter Ujfalusi * Firmware (firmware, libraries, topologies) file location
716b1a4ee9fSPeter Ujfalusi */
717b1a4ee9fSPeter Ujfalusi int sof_create_ipc_file_profile(struct snd_sof_dev *sdev,
718b1a4ee9fSPeter Ujfalusi struct sof_loadable_file_profile *base_profile,
719b1a4ee9fSPeter Ujfalusi struct sof_loadable_file_profile *out_profile);
720b1a4ee9fSPeter Ujfalusi
721b1a4ee9fSPeter Ujfalusi /*
722c16211d6SLiam Girdwood * Firmware loading.
723c16211d6SLiam Girdwood */
724c16211d6SLiam Girdwood int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
725c16211d6SLiam Girdwood int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
726c16211d6SLiam Girdwood int snd_sof_run_firmware(struct snd_sof_dev *sdev);
727c16211d6SLiam Girdwood void snd_sof_fw_unload(struct snd_sof_dev *sdev);
728c16211d6SLiam Girdwood
729c16211d6SLiam Girdwood /*
730c16211d6SLiam Girdwood * IPC low level APIs.
731c16211d6SLiam Girdwood */
732c16211d6SLiam Girdwood struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
733c16211d6SLiam Girdwood void snd_sof_ipc_free(struct snd_sof_dev *sdev);
7348ae77801SPeter Ujfalusi void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
735d7a1ed26SRanjani Sridharan void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
snd_sof_ipc_msgs_rx(struct snd_sof_dev * sdev)7362f1f5a43SPeter Ujfalusi static inline void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
7372f1f5a43SPeter Ujfalusi {
7382f1f5a43SPeter Ujfalusi sdev->ipc->ops->rx_msg(sdev);
7392f1f5a43SPeter Ujfalusi }
7402a51c0f8SPeter Ujfalusi int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
7412a51c0f8SPeter Ujfalusi 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)742ccb541a0SCurtis Malainey static inline int sof_ipc_tx_message_no_reply(struct snd_sof_ipc *ipc, void *msg_data,
743ccb541a0SCurtis Malainey size_t msg_bytes)
744ccb541a0SCurtis Malainey {
745ccb541a0SCurtis Malainey return sof_ipc_tx_message(ipc, msg_data, msg_bytes, NULL, 0);
746ccb541a0SCurtis Malainey }
747d8bc54a5SJyri Sarha int sof_ipc_set_get_data(struct snd_sof_ipc *ipc, void *msg_data,
748d8bc54a5SJyri Sarha size_t msg_bytes, bool set);
7492a51c0f8SPeter Ujfalusi int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
75063e51fd3SRanjani Sridharan 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)751ccb541a0SCurtis Malainey static inline int sof_ipc_tx_message_no_pm_no_reply(struct snd_sof_ipc *ipc, void *msg_data,
752ccb541a0SCurtis Malainey size_t msg_bytes)
753ccb541a0SCurtis Malainey {
754ccb541a0SCurtis Malainey return sof_ipc_tx_message_no_pm(ipc, msg_data, msg_bytes, NULL, 0);
755ccb541a0SCurtis Malainey }
756b4dcafe4SPeter Ujfalusi int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
757b4dcafe4SPeter Ujfalusi size_t reply_bytes);
75819faf9eeSPeter Ujfalusi
snd_sof_ipc_process_reply(struct snd_sof_dev * sdev,u32 msg_id)7598ae77801SPeter Ujfalusi static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
7608ae77801SPeter Ujfalusi {
7618ae77801SPeter Ujfalusi snd_sof_ipc_get_reply(sdev);
7628ae77801SPeter Ujfalusi snd_sof_ipc_reply(sdev, msg_id);
7638ae77801SPeter Ujfalusi }
764c16211d6SLiam Girdwood
765c16211d6SLiam Girdwood /*
766c16211d6SLiam Girdwood * Trace/debug
767c16211d6SLiam Girdwood */
768c16211d6SLiam Girdwood int snd_sof_dbg_init(struct snd_sof_dev *sdev);
769c16211d6SLiam Girdwood void snd_sof_free_debug(struct snd_sof_dev *sdev);
770c16211d6SLiam Girdwood int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
771c16211d6SLiam Girdwood void *base, size_t size,
7725c9714f6SRanjani Sridharan const char *name, mode_t mode);
7734995ffceSPeter Ujfalusi void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
7744995ffceSPeter Ujfalusi u32 panic_code, u32 tracep_code, void *oops,
775c16211d6SLiam Girdwood struct sof_ipc_panic_info *panic_info,
776c16211d6SLiam Girdwood void *stack, size_t stack_words);
777145cb4e7SPeter Ujfalusi void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev, const char *msg);
7785b10b629SKarol Trzcinski int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
77907e833b4SPeter Ujfalusi int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
78007e833b4SPeter Ujfalusi enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
78107e833b4SPeter Ujfalusi const char *name, enum sof_debugfs_access_type access_type);
7821dedbe4fSPeter Ujfalusi /* Firmware tracing */
7831dedbe4fSPeter Ujfalusi int sof_fw_trace_init(struct snd_sof_dev *sdev);
7841dedbe4fSPeter Ujfalusi void sof_fw_trace_free(struct snd_sof_dev *sdev);
7851dedbe4fSPeter Ujfalusi void sof_fw_trace_fw_crashed(struct snd_sof_dev *sdev);
7861dedbe4fSPeter Ujfalusi void sof_fw_trace_suspend(struct snd_sof_dev *sdev, pm_message_t pm_state);
7871dedbe4fSPeter Ujfalusi int sof_fw_trace_resume(struct snd_sof_dev *sdev);
788c16211d6SLiam Girdwood
789c16211d6SLiam Girdwood /*
790c16211d6SLiam Girdwood * DSP Architectures.
791c16211d6SLiam Girdwood */
sof_stack(struct snd_sof_dev * sdev,const char * level,void * oops,u32 * stack,u32 stack_words)792b9f0bfd1SPeter Ujfalusi static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
793b9f0bfd1SPeter Ujfalusi void *oops, u32 *stack, u32 stack_words)
794c16211d6SLiam Girdwood {
795b9f0bfd1SPeter Ujfalusi sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level, oops, stack,
796b9f0bfd1SPeter Ujfalusi stack_words);
797c16211d6SLiam Girdwood }
798c16211d6SLiam Girdwood
sof_oops(struct snd_sof_dev * sdev,const char * level,void * oops)799b9f0bfd1SPeter Ujfalusi static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
800c16211d6SLiam Girdwood {
8010ed66cb7SPeter Ujfalusi if (sof_dsp_arch_ops(sdev)->dsp_oops)
802b9f0bfd1SPeter Ujfalusi sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops);
803c16211d6SLiam Girdwood }
804c16211d6SLiam Girdwood
8050ed66cb7SPeter Ujfalusi extern const struct dsp_arch_ops sof_xtensa_arch_ops;
806c16211d6SLiam Girdwood
807c16211d6SLiam Girdwood /*
80858a5c9a4SPeter Ujfalusi * Firmware state tracking
80958a5c9a4SPeter Ujfalusi */
8106955d951SPeter Ujfalusi void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
81158a5c9a4SPeter Ujfalusi
81258a5c9a4SPeter Ujfalusi /*
813c16211d6SLiam Girdwood * Utilities
814c16211d6SLiam Girdwood */
815c16211d6SLiam Girdwood void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
816c16211d6SLiam Girdwood void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
817c16211d6SLiam Girdwood u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
818c16211d6SLiam Girdwood u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
819c16211d6SLiam Girdwood void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
820c16211d6SLiam Girdwood void *message, size_t bytes);
821c16211d6SLiam Girdwood void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
822c16211d6SLiam Girdwood void *message, size_t bytes);
8234624bb2fSPeter Ujfalusi int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
8244624bb2fSPeter Ujfalusi u32 offset, void *src, size_t size);
8254624bb2fSPeter Ujfalusi int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
8264624bb2fSPeter Ujfalusi u32 offset, void *dest, size_t size);
827c16211d6SLiam Girdwood
82897e22cbdSBud Liviu-Alexandru int sof_ipc_msg_data(struct snd_sof_dev *sdev,
8291b905942SDaniel Baluta struct snd_sof_pcm_stream *sps,
830c16211d6SLiam Girdwood void *p, size_t sz);
8319a0a809aSPeter Ujfalusi int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
832249f186dSDaniel Baluta struct snd_sof_pcm_stream *sps,
8339a0a809aSPeter Ujfalusi size_t posn_offset);
834c16211d6SLiam Girdwood
83597e22cbdSBud Liviu-Alexandru int sof_stream_pcm_open(struct snd_sof_dev *sdev,
836c16211d6SLiam Girdwood struct snd_pcm_substream *substream);
83797e22cbdSBud Liviu-Alexandru int sof_stream_pcm_close(struct snd_sof_dev *sdev,
838c16211d6SLiam Girdwood struct snd_pcm_substream *substream);
839c16211d6SLiam Girdwood
8406955d951SPeter Ujfalusi /* SOF client support */
8416955d951SPeter Ujfalusi #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
8426955d951SPeter Ujfalusi int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
8436955d951SPeter Ujfalusi const void *data, size_t size);
8446955d951SPeter Ujfalusi void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
8456955d951SPeter Ujfalusi int sof_register_clients(struct snd_sof_dev *sdev);
8466955d951SPeter Ujfalusi void sof_unregister_clients(struct snd_sof_dev *sdev);
8476955d951SPeter Ujfalusi void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
8486955d951SPeter Ujfalusi void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
8491069967aSPeter Ujfalusi int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
8501069967aSPeter Ujfalusi int sof_resume_clients(struct snd_sof_dev *sdev);
8516955d951SPeter 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)8526955d951SPeter Ujfalusi static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
8536955d951SPeter Ujfalusi u32 id, const void *data, size_t size)
8546955d951SPeter Ujfalusi {
8556955d951SPeter Ujfalusi return 0;
8566955d951SPeter Ujfalusi }
8576955d951SPeter Ujfalusi
sof_client_dev_unregister(struct snd_sof_dev * sdev,const char * name,u32 id)8586955d951SPeter Ujfalusi static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
8596955d951SPeter Ujfalusi const char *name, u32 id)
8606955d951SPeter Ujfalusi {
8616955d951SPeter Ujfalusi }
8626955d951SPeter Ujfalusi
sof_register_clients(struct snd_sof_dev * sdev)8636955d951SPeter Ujfalusi static inline int sof_register_clients(struct snd_sof_dev *sdev)
8646955d951SPeter Ujfalusi {
8656955d951SPeter Ujfalusi return 0;
8666955d951SPeter Ujfalusi }
8676955d951SPeter Ujfalusi
sof_unregister_clients(struct snd_sof_dev * sdev)8686955d951SPeter Ujfalusi static inline void sof_unregister_clients(struct snd_sof_dev *sdev)
8696955d951SPeter Ujfalusi {
8706955d951SPeter Ujfalusi }
8716955d951SPeter Ujfalusi
sof_client_ipc_rx_dispatcher(struct snd_sof_dev * sdev,void * msg_buf)8726955d951SPeter Ujfalusi static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
8736955d951SPeter Ujfalusi {
8746955d951SPeter Ujfalusi }
8756955d951SPeter Ujfalusi
sof_client_fw_state_dispatcher(struct snd_sof_dev * sdev)8766955d951SPeter Ujfalusi static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
8776955d951SPeter Ujfalusi {
8786955d951SPeter Ujfalusi }
8791069967aSPeter Ujfalusi
sof_suspend_clients(struct snd_sof_dev * sdev,pm_message_t state)8801069967aSPeter Ujfalusi static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
8811069967aSPeter Ujfalusi {
8821069967aSPeter Ujfalusi return 0;
8831069967aSPeter Ujfalusi }
8841069967aSPeter Ujfalusi
sof_resume_clients(struct snd_sof_dev * sdev)8851069967aSPeter Ujfalusi static inline int sof_resume_clients(struct snd_sof_dev *sdev)
8861069967aSPeter Ujfalusi {
8871069967aSPeter Ujfalusi return 0;
8881069967aSPeter Ujfalusi }
8896955d951SPeter Ujfalusi #endif /* CONFIG_SND_SOC_SOF_CLIENT */
8906955d951SPeter Ujfalusi
891f80beaf6SPeter Ujfalusi /* Main ops for IPC implementations */
892f80beaf6SPeter Ujfalusi extern const struct sof_ipc_ops ipc3_ops;
893ceb89accSPeter Ujfalusi extern const struct sof_ipc_ops ipc4_ops;
894f80beaf6SPeter Ujfalusi
895c16211d6SLiam Girdwood #endif
896