2 * This file contains low level CPU setup functions.
3 * Copyright (C) 2003 Benjamin Herrenschmidt (benh@kernel.crashing.org)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
12 #include <asm/processor.h>
14 #include <asm/cputable.h>
15 #include <asm/ppc_asm.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/cache.h>
20 _GLOBAL(__setup_cpu_603)
24 mtspr SPRN_SPRG_603_LRU,r10 /* init SW LRU tracking */
25 END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU)
27 bl __init_fpu_registers
28 END_FTR_SECTION_IFCLR(CPU_FTR_FPU_UNAVAILABLE)
29 bl setup_common_caches
32 _GLOBAL(__setup_cpu_604)
34 bl setup_common_caches
38 _GLOBAL(__setup_cpu_750)
40 bl __init_fpu_registers
41 bl setup_common_caches
42 bl setup_750_7400_hid0
45 _GLOBAL(__setup_cpu_750cx)
47 bl __init_fpu_registers
48 bl setup_common_caches
49 bl setup_750_7400_hid0
53 _GLOBAL(__setup_cpu_750fx)
55 bl __init_fpu_registers
56 bl setup_common_caches
57 bl setup_750_7400_hid0
61 _GLOBAL(__setup_cpu_7400)
63 bl __init_fpu_registers
64 bl setup_7400_workarounds
65 bl setup_common_caches
66 bl setup_750_7400_hid0
69 _GLOBAL(__setup_cpu_7410)
71 bl __init_fpu_registers
72 bl setup_7410_workarounds
73 bl setup_common_caches
74 bl setup_750_7400_hid0
79 _GLOBAL(__setup_cpu_745x)
81 bl setup_common_caches
82 bl setup_745x_specifics
86 /* Enable caches for 603's, 604, 750 & 7400 */
90 ori r11,r11,HID0_ICE|HID0_DCE
92 bne 1f /* don't invalidate the D-cache */
93 ori r8,r8,HID0_DCI /* unless it wasn't enabled */
95 mtspr SPRN_HID0,r8 /* enable and invalidate caches */
97 mtspr SPRN_HID0,r11 /* enable caches */
102 /* 604, 604e, 604ev, ...
103 * Enable superscalar execution & branch history table
107 ori r11,r11,HID0_SIED|HID0_BHTE
110 mtspr SPRN_HID0,r8 /* flush branch target address cache */
111 sync /* on 604e/604r */
117 /* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
118 * erratas we work around here.
119 * Moto MPC710CE.pdf describes them, those are errata
121 * Note that we assume the firmware didn't choose to
122 * apply other workarounds (there are other ones documented
123 * in the .pdf). It appear that Apple firmware only works
124 * around #3 and with the same fix we use. We may want to
125 * check if the CPU is using 60x bus mode in which case
126 * the workaround for errata #4 is useless. Also, we may
127 * want to explicitly clear HID0_NOPDST as this is not
128 * needed once we have applied workaround #5 (though it's
129 * not set by Apple's firmware at least).
131 setup_7400_workarounds:
137 setup_7410_workarounds:
143 mfspr r11,SPRN_MSSSR0
144 /* Errata #3: Set L1OPQ_SIZE to 0x10 */
147 /* Errata #4: Set L2MQ_SIZE to 1 (check for MPX mode first ?) */
149 /* Errata #5: Set DRLT_SIZE to 0x01 */
153 mtspr SPRN_MSSSR0,r11
159 * Enable Store Gathering (SGE), Address Broadcast (ABE),
160 * Branch History Table (BHTE), Branch Target ICache (BTIC)
161 * Dynamic Power Management (DPM), Speculative (SPD)
162 * Clear Instruction cache throttling (ICTC)
166 ori r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
167 oris r11,r11,HID0_DPM@h
169 xori r11,r11,HID0_BTIC
170 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
172 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
173 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
175 andc r11,r11,r3 /* clear SPD: enable speculative */
177 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
185 * Looks like we have to disable NAP feature for some PLL settings...
186 * (waiting for confirmation)
190 rlwinm r10,r10,4,28,31
194 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
195 cror 4*cr0+eq,4*cr0+eq,4*cr2+eq
197 lwz r6,CPU_SPEC_FEATURES(r4)
198 li r7,CPU_FTR_CAN_NAP
200 stw r6,CPU_SPEC_FEATURES(r4)
209 * Enable Store Gathering (SGE), Branch Folding (FOLD)
210 * Branch History Table (BHTE), Branch Target ICache (BTIC)
211 * Dynamic Power Management (DPM), Speculative (SPD)
212 * Ensure our data cache instructions really operate.
213 * Timebase has to be running or we wouldn't have made it here,
214 * just ensure we don't disable it.
215 * Clear Instruction cache throttling (ICTC)
216 * Enable L2 HW prefetch
218 setup_745x_specifics:
219 /* We check for the presence of an L3 cache setup by
220 * the firmware. If any, we disable NAP capability as
221 * it's known to be bogus on rev 2.1 and earlier
225 andis. r11,r11,L3CR_L3E@h
227 END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
228 lwz r6,CPU_SPEC_FEATURES(r4)
229 andi. r0,r6,CPU_FTR_L3_DISABLE_NAP
231 li r7,CPU_FTR_CAN_NAP
233 stw r6,CPU_SPEC_FEATURES(r4)
237 /* All of the bits we have to set.....
239 ori r11,r11,HID0_SGE | HID0_FOLD | HID0_BHTE
240 ori r11,r11,HID0_LRSTK | HID0_BTIC
241 oris r11,r11,HID0_DPM@h
242 BEGIN_MMU_FTR_SECTION
243 oris r11,r11,HID0_HIGH_BAT@h
244 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
246 xori r11,r11,HID0_BTIC
247 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
249 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
250 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
252 /* All of the bits we have to clear....
254 li r3,HID0_SPD | HID0_NOPDST | HID0_NOPTI
255 andc r11,r11,r3 /* clear SPD: enable speculative */
258 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
264 /* Enable L2 HW prefetch, if L2 is enabled
267 andis. r3,r3,L2CR_L2E@h
278 * Initialize the FPU registers. This is needed to work around an errata
279 * in some 750 cpus where using a not yet initialized FPU register after
280 * power on reset may hang the CPU
282 _GLOBAL(__init_fpu_registers)
287 addis r9,r3,empty_zero_page@ha
288 addi r9,r9,empty_zero_page@l
296 /* Definitions for the table use to save CPU states */
308 .balign L1_CACHE_BYTES
311 .balign L1_CACHE_BYTES,0
314 /* Called in normal context to backup CPU 0 state. This
315 * does not include cache settings. This function is also
316 * called for machine sleep. This does not include the MMU
317 * setup, BATs, etc... but rather the "special" registers
318 * like HID0, HID1, MSSCR0, etc...
320 _GLOBAL(__save_cpu_setup)
321 /* Some CR fields are volatile, we back it up all */
324 /* Get storage ptr */
325 lis r5,cpu_state_storage@h
326 ori r5,r5,cpu_state_storage@l
328 /* Save HID0 (common to all CONFIG_6xx cpus) */
332 /* Now deal with CPU type dependent registers */
335 cmplwi cr0,r3,0x8000 /* 7450 */
336 cmplwi cr1,r3,0x000c /* 7400 */
337 cmplwi cr2,r3,0x800c /* 7410 */
338 cmplwi cr3,r3,0x8001 /* 7455 */
339 cmplwi cr4,r3,0x8002 /* 7457 */
340 cmplwi cr5,r3,0x8003 /* 7447A */
341 cmplwi cr6,r3,0x7000 /* 750FX */
342 cmplwi cr7,r3,0x8004 /* 7448 */
343 /* cr1 is 7400 || 7410 */
344 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
346 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
347 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
348 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
349 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
350 cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
352 /* Backup 74xx specific regs */
358 /* Backup 745x specific registers */
369 /* Backup 750FX specific registers */
372 /* If rev 2.x, backup HID2 */
383 /* Called with no MMU context (typically MSR:IR/DR off) to
384 * restore CPU state as backed up by the previous
385 * function. This does not include cache setting
387 _GLOBAL(__restore_cpu_setup)
388 /* Some CR fields are volatile, we back it up all */
391 /* Get storage ptr */
392 lis r5,(cpu_state_storage-KERNELBASE)@h
393 ori r5,r5,cpu_state_storage@l
403 /* Now deal with CPU type dependent registers */
406 cmplwi cr0,r3,0x8000 /* 7450 */
407 cmplwi cr1,r3,0x000c /* 7400 */
408 cmplwi cr2,r3,0x800c /* 7410 */
409 cmplwi cr3,r3,0x8001 /* 7455 */
410 cmplwi cr4,r3,0x8002 /* 7457 */
411 cmplwi cr5,r3,0x8003 /* 7447A */
412 cmplwi cr6,r3,0x7000 /* 750FX */
413 cmplwi cr7,r3,0x8004 /* 7448 */
414 /* cr1 is 7400 || 7410 */
415 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
417 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
418 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
419 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
420 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
421 cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
423 /* Restore 74xx specific regs */
435 /* Clear 7410 L2CR2 */
439 /* Restore 745x specific registers */
461 /* Restore 750FX specific registers
462 * that is restore HID2 on rev 2.x and PLL config & switch
465 /* If rev 2.x, restore HID2 with low voltage bit cleared */
478 /* Wait for PLL to stabilize */
484 /* Setup final PLL */