vserver 2.0 rc7
[linux-2.6.git] / arch / ppc / kernel / cpu_setup_6xx.S
1 /*
2  * This file contains low level CPU setup functions.
3  *    Copyright (C) 2003 Benjamin Herrenschmidt (benh@kernel.crashing.org)
4  *
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.
9  *
10  */
11
12 #include <linux/config.h>
13 #include <asm/processor.h>
14 #include <asm/page.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>
20
21 _GLOBAL(__setup_cpu_601)
22         blr
23 _GLOBAL(__setup_cpu_603)
24         b       setup_common_caches
25 _GLOBAL(__setup_cpu_604)
26         mflr    r4
27         bl      setup_common_caches
28         bl      setup_604_hid0
29         mtlr    r4
30         blr
31 _GLOBAL(__setup_cpu_750)
32         mflr    r4
33         bl      __init_fpu_registers
34         bl      setup_common_caches
35         bl      setup_750_7400_hid0
36         mtlr    r4
37         blr
38 _GLOBAL(__setup_cpu_750cx)
39         mflr    r4
40         bl      __init_fpu_registers
41         bl      setup_common_caches
42         bl      setup_750_7400_hid0
43         bl      setup_750cx
44         mtlr    r4
45         blr
46 _GLOBAL(__setup_cpu_750fx)
47         mflr    r4
48         bl      __init_fpu_registers
49         bl      setup_common_caches
50         bl      setup_750_7400_hid0
51         bl      setup_750fx
52         mtlr    r4
53         blr
54 _GLOBAL(__setup_cpu_7400)
55         mflr    r4
56         bl      __init_fpu_registers
57         bl      setup_7400_workarounds
58         bl      setup_common_caches
59         bl      setup_750_7400_hid0
60         mtlr    r4
61         blr
62 _GLOBAL(__setup_cpu_7410)
63         mflr    r4
64         bl      __init_fpu_registers
65         bl      setup_7410_workarounds
66         bl      setup_common_caches
67         bl      setup_750_7400_hid0
68         li      r3,0
69         mtspr   SPRN_L2CR2,r3
70         mtlr    r4
71         blr
72 _GLOBAL(__setup_cpu_745x)
73         mflr    r4
74         bl      setup_common_caches
75         bl      setup_745x_specifics
76         mtlr    r4
77         blr
78
79 /* Enable caches for 603's, 604, 750 & 7400 */
80 setup_common_caches:
81         mfspr   r11,SPRN_HID0
82         andi.   r0,r11,HID0_DCE
83         ori     r11,r11,HID0_ICE|HID0_DCE
84         ori     r8,r11,HID0_ICFI
85         bne     1f                      /* don't invalidate the D-cache */
86         ori     r8,r8,HID0_DCI          /* unless it wasn't enabled */
87 1:      sync
88         mtspr   SPRN_HID0,r8            /* enable and invalidate caches */
89         sync
90         mtspr   SPRN_HID0,r11           /* enable caches */
91         sync
92         isync
93         blr
94
95 /* 604, 604e, 604ev, ...
96  * Enable superscalar execution & branch history table
97  */
98 setup_604_hid0:
99         mfspr   r11,SPRN_HID0
100         ori     r11,r11,HID0_SIED|HID0_BHTE
101         ori     r8,r11,HID0_BTCD
102         sync
103         mtspr   SPRN_HID0,r8    /* flush branch target address cache */
104         sync                    /* on 604e/604r */
105         mtspr   SPRN_HID0,r11
106         sync
107         isync
108         blr
109
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
113  * #3, #4 and #5
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).
123  */
124 setup_7400_workarounds:
125         mfpvr   r3
126         rlwinm  r3,r3,0,20,31
127         cmpwi   0,r3,0x0207
128         ble     1f
129         blr
130 setup_7410_workarounds:
131         mfpvr   r3
132         rlwinm  r3,r3,0,20,31
133         cmpwi   0,r3,0x0100
134         bnelr
135 1:
136         mfspr   r11,SPRN_MSSSR0
137         /* Errata #3: Set L1OPQ_SIZE to 0x10 */
138         rlwinm  r11,r11,0,9,6
139         oris    r11,r11,0x0100
140         /* Errata #4: Set L2MQ_SIZE to 1 (check for MPX mode first ?) */
141         oris    r11,r11,0x0002
142         /* Errata #5: Set DRLT_SIZE to 0x01 */
143         rlwinm  r11,r11,0,5,2
144         oris    r11,r11,0x0800
145         sync
146         mtspr   SPRN_MSSSR0,r11
147         sync
148         isync
149         blr
150
151 /* 740/750/7400/7410
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)
156  */
157 setup_750_7400_hid0:
158         mfspr   r11,SPRN_HID0
159         ori     r11,r11,HID0_SGE | HID0_ABE | HID0_BHTE | HID0_BTIC
160         oris    r11,r11,HID0_DPM@h
161 BEGIN_FTR_SECTION
162         xori    r11,r11,HID0_BTIC
163 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
164 BEGIN_FTR_SECTION
165         xoris   r11,r11,HID0_DPM@h      /* disable dynamic power mgmt */
166 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
167         li      r3,HID0_SPD
168         andc    r11,r11,r3              /* clear SPD: enable speculative */
169         li      r3,0
170         mtspr   SPRN_ICTC,r3            /* Instruction Cache Throttling off */
171         isync
172         mtspr   SPRN_HID0,r11
173         sync
174         isync
175         blr
176
177 /* 750cx specific
178  * Looks like we have to disable NAP feature for some PLL settings...
179  * (waiting for confirmation)
180  */
181 setup_750cx:
182         mfspr   r10, SPRN_HID1
183         rlwinm  r10,r10,4,28,31
184         cmpwi   cr0,r10,7
185         cmpwi   cr1,r10,9
186         cmpwi   cr2,r10,11
187         cror    4*cr0+eq,4*cr0+eq,4*cr1+eq
188         cror    4*cr0+eq,4*cr0+eq,4*cr2+eq
189         bnelr
190         lwz     r6,CPU_SPEC_FEATURES(r5)
191         li      r7,CPU_FTR_CAN_NAP
192         andc    r6,r6,r7
193         stw     r6,CPU_SPEC_FEATURES(r5)
194         blr
195
196 /* 750fx specific
197  */
198 setup_750fx:
199         blr
200
201 /* MPC 745x
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
210  */
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
215          */
216         mfspr   r11,SPRN_L3CR
217         andis.  r11,r11,L3CR_L3E@h
218         beq     1f
219         lwz     r6,CPU_SPEC_FEATURES(r5)
220         andi.   r0,r6,CPU_FTR_L3_DISABLE_NAP
221         beq     1f
222         li      r7,CPU_FTR_CAN_NAP
223         andc    r6,r6,r7
224         stw     r6,CPU_SPEC_FEATURES(r5)
225 1:
226         mfspr   r11,SPRN_HID0
227
228         /* All of the bits we have to set.....
229          */
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
233 BEGIN_FTR_SECTION
234         xori    r11,r11,HID0_BTIC
235 END_FTR_SECTION_IFSET(CPU_FTR_NO_BTIC)
236 BEGIN_FTR_SECTION
237         xoris   r11,r11,HID0_DPM@h      /* disable dynamic power mgmt */
238 END_FTR_SECTION_IFSET(CPU_FTR_NO_DPM)
239
240         /* All of the bits we have to clear....
241          */
242         li      r3,HID0_SPD | HID0_NOPDST | HID0_NOPTI
243         andc    r11,r11,r3              /* clear SPD: enable speculative */
244         li      r3,0
245
246         mtspr   SPRN_ICTC,r3            /* Instruction Cache Throttling off */
247         isync
248         mtspr   SPRN_HID0,r11
249         sync
250         isync
251
252         /* Enable L2 HW prefetch
253          */
254         mfspr   r3,SPRN_MSSCR0
255         ori     r3,r3,3
256         sync
257         mtspr   SPRN_MSSCR0,r3
258         sync
259         isync
260         blr
261
262 /*
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
266  */
267 _GLOBAL(__init_fpu_registers)
268         mfmsr   r10
269         ori     r11,r10,MSR_FP
270         mtmsr   r11
271         isync
272         addis   r9,r3,empty_zero_page@ha
273         addi    r9,r9,empty_zero_page@l
274         REST_32FPRS(0,r9)
275         sync
276         mtmsr   r10
277         isync
278         blr
279
280
281 /* Definitions for the table use to save CPU states */
282 #define CS_HID0         0
283 #define CS_HID1         4
284 #define CS_HID2         8
285 #define CS_MSSCR0       12
286 #define CS_MSSSR0       16
287 #define CS_ICTRL        20
288 #define CS_LDSTCR       24
289 #define CS_LDSTDB       28
290 #define CS_SIZE         32
291
292         .data
293         .balign L1_CACHE_LINE_SIZE
294 cpu_state_storage:
295         .space  CS_SIZE
296         .balign L1_CACHE_LINE_SIZE,0
297         .text
298
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...
304  */
305 _GLOBAL(__save_cpu_setup)
306         /* Some CR fields are volatile, we back it up all */
307         mfcr    r7
308
309         /* Get storage ptr */
310         lis     r5,cpu_state_storage@h
311         ori     r5,r5,cpu_state_storage@l
312
313         /* Save HID0 (common to all CONFIG_6xx cpus) */
314         mfspr   r3,SPRN_HID0
315         stw     r3,CS_HID0(r5)
316
317         /* Now deal with CPU type dependent registers */
318         mfspr   r3,SPRN_PVR
319         srwi    r3,r3,16
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
329         /* cr0 is 74xx */
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
334         bne     1f
335         /* Backup 74xx specific regs */
336         mfspr   r4,SPRN_MSSCR0
337         stw     r4,CS_MSSCR0(r5)
338         mfspr   r4,SPRN_MSSSR0
339         stw     r4,CS_MSSSR0(r5)
340         beq     cr1,1f
341         /* Backup 745x specific registers */
342         mfspr   r4,SPRN_HID1
343         stw     r4,CS_HID1(r5)
344         mfspr   r4,SPRN_ICTRL
345         stw     r4,CS_ICTRL(r5)
346         mfspr   r4,SPRN_LDSTCR
347         stw     r4,CS_LDSTCR(r5)
348         mfspr   r4,SPRN_LDSTDB
349         stw     r4,CS_LDSTDB(r5)
350 1:
351         bne     cr6,1f
352         /* Backup 750FX specific registers */
353         mfspr   r4,SPRN_HID1
354         stw     r4,CS_HID1(r5)
355         /* If rev 2.x, backup HID2 */
356         mfspr   r3,SPRN_PVR
357         andi.   r3,r3,0xff00
358         cmpwi   cr0,r3,0x0200
359         bne     1f
360         mfspr   r4,SPRN_HID2
361         stw     r4,CS_HID2(r5)
362 1:
363         mtcr    r7
364         blr
365
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
369  */
370 _GLOBAL(__restore_cpu_setup)
371         /* Some CR fields are volatile, we back it up all */
372         mfcr    r7
373
374         /* Get storage ptr */
375         lis     r5,(cpu_state_storage-KERNELBASE)@h
376         ori     r5,r5,cpu_state_storage@l
377
378         /* Restore HID0 */
379         lwz     r3,CS_HID0(r5)
380         sync
381         isync
382         mtspr   SPRN_HID0,r3
383         sync
384         isync
385
386         /* Now deal with CPU type dependent registers */
387         mfspr   r3,SPRN_PVR
388         srwi    r3,r3,16
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
398         /* cr0 is 74xx */
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
403         bne     2f
404         /* Restore 74xx specific regs */
405         lwz     r4,CS_MSSCR0(r5)
406         sync
407         mtspr   SPRN_MSSCR0,r4
408         sync
409         isync
410         lwz     r4,CS_MSSSR0(r5)
411         sync
412         mtspr   SPRN_MSSSR0,r4
413         sync
414         isync
415         bne     cr2,1f
416         /* Clear 7410 L2CR2 */
417         li      r4,0
418         mtspr   SPRN_L2CR2,r4
419 1:      beq     cr1,2f
420         /* Restore 745x specific registers */
421         lwz     r4,CS_HID1(r5)
422         sync
423         mtspr   SPRN_HID1,r4
424         isync
425         sync
426         lwz     r4,CS_ICTRL(r5)
427         sync
428         mtspr   SPRN_ICTRL,r4
429         isync
430         sync
431         lwz     r4,CS_LDSTCR(r5)
432         sync
433         mtspr   SPRN_LDSTCR,r4
434         isync
435         sync
436         lwz     r4,CS_LDSTDB(r5)
437         sync
438         mtspr   SPRN_LDSTDB,r4
439         isync
440         sync
441 2:      bne     cr6,1f
442         /* Restore 750FX specific registers
443          * that is restore HID2 on rev 2.x and PLL config & switch
444          * to PLL 0 on all
445          */
446         /* If rev 2.x, restore HID2 with low voltage bit cleared */
447         mfspr   r3,SPRN_PVR
448         andi.   r3,r3,0xff00
449         cmpwi   cr0,r3,0x0200
450         bne     4f
451         lwz     r4,CS_HID2(r5)
452         rlwinm  r4,r4,0,19,17
453         mtspr   SPRN_HID2,r4
454         sync
455 4:
456         lwz     r4,CS_HID1(r5)
457         rlwinm  r5,r4,0,16,14
458         mtspr   SPRN_HID1,r5
459                 /* Wait for PLL to stabilize */
460         mftbl   r5
461 3:      mftbl   r6
462         sub     r6,r6,r5
463         cmplwi  cr0,r6,10000
464         ble     3b
465         /* Setup final PLL */
466         mtspr   SPRN_HID1,r4
467 1:
468         mtcr    r7
469         blr
470