1717#include <rtos/alloc.h>
1818#include <rtos/cache.h>
1919#include <sof/lib/vregion.h>
20+ #include <sof/ctx_alloc.h>
2021#include <sof/list.h>
2122#include <sof/schedule/dp_schedule.h>
2223#include <rtos/spinlock.h>
@@ -158,10 +159,7 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)
158159
159160#ifdef CONFIG_SOF_USERSPACE_LL
160161 assert (alloc );
161- if (alloc -> vreg )
162- vregion_free (alloc -> vreg , buffer -> stream .addr );
163- else
164- sof_heap_free (alloc -> heap , buffer -> stream .addr );
162+ sof_ctx_free (alloc , buffer -> stream .addr );
165163#else
166164 rfree (buffer -> stream .addr );
167165#endif
@@ -214,12 +212,7 @@ static struct comp_buffer *buffer_alloc_struct(struct mod_alloc_ctx *alloc,
214212 if (is_shared )
215213 flags |= SOF_MEM_FLAG_COHERENT ;
216214
217- if (!alloc || !alloc -> vreg )
218- buffer = sof_heap_alloc (alloc ? alloc -> heap : NULL , flags , sizeof (* buffer ), 0 );
219- else if (is_shared )
220- buffer = vregion_alloc_coherent (alloc -> vreg , VREGION_MEM_TYPE_INTERIM , sizeof (* buffer ));
221- else
222- buffer = vregion_alloc (alloc -> vreg , VREGION_MEM_TYPE_INTERIM , sizeof (* buffer ));
215+ buffer = sof_ctx_alloc (alloc , flags , sizeof (* buffer ), 0 );
223216 if (!buffer ) {
224217 tr_err (& buffer_tr , "could not alloc structure" );
225218 return NULL ;
@@ -265,10 +258,7 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
265258
266259#ifdef CONFIG_SOF_USERSPACE_LL
267260 assert (alloc );
268- if (alloc -> vreg )
269- stream_addr = vregion_alloc_align (alloc -> vreg , VREGION_MEM_TYPE_INTERIM , size , align );
270- else
271- stream_addr = sof_heap_alloc (alloc -> heap , flags , size , align );
261+ stream_addr = sof_ctx_alloc (alloc , flags , size , align );
272262#else
273263 stream_addr = rballoc_align (flags , size , align );
274264#endif
@@ -283,10 +273,7 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
283273 tr_err (& buffer_tr , "could not alloc buffer structure" );
284274#ifdef CONFIG_SOF_USERSPACE_LL
285275 assert (alloc );
286- if (alloc -> vreg )
287- vregion_free (alloc -> vreg , stream_addr );
288- else
289- sof_heap_free (alloc -> heap , stream_addr );
276+ sof_ctx_free (alloc , stream_addr );
290277#else
291278 rfree (stream_addr );
292279#endif
@@ -319,10 +306,7 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
319306 for (size = preferred_size ; size >= minimum_size ; size -= minimum_size ) {
320307#ifdef CONFIG_SOF_USERSPACE_LL
321308 assert (alloc );
322- if (alloc -> vreg )
323- stream_addr = vregion_alloc_align (alloc -> vreg , VREGION_MEM_TYPE_INTERIM , size , align );
324- else
325- stream_addr = sof_heap_alloc (alloc -> heap , flags , size , align );
309+ stream_addr = sof_ctx_alloc (alloc , flags , size , align );
326310#else
327311 stream_addr = rballoc_align (flags , size , align );
328312#endif
@@ -343,10 +327,7 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
343327 tr_err (& buffer_tr , "could not alloc buffer structure" );
344328#ifdef CONFIG_SOF_USERSPACE_LL
345329 assert (alloc );
346- if (alloc -> vreg )
347- vregion_free (alloc -> vreg , stream_addr );
348- else
349- sof_heap_free (alloc -> heap , stream_addr );
330+ sof_ctx_free (alloc , stream_addr );
350331#else
351332 rfree (stream_addr );
352333#endif
@@ -387,10 +368,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
387368
388369#ifdef CONFIG_SOF_USERSPACE_LL
389370 assert (alloc );
390- if (alloc -> vreg )
391- new_ptr = vregion_alloc_align (alloc -> vreg , VREGION_MEM_TYPE_INTERIM , size , alignment );
392- else
393- new_ptr = sof_heap_alloc (alloc -> heap , buffer -> flags , size , alignment );
371+ new_ptr = sof_ctx_alloc (alloc , buffer -> flags , size , alignment );
394372#else
395373 new_ptr = rballoc_align (buffer -> flags , size , alignment );
396374#endif
@@ -406,10 +384,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
406384 if (new_ptr ) {
407385#ifdef CONFIG_SOF_USERSPACE_LL
408386 assert (alloc );
409- if (alloc -> vreg )
410- vregion_free (alloc -> vreg , audio_stream_get_addr (& buffer -> stream ));
411- else
412- sof_heap_free (alloc -> heap , audio_stream_get_addr (& buffer -> stream ));
387+ sof_ctx_free (alloc , audio_stream_get_addr (& buffer -> stream ));
413388#else
414389 rfree (audio_stream_get_addr (& buffer -> stream ));
415390#endif
@@ -451,10 +426,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
451426 new_size -= minimum_size ) {
452427#ifdef CONFIG_SOF_USERSPACE_LL
453428 assert (alloc );
454- if (alloc -> vreg )
455- new_ptr = vregion_alloc_align (alloc -> vreg , VREGION_MEM_TYPE_INTERIM , new_size , alignment );
456- else
457- new_ptr = sof_heap_alloc (alloc -> heap , buffer -> flags , new_size , alignment );
429+ new_ptr = sof_ctx_alloc (alloc , buffer -> flags , new_size , alignment );
458430#else
459431 new_ptr = rballoc_align (buffer -> flags , new_size , alignment );
460432#endif
@@ -473,10 +445,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
473445 if (new_ptr ) {
474446#ifdef CONFIG_SOF_USERSPACE_LL
475447 assert (alloc );
476- if (alloc -> vreg )
477- vregion_free (alloc -> vreg , audio_stream_get_addr (& buffer -> stream ));
478- else
479- sof_heap_free (alloc -> heap , audio_stream_get_addr (& buffer -> stream ));
448+ sof_ctx_free (alloc , audio_stream_get_addr (& buffer -> stream ));
480449#else
481450 rfree (audio_stream_get_addr (& buffer -> stream ));
482451#endif
0 commit comments