From 0933bddee0430107182e3593366bda20042e1659 Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Wed, 2 Jan 2019 16:59:28 +0800 Subject: [PATCH 1/2] dai: only get dma channel at first config For dais, we don't support change dma channel dynamically, so only get dma channel at first config, ignore that for latter dai_config invokings to avoid dma channel leaking. Signed-off-by: Keyon Jie --- src/audio/dai.c | 7 +++++-- src/include/sof/dma.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/audio/dai.c b/src/audio/dai.c index f61b822459a9..0ecb8e39306c 100644 --- a/src/audio/dai.c +++ b/src/audio/dai.c @@ -236,6 +236,7 @@ static struct comp_dev *dai_new(struct sof_ipc_comp *comp) dd->dai_pos_blks = 0; dd->xrun = 0; dd->pointer_init = 0; + dd->chan = DMA_CHAN_INVALID; dev->state = COMP_STATE_READY; return dev; @@ -747,8 +748,10 @@ static int dai_config(struct comp_dev *dev, struct sof_ipc_dai_config *config) return -EINVAL; } - /* channel is ignored by GP dma get function */ - dd->chan = dma_channel_get(dd->dma, channel); + if (dd->chan == DMA_CHAN_INVALID) + /* get dma channel at first config only */ + dd->chan = dma_channel_get(dd->dma, channel); + if (dd->chan < 0) { trace_dai_error("dai_config() error: dma_channel_get() failed"); return -EIO; diff --git a/src/include/sof/dma.h b/src/include/sof/dma.h index bf03fb8c4cb8..68cfa8d49f6e 100644 --- a/src/include/sof/dma.h +++ b/src/include/sof/dma.h @@ -89,6 +89,8 @@ #define DMA_RELOAD_END 0 #define DMA_RELOAD_LLI 0xFFFFFFFF +#define DMA_CHAN_INVALID 0xFFFFFFFF + struct dma; /** From 572ea83890e31b6442d1c4cb986c9a058960faf9 Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Wed, 2 Jan 2019 17:33:37 +0800 Subject: [PATCH 2/2] host: reset dma channel to invalid by default This will be helpful for error reporting at host dma channel management. Signed-off-by: Keyon Jie --- src/audio/host.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/audio/host.c b/src/audio/host.c index e65ccdb354f5..04f7d289c74b 100644 --- a/src/audio/host.c +++ b/src/audio/host.c @@ -389,6 +389,8 @@ static struct comp_dev *host_new(struct sof_ipc_comp *comp) goto error; #endif + hd->chan = DMA_CHAN_INVALID; + /* init posn data. TODO: other fields */ hd->posn.comp_id = comp->id; hd->pointer_init = 0; @@ -644,6 +646,9 @@ static int host_reset(struct comp_dev *dev) dma_sg_free(&hd->config.elem_array); #endif + /* reset dma channel as we have put it */ + hd->chan = DMA_CHAN_INVALID; + host_pointer_reset(dev); hd->pointer_init = 0; #if !defined CONFIG_DMA_GW