Skip to content

Commit 943ac4c

Browse files
committed
ASoC: SOF: Intel: get/put hda_dsp_stream with use_link_dma flag
Currently, we get host and link DMA streams separately by hda_dsp_stream_get() and hda_link_stream_assign(). However, in some cases like SoundWire BPT, we use hda_dsp_stream_get() to get the HDA stream and use the same HDA stream for both host and link DMAs. Add a use_link_dma flag to handle the case. Signed-off-by: Bard Liao <[email protected]>
1 parent 4ded0e1 commit 943ac4c

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

sound/soc/sof/intel/hda-loader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ hda_cl_prepare(struct device *dev, unsigned int format, unsigned int size,
5858
struct hdac_stream *hstream;
5959
int ret;
6060

61-
hext_stream = hda_dsp_stream_get(sdev, direction, 0);
61+
hext_stream = hda_dsp_stream_get(sdev, direction, 0, true);
6262

6363
if (!hext_stream) {
6464
dev_err(sdev->dev, "error: no stream available\n");
@@ -110,7 +110,7 @@ hda_cl_prepare(struct device *dev, unsigned int format, unsigned int size,
110110
hstream->bufsize = 0;
111111
hstream->format_val = 0;
112112
out_put:
113-
hda_dsp_stream_put(sdev, direction, hstream->stream_tag);
113+
hda_dsp_stream_put(sdev, direction, hstream->stream_tag, true);
114114
return ERR_PTR(ret);
115115
}
116116
EXPORT_SYMBOL_NS(hda_cl_prepare, "SND_SOC_SOF_INTEL_HDA_COMMON");
@@ -286,7 +286,7 @@ int hda_cl_cleanup(struct device *dev, struct snd_dma_buffer *dmab,
286286
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, sd_offset,
287287
SOF_HDA_SD_CTL_DMA_START, 0);
288288

289-
hda_dsp_stream_put(sdev, hstream->direction, hstream->stream_tag);
289+
hda_dsp_stream_put(sdev, hstream->direction, hstream->stream_tag, true);
290290
hstream->running = 0;
291291
hstream->substream = NULL;
292292

sound/soc/sof/intel/hda-pcm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev,
260260
spcm->stream[substream->stream].d0i3_compatible)
261261
flags |= SOF_HDA_STREAM_DMI_L1_COMPATIBLE;
262262

263-
dsp_stream = hda_dsp_stream_get(sdev, direction, flags);
263+
dsp_stream = hda_dsp_stream_get(sdev, direction, flags, false);
264264
if (!dsp_stream) {
265265
dev_err(sdev->dev, "error: no stream available\n");
266266
return -ENODEV;
@@ -326,7 +326,7 @@ int hda_dsp_pcm_close(struct snd_sof_dev *sdev,
326326
int direction = substream->stream;
327327
int ret;
328328

329-
ret = hda_dsp_stream_put(sdev, direction, hstream->stream_tag);
329+
ret = hda_dsp_stream_put(sdev, direction, hstream->stream_tag, false);
330330

331331
if (ret) {
332332
dev_dbg(sdev->dev, "stream %s not opened!\n", substream->name);

sound/soc/sof/intel/hda-probes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int hda_probes_compr_startup(struct sof_client_dev *cdev,
3232
struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
3333
struct hdac_ext_stream *hext_stream;
3434

35-
hext_stream = hda_dsp_stream_get(sdev, cstream->direction, 0);
35+
hext_stream = hda_dsp_stream_get(sdev, cstream->direction, 0, false);
3636
if (!hext_stream)
3737
return -EBUSY;
3838

@@ -54,7 +54,7 @@ static int hda_probes_compr_shutdown(struct sof_client_dev *cdev,
5454
int ret;
5555

5656
ret = hda_dsp_stream_put(sdev, cstream->direction,
57-
hdac_stream(hext_stream)->stream_tag);
57+
hdac_stream(hext_stream)->stream_tag, false);
5858
if (ret < 0) {
5959
dev_dbg(sdev->dev, "stream put failed: %d\n", ret);
6060
return ret;

sound/soc/sof/intel/hda-stream.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev,
211211

212212
/* get next unused stream */
213213
struct hdac_ext_stream *
214-
hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags)
214+
hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags, bool use_link_dma)
215215
{
216216
const struct sof_intel_dsp_desc *chip_info = get_chip_info(sdev->pdata);
217217
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
@@ -233,7 +233,14 @@ hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags)
233233
if (hda_stream->host_reserved)
234234
continue;
235235

236+
/* check if the link stream is available if the link dma is used */
237+
if (use_link_dma && hext_stream->link_locked)
238+
continue;
239+
236240
s->opened = true;
241+
if (use_link_dma)
242+
hext_stream->link_locked = true;
243+
237244
break;
238245
}
239246
}
@@ -265,13 +272,14 @@ hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags)
265272
}
266273

