-
Notifications
You must be signed in to change notification settings - Fork 364
Expand file tree
/
Copy pathalloc.h
More file actions
139 lines (117 loc) · 3.65 KB
/
Copy pathalloc.h
File metadata and controls
139 lines (117 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2022 Intel Corporation. All rights reserved.
*/
#ifndef __ZEPHYR_RTOS_ALLOC_H__
#define __ZEPHYR_RTOS_ALLOC_H__
#include <rtos/bit.h>
#include <rtos/string.h>
#include <sof/lib/memory.h> /* PLATFORM_DCACHE_ALIGN */
#include <sof/trace/trace.h>
#include <user/trace.h>
#include <stddef.h>
#include <stdint.h>
/** \addtogroup alloc_api Memory Allocation API
* @{
*/
/*
* for compatibility with the initial `flags` meaning
* SOF_MEM_FLAG_ should start at BIT(2)
* the first two positions are reserved for SOF_BUF_ flags
*/
/** \name Heap zone flags
* @{
*/
/** \brief Indicates we should return DMA-able memory. */
#define SOF_MEM_FLAG_DMA BIT(2)
/** \brief Indicates that original content should not be copied by realloc. */
#define SOF_MEM_FLAG_NO_COPY BIT(3)
/** \brief Indicates that if we should return uncached address. */
#define SOF_MEM_FLAG_COHERENT BIT(4)
/** \brief Indicates that if we should return L3 address. */
#define SOF_MEM_FLAG_L3 BIT(5)
/** \brief Indicates that if we should return Low power memory address. */
#define SOF_MEM_FLAG_LOW_POWER BIT(6)
/** \brief Indicates that if we should return kernel memory address. */
#define SOF_MEM_FLAG_KERNEL BIT(7)
/** \brief Indicates that if we should return user memory address. */
#define SOF_MEM_FLAG_USER BIT(8)
/** \brief Indicates that if we should return shared user memory address. */
#define SOF_MEM_FLAG_USER_SHARED_BUFFER BIT(9)
/** @} */
/**
* Allocates memory block.
* @param flags Flags, see SOF_MEM_FLAG_....
* @param bytes Size in bytes.
* @return Pointer to the allocated memory or NULL if failed.
*
*/
void *rmalloc(uint32_t flags, size_t bytes);
/**
* Similar to rmalloc(), guarantees that returned block is zeroed.
*/
void *rzalloc(uint32_t flags, size_t bytes);
/**
* Allocates memory block.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param bytes Size in bytes.
* @param alignment Alignment in bytes.
* @return Pointer to the allocated memory or NULL if failed.
*/
void *rballoc_align(uint32_t flags, size_t bytes,
uint32_t alignment);
/**
* Similar to rballoc_align(), returns buffer aligned to PLATFORM_DCACHE_ALIGN.
*/
static inline void *rballoc(uint32_t flags, size_t bytes)
{
return rballoc_align(flags, bytes, PLATFORM_DCACHE_ALIGN);
}
/**
* Changes size of the memory block allocated.
* @param ptr Address of the block to resize.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param bytes New size in bytes.
* @param old_bytes Old size in bytes.
* @param alignment Alignment in bytes.
* @return Pointer to the resized memory of NULL if failed.
*/
void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes,
size_t old_bytes, uint32_t alignment);
/**
* Similar to rballoc_align(), returns resized buffer aligned to
* PLATFORM_DCACHE_ALIGN.
*/
static inline void *rbrealloc(void *ptr, uint32_t flags,
size_t bytes, size_t old_bytes)
{
return rbrealloc_align(ptr, flags, bytes, old_bytes,
PLATFORM_DCACHE_ALIGN);
}
/**
* Frees the memory block.
* @param ptr Pointer to the memory block.
*/
void rfree(void *ptr);
/**
* Save L3 heap over DSP reset
*/
void l3_heap_save(void);
/* TODO: remove - debug only - only needed for linking */
static inline void heap_trace_all(int force) {}
/** @}*/
#if CONFIG_USERSPACE
/**
* Returns the start address of shared memory heap for buffers.
*
* @return pointer to shared memory heap start
*/
uintptr_t get_shared_buffer_heap_start(void);
/**
* Returns the size of shared memory heap for buffers.
*
* @return size of shared memory heap start
*/
size_t get_shared_buffer_heap_size(void);
#endif
#endif /* __ZEPHYR_RTOS_ALLOC_H__ */