1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /*
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * Copyright(c) 2018 Intel Corporation. All rights reserved.
7 *
8 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9 */
10
11 #ifndef __SOUND_SOC_SOF_PRIV_H
12 #define __SOUND_SOC_SOF_PRIV_H
13
14 #include <linux/device.h>
15 #include <sound/hdaudio.h>
16 #include <sound/sof.h>
17 #include <sound/sof/info.h>
18 #include <sound/sof/pm.h>
19 #include <sound/sof/trace.h>
20 #include <uapi/sound/sof/fw.h>
21 #include <sound/sof/ext_manifest.h>
22
23 struct snd_sof_pcm_stream;
24
25 /* Flag definitions used in sof_core_debug (sof_debug module parameter) */
26 #define SOF_DBG_ENABLE_TRACE BIT(0)
27 #define SOF_DBG_RETAIN_CTX BIT(1) /* prevent DSP D3 on FW exception */
28 #define SOF_DBG_VERIFY_TPLG BIT(2) /* verify topology during load */
29 #define SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE BIT(3) /* 0: use topology token
30 * 1: override topology
31 */
32 #define SOF_DBG_DYNAMIC_PIPELINES_ENABLE BIT(4) /* 0: use static pipelines
33 * 1: use dynamic pipelines
34 */
35 #define SOF_DBG_DISABLE_MULTICORE BIT(5) /* schedule all pipelines/widgets
36 * on primary core
37 */
38 #define SOF_DBG_PRINT_ALL_DUMPS BIT(6) /* Print all ipc and dsp dumps */
39 #define SOF_DBG_IGNORE_D3_PERSISTENT BIT(7) /* ignore the DSP D3 persistent capability
40 * and always download firmware upon D3 exit
41 */
42 #define SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS BIT(8) /* print DMA position updates
43 * in dmesg logs
44 */
45 #define SOF_DBG_PRINT_IPC_SUCCESS_LOGS BIT(9) /* print IPC success
46 * in dmesg logs
47 */
48 #define SOF_DBG_FORCE_NOCODEC BIT(10) /* ignore all codec-related
49 * configurations
50 */
51
52 /* Flag definitions used for controlling the DSP dump behavior */
53 #define SOF_DBG_DUMP_REGS BIT(0)
54 #define SOF_DBG_DUMP_MBOX BIT(1)
55 #define SOF_DBG_DUMP_TEXT BIT(2)
56 #define SOF_DBG_DUMP_PCI BIT(3)
57 /* Output this dump (at the DEBUG level) only when SOF_DBG_PRINT_ALL_DUMPS is set */
58 #define SOF_DBG_DUMP_OPTIONAL BIT(4)
59
60 /* global debug state set by SOF_DBG_ flags */
61 bool sof_debug_check_flag(int mask);
62
63 /* max BARs mmaped devices can use */
64 #define SND_SOF_BARS 8
65
66 /* time in ms for runtime suspend delay */
67 #define SND_SOF_SUSPEND_DELAY_MS 2000
68
69 /* DMA buffer size for trace */
70 #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16)
71
72 #define SOF_IPC_DSP_REPLY 0
73 #define SOF_IPC_HOST_REPLY 1
74
75 /* convenience constructor for DAI driver streams */
76 #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \
77 {.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \
78 .rates = srates, .formats = sfmt}
79
80 #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
81 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
82
83 /* So far the primary core on all DSPs has ID 0 */
84 #define SOF_DSP_PRIMARY_CORE 0
85
86 /* max number of DSP cores */
87 #define SOF_MAX_DSP_NUM_CORES 8
88
89 struct sof_dsp_power_state {
90 u32 state;
91 u32 substate; /* platform-specific */
92 };
93
94 /* System suspend target state */
95 enum sof_system_suspend_state {
96 SOF_SUSPEND_NONE = 0,
97 SOF_SUSPEND_S0IX,
98 SOF_SUSPEND_S3,
99 SOF_SUSPEND_S4,
100 SOF_SUSPEND_S5,
101 };
102
103 enum sof_dfsentry_type {
104 SOF_DFSENTRY_TYPE_IOMEM = 0,
105 SOF_DFSENTRY_TYPE_BUF,
106 };
107
108 enum sof_debugfs_access_type {
109 SOF_DEBUGFS_ACCESS_ALWAYS = 0,
110 SOF_DEBUGFS_ACCESS_D0_ONLY,
111 };
112
113 struct sof_compr_stream {
114 u64 copied_total;
115 u32 sampling_rate;
116 u16 channels;
117 u16 sample_container_bytes;
118 size_t posn_offset;
119 };
120
121 struct snd_sof_dev;
122 struct snd_sof_ipc_msg;
123 struct snd_sof_ipc;
124 struct snd_sof_debugfs_map;
125 struct snd_soc_tplg_ops;
126 struct snd_soc_component;
127 struct snd_sof_pdata;
128
129 /**
130 * struct snd_sof_platform_stream_params - platform dependent stream parameters
131 * @stream_tag: Stream tag to use
132 * @use_phy_addr: Use the provided @phy_addr for configuration
133 * @phy_addr: Platform dependent address to be used, if @use_phy_addr
134 * is true
135 * @no_ipc_position: Disable position update IPC from firmware
136 */
137 struct snd_sof_platform_stream_params {
138 u16 stream_tag;
139 bool use_phy_address;
140 u32 phy_addr;
141 bool no_ipc_position;
142 bool cont_update_posn;
143 };
144
145 /**
146 * struct sof_firmware - Container struct for SOF firmware
147 * @fw: Pointer to the firmware
148 * @payload_offset: Offset of the data within the loaded firmware image to be
149 * loaded to the DSP (skipping for example ext_manifest section)
150 */
151 struct sof_firmware {
152 const struct firmware *fw;
153 u32 payload_offset;
154 };
155
156 /*
157 * SOF DSP HW abstraction operations.
158 * Used to abstract DSP HW architecture and any IO busses between host CPU
159 * and DSP device(s).
160 */
161 struct snd_sof_dsp_ops {
162
163 /* probe/remove/shutdown */
164 int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
165 int (*remove)(struct snd_sof_dev *sof_dev); /* optional */
166 int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */
167
168 /* DSP core boot / reset */
169 int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */
170 int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */
171 int (*reset)(struct snd_sof_dev *sof_dev); /* optional */
172 int (*core_get)(struct snd_sof_dev *sof_dev, int core); /* optional */
173 int (*core_put)(struct snd_sof_dev *sof_dev, int core); /* optional */
174
175 /*
176 * Register IO: only used by respective drivers themselves,
177 * TODO: consider removing these operations and calling respective
178 * implementations directly
179 */
180 void (*write8)(struct snd_sof_dev *sof_dev, void __iomem *addr,
181 u8 value); /* optional */
182 u8 (*read8)(struct snd_sof_dev *sof_dev,
183 void __iomem *addr); /* optional */
184 void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
185 u32 value); /* optional */
186 u32 (*read)(struct snd_sof_dev *sof_dev,
187 void __iomem *addr); /* optional */
188 void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
189 u64 value); /* optional */
190 u64 (*read64)(struct snd_sof_dev *sof_dev,
191 void __iomem *addr); /* optional */
192
193 /* memcpy IO */
194 int (*block_read)(struct snd_sof_dev *sof_dev,
195 enum snd_sof_fw_blk_type type, u32 offset,
196 void *dest, size_t size); /* mandatory */
197 int (*block_write)(struct snd_sof_dev *sof_dev,
198 enum snd_sof_fw_blk_type type, u32 offset,
199 void *src, size_t size); /* mandatory */
200
201 /* Mailbox IO */
202 void (*mailbox_read)(struct snd_sof_dev *sof_dev,
203 u32 offset, void *dest,
204 size_t size); /* optional */
205 void (*mailbox_write)(struct snd_sof_dev *sof_dev,
206 u32 offset, void *src,
207 size_t size); /* optional */
208
209 /* doorbell */
210 irqreturn_t (*irq_handler)(int irq, void *context); /* optional */
211 irqreturn_t (*irq_thread)(int irq, void *context); /* optional */
212
213 /* ipc */
214 int (*send_msg)(struct snd_sof_dev *sof_dev,
215 struct snd_sof_ipc_msg *msg); /* mandatory */
216
217 /* FW loading */
218 int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
219 int (*load_module)(struct snd_sof_dev *sof_dev,
220 struct snd_sof_mod_hdr *hdr); /* optional */
221
222 /* connect pcm substream to a host stream */
223 int (*pcm_open)(struct snd_sof_dev *sdev,
224 struct snd_pcm_substream *substream); /* optional */
225 /* disconnect pcm substream to a host stream */
226 int (*pcm_close)(struct snd_sof_dev *sdev,
227 struct snd_pcm_substream *substream); /* optional */
228
229 /* host stream hw params */
230 int (*pcm_hw_params)(struct snd_sof_dev *sdev,
231 struct snd_pcm_substream *substream,
232 struct snd_pcm_hw_params *params,
233 struct snd_sof_platform_stream_params *platform_params); /* optional */
234
235 /* host stream hw_free */
236 int (*pcm_hw_free)(struct snd_sof_dev *sdev,
237 struct snd_pcm_substream *substream); /* optional */
238
239 /* host stream trigger */
240 int (*pcm_trigger)(struct snd_sof_dev *sdev,
241 struct snd_pcm_substream *substream,
242 int cmd); /* optional */
243
244 /* host stream pointer */
245 snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
246 struct snd_pcm_substream *substream); /* optional */
247
248 /* pcm ack */
249 int (*pcm_ack)(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream); /* optional */
250
251 /*
252 * optional callback to retrieve the link DMA position for the substream
253 * when the position is not reported in the shared SRAM windows but
254 * instead from a host-accessible hardware counter.
255 */
256 u64 (*get_stream_position)(struct snd_sof_dev *sdev,
257 struct snd_soc_component *component,
258 struct snd_pcm_substream *substream); /* optional */
259
260 /* host read DSP stream data */
261 int (*ipc_msg_data)(struct snd_sof_dev *sdev,
262 struct snd_sof_pcm_stream *sps,
263 void *p, size_t sz); /* mandatory */
264
265 /* host side configuration of the stream's data offset in stream mailbox area */
266 int (*set_stream_data_offset)(struct snd_sof_dev *sdev,
267 struct snd_sof_pcm_stream *sps,
268 size_t posn_offset); /* optional */
269
270 /* pre/post firmware run */
271 int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
272 int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */
273
274 /* parse platform specific extended manifest, optional */
275 int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev,
276 const struct sof_ext_man_elem_header *hdr);
277
278 /* DSP PM */
279 int (*suspend)(struct snd_sof_dev *sof_dev,
280 u32 target_state); /* optional */
281 int (*resume)(struct snd_sof_dev *sof_dev); /* optional */
282 int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */
283 int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */
284 int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */
285 int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */
286 int (*set_power_state)(struct snd_sof_dev *sdev,
287 const struct sof_dsp_power_state *target_state); /* optional */
288
289 /* DSP clocking */
290 int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */
291
292 /* debug */
293 const struct snd_sof_debugfs_map *debug_map; /* optional */
294 int debug_map_count; /* optional */
295 void (*dbg_dump)(struct snd_sof_dev *sof_dev,
296 u32 flags); /* optional */
297 void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */
298 int (*debugfs_add_region_item)(struct snd_sof_dev *sdev,
299 enum snd_sof_fw_blk_type blk_type, u32 offset,
300 size_t size, const char *name,
301 enum sof_debugfs_access_type access_type); /* optional */
302
303 /* host DMA trace (IPC3) */
304 int (*trace_init)(struct snd_sof_dev *sdev,
305 struct snd_dma_buffer *dmatb,
306 struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */
307 int (*trace_release)(struct snd_sof_dev *sdev); /* optional */
308 int (*trace_trigger)(struct snd_sof_dev *sdev,
309 int cmd); /* optional */
310
311 /* misc */
312 int (*get_bar_index)(struct snd_sof_dev *sdev,
313 u32 type); /* optional */
314 int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */
315 int (*get_window_offset)(struct snd_sof_dev *sdev,
316 u32 id);/* mandatory for common loader code */
317
318 /* machine driver ops */
319 int (*machine_register)(struct snd_sof_dev *sdev,
320 void *pdata); /* optional */
321 void (*machine_unregister)(struct snd_sof_dev *sdev,
322 void *pdata); /* optional */
323 struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */
324 void (*set_mach_params)(struct snd_soc_acpi_mach *mach,
325 struct snd_sof_dev *sdev); /* optional */
326
327 /* IPC client ops */
328 int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
329 void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */
330
331 /* DAI ops */
332 struct snd_soc_dai_driver *drv;
333 int num_drv;
334
335 /* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */
336 u32 hw_info;
337
338 const struct dsp_arch_ops *dsp_arch_ops;
339 };
340
341 /* DSP architecture specific callbacks for oops and stack dumps */
342 struct dsp_arch_ops {
343 void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops);
344 void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops,
345 u32 *stack, u32 stack_words);
346 };
347
348 #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops)
349
350 /* FS entry for debug files that can expose DSP memories, registers */
351 struct snd_sof_dfsentry {
352 size_t size;
353 size_t buf_data_size; /* length of buffered data for file read operation */
354 enum sof_dfsentry_type type;
355 /*
356 * access_type specifies if the
357 * memory -> DSP resource (memory, register etc) is always accessible
358 * or if it is accessible only when the DSP is in D0.
359 */
360 enum sof_debugfs_access_type access_type;
361 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE)
362 char *cache_buf; /* buffer to cache the contents of debugfs memory */
363 #endif
364 struct snd_sof_dev *sdev;
365 struct list_head list; /* list in sdev dfsentry list */
366 union {
367 void __iomem *io_mem;
368 void *buf;
369 };
370 };
371
372 /* Debug mapping for any DSP memory or registers that can used for debug */
373 struct snd_sof_debugfs_map {
374 const char *name;
375 u32 bar;
376 u32 offset;
377 u32 size;
378 /*
379 * access_type specifies if the memory is always accessible
380 * or if it is accessible only when the DSP is in D0.
381 */
382 enum sof_debugfs_access_type access_type;
383 };
384
385 /* mailbox descriptor, used for host <-> DSP IPC */
386 struct snd_sof_mailbox {
387 u32 offset;
388 size_t size;
389 };
390
391 /* IPC message descriptor for host <-> DSP IO */
392 struct snd_sof_ipc_msg {
393 /* message data */
394 void *msg_data;
395 void *reply_data;
396 size_t msg_size;
397 size_t reply_size;
398 int reply_error;
399
400 /* notification, firmware initiated messages */
401 void *rx_data;
402
403 wait_queue_head_t waitq;
404 bool ipc_complete;
405 };
406
407 /**
408 * struct sof_ipc_fw_tracing_ops - IPC-specific firmware tracing ops
409 * @init: Function pointer for initialization of the tracing
410 * @free: Optional function pointer for freeing of the tracing
411 * @fw_crashed: Optional function pointer to notify the tracing of a firmware crash
412 * @suspend: Function pointer for system/runtime suspend
413 * @resume: Function pointer for system/runtime resume
414 */
415 struct sof_ipc_fw_tracing_ops {
416 int (*init)(struct snd_sof_dev *sdev);
417 void (*free)(struct snd_sof_dev *sdev);
418 void (*fw_crashed)(struct snd_sof_dev *sdev);
419 void (*suspend)(struct snd_sof_dev *sdev, pm_message_t pm_state);
420 int (*resume)(struct snd_sof_dev *sdev);
421 };
422
423 /**
424 * struct sof_ipc_pm_ops - IPC-specific PM ops
425 * @ctx_save: Optional function pointer for context save
426 * @ctx_restore: Optional function pointer for context restore
427 * @set_core_state: Optional function pointer for turning on/off a DSP core
428 * @set_pm_gate: Optional function pointer for pm gate settings
429 */
430 struct sof_ipc_pm_ops {
431 int (*ctx_save)(struct snd_sof_dev *sdev);
432 int (*ctx_restore)(struct snd_sof_dev *sdev);
433 int (*set_core_state)(struct snd_sof_dev *sdev, int core_idx, bool on);
434 int (*set_pm_gate)(struct snd_sof_dev *sdev, u32 flags);
435 };
436
437 /**
438 * struct sof_ipc_fw_loader_ops - IPC/FW-specific loader ops
439 * @validate: Function pointer for validating the firmware image
440 * @parse_ext_manifest: Function pointer for parsing the manifest of the firmware
441 * @load_fw_to_dsp: Optional function pointer for loading the firmware to the
442 * DSP.
443 * The function implements generic, hardware independent way
444 * of loading the initial firmware and its modules (if any).
445 */
446 struct sof_ipc_fw_loader_ops {
447 int (*validate)(struct snd_sof_dev *sdev);
448 size_t (*parse_ext_manifest)(struct snd_sof_dev *sdev);
449 int (*load_fw_to_dsp)(struct snd_sof_dev *sdev);
450 };
451
452 struct sof_ipc_tplg_ops;
453 struct sof_ipc_pcm_ops;
454
455 /**
456 * struct sof_ipc_ops - IPC-specific ops
457 * @tplg: Pointer to IPC-specific topology ops
458 * @pm: Pointer to PM ops
459 * @pcm: Pointer to PCM ops
460 * @fw_loader: Pointer to Firmware Loader ops
461 * @fw_tracing: Optional pointer to Firmware tracing ops
462 *
463 * @init: Optional pointer for IPC related initialization
464 * @exit: Optional pointer for IPC related cleanup
465 * @post_fw_boot: Optional pointer to execute IPC related tasks after firmware
466 * boot.
467 *
468 * @tx_msg: Function pointer for sending a 'short' IPC message
469 * @set_get_data: Function pointer for set/get data ('large' IPC message). This
470 * function may split up the 'large' message and use the @tx_msg
471 * path to transfer individual chunks, or use other means to transfer
472 * the message.
473 * @get_reply: Function pointer for fetching the reply to
474 * sdev->ipc->msg.reply_data
475 * @rx_msg: Function pointer for handling a received message
476 *
477 * Note: both @tx_msg and @set_get_data considered as TX functions and they are
478 * serialized for the duration of the instructed transfer. A large message sent
479 * via @set_get_data is a single transfer even if at the hardware level it is
480 * handled with multiple chunks.
481 */
482 struct sof_ipc_ops {
483 const struct sof_ipc_tplg_ops *tplg;
484 const struct sof_ipc_pm_ops *pm;
485 const struct sof_ipc_pcm_ops *pcm;
486 const struct sof_ipc_fw_loader_ops *fw_loader;
487 const struct sof_ipc_fw_tracing_ops *fw_tracing;
488
489 int (*init)(struct snd_sof_dev *sdev);
490 void (*exit)(struct snd_sof_dev *sdev);
491 int (*post_fw_boot)(struct snd_sof_dev *sdev);
492
493 int (*tx_msg)(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
494 void *reply_data, size_t reply_bytes, bool no_pm);
495 int (*set_get_data)(struct snd_sof_dev *sdev, void *data, size_t data_bytes,
496 bool set);
497 int (*get_reply)(struct snd_sof_dev *sdev);
498 void (*rx_msg)(struct snd_sof_dev *sdev);
499 };
500
501 /* SOF generic IPC data */
502 struct snd_sof_ipc {
503 struct snd_sof_dev *sdev;
504
505 /* protects messages and the disable flag */
506 struct mutex tx_mutex;
507 /* disables further sending of ipc's */
508 bool disable_ipc_tx;
509
510 /* Maximum allowed size of a single IPC message/reply */
511 size_t max_payload_size;
512
513 struct snd_sof_ipc_msg msg;
514
515 /* IPC ops based on version */
516 const struct sof_ipc_ops *ops;
517 };
518
519 /* Helper to retrieve the IPC ops */
520 #define sof_ipc_get_ops(sdev, ops_name) \
521 (((sdev)->ipc && (sdev)->ipc->ops) ? (sdev)->ipc->ops->ops_name : NULL)
522
523 /*
524 * SOF Device Level.
525 */
526 struct snd_sof_dev {
527 struct device *dev;
528 spinlock_t ipc_lock; /* lock for IPC users */
529 spinlock_t hw_lock; /* lock for HW IO access */
530
531 /* Main, Base firmware image */
532 struct sof_firmware basefw;
533
534 /*
535 * ASoC components. plat_drv fields are set dynamically so
536 * can't use const
537 */
538 struct snd_soc_component_driver plat_drv;
539
540 /* current DSP power state */
541 struct sof_dsp_power_state dsp_power_state;
542 /* mutex to protect the dsp_power_state access */
543 struct mutex power_state_access;
544
545 /* Intended power target of system suspend */
546 enum sof_system_suspend_state system_suspend_target;
547
548 /* DSP firmware boot */
549 wait_queue_head_t boot_wait;
550 enum sof_fw_state fw_state;
551 bool first_boot;
552
553 /* work queue in case the probe is implemented in two steps */
554 struct work_struct probe_work;
555 bool probe_completed;
556
557 /* DSP HW differentiation */
558 struct snd_sof_pdata *pdata;
559
560 /* IPC */
561 struct snd_sof_ipc *ipc;
562 struct snd_sof_mailbox fw_info_box; /* FW shared memory */
563 struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */
564 struct snd_sof_mailbox host_box; /* Host initiated IPC */
565 struct snd_sof_mailbox stream_box; /* Stream position update */
566 struct snd_sof_mailbox debug_box; /* Debug info updates */
567 struct snd_sof_ipc_msg *msg;
568 int ipc_irq;
569 u32 next_comp_id; /* monotonic - reset during S3 */
570
571 /* memory bases for mmaped DSPs - set by dsp_init() */
572 void __iomem *bar[SND_SOF_BARS]; /* DSP base address */
573 int mmio_bar;
574 int mailbox_bar;
575 size_t dsp_oops_offset;
576
577 /* debug */
578 struct dentry *debugfs_root;
579 struct list_head dfsentry_list;
580 bool dbg_dump_printed;
581 bool ipc_dump_printed;
582
583 /* firmware loader */
584 struct sof_ipc_fw_ready fw_ready;
585 struct sof_ipc_fw_version fw_version;
586 struct sof_ipc_cc_version *cc_version;
587
588 /* topology */
589 struct snd_soc_tplg_ops *tplg_ops;
590 struct list_head pcm_list;
591 struct list_head kcontrol_list;
592 struct list_head widget_list;
593 struct list_head pipeline_list;
594 struct list_head dai_list;
595 struct list_head dai_link_list;
596 struct list_head route_list;
597 struct snd_soc_component *component;
598 u32 enabled_cores_mask; /* keep track of enabled cores */
599 bool led_present;
600
601 /* FW configuration */
602 struct sof_ipc_window *info_window;
603
604 /* IPC timeouts in ms */
605 int ipc_timeout;
606 int boot_timeout;
607
608 /* firmwre tracing */
609 bool fw_trace_is_supported; /* set with Kconfig or module parameter */
610 void *fw_trace_data; /* private data used by firmware tracing implementation */
611
612 bool msi_enabled;
613
614 /* DSP core context */
615 u32 num_cores;
616
617 /*
618 * ref count per core that will be modified during system suspend/resume and during pcm
619 * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
620 * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
621 * sound/core/ when streams are active and during system suspend/resume, streams are
622 * already suspended.
623 */
624 int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
625
626 /*
627 * Used to keep track of registered IPC client devices so that they can
628 * be removed when the parent SOF module is removed.
629 */
630 struct list_head ipc_client_list;
631
632 /* mutex to protect client list */
633 struct mutex ipc_client_mutex;
634
635 /*
636 * Used for tracking the IPC client's RX registration for DSP initiated
637 * message handling.
638 */
639 struct list_head ipc_rx_handler_list;
640
641 /*
642 * Used for tracking the IPC client's registration for DSP state change
643 * notification
644 */
645 struct list_head fw_state_handler_list;
646
647 /* to protect the ipc_rx_handler_list and dsp_state_handler_list list */
648 struct mutex client_event_handler_mutex;
649
650 /* quirks to override topology values */
651 bool mclk_id_override;
652 u16 mclk_id_quirk; /* same size as in IPC3 definitions */
653
654 void *private; /* core does not touch this */
655 };
656
657 /*
658 * Device Level.
659 */
660
661 int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
662 int snd_sof_device_remove(struct device *dev);
663 int snd_sof_device_shutdown(struct device *dev);
664 bool snd_sof_device_probe_completed(struct device *dev);
665
666 int snd_sof_runtime_suspend(struct device *dev);
667 int snd_sof_runtime_resume(struct device *dev);
668 int snd_sof_runtime_idle(struct device *dev);
669 int snd_sof_resume(struct device *dev);
670 int snd_sof_suspend(struct device *dev);
671 int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev);
672 int snd_sof_prepare(struct device *dev);
673 void snd_sof_complete(struct device *dev);
674
675 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
676
677 /*
678 * Compress support
679 */
680 extern struct snd_compress_ops sof_compressed_ops;
681
682 /*
683 * Firmware loading.
684 */
685 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
686 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
687 int snd_sof_run_firmware(struct snd_sof_dev *sdev);
688 void snd_sof_fw_unload(struct snd_sof_dev *sdev);
689
690 /*
691 * IPC low level APIs.
692 */
693 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
694 void snd_sof_ipc_free(struct snd_sof_dev *sdev);
695 void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev);
696 void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
snd_sof_ipc_msgs_rx(struct snd_sof_dev * sdev)697 static inline void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
698 {
699 sdev->ipc->ops->rx_msg(sdev);
700 }
701 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
702 void *reply_data, size_t reply_bytes);
703 int sof_ipc_set_get_data(struct snd_sof_ipc *ipc, void *msg_data,
704 size_t msg_bytes, bool set);
705 int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
706 void *reply_data, size_t reply_bytes);
707 int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
708 size_t reply_bytes);
709
snd_sof_ipc_process_reply(struct snd_sof_dev * sdev,u32 msg_id)710 static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id)
711 {
712 snd_sof_ipc_get_reply(sdev);
713 snd_sof_ipc_reply(sdev, msg_id);
714 }
715
716 /*
717 * Trace/debug
718 */
719 int snd_sof_dbg_init(struct snd_sof_dev *sdev);
720 void snd_sof_free_debug(struct snd_sof_dev *sdev);
721 int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
722 void *base, size_t size,
723 const char *name, mode_t mode);
724 void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
725 u32 panic_code, u32 tracep_code, void *oops,
726 struct sof_ipc_panic_info *panic_info,
727 void *stack, size_t stack_words);
728 void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev, const char *msg);
729 int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev);
730 int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev,
731 enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
732 const char *name, enum sof_debugfs_access_type access_type);
733 /* Firmware tracing */
734 int sof_fw_trace_init(struct snd_sof_dev *sdev);
735 void sof_fw_trace_free(struct snd_sof_dev *sdev);
736 void sof_fw_trace_fw_crashed(struct snd_sof_dev *sdev);
737 void sof_fw_trace_suspend(struct snd_sof_dev *sdev, pm_message_t pm_state);
738 int sof_fw_trace_resume(struct snd_sof_dev *sdev);
739
740 /*
741 * DSP Architectures.
742 */
sof_stack(struct snd_sof_dev * sdev,const char * level,void * oops,u32 * stack,u32 stack_words)743 static inline void sof_stack(struct snd_sof_dev *sdev, const char *level,
744 void *oops, u32 *stack, u32 stack_words)
745 {
746 sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level, oops, stack,
747 stack_words);
748 }
749
sof_oops(struct snd_sof_dev * sdev,const char * level,void * oops)750 static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
751 {
752 if (sof_dsp_arch_ops(sdev)->dsp_oops)
753 sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops);
754 }
755
756 extern const struct dsp_arch_ops sof_xtensa_arch_ops;
757
758 /*
759 * Firmware state tracking
760 */
761 void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state);
762
763 /*
764 * Utilities
765 */
766 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
767 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
768 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
769 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
770 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
771 void *message, size_t bytes);
772 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
773 void *message, size_t bytes);
774 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
775 u32 offset, void *src, size_t size);
776 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
777 u32 offset, void *dest, size_t size);
778
779 int sof_ipc_msg_data(struct snd_sof_dev *sdev,
780 struct snd_sof_pcm_stream *sps,
781 void *p, size_t sz);
782 int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
783 struct snd_sof_pcm_stream *sps,
784 size_t posn_offset);
785
786 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
787 struct snd_pcm_substream *substream);
788 int sof_stream_pcm_close(struct snd_sof_dev *sdev,
789 struct snd_pcm_substream *substream);
790
791 int sof_machine_check(struct snd_sof_dev *sdev);
792
793 /* SOF client support */
794 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT)
795 int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
796 const void *data, size_t size);
797 void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id);
798 int sof_register_clients(struct snd_sof_dev *sdev);
799 void sof_unregister_clients(struct snd_sof_dev *sdev);
800 void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf);
801 void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev);
802 int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state);
803 int sof_resume_clients(struct snd_sof_dev *sdev);
804 #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)805 static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name,
806 u32 id, const void *data, size_t size)
807 {
808 return 0;
809 }
810
sof_client_dev_unregister(struct snd_sof_dev * sdev,const char * name,u32 id)811 static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev,
812 const char *name, u32 id)
813 {
814 }
815
sof_register_clients(struct snd_sof_dev * sdev)816 static inline int sof_register_clients(struct snd_sof_dev *sdev)
817 {
818 return 0;
819 }
820
sof_unregister_clients(struct snd_sof_dev * sdev)821 static inline void sof_unregister_clients(struct snd_sof_dev *sdev)
822 {
823 }
824
sof_client_ipc_rx_dispatcher(struct snd_sof_dev * sdev,void * msg_buf)825 static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
826 {
827 }
828
sof_client_fw_state_dispatcher(struct snd_sof_dev * sdev)829 static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
830 {
831 }
832
sof_suspend_clients(struct snd_sof_dev * sdev,pm_message_t state)833 static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
834 {
835 return 0;
836 }
837
sof_resume_clients(struct snd_sof_dev * sdev)838 static inline int sof_resume_clients(struct snd_sof_dev *sdev)
839 {
840 return 0;
841 }
842 #endif /* CONFIG_SND_SOC_SOF_CLIENT */
843
844 /* Main ops for IPC implementations */
845 extern const struct sof_ipc_ops ipc3_ops;
846 extern const struct sof_ipc_ops ipc4_ops;
847
848 #endif
849