2121#if CONFIG_VIRTUAL_HEAP
2222#include <sof/lib/regions_mm.h>
2323
24- struct vmh_heap * virtual_buffers_heap ;
24+ struct vmh_heap * virtual_buffers_heap [ CONFIG_MP_MAX_NUM_CPUS ] ;
2525struct k_spinlock vmh_lock ;
2626
2727#undef HEAPMEM_SIZE
@@ -211,10 +211,10 @@ static void *virtual_heap_alloc(struct vmh_heap *heap, uint32_t flags, uint32_t
211211{
212212 void * mem ;
213213
214- K_SPINLOCK (& vmh_lock ) {
215- heap -> core_id = cpu_get_id ();
214+ // K_SPINLOCK(&vmh_lock) {
215+ // heap->core_id = cpu_get_id();
216216 mem = vmh_alloc (heap , bytes );
217- }
217+ // }
218218
219219 if (!mem )
220220 return NULL ;
@@ -247,14 +247,15 @@ static bool is_virtual_heap_pointer(void *ptr)
247247
248248static void virtual_heap_free (void * ptr )
249249{
250+ struct vmh_heap * const heap = virtual_buffers_heap [cpu_get_id ()];
250251 int ret ;
251252
252253 ptr = (__sparse_force void * )sys_cache_cached_ptr_get (ptr );
253254
254- K_SPINLOCK (& vmh_lock ) {
255- virtual_buffers_heap -> core_id = cpu_get_id ();
256- ret = vmh_free (virtual_buffers_heap , ptr );
257- }
255+ // K_SPINLOCK(&vmh_lock) {
256+ // virtual_buffers_heap->core_id = cpu_get_id();
257+ ret = vmh_free (heap , ptr );
258+ // }
258259
259260 if (ret )
260261 tr_err (& zephyr_tr , "Unable to free %p! %d" , ptr , ret );
@@ -276,12 +277,18 @@ static const struct vmh_heap_config static_hp_buffers = {
276277
277278static int virtual_heap_init (void )
278279{
280+ int core ;
281+
279282 k_spinlock_init (& vmh_lock );
280283
281- virtual_buffers_heap = vmh_init_heap (& static_hp_buffers , MEM_REG_ATTR_SHARED_HEAP , 0 ,
282- false);
283- if (!virtual_buffers_heap )
284- tr_err (& zephyr_tr , "Unable to init virtual buffers heap!" );
284+ for (core = 0 ; core < CONFIG_MP_MAX_NUM_CPUS ; core ++ ) {
285+ struct vmh_heap * heap = vmh_init_heap (& static_hp_buffers , MEM_REG_ATTR_CORE_HEAP ,
286+ core , false);
287+ if (!heap )
288+ tr_err (& zephyr_tr , "Unable to init virtual heap for core %d!" , core );
289+
290+ virtual_buffers_heap [core ] = heap ;
291+ }
285292
286293 return 0 ;
287294}
@@ -481,6 +488,9 @@ EXPORT_SYMBOL(rzalloc);
481488void * rballoc_align (uint32_t flags , uint32_t caps , size_t bytes ,
482489 uint32_t align )
483490{
491+ #if CONFIG_VIRTUAL_HEAP
492+ struct vmh_heap * virtual_heap ;
493+ #endif
484494 struct k_heap * heap ;
485495
486496 /* choose a heap */
@@ -498,8 +508,10 @@ void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes,
498508
499509#if CONFIG_VIRTUAL_HEAP
500510 /* Use virtual heap if it is available */
501- if (virtual_buffers_heap )
502- return virtual_heap_alloc (virtual_buffers_heap , flags , caps , bytes , align );
511+ virtual_heap = virtual_buffers_heap [cpu_get_id ()];
512+ if (virtual_heap ) {
513+ return virtual_heap_alloc (virtual_heap , flags , caps , bytes , align );
514+ }
503515#endif /* CONFIG_VIRTUAL_HEAP */
504516
505517 if (flags & SOF_MEM_FLAG_COHERENT )
0 commit comments