Skip to content

Commit e145e9a

Browse files
crojewsk-intelbroonie
authored andcommitted
ASoC: SOF: Generic probe compress operations
Define system-agnostic probe compress flow which serves as a base for actual, hardware-dependent implementations. As per firmware spec, maximum of one extraction stream is allowed, while for injection, there can be plenty. Apart from probe_pointer, all probe compress operations are mandatory. Copy operation is defined as unified as its flow should be shared across all SOF systems. Signed-off-by: Cezary Rojewski <[email protected]> Acked-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent f3b433e commit e145e9a

File tree

7 files changed

+246
-1
lines changed

7 files changed

+246
-1
lines changed

sound/soc/sof/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ config SND_SOC_SOF_OF
4343

4444
config SND_SOC_SOF_DEBUG_PROBES
4545
bool "SOF enable data probing"
46+
select SND_SOC_COMPRESS
4647
help
4748
This option enables the data probing feature that can be used to
4849
gather data directly from specific points of the audio pipeline.

sound/soc/sof/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
44
control.o trace.o utils.o sof-audio.o
5-
snd-sof-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += probe.o
5+
snd-sof-$(CONFIG_SND_SOC_SOF_DEBUG_PROBES) += probe.o compress.o
66

77
snd-sof-pci-objs := sof-pci-dev.o
88
snd-sof-acpi-objs := sof-acpi-dev.o

sound/soc/sof/compress.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2+
//
3+
// This file is provided under a dual BSD/GPLv2 license. When using or
4+
// redistributing this file, you may do so under either license.
5+
//
6+
// Copyright(c) 2019-2020 Intel Corporation. All rights reserved.
7+
//
8+
// Author: Cezary Rojewski <[email protected]>
9+
//
10+
11+
#include <sound/soc.h>
12+
#include "compress.h"
13+
#include "ops.h"
14+
#include "probe.h"
15+
16+
int sof_probe_compr_open(struct snd_compr_stream *cstream,
17+
struct snd_soc_dai *dai)
18+
{
19+
struct snd_sof_dev *sdev =
20+
snd_soc_component_get_drvdata(dai->component);
21+
int ret;
22+
23+
ret = snd_sof_probe_compr_assign(sdev, cstream, dai);
24+
if (ret < 0) {
25+
dev_err(dai->dev, "Failed to assign probe stream: %d\n", ret);
26+
return ret;
27+
}
28+
29+
sdev->extractor_stream_tag = ret;
30+
return 0;
31+
}
32+
EXPORT_SYMBOL(sof_probe_compr_open);
33+
34+
int sof_probe_compr_free(struct snd_compr_stream *cstream,
35+
struct snd_soc_dai *dai)
36+
{
37+
struct snd_sof_dev *sdev =
38+
snd_soc_component_get_drvdata(dai->component);
39+
struct sof_probe_point_desc *desc;
40+
size_t num_desc;
41+
int i, ret;
42+
43+
/* disconnect all probe points */
44+
ret = sof_ipc_probe_points_info(sdev, &desc, &num_desc);
45+
if (ret < 0) {
46+
dev_err(dai->dev, "Failed to get probe points: %d\n", ret);
47+
goto exit;
48+
}
49+
50+
for (i = 0; i < num_desc; i++)
51+
sof_ipc_probe_points_remove(sdev, &desc[i].buffer_id, 1);
52+
kfree(desc);
53+
54+
exit:
55+
ret = sof_ipc_probe_deinit(sdev);
56+
if (ret < 0)
57+
dev_err(dai->dev, "Failed to deinit probe: %d\n", ret);
58+
59+
sdev->extractor_stream_tag = SOF_PROBE_INVALID_NODE_ID;
60+
snd_compr_free_pages(cstream);
61+
62+
return snd_sof_probe_compr_free(sdev, cstream, dai);
63+
}
64+
EXPORT_SYMBOL(sof_probe_compr_free);
65+
66+
int sof_probe_compr_set_params(struct snd_compr_stream *cstream,
67+
struct snd_compr_params *params, struct snd_soc_dai *dai)
68+
{
69+
struct snd_compr_runtime *rtd = cstream->runtime;
70+
struct snd_sof_dev *sdev =
71+
snd_soc_component_get_drvdata(dai->component);
72+
int ret;
73+
74+
cstream->dma_buffer.dev.type = SNDRV_DMA_TYPE_DEV_SG;
75+
cstream->dma_buffer.dev.dev = sdev->dev;
76+
ret = snd_compr_malloc_pages(cstream, rtd->buffer_size);
77+
if (ret < 0)
78+
return ret;
79+
80+
ret = snd_sof_probe_compr_set_params(sdev, cstream, params, dai);
81+
if (ret < 0)
82+
return ret;
83+
84+
ret = sof_ipc_probe_init(sdev, sdev->extractor_stream_tag,
85+
rtd->dma_bytes);
86+
if (ret < 0) {
87+
dev_err(dai->dev, "Failed to init probe: %d\n", ret);
88+
return ret;
89+
}
90+
91+
return 0;
92+
}
93+
EXPORT_SYMBOL(sof_probe_compr_set_params);
94+
95+
int sof_probe_compr_trigger(struct snd_compr_stream *cstream, int cmd,
96+
struct snd_soc_dai *dai)
97+
{
98+
struct snd_sof_dev *sdev =
99+
snd_soc_component_get_drvdata(dai->component);
100+
101+
return snd_sof_probe_compr_trigger(sdev, cstream, cmd, dai);
102+
}
103+
EXPORT_SYMBOL(sof_probe_compr_trigger);
104+
105+
int sof_probe_compr_pointer(struct snd_compr_stream *cstream,
106+
struct snd_compr_tstamp *tstamp, struct snd_soc_dai *dai)
107+
{
108+
struct snd_sof_dev *sdev =
109+
snd_soc_component_get_drvdata(dai->component);
110+
111+
return snd_sof_probe_compr_pointer(sdev, cstream, tstamp, dai);
112+
}
113+
EXPORT_SYMBOL(sof_probe_compr_pointer);
114+
115+
int sof_probe_compr_copy(struct snd_compr_stream *cstream,
116+
char __user *buf, size_t count)
117+
{
118+
struct snd_compr_runtime *rtd = cstream->runtime;
119+
unsigned int offset, n;
120+
void *ptr;
121+
int ret;
122+
123+
if (count > rtd->buffer_size)
124+
count = rtd->buffer_size;
125+
126+
div_u64_rem(rtd->total_bytes_transferred, rtd->buffer_size, &offset);
127+
ptr = rtd->dma_area + offset;
128+
n = rtd->buffer_size - offset;
129+
130+
if (count < n) {
131+
ret = copy_to_user(buf, ptr, count);
132+
} else {
133+
ret = copy_to_user(buf, ptr, n);
134+
ret += copy_to_user(buf + n, rtd->dma_area, count - n);
135+
}
136+
137+
if (ret)
138+
return count - ret;
139+
return count;
140+
}
141+
EXPORT_SYMBOL(sof_probe_compr_copy);

