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