@@ -58,13 +58,49 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
5858#endif
5959
6060static struct dp_heap_user * module_adapter_dp_heap_new (const struct comp_ipc_config * config ,
61+ const struct module_ext_init_data * ext_init ,
6162 size_t * heap_size )
6263{
64+ const size_t heap_prefix_size = ALIGN_UP (sizeof (struct dp_heap_user ), 4 );
6365 /* src-lite with 8 channels has been seen allocating 14k in one go */
64- /* FIXME: the size will be derived from configuration */
65- const size_t buf_size = 20 * 1024 ;
66+ size_t buf_size = CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE ;
6667
68+ #if CONFIG_IPC_MAJOR_4
69+ if (config -> ipc_extended_init && ext_init && ext_init -> dp_data &&
70+ (ext_init -> dp_data -> lifetime_heap_bytes > 0 ||
71+ ext_init -> dp_data -> interim_heap_bytes > 0 )) {
72+ if (ext_init -> dp_data -> lifetime_heap_bytes > 64 * 1024 * 1024 ||
73+ ext_init -> dp_data -> interim_heap_bytes > 64 * 1024 * 1024 ) {
74+ LOG_ERR ("Insanely large lifetime %u or interim %u heap size for %#x" ,
75+ ext_init -> dp_data -> lifetime_heap_bytes ,
76+ ext_init -> dp_data -> interim_heap_bytes , config -> id );
77+ return NULL ;
78+ }
79+
80+ /*
81+ * For the moment there is only one heap so sum up
82+ * lifetime and interim values. It is also a conscious
83+ * decision here to count the size of struct
84+ * dp_heap_user to be included into required heap
85+ * size.
86+ */
87+ buf_size = ext_init -> dp_data -> lifetime_heap_bytes +
88+ ext_init -> dp_data -> interim_heap_bytes ;
89+ LOG_DBG ("%u + %u = %zu byte heap size requested in IPC for %#x" ,
90+ ext_init -> dp_data -> lifetime_heap_bytes ,
91+ ext_init -> dp_data -> interim_heap_bytes , buf_size , config -> id );
92+ }
93+ #endif
94+ if (buf_size < heap_prefix_size ) {
95+ LOG_ERR ("Too small heap size %zu (< %zu) for %#x" , buf_size , heap_prefix_size ,
96+ config -> id );
97+ return NULL ;
98+ }
99+
100+ LOG_INF ("Allocating %zu byte heap (default %zu) for %#x" , buf_size ,
101+ CONFIG_SOF_USERSPACE_DP_DEFAULT_HEAP_SIZE , config -> id );
67102 /* Keep uncached to match the default SOF heap! */
103+ /* Note that 'align' argumet is ignored by vmh backend */
68104 uint8_t * mod_heap_mem = rballoc_align (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT ,
69105 buf_size , PAGE_SZ );
70106
@@ -73,7 +109,6 @@ static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_con
73109
74110 struct dp_heap_user * mod_heap_user = (struct dp_heap_user * )mod_heap_mem ;
75111 struct k_heap * mod_heap = & mod_heap_user -> heap ;
76- const size_t heap_prefix_size = ALIGN_UP (sizeof (* mod_heap_user ), 4 );
77112 void * mod_heap_buf = mod_heap_mem + heap_prefix_size ;
78113
79114 * heap_size = buf_size - heap_prefix_size ;
@@ -86,8 +121,10 @@ static struct dp_heap_user *module_adapter_dp_heap_new(const struct comp_ipc_con
86121 return mod_heap_user ;
87122}
88123
89- static struct processing_module * module_adapter_mem_alloc (const struct comp_driver * drv ,
90- const struct comp_ipc_config * config )
124+ static
125+ struct processing_module * module_adapter_mem_alloc (const struct comp_driver * drv ,
126+ const struct comp_ipc_config * config ,
127+ const struct module_ext_init_data * ext_init )
91128{
92129 struct k_heap * mod_heap ;
93130 /*
@@ -104,7 +141,7 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
104141
105142 if (config -> proc_domain == COMP_PROCESSING_DOMAIN_DP && IS_ENABLED (CONFIG_USERSPACE ) &&
106143 !IS_ENABLED (CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP )) {
107- mod_heap_user = module_adapter_dp_heap_new (config , & heap_size );
144+ mod_heap_user = module_adapter_dp_heap_new (config , ext_init , & heap_size );
108145 if (!mod_heap_user ) {
109146 comp_cl_err (drv , "Failed to allocate DP module heap" );
110147 return NULL ;
@@ -220,8 +257,14 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
220257 return NULL ;
221258 }
222259#endif
260+ const struct module_ext_init_data * ext_init =
261+ #if CONFIG_IPC_MAJOR_4
262+ & ext_data ;
263+ #else
264+ NULL ;
265+ #endif
223266
224- struct processing_module * mod = module_adapter_mem_alloc (drv , config );
267+ struct processing_module * mod = module_adapter_mem_alloc (drv , config , ext_init );
225268
226269 if (!mod )
227270 return NULL ;
@@ -238,8 +281,8 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
238281 /*
239282 * NOTE: dst->ext_data points to stack variable and contains
240283 * pointers to IPC payload mailbox, so its only valid in
241- * functions that called from this function. This why
242- * the pointer is set NULL before this function exits.
284+ * functions that called from this function. This is why
285+ * the pointer is set to NULL before this function exits.
243286 */
244287#if CONFIG_IPC_MAJOR_4
245288 dst -> ext_data = & ext_data ;
0 commit comments