xref: /openbmc/linux/arch/powerpc/mm/book3s32/hash_low.S (revision 397d2300b08cdee052053e362018cdb6dd65eea2)
117312f25SChristophe Leroy/*
217312f25SChristophe Leroy *  PowerPC version
317312f25SChristophe Leroy *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
417312f25SChristophe Leroy *  Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
517312f25SChristophe Leroy *    Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
617312f25SChristophe Leroy *  Adapted for Power Macintosh by Paul Mackerras.
717312f25SChristophe Leroy *  Low-level exception handlers and MMU support
817312f25SChristophe Leroy *  rewritten by Paul Mackerras.
917312f25SChristophe Leroy *    Copyright (C) 1996 Paul Mackerras.
1017312f25SChristophe Leroy *
1117312f25SChristophe Leroy *  This file contains low-level assembler routines for managing
1217312f25SChristophe Leroy *  the PowerPC MMU hash table.  (PPC 8xx processors don't use a
1317312f25SChristophe Leroy *  hash table, so this file is not used on them.)
1417312f25SChristophe Leroy *
1517312f25SChristophe Leroy *  This program is free software; you can redistribute it and/or
1617312f25SChristophe Leroy *  modify it under the terms of the GNU General Public License
1717312f25SChristophe Leroy *  as published by the Free Software Foundation; either version
1817312f25SChristophe Leroy *  2 of the License, or (at your option) any later version.
1917312f25SChristophe Leroy *
2017312f25SChristophe Leroy */
2117312f25SChristophe Leroy
2217312f25SChristophe Leroy#include <asm/reg.h>
2317312f25SChristophe Leroy#include <asm/page.h>
2417312f25SChristophe Leroy#include <asm/pgtable.h>
2517312f25SChristophe Leroy#include <asm/cputable.h>
2617312f25SChristophe Leroy#include <asm/ppc_asm.h>
2717312f25SChristophe Leroy#include <asm/thread_info.h>
2817312f25SChristophe Leroy#include <asm/asm-offsets.h>
2917312f25SChristophe Leroy#include <asm/export.h>
3017312f25SChristophe Leroy#include <asm/feature-fixups.h>
3117312f25SChristophe Leroy#include <asm/code-patching-asm.h>
3217312f25SChristophe Leroy
3317312f25SChristophe Leroy#ifdef CONFIG_SMP
3417312f25SChristophe Leroy	.section .bss
3517312f25SChristophe Leroy	.align	2
3617312f25SChristophe Leroymmu_hash_lock:
3717312f25SChristophe Leroy	.space	4
3817312f25SChristophe Leroy#endif /* CONFIG_SMP */
3917312f25SChristophe Leroy
4017312f25SChristophe Leroy/*
4117312f25SChristophe Leroy * Load a PTE into the hash table, if possible.
4217312f25SChristophe Leroy * The address is in r4, and r3 contains an access flag:
4317312f25SChristophe Leroy * _PAGE_RW (0x400) if a write.
4417312f25SChristophe Leroy * r9 contains the SRR1 value, from which we use the MSR_PR bit.
4517312f25SChristophe Leroy * SPRG_THREAD contains the physical address of the current task's thread.
4617312f25SChristophe Leroy *
4717312f25SChristophe Leroy * Returns to the caller if the access is illegal or there is no
4817312f25SChristophe Leroy * mapping for the address.  Otherwise it places an appropriate PTE
4917312f25SChristophe Leroy * in the hash table and returns from the exception.
5017312f25SChristophe Leroy * Uses r0, r3 - r6, r8, r10, ctr, lr.
5117312f25SChristophe Leroy */
5217312f25SChristophe Leroy	.text
5317312f25SChristophe Leroy_GLOBAL(hash_page)
5417312f25SChristophe Leroy#ifdef CONFIG_SMP
5517312f25SChristophe Leroy	lis	r8, (mmu_hash_lock - PAGE_OFFSET)@h
5617312f25SChristophe Leroy	ori	r8, r8, (mmu_hash_lock - PAGE_OFFSET)@l
5717312f25SChristophe Leroy	lis	r0,0x0fff
5817312f25SChristophe Leroy	b	10f
5917312f25SChristophe Leroy11:	lwz	r6,0(r8)
6017312f25SChristophe Leroy	cmpwi	0,r6,0
6117312f25SChristophe Leroy	bne	11b
6217312f25SChristophe Leroy10:	lwarx	r6,0,r8
6317312f25SChristophe Leroy	cmpwi	0,r6,0
6417312f25SChristophe Leroy	bne-	11b
6517312f25SChristophe Leroy	stwcx.	r0,0,r8
6617312f25SChristophe Leroy	bne-	10b
6717312f25SChristophe Leroy	isync
6817312f25SChristophe Leroy#endif
6917312f25SChristophe Leroy	/* Get PTE (linux-style) and check access */
7017312f25SChristophe Leroy	lis	r0,KERNELBASE@h		/* check if kernel address */
7117312f25SChristophe Leroy	cmplw	0,r4,r0
7217312f25SChristophe Leroy	ori	r3,r3,_PAGE_USER|_PAGE_PRESENT /* test low addresses as user */
7317312f25SChristophe Leroy	mfspr	r5, SPRN_SPRG_PGDIR	/* phys page-table root */
7417312f25SChristophe Leroy	blt+	112f			/* assume user more likely */
7517312f25SChristophe Leroy	lis	r5, (swapper_pg_dir - PAGE_OFFSET)@ha	/* if kernel address, use */
7617312f25SChristophe Leroy	addi	r5 ,r5 ,(swapper_pg_dir - PAGE_OFFSET)@l	/* kernel page table */
7717312f25SChristophe Leroy	rlwimi	r3,r9,32-12,29,29	/* MSR_PR -> _PAGE_USER */
7817312f25SChristophe Leroy112:
7917312f25SChristophe Leroy#ifndef CONFIG_PTE_64BIT
8017312f25SChristophe Leroy	rlwimi	r5,r4,12,20,29		/* insert top 10 bits of address */
8117312f25SChristophe Leroy	lwz	r8,0(r5)		/* get pmd entry */
8217312f25SChristophe Leroy	rlwinm.	r8,r8,0,0,19		/* extract address of pte page */
8317312f25SChristophe Leroy#else
8417312f25SChristophe Leroy	rlwinm	r8,r4,13,19,29		/* Compute pgdir/pmd offset */
8517312f25SChristophe Leroy	lwzx	r8,r8,r5		/* Get L1 entry */
8617312f25SChristophe Leroy	rlwinm.	r8,r8,0,0,20		/* extract pt base address */
8717312f25SChristophe Leroy#endif
8817312f25SChristophe Leroy#ifdef CONFIG_SMP
8917312f25SChristophe Leroy	beq-	hash_page_out		/* return if no mapping */
9017312f25SChristophe Leroy#else
9117312f25SChristophe Leroy	/* XXX it seems like the 601 will give a machine fault on the
9217312f25SChristophe Leroy	   rfi if its alignment is wrong (bottom 4 bits of address are
9317312f25SChristophe Leroy	   8 or 0xc) and we have had a not-taken conditional branch
9417312f25SChristophe Leroy	   to the address following the rfi. */
9517312f25SChristophe Leroy	beqlr-
9617312f25SChristophe Leroy#endif
9717312f25SChristophe Leroy#ifndef CONFIG_PTE_64BIT
9817312f25SChristophe Leroy	rlwimi	r8,r4,22,20,29		/* insert next 10 bits of address */
9917312f25SChristophe Leroy#else
10017312f25SChristophe Leroy	rlwimi	r8,r4,23,20,28		/* compute pte address */
10117312f25SChristophe Leroy#endif
10217312f25SChristophe Leroy	rlwinm	r0,r3,32-3,24,24	/* _PAGE_RW access -> _PAGE_DIRTY */
10317312f25SChristophe Leroy	ori	r0,r0,_PAGE_ACCESSED|_PAGE_HASHPTE
10417312f25SChristophe Leroy
10517312f25SChristophe Leroy	/*
10617312f25SChristophe Leroy	 * Update the linux PTE atomically.  We do the lwarx up-front
10717312f25SChristophe Leroy	 * because almost always, there won't be a permission violation
10817312f25SChristophe Leroy	 * and there won't already be an HPTE, and thus we will have
10917312f25SChristophe Leroy	 * to update the PTE to set _PAGE_HASHPTE.  -- paulus.
11017312f25SChristophe Leroy	 *
11117312f25SChristophe Leroy	 * If PTE_64BIT is set, the low word is the flags word; use that
11217312f25SChristophe Leroy	 * word for locking since it contains all the interesting bits.
11317312f25SChristophe Leroy	 */
11417312f25SChristophe Leroy#if (PTE_FLAGS_OFFSET != 0)
11517312f25SChristophe Leroy	addi	r8,r8,PTE_FLAGS_OFFSET
11617312f25SChristophe Leroy#endif
11717312f25SChristophe Leroyretry:
11817312f25SChristophe Leroy	lwarx	r6,0,r8			/* get linux-style pte, flag word */
11917312f25SChristophe Leroy	andc.	r5,r3,r6		/* check access & ~permission */
12017312f25SChristophe Leroy#ifdef CONFIG_SMP
12117312f25SChristophe Leroy	bne-	hash_page_out		/* return if access not permitted */
12217312f25SChristophe Leroy#else
12317312f25SChristophe Leroy	bnelr-
12417312f25SChristophe Leroy#endif
12517312f25SChristophe Leroy	or	r5,r0,r6		/* set accessed/dirty bits */
12617312f25SChristophe Leroy#ifdef CONFIG_PTE_64BIT
12717312f25SChristophe Leroy#ifdef CONFIG_SMP
12817312f25SChristophe Leroy	subf	r10,r6,r8		/* create false data dependency */
12917312f25SChristophe Leroy	subi	r10,r10,PTE_FLAGS_OFFSET
13017312f25SChristophe Leroy	lwzx	r10,r6,r10		/* Get upper PTE word */
13117312f25SChristophe Leroy#else
13217312f25SChristophe Leroy	lwz	r10,-PTE_FLAGS_OFFSET(r8)
13317312f25SChristophe Leroy#endif /* CONFIG_SMP */
13417312f25SChristophe Leroy#endif /* CONFIG_PTE_64BIT */
13517312f25SChristophe Leroy	stwcx.	r5,0,r8			/* attempt to update PTE */
13617312f25SChristophe Leroy	bne-	retry			/* retry if someone got there first */
13717312f25SChristophe Leroy
13817312f25SChristophe Leroy	mfsrin	r3,r4			/* get segment reg for segment */
13917312f25SChristophe Leroy	mfctr	r0
14017312f25SChristophe Leroy	stw	r0,_CTR(r11)
14117312f25SChristophe Leroy	bl	create_hpte		/* add the hash table entry */
14217312f25SChristophe Leroy
14317312f25SChristophe Leroy#ifdef CONFIG_SMP
14417312f25SChristophe Leroy	eieio
14517312f25SChristophe Leroy	lis	r8, (mmu_hash_lock - PAGE_OFFSET)@ha
14617312f25SChristophe Leroy	li	r0,0
14717312f25SChristophe Leroy	stw	r0, (mmu_hash_lock - PAGE_OFFSET)@l(r8)
14817312f25SChristophe Leroy#endif
14917312f25SChristophe Leroy
15017312f25SChristophe Leroy	/* Return from the exception */
15117312f25SChristophe Leroy	lwz	r5,_CTR(r11)
15217312f25SChristophe Leroy	mtctr	r5
15317312f25SChristophe Leroy	lwz	r0,GPR0(r11)
15417312f25SChristophe Leroy	lwz	r8,GPR8(r11)
15517312f25SChristophe Leroy	b	fast_exception_return
15617312f25SChristophe Leroy
15717312f25SChristophe Leroy#ifdef CONFIG_SMP
15817312f25SChristophe Leroyhash_page_out:
15917312f25SChristophe Leroy	eieio
16017312f25SChristophe Leroy	lis	r8, (mmu_hash_lock - PAGE_OFFSET)@ha
16117312f25SChristophe Leroy	li	r0,0
16217312f25SChristophe Leroy	stw	r0, (mmu_hash_lock - PAGE_OFFSET)@l(r8)
16317312f25SChristophe Leroy	blr
16417312f25SChristophe Leroy#endif /* CONFIG_SMP */
16517312f25SChristophe Leroy
16617312f25SChristophe Leroy/*
16717312f25SChristophe Leroy * Add an entry for a particular page to the hash table.
16817312f25SChristophe Leroy *
16917312f25SChristophe Leroy * add_hash_page(unsigned context, unsigned long va, unsigned long pmdval)
17017312f25SChristophe Leroy *
17117312f25SChristophe Leroy * We assume any necessary modifications to the pte (e.g. setting
17217312f25SChristophe Leroy * the accessed bit) have already been done and that there is actually
17317312f25SChristophe Leroy * a hash table in use (i.e. we're not on a 603).
17417312f25SChristophe Leroy */
17517312f25SChristophe Leroy_GLOBAL(add_hash_page)
17617312f25SChristophe Leroy	mflr	r0
17717312f25SChristophe Leroy	stw	r0,4(r1)
17817312f25SChristophe Leroy
17917312f25SChristophe Leroy	/* Convert context and va to VSID */
18017312f25SChristophe Leroy	mulli	r3,r3,897*16		/* multiply context by context skew */
18117312f25SChristophe Leroy	rlwinm	r0,r4,4,28,31		/* get ESID (top 4 bits of va) */
18217312f25SChristophe Leroy	mulli	r0,r0,0x111		/* multiply by ESID skew */
18317312f25SChristophe Leroy	add	r3,r3,r0		/* note create_hpte trims to 24 bits */
18417312f25SChristophe Leroy
18517312f25SChristophe Leroy#ifdef CONFIG_SMP
18617312f25SChristophe Leroy	lwz	r8,TASK_CPU(r2)		/* to go in mmu_hash_lock */
18717312f25SChristophe Leroy	oris	r8,r8,12
18817312f25SChristophe Leroy#endif /* CONFIG_SMP */
18917312f25SChristophe Leroy
19017312f25SChristophe Leroy	/*
19117312f25SChristophe Leroy	 * We disable interrupts here, even on UP, because we don't
19217312f25SChristophe Leroy	 * want to race with hash_page, and because we want the
19317312f25SChristophe Leroy	 * _PAGE_HASHPTE bit to be a reliable indication of whether
19417312f25SChristophe Leroy	 * the HPTE exists (or at least whether one did once).
19517312f25SChristophe Leroy	 * We also turn off the MMU for data accesses so that we
19617312f25SChristophe Leroy	 * we can't take a hash table miss (assuming the code is
19717312f25SChristophe Leroy	 * covered by a BAT).  -- paulus
19817312f25SChristophe Leroy	 */
19917312f25SChristophe Leroy	mfmsr	r9
20017312f25SChristophe Leroy	SYNC
20117312f25SChristophe Leroy	rlwinm	r0,r9,0,17,15		/* clear bit 16 (MSR_EE) */
20217312f25SChristophe Leroy	rlwinm	r0,r0,0,28,26		/* clear MSR_DR */
20317312f25SChristophe Leroy	mtmsr	r0
20417312f25SChristophe Leroy	SYNC_601
20517312f25SChristophe Leroy	isync
20617312f25SChristophe Leroy
20717312f25SChristophe Leroy#ifdef CONFIG_SMP
20817312f25SChristophe Leroy	lis	r6, (mmu_hash_lock - PAGE_OFFSET)@ha
20917312f25SChristophe Leroy	addi	r6, r6, (mmu_hash_lock - PAGE_OFFSET)@l
21017312f25SChristophe Leroy10:	lwarx	r0,0,r6			/* take the mmu_hash_lock */
21117312f25SChristophe Leroy	cmpi	0,r0,0
21217312f25SChristophe Leroy	bne-	11f
21317312f25SChristophe Leroy	stwcx.	r8,0,r6
21417312f25SChristophe Leroy	beq+	12f
21517312f25SChristophe Leroy11:	lwz	r0,0(r6)
21617312f25SChristophe Leroy	cmpi	0,r0,0
21717312f25SChristophe Leroy	beq	10b
21817312f25SChristophe Leroy	b	11b
21917312f25SChristophe Leroy12:	isync
22017312f25SChristophe Leroy#endif
22117312f25SChristophe Leroy
22217312f25SChristophe Leroy	/*
22317312f25SChristophe Leroy	 * Fetch the linux pte and test and set _PAGE_HASHPTE atomically.
22417312f25SChristophe Leroy	 * If _PAGE_HASHPTE was already set, we don't replace the existing
22517312f25SChristophe Leroy	 * HPTE, so we just unlock and return.
22617312f25SChristophe Leroy	 */
22717312f25SChristophe Leroy	mr	r8,r5
22817312f25SChristophe Leroy#ifndef CONFIG_PTE_64BIT
22917312f25SChristophe Leroy	rlwimi	r8,r4,22,20,29
23017312f25SChristophe Leroy#else
23117312f25SChristophe Leroy	rlwimi	r8,r4,23,20,28
23217312f25SChristophe Leroy	addi	r8,r8,PTE_FLAGS_OFFSET
23317312f25SChristophe Leroy#endif
23417312f25SChristophe Leroy1:	lwarx	r6,0,r8
23517312f25SChristophe Leroy	andi.	r0,r6,_PAGE_HASHPTE
23617312f25SChristophe Leroy	bne	9f			/* if HASHPTE already set, done */
23717312f25SChristophe Leroy#ifdef CONFIG_PTE_64BIT
23817312f25SChristophe Leroy#ifdef CONFIG_SMP
23917312f25SChristophe Leroy	subf	r10,r6,r8		/* create false data dependency */
24017312f25SChristophe Leroy	subi	r10,r10,PTE_FLAGS_OFFSET
24117312f25SChristophe Leroy	lwzx	r10,r6,r10		/* Get upper PTE word */
24217312f25SChristophe Leroy#else
24317312f25SChristophe Leroy	lwz	r10,-PTE_FLAGS_OFFSET(r8)
24417312f25SChristophe Leroy#endif /* CONFIG_SMP */
24517312f25SChristophe Leroy#endif /* CONFIG_PTE_64BIT */
24617312f25SChristophe Leroy	ori	r5,r6,_PAGE_HASHPTE
24717312f25SChristophe Leroy	stwcx.	r5,0,r8
24817312f25SChristophe Leroy	bne-	1b
24917312f25SChristophe Leroy
25017312f25SChristophe Leroy	bl	create_hpte
25117312f25SChristophe Leroy
25217312f25SChristophe Leroy9:
25317312f25SChristophe Leroy#ifdef CONFIG_SMP
25417312f25SChristophe Leroy	lis	r6, (mmu_hash_lock - PAGE_OFFSET)@ha
25517312f25SChristophe Leroy	addi	r6, r6, (mmu_hash_lock - PAGE_OFFSET)@l
25617312f25SChristophe Leroy	eieio
25717312f25SChristophe Leroy	li	r0,0
25817312f25SChristophe Leroy	stw	r0,0(r6)		/* clear mmu_hash_lock */
25917312f25SChristophe Leroy#endif
26017312f25SChristophe Leroy
26117312f25SChristophe Leroy	/* reenable interrupts and DR */
26217312f25SChristophe Leroy	mtmsr	r9
26317312f25SChristophe Leroy	SYNC_601
26417312f25SChristophe Leroy	isync
26517312f25SChristophe Leroy
26617312f25SChristophe Leroy	lwz	r0,4(r1)
26717312f25SChristophe Leroy	mtlr	r0
26817312f25SChristophe Leroy	blr
26917312f25SChristophe Leroy
27017312f25SChristophe Leroy/*
27117312f25SChristophe Leroy * This routine adds a hardware PTE to the hash table.
27217312f25SChristophe Leroy * It is designed to be called with the MMU either on or off.
27317312f25SChristophe Leroy * r3 contains the VSID, r4 contains the virtual address,
27417312f25SChristophe Leroy * r5 contains the linux PTE, r6 contains the old value of the
27517312f25SChristophe Leroy * linux PTE (before setting _PAGE_HASHPTE). r10 contains the
27617312f25SChristophe Leroy * upper half of the PTE if CONFIG_PTE_64BIT.
27717312f25SChristophe Leroy * On SMP, the caller should have the mmu_hash_lock held.
27817312f25SChristophe Leroy * We assume that the caller has (or will) set the _PAGE_HASHPTE
27917312f25SChristophe Leroy * bit in the linux PTE in memory.  The value passed in r6 should
28017312f25SChristophe Leroy * be the old linux PTE value; if it doesn't have _PAGE_HASHPTE set
28117312f25SChristophe Leroy * this routine will skip the search for an existing HPTE.
28217312f25SChristophe Leroy * This procedure modifies r0, r3 - r6, r8, cr0.
28317312f25SChristophe Leroy *  -- paulus.
28417312f25SChristophe Leroy *
28517312f25SChristophe Leroy * For speed, 4 of the instructions get patched once the size and
28617312f25SChristophe Leroy * physical address of the hash table are known.  These definitions
28717312f25SChristophe Leroy * of Hash_base and Hash_bits below are just an example.
28817312f25SChristophe Leroy */
28917312f25SChristophe LeroyHash_base = 0xc0180000
29017312f25SChristophe LeroyHash_bits = 12				/* e.g. 256kB hash table */
29117312f25SChristophe LeroyHash_msk = (((1 << Hash_bits) - 1) * 64)
29217312f25SChristophe Leroy
29317312f25SChristophe Leroy/* defines for the PTE format for 32-bit PPCs */
29417312f25SChristophe Leroy#define HPTE_SIZE	8
29517312f25SChristophe Leroy#define PTEG_SIZE	64
29617312f25SChristophe Leroy#define LG_PTEG_SIZE	6
29717312f25SChristophe Leroy#define LDPTEu		lwzu
29817312f25SChristophe Leroy#define LDPTE		lwz
29917312f25SChristophe Leroy#define STPTE		stw
30017312f25SChristophe Leroy#define CMPPTE		cmpw
30117312f25SChristophe Leroy#define PTE_H		0x40
30217312f25SChristophe Leroy#define PTE_V		0x80000000
30317312f25SChristophe Leroy#define TST_V(r)	rlwinm. r,r,0,0,0
30417312f25SChristophe Leroy#define SET_V(r)	oris r,r,PTE_V@h
30517312f25SChristophe Leroy#define CLR_V(r,t)	rlwinm r,r,0,1,31
30617312f25SChristophe Leroy
30717312f25SChristophe Leroy#define HASH_LEFT	31-(LG_PTEG_SIZE+Hash_bits-1)
30817312f25SChristophe Leroy#define HASH_RIGHT	31-LG_PTEG_SIZE
30917312f25SChristophe Leroy
31017312f25SChristophe Leroy_GLOBAL(create_hpte)
31117312f25SChristophe Leroy	/* Convert linux-style PTE (r5) to low word of PPC-style PTE (r8) */
31217312f25SChristophe Leroy	rlwinm	r8,r5,32-9,30,30	/* _PAGE_RW -> PP msb */
31317312f25SChristophe Leroy	rlwinm	r0,r5,32-6,30,30	/* _PAGE_DIRTY -> PP msb */
31417312f25SChristophe Leroy	and	r8,r8,r0		/* writable if _RW & _DIRTY */
31517312f25SChristophe Leroy	rlwimi	r5,r5,32-1,30,30	/* _PAGE_USER -> PP msb */
31617312f25SChristophe Leroy	rlwimi	r5,r5,32-2,31,31	/* _PAGE_USER -> PP lsb */
31717312f25SChristophe Leroy	ori	r8,r8,0xe04		/* clear out reserved bits */
31817312f25SChristophe Leroy	andc	r8,r5,r8		/* PP = user? (rw&dirty? 1: 3): 0 */
31917312f25SChristophe LeroyBEGIN_FTR_SECTION
32017312f25SChristophe Leroy	rlwinm	r8,r8,0,~_PAGE_COHERENT	/* clear M (coherence not required) */
32117312f25SChristophe LeroyEND_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
32217312f25SChristophe Leroy#ifdef CONFIG_PTE_64BIT
32317312f25SChristophe Leroy	/* Put the XPN bits into the PTE */
32417312f25SChristophe Leroy	rlwimi	r8,r10,8,20,22
32517312f25SChristophe Leroy	rlwimi	r8,r10,2,29,29
32617312f25SChristophe Leroy#endif
32717312f25SChristophe Leroy
32817312f25SChristophe Leroy	/* Construct the high word of the PPC-style PTE (r5) */
32917312f25SChristophe Leroy	rlwinm	r5,r3,7,1,24		/* put VSID in 0x7fffff80 bits */
33017312f25SChristophe Leroy	rlwimi	r5,r4,10,26,31		/* put in API (abbrev page index) */
33117312f25SChristophe Leroy	SET_V(r5)			/* set V (valid) bit */
33217312f25SChristophe Leroy
33317312f25SChristophe Leroy	patch_site	0f, patch__hash_page_A0
33417312f25SChristophe Leroy	patch_site	1f, patch__hash_page_A1
33517312f25SChristophe Leroy	patch_site	2f, patch__hash_page_A2
33617312f25SChristophe Leroy	/* Get the address of the primary PTE group in the hash table (r3) */
33717312f25SChristophe Leroy0:	lis	r0, (Hash_base - PAGE_OFFSET)@h	/* base address of hash table */
33817312f25SChristophe Leroy1:	rlwimi	r0,r3,LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT    /* VSID -> hash */
33917312f25SChristophe Leroy2:	rlwinm	r3,r4,20+LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* PI -> hash */
34017312f25SChristophe Leroy	xor	r3,r3,r0		/* make primary hash */
34117312f25SChristophe Leroy	li	r0,8			/* PTEs/group */
34217312f25SChristophe Leroy
34317312f25SChristophe Leroy	/*
34417312f25SChristophe Leroy	 * Test the _PAGE_HASHPTE bit in the old linux PTE, and skip the search
34517312f25SChristophe Leroy	 * if it is clear, meaning that the HPTE isn't there already...
34617312f25SChristophe Leroy	 */
34717312f25SChristophe Leroy	andi.	r6,r6,_PAGE_HASHPTE
34817312f25SChristophe Leroy	beq+	10f			/* no PTE: go look for an empty slot */
34917312f25SChristophe Leroy	tlbie	r4
35017312f25SChristophe Leroy
35117312f25SChristophe Leroy	lis	r4, (htab_hash_searches - PAGE_OFFSET)@ha
35217312f25SChristophe Leroy	lwz	r6, (htab_hash_searches - PAGE_OFFSET)@l(r4)
35317312f25SChristophe Leroy	addi	r6,r6,1			/* count how many searches we do */
35417312f25SChristophe Leroy	stw	r6, (htab_hash_searches - PAGE_OFFSET)@l(r4)
35517312f25SChristophe Leroy
35617312f25SChristophe Leroy	/* Search the primary PTEG for a PTE whose 1st (d)word matches r5 */
35717312f25SChristophe Leroy	mtctr	r0
35817312f25SChristophe Leroy	addi	r4,r3,-HPTE_SIZE
35917312f25SChristophe Leroy1:	LDPTEu	r6,HPTE_SIZE(r4)	/* get next PTE */
36017312f25SChristophe Leroy	CMPPTE	0,r6,r5
36117312f25SChristophe Leroy	bdnzf	2,1b			/* loop while ctr != 0 && !cr0.eq */
36217312f25SChristophe Leroy	beq+	found_slot
36317312f25SChristophe Leroy
36417312f25SChristophe Leroy	patch_site	0f, patch__hash_page_B
36517312f25SChristophe Leroy	/* Search the secondary PTEG for a matching PTE */
36617312f25SChristophe Leroy	ori	r5,r5,PTE_H		/* set H (secondary hash) bit */
36717312f25SChristophe Leroy0:	xoris	r4,r3,Hash_msk>>16	/* compute secondary hash */
36817312f25SChristophe Leroy	xori	r4,r4,(-PTEG_SIZE & 0xffff)
36917312f25SChristophe Leroy	addi	r4,r4,-HPTE_SIZE
37017312f25SChristophe Leroy	mtctr	r0
37117312f25SChristophe Leroy2:	LDPTEu	r6,HPTE_SIZE(r4)
37217312f25SChristophe Leroy	CMPPTE	0,r6,r5
37317312f25SChristophe Leroy	bdnzf	2,2b
37417312f25SChristophe Leroy	beq+	found_slot
37517312f25SChristophe Leroy	xori	r5,r5,PTE_H		/* clear H bit again */
37617312f25SChristophe Leroy
37717312f25SChristophe Leroy	/* Search the primary PTEG for an empty slot */
37817312f25SChristophe Leroy10:	mtctr	r0
37917312f25SChristophe Leroy	addi	r4,r3,-HPTE_SIZE	/* search primary PTEG */
38017312f25SChristophe Leroy1:	LDPTEu	r6,HPTE_SIZE(r4)	/* get next PTE */
38117312f25SChristophe Leroy	TST_V(r6)			/* test valid bit */
38217312f25SChristophe Leroy	bdnzf	2,1b			/* loop while ctr != 0 && !cr0.eq */
38317312f25SChristophe Leroy	beq+	found_empty
38417312f25SChristophe Leroy
38517312f25SChristophe Leroy	/* update counter of times that the primary PTEG is full */
38617312f25SChristophe Leroy	lis	r4, (primary_pteg_full - PAGE_OFFSET)@ha
38717312f25SChristophe Leroy	lwz	r6, (primary_pteg_full - PAGE_OFFSET)@l(r4)
38817312f25SChristophe Leroy	addi	r6,r6,1
38917312f25SChristophe Leroy	stw	r6, (primary_pteg_full - PAGE_OFFSET)@l(r4)
39017312f25SChristophe Leroy
39117312f25SChristophe Leroy	patch_site	0f, patch__hash_page_C
39217312f25SChristophe Leroy	/* Search the secondary PTEG for an empty slot */
39317312f25SChristophe Leroy	ori	r5,r5,PTE_H		/* set H (secondary hash) bit */
39417312f25SChristophe Leroy0:	xoris	r4,r3,Hash_msk>>16	/* compute secondary hash */
39517312f25SChristophe Leroy	xori	r4,r4,(-PTEG_SIZE & 0xffff)
39617312f25SChristophe Leroy	addi	r4,r4,-HPTE_SIZE
39717312f25SChristophe Leroy	mtctr	r0
39817312f25SChristophe Leroy2:	LDPTEu	r6,HPTE_SIZE(r4)
39917312f25SChristophe Leroy	TST_V(r6)
40017312f25SChristophe Leroy	bdnzf	2,2b
40117312f25SChristophe Leroy	beq+	found_empty
40217312f25SChristophe Leroy	xori	r5,r5,PTE_H		/* clear H bit again */
40317312f25SChristophe Leroy
40417312f25SChristophe Leroy	/*
40517312f25SChristophe Leroy	 * Choose an arbitrary slot in the primary PTEG to overwrite.
40617312f25SChristophe Leroy	 * Since both the primary and secondary PTEGs are full, and we
40717312f25SChristophe Leroy	 * have no information that the PTEs in the primary PTEG are
40817312f25SChristophe Leroy	 * more important or useful than those in the secondary PTEG,
40917312f25SChristophe Leroy	 * and we know there is a definite (although small) speed
41017312f25SChristophe Leroy	 * advantage to putting the PTE in the primary PTEG, we always
41117312f25SChristophe Leroy	 * put the PTE in the primary PTEG.
41217312f25SChristophe Leroy	 *
41317312f25SChristophe Leroy	 * In addition, we skip any slot that is mapping kernel text in
41417312f25SChristophe Leroy	 * order to avoid a deadlock when not using BAT mappings if
41517312f25SChristophe Leroy	 * trying to hash in the kernel hash code itself after it has
41617312f25SChristophe Leroy	 * already taken the hash table lock. This works in conjunction
41717312f25SChristophe Leroy	 * with pre-faulting of the kernel text.
41817312f25SChristophe Leroy	 *
41917312f25SChristophe Leroy	 * If the hash table bucket is full of kernel text entries, we'll
42017312f25SChristophe Leroy	 * lockup here but that shouldn't happen
42117312f25SChristophe Leroy	 */
42217312f25SChristophe Leroy
42317312f25SChristophe Leroy1:	lis	r4, (next_slot - PAGE_OFFSET)@ha	/* get next evict slot */
42417312f25SChristophe Leroy	lwz	r6, (next_slot - PAGE_OFFSET)@l(r4)
42517312f25SChristophe Leroy	addi	r6,r6,HPTE_SIZE			/* search for candidate */
42617312f25SChristophe Leroy	andi.	r6,r6,7*HPTE_SIZE
42717312f25SChristophe Leroy	stw	r6,next_slot@l(r4)
42817312f25SChristophe Leroy	add	r4,r3,r6
42917312f25SChristophe Leroy	LDPTE	r0,HPTE_SIZE/2(r4)		/* get PTE second word */
43017312f25SChristophe Leroy	clrrwi	r0,r0,12
43117312f25SChristophe Leroy	lis	r6,etext@h
43217312f25SChristophe Leroy	ori	r6,r6,etext@l			/* get etext */
43317312f25SChristophe Leroy	tophys(r6,r6)
43417312f25SChristophe Leroy	cmpl	cr0,r0,r6			/* compare and try again */
43517312f25SChristophe Leroy	blt	1b
43617312f25SChristophe Leroy
43717312f25SChristophe Leroy#ifndef CONFIG_SMP
43817312f25SChristophe Leroy	/* Store PTE in PTEG */
43917312f25SChristophe Leroyfound_empty:
44017312f25SChristophe Leroy	STPTE	r5,0(r4)
44117312f25SChristophe Leroyfound_slot:
44217312f25SChristophe Leroy	STPTE	r8,HPTE_SIZE/2(r4)
44317312f25SChristophe Leroy
44417312f25SChristophe Leroy#else /* CONFIG_SMP */
44517312f25SChristophe Leroy/*
44617312f25SChristophe Leroy * Between the tlbie above and updating the hash table entry below,
44717312f25SChristophe Leroy * another CPU could read the hash table entry and put it in its TLB.
44817312f25SChristophe Leroy * There are 3 cases:
44917312f25SChristophe Leroy * 1. using an empty slot
45017312f25SChristophe Leroy * 2. updating an earlier entry to change permissions (i.e. enable write)
45117312f25SChristophe Leroy * 3. taking over the PTE for an unrelated address
45217312f25SChristophe Leroy *
45317312f25SChristophe Leroy * In each case it doesn't really matter if the other CPUs have the old
45417312f25SChristophe Leroy * PTE in their TLB.  So we don't need to bother with another tlbie here,
45517312f25SChristophe Leroy * which is convenient as we've overwritten the register that had the
45617312f25SChristophe Leroy * address. :-)  The tlbie above is mainly to make sure that this CPU comes
45717312f25SChristophe Leroy * and gets the new PTE from the hash table.
45817312f25SChristophe Leroy *
45917312f25SChristophe Leroy * We do however have to make sure that the PTE is never in an invalid
46017312f25SChristophe Leroy * state with the V bit set.
46117312f25SChristophe Leroy */
46217312f25SChristophe Leroyfound_empty:
46317312f25SChristophe Leroyfound_slot:
46417312f25SChristophe Leroy	CLR_V(r5,r0)		/* clear V (valid) bit in PTE */
46517312f25SChristophe Leroy	STPTE	r5,0(r4)
46617312f25SChristophe Leroy	sync
46717312f25SChristophe Leroy	TLBSYNC
46817312f25SChristophe Leroy	STPTE	r8,HPTE_SIZE/2(r4) /* put in correct RPN, WIMG, PP bits */
46917312f25SChristophe Leroy	sync
47017312f25SChristophe Leroy	SET_V(r5)
47117312f25SChristophe Leroy	STPTE	r5,0(r4)	/* finally set V bit in PTE */
47217312f25SChristophe Leroy#endif /* CONFIG_SMP */
47317312f25SChristophe Leroy
47417312f25SChristophe Leroy	sync		/* make sure pte updates get to memory */
47517312f25SChristophe Leroy	blr
47617312f25SChristophe Leroy
47717312f25SChristophe Leroy	.section .bss
47817312f25SChristophe Leroy	.align	2
47917312f25SChristophe Leroynext_slot:
48017312f25SChristophe Leroy	.space	4
48117312f25SChristophe Leroyprimary_pteg_full:
48217312f25SChristophe Leroy	.space	4
48317312f25SChristophe Leroyhtab_hash_searches:
48417312f25SChristophe Leroy	.space	4
48517312f25SChristophe Leroy	.previous
48617312f25SChristophe Leroy
48717312f25SChristophe Leroy/*
48817312f25SChristophe Leroy * Flush the entry for a particular page from the hash table.
48917312f25SChristophe Leroy *
49017312f25SChristophe Leroy * flush_hash_pages(unsigned context, unsigned long va, unsigned long pmdval,
49117312f25SChristophe Leroy *		    int count)
49217312f25SChristophe Leroy *
49317312f25SChristophe Leroy * We assume that there is a hash table in use (Hash != 0).
49417312f25SChristophe Leroy */
49517312f25SChristophe Leroy_GLOBAL(flush_hash_pages)
49617312f25SChristophe Leroy	/*
49717312f25SChristophe Leroy	 * We disable interrupts here, even on UP, because we want
49817312f25SChristophe Leroy	 * the _PAGE_HASHPTE bit to be a reliable indication of
49917312f25SChristophe Leroy	 * whether the HPTE exists (or at least whether one did once).
50017312f25SChristophe Leroy	 * We also turn off the MMU for data accesses so that we
50117312f25SChristophe Leroy	 * we can't take a hash table miss (assuming the code is
50217312f25SChristophe Leroy	 * covered by a BAT).  -- paulus
50317312f25SChristophe Leroy	 */
50417312f25SChristophe Leroy	mfmsr	r10
50517312f25SChristophe Leroy	SYNC
50617312f25SChristophe Leroy	rlwinm	r0,r10,0,17,15		/* clear bit 16 (MSR_EE) */
50717312f25SChristophe Leroy	rlwinm	r0,r0,0,28,26		/* clear MSR_DR */
50817312f25SChristophe Leroy	mtmsr	r0
50917312f25SChristophe Leroy	SYNC_601
51017312f25SChristophe Leroy	isync
51117312f25SChristophe Leroy
51217312f25SChristophe Leroy	/* First find a PTE in the range that has _PAGE_HASHPTE set */
51317312f25SChristophe Leroy#ifndef CONFIG_PTE_64BIT
51417312f25SChristophe Leroy	rlwimi	r5,r4,22,20,29
51517312f25SChristophe Leroy#else
51617312f25SChristophe Leroy	rlwimi	r5,r4,23,20,28
51717312f25SChristophe Leroy#endif
51817312f25SChristophe Leroy1:	lwz	r0,PTE_FLAGS_OFFSET(r5)
51917312f25SChristophe Leroy	cmpwi	cr1,r6,1
52017312f25SChristophe Leroy	andi.	r0,r0,_PAGE_HASHPTE
52117312f25SChristophe Leroy	bne	2f
52217312f25SChristophe Leroy	ble	cr1,19f
52317312f25SChristophe Leroy	addi	r4,r4,0x1000
52417312f25SChristophe Leroy	addi	r5,r5,PTE_SIZE
52517312f25SChristophe Leroy	addi	r6,r6,-1
52617312f25SChristophe Leroy	b	1b
52717312f25SChristophe Leroy
52817312f25SChristophe Leroy	/* Convert context and va to VSID */
52917312f25SChristophe Leroy2:	mulli	r3,r3,897*16		/* multiply context by context skew */
53017312f25SChristophe Leroy	rlwinm	r0,r4,4,28,31		/* get ESID (top 4 bits of va) */
53117312f25SChristophe Leroy	mulli	r0,r0,0x111		/* multiply by ESID skew */
53217312f25SChristophe Leroy	add	r3,r3,r0		/* note code below trims to 24 bits */
53317312f25SChristophe Leroy
53417312f25SChristophe Leroy	/* Construct the high word of the PPC-style PTE (r11) */
53517312f25SChristophe Leroy	rlwinm	r11,r3,7,1,24		/* put VSID in 0x7fffff80 bits */
53617312f25SChristophe Leroy	rlwimi	r11,r4,10,26,31		/* put in API (abbrev page index) */
53717312f25SChristophe Leroy	SET_V(r11)			/* set V (valid) bit */
53817312f25SChristophe Leroy
53917312f25SChristophe Leroy#ifdef CONFIG_SMP
54017312f25SChristophe Leroy	lis	r9, (mmu_hash_lock - PAGE_OFFSET)@ha
54117312f25SChristophe Leroy	addi	r9, r9, (mmu_hash_lock - PAGE_OFFSET)@l
542*397d2300SChristophe Leroy	tophys	(r8, r2)
543*397d2300SChristophe Leroy	lwz	r8, TASK_CPU(r8)
54417312f25SChristophe Leroy	oris	r8,r8,9
54517312f25SChristophe Leroy10:	lwarx	r0,0,r9
54617312f25SChristophe Leroy	cmpi	0,r0,0
54717312f25SChristophe Leroy	bne-	11f
54817312f25SChristophe Leroy	stwcx.	r8,0,r9
54917312f25SChristophe Leroy	beq+	12f
55017312f25SChristophe Leroy11:	lwz	r0,0(r9)
55117312f25SChristophe Leroy	cmpi	0,r0,0
55217312f25SChristophe Leroy	beq	10b
55317312f25SChristophe Leroy	b	11b
55417312f25SChristophe Leroy12:	isync
55517312f25SChristophe Leroy#endif
55617312f25SChristophe Leroy
55717312f25SChristophe Leroy	/*
55817312f25SChristophe Leroy	 * Check the _PAGE_HASHPTE bit in the linux PTE.  If it is
55917312f25SChristophe Leroy	 * already clear, we're done (for this pte).  If not,
56017312f25SChristophe Leroy	 * clear it (atomically) and proceed.  -- paulus.
56117312f25SChristophe Leroy	 */
56217312f25SChristophe Leroy#if (PTE_FLAGS_OFFSET != 0)
56317312f25SChristophe Leroy	addi	r5,r5,PTE_FLAGS_OFFSET
56417312f25SChristophe Leroy#endif
56517312f25SChristophe Leroy33:	lwarx	r8,0,r5			/* fetch the pte flags word */
56617312f25SChristophe Leroy	andi.	r0,r8,_PAGE_HASHPTE
56717312f25SChristophe Leroy	beq	8f			/* done if HASHPTE is already clear */
56817312f25SChristophe Leroy	rlwinm	r8,r8,0,31,29		/* clear HASHPTE bit */
56917312f25SChristophe Leroy	stwcx.	r8,0,r5			/* update the pte */
57017312f25SChristophe Leroy	bne-	33b
57117312f25SChristophe Leroy
57217312f25SChristophe Leroy	patch_site	0f, patch__flush_hash_A0
57317312f25SChristophe Leroy	patch_site	1f, patch__flush_hash_A1
57417312f25SChristophe Leroy	patch_site	2f, patch__flush_hash_A2
57517312f25SChristophe Leroy	/* Get the address of the primary PTE group in the hash table (r3) */
57617312f25SChristophe Leroy0:	lis	r8, (Hash_base - PAGE_OFFSET)@h	/* base address of hash table */
57717312f25SChristophe Leroy1:	rlwimi	r8,r3,LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT    /* VSID -> hash */
57817312f25SChristophe Leroy2:	rlwinm	r0,r4,20+LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* PI -> hash */
57917312f25SChristophe Leroy	xor	r8,r0,r8		/* make primary hash */
58017312f25SChristophe Leroy
58117312f25SChristophe Leroy	/* Search the primary PTEG for a PTE whose 1st (d)word matches r5 */
58217312f25SChristophe Leroy	li	r0,8			/* PTEs/group */
58317312f25SChristophe Leroy	mtctr	r0
58417312f25SChristophe Leroy	addi	r12,r8,-HPTE_SIZE
58517312f25SChristophe Leroy1:	LDPTEu	r0,HPTE_SIZE(r12)	/* get next PTE */
58617312f25SChristophe Leroy	CMPPTE	0,r0,r11
58717312f25SChristophe Leroy	bdnzf	2,1b			/* loop while ctr != 0 && !cr0.eq */
58817312f25SChristophe Leroy	beq+	3f
58917312f25SChristophe Leroy
59017312f25SChristophe Leroy	patch_site	0f, patch__flush_hash_B
59117312f25SChristophe Leroy	/* Search the secondary PTEG for a matching PTE */
59217312f25SChristophe Leroy	ori	r11,r11,PTE_H		/* set H (secondary hash) bit */
59317312f25SChristophe Leroy	li	r0,8			/* PTEs/group */
59417312f25SChristophe Leroy0:	xoris	r12,r8,Hash_msk>>16	/* compute secondary hash */
59517312f25SChristophe Leroy	xori	r12,r12,(-PTEG_SIZE & 0xffff)
59617312f25SChristophe Leroy	addi	r12,r12,-HPTE_SIZE
59717312f25SChristophe Leroy	mtctr	r0
59817312f25SChristophe Leroy2:	LDPTEu	r0,HPTE_SIZE(r12)
59917312f25SChristophe Leroy	CMPPTE	0,r0,r11
60017312f25SChristophe Leroy	bdnzf	2,2b
60117312f25SChristophe Leroy	xori	r11,r11,PTE_H		/* clear H again */
60217312f25SChristophe Leroy	bne-	4f			/* should rarely fail to find it */
60317312f25SChristophe Leroy
60417312f25SChristophe Leroy3:	li	r0,0
60517312f25SChristophe Leroy	STPTE	r0,0(r12)		/* invalidate entry */
60617312f25SChristophe Leroy4:	sync
60717312f25SChristophe Leroy	tlbie	r4			/* in hw tlb too */
60817312f25SChristophe Leroy	sync
60917312f25SChristophe Leroy
61017312f25SChristophe Leroy8:	ble	cr1,9f			/* if all ptes checked */
61117312f25SChristophe Leroy81:	addi	r6,r6,-1
61217312f25SChristophe Leroy	addi	r5,r5,PTE_SIZE
61317312f25SChristophe Leroy	addi	r4,r4,0x1000
61417312f25SChristophe Leroy	lwz	r0,0(r5)		/* check next pte */
61517312f25SChristophe Leroy	cmpwi	cr1,r6,1
61617312f25SChristophe Leroy	andi.	r0,r0,_PAGE_HASHPTE
61717312f25SChristophe Leroy	bne	33b
61817312f25SChristophe Leroy	bgt	cr1,81b
61917312f25SChristophe Leroy
62017312f25SChristophe Leroy9:
62117312f25SChristophe Leroy#ifdef CONFIG_SMP
62217312f25SChristophe Leroy	TLBSYNC
62317312f25SChristophe Leroy	li	r0,0
62417312f25SChristophe Leroy	stw	r0,0(r9)		/* clear mmu_hash_lock */
62517312f25SChristophe Leroy#endif
62617312f25SChristophe Leroy
62717312f25SChristophe Leroy19:	mtmsr	r10
62817312f25SChristophe Leroy	SYNC_601
62917312f25SChristophe Leroy	isync
63017312f25SChristophe Leroy	blr
63117312f25SChristophe LeroyEXPORT_SYMBOL(flush_hash_pages)
63217312f25SChristophe Leroy
63317312f25SChristophe Leroy/*
63417312f25SChristophe Leroy * Flush an entry from the TLB
63517312f25SChristophe Leroy */
63617312f25SChristophe Leroy_GLOBAL(_tlbie)
63717312f25SChristophe Leroy#ifdef CONFIG_SMP
63817312f25SChristophe Leroy	lwz	r8,TASK_CPU(r2)
63917312f25SChristophe Leroy	oris	r8,r8,11
64017312f25SChristophe Leroy	mfmsr	r10
64117312f25SChristophe Leroy	SYNC
64217312f25SChristophe Leroy	rlwinm	r0,r10,0,17,15		/* clear bit 16 (MSR_EE) */
64317312f25SChristophe Leroy	rlwinm	r0,r0,0,28,26		/* clear DR */
64417312f25SChristophe Leroy	mtmsr	r0
64517312f25SChristophe Leroy	SYNC_601
64617312f25SChristophe Leroy	isync
64717312f25SChristophe Leroy	lis	r9,mmu_hash_lock@h
64817312f25SChristophe Leroy	ori	r9,r9,mmu_hash_lock@l
64917312f25SChristophe Leroy	tophys(r9,r9)
65017312f25SChristophe Leroy10:	lwarx	r7,0,r9
65117312f25SChristophe Leroy	cmpwi	0,r7,0
65217312f25SChristophe Leroy	bne-	10b
65317312f25SChristophe Leroy	stwcx.	r8,0,r9
65417312f25SChristophe Leroy	bne-	10b
65517312f25SChristophe Leroy	eieio
65617312f25SChristophe Leroy	tlbie	r3
65717312f25SChristophe Leroy	sync
65817312f25SChristophe Leroy	TLBSYNC
65917312f25SChristophe Leroy	li	r0,0
66017312f25SChristophe Leroy	stw	r0,0(r9)		/* clear mmu_hash_lock */
66117312f25SChristophe Leroy	mtmsr	r10
66217312f25SChristophe Leroy	SYNC_601
66317312f25SChristophe Leroy	isync
66417312f25SChristophe Leroy#else /* CONFIG_SMP */
66517312f25SChristophe Leroy	tlbie	r3
66617312f25SChristophe Leroy	sync
66717312f25SChristophe Leroy#endif /* CONFIG_SMP */
66817312f25SChristophe Leroy	blr
66917312f25SChristophe Leroy
67017312f25SChristophe Leroy/*
67117312f25SChristophe Leroy * Flush the entire TLB. 603/603e only
67217312f25SChristophe Leroy */
67317312f25SChristophe Leroy_GLOBAL(_tlbia)
67417312f25SChristophe Leroy#if defined(CONFIG_SMP)
67517312f25SChristophe Leroy	lwz	r8,TASK_CPU(r2)
67617312f25SChristophe Leroy	oris	r8,r8,10
67717312f25SChristophe Leroy	mfmsr	r10
67817312f25SChristophe Leroy	SYNC
67917312f25SChristophe Leroy	rlwinm	r0,r10,0,17,15		/* clear bit 16 (MSR_EE) */
68017312f25SChristophe Leroy	rlwinm	r0,r0,0,28,26		/* clear DR */
68117312f25SChristophe Leroy	mtmsr	r0
68217312f25SChristophe Leroy	SYNC_601
68317312f25SChristophe Leroy	isync
68417312f25SChristophe Leroy	lis	r9,mmu_hash_lock@h
68517312f25SChristophe Leroy	ori	r9,r9,mmu_hash_lock@l
68617312f25SChristophe Leroy	tophys(r9,r9)
68717312f25SChristophe Leroy10:	lwarx	r7,0,r9
68817312f25SChristophe Leroy	cmpwi	0,r7,0
68917312f25SChristophe Leroy	bne-	10b
69017312f25SChristophe Leroy	stwcx.	r8,0,r9
69117312f25SChristophe Leroy	bne-	10b
69217312f25SChristophe Leroy	sync
69317312f25SChristophe Leroy	tlbia
69417312f25SChristophe Leroy	sync
69517312f25SChristophe Leroy	TLBSYNC
69617312f25SChristophe Leroy	li	r0,0
69717312f25SChristophe Leroy	stw	r0,0(r9)		/* clear mmu_hash_lock */
69817312f25SChristophe Leroy	mtmsr	r10
69917312f25SChristophe Leroy	SYNC_601
70017312f25SChristophe Leroy	isync
70117312f25SChristophe Leroy#else /* CONFIG_SMP */
70217312f25SChristophe Leroy	sync
70317312f25SChristophe Leroy	tlbia
70417312f25SChristophe Leroy	sync
70517312f25SChristophe Leroy#endif /* CONFIG_SMP */
70617312f25SChristophe Leroy	blr
707