Skip to content

Commit 2fe341f

Browse files
Jyri Sarhalgirdwood
authored andcommitted
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 bb400ed commit 2fe341f

5 files changed

Lines changed: 48 additions & 39 deletions

File tree

src/audio/copier/copier.c

Lines changed: 23 additions & 23 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,31 +98,34 @@ 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
}
119118

120-
static void mic_privacy_free(struct copier_data *cd)
119+
static void mic_privacy_free(struct processing_module *mod)
121120
{
121+
struct copier_data *cd = module_get_private_data(mod);
122+
122123
if (cd->gtw_type == ipc4_gtw_dmic)
123124
mic_privacy_enable_dmic_irq(false);
124125

125126
notifier_unregister(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE);
126127

127-
rfree(cd->mic_priv);
128+
mod_free(mod, cd->mic_priv);
128129
}
129130
#endif
130131

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

142143
assert_can_be_cold();
143144

144-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
145+
cd = mod_zalloc(mod, sizeof(*cd));
145146
if (!cd)
146147
return -ENOMEM;
147148

@@ -163,8 +164,7 @@ __cold static int copier_init(struct processing_module *mod)
163164
*/
164165
if (copier->gtw_cfg.config_length) {
165166
gtw_cfg_size = copier->gtw_cfg.config_length << 2;
166-
gtw_cfg = rmalloc(SOF_MEM_FLAG_USER,
167-
gtw_cfg_size);
167+
gtw_cfg = mod_alloc(mod, gtw_cfg_size);
168168
if (!gtw_cfg) {
169169
ret = -ENOMEM;
170170
goto error_cd;
@@ -191,15 +191,15 @@ __cold static int copier_init(struct processing_module *mod)
191191
switch (node_id.f.dma_type) {
192192
case ipc4_hda_host_output_class:
193193
case ipc4_hda_host_input_class:
194-
ret = copier_host_create(dev, cd, copier, dev->pipeline);
194+
ret = copier_host_create(mod, copier, dev->pipeline);
195195
if (ret < 0) {
196196
comp_err(dev, "unable to create host");
197197
goto error;
198198
}
199199
#if CONFIG_INTEL_ADSP_MIC_PRIVACY
200200
if (cd->direction == SOF_IPC_STREAM_CAPTURE &&
201201
node_id.f.dma_type == ipc4_hda_host_output_class) {
202-
ret = mic_privacy_configure(dev, cd);
202+
ret = mic_privacy_configure(mod, cd);
203203
if (ret < 0) {
204204
comp_err(dev, "unable to configure mic privacy");
205205
goto error;
@@ -221,7 +221,7 @@ __cold static int copier_init(struct processing_module *mod)
221221
}
222222
#if CONFIG_INTEL_ADSP_MIC_PRIVACY
223223
if (cd->direction == SOF_IPC_STREAM_CAPTURE) {
224-
ret = mic_privacy_configure(dev, cd);
224+
ret = mic_privacy_configure(mod, cd);
225225
if (ret < 0) {
226226
comp_err(dev, "unable to configure mic privacy");
227227
goto error;
@@ -232,7 +232,7 @@ __cold static int copier_init(struct processing_module *mod)
232232
#if CONFIG_IPC4_GATEWAY
233233
case ipc4_ipc_output_class:
234234
case ipc4_ipc_input_class:
235-
ret = copier_ipcgtw_create(dev, cd, copier, dev->pipeline);
235+
ret = copier_ipcgtw_create(mod, copier, dev->pipeline);
236236
if (ret < 0) {
237237
comp_err(dev, "unable to create IPC gateway");
238238
goto error;
@@ -257,9 +257,9 @@ __cold static int copier_init(struct processing_module *mod)
257257
dev->state = COMP_STATE_READY;
258258
return 0;
259259
error:
260-
rfree(gtw_cfg);
260+
mod_free(mod, gtw_cfg);
261261
error_cd:
262-
rfree(cd);
262+
mod_free(mod, cd);
263263
return ret;
264264
}
265265

@@ -271,16 +271,16 @@ __cold static int copier_free(struct processing_module *mod)
271271
assert_can_be_cold();
272272

273273
#if CONFIG_INTEL_ADSP_MIC_PRIVACY
274-
mic_privacy_free(cd);
274+
mic_privacy_free(mod);
275275
#endif
276276

277277
switch (dev->ipc_config.type) {
278278
case SOF_COMP_HOST:
279279
if (!cd->ipc_gtw)
280-
copier_host_free(cd);
280+
copier_host_free(mod);
281281
else
282282
/* handle gtw case */
283-
copier_ipcgtw_free(cd);
283+
copier_ipcgtw_free(mod);
284284
break;
285285
case SOF_COMP_DAI:
286286
copier_dai_free(cd);
@@ -290,8 +290,8 @@ __cold static int copier_free(struct processing_module *mod)
290290
}
291291

292292
if (cd)
293-
rfree(cd->gtw_cfg);
294-
rfree(cd);
293+
mod_free(mod, cd->gtw_cfg);
294+
mod_free(mod, cd);
295295

296296
return 0;
297297
}

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)