1010#if defined(CONFIG_MM_DRV )
1111#include <sof/lib/regions_mm.h>
1212
13- /* list of vmh_heap objects created */
14- static struct list_item vmh_list = LIST_INIT (vmh_list );
1513
1614/** @struct vmh_heap
1715 *
1816 * @brief This structure holds all information about virtual memory heap
1917 * it aggregates information about its allocations and
2018 * physical mappings.
2119 *
22- * @var node generic list member used for list operations
2320 * @var virtual_region pointer to virtual region information, it holds its
2421 * attributes size and beginning ptr provided by zephyr.
2522 * @var physical_blocks_allocators[] a table of block allocators
2623 * each representing a virtual regions part in blocks of a given size
2724 * governed by sys_mem_blocks API.
2825 * @var allocation_sizes[] a table of bit arrays representing sizes of allocations
2926 * made in physical_blocks_allocators directly related to physical_blocks_allocators
30- * @var core_id id of the core that heap was created on
3127 * @var allocating_continuously configuration value deciding if heap allocations
3228 * will be contiguous or single block.
3329 */
3430struct vmh_heap {
35- struct list_item node ;
3631 const struct sys_mm_drv_region * virtual_region ;
3732 struct sys_mem_blocks * physical_blocks_allocators [MAX_MEMORY_ALLOCATORS_COUNT ];
3833 struct sys_bitarray * allocation_sizes [MAX_MEMORY_ALLOCATORS_COUNT ];
39- int core_id ;
4034 bool allocating_continuously ;
4135};
4236
@@ -47,49 +41,32 @@ struct vmh_heap {
4741 * and config. The heap size overall must be aligned to physical page
4842 * size.
4943 * @param cfg Configuration structure with block structure for the heap
50- * @param memory_region_attribute A zephyr defined virtual region identifier
51- * @param core_id Core id of a heap that will be created
5244 * @param allocating_continuously Flag deciding if heap can do contiguous allocation.
5345 *
5446 * @retval ptr to a new heap if successful.
5547 * @retval NULL on creation failure.
5648 */
57- struct vmh_heap * vmh_init_heap (const struct vmh_heap_config * cfg ,
58- int memory_region_attribute , int core_id , bool allocating_continuously )
49+ struct vmh_heap * vmh_init_heap (const struct vmh_heap_config * cfg , bool allocating_continuously )
5950{
6051 const struct sys_mm_drv_region * virtual_memory_regions =
6152 sys_mm_drv_query_memory_regions ();
6253 int i ;
6354
64- /* Check if we haven't created heap for this region already */
65- if (vmh_get_heap_by_attribute (memory_region_attribute , core_id ))
66- return NULL ;
67-
6855 struct vmh_heap * new_heap =
6956 rzalloc (SOF_MEM_ZONE_RUNTIME_SHARED , 0 , SOF_MEM_CAPS_RAM , sizeof (* new_heap ));
7057
7158 if (!new_heap )
7259 return NULL ;
7360
74- new_heap -> core_id = core_id ;
75- list_init (& new_heap -> node );
7661 struct vmh_heap_config new_config = {0 };
7762
78- /* Search for matching attribute so we place heap on right
79- * virtual region.
80- * In case of core heaps regions we count theme from 0 to max
81- * available cores
82- */
83- if (memory_region_attribute == MEM_REG_ATTR_CORE_HEAP ) {
84- new_heap -> virtual_region = & virtual_memory_regions [core_id ];
85- } else {
86- for (i = CONFIG_MP_MAX_NUM_CPUS ;
87- i < CONFIG_MP_MAX_NUM_CPUS + VIRTUAL_REGION_COUNT ; i ++ ) {
63+ /* Search for matching attribute so we place heap on shared virtual region */
64+ for (i = CONFIG_MP_MAX_NUM_CPUS ;
65+ i < CONFIG_MP_MAX_NUM_CPUS + VIRTUAL_REGION_COUNT ; i ++ ) {
8866
89- if (memory_region_attribute == virtual_memory_regions [i ].attr ) {
90- new_heap -> virtual_region = & virtual_memory_regions [i ];
91- break ;
92- }
67+ if (virtual_memory_regions [i ].attr == MEM_REG_ATTR_SHARED_HEAP ) {
68+ new_heap -> virtual_region = & virtual_memory_regions [i ];
69+ break ;
9370 }
9471 }
9572
@@ -220,9 +197,6 @@ struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg,
220197
221198 new_heap -> allocating_continuously = allocating_continuously ;
222199
223- /* Save the new heap pointer to a linked list */
224- list_item_append (& vmh_list , & new_heap -> node );
225-
226200 return new_heap ;
227201fail :
228202 for (i = 0 ; i < MAX_MEMORY_ALLOCATORS_COUNT ; i ++ ) {
@@ -419,9 +393,6 @@ void *vmh_alloc(struct vmh_heap *heap, uint32_t alloc_size)
419393{
420394 if (!alloc_size )
421395 return NULL ;
422- /* Only operations on the same core are allowed */
423- if (heap -> core_id != cpu_get_id ())
424- return NULL ;
425396
426397 void * ptr = NULL ;
427398 int mem_block_iterator , allocation_error_code = - ENOMEM ;
@@ -566,7 +537,6 @@ int vmh_free_heap(struct vmh_heap *heap)
566537 rfree (heap -> allocation_sizes [i ]);
567538 }
568539 }
569- list_item_del (& heap -> node );
570540 rfree (heap );
571541 return 0 ;
572542}
@@ -587,9 +557,6 @@ int vmh_free(struct vmh_heap *heap, void *ptr)
587557{
588558 int retval ;
589559
590- if (heap -> core_id != cpu_get_id ())
591- return - EINVAL ;
592-
593560 size_t mem_block_iter , i , size_to_free , block_size , ptr_bit_array_offset ,
594561 ptr_bit_array_position , blocks_to_free ;
595562 bool ptr_range_found ;
@@ -703,32 +670,6 @@ int vmh_free(struct vmh_heap *heap, void *ptr)
703670 size_to_free );
704671}
705672
706- /**
707- * @brief Reconfigure heap with given config
708- *
709- * This will destroy the heap from the pointer and recreate it
710- * using provided config. Individual region attribute is the
711- * "anchor" to the virtual space we use.
712- *
713- * @param heap Ptr to the heap that should be reconfigured
714- * @param cfg heap blocks configuration
715- * @param allocating_continuously allow contiguous on the reconfigured heap
716- *
717- * @retval heap_pointer Returns new heap pointer on success
718- * @retval NULL when reconfiguration failed
719- */
720- struct vmh_heap * vmh_reconfigure_heap (
721- struct vmh_heap * heap , struct vmh_heap_config * cfg ,
722- int core_id , bool allocating_continuously )
723- {
724- uint32_t region_attribute = heap -> virtual_region -> attr ;
725-
726- if (vmh_free_heap (heap ))
727- return NULL ;
728-
729- return vmh_init_heap (cfg , region_attribute , core_id , allocating_continuously );
730- }
731-
732673/**
733674 * @brief Get default configuration for heap
734675 *
@@ -757,47 +698,4 @@ void vmh_get_default_heap_config(const struct sys_mm_drv_region *region,
757698 }
758699}
759700
760- /**
761- * @brief Gets pointer to already created heap identified by
762- * provided attribute.
763- *
764- * @param attr Virtual memory region attribute.
765- * @param core_id id of the core that heap was created for (core heap specific).
766- *
767- * @retval heap ptr on success
768- * @retval NULL if there was no heap created fitting the attr.
769- */
770- struct vmh_heap * vmh_get_heap_by_attribute (uint32_t attr , uint32_t core_id )
771- {
772- struct list_item * vm_heaps_iterator ;
773- struct vmh_heap * retval ;
774-
775- if (attr == MEM_REG_ATTR_CORE_HEAP ) {
776- /* if we look up cpu heap we need to match its cpuid with addr
777- * we know that regions keep cpu heaps from 0 to max so we match
778- * the region of the cpu id with lists one to find match
779- */
780- const struct sys_mm_drv_region * virtual_memory_region =
781- sys_mm_drv_query_memory_regions ();
782- /* we move ptr to cpu vmr */
783- virtual_memory_region = & virtual_memory_region [core_id ];
784-
785- list_for_item (vm_heaps_iterator , & vmh_list ) {
786- retval =
787- CONTAINER_OF (vm_heaps_iterator , struct vmh_heap , node );
788-
789- if (retval -> virtual_region -> addr == virtual_memory_region -> addr )
790- return retval ;
791- }
792- } else {
793- list_for_item (vm_heaps_iterator , & vmh_list ) {
794- retval =
795- CONTAINER_OF (vm_heaps_iterator , struct vmh_heap , node );
796- if (retval -> virtual_region -> attr == attr )
797- return retval ;
798- }
799- }
800- return NULL ;
801- }
802-
803701#endif /* if defined (CONFIG_MM_DRV) */
0 commit comments