@@ -156,12 +156,12 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)
156156
157157 struct mod_alloc_ctx * alloc = buffer -> audio_buffer .alloc ;
158158
159- #ifdef CONFIG_SOF_USERSPACE_LL
160- assert ( alloc );
161- sof_ctx_free (alloc , buffer -> stream . addr );
162- #else
163- rfree ( buffer -> stream . addr );
164- #endif
159+ assert (! IS_ENABLED ( CONFIG_SOF_USERSPACE_LL ) || alloc );
160+
161+ if (alloc )
162+ sof_ctx_free ( alloc , buffer -> stream . addr );
163+ else
164+ sof_heap_free ( sof_sys_user_heap_get (), buffer -> stream . addr );
165165
166166 if (alloc && alloc -> vreg ) {
167167 vregion_free (alloc -> vreg , buffer );
@@ -255,12 +255,13 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
255255 return NULL ;
256256 }
257257
258- #ifdef CONFIG_SOF_USERSPACE_LL
259- assert (alloc );
260- stream_addr = sof_ctx_alloc (alloc , flags , size , align );
261- #else
262- stream_addr = rballoc_align (flags , size , align );
263- #endif
258+ assert (!IS_ENABLED (CONFIG_SOF_USERSPACE_LL ) || alloc );
259+
260+ if (alloc )
261+ stream_addr = sof_ctx_alloc (alloc , flags , size , align );
262+ else
263+ stream_addr = sof_heap_alloc (sof_sys_user_heap_get (), flags , size , align );
264+
264265 if (!stream_addr ) {
265266 tr_err (& buffer_tr , "could not alloc size = %zu bytes of flags = 0x%x" ,
266267 size , flags );
@@ -270,12 +271,11 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
270271 buffer = buffer_alloc_struct (alloc , stream_addr , size , flags , is_shared );
271272 if (!buffer ) {
272273 tr_err (& buffer_tr , "could not alloc buffer structure" );
273- #ifdef CONFIG_SOF_USERSPACE_LL
274- assert (alloc );
275- sof_ctx_free (alloc , stream_addr );
276- #else
277- rfree (stream_addr );
278- #endif
274+
275+ if (alloc )
276+ sof_ctx_free (alloc , stream_addr );
277+ else
278+ sof_heap_free (sof_sys_user_heap_get (), stream_addr );
279279 }
280280
281281 return buffer ;
@@ -302,13 +302,14 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
302302 if (preferred_size % minimum_size )
303303 preferred_size += minimum_size - preferred_size % minimum_size ;
304304
305+ assert (!IS_ENABLED (CONFIG_SOF_USERSPACE_LL ) || alloc );
306+
305307 for (size = preferred_size ; size >= minimum_size ; size -= minimum_size ) {
306- #ifdef CONFIG_SOF_USERSPACE_LL
307- assert (alloc );
308- stream_addr = sof_ctx_alloc (alloc , flags , size , align );
309- #else
310- stream_addr = rballoc_align (flags , size , align );
311- #endif
308+ if (alloc )
309+ stream_addr = sof_ctx_alloc (alloc , flags , size , align );
310+ else
311+ stream_addr = sof_heap_alloc (sof_sys_user_heap_get (), flags , size , align );
312+
312313 if (stream_addr )
313314 break ;
314315 }
@@ -324,12 +325,11 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
324325 buffer = buffer_alloc_struct (alloc , stream_addr , size , flags , is_shared );
325326 if (!buffer ) {
326327 tr_err (& buffer_tr , "could not alloc buffer structure" );
327- #ifdef CONFIG_SOF_USERSPACE_LL
328- assert (alloc );
329- sof_ctx_free (alloc , stream_addr );
330- #else
331- rfree (stream_addr );
332- #endif
328+
329+ if (alloc )
330+ sof_ctx_free (alloc , stream_addr );
331+ else
332+ sof_heap_free (sof_sys_user_heap_get (), stream_addr );
333333 }
334334
335335 return buffer ;
@@ -350,9 +350,7 @@ void buffer_zero(struct comp_buffer *buffer)
350350int buffer_set_size (struct comp_buffer * buffer , uint32_t size , uint32_t alignment )
351351{
352352 void * new_ptr = NULL ;
353- #ifdef CONFIG_SOF_USERSPACE_LL
354353 struct mod_alloc_ctx * alloc = buffer -> audio_buffer .alloc ;
355- #endif
356354
357355 CORE_CHECK_STRUCT (& buffer -> audio_buffer );
358356
@@ -365,12 +363,12 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
365363 if (size == audio_stream_get_size (& buffer -> stream ))
366364 return 0 ;
367365
368- #ifdef CONFIG_SOF_USERSPACE_LL
369- assert ( alloc );
370- new_ptr = sof_ctx_alloc (alloc , buffer -> flags , size , alignment );
371- #else
372- new_ptr = rballoc_align ( buffer -> flags , size , alignment );
373- #endif
366+ assert (! IS_ENABLED ( CONFIG_SOF_USERSPACE_LL ) || alloc );
367+
368+ if (alloc )
369+ new_ptr = sof_ctx_alloc ( alloc , buffer -> flags , size , alignment );
370+ else
371+ new_ptr = sof_heap_alloc ( sof_sys_user_heap_get (), buffer -> flags , size , alignment );
374372
375373 /* we couldn't allocate bigger chunk */
376374 if (!new_ptr && size > audio_stream_get_size (& buffer -> stream )) {
@@ -381,12 +379,11 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
381379
382380 /* use bigger chunk, else just use the old chunk but set smaller */
383381 if (new_ptr ) {
384- #ifdef CONFIG_SOF_USERSPACE_LL
385- assert (alloc );
386- sof_ctx_free (alloc , audio_stream_get_addr (& buffer -> stream ));
387- #else
388- rfree (audio_stream_get_addr (& buffer -> stream ));
389- #endif
382+ if (alloc )
383+ sof_ctx_free (alloc , audio_stream_get_addr (& buffer -> stream ));
384+ else
385+ sof_heap_free (sof_sys_user_heap_get (), audio_stream_get_addr (& buffer -> stream ));
386+
390387 audio_stream_set_addr (& buffer -> stream , new_ptr );
391388 }
392389
@@ -401,9 +398,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
401398 const size_t actual_size = audio_stream_get_size (& buffer -> stream );
402399 void * new_ptr = NULL ;
403400 size_t new_size ;
404- #ifdef CONFIG_SOF_USERSPACE_LL
405401 struct mod_alloc_ctx * alloc = buffer -> audio_buffer .alloc ;
406- #endif
407402
408403 CORE_CHECK_STRUCT (& buffer -> audio_buffer );
409404
@@ -421,14 +416,15 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
421416 if (preferred_size == actual_size )
422417 return 0 ;
423418
419+ assert (!IS_ENABLED (CONFIG_SOF_USERSPACE_LL ) || alloc );
420+
424421 for (new_size = preferred_size ; new_size >= minimum_size ;
425422 new_size -= minimum_size ) {
426- #ifdef CONFIG_SOF_USERSPACE_LL
427- assert (alloc );
428- new_ptr = sof_ctx_alloc (alloc , buffer -> flags , new_size , alignment );
429- #else
430- new_ptr = rballoc_align (buffer -> flags , new_size , alignment );
431- #endif
423+ if (alloc )
424+ new_ptr = sof_ctx_alloc (alloc , buffer -> flags , new_size , alignment );
425+ else
426+ new_ptr = sof_heap_alloc (sof_sys_user_heap_get (), buffer -> flags , new_size , alignment );
427+
432428 if (new_ptr )
433429 break ;
434430 }
@@ -442,12 +438,11 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
442438
443439 /* use bigger chunk, else just use the old chunk but set smaller */
444440 if (new_ptr ) {
445- #ifdef CONFIG_SOF_USERSPACE_LL
446- assert (alloc );
447- sof_ctx_free (alloc , audio_stream_get_addr (& buffer -> stream ));
448- #else
449- rfree (audio_stream_get_addr (& buffer -> stream ));
450- #endif
441+ if (alloc )
442+ sof_ctx_free (alloc , audio_stream_get_addr (& buffer -> stream ));
443+ else
444+ sof_heap_free (sof_sys_user_heap_get (), audio_stream_get_addr (& buffer -> stream ));
445+
451446 audio_stream_set_addr (& buffer -> stream , new_ptr );
452447 }
453448
0 commit comments