IB/core: Set alternate port number when initializing QP attributes
[sfrench/cifs-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_ppc970)
77         mfspr   r0,SPRN_HID0
78         li      r11,5                   /* clear DOZE and SLEEP */
79         rldimi  r0,r11,52,8             /* set NAP and DPM */
80         mtspr   SPRN_HID0,r0
81         mfspr   r0,SPRN_HID0
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         sync
88         isync
89         blr
90
91 /* Definitions for the table use to save CPU states */
92 #define CS_HID0         0
93 #define CS_HID1         8
94 #define CS_HID4         16
95 #define CS_HID5         24
96 #define CS_SIZE         32
97
98         .data
99         .balign L1_CACHE_BYTES,0
100 cpu_state_storage:
101         .space  CS_SIZE
102         .balign L1_CACHE_BYTES,0
103         .text
104
105 /* Called in normal context to backup CPU 0 state. This
106  * does not include cache settings. This function is also
107  * called for machine sleep. This does not include the MMU
108  * setup, BATs, etc... but rather the "special" registers
109  * like HID0, HID1, HID4, etc...
110  */
111 _GLOBAL(__save_cpu_setup)
112         /* Some CR fields are volatile, we back it up all */
113         mfcr    r7
114
115         /* Get storage ptr */
116         LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
117
118         /* We only deal with 970 for now */
119         mfspr   r0,SPRN_PVR
120         srwi    r0,r0,16
121         cmpwi   r0,0x39
122         beq     1f
123         cmpwi   r0,0x3c
124         beq     1f
125         cmpwi   r0,0x44
126         bne     2f
127
128 1:      /* skip if not running in HV mode */
129         mfmsr   r0
130         rldicl. r0,r0,4,63
131         beq     2f
132
133         /* Save HID0,1,4 and 5 */
134         mfspr   r3,SPRN_HID0
135         std     r3,CS_HID0(r5)
136         mfspr   r3,SPRN_HID1
137         std     r3,CS_HID1(r5)
138         mfspr   r3,SPRN_HID4
139         std     r3,CS_HID4(r5)
140         mfspr   r3,SPRN_HID5
141         std     r3,CS_HID5(r5)
142
143 2:
144         mtcr    r7
145         blr
146
147 /* Called with no MMU context (typically MSR:IR/DR off) to
148  * restore CPU state as backed up by the previous
149  * function. This does not include cache setting
150  */
151 _GLOBAL(__restore_cpu_setup)
152         /* Get storage ptr (FIXME when using anton reloc as we
153          * are running with translation disabled here
154          */
155         LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
156
157         /* We only deal with 970 for now */
158         mfspr   r0,SPRN_PVR
159         srwi    r0,r0,16
160         cmpwi   r0,0x39
161         beq     1f
162         cmpwi   r0,0x3c
163         beq     1f
164         cmpwi   r0,0x44
165         bnelr
166
167 1:      /* skip if not running in HV mode */
168         mfmsr   r0
169         rldicl. r0,r0,4,63
170         beqlr
171
172         /* Before accessing memory, we make sure rm_ci is clear */
173         li      r0,0
174         mfspr   r3,SPRN_HID4
175         rldimi  r3,r0,40,23     /* clear bit 23 (rm_ci) */
176         sync
177         mtspr   SPRN_HID4,r3
178         isync
179         sync
180
181         /* Clear interrupt prefix */
182         li      r0,0
183         sync
184         mtspr   SPRN_HIOR,0
185         isync
186
187         /* Restore HID0 */
188         ld      r3,CS_HID0(r5)
189         sync
190         isync
191         mtspr   SPRN_HID0,r3
192         mfspr   r3,SPRN_HID0
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         sync
199         isync
200
201         /* Restore HID1 */
202         ld      r3,CS_HID1(r5)
203         sync
204         isync
205         mtspr   SPRN_HID1,r3
206         mtspr   SPRN_HID1,r3
207         sync
208         isync
209
210         /* Restore HID4 */
211         ld      r3,CS_HID4(r5)
212         sync
213         isync
214         mtspr   SPRN_HID4,r3
215         sync
216         isync
217
218         /* Restore HID5 */
219         ld      r3,CS_HID5(r5)
220         sync
221         isync
222         mtspr   SPRN_HID5,r3
223         sync
224         isync
225         blr
226