Andrew Thoelke | 8c28fe0 | 2014-06-02 11:40:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __CPU_DATA_H__ |
| 32 | #define __CPU_DATA_H__ |
| 33 | |
| 34 | /* Offsets for the cpu_data structure */ |
Andrew Thoelke | c02dbd6 | 2014-06-02 10:00:25 +0100 | [diff] [blame] | 35 | #define CPU_DATA_CRASH_STACK_OFFSET 0x10 |
Andrew Thoelke | 8c28fe0 | 2014-06-02 11:40:35 +0100 | [diff] [blame] | 36 | #define CPU_DATA_LOG2SIZE 6 |
| 37 | |
| 38 | #ifndef __ASSEMBLY__ |
| 39 | |
| 40 | #include <arch_helpers.h> |
| 41 | #include <platform_def.h> |
| 42 | #include <stdint.h> |
| 43 | |
| 44 | /******************************************************************************* |
| 45 | * Function & variable prototypes |
| 46 | ******************************************************************************/ |
| 47 | |
| 48 | /******************************************************************************* |
| 49 | * Cache of frequently used per-cpu data: |
Andrew Thoelke | c02dbd6 | 2014-06-02 10:00:25 +0100 | [diff] [blame] | 50 | * Pointers to non-secure and secure security state contexts |
Andrew Thoelke | 8c28fe0 | 2014-06-02 11:40:35 +0100 | [diff] [blame] | 51 | * Address of the crash stack |
| 52 | * It is aligned to the cache line boundary to allow efficient concurrent |
| 53 | * manipulation of these pointers on different cpus |
| 54 | * |
| 55 | * TODO: Add other commonly used variables to this (tf_issues#90) |
| 56 | * |
| 57 | * The data structure and the _cpu_data accessors should not be used directly |
| 58 | * by components that have per-cpu members. The member access macros should be |
| 59 | * used for this. |
| 60 | ******************************************************************************/ |
| 61 | |
| 62 | typedef struct cpu_data { |
Andrew Thoelke | c02dbd6 | 2014-06-02 10:00:25 +0100 | [diff] [blame] | 63 | void *cpu_context[2]; |
Andrew Thoelke | 8c28fe0 | 2014-06-02 11:40:35 +0100 | [diff] [blame] | 64 | uint64_t crash_stack; |
| 65 | } __aligned(CACHE_WRITEBACK_GRANULE) cpu_data_t; |
| 66 | |
| 67 | struct cpu_data *_cpu_data_by_index(uint32_t cpu_index); |
| 68 | struct cpu_data *_cpu_data_by_mpidr(uint64_t mpidr); |
| 69 | |
| 70 | /* Return the cpu_data structure for the current CPU. */ |
| 71 | static inline struct cpu_data *_cpu_data(void) |
| 72 | { |
| 73 | return (cpu_data_t *)read_tpidr_el3(); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /************************************************************************** |
| 78 | * APIs for initialising and accessing per-cpu data |
| 79 | *************************************************************************/ |
| 80 | |
| 81 | void init_cpu_data_ptr(void); |
| 82 | |
| 83 | #define get_cpu_data(_m) _cpu_data()->_m |
| 84 | #define set_cpu_data(_m, _v) _cpu_data()->_m = _v |
| 85 | #define get_cpu_data_by_index(_ix, _m) _cpu_data_by_index(_ix)->_m |
| 86 | #define set_cpu_data_by_index(_ix, _m, _v) _cpu_data_by_index(_ix)->_m = _v |
| 87 | #define get_cpu_data_by_mpidr(_id, _m) _cpu_data_by_mpidr(_id)->_m |
| 88 | #define set_cpu_data_by_mpidr(_id, _m, _v) _cpu_data_by_mpidr(_id)->_m = _v |
| 89 | |
| 90 | |
| 91 | #endif /* __ASSEMBLY__ */ |
| 92 | #endif /* __CPU_DATA_H__ */ |