Merge davem@outer-richmond.davemloft.net:src/GIT/net-2.6/
[pandora-kernel.git] / arch / ppc / kernel / cpu_setup_power4.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/asm-offsets.h>
18 #include <asm/cache.h>
19
20 _GLOBAL(__970_cpu_preinit)
21         /*
22          * Deal only with PPC970 and PPC970FX.
23          */
24         mfspr   r0,SPRN_PVR
25         srwi    r0,r0,16
26         cmpwi   cr0,r0,0x39
27         cmpwi   cr1,r0,0x3c
28         cror    4*cr0+eq,4*cr0+eq,4*cr1+eq
29         bnelr
30
31         /* Make sure HID4:rm_ci is off before MMU is turned off, that large
32          * pages are enabled with HID4:61 and clear HID5:DCBZ_size and
33          * HID5:DCBZ32_ill
34          */
35         li      r0,0
36         mfspr   r11,SPRN_HID4
37         rldimi  r11,r0,40,23    /* clear bit 23 (rm_ci) */
38         rldimi  r11,r0,2,61     /* clear bit 61 (lg_pg_en) */
39         sync
40         mtspr   SPRN_HID4,r11
41         isync
42         sync
43         mfspr   r11,SPRN_HID5
44         rldimi  r11,r0,6,56     /* clear bits 56 & 57 (DCBZ*) */
45         sync
46         mtspr   SPRN_HID5,r11
47         isync
48         sync
49
50         /* Setup some basic HID1 features */
51         mfspr   r0,SPRN_HID1
52         li      r11,0x1200              /* enable i-fetch cacheability */
53         sldi    r11,r11,44              /* and prefetch */
54         or      r0,r0,r11
55         mtspr   SPRN_HID1,r0
56         mtspr   SPRN_HID1,r0
57         isync
58
59         /* Clear HIOR */
60         li      r0,0
61         sync
62         mtspr   SPRN_HIOR,0             /* Clear interrupt prefix */
63         isync
64         blr
65
66 _GLOBAL(__setup_cpu_power4)
67         blr
68 _GLOBAL(__setup_cpu_ppc970)
69         mfspr   r0,SPRN_HID0
70         li      r11,5                   /* clear DOZE and SLEEP */
71         rldimi  r0,r11,52,8             /* set NAP and DPM */
72         mtspr   SPRN_HID0,r0
73         mfspr   r0,SPRN_HID0
74         mfspr   r0,SPRN_HID0
75         mfspr   r0,SPRN_HID0
76         mfspr   r0,SPRN_HID0
77         mfspr   r0,SPRN_HID0
78         mfspr   r0,SPRN_HID0
79         sync
80         isync
81         blr
82
83 /* Definitions for the table use to save CPU states */
84 #define CS_HID0         0
85 #define CS_HID1         8
86 #define CS_HID4         16
87 #define CS_HID5         24
88 #define CS_SIZE         32
89
90         .data
91         .balign L1_CACHE_LINE_SIZE
92 cpu_state_storage:      
93         .space  CS_SIZE
94         .balign L1_CACHE_LINE_SIZE,0
95         .text
96         
97 /* Called in normal context to backup CPU 0 state. This
98  * does not include cache settings. This function is also
99  * called for machine sleep. This does not include the MMU
100  * setup, BATs, etc... but rather the "special" registers
101  * like HID0, HID1, HID4, etc...
102  */
103 _GLOBAL(__save_cpu_setup)
104         /* Some CR fields are volatile, we back it up all */
105         mfcr    r7
106
107         /* Get storage ptr */
108         lis     r5,cpu_state_storage@h
109         ori     r5,r5,cpu_state_storage@l
110
111         /* We only deal with 970 for now */
112         mfspr   r0,SPRN_PVR
113         srwi    r0,r0,16
114         cmpwi   cr0,r0,0x39
115         cmpwi   cr1,r0,0x3c
116         cror    4*cr0+eq,4*cr0+eq,4*cr1+eq
117         bne     1f
118
119         /* Save HID0,1,4 and 5 */
120         mfspr   r3,SPRN_HID0
121         std     r3,CS_HID0(r5)
122         mfspr   r3,SPRN_HID1
123         std     r3,CS_HID1(r5)
124         mfspr   r3,SPRN_HID4
125         std     r3,CS_HID4(r5)
126         mfspr   r3,SPRN_HID5
127         std     r3,CS_HID5(r5)
128         
129 1:
130         mtcr    r7
131         blr
132
133 /* Called with no MMU context (typically MSR:IR/DR off) to
134  * restore CPU state as backed up by the previous
135  * function. This does not include cache setting
136  */
137 _GLOBAL(__restore_cpu_setup)
138         /* Some CR fields are volatile, we back it up all */
139         mfcr    r7
140
141         /* Get storage ptr */
142         lis     r5,(cpu_state_storage-KERNELBASE)@h
143         ori     r5,r5,cpu_state_storage@l
144
145         /* We only deal with 970 for now */
146         mfspr   r0,SPRN_PVR
147         srwi    r0,r0,16
148         cmpwi   cr0,r0,0x39
149         cmpwi   cr1,r0,0x3c
150         cror    4*cr0+eq,4*cr0+eq,4*cr1+eq
151         bne     1f
152
153         /* Clear interrupt prefix */
154         li      r0,0
155         sync
156         mtspr   SPRN_HIOR,0
157         isync
158
159         /* Restore HID0 */
160         ld      r3,CS_HID0(r5)
161         sync
162         isync
163         mtspr   SPRN_HID0,r3
164         mfspr   r3,SPRN_HID0
165         mfspr   r3,SPRN_HID0
166         mfspr   r3,SPRN_HID0
167         mfspr   r3,SPRN_HID0
168         mfspr   r3,SPRN_HID0
169         mfspr   r3,SPRN_HID0
170         sync
171         isync
172
173         /* Restore HID1 */
174         ld      r3,CS_HID1(r5)
175         sync
176         isync
177         mtspr   SPRN_HID1,r3
178         mtspr   SPRN_HID1,r3
179         sync
180         isync
181         
182         /* Restore HID4 */
183         ld      r3,CS_HID4(r5)
184         sync
185         isync
186         mtspr   SPRN_HID4,r3
187         sync
188         isync
189
190         /* Restore HID5 */
191         ld      r3,CS_HID5(r5)
192         sync
193         isync
194         mtspr   SPRN_HID5,r3
195         sync
196         isync
197 1:
198         mtcr    r7
199         blr
200