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