|
| 1 | +/* |
| 2 | + * Copyright (c) 2018, 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: Tomasz Lauda <tomasz.lauda@linux.intel.com> |
| 29 | + */ |
| 30 | + |
| 31 | +/** |
| 32 | + * \file arch/xtensa/smp/include/arch/alloc.h |
| 33 | + * \brief Xtensa SMP memory allocation header file |
| 34 | + * \authors Tomasz Lauda <tomasz.lauda@linux.intel.com> |
| 35 | + */ |
| 36 | + |
| 37 | +#ifndef __ARCH_ALLOC_H__ |
| 38 | +#define __ARCH_ALLOC_H__ |
| 39 | + |
| 40 | +#include <xtos-structs.h> |
| 41 | +#include <sof/alloc.h> |
| 42 | + |
| 43 | +extern struct core_context *core_ctx_ptr[PLATFORM_CORE_COUNT]; |
| 44 | +extern struct xtos_core_data *core_data_ptr[PLATFORM_CORE_COUNT]; |
| 45 | + |
| 46 | +/** |
| 47 | + * \brief Allocates memory for core specific data. |
| 48 | + * \param[in] core Slave core for which data needs to be allocated. |
| 49 | + */ |
| 50 | +static inline void alloc_core_context(int core) |
| 51 | +{ |
| 52 | + struct core_context *core_ctx; |
| 53 | + |
| 54 | + core_ctx = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(*core_ctx)); |
| 55 | + dcache_writeback_invalidate_region(core_ctx, sizeof(*core_ctx)); |
| 56 | + |
| 57 | + /* xtos_core_data is a big struct, so allocate it from system heap |
| 58 | + * and never free again. Allocating from runtime heap would be |
| 59 | + * a waste of a very big memory block. |
| 60 | + */ |
| 61 | + if (!core_data_ptr[core]) |
| 62 | + core_data_ptr[core] = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, |
| 63 | + sizeof(*core_data_ptr[core])); |
| 64 | + |
| 65 | + core_data_ptr[core]->thread_data_ptr = &core_ctx->td; |
| 66 | + dcache_writeback_invalidate_region(core_data_ptr[core], |
| 67 | + sizeof(*core_data_ptr[core])); |
| 68 | + |
| 69 | + dcache_writeback_invalidate_region(core_data_ptr, |
| 70 | + sizeof(core_data_ptr)); |
| 71 | + |
| 72 | + core_ctx_ptr[core] = core_ctx; |
| 73 | + dcache_writeback_invalidate_region(core_ctx_ptr, |
| 74 | + sizeof(core_ctx_ptr)); |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * \brief Frees memory allocated for core specific data. |
| 79 | + * \param[in] core Slave core for which data needs to be freed. |
| 80 | + */ |
| 81 | +static inline void free_core_context(int core) |
| 82 | +{ |
| 83 | + rfree(core_ctx_ptr[core]); |
| 84 | + dcache_writeback_invalidate_region(core_ctx_ptr[core], |
| 85 | + sizeof(*core_ctx_ptr[core])); |
| 86 | +} |
| 87 | + |
| 88 | +#endif |
0 commit comments