Repository navigation
Expand file tree
/
Copy pathcomponent_ext.h
More file actions
383 lines (310 loc) · 8.69 KB
/
Copy pathcomponent_ext.h
File metadata and controls
383 lines (310 loc) · 8.69 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2016 Intel Corporation. All rights reserved.
*
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
* Keyon Jie <yang.jie@linux.intel.com>
*/
/**
* \file include/sof/audio/component_ext.h
* \brief Component API for Infrastructure
* \author Liam Girdwood <liam.r.girdwood@linux.intel.com>
* \author Keyon Jie <yang.jie@linux.intel.com>
*/
#ifndef __SOF_AUDIO_COMPONENT_INT_H__
#define __SOF_AUDIO_COMPONENT_INT_H__
#include <sof/audio/component.h>
#include <sof/drivers/idc.h>
#include <sof/list.h>
#include <ipc/topology.h>
#include <kernel/abi.h>
#include <stdbool.h>
/** \addtogroup component_api_helpers Component Mgmt API
* @{
*/
/** \brief Holds list of registered components' drivers */
struct comp_driver_list {
struct list_item list; /**< list of component drivers */
};
/** \brief Retrieves the component device buffer list. */
#define comp_buffer_list(comp, dir) \
((dir) == PPL_DIR_DOWNSTREAM ? &comp->bsink_list : \
&comp->bsource_list)
/** See comp_ops::new */
struct comp_dev *comp_new(struct sof_ipc_comp *comp);
/** See comp_ops::free */
static inline void comp_free(struct comp_dev *dev)
{
assert(dev->drv->ops.free);
/* free task if shared component */
if (dev->is_shared && dev->task) {
schedule_task_free(dev->task);
rfree(dev->task);
}
dev->drv->ops.free(dev);
}
/**
* Commits component's memory if it's shared.
* @param dev Component device.
*/
static inline void comp_shared_commit(struct comp_dev *dev)
{
if (dev->is_shared)
platform_shared_commit(dev, sizeof(*dev));
}
/**
* Parameter init for component on other core.
* @param dev Component device.
* @param params Parameters to be set.
* @return 0 if succeeded, error code otherwise.
*/
static inline int comp_params_remote(struct comp_dev *dev,
struct sof_ipc_stream_params *params)
{
struct idc_msg msg = { IDC_MSG_PARAMS, IDC_MSG_PARAMS_EXT(dev->comp.id),
dev->comp.core, sizeof(*params), params, };
return idc_send_msg(&msg, IDC_BLOCKING);
}
/** See comp_ops::params */
static inline int comp_params(struct comp_dev *dev,
struct sof_ipc_stream_params *params)
{
int ret = 0;
if (dev->is_shared && !cpu_is_me(dev->comp.core)) {
ret = comp_params_remote(dev, params);
} else {
if (dev->drv->ops.params) {
ret = dev->drv->ops.params(dev, params);
} else {
/* not defined, run the default handler */
ret = comp_verify_params(dev, 0, params);
if (ret < 0)
comp_err(dev, "pcm params verification failed");
}
}
comp_shared_commit(dev);
return ret;
}
/** See comp_ops::dai_get_hw_params */
static inline int comp_dai_get_hw_params(struct comp_dev *dev,
struct sof_ipc_stream_params *params,
int dir)
{
int ret = -EINVAL;
if (dev->drv->ops.dai_get_hw_params)
ret = dev->drv->ops.dai_get_hw_params(dev, params, dir);
comp_shared_commit(dev);
return ret;
}
/** See comp_ops::cmd */
static inline int comp_cmd(struct comp_dev *dev, int cmd, void *data,
int max_data_size)
{
struct sof_ipc_ctrl_data *cdata = data;
int ret = -EINVAL;
if (cmd == COMP_CMD_SET_DATA &&
(cdata->data->magic != SOF_ABI_MAGIC ||
SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, cdata->data->abi))) {
comp_err(dev, "comp_cmd(): invalid version, data->magic = %u, data->abi = %u",
cdata->data->magic, cdata->data->abi);
goto out;
}
if (dev->drv->ops.cmd)
ret = dev->drv->ops.cmd(dev, cmd, data, max_data_size);
out:
comp_shared_commit(dev);
return ret;
}
/**
* Runs comp_ops::trigger on the core the target component is assigned to.
*/
static inline int comp_trigger_remote(struct comp_dev *dev, int cmd)
{
struct idc_msg msg = { IDC_MSG_TRIGGER,
IDC_MSG_TRIGGER_EXT(dev->comp.id), dev->comp.core, sizeof(cmd),
&cmd, };
return idc_send_msg(&msg, IDC_BLOCKING);
}
/** See comp_ops::trigger */
static inline int comp_trigger(struct comp_dev *dev, int cmd)
{
int ret = 0;
assert(dev->drv->ops.trigger);
ret = (dev->is_shared && !cpu_is_me(dev->comp.core)) ?
comp_trigger_remote(dev, cmd) : dev->drv->ops.trigger(dev, cmd);
comp_shared_commit(dev);
return ret;
}
/** Runs comp_ops::prepare on the target component's core */
static inline int comp_prepare_remote(struct comp_dev *dev)
{
struct idc_msg msg = { IDC_MSG_PREPARE,
IDC_MSG_PREPARE_EXT(dev->comp.id), dev->comp.core, };
return idc_send_msg(&msg, IDC_BLOCKING);
}
/** See comp_ops::prepare */
static inline int comp_prepare(struct comp_dev *dev)
{
int ret = 0;
if (dev->drv->ops.prepare)
ret = (dev->is_shared && !cpu_is_me(dev->comp.core)) ?
comp_prepare_remote(dev) : dev->drv->ops.prepare(dev);
comp_shared_commit(dev);
return ret;
}
/** See comp_ops::copy */
static inline int comp_copy(struct comp_dev *dev)
{
int ret = 0;
assert(dev->drv->ops.copy);
/* copy only if we are the owner of the component */
if (cpu_is_me(dev->comp.core)) {
perf_cnt_init(&dev->pcd);
ret = dev->drv->ops.copy(dev);
perf_cnt_stamp(&dev->pcd, comp_perf_info, dev);
}
comp_shared_commit(dev);
return ret;
}
/** See comp_ops::set_attribute */
static inline int comp_set_attribute(struct comp_dev *dev, uint32_t type,
void *value)
{
int ret = 0;
if (dev->drv->ops.set_attribute)
ret = dev->drv->ops.set_attribute(dev, type, value);
comp_shared_commit(dev);
return ret;
}
/** Runs comp_ops::reset on the target component's core */
static inline int comp_reset_remote(struct comp_dev *dev)
{
struct idc_msg msg = { IDC_MSG_RESET,
IDC_MSG_RESET_EXT(dev->comp.id), dev->comp.core, };
return idc_send_msg(&msg, IDC_BLOCKING);
}
/**
* Component reset and free runtime resources.
* @param dev Component device.
* @return 0 if succeeded, error code otherwise.
*/
static inline int comp_reset(struct comp_dev *dev)
{
int ret = 0;
if (dev->drv->ops.reset)
ret = (dev->is_shared && !cpu_is_me(dev->comp.core)) ?
comp_reset_remote(dev) : dev->drv->ops.reset(dev);
comp_shared_commit(dev);
return ret;
}
/** See comp_ops::dai_config */
static inline int comp_dai_config(struct comp_dev *dev,
struct sof_ipc_dai_config *config)
{
int ret = 0;
if (dev->drv->ops.dai_config)
ret = dev->drv->ops.dai_config(dev, config);
comp_shared_commit(dev);
return ret;
}
/** See comp_ops::position */
static inline int comp_position(struct comp_dev *dev,
struct sof_ipc_stream_posn *posn)
{
int ret = 0;
if (dev->drv->ops.position)
ret = dev->drv->ops.position(dev, posn);
comp_shared_commit(dev);
return ret;
}
/**
* Allocates and initializes audio component list.
* To be called once at boot time.
*/
void sys_comp_init(struct sof *sof);
/**
* Checks if two component devices belong to the same parent pipeline.
* @param current Component device.
* @param previous Another component device.
* @return 1 if children of the same pipeline, 0 otherwise.
*/
static inline int comp_is_single_pipeline(struct comp_dev *current,
struct comp_dev *previous)
{
return dev_comp_pipe_id(current) == dev_comp_pipe_id(previous);
}
/**
* Checks if component device is active.
* @param current Component device.
* @return 1 if active, 0 otherwise.
*/
static inline int comp_is_active(struct comp_dev *current)
{
return current->state == COMP_STATE_ACTIVE;
}
/**
* Returns component state based on requested command.
* @param cmd Request command.
* @return Component state.
*/
static inline int comp_get_requested_state(int cmd)
{
int state = COMP_STATE_INIT;
switch (cmd) {
case COMP_TRIGGER_START:
case COMP_TRIGGER_RELEASE:
state = COMP_STATE_ACTIVE;
break;
case COMP_TRIGGER_PREPARE:
case COMP_TRIGGER_STOP:
state = COMP_STATE_PREPARE;
break;
case COMP_TRIGGER_PAUSE:
state = COMP_STATE_PAUSED;
break;
case COMP_TRIGGER_XRUN:
case COMP_TRIGGER_RESET:
state = COMP_STATE_READY;
break;
default:
break;
}
return state;
}
/**
* \brief Returns endpoint type of given component.
* @param dev Component device
* @return Endpoint type, one of comp_endpoint_type.
*/
static inline int comp_get_endpoint_type(struct comp_dev *dev)
{
switch (dev_comp_type(dev)) {
case SOF_COMP_HOST:
return COMP_ENDPOINT_HOST;
case SOF_COMP_DAI:
return COMP_ENDPOINT_DAI;
default:
return COMP_ENDPOINT_NODE;
}
}
/**
* Called to check whether component schedules its pipeline.
* @param dev Component device.
* @return True if this is scheduling component, false otherwise.
*/
static inline bool comp_is_scheduling_source(struct comp_dev *dev)
{
return dev == dev->pipeline->sched_comp;
}
/**
* Called to reallocate component in shared memory.
* @param dev Component device.
* @return Pointer to reallocated component device.
*/
struct comp_dev *comp_make_shared(struct comp_dev *dev);
static inline struct comp_driver_list *comp_drivers_get(void)
{
return sof_get()->comp_drivers;
}
/** @}*/
#endif /* __SOF_AUDIO_COMPONENT_INT_H__ */