Skip to content

Commit b31d3fa

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 b31d3fa

File tree

6 files changed

+40
-14
lines changed

6 files changed

+40
-14
lines changed

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

Lines changed: 4 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, HDA_STREAM_USE_HOST_LINK_DMA);
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, HDA_STREAM_USE_HOST_LINK_DMA);
114114
return ERR_PTR(ret);
115115
}
116116
EXPORT_SYMBOL_NS(hda_cl_prepare, "SND_SOC_SOF_INTEL_HDA_COMMON");
@@ -286,7 +286,8 @@ 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,
290+
HDA_STREAM_USE_HOST_LINK_DMA);
290291
hstream->running = 0;
291292
hstream->substream = NULL;
292293

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, HDA_STREAM_USE_HOST_DMA);
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, HDA_STREAM_USE_HOST_DMA);
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, HDA_STREAM_USE_HOST_DMA);
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, HDA_STREAM_USE_HOST_DMA);
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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ 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,
215+
enum sof_hda_stream_type type)
215216
{
216217
const struct sof_intel_dsp_desc *chip_info = get_chip_info(sdev->pdata);
217218
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
@@ -233,7 +234,14 @@ hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags)
233234
if (hda_stream->host_reserved)
234235
continue;
235236

237+
/* check if the link stream is available if the link dma is used */
238+
if (type == HDA_STREAM_USE_HOST_LINK_DMA && hext_stream->link_locked)
239+
continue;
240+
236241
s->opened = true;
242+
if (type == HDA_STREAM_USE_HOST_LINK_DMA)
243+
hext_stream->link_locked = true;
244+
237245
break;
238246
}
239247
}
@@ -265,13 +273,15 @@ hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags)
265273
}
266274

267275
/* free a stream */
268-
int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag)
276+
int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag,
277+
enum sof_hda_stream_type type)
269278
{
270279
const struct sof_intel_dsp_desc *chip_info = get_chip_info(sdev->pdata);
271280
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
272281
struct hdac_bus *bus = sof_to_bus(sdev);
273282
struct sof_intel_hda_stream *hda_stream;
274283
struct hdac_ext_stream *hext_stream;
284+
struct hdac_ext_stream *link_stream;
275285
struct hdac_stream *s;
276286
bool dmi_l1_enable = true;
277287
bool found = false;
@@ -292,6 +302,10 @@ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag)
292302
if (s->direction == direction && s->stream_tag == stream_tag) {
293303
s->opened = false;
294304
found = true;
305+
306+
if (type == HDA_STREAM_USE_HOST_LINK_DMA)
307+
link_stream = hext_stream;
308+
295309
} else if (!(hda_stream->flags & SOF_HDA_STREAM_DMI_L1_COMPATIBLE)) {
296310
dmi_l1_enable = false;
297311
}
@@ -312,6 +326,9 @@ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag)
312326
return -ENODEV;
313327
}
314328

329+
if (type == HDA_STREAM_USE_HOST_LINK_DMA)
330+
snd_hdac_ext_stream_release(link_stream, HDAC_EXT_STREAM_TYPE_LINK);
331+
315332
return 0;
316333
}
317334

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ 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,
47+
HDA_STREAM_USE_HOST_DMA);
4748

4849
if (!hda->dtrace_stream) {
4950
dev_err(sdev->dev,
@@ -61,7 +62,7 @@ int hda_dsp_trace_init(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
6162
if (ret < 0) {
6263
dev_err(sdev->dev, "error: hdac trace init failed: %d\n", ret);
6364
hda_dsp_stream_put(sdev, SNDRV_PCM_STREAM_CAPTURE,
64-
dtrace_params->stream_tag);
65+
dtrace_params->stream_tag, HDA_STREAM_USE_HOST_DMA);
6566
hda->dtrace_stream = NULL;
6667
dtrace_params->stream_tag = 0;
6768
}
@@ -79,7 +80,7 @@ int hda_dsp_trace_release(struct snd_sof_dev *sdev)
7980
hstream = &hda->dtrace_stream->hstream;
8081
hda_dsp_stream_put(sdev,
8182
SNDRV_PCM_STREAM_CAPTURE,
82-
hstream->stream_tag);
83+
hstream->stream_tag, HDA_STREAM_USE_HOST_DMA);
8384
hda->dtrace_stream = NULL;
8485
return 0;
8586
}

sound/soc/sof/intel/hda.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ enum sof_hda_D0_substate {
487487
SOF_HDA_DSP_PM_D0I3, /* low power D0 substate */
488488
};
489489

490+
enum sof_hda_stream_type {
491+
HDA_STREAM_USE_HOST_DMA,
492+
HDA_STREAM_USE_HOST_LINK_DMA,
493+
};
494+
490495
struct sof_ace3_mic_privacy {
491496
bool active;
492497
struct work_struct work;
@@ -693,8 +698,10 @@ u64 hda_dsp_get_stream_ldp(struct snd_sof_dev *sdev,
693698
struct snd_pcm_substream *substream);
694699

695700
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);
701+
hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, u32 flags,
702+
enum sof_hda_stream_type type);
703+
int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag,
704+
enum sof_hda_stream_type type);
698705
int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev,
699706
struct hdac_ext_stream *hext_stream,
700707
int enable, u32 size);

0 commit comments

Comments
 (0)