12874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */ 214cf11afSPaul Mackerras/* 314cf11afSPaul Mackerras * PowerPC version 414cf11afSPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 514cf11afSPaul Mackerras * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP 614cf11afSPaul Mackerras * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu> 714cf11afSPaul Mackerras * Low-level exception handlers and MMU support 814cf11afSPaul Mackerras * rewritten by Paul Mackerras. 914cf11afSPaul Mackerras * Copyright (C) 1996 Paul Mackerras. 1014cf11afSPaul Mackerras * MPC8xx modifications by Dan Malek 1114cf11afSPaul Mackerras * Copyright (C) 1997 Dan Malek (dmalek@jlc.net). 1214cf11afSPaul Mackerras * 1314cf11afSPaul Mackerras * This file contains low-level support and setup for PowerPC 8xx 1414cf11afSPaul Mackerras * embedded processors, including trap and interrupt dispatch. 1514cf11afSPaul Mackerras */ 1614cf11afSPaul Mackerras 17e7039845STim Abbott#include <linux/init.h> 183bbd2343SChristophe Leroy#include <linux/magic.h> 1965fddcfcSMike Rapoport#include <linux/pgtable.h> 20f76c8f6dSChristophe Leroy#include <linux/sizes.h> 212da37761SChristophe Leroy#include <linux/linkage.h> 222da37761SChristophe Leroy 2314cf11afSPaul Mackerras#include <asm/processor.h> 2414cf11afSPaul Mackerras#include <asm/page.h> 2514cf11afSPaul Mackerras#include <asm/mmu.h> 2614cf11afSPaul Mackerras#include <asm/cache.h> 2714cf11afSPaul Mackerras#include <asm/cputable.h> 2814cf11afSPaul Mackerras#include <asm/thread_info.h> 2914cf11afSPaul Mackerras#include <asm/ppc_asm.h> 3014cf11afSPaul Mackerras#include <asm/asm-offsets.h> 3146f52210SStephen Rothwell#include <asm/ptrace.h> 321a210878SChristophe Leroy#include <asm/code-patching-asm.h> 330f5eb28aSChristophe Leroy#include <asm/interrupt.h> 3414cf11afSPaul Mackerras 355b1c9a0dSChristophe Leroy/* 365b1c9a0dSChristophe Leroy * Value for the bits that have fixed value in RPN entries. 375b1c9a0dSChristophe Leroy * Also used for tagging DAR for DTLBerror. 385b1c9a0dSChristophe Leroy */ 395b1c9a0dSChristophe Leroy#define RPN_PATTERN 0x00f0 405b1c9a0dSChristophe Leroy 418a23fdecSChristophe Leroy#include "head_32.h" 428a23fdecSChristophe Leroy 43c8bef10aSChristophe Leroy.macro compare_to_kernel_boundary scratch, addr 44*efdf2af5SChristophe Leroy#if CONFIG_TASK_SIZE <= 0x80000000 && MODULES_VADDR >= 0x80000000 45c8a12709SChristophe Leroy/* By simply checking Address >= 0x80000000, we know if its a kernel address */ 46c8bef10aSChristophe Leroy not. \scratch, \addr 47c8bef10aSChristophe Leroy#else 48c8bef10aSChristophe Leroy rlwinm \scratch, \addr, 16, 0xfff8 49*efdf2af5SChristophe Leroy cmpli cr0, \scratch, TASK_SIZE@h 50eeba1f7cSLEROY Christophe#endif 51c8bef10aSChristophe Leroy.endm 52eeba1f7cSLEROY Christophe 534b914286SChristophe Leroy#define PAGE_SHIFT_512K 19 544b914286SChristophe Leroy#define PAGE_SHIFT_8M 23 554b914286SChristophe Leroy 56e7039845STim Abbott __HEAD 5727e21e8fSChristophe Leroy_GLOBAL(_stext); 5827e21e8fSChristophe Leroy_GLOBAL(_start); 5914cf11afSPaul Mackerras 6014cf11afSPaul Mackerras/* MPC8xx 6114cf11afSPaul Mackerras * This port was done on an MBX board with an 860. Right now I only 6214cf11afSPaul Mackerras * support an ELF compressed (zImage) boot from EPPC-Bug because the 6314cf11afSPaul Mackerras * code there loads up some registers before calling us: 6414cf11afSPaul Mackerras * r3: ptr to board info data 6514cf11afSPaul Mackerras * r4: initrd_start or if no initrd then 0 6614cf11afSPaul Mackerras * r5: initrd_end - unused if r4 is 0 6714cf11afSPaul Mackerras * r6: Start of command line string 6814cf11afSPaul Mackerras * r7: End of command line string 6914cf11afSPaul Mackerras * 7014cf11afSPaul Mackerras * I decided to use conditional compilation instead of checking PVR and 7114cf11afSPaul Mackerras * adding more processor specific branches around code I don't need. 7214cf11afSPaul Mackerras * Since this is an embedded processor, I also appreciate any memory 7314cf11afSPaul Mackerras * savings I can get. 7414cf11afSPaul Mackerras * 7514cf11afSPaul Mackerras * The MPC8xx does not have any BATs, but it supports large page sizes. 7614cf11afSPaul Mackerras * We first initialize the MMU to support 8M byte pages, then load one 7714cf11afSPaul Mackerras * entry into each of the instruction and data TLBs to map the first 7814cf11afSPaul Mackerras * 8M 1:1. I also mapped an additional I/O space 1:1 so we can get to 7914cf11afSPaul Mackerras * the "internal" processor registers before MMU_init is called. 8014cf11afSPaul Mackerras * 8114cf11afSPaul Mackerras * -- Dan 8214cf11afSPaul Mackerras */ 8314cf11afSPaul Mackerras .globl __start 8414cf11afSPaul Mackerras__start: 856dece0ebSScott Wood mr r31,r3 /* save device tree ptr */ 8614cf11afSPaul Mackerras 8714cf11afSPaul Mackerras /* We have to turn on the MMU right away so we get cache modes 8814cf11afSPaul Mackerras * set correctly. 8914cf11afSPaul Mackerras */ 9014cf11afSPaul Mackerras bl initial_mmu 9114cf11afSPaul Mackerras 9214cf11afSPaul Mackerras/* We now have the lower 8 Meg mapped into TLB entries, and the caches 9314cf11afSPaul Mackerras * ready to work. 9414cf11afSPaul Mackerras */ 9514cf11afSPaul Mackerras 9614cf11afSPaul Mackerrasturn_on_mmu: 9714cf11afSPaul Mackerras mfmsr r0 9814cf11afSPaul Mackerras ori r0,r0,MSR_DR|MSR_IR 9914cf11afSPaul Mackerras mtspr SPRN_SRR1,r0 10014cf11afSPaul Mackerras lis r0,start_here@h 10114cf11afSPaul Mackerras ori r0,r0,start_here@l 10214cf11afSPaul Mackerras mtspr SPRN_SRR0,r0 10314cf11afSPaul Mackerras rfi /* enables MMU */ 10414cf11afSPaul Mackerras 1058cfe4f52SChristophe Leroy 1068cfe4f52SChristophe Leroy#ifdef CONFIG_PERF_EVENTS 1078cfe4f52SChristophe Leroy .align 4 1088cfe4f52SChristophe Leroy 1098cfe4f52SChristophe Leroy .globl itlb_miss_counter 1108cfe4f52SChristophe Leroyitlb_miss_counter: 1118cfe4f52SChristophe Leroy .space 4 1128cfe4f52SChristophe Leroy 1138cfe4f52SChristophe Leroy .globl dtlb_miss_counter 1148cfe4f52SChristophe Leroydtlb_miss_counter: 1158cfe4f52SChristophe Leroy .space 4 1168cfe4f52SChristophe Leroy 1178cfe4f52SChristophe Leroy .globl instruction_counter 1188cfe4f52SChristophe Leroyinstruction_counter: 1198cfe4f52SChristophe Leroy .space 4 1208cfe4f52SChristophe Leroy#endif 1218cfe4f52SChristophe Leroy 12214cf11afSPaul Mackerras/* System reset */ 1230f5eb28aSChristophe Leroy EXCEPTION(INTERRUPT_SYSTEM_RESET, Reset, system_reset_exception) 12414cf11afSPaul Mackerras 12514cf11afSPaul Mackerras/* Machine check */ 1260f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_MACHINE_CHECK, MachineCheck) 1270f5eb28aSChristophe Leroy EXCEPTION_PROLOG INTERRUPT_MACHINE_CHECK MachineCheck handle_dar_dsisr=1 1284c0104a8SChristophe Leroy prepare_transfer_to_handler 1294c0104a8SChristophe Leroy bl machine_check_exception 1304c0104a8SChristophe Leroy b interrupt_return 13114cf11afSPaul Mackerras 13214cf11afSPaul Mackerras/* External interrupt */ 1330f5eb28aSChristophe Leroy EXCEPTION(INTERRUPT_EXTERNAL, HardwareInterrupt, do_IRQ) 13414cf11afSPaul Mackerras 13514cf11afSPaul Mackerras/* Alignment exception */ 1360f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_ALIGNMENT, Alignment) 1370f5eb28aSChristophe Leroy EXCEPTION_PROLOG INTERRUPT_ALIGNMENT Alignment handle_dar_dsisr=1 1388f6ff5bdSChristophe Leroy prepare_transfer_to_handler 1398f6ff5bdSChristophe Leroy bl alignment_exception 1408f6ff5bdSChristophe Leroy REST_NVGPRS(r1) 1418f6ff5bdSChristophe Leroy b interrupt_return 14214cf11afSPaul Mackerras 14314cf11afSPaul Mackerras/* Program check exception */ 1440f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_PROGRAM, ProgramCheck) 1450f5eb28aSChristophe Leroy EXCEPTION_PROLOG INTERRUPT_PROGRAM ProgramCheck 1468f6ff5bdSChristophe Leroy prepare_transfer_to_handler 1478f6ff5bdSChristophe Leroy bl program_check_exception 1488f6ff5bdSChristophe Leroy REST_NVGPRS(r1) 1498f6ff5bdSChristophe Leroy b interrupt_return 15014cf11afSPaul Mackerras 15114cf11afSPaul Mackerras/* Decrementer */ 1520f5eb28aSChristophe Leroy EXCEPTION(INTERRUPT_DECREMENTER, Decrementer, timer_interrupt) 15314cf11afSPaul Mackerras 15414cf11afSPaul Mackerras/* System call */ 1550f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_SYSCALL, SystemCall) 1560f5eb28aSChristophe Leroy SYSCALL_ENTRY INTERRUPT_SYSCALL 15714cf11afSPaul Mackerras 15814cf11afSPaul Mackerras/* Single step - not used on 601 */ 1590f5eb28aSChristophe Leroy EXCEPTION(INTERRUPT_TRACE, SingleStep, single_step_exception) 16014cf11afSPaul Mackerras 16114cf11afSPaul Mackerras/* On the MPC8xx, this is a software emulation interrupt. It occurs 16214cf11afSPaul Mackerras * for all unimplemented and illegal instructions. 16314cf11afSPaul Mackerras */ 1640f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_SOFT_EMU_8xx, SoftEmu) 1650f5eb28aSChristophe Leroy EXCEPTION_PROLOG INTERRUPT_SOFT_EMU_8xx SoftEmu 1668f6ff5bdSChristophe Leroy prepare_transfer_to_handler 1678f6ff5bdSChristophe Leroy bl emulation_assist_interrupt 1688f6ff5bdSChristophe Leroy REST_NVGPRS(r1) 1698f6ff5bdSChristophe Leroy b interrupt_return 17014cf11afSPaul Mackerras 17114cf11afSPaul Mackerras/* 17214cf11afSPaul Mackerras * For the MPC8xx, this is a software tablewalk to load the instruction 1736a8f911bSChristophe Leroy * TLB. The task switch loads the M_TWB register with the pointer to the first 174cbc130f1SLEROY Christophe * level table. 17514cf11afSPaul Mackerras * If we discover there is no second level table (value is zero) or if there 17614cf11afSPaul Mackerras * is an invalid pte, we load that into the TLB, which causes another fault 17714cf11afSPaul Mackerras * into the TLB Error interrupt where we can handle such problems. 17814cf11afSPaul Mackerras * We have to use the MD_xxx registers for the tablewalk because the 17914cf11afSPaul Mackerras * equivalent MI_xxx registers only perform the attribute functions. 18014cf11afSPaul Mackerras */ 18190883a82SLEROY Christophe 18290883a82SLEROY Christophe#ifdef CONFIG_8xx_CPU15 183576e02bbSChristophe Leroy#define INVALIDATE_ADJACENT_PAGES_CPU15(addr, tmp) \ 184576e02bbSChristophe Leroy addi tmp, addr, PAGE_SIZE; \ 185576e02bbSChristophe Leroy tlbie tmp; \ 186576e02bbSChristophe Leroy addi tmp, addr, -PAGE_SIZE; \ 187576e02bbSChristophe Leroy tlbie tmp 18890883a82SLEROY Christophe#else 189576e02bbSChristophe Leroy#define INVALIDATE_ADJACENT_PAGES_CPU15(addr, tmp) 19090883a82SLEROY Christophe#endif 19190883a82SLEROY Christophe 1920f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_INST_TLB_MISS_8xx, InstructionTLBMiss) 193a314ea5aSChristophe Leroy mtspr SPRN_SPRG_SCRATCH2, r10 194a314ea5aSChristophe Leroy mtspr SPRN_M_TW, r11 19514cf11afSPaul Mackerras 19614cf11afSPaul Mackerras /* If we are faulting a kernel address, we have to use the 19714cf11afSPaul Mackerras * kernel page tables. 19814cf11afSPaul Mackerras */ 199d1b9f814SChristophe Leroy mfspr r10, SPRN_SRR0 /* Get effective address of fault */ 200576e02bbSChristophe Leroy INVALIDATE_ADJACENT_PAGES_CPU15(r10, r11) 2016a8f911bSChristophe Leroy mtspr SPRN_MD_EPN, r10 202bccc5898SChristophe Leroy#ifdef CONFIG_MODULES 20374fabcadSChristophe Leroy mfcr r11 204c8bef10aSChristophe Leroy compare_to_kernel_boundary r10, r10 205d1b9f814SChristophe Leroy#endif 20674fabcadSChristophe Leroy mfspr r10, SPRN_M_TWB /* Get level 1 table */ 207bccc5898SChristophe Leroy#ifdef CONFIG_MODULES 208c8a12709SChristophe Leroy blt+ 3f 20974fabcadSChristophe Leroy rlwinm r10, r10, 0, 20, 31 21074fabcadSChristophe Leroy oris r10, r10, (swapper_pg_dir - PAGE_OFFSET)@ha 21114cf11afSPaul Mackerras3: 21274fabcadSChristophe Leroy mtcr r11 2134b914286SChristophe Leroy#endif 214a891c43bSChristophe Leroy lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r10) /* Get level 1 entry */ 215a891c43bSChristophe Leroy mtspr SPRN_MD_TWC, r11 216a891c43bSChristophe Leroy mfspr r10, SPRN_MD_TWC 217a891c43bSChristophe Leroy lwz r10, 0(r10) /* Get the pte */ 21833fe43cfSChristophe Leroy rlwimi r11, r10, 0, _PAGE_GUARDED | _PAGE_ACCESSED 219b250c8c0SChristophe Leroy rlwimi r11, r10, 32 - 9, _PMD_PAGE_512K 220b250c8c0SChristophe Leroy mtspr SPRN_MI_TWC, r11 22114cf11afSPaul Mackerras /* The Linux PTE won't go exactly into the MMU TLB. 222de0f9387SChristophe Leroy * Software indicator bits 20 and 23 must be clear. 223de0f9387SChristophe Leroy * Software indicator bits 22, 24, 25, 26, and 27 must be 22414cf11afSPaul Mackerras * set. All other Linux PTE bits control the behavior 22514cf11afSPaul Mackerras * of the MMU. 22614cf11afSPaul Mackerras */ 227a4031afbSChristophe Leroy rlwinm r10, r10, 0, ~0x0f00 /* Clear bits 20-23 */ 22874fabcadSChristophe Leroy rlwimi r10, r10, 4, 0x0400 /* Copy _PAGE_EXEC into bit 21 */ 22974fabcadSChristophe Leroy ori r10, r10, RPN_PATTERN | 0x200 /* Set 22 and 24-27 */ 2302a45adddSChristophe Leroy mtspr SPRN_MI_RPN, r10 /* Update TLB entry */ 23114cf11afSPaul Mackerras 232469d62beSJoakim Tjernlund /* Restore registers */ 233a314ea5aSChristophe Leroy0: mfspr r10, SPRN_SPRG_SCRATCH2 234a314ea5aSChristophe Leroy mfspr r11, SPRN_M_TW 235cd99ddbeSChristophe Leroy rfi 236709cf19cSChristophe Leroy patch_site 0b, patch__itlbmiss_exit_1 237709cf19cSChristophe Leroy 238cd99ddbeSChristophe Leroy#ifdef CONFIG_PERF_EVENTS 239709cf19cSChristophe Leroy patch_site 0f, patch__itlbmiss_perf 2408cfe4f52SChristophe Leroy0: lwz r10, (itlb_miss_counter - PAGE_OFFSET)@l(0) 2418cfe4f52SChristophe Leroy addi r10, r10, 1 2428cfe4f52SChristophe Leroy stw r10, (itlb_miss_counter - PAGE_OFFSET)@l(0) 243a314ea5aSChristophe Leroy mfspr r10, SPRN_SPRG_SCRATCH2 244a314ea5aSChristophe Leroy mfspr r11, SPRN_M_TW 24514cf11afSPaul Mackerras rfi 2468cfe4f52SChristophe Leroy#endif 24714cf11afSPaul Mackerras 2480f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_DATA_TLB_MISS_8xx, DataStoreTLBMiss) 24989eecd93SChristophe Leroy mtspr SPRN_SPRG_SCRATCH2, r10 2506edc3185SChristophe Leroy mtspr SPRN_M_TW, r11 25174fabcadSChristophe Leroy mfcr r11 25214cf11afSPaul Mackerras 25314cf11afSPaul Mackerras /* If we are faulting a kernel address, we have to use the 25414cf11afSPaul Mackerras * kernel page tables. 25514cf11afSPaul Mackerras */ 25636eb1542SChristophe Leroy mfspr r10, SPRN_MD_EPN 257c8bef10aSChristophe Leroy compare_to_kernel_boundary r10, r10 25874fabcadSChristophe Leroy mfspr r10, SPRN_M_TWB /* Get level 1 table */ 25974fabcadSChristophe Leroy blt+ 3f 26074fabcadSChristophe Leroy rlwinm r10, r10, 0, 20, 31 26174fabcadSChristophe Leroy oris r10, r10, (swapper_pg_dir - PAGE_OFFSET)@ha 26214cf11afSPaul Mackerras3: 26374fabcadSChristophe Leroy mtcr r11 26474fabcadSChristophe Leroy lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r10) /* Get level 1 entry */ 26514cf11afSPaul Mackerras 2666a8f911bSChristophe Leroy mtspr SPRN_MD_TWC, r11 2676a8f911bSChristophe Leroy mfspr r10, SPRN_MD_TWC 26814cf11afSPaul Mackerras lwz r10, 0(r10) /* Get the pte */ 2696a8f911bSChristophe Leroy 27033fe43cfSChristophe Leroy /* Insert Guarded and Accessed flags into the TWC from the Linux PTE. 271de0f9387SChristophe Leroy * It is bit 27 of both the Linux PTE and the TWC (at least 27214cf11afSPaul Mackerras * I got that right :-). It will be better when we can put 27314cf11afSPaul Mackerras * this into the Linux pgd/pmd and load it in the operation 27414cf11afSPaul Mackerras * above. 27514cf11afSPaul Mackerras */ 27633fe43cfSChristophe Leroy rlwimi r11, r10, 0, _PAGE_GUARDED | _PAGE_ACCESSED 277b250c8c0SChristophe Leroy rlwimi r11, r10, 32 - 9, _PMD_PAGE_512K 2782a45adddSChristophe Leroy mtspr SPRN_MD_TWC, r11 27914cf11afSPaul Mackerras 28014cf11afSPaul Mackerras /* The Linux PTE won't go exactly into the MMU TLB. 28114cf11afSPaul Mackerras * Software indicator bits 24, 25, 26, and 27 must be 28214cf11afSPaul Mackerras * set. All other Linux PTE bits control the behavior 28314cf11afSPaul Mackerras * of the MMU. 28414cf11afSPaul Mackerras */ 2855ddb75ceSLEROY Christophe li r11, RPN_PATTERN 2864b914286SChristophe Leroy rlwimi r10, r11, 0, 24, 27 /* Set 24-27 */ 2872a45adddSChristophe Leroy mtspr SPRN_MD_RPN, r10 /* Update TLB entry */ 28889eecd93SChristophe Leroy mtspr SPRN_DAR, r11 /* Tag DAR */ 28914cf11afSPaul Mackerras 290469d62beSJoakim Tjernlund /* Restore registers */ 291709cf19cSChristophe Leroy 29289eecd93SChristophe Leroy0: mfspr r10, SPRN_SPRG_SCRATCH2 2936edc3185SChristophe Leroy mfspr r11, SPRN_M_TW 294cd99ddbeSChristophe Leroy rfi 295709cf19cSChristophe Leroy patch_site 0b, patch__dtlbmiss_exit_1 296709cf19cSChristophe Leroy 2970c8c2c9cSChristophe Leroy#ifdef CONFIG_PERF_EVENTS 2980c8c2c9cSChristophe Leroy patch_site 0f, patch__dtlbmiss_perf 2990c8c2c9cSChristophe Leroy0: lwz r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0) 3000c8c2c9cSChristophe Leroy addi r10, r10, 1 3010c8c2c9cSChristophe Leroy stw r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0) 30289eecd93SChristophe Leroy mfspr r10, SPRN_SPRG_SCRATCH2 3030c8c2c9cSChristophe Leroy mfspr r11, SPRN_M_TW 3040c8c2c9cSChristophe Leroy rfi 3050c8c2c9cSChristophe Leroy#endif 3060c8c2c9cSChristophe Leroy 30714cf11afSPaul Mackerras/* This is an instruction TLB error on the MPC8xx. This could be due 30814cf11afSPaul Mackerras * to many reasons, such as executing guarded memory or illegal instruction 30914cf11afSPaul Mackerras * addresses. There is nothing to do but handle a big time error fault. 31014cf11afSPaul Mackerras */ 3110f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_INST_TLB_ERROR_8xx, InstructionTLBError) 312719e7e21SChristophe Leroy /* 0x400 is InstructionAccess exception, needed by bad_page_fault() */ 3130f5eb28aSChristophe Leroy EXCEPTION_PROLOG INTERRUPT_INST_STORAGE InstructionTLBError 314b4c001dcSBenjamin Herrenschmidt andis. r5,r9,DSISR_SRR1_MATCH_32S@h /* Filter relevant SRR1 bits */ 315b4c001dcSBenjamin Herrenschmidt andis. r10,r9,SRR1_ISI_NOPT@h 31632ceaa6eSChristophe Leroy beq+ .Litlbie 317a01a3f2dSNicholas Piggin tlbie r12 31832ceaa6eSChristophe Leroy.Litlbie: 319a01a3f2dSNicholas Piggin stw r12, _DAR(r11) 320a01a3f2dSNicholas Piggin stw r5, _DSISR(r11) 3214c0104a8SChristophe Leroy prepare_transfer_to_handler 3224c0104a8SChristophe Leroy bl do_page_fault 3234c0104a8SChristophe Leroy b interrupt_return 32414cf11afSPaul Mackerras 32514cf11afSPaul Mackerras/* This is the data TLB error on the MPC8xx. This could be due to 326140a6a60SLEROY Christophe * many reasons, including a dirty update to a pte. We bail out to 327140a6a60SLEROY Christophe * a higher level function that can handle it. 32814cf11afSPaul Mackerras */ 3290f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_DATA_TLB_ERROR_8xx, DataTLBError) 33099b22916SChristophe Leroy EXCEPTION_PROLOG_0 handle_dar_dsisr=1 3315bcbe24fSLEROY Christophe mfspr r11, SPRN_DAR 3325ae8fabcSChristophe Leroy cmpwi cr1, r11, RPN_PATTERN 3335ae8fabcSChristophe Leroy beq- cr1, FixupDAR /* must be a buggy dcbX, icbi insn. */ 3343e436403SLEROY ChristopheDARFixed:/* Return from dcbx instruction bug workaround */ 3356cde2b6fSLEROY Christophe EXCEPTION_PROLOG_1 336719e7e21SChristophe Leroy /* 0x300 is DataAccess exception, needed by bad_page_fault() */ 3370f5eb28aSChristophe Leroy EXCEPTION_PROLOG_2 INTERRUPT_DATA_STORAGE DataTLBError handle_dar_dsisr=1 3387aa8dd67SChristophe Leroy lwz r4, _DAR(r11) 3397aa8dd67SChristophe Leroy lwz r5, _DSISR(r11) 3404915349bSChristophe Leroy andis. r10,r5,DSISR_NOHPTE@h 34132ceaa6eSChristophe Leroy beq+ .Ldtlbie 342c51a6821SLEROY Christophe tlbie r4 34332ceaa6eSChristophe Leroy.Ldtlbie: 3444c0104a8SChristophe Leroy prepare_transfer_to_handler 3454c0104a8SChristophe Leroy bl do_page_fault 3464c0104a8SChristophe Leroy b interrupt_return 34714cf11afSPaul Mackerras 3485b5e5bc5SChristophe Leroy#ifdef CONFIG_VMAP_STACK 34999b22916SChristophe Leroy vmap_stack_overflow_exception 3505b5e5bc5SChristophe Leroy#endif 35199b22916SChristophe Leroy 35214cf11afSPaul Mackerras/* On the MPC8xx, these next four traps are used for development 35314cf11afSPaul Mackerras * support of breakpoints and such. Someday I will get around to 35414cf11afSPaul Mackerras * using them. 35514cf11afSPaul Mackerras */ 3560f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_DATA_BREAKPOINT_8xx, DataBreakpoint) 35799b22916SChristophe Leroy EXCEPTION_PROLOG_0 handle_dar_dsisr=1 358afe1ec5aSChristophe Leroy mfspr r11, SPRN_SRR0 359afe1ec5aSChristophe Leroy cmplwi cr1, r11, (.Ldtlbie - PAGE_OFFSET)@l 360afe1ec5aSChristophe Leroy cmplwi cr7, r11, (.Litlbie - PAGE_OFFSET)@l 361afe1ec5aSChristophe Leroy cror 4*cr1+eq, 4*cr1+eq, 4*cr7+eq 362dc13b889SChristophe Leroy bne cr1, 1f 3634ad8622dSChristophe Leroy mtcr r10 364bb9b5a83SChristophe Leroy mfspr r10, SPRN_SPRG_SCRATCH0 365bb9b5a83SChristophe Leroy mfspr r11, SPRN_SPRG_SCRATCH1 3664ad8622dSChristophe Leroy rfi 3674ad8622dSChristophe Leroy 368dc13b889SChristophe Leroy1: EXCEPTION_PROLOG_1 3690f5eb28aSChristophe Leroy EXCEPTION_PROLOG_2 INTERRUPT_DATA_BREAKPOINT_8xx DataBreakpoint handle_dar_dsisr=1 370dc13b889SChristophe Leroy mfspr r4,SPRN_BAR 371dc13b889SChristophe Leroy stw r4,_DAR(r11) 3728f6ff5bdSChristophe Leroy prepare_transfer_to_handler 3738f6ff5bdSChristophe Leroy bl do_break 3748f6ff5bdSChristophe Leroy REST_NVGPRS(r1) 3758f6ff5bdSChristophe Leroy b interrupt_return 376dc13b889SChristophe Leroy 377cd99ddbeSChristophe Leroy#ifdef CONFIG_PERF_EVENTS 3780f5eb28aSChristophe Leroy START_EXCEPTION(INTERRUPT_INST_BREAKPOINT_8xx, InstructionBreakpoint) 379bb9b5a83SChristophe Leroy mtspr SPRN_SPRG_SCRATCH0, r10 3808cfe4f52SChristophe Leroy lwz r10, (instruction_counter - PAGE_OFFSET)@l(0) 3818cfe4f52SChristophe Leroy addi r10, r10, -1 3828cfe4f52SChristophe Leroy stw r10, (instruction_counter - PAGE_OFFSET)@l(0) 38375b82472SChristophe Leroy lis r10, 0xffff 38475b82472SChristophe Leroy ori r10, r10, 0x01 38575b82472SChristophe Leroy mtspr SPRN_COUNTA, r10 386bb9b5a83SChristophe Leroy mfspr r10, SPRN_SPRG_SCRATCH0 38775b82472SChristophe Leroy rfi 38875b82472SChristophe Leroy#else 3890f5eb28aSChristophe Leroy EXCEPTION(INTERRUPT_INST_BREAKPOINT_8xx, Trap_1d, unknown_exception) 39075b82472SChristophe Leroy#endif 391acc142b6SChristophe Leroy EXCEPTION(0x1e00, Trap_1e, unknown_exception) 392acc142b6SChristophe Leroy EXCEPTION(0x1f00, Trap_1f, unknown_exception) 39314cf11afSPaul Mackerras 394dc13b889SChristophe Leroy __HEAD 39514cf11afSPaul Mackerras . = 0x2000 39614cf11afSPaul Mackerras 3970a2ab51fSJoakim Tjernlund/* This is the procedure to calculate the data EA for buggy dcbx,dcbi instructions 3980a2ab51fSJoakim Tjernlund * by decoding the registers used by the dcbx instruction and adding them. 3993e436403SLEROY Christophe * DAR is set to the calculated address. 4000a2ab51fSJoakim Tjernlund */ 4010a2ab51fSJoakim TjernlundFixupDAR:/* Entry point for dcbx workaround. */ 40274fabcadSChristophe Leroy mtspr SPRN_M_TW, r10 4030a2ab51fSJoakim Tjernlund /* fetch instruction from memory. */ 4040a2ab51fSJoakim Tjernlund mfspr r10, SPRN_SRR0 4056a8f911bSChristophe Leroy mtspr SPRN_MD_EPN, r10 406c8a12709SChristophe Leroy rlwinm r11, r10, 16, 0xfff8 407*efdf2af5SChristophe Leroy cmpli cr1, r11, TASK_SIZE@h 4086a8f911bSChristophe Leroy mfspr r11, SPRN_M_TWB /* Get level 1 table */ 4095ae8fabcSChristophe Leroy blt+ cr1, 3f 4101a210878SChristophe Leroy 41136eb1542SChristophe Leroy /* create physical page address from effective address */ 41236eb1542SChristophe Leroy tophys(r11, r10) 4136a8f911bSChristophe Leroy mfspr r11, SPRN_M_TWB /* Get level 1 table */ 4146a8f911bSChristophe Leroy rlwinm r11, r11, 0, 20, 31 4156a8f911bSChristophe Leroy oris r11, r11, (swapper_pg_dir - PAGE_OFFSET)@ha 4166a8f911bSChristophe Leroy3: 417fde5a905SLEROY Christophe lwz r11, (swapper_pg_dir-PAGE_OFFSET)@l(r11) /* Get the level 1 entry */ 4186a8f911bSChristophe Leroy mtspr SPRN_MD_TWC, r11 4195ae8fabcSChristophe Leroy mtcrf 0x01, r11 4206a8f911bSChristophe Leroy mfspr r11, SPRN_MD_TWC 4216a8f911bSChristophe Leroy lwz r11, 0(r11) /* Get the pte */ 4224b914286SChristophe Leroy bt 28,200f /* bit 28 = Large page (8M) */ 4230a2ab51fSJoakim Tjernlund /* concat physical page address(r11) and page offset(r10) */ 424d1406803SLEROY Christophe rlwimi r11, r10, 0, 32 - PAGE_SHIFT, 31 425a372acfaSChristophe Leroy201: lwz r11,0(r11) 4260a2ab51fSJoakim Tjernlund/* Check if it really is a dcbx instruction. */ 4270a2ab51fSJoakim Tjernlund/* dcbt and dcbtst does not generate DTLB Misses/Errors, 4280a2ab51fSJoakim Tjernlund * no need to include them here */ 42941cacac6SLEROY Christophe xoris r10, r11, 0x7c00 /* check if major OP code is 31 */ 43041cacac6SLEROY Christophe rlwinm r10, r10, 0, 21, 5 4315ae8fabcSChristophe Leroy cmpwi cr1, r10, 2028 /* Is dcbz? */ 4325ae8fabcSChristophe Leroy beq+ cr1, 142f 4335ae8fabcSChristophe Leroy cmpwi cr1, r10, 940 /* Is dcbi? */ 4345ae8fabcSChristophe Leroy beq+ cr1, 142f 4355ae8fabcSChristophe Leroy cmpwi cr1, r10, 108 /* Is dcbst? */ 4365ae8fabcSChristophe Leroy beq+ cr1, 144f /* Fix up store bit! */ 4375ae8fabcSChristophe Leroy cmpwi cr1, r10, 172 /* Is dcbf? */ 4385ae8fabcSChristophe Leroy beq+ cr1, 142f 4395ae8fabcSChristophe Leroy cmpwi cr1, r10, 1964 /* Is icbi? */ 4405ae8fabcSChristophe Leroy beq+ cr1, 142f 44174fabcadSChristophe Leroy141: mfspr r10,SPRN_M_TW 4425bcbe24fSLEROY Christophe b DARFixed /* Nope, go back to normal TLB processing */ 4430a2ab51fSJoakim Tjernlund 4444b914286SChristophe Leroy200: 4454b914286SChristophe Leroy /* concat physical page address(r11) and page offset(r10) */ 4464b914286SChristophe Leroy rlwimi r11, r10, 0, 32 - PAGE_SHIFT_8M, 31 4474b914286SChristophe Leroy b 201b 4484b914286SChristophe Leroy 4490a2ab51fSJoakim Tjernlund144: mfspr r10, SPRN_DSISR 4500a2ab51fSJoakim Tjernlund rlwinm r10, r10,0,7,5 /* Clear store bit for buggy dcbst insn */ 4510a2ab51fSJoakim Tjernlund mtspr SPRN_DSISR, r10 4520a2ab51fSJoakim Tjernlund142: /* continue, it was a dcbx, dcbi instruction. */ 4530a2ab51fSJoakim Tjernlund mfctr r10 4540a2ab51fSJoakim Tjernlund mtdar r10 /* save ctr reg in DAR */ 4550a2ab51fSJoakim Tjernlund rlwinm r10, r11, 24, 24, 28 /* offset into jump table for reg RB */ 4560a2ab51fSJoakim Tjernlund addi r10, r10, 150f@l /* add start of table */ 4570a2ab51fSJoakim Tjernlund mtctr r10 /* load ctr with jump address */ 4580a2ab51fSJoakim Tjernlund xor r10, r10, r10 /* sum starts at zero */ 4590a2ab51fSJoakim Tjernlund bctr /* jump into table */ 4600a2ab51fSJoakim Tjernlund150: 4610a2ab51fSJoakim Tjernlund add r10, r10, r0 ;b 151f 4620a2ab51fSJoakim Tjernlund add r10, r10, r1 ;b 151f 4630a2ab51fSJoakim Tjernlund add r10, r10, r2 ;b 151f 4640a2ab51fSJoakim Tjernlund add r10, r10, r3 ;b 151f 4650a2ab51fSJoakim Tjernlund add r10, r10, r4 ;b 151f 4660a2ab51fSJoakim Tjernlund add r10, r10, r5 ;b 151f 4670a2ab51fSJoakim Tjernlund add r10, r10, r6 ;b 151f 4680a2ab51fSJoakim Tjernlund add r10, r10, r7 ;b 151f 4690a2ab51fSJoakim Tjernlund add r10, r10, r8 ;b 151f 4700a2ab51fSJoakim Tjernlund add r10, r10, r9 ;b 151f 4710a2ab51fSJoakim Tjernlund mtctr r11 ;b 154f /* r10 needs special handling */ 4720a2ab51fSJoakim Tjernlund mtctr r11 ;b 153f /* r11 needs special handling */ 4730a2ab51fSJoakim Tjernlund add r10, r10, r12 ;b 151f 4740a2ab51fSJoakim Tjernlund add r10, r10, r13 ;b 151f 4750a2ab51fSJoakim Tjernlund add r10, r10, r14 ;b 151f 4760a2ab51fSJoakim Tjernlund add r10, r10, r15 ;b 151f 4770a2ab51fSJoakim Tjernlund add r10, r10, r16 ;b 151f 4780a2ab51fSJoakim Tjernlund add r10, r10, r17 ;b 151f 4790a2ab51fSJoakim Tjernlund add r10, r10, r18 ;b 151f 4800a2ab51fSJoakim Tjernlund add r10, r10, r19 ;b 151f 4810a2ab51fSJoakim Tjernlund add r10, r10, r20 ;b 151f 4820a2ab51fSJoakim Tjernlund add r10, r10, r21 ;b 151f 4830a2ab51fSJoakim Tjernlund add r10, r10, r22 ;b 151f 4840a2ab51fSJoakim Tjernlund add r10, r10, r23 ;b 151f 4850a2ab51fSJoakim Tjernlund add r10, r10, r24 ;b 151f 4860a2ab51fSJoakim Tjernlund add r10, r10, r25 ;b 151f 4870a2ab51fSJoakim Tjernlund add r10, r10, r26 ;b 151f 4880a2ab51fSJoakim Tjernlund add r10, r10, r27 ;b 151f 4890a2ab51fSJoakim Tjernlund add r10, r10, r28 ;b 151f 4900a2ab51fSJoakim Tjernlund add r10, r10, r29 ;b 151f 4910a2ab51fSJoakim Tjernlund add r10, r10, r30 ;b 151f 4920a2ab51fSJoakim Tjernlund add r10, r10, r31 4930a2ab51fSJoakim Tjernlund151: 4945ae8fabcSChristophe Leroy rlwinm r11,r11,19,24,28 /* offset into jump table for reg RA */ 4955ae8fabcSChristophe Leroy cmpwi cr1, r11, 0 4965ae8fabcSChristophe Leroy beq cr1, 152f /* if reg RA is zero, don't add it */ 4970a2ab51fSJoakim Tjernlund addi r11, r11, 150b@l /* add start of table */ 4980a2ab51fSJoakim Tjernlund mtctr r11 /* load ctr with jump address */ 4990a2ab51fSJoakim Tjernlund rlwinm r11,r11,0,16,10 /* make sure we don't execute this more than once */ 5000a2ab51fSJoakim Tjernlund bctr /* jump into table */ 5010a2ab51fSJoakim Tjernlund152: 5020a2ab51fSJoakim Tjernlund mfdar r11 5030a2ab51fSJoakim Tjernlund mtctr r11 /* restore ctr reg from DAR */ 50499b22916SChristophe Leroy mfspr r11, SPRN_SPRG_THREAD 50599b22916SChristophe Leroy stw r10, DAR(r11) 50699b22916SChristophe Leroy mfspr r10, SPRN_DSISR 50799b22916SChristophe Leroy stw r10, DSISR(r11) 50874fabcadSChristophe Leroy mfspr r10,SPRN_M_TW 5090a2ab51fSJoakim Tjernlund b DARFixed /* Go back to normal TLB handling */ 5100a2ab51fSJoakim Tjernlund 5110a2ab51fSJoakim Tjernlund /* special handling for r10,r11 since these are modified already */ 51292625d49SLEROY Christophe153: mfspr r11, SPRN_SPRG_SCRATCH1 /* load r11 from SPRN_SPRG_SCRATCH1 */ 513111e32b2SLEROY Christophe add r10, r10, r11 /* add it */ 514111e32b2SLEROY Christophe mfctr r11 /* restore r11 */ 515111e32b2SLEROY Christophe b 151b 51692625d49SLEROY Christophe154: mfspr r11, SPRN_SPRG_SCRATCH0 /* load r10 from SPRN_SPRG_SCRATCH0 */ 517111e32b2SLEROY Christophe add r10, r10, r11 /* add it */ 5180a2ab51fSJoakim Tjernlund mfctr r11 /* restore r11 */ 5190a2ab51fSJoakim Tjernlund b 151b 5200a2ab51fSJoakim Tjernlund 52114cf11afSPaul Mackerras/* 52214cf11afSPaul Mackerras * This is where the main kernel code starts. 52314cf11afSPaul Mackerras */ 52414cf11afSPaul Mackerrasstart_here: 52514cf11afSPaul Mackerras /* ptr to current */ 52614cf11afSPaul Mackerras lis r2,init_task@h 52714cf11afSPaul Mackerras ori r2,r2,init_task@l 52814cf11afSPaul Mackerras 52914cf11afSPaul Mackerras /* ptr to phys current thread */ 53014cf11afSPaul Mackerras tophys(r4,r2) 53114cf11afSPaul Mackerras addi r4,r4,THREAD /* init task's THREAD */ 532ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_THREAD,r4 53314cf11afSPaul Mackerras 53414cf11afSPaul Mackerras /* stack */ 53514cf11afSPaul Mackerras lis r1,init_thread_union@ha 53614cf11afSPaul Mackerras addi r1,r1,init_thread_union@l 5373bbd2343SChristophe Leroy lis r0, STACK_END_MAGIC@h 5383bbd2343SChristophe Leroy ori r0, r0, STACK_END_MAGIC@l 5393bbd2343SChristophe Leroy stw r0, 0(r1) 54014cf11afSPaul Mackerras li r0,0 54190f1b431SNicholas Piggin stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1) 54214cf11afSPaul Mackerras 5438c8c10b9SChristophe Leroy lis r6, swapper_pg_dir@ha 5448c8c10b9SChristophe Leroy tophys(r6,r6) 5456a8f911bSChristophe Leroy mtspr SPRN_M_TWB, r6 5468c8c10b9SChristophe Leroy 54714cf11afSPaul Mackerras bl early_init /* We have to do this with MMU on */ 54814cf11afSPaul Mackerras 54914cf11afSPaul Mackerras/* 55014cf11afSPaul Mackerras * Decide what sort of machine this is and initialize the MMU. 55114cf11afSPaul Mackerras */ 5522edb16efSChristophe Leroy#ifdef CONFIG_KASAN 5532edb16efSChristophe Leroy bl kasan_early_init 5542edb16efSChristophe Leroy#endif 5556dece0ebSScott Wood li r3,0 5566dece0ebSScott Wood mr r4,r31 55714cf11afSPaul Mackerras bl machine_init 55814cf11afSPaul Mackerras bl MMU_init 55914cf11afSPaul Mackerras 56014cf11afSPaul Mackerras/* 56114cf11afSPaul Mackerras * Go back to running unmapped so we can load up new values 56214cf11afSPaul Mackerras * and change to using our exception vectors. 56314cf11afSPaul Mackerras * On the 8xx, all we have to do is invalidate the TLB to clear 56414cf11afSPaul Mackerras * the old 8M byte TLB mappings and load the page table base register. 56514cf11afSPaul Mackerras */ 56614cf11afSPaul Mackerras /* The right way to do this would be to track it down through 56714cf11afSPaul Mackerras * init's THREAD like the context switch code does, but this is 56814cf11afSPaul Mackerras * easier......until someone changes init's static structures. 56914cf11afSPaul Mackerras */ 57014cf11afSPaul Mackerras lis r4,2f@h 57114cf11afSPaul Mackerras ori r4,r4,2f@l 57214cf11afSPaul Mackerras tophys(r4,r4) 57314cf11afSPaul Mackerras li r3,MSR_KERNEL & ~(MSR_IR|MSR_DR) 57414cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 57514cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 57614cf11afSPaul Mackerras rfi 57714cf11afSPaul Mackerras/* Load up the kernel context */ 57814cf11afSPaul Mackerras2: 579136a9a0fSChristophe Leroy#ifdef CONFIG_PIN_TLB_IMMR 580136a9a0fSChristophe Leroy lis r0, MD_TWAM@h 581136a9a0fSChristophe Leroy oris r0, r0, 0x1f00 582136a9a0fSChristophe Leroy mtspr SPRN_MD_CTR, r0 583136a9a0fSChristophe Leroy LOAD_REG_IMMEDIATE(r0, VIRT_IMMR_BASE | MD_EVALID) 584136a9a0fSChristophe Leroy tlbie r0 585136a9a0fSChristophe Leroy mtspr SPRN_MD_EPN, r0 586136a9a0fSChristophe Leroy LOAD_REG_IMMEDIATE(r0, MD_SVALID | MD_PS512K | MD_GUARDED) 587136a9a0fSChristophe Leroy mtspr SPRN_MD_TWC, r0 588136a9a0fSChristophe Leroy mfspr r0, SPRN_IMMR 589136a9a0fSChristophe Leroy rlwinm r0, r0, 0, 0xfff80000 590136a9a0fSChristophe Leroy ori r0, r0, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | \ 591136a9a0fSChristophe Leroy _PAGE_NO_CACHE | _PAGE_PRESENT 592136a9a0fSChristophe Leroy mtspr SPRN_MD_RPN, r0 593136a9a0fSChristophe Leroy lis r0, (MD_TWAM | MD_RSV4I)@h 594136a9a0fSChristophe Leroy mtspr SPRN_MD_CTR, r0 595136a9a0fSChristophe Leroy#endif 596684c1664SChristophe Leroy#if !defined(CONFIG_PIN_TLB_DATA) && !defined(CONFIG_PIN_TLB_IMMR) 597684c1664SChristophe Leroy lis r0, MD_TWAM@h 598684c1664SChristophe Leroy mtspr SPRN_MD_CTR, r0 599684c1664SChristophe Leroy#endif 60014cf11afSPaul Mackerras tlbia /* Clear all TLB entries */ 60114cf11afSPaul Mackerras sync /* wait for tlbia/tlbie to finish */ 60214cf11afSPaul Mackerras 60314cf11afSPaul Mackerras /* set up the PTE pointers for the Abatron bdiGDB. 60414cf11afSPaul Mackerras */ 60514cf11afSPaul Mackerras lis r5, abatron_pteptrs@h 60614cf11afSPaul Mackerras ori r5, r5, abatron_pteptrs@l 607e4ccb1daSChristophe Leroy stw r5, 0xf0(0) /* Must match your Abatron config file */ 60814cf11afSPaul Mackerras tophys(r5,r5) 609fb0bdec5SChristophe Leroy lis r6, swapper_pg_dir@h 610fb0bdec5SChristophe Leroy ori r6, r6, swapper_pg_dir@l 61114cf11afSPaul Mackerras stw r6, 0(r5) 61214cf11afSPaul Mackerras 61314cf11afSPaul Mackerras/* Now turn on the MMU for real! */ 61414cf11afSPaul Mackerras li r4,MSR_KERNEL 61514cf11afSPaul Mackerras lis r3,start_kernel@h 61614cf11afSPaul Mackerras ori r3,r3,start_kernel@l 61714cf11afSPaul Mackerras mtspr SPRN_SRR0,r3 61814cf11afSPaul Mackerras mtspr SPRN_SRR1,r4 61914cf11afSPaul Mackerras rfi /* enable MMU and jump to start_kernel */ 62014cf11afSPaul Mackerras 62114cf11afSPaul Mackerras/* Set up the initial MMU state so we can do the first level of 62214cf11afSPaul Mackerras * kernel initialization. This maps the first 8 MBytes of memory 1:1 62314cf11afSPaul Mackerras * virtual to physical. Also, set the cache mode since that is defined 62414cf11afSPaul Mackerras * by TLB entries and perform any additional mapping (like of the IMMR). 62514cf11afSPaul Mackerras * If configured to pin some TLBs, we pin the first 8 Mbytes of kernel, 626f86ef74eSChristophe Leroy * 24 Mbytes of data, and the 512k IMMR space. Anything not covered by 62714cf11afSPaul Mackerras * these mappings is mapped by page tables. 62814cf11afSPaul Mackerras */ 6292da37761SChristophe LeroySYM_FUNC_START_LOCAL(initial_mmu) 6306264dbb9SChristophe Leroy li r8, 0 6316264dbb9SChristophe Leroy mtspr SPRN_MI_CTR, r8 /* remove PINNED ITLB entries */ 632d3efcd38SChristophe Leroy lis r10, MD_TWAM@h 6336264dbb9SChristophe Leroy mtspr SPRN_MD_CTR, r10 /* remove PINNED DTLB entries */ 6346264dbb9SChristophe Leroy 63514cf11afSPaul Mackerras tlbia /* Invalidate all TLB entries */ 63614cf11afSPaul Mackerras 6375b2753fcSLEROY Christophe lis r8, MI_APG_INIT@h /* Set protection modes */ 6385b2753fcSLEROY Christophe ori r8, r8, MI_APG_INIT@l 63914cf11afSPaul Mackerras mtspr SPRN_MI_AP, r8 6405b2753fcSLEROY Christophe lis r8, MD_APG_INIT@h 6415b2753fcSLEROY Christophe ori r8, r8, MD_APG_INIT@l 64214cf11afSPaul Mackerras mtspr SPRN_MD_AP, r8 64314cf11afSPaul Mackerras 644684c1664SChristophe Leroy /* Map the lower RAM (up to 32 Mbytes) into the ITLB and DTLB */ 645e4470bd6SChristophe Leroy lis r8, MI_RSV4I@h 646e4470bd6SChristophe Leroy ori r8, r8, 0x1c00 647684c1664SChristophe Leroy oris r12, r10, MD_RSV4I@h 648684c1664SChristophe Leroy ori r12, r12, 0x1c00 649e4470bd6SChristophe Leroy li r9, 4 /* up to 4 pages of 8M */ 650e4470bd6SChristophe Leroy mtctr r9 651e4470bd6SChristophe Leroy lis r9, KERNELBASE@h /* Create vaddr for TLB */ 65233fe43cfSChristophe Leroy li r10, MI_PS8MEG | _PMD_ACCESSED | MI_SVALID 653e4470bd6SChristophe Leroy li r11, MI_BOOTINIT /* Create RPN for address 0 */ 654e4470bd6SChristophe Leroy1: 655e4470bd6SChristophe Leroy mtspr SPRN_MI_CTR, r8 /* Set instruction MMU control */ 656e4470bd6SChristophe Leroy addi r8, r8, 0x100 657e4470bd6SChristophe Leroy ori r0, r9, MI_EVALID /* Mark it valid */ 658e4470bd6SChristophe Leroy mtspr SPRN_MI_EPN, r0 659e4470bd6SChristophe Leroy mtspr SPRN_MI_TWC, r10 660e4470bd6SChristophe Leroy mtspr SPRN_MI_RPN, r11 /* Store TLB entry */ 661684c1664SChristophe Leroy mtspr SPRN_MD_CTR, r12 662684c1664SChristophe Leroy addi r12, r12, 0x100 663684c1664SChristophe Leroy mtspr SPRN_MD_EPN, r0 664684c1664SChristophe Leroy mtspr SPRN_MD_TWC, r10 665684c1664SChristophe Leroy mtspr SPRN_MD_RPN, r11 666e4470bd6SChristophe Leroy addis r9, r9, 0x80 667e4470bd6SChristophe Leroy addis r11, r11, 0x80 668e4470bd6SChristophe Leroy 669684c1664SChristophe Leroy bdnz 1b 670e4470bd6SChristophe Leroy 67114cf11afSPaul Mackerras /* Since the cache is enabled according to the information we 67214cf11afSPaul Mackerras * just loaded into the TLB, invalidate and enable the caches here. 67314cf11afSPaul Mackerras * We should probably check/set other modes....later. 67414cf11afSPaul Mackerras */ 67514cf11afSPaul Mackerras lis r8, IDC_INVALL@h 67614cf11afSPaul Mackerras mtspr SPRN_IC_CST, r8 67714cf11afSPaul Mackerras mtspr SPRN_DC_CST, r8 67814cf11afSPaul Mackerras lis r8, IDC_ENABLE@h 67914cf11afSPaul Mackerras mtspr SPRN_IC_CST, r8 68014cf11afSPaul Mackerras mtspr SPRN_DC_CST, r8 68175b82472SChristophe Leroy /* Disable debug mode entry on breakpoints */ 6824ad8622dSChristophe Leroy mfspr r8, SPRN_DER 683cd99ddbeSChristophe Leroy#ifdef CONFIG_PERF_EVENTS 68475b82472SChristophe Leroy rlwinm r8, r8, 0, ~0xc 68575b82472SChristophe Leroy#else 6864ad8622dSChristophe Leroy rlwinm r8, r8, 0, ~0x8 68775b82472SChristophe Leroy#endif 6884ad8622dSChristophe Leroy mtspr SPRN_DER, r8 68914cf11afSPaul Mackerras blr 6902da37761SChristophe LeroySYM_FUNC_END(initial_mmu) 69114cf11afSPaul Mackerras 692f76c8f6dSChristophe Leroy_GLOBAL(mmu_pin_tlb) 693f76c8f6dSChristophe Leroy lis r9, (1f - PAGE_OFFSET)@h 694f76c8f6dSChristophe Leroy ori r9, r9, (1f - PAGE_OFFSET)@l 695f76c8f6dSChristophe Leroy mfmsr r10 696f76c8f6dSChristophe Leroy mflr r11 697f76c8f6dSChristophe Leroy li r12, MSR_KERNEL & ~(MSR_IR | MSR_DR | MSR_RI) 698f76c8f6dSChristophe Leroy rlwinm r0, r10, 0, ~MSR_RI 699f76c8f6dSChristophe Leroy rlwinm r0, r0, 0, ~MSR_EE 700f76c8f6dSChristophe Leroy mtmsr r0 701f76c8f6dSChristophe Leroy isync 702f76c8f6dSChristophe Leroy .align 4 703f76c8f6dSChristophe Leroy mtspr SPRN_SRR0, r9 704f76c8f6dSChristophe Leroy mtspr SPRN_SRR1, r12 705f76c8f6dSChristophe Leroy rfi 706f76c8f6dSChristophe Leroy1: 707f76c8f6dSChristophe Leroy li r5, 0 708f76c8f6dSChristophe Leroy lis r6, MD_TWAM@h 709f76c8f6dSChristophe Leroy mtspr SPRN_MI_CTR, r5 710f76c8f6dSChristophe Leroy mtspr SPRN_MD_CTR, r6 711f76c8f6dSChristophe Leroy tlbia 712f76c8f6dSChristophe Leroy 713f76c8f6dSChristophe Leroy LOAD_REG_IMMEDIATE(r5, 28 << 8) 714f76c8f6dSChristophe Leroy LOAD_REG_IMMEDIATE(r6, PAGE_OFFSET) 71533fe43cfSChristophe Leroy LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG | _PMD_ACCESSED) 716f76c8f6dSChristophe Leroy LOAD_REG_IMMEDIATE(r8, 0xf0 | _PAGE_RO | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT) 717f76c8f6dSChristophe Leroy LOAD_REG_ADDR(r9, _sinittext) 718f76c8f6dSChristophe Leroy li r0, 4 719f76c8f6dSChristophe Leroy mtctr r0 720f76c8f6dSChristophe Leroy 721f76c8f6dSChristophe Leroy2: ori r0, r6, MI_EVALID 722f76c8f6dSChristophe Leroy mtspr SPRN_MI_CTR, r5 723f76c8f6dSChristophe Leroy mtspr SPRN_MI_EPN, r0 724f76c8f6dSChristophe Leroy mtspr SPRN_MI_TWC, r7 725f76c8f6dSChristophe Leroy mtspr SPRN_MI_RPN, r8 726f76c8f6dSChristophe Leroy addi r5, r5, 0x100 727f76c8f6dSChristophe Leroy addis r6, r6, SZ_8M@h 728f76c8f6dSChristophe Leroy addis r8, r8, SZ_8M@h 729f76c8f6dSChristophe Leroy cmplw r6, r9 730f76c8f6dSChristophe Leroy bdnzt lt, 2b 731f76c8f6dSChristophe Leroy lis r0, MI_RSV4I@h 732f76c8f6dSChristophe Leroy mtspr SPRN_MI_CTR, r0 733bccc5898SChristophe Leroy 734f76c8f6dSChristophe Leroy LOAD_REG_IMMEDIATE(r5, 28 << 8 | MD_TWAM) 735f76c8f6dSChristophe Leroy#ifdef CONFIG_PIN_TLB_DATA 736f76c8f6dSChristophe Leroy LOAD_REG_IMMEDIATE(r6, PAGE_OFFSET) 73733fe43cfSChristophe Leroy LOAD_REG_IMMEDIATE(r7, MI_SVALID | MI_PS8MEG | _PMD_ACCESSED) 7381e35eba4SChristophe Leroy li r8, 0 739f76c8f6dSChristophe Leroy#ifdef CONFIG_PIN_TLB_IMMR 740f76c8f6dSChristophe Leroy li r0, 3 741f76c8f6dSChristophe Leroy#else 742f76c8f6dSChristophe Leroy li r0, 4 743f76c8f6dSChristophe Leroy#endif 744f76c8f6dSChristophe Leroy mtctr r0 745f76c8f6dSChristophe Leroy cmpwi r4, 0 746f76c8f6dSChristophe Leroy beq 4f 747f76c8f6dSChristophe Leroy LOAD_REG_ADDR(r9, _sinittext) 748f76c8f6dSChristophe Leroy 749f76c8f6dSChristophe Leroy2: ori r0, r6, MD_EVALID 7501e35eba4SChristophe Leroy ori r12, r8, 0xf0 | _PAGE_RO | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT 751f76c8f6dSChristophe Leroy mtspr SPRN_MD_CTR, r5 752f76c8f6dSChristophe Leroy mtspr SPRN_MD_EPN, r0 753f76c8f6dSChristophe Leroy mtspr SPRN_MD_TWC, r7 7541e35eba4SChristophe Leroy mtspr SPRN_MD_RPN, r12 755f76c8f6dSChristophe Leroy addi r5, r5, 0x100 756f76c8f6dSChristophe Leroy addis r6, r6, SZ_8M@h 757f76c8f6dSChristophe Leroy addis r8, r8, SZ_8M@h 758f76c8f6dSChristophe Leroy cmplw r6, r9 759f76c8f6dSChristophe Leroy bdnzt lt, 2b 7601e35eba4SChristophe Leroy4: 761f76c8f6dSChristophe Leroy2: ori r0, r6, MD_EVALID 7621e35eba4SChristophe Leroy ori r12, r8, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | _PAGE_PRESENT 763f76c8f6dSChristophe Leroy mtspr SPRN_MD_CTR, r5 764f76c8f6dSChristophe Leroy mtspr SPRN_MD_EPN, r0 765f76c8f6dSChristophe Leroy mtspr SPRN_MD_TWC, r7 7661e35eba4SChristophe Leroy mtspr SPRN_MD_RPN, r12 767f76c8f6dSChristophe Leroy addi r5, r5, 0x100 768f76c8f6dSChristophe Leroy addis r6, r6, SZ_8M@h 769f76c8f6dSChristophe Leroy addis r8, r8, SZ_8M@h 770f76c8f6dSChristophe Leroy cmplw r6, r3 771f76c8f6dSChristophe Leroy bdnzt lt, 2b 772f76c8f6dSChristophe Leroy#endif 773f76c8f6dSChristophe Leroy#ifdef CONFIG_PIN_TLB_IMMR 774f76c8f6dSChristophe Leroy LOAD_REG_IMMEDIATE(r0, VIRT_IMMR_BASE | MD_EVALID) 77533fe43cfSChristophe Leroy LOAD_REG_IMMEDIATE(r7, MD_SVALID | MD_PS512K | MD_GUARDED | _PMD_ACCESSED) 776f76c8f6dSChristophe Leroy mfspr r8, SPRN_IMMR 777f76c8f6dSChristophe Leroy rlwinm r8, r8, 0, 0xfff80000 778f76c8f6dSChristophe Leroy ori r8, r8, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | \ 779f76c8f6dSChristophe Leroy _PAGE_NO_CACHE | _PAGE_PRESENT 780f76c8f6dSChristophe Leroy mtspr SPRN_MD_CTR, r5 781f76c8f6dSChristophe Leroy mtspr SPRN_MD_EPN, r0 782f76c8f6dSChristophe Leroy mtspr SPRN_MD_TWC, r7 783f76c8f6dSChristophe Leroy mtspr SPRN_MD_RPN, r8 784f76c8f6dSChristophe Leroy#endif 785f76c8f6dSChristophe Leroy#if defined(CONFIG_PIN_TLB_IMMR) || defined(CONFIG_PIN_TLB_DATA) 786f76c8f6dSChristophe Leroy lis r0, (MD_RSV4I | MD_TWAM)@h 7871e35eba4SChristophe Leroy mtspr SPRN_MD_CTR, r0 788f76c8f6dSChristophe Leroy#endif 789f76c8f6dSChristophe Leroy mtspr SPRN_SRR1, r10 790f76c8f6dSChristophe Leroy mtspr SPRN_SRR0, r11 791f76c8f6dSChristophe Leroy rfi 792