Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/boards/intel_adsp_ace15_mtpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ CONFIG_DMA_DW_LLI_POOL_SIZE=50
CONFIG_DMA_INTEL_ADSP_GPDMA=y
CONFIG_MEMORY_WIN_2_SIZE=12288
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=38400000
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000

Expand Down
2 changes: 1 addition & 1 deletion app/boards/intel_adsp_ace20_lnl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CONFIG_DAI_INIT_PRIORITY=70
CONFIG_DMA_INTEL_ADSP_GPDMA=n
CONFIG_MEMORY_WIN_2_SIZE=12288
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=38400000
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000

Expand Down
2 changes: 1 addition & 1 deletion app/boards/intel_adsp_ace30_ptl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CONFIG_DMA_INTEL_ADSP_GPDMA=n
CONFIG_DMA_DW_LLI_POOL_SIZE=50
CONFIG_MEMORY_WIN_2_SIZE=12288
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
CONFIG_XTENSA_MMU_NUM_L2_TABLES=128
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000

Expand Down
2 changes: 1 addition & 1 deletion app/boards/intel_adsp_ace30_wcl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CONFIG_DAI_DMIC_HAS_MULTIPLE_LINE_SYNC=y
CONFIG_DMA_INTEL_ADSP_GPDMA=n
CONFIG_MEMORY_WIN_2_SIZE=12288
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000

# Zephyr / power settings
Expand Down
2 changes: 1 addition & 1 deletion app/boards/intel_adsp_ace40_nvl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CONFIG_DAI_DMIC_HAS_OWNERSHIP=n
CONFIG_DAI_DMIC_HAS_MULTIPLE_LINE_SYNC=y
CONFIG_DMA_INTEL_ADSP_GPDMA=n
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000

# Zephyr / power settings
Expand Down
2 changes: 1 addition & 1 deletion app/boards/intel_adsp_ace40_nvls.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CONFIG_DAI_DMIC_HAS_OWNERSHIP=n
CONFIG_DAI_DMIC_HAS_MULTIPLE_LINE_SYNC=y
CONFIG_DMA_INTEL_ADSP_GPDMA=n
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000

# Zephyr / power settings
Expand Down
8 changes: 6 additions & 2 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,12 @@ if (CONFIG_SOC_SERIES_INTEL_ADSP_ACE)
${SOF_PLATFORM_PATH}/novalake/lib/clk.c
)

# Sources for virtual heap management
zephyr_library_sources(
zephyr_library_sources_ifdef(CONFIG_SOF_VREGIONS
lib/vpages.c
lib/vregion.c
)

zephyr_library_sources_ifdef(CONFIG_VIRTUAL_HEAP
lib/regions_mm.c
)

Expand Down
36 changes: 34 additions & 2 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ config SOF_ZEPHYR_VIRTUAL_HEAP_SIZE
config SOF_ZEPHYR_VIRTUAL_HEAP_REGION_SIZE
hex "Size in bytes of virtual memory region for virtual heap shared for all cores"
depends on MM_DRV_INTEL_ADSP_MTL_TLB
default 0x100000
default 0xc0000
help
This config defines size of virtual heap region shared between all cores

config SOF_ZEPHYR_VIRTUAL_PAGE_REGION_SIZE
hex "Size in bytes of virtual memory regions"
depends on MM_DRV_INTEL_ADSP_MTL_TLB
default 0x40000
help
This config defines size of the memory region, available to the
vregion / vpage API

config SOF_USERSPACE_USE_DRIVER_HEAP
bool "Use driver heap for SOF userspace modules"
depends on USERSPACE
Expand Down Expand Up @@ -145,6 +153,19 @@ config SOF_USERSPACE_APPLICATION
Not manually settable. This is effectively a shortcut to replace numerous
checks for (CONFIG_USERSPACE && !CONFIG_SOF_USERSPACE_PROXY)

config SOF_VPAGE_MAX_ALLOCS
int "Number of virtual memory page allocations"
default 128
help
This setting defines the maximum number of virtual memory page
allocations that can be tracked. Each allocation represents a
contiguous block of virtual memory allocated from the virtual memory
region. This API isn't intended for end-user allocations, instead it
should be used by the framework to allocate memory, which is then
used, e.g. to create one or multiple heap allocators in it. Increasing
this number allows for more simultaneous allocations, but also
increases the memory overhead for tracking these allocations.

config ZEPHYR_NATIVE_DRIVERS
bool "Use Zephyr native drivers"
help
Expand Down Expand Up @@ -237,8 +258,19 @@ config SOF_ZEPHYR_NO_SOF_CLOCK
Do not use SOF clk.h interface to set the DSP clock frequency.
Requires implementation of platform/lib/clk.h.

config SOF_VREGIONS
bool "Enable virtual memory regions"
default y if ACE
depends on ACE
help
Enable the virtual regions memory allocator for pipeline resource management.
This provides a way to manage memory resources for audio pipelines,
including
1) multiple pipeline static lifetime allocations.
2) runtime pipeline allocations.

