Update from upstream to 2.4.0 version
[platform/core/security/tef-optee_os.git] / core / arch / arm / plat-imx / a9_plat_init.S
1 /*
2  * Copyright (c) 2014, STMicroelectronics International N.V.
3  * All rights reserved.
4  * Copyright (c) 2016, Wind River Systems.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 /*
31  * Entry points for the A9 inits, A9 revision specific or not.
32  * It is assume no stack is available when these routines are called.
33  * It is assume each routine is called with return address in LR
34  * and with ARM registers R0, R1, R2, R3 being scratchable.
35  */
36
37 #include <arm32.h>
38 #include <arm32_macros.S>
39 #include <arm32_macros_cortex_a9.S>
40 #include <asm.S>
41 #include <kernel/tz_ssvce_def.h>
42 #include <kernel/unwind.h>
43 #include <platform_config.h>
44
45 .section .text
46 .balign 4
47 .code 32
48
49 /*
50  * Cortex A9 early configuration
51  *
52  * Use registers R0-R3.
53  * No stack usage.
54  * LR store return address.
55  * Trap CPU in case of error.
56  */
57 FUNC plat_cpu_reset_early , :
58 UNWIND( .fnstart)
59
60         /*
61          * Disallow NSec to mask FIQ [bit4: FW=0]
62          * Allow NSec to manage Imprecise Abort [bit5: AW=1]
63          * Imprecise Abort trapped to Abort Mode [bit3: EA=0]
64          * In Sec world, FIQ trapped to FIQ Mode [bit2: FIQ=0]
65          * IRQ always trapped to IRQ Mode [bit1: IRQ=0]
66          * Secure World [bit0: NS=0]
67          */
68         mov r0, #SCR_AW
69         write_scr r0
70
71         /*
72          * Mandated HW config loaded
73          *
74          * SCTLR = 0x00004000
75          * - Round-Robin replac. for icache, btac, i/duTLB (bit14: RoundRobin)
76          *
77          * ACTRL = 0x00000041
78          * - core always in full SMP (FW bit0=1, SMP bit6=1)
79          * - L2 write full line of zero disabled (bit3=0)
80          *   (keep WFLZ low. Will be set once outer L2 is ready)
81          *
82          * NSACR = 0x00020C00
83          * - NSec cannot change ACTRL.SMP (NS_SMP bit18=0)
84          * - Nsec can lockdown TLB (TL bit17=1)
85          * - NSec cannot access PLE (PLE bit16=0)
86          * - NSec can use SIMD/VFP (CP10/CP11) (bit15:14=2b00, bit11:10=2b11)
87          *
88          * PCR
89          * - no change latency, enable clk gating
90          */
91         movw r0, #0x4000
92         movt r0, #0x0000
93         write_sctlr r0
94
95         movw r0, #0x0041
96         movt r0, #0x0000
97         write_actlr r0
98
99         movw r0, #0x0C00
100         movt r0, #0x0002
101         write_nsacr r0
102
103         read_pcr r0
104         orr r0, r0, #0x1
105         write_pcr r0
106
107         mov pc, lr
108 UNWIND( .fnend)
109 END_FUNC plat_cpu_reset_early