2 * SPDX-License-Identifier: BSD-4-Clause AND BSD-2-Clause-FreeBSD
4 * Copyright (c) 2001 Matt Thomas.
5 * Copyright (c) 2001 Tsubai Masanari.
6 * Copyright (c) 1998, 1999, 2001 Internet Research Institute, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by
20 * Internet Research Institute, Inc.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Copyright (C) 2003 Benno Rice.
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
48 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
49 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
53 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
54 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
55 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
56 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
57 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 * from $NetBSD: cpu_subr.c,v 1.1 2003/02/03 17:10:09 matt Exp $
63 #include <sys/param.h>
64 #include <sys/systm.h>
68 #include <sys/kernel.h>
70 #include <sys/sysctl.h>
71 #include <sys/sched.h>
74 #include <machine/bus.h>
75 #include <machine/cpu.h>
76 #include <machine/hid.h>
77 #include <machine/md_var.h>
78 #include <machine/smp.h>
79 #include <machine/spr.h>
81 #include <dev/ofw/openfirm.h>
83 static void cpu_6xx_setup(int cpuid, uint16_t vers);
84 static void cpu_970_setup(int cpuid, uint16_t vers);
85 static void cpu_booke_setup(int cpuid, uint16_t vers);
86 static void cpu_powerx_setup(int cpuid, uint16_t vers);
88 int powerpc_pow_enabled;
89 void (*cpu_idle_hook)(sbintime_t) = NULL;
90 static void cpu_idle_60x(sbintime_t);
91 static void cpu_idle_booke(sbintime_t);
93 static void cpu_idle_e500mc(sbintime_t sbt);
95 #if defined(__powerpc64__) && defined(AIM)
96 static void cpu_idle_powerx(sbintime_t);
97 static void cpu_idle_power9(sbintime_t);
104 int features; /* Do not include PPC_FEATURE_32 or
105 * PPC_FEATURE_HAS_MMU */
107 void (*cpu_setup)(int cpuid, uint16_t vers);
109 #define REVFMT_MAJMIN 1 /* %u.%u */
110 #define REVFMT_HEX 2 /* 0x%04x */
111 #define REVFMT_DEC 3 /* %u */
112 static const struct cputab models[] = {
113 { "Motorola PowerPC 601", MPC601, REVFMT_DEC,
114 PPC_FEATURE_HAS_FPU | PPC_FEATURE_UNIFIED_CACHE, 0, cpu_6xx_setup },
115 { "Motorola PowerPC 602", MPC602, REVFMT_DEC,
116 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
117 { "Motorola PowerPC 603", MPC603, REVFMT_MAJMIN,
118 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
119 { "Motorola PowerPC 603e", MPC603e, REVFMT_MAJMIN,
120 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
121 { "Motorola PowerPC 603ev", MPC603ev, REVFMT_MAJMIN,
122 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
123 { "Motorola PowerPC 604", MPC604, REVFMT_MAJMIN,
124 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
125 { "Motorola PowerPC 604ev", MPC604ev, REVFMT_MAJMIN,
126 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
127 { "Motorola PowerPC 620", MPC620, REVFMT_HEX,
128 PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU, 0, NULL },
129 { "Motorola PowerPC 750", MPC750, REVFMT_MAJMIN,
130 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
131 { "IBM PowerPC 750FX", IBM750FX, REVFMT_MAJMIN,
132 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
133 { "IBM PowerPC 970", IBM970, REVFMT_MAJMIN,
134 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
136 { "IBM PowerPC 970FX", IBM970FX, REVFMT_MAJMIN,
137 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
139 { "IBM PowerPC 970GX", IBM970GX, REVFMT_MAJMIN,
140 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
142 { "IBM PowerPC 970MP", IBM970MP, REVFMT_MAJMIN,
143 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
145 { "IBM POWER4", IBMPOWER4, REVFMT_MAJMIN,
146 PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU | PPC_FEATURE_POWER4, 0, NULL },
147 { "IBM POWER4+", IBMPOWER4PLUS, REVFMT_MAJMIN,
148 PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU | PPC_FEATURE_POWER4, 0, NULL },
149 { "IBM POWER5", IBMPOWER5, REVFMT_MAJMIN,
150 PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU | PPC_FEATURE_POWER4 |
151 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP, 0, NULL },
152 { "IBM POWER5+", IBMPOWER5PLUS, REVFMT_MAJMIN,
153 PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU | PPC_FEATURE_POWER5_PLUS |
154 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP, 0, NULL },
155 { "IBM POWER6", IBMPOWER6, REVFMT_MAJMIN,
156 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU |
157 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP | PPC_FEATURE_ARCH_2_05 |
158 PPC_FEATURE_TRUE_LE, 0, NULL },
159 { "IBM POWER7", IBMPOWER7, REVFMT_MAJMIN,
160 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU |
161 PPC_FEATURE_SMT | PPC_FEATURE_ARCH_2_05 | PPC_FEATURE_ARCH_2_06 |
162 PPC_FEATURE_HAS_VSX | PPC_FEATURE_TRUE_LE, PPC_FEATURE2_DSCR, NULL },
163 { "IBM POWER7+", IBMPOWER7PLUS, REVFMT_MAJMIN,
164 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU |
165 PPC_FEATURE_SMT | PPC_FEATURE_ARCH_2_05 | PPC_FEATURE_ARCH_2_06 |
166 PPC_FEATURE_HAS_VSX, PPC_FEATURE2_DSCR, NULL },
167 { "IBM POWER8E", IBMPOWER8E, REVFMT_MAJMIN,
168 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU |
169 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP | PPC_FEATURE_ARCH_2_05 |
170 PPC_FEATURE_ARCH_2_06 | PPC_FEATURE_HAS_VSX | PPC_FEATURE_TRUE_LE,
171 PPC_FEATURE2_ARCH_2_07 | PPC_FEATURE2_HTM | PPC_FEATURE2_DSCR |
172 PPC_FEATURE2_ISEL | PPC_FEATURE2_TAR | PPC_FEATURE2_HAS_VEC_CRYPTO |
173 PPC_FEATURE2_HTM_NOSC, cpu_powerx_setup },
174 { "IBM POWER8", IBMPOWER8, REVFMT_MAJMIN,
175 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU |
176 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP | PPC_FEATURE_ARCH_2_05 |
177 PPC_FEATURE_ARCH_2_06 | PPC_FEATURE_HAS_VSX | PPC_FEATURE_TRUE_LE,
178 PPC_FEATURE2_ARCH_2_07 | PPC_FEATURE2_HTM | PPC_FEATURE2_DSCR |
179 PPC_FEATURE2_ISEL | PPC_FEATURE2_TAR | PPC_FEATURE2_HAS_VEC_CRYPTO |
180 PPC_FEATURE2_HTM_NOSC, cpu_powerx_setup },
181 { "IBM POWER9", IBMPOWER9, REVFMT_MAJMIN,
182 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU |
183 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP | PPC_FEATURE_ARCH_2_05 |
184 PPC_FEATURE_ARCH_2_06 | PPC_FEATURE_HAS_VSX | PPC_FEATURE_TRUE_LE,
185 PPC_FEATURE2_ARCH_2_07 | PPC_FEATURE2_HTM | PPC_FEATURE2_DSCR |
186 PPC_FEATURE2_EBB | PPC_FEATURE2_ISEL | PPC_FEATURE2_TAR |
187 PPC_FEATURE2_HAS_VEC_CRYPTO | PPC_FEATURE2_HTM_NOSC |
188 PPC_FEATURE2_ARCH_3_00 | PPC_FEATURE2_HAS_IEEE128 |
189 PPC_FEATURE2_DARN, cpu_powerx_setup },
190 { "Motorola PowerPC 7400", MPC7400, REVFMT_MAJMIN,
191 PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
192 { "Motorola PowerPC 7410", MPC7410, REVFMT_MAJMIN,
193 PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
194 { "Motorola PowerPC 7450", MPC7450, REVFMT_MAJMIN,
195 PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
196 { "Motorola PowerPC 7455", MPC7455, REVFMT_MAJMIN,
197 PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
198 { "Motorola PowerPC 7457", MPC7457, REVFMT_MAJMIN,
199 PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
200 { "Motorola PowerPC 7447A", MPC7447A, REVFMT_MAJMIN,
201 PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
202 { "Motorola PowerPC 7448", MPC7448, REVFMT_MAJMIN,
203 PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
204 { "Motorola PowerPC 8240", MPC8240, REVFMT_MAJMIN,
205 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
206 { "Motorola PowerPC 8245", MPC8245, REVFMT_MAJMIN,
207 PPC_FEATURE_HAS_FPU, 0, cpu_6xx_setup },
208 { "Freescale e500v1 core", FSL_E500v1, REVFMT_MAJMIN,
209 PPC_FEATURE_HAS_SPE | PPC_FEATURE_HAS_EFP_SINGLE | PPC_FEATURE_BOOKE,
210 PPC_FEATURE2_ISEL, cpu_booke_setup },
211 { "Freescale e500v2 core", FSL_E500v2, REVFMT_MAJMIN,
212 PPC_FEATURE_HAS_SPE | PPC_FEATURE_BOOKE |
213 PPC_FEATURE_HAS_EFP_SINGLE | PPC_FEATURE_HAS_EFP_DOUBLE,
214 PPC_FEATURE2_ISEL, cpu_booke_setup },
215 { "Freescale e500mc core", FSL_E500mc, REVFMT_MAJMIN,
216 PPC_FEATURE_HAS_FPU | PPC_FEATURE_BOOKE | PPC_FEATURE_ARCH_2_05 |
217 PPC_FEATURE_ARCH_2_06, PPC_FEATURE2_ISEL,
219 { "Freescale e5500 core", FSL_E5500, REVFMT_MAJMIN,
220 PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU | PPC_FEATURE_BOOKE |
221 PPC_FEATURE_ARCH_2_05 | PPC_FEATURE_ARCH_2_06,
222 PPC_FEATURE2_ISEL, cpu_booke_setup },
223 { "Freescale e6500 core", FSL_E6500, REVFMT_MAJMIN,
224 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU |
225 PPC_FEATURE_BOOKE | PPC_FEATURE_ARCH_2_05 | PPC_FEATURE_ARCH_2_06,
226 PPC_FEATURE2_ISEL, cpu_booke_setup },
227 { "IBM Cell Broadband Engine", IBMCELLBE, REVFMT_MAJMIN,
228 PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU |
229 PPC_FEATURE_CELL | PPC_FEATURE_SMT, 0, NULL},
230 { "Unknown PowerPC CPU", 0, REVFMT_HEX, 0, 0, NULL },
233 static void cpu_6xx_print_cacheinfo(u_int, uint16_t);
234 static int cpu_feature_bit(SYSCTL_HANDLER_ARGS);
236 static char model[64];
237 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, model, 0, "");
239 static const struct cputab *cput;
241 u_long cpu_features = PPC_FEATURE_32 | PPC_FEATURE_HAS_MMU;
242 u_long cpu_features2 = 0;
243 SYSCTL_OPAQUE(_hw, OID_AUTO, cpu_features, CTLFLAG_RD,
244 &cpu_features, sizeof(cpu_features), "LX", "PowerPC CPU features");
245 SYSCTL_OPAQUE(_hw, OID_AUTO, cpu_features2, CTLFLAG_RD,
246 &cpu_features2, sizeof(cpu_features2), "LX", "PowerPC CPU features 2");
249 register_t lpcr = LPCR_LPES;
252 /* Provide some user-friendly aliases for bits in cpu_features */
253 SYSCTL_PROC(_hw, OID_AUTO, floatingpoint, CTLTYPE_INT | CTLFLAG_RD,
254 0, PPC_FEATURE_HAS_FPU, cpu_feature_bit, "I",
255 "Floating point instructions executed in hardware");
256 SYSCTL_PROC(_hw, OID_AUTO, altivec, CTLTYPE_INT | CTLFLAG_RD,
257 0, PPC_FEATURE_HAS_ALTIVEC, cpu_feature_bit, "I", "CPU supports Altivec");
260 * Phase 1 (early) CPU setup. Setup the cpu_features/cpu_features2 variables,
261 * so they can be used during platform and MMU bringup.
268 const struct cputab *cp;
272 for (cp = models; cp->version != 0; cp++) {
273 if (cp->version == vers)
278 cpu_features |= cp->features;
279 cpu_features2 |= cp->features2;
284 cpu_setup(u_int cpuid)
289 uint16_t rev, revfmt, vers;
296 min = (pvr >> 0) & 0xff;
297 maj = min <= 4 ? 1 : 2;
303 maj = (pvr >> 4) & 0xf;
304 min = (pvr >> 0) & 0xf;
307 maj = (pvr >> 8) & 0xf;
308 min = (pvr >> 0) & 0xf;
311 revfmt = cput->revfmt;
313 if (rev == MPC750 && pvr == 15) {
314 name = "Motorola MPC755";
317 strncpy(model, name, sizeof(model) - 1);
319 printf("cpu%d: %s revision ", cpuid, name);
323 printf("%u.%u", maj, min);
326 printf("0x%04x", rev);
333 if (cpu_est_clockrate(0, &cps) == 0)
334 printf(", %jd.%02jd MHz", cps / 1000000, (cps / 10000) % 100);
337 printf("cpu%d: Features %b\n", cpuid, (int)cpu_features,
338 PPC_FEATURE_BITMASK);
339 if (cpu_features2 != 0)
340 printf("cpu%d: Features2 %b\n", cpuid, (int)cpu_features2,
341 PPC_FEATURE2_BITMASK);
346 if (cput->cpu_setup != NULL)
347 cput->cpu_setup(cpuid, vers);
350 /* Get current clock frequency for the given cpu id. */
352 cpu_est_clockrate(int cpu_id, uint64_t *cps)
356 phandle_t cpu, dev, root;
360 vers = mfpvr() >> 16;
362 mtmsr(msr & ~PSL_EE);
374 mtspr(SPR_MMCR0, SPR_MMCR0_FC);
376 mtspr(SPR_MMCR0, SPR_MMCR0_PMC1SEL(PMCN_CYCLES));
378 *cps = (mfspr(SPR_PMC1) * 1000) + 4999;
379 mtspr(SPR_MMCR0, SPR_MMCR0_FC);
387 mtspr(SPR_970MMCR0, SPR_MMCR0_FC);
389 mtspr(SPR_970MMCR1, 0);
390 mtspr(SPR_970MMCRA, 0);
391 mtspr(SPR_970PMC1, 0);
393 SPR_970MMCR0_PMC1SEL(PMC970N_CYCLES));
397 mtspr(SPR_970MMCR0, SPR_MMCR0_FC);
398 *cps = (mfspr(SPR_970PMC1) * 1000) + 4999;
408 dev = OF_child(root);
410 res = OF_getprop(dev, "name", buf, sizeof(buf));
411 if (res > 0 && strcmp(buf, "cpus") == 0)
417 res = OF_getprop(cpu, "device_type", buf,
419 if (res > 0 && strcmp(buf, "cpu") == 0)
425 if (OF_getprop(cpu, "ibm,extended-clock-frequency",
426 cps, sizeof(*cps)) >= 0) {
428 } else if (OF_getprop(cpu, "clock-frequency", cps,
429 sizeof(cell_t)) >= 0) {
439 cpu_6xx_setup(int cpuid, uint16_t vers)
441 register_t hid0, pvr;
444 hid0 = mfspr(SPR_HID0);
448 * Configure power-saving mode.
461 /* Select DOZE mode. */
462 hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
463 hid0 |= HID0_DOZE | HID0_DPM;
464 powerpc_pow_enabled = 1;
472 /* Enable the 7450 branch caches */
473 hid0 |= HID0_SGE | HID0_BTIC;
474 hid0 |= HID0_LRSTK | HID0_FOLD | HID0_BHT;
475 /* Disable BTIC on 7450 Rev 2.0 or earlier and on 7457 */
476 if (((pvr >> 16) == MPC7450 && (pvr & 0xFFFF) <= 0x0200)
477 || (pvr >> 16) == MPC7457)
479 /* Select NAP mode. */
480 hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
481 hid0 |= HID0_NAP | HID0_DPM;
482 powerpc_pow_enabled = 1;
486 /* No power-saving mode is available. */ ;
492 hid0 &= ~HID0_DBP; /* XXX correct? */
493 hid0 |= HID0_EMCP | HID0_BTIC | HID0_SGE | HID0_BHT;
499 hid0 |= HID0_EMCP | HID0_BTIC | HID0_SGE | HID0_BHT;
505 mtspr(SPR_HID0, hid0);
508 cpu_6xx_print_cacheinfo(cpuid, vers);
516 bitmask = HID0_7450_BITMASK;
519 bitmask = HID0_BITMASK;
523 printf("cpu%d: HID0 %b\n", cpuid, (int)hid0, bitmask);
525 if (cpu_idle_hook == NULL)
526 cpu_idle_hook = cpu_idle_60x;
531 cpu_6xx_print_cacheinfo(u_int cpuid, uint16_t vers)
535 hid = mfspr(SPR_HID0);
536 printf("cpu%u: ", cpuid);
537 printf("L1 I-cache %sabled, ", (hid & HID0_ICE) ? "en" : "dis");
538 printf("L1 D-cache %sabled\n", (hid & HID0_DCE) ? "en" : "dis");
540 printf("cpu%u: ", cpuid);
541 if (mfspr(SPR_L2CR) & L2CR_L2E) {
546 printf("256KB L2 cache, ");
547 if (mfspr(SPR_L3CR) & L3CR_L3E)
548 printf("%cMB L3 backside cache",
549 mfspr(SPR_L3CR) & L3CR_L3SIZ ? '2' : '1');
551 printf("L3 cache disabled");
555 printf("512KB L2 cache\n");
558 switch (mfspr(SPR_L2CR) & L2CR_L2SIZ) {
569 printf("write-%s", (mfspr(SPR_L2CR) & L2CR_L2WT)
570 ? "through" : "back");
571 if (mfspr(SPR_L2CR) & L2CR_L2PE)
572 printf(", with parity");
573 printf(" backside cache\n");
577 printf("L2 cache disabled\n");
581 cpu_booke_setup(int cpuid, uint16_t vers)
587 hid0 = mfspr(SPR_HID0);
591 bitmask = HID0_E500MC_BITMASK;
592 cpu_idle_hook = cpu_idle_e500mc;
596 bitmask = HID0_E5500_BITMASK;
597 cpu_idle_hook = cpu_idle_e500mc;
601 /* Only e500v1/v2 support HID0 power management setup. */
603 /* Program power-management mode. */
604 hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
607 mtspr(SPR_HID0, hid0);
609 bitmask = HID0_E500_BITMASK;
612 printf("cpu%d: HID0 %b\n", cpuid, (int)hid0, bitmask);
615 if (cpu_idle_hook == NULL)
616 cpu_idle_hook = cpu_idle_booke;
620 cpu_970_setup(int cpuid, uint16_t vers)
623 uint32_t hid0_hi, hid0_lo;
625 __asm __volatile ("mfspr %0,%2; clrldi %1,%0,32; srdi %0,%0,32;"
626 : "=r" (hid0_hi), "=r" (hid0_lo) : "K" (SPR_HID0));
628 /* Configure power-saving mode */
631 hid0_hi |= (HID0_DEEPNAP | HID0_NAP | HID0_DPM);
632 hid0_hi &= ~HID0_DOZE;
635 hid0_hi |= (HID0_NAP | HID0_DPM);
636 hid0_hi &= ~(HID0_DOZE | HID0_DEEPNAP);
639 powerpc_pow_enabled = 1;
641 __asm __volatile (" \
643 sldi %0,%0,32; or %0,%0,%1; \
645 mfspr %0, %2; mfspr %0, %2; mfspr %0, %2; \
646 mfspr %0, %2; mfspr %0, %2; mfspr %0, %2; \
648 :: "r" (hid0_hi), "r"(hid0_lo), "K" (SPR_HID0));
650 __asm __volatile ("mfspr %0,%1; srdi %0,%0,32;"
651 : "=r" (hid0_hi) : "K" (SPR_HID0));
652 printf("cpu%d: HID0 %b\n", cpuid, (int)(hid0_hi), HID0_970_BITMASK);
655 cpu_idle_hook = cpu_idle_60x;
659 cpu_powerx_setup(int cpuid, uint16_t vers)
662 #if defined(__powerpc64__) && defined(AIM)
663 if ((mfmsr() & PSL_HV) == 0)
666 /* Nuke the FSCR, to disable all facilities. */
669 /* Configure power-saving */
673 cpu_idle_hook = cpu_idle_powerx;
674 mtspr(SPR_LPCR, mfspr(SPR_LPCR) | LPCR_PECE_WAKESET);
678 cpu_idle_hook = cpu_idle_power9;
679 mtspr(SPR_LPCR, mfspr(SPR_LPCR) | LPCR_PECE_WAKESET);
690 cpu_feature_bit(SYSCTL_HANDLER_ARGS)
694 result = (cpu_features & arg2) ? 1 : 0;
696 return (sysctl_handle_int(oidp, &result, 0, req));
705 if ((mfmsr() & PSL_EE) != PSL_EE) {
706 struct thread *td = curthread;
707 printf("td msr %#lx\n", (u_long)td->td_md.md_saved_msr);
708 panic("ints disabled in idleproc!");
712 CTR2(KTR_SPARE2, "cpu_idle(%d) at %d",
715 if (cpu_idle_hook != NULL) {
718 sbt = cpu_idleclock();
727 CTR2(KTR_SPARE2, "cpu_idle(%d) at %d done",
732 cpu_idle_60x(sbintime_t sbt)
737 if (!powerpc_pow_enabled)
741 vers = mfpvr() >> 16;
754 dssall; sync; mtmsr %0; isync"
755 :: "r"(msr | PSL_POW));
759 mtmsr(msr | PSL_POW);
767 cpu_idle_e500mc(sbintime_t sbt)
770 * Base binutils doesn't know what the 'wait' instruction is, so
771 * use the opcode encoding here.
773 __asm __volatile(".long 0x7c00007c");
778 cpu_idle_booke(sbintime_t sbt)
790 #if defined(__powerpc64__) && defined(AIM)
792 cpu_idle_powerx(sbintime_t sbt)
794 /* Sleeping when running on one cpu gives no advantages - avoid it */
795 if (smp_started == 0)
799 if (sched_runnable()) {
813 cpu_idle_power9(sbintime_t sbt)
819 /* Suspend external interrupts until stop instruction completes. */
820 mtmsr(msr & ~PSL_EE);
821 /* Set the stop state to lowest latency, wake up to next instruction */
822 /* Set maximum transition level to 2, for deepest lossless sleep. */
823 mtspr(SPR_PSSCR, (2 << PSSCR_MTL_S) | (0 << PSSCR_RL_S));
824 /* "stop" instruction (PowerISA 3.0) */
825 __asm __volatile (".long 0x4c0002e4");
827 * Re-enable external interrupts to capture the interrupt that caused
836 cpu_idle_wakeup(int cpu)