| /* |
| * Copyright (c) 2018, Intel Corporation |
| * All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are met: |
| * * Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * * Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * * Neither the name of the Intel Corporation nor the |
| * names of its contributors may be used to endorse or promote products |
| * derived from this software without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| * POSSIBILITY OF SUCH DAMAGE. |
| * |
| * Author: Tomasz Lauda <tomasz.lauda@linux.intel.com> |
| */ |
| |
| /** |
| * \file arch/xtensa/smp/include/arch/alloc.h |
| * \brief Xtensa SMP memory allocation header file |
| * \authors Tomasz Lauda <tomasz.lauda@linux.intel.com> |
| */ |
| |
| #ifndef __ARCH_ALLOC_H__ |
| #define __ARCH_ALLOC_H__ |
| |
| #include <xtos-structs.h> |
| #include <sof/alloc.h> |
| |
| extern struct core_context *core_ctx_ptr[PLATFORM_CORE_COUNT]; |
| extern struct xtos_core_data *core_data_ptr[PLATFORM_CORE_COUNT]; |
| |
| /** |
| * \brief Allocates memory for core specific data. |
| * \param[in] core Slave core for which data needs to be allocated. |
| */ |
| static inline void alloc_core_context(int core) |
| { |
| struct core_context *core_ctx; |
| |
| core_ctx = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(*core_ctx)); |
| dcache_writeback_invalidate_region(core_ctx, sizeof(*core_ctx)); |
| |
| /* xtos_core_data is a big struct, so allocate it from system heap |
| * and never free again. Allocating from runtime heap would be |
| * a waste of a very big memory block. |
| */ |
| if (!core_data_ptr[core]) |
| core_data_ptr[core] = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, |
| sizeof(*core_data_ptr[core])); |
| |
| core_data_ptr[core]->thread_data_ptr = &core_ctx->td; |
| dcache_writeback_invalidate_region(core_data_ptr[core], |
| sizeof(*core_data_ptr[core])); |
| |
| dcache_writeback_invalidate_region(core_data_ptr, |
| sizeof(core_data_ptr)); |
| |
| core_ctx_ptr[core] = core_ctx; |
| dcache_writeback_invalidate_region(core_ctx_ptr, |
| sizeof(core_ctx_ptr)); |
| } |
| |
| /** |
| * \brief Frees memory allocated for core specific data. |
| * \param[in] core Slave core for which data needs to be freed. |
| */ |
| static inline void free_core_context(int core) |
| { |
| rfree(core_ctx_ptr[core]); |
| dcache_writeback_invalidate_region(core_ctx_ptr[core], |
| sizeof(*core_ctx_ptr[core])); |
| } |
| |
| #endif |