xref: /onnv-gate/usr/src/uts/sun4/os/mp_startup.c (revision 12009:8ea3db5ad9f1)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51455Sandrei  * Common Development and Distribution License (the "License").
61455Sandrei  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211991Sheppo 
220Sstevel@tonic-gate /*
23*12009Srafael.vanoni@sun.com  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include <sys/sysmacros.h>
280Sstevel@tonic-gate #include <sys/prom_plat.h>
290Sstevel@tonic-gate #include <sys/prom_debug.h>
300Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
310Sstevel@tonic-gate #include <vm/seg_kp.h>
320Sstevel@tonic-gate #include <vm/seg_kmem.h>
330Sstevel@tonic-gate #include <sys/machsystm.h>
340Sstevel@tonic-gate #include <sys/callb.h>
350Sstevel@tonic-gate #include <sys/cpu_module.h>
363434Sesaxe #include <sys/pg.h>
373434Sesaxe #include <sys/cmt.h>
380Sstevel@tonic-gate #include <sys/dtrace.h>
390Sstevel@tonic-gate #include <sys/reboot.h>
400Sstevel@tonic-gate #include <sys/kdi.h>
411077Ssvemuri #include <sys/traptrace.h>
420Sstevel@tonic-gate #ifdef TRAPTRACE
430Sstevel@tonic-gate #include <sys/bootconf.h>
440Sstevel@tonic-gate #endif /* TRAPTRACE */
450Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
460Sstevel@tonic-gate 
474050Sjb145095 extern int cpu_intrq_setup(struct cpu *);
481991Sheppo extern void cpu_intrq_cleanup(struct cpu *);
490Sstevel@tonic-gate extern void cpu_intrq_register(struct cpu *);
500Sstevel@tonic-gate 
510Sstevel@tonic-gate struct cpu	*cpus;	/* pointer to other cpus; dynamically allocate */
520Sstevel@tonic-gate struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
530Sstevel@tonic-gate uint64_t	cpu_pa[NCPU];	/* pointers to all CPUs in PA */
540Sstevel@tonic-gate cpu_core_t	cpu_core[NCPU];	/* cpu_core structures */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #ifdef TRAPTRACE
575648Ssetje caddr_t	ttrace_buf;	/* kmem64 traptrace for all cpus except 0 */
580Sstevel@tonic-gate #endif /* TRAPTRACE */
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /* bit mask of cpus ready for x-calls, protected by cpu_lock */
610Sstevel@tonic-gate cpuset_t cpu_ready_set;
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /* bit mask used to communicate with cpus during bringup */
640Sstevel@tonic-gate static cpuset_t proxy_ready_set;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate static void	slave_startup(void);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * Defined in $KARCH/os/mach_mp_startup.c
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate #pragma weak init_cpu_info
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate  * Amount of time (in milliseconds) we should wait before giving up on CPU
750Sstevel@tonic-gate  * initialization and assuming that the CPU we're trying to wake up is dead
760Sstevel@tonic-gate  * or out of control.
770Sstevel@tonic-gate  */
780Sstevel@tonic-gate #define	CPU_WAKEUP_GRACE_MSEC 1000
790Sstevel@tonic-gate 
800Sstevel@tonic-gate #ifdef	TRAPTRACE
810Sstevel@tonic-gate /*
823764Sdp78419  * This function sets traptrace buffers for all cpus
830Sstevel@tonic-gate  * other than boot cpu.
840Sstevel@tonic-gate  */
855648Ssetje size_t
calc_traptrace_sz(void)865648Ssetje calc_traptrace_sz(void)
870Sstevel@tonic-gate {
885648Ssetje 	return (TRAP_TSIZE * (max_ncpus - 1));
890Sstevel@tonic-gate }
900Sstevel@tonic-gate #endif	/* TRAPTRACE */
910Sstevel@tonic-gate 
925648Ssetje 
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate  * common slave cpu initialization code
950Sstevel@tonic-gate  */
960Sstevel@tonic-gate void
common_startup_init(cpu_t * cp,int cpuid)970Sstevel@tonic-gate common_startup_init(cpu_t *cp, int cpuid)
980Sstevel@tonic-gate {
990Sstevel@tonic-gate 	kthread_id_t tp;
1000Sstevel@tonic-gate 	sfmmu_t *sfmmup;
1010Sstevel@tonic-gate 	caddr_t	sp;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	/*
1040Sstevel@tonic-gate 	 * Allocate and initialize the startup thread for this CPU.
1050Sstevel@tonic-gate 	 */
1060Sstevel@tonic-gate 	tp = thread_create(NULL, 0, slave_startup, NULL, 0, &p0,
1070Sstevel@tonic-gate 	    TS_STOPPED, maxclsyspri);
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	/*
1100Sstevel@tonic-gate 	 * Set state to TS_ONPROC since this thread will start running
1110Sstevel@tonic-gate 	 * as soon as the CPU comes online.
1120Sstevel@tonic-gate 	 *
1130Sstevel@tonic-gate 	 * All the other fields of the thread structure are setup by
1140Sstevel@tonic-gate 	 * thread_create().
1150Sstevel@tonic-gate 	 */
1160Sstevel@tonic-gate 	THREAD_ONPROC(tp, cp);
1170Sstevel@tonic-gate 	tp->t_preempt = 1;
1180Sstevel@tonic-gate 	tp->t_bound_cpu = cp;
1190Sstevel@tonic-gate 	tp->t_affinitycnt = 1;
1200Sstevel@tonic-gate 	tp->t_cpu = cp;
1210Sstevel@tonic-gate 	tp->t_disp_queue = cp->cpu_disp;
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	sfmmup = astosfmmu(&kas);
1240Sstevel@tonic-gate 	CPUSET_ADD(sfmmup->sfmmu_cpusran, cpuid);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	/*
1270Sstevel@tonic-gate 	 * Setup thread to start in slave_startup.
1280Sstevel@tonic-gate 	 */
1290Sstevel@tonic-gate 	sp = tp->t_stk;
1300Sstevel@tonic-gate 	tp->t_pc = (uintptr_t)slave_startup - 8;
1310Sstevel@tonic-gate 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	cp->cpu_id = cpuid;
1340Sstevel@tonic-gate 	cp->cpu_self = cp;
1350Sstevel@tonic-gate 	cp->cpu_thread = tp;
1360Sstevel@tonic-gate 	cp->cpu_lwp = NULL;
1370Sstevel@tonic-gate 	cp->cpu_dispthread = tp;
1380Sstevel@tonic-gate 	cp->cpu_dispatch_pri = DISP_PRIO(tp);
139834Sandrei 	cp->cpu_startup_thread = tp;
140*12009Srafael.vanoni@sun.com 
141*12009Srafael.vanoni@sun.com 	/*
142*12009Srafael.vanoni@sun.com 	 * The dispatcher may discover the CPU before it is in cpu_ready_set
143*12009Srafael.vanoni@sun.com 	 * and attempt to poke it. Before the CPU is in cpu_ready_set, any
144*12009Srafael.vanoni@sun.com 	 * cross calls to it will be dropped. We initialize
145*12009Srafael.vanoni@sun.com 	 * poke_cpu_outstanding to true so that poke_cpu will ignore any poke
146*12009Srafael.vanoni@sun.com 	 * requests for this CPU. Pokes that come in before the CPU is in
147*12009Srafael.vanoni@sun.com 	 * cpu_ready_set can be ignored because the CPU is about to come
148*12009Srafael.vanoni@sun.com 	 * online.
149*12009Srafael.vanoni@sun.com 	 */
150*12009Srafael.vanoni@sun.com 	cp->cpu_m.poke_cpu_outstanding = B_TRUE;
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * parametric flag setting functions.  these routines set the cpu
1550Sstevel@tonic-gate  * state just prior to releasing the slave cpu.
1560Sstevel@tonic-gate  */
1570Sstevel@tonic-gate void
cold_flag_set(int cpuid)1580Sstevel@tonic-gate cold_flag_set(int cpuid)
1590Sstevel@tonic-gate {
1600Sstevel@tonic-gate 	cpu_t *cp;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	cp = cpu[cpuid];
1650Sstevel@tonic-gate 	cp->cpu_flags |= CPU_RUNNING | CPU_ENABLE | CPU_EXISTS;
1660Sstevel@tonic-gate 	cpu_add_active(cp);
1670Sstevel@tonic-gate 	/*
1680Sstevel@tonic-gate 	 * Add CPU_READY after the cpu_add_active() call
1690Sstevel@tonic-gate 	 * to avoid pausing cp.
1700Sstevel@tonic-gate 	 */
1710Sstevel@tonic-gate 	cp->cpu_flags |= CPU_READY;		/* ready */
1720Sstevel@tonic-gate 	cpu_set_state(cp);
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate static void
warm_flag_set(int cpuid)1760Sstevel@tonic-gate warm_flag_set(int cpuid)
1770Sstevel@tonic-gate {
1780Sstevel@tonic-gate 	cpu_t *cp;
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 	/*
1830Sstevel@tonic-gate 	 * warm start activates cpus into the OFFLINE state
1840Sstevel@tonic-gate 	 */
1850Sstevel@tonic-gate 	cp = cpu[cpuid];
1860Sstevel@tonic-gate 	cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_EXISTS
1874681Sbholler 	    | CPU_OFFLINE | CPU_QUIESCED;
1880Sstevel@tonic-gate 	cpu_set_state(cp);
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate /*
1920Sstevel@tonic-gate  * Internal cpu startup sequencer
1930Sstevel@tonic-gate  * The sequence is as follows:
1940Sstevel@tonic-gate  *
1950Sstevel@tonic-gate  * MASTER	SLAVE
1960Sstevel@tonic-gate  * -------	----------
1970Sstevel@tonic-gate  * assume the kernel data is initialized
1980Sstevel@tonic-gate  * clear the proxy bit
1990Sstevel@tonic-gate  * start the slave cpu
2000Sstevel@tonic-gate  * wait for the slave cpu to set the proxy
2010Sstevel@tonic-gate  *
2020Sstevel@tonic-gate  *		the slave runs slave_startup and then sets the proxy
2030Sstevel@tonic-gate  *		the slave waits for the master to add slave to the ready set
2040Sstevel@tonic-gate  *
2050Sstevel@tonic-gate  * the master finishes the initialization and
2060Sstevel@tonic-gate  * adds the slave to the ready set
2070Sstevel@tonic-gate  *
2080Sstevel@tonic-gate  *		the slave exits the startup thread and is running
2090Sstevel@tonic-gate  */
2100Sstevel@tonic-gate void
start_cpu(int cpuid,void (* flag_func)(int))2110Sstevel@tonic-gate start_cpu(int cpuid, void(*flag_func)(int))
2120Sstevel@tonic-gate {
2131640Spetede 	extern void cpu_startup(int);
2140Sstevel@tonic-gate 	int timout;
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 	/*
2190Sstevel@tonic-gate 	 * Before we begin the dance, tell DTrace that we're about to start
2200Sstevel@tonic-gate 	 * a CPU.
2210Sstevel@tonic-gate 	 */
2220Sstevel@tonic-gate 	if (dtrace_cpustart_init != NULL)
2230Sstevel@tonic-gate 		(*dtrace_cpustart_init)();
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 	/* start the slave cpu */
2260Sstevel@tonic-gate 	CPUSET_DEL(proxy_ready_set, cpuid);
2270Sstevel@tonic-gate 	if (prom_test("SUNW,start-cpu-by-cpuid") == 0) {
2280Sstevel@tonic-gate 		(void) prom_startcpu_bycpuid(cpuid, (caddr_t)&cpu_startup,
2290Sstevel@tonic-gate 		    cpuid);
2300Sstevel@tonic-gate 	} else {
2310Sstevel@tonic-gate 		/* "by-cpuid" interface didn't exist.  Do it the old way */
232789Sahrens 		pnode_t nodeid = cpunodes[cpuid].nodeid;
2330Sstevel@tonic-gate 
234789Sahrens 		ASSERT(nodeid != (pnode_t)0);
2350Sstevel@tonic-gate 		(void) prom_startcpu(nodeid, (caddr_t)&cpu_startup, cpuid);
2360Sstevel@tonic-gate 	}
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate 	/* wait for the slave cpu to check in. */
2390Sstevel@tonic-gate 	for (timout = CPU_WAKEUP_GRACE_MSEC; timout; timout--) {
2400Sstevel@tonic-gate 		if (CPU_IN_SET(proxy_ready_set, cpuid))
2410Sstevel@tonic-gate 			break;
2420Sstevel@tonic-gate 		DELAY(1000);
2430Sstevel@tonic-gate 	}
2440Sstevel@tonic-gate 	if (timout == 0) {
2450Sstevel@tonic-gate 		panic("cpu%d failed to start (2)", cpuid);
2460Sstevel@tonic-gate 	}
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 	/*
2490Sstevel@tonic-gate 	 * The slave has started; we can tell DTrace that it's safe again.
2500Sstevel@tonic-gate 	 */
2510Sstevel@tonic-gate 	if (dtrace_cpustart_fini != NULL)
2520Sstevel@tonic-gate 		(*dtrace_cpustart_fini)();
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate 	/* run the master side of stick synchronization for the slave cpu */
2550Sstevel@tonic-gate 	sticksync_master();
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	/*
2580Sstevel@tonic-gate 	 * deal with the cpu flags in a phase-specific manner
2590Sstevel@tonic-gate 	 * for various reasons, this needs to run after the slave
2600Sstevel@tonic-gate 	 * is checked in but before the slave is released.
2610Sstevel@tonic-gate 	 */
2620Sstevel@tonic-gate 	(*flag_func)(cpuid);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	/* release the slave */
2650Sstevel@tonic-gate 	CPUSET_ADD(cpu_ready_set, cpuid);
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate #ifdef TRAPTRACE
2690Sstevel@tonic-gate int trap_tr0_inuse = 1;	/* it is always used on the boot cpu */
2700Sstevel@tonic-gate int trap_trace_inuse[NCPU];
2710Sstevel@tonic-gate #endif /* TRAPTRACE */
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate #define	cpu_next_free	cpu_prev
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate /*
2760Sstevel@tonic-gate  * Routine to set up a CPU to prepare for starting it up.
2770Sstevel@tonic-gate  */
2784050Sjb145095 int
setup_cpu_common(int cpuid)2790Sstevel@tonic-gate setup_cpu_common(int cpuid)
2800Sstevel@tonic-gate {
2810Sstevel@tonic-gate 	struct cpu *cp = NULL;
2820Sstevel@tonic-gate 	kthread_id_t tp;
2830Sstevel@tonic-gate #ifdef TRAPTRACE
2840Sstevel@tonic-gate 	int tt_index;
2850Sstevel@tonic-gate 	TRAP_TRACE_CTL	*ctlp;
2860Sstevel@tonic-gate 	caddr_t	newbuf;
2870Sstevel@tonic-gate #endif /* TRAPTRACE */
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	extern void idle();
2904050Sjb145095 	int	rval;
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
2930Sstevel@tonic-gate 	ASSERT(cpu[cpuid] == NULL);
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	ASSERT(ncpus <= max_ncpus);
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate #ifdef TRAPTRACE
2980Sstevel@tonic-gate 	/*
2990Sstevel@tonic-gate 	 * allocate a traptrace buffer for this CPU.
3000Sstevel@tonic-gate 	 */
3010Sstevel@tonic-gate 	ctlp = &trap_trace_ctl[cpuid];
3020Sstevel@tonic-gate 	if (!trap_tr0_inuse) {
3030Sstevel@tonic-gate 		trap_tr0_inuse = 1;
3040Sstevel@tonic-gate 		newbuf = trap_tr0;
3050Sstevel@tonic-gate 		tt_index = -1;
3060Sstevel@tonic-gate 	} else {
3070Sstevel@tonic-gate 		for (tt_index = 0; tt_index < (max_ncpus-1); tt_index++)
3080Sstevel@tonic-gate 			if (!trap_trace_inuse[tt_index])
3094681Sbholler 				break;
3100Sstevel@tonic-gate 		ASSERT(tt_index < max_ncpus - 1);
3110Sstevel@tonic-gate 		trap_trace_inuse[tt_index] = 1;
3121077Ssvemuri 		newbuf = (caddr_t)(ttrace_buf + (tt_index * TRAP_TSIZE));
3130Sstevel@tonic-gate 	}
3140Sstevel@tonic-gate 	ctlp->d.vaddr_base = newbuf;
3150Sstevel@tonic-gate 	ctlp->d.offset = ctlp->d.last_offset = 0;
3160Sstevel@tonic-gate 	ctlp->d.limit = trap_trace_bufsize;
3170Sstevel@tonic-gate 	ctlp->d.paddr_base = va_to_pa(newbuf);
3180Sstevel@tonic-gate 	ASSERT(ctlp->d.paddr_base != (uint64_t)-1);
3191077Ssvemuri #endif /* TRAPTRACE */
3200Sstevel@tonic-gate 	/*
3211077Ssvemuri 	 * initialize hv traptrace buffer for this CPU
3220Sstevel@tonic-gate 	 */
3231077Ssvemuri 	mach_htraptrace_setup(cpuid);
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	/*
3260Sstevel@tonic-gate 	 * Obtain pointer to the appropriate cpu structure.
3270Sstevel@tonic-gate 	 */
3280Sstevel@tonic-gate 	if (cpu0.cpu_flags == 0) {
3290Sstevel@tonic-gate 		cp = &cpu0;
3300Sstevel@tonic-gate 	} else {
3310Sstevel@tonic-gate 		/*
3320Sstevel@tonic-gate 		 *  When dynamically allocating cpu structs,
3330Sstevel@tonic-gate 		 *  cpus is used as a pointer to a list of freed
3340Sstevel@tonic-gate 		 *  cpu structs.
3350Sstevel@tonic-gate 		 */
3360Sstevel@tonic-gate 		if (cpus) {
3370Sstevel@tonic-gate 			/* grab the first cpu struct on the free list */
3380Sstevel@tonic-gate 			cp = cpus;
3390Sstevel@tonic-gate 			if (cp->cpu_next_free)
3400Sstevel@tonic-gate 				cpus = cp->cpu_next_free;
3410Sstevel@tonic-gate 			else
3420Sstevel@tonic-gate 				cpus = NULL;
3430Sstevel@tonic-gate 		}
3440Sstevel@tonic-gate 	}
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 	if (cp == NULL)
3470Sstevel@tonic-gate 		cp = vmem_xalloc(static_alloc_arena, CPU_ALLOC_SIZE,
3480Sstevel@tonic-gate 		    CPU_ALLOC_SIZE, 0, 0, NULL, NULL, VM_SLEEP);
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 	bzero(cp, sizeof (*cp));
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate 	cp->cpu_id = cpuid;
3530Sstevel@tonic-gate 	cp->cpu_self = cp;
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	/*
3560Sstevel@tonic-gate 	 * Initialize ptl1_panic stack
3570Sstevel@tonic-gate 	 */
3580Sstevel@tonic-gate 	ptl1_init_cpu(cp);
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	/*
3610Sstevel@tonic-gate 	 * Initialize the dispatcher for this CPU.
3620Sstevel@tonic-gate 	 */
3630Sstevel@tonic-gate 	disp_cpu_init(cp);
3640Sstevel@tonic-gate 
3659352SEric.Saxe@Sun.COM 	/*
3669352SEric.Saxe@Sun.COM 	 * Bootstrap the CPU's PG data
3679352SEric.Saxe@Sun.COM 	 */
3689352SEric.Saxe@Sun.COM 	pg_cpu_bootstrap(cp);
3699352SEric.Saxe@Sun.COM 
370414Skchow 	cpu_vm_data_init(cp);
371414Skchow 
3720Sstevel@tonic-gate 	/*
3730Sstevel@tonic-gate 	 * Now, initialize per-CPU idle thread for this CPU.
3740Sstevel@tonic-gate 	 */
3750Sstevel@tonic-gate 	tp = thread_create(NULL, 0, idle, NULL, 0, &p0, TS_ONPROC, -1);
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate 	cp->cpu_idle_thread = tp;
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 	tp->t_preempt = 1;
3800Sstevel@tonic-gate 	tp->t_bound_cpu = cp;
3810Sstevel@tonic-gate 	tp->t_affinitycnt = 1;
3820Sstevel@tonic-gate 	tp->t_cpu = cp;
3830Sstevel@tonic-gate 	tp->t_disp_queue = cp->cpu_disp;
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 	/*
3860Sstevel@tonic-gate 	 * Registering a thread in the callback table is usually
3870Sstevel@tonic-gate 	 * done in the initialization code of the thread. In this
3880Sstevel@tonic-gate 	 * case, we do it right after thread creation to avoid
3890Sstevel@tonic-gate 	 * blocking idle thread while registering itself. It also
3900Sstevel@tonic-gate 	 * avoids the possibility of reregistration in case a CPU
3910Sstevel@tonic-gate 	 * restarts its idle thread.
3920Sstevel@tonic-gate 	 */
3930Sstevel@tonic-gate 	CALLB_CPR_INIT_SAFE(tp, "idle");
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate 	init_cpu_info(cp);
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate 	/*
3980Sstevel@tonic-gate 	 * Initialize the interrupt threads for this CPU
3990Sstevel@tonic-gate 	 */
4001455Sandrei 	cpu_intr_alloc(cp, NINTR_THREADS);
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 	/*
403220Sesaxe 	 * Add CPU to list of available CPUs.
404220Sesaxe 	 * It'll be on the active list after it is started.
4050Sstevel@tonic-gate 	 */
4060Sstevel@tonic-gate 	cpu_add_unit(cp);
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate 	/*
4090Sstevel@tonic-gate 	 * Allocate and init cpu module private data structures,
4100Sstevel@tonic-gate 	 * including scrubber.
4110Sstevel@tonic-gate 	 */
4120Sstevel@tonic-gate 	cpu_init_private(cp);
4137718SJason.Beloro@Sun.COM 	populate_idstr(cp);
4140Sstevel@tonic-gate 
415220Sesaxe 	/*
4163434Sesaxe 	 * Initialize the CPUs physical ID cache, and processor groups
417220Sesaxe 	 */
4183434Sesaxe 	pghw_physid_create(cp);
41911172SHaik.Aftandilian@Sun.COM 	(void) pg_cpu_init(cp, B_FALSE);
4203434Sesaxe 
4214050Sjb145095 	if ((rval = cpu_intrq_setup(cp)) != 0) {
4224050Sjb145095 		return (rval);
4234050Sjb145095 	}
4242241Shuah 
4252241Shuah 	/*
4262241Shuah 	 * Initialize MMU context domain information.
4272241Shuah 	 */
4282241Shuah 	sfmmu_cpu_init(cp);
4292241Shuah 
4304050Sjb145095 	return (0);
4310Sstevel@tonic-gate }
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate /*
4340Sstevel@tonic-gate  * Routine to clean up a CPU after shutting it down.
4350Sstevel@tonic-gate  */
4360Sstevel@tonic-gate int
cleanup_cpu_common(int cpuid)4370Sstevel@tonic-gate cleanup_cpu_common(int cpuid)
4380Sstevel@tonic-gate {
4390Sstevel@tonic-gate 	struct cpu *cp;
4400Sstevel@tonic-gate #ifdef TRAPTRACE
4410Sstevel@tonic-gate 	int i;
4420Sstevel@tonic-gate 	TRAP_TRACE_CTL	*ctlp;
4430Sstevel@tonic-gate 	caddr_t	newbuf;
4440Sstevel@tonic-gate #endif /* TRAPTRACE */
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
4470Sstevel@tonic-gate 	ASSERT(cpu[cpuid] != NULL);
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 	cp = cpu[cpuid];
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate 	/* Free cpu module private data structures, including scrubber. */
4520Sstevel@tonic-gate 	cpu_uninit_private(cp);
4530Sstevel@tonic-gate 
4541670Srab 	/* Free cpu ID string and brand string. */
4554050Sjb145095 	if (cp->cpu_idstr)
4564050Sjb145095 		kmem_free(cp->cpu_idstr, strlen(cp->cpu_idstr) + 1);
4574050Sjb145095 	if (cp->cpu_brandstr)
4584050Sjb145095 		kmem_free(cp->cpu_brandstr, strlen(cp->cpu_brandstr) + 1);
4591670Srab 
460414Skchow 	cpu_vm_data_destroy(cp);
461414Skchow 
4620Sstevel@tonic-gate 	/*
4630Sstevel@tonic-gate 	 * Remove CPU from list of available CPUs.
4640Sstevel@tonic-gate 	 */
4650Sstevel@tonic-gate 	cpu_del_unit(cpuid);
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate 	/*
4681991Sheppo 	 * Clean any machine specific interrupt states.
4691991Sheppo 	 */
4701991Sheppo 	cpu_intrq_cleanup(cp);
4711991Sheppo 
4721991Sheppo 	/*
4730Sstevel@tonic-gate 	 * At this point, the only threads bound to this CPU should be
4740Sstevel@tonic-gate 	 * special per-cpu threads: it's idle thread, it's pause thread,
4750Sstevel@tonic-gate 	 * and it's interrupt threads.  Clean these up.
4760Sstevel@tonic-gate 	 */
4770Sstevel@tonic-gate 	cpu_destroy_bound_threads(cp);
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate 	/*
4800Sstevel@tonic-gate 	 * Free the interrupt stack.
4810Sstevel@tonic-gate 	 */
4820Sstevel@tonic-gate 	segkp_release(segkp, cp->cpu_intr_stack);
4830Sstevel@tonic-gate 
4841077Ssvemuri 	/*
4851077Ssvemuri 	 * Free hv traptrace buffer for this CPU.
4861077Ssvemuri 	 */
4871077Ssvemuri 	mach_htraptrace_cleanup(cpuid);
4880Sstevel@tonic-gate #ifdef TRAPTRACE
4890Sstevel@tonic-gate 	/*
4900Sstevel@tonic-gate 	 * Free the traptrace buffer for this CPU.
4910Sstevel@tonic-gate 	 */
4920Sstevel@tonic-gate 	ctlp = &trap_trace_ctl[cpuid];
4930Sstevel@tonic-gate 	newbuf = ctlp->d.vaddr_base;
4941077Ssvemuri 	i = (newbuf - ttrace_buf) / (TRAP_TSIZE);
4951077Ssvemuri 	if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) &&
4960Sstevel@tonic-gate 	    ((i >= 0) && (i < (max_ncpus-1)))) {
4970Sstevel@tonic-gate 		/*
4980Sstevel@tonic-gate 		 * This CPU got it's trap trace buffer from the
4990Sstevel@tonic-gate 		 * boot-alloc'd bunch of them.
5000Sstevel@tonic-gate 		 */
5010Sstevel@tonic-gate 		trap_trace_inuse[i] = 0;
5021077Ssvemuri 		bzero(newbuf, (TRAP_TSIZE));
5030Sstevel@tonic-gate 	} else if (newbuf == trap_tr0) {
5040Sstevel@tonic-gate 		trap_tr0_inuse = 0;
5051077Ssvemuri 		bzero(trap_tr0, (TRAP_TSIZE));
5060Sstevel@tonic-gate 	} else {
5070Sstevel@tonic-gate 		cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d",
5080Sstevel@tonic-gate 		    cpuid);
5090Sstevel@tonic-gate 	}
5100Sstevel@tonic-gate 	bzero(ctlp, sizeof (*ctlp));
5110Sstevel@tonic-gate #endif /* TRAPTRACE */
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 	/*
5140Sstevel@tonic-gate 	 * There is a race condition with mutex_vector_enter() which
5150Sstevel@tonic-gate 	 * caches a cpu pointer. The race is detected by checking cpu_next.
5160Sstevel@tonic-gate 	 */
5170Sstevel@tonic-gate 	disp_cpu_fini(cp);
5180Sstevel@tonic-gate 	cpu_pa[cpuid] = 0;
5194050Sjb145095 	if (CPU_MMU_CTXP(cp))
5204050Sjb145095 		sfmmu_cpu_cleanup(cp);
5210Sstevel@tonic-gate 	bzero(cp, sizeof (*cp));
5220Sstevel@tonic-gate 
5230Sstevel@tonic-gate 	/*
5240Sstevel@tonic-gate 	 * Place the freed cpu structure on the list of freed cpus.
5250Sstevel@tonic-gate 	 */
5260Sstevel@tonic-gate 	if (cp != &cpu0) {
5270Sstevel@tonic-gate 		if (cpus) {
5280Sstevel@tonic-gate 			cp->cpu_next_free = cpus;
5290Sstevel@tonic-gate 			cpus = cp;
5300Sstevel@tonic-gate 		}
5310Sstevel@tonic-gate 		else
5320Sstevel@tonic-gate 			cpus = cp;
5330Sstevel@tonic-gate 	}
5340Sstevel@tonic-gate 
5350Sstevel@tonic-gate 	return (0);
5360Sstevel@tonic-gate }
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate /*
5390Sstevel@tonic-gate  * This routine is used to start a previously powered off processor.
5400Sstevel@tonic-gate  * Note that restarted cpus are initialized into the offline state.
5410Sstevel@tonic-gate  */
5420Sstevel@tonic-gate void
restart_other_cpu(int cpuid)5430Sstevel@tonic-gate restart_other_cpu(int cpuid)
5440Sstevel@tonic-gate {
5450Sstevel@tonic-gate 	struct cpu *cp;
5460Sstevel@tonic-gate 	kthread_id_t tp;
5470Sstevel@tonic-gate 	caddr_t	sp;
5480Sstevel@tonic-gate 	extern void idle();
5490Sstevel@tonic-gate 
5500Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
5510Sstevel@tonic-gate 	ASSERT(cpuid < NCPU && cpu[cpuid] != NULL);
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate 	/*
5540Sstevel@tonic-gate 	 * Obtain pointer to the appropriate cpu structure.
5550Sstevel@tonic-gate 	 */
5560Sstevel@tonic-gate 	cp = cpu[cpuid];
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate 	common_startup_init(cp, cpuid);
5590Sstevel@tonic-gate 
5600Sstevel@tonic-gate 	/*
5610Sstevel@tonic-gate 	 * idle thread t_lock is held when the idle thread is suspended.
5620Sstevel@tonic-gate 	 * Manually unlock the t_lock of idle loop so that we can resume
5630Sstevel@tonic-gate 	 * the suspended idle thread.
5640Sstevel@tonic-gate 	 * Also adjust the PC of idle thread for re-retry.
5650Sstevel@tonic-gate 	 */
5660Sstevel@tonic-gate 	cp->cpu_intr_actv = 0;	/* clear the value from previous life */
5670Sstevel@tonic-gate 	cp->cpu_m.mutex_ready = 0; /* we are not ready yet */
5680Sstevel@tonic-gate 	lock_clear(&cp->cpu_idle_thread->t_lock);
5690Sstevel@tonic-gate 	tp = cp->cpu_idle_thread;
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate 	sp = tp->t_stk;
5720Sstevel@tonic-gate 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
5730Sstevel@tonic-gate 	tp->t_pc = (uintptr_t)idle - 8;
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate 	/*
5760Sstevel@tonic-gate 	 * restart the cpu now
5770Sstevel@tonic-gate 	 */
5780Sstevel@tonic-gate 	promsafe_pause_cpus();
5790Sstevel@tonic-gate 	start_cpu(cpuid, warm_flag_set);
5800Sstevel@tonic-gate 	start_cpus();
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate 	/* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */
5830Sstevel@tonic-gate 	cmn_err(CE_CONT, "!cpu%d initialization complete - restarted\n",
5840Sstevel@tonic-gate 	    cpuid);
5850Sstevel@tonic-gate }
5860Sstevel@tonic-gate 
5870Sstevel@tonic-gate /*
5880Sstevel@tonic-gate  * Startup function executed on 'other' CPUs.  This is the first
5890Sstevel@tonic-gate  * C function after cpu_start sets up the cpu registers.
5900Sstevel@tonic-gate  */
5910Sstevel@tonic-gate static void
slave_startup(void)5920Sstevel@tonic-gate slave_startup(void)
5930Sstevel@tonic-gate {
5940Sstevel@tonic-gate 	struct cpu	*cp = CPU;
5950Sstevel@tonic-gate 	ushort_t	original_flags = cp->cpu_flags;
5960Sstevel@tonic-gate 
5971077Ssvemuri 	mach_htraptrace_configure(cp->cpu_id);
5980Sstevel@tonic-gate 	cpu_intrq_register(CPU);
5990Sstevel@tonic-gate 	cp->cpu_m.mutex_ready = 1;
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate 	/* acknowledge that we are done with initialization */
6020Sstevel@tonic-gate 	CPUSET_ADD(proxy_ready_set, cp->cpu_id);
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate 	/* synchronize STICK */
6050Sstevel@tonic-gate 	sticksync_slave();
6060Sstevel@tonic-gate 
6070Sstevel@tonic-gate 	if (boothowto & RB_DEBUG)
6080Sstevel@tonic-gate 		kdi_dvec_cpu_init(cp);
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 	/*
6110Sstevel@tonic-gate 	 * the slave will wait here forever -- assuming that the master
6120Sstevel@tonic-gate 	 * will get back to us.  if it doesn't we've got bigger problems
6130Sstevel@tonic-gate 	 * than a master not replying to this slave.
6140Sstevel@tonic-gate 	 * the small delay improves the slave's responsiveness to the
6150Sstevel@tonic-gate 	 * master's ack and decreases the time window between master and
6160Sstevel@tonic-gate 	 * slave operations.
6170Sstevel@tonic-gate 	 */
6180Sstevel@tonic-gate 	while (!CPU_IN_SET(cpu_ready_set, cp->cpu_id))
6190Sstevel@tonic-gate 		DELAY(1);
6200Sstevel@tonic-gate 
621*12009Srafael.vanoni@sun.com 	/*
622*12009Srafael.vanoni@sun.com 	 * The CPU is now in cpu_ready_set, safely able to take pokes.
623*12009Srafael.vanoni@sun.com 	 */
624*12009Srafael.vanoni@sun.com 	cp->cpu_m.poke_cpu_outstanding = B_FALSE;
625*12009Srafael.vanoni@sun.com 
6260Sstevel@tonic-gate 	/* enable interrupts */
6270Sstevel@tonic-gate 	(void) spl0();
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate 	/*
6300Sstevel@tonic-gate 	 * Signature block update to indicate that this CPU is in OS now.
6310Sstevel@tonic-gate 	 * This needs to be done after the PIL is lowered since on
6320Sstevel@tonic-gate 	 * some platforms the update code may block.
6330Sstevel@tonic-gate 	 */
6340Sstevel@tonic-gate 	CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cp->cpu_id);
6350Sstevel@tonic-gate 
6360Sstevel@tonic-gate 	/*
6370Sstevel@tonic-gate 	 * park the slave thread in a safe/quiet state and wait for the master
6380Sstevel@tonic-gate 	 * to finish configuring this CPU before proceeding to thread_exit().
6390Sstevel@tonic-gate 	 */
6400Sstevel@tonic-gate 	while (((volatile ushort_t)cp->cpu_flags) & CPU_QUIESCED)
6410Sstevel@tonic-gate 		DELAY(1);
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 	/*
6440Sstevel@tonic-gate 	 * Initialize CPC CPU state.
6450Sstevel@tonic-gate 	 */
6460Sstevel@tonic-gate 	kcpc_hw_startup_cpu(original_flags);
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate 	/*
6493434Sesaxe 	 * Notify the PG subsystem that the CPU  has started
6500Sstevel@tonic-gate 	 */
6513434Sesaxe 	pg_cmt_cpu_startup(CPU);
6520Sstevel@tonic-gate 
6530Sstevel@tonic-gate 	/*
6540Sstevel@tonic-gate 	 * Now we are done with the startup thread, so free it up.
6550Sstevel@tonic-gate 	 */
6560Sstevel@tonic-gate 	thread_exit();
6570Sstevel@tonic-gate 	cmn_err(CE_PANIC, "slave_startup: cannot return");
6580Sstevel@tonic-gate 	/*NOTREACHED*/
6590Sstevel@tonic-gate }
6600Sstevel@tonic-gate 
6610Sstevel@tonic-gate extern struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate /*
6640Sstevel@tonic-gate  * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that
6650Sstevel@tonic-gate  * can be used during debugging to control which processors are brought
6660Sstevel@tonic-gate  * online at boot time.  The variable represents a bitmap of the id's
6670Sstevel@tonic-gate  * of the processors that will be brought online.  The initialization
6680Sstevel@tonic-gate  * of this variable depends on the type of cpuset_t, which varies
6690Sstevel@tonic-gate  * depending on the number of processors supported (see cpuvar.h).
6700Sstevel@tonic-gate  */
6710Sstevel@tonic-gate cpuset_t cpu_bringup_set;
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate 
6740Sstevel@tonic-gate /*
6750Sstevel@tonic-gate  * Generic start-all cpus entry.  Typically used during cold initialization.
6760Sstevel@tonic-gate  * Note that cold start cpus are initialized into the online state.
6770Sstevel@tonic-gate  */
6780Sstevel@tonic-gate /*ARGSUSED*/
6790Sstevel@tonic-gate void
start_other_cpus(int flag)6800Sstevel@tonic-gate start_other_cpus(int flag)
6810Sstevel@tonic-gate {
6820Sstevel@tonic-gate 	int cpuid;
6830Sstevel@tonic-gate 	extern void idlestop_init(void);
6840Sstevel@tonic-gate 	int bootcpu;
6850Sstevel@tonic-gate 
6860Sstevel@tonic-gate 	/*
6870Sstevel@tonic-gate 	 * Check if cpu_bringup_set has been explicitly set before
6880Sstevel@tonic-gate 	 * initializing it.
6890Sstevel@tonic-gate 	 */
6900Sstevel@tonic-gate 	if (CPUSET_ISNULL(cpu_bringup_set)) {
6910Sstevel@tonic-gate 		CPUSET_ALL(cpu_bringup_set);
6920Sstevel@tonic-gate 	}
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate 	if (&cpu_feature_init)
6950Sstevel@tonic-gate 		cpu_feature_init();
6960Sstevel@tonic-gate 
6970Sstevel@tonic-gate 	/*
6980Sstevel@tonic-gate 	 * Initialize CPC.
6990Sstevel@tonic-gate 	 */
7000Sstevel@tonic-gate 	kcpc_hw_init();
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate 	/*
7050Sstevel@tonic-gate 	 * Initialize our own cpu_info.
7060Sstevel@tonic-gate 	 */
7070Sstevel@tonic-gate 	init_cpu_info(CPU);
7080Sstevel@tonic-gate 
7090Sstevel@tonic-gate 	/*
7100Sstevel@tonic-gate 	 * Initialize CPU 0 cpu module private data area, including scrubber.
7110Sstevel@tonic-gate 	 */
7120Sstevel@tonic-gate 	cpu_init_private(CPU);
7137718SJason.Beloro@Sun.COM 	populate_idstr(CPU);
7140Sstevel@tonic-gate 
7150Sstevel@tonic-gate 	/*
7160Sstevel@tonic-gate 	 * perform such initialization as is needed
7170Sstevel@tonic-gate 	 * to be able to take CPUs on- and off-line.
7180Sstevel@tonic-gate 	 */
7190Sstevel@tonic-gate 	cpu_pause_init();
7200Sstevel@tonic-gate 	xc_init();		/* initialize processor crosscalls */
7210Sstevel@tonic-gate 	idlestop_init();
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate 	if (!use_mp) {
7240Sstevel@tonic-gate 		mutex_exit(&cpu_lock);
7250Sstevel@tonic-gate 		cmn_err(CE_CONT, "?***** Not in MP mode\n");
7260Sstevel@tonic-gate 		return;
7270Sstevel@tonic-gate 	}
7280Sstevel@tonic-gate 	/*
7290Sstevel@tonic-gate 	 * should we be initializing this cpu?
7300Sstevel@tonic-gate 	 */
7310Sstevel@tonic-gate 	bootcpu = getprocessorid();
7320Sstevel@tonic-gate 
7330Sstevel@tonic-gate 	/*
7340Sstevel@tonic-gate 	 * launch all the slave cpus now
7350Sstevel@tonic-gate 	 */
7360Sstevel@tonic-gate 	for (cpuid = 0; cpuid < NCPU; cpuid++) {
737789Sahrens 		pnode_t nodeid = cpunodes[cpuid].nodeid;
7380Sstevel@tonic-gate 
739789Sahrens 		if (nodeid == (pnode_t)0)
7400Sstevel@tonic-gate 			continue;
7410Sstevel@tonic-gate 
7420Sstevel@tonic-gate 		if (cpuid == bootcpu) {
7430Sstevel@tonic-gate 			if (!CPU_IN_SET(cpu_bringup_set, cpuid)) {
7440Sstevel@tonic-gate 				cmn_err(CE_WARN, "boot cpu not a member "
7450Sstevel@tonic-gate 				    "of cpu_bringup_set, adding it");
7460Sstevel@tonic-gate 				CPUSET_ADD(cpu_bringup_set, cpuid);
7470Sstevel@tonic-gate 			}
7480Sstevel@tonic-gate 			continue;
7490Sstevel@tonic-gate 		}
7500Sstevel@tonic-gate 		if (!CPU_IN_SET(cpu_bringup_set, cpuid))
7510Sstevel@tonic-gate 			continue;
7520Sstevel@tonic-gate 
7530Sstevel@tonic-gate 		ASSERT(cpu[cpuid] == NULL);
7540Sstevel@tonic-gate 
7554050Sjb145095 		if (setup_cpu_common(cpuid)) {
7564050Sjb145095 			cmn_err(CE_PANIC, "cpu%d: setup failed", cpuid);
7574050Sjb145095 		}
7580Sstevel@tonic-gate 
7590Sstevel@tonic-gate 		common_startup_init(cpu[cpuid], cpuid);
7600Sstevel@tonic-gate 
7610Sstevel@tonic-gate 		start_cpu(cpuid, cold_flag_set);
7620Sstevel@tonic-gate 		/*
7630Sstevel@tonic-gate 		 * Because slave_startup() gets fired off after init()
7640Sstevel@tonic-gate 		 * starts, we can't use the '?' trick to do 'boot -v'
7650Sstevel@tonic-gate 		 * printing - so we always direct the 'cpu .. online'
7660Sstevel@tonic-gate 		 * messages to the log.
7670Sstevel@tonic-gate 		 */
7680Sstevel@tonic-gate 		cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
7690Sstevel@tonic-gate 		    cpuid);
7700Sstevel@tonic-gate 
7718803SJonathan.Haslam@Sun.COM 		cpu_state_change_notify(cpuid, CPU_SETUP);
7728803SJonathan.Haslam@Sun.COM 
7730Sstevel@tonic-gate 		if (dtrace_cpu_init != NULL)
7740Sstevel@tonic-gate 			(*dtrace_cpu_init)(cpuid);
7750Sstevel@tonic-gate 	}
7760Sstevel@tonic-gate 
7770Sstevel@tonic-gate 	/*
7780Sstevel@tonic-gate 	 * since all the cpus are online now, redistribute interrupts to them.
7790Sstevel@tonic-gate 	 */
7800Sstevel@tonic-gate 	intr_redist_all_cpus();
7810Sstevel@tonic-gate 
7820Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
7830Sstevel@tonic-gate 
7840Sstevel@tonic-gate 	/*
7850Sstevel@tonic-gate 	 * Start the Ecache scrubber.  Must be done after all calls to
7860Sstevel@tonic-gate 	 * cpu_init_private for every cpu (including CPU 0).
7870Sstevel@tonic-gate 	 */
7880Sstevel@tonic-gate 	cpu_init_cache_scrub();
7890Sstevel@tonic-gate 
7900Sstevel@tonic-gate 	if (&cpu_mp_init)
7910Sstevel@tonic-gate 		cpu_mp_init();
7920Sstevel@tonic-gate }
793