Skip to content

Commit 490b614

Browse files
Jyri Sarhakv2019i
authored andcommitted
modules: Drop alignment from mod_alloc() and introduce mod_alloc_align()
Drop alignment argument from mod_alloc() and introduce mod_alloc_align() and apply all the necessary changes to mod_alloc() calls. Also adds Doxygen documentation to mod_alloc_align, mod_alloc, mod_zalloc, mod_free, and mod_free_all. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 86a5460 commit 490b614

5 files changed

Lines changed: 58 additions & 14 deletions

File tree

src/audio/codec/dts/dts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void *dts_effect_allocate_codec_memory(void *mod_void, unsigned int lengt
2525

2626
comp_dbg(dev, "dts_effect_allocate_codec_memory() start");
2727

28-
pMem = mod_alloc(mod, (uint32_t)length, (uint32_t)alignment);
28+
pMem = mod_alloc_align(mod, (uint32_t)length, (uint32_t)alignment);
2929

3030
if (pMem == NULL)
3131
comp_err(dev,

src/audio/module_adapter/module/cadence.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static int init_memory_tables(struct processing_module *mod)
519519
goto err;
520520
}
521521
/* Allocate memory for this type, taking alignment into account */
522-
ptr = mod_alloc(mod, mem_size, mem_alignment);
522+
ptr = mod_alloc_align(mod, mem_size, mem_alignment);
523523
if (!ptr) {
524524
comp_err(dev, "init_memory_tables() error %x: failed to allocate memory for %d",
525525
ret, mem_type);
@@ -688,7 +688,7 @@ static int cadence_codec_prepare(struct processing_module *mod,
688688
return ret;
689689
}
690690

691-
cd->mem_tabs = mod_alloc(mod, mem_tabs_size, 4);
691+
cd->mem_tabs = mod_alloc(mod, mem_tabs_size);
692692
if (!cd->mem_tabs) {
693693
comp_err(dev, "cadence_codec_prepare() error: failed to allocate space for memtabs");
694694
return -ENOMEM;

src/audio/module_adapter/module/generic.c

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,16 @@ int module_init(struct processing_module *mod)
110110
return 0;
111111
}
112112

113-
void *mod_alloc(struct processing_module *mod, uint32_t size, uint32_t alignment)
113+
/**
114+
* Allocates aligned memory block for module.
115+
* @param mod Pointer to the module this memory block is allocatd for.
116+
* @param bytes Size in bytes.
117+
* @param alignment Alignment in bytes.
118+
* @return Pointer to the allocated memory or NULL if failed.
119+
*
120+
* The allocated memory is automatically freed when the module is unloaded.
121+
*/
122+
void *mod_alloc_align(struct processing_module *mod, uint32_t size, uint32_t alignment)
114123
{
115124
struct comp_dev *dev = mod->dev;
116125
struct module_memory *container;
@@ -147,11 +156,34 @@ void *mod_alloc(struct processing_module *mod, uint32_t size, uint32_t alignment
147156

148157
return ptr;
149158
}
159+
EXPORT_SYMBOL(mod_alloc_align);
160+
161+
/**
162+
* Allocates memory block for module.
163+
* @param mod Pointer to module this memory block is allocated for.
164+
* @param bytes Size in bytes.
165+
* @return Pointer to the allocated memory or NULL if failed.
166+
*
167+
* Like mod_alloc_align() but the alignment can not be specified. However,
168+
* rballoc() will always aligns the memory to PLATFORM_DCACHE_ALIGN.
169+
*/
170+
void *mod_alloc(struct processing_module *mod, uint32_t size)
171+
{
172+
return mod_alloc_align(mod, size, 0);
173+
}
150174
EXPORT_SYMBOL(mod_alloc);
151175

152-
void *mod_zalloc(struct processing_module *mod, uint32_t size, uint32_t alignment)
176+
/**
177+
* Allocates memory block for module and initializes it to zero.
178+
* @param mod Pointer to module this memory block is allocated for.
179+
* @param bytes Size in bytes.
180+
* @return Pointer to the allocated memory or NULL if failed.
181+
*
182+
* Like mod_alloc() but the allocated memory is initialized to zero.
183+
*/
184+
void *mod_zalloc(struct processing_module *mod, uint32_t size)
153185
{
154-
void *ret = mod_alloc(mod, size, alignment);
186+
void *ret = mod_alloc(mod, size);
155187

156188
if (ret)
157189
memset(ret, 0, size);
@@ -160,6 +192,11 @@ void *mod_zalloc(struct processing_module *mod, uint32_t size, uint32_t alignmen
160192
}
161193
EXPORT_SYMBOL(mod_zalloc);
162194

195+
/**
196+
* Frees the memory block removes it from module's book keeping.
197+
* @param mod Pointer to module this memory block was allocated for.
198+
* @param ptr Pointer to the memory block.
199+
*/
163200
int mod_free(struct processing_module *mod, void *ptr)
164201
{
165202
struct module_memory *mem;
@@ -357,6 +394,12 @@ int module_reset(struct processing_module *mod)
357394
return 0;
358395
}
359396

397+
/**
398+
* Frees all the memory allocated for this module
399+
* @param mod Pointer to module this memory block was allocated for.
400+
*
401+
* This function is called automatically when the module is unloaded.
402+
*/
360403
void mod_free_all(struct processing_module *mod)
361404
{
362405
struct module_memory *mem;

src/audio/module_adapter/module/waves/waves.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static int waves_effect_allocate(struct processing_module *mod)
200200
return -EINVAL;
201201
}
202202

203-
waves_codec->effect = (MaxxEffect_t *)mod_alloc(mod,
203+
waves_codec->effect = (MaxxEffect_t *)mod_alloc_align(mod,
204204
waves_codec->effect_size, 16);
205205

206206
if (!waves_codec->effect) {
@@ -376,15 +376,15 @@ static int waves_effect_buffers(struct processing_module *mod)
376376

377377
comp_dbg(dev, "waves_effect_buffers() start");
378378

379-
i_buffer = mod_alloc(mod, waves_codec->buffer_bytes, 16);
379+
i_buffer = mod_alloc_align(mod, waves_codec->buffer_bytes, 16);
380380
if (!i_buffer) {
381381
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for i_buffer",
382382
waves_codec->buffer_bytes);
383383
ret = -ENOMEM;
384384
goto err;
385385
}
386386

387-
o_buffer = mod_alloc(mod, waves_codec->buffer_bytes, 16);
387+
o_buffer = mod_alloc_align(mod, waves_codec->buffer_bytes, 16);
388388
if (!o_buffer) {
389389
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for o_buffer",
390390
waves_codec->buffer_bytes);
@@ -481,7 +481,7 @@ static int waves_effect_save_config_blob_to_cache(struct processing_module *mod,
481481
}
482482

483483
if (!waves_codec->config_blob) {
484-
waves_codec->config_blob = mod_alloc(mod, size, 16);
484+
waves_codec->config_blob = mod_alloc_align(mod, size, 16);
485485
if (!waves_codec->config_blob) {
486486
comp_err(dev,
487487
"waves_effect_save_config_blob_to_cache() failed to allocate %d bytes for config blob",
@@ -668,7 +668,7 @@ static int waves_codec_init(struct processing_module *mod)
668668

669669
comp_dbg(dev, "waves_codec_init() start");
670670

671-
waves_codec = mod_alloc(mod, sizeof(struct waves_codec_data), 16);
671+
waves_codec = mod_alloc_align(mod, sizeof(struct waves_codec_data), 16);
672672
if (!waves_codec) {
673673
comp_err(dev, "waves_codec_init() failed to allocate %d bytes for waves_codec_data",
674674
sizeof(struct waves_codec_data));
@@ -696,7 +696,7 @@ static int waves_codec_init(struct processing_module *mod)
696696
return -EINVAL;
697697
}
698698

699-
response = mod_alloc(mod, waves_codec->response_max_bytes, 16);
699+
response = mod_alloc_align(mod, waves_codec->response_max_bytes, 16);
700700
if (!response) {
701701
comp_err(dev, "waves_codec_init() failed to allocate %d bytes for response",
702702
waves_codec->response_max_bytes);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ struct module_processing_data {
153153
/*****************************************************************************/
154154
int module_load_config(struct comp_dev *dev, const void *cfg, size_t size);
155155
int module_init(struct processing_module *mod);
156-
void *mod_alloc(struct processing_module *mod, uint32_t size, uint32_t alignment);
157-
void *mod_zalloc(struct processing_module *mod, uint32_t size, uint32_t alignment);
156+
void *mod_alloc_align(struct processing_module *mod, uint32_t size, uint32_t alignment);
157+
void *mod_alloc(struct processing_module *mod, uint32_t size);
158+
void *mod_zalloc(struct processing_module *mod, uint32_t size);
158159
int mod_free(struct processing_module *mod, void *ptr);
159160
void mod_free_all(struct processing_module *mod);
160161
int module_prepare(struct processing_module *mod,

0 commit comments

Comments
 (0)