Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Add support to compress API to ipc_msg_data /

Merge series from Daniel Baluta <daniel.baluta@oss.nxp.com>:

This patch series adds compress API support to ipc_msg_data /
set_stream_data_offset callbacks.

Changes since v1:
- fixed reviewed-by list (+Peter, -Pierre). Since github had
some glitches I added the reviews received manually in the
commits.
- Github PR link: https://github.com/thesofproject/linux/pull/4133

Daniel Baluta (4):
ASoC: SOF: Prepare ipc_msg_data to be used with compress API
ASoC: SOF: Prepare set_stream_data_offset for compress API
ASoC: SOF: Add support for compress API for stream data/offset
ASoC: SOF: compress: Set compress data offset

sound/soc/sof/amd/acp-ipc.c | 8 ++--
sound/soc/sof/amd/acp.h | 5 ++-
sound/soc/sof/compress.c | 9 +++++
sound/soc/sof/intel/hda-ipc.c | 8 ++--
sound/soc/sof/intel/hda.h | 4 +-
sound/soc/sof/ipc3-pcm.c | 3 +-
sound/soc/sof/ipc3.c | 4 +-
sound/soc/sof/mediatek/mt8186/mt8186.c | 2 +-
sound/soc/sof/mediatek/mt8195/mt8195.c | 2 +-
sound/soc/sof/ops.h | 8 ++--
sound/soc/sof/sof-priv.h | 11 ++++--
sound/soc/sof/stream-ipc.c | 53 +++++++++++++++++++-------
12 files changed, 81 insertions(+), 36 deletions(-)

--
2.25.1

