| 1 |
|
| 2 |
|
| 3 |
#include <arch/cpu.h> |
| 4 |
#include <device/mmio.h> |
| 5 |
#include <soc/cpu.h> |
| 6 |
#include <soc/power.h> |
| 7 |
#include <string.h> |
| 8 |
#include <types.h> |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#define ACTLR_SMP (1 << 6) |
| 13 |
|
| 14 |
#define L2CTLR_ECC_PARITY (1 << 21) |
| 15 |
#define L2CTLR_DATA_RAM_LATENCY_MASK (7 << 0) |
| 16 |
#define L2CTLR_TAG_RAM_LATENCY_MASK (7 << 6) |
| 17 |
#define L2CTLR_DATA_RAM_LATENCY_CYCLES_3 (2 << 0) |
| 18 |
#define L2CTLR_TAG_RAM_LATENCY_CYCLES_3 (2 << 6) |
| 19 |
|
| 20 |
#define L2ACTLR_DISABLE_CLEAN_EVICT_PUSH_EXTERNAL (1 << 3) |
| 21 |
#define L2ACTLR_ENABLE_HAZARD_DETECT_TIMEOUT (1 << 7) |
| 22 |
#define L2ACTLR_FORCE_L2_LOGIC_CLOCK_ENABLE_ACTIVE (1 << 27) |
| 23 |
|
| 24 |
|
| 25 |
#define PART_NUMBER_CORTEX_A15 (0xc0f) |
| 26 |
|
| 27 |
|
| 28 |
#define CORE_STATE_RESET (1 << 0) |
| 29 |
#define CORE_STATE_SECONDARY_RESET (1 << 1) |
| 30 |
#define CORE_STATE_SWITCH_CLUSTER (1 << 4) |
| 31 |
|
| 32 |
|
| 33 |
#define CORE_RESET_INIT_ADDRESS ((void *)0x00000000) |
| 34 |
|
| 35 |
|
| 36 |
#define VECTOR_CORE_SEV_HANDLER ((void *)(intptr_t)0x02020004) |
| 37 |
#define VECTOR_LOW_POWER_FLAG ((void *)(intptr_t)0x02020028) |
| 38 |
#define VECTOR_LOW_POWER_ADDRESS ((void *)(intptr_t)0x0202002C) |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
volatile struct exynos5420_cpu_states |
| 45 |
{ |
| 46 |
uint32_t _reserved[2]; |
| 47 |
uint32_t resume_address; |
| 48 |
uint32_t resume_flag; |
| 49 |
uint32_t _reg2; |
| 50 |
uint32_t _reg3; |
| 51 |
uint32_t switch_address; |
| 52 |
uint32_t hotplug_address; |
| 53 |
uint32_t _reg6; |
| 54 |
uint32_t c2_address; |
| 55 |
|
| 56 |
|
| 57 |
uint32_t cpu_states[4]; |
| 58 |
|
| 59 |
|
| 60 |
uint32_t cpu_gic_states[4]; |
| 61 |
} *exynos_cpu_states = (volatile struct exynos5420_cpu_states*)0x02073000; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
static inline void jump_bx(void *address) |
| 68 |
{ |
| 69 |
asm volatile ("bx %0" : : "r"(address)); |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
static inline uint32_t get_bits(uint32_t value, uint32_t start, uint32_t len) |
| 75 |
{ |
| 76 |
return ((value << (sizeof(value) * 8 - len - start)) >> |
| 77 |
(sizeof(value) * 8 - len)); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
static void wait_and_jump(volatile uint32_t *reference) |
| 82 |
{ |
| 83 |
while (!*reference) { |
| 84 |
wfe(); |
| 85 |
} |
| 86 |
jump_bx((void *)*reference); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
static void configure_l2ctlr(void) |
| 91 |
{ |
| 92 |
uint32_t val; |
| 93 |
|
| 94 |
val = read_l2ctlr(); |
| 95 |
val &= ~(L2CTLR_DATA_RAM_LATENCY_MASK | L2CTLR_TAG_RAM_LATENCY_MASK); |
| 96 |
val |= (L2CTLR_DATA_RAM_LATENCY_CYCLES_3 | L2CTLR_TAG_RAM_LATENCY_CYCLES_3 | |
| 97 |
L2CTLR_ECC_PARITY); |
| 98 |
write_l2ctlr(val); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
static void configure_l2actlr(void) |
| 103 |
{ |
| 104 |
uint32_t val; |
| 105 |
|
| 106 |
val = read_l2actlr(); |
| 107 |
val |= (L2ACTLR_DISABLE_CLEAN_EVICT_PUSH_EXTERNAL | |
| 108 |
L2ACTLR_ENABLE_HAZARD_DETECT_TIMEOUT | |
| 109 |
L2ACTLR_FORCE_L2_LOGIC_CLOCK_ENABLE_ACTIVE); |
| 110 |
write_l2actlr(val); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
static void init_exynos_cpu_states(void) { |
| 115 |
memset((void *)exynos_cpu_states, 0, sizeof(*exynos_cpu_states)); |
| 116 |
exynos_cpu_states->cpu_states[0] = CORE_STATE_RESET; |
| 117 |
exynos_cpu_states->cpu_states[1] = CORE_STATE_SECONDARY_RESET; |
| 118 |
exynos_cpu_states->cpu_states[2] = CORE_STATE_SECONDARY_RESET; |
| 119 |
exynos_cpu_states->cpu_states[3] = CORE_STATE_SECONDARY_RESET; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
static void enable_smp(void) |
| 128 |
{ |
| 129 |
uint32_t actlr, val; |
| 130 |
|
| 131 |
|
| 132 |
actlr = read_actlr(); |
| 133 |
actlr |= ACTLR_SMP; |
| 134 |
|
| 135 |
|
| 136 |
val = read32(&exynos_power->inform0); |
| 137 |
val &= 0; |
| 138 |
actlr |= val; |
| 139 |
|
| 140 |
write_actlr(actlr); |
| 141 |
dsb(); |
| 142 |
isb(); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
static void core_start_execution(void) |
| 147 |
{ |
| 148 |
u32 cpu_id, cpu_state; |
| 149 |
|
| 150 |
enable_smp(); |
| 151 |
set_system_mode(); |
| 152 |
|
| 153 |
cpu_id = read_mpidr() & 0x3; |
| 154 |
cpu_state = exynos_cpu_states->cpu_states[cpu_id]; |
| 155 |
|
| 156 |
if (cpu_state & CORE_STATE_SWITCH_CLUSTER) { |
| 157 |
wait_and_jump(&exynos_cpu_states->switch_address); |
| 158 |
|
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
if (exynos_power->inform1) { |
| 163 |
exynos_power->inform1 = 0; |
| 164 |
jump_bx((void *)exynos_power->inform0); |
| 165 |
|
| 166 |
} |
| 167 |
|
| 168 |
if (cpu_state & CORE_STATE_RESET) { |
| 169 |
|
| 170 |
|
| 171 |
} |
| 172 |
wait_and_jump(&exynos_cpu_states->hotplug_address); |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
static void low_power_start(void) |
| 178 |
{ |
| 179 |
uint32_t sctlr, reg_val; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
reg_val = read32(&exynos_power->spare0); |
| 185 |
if (reg_val != RST_FLAG_VAL) { |
| 186 |
write32(VECTOR_LOW_POWER_FLAG, 0x0); |
| 187 |
jump_bx(CORE_RESET_INIT_ADDRESS); |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
reg_val = read32(VECTOR_CORE_SEV_HANDLER); |
| 196 |
if (reg_val != (intptr_t)low_power_start) { |
| 197 |
write32(VECTOR_CORE_SEV_HANDLER, (intptr_t)low_power_start); |
| 198 |
dsb(); |
| 199 |
|
| 200 |
sev(); |
| 201 |
} |
| 202 |
|
| 203 |
set_system_mode(); |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
if (get_bits(read_midr(), 4, 12) == PART_NUMBER_CORTEX_A15) { |
| 208 |
configure_l2ctlr(); |
| 209 |
configure_l2actlr(); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
tlbiall(); |
| 214 |
iciallu(); |
| 215 |
|
| 216 |
|
| 217 |
sctlr = read_sctlr(); |
| 218 |
sctlr &= ~(SCTLR_V | SCTLR_M | SCTLR_C); |
| 219 |
sctlr |= (SCTLR_I | SCTLR_Z | SCTLR_A); |
| 220 |
write_sctlr(sctlr); |
| 221 |
|
| 222 |
core_start_execution(); |
| 223 |
|
| 224 |
|
| 225 |
wfi(); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
static void power_down_core(void) |
| 230 |
{ |
| 231 |
uint32_t mpidr, core_id; |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
mpidr = read_mpidr(); |
| 236 |
core_id = get_bits(mpidr, 0, 2) | (get_bits(mpidr, 8, 4) << 2); |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
write32(&exynos_power->arm_core[core_id].config, 0x0); |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
wfi(); |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
static void configure_secondary_cores(void) |
| 252 |
{ |
| 253 |
if (get_bits(read_midr(), 4, 12) == PART_NUMBER_CORTEX_A15) { |
| 254 |
configure_l2ctlr(); |
| 255 |
configure_l2actlr(); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
write32((void *)&exynos_cpu_states->hotplug_address, 0); |
| 266 |
|
| 267 |
|
| 268 |
write32(VECTOR_LOW_POWER_ADDRESS, (intptr_t)low_power_start); |
| 269 |
write32(VECTOR_LOW_POWER_FLAG, RST_FLAG_VAL); |
| 270 |
write32(&exynos_power->spare0, RST_FLAG_VAL); |
| 271 |
|
| 272 |
|
| 273 |
write32(VECTOR_CORE_SEV_HANDLER, (intptr_t)power_down_core); |
| 274 |
|
| 275 |
|
| 276 |
dsb(); |
| 277 |
sev(); |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
void exynos5420_config_smp(void) |
| 283 |
{ |
| 284 |
init_exynos_cpu_states(); |
| 285 |
configure_secondary_cores(); |
| 286 |
} |