[POWERPC] Cleanup CPU inits
[pandora-kernel.git] / arch / powerpc / kernel / cpu_setup_ppc970.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(__cpu_preinit_ppc970)
20         /* Do nothing if not running in HV mode */
21         mfmsr   r0
22         rldicl. r0,r0,4,63
23         beqlr
24
25         /* Make sure HID4:rm_ci is off before MMU is turned off, that large
26          * pages are enabled with HID4:61 and clear HID5:DCBZ_size and
27          * HID5:DCBZ32_ill
28          */
29         li      r0,0
30         mfspr   r3,SPRN_HID4
31         rldimi  r3,r0,40,23     /* clear bit 23 (rm_ci) */
32         rldimi  r3,r0,2,61      /* clear bit 61 (lg_pg_en) */
33         sync
34         mtspr   SPRN_HID4,r3
35         isync
36         sync
37         mfspr   r3,SPRN_HID5
38         rldimi  r3,r0,6,56      /* clear bits 56 & 57 (DCBZ*) */
39         sync
40         mtspr   SPRN_HID5,r3
41         isync
42         sync
43
44         /* Setup some basic HID1 features */
45         mfspr   r0,SPRN_HID1
46         li      r3,0x1200               /* enable i-fetch cacheability */
47         sldi    r3,r3,44                /* and prefetch */
48         or      r0,r0,r3
49         mtspr   SPRN_HID1,r0
50         mtspr   SPRN_HID1,r0
51         isync
52
53         /* Clear HIOR */
54         li      r0,0
55         sync
56         mtspr   SPRN_HIOR,0             /* Clear interrupt prefix */
57         isync
58         blr
59
60 /* Definitions for the table use to save CPU states */
61 #define CS_HID0         0
62 #define CS_HID1         8
63 #define CS_HID4         16
64 #define CS_HID5         24
65 #define CS_SIZE         32
66
67         .data
68         .balign L1_CACHE_BYTES,0
69 cpu_state_storage:
70         .space  CS_SIZE
71         .balign L1_CACHE_BYTES,0
72         .text
73
74
75 _GLOBAL(__setup_cpu_ppc970)
76         /* Do nothing if not running in HV mode */
77         mfmsr   r0
78         rldicl. r0,r0,4,63
79         beqlr
80
81         mfspr   r0,SPRN_HID0
82         li      r11,5                   /* clear DOZE and SLEEP */
83         rldimi  r0,r11,52,8             /* set NAP and DPM */
84         mtspr   SPRN_HID0,r0
85         mfspr   r0,SPRN_HID0
86         mfspr   r0,SPRN_HID0
87         mfspr   r0,SPRN_HID0
88         mfspr   r0,SPRN_HID0
89         mfspr   r0,SPRN_HID0
90         mfspr   r0,SPRN_HID0
91         sync
92         isync
93
94         /* Save away cpu state */
95         LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
96
97         /* Save HID0,1,4 and 5 */
98         mfspr   r3,SPRN_HID0
99         std     r3,CS_HID0(r5)
100         mfspr   r3,SPRN_HID1
101         std     r3,CS_HID1(r5)
102         mfspr   r3,SPRN_HID4
103         std     r3,CS_HID4(r5)
104         mfspr   r3,SPRN_HID5
105         std     r3,CS_HID5(r5)
106
107         blr
108
109 /* Called with no MMU context (typically MSR:IR/DR off) to
110  * restore CPU state as backed up by the previous
111  * function. This does not include cache setting
112  */
113 _GLOBAL(__restore_cpu_ppc970)
114         /* Do nothing if not running in HV mode */
115         mfmsr   r0
116         rldicl. r0,r0,4,63
117         beqlr
118
119         LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
120         /* Before accessing memory, we make sure rm_ci is clear */
121         li      r0,0
122         mfspr   r3,SPRN_HID4
123         rldimi  r3,r0,40,23     /* clear bit 23 (rm_ci) */
124         sync
125         mtspr   SPRN_HID4,r3
126         isync
127         sync
128
129         /* Clear interrupt prefix */
130         li      r0,0
131         sync
132         mtspr   SPRN_HIOR,0
133         isync
134
135         /* Restore HID0 */
136         ld      r3,CS_HID0(r5)
137         sync
138         isync
139         mtspr   SPRN_HID0,r3
140         mfspr   r3,SPRN_HID0
141         mfspr   r3,SPRN_HID0
142         mfspr   r3,SPRN_HID0
143         mfspr   r3,SPRN_HID0
144         mfspr   r3,SPRN_HID0
145         mfspr   r3,SPRN_HID0
146         sync
147         isync
148
149         /* Restore HID1 */
150         ld      r3,CS_HID1(r5)
151         sync
152         isync
153         mtspr   SPRN_HID1,r3
154         mtspr   SPRN_HID1,r3
155         sync
156         isync
157
158         /* Restore HID4 */
159         ld      r3,CS_HID4(r5)
160         sync
161         isync
162         mtspr   SPRN_HID4,r3
163         sync
164         isync
165
166         /* Restore HID5 */
167         ld      r3,CS_HID5(r5)
168         sync
169         isync
170         mtspr   SPRN_HID5,r3
171         sync
172         isync
173         blr
174