blob: 0a0672cbea7557b5ce9052bad39686f9d5358f28 [file] [log] [blame]
developerf4a079c2018-11-15 10:07:52 +08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2018 MediaTek Inc.
4 */
5
6#include <linux/linkage.h>
developerce6113b2019-07-10 17:35:42 +08007#include <asm/proc-armv/ptrace.h>
developerf4a079c2018-11-15 10:07:52 +08008
developerba042512018-12-20 16:12:50 +08009#define WAIT_CODE_SRAM_BASE 0x0010ff00
10
11#define SLAVE_JUMP_REG 0x10202034
12#define SLAVE1_MAGIC_REG 0x10202038
13#define SLAVE1_MAGIC_NUM 0x534c4131
14
15#define GIC_CPU_BASE 0x10320000
16
developerf4a079c2018-11-15 10:07:52 +080017ENTRY(lowlevel_init)
18
19#ifndef CONFIG_SPL_BUILD
20 /* Return to U-Boot via saved link register */
21 mov pc, lr
22#else
23 /*
24 * Arch timer :
25 * set CNTFRQ = 20Mhz, set CNTVOFF = 0
26 */
27 movw r0, #0x2d00
28 movt r0, #0x131
29 mcr p15, 0, r0, c14, c0, 0
30
developerce6113b2019-07-10 17:35:42 +080031 cps #MON_MODE
32 mrc p15, 0, r1, c1, c1, 0 @ Get Secure Config
33 orr r0, r1, #1
34 mcr p15, 0, r0, c1, c1, 0 @ Set Non Secure bit
35 isb
36 mov r0, #0
37 mcrr p15, 4, r0, r0, c14 @ CNTVOFF = 0
38 isb
39 mcr p15, 0, r1, c1, c1, 0 @ Set Secure bit
40 isb
41 cps #SVC_MODE
42
developerf4a079c2018-11-15 10:07:52 +080043 /* enable SMP bit */
44 mrc p15, 0, r0, c1, c0, 1
45 orr r0, r0, #0x40
46 mcr p15, 0, r0, c1, c0, 1
47
48 /* if MP core, handle secondary cores */
49 mrc p15, 0, r0, c0, c0, 5
50 ands r1, r0, #0x40000000
51 bne go @ Go if UP
developerba042512018-12-20 16:12:50 +080052 /* read slave CPU number */
developerf4a079c2018-11-15 10:07:52 +080053 ands r0, r0, #0x0f
54 beq go @ Go if core0 on primary core tile
55 b secondary
56
57go:
58 /* master CPU */
59 mov pc, lr
60
61secondary:
developerba042512018-12-20 16:12:50 +080062 /* enable GIC as cores will be waken up by IPI */
63 ldr r2, =GIC_CPU_BASE
64 mov r1, #0xf0
65 str r1, [r2, #4]
66 mov r1, #1
67 str r1, [r2, #0]
developerf4a079c2018-11-15 10:07:52 +080068
developerba042512018-12-20 16:12:50 +080069 ldr r1, [r2]
70 orr r1, #1
71 str r1, [r2]
72
73 /* copy wait code into SRAM */
74 ldr r0, =slave_cpu_wait
75 ldm r0, {r1 - r8} @ slave_cpu_wait has eight insns
76 ldr r0, =WAIT_CODE_SRAM_BASE
77 stm r0, {r1 - r8}
78
79 /* pass args to slave_cpu_wait */
80 ldr r0, =SLAVE1_MAGIC_REG
81 ldr r1, =SLAVE1_MAGIC_NUM
82
83 /* jump to wait code in SRAM */
84 ldr pc, =WAIT_CODE_SRAM_BASE
85
developerf4a079c2018-11-15 10:07:52 +080086#endif
87ENDPROC(lowlevel_init)
developerba042512018-12-20 16:12:50 +080088
89/* This function will be copied into SRAM */
90ENTRY(slave_cpu_wait)
91 wfi
92 ldr r2, [r0]
93 cmp r2, r1
94 bne slave_cpu_wait
95 movw r0, #:lower16:SLAVE_JUMP_REG
96 movt r0, #:upper16:SLAVE_JUMP_REG
97 ldr r1, [r0]
98 mov pc, r1
99ENDPROC(slave_cpu_wait)