blob: 910b153414c93bb953580eb82a7f2e3d81dd97ea [file] [log] [blame]
Andrew Thoelke8c28fe02014-06-02 11:40:35 +01001/*
Soby Mathewa0fedc42016-06-16 14:52:04 +01002 * Copyright (c) 2014-2016, ARM Limited and Contributors. All rights reserved.
Andrew Thoelke8c28fe02014-06-02 11:40:35 +01003 *
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
Soby Mathew748be1d2016-05-05 14:10:46 +010034#ifdef AARCH32
35
36#if CRASH_REPORTING
37#error "Crash reporting is not supported in AArch32"
38#endif
39#define CPU_DATA_CPU_OPS_PTR 0x0
40
41#else /* AARCH32 */
42
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010043/* Offsets for the cpu_data structure */
Soby Mathew523d6332015-01-08 18:02:19 +000044#define CPU_DATA_CRASH_BUF_OFFSET 0x18
Soby Mathew748be1d2016-05-05 14:10:46 +010045/* need enough space in crash buffer to save 8 registers */
46#define CPU_DATA_CRASH_BUF_SIZE 64
47#define CPU_DATA_CPU_OPS_PTR 0x10
48
49#endif /* AARCH32 */
50
Soby Mathewc1adbbc2014-06-25 10:07:40 +010051#if CRASH_REPORTING
52#define CPU_DATA_LOG2SIZE 7
53#else
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010054#define CPU_DATA_LOG2SIZE 6
Soby Mathewc1adbbc2014-06-25 10:07:40 +010055#endif
Soby Mathewc704cbc2014-08-14 11:33:56 +010056
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010057#ifndef __ASSEMBLY__
58
59#include <arch_helpers.h>
Soby Mathew523d6332015-01-08 18:02:19 +000060#include <cassert.h>
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010061#include <platform_def.h>
Achin Guptaf3ccbab2014-07-25 14:52:47 +010062#include <psci.h>
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010063#include <stdint.h>
64
Soby Mathew523d6332015-01-08 18:02:19 +000065/* Offsets for the cpu_data structure */
66#define CPU_DATA_PSCI_LOCK_OFFSET __builtin_offsetof\
67 (cpu_data_t, psci_svc_cpu_data.pcpu_bakery_info)
68
69#if PLAT_PCPU_DATA_SIZE
70#define CPU_DATA_PLAT_PCPU_OFFSET __builtin_offsetof\
71 (cpu_data_t, platform_cpu_data)
72#endif
73
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010074/*******************************************************************************
75 * Function & variable prototypes
76 ******************************************************************************/
77
78/*******************************************************************************
79 * Cache of frequently used per-cpu data:
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010080 * Pointers to non-secure and secure security state contexts
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010081 * Address of the crash stack
82 * It is aligned to the cache line boundary to allow efficient concurrent
83 * manipulation of these pointers on different cpus
84 *
85 * TODO: Add other commonly used variables to this (tf_issues#90)
86 *
87 * The data structure and the _cpu_data accessors should not be used directly
88 * by components that have per-cpu members. The member access macros should be
89 * used for this.
90 ******************************************************************************/
Andrew Thoelke8c28fe02014-06-02 11:40:35 +010091typedef struct cpu_data {
Soby Mathew748be1d2016-05-05 14:10:46 +010092#ifndef AARCH32
Andrew Thoelkec02dbd62014-06-02 10:00:25 +010093 void *cpu_context[2];
Soby Mathew748be1d2016-05-05 14:10:46 +010094#endif
Soby Mathewa0fedc42016-06-16 14:52:04 +010095 uintptr_t cpu_ops_ptr;
Soby Mathewc1adbbc2014-06-25 10:07:40 +010096#if CRASH_REPORTING
Soby Mathewa0fedc42016-06-16 14:52:04 +010097 u_register_t crash_buf[CPU_DATA_CRASH_BUF_SIZE >> 3];
Soby Mathewc1adbbc2014-06-25 10:07:40 +010098#endif
Soby Mathew523d6332015-01-08 18:02:19 +000099 struct psci_cpu_data psci_svc_cpu_data;
100#if PLAT_PCPU_DATA_SIZE
101 uint8_t platform_cpu_data[PLAT_PCPU_DATA_SIZE];
102#endif
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100103} __aligned(CACHE_WRITEBACK_GRANULE) cpu_data_t;
104
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100105#if CRASH_REPORTING
106/* verify assembler offsets match data structures */
107CASSERT(CPU_DATA_CRASH_BUF_OFFSET == __builtin_offsetof
108 (cpu_data_t, crash_buf),
109 assert_cpu_data_crash_stack_offset_mismatch);
110#endif
111
112CASSERT((1 << CPU_DATA_LOG2SIZE) == sizeof(cpu_data_t),
113 assert_cpu_data_log2size_mismatch);
114
Soby Mathewc704cbc2014-08-14 11:33:56 +0100115CASSERT(CPU_DATA_CPU_OPS_PTR == __builtin_offsetof
116 (cpu_data_t, cpu_ops_ptr),
117 assert_cpu_data_cpu_ops_ptr_offset_mismatch);
118
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100119struct cpu_data *_cpu_data_by_index(uint32_t cpu_index);
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100120
Soby Mathew748be1d2016-05-05 14:10:46 +0100121#ifndef AARCH32
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100122/* Return the cpu_data structure for the current CPU. */
123static inline struct cpu_data *_cpu_data(void)
124{
125 return (cpu_data_t *)read_tpidr_el3();
126}
Soby Mathew748be1d2016-05-05 14:10:46 +0100127#else
128struct cpu_data *_cpu_data(void);
129#endif
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100130
131/**************************************************************************
132 * APIs for initialising and accessing per-cpu data
133 *************************************************************************/
134
135void init_cpu_data_ptr(void);
Vikram Kanigiri9b38fc82015-01-29 18:27:38 +0000136void init_cpu_ops(void);
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100137
138#define get_cpu_data(_m) _cpu_data()->_m
139#define set_cpu_data(_m, _v) _cpu_data()->_m = _v
140#define get_cpu_data_by_index(_ix, _m) _cpu_data_by_index(_ix)->_m
141#define set_cpu_data_by_index(_ix, _m, _v) _cpu_data_by_index(_ix)->_m = _v
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100142
Soby Mathew24ab34f2016-05-03 17:11:42 +0100143#define flush_cpu_data(_m) flush_dcache_range((uintptr_t) \
Achin Guptae4b9fa42014-07-25 14:47:05 +0100144 &(_cpu_data()->_m), \
145 sizeof(_cpu_data()->_m))
Soby Mathew24ab34f2016-05-03 17:11:42 +0100146#define inv_cpu_data(_m) inv_dcache_range((uintptr_t) \
Soby Mathew85dbf5a2015-04-07 12:16:56 +0100147 &(_cpu_data()->_m), \
148 sizeof(_cpu_data()->_m))
Soby Mathew7d861ea2014-11-18 10:14:14 +0000149#define flush_cpu_data_by_index(_ix, _m) \
Soby Mathewa0fedc42016-06-16 14:52:04 +0100150 flush_dcache_range((uintptr_t) \
Soby Mathew7d861ea2014-11-18 10:14:14 +0000151 &(_cpu_data_by_index(_ix)->_m), \
152 sizeof(_cpu_data_by_index(_ix)->_m))
Achin Guptae4b9fa42014-07-25 14:47:05 +0100153
Andrew Thoelke8c28fe02014-06-02 11:40:35 +0100154
155#endif /* __ASSEMBLY__ */
156#endif /* __CPU_DATA_H__ */