Skip to content

Commit d8a8af7

Browse files
ranj063lgirdwood
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 5e4ab42 commit d8a8af7

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

@@ -265,8 +186,9 @@ static int sof_compr_set_params(struct snd_soc_component *component,
265186
return ret;
266187
}
267188

268-
static int sof_compr_get_params(struct snd_soc_component *component,
269-
struct snd_compr_stream *cstream, struct snd_codec *params)
189+
static int sof_ipc3_compr_get_params(struct snd_soc_component *component,
190+
struct snd_compr_stream *cstream,
191+
struct snd_codec *params)
270192
{
271193
struct sof_compr_stream *sstream = cstream->runtime->private_data;
272194

@@ -275,8 +197,8 @@ static int sof_compr_get_params(struct snd_soc_component *component,
275197
return 0;
276198
}
277199

278-
static int sof_compr_trigger(struct snd_soc_component *component,
279-
struct snd_compr_stream *cstream, int cmd)
200+
static int sof_ipc3_compr_trigger(struct snd_soc_component *component,
201+
struct snd_compr_stream *cstream, int cmd)
280202
{
281203
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
282204
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
@@ -312,8 +234,8 @@ static int sof_compr_trigger(struct snd_soc_component *component,
312234
return sof_ipc_tx_message_no_reply(sdev->ipc, &stream, sizeof(stream));
313235
}
314236

315-
static int sof_compr_copy_playback(struct snd_compr_runtime *rtd,
316-
char __user *buf, size_t count)
237+
static int sof_ipc3_compr_copy_playback(struct snd_compr_runtime *rtd,
238+
char __user *buf, size_t count)
317239
{
318240
void *ptr;
319241
unsigned int offset, n;
@@ -333,8 +255,8 @@ static int sof_compr_copy_playback(struct snd_compr_runtime *rtd,
333255
return count - ret;
334256
}
335257

336-
static int sof_compr_copy_capture(struct snd_compr_runtime *rtd,
337-
char __user *buf, size_t count)
258+
static int sof_ipc3_compr_copy_capture(struct snd_compr_runtime *rtd,
259+
char __user *buf, size_t count)
338260
{
339261
void *ptr;
340262
unsigned int offset, n;
@@ -354,24 +276,24 @@ static int sof_compr_copy_capture(struct snd_compr_runtime *rtd,
354276
return count - ret;
355277
}
356278

357-
static int sof_compr_copy(struct snd_soc_component *component,
358-
struct snd_compr_stream *cstream,
359-
char __user *buf, size_t count)
279+
static int sof_ipc3_compr_copy(struct snd_soc_component *component,
280+
struct snd_compr_stream *cstream,
281+
char __user *buf, size_t count)
360282
{
361283
struct snd_compr_runtime *rtd = cstream->runtime;
362284

363285
if (count > rtd->buffer_size)
364286
count = rtd->buffer_size;
365287

366288
if (cstream->direction == SND_COMPRESS_PLAYBACK)
367-
return sof_compr_copy_playback(rtd, buf, count);
289+
return sof_ipc3_compr_copy_playback(rtd, buf, count);
368290
else
369-
return sof_compr_copy_capture(rtd, buf, count);
291+
return sof_ipc3_compr_copy_capture(rtd, buf, count);
370292
}
371293

372-
static int sof_compr_pointer(struct snd_soc_component *component,
373-
struct snd_compr_stream *cstream,
374-
struct snd_compr_tstamp64 *tstamp)
294+
static int sof_ipc3_compr_pointer(struct snd_soc_component *component,
295+
struct snd_compr_stream *cstream,
296+
struct snd_compr_tstamp64 *tstamp)
375297
{
376298
struct snd_sof_pcm *spcm;
377299
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
@@ -392,13 +314,12 @@ static int sof_compr_pointer(struct snd_soc_component *component,
392314
return 0;
393315
}
394316

395-
struct snd_compress_ops sof_compressed_ops = {
396-
.open = sof_compr_open,
397-
.free = sof_compr_free,
398-
.set_params = sof_compr_set_params,
399-
.get_params = sof_compr_get_params,
400-
.trigger = sof_compr_trigger,
401-
.pointer = sof_compr_pointer,
402-
.copy = sof_compr_copy,
317+
const struct snd_compress_ops sof_ipc3_compressed_ops = {
318+
.open = sof_ipc3_compr_open,
319+
.free = sof_ipc3_compr_free,
320+
.set_params = sof_ipc3_compr_set_params,
321+
.get_params = sof_ipc3_compr_get_params,
322+
.trigger = sof_ipc3_compr_trigger,
323+
.pointer = sof_ipc3_compr_pointer,
324+
.copy = sof_ipc3_compr_copy,
403325
};
404-
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_new = 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
/*
@@ -1051,3 +1052,83 @@ int sof_dai_get_tdm_slots(struct snd_soc_pcm_runtime *rtd)
10511052
return sof_dai_get_param(rtd, SOF_DAI_PARAM_INTEL_SSP_TDM_SLOTS);
10521053
}
10531054
EXPORT_SYMBOL(sof_dai_get_tdm_slots);
1055+
1056+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
1057+
static void sof_set_transferred_bytes(struct sof_compr_stream *sstream,
1058+
u64 host_pos, u64 buffer_size)
1059+
{
1060+
u64 prev_pos;
1061+
unsigned int copied;
1062+
1063+
div64_u64_rem(sstream->copied_total, buffer_size, &prev_pos);
1064+
1065+
if (host_pos < prev_pos)
1066+
copied = (buffer_size - prev_pos) + host_pos;
1067+
else
1068+
copied = host_pos - prev_pos;
1069+
1070+
sstream->copied_total += copied;
1071+
}
1072+
1073+
static void snd_sof_compr_fragment_elapsed_work(struct work_struct *work)
1074+
{
1075+
struct snd_sof_pcm_stream *sps = container_of(work, struct snd_sof_pcm_stream,
1076+
period_elapsed_work);
1077+
1078+
snd_compr_fragment_elapsed(sps->cstream);
1079+
}
1080+
1081+
void snd_sof_compr_init_elapsed_work(struct work_struct *work)
1082+
{
1083+
INIT_WORK(work, snd_sof_compr_fragment_elapsed_work);
1084+
}
1085+
1086+
/*
1087+
* sof compr fragment elapse, this could be called in irq thread context
1088+
*/
1089+
void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream)
1090+
{
1091+
struct snd_soc_pcm_runtime *rtd;
1092+
struct snd_compr_runtime *crtd;
1093+
struct snd_soc_component *component;
1094+
struct sof_compr_stream *sstream;
1095+
struct snd_sof_pcm *spcm;
1096+
1097+
if (!cstream)
1098+
return;
1099+
1100+
rtd = cstream->private_data;
1101+
crtd = cstream->runtime;
1102+
sstream = crtd->private_data;
1103+
component = snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
1104+
1105+
spcm = snd_sof_find_spcm_dai(component, rtd);
1106+
if (!spcm) {
1107+
dev_err(component->dev, "fragment elapsed called for unknown stream!\n");
1108+
return;
1109+
}
1110+
1111+
sof_set_transferred_bytes(sstream, spcm->stream[cstream->direction].posn.host_posn,
1112+
crtd->buffer_size);
1113+
1114+
/* use the same workqueue-based solution as for PCM, cf. snd_sof_pcm_elapsed */
1115+
schedule_work(&spcm->stream[cstream->direction].period_elapsed_work);
1116+
}
1117+
1118+
int snd_sof_compr_create_page_table(struct snd_soc_component *component,
1119+
struct snd_compr_stream *cstream,
1120+
unsigned char *dma_area, size_t size)
1121+
{
1122+
struct snd_dma_buffer *dmab = cstream->runtime->dma_buffer_p;
1123+
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
1124+
int dir = cstream->direction;
1125+
struct snd_sof_pcm *spcm;
1126+
1127+
spcm = snd_sof_find_spcm_dai(component, rtd);
1128+
if (!spcm)
1129+
return -EINVAL;
1130+
1131+
return snd_sof_create_page_table(component->dev, dmab,
1132+
spcm->stream[dir].page_table.area, size);
1133+
}
1134+
#endif

0 commit comments

Comments
 (0)