blob: ba341b1bda0cb842cd9b3243ad16d6f10280bdcf [file] [log] [blame]
Pierre-Louis Bossarte149ca22020-05-01 09:58:50 -05001/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
Liam Girdwoodc16211d2019-04-12 11:05:06 -05002/*
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * Copyright(c) 2018 Intel Corporation. All rights reserved.
7 *
8 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9 */
10
11#ifndef __SOUND_SOC_SOF_PRIV_H
12#define __SOUND_SOC_SOF_PRIV_H
13
14#include <linux/device.h>
Liam Girdwoodc16211d2019-04-12 11:05:06 -050015#include <sound/hdaudio.h>
Liam Girdwoodc16211d2019-04-12 11:05:06 -050016#include <sound/sof.h>
Liam Girdwoodc16211d2019-04-12 11:05:06 -050017#include <sound/sof/info.h>
18#include <sound/sof/pm.h>
Liam Girdwoodc16211d2019-04-12 11:05:06 -050019#include <sound/sof/trace.h>
Liam Girdwoodc16211d2019-04-12 11:05:06 -050020#include <uapi/sound/sof/fw.h>
Fred Ohe984f3ef2020-11-27 18:40:18 +020021#include <sound/sof/ext_manifest.h>
Liam Girdwoodc16211d2019-04-12 11:05:06 -050022
23/* debug flags */
Pierre-Louis Bossart2ab4c502019-09-27 15:05:28 -050024#define SOF_DBG_ENABLE_TRACE BIT(0)
Ranjani Sridharanfbfa22e2020-12-11 12:07:42 +020025#define SOF_DBG_RETAIN_CTX BIT(1) /* prevent DSP D3 on FW exception */
Ranjani Sridharanc0e79692021-09-27 15:05:17 +030026#define SOF_DBG_VERIFY_TPLG BIT(2) /* verify topology during load */
Pierre-Louis Bossartea6bfbb2021-10-04 16:27:28 -050027#define SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE BIT(3) /* 0: use topology token
28 * 1: override topology
29 */
30#define SOF_DBG_DYNAMIC_PIPELINES_ENABLE BIT(4) /* 0: use static pipelines
31 * 1: use dynamic pipelines
32 */
Pierre-Louis Bossart1539c8c2021-10-06 14:06:27 +030033#define SOF_DBG_DISABLE_MULTICORE BIT(5) /* schedule all pipelines/widgets
34 * on primary core
35 */
Peter Ujfalusi9ff90852021-10-06 14:06:30 +030036#define SOF_DBG_PRINT_ALL_DUMPS BIT(6) /* Print all ipc and dsp dumps */
Ranjani Sridharanfbfa22e2020-12-11 12:07:42 +020037
38#define SOF_DBG_DUMP_REGS BIT(0)
39#define SOF_DBG_DUMP_MBOX BIT(1)
40#define SOF_DBG_DUMP_TEXT BIT(2)
41#define SOF_DBG_DUMP_PCI BIT(3)
Peter Ujfalusi23013332021-10-06 14:06:36 +030042#define SOF_DBG_DUMP_OPTIONAL BIT(4) /* only dump if SOF_DBG_PRINT_ALL_DUMPS is set */
Pierre-Louis Bossart2ab4c502019-09-27 15:05:28 -050043
44/* global debug state set by SOF_DBG_ flags */
45extern int sof_core_debug;
Liam Girdwoodc16211d2019-04-12 11:05:06 -050046
47/* max BARs mmaped devices can use */
48#define SND_SOF_BARS 8
49
50/* time in ms for runtime suspend delay */
51#define SND_SOF_SUSPEND_DELAY_MS 2000
52
53/* DMA buffer size for trace */
54#define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16)
55
Liam Girdwoodc16211d2019-04-12 11:05:06 -050056#define SOF_IPC_DSP_REPLY 0
57#define SOF_IPC_HOST_REPLY 1
58
59/* convenience constructor for DAI driver streams */
60#define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \
61 {.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \
62 .rates = srates, .formats = sfmt}
63
64#define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
65 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
66
Ranjani Sridharan091c12e2019-06-03 11:18:20 -050067#define ENABLE_DEBUGFS_CACHEBUF \
68 (IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE) || \
69 IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST))
70
Guennadi Liakhovetski0dcdf842020-09-02 17:07:54 +030071/* So far the primary core on all DSPs has ID 0 */
72#define SOF_DSP_PRIMARY_CORE 0
73
Ranjani Sridharan700d1672020-01-29 16:07:21 -060074/* DSP power state */
75enum sof_dsp_power_states {
76 SOF_DSP_PM_D0,
77 SOF_DSP_PM_D1,
78 SOF_DSP_PM_D2,
79 SOF_DSP_PM_D3_HOT,
80 SOF_DSP_PM_D3,
81 SOF_DSP_PM_D3_COLD,
82};
83
Ranjani Sridharan61e285c2020-01-29 16:07:22 -060084struct sof_dsp_power_state {
85 u32 state;
86 u32 substate; /* platform-specific */
Keyon Jie4c190302019-10-25 17:40:57 -050087};
88
Ranjani Sridharan043ae132020-01-29 16:07:20 -060089/* System suspend target state */
90enum sof_system_suspend_state {
91 SOF_SUSPEND_NONE = 0,
92 SOF_SUSPEND_S0IX,
93 SOF_SUSPEND_S3,
94};
95
Peter Ujfalusi07e833b2021-09-15 15:21:12 +030096enum sof_dfsentry_type {
97 SOF_DFSENTRY_TYPE_IOMEM = 0,
98 SOF_DFSENTRY_TYPE_BUF,
99};
100
101enum sof_debugfs_access_type {
102 SOF_DEBUGFS_ACCESS_ALWAYS = 0,
103 SOF_DEBUGFS_ACCESS_D0_ONLY,
104};
105
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500106struct snd_sof_dev;
107struct snd_sof_ipc_msg;
108struct snd_sof_ipc;
109struct snd_sof_debugfs_map;
110struct snd_soc_tplg_ops;
111struct snd_soc_component;
112struct snd_sof_pdata;
113
114/*
115 * SOF DSP HW abstraction operations.
116 * Used to abstract DSP HW architecture and any IO busses between host CPU
117 * and DSP device(s).
118 */
119struct snd_sof_dsp_ops {
120
Keyon Jie7edb3052021-01-13 17:26:14 +0200121 /* probe/remove/shutdown */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500122 int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
123 int (*remove)(struct snd_sof_dev *sof_dev); /* optional */
Keyon Jie7edb3052021-01-13 17:26:14 +0200124 int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500125
126 /* DSP core boot / reset */
127 int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */
Fred Oha70eb702020-11-27 18:40:21 +0200128 int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500129 int (*reset)(struct snd_sof_dev *sof_dev); /* optional */
130 int (*core_power_up)(struct snd_sof_dev *sof_dev,
131 unsigned int core_mask); /* optional */
132 int (*core_power_down)(struct snd_sof_dev *sof_dev,
133 unsigned int core_mask); /* optional */
134
135 /*
136 * Register IO: only used by respective drivers themselves,
137 * TODO: consider removing these operations and calling respective
138 * implementations directly
139 */
140 void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
141 u32 value); /* optional */
142 u32 (*read)(struct snd_sof_dev *sof_dev,
143 void __iomem *addr); /* optional */
144 void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
145 u64 value); /* optional */
146 u64 (*read64)(struct snd_sof_dev *sof_dev,
147 void __iomem *addr); /* optional */
148
149 /* memcpy IO */
Peter Ujfalusi4624bb22021-09-15 15:21:11 +0300150 int (*block_read)(struct snd_sof_dev *sof_dev,
151 enum snd_sof_fw_blk_type type, u32 offset,
152 void *dest, size_t size); /* mandatory */
153 int (*block_write)(struct snd_sof_dev *sof_dev,
154 enum snd_sof_fw_blk_type type, u32 offset,
155 void *src, size_t size); /* mandatory */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500156
Daniel Balutaf71f59d2021-10-04 18:21:44 +0300157 /* Mailbox IO */
158 void (*mailbox_read)(struct snd_sof_dev *sof_dev,
159 u32 offset, void *dest,
160 size_t size); /* optional */
161 void (*mailbox_write)(struct snd_sof_dev *sof_dev,
162 u32 offset, void *src,
163 size_t size); /* optional */
164
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500165 /* doorbell */
166 irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
167 irqreturn_t (*irq_thread)(int irq, void *context); /* optional */
168
169 /* ipc */
170 int (*send_msg)(struct snd_sof_dev *sof_dev,
171 struct snd_sof_ipc_msg *msg); /* mandatory */
172
173 /* FW loading */
174 int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
175 int (*load_module)(struct snd_sof_dev *sof_dev,
176 struct snd_sof_mod_hdr *hdr); /* optional */
177 /*
178 * FW ready checks for ABI compatibility and creates
179 * memory windows at first boot
180 */
Ranjani Sridharan8692d492019-09-27 15:05:32 -0500181 int (*fw_ready)(struct snd_sof_dev *sdev, u32 msg_id); /* mandatory */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500182
183 /* connect pcm substream to a host stream */
184 int (*pcm_open)(struct snd_sof_dev *sdev,
185 struct snd_pcm_substream *substream); /* optional */
186 /* disconnect pcm substream to a host stream */
187 int (*pcm_close)(struct snd_sof_dev *sdev,
188 struct snd_pcm_substream *substream); /* optional */
189
190 /* host stream hw params */
191 int (*pcm_hw_params)(struct snd_sof_dev *sdev,
192 struct snd_pcm_substream *substream,
193 struct snd_pcm_hw_params *params,
194 struct sof_ipc_stream_params *ipc_params); /* optional */
195
Ranjani Sridharan93146bc2019-06-12 12:23:39 -0500196 /* host stream hw_free */
197 int (*pcm_hw_free)(struct snd_sof_dev *sdev,
198 struct snd_pcm_substream *substream); /* optional */
199
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500200 /* host stream trigger */
201 int (*pcm_trigger)(struct snd_sof_dev *sdev,
202 struct snd_pcm_substream *substream,
203 int cmd); /* optional */
204
205 /* host stream pointer */
206 snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
207 struct snd_pcm_substream *substream); /* optional */
208
Cezary Rojewskie145e9a2020-02-18 15:39:20 +0100209#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
210 /* Except for probe_pointer, all probe ops are mandatory */
211 int (*probe_assign)(struct snd_sof_dev *sdev,
212 struct snd_compr_stream *cstream,
213 struct snd_soc_dai *dai); /* mandatory */
214 int (*probe_free)(struct snd_sof_dev *sdev,
215 struct snd_compr_stream *cstream,
216 struct snd_soc_dai *dai); /* mandatory */
217 int (*probe_set_params)(struct snd_sof_dev *sdev,
218 struct snd_compr_stream *cstream,
219 struct snd_compr_params *params,
220 struct snd_soc_dai *dai); /* mandatory */
221 int (*probe_trigger)(struct snd_sof_dev *sdev,
222 struct snd_compr_stream *cstream, int cmd,
223 struct snd_soc_dai *dai); /* mandatory */
224 int (*probe_pointer)(struct snd_sof_dev *sdev,
225 struct snd_compr_stream *cstream,
226 struct snd_compr_tstamp *tstamp,
227 struct snd_soc_dai *dai); /* optional */
228#endif
229
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500230 /* host read DSP stream data */
Guennadi Liakhovetski6a0ba072021-09-28 13:35:16 +0300231 int (*ipc_msg_data)(struct snd_sof_dev *sdev,
232 struct snd_pcm_substream *substream,
233 void *p, size_t sz); /* mandatory */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500234
235 /* host configure DSP HW parameters */
236 int (*ipc_pcm_params)(struct snd_sof_dev *sdev,
237 struct snd_pcm_substream *substream,
238 const struct sof_ipc_pcm_params_reply *reply); /* mandatory */
239
240 /* pre/post firmware run */
241 int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
242 int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
243
Fred Ohe984f3ef2020-11-27 18:40:18 +0200244 /* parse platform specific extended manifest, optional */
245 int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev,
246 const struct sof_ext_man_elem_header *hdr);
247
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500248 /* DSP PM */
Ranjani Sridharan61e285c2020-01-29 16:07:22 -0600249 int (*suspend)(struct snd_sof_dev *sof_dev,
250 u32 target_state); /* optional */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500251 int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
Fred Oh1c38c922019-07-22 09:13:50 -0500252 int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500253 int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
Kai Vehmanen62fde972019-07-02 16:24:27 +0300254 int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
Ranjani Sridharan7077a072019-06-12 12:23:38 -0500255 int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
Keyon Jiee8f112d2019-10-25 17:40:59 -0500256 int (*set_power_state)(struct snd_sof_dev *sdev,
Ranjani Sridharan61e285c2020-01-29 16:07:22 -0600257 const struct sof_dsp_power_state *target_state); /* optional */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500258
259 /* DSP clocking */
260 int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
261
262 /* debug */
263 const struct snd_sof_debugfs_map *debug_map; /* optional */
264 int debug_map_count; /* optional */
265 void (*dbg_dump)(struct snd_sof_dev *sof_dev,
266 u32 flags); /* optional */
Pan Xiuli5e4a27f2019-04-30 18:09:32 -0500267 void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
Peter Ujfalusi07e833b2021-09-15 15:21:12 +0300268 int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
269 enum snd_sof_fw_blk_type blk_type, u32 offset,
270 size_t size, const char *name,
271 enum sof_debugfs_access_type access_type); /* optional */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500272
273 /* host DMA trace initialization */
274 int (*trace_init)(struct snd_sof_dev *sdev,
275 u32 *stream_tag); /* optional */
276 int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
277 int (*trace_trigger)(struct snd_sof_dev *sdev,
278 int cmd); /* optional */
279
Daniel Balutace8234a2019-07-22 09:13:47 -0500280 /* misc */
281 int (*get_bar_index)(struct snd_sof_dev *sdev,
282 u32 type); /* optional */
Daniel Balutabb9c93f2019-08-07 10:01:59 -0500283 int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
Daniel Balutae17422c2019-08-07 10:02:00 -0500284 int (*get_window_offset)(struct snd_sof_dev *sdev,
285 u32 id);/* mandatory for common loader code */
Daniel Balutabb9c93f2019-08-07 10:01:59 -0500286
Daniel Baluta285880a2019-12-04 15:15:53 -0600287 /* machine driver ops */
288 int (*machine_register)(struct snd_sof_dev *sdev,
289 void *pdata); /* optional */
290 void (*machine_unregister)(struct snd_sof_dev *sdev,
291 void *pdata); /* optional */
292 void (*machine_select)(struct snd_sof_dev *sdev); /* optional */
293 void (*set_mach_params)(const struct snd_soc_acpi_mach *mach,
Pierre-Louis Bossart17e9d6b2021-04-09 15:01:18 -0700294 struct snd_sof_dev *sdev); /* optional */
Daniel Baluta285880a2019-12-04 15:15:53 -0600295
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500296 /* DAI ops */
297 struct snd_soc_dai_driver *drv;
298 int num_drv;
Pierre-Louis Bossart27e322f2019-10-24 16:03:17 -0500299
300 /* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
301 u32 hw_info;
Pierre-Louis Bossart0f501c72019-12-17 14:22:30 -0600302
Peter Ujfalusi0ed66cb2021-09-16 16:03:08 +0300303 const struct dsp_arch_ops *dsp_arch_ops;
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500304};
305
306/* DSP architecture specific callbacks for oops and stack dumps */
Peter Ujfalusi0ed66cb2021-09-16 16:03:08 +0300307struct dsp_arch_ops {
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500308 void (*dsp_oops)(struct snd_sof_dev *sdev, void *oops);
309 void (*dsp_stack)(struct snd_sof_dev *sdev, void *oops,
310 u32 *stack, u32 stack_words);
311};
312
Peter Ujfalusi0ed66cb2021-09-16 16:03:08 +0300313#define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500314
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500315/* FS entry for debug files that can expose DSP memories, registers */
316struct snd_sof_dfsentry {
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500317 size_t size;
Karol Trzcinski5b10b622020-11-24 20:00:17 +0200318 size_t buf_data_size; /* length of buffered data for file read operation */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500319 enum sof_dfsentry_type type;
320 /*
321 * access_type specifies if the
322 * memory -> DSP resource (memory, register etc) is always accessible
323 * or if it is accessible only when the DSP is in D0.
324 */
325 enum sof_debugfs_access_type access_type;
Ranjani Sridharan091c12e2019-06-03 11:18:20 -0500326#if ENABLE_DEBUGFS_CACHEBUF
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500327 char *cache_buf; /* buffer to cache the contents of debugfs memory */
328#endif
329 struct snd_sof_dev *sdev;
330 struct list_head list; /* list in sdev dfsentry list */
331 union {
332 void __iomem *io_mem;
333 void *buf;
334 };
335};
336
337/* Debug mapping for any DSP memory or registers that can used for debug */
338struct snd_sof_debugfs_map {
339 const char *name;
340 u32 bar;
341 u32 offset;
342 u32 size;
343 /*
344 * access_type specifies if the memory is always accessible
345 * or if it is accessible only when the DSP is in D0.
346 */
347 enum sof_debugfs_access_type access_type;
348};
349
350/* mailbox descriptor, used for host <-> DSP IPC */
351struct snd_sof_mailbox {
352 u32 offset;
353 size_t size;
354};
355
356/* IPC message descriptor for host <-> DSP IO */
357struct snd_sof_ipc_msg {
358 /* message data */
359 u32 header;
360 void *msg_data;
361 void *reply_data;
362 size_t msg_size;
363 size_t reply_size;
364 int reply_error;
365
366 wait_queue_head_t waitq;
367 bool ipc_complete;
368};
369
Ranjani Sridharan6ca5cec2019-12-17 18:26:09 -0600370enum snd_sof_fw_state {
371 SOF_FW_BOOT_NOT_STARTED = 0,
372 SOF_FW_BOOT_PREPARE,
373 SOF_FW_BOOT_IN_PROGRESS,
374 SOF_FW_BOOT_FAILED,
375 SOF_FW_BOOT_READY_FAILED, /* firmware booted but fw_ready op failed */
376 SOF_FW_BOOT_COMPLETE,
377};
378
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500379/*
380 * SOF Device Level.
381 */
382struct snd_sof_dev {
383 struct device *dev;
384 spinlock_t ipc_lock; /* lock for IPC users */
385 spinlock_t hw_lock; /* lock for HW IO access */
386
387 /*
388 * ASoC components. plat_drv fields are set dynamically so
389 * can't use const
390 */
391 struct snd_soc_component_driver plat_drv;
392
Ranjani Sridharan61e285c2020-01-29 16:07:22 -0600393 /* current DSP power state */
394 struct sof_dsp_power_state dsp_power_state;
Keyon Jie8b66d7c2021-01-05 17:56:40 +0200395 /* mutex to protect the dsp_power_state access */
396 struct mutex power_state_access;
Ranjani Sridharan043ae132020-01-29 16:07:20 -0600397
398 /* Intended power target of system suspend */
399 enum sof_system_suspend_state system_suspend_target;
Keyon Jie4c190302019-10-25 17:40:57 -0500400
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500401 /* DSP firmware boot */
402 wait_queue_head_t boot_wait;
Ranjani Sridharan6ca5cec2019-12-17 18:26:09 -0600403 enum snd_sof_fw_state fw_state;
Guennadi Liakhovetskif738d812020-08-24 15:09:06 -0500404 bool first_boot;
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500405
406 /* work queue in case the probe is implemented in two steps */
407 struct work_struct probe_work;
Kai Vehmanen271d9372021-02-10 12:52:37 +0200408 bool probe_completed;
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500409
410 /* DSP HW differentiation */
411 struct snd_sof_pdata *pdata;
412
413 /* IPC */
414 struct snd_sof_ipc *ipc;
415 struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */
416 struct snd_sof_mailbox host_box; /* Host initiated IPC */
417 struct snd_sof_mailbox stream_box; /* Stream position update */
Iulian Olarue17b7382020-08-25 16:58:54 -0700418 struct snd_sof_mailbox debug_box; /* Debug info updates */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500419 struct snd_sof_ipc_msg *msg;
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500420 int ipc_irq;
421 u32 next_comp_id; /* monotonic - reset during S3 */
422
423 /* memory bases for mmaped DSPs - set by dsp_init() */
424 void __iomem *bar[SND_SOF_BARS]; /* DSP base address */
425 int mmio_bar;
426 int mailbox_bar;
427 size_t dsp_oops_offset;
428
429 /* debug */
430 struct dentry *debugfs_root;
431 struct list_head dfsentry_list;
Peter Ujfalusi9ff90852021-10-06 14:06:30 +0300432 bool dbg_dump_printed;
433 bool ipc_dump_printed;
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500434
435 /* firmware loader */
436 struct snd_dma_buffer dmab;
437 struct snd_dma_buffer dmab_bdl;
438 struct sof_ipc_fw_ready fw_ready;
439 struct sof_ipc_fw_version fw_version;
Karol Trzcinski59283952019-12-17 18:26:11 -0600440 struct sof_ipc_cc_version *cc_version;
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500441
442 /* topology */
443 struct snd_soc_tplg_ops *tplg_ops;
444 struct list_head pcm_list;
445 struct list_head kcontrol_list;
446 struct list_head widget_list;
447 struct list_head dai_list;
448 struct list_head route_list;
449 struct snd_soc_component *component;
450 u32 enabled_cores_mask; /* keep track of enabled cores */
451
452 /* FW configuration */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500453 struct sof_ipc_window *info_window;
454
455 /* IPC timeouts in ms */
456 int ipc_timeout;
457 int boot_timeout;
458
Cezary Rojewskie145e9a2020-02-18 15:39:20 +0100459#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
460 unsigned int extractor_stream_tag;
461#endif
462
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500463 /* DMA for Trace */
464 struct snd_dma_buffer dmatb;
465 struct snd_dma_buffer dmatp;
466 int dma_trace_pages;
467 wait_queue_head_t trace_sleep;
468 u32 host_offset;
Guennadi Liakhovetskif738d812020-08-24 15:09:06 -0500469 bool dtrace_is_supported; /* set with Kconfig or module parameter */
470 bool dtrace_is_enabled;
471 bool dtrace_error;
472 bool dtrace_draining;
Kai Vehmanenec9025e2019-05-24 14:23:06 -0500473
Guennadi Liakhovetski672ff5e2019-07-22 09:13:57 -0500474 bool msi_enabled;
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500475
476 void *private; /* core does not touch this */
477};
478
479/*
480 * Device Level.
481 */
482
483int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
484int snd_sof_device_remove(struct device *dev);
Keyon Jie7edb3052021-01-13 17:26:14 +0200485int snd_sof_device_shutdown(struct device *dev);
Kai Vehmanen271d9372021-02-10 12:52:37 +0200486bool snd_sof_device_probe_completed(struct device *dev);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500487
488int snd_sof_runtime_suspend(struct device *dev);
489int snd_sof_runtime_resume(struct device *dev);
Kai Vehmanen62fde972019-07-02 16:24:27 +0300490int snd_sof_runtime_idle(struct device *dev);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500491int snd_sof_resume(struct device *dev);
492int snd_sof_suspend(struct device *dev);
Marcin Rajwa3541aef2020-05-15 16:59:52 +0300493int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
Keyon Jie0b50b3b2019-10-25 17:41:17 -0500494int snd_sof_prepare(struct device *dev);
495void snd_sof_complete(struct device *dev);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500496
497void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
498
Ranjani Sridharan3e625792019-12-04 15:15:48 -0600499int snd_sof_create_page_table(struct device *dev,
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500500 struct snd_dma_buffer *dmab,
501 unsigned char *page_table, size_t size);
502
503/*
504 * Firmware loading.
505 */
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500506int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
507int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
508int snd_sof_run_firmware(struct snd_sof_dev *sdev);
509int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
510 struct snd_sof_mod_hdr *module);
511void snd_sof_fw_unload(struct snd_sof_dev *sdev);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500512
513/*
514 * IPC low level APIs.
515 */
516struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
517void snd_sof_ipc_free(struct snd_sof_dev *sdev);
Ranjani Sridharand7a1ed22020-05-26 15:36:37 -0500518void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500519void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev);
520int snd_sof_ipc_stream_pcm_params(struct snd_sof_dev *sdev,
521 struct sof_ipc_pcm_params *params);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500522int snd_sof_ipc_valid(struct snd_sof_dev *sdev);
523int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header,
524 void *msg_data, size_t msg_bytes, void *reply_data,
525 size_t reply_bytes);
Ranjani Sridharan63e51fd32020-01-29 16:07:25 -0600526int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header,
527 void *msg_data, size_t msg_bytes,
528 void *reply_data, size_t reply_bytes);
Rander Wangfebf5da2021-10-08 12:38:36 +0300529int sof_ipc_init_msg_memory(struct snd_sof_dev *sdev);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500530
531/*
532 * Trace/debug
533 */
534int snd_sof_init_trace(struct snd_sof_dev *sdev);
535void snd_sof_release_trace(struct snd_sof_dev *sdev);
536void snd_sof_free_trace(struct snd_sof_dev *sdev);
537int snd_sof_dbg_init(struct snd_sof_dev *sdev);
538void snd_sof_free_debug(struct snd_sof_dev *sdev);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500539int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
540 void *base, size_t size,
Ranjani Sridharan5c9714f2019-06-03 11:18:18 -0500541 const char *name, mode_t mode);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500542int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
543 struct sof_ipc_dma_trace_posn *posn);
544void snd_sof_trace_notify_for_error(struct snd_sof_dev *sdev);
545void snd_sof_get_status(struct snd_sof_dev *sdev, u32 panic_code,
546 u32 tracep_code, void *oops,
547 struct sof_ipc_panic_info *panic_info,
548 void *stack, size_t stack_words);
549int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev);
Liam Girdwood9a065082019-09-27 15:05:29 -0500550void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev);
Karol Trzcinski5b10b622020-11-24 20:00:17 +0200551int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
Peter Ujfalusi07e833b2021-09-15 15:21:12 +0300552int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
553 enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
554 const char *name, enum sof_debugfs_access_type access_type);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500555
556/*
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500557 * DSP Architectures.
558 */
559static inline void sof_stack(struct snd_sof_dev *sdev, void *oops, u32 *stack,
560 u32 stack_words)
561{
Peter Ujfalusi0ed66cb2021-09-16 16:03:08 +0300562 sof_dsp_arch_ops(sdev)->dsp_stack(sdev, oops, stack, stack_words);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500563}
564
565static inline void sof_oops(struct snd_sof_dev *sdev, void *oops)
566{
Peter Ujfalusi0ed66cb2021-09-16 16:03:08 +0300567 if (sof_dsp_arch_ops(sdev)->dsp_oops)
568 sof_dsp_arch_ops(sdev)->dsp_oops(sdev, oops);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500569}
570
Peter Ujfalusi0ed66cb2021-09-16 16:03:08 +0300571extern const struct dsp_arch_ops sof_xtensa_arch_ops;
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500572
573/*
Peter Ujfalusi58a5c9a2021-10-06 14:06:40 +0300574 * Firmware state tracking
575 */
576static inline void sof_set_fw_state(struct snd_sof_dev *sdev,
577 enum snd_sof_fw_state new_state)
578{
579 if (sdev->fw_state == new_state)
580 return;
581
582 dev_dbg(sdev->dev, "fw_state change: %d -> %d\n", sdev->fw_state, new_state);
583 sdev->fw_state = new_state;
584}
585
586/*
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500587 * Utilities
588 */
589void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
590void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
591u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
592u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
593void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
594 void *message, size_t bytes);
595void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
596 void *message, size_t bytes);
Peter Ujfalusi4624bb22021-09-15 15:21:11 +0300597int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
598 u32 offset, void *src, size_t size);
599int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
600 u32 offset, void *dest, size_t size);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500601
Daniel Baluta83ee7ab2019-08-07 10:02:01 -0500602int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id);
603
Bud Liviu-Alexandru97e22cb2021-10-04 18:21:45 +0300604int sof_ipc_msg_data(struct snd_sof_dev *sdev,
605 struct snd_pcm_substream *substream,
606 void *p, size_t sz);
607int sof_ipc_pcm_params(struct snd_sof_dev *sdev,
Guennadi Liakhovetski6a0ba072021-09-28 13:35:16 +0300608 struct snd_pcm_substream *substream,
Bud Liviu-Alexandru97e22cb2021-10-04 18:21:45 +0300609 const struct sof_ipc_pcm_params_reply *reply);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500610
Bud Liviu-Alexandru97e22cb2021-10-04 18:21:45 +0300611int sof_stream_pcm_open(struct snd_sof_dev *sdev,
612 struct snd_pcm_substream *substream);
613int sof_stream_pcm_close(struct snd_sof_dev *sdev,
614 struct snd_pcm_substream *substream);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500615
Daniel Baluta285880a2019-12-04 15:15:53 -0600616int sof_machine_check(struct snd_sof_dev *sdev);
Liam Girdwoodc16211d2019-04-12 11:05:06 -0500617#endif