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)
21 _GLOBAL(__setup_cpu_604)
23 bl setup_common_caches
27 _GLOBAL(__setup_cpu_750)
29 bl __init_fpu_registers
30 bl setup_common_caches
31 bl setup_750_7400_hid0
34 _GLOBAL(__setup_cpu_750cx)
36 bl __init_fpu_registers
37 bl setup_common_caches
38 bl setup_750_7400_hid0
42 _GLOBAL(__setup_cpu_750fx)
44 bl __init_fpu_registers
45 bl setup_common_caches
46 bl setup_750_7400_hid0
50 _GLOBAL(__setup_cpu_7400)
52 bl __init_fpu_registers
53 bl setup_7400_workarounds
54 bl setup_common_caches
55 bl setup_750_7400_hid0
58 _GLOBAL(__setup_cpu_7410)
60 bl __init_fpu_registers
61 bl setup_7410_workarounds
62 bl setup_common_caches
63 bl setup_750_7400_hid0
68 _GLOBAL(__setup_cpu_745x)
70 bl setup_common_caches
71 bl setup_745x_specifics
75 /* Enable caches for 603's, 604, 750 & 7400 */
79 ori r11,r11,HID0_ICE|HID0_DCE
81 bne 1f /* don't invalidate the D-cache */
82 ori r8,r8,HID0_DCI /* unless it wasn't enabled */
84 mtspr SPRN_HID0,r8 /* enable and invalidate caches */
86 mtspr SPRN_HID0,r11 /* enable caches */
91 /* 604, 604e, 604ev, ...
92 * Enable superscalar execution & branch history table
96 ori r11,r11,HID0_SIED|HID0_BHTE
99 mtspr SPRN_HID0,r8 /* flush branch target address cache */
100 sync /* on 604e/604r */
106 /* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
107 * erratas we work around here.
108 * Moto MPC710CE.pdf describes them, those are errata
110 * Note that we assume the firmware didn't choose to
111 * apply other workarounds (there are other ones documented
112 * in the .pdf). It appear that Apple firmware only works
113 * around #3 and with the same fix we use. We may want to
114 * check if the CPU is using 60x bus mode in which case
115 * the workaround for errata #4 is useless. Also, we may
116 * want to explicitely clear HID0_NOPDST as this is not
117 * needed once we have applied workaround #5 (though it's
118 * not set by Apple's firmware at least).
120 setup_7400_workarounds:
126 setup_7410_workarounds:
132 mfspr r11,SPRN_MSSSR0
133 /* Errata #3: Set L1OPQ_SIZE to 0x10 */
136 /* Errata #4: Set L2MQ_SIZE to 1 (check for MPX mode first ?) */
138 /* Errata #5: Set DRLT_SIZE to 0x01 */
142 mtspr SPRN_MSSSR0,r11
148 * Enable Store Gathering (SGE), Address Brodcast (ABE),
149 * Branch History Table (BHTE), Branch Target ICache (BTIC)
150 * Dynamic Power Management (DPM), Speculative (SPD)
151 * Clear Instruction cache throttling (ICTC)
155 ori r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
156 oris r11,r11,HID0_DPM@h
158 xori r11,r11,HID0_BTIC
159 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
161 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
162 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
164 andc r11,r11,r3 /* clear SPD: enable speculative */
166 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
174 * Looks like we have to disable NAP feature for some PLL settings...
175 * (waiting for confirmation)
179 rlwinm r10,r10,4,28,31
183 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
184 cror 4*cr0+eq,4*cr0+eq,4*cr2+eq
186 lwz r6,CPU_SPEC_FEATURES(r5)
187 li r7,CPU_FTR_CAN_NAP
189 stw r6,CPU_SPEC_FEATURES(r5)
198 * Enable Store Gathering (SGE), Branch Folding (FOLD)
199 * Branch History Table (BHTE), Branch Target ICache (BTIC)
200 * Dynamic Power Management (DPM), Speculative (SPD)
201 * Ensure our data cache instructions really operate.
202 * Timebase has to be running or we wouldn't have made it here,
203 * just ensure we don't disable it.
204 * Clear Instruction cache throttling (ICTC)
205 * Enable L2 HW prefetch
207 setup_745x_specifics:
208 /* We check for the presence of an L3 cache setup by
209 * the firmware. If any, we disable NAP capability as
210 * it's known to be bogus on rev 2.1 and earlier
214 andis. r11,r11,L3CR_L3E@h
216 END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
217 lwz r6,CPU_SPEC_FEATURES(r5)
218 andi. r0,r6,CPU_FTR_L3_DISABLE_NAP
220 li r7,CPU_FTR_CAN_NAP
222 stw r6,CPU_SPEC_FEATURES(r5)
226 /* All of the bits we have to set.....
228 ori r11,r11,HID0_SGE | HID0_FOLD | HID0_BHTE
229 ori r11,r11,HID0_LRSTK | HID0_BTIC
230 oris r11,r11,HID0_DPM@h
232 xori r11,r11,HID0_BTIC
233 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
235 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
236 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
238 /* All of the bits we have to clear....
240 li r3,HID0_SPD | HID0_NOPDST | HID0_NOPTI
241 andc r11,r11,r3 /* clear SPD: enable speculative */
244 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
250 /* Enable L2 HW prefetch, if L2 is enabled
253 andis. r3,r3,L2CR_L2E@h
264 * Initialize the FPU registers. This is needed to work around an errata
265 * in some 750 cpus where using a not yet initialized FPU register after
266 * power on reset may hang the CPU
268 _GLOBAL(__init_fpu_registers)
273 addis r9,r3,empty_zero_page@ha
274 addi r9,r9,empty_zero_page@l
282 /* Definitions for the table use to save CPU states */
294 .balign L1_CACHE_BYTES
297 .balign L1_CACHE_BYTES,0
300 /* Called in normal context to backup CPU 0 state. This
301 * does not include cache settings. This function is also
302 * called for machine sleep. This does not include the MMU
303 * setup, BATs, etc... but rather the "special" registers
304 * like HID0, HID1, MSSCR0, etc...
306 _GLOBAL(__save_cpu_setup)
307 /* Some CR fields are volatile, we back it up all */
310 /* Get storage ptr */
311 lis r5,cpu_state_storage@h
312 ori r5,r5,cpu_state_storage@l
314 /* Save HID0 (common to all CONFIG_6xx cpus) */
318 /* Now deal with CPU type dependent registers */
321 cmplwi cr0,r3,0x8000 /* 7450 */
322 cmplwi cr1,r3,0x000c /* 7400 */
323 cmplwi cr2,r3,0x800c /* 7410 */
324 cmplwi cr3,r3,0x8001 /* 7455 */
325 cmplwi cr4,r3,0x8002 /* 7457 */
326 cmplwi cr5,r3,0x8003 /* 7447A */
327 cmplwi cr6,r3,0x7000 /* 750FX */
328 cmplwi cr7,r3,0x8004 /* 7448 */
329 /* cr1 is 7400 || 7410 */
330 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
332 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
333 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
334 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
335 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
336 cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
338 /* Backup 74xx specific regs */
344 /* Backup 745x specific registers */
355 /* Backup 750FX specific registers */
358 /* If rev 2.x, backup HID2 */
369 /* Called with no MMU context (typically MSR:IR/DR off) to
370 * restore CPU state as backed up by the previous
371 * function. This does not include cache setting
373 _GLOBAL(__restore_cpu_setup)
374 /* Some CR fields are volatile, we back it up all */
377 /* Get storage ptr */
378 lis r5,(cpu_state_storage-KERNELBASE)@h
379 ori r5,r5,cpu_state_storage@l
389 /* Now deal with CPU type dependent registers */
392 cmplwi cr0,r3,0x8000 /* 7450 */
393 cmplwi cr1,r3,0x000c /* 7400 */
394 cmplwi cr2,r3,0x800c /* 7410 */
395 cmplwi cr3,r3,0x8001 /* 7455 */
396 cmplwi cr4,r3,0x8002 /* 7457 */
397 cmplwi cr5,r3,0x8003 /* 7447A */
398 cmplwi cr6,r3,0x7000 /* 750FX */
399 cmplwi cr7,r3,0x8004 /* 7448 */
400 /* cr1 is 7400 || 7410 */
401 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
403 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
404 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
405 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
406 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
407 cror 4*cr0+eq,4*cr0+eq,4*cr7+eq
409 /* Restore 74xx specific regs */
421 /* Clear 7410 L2CR2 */
425 /* Restore 745x specific registers */
447 /* Restore 750FX specific registers
448 * that is restore HID2 on rev 2.x and PLL config & switch
451 /* If rev 2.x, restore HID2 with low voltage bit cleared */
464 /* Wait for PLL to stabilize */
470 /* Setup final PLL */