12874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */ 214cf11afSPaul Mackerras/* 314cf11afSPaul Mackerras * Kernel execution entry point code. 414cf11afSPaul Mackerras * 514cf11afSPaul Mackerras * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org> 614cf11afSPaul Mackerras * Initial PowerPC version. 714cf11afSPaul Mackerras * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu> 814cf11afSPaul Mackerras * Rewritten for PReP 914cf11afSPaul Mackerras * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au> 1014cf11afSPaul Mackerras * Low-level exception handers, MMU support, and rewrite. 1114cf11afSPaul Mackerras * Copyright (c) 1997 Dan Malek <dmalek@jlc.net> 1214cf11afSPaul Mackerras * PowerPC 8xx modifications. 1314cf11afSPaul Mackerras * Copyright (c) 1998-1999 TiVo, Inc. 1414cf11afSPaul Mackerras * PowerPC 403GCX modifications. 1514cf11afSPaul Mackerras * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu> 1614cf11afSPaul Mackerras * PowerPC 403GCX/405GP modifications. 1714cf11afSPaul Mackerras * Copyright 2000 MontaVista Software Inc. 1814cf11afSPaul Mackerras * PPC405 modifications 1914cf11afSPaul Mackerras * PowerPC 403GCX/405GP modifications. 2014cf11afSPaul Mackerras * Author: MontaVista Software, Inc. 2114cf11afSPaul Mackerras * frank_rowand@mvista.com or source@mvista.com 2214cf11afSPaul Mackerras * debbie_chu@mvista.com 2314cf11afSPaul Mackerras * Copyright 2002-2005 MontaVista Software, Inc. 2414cf11afSPaul Mackerras * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org> 2514cf11afSPaul Mackerras */ 2614cf11afSPaul Mackerras 27e7039845STim Abbott#include <linux/init.h> 2865fddcfcSMike Rapoport#include <linux/pgtable.h> 2914cf11afSPaul Mackerras#include <asm/processor.h> 3014cf11afSPaul Mackerras#include <asm/page.h> 3114cf11afSPaul Mackerras#include <asm/mmu.h> 3214cf11afSPaul Mackerras#include <asm/cputable.h> 3314cf11afSPaul Mackerras#include <asm/thread_info.h> 3414cf11afSPaul Mackerras#include <asm/ppc_asm.h> 3514cf11afSPaul Mackerras#include <asm/asm-offsets.h> 3646f52210SStephen Rothwell#include <asm/ptrace.h> 37e7f75ad0SDave Kleikamp#include <asm/synch.h> 386c16816bSChristophe Leroy#include <asm/code-patching-asm.h> 3914cf11afSPaul Mackerras#include "head_booke.h" 4014cf11afSPaul Mackerras 4114cf11afSPaul Mackerras 4214cf11afSPaul Mackerras/* As with the other PowerPC ports, it is expected that when code 4314cf11afSPaul Mackerras * execution begins here, the following registers contain valid, yet 4414cf11afSPaul Mackerras * optional, information: 4514cf11afSPaul Mackerras * 4614cf11afSPaul Mackerras * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.) 4714cf11afSPaul Mackerras * r4 - Starting address of the init RAM disk 4814cf11afSPaul Mackerras * r5 - Ending address of the init RAM disk 4914cf11afSPaul Mackerras * r6 - Start of kernel command line string (e.g. "mem=128") 5014cf11afSPaul Mackerras * r7 - End of kernel command line string 5114cf11afSPaul Mackerras * 5214cf11afSPaul Mackerras */ 53e7039845STim Abbott __HEAD 5427e21e8fSChristophe Leroy_GLOBAL(_stext); 5527e21e8fSChristophe Leroy_GLOBAL(_start); 5614cf11afSPaul Mackerras /* 5714cf11afSPaul Mackerras * Reserve a word at a fixed location to store the address 5814cf11afSPaul Mackerras * of abatron_pteptrs 5914cf11afSPaul Mackerras */ 6014cf11afSPaul Mackerras nop 616dece0ebSScott Wood mr r31,r3 /* save device tree ptr */ 6214cf11afSPaul Mackerras li r24,0 /* CPU number */ 6314cf11afSPaul Mackerras 6426ecb6c4SSuzuki Poulose#ifdef CONFIG_RELOCATABLE 6526ecb6c4SSuzuki Poulose/* 6626ecb6c4SSuzuki Poulose * Relocate ourselves to the current runtime address. 6726ecb6c4SSuzuki Poulose * This is called only by the Boot CPU. 6826ecb6c4SSuzuki Poulose * "relocate" is called with our current runtime virutal 6926ecb6c4SSuzuki Poulose * address. 7026ecb6c4SSuzuki Poulose * r21 will be loaded with the physical runtime address of _stext 7126ecb6c4SSuzuki Poulose */ 72f5007dbfSChristophe Leroy bcl 20,31,$+4 /* Get our runtime address */ 7326ecb6c4SSuzuki Poulose0: mflr r21 /* Make it accessible */ 7426ecb6c4SSuzuki Poulose addis r21,r21,(_stext - 0b)@ha 7526ecb6c4SSuzuki Poulose addi r21,r21,(_stext - 0b)@l /* Get our current runtime base */ 7626ecb6c4SSuzuki Poulose 7726ecb6c4SSuzuki Poulose /* 7826ecb6c4SSuzuki Poulose * We have the runtime (virutal) address of our base. 7926ecb6c4SSuzuki Poulose * We calculate our shift of offset from a 256M page. 8026ecb6c4SSuzuki Poulose * We could map the 256M page we belong to at PAGE_OFFSET and 8126ecb6c4SSuzuki Poulose * get going from there. 8226ecb6c4SSuzuki Poulose */ 8326ecb6c4SSuzuki Poulose lis r4,KERNELBASE@h 8426ecb6c4SSuzuki Poulose ori r4,r4,KERNELBASE@l 8526ecb6c4SSuzuki Poulose rlwinm r6,r21,0,4,31 /* r6 = PHYS_START % 256M */ 8626ecb6c4SSuzuki Poulose rlwinm r5,r4,0,4,31 /* r5 = KERNELBASE % 256M */ 8726ecb6c4SSuzuki Poulose subf r3,r5,r6 /* r3 = r6 - r5 */ 8826ecb6c4SSuzuki Poulose add r3,r4,r3 /* Required Virutal Address */ 8926ecb6c4SSuzuki Poulose 9026ecb6c4SSuzuki Poulose bl relocate 9126ecb6c4SSuzuki Poulose#endif 9226ecb6c4SSuzuki Poulose 93795033c3SDave Kleikamp bl init_cpu_state 9414cf11afSPaul Mackerras 9514cf11afSPaul Mackerras /* 9614cf11afSPaul Mackerras * This is where the main kernel code starts. 9714cf11afSPaul Mackerras */ 9814cf11afSPaul Mackerras 9914cf11afSPaul Mackerras /* ptr to current */ 10014cf11afSPaul Mackerras lis r2,init_task@h 10114cf11afSPaul Mackerras ori r2,r2,init_task@l 10214cf11afSPaul Mackerras 10314cf11afSPaul Mackerras /* ptr to current thread */ 10414cf11afSPaul Mackerras addi r4,r2,THREAD /* init task's THREAD */ 105ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_THREAD,r4 10614cf11afSPaul Mackerras 10714cf11afSPaul Mackerras /* stack */ 10814cf11afSPaul Mackerras lis r1,init_thread_union@h 10914cf11afSPaul Mackerras ori r1,r1,init_thread_union@l 11014cf11afSPaul Mackerras li r0,0 111*90f1b431SNicholas Piggin stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1) 11214cf11afSPaul Mackerras 11314cf11afSPaul Mackerras bl early_init 11414cf11afSPaul Mackerras 11526ecb6c4SSuzuki Poulose#ifdef CONFIG_RELOCATABLE 11626ecb6c4SSuzuki Poulose /* 11726ecb6c4SSuzuki Poulose * Relocatable kernel support based on processing of dynamic 11826ecb6c4SSuzuki Poulose * relocation entries. 11926ecb6c4SSuzuki Poulose * 12026ecb6c4SSuzuki Poulose * r25 will contain RPN/ERPN for the start address of memory 12126ecb6c4SSuzuki Poulose * r21 will contain the current offset of _stext 12226ecb6c4SSuzuki Poulose */ 12326ecb6c4SSuzuki Poulose lis r3,kernstart_addr@ha 12426ecb6c4SSuzuki Poulose la r3,kernstart_addr@l(r3) 12526ecb6c4SSuzuki Poulose 12626ecb6c4SSuzuki Poulose /* 12726ecb6c4SSuzuki Poulose * Compute the kernstart_addr. 12826ecb6c4SSuzuki Poulose * kernstart_addr => (r6,r8) 12926ecb6c4SSuzuki Poulose * kernstart_addr & ~0xfffffff => (r6,r7) 13026ecb6c4SSuzuki Poulose */ 13126ecb6c4SSuzuki Poulose rlwinm r6,r25,0,28,31 /* ERPN. Bits 32-35 of Address */ 13226ecb6c4SSuzuki Poulose rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */ 13326ecb6c4SSuzuki Poulose rlwinm r8,r21,0,4,31 /* r8 = (_stext & 0xfffffff) */ 13426ecb6c4SSuzuki Poulose or r8,r7,r8 /* Compute the lower 32bit of kernstart_addr */ 13526ecb6c4SSuzuki Poulose 13626ecb6c4SSuzuki Poulose /* Store kernstart_addr */ 13726ecb6c4SSuzuki Poulose stw r6,0(r3) /* higher 32bit */ 13826ecb6c4SSuzuki Poulose stw r8,4(r3) /* lower 32bit */ 13926ecb6c4SSuzuki Poulose 14026ecb6c4SSuzuki Poulose /* 14126ecb6c4SSuzuki Poulose * Compute the virt_phys_offset : 14226ecb6c4SSuzuki Poulose * virt_phys_offset = stext.run - kernstart_addr 14326ecb6c4SSuzuki Poulose * 14426ecb6c4SSuzuki Poulose * stext.run = (KERNELBASE & ~0xfffffff) + (kernstart_addr & 0xfffffff) 14526ecb6c4SSuzuki Poulose * When we relocate, we have : 14626ecb6c4SSuzuki Poulose * 14726ecb6c4SSuzuki Poulose * (kernstart_addr & 0xfffffff) = (stext.run & 0xfffffff) 14826ecb6c4SSuzuki Poulose * 14926ecb6c4SSuzuki Poulose * hence: 15026ecb6c4SSuzuki Poulose * virt_phys_offset = (KERNELBASE & ~0xfffffff) - (kernstart_addr & ~0xfffffff) 15126ecb6c4SSuzuki Poulose * 15226ecb6c4SSuzuki Poulose */ 15326ecb6c4SSuzuki Poulose 15426ecb6c4SSuzuki Poulose /* KERNELBASE&~0xfffffff => (r4,r5) */ 15526ecb6c4SSuzuki Poulose li r4, 0 /* higer 32bit */ 15626ecb6c4SSuzuki Poulose lis r5,KERNELBASE@h 15726ecb6c4SSuzuki Poulose rlwinm r5,r5,0,0,3 /* Align to 256M, lower 32bit */ 15826ecb6c4SSuzuki Poulose 15926ecb6c4SSuzuki Poulose /* 16026ecb6c4SSuzuki Poulose * 64bit subtraction. 16126ecb6c4SSuzuki Poulose */ 16226ecb6c4SSuzuki Poulose subfc r5,r7,r5 16326ecb6c4SSuzuki Poulose subfe r4,r6,r4 16426ecb6c4SSuzuki Poulose 16526ecb6c4SSuzuki Poulose /* Store virt_phys_offset */ 16626ecb6c4SSuzuki Poulose lis r3,virt_phys_offset@ha 16726ecb6c4SSuzuki Poulose la r3,virt_phys_offset@l(r3) 16826ecb6c4SSuzuki Poulose 16926ecb6c4SSuzuki Poulose stw r4,0(r3) 17026ecb6c4SSuzuki Poulose stw r5,4(r3) 17126ecb6c4SSuzuki Poulose 17226ecb6c4SSuzuki Poulose#elif defined(CONFIG_DYNAMIC_MEMSTART) 1739661534dSDave Kleikamp /* 1740f890c8dSSuzuki Poulose * Mapping based, page aligned dynamic kernel loading. 1750f890c8dSSuzuki Poulose * 1769661534dSDave Kleikamp * r25 will contain RPN/ERPN for the start address of memory 1779661534dSDave Kleikamp * 1789661534dSDave Kleikamp * Add the difference between KERNELBASE and PAGE_OFFSET to the 1799661534dSDave Kleikamp * start of physical memory to get kernstart_addr. 1809661534dSDave Kleikamp */ 1819661534dSDave Kleikamp lis r3,kernstart_addr@ha 1829661534dSDave Kleikamp la r3,kernstart_addr@l(r3) 1839661534dSDave Kleikamp 1849661534dSDave Kleikamp lis r4,KERNELBASE@h 1859661534dSDave Kleikamp ori r4,r4,KERNELBASE@l 1869661534dSDave Kleikamp lis r5,PAGE_OFFSET@h 1879661534dSDave Kleikamp ori r5,r5,PAGE_OFFSET@l 1889661534dSDave Kleikamp subf r4,r5,r4 1899661534dSDave Kleikamp 1909661534dSDave Kleikamp rlwinm r6,r25,0,28,31 /* ERPN */ 1919661534dSDave Kleikamp rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */ 1929661534dSDave Kleikamp add r7,r7,r4 1939661534dSDave Kleikamp 1949661534dSDave Kleikamp stw r6,0(r3) 1959661534dSDave Kleikamp stw r7,4(r3) 1969661534dSDave Kleikamp#endif 1979661534dSDave Kleikamp 19814cf11afSPaul Mackerras/* 19914cf11afSPaul Mackerras * Decide what sort of machine this is and initialize the MMU. 20014cf11afSPaul Mackerras */ 2012edb16efSChristophe Leroy#ifdef CONFIG_KASAN 2022edb16efSChristophe Leroy bl kasan_early_init 2032edb16efSChristophe Leroy#endif 2046dece0ebSScott Wood li r3,0 2056dece0ebSScott Wood mr r4,r31 20614cf11afSPaul Mackerras bl machine_init 20714cf11afSPaul Mackerras bl MMU_init 20814cf11afSPaul Mackerras 20914cf11afSPaul Mackerras /* Setup PTE pointers for the Abatron bdiGDB */ 21014cf11afSPaul Mackerras lis r6, swapper_pg_dir@h 21114cf11afSPaul Mackerras ori r6, r6, swapper_pg_dir@l 21214cf11afSPaul Mackerras lis r5, abatron_pteptrs@h 21314cf11afSPaul Mackerras ori r5, r5, abatron_pteptrs@l 21414cf11afSPaul Mackerras lis r4, KERNELBASE@h 21514cf11afSPaul Mackerras ori r4, r4, KERNELBASE@l 21614cf11afSPaul Mackerras stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */ 21714cf11afSPaul Mackerras stw r6, 0(r5) 21814cf11afSPaul Mackerras 219029b8f66SDave Kleikamp /* Clear the Machine Check Syndrome Register */ 220029b8f66SDave Kleikamp li r0,0 221029b8f66SDave Kleikamp mtspr SPRN_MCSR,r0 222029b8f66SDave Kleikamp 22314cf11afSPaul Mackerras /* Let's move on */ 22414cf11afSPaul Mackerras lis r4,start_kernel@h 22514cf11afSPaul Mackerras ori r4,r4,start_kernel@l 22614cf11afSPaul Mackerras lis r3,MSR_KERNEL@h 22714cf11afSPaul Mackerras ori r3,r3,MSR_KERNEL@l 22814cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 22914cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 23014cf11afSPaul Mackerras rfi /* change context and jump to start_kernel */ 23114cf11afSPaul Mackerras 23214cf11afSPaul Mackerras/* 23314cf11afSPaul Mackerras * Interrupt vector entry code 23414cf11afSPaul Mackerras * 23514cf11afSPaul Mackerras * The Book E MMUs are always on so we don't need to handle 23614cf11afSPaul Mackerras * interrupts in real mode as with previous PPC processors. In 23714cf11afSPaul Mackerras * this case we handle interrupts in the kernel virtual address 23814cf11afSPaul Mackerras * space. 23914cf11afSPaul Mackerras * 24014cf11afSPaul Mackerras * Interrupt vectors are dynamically placed relative to the 24114cf11afSPaul Mackerras * interrupt prefix as determined by the address of interrupt_base. 24214cf11afSPaul Mackerras * The interrupt vectors offsets are programmed using the labels 24314cf11afSPaul Mackerras * for each interrupt vector entry. 24414cf11afSPaul Mackerras * 24514cf11afSPaul Mackerras * Interrupt vectors must be aligned on a 16 byte boundary. 24614cf11afSPaul Mackerras * We align on a 32 byte cache line boundary for good measure. 24714cf11afSPaul Mackerras */ 24814cf11afSPaul Mackerras 24914cf11afSPaul Mackerrasinterrupt_base: 25014cf11afSPaul Mackerras /* Critical Input Interrupt */ 251cfac5784SScott Wood CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception) 25214cf11afSPaul Mackerras 25314cf11afSPaul Mackerras /* Machine Check Interrupt */ 254cfac5784SScott Wood CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \ 255cfac5784SScott Wood machine_check_exception) 25647c0bd1aSBenjamin Herrenschmidt MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception) 25714cf11afSPaul Mackerras 25814cf11afSPaul Mackerras /* Data Storage Interrupt */ 2591bc54c03SBenjamin Herrenschmidt DATA_STORAGE_EXCEPTION 26014cf11afSPaul Mackerras 26114cf11afSPaul Mackerras /* Instruction Storage Interrupt */ 26214cf11afSPaul Mackerras INSTRUCTION_STORAGE_EXCEPTION 26314cf11afSPaul Mackerras 26414cf11afSPaul Mackerras /* External Input Interrupt */ 265acc142b6SChristophe Leroy EXCEPTION(0x0500, BOOKE_INTERRUPT_EXTERNAL, ExternalInput, do_IRQ) 26614cf11afSPaul Mackerras 26714cf11afSPaul Mackerras /* Alignment Interrupt */ 26814cf11afSPaul Mackerras ALIGNMENT_EXCEPTION 26914cf11afSPaul Mackerras 27014cf11afSPaul Mackerras /* Program Interrupt */ 27114cf11afSPaul Mackerras PROGRAM_EXCEPTION 27214cf11afSPaul Mackerras 27314cf11afSPaul Mackerras /* Floating Point Unavailable Interrupt */ 27414cf11afSPaul Mackerras#ifdef CONFIG_PPC_FPU 27514cf11afSPaul Mackerras FP_UNAVAILABLE_EXCEPTION 27614cf11afSPaul Mackerras#else 277cfac5784SScott Wood EXCEPTION(0x2010, BOOKE_INTERRUPT_FP_UNAVAIL, \ 278acc142b6SChristophe Leroy FloatingPointUnavailable, unknown_exception) 27914cf11afSPaul Mackerras#endif 28014cf11afSPaul Mackerras /* System Call Interrupt */ 28114cf11afSPaul Mackerras START_EXCEPTION(SystemCall) 2821a4b739bSChristophe Leroy SYSCALL_ENTRY 0xc00 BOOKE_INTERRUPT_SYSCALL 28314cf11afSPaul Mackerras 28425985edcSLucas De Marchi /* Auxiliary Processor Unavailable Interrupt */ 285cfac5784SScott Wood EXCEPTION(0x2020, BOOKE_INTERRUPT_AP_UNAVAIL, \ 286acc142b6SChristophe Leroy AuxillaryProcessorUnavailable, unknown_exception) 28714cf11afSPaul Mackerras 28814cf11afSPaul Mackerras /* Decrementer Interrupt */ 28914cf11afSPaul Mackerras DECREMENTER_EXCEPTION 29014cf11afSPaul Mackerras 29114cf11afSPaul Mackerras /* Fixed Internal Timer Interrupt */ 29214cf11afSPaul Mackerras /* TODO: Add FIT support */ 293acc142b6SChristophe Leroy EXCEPTION(0x1010, BOOKE_INTERRUPT_FIT, FixedIntervalTimer, unknown_exception) 29414cf11afSPaul Mackerras 29514cf11afSPaul Mackerras /* Watchdog Timer Interrupt */ 29614cf11afSPaul Mackerras /* TODO: Add watchdog support */ 29714cf11afSPaul Mackerras#ifdef CONFIG_BOOKE_WDT 298cfac5784SScott Wood CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, WatchdogException) 29914cf11afSPaul Mackerras#else 300cfac5784SScott Wood CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, unknown_exception) 30114cf11afSPaul Mackerras#endif 30214cf11afSPaul Mackerras 30314cf11afSPaul Mackerras /* Data TLB Error Interrupt */ 304e7f75ad0SDave Kleikamp START_EXCEPTION(DataTLBError44x) 305ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ 306ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH1, r11 307ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH2, r12 308ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH3, r13 30914cf11afSPaul Mackerras mfcr r11 310ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH4, r11 31114cf11afSPaul Mackerras mfspr r10, SPRN_DEAR /* Get faulting address */ 31214cf11afSPaul Mackerras 31314cf11afSPaul Mackerras /* If we are faulting a kernel address, we have to use the 31414cf11afSPaul Mackerras * kernel page tables. 31514cf11afSPaul Mackerras */ 3168a13c4f9SKumar Gala lis r11, PAGE_OFFSET@h 31714cf11afSPaul Mackerras cmplw r10, r11 31814cf11afSPaul Mackerras blt+ 3f 31914cf11afSPaul Mackerras lis r11, swapper_pg_dir@h 32014cf11afSPaul Mackerras ori r11, r11, swapper_pg_dir@l 32114cf11afSPaul Mackerras 32214cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 32314cf11afSPaul Mackerras rlwinm r12,r12,0,0,23 /* Clear TID */ 32414cf11afSPaul Mackerras 32514cf11afSPaul Mackerras b 4f 32614cf11afSPaul Mackerras 32714cf11afSPaul Mackerras /* Get the PGD for the current thread */ 32814cf11afSPaul Mackerras3: 329ee43eb78SBenjamin Herrenschmidt mfspr r11,SPRN_SPRG_THREAD 33014cf11afSPaul Mackerras lwz r11,PGDIR(r11) 33114cf11afSPaul Mackerras 33214cf11afSPaul Mackerras /* Load PID into MMUCR TID */ 33314cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 33414cf11afSPaul Mackerras mfspr r13,SPRN_PID /* Get PID */ 33514cf11afSPaul Mackerras rlwimi r12,r13,0,24,31 /* Set TID */ 336f6fad4fbSChristophe Leroy#ifdef CONFIG_PPC_KUAP 337f6fad4fbSChristophe Leroy cmpwi r13,0 338f6fad4fbSChristophe Leroy beq 2f /* KUAP Fault */ 339f6fad4fbSChristophe Leroy#endif 34014cf11afSPaul Mackerras 34114cf11afSPaul Mackerras4: 34214cf11afSPaul Mackerras mtspr SPRN_MMUCR,r12 34314cf11afSPaul Mackerras 3441bc54c03SBenjamin Herrenschmidt /* Mask of required permission bits. Note that while we 3451bc54c03SBenjamin Herrenschmidt * do copy ESR:ST to _PAGE_RW position as trying to write 3461bc54c03SBenjamin Herrenschmidt * to an RO page is pretty common, we don't do it with 3471bc54c03SBenjamin Herrenschmidt * _PAGE_DIRTY. We could do it, but it's a fairly rare 3481bc54c03SBenjamin Herrenschmidt * event so I'd rather take the overhead when it happens 3491bc54c03SBenjamin Herrenschmidt * rather than adding an instruction here. We should measure 3501bc54c03SBenjamin Herrenschmidt * whether the whole thing is worth it in the first place 3511bc54c03SBenjamin Herrenschmidt * as we could avoid loading SPRN_ESR completely in the first 3521bc54c03SBenjamin Herrenschmidt * place... 3531bc54c03SBenjamin Herrenschmidt * 3541bc54c03SBenjamin Herrenschmidt * TODO: Is it worth doing that mfspr & rlwimi in the first 3551bc54c03SBenjamin Herrenschmidt * place or can we save a couple of instructions here ? 3561bc54c03SBenjamin Herrenschmidt */ 3571bc54c03SBenjamin Herrenschmidt mfspr r12,SPRN_ESR 3581bc54c03SBenjamin Herrenschmidt li r13,_PAGE_PRESENT|_PAGE_ACCESSED 3591bc54c03SBenjamin Herrenschmidt rlwimi r13,r12,10,30,30 3601bc54c03SBenjamin Herrenschmidt 3611bc54c03SBenjamin Herrenschmidt /* Load the PTE */ 362ca9153a3SIlya Yanok /* Compute pgdir/pmd offset */ 363ca9153a3SIlya Yanok rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 36414cf11afSPaul Mackerras lwzx r11, r12, r11 /* Get pgd/pmd entry */ 36514cf11afSPaul Mackerras rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ 36614cf11afSPaul Mackerras beq 2f /* Bail if no table */ 36714cf11afSPaul Mackerras 368ca9153a3SIlya Yanok /* Compute pte address */ 369ca9153a3SIlya Yanok rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 3701bc54c03SBenjamin Herrenschmidt lwz r11, 0(r12) /* Get high word of pte entry */ 3711bc54c03SBenjamin Herrenschmidt lwz r12, 4(r12) /* Get low word of pte entry */ 37214cf11afSPaul Mackerras 3731bc54c03SBenjamin Herrenschmidt lis r10,tlb_44x_index@ha 3741bc54c03SBenjamin Herrenschmidt 3751bc54c03SBenjamin Herrenschmidt andc. r13,r13,r12 /* Check permission */ 3761bc54c03SBenjamin Herrenschmidt 3771bc54c03SBenjamin Herrenschmidt /* Load the next available TLB index */ 3781bc54c03SBenjamin Herrenschmidt lwz r13,tlb_44x_index@l(r10) 3791bc54c03SBenjamin Herrenschmidt 380ea782658SBhaskar Chowdhury bne 2f /* Bail if permission mismatch */ 3811bc54c03SBenjamin Herrenschmidt 3821bc54c03SBenjamin Herrenschmidt /* Increment, rollover, and store TLB index */ 3831bc54c03SBenjamin Herrenschmidt addi r13,r13,1 3841bc54c03SBenjamin Herrenschmidt 3856c16816bSChristophe Leroy patch_site 0f, patch__tlb_44x_hwater_D 3861bc54c03SBenjamin Herrenschmidt /* Compare with watermark (instruction gets patched) */ 3876c16816bSChristophe Leroy0: cmpwi 0,r13,1 /* reserve entries */ 3881bc54c03SBenjamin Herrenschmidt ble 5f 3891bc54c03SBenjamin Herrenschmidt li r13,0 3901bc54c03SBenjamin Herrenschmidt5: 3911bc54c03SBenjamin Herrenschmidt /* Store the next available TLB index */ 3921bc54c03SBenjamin Herrenschmidt stw r13,tlb_44x_index@l(r10) 3931bc54c03SBenjamin Herrenschmidt 3941bc54c03SBenjamin Herrenschmidt /* Re-load the faulting address */ 3951bc54c03SBenjamin Herrenschmidt mfspr r10,SPRN_DEAR 39614cf11afSPaul Mackerras 39714cf11afSPaul Mackerras /* Jump to common tlb load */ 398e7f75ad0SDave Kleikamp b finish_tlb_load_44x 39914cf11afSPaul Mackerras 40014cf11afSPaul Mackerras2: 40114cf11afSPaul Mackerras /* The bailout. Restore registers to pre-exception conditions 40214cf11afSPaul Mackerras * and call the heavyweights to help us out. 40314cf11afSPaul Mackerras */ 404ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH4 40514cf11afSPaul Mackerras mtcr r11 406ee43eb78SBenjamin Herrenschmidt mfspr r13, SPRN_SPRG_RSCRATCH3 407ee43eb78SBenjamin Herrenschmidt mfspr r12, SPRN_SPRG_RSCRATCH2 408ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH1 409ee43eb78SBenjamin Herrenschmidt mfspr r10, SPRN_SPRG_RSCRATCH0 4101bc54c03SBenjamin Herrenschmidt b DataStorage 41114cf11afSPaul Mackerras 41214cf11afSPaul Mackerras /* Instruction TLB Error Interrupt */ 41314cf11afSPaul Mackerras /* 41414cf11afSPaul Mackerras * Nearly the same as above, except we get our 41514cf11afSPaul Mackerras * information from different registers and bailout 41614cf11afSPaul Mackerras * to a different point. 41714cf11afSPaul Mackerras */ 418e7f75ad0SDave Kleikamp START_EXCEPTION(InstructionTLBError44x) 419ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ 420ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH1, r11 421ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH2, r12 422ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH3, r13 42314cf11afSPaul Mackerras mfcr r11 424ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH4, r11 42514cf11afSPaul Mackerras mfspr r10, SPRN_SRR0 /* Get faulting address */ 42614cf11afSPaul Mackerras 42714cf11afSPaul Mackerras /* If we are faulting a kernel address, we have to use the 42814cf11afSPaul Mackerras * kernel page tables. 42914cf11afSPaul Mackerras */ 4308a13c4f9SKumar Gala lis r11, PAGE_OFFSET@h 43114cf11afSPaul Mackerras cmplw r10, r11 43214cf11afSPaul Mackerras blt+ 3f 43314cf11afSPaul Mackerras lis r11, swapper_pg_dir@h 43414cf11afSPaul Mackerras ori r11, r11, swapper_pg_dir@l 43514cf11afSPaul Mackerras 43614cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 43714cf11afSPaul Mackerras rlwinm r12,r12,0,0,23 /* Clear TID */ 43814cf11afSPaul Mackerras 43914cf11afSPaul Mackerras b 4f 44014cf11afSPaul Mackerras 44114cf11afSPaul Mackerras /* Get the PGD for the current thread */ 44214cf11afSPaul Mackerras3: 443ee43eb78SBenjamin Herrenschmidt mfspr r11,SPRN_SPRG_THREAD 44414cf11afSPaul Mackerras lwz r11,PGDIR(r11) 44514cf11afSPaul Mackerras 44614cf11afSPaul Mackerras /* Load PID into MMUCR TID */ 44714cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 44814cf11afSPaul Mackerras mfspr r13,SPRN_PID /* Get PID */ 44914cf11afSPaul Mackerras rlwimi r12,r13,0,24,31 /* Set TID */ 450f6fad4fbSChristophe Leroy#ifdef CONFIG_PPC_KUAP 451f6fad4fbSChristophe Leroy cmpwi r13,0 452f6fad4fbSChristophe Leroy beq 2f /* KUAP Fault */ 453f6fad4fbSChristophe Leroy#endif 45414cf11afSPaul Mackerras 45514cf11afSPaul Mackerras4: 45614cf11afSPaul Mackerras mtspr SPRN_MMUCR,r12 45714cf11afSPaul Mackerras 4581bc54c03SBenjamin Herrenschmidt /* Make up the required permissions */ 459ea3cc330SBenjamin Herrenschmidt li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC 4601bc54c03SBenjamin Herrenschmidt 461ca9153a3SIlya Yanok /* Compute pgdir/pmd offset */ 462ca9153a3SIlya Yanok rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 46314cf11afSPaul Mackerras lwzx r11, r12, r11 /* Get pgd/pmd entry */ 46414cf11afSPaul Mackerras rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ 46514cf11afSPaul Mackerras beq 2f /* Bail if no table */ 46614cf11afSPaul Mackerras 467ca9153a3SIlya Yanok /* Compute pte address */ 468ca9153a3SIlya Yanok rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 4691bc54c03SBenjamin Herrenschmidt lwz r11, 0(r12) /* Get high word of pte entry */ 4701bc54c03SBenjamin Herrenschmidt lwz r12, 4(r12) /* Get low word of pte entry */ 47114cf11afSPaul Mackerras 4721bc54c03SBenjamin Herrenschmidt lis r10,tlb_44x_index@ha 4731bc54c03SBenjamin Herrenschmidt 4741bc54c03SBenjamin Herrenschmidt andc. r13,r13,r12 /* Check permission */ 4751bc54c03SBenjamin Herrenschmidt 4761bc54c03SBenjamin Herrenschmidt /* Load the next available TLB index */ 4771bc54c03SBenjamin Herrenschmidt lwz r13,tlb_44x_index@l(r10) 4781bc54c03SBenjamin Herrenschmidt 479ea782658SBhaskar Chowdhury bne 2f /* Bail if permission mismatch */ 4801bc54c03SBenjamin Herrenschmidt 4811bc54c03SBenjamin Herrenschmidt /* Increment, rollover, and store TLB index */ 4821bc54c03SBenjamin Herrenschmidt addi r13,r13,1 4831bc54c03SBenjamin Herrenschmidt 4846c16816bSChristophe Leroy patch_site 0f, patch__tlb_44x_hwater_I 4851bc54c03SBenjamin Herrenschmidt /* Compare with watermark (instruction gets patched) */ 4866c16816bSChristophe Leroy0: cmpwi 0,r13,1 /* reserve entries */ 4871bc54c03SBenjamin Herrenschmidt ble 5f 4881bc54c03SBenjamin Herrenschmidt li r13,0 4891bc54c03SBenjamin Herrenschmidt5: 4901bc54c03SBenjamin Herrenschmidt /* Store the next available TLB index */ 4911bc54c03SBenjamin Herrenschmidt stw r13,tlb_44x_index@l(r10) 4921bc54c03SBenjamin Herrenschmidt 4931bc54c03SBenjamin Herrenschmidt /* Re-load the faulting address */ 4941bc54c03SBenjamin Herrenschmidt mfspr r10,SPRN_SRR0 49514cf11afSPaul Mackerras 49614cf11afSPaul Mackerras /* Jump to common TLB load point */ 497e7f75ad0SDave Kleikamp b finish_tlb_load_44x 49814cf11afSPaul Mackerras 49914cf11afSPaul Mackerras2: 50014cf11afSPaul Mackerras /* The bailout. Restore registers to pre-exception conditions 50114cf11afSPaul Mackerras * and call the heavyweights to help us out. 50214cf11afSPaul Mackerras */ 503ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH4 50414cf11afSPaul Mackerras mtcr r11 505ee43eb78SBenjamin Herrenschmidt mfspr r13, SPRN_SPRG_RSCRATCH3 506ee43eb78SBenjamin Herrenschmidt mfspr r12, SPRN_SPRG_RSCRATCH2 507ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH1 508ee43eb78SBenjamin Herrenschmidt mfspr r10, SPRN_SPRG_RSCRATCH0 50914cf11afSPaul Mackerras b InstructionStorage 51014cf11afSPaul Mackerras 51114cf11afSPaul Mackerras/* 51214cf11afSPaul Mackerras * Both the instruction and data TLB miss get to this 51314cf11afSPaul Mackerras * point to load the TLB. 51414cf11afSPaul Mackerras * r10 - EA of fault 5151bc54c03SBenjamin Herrenschmidt * r11 - PTE high word value 5161bc54c03SBenjamin Herrenschmidt * r12 - PTE low word value 5171bc54c03SBenjamin Herrenschmidt * r13 - TLB index 51814cf11afSPaul Mackerras * MMUCR - loaded with proper value when we get here 51914cf11afSPaul Mackerras * Upon exit, we reload everything and RFI. 52014cf11afSPaul Mackerras */ 521e7f75ad0SDave Kleikampfinish_tlb_load_44x: 5221bc54c03SBenjamin Herrenschmidt /* Combine RPN & ERPN an write WS 0 */ 523ca9153a3SIlya Yanok rlwimi r11,r12,0,0,31-PAGE_SHIFT 5241bc54c03SBenjamin Herrenschmidt tlbwe r11,r13,PPC44x_TLB_XLAT 52514cf11afSPaul Mackerras 52614cf11afSPaul Mackerras /* 5271bc54c03SBenjamin Herrenschmidt * Create WS1. This is the faulting address (EPN), 52814cf11afSPaul Mackerras * page size, and valid flag. 52914cf11afSPaul Mackerras */ 530ca9153a3SIlya Yanok li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE 531ca9153a3SIlya Yanok /* Insert valid and page size */ 532ca9153a3SIlya Yanok rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31 53314cf11afSPaul Mackerras tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */ 53414cf11afSPaul Mackerras 5351bc54c03SBenjamin Herrenschmidt /* And WS 2 */ 5361bc54c03SBenjamin Herrenschmidt li r10,0xf85 /* Mask to apply from PTE */ 5371bc54c03SBenjamin Herrenschmidt rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ 5381bc54c03SBenjamin Herrenschmidt and r11,r12,r10 /* Mask PTE bits to keep */ 5391bc54c03SBenjamin Herrenschmidt andi. r10,r12,_PAGE_USER /* User page ? */ 5401bc54c03SBenjamin Herrenschmidt beq 1f /* nope, leave U bits empty */ 5411bc54c03SBenjamin Herrenschmidt rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ 542ee263160SChristophe Leroy rlwinm r11,r11,0,~PPC44x_TLB_SX /* Clear SX if User page */ 5431bc54c03SBenjamin Herrenschmidt1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */ 54414cf11afSPaul Mackerras 54514cf11afSPaul Mackerras /* Done...restore registers and get out of here. 54614cf11afSPaul Mackerras */ 547ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH4 54814cf11afSPaul Mackerras mtcr r11 549ee43eb78SBenjamin Herrenschmidt mfspr r13, SPRN_SPRG_RSCRATCH3 550ee43eb78SBenjamin Herrenschmidt mfspr r12, SPRN_SPRG_RSCRATCH2 551ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH1 552ee43eb78SBenjamin Herrenschmidt mfspr r10, SPRN_SPRG_RSCRATCH0 55314cf11afSPaul Mackerras rfi /* Force context change */ 55414cf11afSPaul Mackerras 555e7f75ad0SDave Kleikamp/* TLB error interrupts for 476 556e7f75ad0SDave Kleikamp */ 557e7f75ad0SDave Kleikamp#ifdef CONFIG_PPC_47x 558e7f75ad0SDave Kleikamp START_EXCEPTION(DataTLBError47x) 559e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */ 560e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH1,r11 561e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH2,r12 562e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH3,r13 563e7f75ad0SDave Kleikamp mfcr r11 564e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH4,r11 565e7f75ad0SDave Kleikamp mfspr r10,SPRN_DEAR /* Get faulting address */ 566e7f75ad0SDave Kleikamp 567e7f75ad0SDave Kleikamp /* If we are faulting a kernel address, we have to use the 568e7f75ad0SDave Kleikamp * kernel page tables. 569e7f75ad0SDave Kleikamp */ 570e7f75ad0SDave Kleikamp lis r11,PAGE_OFFSET@h 571e7f75ad0SDave Kleikamp cmplw cr0,r10,r11 572e7f75ad0SDave Kleikamp blt+ 3f 573e7f75ad0SDave Kleikamp lis r11,swapper_pg_dir@h 574e7f75ad0SDave Kleikamp ori r11,r11, swapper_pg_dir@l 575e7f75ad0SDave Kleikamp li r12,0 /* MMUCR = 0 */ 576e7f75ad0SDave Kleikamp b 4f 577e7f75ad0SDave Kleikamp 578e7f75ad0SDave Kleikamp /* Get the PGD for the current thread and setup MMUCR */ 579e7f75ad0SDave Kleikamp3: mfspr r11,SPRN_SPRG3 580e7f75ad0SDave Kleikamp lwz r11,PGDIR(r11) 581e7f75ad0SDave Kleikamp mfspr r12,SPRN_PID /* Get PID */ 582f6fad4fbSChristophe Leroy#ifdef CONFIG_PPC_KUAP 583f6fad4fbSChristophe Leroy cmpwi r12,0 584f6fad4fbSChristophe Leroy beq 2f /* KUAP Fault */ 585f6fad4fbSChristophe Leroy#endif 586e7f75ad0SDave Kleikamp4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ 587e7f75ad0SDave Kleikamp 588e7f75ad0SDave Kleikamp /* Mask of required permission bits. Note that while we 589e7f75ad0SDave Kleikamp * do copy ESR:ST to _PAGE_RW position as trying to write 590e7f75ad0SDave Kleikamp * to an RO page is pretty common, we don't do it with 591e7f75ad0SDave Kleikamp * _PAGE_DIRTY. We could do it, but it's a fairly rare 592e7f75ad0SDave Kleikamp * event so I'd rather take the overhead when it happens 593e7f75ad0SDave Kleikamp * rather than adding an instruction here. We should measure 594e7f75ad0SDave Kleikamp * whether the whole thing is worth it in the first place 595e7f75ad0SDave Kleikamp * as we could avoid loading SPRN_ESR completely in the first 596e7f75ad0SDave Kleikamp * place... 597e7f75ad0SDave Kleikamp * 598e7f75ad0SDave Kleikamp * TODO: Is it worth doing that mfspr & rlwimi in the first 599e7f75ad0SDave Kleikamp * place or can we save a couple of instructions here ? 600e7f75ad0SDave Kleikamp */ 601e7f75ad0SDave Kleikamp mfspr r12,SPRN_ESR 602e7f75ad0SDave Kleikamp li r13,_PAGE_PRESENT|_PAGE_ACCESSED 603e7f75ad0SDave Kleikamp rlwimi r13,r12,10,30,30 604e7f75ad0SDave Kleikamp 605e7f75ad0SDave Kleikamp /* Load the PTE */ 606e7f75ad0SDave Kleikamp /* Compute pgdir/pmd offset */ 607e7f75ad0SDave Kleikamp rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29 608e7f75ad0SDave Kleikamp lwzx r11,r12,r11 /* Get pgd/pmd entry */ 609e7f75ad0SDave Kleikamp 610e7f75ad0SDave Kleikamp /* Word 0 is EPN,V,TS,DSIZ */ 611e7f75ad0SDave Kleikamp li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE 612e7f75ad0SDave Kleikamp rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/ 613e7f75ad0SDave Kleikamp li r12,0 614e7f75ad0SDave Kleikamp tlbwe r10,r12,0 615e7f75ad0SDave Kleikamp 616e7f75ad0SDave Kleikamp /* XXX can we do better ? Need to make sure tlbwe has established 617e7f75ad0SDave Kleikamp * latch V bit in MMUCR0 before the PTE is loaded further down */ 618e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 619e7f75ad0SDave Kleikamp isync 620e7f75ad0SDave Kleikamp#endif 621e7f75ad0SDave Kleikamp 622e7f75ad0SDave Kleikamp rlwinm. r12,r11,0,0,20 /* Extract pt base address */ 623e7f75ad0SDave Kleikamp /* Compute pte address */ 624e7f75ad0SDave Kleikamp rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28 625e7f75ad0SDave Kleikamp beq 2f /* Bail if no table */ 626e7f75ad0SDave Kleikamp lwz r11,0(r12) /* Get high word of pte entry */ 627e7f75ad0SDave Kleikamp 628e7f75ad0SDave Kleikamp /* XXX can we do better ? maybe insert a known 0 bit from r11 into the 629e7f75ad0SDave Kleikamp * bottom of r12 to create a data dependency... We can also use r10 630e7f75ad0SDave Kleikamp * as destination nowadays 631e7f75ad0SDave Kleikamp */ 632e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 633e7f75ad0SDave Kleikamp lwsync 634e7f75ad0SDave Kleikamp#endif 635e7f75ad0SDave Kleikamp lwz r12,4(r12) /* Get low word of pte entry */ 636e7f75ad0SDave Kleikamp 637e7f75ad0SDave Kleikamp andc. r13,r13,r12 /* Check permission */ 638e7f75ad0SDave Kleikamp 639e7f75ad0SDave Kleikamp /* Jump to common tlb load */ 640e7f75ad0SDave Kleikamp beq finish_tlb_load_47x 641e7f75ad0SDave Kleikamp 642e7f75ad0SDave Kleikamp2: /* The bailout. Restore registers to pre-exception conditions 643e7f75ad0SDave Kleikamp * and call the heavyweights to help us out. 644e7f75ad0SDave Kleikamp */ 645e7f75ad0SDave Kleikamp mfspr r11,SPRN_SPRG_RSCRATCH4 646e7f75ad0SDave Kleikamp mtcr r11 647e7f75ad0SDave Kleikamp mfspr r13,SPRN_SPRG_RSCRATCH3 648e7f75ad0SDave Kleikamp mfspr r12,SPRN_SPRG_RSCRATCH2 649e7f75ad0SDave Kleikamp mfspr r11,SPRN_SPRG_RSCRATCH1 650e7f75ad0SDave Kleikamp mfspr r10,SPRN_SPRG_RSCRATCH0 651e7f75ad0SDave Kleikamp b DataStorage 652e7f75ad0SDave Kleikamp 653e7f75ad0SDave Kleikamp /* Instruction TLB Error Interrupt */ 654e7f75ad0SDave Kleikamp /* 655e7f75ad0SDave Kleikamp * Nearly the same as above, except we get our 656e7f75ad0SDave Kleikamp * information from different registers and bailout 657e7f75ad0SDave Kleikamp * to a different point. 658e7f75ad0SDave Kleikamp */ 659e7f75ad0SDave Kleikamp START_EXCEPTION(InstructionTLBError47x) 660e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */ 661e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH1,r11 662e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH2,r12 663e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH3,r13 664e7f75ad0SDave Kleikamp mfcr r11 665e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH4,r11 666e7f75ad0SDave Kleikamp mfspr r10,SPRN_SRR0 /* Get faulting address */ 667e7f75ad0SDave Kleikamp 668e7f75ad0SDave Kleikamp /* If we are faulting a kernel address, we have to use the 669e7f75ad0SDave Kleikamp * kernel page tables. 670e7f75ad0SDave Kleikamp */ 671e7f75ad0SDave Kleikamp lis r11,PAGE_OFFSET@h 672e7f75ad0SDave Kleikamp cmplw cr0,r10,r11 673e7f75ad0SDave Kleikamp blt+ 3f 674e7f75ad0SDave Kleikamp lis r11,swapper_pg_dir@h 675e7f75ad0SDave Kleikamp ori r11,r11, swapper_pg_dir@l 676e7f75ad0SDave Kleikamp li r12,0 /* MMUCR = 0 */ 677e7f75ad0SDave Kleikamp b 4f 678e7f75ad0SDave Kleikamp 679e7f75ad0SDave Kleikamp /* Get the PGD for the current thread and setup MMUCR */ 680e7f75ad0SDave Kleikamp3: mfspr r11,SPRN_SPRG_THREAD 681e7f75ad0SDave Kleikamp lwz r11,PGDIR(r11) 682e7f75ad0SDave Kleikamp mfspr r12,SPRN_PID /* Get PID */ 683f6fad4fbSChristophe Leroy#ifdef CONFIG_PPC_KUAP 684f6fad4fbSChristophe Leroy cmpwi r12,0 685f6fad4fbSChristophe Leroy beq 2f /* KUAP Fault */ 686f6fad4fbSChristophe Leroy#endif 687e7f75ad0SDave Kleikamp4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ 688e7f75ad0SDave Kleikamp 689e7f75ad0SDave Kleikamp /* Make up the required permissions */ 690e7f75ad0SDave Kleikamp li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC 691e7f75ad0SDave Kleikamp 692e7f75ad0SDave Kleikamp /* Load PTE */ 693e7f75ad0SDave Kleikamp /* Compute pgdir/pmd offset */ 694e7f75ad0SDave Kleikamp rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29 695e7f75ad0SDave Kleikamp lwzx r11,r12,r11 /* Get pgd/pmd entry */ 696e7f75ad0SDave Kleikamp 697e7f75ad0SDave Kleikamp /* Word 0 is EPN,V,TS,DSIZ */ 698e7f75ad0SDave Kleikamp li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE 699e7f75ad0SDave Kleikamp rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/ 700e7f75ad0SDave Kleikamp li r12,0 701e7f75ad0SDave Kleikamp tlbwe r10,r12,0 702e7f75ad0SDave Kleikamp 703e7f75ad0SDave Kleikamp /* XXX can we do better ? Need to make sure tlbwe has established 704e7f75ad0SDave Kleikamp * latch V bit in MMUCR0 before the PTE is loaded further down */ 705e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 706e7f75ad0SDave Kleikamp isync 707e7f75ad0SDave Kleikamp#endif 708e7f75ad0SDave Kleikamp 709e7f75ad0SDave Kleikamp rlwinm. r12,r11,0,0,20 /* Extract pt base address */ 710e7f75ad0SDave Kleikamp /* Compute pte address */ 711e7f75ad0SDave Kleikamp rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28 712e7f75ad0SDave Kleikamp beq 2f /* Bail if no table */ 713e7f75ad0SDave Kleikamp 714e7f75ad0SDave Kleikamp lwz r11,0(r12) /* Get high word of pte entry */ 715e7f75ad0SDave Kleikamp /* XXX can we do better ? maybe insert a known 0 bit from r11 into the 716e7f75ad0SDave Kleikamp * bottom of r12 to create a data dependency... We can also use r10 717e7f75ad0SDave Kleikamp * as destination nowadays 718e7f75ad0SDave Kleikamp */ 719e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 720e7f75ad0SDave Kleikamp lwsync 721e7f75ad0SDave Kleikamp#endif 722e7f75ad0SDave Kleikamp lwz r12,4(r12) /* Get low word of pte entry */ 723e7f75ad0SDave Kleikamp 724e7f75ad0SDave Kleikamp andc. r13,r13,r12 /* Check permission */ 725e7f75ad0SDave Kleikamp 726e7f75ad0SDave Kleikamp /* Jump to common TLB load point */ 727e7f75ad0SDave Kleikamp beq finish_tlb_load_47x 728e7f75ad0SDave Kleikamp 729e7f75ad0SDave Kleikamp2: /* The bailout. Restore registers to pre-exception conditions 730e7f75ad0SDave Kleikamp * and call the heavyweights to help us out. 731e7f75ad0SDave Kleikamp */ 732e7f75ad0SDave Kleikamp mfspr r11, SPRN_SPRG_RSCRATCH4 733e7f75ad0SDave Kleikamp mtcr r11 734e7f75ad0SDave Kleikamp mfspr r13, SPRN_SPRG_RSCRATCH3 735e7f75ad0SDave Kleikamp mfspr r12, SPRN_SPRG_RSCRATCH2 736e7f75ad0SDave Kleikamp mfspr r11, SPRN_SPRG_RSCRATCH1 737e7f75ad0SDave Kleikamp mfspr r10, SPRN_SPRG_RSCRATCH0 738e7f75ad0SDave Kleikamp b InstructionStorage 739e7f75ad0SDave Kleikamp 740e7f75ad0SDave Kleikamp/* 741e7f75ad0SDave Kleikamp * Both the instruction and data TLB miss get to this 742e7f75ad0SDave Kleikamp * point to load the TLB. 743e7f75ad0SDave Kleikamp * r10 - free to use 744e7f75ad0SDave Kleikamp * r11 - PTE high word value 745e7f75ad0SDave Kleikamp * r12 - PTE low word value 746e7f75ad0SDave Kleikamp * r13 - free to use 747e7f75ad0SDave Kleikamp * MMUCR - loaded with proper value when we get here 748e7f75ad0SDave Kleikamp * Upon exit, we reload everything and RFI. 749e7f75ad0SDave Kleikamp */ 750e7f75ad0SDave Kleikampfinish_tlb_load_47x: 751e7f75ad0SDave Kleikamp /* Combine RPN & ERPN an write WS 1 */ 752e7f75ad0SDave Kleikamp rlwimi r11,r12,0,0,31-PAGE_SHIFT 753e7f75ad0SDave Kleikamp tlbwe r11,r13,1 754e7f75ad0SDave Kleikamp 755e7f75ad0SDave Kleikamp /* And make up word 2 */ 756e7f75ad0SDave Kleikamp li r10,0xf85 /* Mask to apply from PTE */ 757e7f75ad0SDave Kleikamp rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ 758e7f75ad0SDave Kleikamp and r11,r12,r10 /* Mask PTE bits to keep */ 759e7f75ad0SDave Kleikamp andi. r10,r12,_PAGE_USER /* User page ? */ 760e7f75ad0SDave Kleikamp beq 1f /* nope, leave U bits empty */ 761e7f75ad0SDave Kleikamp rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ 762ee263160SChristophe Leroy rlwinm r11,r11,0,~PPC47x_TLB2_SX /* Clear SX if User page */ 763e7f75ad0SDave Kleikamp1: tlbwe r11,r13,2 764e7f75ad0SDave Kleikamp 765e7f75ad0SDave Kleikamp /* Done...restore registers and get out of here. 766e7f75ad0SDave Kleikamp */ 767e7f75ad0SDave Kleikamp mfspr r11, SPRN_SPRG_RSCRATCH4 768e7f75ad0SDave Kleikamp mtcr r11 769e7f75ad0SDave Kleikamp mfspr r13, SPRN_SPRG_RSCRATCH3 770e7f75ad0SDave Kleikamp mfspr r12, SPRN_SPRG_RSCRATCH2 771e7f75ad0SDave Kleikamp mfspr r11, SPRN_SPRG_RSCRATCH1 772e7f75ad0SDave Kleikamp mfspr r10, SPRN_SPRG_RSCRATCH0 773e7f75ad0SDave Kleikamp rfi 774e7f75ad0SDave Kleikamp 775e7f75ad0SDave Kleikamp#endif /* CONFIG_PPC_47x */ 776e7f75ad0SDave Kleikamp 777e7f75ad0SDave Kleikamp /* Debug Interrupt */ 778e7f75ad0SDave Kleikamp /* 779e7f75ad0SDave Kleikamp * This statement needs to exist at the end of the IVPR 780e7f75ad0SDave Kleikamp * definition just in case you end up taking a debug 781e7f75ad0SDave Kleikamp * exception within another exception. 782e7f75ad0SDave Kleikamp */ 783e7f75ad0SDave Kleikamp DEBUG_CRIT_EXCEPTION 784e7f75ad0SDave Kleikamp 785fc2a6cfeSBharat Bhushaninterrupt_end: 786fc2a6cfeSBharat Bhushan 78714cf11afSPaul Mackerras/* 78814cf11afSPaul Mackerras * Global functions 78914cf11afSPaul Mackerras */ 79014cf11afSPaul Mackerras 79114cf11afSPaul Mackerras/* 79247c0bd1aSBenjamin Herrenschmidt * Adjust the machine check IVOR on 440A cores 79347c0bd1aSBenjamin Herrenschmidt */ 79447c0bd1aSBenjamin Herrenschmidt_GLOBAL(__fixup_440A_mcheck) 79547c0bd1aSBenjamin Herrenschmidt li r3,MachineCheckA@l 79647c0bd1aSBenjamin Herrenschmidt mtspr SPRN_IVOR1,r3 79747c0bd1aSBenjamin Herrenschmidt sync 79847c0bd1aSBenjamin Herrenschmidt blr 79947c0bd1aSBenjamin Herrenschmidt 80014cf11afSPaul Mackerras/* 801795033c3SDave Kleikamp * Init CPU state. This is called at boot time or for secondary CPUs 802795033c3SDave Kleikamp * to setup initial TLB entries, setup IVORs, etc... 803e7f75ad0SDave Kleikamp * 804795033c3SDave Kleikamp */ 805795033c3SDave Kleikamp_GLOBAL(init_cpu_state) 806795033c3SDave Kleikamp mflr r22 807e7f75ad0SDave Kleikamp#ifdef CONFIG_PPC_47x 808446957baSAdam Buchbinder /* We use the PVR to differentiate 44x cores from 476 */ 809e7f75ad0SDave Kleikamp mfspr r3,SPRN_PVR 810e7f75ad0SDave Kleikamp srwi r3,r3,16 811df777bd3STony Breeds cmplwi cr0,r3,PVR_476FPE@h 812df777bd3STony Breeds beq head_start_47x 813e7f75ad0SDave Kleikamp cmplwi cr0,r3,PVR_476@h 814e7f75ad0SDave Kleikamp beq head_start_47x 815b4e8c8ddSTorez Smith cmplwi cr0,r3,PVR_476_ISS@h 816b4e8c8ddSTorez Smith beq head_start_47x 817e7f75ad0SDave Kleikamp#endif /* CONFIG_PPC_47x */ 818e7f75ad0SDave Kleikamp 819795033c3SDave Kleikamp/* 820795033c3SDave Kleikamp * In case the firmware didn't do it, we apply some workarounds 821795033c3SDave Kleikamp * that are good for all 440 core variants here 822795033c3SDave Kleikamp */ 823795033c3SDave Kleikamp mfspr r3,SPRN_CCR0 824795033c3SDave Kleikamp rlwinm r3,r3,0,0,27 /* disable icache prefetch */ 825795033c3SDave Kleikamp isync 826795033c3SDave Kleikamp mtspr SPRN_CCR0,r3 827795033c3SDave Kleikamp isync 828795033c3SDave Kleikamp sync 829795033c3SDave Kleikamp 830795033c3SDave Kleikamp/* 831e7f75ad0SDave Kleikamp * Set up the initial MMU state for 44x 832795033c3SDave Kleikamp * 833795033c3SDave Kleikamp * We are still executing code at the virtual address 834795033c3SDave Kleikamp * mappings set by the firmware for the base of RAM. 835795033c3SDave Kleikamp * 836795033c3SDave Kleikamp * We first invalidate all TLB entries but the one 837795033c3SDave Kleikamp * we are running from. We then load the KERNELBASE 838795033c3SDave Kleikamp * mappings so we can begin to use kernel addresses 839795033c3SDave Kleikamp * natively and so the interrupt vector locations are 840795033c3SDave Kleikamp * permanently pinned (necessary since Book E 841795033c3SDave Kleikamp * implementations always have translation enabled). 842795033c3SDave Kleikamp * 843795033c3SDave Kleikamp * TODO: Use the known TLB entry we are running from to 844795033c3SDave Kleikamp * determine which physical region we are located 845795033c3SDave Kleikamp * in. This can be used to determine where in RAM 846795033c3SDave Kleikamp * (on a shared CPU system) or PCI memory space 847795033c3SDave Kleikamp * (on a DRAMless system) we are located. 848795033c3SDave Kleikamp * For now, we assume a perfect world which means 849795033c3SDave Kleikamp * we are located at the base of DRAM (physical 0). 850795033c3SDave Kleikamp */ 851795033c3SDave Kleikamp 852795033c3SDave Kleikamp/* 853795033c3SDave Kleikamp * Search TLB for entry that we are currently using. 854795033c3SDave Kleikamp * Invalidate all entries but the one we are using. 855795033c3SDave Kleikamp */ 856795033c3SDave Kleikamp /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ 857795033c3SDave Kleikamp mfspr r3,SPRN_PID /* Get PID */ 858795033c3SDave Kleikamp mfmsr r4 /* Get MSR */ 859795033c3SDave Kleikamp andi. r4,r4,MSR_IS@l /* TS=1? */ 860795033c3SDave Kleikamp beq wmmucr /* If not, leave STS=0 */ 861795033c3SDave Kleikamp oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */ 862795033c3SDave Kleikampwmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ 863795033c3SDave Kleikamp sync 864795033c3SDave Kleikamp 865f5007dbfSChristophe Leroy bcl 20,31,$+4 /* Find our address */ 866795033c3SDave Kleikampinvstr: mflr r5 /* Make it accessible */ 867795033c3SDave Kleikamp tlbsx r23,0,r5 /* Find entry we are in */ 868795033c3SDave Kleikamp li r4,0 /* Start at TLB entry 0 */ 869795033c3SDave Kleikamp li r3,0 /* Set PAGEID inval value */ 870795033c3SDave Kleikamp1: cmpw r23,r4 /* Is this our entry? */ 871795033c3SDave Kleikamp beq skpinv /* If so, skip the inval */ 872795033c3SDave Kleikamp tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */ 873795033c3SDave Kleikampskpinv: addi r4,r4,1 /* Increment */ 874795033c3SDave Kleikamp cmpwi r4,64 /* Are we done? */ 875795033c3SDave Kleikamp bne 1b /* If not, repeat */ 876795033c3SDave Kleikamp isync /* If so, context change */ 877795033c3SDave Kleikamp 878795033c3SDave Kleikamp/* 879795033c3SDave Kleikamp * Configure and load pinned entry into TLB slot 63. 880795033c3SDave Kleikamp */ 88126ecb6c4SSuzuki Poulose#ifdef CONFIG_NONSTATIC_KERNEL 88226ecb6c4SSuzuki Poulose /* 88326ecb6c4SSuzuki Poulose * In case of a NONSTATIC_KERNEL we reuse the TLB XLAT 88426ecb6c4SSuzuki Poulose * entries of the initial mapping set by the boot loader. 88526ecb6c4SSuzuki Poulose * The XLAT entry is stored in r25 88626ecb6c4SSuzuki Poulose */ 88723913245SSuzuki Poulose 88823913245SSuzuki Poulose /* Read the XLAT entry for our current mapping */ 88923913245SSuzuki Poulose tlbre r25,r23,PPC44x_TLB_XLAT 89023913245SSuzuki Poulose 89123913245SSuzuki Poulose lis r3,KERNELBASE@h 89223913245SSuzuki Poulose ori r3,r3,KERNELBASE@l 89323913245SSuzuki Poulose 89423913245SSuzuki Poulose /* Use our current RPN entry */ 89523913245SSuzuki Poulose mr r4,r25 89623913245SSuzuki Poulose#else 897795033c3SDave Kleikamp 898795033c3SDave Kleikamp lis r3,PAGE_OFFSET@h 899795033c3SDave Kleikamp ori r3,r3,PAGE_OFFSET@l 900795033c3SDave Kleikamp 901795033c3SDave Kleikamp /* Kernel is at the base of RAM */ 902795033c3SDave Kleikamp li r4, 0 /* Load the kernel physical address */ 90323913245SSuzuki Poulose#endif 904795033c3SDave Kleikamp 905795033c3SDave Kleikamp /* Load the kernel PID = 0 */ 906795033c3SDave Kleikamp li r0,0 907795033c3SDave Kleikamp mtspr SPRN_PID,r0 908795033c3SDave Kleikamp sync 909795033c3SDave Kleikamp 910795033c3SDave Kleikamp /* Initialize MMUCR */ 911795033c3SDave Kleikamp li r5,0 912795033c3SDave Kleikamp mtspr SPRN_MMUCR,r5 913795033c3SDave Kleikamp sync 914795033c3SDave Kleikamp 915795033c3SDave Kleikamp /* pageid fields */ 916795033c3SDave Kleikamp clrrwi r3,r3,10 /* Mask off the effective page number */ 917795033c3SDave Kleikamp ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M 918795033c3SDave Kleikamp 919795033c3SDave Kleikamp /* xlat fields */ 920795033c3SDave Kleikamp clrrwi r4,r4,10 /* Mask off the real page number */ 921795033c3SDave Kleikamp /* ERPN is 0 for first 4GB page */ 922795033c3SDave Kleikamp 923795033c3SDave Kleikamp /* attrib fields */ 924795033c3SDave Kleikamp /* Added guarded bit to protect against speculative loads/stores */ 925795033c3SDave Kleikamp li r5,0 926795033c3SDave Kleikamp ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G) 927795033c3SDave Kleikamp 928795033c3SDave Kleikamp li r0,63 /* TLB slot 63 */ 929795033c3SDave Kleikamp 930795033c3SDave Kleikamp tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */ 931795033c3SDave Kleikamp tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */ 932795033c3SDave Kleikamp tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */ 933795033c3SDave Kleikamp 934795033c3SDave Kleikamp /* Force context change */ 935795033c3SDave Kleikamp mfmsr r0 936795033c3SDave Kleikamp mtspr SPRN_SRR1, r0 937795033c3SDave Kleikamp lis r0,3f@h 938795033c3SDave Kleikamp ori r0,r0,3f@l 939795033c3SDave Kleikamp mtspr SPRN_SRR0,r0 940795033c3SDave Kleikamp sync 941795033c3SDave Kleikamp rfi 942795033c3SDave Kleikamp 943795033c3SDave Kleikamp /* If necessary, invalidate original entry we used */ 944795033c3SDave Kleikamp3: cmpwi r23,63 945795033c3SDave Kleikamp beq 4f 946795033c3SDave Kleikamp li r6,0 947795033c3SDave Kleikamp tlbwe r6,r23,PPC44x_TLB_PAGEID 948795033c3SDave Kleikamp isync 949795033c3SDave Kleikamp 950795033c3SDave Kleikamp4: 951795033c3SDave Kleikamp#ifdef CONFIG_PPC_EARLY_DEBUG_44x 952795033c3SDave Kleikamp /* Add UART mapping for early debug. */ 953795033c3SDave Kleikamp 954795033c3SDave Kleikamp /* pageid fields */ 955795033c3SDave Kleikamp lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h 956795033c3SDave Kleikamp ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K 957795033c3SDave Kleikamp 958795033c3SDave Kleikamp /* xlat fields */ 959795033c3SDave Kleikamp lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h 960795033c3SDave Kleikamp ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH 961795033c3SDave Kleikamp 962795033c3SDave Kleikamp /* attrib fields */ 963795033c3SDave Kleikamp li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G) 964795033c3SDave Kleikamp li r0,62 /* TLB slot 0 */ 965795033c3SDave Kleikamp 966795033c3SDave Kleikamp tlbwe r3,r0,PPC44x_TLB_PAGEID 967795033c3SDave Kleikamp tlbwe r4,r0,PPC44x_TLB_XLAT 968795033c3SDave Kleikamp tlbwe r5,r0,PPC44x_TLB_ATTRIB 969795033c3SDave Kleikamp 970795033c3SDave Kleikamp /* Force context change */ 971795033c3SDave Kleikamp isync 972795033c3SDave Kleikamp#endif /* CONFIG_PPC_EARLY_DEBUG_44x */ 973795033c3SDave Kleikamp 974795033c3SDave Kleikamp /* Establish the interrupt vector offsets */ 975795033c3SDave Kleikamp SET_IVOR(0, CriticalInput); 976795033c3SDave Kleikamp SET_IVOR(1, MachineCheck); 977795033c3SDave Kleikamp SET_IVOR(2, DataStorage); 978795033c3SDave Kleikamp SET_IVOR(3, InstructionStorage); 979795033c3SDave Kleikamp SET_IVOR(4, ExternalInput); 980795033c3SDave Kleikamp SET_IVOR(5, Alignment); 981795033c3SDave Kleikamp SET_IVOR(6, Program); 982795033c3SDave Kleikamp SET_IVOR(7, FloatingPointUnavailable); 983795033c3SDave Kleikamp SET_IVOR(8, SystemCall); 984795033c3SDave Kleikamp SET_IVOR(9, AuxillaryProcessorUnavailable); 985795033c3SDave Kleikamp SET_IVOR(10, Decrementer); 986795033c3SDave Kleikamp SET_IVOR(11, FixedIntervalTimer); 987795033c3SDave Kleikamp SET_IVOR(12, WatchdogTimer); 988e7f75ad0SDave Kleikamp SET_IVOR(13, DataTLBError44x); 989e7f75ad0SDave Kleikamp SET_IVOR(14, InstructionTLBError44x); 990795033c3SDave Kleikamp SET_IVOR(15, DebugCrit); 991795033c3SDave Kleikamp 992e7f75ad0SDave Kleikamp b head_start_common 993e7f75ad0SDave Kleikamp 994e7f75ad0SDave Kleikamp 995e7f75ad0SDave Kleikamp#ifdef CONFIG_PPC_47x 996e7f75ad0SDave Kleikamp 997e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 998e7f75ad0SDave Kleikamp 999e7f75ad0SDave Kleikamp/* Entry point for secondary 47x processors */ 1000e7f75ad0SDave Kleikamp_GLOBAL(start_secondary_47x) 1001e7f75ad0SDave Kleikamp mr r24,r3 /* CPU number */ 1002e7f75ad0SDave Kleikamp 1003e7f75ad0SDave Kleikamp bl init_cpu_state 1004e7f75ad0SDave Kleikamp 1005e7f75ad0SDave Kleikamp /* Now we need to bolt the rest of kernel memory which 1006e7f75ad0SDave Kleikamp * is done in C code. We must be careful because our task 1007e7f75ad0SDave Kleikamp * struct or our stack can (and will probably) be out 1008e7f75ad0SDave Kleikamp * of reach of the initial 256M TLB entry, so we use a 1009e7f75ad0SDave Kleikamp * small temporary stack in .bss for that. This works 1010e7f75ad0SDave Kleikamp * because only one CPU at a time can be in this code 1011e7f75ad0SDave Kleikamp */ 1012e7f75ad0SDave Kleikamp lis r1,temp_boot_stack@h 1013e7f75ad0SDave Kleikamp ori r1,r1,temp_boot_stack@l 1014*90f1b431SNicholas Piggin addi r1,r1,1024-STACK_FRAME_MIN_SIZE 1015e7f75ad0SDave Kleikamp li r0,0 1016e7f75ad0SDave Kleikamp stw r0,0(r1) 1017e7f75ad0SDave Kleikamp bl mmu_init_secondary 1018e7f75ad0SDave Kleikamp 1019e7f75ad0SDave Kleikamp /* Now we can get our task struct and real stack pointer */ 1020e7f75ad0SDave Kleikamp 10214e67bfd7SChristophe Leroy /* Get current's stack and current */ 10227c19c2e5SChristophe Leroy lis r2,secondary_current@ha 10237c19c2e5SChristophe Leroy lwz r2,secondary_current@l(r2) 1024ed1cd6deSChristophe Leroy lwz r1,TASK_STACK(r2) 1025e7f75ad0SDave Kleikamp 1026e7f75ad0SDave Kleikamp /* Current stack pointer */ 1027*90f1b431SNicholas Piggin addi r1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE 1028e7f75ad0SDave Kleikamp li r0,0 1029e7f75ad0SDave Kleikamp stw r0,0(r1) 1030e7f75ad0SDave Kleikamp 1031e7f75ad0SDave Kleikamp /* Kernel stack for exception entry in SPRG3 */ 1032e7f75ad0SDave Kleikamp addi r4,r2,THREAD /* init task's THREAD */ 1033e7f75ad0SDave Kleikamp mtspr SPRN_SPRG3,r4 1034e7f75ad0SDave Kleikamp 1035e7f75ad0SDave Kleikamp b start_secondary 1036e7f75ad0SDave Kleikamp 1037e7f75ad0SDave Kleikamp#endif /* CONFIG_SMP */ 1038e7f75ad0SDave Kleikamp 1039e7f75ad0SDave Kleikamp/* 1040e7f75ad0SDave Kleikamp * Set up the initial MMU state for 44x 1041e7f75ad0SDave Kleikamp * 1042e7f75ad0SDave Kleikamp * We are still executing code at the virtual address 1043e7f75ad0SDave Kleikamp * mappings set by the firmware for the base of RAM. 1044e7f75ad0SDave Kleikamp */ 1045e7f75ad0SDave Kleikamp 1046e7f75ad0SDave Kleikamphead_start_47x: 1047e7f75ad0SDave Kleikamp /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ 1048e7f75ad0SDave Kleikamp mfspr r3,SPRN_PID /* Get PID */ 1049e7f75ad0SDave Kleikamp mfmsr r4 /* Get MSR */ 1050e7f75ad0SDave Kleikamp andi. r4,r4,MSR_IS@l /* TS=1? */ 1051e7f75ad0SDave Kleikamp beq 1f /* If not, leave STS=0 */ 1052e7f75ad0SDave Kleikamp oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */ 1053e7f75ad0SDave Kleikamp1: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ 1054e7f75ad0SDave Kleikamp sync 1055e7f75ad0SDave Kleikamp 1056e7f75ad0SDave Kleikamp /* Find the entry we are running from */ 1057f5007dbfSChristophe Leroy bcl 20,31,$+4 1058e7f75ad0SDave Kleikamp1: mflr r23 1059e7f75ad0SDave Kleikamp tlbsx r23,0,r23 1060e7f75ad0SDave Kleikamp tlbre r24,r23,0 1061e7f75ad0SDave Kleikamp tlbre r25,r23,1 1062e7f75ad0SDave Kleikamp tlbre r26,r23,2 1063e7f75ad0SDave Kleikamp 1064e7f75ad0SDave Kleikamp/* 1065e7f75ad0SDave Kleikamp * Cleanup time 1066e7f75ad0SDave Kleikamp */ 1067e7f75ad0SDave Kleikamp 1068e7f75ad0SDave Kleikamp /* Initialize MMUCR */ 1069e7f75ad0SDave Kleikamp li r5,0 1070e7f75ad0SDave Kleikamp mtspr SPRN_MMUCR,r5 1071e7f75ad0SDave Kleikamp sync 1072e7f75ad0SDave Kleikamp 1073e7f75ad0SDave Kleikampclear_all_utlb_entries: 1074e7f75ad0SDave Kleikamp 1075e7f75ad0SDave Kleikamp #; Set initial values. 1076e7f75ad0SDave Kleikamp 1077e7f75ad0SDave Kleikamp addis r3,0,0x8000 1078e7f75ad0SDave Kleikamp addi r4,0,0 1079e7f75ad0SDave Kleikamp addi r5,0,0 1080e7f75ad0SDave Kleikamp b clear_utlb_entry 1081e7f75ad0SDave Kleikamp 1082e7f75ad0SDave Kleikamp #; Align the loop to speed things up. 1083e7f75ad0SDave Kleikamp 1084e7f75ad0SDave Kleikamp .align 6 1085e7f75ad0SDave Kleikamp 1086e7f75ad0SDave Kleikampclear_utlb_entry: 1087e7f75ad0SDave Kleikamp 1088e7f75ad0SDave Kleikamp tlbwe r4,r3,0 1089e7f75ad0SDave Kleikamp tlbwe r5,r3,1 1090e7f75ad0SDave Kleikamp tlbwe r5,r3,2 1091e7f75ad0SDave Kleikamp addis r3,r3,0x2000 1092e7f75ad0SDave Kleikamp cmpwi r3,0 1093e7f75ad0SDave Kleikamp bne clear_utlb_entry 1094e7f75ad0SDave Kleikamp addis r3,0,0x8000 1095e7f75ad0SDave Kleikamp addis r4,r4,0x100 1096e7f75ad0SDave Kleikamp cmpwi r4,0 1097e7f75ad0SDave Kleikamp bne clear_utlb_entry 1098e7f75ad0SDave Kleikamp 1099e7f75ad0SDave Kleikamp #; Restore original entry. 1100e7f75ad0SDave Kleikamp 1101e7f75ad0SDave Kleikamp oris r23,r23,0x8000 /* specify the way */ 1102e7f75ad0SDave Kleikamp tlbwe r24,r23,0 1103e7f75ad0SDave Kleikamp tlbwe r25,r23,1 1104e7f75ad0SDave Kleikamp tlbwe r26,r23,2 1105e7f75ad0SDave Kleikamp 1106e7f75ad0SDave Kleikamp/* 1107e7f75ad0SDave Kleikamp * Configure and load pinned entry into TLB for the kernel core 1108e7f75ad0SDave Kleikamp */ 1109e7f75ad0SDave Kleikamp 1110e7f75ad0SDave Kleikamp lis r3,PAGE_OFFSET@h 1111e7f75ad0SDave Kleikamp ori r3,r3,PAGE_OFFSET@l 1112e7f75ad0SDave Kleikamp 1113e7f75ad0SDave Kleikamp /* Load the kernel PID = 0 */ 1114e7f75ad0SDave Kleikamp li r0,0 1115e7f75ad0SDave Kleikamp mtspr SPRN_PID,r0 1116e7f75ad0SDave Kleikamp sync 1117e7f75ad0SDave Kleikamp 1118e7f75ad0SDave Kleikamp /* Word 0 */ 1119e7f75ad0SDave Kleikamp clrrwi r3,r3,12 /* Mask off the effective page number */ 1120e7f75ad0SDave Kleikamp ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M 1121e7f75ad0SDave Kleikamp 11229661534dSDave Kleikamp /* Word 1 - use r25. RPN is the same as the original entry */ 11239661534dSDave Kleikamp 1124e7f75ad0SDave Kleikamp /* Word 2 */ 1125e7f75ad0SDave Kleikamp li r5,0 1126e7f75ad0SDave Kleikamp ori r5,r5,PPC47x_TLB2_S_RWX 1127e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 1128e7f75ad0SDave Kleikamp ori r5,r5,PPC47x_TLB2_M 1129e7f75ad0SDave Kleikamp#endif 1130e7f75ad0SDave Kleikamp 1131e7f75ad0SDave Kleikamp /* We write to way 0 and bolted 0 */ 1132e7f75ad0SDave Kleikamp lis r0,0x8800 1133e7f75ad0SDave Kleikamp tlbwe r3,r0,0 11349661534dSDave Kleikamp tlbwe r25,r0,1 1135e7f75ad0SDave Kleikamp tlbwe r5,r0,2 1136e7f75ad0SDave Kleikamp 1137e7f75ad0SDave Kleikamp/* 1138e7f75ad0SDave Kleikamp * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix 1139e7f75ad0SDave Kleikamp * them up later 1140e7f75ad0SDave Kleikamp */ 1141e7f75ad0SDave Kleikamp LOAD_REG_IMMEDIATE(r3, 0x9abcdef0) 1142e7f75ad0SDave Kleikamp mtspr SPRN_SSPCR,r3 1143e7f75ad0SDave Kleikamp mtspr SPRN_USPCR,r3 1144e7f75ad0SDave Kleikamp LOAD_REG_IMMEDIATE(r3, 0x12345670) 1145e7f75ad0SDave Kleikamp mtspr SPRN_ISPCR,r3 1146e7f75ad0SDave Kleikamp 1147e7f75ad0SDave Kleikamp /* Force context change */ 1148e7f75ad0SDave Kleikamp mfmsr r0 1149e7f75ad0SDave Kleikamp mtspr SPRN_SRR1, r0 1150e7f75ad0SDave Kleikamp lis r0,3f@h 1151e7f75ad0SDave Kleikamp ori r0,r0,3f@l 1152e7f75ad0SDave Kleikamp mtspr SPRN_SRR0,r0 1153e7f75ad0SDave Kleikamp sync 1154e7f75ad0SDave Kleikamp rfi 1155e7f75ad0SDave Kleikamp 1156e7f75ad0SDave Kleikamp /* Invalidate original entry we used */ 1157e7f75ad0SDave Kleikamp3: 1158e7f75ad0SDave Kleikamp rlwinm r24,r24,0,21,19 /* clear the "valid" bit */ 1159e7f75ad0SDave Kleikamp tlbwe r24,r23,0 1160e7f75ad0SDave Kleikamp addi r24,0,0 1161e7f75ad0SDave Kleikamp tlbwe r24,r23,1 1162e7f75ad0SDave Kleikamp tlbwe r24,r23,2 1163e7f75ad0SDave Kleikamp isync /* Clear out the shadow TLB entries */ 1164e7f75ad0SDave Kleikamp 1165e7f75ad0SDave Kleikamp#ifdef CONFIG_PPC_EARLY_DEBUG_44x 1166e7f75ad0SDave Kleikamp /* Add UART mapping for early debug. */ 1167e7f75ad0SDave Kleikamp 1168e7f75ad0SDave Kleikamp /* Word 0 */ 1169e7f75ad0SDave Kleikamp lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h 1170e7f75ad0SDave Kleikamp ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M 1171e7f75ad0SDave Kleikamp 1172e7f75ad0SDave Kleikamp /* Word 1 */ 1173e7f75ad0SDave Kleikamp lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h 1174e7f75ad0SDave Kleikamp ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH 1175e7f75ad0SDave Kleikamp 1176e7f75ad0SDave Kleikamp /* Word 2 */ 1177e7f75ad0SDave Kleikamp li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG) 1178e7f75ad0SDave Kleikamp 1179e7f75ad0SDave Kleikamp /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same 1180e7f75ad0SDave Kleikamp * congruence class as the kernel, we need to make sure of it at 1181e7f75ad0SDave Kleikamp * some point 1182e7f75ad0SDave Kleikamp */ 1183e7f75ad0SDave Kleikamp lis r0,0x8d00 1184e7f75ad0SDave Kleikamp tlbwe r3,r0,0 1185e7f75ad0SDave Kleikamp tlbwe r4,r0,1 1186e7f75ad0SDave Kleikamp tlbwe r5,r0,2 1187e7f75ad0SDave Kleikamp 1188e7f75ad0SDave Kleikamp /* Force context change */ 1189e7f75ad0SDave Kleikamp isync 1190e7f75ad0SDave Kleikamp#endif /* CONFIG_PPC_EARLY_DEBUG_44x */ 1191e7f75ad0SDave Kleikamp 1192e7f75ad0SDave Kleikamp /* Establish the interrupt vector offsets */ 1193e7f75ad0SDave Kleikamp SET_IVOR(0, CriticalInput); 1194e7f75ad0SDave Kleikamp SET_IVOR(1, MachineCheckA); 1195e7f75ad0SDave Kleikamp SET_IVOR(2, DataStorage); 1196e7f75ad0SDave Kleikamp SET_IVOR(3, InstructionStorage); 1197e7f75ad0SDave Kleikamp SET_IVOR(4, ExternalInput); 1198e7f75ad0SDave Kleikamp SET_IVOR(5, Alignment); 1199e7f75ad0SDave Kleikamp SET_IVOR(6, Program); 1200e7f75ad0SDave Kleikamp SET_IVOR(7, FloatingPointUnavailable); 1201e7f75ad0SDave Kleikamp SET_IVOR(8, SystemCall); 1202e7f75ad0SDave Kleikamp SET_IVOR(9, AuxillaryProcessorUnavailable); 1203e7f75ad0SDave Kleikamp SET_IVOR(10, Decrementer); 1204e7f75ad0SDave Kleikamp SET_IVOR(11, FixedIntervalTimer); 1205e7f75ad0SDave Kleikamp SET_IVOR(12, WatchdogTimer); 1206e7f75ad0SDave Kleikamp SET_IVOR(13, DataTLBError47x); 1207e7f75ad0SDave Kleikamp SET_IVOR(14, InstructionTLBError47x); 1208e7f75ad0SDave Kleikamp SET_IVOR(15, DebugCrit); 1209e7f75ad0SDave Kleikamp 1210e7f75ad0SDave Kleikamp /* We configure icbi to invalidate 128 bytes at a time since the 1211e7f75ad0SDave Kleikamp * current 32-bit kernel code isn't too happy with icache != dcache 121297b3be1eSAlistair Popple * block size. We also disable the BTAC as this can cause errors 121397b3be1eSAlistair Popple * in some circumstances (see IBM Erratum 47). 1214e7f75ad0SDave Kleikamp */ 1215e7f75ad0SDave Kleikamp mfspr r3,SPRN_CCR0 1216e7f75ad0SDave Kleikamp oris r3,r3,0x0020 121797b3be1eSAlistair Popple ori r3,r3,0x0040 1218e7f75ad0SDave Kleikamp mtspr SPRN_CCR0,r3 1219e7f75ad0SDave Kleikamp isync 1220e7f75ad0SDave Kleikamp 1221e7f75ad0SDave Kleikamp#endif /* CONFIG_PPC_47x */ 1222e7f75ad0SDave Kleikamp 1223e7f75ad0SDave Kleikamp/* 1224e7f75ad0SDave Kleikamp * Here we are back to code that is common between 44x and 47x 1225e7f75ad0SDave Kleikamp * 1226e7f75ad0SDave Kleikamp * We proceed to further kernel initialization and return to the 1227e7f75ad0SDave Kleikamp * main kernel entry 1228e7f75ad0SDave Kleikamp */ 1229e7f75ad0SDave Kleikamphead_start_common: 1230795033c3SDave Kleikamp /* Establish the interrupt vector base */ 1231795033c3SDave Kleikamp lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */ 1232795033c3SDave Kleikamp mtspr SPRN_IVPR,r4 1233795033c3SDave Kleikamp 12349661534dSDave Kleikamp /* 12359661534dSDave Kleikamp * If the kernel was loaded at a non-zero 256 MB page, we need to 12369661534dSDave Kleikamp * mask off the most significant 4 bits to get the relative address 12379661534dSDave Kleikamp * from the start of physical memory 12389661534dSDave Kleikamp */ 12399661534dSDave Kleikamp rlwinm r22,r22,0,4,31 12409661534dSDave Kleikamp addis r22,r22,PAGE_OFFSET@h 1241795033c3SDave Kleikamp mtlr r22 1242e7f75ad0SDave Kleikamp isync 1243795033c3SDave Kleikamp blr 1244795033c3SDave Kleikamp 1245e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 1246e72421a0SChristophe Leroy .data 1247e7f75ad0SDave Kleikamp .align 12 1248e7f75ad0SDave Kleikamptemp_boot_stack: 1249e7f75ad0SDave Kleikamp .space 1024 1250e7f75ad0SDave Kleikamp#endif /* CONFIG_SMP */ 1251