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