2525#include <sof/ut.h>
2626#include <sof/trace/trace.h>
2727#include <sof/debug/telemetry/performance_monitor.h>
28+ #include <sof/schedule/ll_schedule_domain.h> /* zephyr_ll_user_heap() */
2829#include <ipc/stream.h>
2930#include <ipc/topology.h>
3031#include <user/trace.h>
@@ -610,7 +611,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev,
610611 elem_array = & hd -> local .elem_array ;
611612
612613 /* config buffer will be used as proxy */
613- err = dma_sg_alloc (NULL , & hd -> config .elem_array , SOF_MEM_FLAG_USER ,
614+ err = dma_sg_alloc (hd -> alloc_ctx . heap , & hd -> config .elem_array , SOF_MEM_FLAG_USER ,
614615 dir , 1 , 0 , 0 , 0 );
615616 if (err < 0 ) {
616617 comp_err (dev , "dma_sg_alloc() failed" );
@@ -620,7 +621,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev,
620621 elem_array = & hd -> config .elem_array ;
621622 }
622623
623- err = dma_sg_alloc (NULL , elem_array , SOF_MEM_FLAG_USER , dir , buffer_count ,
624+ err = dma_sg_alloc (hd -> alloc_ctx . heap , elem_array , SOF_MEM_FLAG_USER , dir , buffer_count ,
624625 buffer_bytes ,
625626 (uintptr_t )audio_stream_get_addr (& hd -> dma_buffer -> stream ), 0 );
626627 if (err < 0 ) {
@@ -729,6 +730,15 @@ __cold int host_common_new(struct host_data *hd, struct comp_dev *dev,
729730 hd -> chan_index = - EINVAL ;
730731 hd -> copy_type = COMP_COPY_NORMAL ;
731732
733+ #ifdef CONFIG_SOF_USERSPACE_LL
734+ /*
735+ * copier_host_create() uses mod_zalloc() to allocate
736+ * the 'hd' host data object and does not set hd->alloc_ctx.
737+ * If LL is run in user-space, assign the 'heap' here.
738+ */
739+ hd -> alloc_ctx .heap = zephyr_ll_user_heap ();
740+ #endif
741+
732742 return 0 ;
733743}
734744
@@ -750,10 +760,12 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv,
750760 return NULL ;
751761 dev -> ipc_config = * config ;
752762
753- hd = rzalloc ( SOF_MEM_FLAG_USER , sizeof (* hd ));
763+ hd = sof_heap_alloc ( NULL , SOF_MEM_FLAG_USER , sizeof (* hd ), 0 );
754764 if (!hd )
755765 goto e_data ;
756766
767+ memset (hd , 0 , sizeof (* hd ));
768+
757769 hd -> nobytes_last_logged = k_uptime_get ();
758770 comp_set_drvdata (dev , hd );
759771
@@ -766,7 +778,7 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv,
766778 return dev ;
767779
768780e_dev :
769- rfree ( hd );
781+ sof_heap_free ( hd -> alloc_ctx . heap , hd );
770782e_data :
771783 comp_free_device (dev );
772784 return NULL ;
@@ -794,7 +806,7 @@ __cold void host_common_free(struct host_data *hd)
794806 sof_dma_put (hd -> dma );
795807
796808 ipc_msg_free (hd -> msg );
797- dma_sg_free (NULL , & hd -> config .elem_array );
809+ dma_sg_free (hd -> alloc_ctx . heap , & hd -> config .elem_array );
798810}
799811
800812__cold static void host_free (struct comp_dev * dev )
@@ -805,7 +817,7 @@ __cold static void host_free(struct comp_dev *dev)
805817
806818 comp_dbg (dev , "entry" );
807819 host_common_free (hd );
808- rfree ( hd );
820+ sof_heap_free ( hd -> alloc_ctx . heap , hd );
809821 comp_free_device (dev );
810822}
811823
@@ -963,7 +975,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
963975 }
964976 } else {
965977 /* allocate not shared buffer */
966- hd -> dma_buffer = buffer_alloc_range (NULL , buffer_size_preferred , buffer_size ,
978+ hd -> dma_buffer = buffer_alloc_range (& hd -> alloc_ctx , buffer_size_preferred , buffer_size ,
967979 SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA ,
968980 addr_align , BUFFER_USAGE_NOT_SHARED );
969981 if (!hd -> dma_buffer ) {
@@ -1020,15 +1032,17 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
10201032
10211033 memset (dma_cfg , 0 , sizeof (* dma_cfg ));
10221034
1023- dma_block_cfg = rzalloc ( SOF_MEM_FLAG_USER ,
1024- sizeof (* dma_block_cfg ));
1035+ dma_block_cfg = sof_heap_alloc ( hd -> alloc_ctx . heap , SOF_MEM_FLAG_USER ,
1036+ sizeof (* dma_block_cfg ), 0 );
10251037
10261038 if (!dma_block_cfg ) {
10271039 comp_err (dev , "dma_block_config allocation failed" );
10281040 err = - ENOMEM ;
10291041 goto err_release_channel ;
10301042 }
10311043
1044+ memset (dma_block_cfg , 0 , sizeof (* dma_block_cfg ));
1045+
10321046 dma_cfg -> block_count = 1 ;
10331047 dma_cfg -> source_data_size = config -> src_width ;
10341048 dma_cfg -> dest_data_size = config -> dest_width ;
@@ -1110,7 +1124,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
11101124
11111125err_free_block_cfg :
11121126 dma_cfg -> head_block = NULL ;
1113- rfree ( dma_block_cfg );
1127+ sof_heap_free ( hd -> alloc_ctx . heap , dma_block_cfg );
11141128err_release_channel :
11151129 sof_dma_release_channel (hd -> dma , hd -> chan_index );
11161130 hd -> chan_index = - EINVAL ;
@@ -1178,9 +1192,9 @@ void host_common_reset(struct host_data *hd, uint16_t state)
11781192 }
11791193
11801194 /* free all DMA elements */
1181- dma_sg_free (NULL , & hd -> host .elem_array );
1182- dma_sg_free (NULL , & hd -> local .elem_array );
1183- dma_sg_free (NULL , & hd -> config .elem_array );
1195+ dma_sg_free (hd -> alloc_ctx . heap , & hd -> host .elem_array );
1196+ dma_sg_free (hd -> alloc_ctx . heap , & hd -> local .elem_array );
1197+ dma_sg_free (hd -> alloc_ctx . heap , & hd -> config .elem_array );
11841198
11851199 /* free DMA buffer */
11861200 if (hd -> dma_buffer ) {
@@ -1190,7 +1204,7 @@ void host_common_reset(struct host_data *hd, uint16_t state)
11901204
11911205 /* free DMA block configuration */
11921206 if (hd -> z_config .head_block )
1193- rfree ( hd -> z_config .head_block );
1207+ sof_heap_free ( hd -> alloc_ctx . heap , hd -> z_config .head_block );
11941208
11951209 /* reset buffer pointers */
11961210 hd -> local_pos = 0 ;
0 commit comments