]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/powerpc/cpu.c
Let us manage differences of Book-E PowerPC variations i.e. vendor /
[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/cpu.h>
66 #include <sys/kernel.h>
67 #include <sys/proc.h>
68 #include <sys/sysctl.h>
69
70 #include <machine/bus.h>
71 #include <machine/cpu.h>
72 #include <machine/hid.h>
73 #include <machine/md_var.h>
74 #include <machine/smp.h>
75 #include <machine/spr.h>
76
77 static void     cpu_6xx_setup(int cpuid, uint16_t vers);
78 static void     cpu_970_setup(int cpuid, uint16_t vers);
79 static void     cpu_booke_setup(int cpuid, uint16_t vers);
80
81 int powerpc_pow_enabled;
82 void (*cpu_idle_hook)(void) = NULL;
83 static void     cpu_idle_60x(void);
84 static void     cpu_idle_booke(void);
85
86 struct cputab {
87         const char      *name;
88         uint16_t        version;
89         uint16_t        revfmt;
90         int             features;       /* Do not include PPC_FEATURE_32 or
91                                          * PPC_FEATURE_HAS_MMU */
92         void            (*cpu_setup)(int cpuid, uint16_t vers);
93 };
94 #define REVFMT_MAJMIN   1       /* %u.%u */
95 #define REVFMT_HEX      2       /* 0x%04x */
96 #define REVFMT_DEC      3       /* %u */
97 static const struct cputab models[] = {
98         { "Motorola PowerPC 601",       MPC601,         REVFMT_DEC,
99            PPC_FEATURE_HAS_FPU | PPC_FEATURE_UNIFIED_CACHE, cpu_6xx_setup },
100         { "Motorola PowerPC 602",       MPC602,         REVFMT_DEC,
101            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
102         { "Motorola PowerPC 603",       MPC603,         REVFMT_MAJMIN,
103            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
104         { "Motorola PowerPC 603e",      MPC603e,        REVFMT_MAJMIN,
105            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
106         { "Motorola PowerPC 603ev",     MPC603ev,       REVFMT_MAJMIN,
107            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
108         { "Motorola PowerPC 604",       MPC604,         REVFMT_MAJMIN,
109            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
110         { "Motorola PowerPC 604ev",     MPC604ev,       REVFMT_MAJMIN,
111            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
112         { "Motorola PowerPC 620",       MPC620,         REVFMT_HEX,
113            PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU, NULL },
114         { "Motorola PowerPC 750",       MPC750,         REVFMT_MAJMIN,
115            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
116         { "IBM PowerPC 750FX",          IBM750FX,       REVFMT_MAJMIN,
117            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
118         { "IBM PowerPC 970",            IBM970,         REVFMT_MAJMIN,
119            PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
120            cpu_970_setup },
121         { "IBM PowerPC 970FX",          IBM970FX,       REVFMT_MAJMIN,
122            PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
123            cpu_970_setup },
124         { "IBM PowerPC 970GX",          IBM970GX,       REVFMT_MAJMIN,
125            PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
126            cpu_970_setup },
127         { "IBM PowerPC 970MP",          IBM970MP,       REVFMT_MAJMIN,
128            PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
129            cpu_970_setup },
130         { "Motorola PowerPC 7400",      MPC7400,        REVFMT_MAJMIN,
131            PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
132         { "Motorola PowerPC 7410",      MPC7410,        REVFMT_MAJMIN,
133            PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
134         { "Motorola PowerPC 7450",      MPC7450,        REVFMT_MAJMIN,
135            PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
136         { "Motorola PowerPC 7455",      MPC7455,        REVFMT_MAJMIN,
137            PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
138         { "Motorola PowerPC 7457",      MPC7457,        REVFMT_MAJMIN,
139            PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
140         { "Motorola PowerPC 7447A",     MPC7447A,       REVFMT_MAJMIN,
141            PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
142         { "Motorola PowerPC 7448",      MPC7448,        REVFMT_MAJMIN,
143            PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
144         { "Motorola PowerPC 8240",      MPC8240,        REVFMT_MAJMIN,
145            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
146         { "Motorola PowerPC 8245",      MPC8245,        REVFMT_MAJMIN,
147            PPC_FEATURE_HAS_FPU, cpu_6xx_setup },
148         { "Freescale e500v1 core",      FSL_E500v1,     REVFMT_MAJMIN,
149            0, cpu_booke_setup },
150         { "Freescale e500v2 core",      FSL_E500v2,     REVFMT_MAJMIN,
151            0, cpu_booke_setup },
152         { "Freescale e500mc core",      FSL_E500mc,     REVFMT_MAJMIN,
153            0, cpu_booke_setup },
154         { "Freescale e5500 core",       FSL_E5500,      REVFMT_MAJMIN,
155            0, cpu_booke_setup },
156         { "IBM Cell Broadband Engine",  IBMCELLBE,      REVFMT_MAJMIN,
157            PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_FPU,
158            NULL},
159         { "Unknown PowerPC CPU",        0,              REVFMT_HEX, 0, NULL },
160 };
161
162 static void     cpu_6xx_print_cacheinfo(u_int, uint16_t);
163 static int      cpu_feature_bit(SYSCTL_HANDLER_ARGS);
164
165 static char model[64];
166 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, model, 0, "");
167
168 int cpu_features = PPC_FEATURE_32 | PPC_FEATURE_HAS_MMU;
169 SYSCTL_OPAQUE(_hw, OID_AUTO, cpu_features, CTLTYPE_INT | CTLFLAG_RD,
170     &cpu_features, sizeof(cpu_features), "IX", "PowerPC CPU features");
171
172 /* Provide some user-friendly aliases for bits in cpu_features */
173 SYSCTL_PROC(_hw, OID_AUTO, floatingpoint, CTLTYPE_INT | CTLFLAG_RD,
174     0, PPC_FEATURE_HAS_FPU, cpu_feature_bit, "I",
175     "Floating point instructions executed in hardware");
176 SYSCTL_PROC(_hw, OID_AUTO, altivec, CTLTYPE_INT | CTLFLAG_RD,
177     0, PPC_FEATURE_HAS_ALTIVEC, cpu_feature_bit, "I", "CPU supports Altivec");
178
179 void
180 cpu_setup(u_int cpuid)
181 {
182         u_int           pvr, maj, min;
183         uint16_t        vers, rev, revfmt;
184         uint64_t        cps;
185         const struct    cputab *cp;
186         const char      *name;
187
188         pvr = mfpvr();
189         vers = pvr >> 16;
190         rev = pvr;
191         switch (vers) {
192                 case MPC7410:
193                         min = (pvr >> 0) & 0xff;
194                         maj = min <= 4 ? 1 : 2;
195                         break;
196                 case FSL_E500v1:
197                 case FSL_E500v2:
198                 case FSL_E500mc:
199                 case FSL_E5500:
200                         maj = (pvr >>  4) & 0xf;
201                         min = (pvr >>  0) & 0xf;
202                         break;
203                 default:
204                         maj = (pvr >>  8) & 0xf;
205                         min = (pvr >>  0) & 0xf;
206         }
207
208         for (cp = models; cp->version != 0; cp++) {
209                 if (cp->version == vers)
210                         break;
211         }
212
213         revfmt = cp->revfmt;
214         name = cp->name;
215         if (rev == MPC750 && pvr == 15) {
216                 name = "Motorola MPC755";
217                 revfmt = REVFMT_HEX;
218         }
219         strncpy(model, name, sizeof(model) - 1);
220
221         printf("cpu%d: %s revision ", cpuid, name);
222
223         switch (revfmt) {
224                 case REVFMT_MAJMIN:
225                         printf("%u.%u", maj, min);
226                         break;
227                 case REVFMT_HEX:
228                         printf("0x%04x", rev);
229                         break;
230                 case REVFMT_DEC:
231                         printf("%u", rev);
232                         break;
233         }
234
235         if (cpu_est_clockrate(0, &cps) == 0)
236                 printf(", %jd.%02jd MHz", cps / 1000000, (cps / 10000) % 100);
237         printf("\n");
238
239         cpu_features |= cp->features;
240         printf("cpu%d: Features %b\n", cpuid, cpu_features,
241             PPC_FEATURE_BITMASK);
242
243         /*
244          * Configure CPU
245          */
246         if (cp->cpu_setup != NULL)
247                 cp->cpu_setup(cpuid, vers);
248 }
249
250 /* Get current clock frequency for the given cpu id. */
251 int
252 cpu_est_clockrate(int cpu_id, uint64_t *cps)
253 {
254         uint16_t        vers;
255         register_t      msr;
256
257         vers = mfpvr() >> 16;
258         msr = mfmsr();
259         mtmsr(msr & ~PSL_EE);
260
261         switch (vers) {
262                 case MPC7450:
263                 case MPC7455:
264                 case MPC7457:
265                 case MPC750:
266                 case IBM750FX:
267                 case MPC7400:
268                 case MPC7410:
269                 case MPC7447A:
270                 case MPC7448:
271                         mtspr(SPR_MMCR0, SPR_MMCR0_FC);
272                         mtspr(SPR_PMC1, 0);
273                         mtspr(SPR_MMCR0, SPR_MMCR0_PMC1SEL(PMCN_CYCLES));
274                         DELAY(1000);
275                         *cps = (mfspr(SPR_PMC1) * 1000) + 4999;
276                         mtspr(SPR_MMCR0, SPR_MMCR0_FC);
277
278                         mtmsr(msr);
279                         return (0);
280                 case IBM970:
281                 case IBM970FX:
282                 case IBM970MP:
283                         isync();
284                         mtspr(SPR_970MMCR0, SPR_MMCR0_FC);
285                         isync();
286                         mtspr(SPR_970MMCR1, 0);
287                         mtspr(SPR_970MMCRA, 0);
288                         mtspr(SPR_970PMC1, 0);
289                         mtspr(SPR_970MMCR0,
290                             SPR_970MMCR0_PMC1SEL(PMC970N_CYCLES));
291                         isync();
292                         DELAY(1000);
293                         powerpc_sync();
294                         mtspr(SPR_970MMCR0, SPR_MMCR0_FC);
295                         *cps = (mfspr(SPR_970PMC1) * 1000) + 4999;
296
297                         mtmsr(msr);
298                         return (0);
299         }
300         
301         return (ENXIO);
302 }
303
304 void
305 cpu_6xx_setup(int cpuid, uint16_t vers)
306 {
307         register_t hid0, pvr;
308         const char *bitmask;
309
310         hid0 = mfspr(SPR_HID0);
311         pvr = mfpvr();
312
313         /*
314          * Configure power-saving mode.
315          */
316         switch (vers) {
317                 case MPC603:
318                 case MPC603e:
319                 case MPC603ev:
320                 case MPC604ev:
321                 case MPC750:
322                 case IBM750FX:
323                 case MPC7400:
324                 case MPC7410:
325                 case MPC8240:
326                 case MPC8245:
327                         /* Select DOZE mode. */
328                         hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
329                         hid0 |= HID0_DOZE | HID0_DPM;
330                         powerpc_pow_enabled = 1;
331                         break;
332
333                 case MPC7448:
334                 case MPC7447A:
335                 case MPC7457:
336                 case MPC7455:
337                 case MPC7450:
338                         /* Enable the 7450 branch caches */
339                         hid0 |= HID0_SGE | HID0_BTIC;
340                         hid0 |= HID0_LRSTK | HID0_FOLD | HID0_BHT;
341                         /* Disable BTIC on 7450 Rev 2.0 or earlier and on 7457 */
342                         if (((pvr >> 16) == MPC7450 && (pvr & 0xFFFF) <= 0x0200)
343                                         || (pvr >> 16) == MPC7457)
344                                 hid0 &= ~HID0_BTIC;
345                         /* Select NAP mode. */
346                         hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
347                         hid0 |= HID0_NAP | HID0_DPM;
348                         powerpc_pow_enabled = 1;
349                         break;
350
351                 default:
352                         /* No power-saving mode is available. */ ;
353         }
354
355         switch (vers) {
356                 case IBM750FX:
357                 case MPC750:
358                         hid0 &= ~HID0_DBP;              /* XXX correct? */
359                         hid0 |= HID0_EMCP | HID0_BTIC | HID0_SGE | HID0_BHT;
360                         break;
361
362                 case MPC7400:
363                 case MPC7410:
364                         hid0 &= ~HID0_SPD;
365                         hid0 |= HID0_EMCP | HID0_BTIC | HID0_SGE | HID0_BHT;
366                         hid0 |= HID0_EIEC;
367                         break;
368
369         }
370
371         mtspr(SPR_HID0, hid0);
372
373         if (bootverbose)
374                 cpu_6xx_print_cacheinfo(cpuid, vers);
375
376         switch (vers) {
377                 case MPC7447A:
378                 case MPC7448:
379                 case MPC7450:
380                 case MPC7455:
381                 case MPC7457:
382                         bitmask = HID0_7450_BITMASK;
383                         break;
384                 default:
385                         bitmask = HID0_BITMASK;
386                         break;
387         }
388
389         printf("cpu%d: HID0 %b\n", cpuid, (int)hid0, bitmask);
390
391         if (cpu_idle_hook == NULL)
392                 cpu_idle_hook = cpu_idle_60x;
393 }
394
395
396 static void
397 cpu_6xx_print_cacheinfo(u_int cpuid, uint16_t vers)
398 {
399         register_t hid;
400
401         hid = mfspr(SPR_HID0);
402         printf("cpu%u: ", cpuid);
403         printf("L1 I-cache %sabled, ", (hid & HID0_ICE) ? "en" : "dis");
404         printf("L1 D-cache %sabled\n", (hid & HID0_DCE) ? "en" : "dis");
405
406         printf("cpu%u: ", cpuid);
407         if (mfspr(SPR_L2CR) & L2CR_L2E) {
408                 switch (vers) {
409                 case MPC7450:
410                 case MPC7455:
411                 case MPC7457:
412                         printf("256KB L2 cache, ");
413                         if (mfspr(SPR_L3CR) & L3CR_L3E)
414                                 printf("%cMB L3 backside cache",
415                                     mfspr(SPR_L3CR) & L3CR_L3SIZ ? '2' : '1');
416                         else
417                                 printf("L3 cache disabled");
418                         printf("\n");
419                         break;
420                 case IBM750FX:
421                         printf("512KB L2 cache\n");
422                         break; 
423                 default:
424                         switch (mfspr(SPR_L2CR) & L2CR_L2SIZ) {
425                         case L2SIZ_256K:
426                                 printf("256KB ");
427                                 break;
428                         case L2SIZ_512K:
429                                 printf("512KB ");
430                                 break;
431                         case L2SIZ_1M:
432                                 printf("1MB ");
433                                 break;
434                         }
435                         printf("write-%s", (mfspr(SPR_L2CR) & L2CR_L2WT)
436                             ? "through" : "back");
437                         if (mfspr(SPR_L2CR) & L2CR_L2PE)
438                                 printf(", with parity");
439                         printf(" backside cache\n");
440                         break;
441                 }
442         } else
443                 printf("L2 cache disabled\n");
444 }
445
446 static void
447 cpu_booke_setup(int cpuid, uint16_t vers)
448 {
449 #ifdef BOOKE_E500
450         register_t hid0;
451
452         hid0 = mfspr(SPR_HID0);
453
454         /* Programe power-management mode. */
455         hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
456         hid0 |= HID0_DOZE;
457
458         mtspr(SPR_HID0, hid0);
459
460         printf("cpu%d: HID0 %b\n", cpuid, (int)hid0, HID0_E500_BITMASK);
461 #endif
462
463         if (cpu_idle_hook == NULL)
464                 cpu_idle_hook = cpu_idle_booke;
465 }
466
467 static void
468 cpu_970_setup(int cpuid, uint16_t vers)
469 {
470 #ifdef AIM
471         uint32_t hid0_hi, hid0_lo;
472
473         __asm __volatile ("mfspr %0,%2; clrldi %1,%0,32; srdi %0,%0,32;"
474             : "=r" (hid0_hi), "=r" (hid0_lo) : "K" (SPR_HID0));
475
476         /* Configure power-saving mode */
477         switch (vers) {
478         case IBM970MP:
479                 hid0_hi |= (HID0_DEEPNAP | HID0_NAP | HID0_DPM);
480                 hid0_hi &= ~HID0_DOZE;
481                 break;
482         default:
483                 hid0_hi |= (HID0_NAP | HID0_DPM);
484                 hid0_hi &= ~(HID0_DOZE | HID0_DEEPNAP);
485                 break;
486         }
487         powerpc_pow_enabled = 1;
488
489         __asm __volatile (" \
490                 sync; isync;                                    \
491                 sldi    %0,%0,32; or %0,%0,%1;                  \
492                 mtspr   %2, %0;                                 \
493                 mfspr   %0, %2; mfspr   %0, %2; mfspr   %0, %2; \
494                 mfspr   %0, %2; mfspr   %0, %2; mfspr   %0, %2; \
495                 sync; isync"
496             :: "r" (hid0_hi), "r"(hid0_lo), "K" (SPR_HID0));
497
498         __asm __volatile ("mfspr %0,%1; srdi %0,%0,32;"
499             : "=r" (hid0_hi) : "K" (SPR_HID0));
500         printf("cpu%d: HID0 %b\n", cpuid, (int)(hid0_hi), HID0_970_BITMASK);
501 #endif
502
503         cpu_idle_hook = cpu_idle_60x;
504 }
505
506 static int
507 cpu_feature_bit(SYSCTL_HANDLER_ARGS)
508 {
509         int result;
510
511         result = (cpu_features & arg2) ? 1 : 0;
512
513         return (sysctl_handle_int(oidp, &result, 0, req));
514 }
515
516 void
517 cpu_idle(int busy)
518 {
519
520 #ifdef INVARIANTS
521         if ((mfmsr() & PSL_EE) != PSL_EE) {
522                 struct thread *td = curthread;
523                 printf("td msr %#lx\n", (u_long)td->td_md.md_saved_msr);
524                 panic("ints disabled in idleproc!");
525         }
526 #endif
527
528         CTR2(KTR_SPARE2, "cpu_idle(%d) at %d",
529             busy, curcpu);
530
531         if (cpu_idle_hook != NULL) {
532                 if (!busy) {
533                         critical_enter();
534                         cpu_idleclock();
535                 }
536                 cpu_idle_hook();
537                 if (!busy) {
538                         cpu_activeclock();
539                         critical_exit();
540                 }
541         }
542
543         CTR2(KTR_SPARE2, "cpu_idle(%d) at %d done",
544             busy, curcpu);
545 }
546
547 int
548 cpu_idle_wakeup(int cpu)
549 {
550         return (0);
551 }
552
553 static void
554 cpu_idle_60x(void)
555 {
556         register_t msr;
557         uint16_t vers;
558
559         if (!powerpc_pow_enabled)
560                 return;
561
562         msr = mfmsr();
563         vers = mfpvr() >> 16;
564
565 #ifdef AIM
566         switch (vers) {
567         case IBM970:
568         case IBM970FX:
569         case IBM970MP:
570         case MPC7447A:
571         case MPC7448:
572         case MPC7450:
573         case MPC7455:
574         case MPC7457:
575                 __asm __volatile("\
576                             dssall; sync; mtmsr %0; isync"
577                             :: "r"(msr | PSL_POW));
578                 break;
579         default:
580                 powerpc_sync();
581                 mtmsr(msr | PSL_POW);
582                 isync();
583                 break;
584         }
585 #endif
586 }
587
588 static void
589 cpu_idle_booke(void)
590 {
591         register_t msr;
592
593         msr = mfmsr();
594
595 #ifdef E500
596         /* Freescale E500 core RM section 6.4.1. */
597         __asm __volatile("msync; mtmsr %0; isync" ::
598             "r" (msr | PSL_WE));
599 #endif
600 }
601