2 * skl-message.c - HDA DSP interface for FW registration, Pipe and Module
5 * Copyright (C) 2015 Intel Corp
6 * Author:Rafal Redzimski <rafal.f.redzimski@intel.com>
7 * Jeeja KP <jeeja.kp@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as version 2, as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
20 #include <linux/slab.h>
21 #include <linux/pci.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include "skl-sst-dsp.h"
25 #include "skl-sst-ipc.h"
27 #include "../common/sst-dsp.h"
28 #include "../common/sst-dsp-priv.h"
29 #include "skl-topology.h"
30 #include "skl-tplg-interface.h"
32 static int skl_alloc_dma_buf(struct device
*dev
,
33 struct snd_dma_buffer
*dmab
, size_t size
)
35 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
36 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
41 return bus
->io_ops
->dma_alloc_pages(bus
, SNDRV_DMA_TYPE_DEV
, size
, dmab
);
44 static int skl_free_dma_buf(struct device
*dev
, struct snd_dma_buffer
*dmab
)
46 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
47 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
52 bus
->io_ops
->dma_free_pages(bus
, dmab
);
57 #define NOTIFICATION_PARAM_ID 3
58 #define NOTIFICATION_MASK 0xf
60 /* disable notfication for underruns/overruns from firmware module */
61 static void skl_dsp_enable_notification(struct skl_sst
*ctx
, bool enable
)
63 struct notification_mask mask
;
64 struct skl_ipc_large_config_msg msg
= {0};
66 mask
.notify
= NOTIFICATION_MASK
;
69 msg
.large_param_id
= NOTIFICATION_PARAM_ID
;
70 msg
.param_data_size
= sizeof(mask
);
72 skl_ipc_set_large_config(&ctx
->ipc
, &msg
, (u32
*)&mask
);
75 static int skl_dsp_setup_spib(struct device
*dev
, unsigned int size
,
76 int stream_tag
, int enable
)
78 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
79 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
80 struct hdac_stream
*stream
= snd_hdac_get_stream(bus
,
81 SNDRV_PCM_STREAM_PLAYBACK
, stream_tag
);
82 struct hdac_ext_stream
*estream
;
87 estream
= stream_to_hdac_ext_stream(stream
);
88 /* enable/disable SPIB for this hdac stream */
89 snd_hdac_ext_stream_spbcap_enable(ebus
, enable
, stream
->index
);
91 /* set the spib value */
92 snd_hdac_ext_stream_set_spib(ebus
, estream
, size
);
97 static int skl_dsp_prepare(struct device
*dev
, unsigned int format
,
98 unsigned int size
, struct snd_dma_buffer
*dmab
)
100 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
101 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
102 struct hdac_ext_stream
*estream
;
103 struct hdac_stream
*stream
;
104 struct snd_pcm_substream substream
;
110 memset(&substream
, 0, sizeof(substream
));
111 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
113 estream
= snd_hdac_ext_stream_assign(ebus
, &substream
,
114 HDAC_EXT_STREAM_TYPE_HOST
);
118 stream
= hdac_stream(estream
);
120 /* assign decouple host dma channel */
121 ret
= snd_hdac_dsp_prepare(stream
, format
, size
, dmab
);
125 skl_dsp_setup_spib(dev
, size
, stream
->stream_tag
, true);
127 return stream
->stream_tag
;
130 static int skl_dsp_trigger(struct device
*dev
, bool start
, int stream_tag
)
132 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
133 struct hdac_stream
*stream
;
134 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
139 stream
= snd_hdac_get_stream(bus
,
140 SNDRV_PCM_STREAM_PLAYBACK
, stream_tag
);
144 snd_hdac_dsp_trigger(stream
, start
);
149 static int skl_dsp_cleanup(struct device
*dev
,
150 struct snd_dma_buffer
*dmab
, int stream_tag
)
152 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
153 struct hdac_stream
*stream
;
154 struct hdac_ext_stream
*estream
;
155 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
160 stream
= snd_hdac_get_stream(bus
,
161 SNDRV_PCM_STREAM_PLAYBACK
, stream_tag
);
165 estream
= stream_to_hdac_ext_stream(stream
);
166 skl_dsp_setup_spib(dev
, 0, stream_tag
, false);
167 snd_hdac_ext_stream_release(estream
, HDAC_EXT_STREAM_TYPE_HOST
);
169 snd_hdac_dsp_cleanup(stream
, dmab
);
174 static struct skl_dsp_loader_ops
skl_get_loader_ops(void)
176 struct skl_dsp_loader_ops loader_ops
;
178 memset(&loader_ops
, 0, sizeof(struct skl_dsp_loader_ops
));
180 loader_ops
.alloc_dma_buf
= skl_alloc_dma_buf
;
181 loader_ops
.free_dma_buf
= skl_free_dma_buf
;
186 static struct skl_dsp_loader_ops
bxt_get_loader_ops(void)
188 struct skl_dsp_loader_ops loader_ops
;
190 memset(&loader_ops
, 0, sizeof(loader_ops
));
192 loader_ops
.alloc_dma_buf
= skl_alloc_dma_buf
;
193 loader_ops
.free_dma_buf
= skl_free_dma_buf
;
194 loader_ops
.prepare
= skl_dsp_prepare
;
195 loader_ops
.trigger
= skl_dsp_trigger
;
196 loader_ops
.cleanup
= skl_dsp_cleanup
;
201 static const struct skl_dsp_ops dsp_ops
[] = {
204 .loader_ops
= skl_get_loader_ops
,
205 .init
= skl_sst_dsp_init
,
206 .cleanup
= skl_sst_dsp_cleanup
210 .loader_ops
= bxt_get_loader_ops
,
211 .init
= bxt_sst_dsp_init
,
212 .cleanup
= bxt_sst_dsp_cleanup
216 static int skl_get_dsp_ops(int pci_id
)
220 for (i
= 0; i
< ARRAY_SIZE(dsp_ops
); i
++) {
221 if (dsp_ops
[i
].id
== pci_id
)
228 int skl_init_dsp(struct skl
*skl
)
230 void __iomem
*mmio_base
;
231 struct hdac_ext_bus
*ebus
= &skl
->ebus
;
232 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
233 struct skl_dsp_loader_ops loader_ops
;
237 /* enable ppcap interrupt */
238 snd_hdac_ext_bus_ppcap_enable(&skl
->ebus
, true);
239 snd_hdac_ext_bus_ppcap_int_enable(&skl
->ebus
, true);
241 /* read the BAR of the ADSP MMIO */
242 mmio_base
= pci_ioremap_bar(skl
->pci
, 4);
243 if (mmio_base
== NULL
) {
244 dev_err(bus
->dev
, "ioremap error\n");
248 index
= skl_get_dsp_ops(skl
->pci
->device
);
252 loader_ops
= dsp_ops
[index
].loader_ops();
253 ret
= dsp_ops
[index
].init(bus
->dev
, mmio_base
, irq
,
254 skl
->fw_name
, loader_ops
, &skl
->skl_sst
);
259 skl_dsp_enable_notification(skl
->skl_sst
, false);
260 dev_dbg(bus
->dev
, "dsp registration status=%d\n", ret
);
265 int skl_free_dsp(struct skl
*skl
)
267 struct hdac_ext_bus
*ebus
= &skl
->ebus
;
268 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
269 struct skl_sst
*ctx
= skl
->skl_sst
;
272 /* disable ppcap interrupt */
273 snd_hdac_ext_bus_ppcap_int_enable(&skl
->ebus
, false);
275 index
= skl_get_dsp_ops(skl
->pci
->device
);
279 dsp_ops
[index
].cleanup(bus
->dev
, ctx
);
281 if (ctx
->dsp
->addr
.lpe
)
282 iounmap(ctx
->dsp
->addr
.lpe
);
287 int skl_suspend_dsp(struct skl
*skl
)
289 struct skl_sst
*ctx
= skl
->skl_sst
;
292 /* if ppcap is not supported return 0 */
293 if (!skl
->ebus
.ppcap
)
296 ret
= skl_dsp_sleep(ctx
->dsp
);
300 /* disable ppcap interrupt */
301 snd_hdac_ext_bus_ppcap_int_enable(&skl
->ebus
, false);
302 snd_hdac_ext_bus_ppcap_enable(&skl
->ebus
, false);
307 int skl_resume_dsp(struct skl
*skl
)
309 struct skl_sst
*ctx
= skl
->skl_sst
;
312 /* if ppcap is not supported return 0 */
313 if (!skl
->ebus
.ppcap
)
316 /* enable ppcap interrupt */
317 snd_hdac_ext_bus_ppcap_enable(&skl
->ebus
, true);
318 snd_hdac_ext_bus_ppcap_int_enable(&skl
->ebus
, true);
320 ret
= skl_dsp_wake(ctx
->dsp
);
324 skl_dsp_enable_notification(skl
->skl_sst
, false);
328 enum skl_bitdepth
skl_get_bit_depth(int params
)
332 return SKL_DEPTH_8BIT
;
335 return SKL_DEPTH_16BIT
;
338 return SKL_DEPTH_24BIT
;
341 return SKL_DEPTH_32BIT
;
344 return SKL_DEPTH_INVALID
;
350 * Each module in DSP expects a base module configuration, which consists of
351 * PCM format information, which we calculate in driver and resource values
352 * which are read from widget information passed through topology binary
353 * This is send when we create a module with INIT_INSTANCE IPC msg
355 static void skl_set_base_module_format(struct skl_sst
*ctx
,
356 struct skl_module_cfg
*mconfig
,
357 struct skl_base_cfg
*base_cfg
)
359 struct skl_module_fmt
*format
= &mconfig
->in_fmt
[0];
361 base_cfg
->audio_fmt
.number_of_channels
= (u8
)format
->channels
;
363 base_cfg
->audio_fmt
.s_freq
= format
->s_freq
;
364 base_cfg
->audio_fmt
.bit_depth
= format
->bit_depth
;
365 base_cfg
->audio_fmt
.valid_bit_depth
= format
->valid_bit_depth
;
366 base_cfg
->audio_fmt
.ch_cfg
= format
->ch_cfg
;
368 dev_dbg(ctx
->dev
, "bit_depth=%x valid_bd=%x ch_config=%x\n",
369 format
->bit_depth
, format
->valid_bit_depth
,
372 base_cfg
->audio_fmt
.channel_map
= format
->ch_map
;
374 base_cfg
->audio_fmt
.interleaving
= format
->interleaving_style
;
376 base_cfg
->cps
= mconfig
->mcps
;
377 base_cfg
->ibs
= mconfig
->ibs
;
378 base_cfg
->obs
= mconfig
->obs
;
379 base_cfg
->is_pages
= mconfig
->mem_pages
;
383 * Copies copier capabilities into copier module and updates copier module
386 static void skl_copy_copier_caps(struct skl_module_cfg
*mconfig
,
387 struct skl_cpr_cfg
*cpr_mconfig
)
389 if (mconfig
->formats_config
.caps_size
== 0)
392 memcpy(cpr_mconfig
->gtw_cfg
.config_data
,
393 mconfig
->formats_config
.caps
,
394 mconfig
->formats_config
.caps_size
);
396 cpr_mconfig
->gtw_cfg
.config_length
=
397 (mconfig
->formats_config
.caps_size
) / 4;
400 #define SKL_NON_GATEWAY_CPR_NODE_ID 0xFFFFFFFF
402 * Calculate the gatewat settings required for copier module, type of
403 * gateway and index of gateway to use
405 static u32
skl_get_node_id(struct skl_sst
*ctx
,
406 struct skl_module_cfg
*mconfig
)
408 union skl_connector_node_id node_id
= {0};
409 union skl_ssp_dma_node ssp_node
= {0};
410 struct skl_pipe_params
*params
= mconfig
->pipe
->p_params
;
412 switch (mconfig
->dev_type
) {
414 node_id
.node
.dma_type
=
415 (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
) ?
416 SKL_DMA_I2S_LINK_OUTPUT_CLASS
:
417 SKL_DMA_I2S_LINK_INPUT_CLASS
;
418 node_id
.node
.vindex
= params
->host_dma_id
+
419 (mconfig
->vbus_id
<< 3);
423 node_id
.node
.dma_type
=
424 (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
) ?
425 SKL_DMA_I2S_LINK_OUTPUT_CLASS
:
426 SKL_DMA_I2S_LINK_INPUT_CLASS
;
427 ssp_node
.dma_node
.time_slot_index
= mconfig
->time_slot
;
428 ssp_node
.dma_node
.i2s_instance
= mconfig
->vbus_id
;
429 node_id
.node
.vindex
= ssp_node
.val
;
432 case SKL_DEVICE_DMIC
:
433 node_id
.node
.dma_type
= SKL_DMA_DMIC_LINK_INPUT_CLASS
;
434 node_id
.node
.vindex
= mconfig
->vbus_id
+
435 (mconfig
->time_slot
);
438 case SKL_DEVICE_HDALINK
:
439 node_id
.node
.dma_type
=
440 (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
) ?
441 SKL_DMA_HDA_LINK_OUTPUT_CLASS
:
442 SKL_DMA_HDA_LINK_INPUT_CLASS
;
443 node_id
.node
.vindex
= params
->link_dma_id
;
446 case SKL_DEVICE_HDAHOST
:
447 node_id
.node
.dma_type
=
448 (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
) ?
449 SKL_DMA_HDA_HOST_OUTPUT_CLASS
:
450 SKL_DMA_HDA_HOST_INPUT_CLASS
;
451 node_id
.node
.vindex
= params
->host_dma_id
;
455 node_id
.val
= 0xFFFFFFFF;
462 static void skl_setup_cpr_gateway_cfg(struct skl_sst
*ctx
,
463 struct skl_module_cfg
*mconfig
,
464 struct skl_cpr_cfg
*cpr_mconfig
)
466 cpr_mconfig
->gtw_cfg
.node_id
= skl_get_node_id(ctx
, mconfig
);
468 if (cpr_mconfig
->gtw_cfg
.node_id
== SKL_NON_GATEWAY_CPR_NODE_ID
) {
469 cpr_mconfig
->cpr_feature_mask
= 0;
473 if (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
)
474 cpr_mconfig
->gtw_cfg
.dma_buffer_size
= 2 * mconfig
->obs
;
476 cpr_mconfig
->gtw_cfg
.dma_buffer_size
= 2 * mconfig
->ibs
;
478 cpr_mconfig
->cpr_feature_mask
= 0;
479 cpr_mconfig
->gtw_cfg
.config_length
= 0;
481 skl_copy_copier_caps(mconfig
, cpr_mconfig
);
484 #define DMA_CONTROL_ID 5
486 int skl_dsp_set_dma_control(struct skl_sst
*ctx
, struct skl_module_cfg
*mconfig
)
488 struct skl_dma_control
*dma_ctrl
;
489 struct skl_i2s_config_blob config_blob
;
490 struct skl_ipc_large_config_msg msg
= {0};
495 * if blob size is same as capablity size, then no dma control
498 if (mconfig
->formats_config
.caps_size
== sizeof(config_blob
))
501 msg
.large_param_id
= DMA_CONTROL_ID
;
502 msg
.param_data_size
= sizeof(struct skl_dma_control
) +
503 mconfig
->formats_config
.caps_size
;
505 dma_ctrl
= kzalloc(msg
.param_data_size
, GFP_KERNEL
);
506 if (dma_ctrl
== NULL
)
509 dma_ctrl
->node_id
= skl_get_node_id(ctx
, mconfig
);
512 dma_ctrl
->config_length
= sizeof(config_blob
) / 4;
514 memcpy(dma_ctrl
->config_data
, mconfig
->formats_config
.caps
,
515 mconfig
->formats_config
.caps_size
);
517 err
= skl_ipc_set_large_config(&ctx
->ipc
, &msg
, (u32
*)dma_ctrl
);
524 static void skl_setup_out_format(struct skl_sst
*ctx
,
525 struct skl_module_cfg
*mconfig
,
526 struct skl_audio_data_format
*out_fmt
)
528 struct skl_module_fmt
*format
= &mconfig
->out_fmt
[0];
530 out_fmt
->number_of_channels
= (u8
)format
->channels
;
531 out_fmt
->s_freq
= format
->s_freq
;
532 out_fmt
->bit_depth
= format
->bit_depth
;
533 out_fmt
->valid_bit_depth
= format
->valid_bit_depth
;
534 out_fmt
->ch_cfg
= format
->ch_cfg
;
536 out_fmt
->channel_map
= format
->ch_map
;
537 out_fmt
->interleaving
= format
->interleaving_style
;
538 out_fmt
->sample_type
= format
->sample_type
;
540 dev_dbg(ctx
->dev
, "copier out format chan=%d fre=%d bitdepth=%d\n",
541 out_fmt
->number_of_channels
, format
->s_freq
, format
->bit_depth
);
545 * DSP needs SRC module for frequency conversion, SRC takes base module
546 * configuration and the target frequency as extra parameter passed as src
549 static void skl_set_src_format(struct skl_sst
*ctx
,
550 struct skl_module_cfg
*mconfig
,
551 struct skl_src_module_cfg
*src_mconfig
)
553 struct skl_module_fmt
*fmt
= &mconfig
->out_fmt
[0];
555 skl_set_base_module_format(ctx
, mconfig
,
556 (struct skl_base_cfg
*)src_mconfig
);
558 src_mconfig
->src_cfg
= fmt
->s_freq
;
562 * DSP needs updown module to do channel conversion. updown module take base
563 * module configuration and channel configuration
564 * It also take coefficients and now we have defaults applied here
566 static void skl_set_updown_mixer_format(struct skl_sst
*ctx
,
567 struct skl_module_cfg
*mconfig
,
568 struct skl_up_down_mixer_cfg
*mixer_mconfig
)
570 struct skl_module_fmt
*fmt
= &mconfig
->out_fmt
[0];
573 skl_set_base_module_format(ctx
, mconfig
,
574 (struct skl_base_cfg
*)mixer_mconfig
);
575 mixer_mconfig
->out_ch_cfg
= fmt
->ch_cfg
;
577 /* Select F/W default coefficient */
578 mixer_mconfig
->coeff_sel
= 0x0;
580 /* User coeff, don't care since we are selecting F/W defaults */
581 for (i
= 0; i
< UP_DOWN_MIXER_MAX_COEFF
; i
++)
582 mixer_mconfig
->coeff
[i
] = 0xDEADBEEF;
586 * 'copier' is DSP internal module which copies data from Host DMA (HDA host
587 * dma) or link (hda link, SSP, PDM)
588 * Here we calculate the copier module parameters, like PCM format, output
589 * format, gateway settings
590 * copier_module_config is sent as input buffer with INIT_INSTANCE IPC msg
592 static void skl_set_copier_format(struct skl_sst
*ctx
,
593 struct skl_module_cfg
*mconfig
,
594 struct skl_cpr_cfg
*cpr_mconfig
)
596 struct skl_audio_data_format
*out_fmt
= &cpr_mconfig
->out_fmt
;
597 struct skl_base_cfg
*base_cfg
= (struct skl_base_cfg
*)cpr_mconfig
;
599 skl_set_base_module_format(ctx
, mconfig
, base_cfg
);
601 skl_setup_out_format(ctx
, mconfig
, out_fmt
);
602 skl_setup_cpr_gateway_cfg(ctx
, mconfig
, cpr_mconfig
);
606 * Algo module are DSP pre processing modules. Algo module take base module
607 * configuration and params
610 static void skl_set_algo_format(struct skl_sst
*ctx
,
611 struct skl_module_cfg
*mconfig
,
612 struct skl_algo_cfg
*algo_mcfg
)
614 struct skl_base_cfg
*base_cfg
= (struct skl_base_cfg
*)algo_mcfg
;
616 skl_set_base_module_format(ctx
, mconfig
, base_cfg
);
618 if (mconfig
->formats_config
.caps_size
== 0)
621 memcpy(algo_mcfg
->params
,
622 mconfig
->formats_config
.caps
,
623 mconfig
->formats_config
.caps_size
);
628 * Mic select module allows selecting one or many input channels, thus
631 * Mic select module take base module configuration and out-format
634 static void skl_set_base_outfmt_format(struct skl_sst
*ctx
,
635 struct skl_module_cfg
*mconfig
,
636 struct skl_base_outfmt_cfg
*base_outfmt_mcfg
)
638 struct skl_audio_data_format
*out_fmt
= &base_outfmt_mcfg
->out_fmt
;
639 struct skl_base_cfg
*base_cfg
=
640 (struct skl_base_cfg
*)base_outfmt_mcfg
;
642 skl_set_base_module_format(ctx
, mconfig
, base_cfg
);
643 skl_setup_out_format(ctx
, mconfig
, out_fmt
);
646 static u16
skl_get_module_param_size(struct skl_sst
*ctx
,
647 struct skl_module_cfg
*mconfig
)
651 switch (mconfig
->m_type
) {
652 case SKL_MODULE_TYPE_COPIER
:
653 param_size
= sizeof(struct skl_cpr_cfg
);
654 param_size
+= mconfig
->formats_config
.caps_size
;
657 case SKL_MODULE_TYPE_SRCINT
:
658 return sizeof(struct skl_src_module_cfg
);
660 case SKL_MODULE_TYPE_UPDWMIX
:
661 return sizeof(struct skl_up_down_mixer_cfg
);
663 case SKL_MODULE_TYPE_ALGO
:
664 param_size
= sizeof(struct skl_base_cfg
);
665 param_size
+= mconfig
->formats_config
.caps_size
;
668 case SKL_MODULE_TYPE_BASE_OUTFMT
:
669 return sizeof(struct skl_base_outfmt_cfg
);
673 * return only base cfg when no specific module type is
676 return sizeof(struct skl_base_cfg
);
683 * DSP firmware supports various modules like copier, SRC, updown etc.
684 * These modules required various parameters to be calculated and sent for
685 * the module initialization to DSP. By default a generic module needs only
686 * base module format configuration
689 static int skl_set_module_format(struct skl_sst
*ctx
,
690 struct skl_module_cfg
*module_config
,
691 u16
*module_config_size
,
696 param_size
= skl_get_module_param_size(ctx
, module_config
);
698 *param_data
= kzalloc(param_size
, GFP_KERNEL
);
699 if (NULL
== *param_data
)
702 *module_config_size
= param_size
;
704 switch (module_config
->m_type
) {
705 case SKL_MODULE_TYPE_COPIER
:
706 skl_set_copier_format(ctx
, module_config
, *param_data
);
709 case SKL_MODULE_TYPE_SRCINT
:
710 skl_set_src_format(ctx
, module_config
, *param_data
);
713 case SKL_MODULE_TYPE_UPDWMIX
:
714 skl_set_updown_mixer_format(ctx
, module_config
, *param_data
);
717 case SKL_MODULE_TYPE_ALGO
:
718 skl_set_algo_format(ctx
, module_config
, *param_data
);
721 case SKL_MODULE_TYPE_BASE_OUTFMT
:
722 skl_set_base_outfmt_format(ctx
, module_config
, *param_data
);
726 skl_set_base_module_format(ctx
, module_config
, *param_data
);
731 dev_dbg(ctx
->dev
, "Module type=%d config size: %d bytes\n",
732 module_config
->id
.module_id
, param_size
);
733 print_hex_dump(KERN_DEBUG
, "Module params:", DUMP_PREFIX_OFFSET
, 8, 4,
734 *param_data
, param_size
, false);
738 static int skl_get_queue_index(struct skl_module_pin
*mpin
,
739 struct skl_module_inst_id id
, int max
)
743 for (i
= 0; i
< max
; i
++) {
744 if (mpin
[i
].id
.module_id
== id
.module_id
&&
745 mpin
[i
].id
.instance_id
== id
.instance_id
)
753 * Allocates queue for each module.
754 * if dynamic, the pin_index is allocated 0 to max_pin.
755 * In static, the pin_index is fixed based on module_id and instance id
757 static int skl_alloc_queue(struct skl_module_pin
*mpin
,
758 struct skl_module_cfg
*tgt_cfg
, int max
)
761 struct skl_module_inst_id id
= tgt_cfg
->id
;
763 * if pin in dynamic, find first free pin
764 * otherwise find match module and instance id pin as topology will
765 * ensure a unique pin is assigned to this so no need to
768 for (i
= 0; i
< max
; i
++) {
769 if (mpin
[i
].is_dynamic
) {
770 if (!mpin
[i
].in_use
&&
771 mpin
[i
].pin_state
== SKL_PIN_UNBIND
) {
773 mpin
[i
].in_use
= true;
774 mpin
[i
].id
.module_id
= id
.module_id
;
775 mpin
[i
].id
.instance_id
= id
.instance_id
;
776 mpin
[i
].tgt_mcfg
= tgt_cfg
;
780 if (mpin
[i
].id
.module_id
== id
.module_id
&&
781 mpin
[i
].id
.instance_id
== id
.instance_id
&&
782 mpin
[i
].pin_state
== SKL_PIN_UNBIND
) {
784 mpin
[i
].tgt_mcfg
= tgt_cfg
;
793 static void skl_free_queue(struct skl_module_pin
*mpin
, int q_index
)
795 if (mpin
[q_index
].is_dynamic
) {
796 mpin
[q_index
].in_use
= false;
797 mpin
[q_index
].id
.module_id
= 0;
798 mpin
[q_index
].id
.instance_id
= 0;
800 mpin
[q_index
].pin_state
= SKL_PIN_UNBIND
;
801 mpin
[q_index
].tgt_mcfg
= NULL
;
804 /* Module state will be set to unint, if all the out pin state is UNBIND */
806 static void skl_clear_module_state(struct skl_module_pin
*mpin
, int max
,
807 struct skl_module_cfg
*mcfg
)
812 for (i
= 0; i
< max
; i
++) {
813 if (mpin
[i
].pin_state
== SKL_PIN_UNBIND
)
820 mcfg
->m_state
= SKL_MODULE_UNINIT
;
825 * A module needs to be instanataited in DSP. A mdoule is present in a
826 * collection of module referred as a PIPE.
827 * We first calculate the module format, based on module type and then
828 * invoke the DSP by sending IPC INIT_INSTANCE using ipc helper
830 int skl_init_module(struct skl_sst
*ctx
,
831 struct skl_module_cfg
*mconfig
)
833 u16 module_config_size
= 0;
834 void *param_data
= NULL
;
836 struct skl_ipc_init_instance_msg msg
;
838 dev_dbg(ctx
->dev
, "%s: module_id = %d instance=%d\n", __func__
,
839 mconfig
->id
.module_id
, mconfig
->id
.instance_id
);
841 if (mconfig
->pipe
->state
!= SKL_PIPE_CREATED
) {
842 dev_err(ctx
->dev
, "Pipe not created state= %d pipe_id= %d\n",
843 mconfig
->pipe
->state
, mconfig
->pipe
->ppl_id
);
847 ret
= skl_set_module_format(ctx
, mconfig
,
848 &module_config_size
, ¶m_data
);
850 dev_err(ctx
->dev
, "Failed to set module format ret=%d\n", ret
);
854 msg
.module_id
= mconfig
->id
.module_id
;
855 msg
.instance_id
= mconfig
->id
.instance_id
;
856 msg
.ppl_instance_id
= mconfig
->pipe
->ppl_id
;
857 msg
.param_data_size
= module_config_size
;
858 msg
.core_id
= mconfig
->core_id
;
860 ret
= skl_ipc_init_instance(&ctx
->ipc
, &msg
, param_data
);
862 dev_err(ctx
->dev
, "Failed to init instance ret=%d\n", ret
);
866 mconfig
->m_state
= SKL_MODULE_INIT_DONE
;
871 static void skl_dump_bind_info(struct skl_sst
*ctx
, struct skl_module_cfg
872 *src_module
, struct skl_module_cfg
*dst_module
)
874 dev_dbg(ctx
->dev
, "%s: src module_id = %d src_instance=%d\n",
875 __func__
, src_module
->id
.module_id
, src_module
->id
.instance_id
);
876 dev_dbg(ctx
->dev
, "%s: dst_module=%d dst_instacne=%d\n", __func__
,
877 dst_module
->id
.module_id
, dst_module
->id
.instance_id
);
879 dev_dbg(ctx
->dev
, "src_module state = %d dst module state = %d\n",
880 src_module
->m_state
, dst_module
->m_state
);
884 * On module freeup, we need to unbind the module with modules
885 * it is already bind.
886 * Find the pin allocated and unbind then using bind_unbind IPC
888 int skl_unbind_modules(struct skl_sst
*ctx
,
889 struct skl_module_cfg
*src_mcfg
,
890 struct skl_module_cfg
*dst_mcfg
)
893 struct skl_ipc_bind_unbind_msg msg
;
894 struct skl_module_inst_id src_id
= src_mcfg
->id
;
895 struct skl_module_inst_id dst_id
= dst_mcfg
->id
;
896 int in_max
= dst_mcfg
->max_in_queue
;
897 int out_max
= src_mcfg
->max_out_queue
;
898 int src_index
, dst_index
, src_pin_state
, dst_pin_state
;
900 skl_dump_bind_info(ctx
, src_mcfg
, dst_mcfg
);
902 /* get src queue index */
903 src_index
= skl_get_queue_index(src_mcfg
->m_out_pin
, dst_id
, out_max
);
907 msg
.src_queue
= src_index
;
909 /* get dst queue index */
910 dst_index
= skl_get_queue_index(dst_mcfg
->m_in_pin
, src_id
, in_max
);
914 msg
.dst_queue
= dst_index
;
916 src_pin_state
= src_mcfg
->m_out_pin
[src_index
].pin_state
;
917 dst_pin_state
= dst_mcfg
->m_in_pin
[dst_index
].pin_state
;
919 if (src_pin_state
!= SKL_PIN_BIND_DONE
||
920 dst_pin_state
!= SKL_PIN_BIND_DONE
)
923 msg
.module_id
= src_mcfg
->id
.module_id
;
924 msg
.instance_id
= src_mcfg
->id
.instance_id
;
925 msg
.dst_module_id
= dst_mcfg
->id
.module_id
;
926 msg
.dst_instance_id
= dst_mcfg
->id
.instance_id
;
929 ret
= skl_ipc_bind_unbind(&ctx
->ipc
, &msg
);
931 /* free queue only if unbind is success */
932 skl_free_queue(src_mcfg
->m_out_pin
, src_index
);
933 skl_free_queue(dst_mcfg
->m_in_pin
, dst_index
);
936 * check only if src module bind state, bind is
937 * always from src -> sink
939 skl_clear_module_state(src_mcfg
->m_out_pin
, out_max
, src_mcfg
);
946 * Once a module is instantiated it need to be 'bind' with other modules in
947 * the pipeline. For binding we need to find the module pins which are bind
949 * This function finds the pins and then sends bund_unbind IPC message to
950 * DSP using IPC helper
952 int skl_bind_modules(struct skl_sst
*ctx
,
953 struct skl_module_cfg
*src_mcfg
,
954 struct skl_module_cfg
*dst_mcfg
)
957 struct skl_ipc_bind_unbind_msg msg
;
958 int in_max
= dst_mcfg
->max_in_queue
;
959 int out_max
= src_mcfg
->max_out_queue
;
960 int src_index
, dst_index
;
962 skl_dump_bind_info(ctx
, src_mcfg
, dst_mcfg
);
964 if (src_mcfg
->m_state
< SKL_MODULE_INIT_DONE
||
965 dst_mcfg
->m_state
< SKL_MODULE_INIT_DONE
)
968 src_index
= skl_alloc_queue(src_mcfg
->m_out_pin
, dst_mcfg
, out_max
);
972 msg
.src_queue
= src_index
;
973 dst_index
= skl_alloc_queue(dst_mcfg
->m_in_pin
, src_mcfg
, in_max
);
975 skl_free_queue(src_mcfg
->m_out_pin
, src_index
);
979 msg
.dst_queue
= dst_index
;
981 dev_dbg(ctx
->dev
, "src queue = %d dst queue =%d\n",
982 msg
.src_queue
, msg
.dst_queue
);
984 msg
.module_id
= src_mcfg
->id
.module_id
;
985 msg
.instance_id
= src_mcfg
->id
.instance_id
;
986 msg
.dst_module_id
= dst_mcfg
->id
.module_id
;
987 msg
.dst_instance_id
= dst_mcfg
->id
.instance_id
;
990 ret
= skl_ipc_bind_unbind(&ctx
->ipc
, &msg
);
993 src_mcfg
->m_state
= SKL_MODULE_BIND_DONE
;
994 src_mcfg
->m_out_pin
[src_index
].pin_state
= SKL_PIN_BIND_DONE
;
995 dst_mcfg
->m_in_pin
[dst_index
].pin_state
= SKL_PIN_BIND_DONE
;
997 /* error case , if IPC fails, clear the queue index */
998 skl_free_queue(src_mcfg
->m_out_pin
, src_index
);
999 skl_free_queue(dst_mcfg
->m_in_pin
, dst_index
);
1005 static int skl_set_pipe_state(struct skl_sst
*ctx
, struct skl_pipe
*pipe
,
1006 enum skl_ipc_pipeline_state state
)
1008 dev_dbg(ctx
->dev
, "%s: pipe_satate = %d\n", __func__
, state
);
1010 return skl_ipc_set_pipeline_state(&ctx
->ipc
, pipe
->ppl_id
, state
);
1014 * A pipeline is a collection of modules. Before a module in instantiated a
1015 * pipeline needs to be created for it.
1016 * This function creates pipeline, by sending create pipeline IPC messages
1019 int skl_create_pipeline(struct skl_sst
*ctx
, struct skl_pipe
*pipe
)
1023 dev_dbg(ctx
->dev
, "%s: pipe_id = %d\n", __func__
, pipe
->ppl_id
);
1025 ret
= skl_ipc_create_pipeline(&ctx
->ipc
, pipe
->memory_pages
,
1026 pipe
->pipe_priority
, pipe
->ppl_id
);
1028 dev_err(ctx
->dev
, "Failed to create pipeline\n");
1032 pipe
->state
= SKL_PIPE_CREATED
;
1038 * A pipeline needs to be deleted on cleanup. If a pipeline is running, then
1039 * pause the pipeline first and then delete it
1040 * The pipe delete is done by sending delete pipeline IPC. DSP will stop the
1041 * DMA engines and releases resources
1043 int skl_delete_pipe(struct skl_sst
*ctx
, struct skl_pipe
*pipe
)
1047 dev_dbg(ctx
->dev
, "%s: pipe = %d\n", __func__
, pipe
->ppl_id
);
1049 /* If pipe is started, do stop the pipe in FW. */
1050 if (pipe
->state
> SKL_PIPE_STARTED
) {
1051 ret
= skl_set_pipe_state(ctx
, pipe
, PPL_PAUSED
);
1053 dev_err(ctx
->dev
, "Failed to stop pipeline\n");
1057 pipe
->state
= SKL_PIPE_PAUSED
;
1060 /* If pipe was not created in FW, do not try to delete it */
1061 if (pipe
->state
< SKL_PIPE_CREATED
)
1064 ret
= skl_ipc_delete_pipeline(&ctx
->ipc
, pipe
->ppl_id
);
1066 dev_err(ctx
->dev
, "Failed to delete pipeline\n");
1070 pipe
->state
= SKL_PIPE_INVALID
;
1076 * A pipeline is also a scheduling entity in DSP which can be run, stopped
1077 * For processing data the pipe need to be run by sending IPC set pipe state
1080 int skl_run_pipe(struct skl_sst
*ctx
, struct skl_pipe
*pipe
)
1084 dev_dbg(ctx
->dev
, "%s: pipe = %d\n", __func__
, pipe
->ppl_id
);
1086 /* If pipe was not created in FW, do not try to pause or delete */
1087 if (pipe
->state
< SKL_PIPE_CREATED
)
1090 /* Pipe has to be paused before it is started */
1091 ret
= skl_set_pipe_state(ctx
, pipe
, PPL_PAUSED
);
1093 dev_err(ctx
->dev
, "Failed to pause pipe\n");
1097 pipe
->state
= SKL_PIPE_PAUSED
;
1099 ret
= skl_set_pipe_state(ctx
, pipe
, PPL_RUNNING
);
1101 dev_err(ctx
->dev
, "Failed to start pipe\n");
1105 pipe
->state
= SKL_PIPE_STARTED
;
1111 * Stop the pipeline by sending set pipe state IPC
1112 * DSP doesnt implement stop so we always send pause message
1114 int skl_stop_pipe(struct skl_sst
*ctx
, struct skl_pipe
*pipe
)
1118 dev_dbg(ctx
->dev
, "In %s pipe=%d\n", __func__
, pipe
->ppl_id
);
1120 /* If pipe was not created in FW, do not try to pause or delete */
1121 if (pipe
->state
< SKL_PIPE_PAUSED
)
1124 ret
= skl_set_pipe_state(ctx
, pipe
, PPL_PAUSED
);
1126 dev_dbg(ctx
->dev
, "Failed to stop pipe\n");
1130 pipe
->state
= SKL_PIPE_PAUSED
;
1136 * Reset the pipeline by sending set pipe state IPC this will reset the DMA
1139 int skl_reset_pipe(struct skl_sst
*ctx
, struct skl_pipe
*pipe
)
1143 /* If pipe was not created in FW, do not try to pause or delete */
1144 if (pipe
->state
< SKL_PIPE_PAUSED
)
1147 ret
= skl_set_pipe_state(ctx
, pipe
, PPL_RESET
);
1149 dev_dbg(ctx
->dev
, "Failed to reset pipe ret=%d\n", ret
);
1153 pipe
->state
= SKL_PIPE_RESET
;
1158 /* Algo parameter set helper function */
1159 int skl_set_module_params(struct skl_sst
*ctx
, u32
*params
, int size
,
1160 u32 param_id
, struct skl_module_cfg
*mcfg
)
1162 struct skl_ipc_large_config_msg msg
;
1164 msg
.module_id
= mcfg
->id
.module_id
;
1165 msg
.instance_id
= mcfg
->id
.instance_id
;
1166 msg
.param_data_size
= size
;
1167 msg
.large_param_id
= param_id
;
1169 return skl_ipc_set_large_config(&ctx
->ipc
, &msg
, params
);
1172 int skl_get_module_params(struct skl_sst
*ctx
, u32
*params
, int size
,
1173 u32 param_id
, struct skl_module_cfg
*mcfg
)
1175 struct skl_ipc_large_config_msg msg
;
1177 msg
.module_id
= mcfg
->id
.module_id
;
1178 msg
.instance_id
= mcfg
->id
.instance_id
;
1179 msg
.param_data_size
= size
;
1180 msg
.large_param_id
= param_id
;
1182 return skl_ipc_get_large_config(&ctx
->ipc
, &msg
, params
);