-
Notifications
You must be signed in to change notification settings - Fork 350
vpage / vregion: a minimal version with a test #10636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lyakh
wants to merge
3
commits into
thesofproject:main
Choose a base branch
from
lyakh:vreg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __SOF_LIB_VPAGE_H__ */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vpages.hdeclaresint vpage_init(void);, butzephyr/lib/vpages.conly definesinit_vpages()as aSYS_INIThook and does not provide avpage_init()symbol. This makes the public header/API inconsistent and will cause link failures for any caller. Either add an exportedvpage_init()wrapper or remove the declaration if initialization is exclusively viaSYS_INIT.