Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions zephyr/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ __section(".heap_mem") static uint8_t __aligned(64) heapmem[HEAPMEM_SIZE];

static uint8_t __aligned(PLATFORM_DCACHE_ALIGN)heapmem[HEAPMEM_SIZE];
static uint8_t __aligned(PLATFORM_DCACHE_ALIGN)heapmem_shared[HEAPMEM_SHARED_SIZE];

/* Use k_heap structure */
static struct k_heap sof_heap_shared;
#endif

/* Use k_heap structure */
static struct k_heap sof_heap;
static struct k_heap sof_heap_shared;

static int statics_init(const struct device *unused)
{
Expand Down Expand Up @@ -151,10 +153,12 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes)
{
if (zone_is_cached(zone))
return heap_alloc_aligned_cached(&sof_heap, 0, bytes);
else
return heap_alloc_aligned(&sof_heap, 8, bytes);

#ifdef CONFIG_IMX
return heap_alloc_aligned(&sof_heap, 8, bytes);
#else
return heap_alloc_aligned(&sof_heap_shared, 8, bytes);
#endif
}

/* Use SOF_MEM_ZONE_BUFFER at the moment */
Expand Down Expand Up @@ -230,7 +234,11 @@ void rfree(void *ptr)

/* select heap based on address range */
if (is_uncached(ptr)) {
#ifdef CONFIG_IMX
heap_free(&sof_heap, ptr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you ever get uncached pointers from malloc on IMX? From your description it sounds like you don't need those. Let's do this: let's get one of these PRs in - either this one or #4479 (I don't mind either, but I'd prefer mine because it's smaller, it only fixes a bug without adding more confusion). After that I'd make a new PR to extract all heap management into a separate file zephyr/alloc.c and then we'd duplicate it into zephyr/alloc_cavs.c and zephyr/alloc_imx.c or whatever. And remove all the #ifdefs from both. Then you can do what you need in your copy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you ever get uncached pointers from malloc on IMX?

We don't have the memory map aliasing that permits cached vs uncached pointers. I was having internal discussions more than a year ago about this, currently cache_to_uncache and uncache_to_cache macros are no-ops but I was wondering if there was a way to remove them (because they cannot be meaningfully implemented) for platforms like IMX.

#else
heap_free(&sof_heap_shared, ptr);
#endif
return;
}

Expand Down