|
Sound Open Firmware
|
System heaps, Virtual Memory Heap (VMH), virtual regions, cold DRAM staging, and audio buffer allocators. More...
Files | |
| file | coherent.h |
| Cache-coherent multi-core shared memory access abstractions. | |
| file | fast-get.h |
| Dynamic SRAM staging and cache mechanisms for cold DRAM-resident modules. | |
| file | vregion.h |
| Pre-allocated contiguous virtual memory region allocator (lifetime vs interim). | |
| file | alloc.h |
| Memory allocation API, zones, heaps, and alignment utilities. | |
| file | memory.h |
| Memory attributes, cold/hot execution paths, and platform memory inclusions. | |
| file | mm_heap.h |
| Legacy XTOS heap compatibility header. | |
| file | regions_mm.h |
| Virtual Memory Heap (VMH) and multi-block region allocator API. | |
| file | vpage.h |
| Virtual Page Allocator API for mapping contiguous memory pages. | |
Data Structures | |
| struct | coherent |
| Header embedded at start of multi-core shared memory objects for cache coherence. More... | |
| struct | mod_alloc_ctx |
| Module and pipeline allocation context aggregating a Zephyr heap and optional virtual region. More... | |
| struct | vmh_block_bundle_descriptor |
| Descriptor for a power-of-2 block size bundle in a virtual memory heap. More... | |
| struct | vmh_heap_config |
| This is a struct that aggregates vmh_block_bundle_descriptor to create one cfg that can be passed to heap initiation. More... | |
Macros | |
| #define | __coherent __aligned(PLATFORM_DCACHE_ALIGN) |
| Cache line alignment specifier for coherent shared memory objects. | |
| #define | ADDR_IS_INCOHERENT(_c) |
| #define | ADDR_IS_COHERENT(_c) |
| #define | CORE_CHECK_STRUCT_FIELD |
| #define | CORE_CHECK_STRUCT_INIT(_c, is_shared) |
| #define | CORE_CHECK_STRUCT(_c) |
| #define | CHECK_COHERENT_CORE(_c) |
| #define | CHECK_ISR() __ASSERT(!k_is_in_isr(), "Attempt to sleep in ISR!") |
| #define | CHECK_SLEEP(_c) |
| #define | CHECK_ATOMIC(_c) |
| #define | coherent_init(type, member) |
| Allocate and initialize a coherent shared object with spinlock protection. | |
| #define | coherent_shared(object, member) |
| Mark an allocated coherent object as actively shared across multiple DSP cores. | |
| #define | coherent_init_thread(type, member) |
| Allocate and initialize a coherent shared object with mutex protection for thread context. | |
| #define | coherent_shared_thread(object, member) |
| Mark a thread-capable coherent object as shared across multiple DSP cores. | |
| #define | coherent_free(object, member) |
| Invalidate cache and free a coherent shared memory object. | |
| #define | coherent_free_thread coherent_free |
| Free a thread-capable coherent shared memory object. | |
| #define | is_coherent_shared(object, member) ((object)->member.shared) |
| Query whether a coherent object is configured for multi-core shared mode. | |
| #define | __cold |
| Attribute marking non-latency-critical code for placement in cold memory sections. | |
| #define | __cold_rodata |
| Attribute marking read-only constants for placement in cold memory sections. | |
| #define | dbg_path_hot_start_watching() do {} while (0) |
| #define | dbg_path_hot_stop_watching() do {} while (0) |
| #define | dbg_path_hot_confirm() do {} while (0) |
| #define | dbg_path_cold_enter() do {} while (0) |
| #define | assert_can_be_cold() do {} while (0) |
| Assert that the current function is not executing from a latency-critical LL thread. | |
| #define | VIRTUAL_REGION_SHARED_HEAP_ATTR 1U |
| Region attribute for shared virtual memory heap. | |
| #define | VIRTUAL_REGION_LLEXT_LIBRARIES_ATTR 2U |
| Region attribute for loadable LLEXT libraries. | |
| #define | VIRTUAL_REGION_VPAGES_ATTR 3U |
| Region attribute for virtual page allocator. | |
| #define | MAX_MEMORY_ALLOCATORS_COUNT 10 |
| Maximum amount of memory block allocators in one heap. | |
| #define | DEFAULT_CONFIG_ALOCATORS_COUNT 5 |
| Default number of power-of-2 block allocators partitioned across a region. | |
Enumerations | |
| enum | vregion_mem_type { VREGION_MEM_TYPE_INTERIM , VREGION_MEM_TYPE_LIFETIME , VREGION_MEM_TYPE_INVALID } |
| Memory allocation modes within a virtual memory region. More... | |
Functions | |
| static struct coherent * | coherent_acquire (struct coherent *c, const size_t size) |
| Acquire exclusive access to a cache-coherent shared object in atomic/spinlock context. | |
| static void | coherent_release (struct coherent *c, const size_t size) |
| Release exclusive access to a cache-coherent shared object in atomic/spinlock context. | |
| static void * | __coherent_init (size_t offset, const size_t size) |
| Internal helper to allocate and initialize a coherent shared object. | |
| static void | __coherent_shared (struct coherent *c, const size_t size) |
| Internal helper to mark an allocated coherent object as actively shared. | |
| static struct coherent * | coherent_acquire_thread (struct coherent *c, const size_t size) |
| Acquire exclusive access to a cache-coherent shared object in thread/mutex context. | |
| static void | coherent_release_thread (struct coherent *c, const size_t size) |
| Release exclusive access to a cache-coherent shared object in thread/mutex context. | |
| static void * | __coherent_init_thread (size_t offset, const size_t size) |
| Internal helper to allocate and initialize a thread-capable coherent shared object. | |
| static void | __coherent_shared_thread (struct coherent *c, const size_t size) |
| Internal helper to mark a thread-capable coherent object as actively shared. | |
| static const void * | fast_get (struct mod_alloc_ctx *alloc, const void *const dram_ptr, size_t size) |
| static void | fast_put (struct mod_alloc_ctx *alloc, struct k_mem_domain *mdom, const void *sram_ptr) |
| struct vregion * | vregion_create (size_t memsize) |
| Create a new virtual region instance. | |
| struct vregion * | vregion_create_map (uintptr_t *vreg_start, size_t *vreg_size) |
| Create and map a new virtual region instance accessible by user-space domains. | |
| void | vregion_set_interim (struct vregion *vr) |
| Switch virtual region allocations to interim mode. | |
| struct vregion * | vregion_get (struct vregion *vr) |
| Increment virtual region's user count. | |
| struct vregion * | vregion_put (struct vregion *vr) |
| Decrement virtual region's user count or destroy it. | |
| void * | vregion_alloc_align (struct vregion *vr, size_t size, size_t alignment) |
| Allocate aligned memory from the specified virtual region. | |
| void * | vregion_alloc_coherent_align (struct vregion *vr, size_t size, size_t alignment) |
| Allocate aligned coherent (uncached) memory from the specified virtual region. | |
| static void * | vregion_alloc (struct vregion *vr, size_t size) |
| Allocate memory from the specified virtual region. | |
| static void * | vregion_alloc_coherent (struct vregion *vr, size_t size) |
| Allocate naturally aligned coherent (uncached) memory from the specified virtual region. | |
| void | vregion_free (struct vregion *vr, void *ptr) |
| Free memory allocated from the specified virtual region. | |
| void | vregion_info (struct vregion *vr) |
| Log virtual region memory usage. | |
| void | vregion_mem_info (struct vregion *vr, size_t *size, uintptr_t *start) |
| Retrieve virtual region memory base address and size. | |
| bool | vregion_verify (struct vregion *vr) |
| Validate that a virtual region handle is genuine and isolated from user space. | |
| void * | rmalloc_align (uint32_t flags, size_t bytes, uint32_t alignment) |
| Allocate memory block with explicit alignment and heap selection flags. | |
| void * | rmalloc (uint32_t flags, size_t bytes) |
| Allocate memory block with default natural alignment. | |
| void * | rzalloc (uint32_t flags, size_t bytes) |
| Allocate zero-initialized memory block with default natural alignment. | |
| void * | rballoc_align (uint32_t flags, size_t bytes, uint32_t alignment) |
| Allocate runtime stream buffer with explicit alignment. | |
| static void * | rballoc (uint32_t flags, size_t bytes) |
| Allocate runtime stream buffer aligned to platform data cache line size. | |
| void | rfree (void *ptr) |
| Free memory block allocated by SOF RTOS allocators. | |
| void | l3_heap_save (void) |
| Save and flush L3 heap state and metadata across DSP reset or power gating. | |
| void * | sof_heap_alloc (struct k_heap *heap, uint32_t flags, size_t bytes, size_t alignment) |
| Allocate memory from a specified Zephyr heap or default system heap. | |
| void | sof_heap_free (struct k_heap *heap, void *addr) |
| Free memory allocated via sof_heap_alloc(). | |
| struct k_heap * | sof_sys_heap_get (void) |
| Get the system kernel heap descriptor. | |
| struct k_heap * | sof_sys_user_heap_get (void) |
| Get the heap object to use for audio application allocations. | |
| static void | heap_trace_all (int force) |
| Trace and log memory allocation statistics across all active heaps. | |
| uintptr_t | get_shared_buffer_heap_start (void) |
| Returns the start address of shared memory heap for buffers. | |
| size_t | get_shared_buffer_heap_size (void) |
| Returns the total size of shared memory heap for buffers. | |
| static void * | sof_ctx_alloc (struct mod_alloc_ctx *ctx, uint32_t flags, size_t size, size_t alignment) |
| Allocate memory from an allocation context. | |
| static void * | sof_ctx_zalloc (struct mod_alloc_ctx *ctx, uint32_t flags, size_t size, size_t alignment) |
| Allocate zero-initialized memory from an allocation context. | |
| static void | sof_ctx_free (struct mod_alloc_ctx *ctx, void *ptr) |
| Free memory allocated from an allocation context. | |
| bool | ll_sch_is_current (void) |
| struct vmh_heap * | vmh_init_heap (const struct vmh_heap_config *cfg, bool allocating_continuously) |
| Initialize a virtual memory heap with the given bundle configuration. | |
| void * | vmh_alloc (struct vmh_heap *heap, uint32_t alloc_size) |
| Allocate a memory block from the virtual memory heap. | |
| int | vmh_free_heap (struct vmh_heap *heap) |
| Destroy a virtual memory heap and unmap all backing pages. | |
| int | vmh_free (struct vmh_heap *heap, void *ptr) |
| Free a memory block previously allocated from a virtual memory heap. | |
| void | vmh_get_default_heap_config (const struct sys_mm_drv_region *region, struct vmh_heap_config *cfg) |
| Generate a default heap partition configuration for a memory driver region. | |
| static bool | vmh_is_ptr_in_memory_range (uintptr_t ptr, uintptr_t range_start, size_t range_size) |
| Checks if ptr is in range of given memory range. | |
| void * | vpage_alloc (unsigned int pages) |
| Allocate contiguous virtual pages. | |
| void | vpage_free (void *ptr) |
| Free virtual pages. | |
Allocation flags | |
| #define | SOF_MEM_FLAG_DMA BIT(2) |
| Allocate memory accessible by DMA controllers (e.g. | |
| #define | SOF_MEM_FLAG_NO_COPY BIT(3) |
| realloc() skips copying the original content. | |
| #define | SOF_MEM_FLAG_COHERENT BIT(4) |
| Allocate uncached / coherent memory address. | |
| #define | SOF_MEM_FLAG_L3 BIT(5) |
| Allocate from L3 address space (IMR / external DRAM heap). | |
| #define | SOF_MEM_FLAG_LOW_POWER BIT(6) |
| Allocate Low power memory address. | |
| #define | SOF_MEM_FLAG_KERNEL BIT(7) |
| Base allocation flag denoting memory allocated for kernel-space data structures. | |
| #define | SOF_MEM_FLAG_USER BIT(8) |
| Base allocation flag denoting memory allocated for user-space threads and module execution. | |
| #define | SOF_MEM_FLAG_USER_SHARED_BUFFER BIT(9) |
| Allocate from shared user memory heap (shared_buffer_heap) accessible across user/kernel domains. | |
| #define | SOF_MEM_FLAG_LARGE_BUFFER BIT(10) |
| Route allocation to the Virtual Memory Heap (VMH / virtual_buffers_heap) for large stream buffers. | |
System heaps, Virtual Memory Heap (VMH), virtual regions, cold DRAM staging, and audio buffer allocators.
| #define __coherent __aligned(PLATFORM_DCACHE_ALIGN) |
Cache line alignment specifier for coherent shared memory objects.
| #define __cold |
Attribute marking non-latency-critical code for placement in cold memory sections.
Cold code (e.g. initialization, IPC setup, or offload modules) may be placed in DRAM / L3 memory or powered-down banks to conserve high-speed internal SRAM.
| #define __cold_rodata |
Attribute marking read-only constants for placement in cold memory sections.
| #define ADDR_IS_COHERENT | ( | _c | ) |
| #define ADDR_IS_INCOHERENT | ( | _c | ) |
| #define assert_can_be_cold | ( | ) | do {} while (0) |
Assert that the current function is not executing from a latency-critical LL thread.
| #define CHECK_ATOMIC | ( | _c | ) |
| #define CHECK_COHERENT_CORE | ( | _c | ) |
| #define CHECK_ISR | ( | ) | __ASSERT(!k_is_in_isr(), "Attempt to sleep in ISR!") |
| #define CHECK_SLEEP | ( | _c | ) |
| #define coherent_free | ( | object, | |
| member | |||
| ) |
Invalidate cache and free a coherent shared memory object.
Flushes dirty cache lines back to physical memory and frees the memory block via rfree().
| [in,out] | object | Pointer to the container structure. |
| [in] | member | Member name of the embedded struct coherent. |
| #define coherent_free_thread coherent_free |
Free a thread-capable coherent shared memory object.
Flushes dirty cache lines back to physical memory and frees the memory block via rfree().
| [in,out] | object | Pointer to the container structure. |
| [in] | member | Member name of the embedded struct coherent. |
| #define coherent_init | ( | type, | |
| member | |||
| ) |
Allocate and initialize a coherent shared object with spinlock protection.
Wrapper around __coherent_init() computing the member offset and container type size.
| [in] | type | Type of the container structure. |
| [in] | member | Member name of the embedded struct coherent. |
| #define coherent_init_thread | ( | type, | |
| member | |||
| ) |
Allocate and initialize a coherent shared object with mutex protection for thread context.
Wrapper around __coherent_init_thread() computing the member offset and container type size.
| [in] | type | Type of the container structure. |
| [in] | member | Member name of the embedded struct coherent. |
| #define coherent_shared | ( | object, | |
| member | |||
| ) |
Mark an allocated coherent object as actively shared across multiple DSP cores.
Wrapper around __coherent_shared() computing the member address and container size.
| [in,out] | object | Pointer to the container structure. |
| [in] | member | Member name of the embedded struct coherent. |
| #define coherent_shared_thread | ( | object, | |
| member | |||
| ) |
Mark a thread-capable coherent object as shared across multiple DSP cores.
Wrapper around __coherent_shared_thread() computing the member address and container size.
| [in,out] | object | Pointer to the container structure. |
| [in] | member | Member name of the embedded struct coherent. |
| #define CORE_CHECK_STRUCT | ( | _c | ) |
| #define CORE_CHECK_STRUCT_FIELD |
| #define CORE_CHECK_STRUCT_INIT | ( | _c, | |
| is_shared | |||
| ) |
| #define dbg_path_cold_enter | ( | ) | do {} while (0) |
| #define dbg_path_hot_confirm | ( | ) | do {} while (0) |
| #define dbg_path_hot_start_watching | ( | ) | do {} while (0) |
| #define dbg_path_hot_stop_watching | ( | ) | do {} while (0) |
| #define DEFAULT_CONFIG_ALOCATORS_COUNT 5 |
Default number of power-of-2 block allocators partitioned across a region.
| #define is_coherent_shared | ( | object, | |
| member | |||
| ) | ((object)->member.shared) |
Query whether a coherent object is configured for multi-core shared mode.
| [in] | object | Pointer to the container structure. |
| [in] | member | Member name of the embedded struct coherent. |
| #define MAX_MEMORY_ALLOCATORS_COUNT 10 |
Maximum amount of memory block allocators in one heap.
Since minimum realistic block is cache line size and block sizes must be powers of 2 (e.g. 64, 128, 256, 512, 1024, 2048, 4096, 8192).
| #define SOF_MEM_FLAG_COHERENT BIT(4) |
Allocate uncached / coherent memory address.
Directs the allocator to return an uncached pointer (e.g. bypassing cache alias or mapping uncached). Mandatory for DMA descriptors, mailboxes, and cross-core shared variables. Not supported for L3 memory.
| #define SOF_MEM_FLAG_DMA BIT(2) |
Allocate memory accessible by DMA controllers (e.g.
Host or DSP DMA).
| #define SOF_MEM_FLAG_KERNEL BIT(7) |
Base allocation flag denoting memory allocated for kernel-space data structures.
| #define SOF_MEM_FLAG_L3 BIT(5) |
Allocate from L3 address space (IMR / external DRAM heap).
Allocates from the L3 heap (l3_heap). Only cached allocations are supported; requesting coherent L3 memory will fail and return NULL.
| #define SOF_MEM_FLAG_LARGE_BUFFER BIT(10) |
Route allocation to the Virtual Memory Heap (VMH / virtual_buffers_heap) for large stream buffers.
| #define SOF_MEM_FLAG_LOW_POWER BIT(6) |
Allocate Low power memory address.
| #define SOF_MEM_FLAG_NO_COPY BIT(3) |
realloc() skips copying the original content.
| #define SOF_MEM_FLAG_USER BIT(8) |
Base allocation flag denoting memory allocated for user-space threads and module execution.
| #define SOF_MEM_FLAG_USER_SHARED_BUFFER BIT(9) |
Allocate from shared user memory heap (shared_buffer_heap) accessible across user/kernel domains.
| #define VIRTUAL_REGION_LLEXT_LIBRARIES_ATTR 2U |
Region attribute for loadable LLEXT libraries.
| #define VIRTUAL_REGION_SHARED_HEAP_ATTR 1U |
Region attribute for shared virtual memory heap.
| #define VIRTUAL_REGION_VPAGES_ATTR 3U |
Region attribute for virtual page allocator.
| enum vregion_mem_type |
Memory allocation modes within a virtual memory region.
Distinguishes lifetime allocations (bound to pipeline topology, cannot be freed until teardown) from interim allocations (dynamically created and released during runtime operations).
|
inlinestatic |
Internal helper to allocate and initialize a coherent shared object.
Allocates cache-aligned uncached memory with SOF_MEM_FLAG_COHERENT and initializes the coherent spinlock, tracking list, and owner core ID.
| [in] | offset | Byte offset of the struct coherent member within the allocated object. |
| [in] | size | Total size in bytes of the container object. |
|
inlinestatic |
Internal helper to allocate and initialize a thread-capable coherent shared object.
Allocates cache-aligned uncached memory with SOF_MEM_FLAG_COHERENT and initializes the embedded mutex and list header with sleeping allowed.
| [in] | offset | Byte offset of the struct coherent member within the allocated object. |
| [in] | size | Total size in bytes of the container object. |
|
inlinestatic |
Internal helper to mark an allocated coherent object as actively shared.
Transitions the coherent object state to shared mode under spinlock protection and invalidates local cache.
| [in,out] | c | Pointer to uncached coherent object header. |
| [in] | size | Total size in bytes of the coherent object. |
|
inlinestatic |
Internal helper to mark a thread-capable coherent object as actively shared.
Transitions the coherent object state to shared mode under mutex protection and invalidates local cache.
| [in,out] | c | Pointer to uncached coherent object header. |
| [in] | size | Total size in bytes of the coherent object. |
Acquire exclusive access to a cache-coherent shared object in atomic/spinlock context.
For incoherent hardware platforms, validates uncache alias, acquires the spinlock, and invalidates the local data cache over the object range so local accesses observe fresh multi-core updates.
| [in,out] | c | Pointer to uncached coherent object header. |
| [in] | size | Size of the coherent object including header in bytes. |
|
inlinestatic |
Acquire exclusive access to a cache-coherent shared object in thread/mutex context.
Locks the embedded mutex (blocking if necessary) and invalidates the local data cache region so thread-level accesses observe updates from other cores.
| [in,out] | c | Pointer to uncached coherent object header. |
| [in] | size | Size of the coherent object including header in bytes. |
|
inlinestatic |
Release exclusive access to a cache-coherent shared object in atomic/spinlock context.
Writes back dirty cache lines across the object range to physical memory, invalidates local cache lines, and releases the multi-core spinlock.
| [in,out] | c | Pointer to cached memory view of the coherent object. |
| [in] | size | Size of the coherent object including header in bytes. |
|
inlinestatic |
Release exclusive access to a cache-coherent shared object in thread/mutex context.
Writes back dirty cache lines to physical memory, invalidates local cache, and unlocks the embedded mutex.
| [in,out] | c | Pointer to cached memory view of the coherent object. |
| [in] | size | Size of the coherent object including header in bytes. |
|
inlinestatic |
|
inlinestatic |
| size_t get_shared_buffer_heap_size | ( | void | ) |
Returns the total size of shared memory heap for buffers.
| uintptr_t get_shared_buffer_heap_start | ( | void | ) |
Returns the start address of shared memory heap for buffers.
|
inlinestatic |
Trace and log memory allocation statistics across all active heaps.
| [in] | force | Force dumping heap trace even if logging threshold is not met. |
| void l3_heap_save | ( | void | ) |
Save and flush L3 heap state and metadata across DSP reset or power gating.
Flushes dirty cache lines for the L3 heap region and copies metadata into preserved storage to ensure data persistence across low-power reset cycles.
| bool ll_sch_is_current | ( | void | ) |
|
inlinestatic |
Allocate runtime stream buffer aligned to platform data cache line size.
Helper calling rballoc_align() with alignment set to PLATFORM_DCACHE_ALIGN.
| [in] | flags | Memory allocation flags, see SOF_MEM_FLAG_... |
| [in] | bytes | Size in bytes to allocate. |
| void * rballoc_align | ( | uint32_t | flags, |
| size_t | bytes, | ||
| uint32_t | alignment | ||
| ) |
Allocate runtime stream buffer with explicit alignment.
Runtime buffer allocator designed for audio stream buffers. Unlike rmalloc_align(), rballoc_align() actively prioritizes the Virtual Memory Heap (VMH / virtual_buffers_heap) when CONFIG_VIRTUAL_HEAP is enabled to preserve internal SRAM. Supports SOF_MEM_FLAG_L3 and SOF_MEM_FLAG_USER_SHARED_BUFFER. Respects SOF_MEM_FLAG_COHERENT for system and shared heaps, but note that the L3 heap path returns cached memory directly and does not support coherent uncached views.
| [in] | flags | Memory allocation flags, see SOF_MEM_FLAG_... |
| [in] | bytes | Size in bytes to allocate. |
| [in] | alignment | Required alignment in bytes. |
| void rfree | ( | void * | ptr | ) |
Free memory block allocated by SOF RTOS allocators.
Unified memory deallocator. Automatically determines the origin heap (L3 heap, Virtual Memory Heap, shared buffer heap, or system heap) using address boundary checks and returns memory to the respective pool. Passing a NULL pointer is safely treated as a no-op.
| [in,out] | ptr | Pointer to the memory block to free (can be NULL). |
| void * rmalloc | ( | uint32_t | flags, |
| size_t | bytes | ||
| ) |
Allocate memory block with default natural alignment.
Convenience wrapper calling rmalloc_align() with alignment set to 0.
| [in] | flags | Memory allocation flags, see SOF_MEM_FLAG_... |
| [in] | bytes | Size in bytes to allocate. |
| void * rmalloc_align | ( | uint32_t | flags, |
| size_t | bytes, | ||
| uint32_t | alignment | ||
| ) |
Allocate memory block with explicit alignment and heap selection flags.
Core RTOS memory allocator. Evaluates flags to select the appropriate heap:
If SOF_MEM_FLAG_COHERENT is specified, returns an uncached (coherent) pointer. Otherwise, returns a cached pointer. When CONFIG_VIRTUAL_HEAP is enabled and system heap allocation fails, transparently attempts fallback allocation from the Virtual Memory Heap (VMH).
| [in] | flags | Memory allocation flags, see SOF_MEM_FLAG_... |
| [in] | bytes | Size in bytes to allocate. |
| [in] | alignment | Required alignment in bytes (0 for default/natural alignment). |
| void * rzalloc | ( | uint32_t | flags, |
| size_t | bytes | ||
| ) |
Allocate zero-initialized memory block with default natural alignment.
Allocates memory via rmalloc() and, if successful, zeroes the entire block with memset() before returning.
| [in] | flags | Memory allocation flags, see SOF_MEM_FLAG_... |
| [in] | bytes | Size in bytes to allocate. |
|
inlinestatic |
Allocate memory from an allocation context.
When the context has an associated vregion, allocates from the vregion interim partition using vregion_alloc_coherent_align() (if SOF_MEM_FLAG_COHERENT is set) or vregion_alloc_align(). When no vregion is attached, falls back to sof_heap_alloc().
| [in,out] | ctx | Allocation context (heap + optional vregion). |
| [in] | flags | Allocation flags (SOF_MEM_FLAG_*). |
| [in] | size | Size in bytes to allocate. |
| [in] | alignment | Required alignment in bytes. |
|
inlinestatic |
Free memory allocated from an allocation context.
If the context contains a vregion, frees via vregion_free(); otherwise delegates to sof_heap_free(). Passing a NULL pointer is safely treated as a no-op.
| [in,out] | ctx | Allocation context. |
| [in,out] | ptr | Pointer to memory to free (can be NULL). |
|
inlinestatic |
Allocate zero-initialized memory from an allocation context.
Allocates memory via sof_ctx_alloc() and clears it with memset() if successful.
| [in,out] | ctx | Allocation context. |
| [in] | flags | Allocation flags (SOF_MEM_FLAG_*). |
| [in] | size | Size in bytes to allocate. |
| [in] | alignment | Required alignment in bytes. |
| void * sof_heap_alloc | ( | struct k_heap * | heap, |
| uint32_t | flags, | ||
| size_t | bytes, | ||
| size_t | alignment | ||
| ) |
Allocate memory from a specified Zephyr heap or default system heap.
| [in,out] | heap | Target Zephyr k_heap (or NULL to let implementation choose). |
| [in] | flags | Memory allocation flags (SOF_MEM_FLAG_...). |
| [in] | bytes | Size in bytes to allocate. |
| [in] | alignment | Required memory alignment in bytes. |
| void sof_heap_free | ( | struct k_heap * | heap, |
| void * | addr | ||
| ) |
Free memory allocated via sof_heap_alloc().
| [in,out] | heap | Target Zephyr k_heap. |
| [in,out] | addr | Address of allocated buffer to free. |
| struct k_heap * sof_sys_heap_get | ( | void | ) |
Get the system kernel heap descriptor.
| struct k_heap * sof_sys_user_heap_get | ( | void | ) |
Get the heap object to use for audio application allocations.
Returns zephyr_ll_user_heap() when CONFIG_SOF_USERSPACE_LL is enabled, or NULL to allow sof_heap_alloc() to pick the default heap.
| void * vmh_alloc | ( | struct vmh_heap * | heap, |
| uint32_t | alloc_size | ||
| ) |
Allocate a memory block from the virtual memory heap.
| [in,out] | heap | Pointer to target vmh_heap instance. |
| [in] | alloc_size | Allocation size in bytes. |
| int vmh_free | ( | struct vmh_heap * | heap, |
| void * | ptr | ||
| ) |
Free a memory block previously allocated from a virtual memory heap.
| [in,out] | heap | Pointer to vmh_heap instance. |
| [in,out] | ptr | Pointer to memory block to free. |
| int vmh_free_heap | ( | struct vmh_heap * | heap | ) |
Destroy a virtual memory heap and unmap all backing pages.
| [in,out] | heap | Pointer to vmh_heap instance to destroy. |
| void vmh_get_default_heap_config | ( | const struct sys_mm_drv_region * | region, |
| struct vmh_heap_config * | cfg | ||
| ) |
Generate a default heap partition configuration for a memory driver region.
| [in] | region | Driver region describing base and size. |
| [out] | cfg | Destination configuration structure to populate. |
| struct vmh_heap * vmh_init_heap | ( | const struct vmh_heap_config * | cfg, |
| bool | allocating_continuously | ||
| ) |
Initialize a virtual memory heap with the given bundle configuration.
| [in] | cfg | Pointer to heap bundle configuration. |
| [in] | allocating_continuously | If true, allows allocations to span a contiguous run of VMH block slots within a bundle; does not guarantee contiguous physical backing pages. |
|
inlinestatic |
Checks if ptr is in range of given memory range.
| [in] | ptr | Checked pointer address. |
| [in] | range_start | Start of checked memory range. |
| [in] | range_size | Size of checked memory range in bytes. |
| false | if no overlap detected. |
| true | if any overlap detected. |
| void * vpage_alloc | ( | unsigned int | pages | ) |
Allocate contiguous virtual pages.
Allocates a specified number of contiguous virtual memory pages by mapping physical backing pages into the DSP page table.
| [in] | pages | Number of pages (typically 4KB per page) to allocate. |
| void vpage_free | ( | void * | ptr | ) |
Free virtual pages.
Frees previously allocated virtual memory pages and unmaps them from the page table.
| [in,out] | ptr | Pointer to the virtual memory pages to free. |
|
inlinestatic |
Allocate memory from the specified virtual region.
| [in,out] | vr | Pointer to the virtual region instance. |
| [in] | size | Size of memory to allocate in bytes. |
| void * vregion_alloc_align | ( | struct vregion * | vr, |
| size_t | size, | ||
| size_t | alignment | ||
| ) |
Allocate aligned memory from the specified virtual region.
Allocate aligned memory from the specified virtual region using the current allocation mode (lifetime or interim).
| [in] | vr | Pointer to the virtual region instance. |
| [in] | size | Size of memory to allocate in bytes. |
| [in] | alignment | Alignment of memory to allocate in bytes. |
|
inlinestatic |
Allocate naturally aligned coherent (uncached) memory from the specified virtual region.
| [in,out] | vr | Pointer to the virtual region instance. |
| [in] | size | Size of memory to allocate in bytes. |
| void * vregion_alloc_coherent_align | ( | struct vregion * | vr, |
| size_t | size, | ||
| size_t | alignment | ||
| ) |
Allocate aligned coherent (uncached) memory from the specified virtual region.
| [in,out] | vr | Pointer to the virtual region instance. |
| [in] | size | Size of memory to allocate in bytes. |
| [in] | alignment | Alignment of memory to allocate in bytes. |
| struct vregion * vregion_create | ( | size_t | memsize | ) |
Create a new virtual region instance.
Create a new virtual region instance with specified memory size. Allocations start in LIFETIME mode.
| [in] | memsize | Total size of the virtual region memory in bytes. |
| struct vregion * vregion_create_map | ( | uintptr_t * | vreg_start, |
| size_t * | vreg_size | ||
| ) |
Create and map a new virtual region instance accessible by user-space domains.
Allocates contiguous virtual memory and configures memory protection domain permissions.
| [out] | vreg_start | Output pointer receiving the virtual start address of the region. |
| [in,out] | vreg_size | Input pointer specifying the requested size in bytes (must be non-zero); updated on return with the actual mapped size in bytes. |
| void vregion_free | ( | struct vregion * | vr, |
| void * | ptr | ||
| ) |
Free memory allocated from the specified virtual region.
Free memory previously allocated from the specified virtual region.
| [in,out] | vr | Pointer to the virtual region instance. |
| [in,out] | ptr | Pointer to the memory to free. |
| struct vregion * vregion_get | ( | struct vregion * | vr | ) |
Increment virtual region's user count.
The creator of the virtual region is its first user, for any additional users increment the region's use-count.
| [in] | vr | Pointer to the virtual region instance to release. |
| void vregion_info | ( | struct vregion * | vr | ) |
Log virtual region memory usage.
| [in] | vr | Pointer to the virtual region instance. |
| void vregion_mem_info | ( | struct vregion * | vr, |
| size_t * | size, | ||
| uintptr_t * | start | ||
| ) |
Retrieve virtual region memory base address and size.
| [in] | vr | Pointer to the virtual region instance. |
| [out] | size | Output pointer receiving total region size in bytes. |
| [out] | start | Output pointer receiving starting virtual address. |
| struct vregion * vregion_put | ( | struct vregion * | vr | ) |
Decrement virtual region's user count or destroy it.
Decrement virtual region's user count, when it reaches 0 free all associated resources.
| [in] | vr | Pointer to the virtual region instance to release. |
| void vregion_set_interim | ( | struct vregion * | vr | ) |
Switch virtual region allocations to interim mode.
After this call, all allocations from this vregion will use the interim heap. The interim heap is created lazily from remaining lifetime space. Multiple calls are allowed but log a warning.
| [in] | vr | Pointer to the virtual region instance. |
| bool vregion_verify | ( | struct vregion * | vr | ) |
Validate that a virtual region handle is genuine and isolated from user space.
| [in] | vr | Pointer to virtual region instance to verify. |