Skip to content

Commit 477948d

Browse files
ranj063ujfalusi
authored andcommitted
ASoC: SOF: compress: Rename compress ops with ipc3 prefix
In preparation for adding support for compressed offload support for IPC4, rename the current compress implementation with the IPC3 prefix. Introduce a new field in struct sof_ipc_pcm_ops to save the IPC-specific compressed ops pointer. This should be set when the component driver ops are assigned during SOF device probe. Expose a couple of common functions that will be used by both IPC-specific implementations and rename the compress.c file to ipc3-compress.c Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent e0481a4 commit 477948d

8 files changed

Lines changed: 137 additions & 117 deletions

File tree

sound/soc/sof/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ifneq ($(CONFIG_SND_SOC_SOF_CLIENT),)
1919
snd-sof-y += sof-client.o
2020
endif
2121

22-
snd-sof-$(CONFIG_SND_SOC_SOF_COMPRESS) += compress.o
22+
snd-sof-$(CONFIG_SND_SOC_SOF_COMPRESS) += ipc3-compress.o
2323

2424
snd-sof-pci-y := sof-pci-dev.o
2525
snd-sof-acpi-y := sof-acpi-dev.o

sound/soc/sof/core.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,12 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
469469

470470
sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
471471

472-
/* set up platform component driver */
473-
snd_sof_new_platform_drv(sdev);
474-
475472
if (sdev->dspless_mode_selected) {
476473
sof_set_fw_state(sdev, SOF_DSPLESS_MODE);
474+
475+
/* set up platform component driver */
476+
snd_sof_new_platform_drv(sdev);
477+
477478
goto skip_dsp_init;
478479
}
479480

@@ -498,6 +499,9 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
498499
goto ipc_err;
499500
}
500501

