Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 1 | /* |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 2 | * Copyright 2008-2012 Freescale Semiconductor, Inc. |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 3 | * Kumar Gala <kumar.gala@freescale.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 8 | #include <asm-offsets.h> |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 9 | #include <config.h> |
| 10 | #include <mpc85xx.h> |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 11 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 12 | #include <ppc_asm.tmpl> |
| 13 | #include <ppc_defs.h> |
| 14 | |
| 15 | #include <asm/cache.h> |
| 16 | #include <asm/mmu.h> |
| 17 | |
| 18 | /* To boot secondary cpus, we need a place for them to start up. |
| 19 | * Normally, they start at 0xfffffffc, but that's usually the |
| 20 | * firmware, and we don't want to have to run the firmware again. |
| 21 | * Instead, the primary cpu will set the BPTR to point here to |
| 22 | * this page. We then set up the core, and head to |
| 23 | * start_secondary. Note that this means that the code below |
| 24 | * must never exceed 1023 instructions (the branch at the end |
| 25 | * would then be the 1024th). |
| 26 | */ |
| 27 | .globl __secondary_start_page |
| 28 | .align 12 |
| 29 | __secondary_start_page: |
| 30 | /* First do some preliminary setup */ |
| 31 | lis r3, HID0_EMCP@h /* enable machine check */ |
Kumar Gala | 9f4a689 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 32 | #ifndef CONFIG_E500MC |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 33 | ori r3,r3,HID0_TBEN@l /* enable Timebase */ |
Kumar Gala | 9f4a689 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 34 | #endif |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 35 | #ifdef CONFIG_PHYS_64BIT |
| 36 | ori r3,r3,HID0_ENMAS7@l /* enable MAS7 updates */ |
| 37 | #endif |
| 38 | mtspr SPRN_HID0,r3 |
| 39 | |
Kumar Gala | 9f4a689 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 40 | #ifndef CONFIG_E500MC |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 41 | li r3,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */ |
Sandeep Gopalpet | 8709aed | 2010-03-12 10:45:02 +0530 | [diff] [blame] | 42 | mfspr r0,PVR |
| 43 | andi. r0,r0,0xff |
| 44 | cmpwi r0,0x50@l /* if we are rev 5.0 or greater set MBDD */ |
| 45 | blt 1f |
| 46 | /* Set MBDD bit also */ |
| 47 | ori r3, r3, HID1_MBDD@l |
| 48 | 1: |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 49 | mtspr SPRN_HID1,r3 |
Kumar Gala | 9f4a689 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 50 | #endif |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 51 | |
Kumar Gala | 945e59a | 2011-11-22 06:51:15 -0600 | [diff] [blame] | 52 | #ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999 |
Andy Fleming | eab55c0 | 2013-03-25 07:33:10 +0000 | [diff] [blame] | 53 | mfspr r3,SPRN_HDBCR1 |
Kumar Gala | 945e59a | 2011-11-22 06:51:15 -0600 | [diff] [blame] | 54 | oris r3,r3,0x0100 |
Andy Fleming | eab55c0 | 2013-03-25 07:33:10 +0000 | [diff] [blame] | 55 | mtspr SPRN_HDBCR1,r3 |
Kumar Gala | 945e59a | 2011-11-22 06:51:15 -0600 | [diff] [blame] | 56 | #endif |
| 57 | |
Scott Wood | 8080696 | 2012-08-14 10:14:53 +0000 | [diff] [blame] | 58 | #ifdef CONFIG_SYS_FSL_ERRATUM_A004510 |
| 59 | mfspr r3,SPRN_SVR |
| 60 | rlwinm r3,r3,0,0xff |
| 61 | li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV |
| 62 | cmpw r3,r4 |
| 63 | beq 1f |
| 64 | |
| 65 | #ifdef CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2 |
| 66 | li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2 |
| 67 | cmpw r3,r4 |
| 68 | beq 1f |
| 69 | #endif |
| 70 | |
| 71 | /* Not a supported revision affected by erratum */ |
| 72 | b 2f |
| 73 | |
| 74 | 1: /* Erratum says set bits 55:60 to 001001 */ |
| 75 | msync |
| 76 | isync |
Andy Fleming | eab55c0 | 2013-03-25 07:33:10 +0000 | [diff] [blame] | 77 | mfspr r3,SPRN_HDBCR0 |
Scott Wood | 8080696 | 2012-08-14 10:14:53 +0000 | [diff] [blame] | 78 | li r4,0x48 |
| 79 | rlwimi r3,r4,0,0x1f8 |
Andy Fleming | eab55c0 | 2013-03-25 07:33:10 +0000 | [diff] [blame] | 80 | mtspr SPRN_HDBCR0,r3 |
Scott Wood | 8080696 | 2012-08-14 10:14:53 +0000 | [diff] [blame] | 81 | isync |
| 82 | 2: |
| 83 | #endif |
| 84 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 85 | /* Enable branch prediction */ |
Kumar Gala | 5530cb8 | 2010-03-29 13:50:31 -0500 | [diff] [blame] | 86 | lis r3,BUCSR_ENABLE@h |
| 87 | ori r3,r3,BUCSR_ENABLE@l |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 88 | mtspr SPRN_BUCSR,r3 |
| 89 | |
Kumar Gala | b937cc5 | 2008-09-08 08:51:29 -0500 | [diff] [blame] | 90 | /* Ensure TB is 0 */ |
| 91 | li r3,0 |
| 92 | mttbl r3 |
| 93 | mttbu r3 |
| 94 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 95 | /* Enable/invalidate the I-Cache */ |
Kumar Gala | 48bd5f0 | 2010-03-26 15:14:43 -0500 | [diff] [blame] | 96 | lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h |
| 97 | ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l |
| 98 | mtspr SPRN_L1CSR1,r2 |
| 99 | 1: |
| 100 | mfspr r3,SPRN_L1CSR1 |
| 101 | and. r1,r3,r2 |
| 102 | bne 1b |
| 103 | |
| 104 | lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h |
| 105 | ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l |
| 106 | mtspr SPRN_L1CSR1,r3 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 107 | isync |
Kumar Gala | 48bd5f0 | 2010-03-26 15:14:43 -0500 | [diff] [blame] | 108 | 2: |
| 109 | mfspr r3,SPRN_L1CSR1 |
| 110 | andi. r1,r3,L1CSR1_ICE@l |
| 111 | beq 2b |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 112 | |
| 113 | /* Enable/invalidate the D-Cache */ |
Kumar Gala | 48bd5f0 | 2010-03-26 15:14:43 -0500 | [diff] [blame] | 114 | lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h |
| 115 | ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l |
| 116 | mtspr SPRN_L1CSR0,r2 |
| 117 | 1: |
| 118 | mfspr r3,SPRN_L1CSR0 |
| 119 | and. r1,r3,r2 |
| 120 | bne 1b |
| 121 | |
| 122 | lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h |
| 123 | ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l |
| 124 | mtspr SPRN_L1CSR0,r3 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 125 | isync |
Kumar Gala | 48bd5f0 | 2010-03-26 15:14:43 -0500 | [diff] [blame] | 126 | 2: |
| 127 | mfspr r3,SPRN_L1CSR0 |
| 128 | andi. r1,r3,L1CSR0_DCE@l |
| 129 | beq 2b |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 130 | |
| 131 | #define toreset(x) (x - __secondary_start_page + 0xfffff000) |
| 132 | |
| 133 | /* get our PIR to figure out our table entry */ |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 134 | lis r3,toreset(__spin_table_addr)@h |
| 135 | ori r3,r3,toreset(__spin_table_addr)@l |
| 136 | lwz r3,0(r3) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 137 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 138 | mfspr r0,SPRN_PIR |
York Sun | 14c3049 | 2013-03-25 07:33:27 +0000 | [diff] [blame] | 139 | #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2 |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 140 | /* |
York Sun | 14c3049 | 2013-03-25 07:33:27 +0000 | [diff] [blame] | 141 | * PIR definition for Chassis 2 |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 142 | * 0-17 Reserved (logic 0s) |
York Sun | aa150bb | 2013-03-25 07:40:07 +0000 | [diff] [blame] | 143 | * 18-19 CHIP_ID, 2'b00 - SoC 1 |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 144 | * all others - reserved |
Timur Tabi | e6c2819 | 2012-10-05 09:48:50 +0000 | [diff] [blame] | 145 | * 20-24 CLUSTER_ID 5'b00000 - CCM 1 |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 146 | * all others - reserved |
Timur Tabi | e6c2819 | 2012-10-05 09:48:50 +0000 | [diff] [blame] | 147 | * 25-26 CORE_CLUSTER_ID 2'b00 - cluster 1 |
| 148 | * 2'b01 - cluster 2 |
| 149 | * 2'b10 - cluster 3 |
| 150 | * 2'b11 - cluster 4 |
| 151 | * 27-28 CORE_ID 2'b00 - core 0 |
| 152 | * 2'b01 - core 1 |
| 153 | * 2'b10 - core 2 |
| 154 | * 2'b11 - core 3 |
| 155 | * 29-31 THREAD_ID 3'b000 - thread 0 |
| 156 | * 3'b001 - thread 1 |
York Sun | aa150bb | 2013-03-25 07:40:07 +0000 | [diff] [blame] | 157 | * |
| 158 | * Power-on PIR increments threads by 0x01, cores within a cluster by 0x08 |
| 159 | * and clusters by 0x20. |
| 160 | * |
| 161 | * We renumber PIR so that all threads in the system are consecutive. |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 162 | */ |
York Sun | aa150bb | 2013-03-25 07:40:07 +0000 | [diff] [blame] | 163 | |
| 164 | rlwinm r8,r0,29,0x03 /* r8 = core within cluster */ |
| 165 | srwi r10,r0,5 /* r10 = cluster */ |
| 166 | |
| 167 | mulli r5,r10,CONFIG_SYS_FSL_CORES_PER_CLUSTER |
| 168 | add r5,r5,r8 /* for spin table index */ |
| 169 | mulli r4,r5,CONFIG_SYS_FSL_THREADS_PER_CORE /* for PIR */ |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 170 | #elif defined(CONFIG_E500MC) |
Kumar Gala | 9f4a689 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 171 | rlwinm r4,r0,27,27,31 |
York Sun | aa150bb | 2013-03-25 07:40:07 +0000 | [diff] [blame] | 172 | mr r5,r4 |
Kumar Gala | 9f4a689 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 173 | #else |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 174 | mr r4,r0 |
York Sun | aa150bb | 2013-03-25 07:40:07 +0000 | [diff] [blame] | 175 | mr r5,r4 |
Kumar Gala | 9f4a689 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 176 | #endif |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 177 | |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 178 | /* |
York Sun | aa150bb | 2013-03-25 07:40:07 +0000 | [diff] [blame] | 179 | * r10 has the base address for the entry. |
| 180 | * we cannot access it yet before setting up a new TLB |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 181 | */ |
York Sun | aa150bb | 2013-03-25 07:40:07 +0000 | [diff] [blame] | 182 | slwi r8,r5,6 /* spin table is padded to 64 byte */ |
| 183 | add r10,r3,r8 |
York Sun | 2adf2ce | 2012-08-17 08:20:26 +0000 | [diff] [blame] | 184 | |
| 185 | mtspr SPRN_PIR,r4 /* write to PIR register */ |
| 186 | |
York Sun | 548b8ba | 2017-10-17 08:00:21 -0700 | [diff] [blame] | 187 | #ifdef CONFIG_SYS_FSL_ERRATUM_A007907 |
| 188 | mfspr r8, L1CSR2 |
| 189 | clrrwi r8, r8, 10 /* clear bit [54-63] DCSTASHID */ |
| 190 | mtspr L1CSR2, r8 |
| 191 | #else |
York Sun | c3d87b1 | 2012-10-08 07:44:08 +0000 | [diff] [blame] | 192 | #ifdef CONFIG_SYS_CACHE_STASHING |
| 193 | /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */ |
| 194 | slwi r8,r4,1 |
| 195 | addi r8,r8,32 |
| 196 | mtspr L1CSR2,r8 |
| 197 | #endif |
York Sun | 548b8ba | 2017-10-17 08:00:21 -0700 | [diff] [blame] | 198 | #endif /* CONFIG_SYS_FSL_ERRATUM_A007907 */ |
York Sun | c3d87b1 | 2012-10-08 07:44:08 +0000 | [diff] [blame] | 199 | |
York Sun | 9ed8811 | 2012-05-07 07:26:47 +0000 | [diff] [blame] | 200 | #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \ |
| 201 | defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011) |
| 202 | /* |
| 203 | * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0 |
| 204 | * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0 |
| 205 | * also appleis to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1 |
| 206 | */ |
York Sun | d755c83 | 2012-05-07 07:26:45 +0000 | [diff] [blame] | 207 | mfspr r3,SPRN_SVR |
York Sun | 9ed8811 | 2012-05-07 07:26:47 +0000 | [diff] [blame] | 208 | rlwinm r6,r3,24,~0x800 /* clear E bit */ |
| 209 | |
| 210 | lis r5,SVR_P4080@h |
| 211 | ori r5,r5,SVR_P4080@l |
| 212 | cmpw r6,r5 |
| 213 | bne 1f |
| 214 | |
York Sun | d755c83 | 2012-05-07 07:26:45 +0000 | [diff] [blame] | 215 | rlwinm r3,r3,0,0xf0 |
York Sun | 9ed8811 | 2012-05-07 07:26:47 +0000 | [diff] [blame] | 216 | li r5,0x30 |
| 217 | cmpw r3,r5 |
York Sun | d755c83 | 2012-05-07 07:26:45 +0000 | [diff] [blame] | 218 | bge 2f |
York Sun | 9ed8811 | 2012-05-07 07:26:47 +0000 | [diff] [blame] | 219 | 1: |
York Sun | 5315553 | 2012-08-08 18:04:53 +0000 | [diff] [blame] | 220 | #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011 |
| 221 | lis r3,toreset(enable_cpu_a011_workaround)@ha |
| 222 | lwz r3,toreset(enable_cpu_a011_workaround)@l(r3) |
| 223 | cmpwi r3,0 |
| 224 | beq 2f |
| 225 | #endif |
York Sun | 9ed8811 | 2012-05-07 07:26:47 +0000 | [diff] [blame] | 226 | mfspr r3,L1CSR2 |
| 227 | oris r3,r3,(L1CSR2_DCWS)@h |
| 228 | mtspr L1CSR2,r3 |
York Sun | d755c83 | 2012-05-07 07:26:45 +0000 | [diff] [blame] | 229 | 2: |
Kumar Gala | 6b245b9 | 2010-05-05 22:35:27 -0500 | [diff] [blame] | 230 | #endif |
| 231 | |
York Sun | cca41c5 | 2013-06-25 11:37:49 -0700 | [diff] [blame] | 232 | #ifdef CONFIG_SYS_FSL_ERRATUM_A005812 |
| 233 | /* |
| 234 | * A-005812 workaround sets bit 32 of SPR 976 for SoCs running in |
| 235 | * write shadow mode. This code should run after other code setting |
| 236 | * DCWS. |
| 237 | */ |
| 238 | mfspr r3,L1CSR2 |
| 239 | andis. r3,r3,(L1CSR2_DCWS)@h |
| 240 | beq 1f |
| 241 | mfspr r3, SPRN_HDBCR0 |
| 242 | oris r3, r3, 0x8000 |
| 243 | mtspr SPRN_HDBCR0, r3 |
| 244 | 1: |
| 245 | #endif |
| 246 | |
Kumar Gala | e56f2c5 | 2009-03-19 09:16:10 -0500 | [diff] [blame] | 247 | #ifdef CONFIG_BACKSIDE_L2_CACHE |
Kumar Gala | e08c6d8 | 2011-07-21 00:20:21 -0500 | [diff] [blame] | 248 | /* skip L2 setup on P2040/P2040E as they have no L2 */ |
York Sun | 8d131c4 | 2012-05-07 07:39:53 +0000 | [diff] [blame] | 249 | mfspr r3,SPRN_SVR |
| 250 | rlwinm r6,r3,24,~0x800 /* clear E bit of SVR */ |
| 251 | |
Kumar Gala | e08c6d8 | 2011-07-21 00:20:21 -0500 | [diff] [blame] | 252 | lis r3,SVR_P2040@h |
| 253 | ori r3,r3,SVR_P2040@l |
York Sun | 8d131c4 | 2012-05-07 07:39:53 +0000 | [diff] [blame] | 254 | cmpw r6,r3 |
Kumar Gala | e08c6d8 | 2011-07-21 00:20:21 -0500 | [diff] [blame] | 255 | beq 3f |
| 256 | |
Kumar Gala | e56f2c5 | 2009-03-19 09:16:10 -0500 | [diff] [blame] | 257 | /* Enable/invalidate the L2 cache */ |
| 258 | msync |
Dave Liu | b8bb411 | 2009-10-31 07:59:55 +0800 | [diff] [blame] | 259 | lis r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@h |
| 260 | ori r2,r2,(L2CSR0_L2FI|L2CSR0_L2LFC)@l |
| 261 | mtspr SPRN_L2CSR0,r2 |
Kumar Gala | e56f2c5 | 2009-03-19 09:16:10 -0500 | [diff] [blame] | 262 | 1: |
| 263 | mfspr r3,SPRN_L2CSR0 |
Dave Liu | b8bb411 | 2009-10-31 07:59:55 +0800 | [diff] [blame] | 264 | and. r1,r3,r2 |
Kumar Gala | e56f2c5 | 2009-03-19 09:16:10 -0500 | [diff] [blame] | 265 | bne 1b |
| 266 | |
Kumar Gala | 8d2817c | 2009-03-19 02:53:01 -0500 | [diff] [blame] | 267 | #ifdef CONFIG_SYS_CACHE_STASHING |
| 268 | /* set stash id to (coreID) * 2 + 32 + L2 (1) */ |
| 269 | addi r3,r8,1 |
| 270 | mtspr SPRN_L2CSR1,r3 |
| 271 | #endif |
| 272 | |
Kumar Gala | e56f2c5 | 2009-03-19 09:16:10 -0500 | [diff] [blame] | 273 | lis r3,CONFIG_SYS_INIT_L2CSR0@h |
| 274 | ori r3,r3,CONFIG_SYS_INIT_L2CSR0@l |
| 275 | mtspr SPRN_L2CSR0,r3 |
| 276 | isync |
Dave Liu | b8bb411 | 2009-10-31 07:59:55 +0800 | [diff] [blame] | 277 | 2: |
| 278 | mfspr r3,SPRN_L2CSR0 |
| 279 | andis. r1,r3,L2CSR0_L2E@h |
| 280 | beq 2b |
Kumar Gala | e56f2c5 | 2009-03-19 09:16:10 -0500 | [diff] [blame] | 281 | #endif |
Kumar Gala | e08c6d8 | 2011-07-21 00:20:21 -0500 | [diff] [blame] | 282 | 3: |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 283 | /* setup mapping for the spin table, WIMGE=0b00100 */ |
| 284 | lis r13,toreset(__spin_table_addr)@h |
| 285 | ori r13,r13,toreset(__spin_table_addr)@l |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 286 | lwz r13,0(r13) |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 287 | /* mask by 4K */ |
| 288 | rlwinm r13,r13,0,0,19 |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 289 | |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 290 | lis r11,(MAS0_TLBSEL(1)|MAS0_ESEL(1))@h |
| 291 | mtspr SPRN_MAS0,r11 |
| 292 | lis r11,(MAS1_VALID|MAS1_IPROT)@h |
| 293 | ori r11,r11,(MAS1_TS|MAS1_TSIZE(BOOKE_PAGESZ_4K))@l |
| 294 | mtspr SPRN_MAS1,r11 |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 295 | oris r11,r13,(MAS2_M|MAS2_G)@h |
| 296 | ori r11,r13,(MAS2_M|MAS2_G)@l |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 297 | mtspr SPRN_MAS2,r11 |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 298 | oris r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@h |
| 299 | ori r11,r13,(MAS3_SX|MAS3_SW|MAS3_SR)@l |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 300 | mtspr SPRN_MAS3,r11 |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 301 | li r11,0 |
| 302 | mtspr SPRN_MAS7,r11 |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 303 | tlbwe |
| 304 | |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 305 | /* |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 306 | * __bootpg_addr has the address of __second_half_boot_page |
| 307 | * jump there in AS=1 space with cache enabled |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 308 | */ |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 309 | lis r13,toreset(__bootpg_addr)@h |
| 310 | ori r13,r13,toreset(__bootpg_addr)@l |
| 311 | lwz r11,0(r13) |
| 312 | mtspr SPRN_SRR0,r11 |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 313 | mfmsr r13 |
| 314 | ori r12,r13,MSR_IS|MSR_DS@l |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 315 | mtspr SPRN_SRR1,r12 |
| 316 | rfi |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 317 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 318 | /* |
| 319 | * Allocate some space for the SDRAM address of the bootpg. |
| 320 | * This variable has to be in the boot page so that it can |
| 321 | * be accessed by secondary cores when they come out of reset. |
| 322 | */ |
| 323 | .align L1_CACHE_SHIFT |
| 324 | .globl __bootpg_addr |
| 325 | __bootpg_addr: |
| 326 | .long 0 |
| 327 | |
| 328 | .global __spin_table_addr |
| 329 | __spin_table_addr: |
| 330 | .long 0 |
| 331 | |
| 332 | /* |
| 333 | * This variable is set by cpu_init_r() after parsing hwconfig |
| 334 | * to enable workaround for erratum NMG_CPU_A011. |
| 335 | */ |
| 336 | .align L1_CACHE_SHIFT |
| 337 | .global enable_cpu_a011_workaround |
| 338 | enable_cpu_a011_workaround: |
| 339 | .long 1 |
| 340 | |
| 341 | /* Fill in the empty space. The actual reset vector is |
| 342 | * the last word of the page */ |
| 343 | __secondary_start_code_end: |
| 344 | .space 4092 - (__secondary_start_code_end - __secondary_start_page) |
| 345 | __secondary_reset_vector: |
| 346 | b __secondary_start_page |
| 347 | |
| 348 | |
| 349 | /* this is a separated page for the spin table and cacheable boot code */ |
| 350 | .align L1_CACHE_SHIFT |
| 351 | .global __second_half_boot_page |
| 352 | __second_half_boot_page: |
York Sun | f066a04 | 2012-10-28 08:12:54 +0000 | [diff] [blame] | 353 | #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE |
| 354 | lis r3,(spin_table_compat - __second_half_boot_page)@h |
| 355 | ori r3,r3,(spin_table_compat - __second_half_boot_page)@l |
| 356 | add r3,r3,r11 /* r11 has the address of __second_half_boot_page */ |
| 357 | lwz r14,0(r3) |
| 358 | #endif |
| 359 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 360 | #define ENTRY_ADDR_UPPER 0 |
| 361 | #define ENTRY_ADDR_LOWER 4 |
| 362 | #define ENTRY_R3_UPPER 8 |
| 363 | #define ENTRY_R3_LOWER 12 |
| 364 | #define ENTRY_RESV 16 |
| 365 | #define ENTRY_PIR 20 |
| 366 | #define ENTRY_SIZE 64 |
| 367 | /* |
| 368 | * setup the entry |
| 369 | * r10 has the base address of the spin table. |
| 370 | * spin table is defined as |
| 371 | * struct { |
| 372 | * uint64_t entry_addr; |
| 373 | * uint64_t r3; |
| 374 | * uint32_t rsvd1; |
| 375 | * uint32_t pir; |
| 376 | * }; |
| 377 | * we pad this struct to 64 bytes so each entry is in its own cacheline |
| 378 | */ |
| 379 | li r3,0 |
| 380 | li r8,1 |
| 381 | mfspr r4,SPRN_PIR |
| 382 | stw r3,ENTRY_ADDR_UPPER(r10) |
| 383 | stw r3,ENTRY_R3_UPPER(r10) |
| 384 | stw r4,ENTRY_R3_LOWER(r10) |
| 385 | stw r3,ENTRY_RESV(r10) |
| 386 | stw r4,ENTRY_PIR(r10) |
| 387 | msync |
| 388 | stw r8,ENTRY_ADDR_LOWER(r10) |
| 389 | |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 390 | /* spin waiting for addr */ |
York Sun | f066a04 | 2012-10-28 08:12:54 +0000 | [diff] [blame] | 391 | 3: |
| 392 | /* |
| 393 | * To comply with ePAPR 1.1, the spin table has been moved to cache-enabled |
| 394 | * memory. Old OS may not work with this change. A patch is waiting to be |
| 395 | * accepted for Linux kernel. Other OS needs similar fix to spin table. |
| 396 | * For OSes with old spin table code, we can enable this temporary fix by |
| 397 | * setting environmental variable "spin_table_compat". For new OSes, set |
| 398 | * "spin_table_compat=no". After Linux is fixed, we can remove this macro |
| 399 | * and related code. For now, it is enabled by default. |
| 400 | */ |
| 401 | #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE |
| 402 | cmpwi r14,0 |
| 403 | beq 4f |
| 404 | dcbf 0, r10 |
| 405 | sync |
| 406 | 4: |
| 407 | #endif |
| 408 | lwz r4,ENTRY_ADDR_LOWER(r10) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 409 | andi. r11,r4,1 |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 410 | bne 3b |
Kumar Gala | 398dcd6 | 2008-04-28 02:24:04 -0500 | [diff] [blame] | 411 | isync |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 412 | |
| 413 | /* get the upper bits of the addr */ |
| 414 | lwz r11,ENTRY_ADDR_UPPER(r10) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 415 | |
| 416 | /* setup branch addr */ |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 417 | mtspr SPRN_SRR0,r4 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 418 | |
| 419 | /* mark the entry as released */ |
| 420 | li r8,3 |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 421 | stw r8,ENTRY_ADDR_LOWER(r10) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 422 | |
| 423 | /* mask by ~64M to setup our tlb we will jump to */ |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 424 | rlwinm r12,r4,0,0,5 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 425 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 426 | /* |
| 427 | * setup r3, r4, r5, r6, r7, r8, r9 |
| 428 | * r3 contains the value to put in the r3 register at secondary cpu |
| 429 | * entry. The high 32-bits are ignored on 32-bit chip implementations. |
| 430 | * 64-bit chip implementations however shall load all 64-bits |
| 431 | */ |
| 432 | #ifdef CONFIG_SYS_PPC64 |
| 433 | ld r3,ENTRY_R3_UPPER(r10) |
| 434 | #else |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 435 | lwz r3,ENTRY_R3_LOWER(r10) |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 436 | #endif |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 437 | li r4,0 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 438 | li r5,0 |
York Sun | 31a0c8c | 2012-10-08 07:44:29 +0000 | [diff] [blame] | 439 | li r6,0 |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 440 | lis r7,(64*1024*1024)@h |
| 441 | li r8,0 |
| 442 | li r9,0 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 443 | |
| 444 | /* load up the pir */ |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 445 | lwz r0,ENTRY_PIR(r10) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 446 | mtspr SPRN_PIR,r0 |
| 447 | mfspr r0,SPRN_PIR |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 448 | stw r0,ENTRY_PIR(r10) |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 449 | |
Haiying Wang | f474551 | 2008-12-03 10:08:19 -0500 | [diff] [blame] | 450 | mtspr IVPR,r12 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 451 | /* |
| 452 | * Coming here, we know the cpu has one TLB mapping in TLB1[0] |
| 453 | * which maps 0xfffff000-0xffffffff one-to-one. We set up a |
| 454 | * second mapping that maps addr 1:1 for 64M, and then we jump to |
| 455 | * addr |
| 456 | */ |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 457 | lis r10,(MAS0_TLBSEL(1)|MAS0_ESEL(0))@h |
| 458 | mtspr SPRN_MAS0,r10 |
| 459 | lis r10,(MAS1_VALID|MAS1_IPROT)@h |
| 460 | ori r10,r10,(MAS1_TSIZE(BOOKE_PAGESZ_64M))@l |
| 461 | mtspr SPRN_MAS1,r10 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 462 | /* WIMGE = 0b00000 for now */ |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 463 | mtspr SPRN_MAS2,r12 |
| 464 | ori r12,r12,(MAS3_SX|MAS3_SW|MAS3_SR) |
| 465 | mtspr SPRN_MAS3,r12 |
| 466 | #ifdef CONFIG_ENABLE_36BIT_PHYS |
| 467 | mtspr SPRN_MAS7,r11 |
| 468 | #endif |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 469 | tlbwe |
| 470 | |
| 471 | /* Now we have another mapping for this page, so we jump to that |
| 472 | * mapping |
| 473 | */ |
Kumar Gala | deeac57 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 474 | mtspr SPRN_SRR1,r13 |
| 475 | rfi |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 476 | |
Peter Tyser | 7feaacb | 2009-10-23 15:55:47 -0500 | [diff] [blame] | 477 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 478 | .align 6 |
Kumar Gala | 36d6b3f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 479 | .globl __spin_table |
| 480 | __spin_table: |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 481 | .space CONFIG_MAX_CPUS*ENTRY_SIZE |
York Sun | f066a04 | 2012-10-28 08:12:54 +0000 | [diff] [blame] | 482 | |
| 483 | #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE |
| 484 | .align L1_CACHE_SHIFT |
| 485 | .global spin_table_compat |
| 486 | spin_table_compat: |
| 487 | .long 1 |
| 488 | |
| 489 | #endif |
| 490 | |
York Sun | 2394a0f | 2012-10-08 07:44:30 +0000 | [diff] [blame] | 491 | __spin_table_end: |
| 492 | .space 4096 - (__spin_table_end - __spin_table) |