@@ -57,8 +57,8 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
5757#define PAGE_SZ HOST_PAGE_SIZE
5858#endif
5959
60- static struct dp_heap_user * module_adapter_dp_heap_new (const struct comp_ipc_config * config ,
61- size_t * heap_size )
60+ static struct k_heap * module_adapter_dp_heap_new (const struct comp_ipc_config * config ,
61+ size_t * heap_size )
6262{
6363 /* src-lite with 8 channels has been seen allocating 14k in one go */
6464 /* FIXME: the size will be derived from configuration */
@@ -71,9 +71,8 @@ static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_con
7171 if (!mod_heap_mem )
7272 return NULL ;
7373
74- struct dp_heap_user * mod_heap_user = (struct dp_heap_user * )mod_heap_mem ;
75- struct k_heap * mod_heap = & mod_heap_user -> heap ;
76- const size_t heap_prefix_size = ALIGN_UP (sizeof (* mod_heap_user ), 4 );
74+ struct k_heap * mod_heap = (struct k_heap * )mod_heap_mem ;
75+ const size_t heap_prefix_size = ALIGN_UP (sizeof (* mod_heap ), 4 );
7776 void * mod_heap_buf = mod_heap_mem + heap_prefix_size ;
7877
7978 * heap_size = buf_size - heap_prefix_size ;
@@ -83,7 +82,7 @@ static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_con
8382 mod_heap -> heap .init_bytes = * heap_size ;
8483#endif
8584
86- return mod_heap_user ;
85+ return mod_heap ;
8786}
8887
8988static struct processing_module * module_adapter_mem_alloc (const struct comp_driver * drv ,
@@ -99,20 +98,17 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
9998 */
10099 uint32_t flags = config -> proc_domain == COMP_PROCESSING_DOMAIN_DP ?
101100 SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT : SOF_MEM_FLAG_USER ;
102- struct dp_heap_user * mod_heap_user ;
103101 size_t heap_size ;
104102
105103 if (config -> proc_domain == COMP_PROCESSING_DOMAIN_DP && IS_ENABLED (CONFIG_USERSPACE ) &&
106104 !IS_ENABLED (CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP )) {
107- mod_heap_user = module_adapter_dp_heap_new (config , & heap_size );
108- if (!mod_heap_user ) {
105+ mod_heap = module_adapter_dp_heap_new (config , & heap_size );
106+ if (!mod_heap ) {
109107 comp_cl_err (drv , "Failed to allocate DP module heap" );
110108 return NULL ;
111109 }
112- mod_heap = & mod_heap_user -> heap ;
113110 } else {
114111 mod_heap = drv -> user_heap ;
115- mod_heap_user = NULL ;
116112 heap_size = 0 ;
117113 }
118114
@@ -123,9 +119,14 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
123119 goto emod ;
124120 }
125121
122+ struct mod_alloc_ctx * alloc = rmalloc (0 , sizeof (* alloc ));
123+
124+ if (!alloc )
125+ goto ealloc ;
126+
126127 memset (mod , 0 , sizeof (* mod ));
127- mod -> priv .resources .alloc . heap = mod_heap ;
128- mod -> priv . resources . alloc . client = mod_heap_user ;
128+ mod -> priv .resources .alloc = alloc ;
129+ alloc -> heap = mod_heap ;
129130 mod_resource_init (mod );
130131
131132 /*
@@ -138,7 +139,7 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
138139
139140 if (!dev ) {
140141 comp_cl_err (drv , "failed to allocate memory for comp_dev" );
141- goto err ;
142+ goto edev ;
142143 }
143144
144145 memset (dev , 0 , sizeof (* dev ));
@@ -147,22 +148,25 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
147148 mod -> dev = dev ;
148149 dev -> mod = mod ;
149150
150- if (mod_heap_user )
151- mod_heap_user -> client_count ++ ;
151+ if (config -> proc_domain == COMP_PROCESSING_DOMAIN_DP )
152+ alloc -> client_count ++ ;
152153
153154 return mod ;
154155
155- err :
156+ edev :
157+ rfree (alloc );
158+ ealloc :
156159 sof_heap_free (mod_heap , mod );
157160emod :
158- rfree (mod_heap_user );
161+ rfree (mod_heap );
159162
160163 return NULL ;
161164}
162165
163166static void module_adapter_mem_free (struct processing_module * mod )
164167{
165- struct k_heap * mod_heap = mod -> priv .resources .alloc .heap ;
168+ struct mod_alloc_ctx * alloc = mod -> priv .resources .alloc ;
169+ struct k_heap * mod_heap = alloc -> heap ;
166170 unsigned int domain = mod -> dev -> ipc_config .proc_domain ;
167171
168172 /*
@@ -175,11 +179,10 @@ static void module_adapter_mem_free(struct processing_module *mod)
175179 sof_heap_free (mod_heap , mod -> dev );
176180 sof_heap_free (mod_heap , mod );
177181 if (domain == COMP_PROCESSING_DOMAIN_DP ) {
178- struct dp_heap_user * mod_heap_user = container_of (mod_heap , struct dp_heap_user ,
179- heap );
180-
181- if (mod_heap && !-- mod_heap_user -> client_count )
182- rfree (mod_heap_user );
182+ if (!IS_ENABLED (CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP ))
183+ rfree (mod_heap );
184+ if (!-- alloc -> client_count )
185+ rfree (alloc );
183186 }
184187}
185188
@@ -612,7 +615,7 @@ int module_adapter_prepare(struct comp_dev *dev)
612615 if (list_is_empty (& mod -> raw_data_buffers_list )) {
613616 for (i = 0 ; i < mod -> num_of_sinks ; i ++ ) {
614617 /* allocate not shared buffer */
615- struct comp_buffer * buffer = buffer_alloc (& md -> resources .alloc ,
618+ struct comp_buffer * buffer = buffer_alloc (md -> resources .alloc ,
616619 buff_size , memory_flags ,
617620 PLATFORM_DCACHE_ALIGN ,
618621 BUFFER_USAGE_NOT_SHARED );
@@ -624,9 +627,9 @@ int module_adapter_prepare(struct comp_dev *dev)
624627 goto free ;
625628 }
626629
627- if (md -> resources .alloc . heap &&
628- md -> resources .alloc . heap != dev -> drv -> user_heap )
629- md -> resources .alloc . client -> client_count ++ ;
630+ if (md -> resources .alloc -> heap &&
631+ md -> resources .alloc -> heap != dev -> drv -> user_heap )
632+ md -> resources .alloc -> client_count ++ ;
630633
631634 irq_local_disable (flags );
632635 list_item_prepend (& buffer -> buffers_list , & mod -> raw_data_buffers_list );
0 commit comments