/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Low level TLB miss handlers for Book3E3*4* Copyright (C) 2008-20095* Ben. Herrenschmidt ([email protected]), IBM Corp.6*/78#include <linux/pgtable.h>9#include <asm/processor.h>10#include <asm/reg.h>11#include <asm/page.h>12#include <asm/mmu.h>13#include <asm/ppc_asm.h>14#include <asm/asm-offsets.h>15#include <asm/cputable.h>16#include <asm/exception-64e.h>17#include <asm/ppc-opcode.h>18#include <asm/kvm_asm.h>19#include <asm/kvm_booke_hv_asm.h>20#include <asm/feature-fixups.h>2122#define VPTE_PMD_SHIFT (PTE_INDEX_SIZE)23#define VPTE_PUD_SHIFT (VPTE_PMD_SHIFT + PMD_INDEX_SIZE)24#define VPTE_PGD_SHIFT (VPTE_PUD_SHIFT + PUD_INDEX_SIZE)25#define VPTE_INDEX_SIZE (VPTE_PGD_SHIFT + PGD_INDEX_SIZE)2627/**********************************************************************28* *29* TLB miss handling for Book3E with a bolted linear mapping *30* No virtual page table, no nested TLB misses *31* *32**********************************************************************/3334/*35* Note that, unlike non-bolted handlers, TLB_EXFRAME is not36* modified by the TLB miss handlers themselves, since the TLB miss37* handler code will not itself cause a recursive TLB miss.38*39* TLB_EXFRAME will be modified when crit/mc/debug exceptions are40* entered/exited.41*/42.macro tlb_prolog_bolted intnum addr43mtspr SPRN_SPRG_GEN_SCRATCH,r1244mfspr r12,SPRN_SPRG_TLB_EXFRAME45std r13,EX_TLB_R13(r12)46std r10,EX_TLB_R10(r12)47mfspr r13,SPRN_SPRG_PACA4849mfcr r1050std r11,EX_TLB_R11(r12)51#ifdef CONFIG_KVM_BOOKE_HV52BEGIN_FTR_SECTION53mfspr r11, SPRN_SRR154END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)55#endif56DO_KVM \intnum, SPRN_SRR157std r16,EX_TLB_R16(r12)58mfspr r16,\addr /* get faulting address */59std r14,EX_TLB_R14(r12)60ld r14,PACAPGD(r13)61std r15,EX_TLB_R15(r12)62std r10,EX_TLB_CR(r12)63START_BTB_FLUSH_SECTION64mfspr r11, SPRN_SRR165andi. r10,r11,MSR_PR66beq 1f67BTB_FLUSH(r10)681:69END_BTB_FLUSH_SECTION70std r7,EX_TLB_R7(r12)71.endm7273.macro tlb_epilog_bolted74ld r14,EX_TLB_CR(r12)75ld r7,EX_TLB_R7(r12)76ld r10,EX_TLB_R10(r12)77ld r11,EX_TLB_R11(r12)78ld r13,EX_TLB_R13(r12)79mtcr r1480ld r14,EX_TLB_R14(r12)81ld r15,EX_TLB_R15(r12)82ld r16,EX_TLB_R16(r12)83mfspr r12,SPRN_SPRG_GEN_SCRATCH84.endm8586/* Data TLB miss */87START_EXCEPTION(data_tlb_miss_bolted)88tlb_prolog_bolted BOOKE_INTERRUPT_DTLB_MISS SPRN_DEAR8990/* We need _PAGE_PRESENT and _PAGE_ACCESSED set */9192/* We do the user/kernel test for the PID here along with the RW test93*/94/* We pre-test some combination of permissions to avoid double95* faults:96*97* We move the ESR:ST bit into the position of _PAGE_BAP_SW in the PTE98* ESR_ST is 0x0080000099* _PAGE_BAP_SW is 0x00000010100* So the shift is >> 19. This tests for supervisor writeability.101* If the page happens to be supervisor writeable and not user102* writeable, we will take a new fault later, but that should be103* a rare enough case.104*105* We also move ESR_ST in _PAGE_DIRTY position106* _PAGE_DIRTY is 0x00001000 so the shift is >> 11107*108* MAS1 is preset for all we need except for TID that needs to109* be cleared for kernel translations110*/111112mfspr r11,SPRN_ESR113114srdi r15,r16,60 /* get region */115rldicl. r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4116bne- dtlb_miss_fault_bolted /* Bail if fault addr is invalid */117118rlwinm r10,r11,32-19,27,27119rlwimi r10,r11,32-16,19,19120cmpwi r15,0 /* user vs kernel check */121ori r10,r10,_PAGE_PRESENT122oris r11,r10,_PAGE_ACCESSED@h123124bne tlb_miss_kernel_bolted125126tlb_miss_user_bolted:127#ifdef CONFIG_PPC_KUAP128mfspr r10,SPRN_MAS1129rlwinm. r10,r10,0,0x3fff0000130beq- tlb_miss_fault_bolted /* KUAP fault */131#endif132133tlb_miss_common_bolted:134/*135* This is the guts of the TLB miss handler for bolted-linear.136* We are entered with:137*138* r16 = faulting address139* r15 = crap (free to use)140* r14 = page table base141* r13 = PACA142* r11 = PTE permission mask143* r10 = crap (free to use)144*/145rldicl r15,r16,64-PGDIR_SHIFT+3,64-PGD_INDEX_SIZE-3146cmpldi cr0,r14,0147clrrdi r15,r15,3148beq tlb_miss_fault_bolted /* No PGDIR, bail */149150ldx r14,r14,r15 /* grab pgd entry */151152rldicl r15,r16,64-PUD_SHIFT+3,64-PUD_INDEX_SIZE-3153clrrdi r15,r15,3154cmpdi cr0,r14,0155bge tlb_miss_fault_bolted /* Bad pgd entry or hugepage; bail */156ldx r14,r14,r15 /* grab pud entry */157158rldicl r15,r16,64-PMD_SHIFT+3,64-PMD_INDEX_SIZE-3159clrrdi r15,r15,3160cmpdi cr0,r14,0161bge tlb_miss_fault_bolted162ldx r14,r14,r15 /* Grab pmd entry */163164rldicl r15,r16,64-PAGE_SHIFT+3,64-PTE_INDEX_SIZE-3165clrrdi r15,r15,3166cmpdi cr0,r14,0167bge tlb_miss_fault_bolted168ldx r14,r14,r15 /* Grab PTE, normal (!huge) page */169170/* Check if required permissions are met */171andc. r15,r11,r14172rldicr r15,r14,64-(PTE_RPN_SHIFT-PAGE_SHIFT),63-PAGE_SHIFT173bne- tlb_miss_fault_bolted174175/* Now we build the MAS:176*177* MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG178* MAS 1 : Almost fully setup179* - PID already updated by caller if necessary180* - TSIZE need change if !base page size, not181* yet implemented for now182* MAS 2 : Defaults not useful, need to be redone183* MAS 3+7 : Needs to be done184*/185clrrdi r11,r16,12 /* Clear low crap in EA */186clrldi r15,r15,12 /* Clear crap at the top */187rlwimi r11,r14,32-19,27,31 /* Insert WIMGE */188rlwimi r15,r14,32-8,22,25 /* Move in U bits */189mtspr SPRN_MAS2,r11190andi. r11,r14,_PAGE_DIRTY191rlwimi r15,r14,32-2,26,31 /* Move in BAP bits */192193/* Mask out SW and UW if !DIRTY (XXX optimize this !) */194bne 1f195li r11,MAS3_SW|MAS3_UW196andc r15,r15,r111971:198mtspr SPRN_MAS7_MAS3,r15199tlbwe200201tlb_miss_done_bolted:202tlb_epilog_bolted203rfi204205itlb_miss_kernel_bolted:206li r11,_PAGE_PRESENT|_PAGE_BAP_SX /* Base perm */207oris r11,r11,_PAGE_ACCESSED@h208tlb_miss_kernel_bolted:209mfspr r10,SPRN_MAS1210ld r14,PACA_KERNELPGD(r13)211srdi r15,r16,44 /* get kernel region */212andi. r15,r15,1 /* Check for vmalloc region */213rlwinm r10,r10,0,16,1 /* Clear TID */214mtspr SPRN_MAS1,r10215bne+ tlb_miss_common_bolted216217tlb_miss_fault_bolted:218/* We need to check if it was an instruction miss */219andi. r10,r11,_PAGE_BAP_UX|_PAGE_BAP_SX220bne itlb_miss_fault_bolted221dtlb_miss_fault_bolted:222tlb_epilog_bolted223b exc_data_storage_book3e224itlb_miss_fault_bolted:225tlb_epilog_bolted226b exc_instruction_storage_book3e227228/* Instruction TLB miss */229START_EXCEPTION(instruction_tlb_miss_bolted)230tlb_prolog_bolted BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR0231232rldicl. r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4233srdi r15,r16,60 /* get region */234bne- itlb_miss_fault_bolted235236li r11,_PAGE_PRESENT|_PAGE_BAP_UX /* Base perm */237238/* We do the user/kernel test for the PID here along with the RW test239*/240241cmpldi cr0,r15,0 /* Check for user region */242oris r11,r11,_PAGE_ACCESSED@h243beq tlb_miss_user_bolted244b itlb_miss_kernel_bolted245246/*247* TLB miss handling for e6500 and derivatives, using hardware tablewalk.248*249* Linear mapping is bolted: no virtual page table or nested TLB misses250* Indirect entries in TLB1, hardware loads resulting direct entries251* into TLB0252* No HES or NV hint on TLB1, so we need to do software round-robin253* No tlbsrx. so we need a spinlock, and we have to deal254* with MAS-damage caused by tlbsx255* 4K pages only256*/257258START_EXCEPTION(instruction_tlb_miss_e6500)259tlb_prolog_bolted BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR0260261ld r11,PACA_TCD_PTR(r13)262srdi. r15,r16,60 /* get region */263ori r16,r16,1264265bne tlb_miss_kernel_e6500 /* user/kernel test */266267b tlb_miss_common_e6500268269START_EXCEPTION(data_tlb_miss_e6500)270tlb_prolog_bolted BOOKE_INTERRUPT_DTLB_MISS SPRN_DEAR271272ld r11,PACA_TCD_PTR(r13)273srdi. r15,r16,60 /* get region */274rldicr r16,r16,0,62275276bne tlb_miss_kernel_e6500 /* user vs kernel check */277278/*279* This is the guts of the TLB miss handler for e6500 and derivatives.280* We are entered with:281*282* r16 = page of faulting address (low bit 0 if data, 1 if instruction)283* r15 = crap (free to use)284* r14 = page table base285* r13 = PACA286* r11 = tlb_per_core ptr287* r10 = crap (free to use)288* r7 = esel_next289*/290tlb_miss_common_e6500:291crmove cr2*4+2,cr0*4+2 /* cr2.eq != 0 if kernel address */292293BEGIN_FTR_SECTION /* CPU_FTR_SMT */294/*295* Search if we already have an indirect entry for that virtual296* address, and if we do, bail out.297*298* MAS6:IND should be already set based on MAS4299*/300lhz r10,PACAPACAINDEX(r13)301addi r10,r10,1302crclr cr1*4+eq /* set cr1.eq = 0 for non-recursive */3031: lbarx r15,0,r11304cmpdi r15,0305bne 2f306stbcx. r10,0,r11307bne 1b3083:309.subsection 13102: cmpd cr1,r15,r10 /* recursive lock due to mcheck/crit/etc? */311beq cr1,3b /* unlock will happen if cr1.eq = 0 */31210: lbz r15,0(r11)313cmpdi r15,0314bne 10b315b 1b316.previous317END_FTR_SECTION_IFSET(CPU_FTR_SMT)318319lbz r7,TCD_ESEL_NEXT(r11)320321BEGIN_FTR_SECTION /* CPU_FTR_SMT */322/*323* Erratum A-008139 says that we can't use tlbwe to change324* an indirect entry in any way (including replacing or325* invalidating) if the other thread could be in the process326* of a lookup. The workaround is to invalidate the entry327* with tlbilx before overwriting.328*/329330rlwinm r10,r7,16,0xff0000331oris r10,r10,MAS0_TLBSEL(1)@h332mtspr SPRN_MAS0,r10333isync334tlbre335mfspr r15,SPRN_MAS1336andis. r15,r15,MAS1_VALID@h337beq 5f338339BEGIN_FTR_SECTION_NESTED(532)340mfspr r10,SPRN_MAS8341rlwinm r10,r10,0,0x80000fff /* tgs,tlpid -> sgs,slpid */342mtspr SPRN_MAS5,r10343END_FTR_SECTION_NESTED(CPU_FTR_EMB_HV,CPU_FTR_EMB_HV,532)344345mfspr r10,SPRN_MAS1346rlwinm r15,r10,0,0x3fff0000 /* tid -> spid */347rlwimi r15,r10,20,0x00000003 /* ind,ts -> sind,sas */348mfspr r10,SPRN_MAS6349mtspr SPRN_MAS6,r15350351mfspr r15,SPRN_MAS2352isync353PPC_TLBILX_VA(0,R15)354isync355356mtspr SPRN_MAS6,r103573585:359BEGIN_FTR_SECTION_NESTED(532)360li r10,0361mtspr SPRN_MAS8,r10362mtspr SPRN_MAS5,r10363END_FTR_SECTION_NESTED(CPU_FTR_EMB_HV,CPU_FTR_EMB_HV,532)364365tlbsx 0,r16366mfspr r10,SPRN_MAS1367andis. r15,r10,MAS1_VALID@h368bne tlb_miss_done_e6500369FTR_SECTION_ELSE370mfspr r10,SPRN_MAS1371ALT_FTR_SECTION_END_IFSET(CPU_FTR_SMT)372373oris r10,r10,MAS1_VALID@h374beq cr2,4f375rlwinm r10,r10,0,16,1 /* Clear TID */3764: mtspr SPRN_MAS1,r10377378/* Now, we need to walk the page tables. First check if we are in379* range.380*/381rldicl. r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4382bne- tlb_miss_fault_e6500383384rldicl r15,r16,64-PGDIR_SHIFT+3,64-PGD_INDEX_SIZE-3385cmpldi cr0,r14,0386clrrdi r15,r15,3387beq- tlb_miss_fault_e6500 /* No PGDIR, bail */388ldx r14,r14,r15 /* grab pgd entry */389390rldicl r15,r16,64-PUD_SHIFT+3,64-PUD_INDEX_SIZE-3391clrrdi r15,r15,3392cmpdi cr0,r14,0393bge tlb_miss_huge_e6500 /* Bad pgd entry or hugepage; bail */394ldx r14,r14,r15 /* grab pud entry */395396rldicl r15,r16,64-PMD_SHIFT+3,64-PMD_INDEX_SIZE-3397clrrdi r15,r15,3398cmpdi cr0,r14,0399bge tlb_miss_huge_e6500400ldx r14,r14,r15 /* Grab pmd entry */401402mfspr r10,SPRN_MAS0403cmpdi cr0,r14,0404bge tlb_miss_huge_e6500405406/* Now we build the MAS for a 2M indirect page:407*408* MAS 0 : ESEL needs to be filled by software round-robin409* MAS 1 : Fully set up410* - PID already updated by caller if necessary411* - TSIZE for now is base ind page size always412* - TID already cleared if necessary413* MAS 2 : Default not 2M-aligned, need to be redone414* MAS 3+7 : Needs to be done415*/416417ori r14,r14,(BOOK3E_PAGESZ_4K << MAS3_SPSIZE_SHIFT)418mtspr SPRN_MAS7_MAS3,r14419420clrrdi r15,r16,21 /* make EA 2M-aligned */421mtspr SPRN_MAS2,r15422423tlb_miss_huge_done_e6500:424lbz r16,TCD_ESEL_MAX(r11)425lbz r14,TCD_ESEL_FIRST(r11)426rlwimi r10,r7,16,0x00ff0000 /* insert esel_next into MAS0 */427addi r7,r7,1 /* increment esel_next */428mtspr SPRN_MAS0,r10429cmpw r7,r16430iseleq r7,r14,r7 /* if next == last use first */431stb r7,TCD_ESEL_NEXT(r11)432433tlbwe434435tlb_miss_done_e6500:436.macro tlb_unlock_e6500437BEGIN_FTR_SECTION438beq cr1,1f /* no unlock if lock was recursively grabbed */439li r15,0440isync441stb r15,0(r11)4421:443END_FTR_SECTION_IFSET(CPU_FTR_SMT)444.endm445446tlb_unlock_e6500447tlb_epilog_bolted448rfi449450tlb_miss_huge_e6500:451beq tlb_miss_fault_e6500452rlwinm r15,r14,32-_PAGE_PSIZE_SHIFT,0x1e453454/*455* Now we build the MAS for a huge page.456*457* MAS 0 : ESEL needs to be filled by software round-robin458* - can be handled by indirect code459* MAS 1 : Need to clear IND and set TSIZE460* MAS 2,3+7: Needs to be redone similar to non-tablewalk handler461*/462463mfspr r10,SPRN_MAS1464rlwinm r10,r10,0,~MAS1_IND465rlwimi r10,r15,MAS1_TSIZE_SHIFT,MAS1_TSIZE_MASK466mtspr SPRN_MAS1,r10467468li r10,-0x400469sld r15,r10,r15 /* Generate mask based on size */470and r10,r16,r15471rldicr r15,r14,64-(PTE_RPN_SHIFT-PAGE_SHIFT),63-PAGE_SHIFT472rlwimi r10,r14,32-19,27,31 /* Insert WIMGE */473clrldi r15,r15,PAGE_SHIFT /* Clear crap at the top */474rlwimi r15,r14,32-8,22,25 /* Move in U bits */475mtspr SPRN_MAS2,r10476andi. r10,r14,_PAGE_DIRTY477rlwimi r15,r14,32-2,26,31 /* Move in BAP bits */478479/* Mask out SW and UW if !DIRTY (XXX optimize this !) */480bne 1f481li r10,MAS3_SW|MAS3_UW482andc r15,r15,r104831:484mtspr SPRN_MAS7_MAS3,r15485486mfspr r10,SPRN_MAS0487b tlb_miss_huge_done_e6500488489tlb_miss_kernel_e6500:490ld r14,PACA_KERNELPGD(r13)491srdi r15,r16,44 /* get kernel region */492xoris r15,r15,0xc /* Check for vmalloc region */493cmplwi cr1,r15,1494beq+ cr1,tlb_miss_common_e6500495496tlb_miss_fault_e6500:497tlb_unlock_e6500498/* We need to check if it was an instruction miss */499andi. r16,r16,1500bne itlb_miss_fault_e6500501dtlb_miss_fault_e6500:502tlb_epilog_bolted503b exc_data_storage_book3e504itlb_miss_fault_e6500:505tlb_epilog_bolted506b exc_instruction_storage_book3e507508/*509* This is the guts of the second-level TLB miss handler for direct510* misses. We are entered with:511*512* r16 = virtual page table faulting address513* r15 = region (top 4 bits of address)514* r14 = crap (free to use)515* r13 = PACA516* r12 = TLB exception frame in PACA517* r11 = crap (free to use)518* r10 = crap (free to use)519*520* Note that this should only ever be called as a second level handler521* with the current scheme when using SW load.522* That means we can always get the original fault DEAR at523* EX_TLB_DEAR-EX_TLB_SIZE(r12)524*525* It can be re-entered by the linear mapping miss handler. However, to526* avoid too much complication, it will restart the whole fault at level527* 0 so we don't care too much about clobbers528*529* XXX That code was written back when we couldn't clobber r14. We can now,530* so we could probably optimize things a bit531*/532virt_page_table_tlb_miss:533/* Are we hitting a kernel page table ? */534srdi r15,r16,60535andi. r10,r15,0x8536537/* The cool thing now is that r10 contains 0 for user and 8 for kernel,538* and we happen to have the swapper_pg_dir at offset 8 from the user539* pgdir in the PACA :-).540*/541add r11,r10,r13542543/* If kernel, we need to clear MAS1 TID */544beq 1f545/* XXX replace the RMW cycles with immediate loads + writes */546mfspr r10,SPRN_MAS1547rlwinm r10,r10,0,16,1 /* Clear TID */548mtspr SPRN_MAS1,r10549#ifdef CONFIG_PPC_KUAP550b 2f5511:552mfspr r10,SPRN_MAS1553rlwinm. r10,r10,0,0x3fff0000554beq- virt_page_table_tlb_miss_fault /* KUAP fault */5552:556#else5571:558#endif559560/* Now, we need to walk the page tables. First check if we are in561* range.562*/563rldicl r10,r16,64-(VPTE_INDEX_SIZE+3),VPTE_INDEX_SIZE+3+4564cmpldi r10,0x80565bne- virt_page_table_tlb_miss_fault566567/* Get the PGD pointer */568ld r15,PACAPGD(r11)569cmpldi cr0,r15,0570beq- virt_page_table_tlb_miss_fault571572/* Get to PGD entry */573rldicl r11,r16,64-VPTE_PGD_SHIFT,64-PGD_INDEX_SIZE-3574clrrdi r10,r11,3575ldx r15,r10,r15576cmpdi cr0,r15,0577bge virt_page_table_tlb_miss_fault578579/* Get to PUD entry */580rldicl r11,r16,64-VPTE_PUD_SHIFT,64-PUD_INDEX_SIZE-3581clrrdi r10,r11,3582ldx r15,r10,r15583cmpdi cr0,r15,0584bge virt_page_table_tlb_miss_fault585586/* Get to PMD entry */587rldicl r11,r16,64-VPTE_PMD_SHIFT,64-PMD_INDEX_SIZE-3588clrrdi r10,r11,3589ldx r15,r10,r15590cmpdi cr0,r15,0591bge virt_page_table_tlb_miss_fault592593/* Ok, we're all right, we can now create a kernel translation for594* a 4K or 64K page from r16 -> r15.595*/596/* Now we build the MAS:597*598* MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG599* MAS 1 : Almost fully setup600* - PID already updated by caller if necessary601* - TSIZE for now is base page size always602* MAS 2 : Use defaults603* MAS 3+7 : Needs to be done604*605* So we only do MAS 2 and 3 for now...606*/607clrldi r11,r15,4 /* remove region ID from RPN */608ori r10,r11,1 /* Or-in SR */609610srdi r16,r10,32611mtspr SPRN_MAS3,r10612mtspr SPRN_MAS7,r16613614tlbwe615616/* Return to caller, normal case */617TLB_MISS_EPILOG_SUCCESS618rfi619620virt_page_table_tlb_miss_fault:621/* If we fault here, things are a little bit tricky. We need to call622* either data or instruction store fault, and we need to retrieve623* the original fault address and ESR (for data).624*625* The thing is, we know that in normal circumstances, this is626* always called as a second level tlb miss for SW load or as a first627* level TLB miss for HW load, so we should be able to peek at the628* relevant information in the first exception frame in the PACA.629*630* However, we do need to double check that, because we may just hit631* a stray kernel pointer or a userland attack trying to hit those632* areas. If that is the case, we do a data fault. (We can't get here633* from an instruction tlb miss anyway).634*635* Note also that when going to a fault, we must unwind the previous636* level as well. Since we are doing that, we don't need to clear or637* restore the TLB reservation neither.638*/639subf r10,r13,r12640cmpldi cr0,r10,PACA_EXTLB+EX_TLB_SIZE641bne- virt_page_table_tlb_miss_whacko_fault642643/* We dig the original DEAR and ESR from slot 0 */644ld r15,EX_TLB_DEAR+PACA_EXTLB(r13)645ld r16,EX_TLB_ESR+PACA_EXTLB(r13)646647/* We check for the "special" ESR value for instruction faults */648cmpdi cr0,r16,-1649beq 1f650mtspr SPRN_DEAR,r15651mtspr SPRN_ESR,r16652TLB_MISS_EPILOG_ERROR653b exc_data_storage_book3e6541: TLB_MISS_EPILOG_ERROR655b exc_instruction_storage_book3e656657virt_page_table_tlb_miss_whacko_fault:658/* The linear fault will restart everything so ESR and DEAR will659* not have been clobbered, let's just fault with what we have660*/661TLB_MISS_EPILOG_ERROR662b exc_data_storage_book3e663664/*665* This is the guts of "any" level TLB miss handler for kernel linear666* mapping misses. We are entered with:667*668*669* r16 = faulting address670* r15 = crap (free to use)671* r14 = ESR (data) or -1 (instruction)672* r13 = PACA673* r12 = TLB exception frame in PACA674* r11 = crap (free to use)675* r10 = crap (free to use)676*677* In addition we know that we will not re-enter, so in theory, we could678* use a simpler epilog not restoring SRR0/1 etc.. but we'll do that later.679*680* We also need to be careful about MAS registers here & TLB reservation,681* as we know we'll have clobbered them if we interrupt the main TLB miss682* handlers in which case we probably want to do a full restart at level683* 0 rather than saving / restoring the MAS.684*685* Note: If we care about performance of that core, we can easily shuffle686* a few things around687*/688tlb_load_linear:689/* For now, we assume the linear mapping is contiguous and stops at690* linear_map_top. We also assume the size is a multiple of 1G, thus691* we only use 1G pages for now. That might have to be changed in a692* final implementation, especially when dealing with hypervisors693*/694__LOAD_PACA_TOC(r11)695LOAD_REG_ADDR_ALTTOC(r11, r11, linear_map_top)696ld r10,0(r11)697tovirt(10,10)698cmpld cr0,r16,r10699bge tlb_load_linear_fault700701/* MAS1 need whole new setup. */702li r15,(BOOK3E_PAGESZ_1GB<<MAS1_TSIZE_SHIFT)703oris r15,r15,MAS1_VALID@h /* MAS1 needs V and TSIZE */704mtspr SPRN_MAS1,r15705706/* Already somebody there ? */707PPC_TLBSRX_DOT(0,R16)708beq tlb_load_linear_done709710/* Now we build the remaining MAS. MAS0 and 2 should be fine711* with their defaults, which leaves us with MAS 3 and 7. The712* mapping is linear, so we just take the address, clear the713* region bits, and or in the permission bits which are currently714* hard wired715*/716clrrdi r10,r16,30 /* 1G page index */717clrldi r10,r10,4 /* clear region bits */718ori r10,r10,MAS3_SR|MAS3_SW|MAS3_SX719720srdi r16,r10,32721mtspr SPRN_MAS3,r10722mtspr SPRN_MAS7,r16723724tlbwe725726tlb_load_linear_done:727/* We use the "error" epilog for success as we do want to728* restore to the initial faulting context, whatever it was.729* We do that because we can't resume a fault within a TLB730* miss handler, due to MAS and TLB reservation being clobbered.731*/732TLB_MISS_EPILOG_ERROR733rfi734735tlb_load_linear_fault:736/* We keep the DEAR and ESR around, this shouldn't have happened */737cmpdi cr0,r14,-1738beq 1f739TLB_MISS_EPILOG_ERROR_SPECIAL740b exc_data_storage_book3e7411: TLB_MISS_EPILOG_ERROR_SPECIAL742b exc_instruction_storage_book3e743744745