config VIRTUAL_HEAP
bool "Use virtual memory heap to allocate a buffers"
bool "Use virtual memory heap to allocate buffers"
default y if ACE
depends on ACE
help
Expand Down
5 changes: 3 additions & 2 deletions zephyr/include/sof/lib/regions_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#include <zephyr/sys/mem_blocks.h>

/* Attributes for memory regions */
#define VIRTUAL_REGION_SHARED_HEAP_ATTR 1U /*< region dedicated for shared virtual heap */
#define VIRTUAL_REGION_LLEXT_LIBRARIES_ATTR 2U /*< region dedicated for LLEXT libraries */
#define VIRTUAL_REGION_SHARED_HEAP_ATTR 1U /*< region for shared virtual heap */
#define VIRTUAL_REGION_LLEXT_LIBRARIES_ATTR 2U /*< region for LLEXT libraries */
#define VIRTUAL_REGION_VPAGES_ATTR 3U /*< region for virtual page allocator */

/* Dependency on ipc/topology.h created due to memory capability definitions
* that are defined there
Expand Down
49 changes: 49 additions & 0 deletions zephyr/include/sof/lib/vpages.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright(c) 2025 Intel Corporation.

/* Virtual Page Allocator API */
#ifndef __SOF_LIB_VPAGE_H__
#define __SOF_LIB_VPAGE_H__

#include <zephyr/kernel.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Allocate virtual pages
* Allocates a specified number of contiguous virtual memory pages by mapping
* physical pages.
*
* @param[in] pages Number of 4kB pages to allocate.
*
* @return Pointer to the allocated virtual memory region, or NULL on failure.
*/
void *vpage_alloc(unsigned int pages);

/**
* @brief Free virtual pages
* Frees previously allocated virtual memory pages and unmaps them.
*
* @param[in] ptr Pointer to the memory pages to free.
*/
void vpage_free(void *ptr);

/**
* @brief Initialize virtual page allocator
*
* Initializes a virtual page allocator that manages a virtual memory region
* using a page table and block structures.
*
* @retval 0 if successful.
* @retval -ENOMEM on creation failure.
*/
int vpage_init(void);

Comment on lines +34 to +44
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

vpages.h declares int vpage_init(void);, but zephyr/lib/vpages.c only defines init_vpages() as a SYS_INIT hook and does not provide a vpage_init() symbol. This makes the public header/API inconsistent and will cause link failures for any caller. Either add an exported vpage_init() wrapper or remove the declaration if initialization is exclusively via SYS_INIT.

Suggested change
/**
* @brief Initialize virtual page allocator
*
* Initializes a virtual page allocator that manages a virtual memory region
* using a page table and block structures.
*
* @retval 0 if successful.
* @retval -ENOMEM on creation failure.
*/
int vpage_init(void);
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Allocate virtual pages
* Allocates a specified number of contiguous virtual memory pages by mapping
* physical pages.
*
* @param[in] pages Number of 4kB pages to allocate.
*
* @return Pointer to the allocated virtual memory region, or NULL on failure.
*/
void *vpage_alloc(unsigned int pages);
/**
* @brief Free virtual pages
* Frees previously allocated virtual memory pages and unmaps them.
*
* @param[in] ptr Pointer to the memory pages to free.
*/
void vpage_free(void *ptr);

