From eb8f4b6469c8b5f1a27db5883102759a9b5998a7 Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Fri, 19 Oct 2018 13:48:52 +0800 Subject: [PATCH 1/2] ASOC: SOF: refine hda stream management for dma trace (1) remove redundant stream get function for different direction (2) get last capture stream for dma trace. this make FW easier to manage dma channels just from index 0, or it is complex to match host dma and link dma because the channel of host dma would be based on one, but zero with link dma Signed-off-by: Rander Wang --- sound/soc/sof/intel/hda-loader.c | 2 +- sound/soc/sof/intel/hda-pcm.c | 6 +-- sound/soc/sof/intel/hda-stream.c | 74 ++++++++------------------------ sound/soc/sof/intel/hda-trace.c | 7 ++- sound/soc/sof/intel/hda.h | 7 +-- 5 files changed, 27 insertions(+), 69 deletions(-) diff --git a/sound/soc/sof/intel/hda-loader.c b/sound/soc/sof/intel/hda-loader.c index 796d772a6a8d30..7fef1b33961c5b 100644 --- a/sound/soc/sof/intel/hda-loader.c +++ b/sound/soc/sof/intel/hda-loader.c @@ -44,7 +44,7 @@ static int cl_stream_prepare(struct snd_sof_dev *sdev, unsigned int format, int ret; if (direction == SNDRV_PCM_STREAM_PLAYBACK) { - stream = hda_dsp_stream_get_pstream(sdev); + stream = hda_dsp_stream_get(sdev, direction, FALSE); } else { dev_err(sdev->dev, "error: code loading DMA is playback only\n"); return -EINVAL; diff --git a/sound/soc/sof/intel/hda-pcm.c b/sound/soc/sof/intel/hda-pcm.c index d5a09dcceeee4d..de0711ee795d0c 100644 --- a/sound/soc/sof/intel/hda-pcm.c +++ b/sound/soc/sof/intel/hda-pcm.c @@ -212,11 +212,7 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev, { struct hdac_ext_stream *stream; - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - stream = hda_dsp_stream_get_pstream(sdev); - else - stream = hda_dsp_stream_get_cstream(sdev); - + stream = hda_dsp_stream_get(sdev, substream->stream, FALSE); if (!stream) { dev_err(sdev->dev, "error: no stream available\n"); return -ENODEV; diff --git a/sound/soc/sof/intel/hda-stream.c b/sound/soc/sof/intel/hda-stream.c index a9189058f5dfc4..5d0025c33e4ebd 100644 --- a/sound/soc/sof/intel/hda-stream.c +++ b/sound/soc/sof/intel/hda-stream.c @@ -165,18 +165,28 @@ int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev, /* get next unused stream */ struct hdac_ext_stream * -hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction) +hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, int reverse) { struct hdac_bus *bus = sof_to_bus(sdev); struct hdac_ext_stream *stream = NULL; struct hdac_stream *s; - /* get an unused playback stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == direction && !s->opened) { - s->opened = true; - stream = stream_to_hdac_ext_stream(s); - break; + /* get an unused stream */ + if (reverse) { + list_for_each_entry_reverse(s, &bus->stream_list, list) { + if (s->direction == direction && !s->opened) { + s->opened = true; + stream = stream_to_hdac_ext_stream(s); + break; + } + } + } else { + list_for_each_entry(s, &bus->stream_list, list) { + if (s->direction == direction && !s->opened) { + s->opened = true; + stream = stream_to_hdac_ext_stream(s); + break; + } } } @@ -189,56 +199,6 @@ hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction) return stream; } -/* get next unused playback stream */ -struct hdac_ext_stream * -hda_dsp_stream_get_pstream(struct snd_sof_dev *sdev) -{ - struct hdac_bus *bus = sof_to_bus(sdev); - struct hdac_ext_stream *stream = NULL; - struct hdac_stream *s; - - /* get an unused playback stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == SNDRV_PCM_STREAM_PLAYBACK - && !s->opened) { - s->opened = true; - stream = stream_to_hdac_ext_stream(s); - break; - } - } - - /* stream found ? */ - if (!stream) - dev_err(sdev->dev, "error: no free playback streams\n"); - - return stream; -} - -/* get next unused capture stream */ -struct hdac_ext_stream * -hda_dsp_stream_get_cstream(struct snd_sof_dev *sdev) -{ - struct hdac_bus *bus = sof_to_bus(sdev); - struct hdac_ext_stream *stream = NULL; - struct hdac_stream *s; - - /* get an unused capture stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == SNDRV_PCM_STREAM_CAPTURE - && !s->opened) { - s->opened = true; - stream = stream_to_hdac_ext_stream(s); - break; - } - } - - /* stream found ? */ - if (!stream) - dev_err(sdev->dev, "error: no free capture streams\n"); - - return stream; -} - /* free a stream */ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int tag) { diff --git a/sound/soc/sof/intel/hda-trace.c b/sound/soc/sof/intel/hda-trace.c index a1c9f1b45dca14..b4b589251fd11f 100644 --- a/sound/soc/sof/intel/hda-trace.c +++ b/sound/soc/sof/intel/hda-trace.c @@ -52,7 +52,12 @@ static int hda_dsp_trace_prepare(struct snd_sof_dev *sdev) int hda_dsp_trace_init(struct snd_sof_dev *sdev, u32 *tag) { - sdev->hda->dtrace_stream = hda_dsp_stream_get_cstream(sdev); + /* get last capture stream for dma trace, this make FW easier + * to manage dma channels just from index 0 + */ + sdev->hda->dtrace_stream = hda_dsp_stream_get(sdev, + SNDRV_PCM_STREAM_CAPTURE, + TRUE); if (!sdev->hda->dtrace_stream) { dev_err(sdev->dev, diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h index 5e27345022a86d..1f6fe775693622 100644 --- a/sound/soc/sof/intel/hda.h +++ b/sound/soc/sof/intel/hda.h @@ -451,11 +451,8 @@ int hda_dsp_stream_setup_bdl(struct snd_sof_dev *sdev, struct hdac_stream *stream); struct hdac_ext_stream * - hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction); -struct hdac_ext_stream * - hda_dsp_stream_get_cstream(struct snd_sof_dev *sdev); -struct hdac_ext_stream * - hda_dsp_stream_get_pstream(struct snd_sof_dev *sdev); + hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, + int reverse); int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag); int hda_dsp_stream_put_pstream(struct snd_sof_dev *sdev, int stream_tag); int hda_dsp_stream_put_cstream(struct snd_sof_dev *sdev, int stream_tag); From 0d45e4418fd82126cc2eac3e20351bf58d87085c Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Fri, 19 Oct 2018 14:05:41 +0800 Subject: [PATCH 2/2] ASOC: SOF: remove redundant stream function Signed-off-by: Rander Wang --- sound/soc/sof/intel/hda-loader.c | 3 ++- sound/soc/sof/intel/hda-pcm.c | 6 ++--- sound/soc/sof/intel/hda-stream.c | 38 -------------------------------- sound/soc/sof/intel/hda-trace.c | 5 +++-- sound/soc/sof/intel/hda.h | 2 -- 5 files changed, 7 insertions(+), 47 deletions(-) diff --git a/sound/soc/sof/intel/hda-loader.c b/sound/soc/sof/intel/hda-loader.c index 7fef1b33961c5b..d423f751ade3c3 100644 --- a/sound/soc/sof/intel/hda-loader.c +++ b/sound/soc/sof/intel/hda-loader.c @@ -77,7 +77,8 @@ static int cl_stream_prepare(struct snd_sof_dev *sdev, unsigned int format, return hstream->stream_tag; error: - hda_dsp_stream_put_pstream(sdev, hstream->stream_tag); + hda_dsp_stream_put(sdev, SNDRV_PCM_STREAM_PLAYBACK, + hstream->stream_tag); snd_dma_free_pages(dmab); return ret; } diff --git a/sound/soc/sof/intel/hda-pcm.c b/sound/soc/sof/intel/hda-pcm.c index de0711ee795d0c..07a85a409de363 100644 --- a/sound/soc/sof/intel/hda-pcm.c +++ b/sound/soc/sof/intel/hda-pcm.c @@ -229,10 +229,8 @@ int hda_dsp_pcm_close(struct snd_sof_dev *sdev, struct hdac_stream *hstream = substream->runtime->private_data; int ret; - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - ret = hda_dsp_stream_put_pstream(sdev, hstream->stream_tag); - else - ret = hda_dsp_stream_put_cstream(sdev, hstream->stream_tag); + ret = hda_dsp_stream_put(sdev, substream->stream, + hstream->stream_tag); if (ret) { dev_dbg(sdev->dev, "stream %s not opened!\n", substream->name); diff --git a/sound/soc/sof/intel/hda-stream.c b/sound/soc/sof/intel/hda-stream.c index 5d0025c33e4ebd..2547bb50fe815e 100644 --- a/sound/soc/sof/intel/hda-stream.c +++ b/sound/soc/sof/intel/hda-stream.c @@ -218,44 +218,6 @@ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int tag) return -ENODEV; } -/* free playback stream */ -int hda_dsp_stream_put_pstream(struct snd_sof_dev *sdev, int tag) -{ - struct hdac_bus *bus = sof_to_bus(sdev); - struct hdac_stream *s; - - /* find used playback stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == SNDRV_PCM_STREAM_PLAYBACK - && s->opened && s->stream_tag == tag) { - s->opened = false; - return 0; - } - } - - dev_dbg(sdev->dev, "tag %d not opened!\n", tag); - return -ENODEV; -} - -/* free capture stream */ -int hda_dsp_stream_put_cstream(struct snd_sof_dev *sdev, int tag) -{ - struct hdac_bus *bus = sof_to_bus(sdev); - struct hdac_stream *s; - - /* find used capture stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == SNDRV_PCM_STREAM_CAPTURE - && s->opened && s->stream_tag == tag) { - s->opened = false; - return 0; - } - } - - dev_dbg(sdev->dev, "tag %d not opened!\n", tag); - return -ENODEV; -} - int hda_dsp_stream_trigger(struct snd_sof_dev *sdev, struct hdac_ext_stream *stream, int cmd) { diff --git a/sound/soc/sof/intel/hda-trace.c b/sound/soc/sof/intel/hda-trace.c index b4b589251fd11f..d2464564ed22dd 100644 --- a/sound/soc/sof/intel/hda-trace.c +++ b/sound/soc/sof/intel/hda-trace.c @@ -81,8 +81,9 @@ int hda_dsp_trace_release(struct snd_sof_dev *sdev) if (sdev->hda->dtrace_stream) { hstream = &sdev->hda->dtrace_stream->hstream; hstream->opened = false; - hda_dsp_stream_put_cstream(sdev, - hstream->stream_tag); + hda_dsp_stream_put(sdev, + SNDRV_PCM_STREAM_CAPTURE, + hstream->stream_tag); sdev->hda->dtrace_stream = NULL; return 0; } diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h index 1f6fe775693622..32a1bd680eadff 100644 --- a/sound/soc/sof/intel/hda.h +++ b/sound/soc/sof/intel/hda.h @@ -454,8 +454,6 @@ struct hdac_ext_stream * hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, int reverse); int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag); -int hda_dsp_stream_put_pstream(struct snd_sof_dev *sdev, int stream_tag); -int hda_dsp_stream_put_cstream(struct snd_sof_dev *sdev, int stream_tag); int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev, struct hdac_ext_stream *stream, int enable, u32 size);