Skip to content

Commit d69eea8

Browse files
committed
ipc4: notification: Internal IPC allocation
Moving memory allocation for IPC4 notifications to the notification module. With this change all the logic needed for sending IPC4 notifications is contained within the notification module. Currently all the notifications are allocated out of the same memory pool, so the selection of a memory pool is not part of the function interface of the notification module, but we can easily modify that behavior by adding a pool ID parameter. This change enables robust implementation of the notification filtering feature without exposing additional symbols to LLEXT modules. Signed-off-by: Wojciech Jablonski <wojciech.jablonski@intel.com>
1 parent 9ce8671 commit d69eea8

File tree

8 files changed

+66
-121
lines changed

8 files changed

+66
-121
lines changed

src/audio/chain_dma.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <zephyr/pm/policy.h>
2727
#include <rtos/init.h>
2828
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
29-
#include <sof/ipc/notification_pool.h>
3029
#include <ipc4/notification.h>
3130
#endif
3231

@@ -150,19 +149,8 @@ static int chain_get_dma_status(struct chain_dma_data *cd, struct dma_chan_data
150149
int ret = dma_get_status(chan->dma->z_dev, chan->index, stat);
151150
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
152151
if (ret == -EPIPE && !cd->xrun_notification_sent) {
153-
struct ipc_msg *notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
154-
155-
if (notify) {
156-
if (cd->stream_direction == SOF_IPC_STREAM_PLAYBACK)
157-
gateway_underrun_notif_msg_init(notify,
158-
cd->link_connector_node_id.dw);
159-
else
160-
gateway_overrun_notif_msg_init(notify,
161-
cd->link_connector_node_id.dw);
162-
163-
ipc_msg_send(notify, notify->tx_data, false);
164-
cd->xrun_notification_sent = true;
165-
}
152+
cd->xrun_notification_sent = send_gateway_xrun_notif_msg
153+
(cd->link_connector_node_id.dw, cd->stream_direction);
166154
} else if (!ret) {
167155
cd->xrun_notification_sent = false;
168156
}

src/audio/dai-zephyr.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <stdint.h>
3838

3939
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
40-
#include <sof/ipc/notification_pool.h>
4140
#include <ipc4/notification.h>
4241
#endif
4342

@@ -1478,19 +1477,8 @@ static int dai_get_status(struct comp_dev *dev, struct dai_data *dd, struct dma_
14781477
int ret = sof_dma_get_status(dd->chan->dma, dd->chan->index, stat);
14791478
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
14801479
if (ret == -EPIPE && !dd->xrun_notification_sent) {
1481-
struct ipc_msg *notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
1482-
1483-
if (notify) {
1484-
if (dev->direction == SOF_IPC_STREAM_PLAYBACK)
1485-
copier_gateway_underrun_notif_msg_init(notify,
1486-
dev->pipeline->pipeline_id);
1487-
else
1488-
copier_gateway_overrun_notif_msg_init(notify,
1489-
dev->pipeline->pipeline_id);
1490-
1491-
ipc_msg_send(notify, notify->tx_data, false);
1492-
dd->xrun_notification_sent = true;
1493-
}
1480+
dd->xrun_notification_sent = send_copier_gateway_xrun_notif_msg
1481+
(dev->pipeline->pipeline_id, dev->direction);
14941482
} else if (!ret) {
14951483
dd->xrun_notification_sent = false;
14961484
}

src/audio/host-zephyr.c

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

3535
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
36-
#include <sof/ipc/notification_pool.h>
3736
#include <ipc4/notification.h>
3837
#endif
3938

@@ -368,19 +367,8 @@ static int host_get_status(struct comp_dev *dev, struct host_data *hd, struct dm
368367
int ret = sof_dma_get_status(hd->chan->dma, hd->chan->index, stat);
369368
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
370369
if (ret == -EPIPE && !hd->xrun_notification_sent) {
371-
struct ipc_msg *notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
372-
373-
if (notify) {
374-
if (dev->direction == SOF_IPC_STREAM_PLAYBACK)
375-
copier_gateway_underrun_notif_msg_init(notify,
376-
dev->pipeline->pipeline_id);
377-
else
378-
copier_gateway_overrun_notif_msg_init(notify,
379-
dev->pipeline->pipeline_id);
380-
381-
ipc_msg_send(notify, notify->tx_data, false);
382-
hd->xrun_notification_sent = true;
383-
}
370+
hd->xrun_notification_sent = send_copier_gateway_xrun_notif_msg
371+
(dev->pipeline->pipeline_id, dev->direction);
384372
} else if (!ret) {
385373
hd->xrun_notification_sent = false;
386374
}

src/audio/mixin_mixout/mixin_mixout.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <sof/compiler_attributes.h>
1313
#include <rtos/panic.h>
1414
#include <sof/ipc/msg.h>
15-
#include <sof/ipc/notification_pool.h>
1615
#include <rtos/init.h>
1716
#include <sof/lib/uuid.h>
1817
#include <sof/list.h>
@@ -253,8 +252,6 @@ static void mixin_check_notify_underrun(struct comp_dev *dev, struct mixin_data
253252
const bool eos_detected = state == AUDIOBUF_STATE_END_OF_STREAM_FLUSH ||
254253
state == AUDIOBUF_STATE_END_OF_STREAM;
255254

256-
struct ipc_msg *notify;
257-
258255
mixin_data->last_reported_underrun++;
259256

260257
if (!source_avail || eos_detected) {
@@ -273,13 +270,8 @@ static void mixin_check_notify_underrun(struct comp_dev *dev, struct mixin_data
273270
(eos_detected && mixin_data->eos_delay_periods == 0)) {
274271
mixin_data->last_reported_underrun = 0;
275272

276-
notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
277-
if (!notify)
278-
return;
279-
280-
mixer_underrun_notif_msg_init(notify, dev->ipc_config.id, eos_detected,
273+
send_mixer_underrun_notif_msg(dev->ipc_config.id, eos_detected,
281274
source_avail, sinks_free);
282-
ipc_msg_send(notify, notify->tx_data, false);
283275
}
284276
}
285277
}

src/audio/pipeline/pipeline-stream.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <rtos/kernel.h>
2222
#include <sof/audio/module_adapter/module/generic.h>
2323
#include <sof/lib/cpu-clk-manager.h>
24-
#include <sof/ipc/notification_pool.h>
2524

2625
#ifdef CONFIG_IPC_MAJOR_4
2726
#include <ipc4/notification.h>
@@ -96,14 +95,7 @@ pipeline_should_report_enodata_on_trigger(struct comp_dev *rsrc,
9695
void pipeline_comp_copy_error_notify(const struct comp_dev *component, int err)
9796
{
9897
#ifdef CONFIG_IPC_MAJOR_4
99-
struct ipc_msg *notify;
100-
101-
notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
102-
if (!notify)
103-
return;
104-
105-
process_data_error_notif_msg_init(notify, component->ipc_config.id, err);
106-
ipc_msg_send(notify, notify->tx_data, false);
98+
send_process_data_error_notif_msg(component->ipc_config.id, err);
10799
#endif
108100
}
109101

src/include/ipc4/notification.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,12 @@ struct ipc4_resource_event_data_notification {
288288

289289
#define IPC4_RESOURCE_EVENT_SIZE sizeof(struct ipc4_resource_event_data_notification)
290290

291-
void process_data_error_notif_msg_init(struct ipc_msg *msg, uint32_t resource_id,
292-
uint32_t error_code);
291+
void send_process_data_error_notif_msg(uint32_t resource_id, uint32_t error_code);
293292

294-
void copier_gateway_underrun_notif_msg_init(struct ipc_msg *msg, uint32_t pipeline_id);
295-
void copier_gateway_overrun_notif_msg_init(struct ipc_msg *msg, uint32_t pipeline_id);
296-
void gateway_underrun_notif_msg_init(struct ipc_msg *msg, uint32_t resource_id);
297-
void gateway_overrun_notif_msg_init(struct ipc_msg *msg, uint32_t resource_id);
293+
bool send_copier_gateway_xrun_notif_msg(uint32_t pipeline_id, enum sof_ipc_stream_direction dir);
294+
bool send_gateway_xrun_notif_msg(uint32_t resource_id, enum sof_ipc_stream_direction dir);
298295

299-
void mixer_underrun_notif_msg_init(struct ipc_msg *msg, uint32_t resource_id, uint32_t eos_flag,
300-
uint32_t data_mixed, uint32_t expected_data_mixed);
296+
void send_mixer_underrun_notif_msg(uint32_t resource_id, uint32_t eos_flag, uint32_t data_mixed,
297+
uint32_t expected_data_mixed);
301298

302299
#endif /* __IPC4_NOTIFICATION_H__ */

src/ipc/ipc4/notification.c

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,85 +10,86 @@
1010
#include <sof/ipc/msg.h>
1111
#include <stdbool.h>
1212
#include <ipc4/notification.h>
13+
#include <sof/ipc/notification_pool.h>
1314

1415
#include <rtos/symbol.h>
1516

16-
static void resource_notif_header_init(struct ipc_msg *msg)
17+
static bool send_resource_notif(uint32_t resource_id, uint32_t event_type, uint32_t resource_type,
18+
void *data, uint32_t data_size)
1719
{
18-
struct ipc4_resource_event_data_notification *notif_data = msg->tx_data;
20+
struct ipc_msg *msg = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
21+
22+
if (!msg)
23+
return false;
24+
25+
struct ipc4_resource_event_data_notification *notif = msg->tx_data;
1926
union ipc4_notification_header header;
2027

2128
header.r.notif_type = SOF_IPC4_NOTIFY_RESOURCE_EVENT;
2229
header.r.type = SOF_IPC4_GLB_NOTIFICATION;
2330
header.r.rsp = SOF_IPC4_MESSAGE_DIR_MSG_REQUEST;
2431
header.r.msg_tgt = SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG;
2532
msg->header = header.dat;
26-
memset(&notif_data->event_data, 0, sizeof(notif_data->event_data));
33+
34+
notif->resource_id = resource_id;
35+
notif->event_type = event_type;
36+
notif->resource_type = resource_type;
37+
memset(&notif->event_data, 0, sizeof(notif->event_data));
38+
if (data && data_size) {
39+
int ret = memcpy_s(&notif->event_data, sizeof(notif->event_data), data, data_size);
40+
41+
if (!ret) {
42+
/* Most likely a simple coding mistake:
43+
* Using a data type that is not included in the event_data union.
44+
* Return true to prevent an infinite re-try loop in non-debug builds
45+
*/
46+
assert(false);
47+
return true;
48+
}
49+
}
50+
51+
ipc_msg_send(msg, msg->tx_data, false);
52+
53+
return true;
2754
}
2855

29-
void copier_gateway_underrun_notif_msg_init(struct ipc_msg *msg, uint32_t pipeline_id)
56+
static enum sof_ipc4_resource_event_type dir_to_xrun_event(enum sof_ipc_stream_direction dir)
3057
{
31-
struct ipc4_resource_event_data_notification *notif_data = msg->tx_data;
32-
33-
resource_notif_header_init(msg);
34-
notif_data->resource_id = pipeline_id;
35-
notif_data->event_type = SOF_IPC4_GATEWAY_UNDERRUN_DETECTED;
36-
notif_data->resource_type = SOF_IPC4_PIPELINE;
58+
return (dir == SOF_IPC_STREAM_PLAYBACK) ? SOF_IPC4_GATEWAY_UNDERRUN_DETECTED :
59+
SOF_IPC4_GATEWAY_OVERRUN_DETECTED;
3760
}
3861

39-
void gateway_underrun_notif_msg_init(struct ipc_msg *msg, uint32_t resource_id)
62+
bool send_copier_gateway_xrun_notif_msg(uint32_t pipeline_id, enum sof_ipc_stream_direction dir)
4063
{
41-
struct ipc4_resource_event_data_notification *notif_data = msg->tx_data;
42-
43-
resource_notif_header_init(msg);
44-
notif_data->resource_id = resource_id;
45-
notif_data->event_type = SOF_IPC4_GATEWAY_UNDERRUN_DETECTED;
46-
notif_data->resource_type = SOF_IPC4_GATEWAY;
64+
return send_resource_notif(pipeline_id, dir_to_xrun_event(dir), SOF_IPC4_PIPELINE, NULL,
65+
0);
4766
}
4867

49-
void copier_gateway_overrun_notif_msg_init(struct ipc_msg *msg, uint32_t pipeline_id)
68+
bool send_gateway_xrun_notif_msg(uint32_t resource_id, enum sof_ipc_stream_direction dir)
5069
{
51-
struct ipc4_resource_event_data_notification *notif_data = msg->tx_data;
52-
53-
resource_notif_header_init(msg);
54-
notif_data->resource_id = pipeline_id;
55-
notif_data->event_type = SOF_IPC4_GATEWAY_OVERRUN_DETECTED;
56-
notif_data->resource_type = SOF_IPC4_PIPELINE;
70+
return send_resource_notif(resource_id, dir_to_xrun_event(dir), SOF_IPC4_GATEWAY, NULL, 0);
5771
}
5872

59-
void gateway_overrun_notif_msg_init(struct ipc_msg *msg, uint32_t resource_id)
73+
void send_mixer_underrun_notif_msg(uint32_t resource_id, uint32_t eos_flag, uint32_t data_mixed,
74+
uint32_t expected_data_mixed)
6075
{
61-
struct ipc4_resource_event_data_notification *notif_data = msg->tx_data;
76+
struct ipc4_mixer_underrun_event_data mixer_underrun_data;
6277

63-
resource_notif_header_init(msg);
64-
notif_data->resource_id = resource_id;
65-
notif_data->event_type = SOF_IPC4_GATEWAY_OVERRUN_DETECTED;
66-
notif_data->resource_type = SOF_IPC4_GATEWAY;
67-
}
78+
mixer_underrun_data.eos_flag = eos_flag;
79+
mixer_underrun_data.data_mixed = data_mixed;
80+
mixer_underrun_data.expected_data_mixed = expected_data_mixed;
6881

69-
void mixer_underrun_notif_msg_init(struct ipc_msg *msg, uint32_t resource_id, uint32_t eos_flag,
70-
uint32_t data_mixed, uint32_t expected_data_mixed)
71-
{
72-
struct ipc4_resource_event_data_notification *notif_data = msg->tx_data;
73-
74-
resource_notif_header_init(msg);
75-
notif_data->resource_id = resource_id;
76-
notif_data->event_type = SOF_IPC4_MIXER_UNDERRUN_DETECTED;
77-
notif_data->resource_type = SOF_IPC4_PIPELINE;
78-
notif_data->event_data.mixer_underrun.eos_flag = eos_flag;
79-
notif_data->event_data.mixer_underrun.data_mixed = data_mixed;
80-
notif_data->event_data.mixer_underrun.expected_data_mixed = expected_data_mixed;
82+
send_resource_notif(resource_id, SOF_IPC4_MIXER_UNDERRUN_DETECTED, SOF_IPC4_PIPELINE,
83+
&mixer_underrun_data, sizeof(mixer_underrun_data));
8184
}
82-
EXPORT_SYMBOL(mixer_underrun_notif_msg_init);
85+
EXPORT_SYMBOL(send_mixer_underrun_notif_msg);
8386

84-
void process_data_error_notif_msg_init(struct ipc_msg *msg, uint32_t resource_id,
85-
uint32_t error_code)
87+
void send_process_data_error_notif_msg(uint32_t resource_id, uint32_t error_code)
8688
{
87-
struct ipc4_resource_event_data_notification *notif_data = msg->tx_data;
89+
struct ipc4_process_data_error_event_data error_data;
90+
91+
error_data.error_code = error_code;
8892

89-
resource_notif_header_init(msg);
90-
notif_data->resource_id = resource_id;
91-
notif_data->event_type = SOF_IPC4_PROCESS_DATA_ERROR;
92-
notif_data->resource_type = SOF_IPC4_MODULE_INSTANCE;
93-
notif_data->event_data.process_data_error.error_code = error_code;
93+
send_resource_notif(resource_id, SOF_IPC4_PROCESS_DATA_ERROR, SOF_IPC4_MODULE_INSTANCE,
94+
&error_data, sizeof(error_data));
9495
}

src/ipc/notification_pool.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,3 @@ struct ipc_msg *ipc_notification_pool_get(size_t size)
100100
item->msg.tx_size = size;
101101
return &item->msg;
102102
}
103-
EXPORT_SYMBOL(ipc_notification_pool_get);

0 commit comments

Comments
 (0)