This source file includes following definitions.
- snd_sof_find_spcm_dai
- sof_stack
- sof_oops
1
2
3
4
5
6
7
8
9
10
11 #ifndef __SOUND_SOC_SOF_PRIV_H
12 #define __SOUND_SOC_SOF_PRIV_H
13
14 #include <linux/device.h>
15
16 #include <sound/hdaudio.h>
17 #include <sound/soc.h>
18
19 #include <sound/sof.h>
20 #include <sound/sof/stream.h>
21 #include <sound/sof/control.h>
22 #include <sound/sof/dai.h>
23 #include <sound/sof/info.h>
24 #include <sound/sof/pm.h>
25 #include <sound/sof/topology.h>
26 #include <sound/sof/trace.h>
27
28 #include <uapi/sound/sof/fw.h>
29
30
31 #define SOF_DBG_REGS BIT(1)
32 #define SOF_DBG_MBOX BIT(2)
33 #define SOF_DBG_TEXT BIT(3)
34 #define SOF_DBG_PCI BIT(4)
35
36
37 #define SND_SOF_BARS 8
38
39
40 #define SND_SOF_SUSPEND_DELAY_MS 2000
41
42
43 #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16)
44
45
46 #define SOF_BE_PCM_BASE 16
47
48 #define SOF_IPC_DSP_REPLY 0
49 #define SOF_IPC_HOST_REPLY 1
50
51
52 #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \
53 {.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \
54 .rates = srates, .formats = sfmt}
55
56 #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \
57 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT)
58
59 #define ENABLE_DEBUGFS_CACHEBUF \
60 (IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE) || \
61 IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST))
62
63 #define DMA_CHAN_INVALID 0xFFFFFFFF
64
65 struct snd_sof_dev;
66 struct snd_sof_ipc_msg;
67 struct snd_sof_ipc;
68 struct snd_sof_debugfs_map;
69 struct snd_soc_tplg_ops;
70 struct snd_soc_component;
71 struct snd_sof_pdata;
72
73
74
75
76
77
78 struct snd_sof_dsp_ops {
79
80
81 int (*probe)(struct snd_sof_dev *sof_dev);
82 int (*remove)(struct snd_sof_dev *sof_dev);
83
84
85 int (*run)(struct snd_sof_dev *sof_dev);
86 int (*stall)(struct snd_sof_dev *sof_dev);
87 int (*reset)(struct snd_sof_dev *sof_dev);
88 int (*core_power_up)(struct snd_sof_dev *sof_dev,
89 unsigned int core_mask);
90 int (*core_power_down)(struct snd_sof_dev *sof_dev,
91 unsigned int core_mask);
92
93
94
95
96
97
98 void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr,
99 u32 value);
100 u32 (*read)(struct snd_sof_dev *sof_dev,
101 void __iomem *addr);
102 void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr,
103 u64 value);
104 u64 (*read64)(struct snd_sof_dev *sof_dev,
105 void __iomem *addr);
106
107
108 void (*block_read)(struct snd_sof_dev *sof_dev, u32 bar,
109 u32 offset, void *dest,
110 size_t size);
111 void (*block_write)(struct snd_sof_dev *sof_dev, u32 bar,
112 u32 offset, void *src,
113 size_t size);
114
115
116 irqreturn_t (*irq_handler)(int irq, void *context);
117 irqreturn_t (*irq_thread)(int irq, void *context);
118
119
120 int (*send_msg)(struct snd_sof_dev *sof_dev,
121 struct snd_sof_ipc_msg *msg);
122
123
124 int (*load_firmware)(struct snd_sof_dev *sof_dev);
125 int (*load_module)(struct snd_sof_dev *sof_dev,
126 struct snd_sof_mod_hdr *hdr);
127
128
129
130
131 int (*fw_ready)(struct snd_sof_dev *sdev, u32 msg_id);
132
133
134 int (*pcm_open)(struct snd_sof_dev *sdev,
135 struct snd_pcm_substream *substream);
136
137 int (*pcm_close)(struct snd_sof_dev *sdev,
138 struct snd_pcm_substream *substream);
139
140
141 int (*pcm_hw_params)(struct snd_sof_dev *sdev,
142 struct snd_pcm_substream *substream,
143 struct snd_pcm_hw_params *params,
144 struct sof_ipc_stream_params *ipc_params);
145
146
147 int (*pcm_hw_free)(struct snd_sof_dev *sdev,
148 struct snd_pcm_substream *substream);
149
150
151 int (*pcm_trigger)(struct snd_sof_dev *sdev,
152 struct snd_pcm_substream *substream,
153 int cmd);
154
155
156 snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
157 struct snd_pcm_substream *substream);
158
159
160 void (*ipc_msg_data)(struct snd_sof_dev *sdev,
161 struct snd_pcm_substream *substream,
162 void *p, size_t sz);
163
164
165 int (*ipc_pcm_params)(struct snd_sof_dev *sdev,
166 struct snd_pcm_substream *substream,
167 const struct sof_ipc_pcm_params_reply *reply);
168
169
170 int (*pre_fw_run)(struct snd_sof_dev *sof_dev);
171 int (*post_fw_run)(struct snd_sof_dev *sof_dev);
172
173
174 int (*suspend)(struct snd_sof_dev *sof_dev);
175 int (*resume)(struct snd_sof_dev *sof_dev);
176 int (*runtime_suspend)(struct snd_sof_dev *sof_dev);
177 int (*runtime_resume)(struct snd_sof_dev *sof_dev);
178 int (*runtime_idle)(struct snd_sof_dev *sof_dev);
179 int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev);
180
181
182 int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq);
183
184
185 const struct snd_sof_debugfs_map *debug_map;
186 int debug_map_count;
187 void (*dbg_dump)(struct snd_sof_dev *sof_dev,
188 u32 flags);
189 void (*ipc_dump)(struct snd_sof_dev *sof_dev);
190
191
192 int (*trace_init)(struct snd_sof_dev *sdev,
193 u32 *stream_tag);
194 int (*trace_release)(struct snd_sof_dev *sdev);
195 int (*trace_trigger)(struct snd_sof_dev *sdev,
196 int cmd);
197
198
199 int (*get_bar_index)(struct snd_sof_dev *sdev,
200 u32 type);
201 int (*get_mailbox_offset)(struct snd_sof_dev *sdev);
202 int (*get_window_offset)(struct snd_sof_dev *sdev,
203 u32 id);
204
205
206 struct snd_soc_dai_driver *drv;
207 int num_drv;
208 };
209
210
211 struct sof_arch_ops {
212 void (*dsp_oops)(struct snd_sof_dev *sdev, void *oops);
213 void (*dsp_stack)(struct snd_sof_dev *sdev, void *oops,
214 u32 *stack, u32 stack_words);
215 };
216
217 #define sof_arch_ops(sdev) ((sdev)->pdata->desc->arch_ops)
218
219
220 struct sof_ops_table {
221 const struct sof_dev_desc *desc;
222 const struct snd_sof_dsp_ops *ops;
223 };
224
225 enum sof_dfsentry_type {
226 SOF_DFSENTRY_TYPE_IOMEM = 0,
227 SOF_DFSENTRY_TYPE_BUF,
228 };
229
230 enum sof_debugfs_access_type {
231 SOF_DEBUGFS_ACCESS_ALWAYS = 0,
232 SOF_DEBUGFS_ACCESS_D0_ONLY,
233 };
234
235
236 struct snd_sof_dfsentry {
237 size_t size;
238 enum sof_dfsentry_type type;
239
240
241
242
243
244 enum sof_debugfs_access_type access_type;
245 #if ENABLE_DEBUGFS_CACHEBUF
246 char *cache_buf;
247 #endif
248 struct snd_sof_dev *sdev;
249 struct list_head list;
250 union {
251 void __iomem *io_mem;
252 void *buf;
253 };
254 };
255
256
257 struct snd_sof_debugfs_map {
258 const char *name;
259 u32 bar;
260 u32 offset;
261 u32 size;
262
263
264
265
266 enum sof_debugfs_access_type access_type;
267 };
268
269
270 struct snd_sof_mailbox {
271 u32 offset;
272 size_t size;
273 };
274
275
276 struct snd_sof_ipc_msg {
277
278 u32 header;
279 void *msg_data;
280 void *reply_data;
281 size_t msg_size;
282 size_t reply_size;
283 int reply_error;
284
285 wait_queue_head_t waitq;
286 bool ipc_complete;
287 };
288
289
290 struct snd_sof_pcm_stream {
291 u32 comp_id;
292 struct snd_dma_buffer page_table;
293 struct sof_ipc_stream_posn posn;
294 struct snd_pcm_substream *substream;
295 struct work_struct period_elapsed_work;
296 };
297
298
299 struct snd_sof_pcm {
300 struct snd_sof_dev *sdev;
301 struct snd_soc_tplg_pcm pcm;
302 struct snd_sof_pcm_stream stream[2];
303 struct list_head list;
304 struct snd_pcm_hw_params params[2];
305 bool prepared[2];
306 };
307
308
309 struct snd_sof_control {
310 struct snd_sof_dev *sdev;
311 int comp_id;
312 int min_volume_step;
313 int max_volume_step;
314 int num_channels;
315 u32 readback_offset;
316 struct sof_ipc_ctrl_data *control_data;
317 u32 size;
318 enum sof_ipc_ctrl_cmd cmd;
319 u32 *volume_table;
320
321 struct list_head list;
322 };
323
324
325 struct snd_sof_widget {
326 struct snd_sof_dev *sdev;
327 int comp_id;
328 int pipeline_id;
329 int complete;
330 int id;
331
332 struct snd_soc_dapm_widget *widget;
333 struct list_head list;
334
335 void *private;
336 };
337
338
339 struct snd_sof_route {
340 struct snd_sof_dev *sdev;
341
342 struct snd_soc_dapm_route *route;
343 struct list_head list;
344
345 void *private;
346 };
347
348
349 struct snd_sof_dai {
350 struct snd_sof_dev *sdev;
351 const char *name;
352 const char *cpu_dai_name;
353
354 struct sof_ipc_comp_dai comp_dai;
355 struct sof_ipc_dai_config *dai_config;
356 struct list_head list;
357 };
358
359 enum snd_sof_fw_state {
360 SOF_FW_BOOT_NOT_STARTED = 0,
361 SOF_FW_BOOT_PREPARE,
362 SOF_FW_BOOT_IN_PROGRESS,
363 SOF_FW_BOOT_FAILED,
364 SOF_FW_BOOT_READY_FAILED,
365 SOF_FW_BOOT_COMPLETE,
366 };
367
368
369
370
371 struct snd_sof_dev {
372 struct device *dev;
373 spinlock_t ipc_lock;
374 spinlock_t hw_lock;
375
376
377
378
379
380 struct snd_soc_component_driver plat_drv;
381
382
383 wait_queue_head_t boot_wait;
384 enum snd_sof_fw_state fw_state;
385 u32 first_boot;
386
387
388 struct work_struct probe_work;
389
390
391 struct snd_sof_pdata *pdata;
392
393
394 struct snd_sof_ipc *ipc;
395 struct snd_sof_mailbox dsp_box;
396 struct snd_sof_mailbox host_box;
397 struct snd_sof_mailbox stream_box;
398 struct snd_sof_ipc_msg *msg;
399 int ipc_irq;
400 u32 next_comp_id;
401
402
403 void __iomem *bar[SND_SOF_BARS];
404 int mmio_bar;
405 int mailbox_bar;
406 size_t dsp_oops_offset;
407
408
409 struct dentry *debugfs_root;
410 struct list_head dfsentry_list;
411
412
413 struct snd_dma_buffer dmab;
414 struct snd_dma_buffer dmab_bdl;
415 struct sof_ipc_fw_ready fw_ready;
416 struct sof_ipc_fw_version fw_version;
417
418
419 struct snd_soc_tplg_ops *tplg_ops;
420 struct list_head pcm_list;
421 struct list_head kcontrol_list;
422 struct list_head widget_list;
423 struct list_head dai_list;
424 struct list_head route_list;
425 struct snd_soc_component *component;
426 u32 enabled_cores_mask;
427
428
429 struct sof_ipc_dma_buffer_data *info_buffer;
430 struct sof_ipc_window *info_window;
431
432
433 int ipc_timeout;
434 int boot_timeout;
435
436
437 wait_queue_head_t waitq;
438 int code_loading;
439
440
441 struct snd_dma_buffer dmatb;
442 struct snd_dma_buffer dmatp;
443 int dma_trace_pages;
444 wait_queue_head_t trace_sleep;
445 u32 host_offset;
446 u32 dtrace_is_enabled;
447 u32 dtrace_error;
448 u32 dtrace_draining;
449
450 bool msi_enabled;
451
452 void *private;
453 };
454
455
456
457
458
459 int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data);
460 int snd_sof_device_remove(struct device *dev);
461
462 int snd_sof_runtime_suspend(struct device *dev);
463 int snd_sof_runtime_resume(struct device *dev);
464 int snd_sof_runtime_idle(struct device *dev);
465 int snd_sof_resume(struct device *dev);
466 int snd_sof_suspend(struct device *dev);
467
468 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev);
469
470 int snd_sof_create_page_table(struct snd_sof_dev *sdev,
471 struct snd_dma_buffer *dmab,
472 unsigned char *page_table, size_t size);
473
474
475
476
477 int snd_sof_load_firmware(struct snd_sof_dev *sdev);
478 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev);
479 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev);
480 int snd_sof_run_firmware(struct snd_sof_dev *sdev);
481 int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
482 struct snd_sof_mod_hdr *module);
483 void snd_sof_fw_unload(struct snd_sof_dev *sdev);
484 int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offset);
485
486
487
488
489 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev);
490 void snd_sof_ipc_free(struct snd_sof_dev *sdev);
491 int snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id);
492 void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev);
493 int snd_sof_ipc_stream_pcm_params(struct snd_sof_dev *sdev,
494 struct sof_ipc_pcm_params *params);
495 int snd_sof_dsp_mailbox_init(struct snd_sof_dev *sdev, u32 dspbox,
496 size_t dspbox_size, u32 hostbox,
497 size_t hostbox_size);
498 int snd_sof_ipc_valid(struct snd_sof_dev *sdev);
499 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header,
500 void *msg_data, size_t msg_bytes, void *reply_data,
501 size_t reply_bytes);
502 struct snd_sof_widget *snd_sof_find_swidget(struct snd_sof_dev *sdev,
503 const char *name);
504 struct snd_sof_widget *snd_sof_find_swidget_sname(struct snd_sof_dev *sdev,
505 const char *pcm_name,
506 int dir);
507 struct snd_sof_dai *snd_sof_find_dai(struct snd_sof_dev *sdev,
508 const char *name);
509
510 static inline
511 struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_sof_dev *sdev,
512 struct snd_soc_pcm_runtime *rtd)
513 {
514 struct snd_sof_pcm *spcm = NULL;
515
516 list_for_each_entry(spcm, &sdev->pcm_list, list) {
517 if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id)
518 return spcm;
519 }
520
521 return NULL;
522 }
523
524 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_sof_dev *sdev,
525 const char *name);
526 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_sof_dev *sdev,
527 unsigned int comp_id,
528 int *direction);
529 struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_sof_dev *sdev,
530 unsigned int pcm_id);
531 void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
532
533
534
535
536 int snd_sof_ipc_stream_posn(struct snd_sof_dev *sdev,
537 struct snd_sof_pcm *spcm, int direction,
538 struct sof_ipc_stream_posn *posn);
539
540
541
542
543 int snd_sof_ipc_set_get_comp_data(struct snd_sof_ipc *ipc,
544 struct snd_sof_control *scontrol, u32 ipc_cmd,
545 enum sof_ipc_ctrl_type ctrl_type,
546 enum sof_ipc_ctrl_cmd ctrl_cmd,
547 bool send);
548
549
550
551
552
553
554 int snd_sof_init_topology(struct snd_sof_dev *sdev,
555 struct snd_soc_tplg_ops *ops);
556 int snd_sof_load_topology(struct snd_sof_dev *sdev, const char *file);
557 int snd_sof_complete_pipeline(struct snd_sof_dev *sdev,
558 struct snd_sof_widget *swidget);
559
560 int sof_load_pipeline_ipc(struct snd_sof_dev *sdev,
561 struct sof_ipc_pipe_new *pipeline,
562 struct sof_ipc_comp_reply *r);
563
564
565
566
567 int snd_sof_init_trace(struct snd_sof_dev *sdev);
568 void snd_sof_release_trace(struct snd_sof_dev *sdev);
569 void snd_sof_free_trace(struct snd_sof_dev *sdev);
570 int snd_sof_dbg_init(struct snd_sof_dev *sdev);
571 void snd_sof_free_debug(struct snd_sof_dev *sdev);
572 int snd_sof_debugfs_io_item(struct snd_sof_dev *sdev,
573 void __iomem *base, size_t size,
574 const char *name,
575 enum sof_debugfs_access_type access_type);
576 int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
577 void *base, size_t size,
578 const char *name, mode_t mode);
579 int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
580 struct sof_ipc_dma_trace_posn *posn);
581 void snd_sof_trace_notify_for_error(struct snd_sof_dev *sdev);
582 void snd_sof_get_status(struct snd_sof_dev *sdev, u32 panic_code,
583 u32 tracep_code, void *oops,
584 struct sof_ipc_panic_info *panic_info,
585 void *stack, size_t stack_words);
586 int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev);
587
588
589
590
591 extern struct snd_compr_ops sof_compressed_ops;
592
593
594
595
596
597 int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
598 struct snd_ctl_elem_value *ucontrol);
599 int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
600 struct snd_ctl_elem_value *ucontrol);
601 int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
602 struct snd_ctl_elem_value *ucontrol);
603 int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
604 struct snd_ctl_elem_value *ucontrol);
605 int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
606 struct snd_ctl_elem_value *ucontrol);
607 int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_value *ucontrol);
609 int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol);
611 int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
612 struct snd_ctl_elem_value *ucontrol);
613 int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
614 const unsigned int __user *binary_data,
615 unsigned int size);
616 int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
617 unsigned int __user *binary_data,
618 unsigned int size);
619
620
621
622
623 static inline void sof_stack(struct snd_sof_dev *sdev, void *oops, u32 *stack,
624 u32 stack_words)
625 {
626 if (sof_arch_ops(sdev)->dsp_stack)
627 sof_arch_ops(sdev)->dsp_stack(sdev, oops, stack, stack_words);
628 }
629
630 static inline void sof_oops(struct snd_sof_dev *sdev, void *oops)
631 {
632 if (sof_arch_ops(sdev)->dsp_oops)
633 sof_arch_ops(sdev)->dsp_oops(sdev, oops);
634 }
635
636 extern const struct sof_arch_ops sof_xtensa_arch_ops;
637
638
639
640
641 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value);
642 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value);
643 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr);
644 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr);
645 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
646 void *message, size_t bytes);
647 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
648 void *message, size_t bytes);
649 void sof_block_write(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *src,
650 size_t size);
651 void sof_block_read(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *dest,
652 size_t size);
653
654 int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id);
655
656 void intel_ipc_msg_data(struct snd_sof_dev *sdev,
657 struct snd_pcm_substream *substream,
658 void *p, size_t sz);
659 int intel_ipc_pcm_params(struct snd_sof_dev *sdev,
660 struct snd_pcm_substream *substream,
661 const struct sof_ipc_pcm_params_reply *reply);
662
663 int intel_pcm_open(struct snd_sof_dev *sdev,
664 struct snd_pcm_substream *substream);
665 int intel_pcm_close(struct snd_sof_dev *sdev,
666 struct snd_pcm_substream *substream);
667
668 #endif