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
@@ -216,10 +214,8 @@ static struct comp_buffer *buffer_alloc_struct(struct mod_alloc_ctx *alloc,
216214
217215 if (!alloc || !alloc -> vreg )
218216 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 ));
221217 else
222- buffer = vregion_alloc (alloc -> vreg , VREGION_MEM_TYPE_INTERIM , sizeof (* buffer ));
218+ buffer = sof_ctx_alloc (alloc , flags , sizeof (* buffer ), 0 );
223219 if (!buffer ) {
224220 tr_err (& buffer_tr , "could not alloc structure" );
225221 return NULL ;
@@ -265,10 +261,7 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
265261
266262#ifdef CONFIG_SOF_USERSPACE_LL
267263 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 );
264+ stream_addr = sof_ctx_alloc (alloc , flags , size , align );
272265#else
273266 stream_addr = rballoc_align (flags , size , align );
274267#endif
@@ -283,10 +276,7 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
283276 tr_err (& buffer_tr , "could not alloc buffer structure" );
284277#ifdef CONFIG_SOF_USERSPACE_LL
285278 assert (alloc );
286- if (alloc -> vreg )
287- vregion_free (alloc -> vreg , stream_addr );
288- else
289- sof_heap_free (alloc -> heap , stream_addr );
279+ sof_ctx_free (alloc , stream_addr );
290280#else
291281 rfree (stream_addr );
292282#endif
@@ -319,10 +309,7 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
319309 for (size = preferred_size ; size >= minimum_size ; size -= minimum_size ) {
320310#ifdef CONFIG_SOF_USERSPACE_LL
321311 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 );
312+ stream_addr = sof_ctx_alloc (alloc , flags , size , align );
326313#else
327314 stream_addr = rballoc_align (flags , size , align );
328315#endif
@@ -343,10 +330,7 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
343330 tr_err (& buffer_tr , "could not alloc buffer structure" );
344331#ifdef CONFIG_SOF_USERSPACE_LL
345332 assert (alloc );
346- if (alloc -> vreg )
347- vregion_free (alloc -> vreg , stream_addr );
348- else
349- sof_heap_free (alloc -> heap , stream_addr );
333+ sof_ctx_free (alloc , stream_addr );
350334#else
351335 rfree (stream_addr );
352336#endif
@@ -387,10 +371,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
387371
388372#ifdef CONFIG_SOF_USERSPACE_LL
389373 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 );
374+ new_ptr = sof_ctx_alloc (alloc , buffer -> flags , size , alignment );
394375#else
395376 new_ptr = rballoc_align (buffer -> flags , size , alignment );
396377#endif
@@ -406,10 +387,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
406387 if (new_ptr ) {
407388#ifdef CONFIG_SOF_USERSPACE_LL
408389 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 ));
390+ sof_ctx_free (alloc , audio_stream_get_addr (& buffer -> stream ));
413391#else
414392 rfree (audio_stream_get_addr (& buffer -> stream ));
415393#endif
@@ -451,10 +429,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
451429 new_size -= minimum_size ) {
452430#ifdef CONFIG_SOF_USERSPACE_LL
453431 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 );
432+ new_ptr = sof_ctx_alloc (alloc , buffer -> flags , new_size , alignment );
458433#else
459434 new_ptr = rballoc_align (buffer -> flags , new_size , alignment );
460435#endif
@@ -473,10 +448,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
473448 if (new_ptr ) {
474449#ifdef CONFIG_SOF_USERSPACE_LL
475450 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 ));
451+ sof_ctx_free (alloc , audio_stream_get_addr (& buffer -> stream ));
480452#else
481453 rfree (audio_stream_get_addr (& buffer -> stream ));
482454#endif
0 commit comments