1111#include <asm/gic.h>
1212#include <asm/armv7.h>
1313#include <asm/proc - armv/ptrace.h>
14+ #ifdef CONFIG_ARMV7_TEE
15+ #ifndef CONFIG_OPTEE_ENTRY
16+ #error "error optee entry"
17+ #endif
18+ #define OPTEE_ENTRY CONFIG_OPTEE_ENTRY
19+ #endif
1420
1521.arch_extension sec
1622.arch_extension virt
1723
1824 .pushsection ._secure.text , "ax"
1925
2026 . align 5
27+ / * Ugly code which can only boot smp 2 cores , enough for 7d * /
28+ _regs_save:
29+ . word 0
30+ . word 0
31+ . word 0
32+ . word 0
33+ . word 0
34+ . word 0
35+ . word 0
36+ . word 0
37+ . word 0
38+ . word 0
39+ . word 0
40+ . word 0
41+ . word 0
42+ . word 0
43+ . word 0
44+ / * Maybe we can use cpu sync in optee os , but not in uboot * /
45+ _cpu_sync:
46+ . word 0
2147/ * the vector table for secure state and HYP mode * /
2248_monitor_vectors:
2349 . word 0 / * reset * /
@@ -113,6 +139,16 @@ ENDPROC(_do_nonsec_entry)
113139 add \addr , \addr , \tmp
114140.endm
115141
142+ .macro get_core_pos reg , tmp
143+ #define MPIDR_CPU_MASK 0xff
144+ #define MPIDR_CLUSTER_SHIFT 8
145+ #define MPIDR_CLUSTER_MASK ( 0xff << MPIDR_CLUSTER_SHIFT)
146+ mrc p15 , 0 , \reg , c0 , c0 , 5
147+ and \tmp , \reg , #MPIDR_CPU_MASK
148+ and \reg , \reg , #MPIDR_CLUSTER_MASK
149+ add \reg , \tmp , \reg , LSR # 6
150+ .endm
151+
116152#ifndef CONFIG_ARMV7_PSCI
117153/ *
118154 * Secondary CPUs start here and call the code for the core specific parts
@@ -121,9 +157,26 @@ ENDPROC(_do_nonsec_entry)
121157 * Then they go back to wfi and wait to be woken up by the kernel again.
122158 * /
123159ENTRY(_smp_pen)
160+ / * Remove this in future * /
161+ ldr sp , = 0x80001000
124162 cpsid i
125163 cpsid f
126164
165+ / * Ugly sync code , use cpu sync in optee os in future * /
166+ wait_cpu0:
167+ dsb
168+ adr r0 , _cpu_sync
169+ ldr r1 , [ r0 ]
170+ ldr r2 , = 0x55555555
171+ cmp r1 , r2
172+ bne wait_cpu0
173+
174+ adr r0 , _cpu_sync
175+ ldr r1 , = 0xaaaabbbb
176+ str r1 , [ r0 ]
177+
178+ dsb
179+
127180 bl _nonsec_init
128181
129182 adr r0 , _smp_pen @ do not use this address again
@@ -177,12 +230,54 @@ ENTRY(_nonsec_init)
177230 mcreq p15 , 0 , r1 , c14 , c0 , 0 @ write CNTFRQ
178231#endif
179232
233+ #ifdef CONFIG_ARMV7_TEE
234+ isb
235+
236+ mov ip , r0
237+ adr r0 , _regs_save
238+ str ip , [ r0 ]
239+ add r0 , r0 , # 4
240+
241+ str sp , [ r0 ]
242+ add r0 , r0 , # 4
243+
244+ stmia r0! , {r1 - r12 }
245+
246+ str lr , [ r0 ]
247+ adr lr , end_init_optee
248+
249+ ldr r0 , =OPTEE_ENTRY
250+ movs pc , r0
251+ b .
252+ end_init_optee:
253+ #if 0
254+ b end_init_optee @for test use
255+ #endif
256+ adr lr , _regs_save
257+ ldr r0 , [ lr ]
258+ add lr , lr , # 4
259+
260+ ldr sp , [ lr ]
261+ add lr , lr , # 4
262+
263+ ldmfd lr! , {r1 - r12 }
264+ ldr lr , [ lr ]
265+
266+ adr r0 , _cpu_sync
267+ ldr r1 , = 0x55555555
268+ str r1 , [ r0 ]
269+
270+ dsb
271+
272+ bx lr
273+ #else
180274 adr r1 , _monitor_vectors
181275 mcr p15 , 0 , r1 , c12 , c0 , 1 @ set MVBAR to secure vectors
182276 isb
183277
184278 mov r0 , r3 @ return GICC address
185279 bx lr
280+ #endif
186281ENDPROC(_nonsec_init)
187282
188283#ifdef CONFIG_SMP_PEN_ADDR
@@ -197,7 +292,13 @@ ENTRY(smp_waitloop)
197292 cmp r0 , r1 @ make sure we dont execute this code
198293 beq smp_waitloop @ again (due to a spurious wakeup)
199294 mov r0 , r1
295+ #ifdef CONFIG_ARMV7_TEE
296+ mrs r1 , cpsr
297+ msr spsr , r1
298+ movs pc , r0
299+ #else
200300 b _do_nonsec_entry
301+ #endif
201302ENDPROC(smp_waitloop)
202303.weak smp_waitloop
203304#endif
0 commit comments