forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.c
More file actions
251 lines (210 loc) · 7.11 KB
/
process.c
File metadata and controls
251 lines (210 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2019 Intel Corporation. All rights reserved.
//
// Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
/* Topology parser */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <errno.h>
#include <string.h>
#include <ipc/topology.h>
#include <sof/lib/uuid.h>
#include <sof/ipc/topology.h>
#include <kernel/header.h>
#include <tplg_parser/topology.h>
#include <tplg_parser/tokens.h>
/** \brief Types of processing components */
enum sof_ipc_process_type {
SOF_PROCESS_NONE = 0, /**< None */
SOF_PROCESS_EQFIR, /**< Intel FIR */
SOF_PROCESS_EQIIR, /**< Intel IIR */
SOF_PROCESS_KEYWORD_DETECT, /**< Keyword Detection */
SOF_PROCESS_KPB, /**< KeyPhrase Buffer Manager */
SOF_PROCESS_CHAN_SELECTOR, /**< Channel Selector */
SOF_PROCESS_MUX,
SOF_PROCESS_DEMUX,
SOF_PROCESS_DCBLOCK,
};
struct sof_process_types {
const char *name;
enum sof_ipc_process_type type;
enum sof_comp_type comp_type;
};
static const struct sof_process_types ipc3_process[] = {
{"EQFIR", SOF_PROCESS_EQFIR, SOF_COMP_EQ_FIR},
{"EQIIR", SOF_PROCESS_EQIIR, SOF_COMP_EQ_IIR},
{"KEYWORD_DETECT", SOF_PROCESS_KEYWORD_DETECT, SOF_COMP_KEYWORD_DETECT},
{"KPB", SOF_PROCESS_KPB, SOF_COMP_KPB},
{"CHAN_SELECTOR", SOF_PROCESS_CHAN_SELECTOR, SOF_COMP_SELECTOR},
{"MUX", SOF_PROCESS_MUX, SOF_COMP_MUX},
{"DEMUX", SOF_PROCESS_DEMUX, SOF_COMP_DEMUX},
{"DCBLOCK", SOF_PROCESS_DCBLOCK, SOF_COMP_DCBLOCK},
};
static enum sof_ipc_process_type process_get_name(const char *name)
{
int i;
for (i = 0; i < ARRAY_SIZE(ipc3_process); i++) {
if (strcmp(name, ipc3_process[i].name) == 0)
return ipc3_process[i].type;
}
return SOF_PROCESS_NONE;
}
static enum sof_comp_type process_get_type(enum sof_ipc_process_type type)
{
int i;
for (i = 0; i < ARRAY_SIZE(ipc3_process); i++) {
if (ipc3_process[i].type == type)
return ipc3_process[i].comp_type;
}
return SOF_COMP_NONE;
}
static int process_token_get_type(void *elem, void *object, uint32_t offset,
uint32_t size)
{
struct snd_soc_tplg_vendor_string_elem *velem = elem;
uint32_t *val = (uint32_t *)((uint8_t *)object + offset);
*val = process_get_name(velem->string);
return 0;
}
static const struct sof_topology_token process_tokens[] = {
{SOF_TKN_PROCESS_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING,
process_token_get_type,
offsetof(struct sof_ipc_comp_process, type), 0},
};
/* process - IPC3 */
static const struct sof_topology_token_group process_ipc3_tokens[] = {
{comp_tokens, ARRAY_SIZE(comp_tokens),
offsetof(struct sof_ipc_comp_process, config)},
{process_tokens, ARRAY_SIZE(process_tokens),
0},
{comp_ext_tokens, ARRAY_SIZE(comp_ext_tokens),
sizeof(struct sof_ipc_comp_process)},
};
static int process_ipc3_build(struct tplg_context *ctx, void *_process)
{
struct sof_ipc_comp_process *process = _process;
int comp_id = ctx->comp_id;
/* configure asrc */
process->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
process->comp.id = comp_id;
process->comp.hdr.size = sizeof(struct sof_ipc_comp_process) + UUID_SIZE;
process->comp.type = process_get_type(process->type);
process->comp.pipeline_id = ctx->pipeline_id;
process->config.hdr.size = sizeof(struct sof_ipc_comp_config);
process->comp.ext_data_length = UUID_SIZE;
return 0;
}
/* process - IPC4 */
static const struct sof_topology_token process4_tokens[] = {
/* TODO */
};
static const struct sof_topology_token_group process_ipc4_tokens[] = {
{process4_tokens, ARRAY_SIZE(process4_tokens)},
};
static int process_ipc4_build(struct tplg_context *ctx, void *process)
{
return tplg_parse_widget_audio_formats(ctx);
}
static const struct sof_topology_module_desc process_ipc[] = {
{3, process_ipc3_tokens, ARRAY_SIZE(process_ipc3_tokens),
process_ipc3_build, sizeof(struct sof_ipc_comp_process)},
{4, process_ipc4_tokens, ARRAY_SIZE(process_ipc4_tokens),
process_ipc4_build},
};
static int process_append_data3(void *_process_ipc,
struct snd_soc_tplg_ctl_hdr *ctl,
struct snd_soc_tplg_private *priv_data,
size_t max_process_size)
{
struct sof_ipc_comp_process *process_ipc = _process_ipc;
struct snd_soc_tplg_bytes_control *bytes_ctl;
size_t size, ipc_size;
if (ctl->ops.info != SND_SOC_TPLG_CTL_BYTES)
return 0;
/* Size is process IPC plus private data minus ABI header */
bytes_ctl = (struct snd_soc_tplg_bytes_control *)ctl;
size = bytes_ctl->priv.size - sizeof(struct sof_abi_hdr);
ipc_size = sizeof(struct sof_ipc_comp_process) + UUID_SIZE +
process_ipc->size + size;
/* validate if everything will fit */
if (ipc_size > max_process_size) {
fprintf(stderr, "error: process priv data too big, have %zu need %zu\n",
max_process_size, ipc_size);
return -EINVAL;
}
/* Copy configuration data, need to strip ABI header*/
memcpy((char *)process_ipc + sizeof(struct sof_ipc_comp_process)
+ UUID_SIZE + process_ipc->size,
(char *)priv_data->data + sizeof(struct sof_abi_hdr), size);
process_ipc->size += size;
return 0;
}
static int process_append_data4(void *_process_ipc,
struct snd_soc_tplg_ctl_hdr *ctl,
struct snd_soc_tplg_private *priv_data,
size_t max_process_size)
{
struct sof_ipc_comp_process *process_ipc = _process_ipc;
struct snd_soc_tplg_bytes_control *bytes_ctl;
size_t size;
if (ctl->ops.info != SND_SOC_TPLG_CTL_BYTES)
return 0;
/* Size is process IPC plus private data minus ABI header */
bytes_ctl = (struct snd_soc_tplg_bytes_control *)ctl;
size = bytes_ctl->priv.size - sizeof(struct sof_abi_hdr);
/* validate if everything will fit */
if (size > max_process_size) {
fprintf(stderr, "error: process priv data too big, have %zu need %zu\n",
max_process_size, size);
return -EINVAL;
}
/* Copy configuration data, need to strip ABI header */
memcpy((char *)process_ipc + process_ipc->size,
(char *)priv_data->data + sizeof(struct sof_abi_hdr), size);
process_ipc->size += size;
fprintf(stdout, "process configuration data size %#x\n", process_ipc->size);
return 0;
}
int tplg_new_process(struct tplg_context *ctx, void *process, size_t process_size,
struct snd_soc_tplg_ctl_hdr *rctl, size_t max_ctl_size)
{
struct snd_soc_tplg_dapm_widget *widget = ctx->widget;
struct snd_soc_tplg_ctl_hdr *ctl = NULL;
struct snd_soc_tplg_private *priv_data = NULL;
int ret, i;
ret = tplg_create_object(ctx, process_ipc, ARRAY_SIZE(process_ipc),
"process", process, process_size);
/* Get control into ctl and priv_data */
for (i = 0; i < widget->num_kcontrols; i++) {
ret = tplg_get_single_control(ctx, &ctl, &priv_data);
if (ret < 0) {
fprintf(stderr, "error: failed control load\n");
return ret;
}
/* call ctl creation callback if needed */
if (ctx->ctl_cb)
ctx->ctl_cb(ctl, process, ctx->ctl_arg);
/* Merge process and priv_data into process_ipc */
if (!priv_data)
continue;
switch (ctx->ipc_major) {
case 3:
ret = process_append_data3(process, ctl,
priv_data, process_size);
break;
case 4:
ret = process_append_data4(process, ctl, priv_data, process_size);
break;
default:
break;
}
if (ret < 0) {
fprintf(stderr, "error: failed to append process priv data\n");
return ret;
}
}
return ret;
}