]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/ppc/kernel/cpu_setup_power4.S
ppc32: use L1_CACHE_SHIFT/L1_CACHE_BYTES
[karo-tx-linux.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_ppc970)
67         mfspr   r0,SPRN_HID0
68         li      r11,5                   /* clear DOZE and SLEEP */
69         rldimi  r0,r11,52,8             /* set NAP and DPM */
70         mtspr   SPRN_HID0,r0
71         mfspr   r0,SPRN_HID0
72         mfspr   r0,SPRN_HID0
73         mfspr   r0,SPRN_HID0
74         mfspr   r0,SPRN_HID0
75         mfspr   r0,SPRN_HID0
76         mfspr   r0,SPRN_HID0
77         sync
78         isync
79         blr
80
81 /* Definitions for the table use to save CPU states */
82 #define CS_HID0         0
83 #define CS_HID1         8
84 #define CS_HID4         16
85 #define CS_HID5         24
86 #define CS_SIZE         32
87
88         .data
89         .balign L1_CACHE_BYTES
90 cpu_state_storage:      
91         .space  CS_SIZE
92         .balign L1_CACHE_BYTES,0
93         .text
94         
95 /* Called in normal context to backup CPU 0 state. This
96  * does not include cache settings. This function is also
97  * called for machine sleep. This does not include the MMU
98  * setup, BATs, etc... but rather the "special" registers
99  * like HID0, HID1, HID4, etc...
100  */
101 _GLOBAL(__save_cpu_setup)
102         /* Some CR fields are volatile, we back it up all */
103         mfcr    r7
104
105         /* Get storage ptr */
106         lis     r5,cpu_state_storage@h
107         ori     r5,r5,cpu_state_storage@l
108
109         /* We only deal with 970 for now */
110         mfspr   r0,SPRN_PVR
111         srwi    r0,r0,16
112         cmpwi   cr0,r0,0x39
113         cmpwi   cr1,r0,0x3c
114         cror    4*cr0+eq,4*cr0+eq,4*cr1+eq
115         bne     1f
116
117         /* Save HID0,1,4 and 5 */
118         mfspr   r3,SPRN_HID0
119         std     r3,CS_HID0(r5)
120         mfspr   r3,SPRN_HID1
121         std     r3,CS_HID1(r5)
122         mfspr   r3,SPRN_HID4
123         std     r3,CS_HID4(r5)
124         mfspr   r3,SPRN_HID5
125         std     r3,CS_HID5(r5)
126         
127 1:
128         mtcr    r7
129         blr
130
131 /* Called with no MMU context (typically MSR:IR/DR off) to
132  * restore CPU state as backed up by the previous
133  * function. This does not include cache setting
134  */
135 _GLOBAL(__restore_cpu_setup)
136         /* Some CR fields are volatile, we back it up all */
137         mfcr    r7
138
139         /* Get storage ptr */
140         lis     r5,(cpu_state_storage-KERNELBASE)@h
141         ori     r5,r5,cpu_state_storage@l
142
143         /* We only deal with 970 for now */
144         mfspr   r0,SPRN_PVR
145         srwi    r0,r0,16
146         cmpwi   cr0,r0,0x39
147         cmpwi   cr1,r0,0x3c
148         cror    4*cr0+eq,4*cr0+eq,4*cr1+eq
149         bne     1f
150
151         /* Clear interrupt prefix */
152         li      r0,0
153         sync
154         mtspr   SPRN_HIOR,0
155         isync
156
157         /* Restore HID0 */
158         ld      r3,CS_HID0(r5)
159         sync
160         isync
161         mtspr   SPRN_HID0,r3
162         mfspr   r3,SPRN_HID0
163         mfspr   r3,SPRN_HID0
164         mfspr   r3,SPRN_HID0
165         mfspr   r3,SPRN_HID0
166         mfspr   r3,SPRN_HID0
167         mfspr   r3,SPRN_HID0
168         sync
169         isync
170
171         /* Restore HID1 */
172         ld      r3,CS_HID1(r5)
173         sync
174         isync
175         mtspr   SPRN_HID1,r3
176         mtspr   SPRN_HID1,r3
177         sync
178         isync
179         
180         /* Restore HID4 */
181         ld      r3,CS_HID4(r5)
182         sync
183         isync
184         mtspr   SPRN_HID4,r3
185         sync
186         isync
187
188         /* Restore HID5 */
189         ld      r3,CS_HID5(r5)
190         sync
191         isync
192         mtspr   SPRN_HID5,r3
193         sync
194         isync
195 1:
196         mtcr    r7
197         blr
198