sound/soc/sof/compress.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2+
/*
3+
* This file is provided under a dual BSD/GPLv2 license. When using or
4+
* redistributing this file, you may do so under either license.
5+
*
6+
* Copyright(c) 2019-2020 Intel Corporation. All rights reserved.
7+
*
8+
* Author: Cezary Rojewski <[email protected]>
9+
*/
10+
11+
#ifndef __SOF_COMPRESS_H
12+
#define __SOF_COMPRESS_H
13+
14+
#include <sound/compress_driver.h>
15+
16+
int sof_probe_compr_open(struct snd_compr_stream *cstream,
17+
struct snd_soc_dai *dai);
18+
int sof_probe_compr_free(struct snd_compr_stream *cstream,
19+
struct snd_soc_dai *dai);
20+
int sof_probe_compr_set_params(struct snd_compr_stream *cstream,
21+
struct snd_compr_params *params, struct snd_soc_dai *dai);
22+
int sof_probe_compr_trigger(struct snd_compr_stream *cstream, int cmd,
23+
struct snd_soc_dai *dai);
24+
int sof_probe_compr_pointer(struct snd_compr_stream *cstream,
25+
struct snd_compr_tstamp *tstamp, struct snd_soc_dai *dai);
26+
int sof_probe_compr_copy(struct snd_compr_stream *cstream,
27+
char __user *buf, size_t count);
28+
29+
#endif

sound/soc/sof/core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <sound/sof.h>
1515
#include "sof-priv.h"
1616
#include "ops.h"
17+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
18+
#include "probe.h"
19+
#endif
1720

