blob: 03541620c3f976b383bf14f4279849e059cebeae [file] [log] [blame]
Sandrine Bailleux01b916b2014-07-17 16:06:39 +01001/*
2 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch.h>
32#include <asm_macros.S>
33#include <bl_common.h>
34#include <cortex_a57.h>
35#include <cpu_macros.S>
36#include <platform_def.h>
37#include "../juno_def.h"
38
39 .globl plat_crash_console_init
40 .globl plat_crash_console_putc
41 .globl plat_report_exception
42 .globl plat_reset_handler
43 .globl platform_get_core_pos
44 .globl platform_is_primary_cpu
45 .globl platform_mem_init
46
47 /* Define a crash console for the plaform */
48#define JUNO_CRASH_CONSOLE_BASE PL011_UART0_BASE
49
50 /* ---------------------------------------------
51 * int plat_crash_console_init(void)
52 * Function to initialize the crash console
53 * without a C Runtime to print crash report.
54 * Clobber list : x0, x1, x2
55 * ---------------------------------------------
56 */
57func plat_crash_console_init
58 mov_imm x0, JUNO_CRASH_CONSOLE_BASE
59 mov_imm x1, PL011_UART0_CLK_IN_HZ
60 mov_imm x2, PL011_BAUDRATE
61 b console_core_init
62
63 /* ---------------------------------------------
64 * int plat_crash_console_putc(int c)
65 * Function to print a character on the crash
66 * console without a C Runtime.
67 * Clobber list : x1, x2
68 * ---------------------------------------------
69 */
70func plat_crash_console_putc
71 mov_imm x1, JUNO_CRASH_CONSOLE_BASE
72 b console_core_putc
73
74 /* ---------------------------------------------
75 * void plat_report_exception(unsigned int type)
76 * Function to report an unhandled exception
77 * with platform-specific means.
78 * On Juno platform, it updates the LEDs
79 * to indicate where we are
80 * ---------------------------------------------
81 */
82func plat_report_exception
83 mrs x1, CurrentEl
84 lsr x1, x1, #MODE_EL_SHIFT
85 lsl x1, x1, #SYS_LED_EL_SHIFT
86 lsl x0, x0, #SYS_LED_EC_SHIFT
87 mov x2, #(SECURE << SYS_LED_SS_SHIFT)
88 orr x0, x0, x2
89 orr x0, x0, x1
90 mov x1, #VE_SYSREGS_BASE
91 add x1, x1, #V2M_SYS_LED
92 str w0, [x1]
93 ret
94
95 /*
96 * Return 0 to 3 for the A53s and 4 or 5 for the A57s
97 */
98func platform_get_core_pos
99 and x1, x0, #MPIDR_CPU_MASK
100 and x0, x0, #MPIDR_CLUSTER_MASK
101 eor x0, x0, #(1 << MPIDR_AFFINITY_BITS) // swap A53/A57 order
102 add x0, x1, x0, LSR #6
103 ret
104
105
106 /* -----------------------------------------------------
107 * unsigned int platform_is_primary_cpu(unsigned long mpid);
108 *
109 * Given the mpidr say whether this cpu is the primary
110 * cpu (applicable only after a cold boot)
111 * -----------------------------------------------------
112 */
113func platform_is_primary_cpu
114 /* Juno todo: allow configuration of primary CPU using SCC */
115 and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
116 cmp x0, #JUNO_PRIMARY_CPU
117 cset x0, eq
118 ret
119
120
121 /* -----------------------------------------------------
122 * void platform_mem_init(void);
123 *
124 * We don't need to carry out any memory initialization
125 * on Juno. The Secure RAM is accessible straight away.
126 * -----------------------------------------------------
127 */
128func platform_mem_init
129 ret
130
131 /* -----------------------------------------------------
132 * void plat_reset_handler(void);
133 *
134 * Implement workaround for defect id 831273 by enabling
135 * an event stream every 65536 cycles and set the L2 RAM
136 * latencies for Cortex-A57.
137 * -----------------------------------------------------
138 */
139func plat_reset_handler
140 /* Read the MIDR_EL1 */
141 mrs x0, midr_el1
142 ubfx x1, x0, MIDR_PN_SHIFT, #12
143 cmp w1, #((CORTEX_A57_MIDR >> MIDR_PN_SHIFT) & MIDR_PN_MASK)
144 b.ne 1f
145
146 /* Change the L2 Data and Tag Ram latency to 3 cycles */
147 mov x0, #(L2_DATA_RAM_LATENCY_3_CYCLES | \
148 (L2_TAG_RAM_LATENCY_3_CYCLES << \
149 L2CTLR_TAG_RAM_LATENCY_SHIFT))
150 msr L2CTLR_EL1, x0
151
1521:
153 /* ---------------------------------------------
154 * Enable the event stream every 65536 cycles
155 * ---------------------------------------------
156 */
157 mov x0, #(0xf << EVNTI_SHIFT)
158 orr x0, x0, #EVNTEN_BIT
159 msr CNTKCTL_EL1, x0
160 isb
161 ret