Skip to content

Commit b781033

Browse files
marcinszkudlinskilgirdwood
authored andcommitted
mod: add bind/unbind hook to sink/source API
This commit adds bind/unbind hook to sink/source API It is guaranteed that the hooks will be called on core that the API will be / was used on, what makes them a perfect place for cache operations needed at start/end of usage. Note that free method is not a good place for this, as in case of shared buffers it may happen on either of the cores the buffer connects Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
1 parent 894fe70 commit b781033

3 files changed

Lines changed: 148 additions & 5 deletions

File tree

src/audio/module_adapter/module/generic.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,20 +495,50 @@ EXPORT_SYMBOL(module_set_configuration);
495495

496496
int module_bind(struct processing_module *mod, struct bind_info *bind_data)
497497
{
498+
int ret;
498499
const struct module_interface *const ops = mod->dev->drv->adapter_ops;
499500

501+
switch (bind_data->bind_type) {
502+
case COMP_BIND_TYPE_SINK:
503+
ret = sink_bind(bind_data->sink, mod);
504+
break;
505+
case COMP_BIND_TYPE_SOURCE:
506+
ret = source_bind(bind_data->source, mod);
507+
break;
508+
default:
509+
ret = -EINVAL;
510+
}
511+
if (ret)
512+
return ret;
513+
500514
if (ops->bind)
501-
return ops->bind(mod, bind_data);
502-
return 0;
515+
ret = ops->bind(mod, bind_data);
516+
517+
return ret;
503518
}
504519

505520
int module_unbind(struct processing_module *mod, struct bind_info *unbind_data)
506521
{
522+
int ret;
507523
const struct module_interface *const ops = mod->dev->drv->adapter_ops;
508524

525+
switch (unbind_data->bind_type) {
526+
case COMP_BIND_TYPE_SINK:
527+
ret = sink_unbind(unbind_data->sink);
528+
break;
529+
case COMP_BIND_TYPE_SOURCE:
530+
ret = source_unbind(unbind_data->source);
531+
break;
532+
default:
533+
ret = -EINVAL;
534+
}
535+
if (ret)
536+
return ret;
537+
509538
if (ops->unbind)
510-
return ops->unbind(mod, unbind_data);
511-
return 0;
539+
ret = ops->unbind(mod, unbind_data);
540+
541+
return ret;
512542
}
513543

514544
void module_update_buffer_position(struct input_stream_buffer *input_buffers,

src/include/module/audio/sink_api.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
struct sof_sink;
5252
struct sof_audio_stream_params;
5353
struct sof_ipc_stream_params;
54+
struct processing_module;
5455

5556
/**
5657
* this is a definition of internals of sink API
@@ -101,6 +102,14 @@ struct sink_ops {
101102
int (*set_alignment_constants)(struct sof_sink *sink,
102103
const uint32_t byte_align,
103104
const uint32_t frame_align_req);
105+
106+
/**
107+
* OPTIONAL
108+
* events called when a module is starting / finishing using of the API
109+
* on the core that the module and API will executed on
110+
*/
111+
int (*on_bind)(struct sof_sink *sink, struct processing_module *module);
112+
int (*on_unbind)(struct sof_sink *sink);
104113
};
105114

106115
/** internals of sink API. NOT TO BE MODIFIED OUTSIDE OF sink_api.c */
@@ -111,6 +120,7 @@ struct sof_sink {
111120
size_t min_free_space; /** minimum buffer space required by the module using sink
112121
* it is module's OBS as declared in module bind IPC
113122
*/
123+
struct processing_module *bound_module; /* a pointer module that is using sink API */
114124
struct sof_audio_stream_params *audio_stream_params; /** pointer to audio params */
115125
};
116126

@@ -291,4 +301,51 @@ static inline uint32_t sink_get_pipeline_id(struct sof_sink *sink)
291301
return sink->audio_stream_params->pipeline_id;
292302
}
293303

