Merge to Fedora kernel-2.6.17-1.2187_FC5 patched with stable patch-2.6.17.13-vs2...
[linux-2.6.git] / arch / powerpc / 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/cputable.h>
16 #include <asm/ppc_asm.h>
17 #include <asm/asm-offsets.h>
18 #include <asm/cache.h>
19
20 _GLOBAL(__970_cpu_preinit)
21         /*
22          * Do nothing if not running in HV mode
23          */
24         mfmsr   r0
25         rldicl. r0,r0,4,63
26         beqlr
27
28         /*
29          * Deal only with PPC970 and PPC970FX.
30          */
31         mfspr   r0,SPRN_PVR
32         srwi    r0,r0,16
33         cmpwi   r0,0x39
34         beq     1f
35         cmpwi   r0,0x3c
36         beq     1f
37         cmpwi   r0,0x44
38         bnelr
39 1:
40
41         /* Make sure HID4:rm_ci is off before MMU is turned off, that large
42          * pages are enabled with HID4:61 and clear HID5:DCBZ_size and
43          * HID5:DCBZ32_ill
44          */
45         li      r0,0
46         mfspr   r3,SPRN_HID4
47         rldimi  r3,r0,40,23     /* clear bit 23 (rm_ci) */
48         rldimi  r3,r0,2,61      /* clear bit 61 (lg_pg_en) */
49         sync
50         mtspr   SPRN_HID4,r3
51         isync
52         sync
53         mfspr   r3,SPRN_HID5
54         rldimi  r3,r0,6,56      /* clear bits 56 & 57 (DCBZ*) */
55         sync
56         mtspr   SPRN_HID5,r3
57         isync
58         sync
59
60         /* Setup some basic HID1 features */
61         mfspr   r0,SPRN_HID1
62         li      r3,0x1200               /* enable i-fetch cacheability */
63         sldi    r3,r3,44                /* and prefetch */
64         or      r0,r0,r3
65         mtspr   SPRN_HID1,r0
66         mtspr   SPRN_HID1,r0
67         isync
68
69         /* Clear HIOR */
70         li      r0,0
71         sync
72         mtspr   SPRN_HIOR,0             /* Clear interrupt prefix */
73         isync
74         blr
75
76 _GLOBAL(__setup_cpu_power4)
77         blr
78
79 _GLOBAL(__setup_cpu_be)
80         /* Set large page sizes LP=0: 16MB, LP=1: 64KB */
81         addi    r3, 0,  0
82         ori     r3, r3, HID6_LB
83         sldi    r3, r3, 32
84         nor     r3, r3, r3
85         mfspr   r4, SPRN_HID6
86         and     r4, r4, r3
87         addi    r3, 0, 0x02000
88         sldi    r3, r3, 32
89         or      r4, r4, r3
90         mtspr   SPRN_HID6, r4
91         blr
92
93 _GLOBAL(__setup_cpu_ppc970)
94         mfspr   r0,SPRN_HID0
95         li      r11,5                   /* clear DOZE and SLEEP */
96         rldimi  r0,r11,52,8             /* set NAP and DPM */
97         li      r11,0
98         rldimi  r0,r11,32,31            /* clear EN_ATTN */
99         mtspr   SPRN_HID0,r0
100         mfspr   r0,SPRN_HID0
101         mfspr   r0,SPRN_HID0
102         mfspr   r0,SPRN_HID0
103         mfspr   r0,SPRN_HID0
104         mfspr   r0,SPRN_HID0
105         mfspr   r0,SPRN_HID0
106         sync
107         isync
108         blr
109
110 /* Definitions for the table use to save CPU states */
111 #define CS_HID0         0
112 #define CS_HID1         8
113 #define CS_HID4         16
114 #define CS_HID5         24
115 #define CS_SIZE         32
116
117         .data
118         .balign L1_CACHE_BYTES,0
119 cpu_state_storage:
120         .space  CS_SIZE
121         .balign L1_CACHE_BYTES,0
122         .text
123
124 /* Called in normal context to backup CPU 0 state. This
125  * does not include cache settings. This function is also
126  * called for machine sleep. This does not include the MMU
127  * setup, BATs, etc... but rather the "special" registers
128  * like HID0, HID1, HID4, etc...
129  */
130 _GLOBAL(__save_cpu_setup)
131         /* Some CR fields are volatile, we back it up all */
132         mfcr    r7
133
134         /* Get storage ptr */
135         LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
136
137         /* We only deal with 970 for now */
138         mfspr   r0,SPRN_PVR
139         srwi    r0,r0,16
140         cmpwi   r0,0x39
141         beq     1f
142         cmpwi   r0,0x3c
143         beq     1f
144         cmpwi   r0,0x44
145         bne     2f
146
147 1:      /* Save HID0,1,4 and 5 */
148         mfspr   r3,SPRN_HID0
149         std     r3,CS_HID0(r5)
150         mfspr   r3,SPRN_HID1
151         std     r3,CS_HID1(r5)
152         mfspr   r3,SPRN_HID4
153         std     r3,CS_HID4(r5)
154         mfspr   r3,SPRN_HID5
155         std     r3,CS_HID5(r5)
156
157 2:
158         mtcr    r7
159         blr
160
161 /* Called with no MMU context (typically MSR:IR/DR off) to
162  * restore CPU state as backed up by the previous
163  * function. This does not include cache setting
164  */
165 _GLOBAL(__restore_cpu_setup)
166         /* Get storage ptr (FIXME when using anton reloc as we
167          * are running with translation disabled here
168          */
169         LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
170
171         /* We only deal with 970 for now */
172         mfspr   r0,SPRN_PVR
173         srwi    r0,r0,16
174         cmpwi   r0,0x39
175         beq     1f
176         cmpwi   r0,0x3c
177         beq     1f
178         cmpwi   r0,0x44
179         bnelr
180
181 1:      /* Before accessing memory, we make sure rm_ci is clear */
182         li      r0,0
183         mfspr   r3,SPRN_HID4
184         rldimi  r3,r0,40,23     /* clear bit 23 (rm_ci) */
185         sync
186         mtspr   SPRN_HID4,r3
187         isync
188         sync
189
190         /* Clear interrupt prefix */
191         li      r0,0
192         sync
193         mtspr   SPRN_HIOR,0
194         isync
195
196         /* Restore HID0 */
197         ld      r3,CS_HID0(r5)
198         sync
199         isync
200         mtspr   SPRN_HID0,r3
201         mfspr   r3,SPRN_HID0
202         mfspr   r3,SPRN_HID0
203         mfspr   r3,SPRN_HID0
204         mfspr   r3,SPRN_HID0
205         mfspr   r3,SPRN_HID0
206         mfspr   r3,SPRN_HID0
207         sync
208         isync
209
210         /* Restore HID1 */
211         ld      r3,CS_HID1(r5)
212         sync
213         isync
214         mtspr   SPRN_HID1,r3
215         mtspr   SPRN_HID1,r3
216         sync
217         isync
218
219         /* Restore HID4 */
220         ld      r3,CS_HID4(r5)
221         sync
222         isync
223         mtspr   SPRN_HID4,r3
224         sync
225         isync
226
227         /* Restore HID5 */
228         ld      r3,CS_HID5(r5)
229         sync
230         isync
231         mtspr   SPRN_HID5,r3
232         sync
233         isync
234         blr
235