cpu_setup_power.S 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * This file contains low level CPU setup functions.
 *    Copyright (C) 2003 Benjamin Herrenschmidt (benh@kernel.crashing.org)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 *
 */

#include <asm/processor.h>
#include <asm/page.h>
#include <asm/cputable.h>
#include <asm/ppc_asm.h>
#include <asm/asm-offsets.h>
#include <asm/cache.h>
18
#include <asm/mmu-hash64.h>
19 20 21 22 23 24 25 26 27 28

/* Entry: r3 = crap, r4 = ptr to cputable entry
 *
 * Note that we can be called twice for pseudo-PVRs
 */
_GLOBAL(__setup_cpu_power7)
	mflr	r11
	bl	__init_hvmode_206
	mtlr	r11
	beqlr
29 30
	li	r0,0
	mtspr	SPRN_LPID,r0
31
	mfspr	r3,SPRN_LPCR
32
	bl	__init_LPCR
33
	bl	__init_tlb_power7
34 35 36 37 38 39 40 41
	mtlr	r11
	blr

_GLOBAL(__restore_cpu_power7)
	mflr	r11
	mfmsr	r3
	rldicl.	r0,r3,4,63
	beqlr
42 43
	li	r0,0
	mtspr	SPRN_LPID,r0
44
	mfspr	r3,SPRN_LPCR
45
	bl	__init_LPCR
46
	bl	__init_tlb_power7
M
Michael Neuling 已提交
47 48 49 50 51
	mtlr	r11
	blr

_GLOBAL(__setup_cpu_power8)
	mflr	r11
52
	bl	__init_FSCR
53
	bl	__init_PMU
M
Michael Neuling 已提交
54 55 56 57 58
	bl	__init_hvmode_206
	mtlr	r11
	beqlr
	li	r0,0
	mtspr	SPRN_LPID,r0
59
	mfspr	r3,SPRN_LPCR
60
	ori	r3, r3, LPCR_PECEDH
M
Michael Neuling 已提交
61
	bl	__init_LPCR
62
	bl	__init_HFSCR
63
	bl	__init_tlb_power8
64
	bl	__init_PMU_HV
M
Michael Neuling 已提交
65 66 67 68 69
	mtlr	r11
	blr

_GLOBAL(__restore_cpu_power8)
	mflr	r11
70
	bl	__init_FSCR
71
	bl	__init_PMU
M
Michael Neuling 已提交
72 73
	mfmsr	r3
	rldicl.	r0,r3,4,63
74
	mtlr	r11
M
Michael Neuling 已提交
75 76 77
	beqlr
	li	r0,0
	mtspr	SPRN_LPID,r0
78
	mfspr   r3,SPRN_LPCR
79
	ori	r3, r3, LPCR_PECEDH
M
Michael Neuling 已提交
80
	bl	__init_LPCR
81
	bl	__init_HFSCR
82
	bl	__init_tlb_power8
83
	bl	__init_PMU_HV
84 85 86
	mtlr	r11
	blr

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
_GLOBAL(__setup_cpu_power9)
	mflr	r11
	bl	__init_FSCR
	bl	__init_hvmode_206
	mtlr	r11
	beqlr
	li	r0,0
	mtspr	SPRN_LPID,r0
	mfspr	r3,SPRN_LPCR
	ori	r3, r3, LPCR_PECEDH
	bl	__init_LPCR
	bl	__init_HFSCR
	bl	__init_tlb_power9
	mtlr	r11
	blr

_GLOBAL(__restore_cpu_power9)
	mflr	r11
	bl	__init_FSCR
	mfmsr	r3
	rldicl.	r0,r3,4,63
	mtlr	r11
	beqlr
	li	r0,0
	mtspr	SPRN_LPID,r0
	mfspr   r3,SPRN_LPCR
	ori	r3, r3, LPCR_PECEDH
	bl	__init_LPCR
	bl	__init_HFSCR
	bl	__init_tlb_power9
	mtlr	r11
	blr

