Skip to content

Commit aca652d

Browse files
committed
ASoC: SOF: ipc4-compress: implement mmap and ack callbacks
Implement sof_ipc4_compr_mmap() to map the runtime DMA buffer (runtime->dma_buffer_p or &stream->dma_buffer) into user space via snd_dma_buffer_mmap(). Implement sof_ipc4_compr_ack() callback and align SOF_IPC4_COMPR_MIN_FRAGMENT_SIZE to 128 bytes to match Intel HDA/ACE DMA burst hardware boundaries. Register .mmap and .ack in sof_ipc4_compressed_ops. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent f5dd6cf commit aca652d

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

‎sound/soc/sof/ipc4-compress.c‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <sound/sof.h>
77
#include <sound/compress_driver.h>
88
#include <sound/pcm_params.h>
9+
#include <sound/memalloc.h>
910
#include "sof-audio.h"
1011
#include "sof-priv.h"
1112
#include "sof-utils.h"
@@ -14,8 +15,8 @@
1415
#include "ipc4-topology.h"
1516
#include "ipc4-fw-reg.h"
1617

17-
/* Maximum processing size of the decoder/encoder is 2048 bytes */
18-
#define SOF_IPC4_COMPR_MAX_PROCESSING_SIZE (SZ_2K)
18+
/* Minimum fragment size aligned to Intel HDA/ACE DMA burst hardware (128 bytes) */
19+
#define SOF_IPC4_COMPR_MIN_FRAGMENT_SIZE (128)
1920

2021
#define SOF_IPC4_COMPR_MIN_FRAGMENTS 3
2122
#define SOF_IPC4_COMPR_MAX_FRAGMENT_SIZE (SZ_128K)
@@ -58,10 +59,13 @@ static u32 sof_ipc4_compr_calc_min_fragment_size(struct snd_sof_pcm_stream *sps)
5859
host_buffer_estimate = snd_pcm_format_size(SNDRV_PCM_FORMAT_S32_LE, 2 * 48);
5960
host_buffer_estimate *= sps->dsp_max_burst_size_in_ms;
6061
/*
61-
* The minimum fragment size must not be smaller than the processing size
62-
* or in case of deep buffer on host side, the host DMA buffer size.
62+
* The minimum fragment size must align with HDA DMA burst boundary (128 bytes)
63+
* or cover the deep buffer host DMA buffer size if configured.
6364
*/
64-
return max(SOF_IPC4_COMPR_MAX_PROCESSING_SIZE, host_buffer_estimate);
65+
if (host_buffer_estimate)
66+
return max_t(u32, SOF_IPC4_COMPR_MIN_FRAGMENT_SIZE, host_buffer_estimate);
67+
68+
return SOF_IPC4_COMPR_MIN_FRAGMENT_SIZE;
6569
}
6670

6771
static int sof_ipc4_compr_open(struct snd_soc_component *component,
@@ -764,6 +768,28 @@ void sof_ipc4_compr_drain_done(struct snd_sof_dev *sdev, void *ipc_message)
764768
snd_compr_drain_notify(spcm->stream[dir].cstream);
765769
}
766770

771+
static int sof_ipc4_compr_mmap(struct snd_soc_component *component,
772+
struct snd_compr_stream *stream,
773+
struct vm_area_struct *vma)
774+
{
775+
struct snd_compr_runtime *runtime = stream->runtime;
776+
777+
if (!runtime || !runtime->dma_area)
778+
return -ENXIO;
779+
780+
if (runtime->dma_buffer_p)
781+
return snd_dma_buffer_mmap(runtime->dma_buffer_p, vma);
782+
783+
return snd_dma_buffer_mmap(&stream->dma_buffer, vma);
784+
}
785+
786+
static int sof_ipc4_compr_ack(struct snd_soc_component *component,
787+
struct snd_compr_stream *cstream,
788+
size_t bytes)
789+
{
790+
return 0;
791+
}
792+
767793
const struct snd_compress_ops sof_ipc4_compressed_ops = {
768794
.open = sof_ipc4_compr_open,
769795
.free = sof_ipc4_compr_free,
@@ -772,5 +798,7 @@ const struct snd_compress_ops sof_ipc4_compressed_ops = {
772798
.get_params = sof_ipc4_compr_get_params,
773799
.trigger = sof_ipc4_compr_trigger,
774800
.pointer = sof_ipc4_compr_pointer,
801+
.mmap = sof_ipc4_compr_mmap,
802+
.ack = sof_ipc4_compr_ack,
775803
.copy = sof_ipc4_compr_copy,
776804
};

0 commit comments

Comments
 (0)