Sound Open Firmware
Loading...
Searching...
No Matches
vregion.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2// Copyright(c) 2025 Intel Corporation.
3
10#ifndef __SOF_LIB_VREGION_H__
11#define __SOF_LIB_VREGION_H__
12
13#include <stddef.h>
14#include <stdint.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
28struct vregion;
29
44
45#if CONFIG_SOF_VREGIONS
46
56struct vregion *vregion_create(size_t memsize);
57
68__syscall struct vregion *vregion_create_map(uintptr_t *vreg_start, size_t *vreg_size);
69
79__syscall void vregion_set_interim(struct vregion *vr);
80
90__syscall struct vregion *vregion_get(struct vregion *vr);
91
101__syscall struct vregion *vregion_put(struct vregion *vr);
102
114__syscall void *vregion_alloc_align(struct vregion *vr, size_t size, size_t alignment);
115
123__syscall void *vregion_alloc_coherent_align(struct vregion *vr, size_t size, size_t alignment);
124
132static inline void *vregion_alloc(struct vregion *vr, size_t size)
133{
134 return vregion_alloc_align(vr, size, 0);
135}
136
143static inline void *vregion_alloc_coherent(struct vregion *vr, size_t size)
144{
145 return vregion_alloc_coherent_align(vr, size, 0);
146}
147
156__syscall void vregion_free(struct vregion *vr, void *ptr);
157
163void vregion_info(struct vregion *vr);
164
172void vregion_mem_info(struct vregion *vr, size_t *size, uintptr_t *start);
173
179bool vregion_verify(struct vregion *vr);
180
181#include <zephyr/syscalls/vregion.h>
182
183#else
184
185struct vregion {
186 unsigned int use_count;
187};
188
189static inline struct vregion *vregion_create(size_t memsize)
190{
191 return NULL;
192}
193static inline struct vregion *vregion_create_map(uintptr_t *vreg_start, size_t *vreg_size)
194{
195 return NULL;
196}
197static inline void vregion_set_interim(struct vregion *vr) {}
198static inline struct vregion *vregion_get(struct vregion *vr)
199{
200 return vr;
201}
202static inline struct vregion *vregion_put(struct vregion *vr)
203{
204 return vr;
205}
206static inline void *vregion_alloc(struct vregion *vr, size_t size)
207{
208 return NULL;
209}
210static inline void *vregion_alloc_coherent(struct vregion *vr, size_t size)
211{
212 return NULL;
213}
214static inline void *vregion_alloc_align(struct vregion *vr, size_t size, size_t alignment)
215{
216 return NULL;
217}
218static inline void *vregion_alloc_coherent_align(struct vregion *vr, size_t size,
219 size_t alignment)
220{
221 return NULL;
222}
223static inline void vregion_free(struct vregion *vr, void *ptr) {}
224static inline void vregion_info(struct vregion *vr) {}
225static inline void vregion_mem_info(struct vregion *vr, size_t *size, uintptr_t *start)
226{
227 if (size)
228 *size = 0;
229}
230static inline bool vregion_verify(struct vregion *vr) {return false;}
231
232#endif /* CONFIG_SOF_VREGIONS */
233
236#ifdef __cplusplus
237}
238#endif
239
240#endif /* __SOF_LIB_VREGION_H__ */
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.
void vregion_free(struct vregion *vr, void *ptr)
Free memory allocated from the specified virtual region.
vregion_mem_type
Memory allocation modes within a virtual memory region.
Definition vregion.h:36
struct vregion * vregion_create(size_t memsize)
Create a new virtual region instance.
void * vregion_alloc_align(struct vregion *vr, size_t size, size_t alignment)
Allocate aligned memory from the specified virtual region.
struct vregion * vregion_get(struct vregion *vr)
Increment virtual region's user count.
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.
static void * vregion_alloc_coherent(struct vregion *vr, size_t size)
Allocate naturally aligned coherent (uncached) memory from the specified virtual region.
Definition vregion.h:143
void * vregion_alloc_coherent_align(struct vregion *vr, size_t size, size_t alignment)
Allocate aligned coherent (uncached) memory from the specified virtual region.
struct vregion * vregion_put(struct vregion *vr)
Decrement virtual region's user count or destroy it.
bool vregion_verify(struct vregion *vr)
Validate that a virtual region handle is genuine and isolated from user space.
static void * vregion_alloc(struct vregion *vr, size_t size)
Allocate memory from the specified virtual region.
Definition vregion.h:132
@ VREGION_MEM_TYPE_INVALID
Invalid memory type indicating initialization error or exhaustion.
Definition vregion.h:42
@ VREGION_MEM_TYPE_INTERIM
Interim allocation that can be freed dynamically (e.g.
Definition vregion.h:38
@ VREGION_MEM_TYPE_LIFETIME
Lifetime allocation that persists until region destruction (e.g.
Definition vregion.h:40