Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 2 | * Kernel execution entry point code. |
| 3 | * |
| 4 | * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org> |
| 5 | * Initial PowerPC version. |
| 6 | * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu> |
| 7 | * Rewritten for PReP |
| 8 | * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au> |
| 9 | * Low-level exception handers, MMU support, and rewrite. |
| 10 | * Copyright (c) 1997 Dan Malek <dmalek@jlc.net> |
| 11 | * PowerPC 8xx modifications. |
| 12 | * Copyright (c) 1998-1999 TiVo, Inc. |
| 13 | * PowerPC 403GCX modifications. |
| 14 | * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu> |
| 15 | * PowerPC 403GCX/405GP modifications. |
| 16 | * Copyright 2000 MontaVista Software Inc. |
| 17 | * PPC405 modifications |
| 18 | * PowerPC 403GCX/405GP modifications. |
| 19 | * Author: MontaVista Software, Inc. |
| 20 | * frank_rowand@mvista.com or source@mvista.com |
| 21 | * debbie_chu@mvista.com |
| 22 | * Copyright 2002-2005 MontaVista Software, Inc. |
| 23 | * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org> |
| 24 | * |
| 25 | * This program is free software; you can redistribute it and/or modify it |
| 26 | * under the terms of the GNU General Public License as published by the |
| 27 | * Free Software Foundation; either version 2 of the License, or (at your |
| 28 | * option) any later version. |
| 29 | */ |
| 30 | |
Tim Abbott | e703984 | 2009-04-25 22:11:05 -0400 | [diff] [blame] | 31 | #include <linux/init.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 32 | #include <asm/processor.h> |
| 33 | #include <asm/page.h> |
| 34 | #include <asm/mmu.h> |
| 35 | #include <asm/pgtable.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 36 | #include <asm/cputable.h> |
| 37 | #include <asm/thread_info.h> |
| 38 | #include <asm/ppc_asm.h> |
| 39 | #include <asm/asm-offsets.h> |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 40 | #include <asm/synch.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 41 | #include "head_booke.h" |
| 42 | |
| 43 | |
| 44 | /* As with the other PowerPC ports, it is expected that when code |
| 45 | * execution begins here, the following registers contain valid, yet |
| 46 | * optional, information: |
| 47 | * |
| 48 | * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.) |
| 49 | * r4 - Starting address of the init RAM disk |
| 50 | * r5 - Ending address of the init RAM disk |
| 51 | * r6 - Start of kernel command line string (e.g. "mem=128") |
| 52 | * r7 - End of kernel command line string |
| 53 | * |
| 54 | */ |
Tim Abbott | e703984 | 2009-04-25 22:11:05 -0400 | [diff] [blame] | 55 | __HEAD |
Kumar Gala | 748a768 | 2007-09-13 15:42:35 -0500 | [diff] [blame] | 56 | _ENTRY(_stext); |
| 57 | _ENTRY(_start); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 58 | /* |
| 59 | * Reserve a word at a fixed location to store the address |
| 60 | * of abatron_pteptrs |
| 61 | */ |
| 62 | nop |
| 63 | /* |
| 64 | * Save parameters we are passed |
| 65 | */ |
| 66 | mr r31,r3 |
| 67 | mr r30,r4 |
| 68 | mr r29,r5 |
| 69 | mr r28,r6 |
| 70 | mr r27,r7 |
| 71 | li r24,0 /* CPU number */ |
| 72 | |
Dave Kleikamp | 795033c | 2010-03-05 10:43:07 +0000 | [diff] [blame] | 73 | bl init_cpu_state |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 74 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 75 | /* |
| 76 | * This is where the main kernel code starts. |
| 77 | */ |
| 78 | |
| 79 | /* ptr to current */ |
| 80 | lis r2,init_task@h |
| 81 | ori r2,r2,init_task@l |
| 82 | |
| 83 | /* ptr to current thread */ |
| 84 | addi r4,r2,THREAD /* init task's THREAD */ |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 85 | mtspr SPRN_SPRG_THREAD,r4 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 86 | |
| 87 | /* stack */ |
| 88 | lis r1,init_thread_union@h |
| 89 | ori r1,r1,init_thread_union@l |
| 90 | li r0,0 |
| 91 | stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) |
| 92 | |
| 93 | bl early_init |
| 94 | |
| 95 | /* |
| 96 | * Decide what sort of machine this is and initialize the MMU. |
| 97 | */ |
| 98 | mr r3,r31 |
| 99 | mr r4,r30 |
| 100 | mr r5,r29 |
| 101 | mr r6,r28 |
| 102 | mr r7,r27 |
| 103 | bl machine_init |
| 104 | bl MMU_init |
| 105 | |
| 106 | /* Setup PTE pointers for the Abatron bdiGDB */ |
| 107 | lis r6, swapper_pg_dir@h |
| 108 | ori r6, r6, swapper_pg_dir@l |
| 109 | lis r5, abatron_pteptrs@h |
| 110 | ori r5, r5, abatron_pteptrs@l |
| 111 | lis r4, KERNELBASE@h |
| 112 | ori r4, r4, KERNELBASE@l |
| 113 | stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */ |
| 114 | stw r6, 0(r5) |
| 115 | |
| 116 | /* Let's move on */ |
| 117 | lis r4,start_kernel@h |
| 118 | ori r4,r4,start_kernel@l |
| 119 | lis r3,MSR_KERNEL@h |
| 120 | ori r3,r3,MSR_KERNEL@l |
| 121 | mtspr SPRN_SRR0,r4 |
| 122 | mtspr SPRN_SRR1,r3 |
| 123 | rfi /* change context and jump to start_kernel */ |
| 124 | |
| 125 | /* |
| 126 | * Interrupt vector entry code |
| 127 | * |
| 128 | * The Book E MMUs are always on so we don't need to handle |
| 129 | * interrupts in real mode as with previous PPC processors. In |
| 130 | * this case we handle interrupts in the kernel virtual address |
| 131 | * space. |
| 132 | * |
| 133 | * Interrupt vectors are dynamically placed relative to the |
| 134 | * interrupt prefix as determined by the address of interrupt_base. |
| 135 | * The interrupt vectors offsets are programmed using the labels |
| 136 | * for each interrupt vector entry. |
| 137 | * |
| 138 | * Interrupt vectors must be aligned on a 16 byte boundary. |
| 139 | * We align on a 32 byte cache line boundary for good measure. |
| 140 | */ |
| 141 | |
| 142 | interrupt_base: |
| 143 | /* Critical Input Interrupt */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 144 | CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 145 | |
| 146 | /* Machine Check Interrupt */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 147 | CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception) |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 148 | MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 149 | |
| 150 | /* Data Storage Interrupt */ |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 151 | DATA_STORAGE_EXCEPTION |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 152 | |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 153 | /* Instruction Storage Interrupt */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 154 | INSTRUCTION_STORAGE_EXCEPTION |
| 155 | |
| 156 | /* External Input Interrupt */ |
| 157 | EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE) |
| 158 | |
| 159 | /* Alignment Interrupt */ |
| 160 | ALIGNMENT_EXCEPTION |
| 161 | |
| 162 | /* Program Interrupt */ |
| 163 | PROGRAM_EXCEPTION |
| 164 | |
| 165 | /* Floating Point Unavailable Interrupt */ |
| 166 | #ifdef CONFIG_PPC_FPU |
| 167 | FP_UNAVAILABLE_EXCEPTION |
| 168 | #else |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 169 | EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 170 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 171 | /* System Call Interrupt */ |
| 172 | START_EXCEPTION(SystemCall) |
| 173 | NORMAL_EXCEPTION_PROLOG |
| 174 | EXC_XFER_EE_LITE(0x0c00, DoSyscall) |
| 175 | |
| 176 | /* Auxillary Processor Unavailable Interrupt */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 177 | EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 178 | |
| 179 | /* Decrementer Interrupt */ |
| 180 | DECREMENTER_EXCEPTION |
| 181 | |
| 182 | /* Fixed Internal Timer Interrupt */ |
| 183 | /* TODO: Add FIT support */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 184 | EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 185 | |
| 186 | /* Watchdog Timer Interrupt */ |
| 187 | /* TODO: Add watchdog support */ |
| 188 | #ifdef CONFIG_BOOKE_WDT |
| 189 | CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException) |
| 190 | #else |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 191 | CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 192 | #endif |
| 193 | |
| 194 | /* Data TLB Error Interrupt */ |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 195 | START_EXCEPTION(DataTLBError44x) |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 196 | mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ |
| 197 | mtspr SPRN_SPRG_WSCRATCH1, r11 |
| 198 | mtspr SPRN_SPRG_WSCRATCH2, r12 |
| 199 | mtspr SPRN_SPRG_WSCRATCH3, r13 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 200 | mfcr r11 |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 201 | mtspr SPRN_SPRG_WSCRATCH4, r11 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 202 | mfspr r10, SPRN_DEAR /* Get faulting address */ |
| 203 | |
| 204 | /* If we are faulting a kernel address, we have to use the |
| 205 | * kernel page tables. |
| 206 | */ |
Kumar Gala | 8a13c4f | 2007-10-11 13:36:52 -0500 | [diff] [blame] | 207 | lis r11, PAGE_OFFSET@h |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 208 | cmplw r10, r11 |
| 209 | blt+ 3f |
| 210 | lis r11, swapper_pg_dir@h |
| 211 | ori r11, r11, swapper_pg_dir@l |
| 212 | |
| 213 | mfspr r12,SPRN_MMUCR |
| 214 | rlwinm r12,r12,0,0,23 /* Clear TID */ |
| 215 | |
| 216 | b 4f |
| 217 | |
| 218 | /* Get the PGD for the current thread */ |
| 219 | 3: |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 220 | mfspr r11,SPRN_SPRG_THREAD |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 221 | lwz r11,PGDIR(r11) |
| 222 | |
| 223 | /* Load PID into MMUCR TID */ |
| 224 | mfspr r12,SPRN_MMUCR |
| 225 | mfspr r13,SPRN_PID /* Get PID */ |
| 226 | rlwimi r12,r13,0,24,31 /* Set TID */ |
| 227 | |
| 228 | 4: |
| 229 | mtspr SPRN_MMUCR,r12 |
| 230 | |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 231 | /* Mask of required permission bits. Note that while we |
| 232 | * do copy ESR:ST to _PAGE_RW position as trying to write |
| 233 | * to an RO page is pretty common, we don't do it with |
| 234 | * _PAGE_DIRTY. We could do it, but it's a fairly rare |
| 235 | * event so I'd rather take the overhead when it happens |
| 236 | * rather than adding an instruction here. We should measure |
| 237 | * whether the whole thing is worth it in the first place |
| 238 | * as we could avoid loading SPRN_ESR completely in the first |
| 239 | * place... |
| 240 | * |
| 241 | * TODO: Is it worth doing that mfspr & rlwimi in the first |
| 242 | * place or can we save a couple of instructions here ? |
| 243 | */ |
| 244 | mfspr r12,SPRN_ESR |
| 245 | li r13,_PAGE_PRESENT|_PAGE_ACCESSED |
| 246 | rlwimi r13,r12,10,30,30 |
| 247 | |
| 248 | /* Load the PTE */ |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 249 | /* Compute pgdir/pmd offset */ |
| 250 | rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 251 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
| 252 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ |
| 253 | beq 2f /* Bail if no table */ |
| 254 | |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 255 | /* Compute pte address */ |
| 256 | rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 257 | lwz r11, 0(r12) /* Get high word of pte entry */ |
| 258 | lwz r12, 4(r12) /* Get low word of pte entry */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 259 | |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 260 | lis r10,tlb_44x_index@ha |
| 261 | |
| 262 | andc. r13,r13,r12 /* Check permission */ |
| 263 | |
| 264 | /* Load the next available TLB index */ |
| 265 | lwz r13,tlb_44x_index@l(r10) |
| 266 | |
| 267 | bne 2f /* Bail if permission mismach */ |
| 268 | |
| 269 | /* Increment, rollover, and store TLB index */ |
| 270 | addi r13,r13,1 |
| 271 | |
| 272 | /* Compare with watermark (instruction gets patched) */ |
| 273 | .globl tlb_44x_patch_hwater_D |
| 274 | tlb_44x_patch_hwater_D: |
| 275 | cmpwi 0,r13,1 /* reserve entries */ |
| 276 | ble 5f |
| 277 | li r13,0 |
| 278 | 5: |
| 279 | /* Store the next available TLB index */ |
| 280 | stw r13,tlb_44x_index@l(r10) |
| 281 | |
| 282 | /* Re-load the faulting address */ |
| 283 | mfspr r10,SPRN_DEAR |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 284 | |
| 285 | /* Jump to common tlb load */ |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 286 | b finish_tlb_load_44x |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 287 | |
| 288 | 2: |
| 289 | /* The bailout. Restore registers to pre-exception conditions |
| 290 | * and call the heavyweights to help us out. |
| 291 | */ |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 292 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 293 | mtcr r11 |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 294 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
| 295 | mfspr r12, SPRN_SPRG_RSCRATCH2 |
| 296 | mfspr r11, SPRN_SPRG_RSCRATCH1 |
| 297 | mfspr r10, SPRN_SPRG_RSCRATCH0 |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 298 | b DataStorage |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 299 | |
| 300 | /* Instruction TLB Error Interrupt */ |
| 301 | /* |
| 302 | * Nearly the same as above, except we get our |
| 303 | * information from different registers and bailout |
| 304 | * to a different point. |
| 305 | */ |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 306 | START_EXCEPTION(InstructionTLBError44x) |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 307 | mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ |
| 308 | mtspr SPRN_SPRG_WSCRATCH1, r11 |
| 309 | mtspr SPRN_SPRG_WSCRATCH2, r12 |
| 310 | mtspr SPRN_SPRG_WSCRATCH3, r13 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 311 | mfcr r11 |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 312 | mtspr SPRN_SPRG_WSCRATCH4, r11 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 313 | mfspr r10, SPRN_SRR0 /* Get faulting address */ |
| 314 | |
| 315 | /* If we are faulting a kernel address, we have to use the |
| 316 | * kernel page tables. |
| 317 | */ |
Kumar Gala | 8a13c4f | 2007-10-11 13:36:52 -0500 | [diff] [blame] | 318 | lis r11, PAGE_OFFSET@h |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 319 | cmplw r10, r11 |
| 320 | blt+ 3f |
| 321 | lis r11, swapper_pg_dir@h |
| 322 | ori r11, r11, swapper_pg_dir@l |
| 323 | |
| 324 | mfspr r12,SPRN_MMUCR |
| 325 | rlwinm r12,r12,0,0,23 /* Clear TID */ |
| 326 | |
| 327 | b 4f |
| 328 | |
| 329 | /* Get the PGD for the current thread */ |
| 330 | 3: |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 331 | mfspr r11,SPRN_SPRG_THREAD |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 332 | lwz r11,PGDIR(r11) |
| 333 | |
| 334 | /* Load PID into MMUCR TID */ |
| 335 | mfspr r12,SPRN_MMUCR |
| 336 | mfspr r13,SPRN_PID /* Get PID */ |
| 337 | rlwimi r12,r13,0,24,31 /* Set TID */ |
| 338 | |
| 339 | 4: |
| 340 | mtspr SPRN_MMUCR,r12 |
| 341 | |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 342 | /* Make up the required permissions */ |
Benjamin Herrenschmidt | ea3cc33 | 2009-08-18 19:00:34 +0000 | [diff] [blame] | 343 | li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 344 | |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 345 | /* Compute pgdir/pmd offset */ |
| 346 | rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 347 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
| 348 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ |
| 349 | beq 2f /* Bail if no table */ |
| 350 | |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 351 | /* Compute pte address */ |
| 352 | rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 353 | lwz r11, 0(r12) /* Get high word of pte entry */ |
| 354 | lwz r12, 4(r12) /* Get low word of pte entry */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 355 | |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 356 | lis r10,tlb_44x_index@ha |
| 357 | |
| 358 | andc. r13,r13,r12 /* Check permission */ |
| 359 | |
| 360 | /* Load the next available TLB index */ |
| 361 | lwz r13,tlb_44x_index@l(r10) |
| 362 | |
| 363 | bne 2f /* Bail if permission mismach */ |
| 364 | |
| 365 | /* Increment, rollover, and store TLB index */ |
| 366 | addi r13,r13,1 |
| 367 | |
| 368 | /* Compare with watermark (instruction gets patched) */ |
| 369 | .globl tlb_44x_patch_hwater_I |
| 370 | tlb_44x_patch_hwater_I: |
| 371 | cmpwi 0,r13,1 /* reserve entries */ |
| 372 | ble 5f |
| 373 | li r13,0 |
| 374 | 5: |
| 375 | /* Store the next available TLB index */ |
| 376 | stw r13,tlb_44x_index@l(r10) |
| 377 | |
| 378 | /* Re-load the faulting address */ |
| 379 | mfspr r10,SPRN_SRR0 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 380 | |
| 381 | /* Jump to common TLB load point */ |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 382 | b finish_tlb_load_44x |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 383 | |
| 384 | 2: |
| 385 | /* The bailout. Restore registers to pre-exception conditions |
| 386 | * and call the heavyweights to help us out. |
| 387 | */ |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 388 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 389 | mtcr r11 |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 390 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
| 391 | mfspr r12, SPRN_SPRG_RSCRATCH2 |
| 392 | mfspr r11, SPRN_SPRG_RSCRATCH1 |
| 393 | mfspr r10, SPRN_SPRG_RSCRATCH0 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 394 | b InstructionStorage |
| 395 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 396 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 397 | * Both the instruction and data TLB miss get to this |
| 398 | * point to load the TLB. |
| 399 | * r10 - EA of fault |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 400 | * r11 - PTE high word value |
| 401 | * r12 - PTE low word value |
| 402 | * r13 - TLB index |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 403 | * MMUCR - loaded with proper value when we get here |
| 404 | * Upon exit, we reload everything and RFI. |
| 405 | */ |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 406 | finish_tlb_load_44x: |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 407 | /* Combine RPN & ERPN an write WS 0 */ |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 408 | rlwimi r11,r12,0,0,31-PAGE_SHIFT |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 409 | tlbwe r11,r13,PPC44x_TLB_XLAT |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 410 | |
| 411 | /* |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 412 | * Create WS1. This is the faulting address (EPN), |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 413 | * page size, and valid flag. |
| 414 | */ |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 415 | li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE |
| 416 | /* Insert valid and page size */ |
| 417 | rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31 |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 418 | tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 419 | |
Benjamin Herrenschmidt | 1bc54c0 | 2008-07-08 15:54:40 +1000 | [diff] [blame] | 420 | /* And WS 2 */ |
| 421 | li r10,0xf85 /* Mask to apply from PTE */ |
| 422 | rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ |
| 423 | and r11,r12,r10 /* Mask PTE bits to keep */ |
| 424 | andi. r10,r12,_PAGE_USER /* User page ? */ |
| 425 | beq 1f /* nope, leave U bits empty */ |
| 426 | rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ |
| 427 | 1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 428 | |
| 429 | /* Done...restore registers and get out of here. |
| 430 | */ |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 431 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 432 | mtcr r11 |
Benjamin Herrenschmidt | ee43eb7 | 2009-07-14 20:52:54 +0000 | [diff] [blame] | 433 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
| 434 | mfspr r12, SPRN_SPRG_RSCRATCH2 |
| 435 | mfspr r11, SPRN_SPRG_RSCRATCH1 |
| 436 | mfspr r10, SPRN_SPRG_RSCRATCH0 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 437 | rfi /* Force context change */ |
| 438 | |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 439 | /* TLB error interrupts for 476 |
| 440 | */ |
| 441 | #ifdef CONFIG_PPC_47x |
| 442 | START_EXCEPTION(DataTLBError47x) |
| 443 | mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */ |
| 444 | mtspr SPRN_SPRG_WSCRATCH1,r11 |
| 445 | mtspr SPRN_SPRG_WSCRATCH2,r12 |
| 446 | mtspr SPRN_SPRG_WSCRATCH3,r13 |
| 447 | mfcr r11 |
| 448 | mtspr SPRN_SPRG_WSCRATCH4,r11 |
| 449 | mfspr r10,SPRN_DEAR /* Get faulting address */ |
| 450 | |
| 451 | /* If we are faulting a kernel address, we have to use the |
| 452 | * kernel page tables. |
| 453 | */ |
| 454 | lis r11,PAGE_OFFSET@h |
| 455 | cmplw cr0,r10,r11 |
| 456 | blt+ 3f |
| 457 | lis r11,swapper_pg_dir@h |
| 458 | ori r11,r11, swapper_pg_dir@l |
| 459 | li r12,0 /* MMUCR = 0 */ |
| 460 | b 4f |
| 461 | |
| 462 | /* Get the PGD for the current thread and setup MMUCR */ |
| 463 | 3: mfspr r11,SPRN_SPRG3 |
| 464 | lwz r11,PGDIR(r11) |
| 465 | mfspr r12,SPRN_PID /* Get PID */ |
| 466 | 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ |
| 467 | |
| 468 | /* Mask of required permission bits. Note that while we |
| 469 | * do copy ESR:ST to _PAGE_RW position as trying to write |
| 470 | * to an RO page is pretty common, we don't do it with |
| 471 | * _PAGE_DIRTY. We could do it, but it's a fairly rare |
| 472 | * event so I'd rather take the overhead when it happens |
| 473 | * rather than adding an instruction here. We should measure |
| 474 | * whether the whole thing is worth it in the first place |
| 475 | * as we could avoid loading SPRN_ESR completely in the first |
| 476 | * place... |
| 477 | * |
| 478 | * TODO: Is it worth doing that mfspr & rlwimi in the first |
| 479 | * place or can we save a couple of instructions here ? |
| 480 | */ |
| 481 | mfspr r12,SPRN_ESR |
| 482 | li r13,_PAGE_PRESENT|_PAGE_ACCESSED |
| 483 | rlwimi r13,r12,10,30,30 |
| 484 | |
| 485 | /* Load the PTE */ |
| 486 | /* Compute pgdir/pmd offset */ |
| 487 | rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29 |
| 488 | lwzx r11,r12,r11 /* Get pgd/pmd entry */ |
| 489 | |
| 490 | /* Word 0 is EPN,V,TS,DSIZ */ |
| 491 | li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE |
| 492 | rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/ |
| 493 | li r12,0 |
| 494 | tlbwe r10,r12,0 |
| 495 | |
| 496 | /* XXX can we do better ? Need to make sure tlbwe has established |
| 497 | * latch V bit in MMUCR0 before the PTE is loaded further down */ |
| 498 | #ifdef CONFIG_SMP |
| 499 | isync |
| 500 | #endif |
| 501 | |
| 502 | rlwinm. r12,r11,0,0,20 /* Extract pt base address */ |
| 503 | /* Compute pte address */ |
| 504 | rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28 |
| 505 | beq 2f /* Bail if no table */ |
| 506 | lwz r11,0(r12) /* Get high word of pte entry */ |
| 507 | |
| 508 | /* XXX can we do better ? maybe insert a known 0 bit from r11 into the |
| 509 | * bottom of r12 to create a data dependency... We can also use r10 |
| 510 | * as destination nowadays |
| 511 | */ |
| 512 | #ifdef CONFIG_SMP |
| 513 | lwsync |
| 514 | #endif |
| 515 | lwz r12,4(r12) /* Get low word of pte entry */ |
| 516 | |
| 517 | andc. r13,r13,r12 /* Check permission */ |
| 518 | |
| 519 | /* Jump to common tlb load */ |
| 520 | beq finish_tlb_load_47x |
| 521 | |
| 522 | 2: /* The bailout. Restore registers to pre-exception conditions |
| 523 | * and call the heavyweights to help us out. |
| 524 | */ |
| 525 | mfspr r11,SPRN_SPRG_RSCRATCH4 |
| 526 | mtcr r11 |
| 527 | mfspr r13,SPRN_SPRG_RSCRATCH3 |
| 528 | mfspr r12,SPRN_SPRG_RSCRATCH2 |
| 529 | mfspr r11,SPRN_SPRG_RSCRATCH1 |
| 530 | mfspr r10,SPRN_SPRG_RSCRATCH0 |
| 531 | b DataStorage |
| 532 | |
| 533 | /* Instruction TLB Error Interrupt */ |
| 534 | /* |
| 535 | * Nearly the same as above, except we get our |
| 536 | * information from different registers and bailout |
| 537 | * to a different point. |
| 538 | */ |
| 539 | START_EXCEPTION(InstructionTLBError47x) |
| 540 | mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */ |
| 541 | mtspr SPRN_SPRG_WSCRATCH1,r11 |
| 542 | mtspr SPRN_SPRG_WSCRATCH2,r12 |
| 543 | mtspr SPRN_SPRG_WSCRATCH3,r13 |
| 544 | mfcr r11 |
| 545 | mtspr SPRN_SPRG_WSCRATCH4,r11 |
| 546 | mfspr r10,SPRN_SRR0 /* Get faulting address */ |
| 547 | |
| 548 | /* If we are faulting a kernel address, we have to use the |
| 549 | * kernel page tables. |
| 550 | */ |
| 551 | lis r11,PAGE_OFFSET@h |
| 552 | cmplw cr0,r10,r11 |
| 553 | blt+ 3f |
| 554 | lis r11,swapper_pg_dir@h |
| 555 | ori r11,r11, swapper_pg_dir@l |
| 556 | li r12,0 /* MMUCR = 0 */ |
| 557 | b 4f |
| 558 | |
| 559 | /* Get the PGD for the current thread and setup MMUCR */ |
| 560 | 3: mfspr r11,SPRN_SPRG_THREAD |
| 561 | lwz r11,PGDIR(r11) |
| 562 | mfspr r12,SPRN_PID /* Get PID */ |
| 563 | 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ |
| 564 | |
| 565 | /* Make up the required permissions */ |
| 566 | li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC |
| 567 | |
| 568 | /* Load PTE */ |
| 569 | /* Compute pgdir/pmd offset */ |
| 570 | rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29 |
| 571 | lwzx r11,r12,r11 /* Get pgd/pmd entry */ |
| 572 | |
| 573 | /* Word 0 is EPN,V,TS,DSIZ */ |
| 574 | li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE |
| 575 | rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/ |
| 576 | li r12,0 |
| 577 | tlbwe r10,r12,0 |
| 578 | |
| 579 | /* XXX can we do better ? Need to make sure tlbwe has established |
| 580 | * latch V bit in MMUCR0 before the PTE is loaded further down */ |
| 581 | #ifdef CONFIG_SMP |
| 582 | isync |
| 583 | #endif |
| 584 | |
| 585 | rlwinm. r12,r11,0,0,20 /* Extract pt base address */ |
| 586 | /* Compute pte address */ |
| 587 | rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28 |
| 588 | beq 2f /* Bail if no table */ |
| 589 | |
| 590 | lwz r11,0(r12) /* Get high word of pte entry */ |
| 591 | /* XXX can we do better ? maybe insert a known 0 bit from r11 into the |
| 592 | * bottom of r12 to create a data dependency... We can also use r10 |
| 593 | * as destination nowadays |
| 594 | */ |
| 595 | #ifdef CONFIG_SMP |
| 596 | lwsync |
| 597 | #endif |
| 598 | lwz r12,4(r12) /* Get low word of pte entry */ |
| 599 | |
| 600 | andc. r13,r13,r12 /* Check permission */ |
| 601 | |
| 602 | /* Jump to common TLB load point */ |
| 603 | beq finish_tlb_load_47x |
| 604 | |
| 605 | 2: /* The bailout. Restore registers to pre-exception conditions |
| 606 | * and call the heavyweights to help us out. |
| 607 | */ |
| 608 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
| 609 | mtcr r11 |
| 610 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
| 611 | mfspr r12, SPRN_SPRG_RSCRATCH2 |
| 612 | mfspr r11, SPRN_SPRG_RSCRATCH1 |
| 613 | mfspr r10, SPRN_SPRG_RSCRATCH0 |
| 614 | b InstructionStorage |
| 615 | |
| 616 | /* |
| 617 | * Both the instruction and data TLB miss get to this |
| 618 | * point to load the TLB. |
| 619 | * r10 - free to use |
| 620 | * r11 - PTE high word value |
| 621 | * r12 - PTE low word value |
| 622 | * r13 - free to use |
| 623 | * MMUCR - loaded with proper value when we get here |
| 624 | * Upon exit, we reload everything and RFI. |
| 625 | */ |
| 626 | finish_tlb_load_47x: |
| 627 | /* Combine RPN & ERPN an write WS 1 */ |
| 628 | rlwimi r11,r12,0,0,31-PAGE_SHIFT |
| 629 | tlbwe r11,r13,1 |
| 630 | |
| 631 | /* And make up word 2 */ |
| 632 | li r10,0xf85 /* Mask to apply from PTE */ |
| 633 | rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ |
| 634 | and r11,r12,r10 /* Mask PTE bits to keep */ |
| 635 | andi. r10,r12,_PAGE_USER /* User page ? */ |
| 636 | beq 1f /* nope, leave U bits empty */ |
| 637 | rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ |
| 638 | 1: tlbwe r11,r13,2 |
| 639 | |
| 640 | /* Done...restore registers and get out of here. |
| 641 | */ |
| 642 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
| 643 | mtcr r11 |
| 644 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
| 645 | mfspr r12, SPRN_SPRG_RSCRATCH2 |
| 646 | mfspr r11, SPRN_SPRG_RSCRATCH1 |
| 647 | mfspr r10, SPRN_SPRG_RSCRATCH0 |
| 648 | rfi |
| 649 | |
| 650 | #endif /* CONFIG_PPC_47x */ |
| 651 | |
| 652 | /* Debug Interrupt */ |
| 653 | /* |
| 654 | * This statement needs to exist at the end of the IVPR |
| 655 | * definition just in case you end up taking a debug |
| 656 | * exception within another exception. |
| 657 | */ |
| 658 | DEBUG_CRIT_EXCEPTION |
| 659 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 660 | /* |
| 661 | * Global functions |
| 662 | */ |
| 663 | |
| 664 | /* |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 665 | * Adjust the machine check IVOR on 440A cores |
| 666 | */ |
| 667 | _GLOBAL(__fixup_440A_mcheck) |
| 668 | li r3,MachineCheckA@l |
| 669 | mtspr SPRN_IVOR1,r3 |
| 670 | sync |
| 671 | blr |
| 672 | |
| 673 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 674 | * extern void giveup_altivec(struct task_struct *prev) |
| 675 | * |
| 676 | * The 44x core does not have an AltiVec unit. |
| 677 | */ |
| 678 | _GLOBAL(giveup_altivec) |
| 679 | blr |
| 680 | |
| 681 | /* |
| 682 | * extern void giveup_fpu(struct task_struct *prev) |
| 683 | * |
| 684 | * The 44x core does not have an FPU. |
| 685 | */ |
| 686 | #ifndef CONFIG_PPC_FPU |
| 687 | _GLOBAL(giveup_fpu) |
| 688 | blr |
| 689 | #endif |
| 690 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 691 | _GLOBAL(set_context) |
| 692 | |
| 693 | #ifdef CONFIG_BDI_SWITCH |
| 694 | /* Context switch the PTE pointer for the Abatron BDI2000. |
| 695 | * The PGDIR is the second parameter. |
| 696 | */ |
| 697 | lis r5, abatron_pteptrs@h |
| 698 | ori r5, r5, abatron_pteptrs@l |
| 699 | stw r4, 0x4(r5) |
| 700 | #endif |
| 701 | mtspr SPRN_PID,r3 |
| 702 | isync /* Force context change */ |
| 703 | blr |
| 704 | |
| 705 | /* |
Dave Kleikamp | 795033c | 2010-03-05 10:43:07 +0000 | [diff] [blame] | 706 | * Init CPU state. This is called at boot time or for secondary CPUs |
| 707 | * to setup initial TLB entries, setup IVORs, etc... |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 708 | * |
Dave Kleikamp | 795033c | 2010-03-05 10:43:07 +0000 | [diff] [blame] | 709 | */ |
| 710 | _GLOBAL(init_cpu_state) |
| 711 | mflr r22 |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 712 | #ifdef CONFIG_PPC_47x |
| 713 | /* We use the PVR to differenciate 44x cores from 476 */ |
| 714 | mfspr r3,SPRN_PVR |
| 715 | srwi r3,r3,16 |
| 716 | cmplwi cr0,r3,PVR_476@h |
| 717 | beq head_start_47x |
| 718 | #endif /* CONFIG_PPC_47x */ |
| 719 | |
Dave Kleikamp | 795033c | 2010-03-05 10:43:07 +0000 | [diff] [blame] | 720 | /* |
| 721 | * In case the firmware didn't do it, we apply some workarounds |
| 722 | * that are good for all 440 core variants here |
| 723 | */ |
| 724 | mfspr r3,SPRN_CCR0 |
| 725 | rlwinm r3,r3,0,0,27 /* disable icache prefetch */ |
| 726 | isync |
| 727 | mtspr SPRN_CCR0,r3 |
| 728 | isync |
| 729 | sync |
| 730 | |
| 731 | /* |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 732 | * Set up the initial MMU state for 44x |
Dave Kleikamp | 795033c | 2010-03-05 10:43:07 +0000 | [diff] [blame] | 733 | * |
| 734 | * We are still executing code at the virtual address |
| 735 | * mappings set by the firmware for the base of RAM. |
| 736 | * |
| 737 | * We first invalidate all TLB entries but the one |
| 738 | * we are running from. We then load the KERNELBASE |
| 739 | * mappings so we can begin to use kernel addresses |
| 740 | * natively and so the interrupt vector locations are |
| 741 | * permanently pinned (necessary since Book E |
| 742 | * implementations always have translation enabled). |
| 743 | * |
| 744 | * TODO: Use the known TLB entry we are running from to |
| 745 | * determine which physical region we are located |
| 746 | * in. This can be used to determine where in RAM |
| 747 | * (on a shared CPU system) or PCI memory space |
| 748 | * (on a DRAMless system) we are located. |
| 749 | * For now, we assume a perfect world which means |
| 750 | * we are located at the base of DRAM (physical 0). |
| 751 | */ |
| 752 | |
| 753 | /* |
| 754 | * Search TLB for entry that we are currently using. |
| 755 | * Invalidate all entries but the one we are using. |
| 756 | */ |
| 757 | /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ |
| 758 | mfspr r3,SPRN_PID /* Get PID */ |
| 759 | mfmsr r4 /* Get MSR */ |
| 760 | andi. r4,r4,MSR_IS@l /* TS=1? */ |
| 761 | beq wmmucr /* If not, leave STS=0 */ |
| 762 | oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */ |
| 763 | wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ |
| 764 | sync |
| 765 | |
| 766 | bl invstr /* Find our address */ |
| 767 | invstr: mflr r5 /* Make it accessible */ |
| 768 | tlbsx r23,0,r5 /* Find entry we are in */ |
| 769 | li r4,0 /* Start at TLB entry 0 */ |
| 770 | li r3,0 /* Set PAGEID inval value */ |
| 771 | 1: cmpw r23,r4 /* Is this our entry? */ |
| 772 | beq skpinv /* If so, skip the inval */ |
| 773 | tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */ |
| 774 | skpinv: addi r4,r4,1 /* Increment */ |
| 775 | cmpwi r4,64 /* Are we done? */ |
| 776 | bne 1b /* If not, repeat */ |
| 777 | isync /* If so, context change */ |
| 778 | |
| 779 | /* |
| 780 | * Configure and load pinned entry into TLB slot 63. |
| 781 | */ |
| 782 | |
| 783 | lis r3,PAGE_OFFSET@h |
| 784 | ori r3,r3,PAGE_OFFSET@l |
| 785 | |
| 786 | /* Kernel is at the base of RAM */ |
| 787 | li r4, 0 /* Load the kernel physical address */ |
| 788 | |
| 789 | /* Load the kernel PID = 0 */ |
| 790 | li r0,0 |
| 791 | mtspr SPRN_PID,r0 |
| 792 | sync |
| 793 | |
| 794 | /* Initialize MMUCR */ |
| 795 | li r5,0 |
| 796 | mtspr SPRN_MMUCR,r5 |
| 797 | sync |
| 798 | |
| 799 | /* pageid fields */ |
| 800 | clrrwi r3,r3,10 /* Mask off the effective page number */ |
| 801 | ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M |
| 802 | |
| 803 | /* xlat fields */ |
| 804 | clrrwi r4,r4,10 /* Mask off the real page number */ |
| 805 | /* ERPN is 0 for first 4GB page */ |
| 806 | |
| 807 | /* attrib fields */ |
| 808 | /* Added guarded bit to protect against speculative loads/stores */ |
| 809 | li r5,0 |
| 810 | ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G) |
| 811 | |
| 812 | li r0,63 /* TLB slot 63 */ |
| 813 | |
| 814 | tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */ |
| 815 | tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */ |
| 816 | tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */ |
| 817 | |
| 818 | /* Force context change */ |
| 819 | mfmsr r0 |
| 820 | mtspr SPRN_SRR1, r0 |
| 821 | lis r0,3f@h |
| 822 | ori r0,r0,3f@l |
| 823 | mtspr SPRN_SRR0,r0 |
| 824 | sync |
| 825 | rfi |
| 826 | |
| 827 | /* If necessary, invalidate original entry we used */ |
| 828 | 3: cmpwi r23,63 |
| 829 | beq 4f |
| 830 | li r6,0 |
| 831 | tlbwe r6,r23,PPC44x_TLB_PAGEID |
| 832 | isync |
| 833 | |
| 834 | 4: |
| 835 | #ifdef CONFIG_PPC_EARLY_DEBUG_44x |
| 836 | /* Add UART mapping for early debug. */ |
| 837 | |
| 838 | /* pageid fields */ |
| 839 | lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h |
| 840 | ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K |
| 841 | |
| 842 | /* xlat fields */ |
| 843 | lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h |
| 844 | ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH |
| 845 | |
| 846 | /* attrib fields */ |
| 847 | li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G) |
| 848 | li r0,62 /* TLB slot 0 */ |
| 849 | |
| 850 | tlbwe r3,r0,PPC44x_TLB_PAGEID |
| 851 | tlbwe r4,r0,PPC44x_TLB_XLAT |
| 852 | tlbwe r5,r0,PPC44x_TLB_ATTRIB |
| 853 | |
| 854 | /* Force context change */ |
| 855 | isync |
| 856 | #endif /* CONFIG_PPC_EARLY_DEBUG_44x */ |
| 857 | |
| 858 | /* Establish the interrupt vector offsets */ |
| 859 | SET_IVOR(0, CriticalInput); |
| 860 | SET_IVOR(1, MachineCheck); |
| 861 | SET_IVOR(2, DataStorage); |
| 862 | SET_IVOR(3, InstructionStorage); |
| 863 | SET_IVOR(4, ExternalInput); |
| 864 | SET_IVOR(5, Alignment); |
| 865 | SET_IVOR(6, Program); |
| 866 | SET_IVOR(7, FloatingPointUnavailable); |
| 867 | SET_IVOR(8, SystemCall); |
| 868 | SET_IVOR(9, AuxillaryProcessorUnavailable); |
| 869 | SET_IVOR(10, Decrementer); |
| 870 | SET_IVOR(11, FixedIntervalTimer); |
| 871 | SET_IVOR(12, WatchdogTimer); |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 872 | SET_IVOR(13, DataTLBError44x); |
| 873 | SET_IVOR(14, InstructionTLBError44x); |
Dave Kleikamp | 795033c | 2010-03-05 10:43:07 +0000 | [diff] [blame] | 874 | SET_IVOR(15, DebugCrit); |
| 875 | |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 876 | b head_start_common |
| 877 | |
| 878 | |
| 879 | #ifdef CONFIG_PPC_47x |
| 880 | |
| 881 | #ifdef CONFIG_SMP |
| 882 | |
| 883 | /* Entry point for secondary 47x processors */ |
| 884 | _GLOBAL(start_secondary_47x) |
| 885 | mr r24,r3 /* CPU number */ |
| 886 | |
| 887 | bl init_cpu_state |
| 888 | |
| 889 | /* Now we need to bolt the rest of kernel memory which |
| 890 | * is done in C code. We must be careful because our task |
| 891 | * struct or our stack can (and will probably) be out |
| 892 | * of reach of the initial 256M TLB entry, so we use a |
| 893 | * small temporary stack in .bss for that. This works |
| 894 | * because only one CPU at a time can be in this code |
| 895 | */ |
| 896 | lis r1,temp_boot_stack@h |
| 897 | ori r1,r1,temp_boot_stack@l |
| 898 | addi r1,r1,1024-STACK_FRAME_OVERHEAD |
| 899 | li r0,0 |
| 900 | stw r0,0(r1) |
| 901 | bl mmu_init_secondary |
| 902 | |
| 903 | /* Now we can get our task struct and real stack pointer */ |
| 904 | |
| 905 | /* Get current_thread_info and current */ |
| 906 | lis r1,secondary_ti@ha |
| 907 | lwz r1,secondary_ti@l(r1) |
| 908 | lwz r2,TI_TASK(r1) |
| 909 | |
| 910 | /* Current stack pointer */ |
| 911 | addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD |
| 912 | li r0,0 |
| 913 | stw r0,0(r1) |
| 914 | |
| 915 | /* Kernel stack for exception entry in SPRG3 */ |
| 916 | addi r4,r2,THREAD /* init task's THREAD */ |
| 917 | mtspr SPRN_SPRG3,r4 |
| 918 | |
| 919 | b start_secondary |
| 920 | |
| 921 | #endif /* CONFIG_SMP */ |
| 922 | |
| 923 | /* |
| 924 | * Set up the initial MMU state for 44x |
| 925 | * |
| 926 | * We are still executing code at the virtual address |
| 927 | * mappings set by the firmware for the base of RAM. |
| 928 | */ |
| 929 | |
| 930 | head_start_47x: |
| 931 | /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ |
| 932 | mfspr r3,SPRN_PID /* Get PID */ |
| 933 | mfmsr r4 /* Get MSR */ |
| 934 | andi. r4,r4,MSR_IS@l /* TS=1? */ |
| 935 | beq 1f /* If not, leave STS=0 */ |
| 936 | oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */ |
| 937 | 1: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ |
| 938 | sync |
| 939 | |
| 940 | /* Find the entry we are running from */ |
| 941 | bl 1f |
| 942 | 1: mflr r23 |
| 943 | tlbsx r23,0,r23 |
| 944 | tlbre r24,r23,0 |
| 945 | tlbre r25,r23,1 |
| 946 | tlbre r26,r23,2 |
| 947 | |
| 948 | /* |
| 949 | * Cleanup time |
| 950 | */ |
| 951 | |
| 952 | /* Initialize MMUCR */ |
| 953 | li r5,0 |
| 954 | mtspr SPRN_MMUCR,r5 |
| 955 | sync |
| 956 | |
| 957 | clear_all_utlb_entries: |
| 958 | |
| 959 | #; Set initial values. |
| 960 | |
| 961 | addis r3,0,0x8000 |
| 962 | addi r4,0,0 |
| 963 | addi r5,0,0 |
| 964 | b clear_utlb_entry |
| 965 | |
| 966 | #; Align the loop to speed things up. |
| 967 | |
| 968 | .align 6 |
| 969 | |
| 970 | clear_utlb_entry: |
| 971 | |
| 972 | tlbwe r4,r3,0 |
| 973 | tlbwe r5,r3,1 |
| 974 | tlbwe r5,r3,2 |
| 975 | addis r3,r3,0x2000 |
| 976 | cmpwi r3,0 |
| 977 | bne clear_utlb_entry |
| 978 | addis r3,0,0x8000 |
| 979 | addis r4,r4,0x100 |
| 980 | cmpwi r4,0 |
| 981 | bne clear_utlb_entry |
| 982 | |
| 983 | #; Restore original entry. |
| 984 | |
| 985 | oris r23,r23,0x8000 /* specify the way */ |
| 986 | tlbwe r24,r23,0 |
| 987 | tlbwe r25,r23,1 |
| 988 | tlbwe r26,r23,2 |
| 989 | |
| 990 | /* |
| 991 | * Configure and load pinned entry into TLB for the kernel core |
| 992 | */ |
| 993 | |
| 994 | lis r3,PAGE_OFFSET@h |
| 995 | ori r3,r3,PAGE_OFFSET@l |
| 996 | |
| 997 | /* Kernel is at the base of RAM */ |
| 998 | li r4, 0 /* Load the kernel physical address */ |
| 999 | |
| 1000 | /* Load the kernel PID = 0 */ |
| 1001 | li r0,0 |
| 1002 | mtspr SPRN_PID,r0 |
| 1003 | sync |
| 1004 | |
| 1005 | /* Word 0 */ |
| 1006 | clrrwi r3,r3,12 /* Mask off the effective page number */ |
| 1007 | ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M |
| 1008 | |
| 1009 | /* Word 1 */ |
| 1010 | clrrwi r4,r4,12 /* Mask off the real page number */ |
| 1011 | /* ERPN is 0 for first 4GB page */ |
| 1012 | /* Word 2 */ |
| 1013 | li r5,0 |
| 1014 | ori r5,r5,PPC47x_TLB2_S_RWX |
| 1015 | #ifdef CONFIG_SMP |
| 1016 | ori r5,r5,PPC47x_TLB2_M |
| 1017 | #endif |
| 1018 | |
| 1019 | /* We write to way 0 and bolted 0 */ |
| 1020 | lis r0,0x8800 |
| 1021 | tlbwe r3,r0,0 |
| 1022 | tlbwe r4,r0,1 |
| 1023 | tlbwe r5,r0,2 |
| 1024 | |
| 1025 | /* |
| 1026 | * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix |
| 1027 | * them up later |
| 1028 | */ |
| 1029 | LOAD_REG_IMMEDIATE(r3, 0x9abcdef0) |
| 1030 | mtspr SPRN_SSPCR,r3 |
| 1031 | mtspr SPRN_USPCR,r3 |
| 1032 | LOAD_REG_IMMEDIATE(r3, 0x12345670) |
| 1033 | mtspr SPRN_ISPCR,r3 |
| 1034 | |
| 1035 | /* Force context change */ |
| 1036 | mfmsr r0 |
| 1037 | mtspr SPRN_SRR1, r0 |
| 1038 | lis r0,3f@h |
| 1039 | ori r0,r0,3f@l |
| 1040 | mtspr SPRN_SRR0,r0 |
| 1041 | sync |
| 1042 | rfi |
| 1043 | |
| 1044 | /* Invalidate original entry we used */ |
| 1045 | 3: |
| 1046 | rlwinm r24,r24,0,21,19 /* clear the "valid" bit */ |
| 1047 | tlbwe r24,r23,0 |
| 1048 | addi r24,0,0 |
| 1049 | tlbwe r24,r23,1 |
| 1050 | tlbwe r24,r23,2 |
| 1051 | isync /* Clear out the shadow TLB entries */ |
| 1052 | |
| 1053 | #ifdef CONFIG_PPC_EARLY_DEBUG_44x |
| 1054 | /* Add UART mapping for early debug. */ |
| 1055 | |
| 1056 | /* Word 0 */ |
| 1057 | lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h |
| 1058 | ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M |
| 1059 | |
| 1060 | /* Word 1 */ |
| 1061 | lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h |
| 1062 | ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH |
| 1063 | |
| 1064 | /* Word 2 */ |
| 1065 | li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG) |
| 1066 | |
| 1067 | /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same |
| 1068 | * congruence class as the kernel, we need to make sure of it at |
| 1069 | * some point |
| 1070 | */ |
| 1071 | lis r0,0x8d00 |
| 1072 | tlbwe r3,r0,0 |
| 1073 | tlbwe r4,r0,1 |
| 1074 | tlbwe r5,r0,2 |
| 1075 | |
| 1076 | /* Force context change */ |
| 1077 | isync |
| 1078 | #endif /* CONFIG_PPC_EARLY_DEBUG_44x */ |
| 1079 | |
| 1080 | /* Establish the interrupt vector offsets */ |
| 1081 | SET_IVOR(0, CriticalInput); |
| 1082 | SET_IVOR(1, MachineCheckA); |
| 1083 | SET_IVOR(2, DataStorage); |
| 1084 | SET_IVOR(3, InstructionStorage); |
| 1085 | SET_IVOR(4, ExternalInput); |
| 1086 | SET_IVOR(5, Alignment); |
| 1087 | SET_IVOR(6, Program); |
| 1088 | SET_IVOR(7, FloatingPointUnavailable); |
| 1089 | SET_IVOR(8, SystemCall); |
| 1090 | SET_IVOR(9, AuxillaryProcessorUnavailable); |
| 1091 | SET_IVOR(10, Decrementer); |
| 1092 | SET_IVOR(11, FixedIntervalTimer); |
| 1093 | SET_IVOR(12, WatchdogTimer); |
| 1094 | SET_IVOR(13, DataTLBError47x); |
| 1095 | SET_IVOR(14, InstructionTLBError47x); |
| 1096 | SET_IVOR(15, DebugCrit); |
| 1097 | |
| 1098 | /* We configure icbi to invalidate 128 bytes at a time since the |
| 1099 | * current 32-bit kernel code isn't too happy with icache != dcache |
| 1100 | * block size |
| 1101 | */ |
| 1102 | mfspr r3,SPRN_CCR0 |
| 1103 | oris r3,r3,0x0020 |
| 1104 | mtspr SPRN_CCR0,r3 |
| 1105 | isync |
| 1106 | |
| 1107 | #endif /* CONFIG_PPC_47x */ |
| 1108 | |
| 1109 | /* |
| 1110 | * Here we are back to code that is common between 44x and 47x |
| 1111 | * |
| 1112 | * We proceed to further kernel initialization and return to the |
| 1113 | * main kernel entry |
| 1114 | */ |
| 1115 | head_start_common: |
Dave Kleikamp | 795033c | 2010-03-05 10:43:07 +0000 | [diff] [blame] | 1116 | /* Establish the interrupt vector base */ |
| 1117 | lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */ |
| 1118 | mtspr SPRN_IVPR,r4 |
| 1119 | |
| 1120 | addis r22,r22,KERNELBASE@h |
| 1121 | mtlr r22 |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 1122 | isync |
Dave Kleikamp | 795033c | 2010-03-05 10:43:07 +0000 | [diff] [blame] | 1123 | blr |
| 1124 | |
| 1125 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1126 | * We put a few things here that have to be page-aligned. This stuff |
| 1127 | * goes at the beginning of the data segment, which is page-aligned. |
| 1128 | */ |
| 1129 | .data |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 1130 | .align PAGE_SHIFT |
Kumar Gala | ea703ce | 2005-10-11 23:54:00 -0500 | [diff] [blame] | 1131 | .globl sdata |
| 1132 | sdata: |
| 1133 | .globl empty_zero_page |
| 1134 | empty_zero_page: |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 1135 | .space PAGE_SIZE |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1136 | |
| 1137 | /* |
| 1138 | * To support >32-bit physical addresses, we use an 8KB pgdir. |
| 1139 | */ |
Kumar Gala | ea703ce | 2005-10-11 23:54:00 -0500 | [diff] [blame] | 1140 | .globl swapper_pg_dir |
| 1141 | swapper_pg_dir: |
Kumar Gala | bee86f1 | 2007-12-06 13:11:04 -0600 | [diff] [blame] | 1142 | .space PGD_TABLE_SIZE |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1143 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1144 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1145 | * Room for two PTE pointers, usually the kernel and current user pointers |
| 1146 | * to their respective root page table. |
| 1147 | */ |
| 1148 | abatron_pteptrs: |
| 1149 | .space 8 |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame^] | 1150 | |
| 1151 | #ifdef CONFIG_SMP |
| 1152 | .align 12 |
| 1153 | temp_boot_stack: |
| 1154 | .space 1024 |
| 1155 | #endif /* CONFIG_SMP */ |