@@ -74,28 +74,47 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
7474 return NULL ;
7575 }
7676
77- dev = comp_alloc (drv , sizeof (* dev ));
78- if (!dev ) {
79- comp_cl_err (drv , "module_adapter_new(), failed to allocate memory for comp_dev" );
77+ #define HEAP_SIZE (8 * 1024)
78+ int flags = config -> proc_domain == COMP_PROCESSING_DOMAIN_DP ?
79+ SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT : SOF_MEM_FLAG_USER ;
80+ uint8_t * mod_heap_mem = rballoc_align (flags , HEAP_SIZE , 4096 );
81+
82+ if (!mod_heap_mem )
8083 return NULL ;
81- }
82- dev -> ipc_config = * config ;
84+
85+ struct k_heap * mod_heap = (struct k_heap * )mod_heap_mem ;
86+ const size_t heap_pref_size = ALIGN_UP (sizeof (* mod_heap ), 16 );
87+ void * mod_heap_buf = mod_heap_mem + heap_pref_size ;
88+
89+ k_heap_init (mod_heap , mod_heap_buf , HEAP_SIZE - heap_pref_size );
8390
8491 /* allocate module information.
8592 * for DP shared modules this struct must be accessible from all cores
8693 * Unfortunately at this point there's no information of components the module
8794 * will be bound to. So we need to allocate shared memory for each DP module
8895 * To be removed when pipeline 2.0 is ready
8996 */
90- int flags = config -> proc_domain == COMP_PROCESSING_DOMAIN_DP ?
91- SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT : SOF_MEM_FLAG_USER ;
9297
93- mod = rzalloc ( flags , sizeof (* mod ));
98+ mod = k_heap_alloc ( mod_heap , sizeof (* mod ), K_NO_WAIT );
9499 if (!mod ) {
95- comp_err (dev , "module_adapter_new(), failed to allocate memory for module" );
100+ comp_cl_err (drv , "module_adapter_new(), failed to allocate memory for module" );
101+ goto emod ;
102+ }
103+
104+ memset (mod , 0 , sizeof (* mod ));
105+ mod -> priv .resources .heap = mod_heap ;
106+ mod -> priv .resources .heap_mem = mod_heap_mem ;
107+
108+ dev = k_heap_alloc (mod_heap , sizeof (* dev ), K_NO_WAIT );
109+ if (!dev ) {
110+ comp_cl_err (drv , "module_adapter_new(), failed to allocate memory for comp_dev" );
96111 goto err ;
97112 }
98113
114+ memset (dev , 0 , sizeof (* dev ));
115+ comp_init (drv , dev , sizeof (* dev ));
116+ dev -> ipc_config = * config ;
117+
99118 dst = & mod -> priv .cfg ;
100119
101120 module_set_private_data (mod , mod_priv );
@@ -159,13 +178,17 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
159178
160179 comp_dbg (dev , "module_adapter_new() done" );
161180 return dev ;
181+
162182err :
163183#if CONFIG_IPC_MAJOR_4
164184 if (mod )
165185 rfree (mod -> priv .cfg .input_pins );
166186#endif
167- rfree (mod );
168- rfree (dev );
187+ k_heap_free (mod_heap , dev );
188+ k_heap_free (mod_heap , mod );
189+ emod :
190+ rfree (mod_heap_mem );
191+
169192 return NULL ;
170193}
171194EXPORT_SYMBOL (module_adapter_new );
@@ -1284,8 +1307,12 @@ void module_adapter_free(struct comp_dev *dev)
12841307 rfree (mod -> priv .cfg .input_pins );
12851308#endif
12861309
1287- rfree (mod );
1288- rfree (dev );
1310+ struct k_heap * mod_heap = mod -> priv .resources .heap ;
1311+ void * mem = mod -> priv .resources .heap_mem ;
1312+
1313+ k_heap_free (mod_heap , mod );
1314+ k_heap_free (mod_heap , dev );
1315+ rfree (mem );
12891316}
12901317EXPORT_SYMBOL (module_adapter_free );
12911318
0 commit comments