Skip to content

Commit 3db6d48

Browse files
kv2019ilgirdwood
authored andcommitted
audio: buffer: replace notifier events with direct probe callbacks
Replace the generic notifier dispatch for buffer produce, consume, and free events with direct function pointer callbacks on struct comp_buffer. The only consumer of this notifier event has been probe.c, so there is really no need to use the notifier framework for this. This change allows to run more audio modules in user-space, where the notifier framework is not available. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 4b1de38 commit 3db6d48

4 files changed

Lines changed: 51 additions & 63 deletions

File tree

src/audio/buffers/comp_buffer.c

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <rtos/interrupt.h>
1717
#include <rtos/alloc.h>
1818
#include <rtos/cache.h>
19-
#include <sof/lib/notifier.h>
2019
#include <sof/list.h>
2120
#include <sof/schedule/dp_schedule.h>
2221
#include <rtos/spinlock.h>
@@ -147,17 +146,12 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)
147146

148147
struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer);
149148

150-
struct buffer_cb_free cb_data = {
151-
.buffer = buffer,
152-
};
153-
154149
buf_dbg(buffer, "buffer_free()");
155150

156-
notifier_event(buffer, NOTIFIER_ID_BUFFER_FREE,
157-
NOTIFIER_TARGET_CORE_LOCAL, &cb_data, sizeof(cb_data));
158-
159-
/* In case some listeners didn't unregister from buffer's callbacks */
160-
notifier_unregister_all(NULL, buffer);
151+
#if CONFIG_PROBE
152+
if (buffer->probe_cb_free)
153+
buffer->probe_cb_free(buffer->probe_cb_arg);
154+
#endif
161155

162156
struct k_heap *heap = buffer->audio_buffer.heap;
163157

