@@ -159,6 +159,71 @@ static void container_put(struct processing_module *mod, struct module_resource
159159 list_item_append (& container -> list , & res -> free_cont_list );
160160}
161161
162+ /**
163+ * Allocates aligned buffer memory block for module.
164+ * @param mod Pointer to the module this memory block is allocatd for.
165+ * @param bytes Size in bytes.
166+ * @param alignment Alignment in bytes.
167+ * @return Pointer to the allocated memory or NULL if failed.
168+ *
169+ * The allocated memory is automatically freed when the module is
170+ * unloaded. The back-end, rballoc(), always aligns the memory to
171+ * PLATFORM_DCACHE_ALIGN at the minimum.
172+ */
173+ void * mod_balloc_align (struct processing_module * mod , size_t size , size_t alignment )
174+ {
175+ struct module_resource * container = container_get (mod );
176+ struct module_resources * res = & mod -> priv .resources ;
177+ void * ptr ;
178+
179+ MEM_API_CHECK_THREAD (res );
180+ if (!container )
181+ return NULL ;
182+
183+ if (!size ) {
184+ comp_err (mod -> dev , "requested allocation of 0 bytes." );
185+ container_put (mod , container );
186+ return NULL ;
187+ }
188+
189+ /* Allocate buffer memory for module */
190+ ptr = rballoc_align (SOF_MEM_FLAG_USER , size , alignment );
191+
192+ if (!ptr ) {
193+ comp_err (mod -> dev , "Failed to alloc %zu bytes %zu alignment for comp %#x." ,
194+ size , alignment , dev_comp_id (mod -> dev ));
195+ container_put (mod , container );
196+ return NULL ;
197+ }
198+ /* Store reference to allocated memory */
199+ container -> ptr = ptr ;
200+ container -> size = size ;
201+ container -> type = MOD_RES_HEAP ;
202+ list_item_prepend (& container -> list , & res -> res_list );
203+
204+ res -> heap_usage += size ;
205+ if (res -> heap_usage > res -> heap_high_water_mark )
206+ res -> heap_high_water_mark = res -> heap_usage ;
207+
208+ return ptr ;
209+ }
210+ EXPORT_SYMBOL (mod_balloc_align );
211+
212+ /**
213+ * Allocates buffer memory block for module.
214+ * @param mod Pointer to module this memory block is allocated for.
215+ * @param bytes Size in bytes.
216+ * @return Pointer to the allocated memory or NULL if failed.
217+ *
218+ * Like mod_balloc_align() but the alignment can not be specified. However,
219+ * rballoc() always aligns the memory to PLATFORM_DCACHE_ALIGN.
220+ */
221+ void * mod_balloc (struct processing_module * mod , size_t size )
222+ {
223+ return mod_balloc_align (mod , size , 0 );
224+ }
225+ EXPORT_SYMBOL (mod_balloc );
226+
162227/**
163228 * Allocates aligned memory block for module.
164229 * @param mod Pointer to the module this memory block is allocatd for.
@@ -213,8 +278,7 @@ EXPORT_SYMBOL(mod_alloc_align);
213278 * @param bytes Size in bytes.
214279 * @return Pointer to the allocated memory or NULL if failed.
215280 *
216- * Like mod_alloc_align() but the alignment can not be specified. However,
217- * rballoc() will always aligns the memory to PLATFORM_DCACHE_ALIGN.
281+ * Like mod_alloc_align() but the alignment can not be specified.
218282 */
219283void * mod_alloc (struct processing_module * mod , size_t size )
220284{
0 commit comments