Skip to content

Commit b7777f8

Browse files
author
Jyri Sarha
committed
Audio: Copier: All memory allocations through module API
Allocate all memory through module API mod_alloc() and friends. NOTE: copier_dai.c and copier_host.c still have their shared memory allocated through the old API. This is to be fixed once we have decided on how the shared memory allocations should work in user-space. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 72b1959 commit b7777f8

5 files changed

Lines changed: 44 additions & 37 deletions

File tree

src/audio/copier/copier.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <sof/ipc/topology.h>
1616
#include <rtos/interrupt.h>
1717
#include <rtos/timer.h>
18-
#include <rtos/alloc.h>
1918
#include <rtos/cache.h>
2019
#include <rtos/init.h>
2120
#include <sof/lib/memory.h>
@@ -82,13 +81,12 @@ static void mic_privacy_event(void *arg, enum notify_id type, void *data)
8281
}
8382
}
8483

85-
static int mic_privacy_configure(struct comp_dev *dev, struct copier_data *cd)
84+
static int mic_privacy_configure(struct processing_module *mod, struct copier_data *cd)
8685
{
8786
struct mic_privacy_data *mic_priv_data;
8887
int ret;
8988

90-
mic_priv_data = rzalloc(SOF_MEM_FLAG_USER,
91-
sizeof(struct mic_privacy_data));
89+
mic_priv_data = mod_zalloc(mod, sizeof(struct mic_privacy_data));
9290
if (!mic_priv_data)
9391
return -ENOMEM;
9492

@@ -100,19 +98,20 @@ static int mic_privacy_configure(struct comp_dev *dev, struct copier_data *cd)
10098
uint32_t zeroing_wait_time = (mic_privacy_get_dma_zeroing_wait_time() * 1000) /
10199
ADSP_RTC_FREQUENCY;
102100

103-
ret = copier_gain_set_params(dev, &mic_priv_data->mic_priv_gain_params,
101+
ret = copier_gain_set_params(mod->dev, &mic_priv_data->mic_priv_gain_params,
104102
zeroing_wait_time, SOF_DAI_INTEL_NONE);
105103
if (ret != 0) {
106-
rfree(mic_priv_data);
104+
mod_free(mod, mic_priv_data);
107105
return ret;
108106
}
109107

110108
cd->mic_priv = mic_priv_data;
111109

112110
ret = notifier_register(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE,
113111
mic_privacy_event, 0);
112+
114113
if (ret != 0)
115-
rfree(mic_priv_data);
114+
mod_free(mod, mic_priv_data);
116115

117116
return ret;
118117
}
@@ -124,7 +123,7 @@ static void mic_privacy_free(struct copier_data *cd)
124123

125124
notifier_unregister(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE);
126125

127-
rfree(cd->mic_priv);
126+
mod_free(mod, cd->mic_priv);
128127
}
129128
#endif
130129

@@ -141,7 +140,7 @@ __cold static int copier_init(struct processing_module *mod)
141140

142141
assert_can_be_cold();
143142

144-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
143+
cd = mod_zalloc(mod, sizeof(*cd));
145144
if (!cd)
146145
return -ENOMEM;
147146

