mem: workaround - remove MEM_REG_ATTR_SHARED_HEAP from SOF by marcinszkudlinski · Pull Request #10144 · thesofproject/sof · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions zephyr/Kconfig
3 changes: 3 additions & 0 deletions zephyr/include/sof/lib/regions_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <zephyr/init.h>
#include <zephyr/sys/mem_blocks.h>

/* Attributes for memory regions */
#define VIRTUAL_REGION_SHARED_HEAP_ATTR 1U /*< region dedicated for shared virtual heap */

/* Dependency on ipc/topology.h created due to memory capability definitions
* that are defined there
*/
Expand Down
32 changes: 32 additions & 0 deletions zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#if CONFIG_VIRTUAL_HEAP
#include <sof/lib/regions_mm.h>
#include <zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h>

struct vmh_heap;
struct vmh_heap *virtual_buffers_heap;
Expand Down Expand Up @@ -288,8 +289,39 @@ static const struct vmh_heap_config static_hp_buffers = {
},
};

/* WA Stubs begin

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

The abbreviation 'WA' should be spelled out as 'Workaround' for clarity in the comment.

Suggested change
/* WA Stubs begin
/* Workaround Stubs begin

Copilot uses AI. Check for mistakes.
*
* in order to merge a PR that moves initialization of virtual regions from Zephyr to SOF,
* we need to create weak stubs for 2 functions that will need to be called once the PR is merged
*/

__weak
uintptr_t adsp_mm_get_unused_l2_start_aligned(void)
{
return 0;
}

Comment on lines +297 to +303

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

The weak stub function lacks documentation explaining its purpose, expected behavior when the real implementation is available, and return value meaning.

Suggested change
__weak
uintptr_t adsp_mm_get_unused_l2_start_aligned(void)
{
return 0;
}
/**
* @brief Weak stub for retrieving the start address of unused L2 memory, aligned.
*
* This function is a placeholder and should be overridden by a platform-specific
* implementation. It is expected to return the starting address of unused L2 memory,
* aligned to the required boundary.
*
* @return uintptr_t The aligned start address of unused L2 memory. Returns 0 if
* no implementation is provided.
*/
__weak
uintptr_t adsp_mm_get_unused_l2_start_aligned(void)
{
return 0;
}
/**
* @brief Weak stub for adding a virtual memory region.
*
* This function is a placeholder and should be overridden by a platform-specific
* implementation. It is expected to add a virtual memory region with the specified
* address, size, and attributes.
*
* @param region_address The starting address of the virtual memory region.
* @param region_size The size of the virtual memory region in bytes.
* @param attr Attributes for the virtual memory region (e.g., access permissions).
*
* @return int Returns 0 if successful, or an error code if the operation fails.
*/

Copilot uses AI. Check for mistakes.

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

The weak stub function lacks documentation explaining its parameters, return values, and expected behavior when the real implementation becomes available.

Suggested change
/**
* @brief Add a virtual memory region to the system.
*
* This weak stub function is a placeholder for adding a virtual memory region.
* It is expected to be overridden by a real implementation in the future.
*
* @param region_address The starting address of the memory region.
* @param region_size The size of the memory region in bytes.
* @param attr Attributes for the memory region (e.g., access permissions).
*
* @return 0 on success, or an error code indicating failure.
*/

Copilot uses AI. Check for mistakes.
__weak
int adsp_add_virtual_memory_region(uintptr_t region_address, uint32_t region_size, uint32_t attr)
{
return 0;
}
/* WA Stubs end */

Copilot AI Jul 30, 2025

Copy link

Choose a reason for hiding this comment

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

The abbreviation 'WA' should be spelled out as 'Workaround' for clarity in the comment.

Suggested change
/* WA Stubs end */
/* Workaround Stubs end */

Copilot uses AI. Check for mistakes.

static int virtual_heap_init(void)
{
int ret;

if (virtual_buffers_heap)
return -EEXIST;

/* add a virtual memory region */
ret = adsp_add_virtual_memory_region(adsp_mm_get_unused_l2_start_aligned(),
CONFIG_SOF_ZEPHYR_VIRTUAL_HEAP_REGION_SIZE,
VIRTUAL_REGION_SHARED_HEAP_ATTR);
if (ret)
return ret;

virtual_buffers_heap = vmh_init_heap(&static_hp_buffers, false);
if (!virtual_buffers_heap) {
tr_err(&zephyr_tr, "Unable to init virtual heap");
Expand Down
18 changes: 7 additions & 11 deletions zephyr/lib/regions_mm.c
Loading