Skip to content

Commit a7a1cea

Browse files
committed
audio: host-zephyr: rework calls to DMA driver, remove channel pointer
For historical reasons, host-zephyr has somewhat complicated code to manage the DMA channel instance information. When a DMA channel is allocated, a pointer to the system DMA channel table is acquired and some additional information is stored per channel. This is however redundant as the only piece of information actually needed is the channel index. Simplify the code by not storing the channel pointer anymore, but rather just store the channel index and use that in all calls to the DMA driver. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent cfa5f02 commit a7a1cea

2 files changed

Lines changed: 24 additions & 29 deletions

File tree

src/audio/copier/host_copier.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ struct host_data {
5454
/* local DMA config */
5555
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
5656
struct sof_dma *dma;
57+
int chan_index;
5758
#else
5859
struct dma *dma;
59-
#endif
6060
struct dma_chan_data *chan;
61+
#endif
6162
struct dma_sg_config config;
6263
#ifdef __ZEPHYR__
6364
struct dma_config z_config;

src/audio/host-zephyr.c

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int host_dma_set_config_and_copy(struct host_data *hd, struct comp_dev *d
8484
local_elem->size = bytes;
8585

8686
/* reconfigure transfer */
87-
ret = sof_dma_config(hd->chan->dma, hd->chan->index, &hd->z_config);
87+
ret = sof_dma_config(hd->dma, hd->chan_index, &hd->z_config);
8888
if (ret < 0) {
8989
comp_err(dev, "dma_config() failed, ret = %d",
9090
ret);
@@ -93,7 +93,7 @@ static int host_dma_set_config_and_copy(struct host_data *hd, struct comp_dev *d
9393

9494
cb(dev, bytes);
9595

96-
ret = sof_dma_reload(hd->chan->dma, hd->chan->index, bytes);
96+
ret = sof_dma_reload(hd->dma, hd->chan_index, bytes);
9797
if (ret < 0) {
9898
comp_err(dev, "dma_copy() failed, ret = %d",
9999
ret);
@@ -223,15 +223,15 @@ static int host_copy_one_shot(struct host_data *hd, struct comp_dev *dev, copy_c
223223
hd->z_config.head_block->block_size = local_elem->size;
224224

225225
/* reconfigure transfer */
226-
ret = sof_dma_config(hd->chan->dma, hd->chan->index, &hd->z_config);
226+
ret = sof_dma_config(hd->dma, hd->chan_index, &hd->z_config);
227227
if (ret < 0) {
228228
comp_err(dev, "dma_config() failed, ret = %u", ret);
229229
return ret;
230230
}
231231

232232
cb(dev, copy_bytes);
233233

234-
ret = sof_dma_reload(hd->chan->dma, hd->chan->index, copy_bytes);
234+
ret = sof_dma_reload(hd->dma, hd->chan_index, copy_bytes);
235235
if (ret < 0)
236236
comp_err(dev, "dma_copy() failed, ret = %u", ret);
237237

@@ -369,7 +369,7 @@ static void host_dma_cb(struct comp_dev *dev, size_t bytes)
369369
/* get status from dma and check for xrun */
370370
static int host_get_status(struct comp_dev *dev, struct host_data *hd, struct dma_status *stat)
371371
{
372-
int ret = sof_dma_get_status(hd->chan->dma, hd->chan->index, stat);
372+
int ret = sof_dma_get_status(hd->dma, hd->chan_index, stat);
373373
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
374374
if (ret == -EPIPE && !hd->xrun_notification_sent) {
375375
hd->xrun_notification_sent = send_copier_gateway_xrun_notif_msg
@@ -556,7 +556,7 @@ static int host_copy_normal(struct host_data *hd, struct comp_dev *dev, copy_cal
556556
if (!copy_bytes) {
557557
if (hd->partial_size != 0) {
558558
if (stream_sync(hd, dev)) {
559-
ret = sof_dma_reload(hd->chan->dma, hd->chan->index,
559+
ret = sof_dma_reload(hd->dma, hd->chan_index,
560560
hd->partial_size);
561561
if (ret < 0)
562562
comp_err(dev, "dma_reload() failed, ret = %u", ret);
@@ -583,7 +583,7 @@ static int host_copy_normal(struct host_data *hd, struct comp_dev *dev, copy_cal
583583
hd->dma_buffer_size - hd->partial_size <=
584584
(2 + threshold) * hd->period_bytes) {
585585
if (stream_sync(hd, dev)) {
586-
ret = sof_dma_reload(hd->chan->dma, hd->chan->index,
586+
ret = sof_dma_reload(hd->dma, hd->chan_index,
587587
hd->partial_size);
588588
if (ret < 0)
589589
comp_err(dev, "dma_reload() failed, ret = %u", ret);
@@ -651,22 +651,22 @@ int host_common_trigger(struct host_data *hd, struct comp_dev *dev, int cmd)
651651
if (cmd != COMP_TRIGGER_START && hd->copy_type == COMP_COPY_ONE_SHOT)
652652
return ret;
653653

654-
if (!hd->chan) {
654+
if (hd->chan_index == -EINVAL) {
655655
comp_err(dev, "no dma channel configured");
656656
return -EINVAL;
657657
}
658658

659659
switch (cmd) {
660660
case COMP_TRIGGER_START:
661661
hd->partial_size = 0;
662-
ret = sof_dma_start(hd->chan->dma, hd->chan->index);
662+
ret = sof_dma_start(hd->dma, hd->chan_index);
663663
if (ret < 0)
664664
comp_err(dev, "dma_start() failed, ret = %u",
665665
ret);
666666
break;
667667
case COMP_TRIGGER_STOP:
668668
case COMP_TRIGGER_XRUN:
669-
ret = sof_dma_stop(hd->chan->dma, hd->chan->index);
669+
ret = sof_dma_stop(hd->dma, hd->chan_index);
670670
if (ret < 0)
671671
comp_err(dev, "dma stop failed: %d",
672672
ret);
@@ -726,7 +726,7 @@ __cold int host_common_new(struct host_data *hd, struct comp_dev *dev,
726726
sof_dma_put(hd->dma);
727727
return -ENOMEM;
728728
}
729-
hd->chan = NULL;
729+
hd->chan_index = -EINVAL;
730730
hd->copy_type = COMP_COPY_NORMAL;
731731

732732
return 0;
@@ -865,7 +865,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
865865
uint32_t buffer_size_preferred;
866866
uint32_t addr_align;
867867
uint32_t align;
868-
int i, channel, err;
868+
int i, err;
869869
bool is_scheduling_source = dev == dev->pipeline->sched_comp;
870870
uint32_t round_up_size;
871871

@@ -1001,22 +1001,16 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
10011001
/* get DMA channel from DMAC
10021002
* note: stream_tag is ignored by dw-dma
10031003
*/
1004-
channel = sof_dma_request_channel(hd->dma, hda_chan);
1005-
if (channel < 0) {
1004+
hd->chan_index = sof_dma_request_channel(hd->dma, hda_chan);
1005+
if (hd->chan_index < 0) {
10061006
comp_err(dev, "requested channel %d is busy", hda_chan);
10071007
return -ENODEV;
10081008
}
1009-
hd->chan = &hd->dma->chan[channel];
10101009

10111010
uint32_t buffer_addr = 0;
10121011
uint32_t buffer_bytes = 0;
10131012
uint32_t addr;
10141013

1015-
hd->chan->direction = config->direction;
1016-
hd->chan->desc_count = config->elem_array.count;
1017-
hd->chan->is_scheduling_source = config->is_scheduling_source;
1018-
hd->chan->period = config->period;
1019-
10201014
memset(dma_cfg, 0, sizeof(*dma_cfg));
10211015

10221016
dma_block_cfg = rzalloc(SOF_MEM_FLAG_USER,
@@ -1063,7 +1057,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
10631057
break;
10641058
}
10651059

1066-
err = sof_dma_config(hd->chan->dma, hd->chan->index, dma_cfg);
1060+
err = sof_dma_config(hd->dma, hd->chan_index, dma_cfg);
10671061
if (err < 0) {
10681062
comp_err(dev, "dma_config() failed");
10691063
goto err_free_block_cfg;
@@ -1095,7 +1089,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
10951089
*/
10961090
struct io_perf_data_item init_data = {
10971091
IO_PERF_HDA_ID,
1098-
hd->chan->index,
1092+
hd->chan_index,
10991093
params->direction,
11001094
IO_PERF_POWERED_UP_ENABLED,
11011095
IO_PERF_D0IX_POWER_MODE,
@@ -1111,8 +1105,8 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
11111105
dma_cfg->head_block = NULL;
11121106
rfree(dma_block_cfg);
11131107
err_release_channel:
1114-
sof_dma_release_channel(hd->dma, hd->chan->index);
1115-
hd->chan = NULL;
1108+
sof_dma_release_channel(hd->dma, hd->chan_index);
1109+
hd->chan_index = -EINVAL;
11161110

11171111
return err;
11181112
}
@@ -1170,10 +1164,10 @@ static int host_position(struct comp_dev *dev,
11701164

11711165
void host_common_reset(struct host_data *hd, uint16_t state)
11721166
{
1173-
if (hd->chan) {
1174-
sof_dma_stop(hd->chan->dma, hd->chan->index);
1175-
sof_dma_release_channel(hd->dma, hd->chan->index);
1176-
hd->chan = NULL;
1167+
if (hd->chan_index != -EINVAL) {
1168+
sof_dma_stop(hd->dma, hd->chan_index);
1169+
sof_dma_release_channel(hd->dma, hd->chan_index);
1170+
hd->chan_index = -EINVAL;
11771171
}
11781172

11791173
/* free all DMA elements */

0 commit comments

Comments
 (0)