502+
/* set up platform component driver after initializing the IPC ops */
503+
snd_sof_new_platform_drv(sdev);
504+
501505
/*
502506
* skip loading/booting firmware and registering the machine driver when DSP OPS testing
503507
* is enabled with IPC4. Normal audio operations will be unavailable in this mode.
Lines changed: 33 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -12,88 +12,8 @@
1212
#include "sof-utils.h"
1313
#include "ops.h"
1414

15-
static void sof_set_transferred_bytes(struct sof_compr_stream *sstream,
16-
u64 host_pos, u64 buffer_size)
17-
{
18-
u64 prev_pos;
19-
unsigned int copied;
20-
21-
div64_u64_rem(sstream->copied_total, buffer_size, &prev_pos);
22-
23-
if (host_pos < prev_pos)
24-
copied = (buffer_size - prev_pos) + host_pos;
25-
else
26-
copied = host_pos - prev_pos;
27-
28-
sstream->copied_total += copied;
29-
}
30-
31-
static void snd_sof_compr_fragment_elapsed_work(struct work_struct *work)
32-
{
33-
struct snd_sof_pcm_stream *sps =
34-
container_of(work, struct snd_sof_pcm_stream,
35-
period_elapsed_work);
36-
37-
snd_compr_fragment_elapsed(sps->cstream);
38-
}
39-
40-
void snd_sof_compr_init_elapsed_work(struct work_struct *work)
41-
{
42-
INIT_WORK(work, snd_sof_compr_fragment_elapsed_work);
43-
}
44-
45-
/*
46-
* sof compr fragment elapse, this could be called in irq thread context
47-
*/
48-
void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream)
49-
{
50-
struct snd_soc_pcm_runtime *rtd;
51-
struct snd_compr_runtime *crtd;
52-
struct snd_soc_component *component;
53-
struct sof_compr_stream *sstream;
54-
struct snd_sof_pcm *spcm;
55-
56-
if (!cstream)
57-
return;
58-
59-
rtd = cstream->private_data;
60-
crtd = cstream->runtime;
61-
sstream = crtd->private_data;
62-
component = snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
63-
64-
spcm = snd_sof_find_spcm_dai(component, rtd);
65-
if (!spcm) {
66-
dev_err(component->dev,
67-
"fragment elapsed called for unknown stream!\n");
68-
return;
69-
}
70-
71-
sof_set_transferred_bytes(sstream, spcm->stream[cstream->direction].posn.host_posn,
72-
crtd->buffer_size);
73-
74-
/* use the same workqueue-based solution as for PCM, cf. snd_sof_pcm_elapsed */
75-
schedule_work(&spcm->stream[cstream->direction].period_elapsed_work);
76-
}
77-
78-
static int create_page_table(struct snd_soc_component *component,
79-
struct snd_compr_stream *cstream,
80-
unsigned char *dma_area, size_t size)
81-
{
82-
struct snd_dma_buffer *dmab = cstream->runtime->dma_buffer_p;
83-
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
84-
int dir = cstream->direction;
85-
struct snd_sof_pcm *spcm;
86-
87-
spcm = snd_sof_find_spcm_dai(component, rtd);
88-
if (!spcm)
89-
return -EINVAL;
90-
91-
return snd_sof_create_page_table(component->dev, dmab,
92-
spcm->stream[dir].page_table.area, size);
93-
}
94-
95-
static int sof_compr_open(struct snd_soc_component *component,
96-
struct snd_compr_stream *cstream)
15+
static int sof_ipc3_compr_open(struct snd_soc_component *component,
16+
struct snd_compr_stream *cstream)
9717
{
9818
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
9919
struct snd_compr_runtime *crtd = cstream->runtime;
@@ -128,8 +48,8 @@ static int sof_compr_open(struct snd_soc_component *component,
12848
return 0;
12949
}
13050

131-
static int sof_compr_free(struct snd_soc_component *component,
132-
struct snd_compr_stream *cstream)
51+
static int sof_ipc3_compr_free(struct snd_soc_component *component,
52+
struct snd_compr_stream *cstream)
13353
{
13454
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
13555
struct sof_compr_stream *sstream = cstream->runtime->private_data;
@@ -159,8 +79,9 @@ static int sof_compr_free(struct snd_soc_component *component,
15979
return ret;
16080
}
16181

162-
static int sof_compr_set_params(struct snd_soc_component *component,
163-
struct snd_compr_stream *cstream, struct snd_compr_params *params)
82+
static int sof_ipc3_compr_set_params(struct snd_soc_component *component,
83+
struct snd_compr_stream *cstream,
84+
struct snd_compr_params *params)
16485
{
16586
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
16687
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
@@ -213,7 +134,7 @@ static int sof_compr_set_params(struct snd_soc_component *component,
213134
if (ret < 0)
214135
goto out;
215136

216-
ret = create_page_table(component, cstream, crtd->dma_area, crtd->dma_bytes);
137+
ret = snd_sof_compr_create_page_table(component, cstream, crtd->dma_area, crtd->dma_bytes);
217138
if (ret < 0)
218139
goto out;
219140

@@ -264,17 +185,18 @@ static int sof_compr_set_params(struct snd_soc_component *component,
264185
return ret;
265186
}
266187

267-
static int sof_compr_get_params(struct snd_soc_component *component,
268-
struct snd_compr_stream *cstream, struct snd_codec *params)
188+
static int sof_ipc3_compr_get_params(struct snd_soc_component *component,
189+
struct snd_compr_stream *cstream,
190+
struct snd_codec *params)
269191
{
270192
/* TODO: we don't query the supported codecs for now, if the
271193
* application asks for an unsupported codec the set_params() will fail.
272194
*/
273195
return 0;
274196
}
275197

276-
static int sof_compr_trigger(struct snd_soc_component *component,
277-
struct snd_compr_stream *cstream, int cmd)
198+
static int sof_ipc3_compr_trigger(struct snd_soc_component *component,
199+
struct snd_compr_stream *cstream, int cmd)
278200
{
279201
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
280202
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
@@ -310,8 +232,8 @@ static int sof_compr_trigger(struct snd_soc_component *component,
310232
return sof_ipc_tx_message_no_reply(sdev->ipc, &stream, sizeof(stream));
311233
}
312234

313-
static int sof_compr_copy_playback(struct snd_compr_runtime *rtd,
314-
char __user *buf, size_t count)
235+
static int sof_ipc3_compr_copy_playback(struct snd_compr_runtime *rtd,
236+
char __user *buf, size_t count)
315237
{
316238
void *ptr;
317239
unsigned int offset, n;
@@ -331,8 +253,8 @@ static int sof_compr_copy_playback(struct snd_compr_runtime *rtd,
331253
return count - ret;
332254
}
333255

334-
static int sof_compr_copy_capture(struct snd_compr_runtime *rtd,
335-
char __user *buf, size_t count)
256+
static int sof_ipc3_compr_copy_capture(struct snd_compr_runtime *rtd,
257+
char __user *buf, size_t count)
336258
{
337259
void *ptr;
338260
unsigned int offset, n;
@@ -352,24 +274,24 @@ static int sof_compr_copy_capture(struct snd_compr_runtime *rtd,
352274
return count - ret;
353275
}
354276

355-
static int sof_compr_copy(struct snd_soc_component *component,
356-
struct snd_compr_stream *cstream,
357-
char __user *buf, size_t count)
277+
static int sof_ipc3_compr_copy(struct snd_soc_component *component,
278+
struct snd_compr_stream *cstream,
279+
char __user *buf, size_t count)
358280
{
359281
struct snd_compr_runtime *rtd = cstream->runtime;
360282

361283
if (count > rtd->buffer_size)
362284
count = rtd->buffer_size;
363285

364286
if (cstream->direction == SND_COMPRESS_PLAYBACK)
365-
return sof_compr_copy_playback(rtd, buf, count);
287+
return sof_ipc3_compr_copy_playback(rtd, buf, count);
366288
else
367-
return sof_compr_copy_capture(rtd, buf, count);
289+
return sof_ipc3_compr_copy_capture(rtd, buf, count);
368290
}
369291

370-
static int sof_compr_pointer(struct snd_soc_component *component,
371-
struct snd_compr_stream *cstream,
372-
struct snd_compr_tstamp64 *tstamp)
292+
static int sof_ipc3_compr_pointer(struct snd_soc_component *component,
293+
struct snd_compr_stream *cstream,
294+
struct snd_compr_tstamp64 *tstamp)
373295
{
374296
struct snd_sof_pcm *spcm;
375297
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
@@ -387,13 +309,12 @@ static int sof_compr_pointer(struct snd_soc_component *component,
387309
return 0;
388310
}
389311

390-
struct snd_compress_ops sof_compressed_ops = {
391-
.open = sof_compr_open,
392-
.free = sof_compr_free,
393-
.set_params = sof_compr_set_params,
394-
.get_params = sof_compr_get_params,
395-
.trigger = sof_compr_trigger,
396-
.pointer = sof_compr_pointer,
397-
.copy = sof_compr_copy,
312+
const struct snd_compress_ops sof_ipc3_compressed_ops = {
313+
.open = sof_ipc3_compr_open,
314+
.free = sof_ipc3_compr_free,
315+
.set_params = sof_ipc3_compr_set_params,
316+
.get_params = sof_ipc3_compr_get_params,
317+
.trigger = sof_ipc3_compr_trigger,
318+
.pointer = sof_ipc3_compr_pointer,
319+
.copy = sof_ipc3_compr_copy,
398320
};
399-
EXPORT_SYMBOL(sof_compressed_ops);

sound/soc/sof/ipc3-pcm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,4 +436,7 @@ const struct sof_ipc_pcm_ops ipc3_pcm_ops = {
436436
.dai_link_fixup = sof_ipc3_pcm_dai_link_fixup,
437437
.reset_hw_params_during_stop = true,
438438
.d0i3_supported_in_s0ix = true,
439+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
440+
.compress_ops = &sof_ipc3_compressed_ops,
441+
#endif
439442
};

sound/soc/sof/ipc3-priv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ extern const struct sof_ipc_tplg_ops ipc3_tplg_ops;
1717
extern const struct sof_ipc_tplg_control_ops tplg_ipc3_control_ops;
1818
extern const struct sof_ipc_fw_loader_ops ipc3_loader_ops;
1919
extern const struct sof_ipc_fw_tracing_ops ipc3_dtrace_ops;
20+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
21+
extern const struct snd_compress_ops sof_ipc3_compressed_ops;
22+
#endif
2023

2124
/* helpers for fw_ready and ext_manifest parsing */
2225
int sof_ipc3_get_ext_windows(struct snd_sof_dev *sdev,

sound/soc/sof/pcm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,10 @@ void snd_sof_new_platform_drv(struct snd_sof_dev *sdev)
847847
pd->delay = sof_pcm_delay;
848848

849849
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
850-
pd->compress_ops = &sof_compressed_ops;
850+
const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
851+
852+
if (pcm_ops)
853+
pd->compress_ops = pcm_ops->compress_ops;
851854
#endif
852855

853856
pd->pcm_construct = sof_pcm_new;

sound/soc/sof/sof-audio.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/bitfield.h>
1212
#include <trace/events/sof.h>
1313
#include "sof-audio.h"
14+
#include "sof-utils.h"
1415
#include "ops.h"
1516

1617
/*
@@ -1052,3 +1053,83 @@ int sof_dai_get_tdm_slots(struct snd_soc_pcm_runtime *rtd)
10521053
return sof_dai_get_param(rtd, SOF_DAI_PARAM_INTEL_SSP_TDM_SLOTS);
10531054
}
10541055
EXPORT_SYMBOL(sof_dai_get_tdm_slots);
1056+
1057+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
1058+
static void sof_set_transferred_bytes(struct sof_compr_stream *sstream,
1059+
u64 host_pos, u64 buffer_size)
1060+
{
1061+
u64 prev_pos;
1062+
unsigned int copied;
1063+
1064+
div64_u64_rem(sstream->copied_total, buffer_size, &prev_pos);
1065+
1066+
if (host_pos < prev_pos)
1067+
copied = (buffer_size - prev_pos) + host_pos;
1068+
else
1069+
copied = host_pos - prev_pos;
1070+
1071+
sstream->copied_total += copied;
1072+
}
1073+
1074+
static void snd_sof_compr_fragment_elapsed_work(struct work_struct *work)
1075+
{
1076+
struct snd_sof_pcm_stream *sps = container_of(work, struct snd_sof_pcm_stream,
1077+
period_elapsed_work);
1078+
1079+
snd_compr_fragment_elapsed(sps->cstream);
1080+
}
1081+
1082+
void snd_sof_compr_init_elapsed_work(struct work_struct *work)
1083+
{
1084+
INIT_WORK(work, snd_sof_compr_fragment_elapsed_work);
1085+
}
1086+
1087+
/*
1088+
* sof compr fragment elapse, this could be called in irq thread context
1089+
*/
1090+
void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream)
1091+
{
1092+
struct snd_soc_pcm_runtime *rtd;
1093+
struct snd_compr_runtime *crtd;
1094+
struct snd_soc_component *component;
1095+
struct sof_compr_stream *sstream;
1096+
struct snd_sof_pcm *spcm;
1097+
1098+
if (!cstream)
1099+
return;
1100+
1101+
rtd = cstream->private_data;
1102+
crtd = cstream->runtime;
1103+
sstream = crtd->private_data;
1104+
component = snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
1105+
1106+
spcm = snd_sof_find_spcm_dai(component, rtd);
1107+
if (!spcm) {
1108+
dev_err(component->dev, "fragment elapsed called for unknown stream!\n");
1109+
return;
1110+
}
1111+
1112+
sof_set_transferred_bytes(sstream, spcm->stream[cstream->direction].posn.host_posn,
1113+
crtd->buffer_size);
1114+
1115+
/* use the same workqueue-based solution as for PCM, cf. snd_sof_pcm_elapsed */
1116+
schedule_work(&spcm->stream[cstream->direction].period_elapsed_work);
1117+
}
1118+
1119+
int snd_sof_compr_create_page_table(struct snd_soc_component *component,
1120+
struct snd_compr_stream *cstream,
1121+
unsigned char *dma_area, size_t size)
1122+
{
1123+
struct snd_dma_buffer *dmab = cstream->runtime->dma_buffer_p;
1124+
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
1125+
int dir = cstream->direction;
1126+
struct snd_sof_pcm *spcm;
1127+
1128+
spcm = snd_sof_find_spcm_dai(component, rtd);
1129+
if (!spcm)
1130+
return -EINVAL;
1131+
1132+
return snd_sof_create_page_table(component->dev, dmab,
1133+
spcm->stream[dir].page_table.area, size);
1134+
}
1135+
#endif

0 commit comments

Comments
 (0)