1*83d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */ 277b55e8cSThomas Abraham/* 377b55e8cSThomas Abraham * Copyright (C) 2013 Samsung Electronics 477b55e8cSThomas Abraham * Akshay Saraswat <akshay.s@samsung.com> 577b55e8cSThomas Abraham */ 677b55e8cSThomas Abraham 777b55e8cSThomas Abraham#include <config.h> 877b55e8cSThomas Abraham#include <asm/arch/cpu.h> 977b55e8cSThomas Abraham 1077b55e8cSThomas Abraham .globl relocate_wait_code 1177b55e8cSThomas Abrahamrelocate_wait_code: 1277b55e8cSThomas Abraham adr r0, code_base @ r0: source address (start) 1377b55e8cSThomas Abraham adr r1, code_end @ r1: source address (end) 1477b55e8cSThomas Abraham ldr r2, =0x02073000 @ r2: target address 1577b55e8cSThomas Abraham1: 1677b55e8cSThomas Abraham ldmia r0!, {r3-r6} 1777b55e8cSThomas Abraham stmia r2!, {r3-r6} 1877b55e8cSThomas Abraham cmp r0, r1 1977b55e8cSThomas Abraham blt 1b 2077b55e8cSThomas Abraham b code_end 2177b55e8cSThomas Abraham .ltorg 2277b55e8cSThomas Abraham/* 2377b55e8cSThomas Abraham * Secondary core waits here until Primary wake it up. 2477b55e8cSThomas Abraham * Below code is copied to CONFIG_EXYNOS_RELOCATE_CODE_BASE. 2577b55e8cSThomas Abraham * This is a workaround code which is supposed to act as a 2677b55e8cSThomas Abraham * substitute/supplement to the iROM code. 2777b55e8cSThomas Abraham * 2877b55e8cSThomas Abraham * This workaround code is relocated to the address 0x02073000 2977b55e8cSThomas Abraham * because that comes out to be the last 4KB of the iRAM 3077b55e8cSThomas Abraham * (Base Address - 0x02020000, Limit Address - 0x020740000). 3177b55e8cSThomas Abraham * 32a187559eSBin Meng * U-Boot and kernel are aware of this code and flags by the simple 3377b55e8cSThomas Abraham * fact that we are implementing a workaround in the last 4KB 3477b55e8cSThomas Abraham * of the iRAM and we have already defined these flag and address 35a187559eSBin Meng * values in both kernel and U-Boot for our use. 3677b55e8cSThomas Abraham */ 3777b55e8cSThomas Abrahamcode_base: 3877b55e8cSThomas Abraham b 1f 3977b55e8cSThomas Abraham/* 4077b55e8cSThomas Abraham * These addresses are being used as flags in u-boot and kernel. 4177b55e8cSThomas Abraham * 4277b55e8cSThomas Abraham * Jump address for resume and flag to check for resume/reset: 4377b55e8cSThomas Abraham * Resume address - 0x2073008 4477b55e8cSThomas Abraham * Resume flag - 0x207300C 4577b55e8cSThomas Abraham * 4677b55e8cSThomas Abraham * Jump address for cluster switching: 4777b55e8cSThomas Abraham * Switch address - 0x2073018 4877b55e8cSThomas Abraham * 4977b55e8cSThomas Abraham * Jump address for core hotplug: 5077b55e8cSThomas Abraham * Hotplug address - 0x207301C 5177b55e8cSThomas Abraham * 5277b55e8cSThomas Abraham * Jump address for C2 state (Reserved for future not being used right now): 5377b55e8cSThomas Abraham * C2 address - 0x2073024 5477b55e8cSThomas Abraham * 5577b55e8cSThomas Abraham * Managed per core status for the active cluster: 5677b55e8cSThomas Abraham * CPU0 state - 0x2073028 5777b55e8cSThomas Abraham * CPU1 state - 0x207302C 5877b55e8cSThomas Abraham * CPU2 state - 0x2073030 5977b55e8cSThomas Abraham * CPU3 state - 0x2073034 6077b55e8cSThomas Abraham * 6177b55e8cSThomas Abraham * Managed per core GIC status for the active cluster: 6277b55e8cSThomas Abraham * CPU0 gic state - 0x2073038 6377b55e8cSThomas Abraham * CPU1 gic state - 0x207303C 6477b55e8cSThomas Abraham * CPU2 gic state - 0x2073040 6577b55e8cSThomas Abraham * CPU3 gic state - 0x2073044 6677b55e8cSThomas Abraham * 6777b55e8cSThomas Abraham * Logic of the code: 6877b55e8cSThomas Abraham * Step-1: Read current CPU status. 6977b55e8cSThomas Abraham * Step-2: If it's a resume then continue, else jump to step 4. 7077b55e8cSThomas Abraham * Step-3: Clear inform1 PMU register and jump to inform0 value. 7177b55e8cSThomas Abraham * Step-4: If it's a switch, C2 or reset, get the hotplug address. 7277b55e8cSThomas Abraham * Step-5: If address is not available, enter WFE. 7377b55e8cSThomas Abraham * Step-6: If address is available, jump to that address. 7477b55e8cSThomas Abraham */ 7577b55e8cSThomas Abraham nop @ for backward compatibility 7677b55e8cSThomas Abraham .word 0x0 @ REG0: RESUME_ADDR 7777b55e8cSThomas Abraham .word 0x0 @ REG1: RESUME_FLAG 7877b55e8cSThomas Abraham .word 0x0 @ REG2 7977b55e8cSThomas Abraham .word 0x0 @ REG3 8077b55e8cSThomas Abraham_switch_addr: 8177b55e8cSThomas Abraham .word 0x0 @ REG4: SWITCH_ADDR 8277b55e8cSThomas Abraham_hotplug_addr: 8377b55e8cSThomas Abraham .word 0x0 @ REG5: CPU1_BOOT_REG 8477b55e8cSThomas Abraham .word 0x0 @ REG6 8577b55e8cSThomas Abraham_c2_addr: 8677b55e8cSThomas Abraham .word 0x0 @ REG7: REG_C2_ADDR 8777b55e8cSThomas Abraham_cpu_state: 8877b55e8cSThomas Abraham .word 0x1 @ CPU0_STATE : RESET 8977b55e8cSThomas Abraham .word 0x2 @ CPU1_STATE : SECONDARY RESET 9077b55e8cSThomas Abraham .word 0x2 @ CPU2_STATE : SECONDARY RESET 9177b55e8cSThomas Abraham .word 0x2 @ CPU3_STATE : SECONDARY RESET 9277b55e8cSThomas Abraham_gic_state: 9377b55e8cSThomas Abraham .word 0x0 @ CPU0 - GICD_IGROUPR0 9477b55e8cSThomas Abraham .word 0x0 @ CPU1 - GICD_IGROUPR0 9577b55e8cSThomas Abraham .word 0x0 @ CPU2 - GICD_IGROUPR0 9677b55e8cSThomas Abraham .word 0x0 @ CPU3 - GICD_IGROUPR0 9777b55e8cSThomas Abraham1: 9877b55e8cSThomas Abraham adr r0, _cpu_state 9977b55e8cSThomas Abraham mrc p15, 0, r7, c0, c0, 5 @ read MPIDR 10077b55e8cSThomas Abraham and r7, r7, #0xf @ r7 = cpu id 10177b55e8cSThomas Abraham/* Read the current cpu state */ 10277b55e8cSThomas Abraham ldr r10, [r0, r7, lsl #2] 10377b55e8cSThomas Abrahamsvc_entry: 10477b55e8cSThomas Abraham tst r10, #(1 << 4) 10577b55e8cSThomas Abraham adrne r0, _switch_addr 10677b55e8cSThomas Abraham bne wait_for_addr 10777b55e8cSThomas Abraham/* Clear INFORM1 */ 10877b55e8cSThomas Abraham ldr r0, =(0x10040000 + 0x804) 10977b55e8cSThomas Abraham ldr r1, [r0] 11077b55e8cSThomas Abraham cmp r1, #0x0 11177b55e8cSThomas Abraham movne r1, #0x0 11277b55e8cSThomas Abraham strne r1, [r0] 11377b55e8cSThomas Abraham/* Get INFORM0 */ 11477b55e8cSThomas Abraham ldrne r1, =(0x10040000 + 0x800) 11577b55e8cSThomas Abraham ldrne pc, [r1] 11677b55e8cSThomas Abraham tst r10, #(1 << 0) 11777b55e8cSThomas Abraham ldrne pc, =0x23e00000 11877b55e8cSThomas Abraham adr r0, _hotplug_addr 11977b55e8cSThomas Abrahamwait_for_addr: 12077b55e8cSThomas Abraham ldr r1, [r0] 12177b55e8cSThomas Abraham cmp r1, #0x0 12277b55e8cSThomas Abraham bxne r1 12377b55e8cSThomas Abraham wfe 12477b55e8cSThomas Abraham b wait_for_addr 12577b55e8cSThomas Abraham .ltorg 12677b55e8cSThomas Abrahamcode_end: 12777b55e8cSThomas Abraham mov pc, lr 128