/*1* Low level TLB miss handlers for Book3E2*3* Copyright (C) 2008-20094* Ben. Herrenschmidt ([email protected]), IBM Corp.5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Public License8* as published by the Free Software Foundation; either version9* 2 of the License, or (at your option) any later version.10*/1112#include <asm/processor.h>13#include <asm/reg.h>14#include <asm/page.h>15#include <asm/mmu.h>16#include <asm/ppc_asm.h>17#include <asm/asm-offsets.h>18#include <asm/cputable.h>19#include <asm/pgtable.h>20#include <asm/exception-64e.h>21#include <asm/ppc-opcode.h>2223#ifdef CONFIG_PPC_64K_PAGES24#define VPTE_PMD_SHIFT (PTE_INDEX_SIZE+1)25#else26#define VPTE_PMD_SHIFT (PTE_INDEX_SIZE)27#endif28#define VPTE_PUD_SHIFT (VPTE_PMD_SHIFT + PMD_INDEX_SIZE)29#define VPTE_PGD_SHIFT (VPTE_PUD_SHIFT + PUD_INDEX_SIZE)30#define VPTE_INDEX_SIZE (VPTE_PGD_SHIFT + PGD_INDEX_SIZE)313233/**********************************************************************34* *35* TLB miss handling for Book3E with TLB reservation and HES support *36* *37**********************************************************************/383940/* Data TLB miss */41START_EXCEPTION(data_tlb_miss)42TLB_MISS_PROLOG4344/* Now we handle the fault proper. We only save DEAR in normal45* fault case since that's the only interesting values here.46* We could probably also optimize by not saving SRR0/1 in the47* linear mapping case but I'll leave that for later48*/49mfspr r14,SPRN_ESR50mfspr r16,SPRN_DEAR /* get faulting address */51srdi r15,r16,60 /* get region */52cmpldi cr0,r15,0xc /* linear mapping ? */53TLB_MISS_STATS_SAVE_INFO54beq tlb_load_linear /* yes -> go to linear map load */5556/* The page tables are mapped virtually linear. At this point, though,57* we don't know whether we are trying to fault in a first level58* virtual address or a virtual page table address. We can get that59* from bit 0x1 of the region ID which we have set for a page table60*/61andi. r10,r15,0x162bne- virt_page_table_tlb_miss6364std r14,EX_TLB_ESR(r12); /* save ESR */65std r16,EX_TLB_DEAR(r12); /* save DEAR */6667/* We need _PAGE_PRESENT and _PAGE_ACCESSED set */68li r11,_PAGE_PRESENT69oris r11,r11,_PAGE_ACCESSED@h7071/* We do the user/kernel test for the PID here along with the RW test72*/73cmpldi cr0,r15,0 /* Check for user region */7475/* We pre-test some combination of permissions to avoid double76* faults:77*78* We move the ESR:ST bit into the position of _PAGE_BAP_SW in the PTE79* ESR_ST is 0x0080000080* _PAGE_BAP_SW is 0x0000001081* So the shift is >> 19. This tests for supervisor writeability.82* If the page happens to be supervisor writeable and not user83* writeable, we will take a new fault later, but that should be84* a rare enough case.85*86* We also move ESR_ST in _PAGE_DIRTY position87* _PAGE_DIRTY is 0x00001000 so the shift is >> 1188*89* MAS1 is preset for all we need except for TID that needs to90* be cleared for kernel translations91*/92rlwimi r11,r14,32-19,27,2793rlwimi r11,r14,32-16,19,1994beq normal_tlb_miss95/* XXX replace the RMW cycles with immediate loads + writes */961: mfspr r10,SPRN_MAS197cmpldi cr0,r15,8 /* Check for vmalloc region */98rlwinm r10,r10,0,16,1 /* Clear TID */99mtspr SPRN_MAS1,r10100beq+ normal_tlb_miss101102/* We got a crappy address, just fault with whatever DEAR and ESR103* are here104*/105TLB_MISS_STATS_D(MMSTAT_TLB_MISS_NORM_FAULT)106TLB_MISS_EPILOG_ERROR107b exc_data_storage_book3e108109/* Instruction TLB miss */110START_EXCEPTION(instruction_tlb_miss)111TLB_MISS_PROLOG112113/* If we take a recursive fault, the second level handler may need114* to know whether we are handling a data or instruction fault in115* order to get to the right store fault handler. We provide that116* info by writing a crazy value in ESR in our exception frame117*/118li r14,-1 /* store to exception frame is done later */119120/* Now we handle the fault proper. We only save DEAR in the non121* linear mapping case since we know the linear mapping case will122* not re-enter. We could indeed optimize and also not save SRR0/1123* in the linear mapping case but I'll leave that for later124*125* Faulting address is SRR0 which is already in r16126*/127srdi r15,r16,60 /* get region */128cmpldi cr0,r15,0xc /* linear mapping ? */129TLB_MISS_STATS_SAVE_INFO130beq tlb_load_linear /* yes -> go to linear map load */131132/* We do the user/kernel test for the PID here along with the RW test133*/134li r11,_PAGE_PRESENT|_PAGE_EXEC /* Base perm */135oris r11,r11,_PAGE_ACCESSED@h136137cmpldi cr0,r15,0 /* Check for user region */138std r14,EX_TLB_ESR(r12) /* write crazy -1 to frame */139beq normal_tlb_miss140141li r11,_PAGE_PRESENT|_PAGE_BAP_SX /* Base perm */142oris r11,r11,_PAGE_ACCESSED@h143/* XXX replace the RMW cycles with immediate loads + writes */144mfspr r10,SPRN_MAS1145cmpldi cr0,r15,8 /* Check for vmalloc region */146rlwinm r10,r10,0,16,1 /* Clear TID */147mtspr SPRN_MAS1,r10148beq+ normal_tlb_miss149150/* We got a crappy address, just fault */151TLB_MISS_STATS_I(MMSTAT_TLB_MISS_NORM_FAULT)152TLB_MISS_EPILOG_ERROR153b exc_instruction_storage_book3e154155/*156* This is the guts of the first-level TLB miss handler for direct157* misses. We are entered with:158*159* r16 = faulting address160* r15 = region ID161* r14 = crap (free to use)162* r13 = PACA163* r12 = TLB exception frame in PACA164* r11 = PTE permission mask165* r10 = crap (free to use)166*/167normal_tlb_miss:168/* So we first construct the page table address. We do that by169* shifting the bottom of the address (not the region ID) by170* PAGE_SHIFT-3, clearing the bottom 3 bits (get a PTE ptr) and171* or'ing the fourth high bit.172*173* NOTE: For 64K pages, we do things slightly differently in174* order to handle the weird page table format used by linux175*/176ori r10,r15,0x1177#ifdef CONFIG_PPC_64K_PAGES178/* For the top bits, 16 bytes per PTE */179rldicl r14,r16,64-(PAGE_SHIFT-4),PAGE_SHIFT-4+4180/* Now create the bottom bits as 0 in position 0x8000 and181* the rest calculated for 8 bytes per PTE182*/183rldicl r15,r16,64-(PAGE_SHIFT-3),64-15184/* Insert the bottom bits in */185rlwimi r14,r15,0,16,31186#else187rldicl r14,r16,64-(PAGE_SHIFT-3),PAGE_SHIFT-3+4188#endif189sldi r15,r10,60190clrrdi r14,r14,3191or r10,r15,r14192193BEGIN_MMU_FTR_SECTION194/* Set the TLB reservation and search for existing entry. Then load195* the entry.196*/197PPC_TLBSRX_DOT(0,r16)198ld r14,0(r10)199beq normal_tlb_miss_done200MMU_FTR_SECTION_ELSE201ld r14,0(r10)202ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBRSRV)203204finish_normal_tlb_miss:205/* Check if required permissions are met */206andc. r15,r11,r14207bne- normal_tlb_miss_access_fault208209/* Now we build the MAS:210*211* MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG212* MAS 1 : Almost fully setup213* - PID already updated by caller if necessary214* - TSIZE need change if !base page size, not215* yet implemented for now216* MAS 2 : Defaults not useful, need to be redone217* MAS 3+7 : Needs to be done218*219* TODO: mix up code below for better scheduling220*/221clrrdi r11,r16,12 /* Clear low crap in EA */222rlwimi r11,r14,32-19,27,31 /* Insert WIMGE */223mtspr SPRN_MAS2,r11224225/* Check page size, if not standard, update MAS1 */226rldicl r11,r14,64-8,64-8227#ifdef CONFIG_PPC_64K_PAGES228cmpldi cr0,r11,BOOK3E_PAGESZ_64K229#else230cmpldi cr0,r11,BOOK3E_PAGESZ_4K231#endif232beq- 1f233mfspr r11,SPRN_MAS1234rlwimi r11,r14,31,21,24235rlwinm r11,r11,0,21,19236mtspr SPRN_MAS1,r112371:238/* Move RPN in position */239rldicr r11,r14,64-(PTE_RPN_SHIFT-PAGE_SHIFT),63-PAGE_SHIFT240clrldi r15,r11,12 /* Clear crap at the top */241rlwimi r15,r14,32-8,22,25 /* Move in U bits */242rlwimi r15,r14,32-2,26,31 /* Move in BAP bits */243244/* Mask out SW and UW if !DIRTY (XXX optimize this !) */245andi. r11,r14,_PAGE_DIRTY246bne 1f247li r11,MAS3_SW|MAS3_UW248andc r15,r15,r112491:250BEGIN_MMU_FTR_SECTION251srdi r16,r15,32252mtspr SPRN_MAS3,r15253mtspr SPRN_MAS7,r16254MMU_FTR_SECTION_ELSE255mtspr SPRN_MAS7_MAS3,r15256ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)257258tlbwe259260normal_tlb_miss_done:261/* We don't bother with restoring DEAR or ESR since we know we are262* level 0 and just going back to userland. They are only needed263* if you are going to take an access fault264*/265TLB_MISS_STATS_X(MMSTAT_TLB_MISS_NORM_OK)266TLB_MISS_EPILOG_SUCCESS267rfi268269normal_tlb_miss_access_fault:270/* We need to check if it was an instruction miss */271andi. r10,r11,_PAGE_EXEC272bne 1f273ld r14,EX_TLB_DEAR(r12)274ld r15,EX_TLB_ESR(r12)275mtspr SPRN_DEAR,r14276mtspr SPRN_ESR,r15277TLB_MISS_STATS_D(MMSTAT_TLB_MISS_NORM_FAULT)278TLB_MISS_EPILOG_ERROR279b exc_data_storage_book3e2801: TLB_MISS_STATS_I(MMSTAT_TLB_MISS_NORM_FAULT)281TLB_MISS_EPILOG_ERROR282b exc_instruction_storage_book3e283284285/*286* This is the guts of the second-level TLB miss handler for direct287* misses. We are entered with:288*289* r16 = virtual page table faulting address290* r15 = region (top 4 bits of address)291* r14 = crap (free to use)292* r13 = PACA293* r12 = TLB exception frame in PACA294* r11 = crap (free to use)295* r10 = crap (free to use)296*297* Note that this should only ever be called as a second level handler298* with the current scheme when using SW load.299* That means we can always get the original fault DEAR at300* EX_TLB_DEAR-EX_TLB_SIZE(r12)301*302* It can be re-entered by the linear mapping miss handler. However, to303* avoid too much complication, it will restart the whole fault at level304* 0 so we don't care too much about clobbers305*306* XXX That code was written back when we couldn't clobber r14. We can now,307* so we could probably optimize things a bit308*/309virt_page_table_tlb_miss:310/* Are we hitting a kernel page table ? */311andi. r10,r15,0x8312313/* The cool thing now is that r10 contains 0 for user and 8 for kernel,314* and we happen to have the swapper_pg_dir at offset 8 from the user315* pgdir in the PACA :-).316*/317add r11,r10,r13318319/* If kernel, we need to clear MAS1 TID */320beq 1f321/* XXX replace the RMW cycles with immediate loads + writes */322mfspr r10,SPRN_MAS1323rlwinm r10,r10,0,16,1 /* Clear TID */324mtspr SPRN_MAS1,r103251:326BEGIN_MMU_FTR_SECTION327/* Search if we already have a TLB entry for that virtual address, and328* if we do, bail out.329*/330PPC_TLBSRX_DOT(0,r16)331beq virt_page_table_tlb_miss_done332END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_TLBRSRV)333334/* Now, we need to walk the page tables. First check if we are in335* range.336*/337rldicl. r10,r16,64-(VPTE_INDEX_SIZE+3),VPTE_INDEX_SIZE+3+4338bne- virt_page_table_tlb_miss_fault339340/* Get the PGD pointer */341ld r15,PACAPGD(r11)342cmpldi cr0,r15,0343beq- virt_page_table_tlb_miss_fault344345/* Get to PGD entry */346rldicl r11,r16,64-VPTE_PGD_SHIFT,64-PGD_INDEX_SIZE-3347clrrdi r10,r11,3348ldx r15,r10,r15349cmpldi cr0,r15,0350beq virt_page_table_tlb_miss_fault351352#ifndef CONFIG_PPC_64K_PAGES353/* Get to PUD entry */354rldicl r11,r16,64-VPTE_PUD_SHIFT,64-PUD_INDEX_SIZE-3355clrrdi r10,r11,3356ldx r15,r10,r15357cmpldi cr0,r15,0358beq virt_page_table_tlb_miss_fault359#endif /* CONFIG_PPC_64K_PAGES */360361/* Get to PMD entry */362rldicl r11,r16,64-VPTE_PMD_SHIFT,64-PMD_INDEX_SIZE-3363clrrdi r10,r11,3364ldx r15,r10,r15365cmpldi cr0,r15,0366beq virt_page_table_tlb_miss_fault367368/* Ok, we're all right, we can now create a kernel translation for369* a 4K or 64K page from r16 -> r15.370*/371/* Now we build the MAS:372*373* MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG374* MAS 1 : Almost fully setup375* - PID already updated by caller if necessary376* - TSIZE for now is base page size always377* MAS 2 : Use defaults378* MAS 3+7 : Needs to be done379*380* So we only do MAS 2 and 3 for now...381*/382clrldi r11,r15,4 /* remove region ID from RPN */383ori r10,r11,1 /* Or-in SR */384385BEGIN_MMU_FTR_SECTION386srdi r16,r10,32387mtspr SPRN_MAS3,r10388mtspr SPRN_MAS7,r16389MMU_FTR_SECTION_ELSE390mtspr SPRN_MAS7_MAS3,r10391ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)392393tlbwe394395BEGIN_MMU_FTR_SECTION396virt_page_table_tlb_miss_done:397398/* We have overriden MAS2:EPN but currently our primary TLB miss399* handler will always restore it so that should not be an issue,400* if we ever optimize the primary handler to not write MAS2 on401* some cases, we'll have to restore MAS2:EPN here based on the402* original fault's DEAR. If we do that we have to modify the403* ITLB miss handler to also store SRR0 in the exception frame404* as DEAR.405*406* However, one nasty thing we did is we cleared the reservation407* (well, potentially we did). We do a trick here thus if we408* are not a level 0 exception (we interrupted the TLB miss) we409* offset the return address by -4 in order to replay the tlbsrx410* instruction there411*/412subf r10,r13,r12413cmpldi cr0,r10,PACA_EXTLB+EX_TLB_SIZE414bne- 1f415ld r11,PACA_EXTLB+EX_TLB_SIZE+EX_TLB_SRR0(r13)416addi r10,r11,-4417std r10,PACA_EXTLB+EX_TLB_SIZE+EX_TLB_SRR0(r13)4181:419END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_TLBRSRV)420/* Return to caller, normal case */421TLB_MISS_STATS_X(MMSTAT_TLB_MISS_PT_OK);422TLB_MISS_EPILOG_SUCCESS423rfi424425virt_page_table_tlb_miss_fault:426/* If we fault here, things are a little bit tricky. We need to call427* either data or instruction store fault, and we need to retrieve428* the original fault address and ESR (for data).429*430* The thing is, we know that in normal circumstances, this is431* always called as a second level tlb miss for SW load or as a first432* level TLB miss for HW load, so we should be able to peek at the433* relevant information in the first exception frame in the PACA.434*435* However, we do need to double check that, because we may just hit436* a stray kernel pointer or a userland attack trying to hit those437* areas. If that is the case, we do a data fault. (We can't get here438* from an instruction tlb miss anyway).439*440* Note also that when going to a fault, we must unwind the previous441* level as well. Since we are doing that, we don't need to clear or442* restore the TLB reservation neither.443*/444subf r10,r13,r12445cmpldi cr0,r10,PACA_EXTLB+EX_TLB_SIZE446bne- virt_page_table_tlb_miss_whacko_fault447448/* We dig the original DEAR and ESR from slot 0 */449ld r15,EX_TLB_DEAR+PACA_EXTLB(r13)450ld r16,EX_TLB_ESR+PACA_EXTLB(r13)451452/* We check for the "special" ESR value for instruction faults */453cmpdi cr0,r16,-1454beq 1f455mtspr SPRN_DEAR,r15456mtspr SPRN_ESR,r16457TLB_MISS_STATS_D(MMSTAT_TLB_MISS_PT_FAULT);458TLB_MISS_EPILOG_ERROR459b exc_data_storage_book3e4601: TLB_MISS_STATS_I(MMSTAT_TLB_MISS_PT_FAULT);461TLB_MISS_EPILOG_ERROR462b exc_instruction_storage_book3e463464virt_page_table_tlb_miss_whacko_fault:465/* The linear fault will restart everything so ESR and DEAR will466* not have been clobbered, let's just fault with what we have467*/468TLB_MISS_STATS_X(MMSTAT_TLB_MISS_PT_FAULT);469TLB_MISS_EPILOG_ERROR470b exc_data_storage_book3e471472473/**************************************************************474* *475* TLB miss handling for Book3E with hw page table support *476* *477**************************************************************/478479480/* Data TLB miss */481START_EXCEPTION(data_tlb_miss_htw)482TLB_MISS_PROLOG483484/* Now we handle the fault proper. We only save DEAR in normal485* fault case since that's the only interesting values here.486* We could probably also optimize by not saving SRR0/1 in the487* linear mapping case but I'll leave that for later488*/489mfspr r14,SPRN_ESR490mfspr r16,SPRN_DEAR /* get faulting address */491srdi r11,r16,60 /* get region */492cmpldi cr0,r11,0xc /* linear mapping ? */493TLB_MISS_STATS_SAVE_INFO494beq tlb_load_linear /* yes -> go to linear map load */495496/* We do the user/kernel test for the PID here along with the RW test497*/498cmpldi cr0,r11,0 /* Check for user region */499ld r15,PACAPGD(r13) /* Load user pgdir */500beq htw_tlb_miss501502/* XXX replace the RMW cycles with immediate loads + writes */5031: mfspr r10,SPRN_MAS1504cmpldi cr0,r11,8 /* Check for vmalloc region */505rlwinm r10,r10,0,16,1 /* Clear TID */506mtspr SPRN_MAS1,r10507ld r15,PACA_KERNELPGD(r13) /* Load kernel pgdir */508beq+ htw_tlb_miss509510/* We got a crappy address, just fault with whatever DEAR and ESR511* are here512*/513TLB_MISS_STATS_D(MMSTAT_TLB_MISS_NORM_FAULT)514TLB_MISS_EPILOG_ERROR515b exc_data_storage_book3e516517/* Instruction TLB miss */518START_EXCEPTION(instruction_tlb_miss_htw)519TLB_MISS_PROLOG520521/* If we take a recursive fault, the second level handler may need522* to know whether we are handling a data or instruction fault in523* order to get to the right store fault handler. We provide that524* info by keeping a crazy value for ESR in r14525*/526li r14,-1 /* store to exception frame is done later */527528/* Now we handle the fault proper. We only save DEAR in the non529* linear mapping case since we know the linear mapping case will530* not re-enter. We could indeed optimize and also not save SRR0/1531* in the linear mapping case but I'll leave that for later532*533* Faulting address is SRR0 which is already in r16534*/535srdi r11,r16,60 /* get region */536cmpldi cr0,r11,0xc /* linear mapping ? */537TLB_MISS_STATS_SAVE_INFO538beq tlb_load_linear /* yes -> go to linear map load */539540/* We do the user/kernel test for the PID here along with the RW test541*/542cmpldi cr0,r11,0 /* Check for user region */543ld r15,PACAPGD(r13) /* Load user pgdir */544beq htw_tlb_miss545546/* XXX replace the RMW cycles with immediate loads + writes */5471: mfspr r10,SPRN_MAS1548cmpldi cr0,r11,8 /* Check for vmalloc region */549rlwinm r10,r10,0,16,1 /* Clear TID */550mtspr SPRN_MAS1,r10551ld r15,PACA_KERNELPGD(r13) /* Load kernel pgdir */552beq+ htw_tlb_miss553554/* We got a crappy address, just fault */555TLB_MISS_STATS_I(MMSTAT_TLB_MISS_NORM_FAULT)556TLB_MISS_EPILOG_ERROR557b exc_instruction_storage_book3e558559560/*561* This is the guts of the second-level TLB miss handler for direct562* misses. We are entered with:563*564* r16 = virtual page table faulting address565* r15 = PGD pointer566* r14 = ESR567* r13 = PACA568* r12 = TLB exception frame in PACA569* r11 = crap (free to use)570* r10 = crap (free to use)571*572* It can be re-entered by the linear mapping miss handler. However, to573* avoid too much complication, it will save/restore things for us574*/575htw_tlb_miss:576/* Search if we already have a TLB entry for that virtual address, and577* if we do, bail out.578*579* MAS1:IND should be already set based on MAS4580*/581PPC_TLBSRX_DOT(0,r16)582beq htw_tlb_miss_done583584/* Now, we need to walk the page tables. First check if we are in585* range.586*/587rldicl. r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4588bne- htw_tlb_miss_fault589590/* Get the PGD pointer */591cmpldi cr0,r15,0592beq- htw_tlb_miss_fault593594/* Get to PGD entry */595rldicl r11,r16,64-(PGDIR_SHIFT-3),64-PGD_INDEX_SIZE-3596clrrdi r10,r11,3597ldx r15,r10,r15598cmpldi cr0,r15,0599beq htw_tlb_miss_fault600601#ifndef CONFIG_PPC_64K_PAGES602/* Get to PUD entry */603rldicl r11,r16,64-(PUD_SHIFT-3),64-PUD_INDEX_SIZE-3604clrrdi r10,r11,3605ldx r15,r10,r15606cmpldi cr0,r15,0607beq htw_tlb_miss_fault608#endif /* CONFIG_PPC_64K_PAGES */609610/* Get to PMD entry */611rldicl r11,r16,64-(PMD_SHIFT-3),64-PMD_INDEX_SIZE-3612clrrdi r10,r11,3613ldx r15,r10,r15614cmpldi cr0,r15,0615beq htw_tlb_miss_fault616617/* Ok, we're all right, we can now create an indirect entry for618* a 1M or 256M page.619*620* The last trick is now that because we use "half" pages for621* the HTW (1M IND is 2K and 256M IND is 32K) we need to account622* for an added LSB bit to the RPN. For 64K pages, there is no623* problem as we already use 32K arrays (half PTE pages), but for624* 4K page we need to extract a bit from the virtual address and625* insert it into the "PA52" bit of the RPN.626*/627#ifndef CONFIG_PPC_64K_PAGES628rlwimi r15,r16,32-9,20,20629#endif630/* Now we build the MAS:631*632* MAS 0 : Fully setup with defaults in MAS4 and TLBnCFG633* MAS 1 : Almost fully setup634* - PID already updated by caller if necessary635* - TSIZE for now is base ind page size always636* MAS 2 : Use defaults637* MAS 3+7 : Needs to be done638*/639#ifdef CONFIG_PPC_64K_PAGES640ori r10,r15,(BOOK3E_PAGESZ_64K << MAS3_SPSIZE_SHIFT)641#else642ori r10,r15,(BOOK3E_PAGESZ_4K << MAS3_SPSIZE_SHIFT)643#endif644645BEGIN_MMU_FTR_SECTION646srdi r16,r10,32647mtspr SPRN_MAS3,r10648mtspr SPRN_MAS7,r16649MMU_FTR_SECTION_ELSE650mtspr SPRN_MAS7_MAS3,r10651ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)652653tlbwe654655htw_tlb_miss_done:656/* We don't bother with restoring DEAR or ESR since we know we are657* level 0 and just going back to userland. They are only needed658* if you are going to take an access fault659*/660TLB_MISS_STATS_X(MMSTAT_TLB_MISS_PT_OK)661TLB_MISS_EPILOG_SUCCESS662rfi663664htw_tlb_miss_fault:665/* We need to check if it was an instruction miss. We know this666* though because r14 would contain -1667*/668cmpdi cr0,r14,-1669beq 1f670mtspr SPRN_DEAR,r16671mtspr SPRN_ESR,r14672TLB_MISS_STATS_D(MMSTAT_TLB_MISS_PT_FAULT)673TLB_MISS_EPILOG_ERROR674b exc_data_storage_book3e6751: TLB_MISS_STATS_I(MMSTAT_TLB_MISS_PT_FAULT)676TLB_MISS_EPILOG_ERROR677b exc_instruction_storage_book3e678679/*680* This is the guts of "any" level TLB miss handler for kernel linear681* mapping misses. We are entered with:682*683*684* r16 = faulting address685* r15 = crap (free to use)686* r14 = ESR (data) or -1 (instruction)687* r13 = PACA688* r12 = TLB exception frame in PACA689* r11 = crap (free to use)690* r10 = crap (free to use)691*692* In addition we know that we will not re-enter, so in theory, we could693* use a simpler epilog not restoring SRR0/1 etc.. but we'll do that later.694*695* We also need to be careful about MAS registers here & TLB reservation,696* as we know we'll have clobbered them if we interrupt the main TLB miss697* handlers in which case we probably want to do a full restart at level698* 0 rather than saving / restoring the MAS.699*700* Note: If we care about performance of that core, we can easily shuffle701* a few things around702*/703tlb_load_linear:704/* For now, we assume the linear mapping is contiguous and stops at705* linear_map_top. We also assume the size is a multiple of 1G, thus706* we only use 1G pages for now. That might have to be changed in a707* final implementation, especially when dealing with hypervisors708*/709ld r11,PACATOC(r13)710ld r11,linear_map_top@got(r11)711ld r10,0(r11)712cmpld cr0,r10,r16713bge tlb_load_linear_fault714715/* MAS1 need whole new setup. */716li r15,(BOOK3E_PAGESZ_1GB<<MAS1_TSIZE_SHIFT)717oris r15,r15,MAS1_VALID@h /* MAS1 needs V and TSIZE */718mtspr SPRN_MAS1,r15719720/* Already somebody there ? */721PPC_TLBSRX_DOT(0,r16)722beq tlb_load_linear_done723724/* Now we build the remaining MAS. MAS0 and 2 should be fine725* with their defaults, which leaves us with MAS 3 and 7. The726* mapping is linear, so we just take the address, clear the727* region bits, and or in the permission bits which are currently728* hard wired729*/730clrrdi r10,r16,30 /* 1G page index */731clrldi r10,r10,4 /* clear region bits */732ori r10,r10,MAS3_SR|MAS3_SW|MAS3_SX733734BEGIN_MMU_FTR_SECTION735srdi r16,r10,32736mtspr SPRN_MAS3,r10737mtspr SPRN_MAS7,r16738MMU_FTR_SECTION_ELSE739mtspr SPRN_MAS7_MAS3,r10740ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)741742tlbwe743744tlb_load_linear_done:745/* We use the "error" epilog for success as we do want to746* restore to the initial faulting context, whatever it was.747* We do that because we can't resume a fault within a TLB748* miss handler, due to MAS and TLB reservation being clobbered.749*/750TLB_MISS_STATS_X(MMSTAT_TLB_MISS_LINEAR)751TLB_MISS_EPILOG_ERROR752rfi753754tlb_load_linear_fault:755/* We keep the DEAR and ESR around, this shouldn't have happened */756cmpdi cr0,r14,-1757beq 1f758TLB_MISS_EPILOG_ERROR_SPECIAL759b exc_data_storage_book3e7601: TLB_MISS_EPILOG_ERROR_SPECIAL761b exc_instruction_storage_book3e762763764#ifdef CONFIG_BOOK3E_MMU_TLB_STATS765.tlb_stat_inc:7661: ldarx r8,0,r9767addi r8,r8,1768stdcx. r8,0,r9769bne- 1b770blr771#endif772773774