]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/powerpc/cpu.c
add -n option to suppress clearing the build tree and add -DNO_CLEAN
[FreeBSD/FreeBSD.git] / sys / powerpc / powerpc / cpu.c
1 /*-
2  * Copyright (c) 2001 Matt Thomas.
3  * Copyright (c) 2001 Tsubai Masanari.
4  * Copyright (c) 1998, 1999, 2001 Internet Research Institute, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by
18  *      Internet Research Institute, Inc.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 /*-
34  * Copyright (C) 2003 Benno Rice.
35  * All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  *
46  * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
51  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
52  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
53  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
54  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
55  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  *
57  * from $NetBSD: cpu_subr.c,v 1.1 2003/02/03 17:10:09 matt Exp $
58  * $FreeBSD$
59  */
60
61 #include <sys/param.h>
62 #include <sys/systm.h>
63 #include <sys/bus.h>
64 #include <sys/conf.h>
65 #include <sys/kernel.h>
66 #include <sys/sysctl.h>
67
68 #include <machine/bus.h>
69 #include <machine/hid.h>
70 #include <machine/md_var.h>
71 #include <machine/spr.h>
72
73 int powerpc_pow_enabled;
74
75 struct cputab {
76         const char      *name;
77         uint16_t        version;
78         uint16_t        revfmt;
79 };
80 #define REVFMT_MAJMIN   1       /* %u.%u */
81 #define REVFMT_HEX      2       /* 0x%04x */
82 #define REVFMT_DEC      3       /* %u */
83 static const struct cputab models[] = {
84         { "Motorola PowerPC 601",       MPC601,         REVFMT_DEC },
85         { "Motorola PowerPC 602",       MPC602,         REVFMT_DEC },
86         { "Motorola PowerPC 603",       MPC603,         REVFMT_MAJMIN },
87         { "Motorola PowerPC 603e",      MPC603e,        REVFMT_MAJMIN },
88         { "Motorola PowerPC 603ev",     MPC603ev,       REVFMT_MAJMIN },
89         { "Motorola PowerPC 604",       MPC604,         REVFMT_MAJMIN },
90         { "Motorola PowerPC 604ev",     MPC604ev,       REVFMT_MAJMIN },
91         { "Motorola PowerPC 620",       MPC620,         REVFMT_HEX },
92         { "Motorola PowerPC 750",       MPC750,         REVFMT_MAJMIN },
93         { "IBM PowerPC 750FX",          IBM750FX,       REVFMT_MAJMIN },
94         { "Motorola PowerPC 7400",      MPC7400,        REVFMT_MAJMIN },
95         { "Motorola PowerPC 7410",      MPC7410,        REVFMT_MAJMIN },
96         { "Motorola PowerPC 7450",      MPC7450,        REVFMT_MAJMIN },
97         { "Motorola PowerPC 7455",      MPC7455,        REVFMT_MAJMIN },
98         { "Motorola PowerPC 7457",      MPC7457,        REVFMT_MAJMIN },
99         { "Motorola PowerPC 7447A",     MPC7447A,       REVFMT_MAJMIN },
100         { "Motorola PowerPC 7448",      MPC7448,        REVFMT_MAJMIN },
101         { "Motorola PowerPC 8240",      MPC8240,        REVFMT_MAJMIN },
102         { "Freescale e500v1 core",      FSL_E500v1,     REVFMT_MAJMIN },
103         { "Freescale e500v2 core",      FSL_E500v2,     REVFMT_MAJMIN },
104         { "Unknown PowerPC CPU",        0,              REVFMT_HEX }
105 };
106
107 static char model[64];
108 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, model, 0, "");
109
110 register_t      l2cr_config = 0;
111 register_t      l3cr_config = 0;
112
113 static void     cpu_print_speed(void);
114 static void     cpu_print_cacheinfo(u_int, uint16_t);
115
116 void
117 cpu_setup(u_int cpuid)
118 {
119         u_int           pvr, maj, min, hid0;
120         uint16_t        vers, rev, revfmt;
121         const struct    cputab *cp;
122         const char      *name;
123         char            *bitmask;
124
125         pvr = mfpvr();
126         vers = pvr >> 16;
127         rev = pvr;
128         switch (vers) {
129                 case MPC7410:
130                         min = (pvr >> 0) & 0xff;
131                         maj = min <= 4 ? 1 : 2;
132                         break;
133                 case FSL_E500v1:
134                 case FSL_E500v2:
135                         maj = (pvr >>  4) & 0xf;
136                         min = (pvr >>  0) & 0xf;
137                         break;
138                 default:
139                         maj = (pvr >>  8) & 0xf;
140                         min = (pvr >>  0) & 0xf;
141         }
142
143         for (cp = models; cp->version != 0; cp++) {
144                 if (cp->version == vers)
145                         break;
146         }
147
148         revfmt = cp->revfmt;
149         name = cp->name;
150         if (rev == MPC750 && pvr == 15) {
151                 name = "Motorola MPC755";
152                 revfmt = REVFMT_HEX;
153         }
154         strncpy(model, name, sizeof(model) - 1);
155
156         printf("cpu%d: %s revision ", cpuid, name);
157
158         switch (revfmt) {
159                 case REVFMT_MAJMIN:
160                         printf("%u.%u", maj, min);
161                         break;
162                 case REVFMT_HEX:
163                         printf("0x%04x", rev);
164                         break;
165                 case REVFMT_DEC:
166                         printf("%u", rev);
167                         break;
168         }
169
170         hid0 = mfspr(SPR_HID0);
171
172         /*
173          * Configure power-saving mode.
174          */
175         switch (vers) {
176                 case MPC603:
177                 case MPC603e:
178                 case MPC603ev:
179                 case MPC604ev:
180                 case MPC750:
181                 case IBM750FX:
182                 case MPC7400:
183                 case MPC7410:
184                 case MPC8240:
185                 case MPC8245:
186                         /* Select DOZE mode. */
187                         hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
188                         hid0 |= HID0_DOZE | HID0_DPM;
189                         powerpc_pow_enabled = 1;
190                         break;
191
192                 case MPC7448:
193                 case MPC7447A:
194                 case MPC7457:
195                 case MPC7455:
196                 case MPC7450:
197                         /* Enable the 7450 branch caches */
198                         hid0 |= HID0_SGE | HID0_BTIC;
199                         hid0 |= HID0_LRSTK | HID0_FOLD | HID0_BHT;
200                         /* Disable BTIC on 7450 Rev 2.0 or earlier and on 7457 */
201                         if (((pvr >> 16) == MPC7450 && (pvr & 0xFFFF) <= 0x0200)
202                                         || (pvr >> 16) == MPC7457)
203                                 hid0 &= ~HID0_BTIC;
204                         /* Select NAP mode. */
205                         hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
206                         hid0 |= HID0_NAP | HID0_DPM;
207                         powerpc_pow_enabled = 1;
208                         break;
209
210                 default:
211                         /* No power-saving mode is available. */ ;
212         }
213
214         switch (vers) {
215                 case IBM750FX:
216                 case MPC750:
217                         hid0 &= ~HID0_DBP;              /* XXX correct? */
218                         hid0 |= HID0_EMCP | HID0_BTIC | HID0_SGE | HID0_BHT;
219                         break;
220
221                 case MPC7400:
222                 case MPC7410:
223                         hid0 &= ~HID0_SPD;
224                         hid0 |= HID0_EMCP | HID0_BTIC | HID0_SGE | HID0_BHT;
225                         hid0 |= HID0_EIEC;
226                         break;
227
228                 case FSL_E500v1:
229                 case FSL_E500v2:
230                         hid0 |= HID0_EMCP;
231                         break;
232         }
233
234         mtspr(SPR_HID0, hid0);
235
236         switch (vers) {
237                 case MPC7447A:
238                 case MPC7448:
239                 case MPC7450:
240                 case MPC7455:
241                 case MPC7457:
242                         bitmask = HID0_7450_BITMASK;
243                         break;
244                 case FSL_E500v1:
245                 case FSL_E500v2:
246                         bitmask = HID0_E500_BITMASK;
247                         break;
248                 default:
249                         bitmask = HID0_BITMASK;
250                         break;
251         }
252
253         switch (vers) {
254                 case MPC7450:
255                 case MPC7455:
256                 case MPC7457:
257                         /* Only MPC745x CPUs have an L3 cache. */
258
259                         l3cr_config = mfspr(SPR_L3CR);
260
261                         /* Fallthrough */
262                 case MPC750:
263                 case IBM750FX:
264                 case MPC7400:
265                 case MPC7410:
266                 case MPC7447A:
267                 case MPC7448:
268                         cpu_print_speed();
269                         printf("\n");
270
271                         l2cr_config = mfspr(SPR_L2CR);
272
273                         if (bootverbose)
274                                 cpu_print_cacheinfo(cpuid, vers);
275                         break;
276                 default:
277                         printf("\n");
278                         break;
279         }
280
281         printf("cpu%d: HID0 %b\n", cpuid, hid0, bitmask);
282 }
283
284 void
285 cpu_print_speed(void)
286 {
287         uint64_t        cps;
288
289         mtspr(SPR_MMCR0, SPR_MMCR0_FC);
290         mtspr(SPR_PMC1, 0);
291         mtspr(SPR_MMCR0, SPR_MMCR0_PMC1SEL(PMCN_CYCLES));
292         DELAY(100000);
293         cps = (mfspr(SPR_PMC1) * 10) + 4999;
294         printf(", %lld.%02lld MHz", cps / 1000000, (cps / 10000) % 100);
295 }
296
297 void
298 cpu_print_cacheinfo(u_int cpuid, uint16_t vers)
299 {
300         uint32_t hid;
301
302
303         hid = mfspr(SPR_HID0);
304         printf("cpu%u: ", cpuid);
305         printf("L1 I-cache %sabled, ", (hid & HID0_ICE) ? "en" : "dis");
306         printf("L1 D-cache %sabled\n", (hid & HID0_DCE) ? "en" : "dis");
307
308         printf("cpu%u: ", cpuid);
309         if (l2cr_config & L2CR_L2E) {
310                 switch (vers) {
311                 case MPC7450:
312                 case MPC7455:
313                 case MPC7457:
314                         printf("256KB L2 cache, ");
315                         if (l3cr_config & L3CR_L3E)
316                                 printf("%cMB L3 backside cache",
317                                     l3cr_config & L3CR_L3SIZ ? '2' : '1');
318                         else
319                                 printf("L3 cache disabled");
320                         printf("\n");
321                         break;
322                 case IBM750FX:
323                         printf("512KB L2 cache\n");
324                         break; 
325                 default:
326                         switch (l2cr_config & L2CR_L2SIZ) {
327                         case L2SIZ_256K:
328                                 printf("256KB ");
329                                 break;
330                         case L2SIZ_512K:
331                                 printf("512KB ");
332                                 break;
333                         case L2SIZ_1M:
334                                 printf("1MB ");
335                                 break;
336                         }
337                         printf("write-%s", (l2cr_config & L2CR_L2WT)
338                             ? "through" : "back");
339                         if (l2cr_config & L2CR_L2PE)
340                                 printf(", with parity");
341                         printf(" backside cache\n");
342                         break;
343                 }
344         } else
345                 printf("L2 cache disabled\n");
346 }