Skip to content

Commit 31308b5

Browse files
author
Jyri Sarha
committed
audio: copier: Use module API also for allocating non cached memory
The module API was extended to pass flags the allocation back-end [1]. With this change there is no reason not use module API also to allocate the DMA buffers. The same commit that extended the API also actively ignored the SOF_MEM_FLAG_USER flag that earlier used every where. It is and idle flag with no functionality behind it, so I dropped it from the converted calls. [1] 1d170fc module: add an allocation function with flags Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 1067470 commit 31308b5

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/audio/copier/copier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ __cold static int copier_free(struct processing_module *mod)
283283
copier_ipcgtw_free(mod);
284284
break;
285285
case SOF_COMP_DAI:
286-
copier_dai_free(cd);
286+
copier_dai_free(mod);
287287
break;
288288
default:
289289
break;

src/audio/copier/copier_dai.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,10 @@ __cold static int copier_dai_init(struct comp_dev *dev,
204204
return ret;
205205
}
206206

207-
dd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*dd));
207+
dd = mod_alloc_ext(mod, SOF_MEM_FLAG_COHERENT, sizeof(*dd), 0);
208208
if (!dd)
209209
return -ENOMEM;
210+
memset(dd, 0, sizeof(*dd));
210211

211212
ret = dai_common_new(dd, dev, dai);
212213
if (ret < 0)
@@ -223,12 +224,13 @@ __cold static int copier_dai_init(struct comp_dev *dev,
223224

224225
/* Allocate gain data if selected for this dai type and set basic params */
225226
if (dai->apply_gain) {
226-
struct copier_gain_params *gain_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
227-
sizeof(*gain_data));
227+
struct copier_gain_params *gain_data =
228+
mod_alloc_ext(mod, SOF_MEM_FLAG_COHERENT, sizeof(*gain_data), 0);
228229
if (!gain_data) {
229230
ret = -ENOMEM;
230231
goto e_zephyr_free;
231232
}
233+
memset(gain_data, 0, sizeof(*gain_data));
232234
cd->dd[index]->gain_data = gain_data;
233235

234236
ret = copier_gain_set_params(dev, cd->dd[index]->gain_data,
@@ -244,11 +246,11 @@ __cold static int copier_dai_init(struct comp_dev *dev,
244246

245247
return 0;
246248
gain_free:
247-
rfree(dd->gain_data);
249+
mod_free(mod, dd->gain_data);
248250
e_zephyr_free:
249251
dai_common_free(dd);
250252
free_dd:
251-
rfree(dd);
253+
mod_free(mod, dd);
252254
return ret;
253255
}
254256

@@ -374,14 +376,16 @@ __cold int copier_dai_create(struct comp_dev *dev, struct copier_data *cd,
374376
return 0;
375377
}
376378

377-
__cold void copier_dai_free(struct copier_data *cd)
379+
__cold void copier_dai_free(struct processing_module *mod)
378380
{
381+
struct copier_data *cd = module_get_private_data(mod);
382+
379383
assert_can_be_cold();
380384

381385
for (int i = 0; i < cd->endpoint_num; i++) {
382386
dai_common_free(cd->dd[i]);
383-
rfree(cd->dd[i]->gain_data);
384-
rfree(cd->dd[i]);
387+
mod_free(mod, cd->dd[i]->gain_data);
388+
mod_free(mod, cd->dd[i]);
385389
}
386390
/* only dai have multi endpoint case */
387391
if (cd->multi_endpoint_buffer)

src/audio/copier/copier_host.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ __cold static int add_to_fpi_sync_group(struct comp_dev *parent_dev,
5050
struct ipc4_copier_sync_group *sync_group)
5151
{
5252
struct fpi_sync_group *group = find_group_by_id(sync_group->group_id);
53+
struct processing_module *mod = comp_mod(parent_dev);
5354

5455
assert_can_be_cold();
5556

@@ -62,11 +63,12 @@ __cold static int add_to_fpi_sync_group(struct comp_dev *parent_dev,
6263

6364
group->ref_count++;
6465
} else {
65-
group = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*group));
66+
group = mod_alloc_ext(mod, SOF_MEM_FLAG_COHERENT, sizeof(*group), 0);
6667
if (!group) {
6768
comp_err(parent_dev, "Failed to alloc memory for new group");
6869
return -ENOMEM;
6970
}
71+
memset(group, 0, sizeof(*group));
7072

7173
group->id = sync_group->group_id;
7274
group->period = sync_group->fpi_update_period_usec;
@@ -81,9 +83,10 @@ __cold static int add_to_fpi_sync_group(struct comp_dev *parent_dev,
8183
return 0;
8284
}
8385

84-
__cold static void delete_from_fpi_sync_group(struct host_data *hd)
86+
__cold static void delete_from_fpi_sync_group(struct processing_module *mod)
8587
{
86-
struct fpi_sync_group *group = find_group_by_id(hd->group_id);
88+
struct copier_data *cd = module_get_private_data(mod);
89+
struct fpi_sync_group *group = find_group_by_id(cd->hd->group_id);
8790

8891
assert_can_be_cold();
8992

@@ -265,7 +268,7 @@ __cold void copier_host_free(struct processing_module *mod)
265268

266269
#if CONFIG_HOST_DMA_STREAM_SYNCHRONIZATION
267270
if (cd->hd->is_grouped)
268-
delete_from_fpi_sync_group(cd->hd);
271+
delete_from_fpi_sync_group(mod);
269272
#endif
270273
host_common_free(cd->hd);
271274
mod_free(mod, cd->hd);

src/audio/copier/dai_copier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int copier_dai_create(struct comp_dev *dev, struct copier_data *cd,
7979
const struct ipc4_copier_module_cfg *copier,
8080
struct pipeline *pipeline);
8181

82-
void copier_dai_free(struct copier_data *cd);
82+
void copier_dai_free(struct processing_module *mod);
8383

8484
int copier_dai_prepare(struct comp_dev *dev, struct copier_data *cd);
8585

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,
202202
*/
203203
static inline void *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignment)
204204
{
205-
return mod_alloc_ext(mod, 0, size, alignment);
205+
return mod_alloc_ext(mod, SOF_MEM_FLAG_USER, size, alignment);
206206
}
207207

208208
static inline void *mod_balloc(struct processing_module *mod, size_t size)

0 commit comments

Comments
 (0)