@@ -478,12 +472,6 @@ bool buffer_params_match(struct comp_buffer *buffer,
478472

479473
void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
480474
{
481-
struct buffer_cb_transact cb_data = {
482-
.buffer = buffer,
483-
.transaction_amount = bytes,
484-
.transaction_begin_address = audio_stream_get_wptr(&buffer->stream),
485-
};
486-
487475
/* return if no bytes */
488476
if (!bytes) {
489477
#if CONFIG_SOF_LOG_DBG_BUFFER
@@ -499,10 +487,23 @@ void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
499487
return;
500488
}
501489

490+
#if CONFIG_PROBE
491+
void *produce_begin = audio_stream_get_wptr(&buffer->stream);
492+
#endif
493+
502494
audio_stream_produce(&buffer->stream, bytes);
503495

504-
notifier_event(buffer, NOTIFIER_ID_BUFFER_PRODUCE,
505-
NOTIFIER_TARGET_CORE_LOCAL, &cb_data, sizeof(cb_data));
496+
#if CONFIG_PROBE
497+
if (buffer->probe_cb_produce) {
498+
struct buffer_cb_transact cb_data = {
499+
.buffer = buffer,
500+
.transaction_amount = bytes,
501+
.transaction_begin_address = produce_begin,
502+
};
503+
504+
buffer->probe_cb_produce(buffer->probe_cb_arg, &cb_data);
505+
}
506+
#endif
506507

507508
#if CONFIG_SOF_LOG_DBG_BUFFER
508509
buf_dbg(buffer, "((buffer->avail << 16) | buffer->free) = %08x, ((buffer->id << 16) | buffer->size) = %08x",
@@ -519,12 +520,6 @@ void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
519520

520521
void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
521522
{
522-
struct buffer_cb_transact cb_data = {
523-
.buffer = buffer,
524-
.transaction_amount = bytes,
525-
.transaction_begin_address = audio_stream_get_rptr(&buffer->stream),
526-
};
527-
528523
CORE_CHECK_STRUCT(&buffer->audio_buffer);
529524

530525
/* return if no bytes */
@@ -544,9 +539,6 @@ void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
544539

545540
audio_stream_consume(&buffer->stream, bytes);
546541

547-
notifier_event(buffer, NOTIFIER_ID_BUFFER_CONSUME,
548-
NOTIFIER_TARGET_CORE_LOCAL, &cb_data, sizeof(cb_data));
549-
550542
#if CONFIG_SOF_LOG_DBG_BUFFER
551543
buf_dbg(buffer, "(buffer->avail << 16) | buffer->free = %08x, (buffer->id << 16) | buffer->size = %08x, (buffer->r_ptr - buffer->addr) << 16 | (buffer->w_ptr - buffer->addr)) = %08x",
552544
(audio_stream_get_avail_bytes(&buffer->stream) << 16) |

src/include/sof/audio/buffer.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <stdint.h>
3434

3535
struct comp_dev;
36+
struct buffer_cb_transact;
3637

3738
/** \name Trace macros
3839
* @{
@@ -148,6 +149,15 @@ struct comp_buffer {
148149

149150
/* list of buffers, to be used i.e. in raw data processing mode*/
150151
struct list_item buffers_list;
152+
153+
#if CONFIG_PROBE
154+
/** probe produce callback, called on buffer produce */
155+
void (*probe_cb_produce)(void *arg, struct buffer_cb_transact *cb_data);
156+
/** probe free callback, called on buffer free */
157+
void (*probe_cb_free)(void *arg);
158+
/** opaque argument passed to probe callbacks */
159+
void *probe_cb_arg;
160+
#endif
151161
};
152162

153163
/*
@@ -188,17 +198,13 @@ static inline void comp_buffer_reset_sink_list(struct comp_buffer *buffer)
188198
list_init(&buffer->sink_list);
189199
}
190200

191-
/* Only to be used for synchronous same-core notifications! */
201+
/* Used as parameter for probe produce callback */
192202
struct buffer_cb_transact {
193203
struct comp_buffer *buffer;
194204
uint32_t transaction_amount;
195205
void *transaction_begin_address;
196206
};
197207

198-
struct buffer_cb_free {
199-
struct comp_buffer *buffer;
200-
};
201-
202208
#define buffer_from_list(ptr, dir) \
203209
((dir) == PPL_DIR_DOWNSTREAM ? \
204210
container_of(ptr, struct comp_buffer, source_list) : \

src/include/sof/lib/notifier.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ enum notify_id {
2727
NOTIFIER_ID_SSP_FREQ, /* struct clock_notify_data * */
2828
NOTIFIER_ID_KPB_CLIENT_EVT, /* struct kpb_event_data * */
2929
NOTIFIER_ID_DMA_DOMAIN_CHANGE, /* struct dma_chan_data * */
30-
NOTIFIER_ID_BUFFER_PRODUCE, /* struct buffer_cb_transact* */
31-
NOTIFIER_ID_BUFFER_CONSUME, /* struct buffer_cb_transact* */
32-
NOTIFIER_ID_BUFFER_FREE, /* struct buffer_cb_free* */
3330
NOTIFIER_ID_DMA_COPY, /* struct dma_cb_data* */
3431
NOTIFIER_ID_LL_POST_RUN, /* NULL */
3532
NOTIFIER_ID_DMA_IRQ, /* struct dma_chan_data * */

src/probe/probe.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <rtos/alloc.h>
1414
#include <rtos/init.h>
1515
#include <sof/lib/dma.h>
16-
#include <sof/lib/notifier.h>
1716
#include <sof/lib/uuid.h>
1817
#include <sof/ipc/topology.h>
1918
#include <sof/ipc/driver.h>
@@ -902,14 +901,12 @@ static ssize_t probe_logging_hook(uint8_t *buffer, size_t length)
902901
* Extraction probe: generate format, header and copy data to probe buffer.
903902
* Injection probe: find corresponding DMA, check avail data, copy data,
904903
* update pointers and request more data from host if needed.
905-
* \param[in] arg pointer (not used).
906-
* \param[in] type of notify.
907-
* \param[in] data pointer.
904+
* \param[in] arg pointer to buffer_id.
905+
* \param[in] cb_data pointer to buffer callback transaction data.
908906
*/
909-
static void probe_cb_produce(void *arg, enum notify_id type, void *data)
907+
static void probe_cb_produce(void *arg, struct buffer_cb_transact *cb_data)
910908
{
911909
struct probe_pdata *_probe = probe_get();
912-
struct buffer_cb_transact *cb_data = data;
913910
struct comp_buffer *buffer = cb_data->buffer;
914911
struct probe_dma_ext *dma;
915912
uint32_t buffer_id;
@@ -921,7 +918,7 @@ static void probe_cb_produce(void *arg, enum notify_id type, void *data)
921918
uint32_t format;
922919
uint64_t checksum;
923920

924-
buffer_id = *(int *)arg;
921+
buffer_id = *(uint32_t *)arg;
925922

926923
/* search for probe point connected to this buffer */
927924
for (i = 0; i < CONFIG_PROBE_POINTS_MAX; i++)
@@ -1068,13 +1065,11 @@ static void probe_cb_produce(void *arg, enum notify_id type, void *data)
10681065

10691066
/**
10701067
* \brief Callback for buffer free, it will remove probe point.
1071-
* \param[in] arg pointer (not used).
1072-
* \param[in] type of notify.
1073-
* \param[in] data pointer.
1068+
* \param[in] arg pointer to buffer_id.
10741069
*/
1075-
static void probe_cb_free(void *arg, enum notify_id type, void *data)
1070+
static void probe_cb_free(void *arg)
10761071
{
1077-
uint32_t buffer_id = *(int *)arg;
1072+
uint32_t buffer_id = *(uint32_t *)arg;
10781073
int ret;
10791074

10801075
tr_dbg(&pr_tr, "buffer_id = %u", buffer_id);
@@ -1315,16 +1310,13 @@ int probe_point_add(uint32_t count, const struct probe_point *probe)
13151310
probe_point_id_t *new_buf_id = &_probe->probe_points[first_free].buffer_id;
13161311

13171312
#if CONFIG_IPC_MAJOR_4
1318-
notifier_register(&new_buf_id->full_id, buf, NOTIFIER_ID_BUFFER_PRODUCE,
1319-
&probe_cb_produce, 0);
1320-
notifier_register(&new_buf_id->full_id, buf, NOTIFIER_ID_BUFFER_FREE,
1321-
&probe_cb_free, 0);
1313+
struct comp_buffer *probe_buf = buf;
13221314
#else
1323-
notifier_register(&new_buf_id->full_id, dev->cb, NOTIFIER_ID_BUFFER_PRODUCE,
1324-
&probe_cb_produce, 0);
1325-
notifier_register(&new_buf_id->full_id, dev->cb, NOTIFIER_ID_BUFFER_FREE,
1326-
&probe_cb_free, 0);
1315+
struct comp_buffer *probe_buf = (struct comp_buffer *)dev->cb;
13271316
#endif
1317+
probe_buf->probe_cb_produce = probe_cb_produce;
1318+
probe_buf->probe_cb_free = probe_cb_free;
1319+
probe_buf->probe_cb_arg = &new_buf_id->full_id;
13281320
}
13291321
}
13301322

@@ -1444,19 +1436,20 @@ int probe_point_remove(uint32_t count, const uint32_t *buffer_id)
14441436
if (dev) {
14451437
buf = ipc4_get_buffer(dev, *buf_id);
14461438
if (buf) {
1447-
notifier_unregister(NULL, buf,
1448-
NOTIFIER_ID_BUFFER_PRODUCE);
1449-
notifier_unregister(NULL, buf,
1450-
NOTIFIER_ID_BUFFER_FREE);
1439+
buf->probe_cb_produce = NULL;
1440+
buf->probe_cb_free = NULL;
1441+
buf->probe_cb_arg = NULL;
14511442
}
14521443
}
14531444
#else
14541445
dev = ipc_get_comp_by_id(ipc_get(), buffer_id[i]);
14551446
if (dev) {
1456-
notifier_unregister(&buf_id->full_id, dev->cb,
1457-
NOTIFIER_ID_BUFFER_PRODUCE);
1458-
notifier_unregister(&buf_id->full_id, dev->cb,
1459-
NOTIFIER_ID_BUFFER_FREE);
1447+
struct comp_buffer *probe_buf =
1448+
(struct comp_buffer *)dev->cb;
1449+
1450+
probe_buf->probe_cb_produce = NULL;
1451+
probe_buf->probe_cb_free = NULL;
1452+
probe_buf->probe_cb_arg = NULL;
14601453
}
14611454
#endif
14621455
_probe->probe_points[j].stream_tag =

0 commit comments

Comments
 (0)