267274
/* free a stream */
268-
int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag)
275+
int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag, bool use_link_dma)
269276
{
270277
const struct sof_intel_dsp_desc *chip_info = get_chip_info(sdev->pdata);
271278
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
272279
struct hdac_bus *bus = sof_to_bus(sdev);
273280
struct sof_intel_hda_stream *hda_stream;
274281
struct hdac_ext_stream *hext_stream;
282+
struct hdac_ext_stream *link_stream;
275283
struct hdac_stream *s;
276284
bool dmi_l1_enable = true;
277285
bool found = false;
@@ -292,6 +300,10 @@ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag)
292300
if (s->direction == direction && s->stream_tag == stream_tag) {
293301
s->opened = false;
294302
found = true;
303+
304+
if (use_link_dma)
305+
link_stream = hext_stream;
306+
295307
} else if (!(hda_stream->flags & SOF_HDA_STREAM_DMI_L1_COMPATIBLE)) {
296308
dmi_l1_enable = false;
297309
}
@@ -312,6 +324,9 @@ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag)
312324
return -ENODEV;
313325
}
314326

327+
if (use_link_dma)
328+
snd_hdac_ext_stream_release(link_stream, HDAC_EXT_STREAM_TYPE_LINK);
329+
315330
return 0;
316331
}
317332

sound/soc/sof/intel/hda-trace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int hda_dsp_trace_init(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
4343
int ret;
4444

4545
hda->dtrace_stream = hda_dsp_stream_get(sdev, SNDRV_PCM_STREAM_CAPTURE,
46-
SOF_HDA_STREAM_DMI_L1_COMPATIBLE);
46+
SOF_HDA_STREAM_DMI_L1_COMPATIBLE, false);
4747

4848
if (!hda->dtrace_stream) {
4949
dev_err(sdev->dev,
@@ -61,7 +61,7 @@ int hda_dsp_trace_init(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
6161
if (ret < 0) {
6262
dev_err(sdev->dev, "error: hdac trace init failed: %d\n", ret);
6363
hda_dsp_stream_put(sdev, SNDRV_PCM_STREAM_CAPTURE,
64-
dtrace_params->stream_tag);
64+
dtrace_params->stream_tag, false);
6565
hda->dtrace_stream = NULL;
6666
dtrace_params->stream_tag = 0;
6767
}
@@ -79,7 +79,7 @@ int hda_dsp_trace_release(struct snd_sof_dev *sdev)
7979
hstream = &hda->dtrace_stream->hstream;
8080
hda_dsp_stream_put(sdev,
8181
SNDRV_PCM_STREAM_CAPTURE,
82-
hstream->stream_tag);
82+
hstream->stream_tag, false);
8383
hda->dtrace_stream = NULL;
8484
return 0;
8585
}

sound/soc/sof/intel/hda.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,9 @@ u64 hda_dsp_get_stream_ldp(struct snd_sof_dev *sdev,
693693
struct snd_pcm_substream *substream);
694694

695695
struct hdac_ext_stream *
696-
hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags);
697-
int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag);
696+
hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags,
697+
bool same_host_link_dma);
698+
int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag, bool use_link_dma);
698699
int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev,
699700
struct hdac_ext_stream *hext_stream,
700701
int enable, u32 size);

0 commit comments

Comments
 (0)