Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 2 | /* |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 3 | * (C) Copyright 2014-2015 Freescale Semiconductor |
Meenakshi Aggarwal | 4470aeb | 2019-05-28 21:37:58 +0530 | [diff] [blame] | 4 | * Copyright 2019 NXP |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 5 | * |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 6 | * Extracted from armv8/start.S |
| 7 | */ |
| 8 | |
| 9 | #include <config.h> |
| 10 | #include <linux/linkage.h> |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 11 | #include <asm/gic.h> |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 12 | #include <asm/macro.h> |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 13 | #include <asm/arch-fsl-layerscape/soc.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 14 | #ifdef CONFIG_MP |
| 15 | #include <asm/arch/mp.h> |
| 16 | #endif |
Priyanka Jain | 96b001f | 2016-11-17 12:29:51 +0530 | [diff] [blame] | 17 | #ifdef CONFIG_FSL_LSCH3 |
| 18 | #include <asm/arch-fsl-layerscape/immap_lsch3.h> |
| 19 | #endif |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 20 | #include <asm/u-boot.h> |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 21 | |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 22 | /* Get GIC offset |
| 23 | * For LS1043a rev1.0, GIC base address align with 4k. |
| 24 | * For LS1043a rev1.1, if DCFG_GIC400_ALIGN[GIC_ADDR_BIT] |
| 25 | * is set, GIC base address align with 4K, or else align |
| 26 | * with 64k. |
| 27 | * output: |
| 28 | * x0: the base address of GICD |
| 29 | * x1: the base address of GICC |
| 30 | */ |
| 31 | ENTRY(get_gic_offset) |
| 32 | ldr x0, =GICD_BASE |
| 33 | #ifdef CONFIG_GICV2 |
| 34 | ldr x1, =GICC_BASE |
| 35 | #endif |
| 36 | #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN |
| 37 | ldr x2, =DCFG_CCSR_SVR |
| 38 | ldr w2, [x2] |
| 39 | rev w2, w2 |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 40 | lsr w3, w2, #16 |
| 41 | ldr w4, =SVR_DEV(SVR_LS1043A) |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 42 | cmp w3, w4 |
| 43 | b.ne 1f |
| 44 | ands w2, w2, #0xff |
| 45 | cmp w2, #REV1_0 |
| 46 | b.eq 1f |
| 47 | ldr x2, =SCFG_GIC400_ALIGN |
| 48 | ldr w2, [x2] |
| 49 | rev w2, w2 |
| 50 | tbnz w2, #GIC_ADDR_BIT, 1f |
| 51 | ldr x0, =GICD_BASE_64K |
| 52 | #ifdef CONFIG_GICV2 |
| 53 | ldr x1, =GICC_BASE_64K |
| 54 | #endif |
| 55 | 1: |
| 56 | #endif |
| 57 | ret |
| 58 | ENDPROC(get_gic_offset) |
| 59 | |
| 60 | ENTRY(smp_kick_all_cpus) |
| 61 | /* Kick secondary cpus up by SGI 0 interrupt */ |
| 62 | #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) |
| 63 | mov x29, lr /* Save LR */ |
| 64 | bl get_gic_offset |
| 65 | bl gic_kick_secondary_cpus |
| 66 | mov lr, x29 /* Restore LR */ |
| 67 | #endif |
| 68 | ret |
| 69 | ENDPROC(smp_kick_all_cpus) |
| 70 | |
| 71 | |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 72 | ENTRY(lowlevel_init) |
| 73 | mov x29, lr /* Save LR */ |
| 74 | |
York Sun | ab4e789 | 2018-11-05 18:01:23 +0000 | [diff] [blame] | 75 | /* unmask SError and abort */ |
| 76 | msr daifclr, #4 |
| 77 | |
| 78 | /* Set HCR_EL2[AMO] so SError @EL2 is taken */ |
| 79 | mrs x0, hcr_el2 |
| 80 | orr x0, x0, #0x20 /* AMO */ |
| 81 | msr hcr_el2, x0 |
| 82 | isb |
| 83 | |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 84 | switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */ |
| 85 | 1: |
| 86 | |
Ashish Kumar | 97393d6 | 2017-08-18 10:54:36 +0530 | [diff] [blame] | 87 | #if defined (CONFIG_SYS_FSL_HAS_CCN504) |
Prabhakar Kushwaha | edbbd25 | 2016-01-25 12:08:45 +0530 | [diff] [blame] | 88 | |
| 89 | /* Set Wuo bit for RN-I 20 */ |
York Sun | 4ce6fbf | 2017-03-27 11:41:01 -0700 | [diff] [blame] | 90 | #ifdef CONFIG_ARCH_LS2080A |
Prabhakar Kushwaha | edbbd25 | 2016-01-25 12:08:45 +0530 | [diff] [blame] | 91 | ldr x0, =CCI_AUX_CONTROL_BASE(20) |
| 92 | ldr x1, =0x00000010 |
| 93 | bl ccn504_set_aux |
Priyanka Jain | 6085079 | 2016-11-09 12:27:54 +0530 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Set forced-order mode in RNI-6, RNI-20 |
| 97 | * This is required for performance optimization on LS2088A |
| 98 | * LS2080A family does not support setting forced-order mode, |
| 99 | * so skip this operation for LS2080A family |
| 100 | */ |
| 101 | bl get_svr |
| 102 | lsr w0, w0, #16 |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 103 | ldr w1, =SVR_DEV(SVR_LS2080A) |
Priyanka Jain | 6085079 | 2016-11-09 12:27:54 +0530 | [diff] [blame] | 104 | cmp w0, w1 |
| 105 | b.eq 1f |
| 106 | |
| 107 | ldr x0, =CCI_AUX_CONTROL_BASE(6) |
| 108 | ldr x1, =0x00000020 |
| 109 | bl ccn504_set_aux |
| 110 | ldr x0, =CCI_AUX_CONTROL_BASE(20) |
| 111 | ldr x1, =0x00000020 |
| 112 | bl ccn504_set_aux |
| 113 | 1: |
Prabhakar Kushwaha | edbbd25 | 2016-01-25 12:08:45 +0530 | [diff] [blame] | 114 | #endif |
| 115 | |
Scott Wood | a814e66 | 2015-03-20 19:28:10 -0700 | [diff] [blame] | 116 | /* Add fully-coherent masters to DVM domain */ |
Bhupesh Sharma | 8238f34 | 2015-07-01 09:58:03 +0530 | [diff] [blame] | 117 | ldr x0, =CCI_MN_BASE |
| 118 | ldr x1, =CCI_MN_RNF_NODEID_LIST |
| 119 | ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET |
| 120 | bl ccn504_add_masters_to_dvm |
| 121 | |
| 122 | /* Set all RN-I ports to QoS of 15 */ |
| 123 | ldr x0, =CCI_S0_QOS_CONTROL_BASE(0) |
| 124 | ldr x1, =0x00FF000C |
| 125 | bl ccn504_set_qos |
| 126 | ldr x0, =CCI_S1_QOS_CONTROL_BASE(0) |
| 127 | ldr x1, =0x00FF000C |
| 128 | bl ccn504_set_qos |
| 129 | ldr x0, =CCI_S2_QOS_CONTROL_BASE(0) |
| 130 | ldr x1, =0x00FF000C |
| 131 | bl ccn504_set_qos |
| 132 | |
| 133 | ldr x0, =CCI_S0_QOS_CONTROL_BASE(2) |
| 134 | ldr x1, =0x00FF000C |
| 135 | bl ccn504_set_qos |
| 136 | ldr x0, =CCI_S1_QOS_CONTROL_BASE(2) |
| 137 | ldr x1, =0x00FF000C |
| 138 | bl ccn504_set_qos |
| 139 | ldr x0, =CCI_S2_QOS_CONTROL_BASE(2) |
| 140 | ldr x1, =0x00FF000C |
| 141 | bl ccn504_set_qos |
| 142 | |
| 143 | ldr x0, =CCI_S0_QOS_CONTROL_BASE(6) |
| 144 | ldr x1, =0x00FF000C |
| 145 | bl ccn504_set_qos |
| 146 | ldr x0, =CCI_S1_QOS_CONTROL_BASE(6) |
| 147 | ldr x1, =0x00FF000C |
| 148 | bl ccn504_set_qos |
| 149 | ldr x0, =CCI_S2_QOS_CONTROL_BASE(6) |
| 150 | ldr x1, =0x00FF000C |
| 151 | bl ccn504_set_qos |
| 152 | |
| 153 | ldr x0, =CCI_S0_QOS_CONTROL_BASE(12) |
| 154 | ldr x1, =0x00FF000C |
| 155 | bl ccn504_set_qos |
| 156 | ldr x0, =CCI_S1_QOS_CONTROL_BASE(12) |
| 157 | ldr x1, =0x00FF000C |
| 158 | bl ccn504_set_qos |
| 159 | ldr x0, =CCI_S2_QOS_CONTROL_BASE(12) |
| 160 | ldr x1, =0x00FF000C |
| 161 | bl ccn504_set_qos |
| 162 | |
| 163 | ldr x0, =CCI_S0_QOS_CONTROL_BASE(16) |
| 164 | ldr x1, =0x00FF000C |
| 165 | bl ccn504_set_qos |
| 166 | ldr x0, =CCI_S1_QOS_CONTROL_BASE(16) |
| 167 | ldr x1, =0x00FF000C |
| 168 | bl ccn504_set_qos |
| 169 | ldr x0, =CCI_S2_QOS_CONTROL_BASE(16) |
| 170 | ldr x1, =0x00FF000C |
| 171 | bl ccn504_set_qos |
| 172 | |
| 173 | ldr x0, =CCI_S0_QOS_CONTROL_BASE(20) |
| 174 | ldr x1, =0x00FF000C |
| 175 | bl ccn504_set_qos |
| 176 | ldr x0, =CCI_S1_QOS_CONTROL_BASE(20) |
| 177 | ldr x1, =0x00FF000C |
| 178 | bl ccn504_set_qos |
| 179 | ldr x0, =CCI_S2_QOS_CONTROL_BASE(20) |
| 180 | ldr x1, =0x00FF000C |
| 181 | bl ccn504_set_qos |
Ashish Kumar | 97393d6 | 2017-08-18 10:54:36 +0530 | [diff] [blame] | 182 | #endif /* CONFIG_SYS_FSL_HAS_CCN504 */ |
Scott Wood | a814e66 | 2015-03-20 19:28:10 -0700 | [diff] [blame] | 183 | |
Prabhakar Kushwaha | ae17df2 | 2016-06-03 18:41:26 +0530 | [diff] [blame] | 184 | #ifdef SMMU_BASE |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 185 | /* Set the SMMU page size in the sACR register */ |
| 186 | ldr x1, =SMMU_BASE |
| 187 | ldr w0, [x1, #0x10] |
| 188 | orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */ |
| 189 | str w0, [x1, #0x10] |
Prabhakar Kushwaha | ae17df2 | 2016-06-03 18:41:26 +0530 | [diff] [blame] | 190 | #endif |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 191 | |
| 192 | /* Initialize GIC Secure Bank Status */ |
| 193 | #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) |
| 194 | branch_if_slave x0, 1f |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 195 | bl get_gic_offset |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 196 | bl gic_init_secure |
| 197 | 1: |
| 198 | #ifdef CONFIG_GICV3 |
| 199 | ldr x0, =GICR_BASE |
| 200 | bl gic_init_secure_percpu |
| 201 | #elif defined(CONFIG_GICV2) |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 202 | bl get_gic_offset |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 203 | bl gic_init_secure_percpu |
| 204 | #endif |
| 205 | #endif |
| 206 | |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 207 | 100: |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 208 | branch_if_master x0, x1, 2f |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 209 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 210 | #if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 211 | ldr x0, =secondary_boot_func |
| 212 | blr x0 |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 213 | #endif |
Bhupesh Sharma | a0c00ff | 2015-01-06 13:11:21 -0800 | [diff] [blame] | 214 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 215 | 2: |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 216 | switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */ |
| 217 | 1: |
Bhupesh Sharma | a0c00ff | 2015-01-06 13:11:21 -0800 | [diff] [blame] | 218 | #ifdef CONFIG_FSL_TZPC_BP147 |
| 219 | /* Set Non Secure access for all devices protected via TZPC */ |
| 220 | ldr x1, =TZPCDECPROT_0_SET_BASE /* Decode Protection-0 Set Reg */ |
| 221 | orr w0, w0, #1 << 3 /* DCFG_RESET is accessible from NS world */ |
| 222 | str w0, [x1] |
| 223 | |
| 224 | isb |
| 225 | dsb sy |
| 226 | #endif |
| 227 | |
| 228 | #ifdef CONFIG_FSL_TZASC_400 |
Priyanka Jain | 583943b | 2016-11-17 12:29:54 +0530 | [diff] [blame] | 229 | /* |
| 230 | * LS2080 and its personalities does not support TZASC |
| 231 | * So skip TZASC related operations |
| 232 | */ |
| 233 | bl get_svr |
| 234 | lsr w0, w0, #16 |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 235 | ldr w1, =SVR_DEV(SVR_LS2080A) |
Priyanka Jain | 583943b | 2016-11-17 12:29:54 +0530 | [diff] [blame] | 236 | cmp w0, w1 |
| 237 | b.eq 1f |
| 238 | |
Bhupesh Sharma | a0c00ff | 2015-01-06 13:11:21 -0800 | [diff] [blame] | 239 | /* Set TZASC so that: |
| 240 | * a. We use only Region0 whose global secure write/read is EN |
| 241 | * b. We use only Region0 whose NSAID write/read is EN |
| 242 | * |
| 243 | * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just |
| 244 | * placeholders. |
| 245 | */ |
Sriram Dash | 0a7a7c3 | 2018-03-26 14:22:43 +0530 | [diff] [blame] | 246 | |
| 247 | .macro tzasc_prog, xreg |
| 248 | |
| 249 | mov x12, TZASC1_BASE |
| 250 | mov x16, #0x10000 |
| 251 | mul x14, \xreg, x16 |
| 252 | add x14, x14,x12 |
| 253 | mov x1, #0x8 |
| 254 | add x1, x1, x14 |
| 255 | |
| 256 | ldr w0, [x1] /* Filter 0 Gate Keeper Register */ |
| 257 | orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */ |
| 258 | str w0, [x1] |
| 259 | |
| 260 | mov x1, #0x110 |
| 261 | add x1, x1, x14 |
Bhupesh Sharma | a0c00ff | 2015-01-06 13:11:21 -0800 | [diff] [blame] | 262 | |
Sriram Dash | 0a7a7c3 | 2018-03-26 14:22:43 +0530 | [diff] [blame] | 263 | ldr w0, [x1] /* Region-0 Attributes Register */ |
| 264 | orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */ |
| 265 | orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */ |
| 266 | str w0, [x1] |
Bhupesh Sharma | a0c00ff | 2015-01-06 13:11:21 -0800 | [diff] [blame] | 267 | |
Sriram Dash | 0a7a7c3 | 2018-03-26 14:22:43 +0530 | [diff] [blame] | 268 | mov x1, #0x114 |
| 269 | add x1, x1, x14 |
| 270 | |
| 271 | ldr w0, [x1] /* Region-0 Access Register */ |
| 272 | mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */ |
| 273 | str w0, [x1] |
| 274 | .endm |
| 275 | |
| 276 | #ifdef CONFIG_FSL_TZASC_1 |
| 277 | mov x13, #0 |
| 278 | tzasc_prog x13 |
| 279 | |
Ashish kumar | 76bd6ce | 2017-04-07 11:40:32 +0530 | [diff] [blame] | 280 | #endif |
| 281 | #ifdef CONFIG_FSL_TZASC_2 |
Sriram Dash | 0a7a7c3 | 2018-03-26 14:22:43 +0530 | [diff] [blame] | 282 | mov x13, #1 |
| 283 | tzasc_prog x13 |
Bhupesh Sharma | a0c00ff | 2015-01-06 13:11:21 -0800 | [diff] [blame] | 284 | |
Ashish kumar | 76bd6ce | 2017-04-07 11:40:32 +0530 | [diff] [blame] | 285 | #endif |
Bhupesh Sharma | a0c00ff | 2015-01-06 13:11:21 -0800 | [diff] [blame] | 286 | isb |
| 287 | dsb sy |
| 288 | #endif |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 289 | 100: |
Priyanka Jain | 583943b | 2016-11-17 12:29:54 +0530 | [diff] [blame] | 290 | 1: |
York Sun | bad4984 | 2016-09-26 08:09:24 -0700 | [diff] [blame] | 291 | #ifdef CONFIG_ARCH_LS1046A |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 292 | switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */ |
| 293 | 1: |
Mingkai Hu | 48ddbe8 | 2016-09-07 17:56:08 +0800 | [diff] [blame] | 294 | /* Initialize the L2 RAM latency */ |
| 295 | mrs x1, S3_1_c11_c0_2 |
| 296 | mov x0, #0x1C7 |
| 297 | /* Clear L2 Tag RAM latency and L2 Data RAM latency */ |
| 298 | bic x1, x1, x0 |
| 299 | /* Set L2 data ram latency bits [2:0] */ |
| 300 | orr x1, x1, #0x2 |
| 301 | /* set L2 tag ram latency bits [8:6] */ |
| 302 | orr x1, x1, #0x80 |
| 303 | msr S3_1_c11_c0_2, x1 |
| 304 | isb |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 305 | 100: |
Mingkai Hu | 48ddbe8 | 2016-09-07 17:56:08 +0800 | [diff] [blame] | 306 | #endif |
| 307 | |
Rajesh Bhagat | 541f8eb | 2018-11-05 18:02:05 +0000 | [diff] [blame] | 308 | #if !defined(CONFIG_TFABOOT) && \ |
| 309 | (defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD)) |
Hou Zhiqiang | c479780 | 2016-12-16 17:15:46 +0800 | [diff] [blame] | 310 | bl fsl_ocram_init |
| 311 | #endif |
| 312 | |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 313 | mov lr, x29 /* Restore LR */ |
| 314 | ret |
| 315 | ENDPROC(lowlevel_init) |
| 316 | |
Hou Zhiqiang | c479780 | 2016-12-16 17:15:46 +0800 | [diff] [blame] | 317 | #if defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD) |
| 318 | ENTRY(fsl_ocram_init) |
| 319 | mov x28, lr /* Save LR */ |
| 320 | bl fsl_clear_ocram |
| 321 | bl fsl_ocram_clear_ecc_err |
| 322 | mov lr, x28 /* Restore LR */ |
| 323 | ret |
| 324 | ENDPROC(fsl_ocram_init) |
| 325 | |
| 326 | ENTRY(fsl_clear_ocram) |
| 327 | /* Clear OCRAM */ |
| 328 | ldr x0, =CONFIG_SYS_FSL_OCRAM_BASE |
| 329 | ldr x1, =(CONFIG_SYS_FSL_OCRAM_BASE + CONFIG_SYS_FSL_OCRAM_SIZE) |
| 330 | mov x2, #0 |
| 331 | clear_loop: |
| 332 | str x2, [x0] |
| 333 | add x0, x0, #8 |
| 334 | cmp x0, x1 |
| 335 | b.lo clear_loop |
| 336 | ret |
| 337 | ENDPROC(fsl_clear_ocram) |
| 338 | |
| 339 | ENTRY(fsl_ocram_clear_ecc_err) |
| 340 | /* OCRAM1/2 ECC status bit */ |
| 341 | mov w1, #0x60 |
| 342 | ldr x0, =DCSR_DCFG_SBEESR2 |
| 343 | str w1, [x0] |
| 344 | ldr x0, =DCSR_DCFG_MBEESR2 |
| 345 | str w1, [x0] |
| 346 | ret |
| 347 | ENDPROC(fsl_ocram_init) |
| 348 | #endif |
| 349 | |
Prabhakar Kushwaha | d169ebe | 2016-06-03 18:41:31 +0530 | [diff] [blame] | 350 | #ifdef CONFIG_FSL_LSCH3 |
Priyanka Jain | 96b001f | 2016-11-17 12:29:51 +0530 | [diff] [blame] | 351 | .globl get_svr |
| 352 | get_svr: |
| 353 | ldr x1, =FSL_LSCH3_SVR |
| 354 | ldr w0, [x1] |
| 355 | ret |
Ashish Kumar | 97393d6 | 2017-08-18 10:54:36 +0530 | [diff] [blame] | 356 | #endif |
Priyanka Jain | 96b001f | 2016-11-17 12:29:51 +0530 | [diff] [blame] | 357 | |
Priyanka Jain | ef76b2e | 2018-10-29 09:17:09 +0000 | [diff] [blame] | 358 | #if defined(CONFIG_SYS_FSL_HAS_CCN504) || defined(CONFIG_SYS_FSL_HAS_CCN508) |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 359 | hnf_pstate_poll: |
Meenakshi Aggarwal | 4470aeb | 2019-05-28 21:37:58 +0530 | [diff] [blame] | 360 | /* x0 has the desired status, return only if operation succeed |
| 361 | * clobber x1, x2, x6 |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 362 | */ |
| 363 | mov x1, x0 |
Meenakshi Aggarwal | 4470aeb | 2019-05-28 21:37:58 +0530 | [diff] [blame] | 364 | mov w6, #8 /* HN-F node count */ |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 365 | mov x0, #0x18 |
| 366 | movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */ |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 367 | 1: |
| 368 | ldr x2, [x0] |
| 369 | cmp x2, x1 /* check status */ |
| 370 | b.eq 2f |
Meenakshi Aggarwal | 4470aeb | 2019-05-28 21:37:58 +0530 | [diff] [blame] | 371 | b 1b |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 372 | 2: |
| 373 | add x0, x0, #0x10000 /* move to next node */ |
| 374 | subs w6, w6, #1 |
| 375 | cbnz w6, 1b |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 376 | ret |
| 377 | |
| 378 | hnf_set_pstate: |
| 379 | /* x0 has the desired state, clobber x1, x2, x6 */ |
| 380 | mov x1, x0 |
| 381 | /* power state to SFONLY */ |
| 382 | mov w6, #8 /* HN-F node count */ |
| 383 | mov x0, #0x10 |
| 384 | movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */ |
| 385 | 1: /* set pstate to sfonly */ |
| 386 | ldr x2, [x0] |
| 387 | and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */ |
| 388 | orr x2, x2, x1 |
| 389 | str x2, [x0] |
| 390 | add x0, x0, #0x10000 /* move to next node */ |
| 391 | subs w6, w6, #1 |
| 392 | cbnz w6, 1b |
| 393 | |
| 394 | ret |
| 395 | |
Stephen Warren | ddb0f63 | 2016-10-19 15:18:46 -0600 | [diff] [blame] | 396 | ENTRY(__asm_flush_l3_dcache) |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 397 | /* |
| 398 | * Return status in x0 |
| 399 | * success 0 |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 400 | */ |
| 401 | mov x29, lr |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 402 | |
| 403 | dsb sy |
| 404 | mov x0, #0x1 /* HNFPSTAT_SFONLY */ |
| 405 | bl hnf_set_pstate |
| 406 | |
| 407 | mov x0, #0x4 /* SFONLY status */ |
| 408 | bl hnf_pstate_poll |
Meenakshi Aggarwal | 4470aeb | 2019-05-28 21:37:58 +0530 | [diff] [blame] | 409 | |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 410 | dsb sy |
| 411 | mov x0, #0x3 /* HNFPSTAT_FAM */ |
| 412 | bl hnf_set_pstate |
| 413 | |
| 414 | mov x0, #0xc /* FAM status */ |
| 415 | bl hnf_pstate_poll |
Meenakshi Aggarwal | 4470aeb | 2019-05-28 21:37:58 +0530 | [diff] [blame] | 416 | |
| 417 | mov x0, #0 |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 418 | mov lr, x29 |
| 419 | ret |
Stephen Warren | ddb0f63 | 2016-10-19 15:18:46 -0600 | [diff] [blame] | 420 | ENDPROC(__asm_flush_l3_dcache) |
Ashish Kumar | 97393d6 | 2017-08-18 10:54:36 +0530 | [diff] [blame] | 421 | #endif /* CONFIG_SYS_FSL_HAS_CCN504 */ |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 422 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 423 | #ifdef CONFIG_MP |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 424 | /* Keep literals not used by the secondary boot code outside it */ |
| 425 | .ltorg |
| 426 | |
| 427 | /* Using 64 bit alignment since the spin table is accessed as data */ |
| 428 | .align 4 |
| 429 | .global secondary_boot_code |
| 430 | /* Secondary Boot Code starts here */ |
| 431 | secondary_boot_code: |
| 432 | .global __spin_table |
| 433 | __spin_table: |
| 434 | .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE |
| 435 | |
| 436 | .align 2 |
| 437 | ENTRY(secondary_boot_func) |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 438 | /* |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 439 | * MPIDR_EL1 Fields: |
| 440 | * MPIDR[1:0] = AFF0_CPUID <- Core ID (0,1) |
| 441 | * MPIDR[7:2] = AFF0_RES |
| 442 | * MPIDR[15:8] = AFF1_CLUSTERID <- Cluster ID (0,1,2,3) |
| 443 | * MPIDR[23:16] = AFF2_CLUSTERID |
| 444 | * MPIDR[24] = MT |
| 445 | * MPIDR[29:25] = RES0 |
| 446 | * MPIDR[30] = U |
| 447 | * MPIDR[31] = ME |
| 448 | * MPIDR[39:32] = AFF3 |
| 449 | * |
| 450 | * Linear Processor ID (LPID) calculation from MPIDR_EL1: |
| 451 | * (We only use AFF0_CPUID and AFF1_CLUSTERID for now |
| 452 | * until AFF2_CLUSTERID and AFF3 have non-zero values) |
| 453 | * |
| 454 | * LPID = MPIDR[15:8] | MPIDR[1:0] |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 455 | */ |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 456 | mrs x0, mpidr_el1 |
| 457 | ubfm x1, x0, #8, #15 |
| 458 | ubfm x2, x0, #0, #1 |
| 459 | orr x10, x2, x1, lsl #2 /* x10 has LPID */ |
| 460 | ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */ |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 461 | /* |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 462 | * offset of the spin table element for this core from start of spin |
| 463 | * table (each elem is padded to 64 bytes) |
York Sun | a84cd72 | 2014-06-23 15:15:54 -0700 | [diff] [blame] | 464 | */ |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 465 | lsl x1, x10, #6 |
| 466 | ldr x0, =__spin_table |
| 467 | /* physical address of this cpus spin table element */ |
| 468 | add x11, x1, x0 |
| 469 | |
York Sun | 77a1097 | 2015-03-20 19:28:08 -0700 | [diff] [blame] | 470 | ldr x0, =__real_cntfrq |
| 471 | ldr x0, [x0] |
| 472 | msr cntfrq_el0, x0 /* set with real frequency */ |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 473 | str x9, [x11, #16] /* LPID */ |
| 474 | mov x4, #1 |
| 475 | str x4, [x11, #8] /* STATUS */ |
| 476 | dsb sy |
| 477 | #if defined(CONFIG_GICV3) |
| 478 | gic_wait_for_interrupt_m x0 |
| 479 | #elif defined(CONFIG_GICV2) |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 480 | bl get_gic_offset |
| 481 | mov x0, x1 |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 482 | gic_wait_for_interrupt_m x0, w1 |
| 483 | #endif |
| 484 | |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 485 | slave_cpu: |
| 486 | wfe |
| 487 | ldr x0, [x11] |
| 488 | cbz x0, slave_cpu |
| 489 | #ifndef CONFIG_ARMV8_SWITCH_TO_EL1 |
| 490 | mrs x1, sctlr_el2 |
| 491 | #else |
| 492 | mrs x1, sctlr_el1 |
| 493 | #endif |
| 494 | tbz x1, #25, cpu_is_le |
| 495 | rev x0, x0 /* BE to LE conversion */ |
| 496 | cpu_is_le: |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 497 | ldr x5, [x11, #24] |
Alison Wang | a6231fe | 2017-06-08 16:15:14 +0800 | [diff] [blame] | 498 | cbz x5, 1f |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 499 | |
| 500 | #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 501 | adr x4, secondary_switch_to_el1 |
| 502 | ldr x5, =ES_TO_AARCH64 |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 503 | #else |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 504 | ldr x4, [x11] |
| 505 | ldr x5, =ES_TO_AARCH32 |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 506 | #endif |
| 507 | bl secondary_switch_to_el2 |
| 508 | |
| 509 | 1: |
| 510 | #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 511 | adr x4, secondary_switch_to_el1 |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 512 | #else |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 513 | ldr x4, [x11] |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 514 | #endif |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 515 | ldr x5, =ES_TO_AARCH64 |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 516 | bl secondary_switch_to_el2 |
| 517 | |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 518 | ENDPROC(secondary_boot_func) |
| 519 | |
| 520 | ENTRY(secondary_switch_to_el2) |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 521 | switch_el x6, 1f, 0f, 0f |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 522 | 0: ret |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 523 | 1: armv8_switch_to_el2_m x4, x5, x6 |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 524 | ENDPROC(secondary_switch_to_el2) |
| 525 | |
| 526 | ENTRY(secondary_switch_to_el1) |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 527 | mrs x0, mpidr_el1 |
| 528 | ubfm x1, x0, #8, #15 |
| 529 | ubfm x2, x0, #0, #1 |
| 530 | orr x10, x2, x1, lsl #2 /* x10 has LPID */ |
| 531 | |
| 532 | lsl x1, x10, #6 |
| 533 | ldr x0, =__spin_table |
| 534 | /* physical address of this cpus spin table element */ |
| 535 | add x11, x1, x0 |
| 536 | |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 537 | ldr x4, [x11] |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 538 | |
| 539 | ldr x5, [x11, #24] |
Alison Wang | a6231fe | 2017-06-08 16:15:14 +0800 | [diff] [blame] | 540 | cbz x5, 2f |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 541 | |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 542 | ldr x5, =ES_TO_AARCH32 |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 543 | bl switch_to_el1 |
| 544 | |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 545 | 2: ldr x5, =ES_TO_AARCH64 |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 546 | |
| 547 | switch_to_el1: |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 548 | switch_el x6, 0f, 1f, 0f |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 549 | 0: ret |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 550 | 1: armv8_switch_to_el1_m x4, x5, x6 |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 551 | ENDPROC(secondary_switch_to_el1) |
| 552 | |
| 553 | /* Ensure that the literals used by the secondary boot code are |
| 554 | * assembled within it (this is required so that we can protect |
| 555 | * this area with a single memreserve region |
| 556 | */ |
| 557 | .ltorg |
| 558 | |
| 559 | /* 64 bit alignment for elements accessed as data */ |
| 560 | .align 4 |
York Sun | 77a1097 | 2015-03-20 19:28:08 -0700 | [diff] [blame] | 561 | .global __real_cntfrq |
| 562 | __real_cntfrq: |
| 563 | .quad COUNTER_FREQUENCY |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 564 | .globl __secondary_boot_code_size |
| 565 | .type __secondary_boot_code_size, %object |
| 566 | /* Secondary Boot Code ends here */ |
| 567 | __secondary_boot_code_size: |
| 568 | .quad .-secondary_boot_code |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 569 | #endif |