Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Intel Corporation |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of the Intel Corporation nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> |
| 29 | * Keyon Jie <yang.jie@linux.intel.com> |
| 30 | */ |
| 31 | |
| 32 | #include <reef/alloc.h> |
| 33 | #include <reef/reef.h> |
| 34 | #include <reef/debug.h> |
Liam Girdwood | e52ce68 | 2018-02-21 15:36:25 +0000 | [diff] [blame] | 35 | #include <reef/panic.h> |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 36 | #include <reef/trace.h> |
| 37 | #include <reef/lock.h> |
| 38 | #include <platform/memory.h> |
| 39 | #include <stdint.h> |
| 40 | |
| 41 | /* debug to set memory value on every allocation */ |
| 42 | #define DEBUG_BLOCK_ALLOC 0 |
| 43 | #define DEBUG_BLOCK_ALLOC_VALUE 0x6b6b6b6b |
| 44 | |
| 45 | /* debug to set memory value on every free TODO: not working atm */ |
| 46 | #define DEBUG_BLOCK_FREE 0 |
| 47 | #define DEBUG_BLOCK_FREE_VALUE 0x5a5a5a5a |
| 48 | |
| 49 | /* memory tracing support */ |
| 50 | #if DEBUG_BLOCK_ALLOC || DEBUG_BLOCK_FREE |
| 51 | #define trace_mem(__e) trace_event(TRACE_CLASS_MEM, __e) |
| 52 | #else |
| 53 | #define trace_mem(__e) |
| 54 | #endif |
| 55 | |
| 56 | #define trace_mem_error(__e) trace_error(TRACE_CLASS_MEM, __e) |
| 57 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 58 | /* We have 3 memory pools |
| 59 | * |
| 60 | * 1) System memory pool does not have a map and it's size is fixed at build |
| 61 | * time. Memory cannot be freed from this pool. Used by device drivers |
| 62 | * and any system core. Saved as part of PM context. |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 63 | * 2) Runtime memory pool has variable size allocation map and memory is freed |
| 64 | * on calls to rfree(). Saved as part of PM context. Global size |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 65 | * set at build time. |
| 66 | * 3) Buffer memory pool has fixed size allocation map and can be freed on |
| 67 | * module removal or calls to rfree(). Saved as part of PM context. |
| 68 | */ |
| 69 | |
| 70 | struct block_hdr { |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 71 | uint16_t size; /* size in blocks of this continuous allocation */ |
| 72 | uint16_t flags; /* usage flags for page */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 73 | } __attribute__ ((packed)); |
| 74 | |
| 75 | struct block_map { |
| 76 | uint16_t block_size; /* size of block in bytes */ |
| 77 | uint16_t count; /* number of blocks in map */ |
| 78 | uint16_t free_count; /* number of free blocks */ |
| 79 | uint16_t first_free; /* index of first free block */ |
| 80 | struct block_hdr *block; /* base block header */ |
| 81 | uint32_t base; /* base address of space */ |
| 82 | } __attribute__ ((packed)); |
| 83 | |
| 84 | #define BLOCK_DEF(sz, cnt, hdr) \ |
| 85 | {.block_size = sz, .count = cnt, .free_count = cnt, .block = hdr} |
| 86 | |
| 87 | /* Heap blocks for modules */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 88 | //static struct block_hdr mod_block8[HEAP_RT_COUNT8]; |
| 89 | static struct block_hdr mod_block16[HEAP_RT_COUNT16]; |
| 90 | static struct block_hdr mod_block32[HEAP_RT_COUNT32]; |
| 91 | static struct block_hdr mod_block64[HEAP_RT_COUNT64]; |
| 92 | static struct block_hdr mod_block128[HEAP_RT_COUNT128]; |
| 93 | static struct block_hdr mod_block256[HEAP_RT_COUNT256]; |
| 94 | static struct block_hdr mod_block512[HEAP_RT_COUNT512]; |
| 95 | static struct block_hdr mod_block1024[HEAP_RT_COUNT1024]; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 96 | |
| 97 | /* Heap memory map for modules */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 98 | static struct block_map rt_heap_map[] = { |
| 99 | /* BLOCK_DEF(8, HEAP_RT_COUNT8, mod_block8), */ |
| 100 | BLOCK_DEF(16, HEAP_RT_COUNT16, mod_block16), |
| 101 | BLOCK_DEF(32, HEAP_RT_COUNT32, mod_block32), |
| 102 | BLOCK_DEF(64, HEAP_RT_COUNT64, mod_block64), |
| 103 | BLOCK_DEF(128, HEAP_RT_COUNT128, mod_block128), |
| 104 | BLOCK_DEF(256, HEAP_RT_COUNT256, mod_block256), |
| 105 | BLOCK_DEF(512, HEAP_RT_COUNT512, mod_block512), |
| 106 | BLOCK_DEF(1024, HEAP_RT_COUNT1024, mod_block1024), |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | /* Heap blocks for buffers */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 110 | static struct block_hdr buf_block[HEAP_BUFFER_COUNT]; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 111 | |
| 112 | /* Heap memory map for buffers */ |
| 113 | static struct block_map buf_heap_map[] = { |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 114 | BLOCK_DEF(HEAP_BUFFER_BLOCK_SIZE, HEAP_BUFFER_COUNT, buf_block), |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 115 | }; |
| 116 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 117 | #if (HEAP_DMA_BUFFER_SIZE > 0) |
| 118 | /* Heap memory map for DMA buffers - only used for HW with special DMA memories */ |
| 119 | static struct block_map dma_buf_heap_map[] = { |
| 120 | BLOCK_DEF(HEAP_DMA_BUFFER_BLOCK_SIZE, HEAP_DMA_BUFFER_COUNT, buf_block), |
| 121 | }; |
| 122 | #endif |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 123 | |
| 124 | struct mm_heap { |
| 125 | uint32_t blocks; |
| 126 | struct block_map *map; |
| 127 | uint32_t heap; |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 128 | uint32_t size; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 129 | struct mm_info info; |
| 130 | }; |
| 131 | |
| 132 | /* heap block memory map */ |
| 133 | struct mm { |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 134 | struct mm_heap runtime; /* general heap for components */ |
| 135 | struct mm_heap system; /* system heap - used during init cannot be freed */ |
| 136 | struct mm_heap buffer; /* general component buffer heap */ |
| 137 | #if (HEAP_DMA_BUFFER_SIZE > 0) |
| 138 | struct mm_heap dma; /* general component DMA buffer heap */ |
| 139 | #endif |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 140 | struct mm_info total; |
| 141 | spinlock_t lock; /* all allocs and frees are atomic */ |
| 142 | }; |
| 143 | |
| 144 | struct mm memmap = { |
| 145 | .system = { |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 146 | .heap = HEAP_SYSTEM_BASE, |
| 147 | .size = HEAP_SYSTEM_SIZE, |
| 148 | .info = {.free = HEAP_SYSTEM_SIZE,}, |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 149 | }, |
| 150 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 151 | .runtime = { |
| 152 | .blocks = ARRAY_SIZE(rt_heap_map), |
| 153 | .map = rt_heap_map, |
| 154 | .heap = HEAP_RUNTIME_BASE, |
| 155 | .size = HEAP_RUNTIME_SIZE, |
| 156 | .info = {.free = HEAP_RUNTIME_SIZE,}, |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 157 | }, |
| 158 | |
| 159 | .buffer = { |
| 160 | .blocks = ARRAY_SIZE(buf_heap_map), |
| 161 | .map = buf_heap_map, |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 162 | .heap = HEAP_BUFFER_BASE, |
| 163 | .size = HEAP_BUFFER_SIZE, |
| 164 | .info = {.free = HEAP_BUFFER_SIZE,}, |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 165 | }, |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 166 | |
| 167 | #if (HEAP_DMA_BUFFER_SIZE > 0) |
| 168 | .dma = { |
| 169 | .blocks = ARRAY_SIZE(dma_buf_heap_map), |
| 170 | .map = dma_buf_heap_map, |
| 171 | .heap = HEAP_DMA_BUFFER_BASE, |
| 172 | .size = HEAP_DMA_BUFFER_SIZE, |
| 173 | .info = {.free = HEAP_DMA_BUFFER_SIZE,}, |
| 174 | }, |
| 175 | #endif |
| 176 | .total = {.free = HEAP_SYSTEM_SIZE + HEAP_RUNTIME_SIZE + |
| 177 | HEAP_BUFFER_SIZE + HEAP_DMA_BUFFER_SIZE,}, |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | /* total size of block */ |
| 181 | static inline uint32_t block_get_size(struct block_map *map) |
| 182 | { |
| 183 | return sizeof(*map) + map->count * |
| 184 | (map->block_size + sizeof(struct block_hdr)); |
| 185 | } |
| 186 | |
| 187 | /* total size of heap */ |
| 188 | static inline uint32_t heap_get_size(struct mm_heap *heap) |
| 189 | { |
| 190 | uint32_t size = sizeof(struct mm_heap); |
| 191 | int i; |
| 192 | |
| 193 | for (i = 0; i < heap->blocks; i++) { |
| 194 | size += block_get_size(&heap->map[i]); |
| 195 | } |
| 196 | |
| 197 | return size; |
| 198 | } |
| 199 | |
| 200 | #if DEBUG_BLOCK_ALLOC || DEBUG_BLOCK_FREE |
| 201 | static void alloc_memset_region(void *ptr, uint32_t bytes, uint32_t val) |
| 202 | { |
| 203 | uint32_t count = bytes >> 2; |
| 204 | uint32_t *dest = ptr, i; |
| 205 | |
| 206 | for (i = 0; i < count; i++) |
| 207 | dest[i] = val; |
| 208 | } |
| 209 | #endif |
| 210 | |
| 211 | /* allocate from system memory pool */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 212 | static void *rmalloc_sys(size_t bytes) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 213 | { |
| 214 | void *ptr = (void *)memmap.system.heap; |
| 215 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 216 | /* always succeeds or panics */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 217 | memmap.system.heap += bytes; |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 218 | if (memmap.system.heap >= HEAP_SYSTEM_BASE + HEAP_SYSTEM_SIZE) { |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 219 | trace_mem_error("eMd"); |
Liam Girdwood | e52ce68 | 2018-02-21 15:36:25 +0000 | [diff] [blame] | 220 | panic(SOF_IPC_PANIC_MEM); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | #if DEBUG_BLOCK_ALLOC |
| 224 | alloc_memset_region(ptr, bytes, DEBUG_BLOCK_ALLOC_VALUE); |
| 225 | #endif |
| 226 | |
| 227 | return ptr; |
| 228 | } |
| 229 | |
| 230 | /* allocate single block */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 231 | static void *alloc_block(struct mm_heap *heap, int level, int bflags) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 232 | { |
| 233 | struct block_map *map = &heap->map[level]; |
| 234 | struct block_hdr *hdr = &map->block[map->first_free]; |
| 235 | void *ptr; |
| 236 | int i; |
| 237 | |
| 238 | map->free_count--; |
| 239 | ptr = (void *)(map->base + map->first_free * map->block_size); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 240 | hdr->size = 1; |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 241 | hdr->flags = RFLAGS_USED | bflags; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 242 | heap->info.used += map->block_size; |
| 243 | heap->info.free -= map->block_size; |
| 244 | |
| 245 | /* find next free */ |
| 246 | for (i = map->first_free; i < map->count; ++i) { |
| 247 | |
| 248 | hdr = &map->block[i]; |
| 249 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 250 | if (hdr->flags == 0) { |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 251 | map->first_free = i; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | #if DEBUG_BLOCK_ALLOC |
| 257 | alloc_memset_region(ptr, map->block_size, DEBUG_BLOCK_ALLOC_VALUE); |
| 258 | #endif |
| 259 | |
| 260 | return ptr; |
| 261 | } |
| 262 | |
Pierre-Louis Bossart | f945809 | 2017-11-09 15:24:07 -0600 | [diff] [blame] | 263 | /* allocates continuous blocks */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 264 | static void *alloc_cont_blocks(struct mm_heap *heap, int level, int bflags, |
| 265 | size_t bytes) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 266 | { |
| 267 | struct block_map *map = &heap->map[level]; |
| 268 | struct block_hdr *hdr = &map->block[map->first_free]; |
| 269 | void *ptr; |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 270 | unsigned int start; |
| 271 | unsigned int current; |
| 272 | unsigned int count = bytes / map->block_size; |
| 273 | unsigned int i; |
| 274 | unsigned int remaining = map->count - count; |
| 275 | unsigned int end; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 276 | |
| 277 | if (bytes % map->block_size) |
| 278 | count++; |
| 279 | |
Pierre-Louis Bossart | f945809 | 2017-11-09 15:24:07 -0600 | [diff] [blame] | 280 | /* check for continuous blocks from "start" */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 281 | for (start = map->first_free; start < remaining; start++) { |
| 282 | |
| 283 | /* check that we have enough free blocks from start pos */ |
| 284 | end = start + count; |
| 285 | for (current = start; current < end; current++) { |
| 286 | hdr = &map->block[current]; |
| 287 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 288 | /* is block used */ |
| 289 | if (hdr->flags == RFLAGS_USED) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 290 | break; |
| 291 | } |
| 292 | |
| 293 | /* enough free blocks ? */ |
| 294 | if (current == end) |
| 295 | goto found; |
| 296 | } |
| 297 | |
| 298 | /* not found */ |
| 299 | trace_mem_error("eCb"); |
| 300 | return NULL; |
| 301 | |
| 302 | found: |
| 303 | /* found some free blocks */ |
| 304 | map->free_count -= count; |
| 305 | ptr = (void *)(map->base + start * map->block_size); |
| 306 | hdr = &map->block[start]; |
| 307 | hdr->size = count; |
| 308 | heap->info.used += count * map->block_size; |
| 309 | heap->info.free -= count * map->block_size; |
| 310 | |
| 311 | /* allocate each block */ |
| 312 | for (current = start; current < end; current++) { |
| 313 | hdr = &map->block[current]; |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 314 | hdr->flags = RFLAGS_USED | bflags; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* do we need to find a new first free block ? */ |
| 318 | if (start == map->first_free) { |
| 319 | |
| 320 | /* find next free */ |
| 321 | for (i = map->first_free + count; i < map->count; ++i) { |
| 322 | |
| 323 | hdr = &map->block[i]; |
| 324 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 325 | if (hdr->flags == 0) { |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 326 | map->first_free = i; |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | #if DEBUG_BLOCK_ALLOC |
| 333 | alloc_memset_region(ptr, bytes, DEBUG_BLOCK_ALLOC_VALUE); |
| 334 | #endif |
| 335 | |
| 336 | return ptr; |
| 337 | } |
| 338 | |
| 339 | /* free block(s) */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 340 | static void free_block(struct mm_heap *heap, void *ptr) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 341 | { |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 342 | struct mm_heap * mm_heap; |
| 343 | struct block_map * block_map; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 344 | struct block_hdr *hdr; |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 345 | int i; |
| 346 | int block; |
| 347 | int array_size; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 348 | |
| 349 | /* sanity check */ |
| 350 | if (ptr == NULL) |
| 351 | return; |
| 352 | |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 353 | /* find mm_heap that ptr belongs to */ |
| 354 | if ((uint32_t)ptr >= memmap.runtime.heap && |
| 355 | (uint32_t)ptr < memmap.runtime.heap + memmap.runtime.size) { |
| 356 | mm_heap = &memmap.runtime; |
| 357 | array_size = ARRAY_SIZE(rt_heap_map); |
| 358 | } else if ((uint32_t)ptr >= memmap.buffer.heap && |
| 359 | (uint32_t)ptr < memmap.buffer.heap + memmap.buffer.size) { |
| 360 | mm_heap = &memmap.buffer; |
| 361 | array_size = ARRAY_SIZE(buf_heap_map); |
| 362 | #if (HEAP_DMA_BUFFER_SIZE > 0) |
| 363 | } else if ((uint32_t)ptr >= memmap.dma.heap && |
| 364 | (uint32_t)ptr < memmap.dma.heap + memmap.dma.size) { |
| 365 | mm_heap = &memmap.dma; |
| 366 | array_size = ARRAY_SIZE(dma_buf_heap_map); |
| 367 | #endif |
| 368 | } else |
| 369 | return; |
| 370 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 371 | /* find block that ptr belongs to */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 372 | for (i = 0; i < array_size - 1; i ++) { |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 373 | |
| 374 | /* is ptr in this block */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 375 | if ((uint32_t)ptr < mm_heap->map[i + 1].base) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 376 | goto found; |
| 377 | } |
| 378 | |
| 379 | /* not found */ |
| 380 | trace_mem_error("eMF"); |
| 381 | return; |
| 382 | |
| 383 | found: |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 384 | /* the block i is it */ |
| 385 | block_map = &mm_heap->map[i]; |
| 386 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 387 | /* calculate block header */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 388 | block = ((uint32_t)ptr - block_map->base) / block_map->block_size; |
| 389 | hdr = &block_map->block[block]; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 390 | |
Pierre-Louis Bossart | f945809 | 2017-11-09 15:24:07 -0600 | [diff] [blame] | 391 | /* free block header and continuous blocks */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 392 | for (i = block; i < block + hdr->size; i++) { |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 393 | hdr = &block_map->block[i]; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 394 | hdr->size = 0; |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 395 | hdr->flags = 0; |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 396 | block_map->free_count++; |
| 397 | heap->info.used -= block_map->block_size; |
| 398 | heap->info.free += block_map->block_size; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /* set first free */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 402 | if (block < block_map->first_free) |
| 403 | block_map->first_free = block; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 404 | |
| 405 | #if DEBUG_BLOCK_FREE |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 406 | alloc_memset_region(ptr, block_map->block_size * (i - 1), DEBUG_BLOCK_FREE_VALUE); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 407 | #endif |
| 408 | } |
| 409 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 410 | /* allocate single block for runtime */ |
| 411 | static void *rmalloc_runtime(int bflags, size_t bytes) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 412 | { |
| 413 | int i; |
| 414 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 415 | for (i = 0; i < ARRAY_SIZE(rt_heap_map); i ++) { |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 416 | |
| 417 | /* is block big enough */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 418 | if (rt_heap_map[i].block_size < bytes) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 419 | continue; |
| 420 | |
| 421 | /* does block have free space */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 422 | if (rt_heap_map[i].free_count == 0) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 423 | continue; |
| 424 | |
| 425 | /* free block space exists */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 426 | return alloc_block(&memmap.runtime, i, bflags); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | trace_mem_error("eMm"); |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 430 | trace_value(bytes); |
| 431 | trace_value(bflags); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 432 | return NULL; |
| 433 | } |
| 434 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 435 | void *rmalloc(int zone, int bflags, size_t bytes) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 436 | { |
| 437 | uint32_t flags; |
| 438 | void *ptr = NULL; |
| 439 | |
| 440 | spin_lock_irq(&memmap.lock, flags); |
| 441 | |
| 442 | switch (zone) { |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 443 | case RZONE_SYS: |
| 444 | ptr = rmalloc_sys(bytes); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 445 | break; |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 446 | case RZONE_RUNTIME: |
| 447 | ptr = rmalloc_runtime(bflags, bytes); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 448 | break; |
| 449 | default: |
| 450 | trace_mem_error("eMz"); |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | spin_unlock_irq(&memmap.lock, flags); |
| 455 | return ptr; |
| 456 | } |
| 457 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 458 | void *rzalloc(int zone, int bflags, size_t bytes) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 459 | { |
| 460 | void *ptr = NULL; |
| 461 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 462 | ptr = rmalloc(zone, bflags, bytes); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 463 | if (ptr != NULL) { |
| 464 | bzero(ptr, bytes); |
| 465 | } |
| 466 | |
| 467 | return ptr; |
| 468 | } |
| 469 | |
| 470 | /* allocates continuous buffer on 1k boundary */ |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 471 | void *rballoc(int zone, int bflags, size_t bytes) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 472 | { |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 473 | struct block_map * block_map = buf_heap_map; |
| 474 | struct mm_heap * mm_heap = &memmap.buffer; |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 475 | int i; |
| 476 | int array_size = ARRAY_SIZE(buf_heap_map); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 477 | uint32_t flags; |
| 478 | void *ptr = NULL; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 479 | |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 480 | #if (HEAP_DMA_BUFFER_SIZE > 0) |
| 481 | if (bflags & RFLAGS_DMA) { |
| 482 | mm_heap = &memmap.dma; |
| 483 | block_map = dma_buf_heap_map; |
| 484 | array_size = ARRAY_SIZE(dma_buf_heap_map); |
| 485 | } |
| 486 | #endif |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 487 | spin_lock_irq(&memmap.lock, flags); |
| 488 | |
| 489 | /* will request fit in single block */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 490 | for (i = 0; i < array_size; i++) { |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 491 | |
| 492 | /* is block big enough */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 493 | if (block_map[i].block_size < bytes) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 494 | continue; |
| 495 | |
| 496 | /* does block have free space */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 497 | if (block_map[i].free_count == 0) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 498 | continue; |
| 499 | |
| 500 | /* allocate block */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 501 | ptr = alloc_block(mm_heap, i, bflags); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 502 | goto out; |
| 503 | } |
| 504 | |
| 505 | /* request spans > 1 block */ |
| 506 | |
| 507 | /* only 1 choice for block size */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 508 | if (array_size == 1) { |
| 509 | ptr = alloc_cont_blocks(mm_heap, 0, bflags, bytes); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 510 | goto out; |
| 511 | } else { |
| 512 | |
| 513 | /* find best block size for request */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 514 | for (i = 0; i < array_size; i++) { |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 515 | |
| 516 | /* allocate is block size smaller than request */ |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 517 | if (block_map[i].block_size < bytes) |
| 518 | alloc_cont_blocks(mm_heap, i, bflags, |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 519 | bytes); |
| 520 | } |
| 521 | } |
| 522 | |
Keyon Jie | 14e2d8e | 2017-09-01 16:41:25 +0800 | [diff] [blame] | 523 | ptr = alloc_cont_blocks(mm_heap, array_size - 1, |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 524 | bflags, bytes); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 525 | |
| 526 | out: |
| 527 | spin_unlock_irq(&memmap.lock, flags); |
| 528 | return ptr; |
| 529 | } |
| 530 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 531 | void rfree(void *ptr) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 532 | { |
| 533 | uint32_t flags; |
| 534 | |
| 535 | spin_lock_irq(&memmap.lock, flags); |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 536 | free_block(&memmap.runtime, ptr); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 537 | spin_unlock_irq(&memmap.lock, flags); |
| 538 | } |
| 539 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 540 | void rbfree(void *ptr) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 541 | { |
| 542 | uint32_t flags; |
| 543 | |
| 544 | spin_lock_irq(&memmap.lock, flags); |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 545 | free_block(&memmap.buffer, ptr); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 546 | spin_unlock_irq(&memmap.lock, flags); |
| 547 | } |
| 548 | |
| 549 | uint32_t mm_pm_context_size(void) |
| 550 | { |
| 551 | uint32_t size; |
| 552 | |
| 553 | /* calc context size for each area */ |
| 554 | size = memmap.buffer.info.used; |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 555 | size += memmap.runtime.info.used; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 556 | size += memmap.system.info.used; |
| 557 | |
| 558 | /* add memory maps */ |
| 559 | size += heap_get_size(&memmap.buffer); |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 560 | size += heap_get_size(&memmap.runtime); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 561 | size += heap_get_size(&memmap.system); |
| 562 | |
| 563 | /* recalc totals */ |
| 564 | memmap.total.free = memmap.buffer.info.free + |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 565 | memmap.runtime.info.free + memmap.system.info.free; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 566 | memmap.total.used = memmap.buffer.info.used + |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 567 | memmap.runtime.info.used + memmap.system.info.used; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 568 | |
| 569 | return size; |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * Save the DSP memories that are in use the system and modules. All pipeline and modules |
| 574 | * must be disabled before calling this functions. No allocations are permitted after |
| 575 | * calling this and before calling restore. |
| 576 | */ |
Liam Girdwood | 1e5c559 | 2017-10-15 23:36:28 +0100 | [diff] [blame] | 577 | int mm_pm_context_save(struct dma_copy *dc, struct dma_sg_config *sg) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 578 | { |
| 579 | uint32_t used; |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 580 | int32_t offset = 0; |
| 581 | int32_t ret; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 582 | |
| 583 | /* first make sure SG buffer has enough space on host for DSP context */ |
| 584 | used = mm_pm_context_size(); |
| 585 | if (used > dma_sg_get_size(sg)) |
| 586 | return -EINVAL; |
| 587 | |
| 588 | /* copy memory maps to SG */ |
Liam Girdwood | 1e5c559 | 2017-10-15 23:36:28 +0100 | [diff] [blame] | 589 | ret = dma_copy_to_host(dc, sg, offset, |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 590 | (void *)&memmap, sizeof(memmap)); |
| 591 | if (ret < 0) |
| 592 | return ret; |
| 593 | |
| 594 | /* copy system memory contents to SG */ |
Liam Girdwood | 1e5c559 | 2017-10-15 23:36:28 +0100 | [diff] [blame] | 595 | ret = dma_copy_to_host(dc, sg, offset + ret, |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 596 | (void *)memmap.system.heap, (int32_t)(memmap.system.size)); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 597 | if (ret < 0) |
| 598 | return ret; |
| 599 | |
| 600 | /* copy module memory contents to SG */ |
| 601 | // TODO: iterate over module block map and copy contents of each block |
| 602 | // to the host. |
| 603 | |
| 604 | /* copy buffer memory contents to SG */ |
| 605 | // TODO: iterate over buffer block map and copy contents of each block |
| 606 | // to the host. |
| 607 | |
| 608 | return ret; |
| 609 | } |
| 610 | |
| 611 | /* |
Pierre-Louis Bossart | f945809 | 2017-11-09 15:24:07 -0600 | [diff] [blame] | 612 | * Restore the DSP memories to modules and the system. This must be called immediately |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 613 | * after booting before any pipeline work. |
| 614 | */ |
Liam Girdwood | 1e5c559 | 2017-10-15 23:36:28 +0100 | [diff] [blame] | 615 | int mm_pm_context_restore(struct dma_copy *dc, struct dma_sg_config *sg) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 616 | { |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 617 | int32_t offset = 0; |
| 618 | int32_t ret; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 619 | |
| 620 | /* copy memory maps from SG */ |
Liam Girdwood | 1e5c559 | 2017-10-15 23:36:28 +0100 | [diff] [blame] | 621 | ret = dma_copy_from_host(dc, sg, offset, |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 622 | (void *)&memmap, sizeof(memmap)); |
| 623 | if (ret < 0) |
| 624 | return ret; |
| 625 | |
| 626 | /* copy system memory contents from SG */ |
Liam Girdwood | 1e5c559 | 2017-10-15 23:36:28 +0100 | [diff] [blame] | 627 | ret = dma_copy_to_host(dc, sg, offset + ret, |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 628 | (void *)memmap.system.heap, (int32_t)(memmap.system.size)); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 629 | if (ret < 0) |
| 630 | return ret; |
| 631 | |
| 632 | /* copy module memory contents from SG */ |
| 633 | // TODO: iterate over module block map and copy contents of each block |
| 634 | // to the host. This is the same block order used by the context store |
| 635 | |
| 636 | /* copy buffer memory contents from SG */ |
| 637 | // TODO: iterate over buffer block map and copy contents of each block |
| 638 | // to the host. This is the same block order used by the context store |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | /* initialise map */ |
Liam Girdwood | 69222cf | 2017-06-06 16:41:07 +0100 | [diff] [blame] | 644 | void init_heap(struct reef *reef) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 645 | { |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 646 | struct block_map *next_map; |
| 647 | struct block_map *current_map; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 648 | int i; |
| 649 | |
| 650 | spinlock_init(&memmap.lock); |
| 651 | |
| 652 | /* initialise buffer map */ |
| 653 | current_map = &buf_heap_map[0]; |
| 654 | current_map->base = memmap.buffer.heap; |
| 655 | |
| 656 | for (i = 1; i < ARRAY_SIZE(buf_heap_map); i++) { |
| 657 | next_map = &buf_heap_map[i]; |
| 658 | next_map->base = current_map->base + |
| 659 | current_map->block_size * current_map->count; |
| 660 | current_map = &buf_heap_map[i]; |
| 661 | } |
| 662 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 663 | /* initialise runtime map */ |
| 664 | current_map = &rt_heap_map[0]; |
| 665 | current_map->base = memmap.runtime.heap; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 666 | |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 667 | for (i = 1; i < ARRAY_SIZE(rt_heap_map); i++) { |
| 668 | next_map = &rt_heap_map[i]; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 669 | next_map->base = current_map->base + |
| 670 | current_map->block_size * current_map->count; |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 671 | current_map = &rt_heap_map[i]; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 672 | } |
Liam Girdwood | 50f7b0e | 2017-06-06 12:52:15 +0100 | [diff] [blame] | 673 | |
| 674 | #if (HEAP_DMA_BUFFER_SIZE > 0) |
| 675 | /* initialise DMA map */ |
| 676 | current_map = &dma_buf_heap_map[0]; |
| 677 | current_map->base = memmap.dma.heap; |
| 678 | |
| 679 | for (i = 1; i < ARRAY_SIZE(dma_buf_heap_map); i++) { |
| 680 | next_map = &dma_buf_heap_map[i]; |
| 681 | next_map->base = current_map->base + |
| 682 | current_map->block_size * current_map->count; |
| 683 | current_map = &dma_buf_heap_map[i]; |
| 684 | } |
| 685 | #endif |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 686 | } |