Copilot uses AI. Check for mistakes.
#ifdef __cplusplus
}
#endif

#endif /* __SOF_LIB_VPAGE_H__ */
96 changes: 96 additions & 0 deletions zephyr/include/sof/lib/vregion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright(c) 2025 Intel Corporation.

/* Pre Allocated Contiguous Virtual Region */
#ifndef __SOF_LIB_VREGION_H__
#define __SOF_LIB_VREGION_H__

#include <zephyr/kernel.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

struct vregion;

/**
* @brief Create a new virtual region instance.
*
* Create a new virtual region instance with specified static and dynamic partitions.
* Total size is the sum of static and dynamic sizes.
*
* @param[in] lifetime_size Size of the virtual region lifetime partition.
* @param[in] interim_size Size of the virtual region interim partition.
* @return struct vregion* Pointer to the new virtual region instance, or NULL on failure.
*/
struct vregion *vregion_create(size_t lifetime_size, size_t interim_size);

/**
* @brief Destroy a virtual region instance.
*
* Free all associated resources and deallocate the virtual region instance.
*
* @param[in] vr Pointer to the virtual region instance to destroy.
*/
void vregion_destroy(struct vregion *vr);

/**
* @brief Memory types for virtual region allocations.
* Used to specify the type of memory allocation within a virtual region.
*
* @note
* - interim: allocation that can be freed i.e. get/set large config, kcontrols.
* - lifetime: allocation that cannot be freed i.e. init data, pipeline data.
*/
enum vregion_mem_type {
VREGION_MEM_TYPE_INTERIM, /* interim allocation that can be freed */
VREGION_MEM_TYPE_LIFETIME, /* lifetime allocation */
};

/**
* @brief Allocate memory from the specified virtual region.
*
* @param[in] vr Pointer to the virtual region instance.
* @param[in] type Type of memory to allocate (static, dynamic, or shared static).
* @param[in] size Size of memory to allocate in bytes.
* @return void* Pointer to the allocated memory, or NULL on failure.
*/
void *vregion_alloc(struct vregion *vr, enum vregion_mem_type type, size_t size);

/**
* @brief Allocate aligned memory from the specified virtual region.
*
* Allocate aligned memory from the specified virtual region based on the memory type.
*
* @param[in] vr Pointer to the virtual region instance.
* @param[in] type Type of memory to allocate (static, dynamic, or shared static).
* @param[in] size Size of memory to allocate in bytes.
* @param[in] alignment Alignment of memory to allocate in bytes.
* @return void* Pointer to the allocated memory, or NULL on failure.
*/
void *vregion_alloc_align(struct vregion *vr, enum vregion_mem_type type,
size_t size, size_t alignment);

/**
* @brief Free memory allocated from the specified virtual region.
*
* Free memory previously allocated from the specified virtual region.
*
* @param[in] vr Pointer to the virtual region instance.
* @param[in] ptr Pointer to the memory to free.
*/
void vregion_free(struct vregion *vr, void *ptr);

/**
* @brief Log virtual region memory usage.
*
* @param[in] vr Pointer to the virtual region instance.
*/
void vregion_info(struct vregion *vr);

#ifdef __cplusplus
}
#endif

#endif /* __SOF_LIB_VREGION_H__ */
17 changes: 8 additions & 9 deletions zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,14 @@ static void virtual_heap_free(void *ptr)

static const struct vmh_heap_config static_hp_buffers = {
{
{ 128, 32},
{ 512, 8},
{ 1024, 44},
{ 2048, 8},
{ 4096, 11},
{ 8192, 10},
{ 65536, 3},
{ 131072, 1},
{ 524288, 1} /* buffer for kpb */
{128, 32}, /* 4k */
{512, 8}, /* 4k -> 8k */
{1024, 28}, /* 28k -> 36k */
{2048, 4}, /* 8k -> 44k */
{4096, 7}, /* 28k -> 72k */
{8192, 7}, /* 56k -> 128k */
{65536, 2}, /* 128k -> 256k */
{524288, 1} /* 512k -> 768k */ /* buffer for kpb */
},
};

Expand Down
Loading
Loading