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 <linux/config.h>
13 #include <asm/processor.h>
15 #include <asm/ppc_asm.h>
16 #include <asm/cputable.h>
17 #include <asm/ppc_asm.h>
18 #include <asm/offsets.h>
19 #include <asm/cache.h>
21 _GLOBAL(__setup_cpu_601)
23 _GLOBAL(__setup_cpu_603)
25 _GLOBAL(__setup_cpu_604)
27 bl setup_common_caches
31 _GLOBAL(__setup_cpu_750)
33 bl __init_fpu_registers
34 bl setup_common_caches
35 bl setup_750_7400_hid0
38 _GLOBAL(__setup_cpu_750cx)
40 bl __init_fpu_registers
41 bl setup_common_caches
42 bl setup_750_7400_hid0
46 _GLOBAL(__setup_cpu_750fx)
48 bl __init_fpu_registers
49 bl setup_common_caches
50 bl setup_750_7400_hid0
54 _GLOBAL(__setup_cpu_7400)
56 bl __init_fpu_registers
57 bl setup_7400_workarounds
58 bl setup_common_caches
59 bl setup_750_7400_hid0
62 _GLOBAL(__setup_cpu_7410)
64 bl __init_fpu_registers
65 bl setup_7410_workarounds
66 bl setup_common_caches
67 bl setup_750_7400_hid0
72 _GLOBAL(__setup_cpu_745x)
74 bl setup_common_caches
75 bl setup_745x_specifics
79 /* Enable caches for 603's, 604, 750 & 7400 */
83 ori r11,r11,HID0_ICE|HID0_DCE
85 bne 1f /* don't invalidate the D-cache */
86 ori r8,r8,HID0_DCI /* unless it wasn't enabled */
88 mtspr SPRN_HID0,r8 /* enable and invalidate caches */
90 mtspr SPRN_HID0,r11 /* enable caches */
95 /* 604, 604e, 604ev, ...
96 * Enable superscalar execution & branch history table
100 ori r11,r11,HID0_SIED|HID0_BHTE
103 mtspr SPRN_HID0,r8 /* flush branch target address cache */
104 sync /* on 604e/604r */
110 /* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
111 * erratas we work around here.
112 * Moto MPC710CE.pdf describes them, those are errata
114 * Note that we assume the firmware didn't choose to
115 * apply other workarounds (there are other ones documented
116 * in the .pdf). It appear that Apple firmware only works
117 * around #3 and with the same fix we use. We may want to
118 * check if the CPU is using 60x bus mode in which case
119 * the workaround for errata #4 is useless. Also, we may
120 * want to explicitely clear HID0_NOPDST as this is not
121 * needed once we have applied workaround #5 (though it's
122 * not set by Apple's firmware at least).
124 setup_7400_workarounds:
130 setup_7410_workarounds:
136 mfspr r11,SPRN_MSSSR0
137 /* Errata #3: Set L1OPQ_SIZE to 0x10 */
140 /* Errata #4: Set L2MQ_SIZE to 1 (check for MPX mode first ?) */
142 /* Errata #5: Set DRLT_SIZE to 0x01 */
146 mtspr SPRN_MSSSR0,r11
152 * Enable Store Gathering (SGE), Address Brodcast (ABE),
153 * Branch History Table (BHTE), Branch Target ICache (BTIC)
154 * Dynamic Power Management (DPM), Speculative (SPD)
155 * Clear Instruction cache throttling (ICTC)
159 ori r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
160 oris r11,r11,HID0_DPM@h
162 xori r11,r11,HID0_BTIC
163 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
165 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
166 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
168 andc r11,r11,r3 /* clear SPD: enable speculative */
170 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
178 * Looks like we have to disable NAP feature for some PLL settings...
179 * (waiting for confirmation)
183 rlwinm r10,r10,4,28,31
187 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
188 cror 4*cr0+eq,4*cr0+eq,4*cr2+eq
190 lwz r6,CPU_SPEC_FEATURES(r5)
191 li r7,CPU_FTR_CAN_NAP
193 stw r6,CPU_SPEC_FEATURES(r5)
202 * Enable Store Gathering (SGE), Branch Folding (FOLD)
203 * Branch History Table (BHTE), Branch Target ICache (BTIC)
204 * Dynamic Power Management (DPM), Speculative (SPD)
205 * Ensure our data cache instructions really operate.
206 * Timebase has to be running or we wouldn't have made it here,
207 * just ensure we don't disable it.
208 * Clear Instruction cache throttling (ICTC)
209 * Enable L2 HW prefetch
211 setup_745x_specifics:
212 /* We check for the presence of an L3 cache setup by
213 * the firmware. If any, we disable NAP capability as
214 * it's known to be bogus on rev 2.1 and earlier
217 andis. r11,r11,L3CR_L3E@h
219 lwz r6,CPU_SPEC_FEATURES(r5)
220 andi. r0,r6,CPU_FTR_L3_DISABLE_NAP
222 li r7,CPU_FTR_CAN_NAP
224 stw r6,CPU_SPEC_FEATURES(r5)
228 /* All of the bits we have to set.....
230 ori r11,r11,HID0_SGE | HID0_FOLD | HID0_BHTE
231 ori r11,r11,HID0_LRSTK | HID0_BTIC
232 oris r11,r11,HID0_DPM@h
234 xori r11,r11,HID0_BTIC
235 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
237 xoris r11,r11,HID0_DPM@h /* disable dynamic power mgmt */
238 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
240 /* All of the bits we have to clear....
242 li r3,HID0_SPD | HID0_NOPDST | HID0_NOPTI
243 andc r11,r11,r3 /* clear SPD: enable speculative */
246 mtspr SPRN_ICTC,r3 /* Instruction Cache Throttling off */
252 /* Enable L2 HW prefetch
263 * Initialize the FPU registers. This is needed to work around an errata
264 * in some 750 cpus where using a not yet initialized FPU register after
265 * power on reset may hang the CPU
267 _GLOBAL(__init_fpu_registers)
272 addis r9,r3,empty_zero_page@ha
273 addi r9,r9,empty_zero_page@l
281 /* Definitions for the table use to save CPU states */
293 .balign L1_CACHE_LINE_SIZE
296 .balign L1_CACHE_LINE_SIZE,0
299 /* Called in normal context to backup CPU 0 state. This
300 * does not include cache settings. This function is also
301 * called for machine sleep. This does not include the MMU
302 * setup, BATs, etc... but rather the "special" registers
303 * like HID0, HID1, MSSCR0, etc...
305 _GLOBAL(__save_cpu_setup)
306 /* Some CR fields are volatile, we back it up all */
309 /* Get storage ptr */
310 lis r5,cpu_state_storage@h
311 ori r5,r5,cpu_state_storage@l
313 /* Save HID0 (common to all CONFIG_6xx cpus) */
317 /* Now deal with CPU type dependent registers */
320 cmplwi cr0,r3,0x8000 /* 7450 */
321 cmplwi cr1,r3,0x000c /* 7400 */
322 cmplwi cr2,r3,0x800c /* 7410 */
323 cmplwi cr3,r3,0x8001 /* 7455 */
324 cmplwi cr4,r3,0x8002 /* 7457 */
325 cmplwi cr5,r3,0x8003 /* 7447A */
326 cmplwi cr6,r3,0x7000 /* 750FX */
327 /* cr1 is 7400 || 7410 */
328 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
330 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
331 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
332 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
333 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
335 /* Backup 74xx specific regs */
341 /* Backup 745x specific registers */
352 /* Backup 750FX specific registers */
355 /* If rev 2.x, backup HID2 */
366 /* Called with no MMU context (typically MSR:IR/DR off) to
367 * restore CPU state as backed up by the previous
368 * function. This does not include cache setting
370 _GLOBAL(__restore_cpu_setup)
371 /* Some CR fields are volatile, we back it up all */
374 /* Get storage ptr */
375 lis r5,(cpu_state_storage-KERNELBASE)@h
376 ori r5,r5,cpu_state_storage@l
386 /* Now deal with CPU type dependent registers */
389 cmplwi cr0,r3,0x8000 /* 7450 */
390 cmplwi cr1,r3,0x000c /* 7400 */
391 cmplwi cr2,r3,0x800c /* 7410 */
392 cmplwi cr3,r3,0x8001 /* 7455 */
393 cmplwi cr4,r3,0x8002 /* 7457 */
394 cmplwi cr5,r3,0x8003 /* 7447A */
395 cmplwi cr6,r3,0x7000 /* 750FX */
396 /* cr1 is 7400 || 7410 */
397 cror 4*cr1+eq,4*cr1+eq,4*cr2+eq
399 cror 4*cr0+eq,4*cr0+eq,4*cr3+eq
400 cror 4*cr0+eq,4*cr0+eq,4*cr4+eq
401 cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
402 cror 4*cr0+eq,4*cr0+eq,4*cr5+eq
404 /* Restore 74xx specific regs */
416 /* Clear 7410 L2CR2 */
420 /* Restore 745x specific registers */
442 /* Restore 750FX specific registers
443 * that is restore HID2 on rev 2.x and PLL config & switch
446 /* If rev 2.x, restore HID2 with low voltage bit cleared */
459 /* Wait for PLL to stabilize */
465 /* Setup final PLL */