@@ -163,8 +162,7 @@ __cold static int copier_init(struct processing_module *mod)
163162
*/
164163
if (copier->gtw_cfg.config_length) {
165164
gtw_cfg_size = copier->gtw_cfg.config_length << 2;
166-
gtw_cfg = rmalloc(SOF_MEM_FLAG_USER,
167-
gtw_cfg_size);
165+
gtw_cfg = mod_alloc(mod, gtw_cfg_size);
168166
if (!gtw_cfg) {
169167
ret = -ENOMEM;
170168
goto error_cd;
@@ -191,15 +189,15 @@ __cold static int copier_init(struct processing_module *mod)
191189
switch (node_id.f.dma_type) {
192190
case ipc4_hda_host_output_class:
193191
case ipc4_hda_host_input_class:
194-
ret = copier_host_create(dev, cd, copier, dev->pipeline);
192+
ret = copier_host_create(mod, copier, dev->pipeline);
195193
if (ret < 0) {
196194
comp_err(dev, "unable to create host");
197195
goto error;
198196
}
199197
#if CONFIG_INTEL_ADSP_MIC_PRIVACY
200198
if (cd->direction == SOF_IPC_STREAM_CAPTURE &&
201199
node_id.f.dma_type == ipc4_hda_host_output_class) {
202-
ret = mic_privacy_configure(dev, cd);
200+
ret = mic_privacy_configure(mod, cd);
203201
if (ret < 0) {
204202
comp_err(dev, "unable to configure mic privacy");
205203
goto error;
@@ -221,7 +219,7 @@ __cold static int copier_init(struct processing_module *mod)
221219
}
222220
#if CONFIG_INTEL_ADSP_MIC_PRIVACY
223221
if (cd->direction == SOF_IPC_STREAM_CAPTURE) {
224-
ret = mic_privacy_configure(dev, cd);
222+
ret = mic_privacy_configure(mod, cd);
225223
if (ret < 0) {
226224
comp_err(dev, "unable to configure mic privacy");
227225
goto error;
@@ -232,7 +230,7 @@ __cold static int copier_init(struct processing_module *mod)
232230
#if CONFIG_IPC4_GATEWAY
233231
case ipc4_ipc_output_class:
234232
case ipc4_ipc_input_class:
235-
ret = copier_ipcgtw_create(dev, cd, copier, dev->pipeline);
233+
ret = copier_ipcgtw_create(mod, copier, dev->pipeline);
236234
if (ret < 0) {
237235
comp_err(dev, "unable to create IPC gateway");
238236
goto error;
@@ -257,9 +255,9 @@ __cold static int copier_init(struct processing_module *mod)
257255
dev->state = COMP_STATE_READY;
258256
return 0;
259257
error:
260-
rfree(gtw_cfg);
258+
mod_free(mod, gtw_cfg);
261259
error_cd:
262-
rfree(cd);
260+
mod_free(mod, cd);
263261
return ret;
264262
}
265263

@@ -277,10 +275,10 @@ __cold static int copier_free(struct processing_module *mod)
277275
switch (dev->ipc_config.type) {
278276
case SOF_COMP_HOST:
279277
if (!cd->ipc_gtw)
280-
copier_host_free(cd);
278+
copier_host_free(mod);
281279
else
282280
/* handle gtw case */
283-
copier_ipcgtw_free(cd);
281+
copier_ipcgtw_free(mod);
284282
break;
285283
case SOF_COMP_DAI:
286284
copier_dai_free(cd);
@@ -290,8 +288,8 @@ __cold static int copier_free(struct processing_module *mod)
290288
}
291289

292290
if (cd)
293-
rfree(cd->gtw_cfg);
294-
rfree(cd);
291+
mod_free(mod, cd->gtw_cfg);
292+
mod_free(mod, cd);
295293

296294
return 0;
297295
}

src/audio/copier/copier_host.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ __cold static int init_pipeline_reg(struct comp_dev *dev)
131131
* Sof host component can support this case so copier reuses host
132132
* component to support host gateway.
133133
*/
134-
__cold int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
134+
__cold int copier_host_create(struct processing_module *mod,
135135
const struct ipc4_copier_module_cfg *copier_cfg,
136136
struct pipeline *pipeline)
137137
{
138-
struct processing_module *mod = comp_mod(dev);
138+
struct copier_data *cd = module_get_private_data(mod);
139+
struct comp_dev *dev = mod->dev;
139140
struct comp_ipc_config *config = &dev->ipc_config;
140141
struct ipc_config_host ipc_host;
141142
struct host_data *hd;
@@ -177,7 +178,7 @@ __cold int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
177178
ipc_host.dma_buffer_size = copier_cfg->gtw_cfg.dma_buffer_size;
178179
ipc_host.feature_mask = copier_cfg->copier_feature_mask;
179180

180-
hd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*hd));
181+
hd = mod_zalloc(mod, sizeof(*hd));
181182
if (!hd)
182183
return -ENOMEM;
183184

@@ -187,6 +188,7 @@ __cold int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
187188
goto e_data;
188189
}
189190
#if CONFIG_HOST_DMA_STREAM_SYNCHRONIZATION
191+
/* NOTE: Should use goto e_conv this #if section, not direct return */
190192
/* Size of a configuration without optional parameters. */
191193
const uint32_t basic_size = sizeof(*copier_cfg) +
192194
(copier_cfg->gtw_cfg.config_length - 1) * sizeof(uint32_t);
@@ -249,21 +251,23 @@ __cold int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
249251
e_conv:
250252
host_common_free(hd);
251253
e_data:
252-
rfree(hd);
254+
mod_free(mod, hd);
253255

254256
return ret;
255257
}
256258

257-
__cold void copier_host_free(struct copier_data *cd)
259+
__cold void copier_host_free(struct processing_module *mod)
258260
{
261+
struct copier_data *cd = module_get_private_data(mod);
262+
259263
assert_can_be_cold();
260264

261265
#if CONFIG_HOST_DMA_STREAM_SYNCHRONIZATION
262266
if (cd->hd->is_grouped)
263267
delete_from_fpi_sync_group(cd->hd);
264268
#endif
265269
host_common_free(cd->hd);
266-
rfree(cd->hd);
270+
mod_free(mod, cd->hd);
267271
}
268272

269273
/* This is called by DMA driver every time when DMA completes its current

src/audio/copier/copier_ipcgtw.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// Copyright 2023 Intel Corporation. All rights reserved.
44

5+
#include <sof/audio/module_adapter/module/generic.h>
56
#include <sof/audio/component_ext.h>
67
#include <sof/trace/trace.h>
78
#include <sof/lib/memory.h>
@@ -207,10 +208,12 @@ void copier_ipcgtw_reset(struct comp_dev *dev)
207208
}
208209
}
209210

210-
__cold int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
211+
__cold int copier_ipcgtw_create(struct processing_module *mod,
211212
const struct ipc4_copier_module_cfg *copier,
212213
struct pipeline *pipeline)
213214
{
215+
struct copier_data *cd = module_get_private_data(mod);
216+
struct comp_dev *dev = mod->dev;
214217
struct comp_ipc_config *config = &dev->ipc_config;
215218
struct ipcgtw_data *ipcgtw_data;
216219
const struct ipc4_copier_gateway_cfg *gtw_cfg;
@@ -231,7 +234,7 @@ __cold int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
231234
config->type = SOF_COMP_HOST;
232235
cd->gtw_type = ipc4_gtw_host;
233236

234-
ipcgtw_data = rzalloc(SOF_MEM_FLAG_USER, sizeof(*ipcgtw_data));
237+
ipcgtw_data = mod_zalloc(mod, sizeof(*ipcgtw_data));
235238
if (!ipcgtw_data)
236239
return -ENOMEM;
237240

@@ -273,14 +276,16 @@ __cold int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
273276
return 0;
274277

275278
e_ipcgtw:
276-
rfree(ipcgtw_data);
279+
mod_free(mod, ipcgtw_data);
277280
return ret;
278281
}
279282

280-
__cold void copier_ipcgtw_free(struct copier_data *cd)
283+
__cold void copier_ipcgtw_free(struct processing_module *mod)
281284
{
285+
struct copier_data *cd = module_get_private_data(mod);
286+
282287
assert_can_be_cold();
283288

284289
list_item_del(&cd->ipcgtw_data->item);
285-
rfree(cd->ipcgtw_data);
290+
mod_free(mod, cd->ipcgtw_data);
286291
}

src/audio/copier/host_copier.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ static inline int host_common_copy(struct host_data *hd, struct comp_dev *dev, c
129129
}
130130
void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t bytes);
131131
void host_common_one_shot(struct host_data *hd, uint32_t bytes);
132-
int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
132+
int copier_host_create(struct processing_module *mod,
133133
const struct ipc4_copier_module_cfg *copier_cfg,
134134
struct pipeline *pipeline);
135-
void copier_host_free(struct copier_data *cd);
135+
void copier_host_free(struct processing_module *mod);
136136
int copier_host_params(struct copier_data *cd, struct comp_dev *dev,
137137
struct sof_ipc_stream_params *params);
138138
void copier_host_dma_cb(struct comp_dev *dev, size_t bytes);

src/audio/copier/ipcgtw_copier.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ struct ipc4_ipc_gateway_cmd_data_reply {
9595
int copier_ipcgtw_process(const struct ipc4_ipcgtw_cmd *cmd,
9696
void *reply_payload, uint32_t *reply_payload_size);
9797

98-
int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
98+
int copier_ipcgtw_create(struct processing_module *mod,
9999
const struct ipc4_copier_module_cfg *copier, struct pipeline *pipeline);
100100

101101
#if CONFIG_IPC4_GATEWAY
102-
void copier_ipcgtw_free(struct copier_data *cd);
102+
void copier_ipcgtw_free(struct processing_module *mod);
103103
int copier_ipcgtw_params(struct ipcgtw_data *ipcgtw_data, struct comp_dev *dev,
104104
struct sof_ipc_stream_params *params);
105105

106106
void copier_ipcgtw_reset(struct comp_dev *dev);
107107
#else
108-
static inline void copier_ipcgtw_free(struct copier_data *cd) {}
108+
static inline void copier_ipcgtw_free(struct processing_module *mod) {}
109109
static inline void copier_ipcgtw_reset(struct comp_dev *dev) {}
110110
static inline int copier_ipcgtw_params(struct ipcgtw_data *ipcgtw_data, struct comp_dev *dev,
111111
struct sof_ipc_stream_params *params)

0 commit comments

Comments
 (0)