304+
/**
305+
* @brief hook to be called when a module connects to the API
306+
*
307+
* NOTE! it MUST be called at core that a module is bound to
308+
*/
309+
static inline int sink_bind(struct sof_sink *sink, struct processing_module *module)
310+
{
311+
int ret = 0;
312+
313+
if (sink->bound_module)
314+
return -EBUSY;
315+
316+
if (sink->ops->on_bind)
317+
ret = sink->ops->on_bind(sink, module);
318+
319+
if (!ret)
320+
sink->bound_module = module;
321+
322+
return ret;
323+
}
324+
325+
/**
326+
* @brief hook to be called when a module disconnects from the API
327+
*
328+
* NOTE! it MUST be called at core that a module is bound to
329+
*/
330+
static inline int sink_unbind(struct sof_sink *sink)
331+
{
332+
int ret = 0;
333+
334+
if (!sink->bound_module)
335+
return -EINVAL;
336+
337+
if (sink->ops->on_unbind)
338+
ret = sink->ops->on_unbind(sink);
339+
340+
if (!ret)
341+
sink->bound_module = NULL;
342+
343+
return ret;
344+
}
345+
346+
static inline struct processing_module *sink_get_bound_module(struct sof_sink *sink)
347+
{
348+
return sink->bound_module;
349+
}
350+
294351
#endif /* __MODULE_AUDIO_SINK_API_H__ */

src/include/module/audio/source_api.h

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
struct sof_source;
5252
struct sof_audio_stream_params;
5353
struct sof_ipc_stream_params;
54+
struct processing_module;
5455

5556
/**
5657
* this is a definition of internals of source API
@@ -101,6 +102,14 @@ struct source_ops {
101102
int (*set_alignment_constants)(struct sof_source *source,
102103
const uint32_t byte_align,
103104
const uint32_t frame_align_req);
105+
106+
/**
107+
* OPTIONAL
108+
* events called when a module is starting / finishing using of the API
109+
* on the core that the module and API will executed on
110+
*/
111+
int (*on_bind)(struct sof_source *source, struct processing_module *module);
112+
int (*on_unbind)(struct sof_source *source);
104113
};
105114

106115
/** internals of source API. NOT TO BE MODIFIED OUTSIDE OF source_api.c */
@@ -112,7 +121,7 @@ struct sof_source {
112121
* source
113122
* it is module's IBS as declared in module bind IPC
114123
*/
115-
124+
struct processing_module *bound_module; /* a pointer module that is using source API */
116125
struct sof_audio_stream_params *audio_stream_params;
117126
};
118127

@@ -267,4 +276,51 @@ static inline uint32_t source_get_pipeline_id(struct sof_source *source)
267276
return source->audio_stream_params->pipeline_id;
268277
}
269278

279+
/**
280+
* @brief hook to be called when a module connects to the API
281+
*
282+
* NOTE! it MUST be called at core that a module is bound to
283+
*/
284+
static inline int source_bind(struct sof_source *source, struct processing_module *module)
285+
{
286+
int ret = 0;
287+
288+
if (source->bound_module)
289+
return -EBUSY;
290+
291+
if (source->ops->on_bind)
292+
ret = source->ops->on_bind(source, module);
293+
294+
if (!ret)
295+
source->bound_module = module;
296+
297+
return ret;
298+
}
299+
300+
/**
301+
* @brief hook to be called when a module disconnects from the API
302+
*
303+
* NOTE! it MUST be called at core that a module is bound to
304+
*/
305+
static inline int source_unbind(struct sof_source *source)
306+
{
307+
int ret = 0;
308+
309+
if (!source->bound_module)
310+
return -EINVAL;
311+
312+
if (source->ops->on_unbind)
313+
ret = source->ops->on_unbind(source);
314+
315+
if (!ret)
316+
source->bound_module = NULL;
317+
318+
return ret;
319+
}
320+
321+
static inline struct processing_module *source_get_bound_module(struct sof_source *source)
322+
{
323+
return source->bound_module;
324+
}
325+
270326
#endif /* __MODULE_AUDIO_SOURCE_API_H__ */

0 commit comments

Comments
 (0)