blob: ba7ae0633597a83f8625e7d470910f86e2047081 [file] [log] [blame]
Andrew Thoelke8c28fe02014-06-02 11:40:35 +01001/*
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 */
Soby Mathewc704cbc2014-08-14 11:33:56 +010035#define CPU_DATA_CRASH_BUF_OFFSET 0x20
Soby Mathewc1adbbc2014-06-25 10:07:40 +010036#if CRASH_REPORTING
37#define CPU_DATA_LOG2SIZE 7
38#else
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010039#define CPU_DATA_LOG2SIZE 6
Soby Mathewc1adbbc2014-06-25 10:07:40 +010040#endif
41/* need enough space in crash buffer to save 8 registers */
Soby Mathewc704cbc2014-08-14 11:33:56 +010042#define CPU_DATA_CRASH_BUF_SIZE 64
43#define CPU_DATA_CPU_OPS_PTR 0x10
44
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010045#ifndef __ASSEMBLY__
46
47#include <arch_helpers.h>
48#include <platform_def.h>
Achin Guptaf3ccbab2014-07-25 14:52:47 +010049#include <psci.h>
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010050#include <stdint.h>
51
52/*******************************************************************************
53 * Function & variable prototypes
54 ******************************************************************************/
55
56/*******************************************************************************
57 * Cache of frequently used per-cpu data:
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010058 * Pointers to non-secure and secure security state contexts
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010059 * Address of the crash stack
60 * It is aligned to the cache line boundary to allow efficient concurrent
61 * manipulation of these pointers on different cpus
62 *
63 * TODO: Add other commonly used variables to this (tf_issues#90)
64 *
65 * The data structure and the _cpu_data accessors should not be used directly
66 * by components that have per-cpu members. The member access macros should be
67 * used for this.
68 ******************************************************************************/
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010069typedef struct cpu_data {
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010070 void *cpu_context[2];
Soby Mathewc704cbc2014-08-14 11:33:56 +010071 uint64_t cpu_ops_ptr;
72 struct psci_cpu_data psci_svc_cpu_data;
Soby Mathewc1adbbc2014-06-25 10:07:40 +010073#if CRASH_REPORTING
74 uint64_t crash_buf[CPU_DATA_CRASH_BUF_SIZE >> 3];
75#endif
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010076} __aligned(CACHE_WRITEBACK_GRANULE) cpu_data_t;
77
Soby Mathewc1adbbc2014-06-25 10:07:40 +010078#if CRASH_REPORTING
79/* verify assembler offsets match data structures */
80CASSERT(CPU_DATA_CRASH_BUF_OFFSET == __builtin_offsetof
81 (cpu_data_t, crash_buf),
82 assert_cpu_data_crash_stack_offset_mismatch);
83#endif
84
85CASSERT((1 << CPU_DATA_LOG2SIZE) == sizeof(cpu_data_t),
86 assert_cpu_data_log2size_mismatch);
87
Soby Mathewc704cbc2014-08-14 11:33:56 +010088CASSERT(CPU_DATA_CPU_OPS_PTR == __builtin_offsetof
89 (cpu_data_t, cpu_ops_ptr),
90 assert_cpu_data_cpu_ops_ptr_offset_mismatch);
91
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010092struct cpu_data *_cpu_data_by_index(uint32_t cpu_index);
93struct cpu_data *_cpu_data_by_mpidr(uint64_t mpidr);
94
95/* Return the cpu_data structure for the current CPU. */
96static inline struct cpu_data *_cpu_data(void)
97{
98 return (cpu_data_t *)read_tpidr_el3();
99}
100
101
102/**************************************************************************
103 * APIs for initialising and accessing per-cpu data
104 *************************************************************************/
105
106void init_cpu_data_ptr(void);
107
108#define get_cpu_data(_m) _cpu_data()->_m
109#define set_cpu_data(_m, _v) _cpu_data()->_m = _v
110#define get_cpu_data_by_index(_ix, _m) _cpu_data_by_index(_ix)->_m
111#define set_cpu_data_by_index(_ix, _m, _v) _cpu_data_by_index(_ix)->_m = _v
112#define get_cpu_data_by_mpidr(_id, _m) _cpu_data_by_mpidr(_id)->_m
113#define set_cpu_data_by_mpidr(_id, _m, _v) _cpu_data_by_mpidr(_id)->_m = _v
114
Achin Guptae4b9fa42014-07-25 14:47:05 +0100115#define flush_cpu_data(_m) flush_dcache_range((uint64_t) \
116 &(_cpu_data()->_m), \
117 sizeof(_cpu_data()->_m))
118
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100119
120#endif /* __ASSEMBLY__ */
121#endif /* __CPU_DATA_H__ */