1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * This file contains low level CPU setup functions.
4 * Kumar Gala <galak@kernel.crashing.org>
5 * Copyright 2009 Freescale Semiconductor, Inc.
7 * Based on cpu_setup_6xx code by
8 * Benjamin Herrenschmidt <benh@kernel.crashing.org>
12 #include <asm/processor.h>
13 #include <asm/cputable.h>
14 #include <asm/ppc_asm.h>
15 #include <asm/nohash/mmu-book3e.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/mpc85xx.h>
19 _GLOBAL(__e500_icache_setup)
21 andi. r3, r0, L1CSR1_ICE
22 bnelr /* Already enabled */
23 oris r0, r0, L1CSR1_CPE@h
24 ori r0, r0, (L1CSR1_ICFI | L1CSR1_ICLFR | L1CSR1_ICE)
25 mtspr SPRN_L1CSR1, r0 /* Enable I-Cache */
29 _GLOBAL(__e500_dcache_setup)
31 andi. r3, r0, L1CSR0_DCE
32 bnelr /* Already enabled */
36 mtspr SPRN_L1CSR0, r0 /* Disable */
39 li r0, (L1CSR0_DCFI | L1CSR0_CLFC)
40 mtspr SPRN_L1CSR0, r0 /* Invalidate */
42 1: mfspr r0, SPRN_L1CSR0
43 andi. r3, r0, L1CSR0_CLFC
44 bne+ 1b /* Wait for lock bits reset */
45 oris r0, r0, L1CSR0_CPE@h
46 ori r0, r0, L1CSR0_DCE
49 mtspr SPRN_L1CSR0, r0 /* Enable */
54 * FIXME - we haven't yet done testing to determine a reasonable default
55 * value for PW20_WAIT_IDLE_BIT.
57 #define PW20_WAIT_IDLE_BIT 50 /* 1ms, TB frequency is 41.66MHZ */
58 _GLOBAL(setup_pw20_idle)
59 mfspr r3, SPRN_PWRMGTCR0
61 /* Set PW20_WAIT bit, enable pw20 state*/
62 ori r3, r3, PWRMGTCR0_PW20_WAIT
63 li r11, PW20_WAIT_IDLE_BIT
65 /* Set Automatic PW20 Core Idle Count */
66 rlwimi r3, r11, PWRMGTCR0_PW20_ENT_SHIFT, PWRMGTCR0_PW20_ENT
68 mtspr SPRN_PWRMGTCR0, r3
73 * FIXME - we haven't yet done testing to determine a reasonable default
74 * value for AV_WAIT_IDLE_BIT.
76 #define AV_WAIT_IDLE_BIT 50 /* 1ms, TB frequency is 41.66MHZ */
77 _GLOBAL(setup_altivec_idle)
78 mfspr r3, SPRN_PWRMGTCR0
80 /* Enable Altivec Idle */
81 oris r3, r3, PWRMGTCR0_AV_IDLE_PD_EN@h
82 li r11, AV_WAIT_IDLE_BIT
84 /* Set Automatic AltiVec Idle Count */
85 rlwimi r3, r11, PWRMGTCR0_AV_IDLE_CNT_SHIFT, PWRMGTCR0_AV_IDLE_CNT
87 mtspr SPRN_PWRMGTCR0, r3
91 #ifdef CONFIG_PPC_E500MC
92 _GLOBAL(__setup_cpu_e6500)
95 bl setup_altivec_ivors
96 /* Touch IVOR42 only if the CPU supports E.HV category */
98 rlwinm. r10,r10,0,MMUCFG_LPIDSIZE
104 bl setup_altivec_idle
108 #endif /* CONFIG_PPC_E500MC */
112 #ifndef CONFIG_PPC_E500MC
113 _GLOBAL(__setup_cpu_e500v1)
114 _GLOBAL(__setup_cpu_e500v2)
116 bl __e500_icache_setup
117 bl __e500_dcache_setup
118 bl __setup_e500_ivors
119 #if defined(CONFIG_FSL_RIO) || defined(CONFIG_FSL_PCI)
120 /* Ensure that RFXE is set */
122 oris r3,r3,HID1_RFXE@h
127 #else /* CONFIG_PPC_E500MC */
128 _GLOBAL(__setup_cpu_e500mc)
129 _GLOBAL(__setup_cpu_e5500)
131 bl __e500_icache_setup
132 bl __e500_dcache_setup
133 bl __setup_e500mc_ivors
135 * We only want to touch IVOR38-41 if we're running on hardware
136 * that supports category E.HV. The architectural way to determine
137 * this is MMUCFG[LPIDSIZE].
139 mfspr r3, SPRN_MMUCFG
140 rlwinm. r3, r3, 0, MMUCFG_LPIDSIZE
145 lwz r3, CPU_SPEC_FEATURES(r4)
146 /* We need this check as cpu_setup is also called for
147 * the secondary cores. So, if we have already cleared
148 * the feature on the primary core, avoid doing it on the
151 andi. r6, r3, CPU_FTR_EMB_HV
153 rlwinm r3, r3, 0, ~CPU_FTR_EMB_HV
154 stw r3, CPU_SPEC_FEATURES(r4)
158 #endif /* CONFIG_PPC_E500MC */
159 #endif /* CONFIG_E500 */
160 #endif /* CONFIG_PPC32 */
162 #ifdef CONFIG_PPC_BOOK3E_64
163 _GLOBAL(__restore_cpu_e6500)
165 bl setup_altivec_ivors
166 /* Touch IVOR42 only if the CPU supports E.HV category */
167 mfspr r10,SPRN_MMUCFG
168 rlwinm. r10,r10,0,MMUCFG_LPIDSIZE
173 bl setup_altivec_idle
174 bl __restore_cpu_e5500
178 _GLOBAL(__restore_cpu_e5500)
180 bl __e500_icache_setup
181 bl __e500_dcache_setup
182 bl __setup_base_ivors
183 bl setup_perfmon_ivor
184 bl setup_doorbell_ivors
186 * We only want to touch IVOR38-41 if we're running on hardware
187 * that supports category E.HV. The architectural way to determine
188 * this is MMUCFG[LPIDSIZE].
190 mfspr r10,SPRN_MMUCFG
191 rlwinm. r10,r10,0,MMUCFG_LPIDSIZE
198 _GLOBAL(__setup_cpu_e5500)
200 bl __e500_icache_setup
201 bl __e500_dcache_setup
202 bl __setup_base_ivors
203 bl setup_perfmon_ivor
204 bl setup_doorbell_ivors
206 * We only want to touch IVOR38-41 if we're running on hardware
207 * that supports category E.HV. The architectural way to determine
208 * this is MMUCFG[LPIDSIZE].
210 mfspr r10,SPRN_MMUCFG
211 rlwinm. r10,r10,0,MMUCFG_LPIDSIZE
216 ld r10,CPU_SPEC_FEATURES(r4)
217 LOAD_REG_IMMEDIATE(r9,CPU_FTR_EMB_HV)
219 std r10,CPU_SPEC_FEATURES(r4)
225 /* flush L1 data cache, it can apply to e500v2, e500mc and e5500 */
226 _GLOBAL(flush_dcache_L1)
231 rlwinm r5,r3,9,3 /* Extract cache block size */
232 twlgti r5,1 /* Only 32 and 64 byte cache blocks
233 * are currently defined.
236 subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
237 * log2(number of ways)
239 slw r5,r4,r5 /* r5 = cache block size */
241 rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
242 mulli r7,r7,13 /* An 8-way cache will require 13
247 /* save off HID0 and set DCFA */
249 ori r9,r8,HID0_DCFA@l
253 LOAD_REG_IMMEDIATE(r6, KERNELBASE)
257 1: lwz r3,0(r4) /* Load... */
265 1: dcbf 0,r4 /* ...and flush. */
278 /* skip L2 cache on P2040/P2040E as they have no L2 cache */
280 /* shift right by 8 bits and clear E bit of SVR */
281 rlwinm r4, r3, 24, ~0x800
284 ori r3, r3, SVR_P2040@l
294 /* flush backside L2 cache */
295 flush_backside_L2_cache:
302 /* Flush the L2 cache */
303 mfspr r3, SPRN_L2CSR0
304 ori r3, r3, L2CSR0_L2FL@l
310 /* check if it is complete */
311 1: mfspr r3,SPRN_L2CSR0
312 andi. r3, r3, L2CSR0_L2FL@l
317 _GLOBAL(cpu_down_flush_e500v2)
323 _GLOBAL(cpu_down_flush_e500mc)
324 _GLOBAL(cpu_down_flush_e5500)
327 bl flush_backside_L2_cache
331 /* L1 Data Cache of e6500 contains no modified data, no flush is required */
332 _GLOBAL(cpu_down_flush_e6500)