1111#include <sof/common.h>
1212#include <sof/list.h>
1313#include <sof/llext_manager.h>
14+ #include <sof/objpool.h>
1415#include <sof/schedule/dp_schedule.h>
1516#include <sof/schedule/ll_schedule_domain.h>
1617
2728LOG_MODULE_DECLARE (dp_schedule , CONFIG_SOF_LOG_LEVEL );
2829extern struct tr_ctx dp_tr ;
2930
30- static struct k_mem_domain dp_mdom [ CONFIG_CORE_COUNT ] ;
31+ static struct objpool_head dp_mdom_head = {. list = LIST_INIT ( dp_mdom_head . list )} ;
3132
3233/* Synchronization semaphore for the scheduler thread to wait for DP startup */
3334#define DP_SYNC_INIT (i , _ ) Z_SEM_INITIALIZER(dp_sync[i], 0, 1)
@@ -384,14 +385,17 @@ void dp_thread_fn(void *p1, void *p2, void *p3)
384385 */
385386void scheduler_dp_domain_free (struct processing_module * pmod )
386387{
387- unsigned int core = pmod -> dev -> task -> core ;
388+ struct k_mem_domain * mdom = pmod -> mdom ;
388389
389- llext_manager_rm_domain (pmod -> dev -> ipc_config .id , dp_mdom + core );
390+ llext_manager_rm_domain (pmod -> dev -> ipc_config .id , mdom );
390391
391392 struct task_dp_pdata * pdata = pmod -> dev -> task -> priv_data ;
392393
393- k_mem_domain_remove_partition (dp_mdom + core , pdata -> mpart + SOF_DP_PART_HEAP );
394- k_mem_domain_remove_partition (dp_mdom + core , pdata -> mpart + SOF_DP_PART_CFG );
394+ k_mem_domain_remove_partition (mdom , pdata -> mpart + SOF_DP_PART_HEAP );
395+ k_mem_domain_remove_partition (mdom , pdata -> mpart + SOF_DP_PART_CFG );
396+
397+ pmod -> mdom = NULL ;
398+ objpool_free (& dp_mdom_head , mdom );
395399}
396400
397401/* Called only in IPC context */
@@ -497,6 +501,19 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
497501 unsigned int pidx ;
498502 size_t size ;
499503 uintptr_t start ;
504+ struct k_mem_domain * mdom = objpool_alloc (& dp_mdom_head , sizeof (* mdom ),
505+ SOF_MEM_FLAG_COHERENT );
506+
507+ if (!mdom )
508+ goto e_thread ;
509+
510+ if (!mdom -> arch .ptables ) {
511+ ret = k_mem_domain_init (mdom , 0 , NULL );
512+ if (ret < 0 )
513+ goto e_dom ;
514+ }
515+
516+ mod -> mdom = mdom ;
500517
501518 /* Module heap partition */
502519 mod_heap_info (mod , & size , & start );
@@ -513,12 +530,12 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
513530 };
514531
515532 for (pidx = 0 ; pidx < SOF_DP_PART_TYPE_COUNT ; pidx ++ ) {
516- ret = k_mem_domain_add_partition (dp_mdom + core , pdata -> mpart + pidx );
533+ ret = k_mem_domain_add_partition (mdom , pdata -> mpart + pidx );
517534 if (ret < 0 )
518535 goto e_dom ;
519536 }
520537
521- ret = llext_manager_add_domain (mod -> dev -> ipc_config .id , dp_mdom + core );
538+ ret = llext_manager_add_domain (mod -> dev -> ipc_config .id , mdom );
522539 if (ret < 0 ) {
523540 tr_err (& dp_tr , "failed to add LLEXT to domain %d" , ret );
524541 goto e_dom ;
@@ -528,7 +545,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
528545 * Keep this call last, able to fail, otherwise domain will be removed
529546 * before its thread
530547 */
531- ret = k_mem_domain_add_thread (dp_mdom + core , pdata -> thread_id );
548+ ret = k_mem_domain_add_thread (mdom , pdata -> thread_id );
532549 if (ret < 0 ) {
533550 tr_err (& dp_tr , "failed to add thread to domain %d" , ret );
534551 goto e_dom ;
@@ -542,6 +559,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
542559
543560e_dom :
544561 scheduler_dp_domain_free (mod );
562+ objpool_free (& dp_mdom_head , mdom );
545563e_thread :
546564 k_thread_abort (pdata -> thread_id );
547565e_kobj :
@@ -554,8 +572,3 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
554572 mod_free (mod , task_memory );
555573 return ret ;
556574}
557-
558- int scheduler_dp_domain_init (void )
559- {
560- return k_mem_domain_init (dp_mdom + cpu_get_id (), 0 , NULL );
561- }
0 commit comments