1821
/* see SOF_DBG_ flags */
1922
int sof_core_debug;
@@ -292,6 +295,9 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
292295
sdev->pdata = plat_data;
293296
sdev->first_boot = true;
294297
sdev->fw_state = SOF_FW_BOOT_NOT_STARTED;
298+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
299+
sdev->extractor_stream_tag = SOF_PROBE_INVALID_NODE_ID;
300+
#endif
295301
dev_set_drvdata(dev, sdev);
296302

297303
/* check all mandatory ops */

sound/soc/sof/ops.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,49 @@ snd_sof_pcm_platform_pointer(struct snd_sof_dev *sdev,
393393
return 0;
394394
}
395395

396+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
397+
static inline int
398+
snd_sof_probe_compr_assign(struct snd_sof_dev *sdev,
399+
struct snd_compr_stream *cstream, struct snd_soc_dai *dai)
400+
{
401+
return sof_ops(sdev)->probe_assign(sdev, cstream, dai);
402+
}
403+
404+
static inline int
405+
snd_sof_probe_compr_free(struct snd_sof_dev *sdev,
406+
struct snd_compr_stream *cstream, struct snd_soc_dai *dai)
407+
{
408+
return sof_ops(sdev)->probe_free(sdev, cstream, dai);
409+
}
410+
411+
static inline int
412+
snd_sof_probe_compr_set_params(struct snd_sof_dev *sdev,
413+
struct snd_compr_stream *cstream,
414+
struct snd_compr_params *params, struct snd_soc_dai *dai)
415+
{
416+
return sof_ops(sdev)->probe_set_params(sdev, cstream, params, dai);
417+
}
418+
419+
static inline int
420+
snd_sof_probe_compr_trigger(struct snd_sof_dev *sdev,
421+
struct snd_compr_stream *cstream, int cmd,
422+
struct snd_soc_dai *dai)
423+
{
424+
return sof_ops(sdev)->probe_trigger(sdev, cstream, cmd, dai);
425+
}
426+
427+
static inline int
428+
snd_sof_probe_compr_pointer(struct snd_sof_dev *sdev,
429+
struct snd_compr_stream *cstream,
430+
struct snd_compr_tstamp *tstamp, struct snd_soc_dai *dai)
431+
{
432+
if (sof_ops(sdev) && sof_ops(sdev)->probe_pointer)
433+
return sof_ops(sdev)->probe_pointer(sdev, cstream, tstamp, dai);
434+
435+
return 0;
436+
}
437+
#endif
438+
396439
/* machine driver */
397440
static inline int
398441
snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata)

sound/soc/sof/sof-priv.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ struct snd_sof_dsp_ops {
170170
snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev,
171171
struct snd_pcm_substream *substream); /* optional */
172172

173+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
174+
/* Except for probe_pointer, all probe ops are mandatory */
175+
int (*probe_assign)(struct snd_sof_dev *sdev,
176+
struct snd_compr_stream *cstream,
177+
struct snd_soc_dai *dai); /* mandatory */
178+
int (*probe_free)(struct snd_sof_dev *sdev,
179+
struct snd_compr_stream *cstream,
180+
struct snd_soc_dai *dai); /* mandatory */
181+
int (*probe_set_params)(struct snd_sof_dev *sdev,
182+
struct snd_compr_stream *cstream,
183+
struct snd_compr_params *params,
184+
struct snd_soc_dai *dai); /* mandatory */
185+
int (*probe_trigger)(struct snd_sof_dev *sdev,
186+
struct snd_compr_stream *cstream, int cmd,
187+
struct snd_soc_dai *dai); /* mandatory */
188+
int (*probe_pointer)(struct snd_sof_dev *sdev,
189+
struct snd_compr_stream *cstream,
190+
struct snd_compr_tstamp *tstamp,
191+
struct snd_soc_dai *dai); /* optional */
192+
#endif
193+
173194
/* host read DSP stream data */
174195
void (*ipc_msg_data)(struct snd_sof_dev *sdev,
175196
struct snd_pcm_substream *substream,
@@ -405,6 +426,10 @@ struct snd_sof_dev {
405426
wait_queue_head_t waitq;
406427
int code_loading;
407428

429+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
430+
unsigned int extractor_stream_tag;
431+
#endif
432+
408433
/* DMA for Trace */
409434
struct snd_dma_buffer dmatb;
410435
struct snd_dma_buffer dmatp;

0 commit comments

Comments
 (0)