Home | History | Annotate | Line # | Download | only in oea
cpu_subr.c revision 1.41
      1 /*	$NetBSD: cpu_subr.c,v 1.41 2008/01/17 23:42:58 garbled Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 Matt Thomas.
      5  * Copyright (c) 2001 Tsubai Masanari.
      6  * Copyright (c) 1998, 1999, 2001 Internet Research Institute, Inc.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     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.
     23  *
     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.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.41 2008/01/17 23:42:58 garbled Exp $");
     38 
     39 #include "opt_ppcparam.h"
     40 #include "opt_multiprocessor.h"
     41 #include "opt_altivec.h"
     42 #include "sysmon_envsys.h"
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/device.h>
     47 #include <sys/types.h>
     48 #include <sys/lwp.h>
     49 #include <sys/user.h>
     50 #include <sys/malloc.h>
     51 
     52 #include <uvm/uvm_extern.h>
     53 
     54 #include <powerpc/oea/hid.h>
     55 #include <powerpc/oea/hid_601.h>
     56 #include <powerpc/spr.h>
     57 
     58 #include <dev/sysmon/sysmonvar.h>
     59 
     60 static void cpu_enable_l2cr(register_t);
     61 static void cpu_enable_l3cr(register_t);
     62 static void cpu_config_l2cr(int);
     63 static void cpu_config_l3cr(int);
     64 static void cpu_probe_speed(struct cpu_info *);
     65 static void cpu_idlespin(void);
     66 #if NSYSMON_ENVSYS > 0
     67 static void cpu_tau_setup(struct cpu_info *);
     68 static void cpu_tau_refresh(struct sysmon_envsys *, envsys_data_t *);
     69 #endif
     70 
     71 int cpu;
     72 int ncpus;
     73 
     74 struct fmttab {
     75 	register_t fmt_mask;
     76 	register_t fmt_value;
     77 	const char *fmt_string;
     78 };
     79 
     80 static const struct fmttab cpu_7450_l2cr_formats[] = {
     81 	{ L2CR_L2E, 0, " disabled" },
     82 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO, " data-only" },
     83 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2IO, " instruction-only" },
     84 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO|L2CR_L2IO, " locked" },
     85 	{ L2CR_L2E, ~0, " 256KB L2 cache" },
     86 	{ L2CR_L2PE, 0, " no parity" },
     87 	{ L2CR_L2PE, ~0, " parity enabled" },
     88 	{ 0, 0, NULL }
     89 };
     90 
     91 static const struct fmttab cpu_7448_l2cr_formats[] = {
     92 	{ L2CR_L2E, 0, " disabled" },
     93 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO, " data-only" },
     94 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2IO, " instruction-only" },
     95 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO|L2CR_L2IO, " locked" },
     96 	{ L2CR_L2E, ~0, " 1MB L2 cache" },
     97 	{ L2CR_L2PE, 0, " no parity" },
     98 	{ L2CR_L2PE, ~0, " parity enabled" },
     99 	{ 0, 0, NULL }
    100 };
    101 
    102 static const struct fmttab cpu_7457_l2cr_formats[] = {
    103 	{ L2CR_L2E, 0, " disabled" },
    104 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO, " data-only" },
    105 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2IO, " instruction-only" },
    106 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO|L2CR_L2IO, " locked" },
    107 	{ L2CR_L2E, ~0, " 512KB L2 cache" },
    108 	{ L2CR_L2PE, 0, " no parity" },
    109 	{ L2CR_L2PE, ~0, " parity enabled" },
    110 	{ 0, 0, NULL }
    111 };
    112 
    113 static const struct fmttab cpu_7450_l3cr_formats[] = {
    114 	{ L3CR_L3DO|L3CR_L3IO, L3CR_L3DO, " data-only" },
    115 	{ L3CR_L3DO|L3CR_L3IO, L3CR_L3IO, " instruction-only" },
    116 	{ L3CR_L3DO|L3CR_L3IO, L3CR_L3DO|L3CR_L3IO, " locked" },
    117 	{ L3CR_L3SIZ, L3SIZ_2M, " 2MB" },
    118 	{ L3CR_L3SIZ, L3SIZ_1M, " 1MB" },
    119 	{ L3CR_L3PE|L3CR_L3APE, L3CR_L3PE|L3CR_L3APE, " parity" },
    120 	{ L3CR_L3PE|L3CR_L3APE, L3CR_L3PE, " data-parity" },
    121 	{ L3CR_L3PE|L3CR_L3APE, L3CR_L3APE, " address-parity" },
    122 	{ L3CR_L3PE|L3CR_L3APE, 0, " no-parity" },
    123 	{ L3CR_L3SIZ, ~0, " L3 cache" },
    124 	{ L3CR_L3RT, L3RT_MSUG2_DDR, " (DDR SRAM)" },
    125 	{ L3CR_L3RT, L3RT_PIPELINE_LATE, " (LW SRAM)" },
    126 	{ L3CR_L3RT, L3RT_PB2_SRAM, " (PB2 SRAM)" },
    127 	{ L3CR_L3CLK, ~0, " at" },
    128 	{ L3CR_L3CLK, L3CLK_20, " 2:1" },
    129 	{ L3CR_L3CLK, L3CLK_25, " 2.5:1" },
    130 	{ L3CR_L3CLK, L3CLK_30, " 3:1" },
    131 	{ L3CR_L3CLK, L3CLK_35, " 3.5:1" },
    132 	{ L3CR_L3CLK, L3CLK_40, " 4:1" },
    133 	{ L3CR_L3CLK, L3CLK_50, " 5:1" },
    134 	{ L3CR_L3CLK, L3CLK_60, " 6:1" },
    135 	{ L3CR_L3CLK, ~0, " ratio" },
    136 	{ 0, 0, NULL },
    137 };
    138 
    139 static const struct fmttab cpu_ibm750_l2cr_formats[] = {
    140 	{ L2CR_L2E, 0, " disabled" },
    141 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO, " data-only" },
    142 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2IO, " instruction-only" },
    143 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO|L2CR_L2IO, " locked" },
    144 	{ 0, ~0, " 512KB" },
    145 	{ L2CR_L2WT, L2CR_L2WT, " WT" },
    146 	{ L2CR_L2WT, 0, " WB" },
    147 	{ L2CR_L2PE, L2CR_L2PE, " with ECC" },
    148 	{ 0, ~0, " L2 cache" },
    149 	{ 0, 0, NULL }
    150 };
    151 
    152 static const struct fmttab cpu_l2cr_formats[] = {
    153 	{ L2CR_L2E, 0, " disabled" },
    154 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO, " data-only" },
    155 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2IO, " instruction-only" },
    156 	{ L2CR_L2DO|L2CR_L2IO, L2CR_L2DO|L2CR_L2IO, " locked" },
    157 	{ L2CR_L2PE, L2CR_L2PE, " parity" },
    158 	{ L2CR_L2PE, 0, " no-parity" },
    159 	{ L2CR_L2SIZ, L2SIZ_2M, " 2MB" },
    160 	{ L2CR_L2SIZ, L2SIZ_1M, " 1MB" },
    161 	{ L2CR_L2SIZ, L2SIZ_512K, " 512KB" },
    162 	{ L2CR_L2SIZ, L2SIZ_256K, " 256KB" },
    163 	{ L2CR_L2WT, L2CR_L2WT, " WT" },
    164 	{ L2CR_L2WT, 0, " WB" },
    165 	{ L2CR_L2E, ~0, " L2 cache" },
    166 	{ L2CR_L2RAM, L2RAM_FLOWTHRU_BURST, " (FB SRAM)" },
    167 	{ L2CR_L2RAM, L2RAM_PIPELINE_LATE, " (LW SRAM)" },
    168 	{ L2CR_L2RAM, L2RAM_PIPELINE_BURST, " (PB SRAM)" },
    169 	{ L2CR_L2CLK, ~0, " at" },
    170 	{ L2CR_L2CLK, L2CLK_10, " 1:1" },
    171 	{ L2CR_L2CLK, L2CLK_15, " 1.5:1" },
    172 	{ L2CR_L2CLK, L2CLK_20, " 2:1" },
    173 	{ L2CR_L2CLK, L2CLK_25, " 2.5:1" },
    174 	{ L2CR_L2CLK, L2CLK_30, " 3:1" },
    175 	{ L2CR_L2CLK, L2CLK_35, " 3.5:1" },
    176 	{ L2CR_L2CLK, L2CLK_40, " 4:1" },
    177 	{ L2CR_L2CLK, ~0, " ratio" },
    178 	{ 0, 0, NULL }
    179 };
    180 
    181 static void cpu_fmttab_print(const struct fmttab *, register_t);
    182 
    183 struct cputab {
    184 	const char name[8];
    185 	uint16_t version;
    186 	uint16_t revfmt;
    187 };
    188 #define	REVFMT_MAJMIN	1		/* %u.%u */
    189 #define	REVFMT_HEX	2		/* 0x%04x */
    190 #define	REVFMT_DEC	3		/* %u */
    191 static const struct cputab models[] = {
    192 	{ "601",	MPC601,		REVFMT_DEC },
    193 	{ "602",	MPC602,		REVFMT_DEC },
    194 	{ "603",	MPC603,		REVFMT_MAJMIN },
    195 	{ "603e",	MPC603e,	REVFMT_MAJMIN },
    196 	{ "603ev",	MPC603ev,	REVFMT_MAJMIN },
    197 	{ "G2",		MPCG2,		REVFMT_MAJMIN },
    198 	{ "604",	MPC604,		REVFMT_MAJMIN },
    199 	{ "604e",	MPC604e,	REVFMT_MAJMIN },
    200 	{ "604ev",	MPC604ev,	REVFMT_MAJMIN },
    201 	{ "620",	MPC620,  	REVFMT_HEX },
    202 	{ "750",	MPC750,		REVFMT_MAJMIN },
    203 	{ "750FX",	IBM750FX,	REVFMT_MAJMIN },
    204 	{ "7400",	MPC7400,	REVFMT_MAJMIN },
    205 	{ "7410",	MPC7410,	REVFMT_MAJMIN },
    206 	{ "7450",	MPC7450,	REVFMT_MAJMIN },
    207 	{ "7455",	MPC7455,	REVFMT_MAJMIN },
    208 	{ "7457",	MPC7457,	REVFMT_MAJMIN },
    209 	{ "7447A",	MPC7447A,	REVFMT_MAJMIN },
    210 	{ "7448",	MPC7448,	REVFMT_MAJMIN },
    211 	{ "8240",	MPC8240,	REVFMT_MAJMIN },
    212 	{ "8245",	MPC8245,	REVFMT_MAJMIN },
    213 	{ "970",	IBM970,		REVFMT_MAJMIN },
    214 	{ "970FX",	IBM970FX,	REVFMT_MAJMIN },
    215 	{ "POWER3II",   IBMPOWER3II,    REVFMT_MAJMIN },
    216 	{ "",		0,		REVFMT_HEX }
    217 };
    218 
    219 #ifdef MULTIPROCESSOR
    220 struct cpu_info cpu_info[CPU_MAXNUM] = { { .ci_curlwp = &lwp0, }, };
    221 volatile struct cpu_hatch_data *cpu_hatch_data;
    222 volatile int cpu_hatch_stack;
    223 extern int ticks_per_intr;
    224 #include <powerpc/oea/bat.h>
    225 #include <arch/powerpc/pic/picvar.h>
    226 #include <arch/powerpc/pic/ipivar.h>
    227 extern struct bat battable[];
    228 #else
    229 struct cpu_info cpu_info[1] = { { .ci_curlwp = &lwp0, }, };
    230 #endif /*MULTIPROCESSOR*/
    231 
    232 int cpu_altivec;
    233 int cpu_psluserset, cpu_pslusermod;
    234 char cpu_model[80];
    235 
    236 void
    237 cpu_fmttab_print(const struct fmttab *fmt, register_t data)
    238 {
    239 	for (; fmt->fmt_mask != 0 || fmt->fmt_value != 0; fmt++) {
    240 		if ((~fmt->fmt_mask & fmt->fmt_value) != 0 ||
    241 		    (data & fmt->fmt_mask) == fmt->fmt_value)
    242 			aprint_normal("%s", fmt->fmt_string);
    243 	}
    244 }
    245 
    246 void
    247 cpu_idlespin(void)
    248 {
    249 	register_t msr;
    250 
    251 	if (powersave <= 0)
    252 		return;
    253 
    254 	__asm volatile(
    255 		"sync;"
    256 		"mfmsr	%0;"
    257 		"oris	%0,%0,%1@h;"	/* enter power saving mode */
    258 		"mtmsr	%0;"
    259 		"isync;"
    260 	    :	"=r"(msr)
    261 	    :	"J"(PSL_POW));
    262 }
    263 
    264 void
    265 cpu_probe_cache(void)
    266 {
    267 	u_int assoc, pvr, vers;
    268 
    269 	pvr = mfpvr();
    270 	vers = pvr >> 16;
    271 
    272 
    273 	/* Presently common across almost all implementations. */
    274 	curcpu()->ci_ci.dcache_line_size = CACHELINESIZE;
    275 	curcpu()->ci_ci.icache_line_size = CACHELINESIZE;
    276 
    277 
    278 	switch (vers) {
    279 #define	K	*1024
    280 	case IBM750FX:
    281 	case MPC601:
    282 	case MPC750:
    283 	case MPC7447A:
    284 	case MPC7448:
    285 	case MPC7450:
    286 	case MPC7455:
    287 	case MPC7457:
    288 		curcpu()->ci_ci.dcache_size = 32 K;
    289 		curcpu()->ci_ci.icache_size = 32 K;
    290 		assoc = 8;
    291 		break;
    292 	case MPC603:
    293 		curcpu()->ci_ci.dcache_size = 8 K;
    294 		curcpu()->ci_ci.icache_size = 8 K;
    295 		assoc = 2;
    296 		break;
    297 	case MPC603e:
    298 	case MPC603ev:
    299 	case MPC604:
    300 	case MPC8240:
    301 	case MPC8245:
    302 	case MPCG2:
    303 		curcpu()->ci_ci.dcache_size = 16 K;
    304 		curcpu()->ci_ci.icache_size = 16 K;
    305 		assoc = 4;
    306 		break;
    307 	case MPC604e:
    308 	case MPC604ev:
    309 		curcpu()->ci_ci.dcache_size = 32 K;
    310 		curcpu()->ci_ci.icache_size = 32 K;
    311 		assoc = 4;
    312 		break;
    313 	case IBMPOWER3II:
    314 		curcpu()->ci_ci.dcache_size = 64 K;
    315 		curcpu()->ci_ci.icache_size = 32 K;
    316 		curcpu()->ci_ci.dcache_line_size = 128;
    317 		curcpu()->ci_ci.icache_line_size = 128;
    318 		assoc = 128; /* not a typo */
    319 		break;
    320 	case IBM970:
    321 	case IBM970FX:
    322 		curcpu()->ci_ci.dcache_size = 32 K;
    323 		curcpu()->ci_ci.icache_size = 64 K;
    324 		curcpu()->ci_ci.dcache_line_size = 128;
    325 		curcpu()->ci_ci.icache_line_size = 128;
    326 		assoc = 2;
    327 		break;
    328 
    329 	default:
    330 		curcpu()->ci_ci.dcache_size = PAGE_SIZE;
    331 		curcpu()->ci_ci.icache_size = PAGE_SIZE;
    332 		assoc = 1;
    333 #undef	K
    334 	}
    335 
    336 	/*
    337 	 * Possibly recolor.
    338 	 */
    339 	uvm_page_recolor(atop(curcpu()->ci_ci.dcache_size / assoc));
    340 }
    341 
    342 struct cpu_info *
    343 cpu_attach_common(struct device *self, int id)
    344 {
    345 	struct cpu_info *ci;
    346 	u_int pvr, vers;
    347 
    348 	ci = &cpu_info[id];
    349 #ifndef MULTIPROCESSOR
    350 	/*
    351 	 * If this isn't the primary CPU, print an error message
    352 	 * and just bail out.
    353 	 */
    354 	if (id != 0) {
    355 		aprint_normal(": ID %d\n", id);
    356 		aprint_normal("%s: processor off-line; multiprocessor support "
    357 		    "not present in kernel\n", self->dv_xname);
    358 		return (NULL);
    359 	}
    360 #endif
    361 
    362 	ci->ci_cpuid = id;
    363 	ci->ci_intrdepth = -1;
    364 	ci->ci_dev = self;
    365 	ci->ci_idlespin = cpu_idlespin;
    366 
    367 	pvr = mfpvr();
    368 	vers = (pvr >> 16) & 0xffff;
    369 
    370 	switch (id) {
    371 	case 0:
    372 		/* load my cpu_number to PIR */
    373 		switch (vers) {
    374 		case MPC601:
    375 		case MPC604:
    376 		case MPC604e:
    377 		case MPC604ev:
    378 		case MPC7400:
    379 		case MPC7410:
    380 		case MPC7447A:
    381 		case MPC7448:
    382 		case MPC7450:
    383 		case MPC7455:
    384 		case MPC7457:
    385 			mtspr(SPR_PIR, id);
    386 		}
    387 		cpu_setup(self, ci);
    388 		break;
    389 	default:
    390 		if (id >= CPU_MAXNUM) {
    391 			aprint_normal(": more than %d cpus?\n", CPU_MAXNUM);
    392 			panic("cpuattach");
    393 		}
    394 #ifndef MULTIPROCESSOR
    395 		aprint_normal(" not configured\n");
    396 		return NULL;
    397 #else
    398 		mi_cpu_attach(ci);
    399 		break;
    400 #endif
    401 	}
    402 	return (ci);
    403 }
    404 
    405 void
    406 cpu_setup(self, ci)
    407 	struct device *self;
    408 	struct cpu_info *ci;
    409 {
    410 	u_int hid0, hid0_save, pvr, vers;
    411 	const char *bitmask;
    412 	char hidbuf[128];
    413 	char model[80];
    414 
    415 	pvr = mfpvr();
    416 	vers = (pvr >> 16) & 0xffff;
    417 
    418 	cpu_identify(model, sizeof(model));
    419 	aprint_normal(": %s, ID %d%s\n", model,  cpu_number(),
    420 	    cpu_number() == 0 ? " (primary)" : "");
    421 
    422 	hid0_save = hid0 = mfspr(SPR_HID0);
    423 
    424 	cpu_probe_cache();
    425 
    426 	/*
    427 	 * Configure power-saving mode.
    428 	 */
    429 	switch (vers) {
    430 	case MPC604:
    431 	case MPC604e:
    432 	case MPC604ev:
    433 		/*
    434 		 * Do not have HID0 support settings, but can support
    435 		 * MSR[POW] off
    436 		 */
    437 		powersave = 1;
    438 		break;
    439 
    440 	case MPC603:
    441 	case MPC603e:
    442 	case MPC603ev:
    443 	case MPC750:
    444 	case IBM750FX:
    445 	case MPC7400:
    446 	case MPC7410:
    447 	case MPC8240:
    448 	case MPC8245:
    449 	case MPCG2:
    450 		/* Select DOZE mode. */
    451 		hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
    452 		hid0 |= HID0_DOZE | HID0_DPM;
    453 		powersave = 1;
    454 		break;
    455 
    456 	case MPC7447A:
    457 	case MPC7448:
    458 	case MPC7457:
    459 	case MPC7455:
    460 	case MPC7450:
    461 		/* Enable the 7450 branch caches */
    462 		hid0 |= HID0_SGE | HID0_BTIC;
    463 		hid0 |= HID0_LRSTK | HID0_FOLD | HID0_BHT;
    464 		/* Disable BTIC on 7450 Rev 2.0 or earlier */
    465 		if (vers == MPC7450 && (pvr & 0xFFFF) <= 0x0200)
    466 			hid0 &= ~HID0_BTIC;
    467 		/* Select NAP mode. */
    468 		hid0 &= ~(HID0_HIGH_BAT_EN | HID0_SLEEP);
    469 		hid0 |= HID0_NAP | HID0_DPM /* | HID0_XBSEN */;
    470 		powersave = 1;
    471 		break;
    472 
    473 	case IBM970:
    474 	case IBM970FX:
    475 	case IBMPOWER3II:
    476 	default:
    477 		/* No power-saving mode is available. */ ;
    478 	}
    479 
    480 #ifdef NAPMODE
    481 	switch (vers) {
    482 	case IBM750FX:
    483 	case MPC750:
    484 	case MPC7400:
    485 		/* Select NAP mode. */
    486 		hid0 &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP);
    487 		hid0 |= HID0_NAP;
    488 		break;
    489 	}
    490 #endif
    491 
    492 	switch (vers) {
    493 	case IBM750FX:
    494 	case MPC750:
    495 		hid0 &= ~HID0_DBP;		/* XXX correct? */
    496 		hid0 |= HID0_EMCP | HID0_BTIC | HID0_SGE | HID0_BHT;
    497 		break;
    498 
    499 	case MPC7400:
    500 	case MPC7410:
    501 		hid0 &= ~HID0_SPD;
    502 		hid0 |= HID0_EMCP | HID0_BTIC | HID0_SGE | HID0_BHT;
    503 		hid0 |= HID0_EIEC;
    504 		break;
    505 	}
    506 
    507 	if (hid0 != hid0_save) {
    508 		mtspr(SPR_HID0, hid0);
    509 		__asm volatile("sync;isync");
    510 	}
    511 
    512 
    513 	switch (vers) {
    514 	case MPC601:
    515 		bitmask = HID0_601_BITMASK;
    516 		break;
    517 	case MPC7450:
    518 	case MPC7455:
    519 	case MPC7457:
    520 		bitmask = HID0_7450_BITMASK;
    521 		break;
    522 	case IBM970:
    523 	case IBM970FX:
    524 		bitmask = 0;
    525 		break;
    526 	default:
    527 		bitmask = HID0_BITMASK;
    528 		break;
    529 	}
    530 	bitmask_snprintf(hid0, bitmask, hidbuf, sizeof hidbuf);
    531 	aprint_normal("%s: HID0 %s, powersave: %d\n", self->dv_xname, hidbuf,
    532 	    powersave);
    533 
    534 	ci->ci_khz = 0;
    535 
    536 	/*
    537 	 * Display speed and cache configuration.
    538 	 */
    539 	switch (vers) {
    540 	case MPC604:
    541 	case MPC604e:
    542 	case MPC604ev:
    543 	case MPC750:
    544 	case IBM750FX:
    545 	case MPC7400:
    546 	case MPC7410:
    547 	case MPC7447A:
    548 	case MPC7448:
    549 	case MPC7450:
    550 	case MPC7455:
    551 	case MPC7457:
    552 		aprint_normal("%s: ", self->dv_xname);
    553 		cpu_probe_speed(ci);
    554 		aprint_normal("%u.%02u MHz",
    555 			      ci->ci_khz / 1000, (ci->ci_khz / 10) % 100);
    556 		switch (vers) {
    557 		case MPC7450: /* 7441 does not have L3! */
    558 		case MPC7455: /* 7445 does not have L3! */
    559 		case MPC7457: /* 7447 does not have L3! */
    560 			cpu_config_l3cr(vers);
    561 			break;
    562 		case IBM750FX:
    563 		case MPC750:
    564 		case MPC7400:
    565 		case MPC7410:
    566 		case MPC7447A:
    567 		case MPC7448:
    568 			cpu_config_l2cr(pvr);
    569 			break;
    570 		default:
    571 			break;
    572 		}
    573 		aprint_normal("\n");
    574 		break;
    575 	}
    576 
    577 #if NSYSMON_ENVSYS > 0
    578 	/*
    579 	 * Attach MPC750 temperature sensor to the envsys subsystem.
    580 	 * XXX the 74xx series also has this sensor, but it is not
    581 	 * XXX supported by Motorola and may return values that are off by
    582 	 * XXX 35-55 degrees C.
    583 	 */
    584 	if (vers == MPC750 || vers == IBM750FX)
    585 		cpu_tau_setup(ci);
    586 #endif
    587 
    588 	evcnt_attach_dynamic(&ci->ci_ev_clock, EVCNT_TYPE_INTR,
    589 		NULL, self->dv_xname, "clock");
    590 	evcnt_attach_dynamic(&ci->ci_ev_softclock, EVCNT_TYPE_INTR,
    591 		NULL, self->dv_xname, "soft clock");
    592 	evcnt_attach_dynamic(&ci->ci_ev_softnet, EVCNT_TYPE_INTR,
    593 		NULL, self->dv_xname, "soft net");
    594 	evcnt_attach_dynamic(&ci->ci_ev_softserial, EVCNT_TYPE_INTR,
    595 		NULL, self->dv_xname, "soft serial");
    596 	evcnt_attach_dynamic(&ci->ci_ev_traps, EVCNT_TYPE_TRAP,
    597 		NULL, self->dv_xname, "traps");
    598 	evcnt_attach_dynamic(&ci->ci_ev_kdsi, EVCNT_TYPE_TRAP,
    599 		&ci->ci_ev_traps, self->dv_xname, "kernel DSI traps");
    600 	evcnt_attach_dynamic(&ci->ci_ev_udsi, EVCNT_TYPE_TRAP,
    601 		&ci->ci_ev_traps, self->dv_xname, "user DSI traps");
    602 	evcnt_attach_dynamic(&ci->ci_ev_udsi_fatal, EVCNT_TYPE_TRAP,
    603 		&ci->ci_ev_udsi, self->dv_xname, "user DSI failures");
    604 	evcnt_attach_dynamic(&ci->ci_ev_kisi, EVCNT_TYPE_TRAP,
    605 		&ci->ci_ev_traps, self->dv_xname, "kernel ISI traps");
    606 	evcnt_attach_dynamic(&ci->ci_ev_isi, EVCNT_TYPE_TRAP,
    607 		&ci->ci_ev_traps, self->dv_xname, "user ISI traps");
    608 	evcnt_attach_dynamic(&ci->ci_ev_isi_fatal, EVCNT_TYPE_TRAP,
    609 		&ci->ci_ev_isi, self->dv_xname, "user ISI failures");
    610 	evcnt_attach_dynamic(&ci->ci_ev_scalls, EVCNT_TYPE_TRAP,
    611 		&ci->ci_ev_traps, self->dv_xname, "system call traps");
    612 	evcnt_attach_dynamic(&ci->ci_ev_pgm, EVCNT_TYPE_TRAP,
    613 		&ci->ci_ev_traps, self->dv_xname, "PGM traps");
    614 	evcnt_attach_dynamic(&ci->ci_ev_fpu, EVCNT_TYPE_TRAP,
    615 		&ci->ci_ev_traps, self->dv_xname, "FPU unavailable traps");
    616 	evcnt_attach_dynamic(&ci->ci_ev_fpusw, EVCNT_TYPE_TRAP,
    617 		&ci->ci_ev_fpu, self->dv_xname, "FPU context switches");
    618 	evcnt_attach_dynamic(&ci->ci_ev_ali, EVCNT_TYPE_TRAP,
    619 		&ci->ci_ev_traps, self->dv_xname, "user alignment traps");
    620 	evcnt_attach_dynamic(&ci->ci_ev_ali_fatal, EVCNT_TYPE_TRAP,
    621 		&ci->ci_ev_ali, self->dv_xname, "user alignment traps");
    622 	evcnt_attach_dynamic(&ci->ci_ev_umchk, EVCNT_TYPE_TRAP,
    623 		&ci->ci_ev_umchk, self->dv_xname, "user MCHK failures");
    624 	evcnt_attach_dynamic(&ci->ci_ev_vec, EVCNT_TYPE_TRAP,
    625 		&ci->ci_ev_traps, self->dv_xname, "AltiVec unavailable");
    626 #ifdef ALTIVEC
    627 	if (cpu_altivec) {
    628 		evcnt_attach_dynamic(&ci->ci_ev_vecsw, EVCNT_TYPE_TRAP,
    629 		    &ci->ci_ev_vec, self->dv_xname, "AltiVec context switches");
    630 	}
    631 #endif
    632 	evcnt_attach_dynamic(&ci->ci_ev_ipi, EVCNT_TYPE_INTR,
    633 		NULL, self->dv_xname, "IPIs");
    634 }
    635 
    636 /*
    637  * According to a document labeled "PVR Register Settings":
    638  ** For integrated microprocessors the PVR register inside the device
    639  ** will identify the version of the microprocessor core. You must also
    640  ** read the Device ID, PCI register 02, to identify the part and the
    641  ** Revision ID, PCI register 08, to identify the revision of the
    642  ** integrated microprocessor.
    643  * This apparently applies to 8240/8245/8241, PVR 00810101 and 80811014
    644  */
    645 
    646 void
    647 cpu_identify(char *str, size_t len)
    648 {
    649 	u_int pvr, major, minor;
    650 	uint16_t vers, rev, revfmt;
    651 	const struct cputab *cp;
    652 	const char *name;
    653 	size_t n;
    654 
    655 	pvr = mfpvr();
    656 	vers = pvr >> 16;
    657 	rev = pvr;
    658 
    659 	switch (vers) {
    660 	case MPC7410:
    661 		minor = (pvr >> 0) & 0xff;
    662 		major = minor <= 4 ? 1 : 2;
    663 		break;
    664 	case MPCG2: /*XXX see note above */
    665 		major = (pvr >> 4) & 0xf;
    666 		minor = (pvr >> 0) & 0xf;
    667 		break;
    668 	default:
    669 		major = (pvr >>  8) & 0xf;
    670 		minor = (pvr >>  0) & 0xf;
    671 	}
    672 
    673 	for (cp = models; cp->name[0] != '\0'; cp++) {
    674 		if (cp->version == vers)
    675 			break;
    676 	}
    677 
    678 	if (str == NULL) {
    679 		str = cpu_model;
    680 		len = sizeof(cpu_model);
    681 		cpu = vers;
    682 	}
    683 
    684 	revfmt = cp->revfmt;
    685 	name = cp->name;
    686 	if (rev == MPC750 && pvr == 15) {
    687 		name = "755";
    688 		revfmt = REVFMT_HEX;
    689 	}
    690 
    691 	if (cp->name[0] != '\0') {
    692 		n = snprintf(str, len, "%s (Revision ", cp->name);
    693 	} else {
    694 		n = snprintf(str, len, "Version %#x (Revision ", vers);
    695 	}
    696 	if (len > n) {
    697 		switch (revfmt) {
    698 		case REVFMT_MAJMIN:
    699 			snprintf(str + n, len - n, "%u.%u)", major, minor);
    700 			break;
    701 		case REVFMT_HEX:
    702 			snprintf(str + n, len - n, "0x%04x)", rev);
    703 			break;
    704 		case REVFMT_DEC:
    705 			snprintf(str + n, len - n, "%u)", rev);
    706 			break;
    707 		}
    708 	}
    709 }
    710 
    711 #ifdef L2CR_CONFIG
    712 u_int l2cr_config = L2CR_CONFIG;
    713 #else
    714 u_int l2cr_config = 0;
    715 #endif
    716 
    717 #ifdef L3CR_CONFIG
    718 u_int l3cr_config = L3CR_CONFIG;
    719 #else
    720 u_int l3cr_config = 0;
    721 #endif
    722 
    723 void
    724 cpu_enable_l2cr(register_t l2cr)
    725 {
    726 	register_t msr, x;
    727 	uint16_t vers;
    728 
    729 	vers = mfpvr() >> 16;
    730 
    731 	/* Disable interrupts and set the cache config bits. */
    732 	msr = mfmsr();
    733 	mtmsr(msr & ~PSL_EE);
    734 #ifdef ALTIVEC
    735 	if (cpu_altivec)
    736 		__asm volatile("dssall");
    737 #endif
    738 	__asm volatile("sync");
    739 	mtspr(SPR_L2CR, l2cr & ~L2CR_L2E);
    740 	__asm volatile("sync");
    741 
    742 	/* Wait for L2 clock to be stable (640 L2 clocks). */
    743 	delay(100);
    744 
    745 	/* Invalidate all L2 contents. */
    746 	if (MPC745X_P(vers)) {
    747 		mtspr(SPR_L2CR, l2cr | L2CR_L2I);
    748 		do {
    749 			x = mfspr(SPR_L2CR);
    750 		} while (x & L2CR_L2I);
    751 	} else {
    752 		mtspr(SPR_L2CR, l2cr | L2CR_L2I);
    753 		do {
    754 			x = mfspr(SPR_L2CR);
    755 		} while (x & L2CR_L2IP);
    756 	}
    757 	/* Enable L2 cache. */
    758 	l2cr |= L2CR_L2E;
    759 	mtspr(SPR_L2CR, l2cr);
    760 	mtmsr(msr);
    761 }
    762 
    763 void
    764 cpu_enable_l3cr(register_t l3cr)
    765 {
    766 	register_t x;
    767 
    768 	/* By The Book (numbered steps from section 3.7.1.3 of MPC7450UM) */
    769 
    770 	/*
    771 	 * 1: Set all L3CR bits for final config except L3E, L3I, L3PE, and
    772 	 *    L3CLKEN.  (also mask off reserved bits in case they were included
    773 	 *    in L3CR_CONFIG)
    774 	 */
    775 	l3cr &= ~(L3CR_L3E|L3CR_L3I|L3CR_L3PE|L3CR_L3CLKEN|L3CR_RESERVED);
    776 	mtspr(SPR_L3CR, l3cr);
    777 
    778 	/* 2: Set L3CR[5] (otherwise reserved bit) to 1 */
    779 	l3cr |= 0x04000000;
    780 	mtspr(SPR_L3CR, l3cr);
    781 
    782 	/* 3: Set L3CLKEN to 1*/
    783 	l3cr |= L3CR_L3CLKEN;
    784 	mtspr(SPR_L3CR, l3cr);
    785 
    786 	/* 4/5: Perform a global cache invalidate (ref section 3.7.3.6) */
    787 	__asm volatile("dssall;sync");
    788 	/* L3 cache is already disabled, no need to clear L3E */
    789 	mtspr(SPR_L3CR, l3cr|L3CR_L3I);
    790 	do {
    791 		x = mfspr(SPR_L3CR);
    792 	} while (x & L3CR_L3I);
    793 
    794 	/* 6: Clear L3CLKEN to 0 */
    795 	l3cr &= ~L3CR_L3CLKEN;
    796 	mtspr(SPR_L3CR, l3cr);
    797 
    798 	/* 7: Perform a 'sync' and wait at least 100 CPU cycles */
    799 	__asm volatile("sync");
    800 	delay(100);
    801 
    802 	/* 8: Set L3E and L3CLKEN */
    803 	l3cr |= (L3CR_L3E|L3CR_L3CLKEN);
    804 	mtspr(SPR_L3CR, l3cr);
    805 
    806 	/* 9: Perform a 'sync' and wait at least 100 CPU cycles */
    807 	__asm volatile("sync");
    808 	delay(100);
    809 }
    810 
    811 void
    812 cpu_config_l2cr(int pvr)
    813 {
    814 	register_t l2cr;
    815 	u_int vers = (pvr >> 16) & 0xffff;
    816 
    817 	l2cr = mfspr(SPR_L2CR);
    818 
    819 	/*
    820 	 * For MP systems, the firmware may only configure the L2 cache
    821 	 * on the first CPU.  In this case, assume that the other CPUs
    822 	 * should use the same value for L2CR.
    823 	 */
    824 	if ((l2cr & L2CR_L2E) != 0 && l2cr_config == 0) {
    825 		l2cr_config = l2cr;
    826 	}
    827 
    828 	/*
    829 	 * Configure L2 cache if not enabled.
    830 	 */
    831 	if ((l2cr & L2CR_L2E) == 0 && l2cr_config != 0) {
    832 		cpu_enable_l2cr(l2cr_config);
    833 		l2cr = mfspr(SPR_L2CR);
    834 	}
    835 
    836 	if ((l2cr & L2CR_L2E) == 0) {
    837 		aprint_normal(" L2 cache present but not enabled ");
    838 		return;
    839 	}
    840 	aprint_normal(",");
    841 
    842 	switch (vers) {
    843 	case IBM750FX:
    844 		cpu_fmttab_print(cpu_ibm750_l2cr_formats, l2cr);
    845 		break;
    846 	case MPC750:
    847 		if ((pvr & 0xffffff00) == 0x00082200 /* IBM750CX */ ||
    848 		    (pvr & 0xffffef00) == 0x00082300 /* IBM750CXe */)
    849 			cpu_fmttab_print(cpu_ibm750_l2cr_formats, l2cr);
    850 		else
    851 			cpu_fmttab_print(cpu_l2cr_formats, l2cr);
    852 		break;
    853 	case MPC7447A:
    854 	case MPC7457:
    855 		cpu_fmttab_print(cpu_7457_l2cr_formats, l2cr);
    856 		return;
    857 	case MPC7448:
    858 		cpu_fmttab_print(cpu_7448_l2cr_formats, l2cr);
    859 		return;
    860 	case MPC7450:
    861 	case MPC7455:
    862 		cpu_fmttab_print(cpu_7450_l2cr_formats, l2cr);
    863 		break;
    864 	default:
    865 		cpu_fmttab_print(cpu_l2cr_formats, l2cr);
    866 		break;
    867 	}
    868 }
    869 
    870 void
    871 cpu_config_l3cr(int vers)
    872 {
    873 	register_t l2cr;
    874 	register_t l3cr;
    875 
    876 	l2cr = mfspr(SPR_L2CR);
    877 
    878 	/*
    879 	 * For MP systems, the firmware may only configure the L2 cache
    880 	 * on the first CPU.  In this case, assume that the other CPUs
    881 	 * should use the same value for L2CR.
    882 	 */
    883 	if ((l2cr & L2CR_L2E) != 0 && l2cr_config == 0) {
    884 		l2cr_config = l2cr;
    885 	}
    886 
    887 	/*
    888 	 * Configure L2 cache if not enabled.
    889 	 */
    890 	if ((l2cr & L2CR_L2E) == 0 && l2cr_config != 0) {
    891 		cpu_enable_l2cr(l2cr_config);
    892 		l2cr = mfspr(SPR_L2CR);
    893 	}
    894 
    895 	aprint_normal(",");
    896 	switch (vers) {
    897 	case MPC7447A:
    898 	case MPC7457:
    899 		cpu_fmttab_print(cpu_7457_l2cr_formats, l2cr);
    900 		return;
    901 	case MPC7448:
    902 		cpu_fmttab_print(cpu_7448_l2cr_formats, l2cr);
    903 		return;
    904 	default:
    905 		cpu_fmttab_print(cpu_7450_l2cr_formats, l2cr);
    906 		break;
    907 	}
    908 
    909 	l3cr = mfspr(SPR_L3CR);
    910 
    911 	/*
    912 	 * For MP systems, the firmware may only configure the L3 cache
    913 	 * on the first CPU.  In this case, assume that the other CPUs
    914 	 * should use the same value for L3CR.
    915 	 */
    916 	if ((l3cr & L3CR_L3E) != 0 && l3cr_config == 0) {
    917 		l3cr_config = l3cr;
    918 	}
    919 
    920 	/*
    921 	 * Configure L3 cache if not enabled.
    922 	 */
    923 	if ((l3cr & L3CR_L3E) == 0 && l3cr_config != 0) {
    924 		cpu_enable_l3cr(l3cr_config);
    925 		l3cr = mfspr(SPR_L3CR);
    926 	}
    927 
    928 	if (l3cr & L3CR_L3E) {
    929 		aprint_normal(",");
    930 		cpu_fmttab_print(cpu_7450_l3cr_formats, l3cr);
    931 	}
    932 }
    933 
    934 void
    935 cpu_probe_speed(struct cpu_info *ci)
    936 {
    937 	uint64_t cps;
    938 
    939 	mtspr(SPR_MMCR0, MMCR0_FC);
    940 	mtspr(SPR_PMC1, 0);
    941 	mtspr(SPR_MMCR0, MMCR0_PMC1SEL(PMCN_CYCLES));
    942 	delay(100000);
    943 	cps = (mfspr(SPR_PMC1) * 10) + 4999;
    944 
    945 	mtspr(SPR_MMCR0, MMCR0_FC);
    946 
    947 	ci->ci_khz = cps / 1000;
    948 }
    949 
    950 #if NSYSMON_ENVSYS > 0
    951 void
    952 cpu_tau_setup(struct cpu_info *ci)
    953 {
    954 	struct sysmon_envsys *sme;
    955 	envsys_data_t sensor;
    956 	int error;
    957 
    958 	sme = sysmon_envsys_create();
    959 
    960 	sensor.state = ENVSYS_SVALID;
    961 	sensor.units = ENVSYS_STEMP;
    962 	(void)strlcpy(sensor.desc, "CPU Temp", sizeof(sensor.desc));
    963 	if (sysmon_envsys_sensor_attach(sme, &sensor)) {
    964 		sysmon_envsys_destroy(sme);
    965 		return;
    966 	}
    967 
    968 	sme->sme_name = ci->ci_dev->dv_xname;
    969 	sme->sme_cookie = ci;
    970 	sme->sme_refresh = cpu_tau_refresh;
    971 
    972 	if ((error = sysmon_envsys_register(sme)) != 0) {
    973 		aprint_error("%s: unable to register with sysmon (%d)\n",
    974 		    ci->ci_dev->dv_xname, error);
    975 		sysmon_envsys_destroy(sme);
    976 	}
    977 }
    978 
    979 
    980 /* Find the temperature of the CPU. */
    981 void
    982 cpu_tau_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
    983 {
    984 	int i, threshold, count;
    985 
    986 	threshold = 64; /* Half of the 7-bit sensor range */
    987 	mtspr(SPR_THRM1, 0);
    988 	mtspr(SPR_THRM2, 0);
    989 	/* XXX This counter is supposed to be "at least 20 microseonds, in
    990 	 * XXX units of clock cycles". Since we don't have convenient
    991 	 * XXX access to the CPU speed, set it to a conservative value,
    992 	 * XXX that is, assuming a fast (1GHz) G3 CPU (As of February 2002,
    993 	 * XXX the fastest G3 processor is 700MHz) . The cost is that
    994 	 * XXX measuring the temperature takes a bit longer.
    995 	 */
    996         mtspr(SPR_THRM3, SPR_THRM_TIMER(20000) | SPR_THRM_ENABLE);
    997 
    998 	/* Successive-approximation code adapted from Motorola
    999 	 * application note AN1800/D, "Programming the Thermal Assist
   1000 	 * Unit in the MPC750 Microprocessor".
   1001 	 */
   1002 	for (i = 4; i >= 0 ; i--) {
   1003 		mtspr(SPR_THRM1,
   1004 		    SPR_THRM_THRESHOLD(threshold) | SPR_THRM_VALID);
   1005 		count = 0;
   1006 		while ((count < 100) &&
   1007 		    ((mfspr(SPR_THRM1) & SPR_THRM_TIV) == 0)) {
   1008 			count++;
   1009 			delay(1);
   1010 		}
   1011 		if (mfspr(SPR_THRM1) & SPR_THRM_TIN) {
   1012 			/* The interrupt bit was set, meaning the
   1013 			 * temperature was above the threshold
   1014 			 */
   1015 			threshold += 2 << i;
   1016 		} else {
   1017 			/* Temperature was below the threshold */
   1018 			threshold -= 2 << i;
   1019 		}
   1020 	}
   1021 	threshold += 2;
   1022 
   1023 	/* Convert the temperature in degrees C to microkelvin */
   1024 	edata->value_cur = (threshold * 1000000) + 273150000;
   1025 }
   1026 #endif /* NSYSMON_ENVSYS > 0 */
   1027 
   1028 #ifdef MULTIPROCESSOR
   1029 int
   1030 cpu_spinup(struct device *self, struct cpu_info *ci)
   1031 {
   1032 	volatile struct cpu_hatch_data hatch_data, *h = &hatch_data;
   1033 	struct pglist mlist;
   1034 	int i, error, pvr, vers;
   1035 	char *cp;
   1036 
   1037 	pvr = mfpvr();
   1038 	vers = pvr >> 16;
   1039 	KASSERT(ci != curcpu());
   1040 
   1041 	/*
   1042 	 * Allocate some contiguous pages for the intteup PCB and stack
   1043 	 * from the lowest 256MB (because bat0 always maps it va == pa).
   1044 	 */
   1045 	error = uvm_pglistalloc(INTSTK, 0x0, 0x10000000, 0, 0, &mlist, 1, 1);
   1046 	if (error) {
   1047 		aprint_error(": unable to allocate idle stack\n");
   1048 		return -1;
   1049 	}
   1050 
   1051 	KASSERT(ci != &cpu_info[0]);
   1052 
   1053 	cp = (void *)VM_PAGE_TO_PHYS(TAILQ_FIRST(&mlist));
   1054 	memset(cp, 0, INTSTK);
   1055 
   1056 	ci->ci_intstk = cp;
   1057 
   1058 	/* Initialize secondary cpu's initial lwp to its idlelwp. */
   1059 	ci->ci_curlwp = ci->ci_data.cpu_idlelwp;
   1060 	ci->ci_curpcb = &ci->ci_curlwp->l_addr->u_pcb;
   1061 	ci->ci_curpm = ci->ci_curpcb->pcb_pm;
   1062 
   1063 	cpu_hatch_data = h;
   1064 	h->running = 0;
   1065 	h->self = self;
   1066 	h->ci = ci;
   1067 	h->pir = ci->ci_cpuid;
   1068 	cpu_hatch_stack = (uint32_t)cp + INTSTK - sizeof(struct trapframe);
   1069 	ci->ci_lasttb = cpu_info[0].ci_lasttb;
   1070 
   1071 	/* copy special registers */
   1072 	h->hid0 = mfspr(SPR_HID0);
   1073 	__asm volatile ("mfsdr1 %0" : "=r"(h->sdr1));
   1074 	for (i = 0; i < 16; i++)
   1075 		__asm ("mfsrin %0,%1" : "=r"(h->sr[i]) :
   1076 		       "r"(i << ADDR_SR_SHFT));
   1077 	/* copy the bat regs */
   1078 	__asm volatile ("mfibatu %0,0" : "=r"(h->batu[0]));
   1079 	__asm volatile ("mfibatl %0,0" : "=r"(h->batl[0]));
   1080 	__asm volatile ("mfibatu %0,1" : "=r"(h->batu[1]));
   1081 	__asm volatile ("mfibatl %0,1" : "=r"(h->batl[1]));
   1082 	__asm volatile ("mfibatu %0,2" : "=r"(h->batu[2]));
   1083 	__asm volatile ("mfibatl %0,2" : "=r"(h->batl[2]));
   1084 	__asm volatile ("mfibatu %0,3" : "=r"(h->batu[3]));
   1085 	__asm volatile ("mfibatl %0,3" : "=r"(h->batl[3]));
   1086 	__asm volatile ("sync; isync");
   1087 
   1088 	if (md_setup_trampoline(h, ci) == -1)
   1089 		return -1;
   1090 	md_presync_timebase(h);
   1091 	md_start_timebase(h);
   1092 
   1093 	/* wait for secondary printf */
   1094 	delay(200000);
   1095 
   1096 	if (h->running == 0) {
   1097 		aprint_error(":CPU %d didn't start\n", ci->ci_cpuid);
   1098 		return -1;
   1099 	}
   1100 
   1101 	/* Register IPI Interrupt */
   1102 	ipiops.ppc_establish_ipi(IST_LEVEL, IPL_HIGH, NULL);
   1103 
   1104 	return 0;
   1105 }
   1106 
   1107 static volatile int start_secondary_cpu;
   1108 
   1109 void
   1110 cpu_hatch()
   1111 {
   1112 	volatile struct cpu_hatch_data *h = cpu_hatch_data;
   1113 	struct cpu_info * const ci = h->ci;
   1114 	u_int msr;
   1115 	int i;
   1116 
   1117 	/* Initialize timebase. */
   1118 	__asm ("mttbl %0; mttbu %0; mttbl %0" :: "r"(0));
   1119 
   1120 	/* Set PIR (Processor Identification Register).  i.e. whoami */
   1121 	mtspr(SPR_PIR, h->pir);
   1122 	__asm volatile ("mtsprg 0,%0" :: "r"(ci));
   1123 
   1124 	/* Initialize MMU. */
   1125 	__asm ("mtibatu 0,%0" :: "r"(h->batu[0]));
   1126 	__asm ("mtibatl 0,%0" :: "r"(h->batl[0]));
   1127 	__asm ("mtibatu 1,%0" :: "r"(h->batu[1]));
   1128 	__asm ("mtibatl 1,%0" :: "r"(h->batl[1]));
   1129 	__asm ("mtibatu 2,%0" :: "r"(h->batu[2]));
   1130 	__asm ("mtibatl 2,%0" :: "r"(h->batl[2]));
   1131 	__asm ("mtibatu 3,%0" :: "r"(h->batu[3]));
   1132 	__asm ("mtibatl 3,%0" :: "r"(h->batl[3]));
   1133 
   1134 	mtspr(SPR_HID0, h->hid0);
   1135 
   1136 	__asm ("mtibatl 0,%0; mtibatu 0,%1; mtdbatl 0,%0; mtdbatu 0,%1;"
   1137 	    :: "r"(battable[0].batl), "r"(battable[0].batu));
   1138 
   1139 	for (i = 0; i < 16; i++)
   1140 		__asm ("mtsrin %0,%1" :: "r"(h->sr[i]), "r"(i << ADDR_SR_SHFT));
   1141 
   1142 	__asm ("mtsdr1 %0" :: "r"(h->sdr1));
   1143 	__asm volatile ("isync");
   1144 
   1145 	/* Enable I/D address translations. */
   1146 	__asm volatile ("mfmsr %0" : "=r"(msr));
   1147 	msr |= PSL_IR|PSL_DR|PSL_ME|PSL_RI;
   1148 	__asm volatile ("mtmsr %0" :: "r"(msr));
   1149 	__asm volatile ("sync; isync");
   1150 
   1151 	md_sync_timebase(h);
   1152 
   1153 	cpu_setup(h->self, ci);
   1154 
   1155 	h->running = 1;
   1156 	__asm volatile ("sync; isync");
   1157 
   1158 	while (start_secondary_cpu == 0)
   1159 		;
   1160 
   1161 	__asm volatile ("sync; isync");
   1162 
   1163 	aprint_normal("cpu%d: started\n", cpu_number());
   1164 	__asm volatile ("mtdec %0" :: "r"(ticks_per_intr));
   1165 
   1166 	md_setup_interrupts();
   1167 
   1168 	ci->ci_ipending = 0;
   1169 	ci->ci_cpl = 0;
   1170 
   1171 	mtmsr(mfmsr() | PSL_EE);
   1172 }
   1173 
   1174 void
   1175 cpu_boot_secondary_processors()
   1176 {
   1177 	start_secondary_cpu = 1;
   1178 	__asm volatile ("sync");
   1179 }
   1180 
   1181 #endif /*MULTIPROCESSOR*/
   1182