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>
19 _GLOBAL(__setup_cpu_603)
22 bl __init_fpu_registers
23 END_FTR_SECTION_IFCLR(CPU_FTR_FPU_UNAVAILABLE)
24 bl setup_common_caches
27 _GLOBAL(__setup_cpu_604)
29 bl setup_common_caches
33 _GLOBAL(__setup_cpu_750)
35 bl __init_fpu_registers
36 bl setup_common_caches
37 bl setup_750_7400_hid0
40 _GLOBAL(__setup_cpu_750cx)
42 bl __init_fpu_registers
43 bl setup_common_caches
44 bl setup_750_7400_hid0
48 _GLOBAL(__setup_cpu_750fx)
50 bl __init_fpu_registers
51 bl setup_common_caches
52 bl setup_750_7400_hid0
56 _GLOBAL(__setup_cpu_7400)
58 bl __init_fpu_registers
59 bl setup_7400_workarounds
60 bl setup_common_caches
61 bl setup_750_7400_hid0
64 _GLOBAL(__setup_cpu_7410)
66 bl __init_fpu_registers
67 bl setup_7410_workarounds
68 bl setup_common_caches
69 bl setup_750_7400_hid0
74 _GLOBAL(__setup_cpu_745x)
76 bl setup_common_caches
77 bl setup_745x_specifics
81 /* Enable caches for 603's, 604, 750 & 7400 */
85 ori r11,r11,HID0_ICE|HID0_DCE
87 bne 1f /* don't invalidate the D-cache */
88 ori r8,r8,HID0_DCI /* unless it wasn't enabled */
90 mtspr SPRN_HID0,r8 /* enable and invalidate caches */
92 mtspr SPRN_HID0,r11 /* enable caches */
97 /* 604, 604e, 604ev, ...
98 * Enable superscalar execution & branch history table
102 ori r11,r11,HID0_SIED|HID0_BHTE
105 mtspr SPRN_HID0,r8 /* flush branch target address cache */
106 sync /* on 604e/604r */
112 /* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
113 * erratas we work around here.
114 * Moto MPC710CE.pdf describes them, those are errata
116 * Note that we assume the firmware didn't choose to
117 * apply other workarounds (there are other ones documented
118 * in the .pdf). It appear that Apple firmware only works
119 * around #3 and with the same fix we use. We may want to
120 * check if the CPU is using 60x bus mode in which case
121 * the workaround for errata #4 is useless. Also, we may
122 * want to explicitly clear HID0_NOPDST as this is not
123 * needed once we have applied workaround #5 (though it's
124 * not set by Apple's firmware at least).
126 setup_7400_workarounds:
132 setup_7410_workarounds:
138 mfspr r11,SPRN_MSSSR0
139 /* Errata #3: Set L1OPQ_SIZE to 0x10 */
142 /* Errata #4: Set L2MQ_SIZE to 1 (check for MPX mode first ?) */
144 /* Errata #5: Set DRLT_SIZE to 0x01 */
148 mtspr SPRN_MSSSR0,r11
154 * Enable Store Gathering (SGE), Address Brodcast (ABE),
155 * Branch History Table (BHTE), Branch Target ICache (BTIC)
156 * Dynamic Power Management (DPM), Speculative (SPD)
157 * Clear Instruction cache throttling (ICTC)
161 ori r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
162 oris r11,r11,HID0_DPM@h
164 xori r11,r11,HID0_BTIC
165 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
167 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
168 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
170 andc r11,r11,r3 /* clear SPD: enable speculative */
172 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
180 * Looks like we have to disable NAP feature for some PLL settings...
181 * (waiting for confirmation)
185 rlwinm r10,r10,4,28,31
189 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
190 cror 4*cr0+eq,4*cr0+eq,4*cr2+eq
192 lwz r6,CPU_SPEC_FEATURES(r5)
193 li r7,CPU_FTR_CAN_NAP
195 stw r6,CPU_SPEC_FEATURES(r5)
204 * Enable Store Gathering (SGE), Branch Folding (FOLD)
205 * Branch History Table (BHTE), Branch Target ICache (BTIC)
206 * Dynamic Power Management (DPM), Speculative (SPD)
207 * Ensure our data cache instructions really operate.
208 * Timebase has to be running or we wouldn't have made it here,
209 * just ensure we don't disable it.
210 * Clear Instruction cache throttling (ICTC)
211 * Enable L2 HW prefetch
213 setup_745x_specifics:
214 /* We check for the presence of an L3 cache setup by
215 * the firmware. If any, we disable NAP capability as
216 * it's known to be bogus on rev 2.1 and earlier
220 andis. r11,r11,L3CR_L3E@h
222 END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
223 lwz r6,CPU_SPEC_FEATURES(r5)
224 andi. r0,r6,CPU_FTR_L3_DISABLE_NAP
226 li r7,CPU_FTR_CAN_NAP
228 stw r6,CPU_SPEC_FEATURES(r5)
232 /* All of the bits we have to set.....
234 ori r11,r11,HID0_SGE | HID0_FOLD | HID0_BHTE
235 ori r11,r11,HID0_LRSTK | HID0_BTIC
236 oris r11,r11,HID0_DPM@h
238 xori r11,r11,HID0_BTIC
239 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
241 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
242 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
244 /* All of the bits we have to clear....
246 li r3,HID0_SPD | HID0_NOPDST | HID0_NOPTI
247 andc r11,r11,r3 /* clear SPD: enable speculative */
250 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
256 /* Enable L2 HW prefetch, if L2 is enabled
259 andis. r3,r3,L2CR_L2E@h
270 * Initialize the FPU registers. This is needed to work around an errata
271 * in some 750 cpus where using a not yet initialized FPU register after
272 * power on reset may hang the CPU
274 _GLOBAL(__init_fpu_registers)
279 addis r9,r3,empty_zero_page@ha
280 addi r9,r9,empty_zero_page@l
288 /* Definitions for the table use to save CPU states */
300 .balign L1_CACHE_BYTES
303 .balign L1_CACHE_BYTES,0
306 /* Called in normal context to backup CPU 0 state. This
307 * does not include cache settings. This function is also
308 * called for machine sleep. This does not include the MMU
309 * setup, BATs, etc... but rather the "special" registers
310 * like HID0, HID1, MSSCR0, etc...
312 _GLOBAL(__save_cpu_setup)
313 /* Some CR fields are volatile, we back it up all */
316 /* Get storage ptr */
317 lis r5,cpu_state_storage@h
318 ori r5,r5,cpu_state_storage@l
320 /* Save HID0 (common to all CONFIG_6xx cpus) */
324 /* Now deal with CPU type dependent registers */
327 cmplwi cr0,r3,0x8000 /* 7450 */
328 cmplwi cr1,r3,0x000c /* 7400 */
329 cmplwi cr2,r3,0x800c /* 7410 */
330 cmplwi cr3,r3,0x8001 /* 7455 */
331 cmplwi cr4,r3,0x8002 /* 7457 */
332 cmplwi cr5,r3,0x8003 /* 7447A */
333 cmplwi cr6,r3,0x7000 /* 750FX */
334 cmplwi cr7,r3,0x8004 /* 7448 */
335 /* cr1 is 7400 || 7410 */
336 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
338 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
339 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
340 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
341 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
342 cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
344 /* Backup 74xx specific regs */
350 /* Backup 745x specific registers */
361 /* Backup 750FX specific registers */
364 /* If rev 2.x, backup HID2 */
375 /* Called with no MMU context (typically MSR:IR/DR off) to
376 * restore CPU state as backed up by the previous
377 * function. This does not include cache setting
379 _GLOBAL(__restore_cpu_setup)
380 /* Some CR fields are volatile, we back it up all */
383 /* Get storage ptr */
384 lis r5,(cpu_state_storage-KERNELBASE)@h
385 ori r5,r5,cpu_state_storage@l
395 /* Now deal with CPU type dependent registers */
398 cmplwi cr0,r3,0x8000 /* 7450 */
399 cmplwi cr1,r3,0x000c /* 7400 */
400 cmplwi cr2,r3,0x800c /* 7410 */
401 cmplwi cr3,r3,0x8001 /* 7455 */
402 cmplwi cr4,r3,0x8002 /* 7457 */
403 cmplwi cr5,r3,0x8003 /* 7447A */
404 cmplwi cr6,r3,0x7000 /* 750FX */
405 cmplwi cr7,r3,0x8004 /* 7448 */
406 /* cr1 is 7400 || 7410 */
407 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
409 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
410 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
411 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
412 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
413 cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
415 /* Restore 74xx specific regs */
427 /* Clear 7410 L2CR2 */
431 /* Restore 745x specific registers */
453 /* Restore 750FX specific registers
454 * that is restore HID2 on rev 2.x and PLL config & switch
457 /* If rev 2.x, restore HID2 with low voltage bit cleared */
470 /* Wait for PLL to stabilize */
476 /* Setup final PLL */