+81 -36
+5 -3
sound/soc/sof/amd/acp-ipc.c
··· 200 200 } 201 201 EXPORT_SYMBOL_NS(acp_sof_ipc_irq_thread, SND_SOC_SOF_AMD_COMMON); 202 202 203 - int acp_sof_ipc_msg_data(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream, 203 + int acp_sof_ipc_msg_data(struct snd_sof_dev *sdev, struct snd_sof_pcm_stream *sps, 204 204 void *p, size_t sz) 205 205 { 206 206 unsigned int offset = sdev->dsp_box.offset; 207 207 208 - if (!substream || !sdev->stream_box.size) { 208 + if (!sps || !sdev->stream_box.size) { 209 209 acp_mailbox_read(sdev, offset, p, sz); 210 210 } else { 211 + struct snd_pcm_substream *substream = sps->substream; 211 212 struct acp_dsp_stream *stream = substream->runtime->private_data; 212 213 213 214 if (!stream) ··· 222 221 EXPORT_SYMBOL_NS(acp_sof_ipc_msg_data, SND_SOC_SOF_AMD_COMMON); 223 222 224 223 int acp_set_stream_data_offset(struct snd_sof_dev *sdev, 225 - struct snd_pcm_substream *substream, 224 + struct snd_sof_pcm_stream *sps, 226 225 size_t posn_offset) 227 226 { 227 + struct snd_pcm_substream *substream = sps->substream; 228 228 struct acp_dsp_stream *stream = substream->runtime->private_data; 229 229 230 230 /* check for unaligned offset or overflow */
+3 -2
sound/soc/sof/amd/acp.h
··· 12 12 #define __SOF_AMD_ACP_H 13 13 14 14 #include "../sof-priv.h" 15 + #include "../sof-audio.h" 15 16 16 17 #define ACP_MAX_STREAM 8 17 18 ··· 212 211 213 212 /* IPC callbacks */ 214 213 irqreturn_t acp_sof_ipc_irq_thread(int irq, void *context); 215 - int acp_sof_ipc_msg_data(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream, 214 + int acp_sof_ipc_msg_data(struct snd_sof_dev *sdev, struct snd_sof_pcm_stream *sps, 216 215 void *p, size_t sz); 217 216 int acp_set_stream_data_offset(struct snd_sof_dev *sdev, 218 - struct snd_pcm_substream *substream, 217 + struct snd_sof_pcm_stream *sps, 219 218 size_t posn_offset); 220 219 int acp_sof_ipc_send_msg(struct snd_sof_dev *sdev, 221 220 struct snd_sof_ipc_msg *msg);
+9
sound/soc/sof/compress.c
··· 10 10 #include "sof-audio.h" 11 11 #include "sof-priv.h" 12 12 #include "sof-utils.h" 13 + #include "ops.h" 13 14 14 15 static void sof_set_transferred_bytes(struct sof_compr_stream *sstream, 15 16 u64 host_pos, u64 buffer_size) ··· 235 234 &ipc_params_reply, sizeof(ipc_params_reply)); 236 235 if (ret < 0) { 237 236 dev_err(component->dev, "error ipc failed\n"); 237 + goto out; 238 + } 239 + 240 + ret = snd_sof_set_stream_data_offset(sdev, &spcm->stream[cstream->direction], 241 + ipc_params_reply.posn_offset); 242 + if (ret < 0) { 243 + dev_err(component->dev, "Invalid stream data offset for Compr %d\n", 244 + spcm->pcm.pcm_id); 238 245 goto out; 239 246 } 240 247
+5 -3
sound/soc/sof/intel/hda-ipc.c
··· 361 361 } 362 362 363 363 int hda_ipc_msg_data(struct snd_sof_dev *sdev, 364 - struct snd_pcm_substream *substream, 364 + struct snd_sof_pcm_stream *sps, 365 365 void *p, size_t sz) 366 366 { 367 - if (!substream || !sdev->stream_box.size) { 367 + if (!sps || !sdev->stream_box.size) { 368 368 sof_mailbox_read(sdev, sdev->dsp_box.offset, p, sz); 369 369 } else { 370 + struct snd_pcm_substream *substream = sps->substream; 370 371 struct hdac_stream *hstream = substream->runtime->private_data; 371 372 struct sof_intel_hda_stream *hda_stream; 372 373 ··· 386 385 } 387 386 388 387 int hda_set_stream_data_offset(struct snd_sof_dev *sdev, 389 - struct snd_pcm_substream *substream, 388 + struct snd_sof_pcm_stream *sps, 390 389 size_t posn_offset) 391 390 { 391 + struct snd_pcm_substream *substream = sps->substream; 392 392 struct hdac_stream *hstream = substream->runtime->private_data; 393 393 struct sof_intel_hda_stream *hda_stream; 394 394
+2 -2
sound/soc/sof/intel/hda.h
··· 656 656 int enable, u32 size); 657 657 658 658 int hda_ipc_msg_data(struct snd_sof_dev *sdev, 659 - struct snd_pcm_substream *substream, 659 + struct snd_sof_pcm_stream *sps, 660 660 void *p, size_t sz); 661 661 int hda_set_stream_data_offset(struct snd_sof_dev *sdev, 662 - struct snd_pcm_substream *substream, 662 + struct snd_sof_pcm_stream *sps, 663 663 size_t posn_offset); 664 664 665 665 /*
+2 -1
sound/soc/sof/ipc3-pcm.c
··· 129 129 return ret; 130 130 } 131 131 132 - ret = snd_sof_set_stream_data_offset(sdev, substream, ipc_params_reply.posn_offset); 132 + ret = snd_sof_set_stream_data_offset(sdev, &spcm->stream[substream->stream], 133 + ipc_params_reply.posn_offset); 133 134 if (ret < 0) { 134 135 dev_err(component->dev, "%s: invalid stream data offset for PCM %d\n", 135 136 __func__, spcm->pcm.pcm_id);
+2 -2
sound/soc/sof/ipc3.c
··· 847 847 } 848 848 849 849 stream = &spcm->stream[direction]; 850 - ret = snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn)); 850 + ret = snd_sof_ipc_msg_data(sdev, stream, &posn, sizeof(posn)); 851 851 if (ret < 0) { 852 852 dev_warn(sdev->dev, "failed to read stream position: %d\n", ret); 853 853 return; ··· 882 882 } 883 883 884 884 stream = &spcm->stream[direction]; 885 - ret = snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn)); 885 + ret = snd_sof_ipc_msg_data(sdev, stream, &posn, sizeof(posn)); 886 886 if (ret < 0) { 887 887 dev_warn(sdev->dev, "failed to read overrun position: %d\n", ret); 888 888 return;
+1 -1
sound/soc/sof/mediatek/mt8186/mt8186.c
··· 494 494 } 495 495 496 496 stream = &spcm->stream[substream->stream]; 497 - ret = snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn)); 497 + ret = snd_sof_ipc_msg_data(sdev, stream, &posn, sizeof(posn)); 498 498 if (ret < 0) { 499 499 dev_warn(sdev->dev, "failed to read stream position: %d\n", ret); 500 500 return 0;
+1 -1
sound/soc/sof/mediatek/mt8195/mt8195.c
··· 520 520 } 521 521 522 522 stream = &spcm->stream[substream->stream]; 523 - ret = snd_sof_ipc_msg_data(sdev, stream->substream, &posn, sizeof(posn)); 523 + ret = snd_sof_ipc_msg_data(sdev, stream, &posn, sizeof(posn)); 524 524 if (ret < 0) { 525 525 dev_warn(sdev->dev, "failed to read stream position: %d\n", ret); 526 526 return 0;
+4 -4
sound/soc/sof/ops.h
··· 472 472 473 473 /* host DSP message data */ 474 474 static inline int snd_sof_ipc_msg_data(struct snd_sof_dev *sdev, 475 - struct snd_pcm_substream *substream, 475 + struct snd_sof_pcm_stream *sps, 476 476 void *p, size_t sz) 477 477 { 478 - return sof_ops(sdev)->ipc_msg_data(sdev, substream, p, sz); 478 + return sof_ops(sdev)->ipc_msg_data(sdev, sps, p, sz); 479 479 } 480 480 /* host side configuration of the stream's data offset in stream mailbox area */ 481 481 static inline int 482 482 snd_sof_set_stream_data_offset(struct snd_sof_dev *sdev, 483 - struct snd_pcm_substream *substream, 483 + struct snd_sof_pcm_stream *sps, 484 484 size_t posn_offset) 485 485 { 486 486 if (sof_ops(sdev) && sof_ops(sdev)->set_stream_data_offset) 487 - return sof_ops(sdev)->set_stream_data_offset(sdev, substream, 487 + return sof_ops(sdev)->set_stream_data_offset(sdev, sps, 488 488 posn_offset); 489 489 490 490 return 0;
+7 -4
sound/soc/sof/sof-priv.h
··· 20 20 #include <uapi/sound/sof/fw.h> 21 21 #include <sound/sof/ext_manifest.h> 22 22 23 + struct snd_sof_pcm_stream; 24 + 23 25 /* Flag definitions used in sof_core_debug (sof_debug module parameter) */ 24 26 #define SOF_DBG_ENABLE_TRACE BIT(0) 25 27 #define SOF_DBG_RETAIN_CTX BIT(1) /* prevent DSP D3 on FW exception */ ··· 115 113 u32 sampling_rate; 116 114 u16 channels; 117 115 u16 sample_container_bytes; 116 + size_t posn_offset; 118 117 }; 119 118 120 119 struct snd_sof_dev; ··· 250 247 251 248 /* host read DSP stream data */ 252 249 int (*ipc_msg_data)(struct snd_sof_dev *sdev, 253 - struct snd_pcm_substream *substream, 250 + struct snd_sof_pcm_stream *sps, 254 251 void *p, size_t sz); /* mandatory */ 255 252 256 253 /* host side configuration of the stream's data offset in stream mailbox area */ 257 254 int (*set_stream_data_offset)(struct snd_sof_dev *sdev, 258 - struct snd_pcm_substream *substream, 255 + struct snd_sof_pcm_stream *sps, 259 256 size_t posn_offset); /* optional */ 260 257 261 258 /* pre/post firmware run */ ··· 764 761 u32 offset, void *dest, size_t size); 765 762 766 763 int sof_ipc_msg_data(struct snd_sof_dev *sdev, 767 - struct snd_pcm_substream *substream, 764 + struct snd_sof_pcm_stream *sps, 768 765 void *p, size_t sz); 769 766 int sof_set_stream_data_offset(struct snd_sof_dev *sdev, 770 - struct snd_pcm_substream *substream, 767 + struct snd_sof_pcm_stream *sps, 771 768 size_t posn_offset); 772 769 773 770 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
+40 -13
sound/soc/sof/stream-ipc.c
··· 19 19 20 20 #include "ops.h" 21 21 #include "sof-priv.h" 22 + #include "sof-audio.h" 22 23 23 24 struct sof_stream { 24 25 size_t posn_offset; ··· 27 26 28 27 /* Mailbox-based Generic IPC implementation */ 29 28 int sof_ipc_msg_data(struct snd_sof_dev *sdev, 30 - struct snd_pcm_substream *substream, 29 + struct snd_sof_pcm_stream *sps, 31 30 void *p, size_t sz) 32 31 { 33 - if (!substream || !sdev->stream_box.size) { 32 + if (!sps || !sdev->stream_box.size) { 34 33 snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, p, sz); 35 34 } else { 36 - struct sof_stream *stream = substream->runtime->private_data; 35 + size_t posn_offset; 37 36 38 - /* The stream might already be closed */ 39 - if (!stream) 40 - return -ESTRPIPE; 37 + if (sps->substream) { 38 + struct sof_stream *stream = sps->substream->runtime->private_data; 41 39 42 - snd_sof_dsp_mailbox_read(sdev, stream->posn_offset, p, sz); 40 + /* The stream might already be closed */ 41 + if (!stream) 42 + return -ESTRPIPE; 43 + 44 + posn_offset = stream->posn_offset; 45 + } else { 46 + 47 + struct sof_compr_stream *sstream = sps->cstream->runtime->private_data; 48 + 49 + if (!sstream) 50 + return -ESTRPIPE; 51 + 52 + posn_offset = sstream->posn_offset; 53 + } 54 + 55 + snd_sof_dsp_mailbox_read(sdev, posn_offset, p, sz); 43 56 } 44 57 45 58 return 0; ··· 61 46 EXPORT_SYMBOL(sof_ipc_msg_data); 62 47 63 48 int sof_set_stream_data_offset(struct snd_sof_dev *sdev, 64 - struct snd_pcm_substream *substream, 49 + struct snd_sof_pcm_stream *sps, 65 50 size_t posn_offset) 66 51 { 67 - struct sof_stream *stream = substream->runtime->private_data; 68 - 69 52 /* check if offset is overflow or it is not aligned */ 70 53 if (posn_offset > sdev->stream_box.size || 71 54 posn_offset % sizeof(struct sof_ipc_stream_posn) != 0) 72 55 return -EINVAL; 73 56 74 - stream->posn_offset = sdev->stream_box.offset + posn_offset; 57 + posn_offset += sdev->stream_box.offset; 75 58 76 - dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu", 77 - substream->stream, stream->posn_offset); 59 + if (sps->substream) { 60 + struct sof_stream *stream = sps->substream->runtime->private_data; 61 + 62 + stream->posn_offset = posn_offset; 63 + dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu", 64 + sps->substream->stream, posn_offset); 65 + } else if (sps->cstream) { 66 + struct sof_compr_stream *sstream = sps->cstream->runtime->private_data; 67 + 68 + sstream->posn_offset = posn_offset; 69 + dev_dbg(sdev->dev, "compr: stream dir %d, posn mailbox offset is %zu", 70 + sps->cstream->direction, posn_offset); 71 + } else { 72 + dev_err(sdev->dev, "No stream opened"); 73 + return -EINVAL; 74 + } 78 75 79 76 return 0; 80 77 }