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