18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Low level TLB miss handlers for Book3E
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2008-2009
68c2ecf20Sopenharmony_ci *      Ben. Herrenschmidt (benh@kernel.crashing.org), IBM Corp.
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/pgtable.h>
108c2ecf20Sopenharmony_ci#include <asm/processor.h>
118c2ecf20Sopenharmony_ci#include <asm/reg.h>
128c2ecf20Sopenharmony_ci#include <asm/page.h>
138c2ecf20Sopenharmony_ci#include <asm/mmu.h>
148c2ecf20Sopenharmony_ci#include <asm/ppc_asm.h>
158c2ecf20Sopenharmony_ci#include <asm/asm-offsets.h>
168c2ecf20Sopenharmony_ci#include <asm/cputable.h>
178c2ecf20Sopenharmony_ci#include <asm/exception-64e.h>
188c2ecf20Sopenharmony_ci#include <asm/ppc-opcode.h>
198c2ecf20Sopenharmony_ci#include <asm/kvm_asm.h>
208c2ecf20Sopenharmony_ci#include <asm/kvm_booke_hv_asm.h>
218c2ecf20Sopenharmony_ci#include <asm/feature-fixups.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define VPTE_PMD_SHIFT	(PTE_INDEX_SIZE)
248c2ecf20Sopenharmony_ci#define VPTE_PUD_SHIFT	(VPTE_PMD_SHIFT + PMD_INDEX_SIZE)
258c2ecf20Sopenharmony_ci#define VPTE_PGD_SHIFT	(VPTE_PUD_SHIFT + PUD_INDEX_SIZE)
268c2ecf20Sopenharmony_ci#define VPTE_INDEX_SIZE (VPTE_PGD_SHIFT + PGD_INDEX_SIZE)
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/**********************************************************************
298c2ecf20Sopenharmony_ci *                                                                    *
308c2ecf20Sopenharmony_ci * TLB miss handling for Book3E with a bolted linear mapping          *
318c2ecf20Sopenharmony_ci * No virtual page table, no nested TLB misses                        *
328c2ecf20Sopenharmony_ci *                                                                    *
338c2ecf20Sopenharmony_ci **********************************************************************/
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/*
368c2ecf20Sopenharmony_ci * Note that, unlike non-bolted handlers, TLB_EXFRAME is not
378c2ecf20Sopenharmony_ci * modified by the TLB miss handlers themselves, since the TLB miss
388c2ecf20Sopenharmony_ci * handler code will not itself cause a recursive TLB miss.
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci * TLB_EXFRAME will be modified when crit/mc/debug exceptions are
418c2ecf20Sopenharmony_ci * entered/exited.
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ci.macro tlb_prolog_bolted intnum addr
448c2ecf20Sopenharmony_ci	mtspr	SPRN_SPRG_GEN_SCRATCH,r12
458c2ecf20Sopenharmony_ci	mfspr	r12,SPRN_SPRG_TLB_EXFRAME
468c2ecf20Sopenharmony_ci	std	r13,EX_TLB_R13(r12)
478c2ecf20Sopenharmony_ci	std	r10,EX_TLB_R10(r12)
488c2ecf20Sopenharmony_ci	mfspr	r13,SPRN_SPRG_PACA
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	mfcr	r10
518c2ecf20Sopenharmony_ci	std	r11,EX_TLB_R11(r12)
528c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOKE_HV
538c2ecf20Sopenharmony_ciBEGIN_FTR_SECTION
548c2ecf20Sopenharmony_ci	mfspr	r11, SPRN_SRR1
558c2ecf20Sopenharmony_ciEND_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
568c2ecf20Sopenharmony_ci#endif
578c2ecf20Sopenharmony_ci	DO_KVM	\intnum, SPRN_SRR1
588c2ecf20Sopenharmony_ci	std	r16,EX_TLB_R16(r12)
598c2ecf20Sopenharmony_ci	mfspr	r16,\addr		/* get faulting address */
608c2ecf20Sopenharmony_ci	std	r14,EX_TLB_R14(r12)
618c2ecf20Sopenharmony_ci	ld	r14,PACAPGD(r13)
628c2ecf20Sopenharmony_ci	std	r15,EX_TLB_R15(r12)
638c2ecf20Sopenharmony_ci	std	r10,EX_TLB_CR(r12)
648c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_FSL_BOOK3E
658c2ecf20Sopenharmony_ciSTART_BTB_FLUSH_SECTION
668c2ecf20Sopenharmony_ci	mfspr r11, SPRN_SRR1
678c2ecf20Sopenharmony_ci	andi. r10,r11,MSR_PR
688c2ecf20Sopenharmony_ci	beq 1f
698c2ecf20Sopenharmony_ci	BTB_FLUSH(r10)
708c2ecf20Sopenharmony_ci1:
718c2ecf20Sopenharmony_ciEND_BTB_FLUSH_SECTION
728c2ecf20Sopenharmony_ci	std	r7,EX_TLB_R7(r12)
738c2ecf20Sopenharmony_ci#endif
748c2ecf20Sopenharmony_ci.endm
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci.macro tlb_epilog_bolted
778c2ecf20Sopenharmony_ci	ld	r14,EX_TLB_CR(r12)
788c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_FSL_BOOK3E
798c2ecf20Sopenharmony_ci	ld	r7,EX_TLB_R7(r12)
808c2ecf20Sopenharmony_ci#endif
818c2ecf20Sopenharmony_ci	ld	r10,EX_TLB_R10(r12)
828c2ecf20Sopenharmony_ci	ld	r11,EX_TLB_R11(r12)
838c2ecf20Sopenharmony_ci	ld	r13,EX_TLB_R13(r12)
848c2ecf20Sopenharmony_ci	mtcr	r14
858c2ecf20Sopenharmony_ci	ld	r14,EX_TLB_R14(r12)
868c2ecf20Sopenharmony_ci	ld	r15,EX_TLB_R15(r12)
878c2ecf20Sopenharmony_ci	ld	r16,EX_TLB_R16(r12)
888c2ecf20Sopenharmony_ci	mfspr	r12,SPRN_SPRG_GEN_SCRATCH
898c2ecf20Sopenharmony_ci.endm
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/* Data TLB miss */
928c2ecf20Sopenharmony_ci	START_EXCEPTION(data_tlb_miss_bolted)
938c2ecf20Sopenharmony_ci	tlb_prolog_bolted BOOKE_INTERRUPT_DTLB_MISS SPRN_DEAR
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	/* We need _PAGE_PRESENT and  _PAGE_ACCESSED set */
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	/* We do the user/kernel test for the PID here along with the RW test
988c2ecf20Sopenharmony_ci	 */
998c2ecf20Sopenharmony_ci	/* We pre-test some combination of permissions to avoid double
1008c2ecf20Sopenharmony_ci	 * faults:
1018c2ecf20Sopenharmony_ci	 *
1028c2ecf20Sopenharmony_ci	 * We move the ESR:ST bit into the position of _PAGE_BAP_SW in the PTE
1038c2ecf20Sopenharmony_ci	 * ESR_ST   is 0x00800000
1048c2ecf20Sopenharmony_ci	 * _PAGE_BAP_SW is 0x00000010
1058c2ecf20Sopenharmony_ci	 * So the shift is >> 19. This tests for supervisor writeability.
1068c2ecf20Sopenharmony_ci	 * If the page happens to be supervisor writeable and not user
1078c2ecf20Sopenharmony_ci	 * writeable, we will take a new fault later, but that should be
1088c2ecf20Sopenharmony_ci	 * a rare enough case.
1098c2ecf20Sopenharmony_ci	 *
1108c2ecf20Sopenharmony_ci	 * We also move ESR_ST in _PAGE_DIRTY position
1118c2ecf20Sopenharmony_ci	 * _PAGE_DIRTY is 0x00001000 so the shift is >> 11
1128c2ecf20Sopenharmony_ci	 *
1138c2ecf20Sopenharmony_ci	 * MAS1 is preset for all we need except for TID that needs to
1148c2ecf20Sopenharmony_ci	 * be cleared for kernel translations
1158c2ecf20Sopenharmony_ci	 */
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	mfspr	r11,SPRN_ESR
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	srdi	r15,r16,60		/* get region */
1208c2ecf20Sopenharmony_ci	rldicl.	r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4
1218c2ecf20Sopenharmony_ci	bne-	dtlb_miss_fault_bolted	/* Bail if fault addr is invalid */
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	rlwinm	r10,r11,32-19,27,27
1248c2ecf20Sopenharmony_ci	rlwimi	r10,r11,32-16,19,19
1258c2ecf20Sopenharmony_ci	cmpwi	r15,0			/* user vs kernel check */
1268c2ecf20Sopenharmony_ci	ori	r10,r10,_PAGE_PRESENT
1278c2ecf20Sopenharmony_ci	oris	r11,r10,_PAGE_ACCESSED@h
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	bne	tlb_miss_kernel_bolted
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_citlb_miss_common_bolted:
1328c2ecf20Sopenharmony_ci/*
1338c2ecf20Sopenharmony_ci * This is the guts of the TLB miss handler for bolted-linear.
1348c2ecf20Sopenharmony_ci * We are entered with:
1358c2ecf20Sopenharmony_ci *
1368c2ecf20Sopenharmony_ci * r16 = faulting address
1378c2ecf20Sopenharmony_ci * r15 = crap (free to use)
1388c2ecf20Sopenharmony_ci * r14 = page table base
1398c2ecf20Sopenharmony_ci * r13 = PACA
1408c2ecf20Sopenharmony_ci * r11 = PTE permission mask
1418c2ecf20Sopenharmony_ci * r10 = crap (free to use)
1428c2ecf20Sopenharmony_ci */
1438c2ecf20Sopenharmony_ci	rldicl	r15,r16,64-PGDIR_SHIFT+3,64-PGD_INDEX_SIZE-3
1448c2ecf20Sopenharmony_ci	cmpldi	cr0,r14,0
1458c2ecf20Sopenharmony_ci	clrrdi	r15,r15,3
1468c2ecf20Sopenharmony_ci	beq	tlb_miss_fault_bolted	/* No PGDIR, bail */
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ciBEGIN_MMU_FTR_SECTION
1498c2ecf20Sopenharmony_ci	/* Set the TLB reservation and search for existing entry. Then load
1508c2ecf20Sopenharmony_ci	 * the entry.
1518c2ecf20Sopenharmony_ci	 */
1528c2ecf20Sopenharmony_ci	PPC_TLBSRX_DOT(0,R16)
1538c2ecf20Sopenharmony_ci	ldx	r14,r14,r15		/* grab pgd entry */
1548c2ecf20Sopenharmony_ci	beq	tlb_miss_done_bolted	/* tlb exists already, bail */
1558c2ecf20Sopenharmony_ciMMU_FTR_SECTION_ELSE
1568c2ecf20Sopenharmony_ci	ldx	r14,r14,r15		/* grab pgd entry */
1578c2ecf20Sopenharmony_ciALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBRSRV)
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	rldicl	r15,r16,64-PUD_SHIFT+3,64-PUD_INDEX_SIZE-3
1608c2ecf20Sopenharmony_ci	clrrdi	r15,r15,3
1618c2ecf20Sopenharmony_ci	cmpdi	cr0,r14,0
1628c2ecf20Sopenharmony_ci	bge	tlb_miss_fault_bolted	/* Bad pgd entry or hugepage; bail */
1638c2ecf20Sopenharmony_ci	ldx	r14,r14,r15		/* grab pud entry */
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci	rldicl	r15,r16,64-PMD_SHIFT+3,64-PMD_INDEX_SIZE-3
1668c2ecf20Sopenharmony_ci	clrrdi	r15,r15,3
1678c2ecf20Sopenharmony_ci	cmpdi	cr0,r14,0
1688c2ecf20Sopenharmony_ci	bge	tlb_miss_fault_bolted
1698c2ecf20Sopenharmony_ci	ldx	r14,r14,r15		/* Grab pmd entry */
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	rldicl	r15,r16,64-PAGE_SHIFT+3,64-PTE_INDEX_SIZE-3
1728c2ecf20Sopenharmony_ci	clrrdi	r15,r15,3
1738c2ecf20Sopenharmony_ci	cmpdi	cr0,r14,0
1748c2ecf20Sopenharmony_ci	bge	tlb_miss_fault_bolted
1758c2ecf20Sopenharmony_ci	ldx	r14,r14,r15		/* Grab PTE, normal (!huge) page */
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	/* Check if required permissions are met */
1788c2ecf20Sopenharmony_ci	andc.	r15,r11,r14
1798c2ecf20Sopenharmony_ci	rldicr	r15,r14,64-(PTE_RPN_SHIFT-PAGE_SHIFT),63-PAGE_SHIFT
1808c2ecf20Sopenharmony_ci	bne-	tlb_miss_fault_bolted
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	/* Now we build the MAS:
1838c2ecf20Sopenharmony_ci	 *
1848c2ecf20Sopenharmony_ci	 * MAS 0   :	Fully setup with defaults in MAS4 and TLBnCFG
1858c2ecf20Sopenharmony_ci	 * MAS 1   :	Almost fully setup
1868c2ecf20Sopenharmony_ci	 *               - PID already updated by caller if necessary
1878c2ecf20Sopenharmony_ci	 *               - TSIZE need change if !base page size, not
1888c2ecf20Sopenharmony_ci	 *                 yet implemented for now
1898c2ecf20Sopenharmony_ci	 * MAS 2   :	Defaults not useful, need to be redone
1908c2ecf20Sopenharmony_ci	 * MAS 3+7 :	Needs to be done
1918c2ecf20Sopenharmony_ci	 */
1928c2ecf20Sopenharmony_ci	clrrdi	r11,r16,12		/* Clear low crap in EA */
1938c2ecf20Sopenharmony_ci	clrldi	r15,r15,12		/* Clear crap at the top */
1948c2ecf20Sopenharmony_ci	rlwimi	r11,r14,32-19,27,31	/* Insert WIMGE */
1958c2ecf20Sopenharmony_ci	rlwimi	r15,r14,32-8,22,25	/* Move in U bits */
1968c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS2,r11
1978c2ecf20Sopenharmony_ci	andi.	r11,r14,_PAGE_DIRTY
1988c2ecf20Sopenharmony_ci	rlwimi	r15,r14,32-2,26,31	/* Move in BAP bits */
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	/* Mask out SW and UW if !DIRTY (XXX optimize this !) */
2018c2ecf20Sopenharmony_ci	bne	1f
2028c2ecf20Sopenharmony_ci	li	r11,MAS3_SW|MAS3_UW
2038c2ecf20Sopenharmony_ci	andc	r15,r15,r11
2048c2ecf20Sopenharmony_ci1:
2058c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7_MAS3,r15
2068c2ecf20Sopenharmony_ci	tlbwe
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_citlb_miss_done_bolted:
2098c2ecf20Sopenharmony_ci	tlb_epilog_bolted
2108c2ecf20Sopenharmony_ci	rfi
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ciitlb_miss_kernel_bolted:
2138c2ecf20Sopenharmony_ci	li	r11,_PAGE_PRESENT|_PAGE_BAP_SX	/* Base perm */
2148c2ecf20Sopenharmony_ci	oris	r11,r11,_PAGE_ACCESSED@h
2158c2ecf20Sopenharmony_citlb_miss_kernel_bolted:
2168c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS1
2178c2ecf20Sopenharmony_ci	ld	r14,PACA_KERNELPGD(r13)
2188c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,8		/* Check for vmalloc region */
2198c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,16,1		/* Clear TID */
2208c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r10
2218c2ecf20Sopenharmony_ci	beq+	tlb_miss_common_bolted
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_citlb_miss_fault_bolted:
2248c2ecf20Sopenharmony_ci	/* We need to check if it was an instruction miss */
2258c2ecf20Sopenharmony_ci	andi.	r10,r11,_PAGE_EXEC|_PAGE_BAP_SX
2268c2ecf20Sopenharmony_ci	bne	itlb_miss_fault_bolted
2278c2ecf20Sopenharmony_cidtlb_miss_fault_bolted:
2288c2ecf20Sopenharmony_ci	tlb_epilog_bolted
2298c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
2308c2ecf20Sopenharmony_ciitlb_miss_fault_bolted:
2318c2ecf20Sopenharmony_ci	tlb_epilog_bolted
2328c2ecf20Sopenharmony_ci	b	exc_instruction_storage_book3e
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci/* Instruction TLB miss */
2358c2ecf20Sopenharmony_ci	START_EXCEPTION(instruction_tlb_miss_bolted)
2368c2ecf20Sopenharmony_ci	tlb_prolog_bolted BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR0
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	rldicl.	r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4
2398c2ecf20Sopenharmony_ci	srdi	r15,r16,60		/* get region */
2408c2ecf20Sopenharmony_ci	bne-	itlb_miss_fault_bolted
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	li	r11,_PAGE_PRESENT|_PAGE_EXEC	/* Base perm */
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	/* We do the user/kernel test for the PID here along with the RW test
2458c2ecf20Sopenharmony_ci	 */
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,0			/* Check for user region */
2488c2ecf20Sopenharmony_ci	oris	r11,r11,_PAGE_ACCESSED@h
2498c2ecf20Sopenharmony_ci	beq	tlb_miss_common_bolted
2508c2ecf20Sopenharmony_ci	b	itlb_miss_kernel_bolted
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_FSL_BOOK3E
2538c2ecf20Sopenharmony_ci/*
2548c2ecf20Sopenharmony_ci * TLB miss handling for e6500 and derivatives, using hardware tablewalk.
2558c2ecf20Sopenharmony_ci *
2568c2ecf20Sopenharmony_ci * Linear mapping is bolted: no virtual page table or nested TLB misses
2578c2ecf20Sopenharmony_ci * Indirect entries in TLB1, hardware loads resulting direct entries
2588c2ecf20Sopenharmony_ci *    into TLB0
2598c2ecf20Sopenharmony_ci * No HES or NV hint on TLB1, so we need to do software round-robin
2608c2ecf20Sopenharmony_ci * No tlbsrx. so we need a spinlock, and we have to deal
2618c2ecf20Sopenharmony_ci *    with MAS-damage caused by tlbsx
2628c2ecf20Sopenharmony_ci * 4K pages only
2638c2ecf20Sopenharmony_ci */
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	START_EXCEPTION(instruction_tlb_miss_e6500)
2668c2ecf20Sopenharmony_ci	tlb_prolog_bolted BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR0
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	ld	r11,PACA_TCD_PTR(r13)
2698c2ecf20Sopenharmony_ci	srdi.	r15,r16,60		/* get region */
2708c2ecf20Sopenharmony_ci	ori	r16,r16,1
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	bne	tlb_miss_kernel_e6500	/* user/kernel test */
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	b	tlb_miss_common_e6500
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	START_EXCEPTION(data_tlb_miss_e6500)
2778c2ecf20Sopenharmony_ci	tlb_prolog_bolted BOOKE_INTERRUPT_DTLB_MISS SPRN_DEAR
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	ld	r11,PACA_TCD_PTR(r13)
2808c2ecf20Sopenharmony_ci	srdi.	r15,r16,60		/* get region */
2818c2ecf20Sopenharmony_ci	rldicr	r16,r16,0,62
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	bne	tlb_miss_kernel_e6500	/* user vs kernel check */
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci/*
2868c2ecf20Sopenharmony_ci * This is the guts of the TLB miss handler for e6500 and derivatives.
2878c2ecf20Sopenharmony_ci * We are entered with:
2888c2ecf20Sopenharmony_ci *
2898c2ecf20Sopenharmony_ci * r16 = page of faulting address (low bit 0 if data, 1 if instruction)
2908c2ecf20Sopenharmony_ci * r15 = crap (free to use)
2918c2ecf20Sopenharmony_ci * r14 = page table base
2928c2ecf20Sopenharmony_ci * r13 = PACA
2938c2ecf20Sopenharmony_ci * r11 = tlb_per_core ptr
2948c2ecf20Sopenharmony_ci * r10 = crap (free to use)
2958c2ecf20Sopenharmony_ci * r7  = esel_next
2968c2ecf20Sopenharmony_ci */
2978c2ecf20Sopenharmony_citlb_miss_common_e6500:
2988c2ecf20Sopenharmony_ci	crmove	cr2*4+2,cr0*4+2		/* cr2.eq != 0 if kernel address */
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ciBEGIN_FTR_SECTION		/* CPU_FTR_SMT */
3018c2ecf20Sopenharmony_ci	/*
3028c2ecf20Sopenharmony_ci	 * Search if we already have an indirect entry for that virtual
3038c2ecf20Sopenharmony_ci	 * address, and if we do, bail out.
3048c2ecf20Sopenharmony_ci	 *
3058c2ecf20Sopenharmony_ci	 * MAS6:IND should be already set based on MAS4
3068c2ecf20Sopenharmony_ci	 */
3078c2ecf20Sopenharmony_ci	lhz	r10,PACAPACAINDEX(r13)
3088c2ecf20Sopenharmony_ci	addi	r10,r10,1
3098c2ecf20Sopenharmony_ci	crclr	cr1*4+eq	/* set cr1.eq = 0 for non-recursive */
3108c2ecf20Sopenharmony_ci1:	lbarx	r15,0,r11
3118c2ecf20Sopenharmony_ci	cmpdi	r15,0
3128c2ecf20Sopenharmony_ci	bne	2f
3138c2ecf20Sopenharmony_ci	stbcx.	r10,0,r11
3148c2ecf20Sopenharmony_ci	bne	1b
3158c2ecf20Sopenharmony_ci3:
3168c2ecf20Sopenharmony_ci	.subsection 1
3178c2ecf20Sopenharmony_ci2:	cmpd	cr1,r15,r10	/* recursive lock due to mcheck/crit/etc? */
3188c2ecf20Sopenharmony_ci	beq	cr1,3b		/* unlock will happen if cr1.eq = 0 */
3198c2ecf20Sopenharmony_ci10:	lbz	r15,0(r11)
3208c2ecf20Sopenharmony_ci	cmpdi	r15,0
3218c2ecf20Sopenharmony_ci	bne	10b
3228c2ecf20Sopenharmony_ci	b	1b
3238c2ecf20Sopenharmony_ci	.previous
3248c2ecf20Sopenharmony_ciEND_FTR_SECTION_IFSET(CPU_FTR_SMT)
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	lbz	r7,TCD_ESEL_NEXT(r11)
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ciBEGIN_FTR_SECTION		/* CPU_FTR_SMT */
3298c2ecf20Sopenharmony_ci	/*
3308c2ecf20Sopenharmony_ci	 * Erratum A-008139 says that we can't use tlbwe to change
3318c2ecf20Sopenharmony_ci	 * an indirect entry in any way (including replacing or
3328c2ecf20Sopenharmony_ci	 * invalidating) if the other thread could be in the process
3338c2ecf20Sopenharmony_ci	 * of a lookup.  The workaround is to invalidate the entry
3348c2ecf20Sopenharmony_ci	 * with tlbilx before overwriting.
3358c2ecf20Sopenharmony_ci	 */
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	rlwinm	r10,r7,16,0xff0000
3388c2ecf20Sopenharmony_ci	oris	r10,r10,MAS0_TLBSEL(1)@h
3398c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS0,r10
3408c2ecf20Sopenharmony_ci	isync
3418c2ecf20Sopenharmony_ci	tlbre
3428c2ecf20Sopenharmony_ci	mfspr	r15,SPRN_MAS1
3438c2ecf20Sopenharmony_ci	andis.	r15,r15,MAS1_VALID@h
3448c2ecf20Sopenharmony_ci	beq	5f
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ciBEGIN_FTR_SECTION_NESTED(532)
3478c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS8
3488c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,0x80000fff  /* tgs,tlpid -> sgs,slpid */
3498c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS5,r10
3508c2ecf20Sopenharmony_ciEND_FTR_SECTION_NESTED(CPU_FTR_EMB_HV,CPU_FTR_EMB_HV,532)
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS1
3538c2ecf20Sopenharmony_ci	rlwinm	r15,r10,0,0x3fff0000  /* tid -> spid */
3548c2ecf20Sopenharmony_ci	rlwimi	r15,r10,20,0x00000003 /* ind,ts -> sind,sas */
3558c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS6
3568c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS6,r15
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	mfspr	r15,SPRN_MAS2
3598c2ecf20Sopenharmony_ci	isync
3608c2ecf20Sopenharmony_ci	tlbilxva 0,r15
3618c2ecf20Sopenharmony_ci	isync
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS6,r10
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci5:
3668c2ecf20Sopenharmony_ciBEGIN_FTR_SECTION_NESTED(532)
3678c2ecf20Sopenharmony_ci	li	r10,0
3688c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS8,r10
3698c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS5,r10
3708c2ecf20Sopenharmony_ciEND_FTR_SECTION_NESTED(CPU_FTR_EMB_HV,CPU_FTR_EMB_HV,532)
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci	tlbsx	0,r16
3738c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS1
3748c2ecf20Sopenharmony_ci	andis.	r15,r10,MAS1_VALID@h
3758c2ecf20Sopenharmony_ci	bne	tlb_miss_done_e6500
3768c2ecf20Sopenharmony_ciFTR_SECTION_ELSE
3778c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS1
3788c2ecf20Sopenharmony_ciALT_FTR_SECTION_END_IFSET(CPU_FTR_SMT)
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	oris	r10,r10,MAS1_VALID@h
3818c2ecf20Sopenharmony_ci	beq	cr2,4f
3828c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,16,1		/* Clear TID */
3838c2ecf20Sopenharmony_ci4:	mtspr	SPRN_MAS1,r10
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	/* Now, we need to walk the page tables. First check if we are in
3868c2ecf20Sopenharmony_ci	 * range.
3878c2ecf20Sopenharmony_ci	 */
3888c2ecf20Sopenharmony_ci	rldicl.	r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4
3898c2ecf20Sopenharmony_ci	bne-	tlb_miss_fault_e6500
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	rldicl	r15,r16,64-PGDIR_SHIFT+3,64-PGD_INDEX_SIZE-3
3928c2ecf20Sopenharmony_ci	cmpldi	cr0,r14,0
3938c2ecf20Sopenharmony_ci	clrrdi	r15,r15,3
3948c2ecf20Sopenharmony_ci	beq-	tlb_miss_fault_e6500 /* No PGDIR, bail */
3958c2ecf20Sopenharmony_ci	ldx	r14,r14,r15		/* grab pgd entry */
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	rldicl	r15,r16,64-PUD_SHIFT+3,64-PUD_INDEX_SIZE-3
3988c2ecf20Sopenharmony_ci	clrrdi	r15,r15,3
3998c2ecf20Sopenharmony_ci	cmpdi	cr0,r14,0
4008c2ecf20Sopenharmony_ci	bge	tlb_miss_huge_e6500	/* Bad pgd entry or hugepage; bail */
4018c2ecf20Sopenharmony_ci	ldx	r14,r14,r15		/* grab pud entry */
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	rldicl	r15,r16,64-PMD_SHIFT+3,64-PMD_INDEX_SIZE-3
4048c2ecf20Sopenharmony_ci	clrrdi	r15,r15,3
4058c2ecf20Sopenharmony_ci	cmpdi	cr0,r14,0
4068c2ecf20Sopenharmony_ci	bge	tlb_miss_huge_e6500
4078c2ecf20Sopenharmony_ci	ldx	r14,r14,r15		/* Grab pmd entry */
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS0
4108c2ecf20Sopenharmony_ci	cmpdi	cr0,r14,0
4118c2ecf20Sopenharmony_ci	bge	tlb_miss_huge_e6500
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci	/* Now we build the MAS for a 2M indirect page:
4148c2ecf20Sopenharmony_ci	 *
4158c2ecf20Sopenharmony_ci	 * MAS 0   :	ESEL needs to be filled by software round-robin
4168c2ecf20Sopenharmony_ci	 * MAS 1   :	Fully set up
4178c2ecf20Sopenharmony_ci	 *               - PID already updated by caller if necessary
4188c2ecf20Sopenharmony_ci	 *               - TSIZE for now is base ind page size always
4198c2ecf20Sopenharmony_ci	 *               - TID already cleared if necessary
4208c2ecf20Sopenharmony_ci	 * MAS 2   :	Default not 2M-aligned, need to be redone
4218c2ecf20Sopenharmony_ci	 * MAS 3+7 :	Needs to be done
4228c2ecf20Sopenharmony_ci	 */
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	ori	r14,r14,(BOOK3E_PAGESZ_4K << MAS3_SPSIZE_SHIFT)
4258c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7_MAS3,r14
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci	clrrdi	r15,r16,21		/* make EA 2M-aligned */
4288c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS2,r15
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_citlb_miss_huge_done_e6500:
4318c2ecf20Sopenharmony_ci	lbz	r16,TCD_ESEL_MAX(r11)
4328c2ecf20Sopenharmony_ci	lbz	r14,TCD_ESEL_FIRST(r11)
4338c2ecf20Sopenharmony_ci	rlwimi	r10,r7,16,0x00ff0000	/* insert esel_next into MAS0 */
4348c2ecf20Sopenharmony_ci	addi	r7,r7,1			/* increment esel_next */
4358c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS0,r10
4368c2ecf20Sopenharmony_ci	cmpw	r7,r16
4378c2ecf20Sopenharmony_ci	iseleq	r7,r14,r7		/* if next == last use first */
4388c2ecf20Sopenharmony_ci	stb	r7,TCD_ESEL_NEXT(r11)
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	tlbwe
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_citlb_miss_done_e6500:
4438c2ecf20Sopenharmony_ci	.macro	tlb_unlock_e6500
4448c2ecf20Sopenharmony_ciBEGIN_FTR_SECTION
4458c2ecf20Sopenharmony_ci	beq	cr1,1f		/* no unlock if lock was recursively grabbed */
4468c2ecf20Sopenharmony_ci	li	r15,0
4478c2ecf20Sopenharmony_ci	isync
4488c2ecf20Sopenharmony_ci	stb	r15,0(r11)
4498c2ecf20Sopenharmony_ci1:
4508c2ecf20Sopenharmony_ciEND_FTR_SECTION_IFSET(CPU_FTR_SMT)
4518c2ecf20Sopenharmony_ci	.endm
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	tlb_unlock_e6500
4548c2ecf20Sopenharmony_ci	tlb_epilog_bolted
4558c2ecf20Sopenharmony_ci	rfi
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_citlb_miss_huge_e6500:
4588c2ecf20Sopenharmony_ci	beq	tlb_miss_fault_e6500
4598c2ecf20Sopenharmony_ci	li	r10,1
4608c2ecf20Sopenharmony_ci	andi.	r15,r14,HUGEPD_SHIFT_MASK@l /* r15 = psize */
4618c2ecf20Sopenharmony_ci	rldimi	r14,r10,63,0		/* Set PD_HUGE */
4628c2ecf20Sopenharmony_ci	xor	r14,r14,r15		/* Clear size bits */
4638c2ecf20Sopenharmony_ci	ldx	r14,0,r14
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	/*
4668c2ecf20Sopenharmony_ci	 * Now we build the MAS for a huge page.
4678c2ecf20Sopenharmony_ci	 *
4688c2ecf20Sopenharmony_ci	 * MAS 0   :	ESEL needs to be filled by software round-robin
4698c2ecf20Sopenharmony_ci	 *		 - can be handled by indirect code
4708c2ecf20Sopenharmony_ci	 * MAS 1   :	Need to clear IND and set TSIZE
4718c2ecf20Sopenharmony_ci	 * MAS 2,3+7:	Needs to be redone similar to non-tablewalk handler
4728c2ecf20Sopenharmony_ci	 */
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	subi	r15,r15,10		/* Convert psize to tsize */
4758c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS1
4768c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,~MAS1_IND
4778c2ecf20Sopenharmony_ci	rlwimi	r10,r15,MAS1_TSIZE_SHIFT,MAS1_TSIZE_MASK
4788c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r10
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	li	r10,-0x400
4818c2ecf20Sopenharmony_ci	sld	r15,r10,r15		/* Generate mask based on size */
4828c2ecf20Sopenharmony_ci	and	r10,r16,r15
4838c2ecf20Sopenharmony_ci	rldicr	r15,r14,64-(PTE_RPN_SHIFT-PAGE_SHIFT),63-PAGE_SHIFT
4848c2ecf20Sopenharmony_ci	rlwimi	r10,r14,32-19,27,31	/* Insert WIMGE */
4858c2ecf20Sopenharmony_ci	clrldi	r15,r15,PAGE_SHIFT	/* Clear crap at the top */
4868c2ecf20Sopenharmony_ci	rlwimi	r15,r14,32-8,22,25	/* Move in U bits */
4878c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS2,r10
4888c2ecf20Sopenharmony_ci	andi.	r10,r14,_PAGE_DIRTY
4898c2ecf20Sopenharmony_ci	rlwimi	r15,r14,32-2,26,31	/* Move in BAP bits */
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	/* Mask out SW and UW if !DIRTY (XXX optimize this !) */
4928c2ecf20Sopenharmony_ci	bne	1f
4938c2ecf20Sopenharmony_ci	li	r10,MAS3_SW|MAS3_UW
4948c2ecf20Sopenharmony_ci	andc	r15,r15,r10
4958c2ecf20Sopenharmony_ci1:
4968c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7_MAS3,r15
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS0
4998c2ecf20Sopenharmony_ci	b	tlb_miss_huge_done_e6500
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_citlb_miss_kernel_e6500:
5028c2ecf20Sopenharmony_ci	ld	r14,PACA_KERNELPGD(r13)
5038c2ecf20Sopenharmony_ci	cmpldi	cr1,r15,8		/* Check for vmalloc region */
5048c2ecf20Sopenharmony_ci	beq+	cr1,tlb_miss_common_e6500
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_citlb_miss_fault_e6500:
5078c2ecf20Sopenharmony_ci	tlb_unlock_e6500
5088c2ecf20Sopenharmony_ci	/* We need to check if it was an instruction miss */
5098c2ecf20Sopenharmony_ci	andi.	r16,r16,1
5108c2ecf20Sopenharmony_ci	bne	itlb_miss_fault_e6500
5118c2ecf20Sopenharmony_cidtlb_miss_fault_e6500:
5128c2ecf20Sopenharmony_ci	tlb_epilog_bolted
5138c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
5148c2ecf20Sopenharmony_ciitlb_miss_fault_e6500:
5158c2ecf20Sopenharmony_ci	tlb_epilog_bolted
5168c2ecf20Sopenharmony_ci	b	exc_instruction_storage_book3e
5178c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC_FSL_BOOK3E */
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci/**********************************************************************
5208c2ecf20Sopenharmony_ci *                                                                    *
5218c2ecf20Sopenharmony_ci * TLB miss handling for Book3E with TLB reservation and HES support  *
5228c2ecf20Sopenharmony_ci *                                                                    *
5238c2ecf20Sopenharmony_ci **********************************************************************/
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci/* Data TLB miss */
5278c2ecf20Sopenharmony_ci	START_EXCEPTION(data_tlb_miss)
5288c2ecf20Sopenharmony_ci	TLB_MISS_PROLOG
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci	/* Now we handle the fault proper. We only save DEAR in normal
5318c2ecf20Sopenharmony_ci	 * fault case since that's the only interesting values here.
5328c2ecf20Sopenharmony_ci	 * We could probably also optimize by not saving SRR0/1 in the
5338c2ecf20Sopenharmony_ci	 * linear mapping case but I'll leave that for later
5348c2ecf20Sopenharmony_ci	 */
5358c2ecf20Sopenharmony_ci	mfspr	r14,SPRN_ESR
5368c2ecf20Sopenharmony_ci	mfspr	r16,SPRN_DEAR		/* get faulting address */
5378c2ecf20Sopenharmony_ci	srdi	r15,r16,60		/* get region */
5388c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,0xc		/* linear mapping ? */
5398c2ecf20Sopenharmony_ci	beq	tlb_load_linear		/* yes -> go to linear map load */
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci	/* The page tables are mapped virtually linear. At this point, though,
5428c2ecf20Sopenharmony_ci	 * we don't know whether we are trying to fault in a first level
5438c2ecf20Sopenharmony_ci	 * virtual address or a virtual page table address. We can get that
5448c2ecf20Sopenharmony_ci	 * from bit 0x1 of the region ID which we have set for a page table
5458c2ecf20Sopenharmony_ci	 */
5468c2ecf20Sopenharmony_ci	andi.	r10,r15,0x1
5478c2ecf20Sopenharmony_ci	bne-	virt_page_table_tlb_miss
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci	std	r14,EX_TLB_ESR(r12);	/* save ESR */
5508c2ecf20Sopenharmony_ci	std	r16,EX_TLB_DEAR(r12);	/* save DEAR */
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci	 /* We need _PAGE_PRESENT and  _PAGE_ACCESSED set */
5538c2ecf20Sopenharmony_ci	li	r11,_PAGE_PRESENT
5548c2ecf20Sopenharmony_ci	oris	r11,r11,_PAGE_ACCESSED@h
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci	/* We do the user/kernel test for the PID here along with the RW test
5578c2ecf20Sopenharmony_ci	 */
5588c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,0		/* Check for user region */
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci	/* We pre-test some combination of permissions to avoid double
5618c2ecf20Sopenharmony_ci	 * faults:
5628c2ecf20Sopenharmony_ci	 *
5638c2ecf20Sopenharmony_ci	 * We move the ESR:ST bit into the position of _PAGE_BAP_SW in the PTE
5648c2ecf20Sopenharmony_ci	 * ESR_ST   is 0x00800000
5658c2ecf20Sopenharmony_ci	 * _PAGE_BAP_SW is 0x00000010
5668c2ecf20Sopenharmony_ci	 * So the shift is >> 19. This tests for supervisor writeability.
5678c2ecf20Sopenharmony_ci	 * If the page happens to be supervisor writeable and not user
5688c2ecf20Sopenharmony_ci	 * writeable, we will take a new fault later, but that should be
5698c2ecf20Sopenharmony_ci	 * a rare enough case.
5708c2ecf20Sopenharmony_ci	 *
5718c2ecf20Sopenharmony_ci	 * We also move ESR_ST in _PAGE_DIRTY position
5728c2ecf20Sopenharmony_ci	 * _PAGE_DIRTY is 0x00001000 so the shift is >> 11
5738c2ecf20Sopenharmony_ci	 *
5748c2ecf20Sopenharmony_ci	 * MAS1 is preset for all we need except for TID that needs to
5758c2ecf20Sopenharmony_ci	 * be cleared for kernel translations
5768c2ecf20Sopenharmony_ci	 */
5778c2ecf20Sopenharmony_ci	rlwimi	r11,r14,32-19,27,27
5788c2ecf20Sopenharmony_ci	rlwimi	r11,r14,32-16,19,19
5798c2ecf20Sopenharmony_ci	beq	normal_tlb_miss
5808c2ecf20Sopenharmony_ci	/* XXX replace the RMW cycles with immediate loads + writes */
5818c2ecf20Sopenharmony_ci1:	mfspr	r10,SPRN_MAS1
5828c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,8		/* Check for vmalloc region */
5838c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,16,1		/* Clear TID */
5848c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r10
5858c2ecf20Sopenharmony_ci	beq+	normal_tlb_miss
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	/* We got a crappy address, just fault with whatever DEAR and ESR
5888c2ecf20Sopenharmony_ci	 * are here
5898c2ecf20Sopenharmony_ci	 */
5908c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
5918c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci/* Instruction TLB miss */
5948c2ecf20Sopenharmony_ci	START_EXCEPTION(instruction_tlb_miss)
5958c2ecf20Sopenharmony_ci	TLB_MISS_PROLOG
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci	/* If we take a recursive fault, the second level handler may need
5988c2ecf20Sopenharmony_ci	 * to know whether we are handling a data or instruction fault in
5998c2ecf20Sopenharmony_ci	 * order to get to the right store fault handler. We provide that
6008c2ecf20Sopenharmony_ci	 * info by writing a crazy value in ESR in our exception frame
6018c2ecf20Sopenharmony_ci	 */
6028c2ecf20Sopenharmony_ci	li	r14,-1	/* store to exception frame is done later */
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_ci	/* Now we handle the fault proper. We only save DEAR in the non
6058c2ecf20Sopenharmony_ci	 * linear mapping case since we know the linear mapping case will
6068c2ecf20Sopenharmony_ci	 * not re-enter. We could indeed optimize and also not save SRR0/1
6078c2ecf20Sopenharmony_ci	 * in the linear mapping case but I'll leave that for later
6088c2ecf20Sopenharmony_ci	 *
6098c2ecf20Sopenharmony_ci	 * Faulting address is SRR0 which is already in r16
6108c2ecf20Sopenharmony_ci	 */
6118c2ecf20Sopenharmony_ci	srdi	r15,r16,60		/* get region */
6128c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,0xc		/* linear mapping ? */
6138c2ecf20Sopenharmony_ci	beq	tlb_load_linear		/* yes -> go to linear map load */
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_ci	/* We do the user/kernel test for the PID here along with the RW test
6168c2ecf20Sopenharmony_ci	 */
6178c2ecf20Sopenharmony_ci	li	r11,_PAGE_PRESENT|_PAGE_EXEC	/* Base perm */
6188c2ecf20Sopenharmony_ci	oris	r11,r11,_PAGE_ACCESSED@h
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,0			/* Check for user region */
6218c2ecf20Sopenharmony_ci	std	r14,EX_TLB_ESR(r12)		/* write crazy -1 to frame */
6228c2ecf20Sopenharmony_ci	beq	normal_tlb_miss
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci	li	r11,_PAGE_PRESENT|_PAGE_BAP_SX	/* Base perm */
6258c2ecf20Sopenharmony_ci	oris	r11,r11,_PAGE_ACCESSED@h
6268c2ecf20Sopenharmony_ci	/* XXX replace the RMW cycles with immediate loads + writes */
6278c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS1
6288c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,8			/* Check for vmalloc region */
6298c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,16,1			/* Clear TID */
6308c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r10
6318c2ecf20Sopenharmony_ci	beq+	normal_tlb_miss
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	/* We got a crappy address, just fault */
6348c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
6358c2ecf20Sopenharmony_ci	b	exc_instruction_storage_book3e
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci/*
6388c2ecf20Sopenharmony_ci * This is the guts of the first-level TLB miss handler for direct
6398c2ecf20Sopenharmony_ci * misses. We are entered with:
6408c2ecf20Sopenharmony_ci *
6418c2ecf20Sopenharmony_ci * r16 = faulting address
6428c2ecf20Sopenharmony_ci * r15 = region ID
6438c2ecf20Sopenharmony_ci * r14 = crap (free to use)
6448c2ecf20Sopenharmony_ci * r13 = PACA
6458c2ecf20Sopenharmony_ci * r12 = TLB exception frame in PACA
6468c2ecf20Sopenharmony_ci * r11 = PTE permission mask
6478c2ecf20Sopenharmony_ci * r10 = crap (free to use)
6488c2ecf20Sopenharmony_ci */
6498c2ecf20Sopenharmony_cinormal_tlb_miss:
6508c2ecf20Sopenharmony_ci	/* So we first construct the page table address. We do that by
6518c2ecf20Sopenharmony_ci	 * shifting the bottom of the address (not the region ID) by
6528c2ecf20Sopenharmony_ci	 * PAGE_SHIFT-3, clearing the bottom 3 bits (get a PTE ptr) and
6538c2ecf20Sopenharmony_ci	 * or'ing the fourth high bit.
6548c2ecf20Sopenharmony_ci	 *
6558c2ecf20Sopenharmony_ci	 * NOTE: For 64K pages, we do things slightly differently in
6568c2ecf20Sopenharmony_ci	 * order to handle the weird page table format used by linux
6578c2ecf20Sopenharmony_ci	 */
6588c2ecf20Sopenharmony_ci	ori	r10,r15,0x1
6598c2ecf20Sopenharmony_ci	rldicl	r14,r16,64-(PAGE_SHIFT-3),PAGE_SHIFT-3+4
6608c2ecf20Sopenharmony_ci	sldi	r15,r10,60
6618c2ecf20Sopenharmony_ci	clrrdi	r14,r14,3
6628c2ecf20Sopenharmony_ci	or	r10,r15,r14
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_ciBEGIN_MMU_FTR_SECTION
6658c2ecf20Sopenharmony_ci	/* Set the TLB reservation and search for existing entry. Then load
6668c2ecf20Sopenharmony_ci	 * the entry.
6678c2ecf20Sopenharmony_ci	 */
6688c2ecf20Sopenharmony_ci	PPC_TLBSRX_DOT(0,R16)
6698c2ecf20Sopenharmony_ci	ld	r14,0(r10)
6708c2ecf20Sopenharmony_ci	beq	normal_tlb_miss_done
6718c2ecf20Sopenharmony_ciMMU_FTR_SECTION_ELSE
6728c2ecf20Sopenharmony_ci	ld	r14,0(r10)
6738c2ecf20Sopenharmony_ciALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBRSRV)
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_cifinish_normal_tlb_miss:
6768c2ecf20Sopenharmony_ci	/* Check if required permissions are met */
6778c2ecf20Sopenharmony_ci	andc.	r15,r11,r14
6788c2ecf20Sopenharmony_ci	bne-	normal_tlb_miss_access_fault
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci	/* Now we build the MAS:
6818c2ecf20Sopenharmony_ci	 *
6828c2ecf20Sopenharmony_ci	 * MAS 0   :	Fully setup with defaults in MAS4 and TLBnCFG
6838c2ecf20Sopenharmony_ci	 * MAS 1   :	Almost fully setup
6848c2ecf20Sopenharmony_ci	 *               - PID already updated by caller if necessary
6858c2ecf20Sopenharmony_ci	 *               - TSIZE need change if !base page size, not
6868c2ecf20Sopenharmony_ci	 *                 yet implemented for now
6878c2ecf20Sopenharmony_ci	 * MAS 2   :	Defaults not useful, need to be redone
6888c2ecf20Sopenharmony_ci	 * MAS 3+7 :	Needs to be done
6898c2ecf20Sopenharmony_ci	 *
6908c2ecf20Sopenharmony_ci	 * TODO: mix up code below for better scheduling
6918c2ecf20Sopenharmony_ci	 */
6928c2ecf20Sopenharmony_ci	clrrdi	r11,r16,12		/* Clear low crap in EA */
6938c2ecf20Sopenharmony_ci	rlwimi	r11,r14,32-19,27,31	/* Insert WIMGE */
6948c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS2,r11
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	/* Check page size, if not standard, update MAS1 */
6978c2ecf20Sopenharmony_ci	rldicl	r11,r14,64-8,64-8
6988c2ecf20Sopenharmony_ci	cmpldi	cr0,r11,BOOK3E_PAGESZ_4K
6998c2ecf20Sopenharmony_ci	beq-	1f
7008c2ecf20Sopenharmony_ci	mfspr	r11,SPRN_MAS1
7018c2ecf20Sopenharmony_ci	rlwimi	r11,r14,31,21,24
7028c2ecf20Sopenharmony_ci	rlwinm	r11,r11,0,21,19
7038c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r11
7048c2ecf20Sopenharmony_ci1:
7058c2ecf20Sopenharmony_ci	/* Move RPN in position */
7068c2ecf20Sopenharmony_ci	rldicr	r11,r14,64-(PTE_RPN_SHIFT-PAGE_SHIFT),63-PAGE_SHIFT
7078c2ecf20Sopenharmony_ci	clrldi	r15,r11,12		/* Clear crap at the top */
7088c2ecf20Sopenharmony_ci	rlwimi	r15,r14,32-8,22,25	/* Move in U bits */
7098c2ecf20Sopenharmony_ci	rlwimi	r15,r14,32-2,26,31	/* Move in BAP bits */
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci	/* Mask out SW and UW if !DIRTY (XXX optimize this !) */
7128c2ecf20Sopenharmony_ci	andi.	r11,r14,_PAGE_DIRTY
7138c2ecf20Sopenharmony_ci	bne	1f
7148c2ecf20Sopenharmony_ci	li	r11,MAS3_SW|MAS3_UW
7158c2ecf20Sopenharmony_ci	andc	r15,r15,r11
7168c2ecf20Sopenharmony_ci1:
7178c2ecf20Sopenharmony_ciBEGIN_MMU_FTR_SECTION
7188c2ecf20Sopenharmony_ci	srdi	r16,r15,32
7198c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS3,r15
7208c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7,r16
7218c2ecf20Sopenharmony_ciMMU_FTR_SECTION_ELSE
7228c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7_MAS3,r15
7238c2ecf20Sopenharmony_ciALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci	tlbwe
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_cinormal_tlb_miss_done:
7288c2ecf20Sopenharmony_ci	/* We don't bother with restoring DEAR or ESR since we know we are
7298c2ecf20Sopenharmony_ci	 * level 0 and just going back to userland. They are only needed
7308c2ecf20Sopenharmony_ci	 * if you are going to take an access fault
7318c2ecf20Sopenharmony_ci	 */
7328c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_SUCCESS
7338c2ecf20Sopenharmony_ci	rfi
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_cinormal_tlb_miss_access_fault:
7368c2ecf20Sopenharmony_ci	/* We need to check if it was an instruction miss */
7378c2ecf20Sopenharmony_ci	andi.	r10,r11,_PAGE_EXEC
7388c2ecf20Sopenharmony_ci	bne	1f
7398c2ecf20Sopenharmony_ci	ld	r14,EX_TLB_DEAR(r12)
7408c2ecf20Sopenharmony_ci	ld	r15,EX_TLB_ESR(r12)
7418c2ecf20Sopenharmony_ci	mtspr	SPRN_DEAR,r14
7428c2ecf20Sopenharmony_ci	mtspr	SPRN_ESR,r15
7438c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
7448c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
7458c2ecf20Sopenharmony_ci1:	TLB_MISS_EPILOG_ERROR
7468c2ecf20Sopenharmony_ci	b	exc_instruction_storage_book3e
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci/*
7508c2ecf20Sopenharmony_ci * This is the guts of the second-level TLB miss handler for direct
7518c2ecf20Sopenharmony_ci * misses. We are entered with:
7528c2ecf20Sopenharmony_ci *
7538c2ecf20Sopenharmony_ci * r16 = virtual page table faulting address
7548c2ecf20Sopenharmony_ci * r15 = region (top 4 bits of address)
7558c2ecf20Sopenharmony_ci * r14 = crap (free to use)
7568c2ecf20Sopenharmony_ci * r13 = PACA
7578c2ecf20Sopenharmony_ci * r12 = TLB exception frame in PACA
7588c2ecf20Sopenharmony_ci * r11 = crap (free to use)
7598c2ecf20Sopenharmony_ci * r10 = crap (free to use)
7608c2ecf20Sopenharmony_ci *
7618c2ecf20Sopenharmony_ci * Note that this should only ever be called as a second level handler
7628c2ecf20Sopenharmony_ci * with the current scheme when using SW load.
7638c2ecf20Sopenharmony_ci * That means we can always get the original fault DEAR at
7648c2ecf20Sopenharmony_ci * EX_TLB_DEAR-EX_TLB_SIZE(r12)
7658c2ecf20Sopenharmony_ci *
7668c2ecf20Sopenharmony_ci * It can be re-entered by the linear mapping miss handler. However, to
7678c2ecf20Sopenharmony_ci * avoid too much complication, it will restart the whole fault at level
7688c2ecf20Sopenharmony_ci * 0 so we don't care too much about clobbers
7698c2ecf20Sopenharmony_ci *
7708c2ecf20Sopenharmony_ci * XXX That code was written back when we couldn't clobber r14. We can now,
7718c2ecf20Sopenharmony_ci * so we could probably optimize things a bit
7728c2ecf20Sopenharmony_ci */
7738c2ecf20Sopenharmony_civirt_page_table_tlb_miss:
7748c2ecf20Sopenharmony_ci	/* Are we hitting a kernel page table ? */
7758c2ecf20Sopenharmony_ci	andi.	r10,r15,0x8
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	/* The cool thing now is that r10 contains 0 for user and 8 for kernel,
7788c2ecf20Sopenharmony_ci	 * and we happen to have the swapper_pg_dir at offset 8 from the user
7798c2ecf20Sopenharmony_ci	 * pgdir in the PACA :-).
7808c2ecf20Sopenharmony_ci	 */
7818c2ecf20Sopenharmony_ci	add	r11,r10,r13
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	/* If kernel, we need to clear MAS1 TID */
7848c2ecf20Sopenharmony_ci	beq	1f
7858c2ecf20Sopenharmony_ci	/* XXX replace the RMW cycles with immediate loads + writes */
7868c2ecf20Sopenharmony_ci	mfspr	r10,SPRN_MAS1
7878c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,16,1			/* Clear TID */
7888c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r10
7898c2ecf20Sopenharmony_ci1:
7908c2ecf20Sopenharmony_ciBEGIN_MMU_FTR_SECTION
7918c2ecf20Sopenharmony_ci	/* Search if we already have a TLB entry for that virtual address, and
7928c2ecf20Sopenharmony_ci	 * if we do, bail out.
7938c2ecf20Sopenharmony_ci	 */
7948c2ecf20Sopenharmony_ci	PPC_TLBSRX_DOT(0,R16)
7958c2ecf20Sopenharmony_ci	beq	virt_page_table_tlb_miss_done
7968c2ecf20Sopenharmony_ciEND_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_TLBRSRV)
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci	/* Now, we need to walk the page tables. First check if we are in
7998c2ecf20Sopenharmony_ci	 * range.
8008c2ecf20Sopenharmony_ci	 */
8018c2ecf20Sopenharmony_ci	rldicl.	r10,r16,64-(VPTE_INDEX_SIZE+3),VPTE_INDEX_SIZE+3+4
8028c2ecf20Sopenharmony_ci	bne-	virt_page_table_tlb_miss_fault
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci	/* Get the PGD pointer */
8058c2ecf20Sopenharmony_ci	ld	r15,PACAPGD(r11)
8068c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,0
8078c2ecf20Sopenharmony_ci	beq-	virt_page_table_tlb_miss_fault
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci	/* Get to PGD entry */
8108c2ecf20Sopenharmony_ci	rldicl	r11,r16,64-VPTE_PGD_SHIFT,64-PGD_INDEX_SIZE-3
8118c2ecf20Sopenharmony_ci	clrrdi	r10,r11,3
8128c2ecf20Sopenharmony_ci	ldx	r15,r10,r15
8138c2ecf20Sopenharmony_ci	cmpdi	cr0,r15,0
8148c2ecf20Sopenharmony_ci	bge	virt_page_table_tlb_miss_fault
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	/* Get to PUD entry */
8178c2ecf20Sopenharmony_ci	rldicl	r11,r16,64-VPTE_PUD_SHIFT,64-PUD_INDEX_SIZE-3
8188c2ecf20Sopenharmony_ci	clrrdi	r10,r11,3
8198c2ecf20Sopenharmony_ci	ldx	r15,r10,r15
8208c2ecf20Sopenharmony_ci	cmpdi	cr0,r15,0
8218c2ecf20Sopenharmony_ci	bge	virt_page_table_tlb_miss_fault
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_ci	/* Get to PMD entry */
8248c2ecf20Sopenharmony_ci	rldicl	r11,r16,64-VPTE_PMD_SHIFT,64-PMD_INDEX_SIZE-3
8258c2ecf20Sopenharmony_ci	clrrdi	r10,r11,3
8268c2ecf20Sopenharmony_ci	ldx	r15,r10,r15
8278c2ecf20Sopenharmony_ci	cmpdi	cr0,r15,0
8288c2ecf20Sopenharmony_ci	bge	virt_page_table_tlb_miss_fault
8298c2ecf20Sopenharmony_ci
8308c2ecf20Sopenharmony_ci	/* Ok, we're all right, we can now create a kernel translation for
8318c2ecf20Sopenharmony_ci	 * a 4K or 64K page from r16 -> r15.
8328c2ecf20Sopenharmony_ci	 */
8338c2ecf20Sopenharmony_ci	/* Now we build the MAS:
8348c2ecf20Sopenharmony_ci	 *
8358c2ecf20Sopenharmony_ci	 * MAS 0   :	Fully setup with defaults in MAS4 and TLBnCFG
8368c2ecf20Sopenharmony_ci	 * MAS 1   :	Almost fully setup
8378c2ecf20Sopenharmony_ci	 *               - PID already updated by caller if necessary
8388c2ecf20Sopenharmony_ci	 *               - TSIZE for now is base page size always
8398c2ecf20Sopenharmony_ci	 * MAS 2   :	Use defaults
8408c2ecf20Sopenharmony_ci	 * MAS 3+7 :	Needs to be done
8418c2ecf20Sopenharmony_ci	 *
8428c2ecf20Sopenharmony_ci	 * So we only do MAS 2 and 3 for now...
8438c2ecf20Sopenharmony_ci	 */
8448c2ecf20Sopenharmony_ci	clrldi	r11,r15,4		/* remove region ID from RPN */
8458c2ecf20Sopenharmony_ci	ori	r10,r11,1		/* Or-in SR */
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ciBEGIN_MMU_FTR_SECTION
8488c2ecf20Sopenharmony_ci	srdi	r16,r10,32
8498c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS3,r10
8508c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7,r16
8518c2ecf20Sopenharmony_ciMMU_FTR_SECTION_ELSE
8528c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7_MAS3,r10
8538c2ecf20Sopenharmony_ciALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	tlbwe
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_ciBEGIN_MMU_FTR_SECTION
8588c2ecf20Sopenharmony_civirt_page_table_tlb_miss_done:
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci	/* We have overridden MAS2:EPN but currently our primary TLB miss
8618c2ecf20Sopenharmony_ci	 * handler will always restore it so that should not be an issue,
8628c2ecf20Sopenharmony_ci	 * if we ever optimize the primary handler to not write MAS2 on
8638c2ecf20Sopenharmony_ci	 * some cases, we'll have to restore MAS2:EPN here based on the
8648c2ecf20Sopenharmony_ci	 * original fault's DEAR. If we do that we have to modify the
8658c2ecf20Sopenharmony_ci	 * ITLB miss handler to also store SRR0 in the exception frame
8668c2ecf20Sopenharmony_ci	 * as DEAR.
8678c2ecf20Sopenharmony_ci	 *
8688c2ecf20Sopenharmony_ci	 * However, one nasty thing we did is we cleared the reservation
8698c2ecf20Sopenharmony_ci	 * (well, potentially we did). We do a trick here thus if we
8708c2ecf20Sopenharmony_ci	 * are not a level 0 exception (we interrupted the TLB miss) we
8718c2ecf20Sopenharmony_ci	 * offset the return address by -4 in order to replay the tlbsrx
8728c2ecf20Sopenharmony_ci	 * instruction there
8738c2ecf20Sopenharmony_ci	 */
8748c2ecf20Sopenharmony_ci	subf	r10,r13,r12
8758c2ecf20Sopenharmony_ci	cmpldi	cr0,r10,PACA_EXTLB+EX_TLB_SIZE
8768c2ecf20Sopenharmony_ci	bne-	1f
8778c2ecf20Sopenharmony_ci	ld	r11,PACA_EXTLB+EX_TLB_SIZE+EX_TLB_SRR0(r13)
8788c2ecf20Sopenharmony_ci	addi	r10,r11,-4
8798c2ecf20Sopenharmony_ci	std	r10,PACA_EXTLB+EX_TLB_SIZE+EX_TLB_SRR0(r13)
8808c2ecf20Sopenharmony_ci1:
8818c2ecf20Sopenharmony_ciEND_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_TLBRSRV)
8828c2ecf20Sopenharmony_ci	/* Return to caller, normal case */
8838c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_SUCCESS
8848c2ecf20Sopenharmony_ci	rfi
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_civirt_page_table_tlb_miss_fault:
8878c2ecf20Sopenharmony_ci	/* If we fault here, things are a little bit tricky. We need to call
8888c2ecf20Sopenharmony_ci	 * either data or instruction store fault, and we need to retrieve
8898c2ecf20Sopenharmony_ci	 * the original fault address and ESR (for data).
8908c2ecf20Sopenharmony_ci	 *
8918c2ecf20Sopenharmony_ci	 * The thing is, we know that in normal circumstances, this is
8928c2ecf20Sopenharmony_ci	 * always called as a second level tlb miss for SW load or as a first
8938c2ecf20Sopenharmony_ci	 * level TLB miss for HW load, so we should be able to peek at the
8948c2ecf20Sopenharmony_ci	 * relevant information in the first exception frame in the PACA.
8958c2ecf20Sopenharmony_ci	 *
8968c2ecf20Sopenharmony_ci	 * However, we do need to double check that, because we may just hit
8978c2ecf20Sopenharmony_ci	 * a stray kernel pointer or a userland attack trying to hit those
8988c2ecf20Sopenharmony_ci	 * areas. If that is the case, we do a data fault. (We can't get here
8998c2ecf20Sopenharmony_ci	 * from an instruction tlb miss anyway).
9008c2ecf20Sopenharmony_ci	 *
9018c2ecf20Sopenharmony_ci	 * Note also that when going to a fault, we must unwind the previous
9028c2ecf20Sopenharmony_ci	 * level as well. Since we are doing that, we don't need to clear or
9038c2ecf20Sopenharmony_ci	 * restore the TLB reservation neither.
9048c2ecf20Sopenharmony_ci	 */
9058c2ecf20Sopenharmony_ci	subf	r10,r13,r12
9068c2ecf20Sopenharmony_ci	cmpldi	cr0,r10,PACA_EXTLB+EX_TLB_SIZE
9078c2ecf20Sopenharmony_ci	bne-	virt_page_table_tlb_miss_whacko_fault
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci	/* We dig the original DEAR and ESR from slot 0 */
9108c2ecf20Sopenharmony_ci	ld	r15,EX_TLB_DEAR+PACA_EXTLB(r13)
9118c2ecf20Sopenharmony_ci	ld	r16,EX_TLB_ESR+PACA_EXTLB(r13)
9128c2ecf20Sopenharmony_ci
9138c2ecf20Sopenharmony_ci	/* We check for the "special" ESR value for instruction faults */
9148c2ecf20Sopenharmony_ci	cmpdi	cr0,r16,-1
9158c2ecf20Sopenharmony_ci	beq	1f
9168c2ecf20Sopenharmony_ci	mtspr	SPRN_DEAR,r15
9178c2ecf20Sopenharmony_ci	mtspr	SPRN_ESR,r16
9188c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
9198c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
9208c2ecf20Sopenharmony_ci1:	TLB_MISS_EPILOG_ERROR
9218c2ecf20Sopenharmony_ci	b	exc_instruction_storage_book3e
9228c2ecf20Sopenharmony_ci
9238c2ecf20Sopenharmony_civirt_page_table_tlb_miss_whacko_fault:
9248c2ecf20Sopenharmony_ci	/* The linear fault will restart everything so ESR and DEAR will
9258c2ecf20Sopenharmony_ci	 * not have been clobbered, let's just fault with what we have
9268c2ecf20Sopenharmony_ci	 */
9278c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
9288c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
9298c2ecf20Sopenharmony_ci
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ci/**************************************************************
9328c2ecf20Sopenharmony_ci *                                                            *
9338c2ecf20Sopenharmony_ci * TLB miss handling for Book3E with hw page table support    *
9348c2ecf20Sopenharmony_ci *                                                            *
9358c2ecf20Sopenharmony_ci **************************************************************/
9368c2ecf20Sopenharmony_ci
9378c2ecf20Sopenharmony_ci
9388c2ecf20Sopenharmony_ci/* Data TLB miss */
9398c2ecf20Sopenharmony_ci	START_EXCEPTION(data_tlb_miss_htw)
9408c2ecf20Sopenharmony_ci	TLB_MISS_PROLOG
9418c2ecf20Sopenharmony_ci
9428c2ecf20Sopenharmony_ci	/* Now we handle the fault proper. We only save DEAR in normal
9438c2ecf20Sopenharmony_ci	 * fault case since that's the only interesting values here.
9448c2ecf20Sopenharmony_ci	 * We could probably also optimize by not saving SRR0/1 in the
9458c2ecf20Sopenharmony_ci	 * linear mapping case but I'll leave that for later
9468c2ecf20Sopenharmony_ci	 */
9478c2ecf20Sopenharmony_ci	mfspr	r14,SPRN_ESR
9488c2ecf20Sopenharmony_ci	mfspr	r16,SPRN_DEAR		/* get faulting address */
9498c2ecf20Sopenharmony_ci	srdi	r11,r16,60		/* get region */
9508c2ecf20Sopenharmony_ci	cmpldi	cr0,r11,0xc		/* linear mapping ? */
9518c2ecf20Sopenharmony_ci	beq	tlb_load_linear		/* yes -> go to linear map load */
9528c2ecf20Sopenharmony_ci
9538c2ecf20Sopenharmony_ci	/* We do the user/kernel test for the PID here along with the RW test
9548c2ecf20Sopenharmony_ci	 */
9558c2ecf20Sopenharmony_ci	cmpldi	cr0,r11,0		/* Check for user region */
9568c2ecf20Sopenharmony_ci	ld	r15,PACAPGD(r13)	/* Load user pgdir */
9578c2ecf20Sopenharmony_ci	beq	htw_tlb_miss
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ci	/* XXX replace the RMW cycles with immediate loads + writes */
9608c2ecf20Sopenharmony_ci1:	mfspr	r10,SPRN_MAS1
9618c2ecf20Sopenharmony_ci	cmpldi	cr0,r11,8		/* Check for vmalloc region */
9628c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,16,1		/* Clear TID */
9638c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r10
9648c2ecf20Sopenharmony_ci	ld	r15,PACA_KERNELPGD(r13)	/* Load kernel pgdir */
9658c2ecf20Sopenharmony_ci	beq+	htw_tlb_miss
9668c2ecf20Sopenharmony_ci
9678c2ecf20Sopenharmony_ci	/* We got a crappy address, just fault with whatever DEAR and ESR
9688c2ecf20Sopenharmony_ci	 * are here
9698c2ecf20Sopenharmony_ci	 */
9708c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
9718c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_ci/* Instruction TLB miss */
9748c2ecf20Sopenharmony_ci	START_EXCEPTION(instruction_tlb_miss_htw)
9758c2ecf20Sopenharmony_ci	TLB_MISS_PROLOG
9768c2ecf20Sopenharmony_ci
9778c2ecf20Sopenharmony_ci	/* If we take a recursive fault, the second level handler may need
9788c2ecf20Sopenharmony_ci	 * to know whether we are handling a data or instruction fault in
9798c2ecf20Sopenharmony_ci	 * order to get to the right store fault handler. We provide that
9808c2ecf20Sopenharmony_ci	 * info by keeping a crazy value for ESR in r14
9818c2ecf20Sopenharmony_ci	 */
9828c2ecf20Sopenharmony_ci	li	r14,-1	/* store to exception frame is done later */
9838c2ecf20Sopenharmony_ci
9848c2ecf20Sopenharmony_ci	/* Now we handle the fault proper. We only save DEAR in the non
9858c2ecf20Sopenharmony_ci	 * linear mapping case since we know the linear mapping case will
9868c2ecf20Sopenharmony_ci	 * not re-enter. We could indeed optimize and also not save SRR0/1
9878c2ecf20Sopenharmony_ci	 * in the linear mapping case but I'll leave that for later
9888c2ecf20Sopenharmony_ci	 *
9898c2ecf20Sopenharmony_ci	 * Faulting address is SRR0 which is already in r16
9908c2ecf20Sopenharmony_ci	 */
9918c2ecf20Sopenharmony_ci	srdi	r11,r16,60		/* get region */
9928c2ecf20Sopenharmony_ci	cmpldi	cr0,r11,0xc		/* linear mapping ? */
9938c2ecf20Sopenharmony_ci	beq	tlb_load_linear		/* yes -> go to linear map load */
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci	/* We do the user/kernel test for the PID here along with the RW test
9968c2ecf20Sopenharmony_ci	 */
9978c2ecf20Sopenharmony_ci	cmpldi	cr0,r11,0			/* Check for user region */
9988c2ecf20Sopenharmony_ci	ld	r15,PACAPGD(r13)		/* Load user pgdir */
9998c2ecf20Sopenharmony_ci	beq	htw_tlb_miss
10008c2ecf20Sopenharmony_ci
10018c2ecf20Sopenharmony_ci	/* XXX replace the RMW cycles with immediate loads + writes */
10028c2ecf20Sopenharmony_ci1:	mfspr	r10,SPRN_MAS1
10038c2ecf20Sopenharmony_ci	cmpldi	cr0,r11,8			/* Check for vmalloc region */
10048c2ecf20Sopenharmony_ci	rlwinm	r10,r10,0,16,1			/* Clear TID */
10058c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r10
10068c2ecf20Sopenharmony_ci	ld	r15,PACA_KERNELPGD(r13)		/* Load kernel pgdir */
10078c2ecf20Sopenharmony_ci	beq+	htw_tlb_miss
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_ci	/* We got a crappy address, just fault */
10108c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
10118c2ecf20Sopenharmony_ci	b	exc_instruction_storage_book3e
10128c2ecf20Sopenharmony_ci
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_ci/*
10158c2ecf20Sopenharmony_ci * This is the guts of the second-level TLB miss handler for direct
10168c2ecf20Sopenharmony_ci * misses. We are entered with:
10178c2ecf20Sopenharmony_ci *
10188c2ecf20Sopenharmony_ci * r16 = virtual page table faulting address
10198c2ecf20Sopenharmony_ci * r15 = PGD pointer
10208c2ecf20Sopenharmony_ci * r14 = ESR
10218c2ecf20Sopenharmony_ci * r13 = PACA
10228c2ecf20Sopenharmony_ci * r12 = TLB exception frame in PACA
10238c2ecf20Sopenharmony_ci * r11 = crap (free to use)
10248c2ecf20Sopenharmony_ci * r10 = crap (free to use)
10258c2ecf20Sopenharmony_ci *
10268c2ecf20Sopenharmony_ci * It can be re-entered by the linear mapping miss handler. However, to
10278c2ecf20Sopenharmony_ci * avoid too much complication, it will save/restore things for us
10288c2ecf20Sopenharmony_ci */
10298c2ecf20Sopenharmony_cihtw_tlb_miss:
10308c2ecf20Sopenharmony_ci	/* Search if we already have a TLB entry for that virtual address, and
10318c2ecf20Sopenharmony_ci	 * if we do, bail out.
10328c2ecf20Sopenharmony_ci	 *
10338c2ecf20Sopenharmony_ci	 * MAS1:IND should be already set based on MAS4
10348c2ecf20Sopenharmony_ci	 */
10358c2ecf20Sopenharmony_ci	PPC_TLBSRX_DOT(0,R16)
10368c2ecf20Sopenharmony_ci	beq	htw_tlb_miss_done
10378c2ecf20Sopenharmony_ci
10388c2ecf20Sopenharmony_ci	/* Now, we need to walk the page tables. First check if we are in
10398c2ecf20Sopenharmony_ci	 * range.
10408c2ecf20Sopenharmony_ci	 */
10418c2ecf20Sopenharmony_ci	rldicl.	r10,r16,64-PGTABLE_EADDR_SIZE,PGTABLE_EADDR_SIZE+4
10428c2ecf20Sopenharmony_ci	bne-	htw_tlb_miss_fault
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_ci	/* Get the PGD pointer */
10458c2ecf20Sopenharmony_ci	cmpldi	cr0,r15,0
10468c2ecf20Sopenharmony_ci	beq-	htw_tlb_miss_fault
10478c2ecf20Sopenharmony_ci
10488c2ecf20Sopenharmony_ci	/* Get to PGD entry */
10498c2ecf20Sopenharmony_ci	rldicl	r11,r16,64-(PGDIR_SHIFT-3),64-PGD_INDEX_SIZE-3
10508c2ecf20Sopenharmony_ci	clrrdi	r10,r11,3
10518c2ecf20Sopenharmony_ci	ldx	r15,r10,r15
10528c2ecf20Sopenharmony_ci	cmpdi	cr0,r15,0
10538c2ecf20Sopenharmony_ci	bge	htw_tlb_miss_fault
10548c2ecf20Sopenharmony_ci
10558c2ecf20Sopenharmony_ci	/* Get to PUD entry */
10568c2ecf20Sopenharmony_ci	rldicl	r11,r16,64-(PUD_SHIFT-3),64-PUD_INDEX_SIZE-3
10578c2ecf20Sopenharmony_ci	clrrdi	r10,r11,3
10588c2ecf20Sopenharmony_ci	ldx	r15,r10,r15
10598c2ecf20Sopenharmony_ci	cmpdi	cr0,r15,0
10608c2ecf20Sopenharmony_ci	bge	htw_tlb_miss_fault
10618c2ecf20Sopenharmony_ci
10628c2ecf20Sopenharmony_ci	/* Get to PMD entry */
10638c2ecf20Sopenharmony_ci	rldicl	r11,r16,64-(PMD_SHIFT-3),64-PMD_INDEX_SIZE-3
10648c2ecf20Sopenharmony_ci	clrrdi	r10,r11,3
10658c2ecf20Sopenharmony_ci	ldx	r15,r10,r15
10668c2ecf20Sopenharmony_ci	cmpdi	cr0,r15,0
10678c2ecf20Sopenharmony_ci	bge	htw_tlb_miss_fault
10688c2ecf20Sopenharmony_ci
10698c2ecf20Sopenharmony_ci	/* Ok, we're all right, we can now create an indirect entry for
10708c2ecf20Sopenharmony_ci	 * a 1M or 256M page.
10718c2ecf20Sopenharmony_ci	 *
10728c2ecf20Sopenharmony_ci	 * The last trick is now that because we use "half" pages for
10738c2ecf20Sopenharmony_ci	 * the HTW (1M IND is 2K and 256M IND is 32K) we need to account
10748c2ecf20Sopenharmony_ci	 * for an added LSB bit to the RPN. For 64K pages, there is no
10758c2ecf20Sopenharmony_ci	 * problem as we already use 32K arrays (half PTE pages), but for
10768c2ecf20Sopenharmony_ci	 * 4K page we need to extract a bit from the virtual address and
10778c2ecf20Sopenharmony_ci	 * insert it into the "PA52" bit of the RPN.
10788c2ecf20Sopenharmony_ci	 */
10798c2ecf20Sopenharmony_ci	rlwimi	r15,r16,32-9,20,20
10808c2ecf20Sopenharmony_ci	/* Now we build the MAS:
10818c2ecf20Sopenharmony_ci	 *
10828c2ecf20Sopenharmony_ci	 * MAS 0   :	Fully setup with defaults in MAS4 and TLBnCFG
10838c2ecf20Sopenharmony_ci	 * MAS 1   :	Almost fully setup
10848c2ecf20Sopenharmony_ci	 *               - PID already updated by caller if necessary
10858c2ecf20Sopenharmony_ci	 *               - TSIZE for now is base ind page size always
10868c2ecf20Sopenharmony_ci	 * MAS 2   :	Use defaults
10878c2ecf20Sopenharmony_ci	 * MAS 3+7 :	Needs to be done
10888c2ecf20Sopenharmony_ci	 */
10898c2ecf20Sopenharmony_ci	ori	r10,r15,(BOOK3E_PAGESZ_4K << MAS3_SPSIZE_SHIFT)
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ciBEGIN_MMU_FTR_SECTION
10928c2ecf20Sopenharmony_ci	srdi	r16,r10,32
10938c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS3,r10
10948c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7,r16
10958c2ecf20Sopenharmony_ciMMU_FTR_SECTION_ELSE
10968c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7_MAS3,r10
10978c2ecf20Sopenharmony_ciALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)
10988c2ecf20Sopenharmony_ci
10998c2ecf20Sopenharmony_ci	tlbwe
11008c2ecf20Sopenharmony_ci
11018c2ecf20Sopenharmony_cihtw_tlb_miss_done:
11028c2ecf20Sopenharmony_ci	/* We don't bother with restoring DEAR or ESR since we know we are
11038c2ecf20Sopenharmony_ci	 * level 0 and just going back to userland. They are only needed
11048c2ecf20Sopenharmony_ci	 * if you are going to take an access fault
11058c2ecf20Sopenharmony_ci	 */
11068c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_SUCCESS
11078c2ecf20Sopenharmony_ci	rfi
11088c2ecf20Sopenharmony_ci
11098c2ecf20Sopenharmony_cihtw_tlb_miss_fault:
11108c2ecf20Sopenharmony_ci	/* We need to check if it was an instruction miss. We know this
11118c2ecf20Sopenharmony_ci	 * though because r14 would contain -1
11128c2ecf20Sopenharmony_ci	 */
11138c2ecf20Sopenharmony_ci	cmpdi	cr0,r14,-1
11148c2ecf20Sopenharmony_ci	beq	1f
11158c2ecf20Sopenharmony_ci	mtspr	SPRN_DEAR,r16
11168c2ecf20Sopenharmony_ci	mtspr	SPRN_ESR,r14
11178c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
11188c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
11198c2ecf20Sopenharmony_ci1:	TLB_MISS_EPILOG_ERROR
11208c2ecf20Sopenharmony_ci	b	exc_instruction_storage_book3e
11218c2ecf20Sopenharmony_ci
11228c2ecf20Sopenharmony_ci/*
11238c2ecf20Sopenharmony_ci * This is the guts of "any" level TLB miss handler for kernel linear
11248c2ecf20Sopenharmony_ci * mapping misses. We are entered with:
11258c2ecf20Sopenharmony_ci *
11268c2ecf20Sopenharmony_ci *
11278c2ecf20Sopenharmony_ci * r16 = faulting address
11288c2ecf20Sopenharmony_ci * r15 = crap (free to use)
11298c2ecf20Sopenharmony_ci * r14 = ESR (data) or -1 (instruction)
11308c2ecf20Sopenharmony_ci * r13 = PACA
11318c2ecf20Sopenharmony_ci * r12 = TLB exception frame in PACA
11328c2ecf20Sopenharmony_ci * r11 = crap (free to use)
11338c2ecf20Sopenharmony_ci * r10 = crap (free to use)
11348c2ecf20Sopenharmony_ci *
11358c2ecf20Sopenharmony_ci * In addition we know that we will not re-enter, so in theory, we could
11368c2ecf20Sopenharmony_ci * use a simpler epilog not restoring SRR0/1 etc.. but we'll do that later.
11378c2ecf20Sopenharmony_ci *
11388c2ecf20Sopenharmony_ci * We also need to be careful about MAS registers here & TLB reservation,
11398c2ecf20Sopenharmony_ci * as we know we'll have clobbered them if we interrupt the main TLB miss
11408c2ecf20Sopenharmony_ci * handlers in which case we probably want to do a full restart at level
11418c2ecf20Sopenharmony_ci * 0 rather than saving / restoring the MAS.
11428c2ecf20Sopenharmony_ci *
11438c2ecf20Sopenharmony_ci * Note: If we care about performance of that core, we can easily shuffle
11448c2ecf20Sopenharmony_ci *       a few things around
11458c2ecf20Sopenharmony_ci */
11468c2ecf20Sopenharmony_citlb_load_linear:
11478c2ecf20Sopenharmony_ci	/* For now, we assume the linear mapping is contiguous and stops at
11488c2ecf20Sopenharmony_ci	 * linear_map_top. We also assume the size is a multiple of 1G, thus
11498c2ecf20Sopenharmony_ci	 * we only use 1G pages for now. That might have to be changed in a
11508c2ecf20Sopenharmony_ci	 * final implementation, especially when dealing with hypervisors
11518c2ecf20Sopenharmony_ci	 */
11528c2ecf20Sopenharmony_ci	ld	r11,PACATOC(r13)
11538c2ecf20Sopenharmony_ci	ld	r11,linear_map_top@got(r11)
11548c2ecf20Sopenharmony_ci	ld	r10,0(r11)
11558c2ecf20Sopenharmony_ci	tovirt(10,10)
11568c2ecf20Sopenharmony_ci	cmpld	cr0,r16,r10
11578c2ecf20Sopenharmony_ci	bge	tlb_load_linear_fault
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci	/* MAS1 need whole new setup. */
11608c2ecf20Sopenharmony_ci	li	r15,(BOOK3E_PAGESZ_1GB<<MAS1_TSIZE_SHIFT)
11618c2ecf20Sopenharmony_ci	oris	r15,r15,MAS1_VALID@h	/* MAS1 needs V and TSIZE */
11628c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS1,r15
11638c2ecf20Sopenharmony_ci
11648c2ecf20Sopenharmony_ci	/* Already somebody there ? */
11658c2ecf20Sopenharmony_ci	PPC_TLBSRX_DOT(0,R16)
11668c2ecf20Sopenharmony_ci	beq	tlb_load_linear_done
11678c2ecf20Sopenharmony_ci
11688c2ecf20Sopenharmony_ci	/* Now we build the remaining MAS. MAS0 and 2 should be fine
11698c2ecf20Sopenharmony_ci	 * with their defaults, which leaves us with MAS 3 and 7. The
11708c2ecf20Sopenharmony_ci	 * mapping is linear, so we just take the address, clear the
11718c2ecf20Sopenharmony_ci	 * region bits, and or in the permission bits which are currently
11728c2ecf20Sopenharmony_ci	 * hard wired
11738c2ecf20Sopenharmony_ci	 */
11748c2ecf20Sopenharmony_ci	clrrdi	r10,r16,30		/* 1G page index */
11758c2ecf20Sopenharmony_ci	clrldi	r10,r10,4		/* clear region bits */
11768c2ecf20Sopenharmony_ci	ori	r10,r10,MAS3_SR|MAS3_SW|MAS3_SX
11778c2ecf20Sopenharmony_ci
11788c2ecf20Sopenharmony_ciBEGIN_MMU_FTR_SECTION
11798c2ecf20Sopenharmony_ci	srdi	r16,r10,32
11808c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS3,r10
11818c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7,r16
11828c2ecf20Sopenharmony_ciMMU_FTR_SECTION_ELSE
11838c2ecf20Sopenharmony_ci	mtspr	SPRN_MAS7_MAS3,r10
11848c2ecf20Sopenharmony_ciALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_PAIRED_MAS)
11858c2ecf20Sopenharmony_ci
11868c2ecf20Sopenharmony_ci	tlbwe
11878c2ecf20Sopenharmony_ci
11888c2ecf20Sopenharmony_citlb_load_linear_done:
11898c2ecf20Sopenharmony_ci	/* We use the "error" epilog for success as we do want to
11908c2ecf20Sopenharmony_ci	 * restore to the initial faulting context, whatever it was.
11918c2ecf20Sopenharmony_ci	 * We do that because we can't resume a fault within a TLB
11928c2ecf20Sopenharmony_ci	 * miss handler, due to MAS and TLB reservation being clobbered.
11938c2ecf20Sopenharmony_ci	 */
11948c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR
11958c2ecf20Sopenharmony_ci	rfi
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_citlb_load_linear_fault:
11988c2ecf20Sopenharmony_ci	/* We keep the DEAR and ESR around, this shouldn't have happened */
11998c2ecf20Sopenharmony_ci	cmpdi	cr0,r14,-1
12008c2ecf20Sopenharmony_ci	beq	1f
12018c2ecf20Sopenharmony_ci	TLB_MISS_EPILOG_ERROR_SPECIAL
12028c2ecf20Sopenharmony_ci	b	exc_data_storage_book3e
12038c2ecf20Sopenharmony_ci1:	TLB_MISS_EPILOG_ERROR_SPECIAL
12048c2ecf20Sopenharmony_ci	b	exc_instruction_storage_book3e
1205