Skip to content

Commit

Permalink
ipc4: add helper function to parse dma config
Browse files Browse the repository at this point in the history
Add helper function to parse DMA config tlv structure added to copier
Init Instance IPC when it has gateway config. Retrieve proper
config when multiple gateway configs are present in IPC payload
using device address value.

Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
  • Loading branch information
iganakov committed Dec 14, 2023
1 parent 60b0e2d commit 8900ca1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/include/sof/audio/ipc-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ struct ipc_config_dai {
uint32_t feature_mask; /**< copier feature mask (set directly from
* ipc4_copier_module_cfg on init)
*/
struct ipc_dma_config *host_dma_config; /**< DMA config - required for ACE 2.0 and newer */
/**< DMA configs - required for ACE 2.0 and newer */
struct ipc_dma_config *host_dma_config[GTW_DMA_DEVICE_MAX_COUNT];
const struct ipc4_audio_format *out_fmt;/**< audio format for output pin 0 - required
* for ACE 2.0 and newer
*/
Expand Down
3 changes: 2 additions & 1 deletion src/include/sof/ipc/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ int ipc4_pipeline_complete(struct ipc *ipc, uint32_t comp_id, uint32_t cmd);
int ipc4_find_dma_config(struct ipc_config_dai *dai, uint8_t *data_buffer, uint32_t size);
int ipc4_pipeline_prepare(struct ipc_comp_dev *ppl_icd, uint32_t cmd);
int ipc4_pipeline_trigger(struct ipc_comp_dev *ppl_icd, uint32_t cmd, bool *delayed);

int ipc4_find_dma_config_multiple(struct ipc_config_dai *dai, uint8_t *data_buffer,
uint32_t size, uint32_t device_id);
#else
#error "No or invalid IPC MAJOR version selected."
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/ipc/ipc4/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void dai_set_link_hda_config(uint16_t *link_config,
case SOF_DAI_INTEL_SSP:
link_cfg.full = 0;
link_cfg.part.dir = common_config->direction;
link_cfg.part.stream = common_config->host_dma_config->stream_id;
link_cfg.part.stream = common_config->host_dma_config[0]->stream_id;
break;
case SOF_DAI_INTEL_DMIC:
link_cfg.full = 0;
Expand All @@ -57,7 +57,7 @@ void dai_set_link_hda_config(uint16_t *link_config,
} else {
link_cfg.part.hchan = out_fmt->channels_count - 1;
}
link_cfg.part.stream = common_config->host_dma_config->stream_id;
link_cfg.part.stream = common_config->host_dma_config[0]->stream_id;
break;
default:
/* other types of DAIs not need link_config */
Expand All @@ -79,8 +79,8 @@ int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void
case SOF_DAI_INTEL_DMIC:
channel = 0;
#if defined(CONFIG_ACE_VERSION_2_0)
if (dai->host_dma_config->pre_allocated_by_host)
channel = dai->host_dma_config->dma_channel_id;
if (dai->host_dma_config[0]->pre_allocated_by_host)
channel = dai->host_dma_config[0]->dma_channel_id;
#endif
break;
case SOF_DAI_INTEL_HDA:
Expand Down
36 changes: 35 additions & 1 deletion src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <ipc4/module.h>
#include <ipc4/error_status.h>
#include <sof/lib_manager.h>
#include <sof/tlv.h>

#include <errno.h>
#include <stdbool.h>
Expand Down Expand Up @@ -1002,11 +1003,44 @@ int ipc4_find_dma_config(struct ipc_config_dai *dai, uint8_t *data_buffer, uint3
if (*dma_config_id != GTW_DMA_CONFIG_ID)
return IPC4_INVALID_REQUEST;

dai->host_dma_config = GET_IPC_DMA_CONFIG(data_buffer, size);
dai->host_dma_config[0] = GET_IPC_DMA_CONFIG(data_buffer, size);
#endif
return IPC4_SUCCESS;
}

int ipc4_find_dma_config_multiple(struct ipc_config_dai *dai, uint8_t *data_buffer,
uint32_t size, uint32_t device_id)
{
uint32_t end_addr = (uint32_t)data_buffer + size;
struct ipc_dma_config *dma_cfg;
struct sof_tlv *tlvs;
int dma_cfg_count = 0;

for (tlvs = (struct sof_tlv *)data_buffer; (uint32_t)tlvs < end_addr;
tlvs = tlv_next(tlvs)) {

dma_cfg = tlv_value_ptr_get(tlvs, GTW_DMA_CONFIG_ID);
if (!dma_cfg)
continue;

if (dma_cfg->channel_map.device_count == 0) {
dai->host_dma_config[dma_cfg_count] = dma_cfg;
return IPC4_SUCCESS;
}

for (uint32_t i = 0; i < dma_cfg->channel_map.device_count; i++) {
if (dma_cfg->channel_map.map[i].device_address == device_id) {
dai->host_dma_config[dma_cfg_count] = dma_cfg;
return IPC4_SUCCESS;
}
}

dma_cfg_count++;
}

return IPC4_INVALID_REQUEST;
}

void ipc4_base_module_cfg_to_stream_params(const struct ipc4_base_module_cfg *base_cfg,
struct sof_ipc_stream_params *params)
{
Expand Down

0 comments on commit 8900ca1

Please sign in to comment.