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