120
__init_hvmode_206:
121
	/* Disable CPU_FTR_HVMODE and exit if MSR:HV is not set */
122 123 124 125
	mfmsr	r3
	rldicl.	r0,r3,4,63
	bnelr
	ld	r5,CPU_SPEC_FEATURES(r4)
126
	LOAD_REG_IMMEDIATE(r6,CPU_FTR_HVMODE)
127 128 129 130 131 132
	xor	r5,r5,r6
	std	r5,CPU_SPEC_FEATURES(r4)
	blr

__init_LPCR:
	/* Setup a sane LPCR:
133
	 *   Called with initial LPCR in R3
134
	 *
135
	 *   LPES = 0b01 (HSRR0/1 used for 0x500)
136
	 *   PECE = 0b111
137
	 *   DPFD = 4
138 139 140
	 *   HDICE = 0
	 *   VC = 0b100 (VPM0=1, VPM1=0, ISL=0)
	 *   VRMASD = 0b10000 (L=1, LP=00)
141 142 143
	 *
	 * Other bits untouched for now
	 */
144 145
	li	r5,1
	rldimi	r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
146
	ori	r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
147
	li	r5,4
148 149 150 151 152 153
	rldimi	r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3
	clrrdi	r3,r3,1		/* clear HDICE */
	li	r5,4
	rldimi	r3,r5, LPCR_VC_SH, 0
	li	r5,0x10
	rldimi	r3,r5, LPCR_VRMASD_SH, 64-LPCR_VRMASD_SH-5
154 155 156
	mtspr	SPRN_LPCR,r3
	isync
	blr
157

158 159
__init_FSCR:
	mfspr	r3,SPRN_FSCR
160
	ori	r3,r3,FSCR_TAR|FSCR_DSCR|FSCR_EBB
161 162 163
	mtspr	SPRN_FSCR,r3
	blr

164 165
__init_HFSCR:
	mfspr	r3,SPRN_HFSCR
166
	ori	r3,r3,HFSCR_TAR|HFSCR_TM|HFSCR_BHRB|HFSCR_PM|\
167
		      HFSCR_DSCR|HFSCR_VECVSX|HFSCR_FP|HFSCR_EBB
168 169 170
	mtspr	SPRN_HFSCR,r3
	blr

171 172 173 174 175
/*
 * Clear the TLB using the specified IS form of tlbiel instruction
 * (invalidate by congruence class). P7 has 128 CCs., P8 has 512.
 */
__init_tlb_power7:
176
	li	r6,POWER7_TLB_SETS
177
	mtctr	r6
178
	li	r7,0xc00	/* IS field = 0b11 */
179 180 181 182 183 184 185 186
	ptesync
2:	tlbiel	r7
	addi	r7,r7,0x1000
	bdnz	2b
	ptesync
1:	blr

__init_tlb_power8:
187
	li	r6,POWER8_TLB_SETS
188
	mtctr	r6
189
	li	r7,0xc00	/* IS field = 0b11 */
190 191 192 193 194 195
	ptesync
2:	tlbiel	r7
	addi	r7,r7,0x1000
	bdnz	2b
	ptesync
1:	blr
196

197 198 199 200 201 202 203 204 205 206 207
__init_tlb_power9:
	li	r6,POWER9_TLB_SETS_HASH
	mtctr	r6
	li	r7,0xc00	/* IS field = 0b11 */
	ptesync
2:	tlbiel	r7
	addi	r7,r7,0x1000
	bdnz	2b
	ptesync
1:	blr

208 209 210 211 212 213 214 215 216 217 218 219 220 221
__init_PMU_HV:
	li	r5,0
	mtspr	SPRN_MMCRC,r5
	mtspr	SPRN_MMCRH,r5
	blr

__init_PMU:
	li	r5,0
	mtspr	SPRN_MMCRS,r5
	mtspr	SPRN_MMCRA,r5
	mtspr	SPRN_MMCR0,r5
	mtspr	SPRN_MMCR1,r5
	mtspr	SPRN_MMCR2,r5
	blr