|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +// Copyright(c) 2025 Intel Corporation. |
| 3 | + |
| 4 | +/* Pre Allocated Contiguous Virtual Region */ |
| 5 | +#ifndef __SOF_LIB_PACOVR_H__ |
| 6 | +#define __SOF_LIB_PACOVR_H__ |
| 7 | + |
| 8 | +#include <zephyr/kernel.h> |
| 9 | +#include <stddef.h> |
| 10 | + |
| 11 | +#ifdef __cplusplus |
| 12 | +extern "C" { |
| 13 | +#endif |
| 14 | + |
| 15 | +struct pacovr; |
| 16 | + |
| 17 | +/** |
| 18 | + * @brief Create a new PACOVR instance. |
| 19 | + * |
| 20 | + * Create a new PACOVR instance with specified batch and scratch sizes. Total |
| 21 | + * size is the sum of batch and scratch sizes. |
| 22 | + * |
| 23 | + * @param[in] batch_size Size of the PACOVR batch region. |
| 24 | + * @param[in] scratch_size Size of the scratch heap. |
| 25 | + * @return struct pacovr* Pointer to the new PACOVR instance, or NULL on failure. |
| 26 | + */ |
| 27 | +struct pacovr *pacovr_create(size_t batch_size, size_t scratch_size); |
| 28 | + |
| 29 | +/** |
| 30 | + * @brief Destroy a PACOVR instance. |
| 31 | + * |
| 32 | + * Free all associated resources and deallocate the PACOVR instance. |
| 33 | + * |
| 34 | + * @param[in] p Pointer to the PACOVR instance to destroy. |
| 35 | + */ |
| 36 | +void pacovr_destroy(struct pacovr *p); |
| 37 | + |
| 38 | +/** |
| 39 | + * @brief Allocate memory from the PACOVR scratch heap. |
| 40 | + * |
| 41 | + * Allocate memory from the PACOVR scratch heap. Intended use for temporary |
| 42 | + * allocations during audio processing. i.e. change of parameters or kcontrols. |
| 43 | + * |
| 44 | + * @param[in] p Pointer to the PACOVR instance. |
| 45 | + * @param[in] size Size of the allocation. |
| 46 | + * @return void* Pointer to the allocated memory, or NULL on failure. |
| 47 | + */ |
| 48 | +void *pacovr_scratch_alloc(struct pacovr *p, size_t size); |
| 49 | + |
| 50 | +/** |
| 51 | + * @brief Allocate memory with alignment from the PACOVR scratch heap. |
| 52 | + * |
| 53 | + * Allocate memory with alignment from the PACOVR scratch heap. Intended use for |
| 54 | + * temporary allocations during audio processing. i.e. change of parameters or |
| 55 | + * kcontrols. |
| 56 | + * |
| 57 | + * @param[in] p Pointer to the PACOVR instance. |
| 58 | + * @param[in] size Size of the allocation. |
| 59 | + * @param[in] align Alignment of the allocation. |
| 60 | + * @return void* Pointer to the allocated memory, or NULL on failure. |
| 61 | + */ |
| 62 | +void *pacovr_scratch_alloc_align(struct pacovr *p, size_t size, size_t align); |
| 63 | + |
| 64 | +/** |
| 65 | + * @brief Free memory from the PACOVR scratch heap. |
| 66 | + * |
| 67 | + * Free memory from the PACOVR scratch heap. Intended use for temporary |
| 68 | + * allocations during audio processing. i.e. change of parameters or |
| 69 | + * kcontrols. |
| 70 | + * |
| 71 | + * @param[in] p Pointer to the PACOVR instance. |
| 72 | + * @param[in] ptr Pointer to the memory to free. |
| 73 | + */ |
| 74 | +void pacovr_scratch_free(struct pacovr *p, void *ptr); |
| 75 | + |
| 76 | +/** |
| 77 | + * @brief Allocate memory from the PACOVR batch allocator. |
| 78 | + * |
| 79 | + * Allocate memory from the PACOVR batch allocator. Intended use for |
| 80 | + * allocations that persist for the lifetime of the audio processing pipeline. |
| 81 | + * i.e. component data, buffers, etc. |
| 82 | + * |
| 83 | + * @param[in] p Pointer to the PACOVR instance. |
| 84 | + * @param[in] size Size of the allocation. |
| 85 | + * @param[in] align Alignment of the allocation. |
| 86 | + * @return void* Pointer to the allocated memory, or NULL on failure. |
| 87 | + */ |
| 88 | +void *pacovr_batch_alloc(struct pacovr *p, size_t size); |
| 89 | + |
| 90 | +/** |
| 91 | + * @brief Free memory from the PACOVR batch allocator. |
| 92 | + * |
| 93 | + * Free memory from the PACOVR batch allocator. This is a no-op and is |
| 94 | + * intended for tuning and tracking only. Batch allocations are freed |
| 95 | + * when the PACOVR instance is destroyed. Any call to this function usually |
| 96 | + * means the allocation should have been from the scratch heap. |
| 97 | + * |
| 98 | + * @param[in] p Pointer to the PACOVR instance. |
| 99 | + * @param[in] ptr Pointer to the memory to free. |
| 100 | + */ |
| 101 | +void pacovr_batch_free(struct pacovr *p, void *ptr); |
| 102 | + |
| 103 | +/** |
| 104 | + * @brief Log PACOVR memory usage. |
| 105 | + * |
| 106 | + * @param[in] p Pointer to the PACOVR instance. |
| 107 | + */ |
| 108 | +void pacovr_info(struct pacovr *p); |
| 109 | + |
| 110 | +#ifdef __cplusplus |
| 111 | +} |
| 112 | +#endif |
| 113 | + |
| 114 | +#endif /* __SOF_LIB_PACOVR_H__ */ |
0 commit comments