1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * This file contains low level CPU setup functions.
4 * Copyright (C) 2003 Benjamin Herrenschmidt (benh@kernel.crashing.org)
7 #include <linux/linkage.h>
9 #include <asm/processor.h>
11 #include <asm/cputable.h>
12 #include <asm/ppc_asm.h>
13 #include <asm/asm-offsets.h>
14 #include <asm/cache.h>
16 #include <asm/feature-fixups.h>
18 _GLOBAL(__setup_cpu_603)
22 mtspr SPRN_SPRG_603_LRU,r10 /* init SW LRU tracking */
23 END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU)
26 bl __init_fpu_registers
27 END_FTR_SECTION_IFCLR(CPU_FTR_FPU_UNAVAILABLE)
28 bl setup_common_caches
31 * This assumes that all cores using __setup_cpu_603 with
32 * MMU_FTR_USE_HIGH_BATS are G2_LE compatible
36 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
40 _GLOBAL(__setup_cpu_604)
42 bl setup_common_caches
46 _GLOBAL(__setup_cpu_750)
48 bl __init_fpu_registers
49 bl setup_common_caches
50 bl setup_750_7400_hid0
53 _GLOBAL(__setup_cpu_750cx)
55 bl __init_fpu_registers
56 bl setup_common_caches
57 bl setup_750_7400_hid0
61 _GLOBAL(__setup_cpu_750fx)
63 bl __init_fpu_registers
64 bl setup_common_caches
65 bl setup_750_7400_hid0
69 _GLOBAL(__setup_cpu_7400)
71 bl __init_fpu_registers
72 bl setup_7400_workarounds
73 bl setup_common_caches
74 bl setup_750_7400_hid0
77 _GLOBAL(__setup_cpu_7410)
79 bl __init_fpu_registers
80 bl setup_7410_workarounds
81 bl setup_common_caches
82 bl setup_750_7400_hid0
87 _GLOBAL(__setup_cpu_745x)
89 bl setup_common_caches
90 bl setup_745x_specifics
94 /* Enable caches for 603's, 604, 750 & 7400 */
95 SYM_FUNC_START_LOCAL(setup_common_caches)
98 ori r11,r11,HID0_ICE|HID0_DCE
100 bne 1f /* don't invalidate the D-cache */
101 ori r8,r8,HID0_DCI /* unless it wasn't enabled */
103 mtspr SPRN_HID0,r8 /* enable and invalidate caches */
105 mtspr SPRN_HID0,r11 /* enable caches */
109 SYM_FUNC_END(setup_common_caches)
111 /* 604, 604e, 604ev, ...
112 * Enable superscalar execution & branch history table
114 SYM_FUNC_START_LOCAL(setup_604_hid0)
116 ori r11,r11,HID0_SIED|HID0_BHTE
119 mtspr SPRN_HID0,r8 /* flush branch target address cache */
120 sync /* on 604e/604r */
125 SYM_FUNC_END(setup_604_hid0)
127 /* Enable high BATs for G2_LE and derivatives like e300cX */
128 SYM_FUNC_START_LOCAL(setup_g2_le_hid2)
129 mfspr r11,SPRN_HID2_G2_LE
130 oris r11,r11,HID2_G2_LE_HBE@h
131 mtspr SPRN_HID2_G2_LE,r11
135 SYM_FUNC_END(setup_g2_le_hid2)
137 /* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
138 * erratas we work around here.
139 * Moto MPC710CE.pdf describes them, those are errata
141 * Note that we assume the firmware didn't choose to
142 * apply other workarounds (there are other ones documented
143 * in the .pdf). It appear that Apple firmware only works
144 * around #3 and with the same fix we use. We may want to
145 * check if the CPU is using 60x bus mode in which case
146 * the workaround for errata #4 is useless. Also, we may
147 * want to explicitly clear HID0_NOPDST as this is not
148 * needed once we have applied workaround #5 (though it's
149 * not set by Apple's firmware at least).
151 SYM_FUNC_START_LOCAL(setup_7400_workarounds)
157 SYM_FUNC_END(setup_7400_workarounds)
158 SYM_FUNC_START_LOCAL(setup_7410_workarounds)
164 mfspr r11,SPRN_MSSSR0
165 /* Errata #3: Set L1OPQ_SIZE to 0x10 */
168 /* Errata #4: Set L2MQ_SIZE to 1 (check for MPX mode first ?) */
170 /* Errata #5: Set DRLT_SIZE to 0x01 */
174 mtspr SPRN_MSSSR0,r11
178 SYM_FUNC_END(setup_7410_workarounds)
181 * Enable Store Gathering (SGE), Address Broadcast (ABE),
182 * Branch History Table (BHTE), Branch Target ICache (BTIC)
183 * Dynamic Power Management (DPM), Speculative (SPD)
184 * Clear Instruction cache throttling (ICTC)
186 SYM_FUNC_START_LOCAL(setup_750_7400_hid0)
188 ori r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
189 oris r11,r11,HID0_DPM@h
191 xori r11,r11,HID0_BTIC
192 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
194 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
195 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
197 andc r11,r11,r3 /* clear SPD: enable speculative */
199 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
205 SYM_FUNC_END(setup_750_7400_hid0)
208 * Looks like we have to disable NAP feature for some PLL settings...
209 * (waiting for confirmation)
211 SYM_FUNC_START_LOCAL(setup_750cx)
213 rlwinm r10,r10,4,28,31
217 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
218 cror 4*cr0+eq,4*cr0+eq,4*cr2+eq
220 lwz r6,CPU_SPEC_FEATURES(r4)
221 li r7,CPU_FTR_CAN_NAP
223 stw r6,CPU_SPEC_FEATURES(r4)
225 SYM_FUNC_END(setup_750cx)
229 SYM_FUNC_START_LOCAL(setup_750fx)
231 SYM_FUNC_END(setup_750fx)
234 * Enable Store Gathering (SGE), Branch Folding (FOLD)
235 * Branch History Table (BHTE), Branch Target ICache (BTIC)
236 * Dynamic Power Management (DPM), Speculative (SPD)
237 * Ensure our data cache instructions really operate.
238 * Timebase has to be running or we wouldn't have made it here,
239 * just ensure we don't disable it.
240 * Clear Instruction cache throttling (ICTC)
241 * Enable L2 HW prefetch
243 SYM_FUNC_START_LOCAL(setup_745x_specifics)
244 /* We check for the presence of an L3 cache setup by
245 * the firmware. If any, we disable NAP capability as
246 * it's known to be bogus on rev 2.1 and earlier
250 andis. r11,r11,L3CR_L3E@h
252 END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
253 lwz r6,CPU_SPEC_FEATURES(r4)
254 andis. r0,r6,CPU_FTR_L3_DISABLE_NAP@h
256 li r7,CPU_FTR_CAN_NAP
258 stw r6,CPU_SPEC_FEATURES(r4)
262 /* All of the bits we have to set.....
264 ori r11,r11,HID0_SGE | HID0_FOLD | HID0_BHTE
265 ori r11,r11,HID0_LRSTK | HID0_BTIC
266 oris r11,r11,HID0_DPM@h
267 BEGIN_MMU_FTR_SECTION
268 oris r11,r11,HID0_HIGH_BAT@h
269 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
271 xori r11,r11,HID0_BTIC
272 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
274 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
275 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
277 /* All of the bits we have to clear....
279 li r3,HID0_SPD | HID0_NOPDST | HID0_NOPTI
280 andc r11,r11,r3 /* clear SPD: enable speculative */
283 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
289 /* Enable L2 HW prefetch, if L2 is enabled
292 andis. r3,r3,L2CR_L2E@h
301 SYM_FUNC_END(setup_745x_specifics)
304 * Initialize the FPU registers. This is needed to work around an errata
305 * in some 750 cpus where using a not yet initialized FPU register after
306 * power on reset may hang the CPU
308 _GLOBAL(__init_fpu_registers)
313 addis r9,r3,empty_zero_page@ha
314 addi r9,r9,empty_zero_page@l
320 _ASM_NOKPROBE_SYMBOL(__init_fpu_registers)
323 /* Definitions for the table use to save CPU states */
335 .balign L1_CACHE_BYTES
338 .balign L1_CACHE_BYTES,0
341 /* Called in normal context to backup CPU 0 state. This
342 * does not include cache settings. This function is also
343 * called for machine sleep. This does not include the MMU
344 * setup, BATs, etc... but rather the "special" registers
345 * like HID0, HID1, MSSCR0, etc...
347 _GLOBAL(__save_cpu_setup)
348 /* Some CR fields are volatile, we back it up all */
351 /* Get storage ptr */
352 lis r5,cpu_state_storage@h
353 ori r5,r5,cpu_state_storage@l
355 /* Save HID0 (common to all CONFIG_PPC_BOOK3S_32 cpus) */
359 /* Now deal with CPU type dependent registers */
362 cmplwi cr0,r3,0x8000 /* 7450 */
363 cmplwi cr1,r3,0x000c /* 7400 */
364 cmplwi cr2,r3,0x800c /* 7410 */
365 cmplwi cr3,r3,0x8001 /* 7455 */
366 cmplwi cr4,r3,0x8002 /* 7457 */
367 cmplwi cr5,r3,0x8003 /* 7447A */
368 cmplwi cr6,r3,0x7000 /* 750FX */
369 cmplwi cr7,r3,0x8004 /* 7448 */
370 /* cr1 is 7400 || 7410 */
371 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
373 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
374 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
375 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
376 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
377 cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
379 /* Backup 74xx specific regs */
385 /* Backup 745x specific registers */
396 /* Backup 750FX specific registers */
399 /* If rev 2.x, backup HID2 */
404 mfspr r4,SPRN_HID2_750FX
410 /* Called with no MMU context (typically MSR:IR/DR off) to
411 * restore CPU state as backed up by the previous
412 * function. This does not include cache setting
414 _GLOBAL(__restore_cpu_setup)
415 /* Some CR fields are volatile, we back it up all */
418 /* Get storage ptr */
419 lis r5,(cpu_state_storage-KERNELBASE)@h
420 ori r5,r5,cpu_state_storage@l
430 /* Now deal with CPU type dependent registers */
433 cmplwi cr0,r3,0x8000 /* 7450 */
434 cmplwi cr1,r3,0x000c /* 7400 */
435 cmplwi cr2,r3,0x800c /* 7410 */
436 cmplwi cr3,r3,0x8001 /* 7455 */
437 cmplwi cr4,r3,0x8002 /* 7457 */
438 cmplwi cr5,r3,0x8003 /* 7447A */
439 cmplwi cr6,r3,0x7000 /* 750FX */
440 cmplwi cr7,r3,0x8004 /* 7448 */
441 /* cr1 is 7400 || 7410 */
442 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
444 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
445 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
446 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
447 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
448 cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
450 /* Restore 74xx specific regs */
462 /* Clear 7410 L2CR2 */
466 /* Restore 745x specific registers */
488 /* Restore 750FX specific registers
489 * that is restore HID2 on rev 2.x and PLL config & switch
492 /* If rev 2.x, restore HID2 with low voltage bit cleared */
499 mtspr SPRN_HID2_750FX,r4
505 /* Wait for PLL to stabilize */
511 /* Setup final PLL */
516 _ASM_NOKPROBE_SYMBOL(__restore_cpu_setup)