Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 1 | /* |
| 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 |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 44 | .globl platform_mem_init |
| 45 | |
| 46 | /* Define a crash console for the plaform */ |
Soby Mathew | 64a76ed | 2014-09-23 11:32:48 +0100 | [diff] [blame] | 47 | #define JUNO_CRASH_CONSOLE_BASE PL011_UART3_BASE |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 48 | |
| 49 | /* --------------------------------------------- |
| 50 | * int plat_crash_console_init(void) |
| 51 | * Function to initialize the crash console |
| 52 | * without a C Runtime to print crash report. |
| 53 | * Clobber list : x0, x1, x2 |
| 54 | * --------------------------------------------- |
| 55 | */ |
| 56 | func plat_crash_console_init |
| 57 | mov_imm x0, JUNO_CRASH_CONSOLE_BASE |
Soby Mathew | 64a76ed | 2014-09-23 11:32:48 +0100 | [diff] [blame] | 58 | mov_imm x1, PL011_UART3_CLK_IN_HZ |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 59 | mov_imm x2, PL011_BAUDRATE |
| 60 | b console_core_init |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 61 | endfunc plat_crash_console_init |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 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 | */ |
| 70 | func plat_crash_console_putc |
| 71 | mov_imm x1, JUNO_CRASH_CONSOLE_BASE |
| 72 | b console_core_putc |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 73 | endfunc plat_crash_console_putc |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 74 | |
| 75 | /* --------------------------------------------- |
| 76 | * void plat_report_exception(unsigned int type) |
| 77 | * Function to report an unhandled exception |
| 78 | * with platform-specific means. |
| 79 | * On Juno platform, it updates the LEDs |
| 80 | * to indicate where we are |
| 81 | * --------------------------------------------- |
| 82 | */ |
| 83 | func plat_report_exception |
| 84 | mrs x1, CurrentEl |
| 85 | lsr x1, x1, #MODE_EL_SHIFT |
| 86 | lsl x1, x1, #SYS_LED_EL_SHIFT |
| 87 | lsl x0, x0, #SYS_LED_EC_SHIFT |
| 88 | mov x2, #(SECURE << SYS_LED_SS_SHIFT) |
| 89 | orr x0, x0, x2 |
| 90 | orr x0, x0, x1 |
| 91 | mov x1, #VE_SYSREGS_BASE |
| 92 | add x1, x1, #V2M_SYS_LED |
| 93 | str w0, [x1] |
| 94 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 95 | endfunc plat_report_exception |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * Return 0 to 3 for the A53s and 4 or 5 for the A57s |
| 99 | */ |
| 100 | func platform_get_core_pos |
| 101 | and x1, x0, #MPIDR_CPU_MASK |
| 102 | and x0, x0, #MPIDR_CLUSTER_MASK |
| 103 | eor x0, x0, #(1 << MPIDR_AFFINITY_BITS) // swap A53/A57 order |
| 104 | add x0, x1, x0, LSR #6 |
| 105 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 106 | endfunc platform_get_core_pos |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 107 | |
| 108 | |
| 109 | /* ----------------------------------------------------- |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 110 | * void platform_mem_init(void); |
| 111 | * |
| 112 | * We don't need to carry out any memory initialization |
| 113 | * on Juno. The Secure RAM is accessible straight away. |
| 114 | * ----------------------------------------------------- |
| 115 | */ |
| 116 | func platform_mem_init |
| 117 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 118 | endfunc platform_mem_init |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 119 | |
Sandrine Bailleux | fd8f898 | 2015-02-04 14:06:10 +0000 | [diff] [blame] | 120 | /* -------------------------------------------------------------------- |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 121 | * void plat_reset_handler(void); |
| 122 | * |
Sandrine Bailleux | fd8f898 | 2015-02-04 14:06:10 +0000 | [diff] [blame] | 123 | * Before adding code in this function, refer to the guidelines in |
| 124 | * docs/firmware-design.md to determine whether the code should reside |
| 125 | * within the FIRST_RESET_HANDLER_CALL block or not. |
Yatharth Kochar | 36433d1 | 2014-11-20 18:09:41 +0000 | [diff] [blame] | 126 | * |
Sandrine Bailleux | fd8f898 | 2015-02-04 14:06:10 +0000 | [diff] [blame] | 127 | * For Juno r0: |
| 128 | * - Implement workaround for defect id 831273 by enabling an event |
| 129 | * stream every 65536 cycles. |
| 130 | * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 |
| 131 | * - Set the L2 Tag RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 |
| 132 | * |
| 133 | * For Juno r1: |
| 134 | * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 |
| 135 | * Note that: |
| 136 | * - The default value for the L2 Tag RAM latency for Cortex-A57 is |
| 137 | * suitable. |
| 138 | * - Defect #831273 doesn't affect Juno r1. |
| 139 | * |
| 140 | * This code is included only when FIRST_RESET_HANDLER_CALL is defined |
| 141 | * since it should be executed only during BL1. |
| 142 | * -------------------------------------------------------------------- |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 143 | */ |
| 144 | func plat_reset_handler |
Yatharth Kochar | 36433d1 | 2014-11-20 18:09:41 +0000 | [diff] [blame] | 145 | #ifdef FIRST_RESET_HANDLER_CALL |
Sandrine Bailleux | fd8f898 | 2015-02-04 14:06:10 +0000 | [diff] [blame] | 146 | /* -------------------------------------------------------------------- |
| 147 | * Determine whether this code is running on Juno r0 or Juno r1. |
| 148 | * Keep this information in x2. |
| 149 | * -------------------------------------------------------------------- |
| 150 | */ |
| 151 | /* Read the V2M SYS_ID register */ |
| 152 | mov_imm x0, (VE_SYSREGS_BASE + V2M_SYS_ID) |
| 153 | ldr w1, [x0] |
| 154 | /* Extract board revision from the SYS_ID */ |
| 155 | ubfx x1, x1, #SYS_ID_REV_SHIFT, #4 |
| 156 | /* |
| 157 | * On Juno R0: x2 := REV_JUNO_R0 - 1 = 0 |
| 158 | * On Juno R1: x2 := REV_JUNO_R1 - 1 = 1 |
| 159 | */ |
| 160 | sub x2, x1, #1 |
| 161 | |
| 162 | /* -------------------------------------------------------------------- |
| 163 | * Determine whether this code is executed on a Cortex-A53 or on a |
| 164 | * Cortex-A57 core. |
| 165 | * -------------------------------------------------------------------- |
| 166 | */ |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 167 | mrs x0, midr_el1 |
| 168 | ubfx x1, x0, MIDR_PN_SHIFT, #12 |
| 169 | cmp w1, #((CORTEX_A57_MIDR >> MIDR_PN_SHIFT) & MIDR_PN_MASK) |
Sandrine Bailleux | fd8f898 | 2015-02-04 14:06:10 +0000 | [diff] [blame] | 170 | b.eq A57 |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 171 | |
Sandrine Bailleux | fd8f898 | 2015-02-04 14:06:10 +0000 | [diff] [blame] | 172 | /* Nothing needs to be done for the Cortex-A53 on Juno r1 */ |
| 173 | cbz x2, apply_831273 |
| 174 | ret |
| 175 | |
| 176 | A57: |
| 177 | /* -------------------------------------------------------------------- |
| 178 | * Cortex-A57 specific settings |
| 179 | * -------------------------------------------------------------------- |
| 180 | */ |
| 181 | |
| 182 | /* Change the L2 Data RAM latency to 3 cycles */ |
| 183 | mov x0, #L2_DATA_RAM_LATENCY_3_CYCLES |
| 184 | cbnz x2, apply_l2_ram_latencies |
| 185 | /* On Juno r0, also change the L2 Tag RAM latency to 3 cycles */ |
| 186 | orr x0, x0, #(L2_TAG_RAM_LATENCY_3_CYCLES << L2CTLR_TAG_RAM_LATENCY_SHIFT) |
| 187 | apply_l2_ram_latencies: |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 188 | msr L2CTLR_EL1, x0 |
| 189 | |
Sandrine Bailleux | fd8f898 | 2015-02-04 14:06:10 +0000 | [diff] [blame] | 190 | /* Juno r1 doesn't suffer from defect #831273 */ |
| 191 | cbnz x2, ret |
| 192 | |
| 193 | apply_831273: |
| 194 | /* -------------------------------------------------------------------- |
| 195 | * On Juno r0, enable the event stream every 65536 cycles |
| 196 | * -------------------------------------------------------------------- |
Yatharth Kochar | 36433d1 | 2014-11-20 18:09:41 +0000 | [diff] [blame] | 197 | */ |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 198 | mov x0, #(0xf << EVNTI_SHIFT) |
| 199 | orr x0, x0, #EVNTEN_BIT |
| 200 | msr CNTKCTL_EL1, x0 |
Sandrine Bailleux | fd8f898 | 2015-02-04 14:06:10 +0000 | [diff] [blame] | 201 | ret: |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 202 | isb |
Yatharth Kochar | 36433d1 | 2014-11-20 18:09:41 +0000 | [diff] [blame] | 203 | #endif /* FIRST_RESET_HANDLER_CALL */ |
Sandrine Bailleux | 798140d | 2014-07-17 16:06:39 +0100 | [diff] [blame] | 204 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 205 | endfunc plat_reset_handler |