1*f2655125SChristophe Leroy/* SPDX-License-Identifier: GPL-2.0-or-later */
2*f2655125SChristophe Leroy/*
3*f2655125SChristophe Leroy *  This file contains low-level assembler routines for managing
4*f2655125SChristophe Leroy *  the PowerPC 603 tlb invalidation.
5*f2655125SChristophe Leroy */
6*f2655125SChristophe Leroy
7*f2655125SChristophe Leroy#include <asm/page.h>
8*f2655125SChristophe Leroy#include <asm/ppc_asm.h>
9*f2655125SChristophe Leroy#include <asm/asm-offsets.h>
10*f2655125SChristophe Leroy
11*f2655125SChristophe Leroy/*
12*f2655125SChristophe Leroy * Flush an entry from the TLB
13*f2655125SChristophe Leroy */
14*f2655125SChristophe Leroy#ifdef CONFIG_SMP
15*f2655125SChristophe Leroy_GLOBAL(_tlbie)
16*f2655125SChristophe Leroy	lwz	r8,TASK_CPU(r2)
17*f2655125SChristophe Leroy	oris	r8,r8,11
18*f2655125SChristophe Leroy	mfmsr	r10
19*f2655125SChristophe Leroy	rlwinm	r0,r10,0,17,15		/* clear bit 16 (MSR_EE) */
20*f2655125SChristophe Leroy	rlwinm	r0,r0,0,28,26		/* clear DR */
21*f2655125SChristophe Leroy	mtmsr	r0
22*f2655125SChristophe Leroy	isync
23*f2655125SChristophe Leroy	lis	r9,mmu_hash_lock@h
24*f2655125SChristophe Leroy	ori	r9,r9,mmu_hash_lock@l
25*f2655125SChristophe Leroy	tophys(r9,r9)
26*f2655125SChristophe Leroy10:	lwarx	r7,0,r9
27*f2655125SChristophe Leroy	cmpwi	0,r7,0
28*f2655125SChristophe Leroy	bne-	10b
29*f2655125SChristophe Leroy	stwcx.	r8,0,r9
30*f2655125SChristophe Leroy	bne-	10b
31*f2655125SChristophe Leroy	eieio
32*f2655125SChristophe Leroy	tlbie	r3
33*f2655125SChristophe Leroy	sync
34*f2655125SChristophe Leroy	TLBSYNC
35*f2655125SChristophe Leroy	li	r0,0
36*f2655125SChristophe Leroy	stw	r0,0(r9)		/* clear mmu_hash_lock */
37*f2655125SChristophe Leroy	mtmsr	r10
38*f2655125SChristophe Leroy	isync
39*f2655125SChristophe Leroy	blr
40*f2655125SChristophe Leroy_ASM_NOKPROBE_SYMBOL(_tlbie)
41*f2655125SChristophe Leroy#endif /* CONFIG_SMP */
42*f2655125SChristophe Leroy
43*f2655125SChristophe Leroy/*
44*f2655125SChristophe Leroy * Flush the entire TLB. 603/603e only
45*f2655125SChristophe Leroy */
46*f2655125SChristophe Leroy_GLOBAL(_tlbia)
47*f2655125SChristophe Leroy#if defined(CONFIG_SMP)
48*f2655125SChristophe Leroy	lwz	r8,TASK_CPU(r2)
49*f2655125SChristophe Leroy	oris	r8,r8,10
50*f2655125SChristophe Leroy	mfmsr	r10
51*f2655125SChristophe Leroy	rlwinm	r0,r10,0,17,15		/* clear bit 16 (MSR_EE) */
52*f2655125SChristophe Leroy	rlwinm	r0,r0,0,28,26		/* clear DR */
53*f2655125SChristophe Leroy	mtmsr	r0
54*f2655125SChristophe Leroy	isync
55*f2655125SChristophe Leroy	lis	r9,mmu_hash_lock@h
56*f2655125SChristophe Leroy	ori	r9,r9,mmu_hash_lock@l
57*f2655125SChristophe Leroy	tophys(r9,r9)
58*f2655125SChristophe Leroy10:	lwarx	r7,0,r9
59*f2655125SChristophe Leroy	cmpwi	0,r7,0
60*f2655125SChristophe Leroy	bne-	10b
61*f2655125SChristophe Leroy	stwcx.	r8,0,r9
62*f2655125SChristophe Leroy	bne-	10b
63*f2655125SChristophe Leroy#endif /* CONFIG_SMP */
64*f2655125SChristophe Leroy	li	r5, 32
65*f2655125SChristophe Leroy	lis	r4, KERNELBASE@h
66*f2655125SChristophe Leroy	mtctr	r5
67*f2655125SChristophe Leroy	sync
68*f2655125SChristophe Leroy0:	tlbie	r4
69*f2655125SChristophe Leroy	addi	r4, r4, 0x1000
70*f2655125SChristophe Leroy	bdnz	0b
71*f2655125SChristophe Leroy	sync
72*f2655125SChristophe Leroy#ifdef CONFIG_SMP
73*f2655125SChristophe Leroy	TLBSYNC
74*f2655125SChristophe Leroy	li	r0,0
75*f2655125SChristophe Leroy	stw	r0,0(r9)		/* clear mmu_hash_lock */
76*f2655125SChristophe Leroy	mtmsr	r10
77*f2655125SChristophe Leroy	isync
78*f2655125SChristophe Leroy#endif /* CONFIG_SMP */
79*f2655125SChristophe Leroy	blr
80*f2655125SChristophe Leroy_ASM_NOKPROBE_SYMBOL(_tlbia)
81