xref: /onnv-gate/usr/src/uts/sun4/os/mp_startup.c (revision 1991)
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  */
21*1991Sheppo 
220Sstevel@tonic-gate /*
231455Sandrei  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/sysmacros.h>
300Sstevel@tonic-gate #include <sys/prom_plat.h>
310Sstevel@tonic-gate #include <sys/prom_debug.h>
320Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
330Sstevel@tonic-gate #include <vm/seg_kp.h>
340Sstevel@tonic-gate #include <vm/seg_kmem.h>
350Sstevel@tonic-gate #include <sys/machsystm.h>
360Sstevel@tonic-gate #include <sys/callb.h>
370Sstevel@tonic-gate #include <sys/cpu_module.h>
380Sstevel@tonic-gate #include <sys/chip.h>
390Sstevel@tonic-gate #include <sys/dtrace.h>
400Sstevel@tonic-gate #include <sys/reboot.h>
410Sstevel@tonic-gate #include <sys/kdi.h>
421077Ssvemuri #include <sys/traptrace.h>
430Sstevel@tonic-gate #ifdef TRAPTRACE
440Sstevel@tonic-gate #include <sys/bootconf.h>
450Sstevel@tonic-gate #endif /* TRAPTRACE */
460Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
470Sstevel@tonic-gate 
480Sstevel@tonic-gate extern void cpu_intrq_setup(struct cpu *);
49*1991Sheppo extern void cpu_intrq_cleanup(struct cpu *);
500Sstevel@tonic-gate extern void cpu_intrq_register(struct cpu *);
510Sstevel@tonic-gate 
520Sstevel@tonic-gate struct cpu	*cpus;	/* pointer to other cpus; dynamically allocate */
530Sstevel@tonic-gate struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
540Sstevel@tonic-gate uint64_t	cpu_pa[NCPU];	/* pointers to all CPUs in PA */
550Sstevel@tonic-gate cpu_core_t	cpu_core[NCPU];	/* cpu_core structures */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #ifdef TRAPTRACE
580Sstevel@tonic-gate caddr_t	ttrace_buf;	/* bop alloced traptrace for all cpus except 0 */
590Sstevel@tonic-gate #endif /* TRAPTRACE */
600Sstevel@tonic-gate 
610Sstevel@tonic-gate /* bit mask of cpus ready for x-calls, protected by cpu_lock */
620Sstevel@tonic-gate cpuset_t cpu_ready_set;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /* bit mask used to communicate with cpus during bringup */
650Sstevel@tonic-gate static cpuset_t proxy_ready_set;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate static void	slave_startup(void);
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * Defined in $KARCH/os/mach_mp_startup.c
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate #pragma weak init_cpu_info
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * Amount of time (in milliseconds) we should wait before giving up on CPU
760Sstevel@tonic-gate  * initialization and assuming that the CPU we're trying to wake up is dead
770Sstevel@tonic-gate  * or out of control.
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate #define	CPU_WAKEUP_GRACE_MSEC 1000
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /*
820Sstevel@tonic-gate  * MP configurations may reserve additional interrupt request entries.
830Sstevel@tonic-gate  * intr_add_{div,max} can be modified to tune memory usage.
840Sstevel@tonic-gate  */
850Sstevel@tonic-gate 
860Sstevel@tonic-gate uint_t	intr_add_div = 1;			/* 1=worst case memory usage */
870Sstevel@tonic-gate size_t	intr_add_max = 0;
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /* intr_add_{pools,head,tail} calculated based on intr_add_{div,max} */
900Sstevel@tonic-gate 
910Sstevel@tonic-gate size_t	intr_add_pools = 0;			/* additional pools per cpu */
920Sstevel@tonic-gate struct intr_req	*intr_add_head = (struct intr_req *)NULL;
930Sstevel@tonic-gate #ifdef	DEBUG
940Sstevel@tonic-gate struct intr_req	*intr_add_tail = (struct intr_req *)NULL;
950Sstevel@tonic-gate #endif	/* DEBUG */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 
980Sstevel@tonic-gate #ifdef	TRAPTRACE
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * This function bop allocs traptrace buffers for all cpus
1010Sstevel@tonic-gate  * other than boot cpu.
1020Sstevel@tonic-gate  */
1030Sstevel@tonic-gate caddr_t
1040Sstevel@tonic-gate trap_trace_alloc(caddr_t base)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate 	caddr_t	vaddr;
1070Sstevel@tonic-gate 	extern int max_ncpus;
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	if (max_ncpus == 1) {
1100Sstevel@tonic-gate 		return (base);
1110Sstevel@tonic-gate 	}
1120Sstevel@tonic-gate 
1131077Ssvemuri 	if ((vaddr = (caddr_t)BOP_ALLOC(bootops, base, (TRAP_TSIZE *
1141077Ssvemuri 		(max_ncpus - 1)), TRAP_TSIZE)) == NULL) {
1150Sstevel@tonic-gate 		panic("traptrace_alloc: can't bop alloc");
1160Sstevel@tonic-gate 	}
1170Sstevel@tonic-gate 	ttrace_buf = vaddr;
1180Sstevel@tonic-gate 	PRM_DEBUG(ttrace_buf);
1191077Ssvemuri 	return (vaddr + (TRAP_TSIZE * (max_ncpus - 1)));
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate #endif	/* TRAPTRACE */
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate  * common slave cpu initialization code
1250Sstevel@tonic-gate  */
1260Sstevel@tonic-gate void
1270Sstevel@tonic-gate common_startup_init(cpu_t *cp, int cpuid)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate 	kthread_id_t tp;
1300Sstevel@tonic-gate 	sfmmu_t *sfmmup;
1310Sstevel@tonic-gate 	caddr_t	sp;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	/*
1340Sstevel@tonic-gate 	 * Allocate and initialize the startup thread for this CPU.
1350Sstevel@tonic-gate 	 */
1360Sstevel@tonic-gate 	tp = thread_create(NULL, 0, slave_startup, NULL, 0, &p0,
1370Sstevel@tonic-gate 	    TS_STOPPED, maxclsyspri);
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	/*
1400Sstevel@tonic-gate 	 * Set state to TS_ONPROC since this thread will start running
1410Sstevel@tonic-gate 	 * as soon as the CPU comes online.
1420Sstevel@tonic-gate 	 *
1430Sstevel@tonic-gate 	 * All the other fields of the thread structure are setup by
1440Sstevel@tonic-gate 	 * thread_create().
1450Sstevel@tonic-gate 	 */
1460Sstevel@tonic-gate 	THREAD_ONPROC(tp, cp);
1470Sstevel@tonic-gate 	tp->t_preempt = 1;
1480Sstevel@tonic-gate 	tp->t_bound_cpu = cp;
1490Sstevel@tonic-gate 	tp->t_affinitycnt = 1;
1500Sstevel@tonic-gate 	tp->t_cpu = cp;
1510Sstevel@tonic-gate 	tp->t_disp_queue = cp->cpu_disp;
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate 	sfmmup = astosfmmu(&kas);
1540Sstevel@tonic-gate 	CPUSET_ADD(sfmmup->sfmmu_cpusran, cpuid);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	/*
1570Sstevel@tonic-gate 	 * Setup thread to start in slave_startup.
1580Sstevel@tonic-gate 	 */
1590Sstevel@tonic-gate 	sp = tp->t_stk;
1600Sstevel@tonic-gate 	tp->t_pc = (uintptr_t)slave_startup - 8;
1610Sstevel@tonic-gate 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	cp->cpu_id = cpuid;
1640Sstevel@tonic-gate 	cp->cpu_self = cp;
1650Sstevel@tonic-gate 	cp->cpu_thread = tp;
1660Sstevel@tonic-gate 	cp->cpu_lwp = NULL;
1670Sstevel@tonic-gate 	cp->cpu_dispthread = tp;
1680Sstevel@tonic-gate 	cp->cpu_dispatch_pri = DISP_PRIO(tp);
169834Sandrei 	cp->cpu_startup_thread = tp;
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate  * parametric flag setting functions.  these routines set the cpu
1740Sstevel@tonic-gate  * state just prior to releasing the slave cpu.
1750Sstevel@tonic-gate  */
1760Sstevel@tonic-gate void
1770Sstevel@tonic-gate cold_flag_set(int cpuid)
1780Sstevel@tonic-gate {
1790Sstevel@tonic-gate 	cpu_t *cp;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 	cp = cpu[cpuid];
1840Sstevel@tonic-gate 	cp->cpu_flags |= CPU_RUNNING | CPU_ENABLE | CPU_EXISTS;
1850Sstevel@tonic-gate 	cpu_add_active(cp);
1860Sstevel@tonic-gate 	/*
1870Sstevel@tonic-gate 	 * Add CPU_READY after the cpu_add_active() call
1880Sstevel@tonic-gate 	 * to avoid pausing cp.
1890Sstevel@tonic-gate 	 */
1900Sstevel@tonic-gate 	cp->cpu_flags |= CPU_READY;		/* ready */
1910Sstevel@tonic-gate 	cpu_set_state(cp);
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate static void
1950Sstevel@tonic-gate warm_flag_set(int cpuid)
1960Sstevel@tonic-gate {
1970Sstevel@tonic-gate 	cpu_t *cp;
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 	/*
2020Sstevel@tonic-gate 	 * warm start activates cpus into the OFFLINE state
2030Sstevel@tonic-gate 	 */
2040Sstevel@tonic-gate 	cp = cpu[cpuid];
2050Sstevel@tonic-gate 	cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_EXISTS
2060Sstevel@tonic-gate 		| CPU_OFFLINE | CPU_QUIESCED;
2070Sstevel@tonic-gate 	cpu_set_state(cp);
2080Sstevel@tonic-gate }
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate /*
2110Sstevel@tonic-gate  * Internal cpu startup sequencer
2120Sstevel@tonic-gate  * The sequence is as follows:
2130Sstevel@tonic-gate  *
2140Sstevel@tonic-gate  * MASTER	SLAVE
2150Sstevel@tonic-gate  * -------	----------
2160Sstevel@tonic-gate  * assume the kernel data is initialized
2170Sstevel@tonic-gate  * clear the proxy bit
2180Sstevel@tonic-gate  * start the slave cpu
2190Sstevel@tonic-gate  * wait for the slave cpu to set the proxy
2200Sstevel@tonic-gate  *
2210Sstevel@tonic-gate  *		the slave runs slave_startup and then sets the proxy
2220Sstevel@tonic-gate  *		the slave waits for the master to add slave to the ready set
2230Sstevel@tonic-gate  *
2240Sstevel@tonic-gate  * the master finishes the initialization and
2250Sstevel@tonic-gate  * adds the slave to the ready set
2260Sstevel@tonic-gate  *
2270Sstevel@tonic-gate  *		the slave exits the startup thread and is running
2280Sstevel@tonic-gate  */
2290Sstevel@tonic-gate void
2300Sstevel@tonic-gate start_cpu(int cpuid, void(*flag_func)(int))
2310Sstevel@tonic-gate {
2321640Spetede 	extern void cpu_startup(int);
2330Sstevel@tonic-gate 	int timout;
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 	/*
2380Sstevel@tonic-gate 	 * Before we begin the dance, tell DTrace that we're about to start
2390Sstevel@tonic-gate 	 * a CPU.
2400Sstevel@tonic-gate 	 */
2410Sstevel@tonic-gate 	if (dtrace_cpustart_init != NULL)
2420Sstevel@tonic-gate 		(*dtrace_cpustart_init)();
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	/* start the slave cpu */
2450Sstevel@tonic-gate 	CPUSET_DEL(proxy_ready_set, cpuid);
2460Sstevel@tonic-gate 	if (prom_test("SUNW,start-cpu-by-cpuid") == 0) {
2470Sstevel@tonic-gate 		(void) prom_startcpu_bycpuid(cpuid, (caddr_t)&cpu_startup,
2480Sstevel@tonic-gate 		    cpuid);
2490Sstevel@tonic-gate 	} else {
2500Sstevel@tonic-gate 		/* "by-cpuid" interface didn't exist.  Do it the old way */
251789Sahrens 		pnode_t nodeid = cpunodes[cpuid].nodeid;
2520Sstevel@tonic-gate 
253789Sahrens 		ASSERT(nodeid != (pnode_t)0);
2540Sstevel@tonic-gate 		(void) prom_startcpu(nodeid, (caddr_t)&cpu_startup, cpuid);
2550Sstevel@tonic-gate 	}
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	/* wait for the slave cpu to check in. */
2580Sstevel@tonic-gate 	for (timout = CPU_WAKEUP_GRACE_MSEC; timout; timout--) {
2590Sstevel@tonic-gate 		if (CPU_IN_SET(proxy_ready_set, cpuid))
2600Sstevel@tonic-gate 			break;
2610Sstevel@tonic-gate 		DELAY(1000);
2620Sstevel@tonic-gate 	}
2630Sstevel@tonic-gate 	if (timout == 0) {
2640Sstevel@tonic-gate 		panic("cpu%d failed to start (2)", cpuid);
2650Sstevel@tonic-gate 	}
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	/*
2680Sstevel@tonic-gate 	 * The slave has started; we can tell DTrace that it's safe again.
2690Sstevel@tonic-gate 	 */
2700Sstevel@tonic-gate 	if (dtrace_cpustart_fini != NULL)
2710Sstevel@tonic-gate 		(*dtrace_cpustart_fini)();
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	/* run the master side of stick synchronization for the slave cpu */
2740Sstevel@tonic-gate 	sticksync_master();
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 	/*
2770Sstevel@tonic-gate 	 * deal with the cpu flags in a phase-specific manner
2780Sstevel@tonic-gate 	 * for various reasons, this needs to run after the slave
2790Sstevel@tonic-gate 	 * is checked in but before the slave is released.
2800Sstevel@tonic-gate 	 */
2810Sstevel@tonic-gate 	(*flag_func)(cpuid);
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	/* release the slave */
2840Sstevel@tonic-gate 	CPUSET_ADD(cpu_ready_set, cpuid);
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate #ifdef TRAPTRACE
2880Sstevel@tonic-gate int trap_tr0_inuse = 1;	/* it is always used on the boot cpu */
2890Sstevel@tonic-gate int trap_trace_inuse[NCPU];
2900Sstevel@tonic-gate #endif /* TRAPTRACE */
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate #define	cpu_next_free	cpu_prev
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate /*
2950Sstevel@tonic-gate  * Routine to set up a CPU to prepare for starting it up.
2960Sstevel@tonic-gate  */
2970Sstevel@tonic-gate void
2980Sstevel@tonic-gate setup_cpu_common(int cpuid)
2990Sstevel@tonic-gate {
3000Sstevel@tonic-gate 	struct cpu *cp = NULL;
3010Sstevel@tonic-gate 	kthread_id_t tp;
3020Sstevel@tonic-gate #ifdef TRAPTRACE
3030Sstevel@tonic-gate 	int tt_index;
3040Sstevel@tonic-gate 	TRAP_TRACE_CTL	*ctlp;
3050Sstevel@tonic-gate 	caddr_t	newbuf;
3060Sstevel@tonic-gate #endif /* TRAPTRACE */
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	extern void idle();
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
3110Sstevel@tonic-gate 	ASSERT(cpu[cpuid] == NULL);
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate 	ASSERT(ncpus <= max_ncpus);
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate #ifdef TRAPTRACE
3160Sstevel@tonic-gate 	/*
3170Sstevel@tonic-gate 	 * allocate a traptrace buffer for this CPU.
3180Sstevel@tonic-gate 	 */
3190Sstevel@tonic-gate 	ctlp = &trap_trace_ctl[cpuid];
3200Sstevel@tonic-gate 	if (!trap_tr0_inuse) {
3210Sstevel@tonic-gate 		trap_tr0_inuse = 1;
3220Sstevel@tonic-gate 		newbuf = trap_tr0;
3230Sstevel@tonic-gate 		tt_index = -1;
3240Sstevel@tonic-gate 	} else {
3250Sstevel@tonic-gate 		for (tt_index = 0; tt_index < (max_ncpus-1); tt_index++)
3260Sstevel@tonic-gate 			if (!trap_trace_inuse[tt_index])
3270Sstevel@tonic-gate 			    break;
3280Sstevel@tonic-gate 		ASSERT(tt_index < max_ncpus - 1);
3290Sstevel@tonic-gate 		trap_trace_inuse[tt_index] = 1;
3301077Ssvemuri 		newbuf = (caddr_t)(ttrace_buf + (tt_index * TRAP_TSIZE));
3310Sstevel@tonic-gate 	}
3320Sstevel@tonic-gate 	ctlp->d.vaddr_base = newbuf;
3330Sstevel@tonic-gate 	ctlp->d.offset = ctlp->d.last_offset = 0;
3340Sstevel@tonic-gate 	ctlp->d.limit = trap_trace_bufsize;
3350Sstevel@tonic-gate 	ctlp->d.paddr_base = va_to_pa(newbuf);
3360Sstevel@tonic-gate 	ASSERT(ctlp->d.paddr_base != (uint64_t)-1);
3371077Ssvemuri #endif /* TRAPTRACE */
3380Sstevel@tonic-gate 	/*
3391077Ssvemuri 	 * initialize hv traptrace buffer for this CPU
3400Sstevel@tonic-gate 	 */
3411077Ssvemuri 	mach_htraptrace_setup(cpuid);
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	/*
3440Sstevel@tonic-gate 	 * Obtain pointer to the appropriate cpu structure.
3450Sstevel@tonic-gate 	 */
3460Sstevel@tonic-gate 	if (cpu0.cpu_flags == 0) {
3470Sstevel@tonic-gate 		cp = &cpu0;
3480Sstevel@tonic-gate 	} else {
3490Sstevel@tonic-gate 		/*
3500Sstevel@tonic-gate 		 *  When dynamically allocating cpu structs,
3510Sstevel@tonic-gate 		 *  cpus is used as a pointer to a list of freed
3520Sstevel@tonic-gate 		 *  cpu structs.
3530Sstevel@tonic-gate 		 */
3540Sstevel@tonic-gate 		if (cpus) {
3550Sstevel@tonic-gate 			/* grab the first cpu struct on the free list */
3560Sstevel@tonic-gate 			cp = cpus;
3570Sstevel@tonic-gate 			if (cp->cpu_next_free)
3580Sstevel@tonic-gate 				cpus = cp->cpu_next_free;
3590Sstevel@tonic-gate 			else
3600Sstevel@tonic-gate 				cpus = NULL;
3610Sstevel@tonic-gate 		}
3620Sstevel@tonic-gate 	}
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate 	if (cp == NULL)
3650Sstevel@tonic-gate 		cp = vmem_xalloc(static_alloc_arena, CPU_ALLOC_SIZE,
3660Sstevel@tonic-gate 		    CPU_ALLOC_SIZE, 0, 0, NULL, NULL, VM_SLEEP);
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	bzero(cp, sizeof (*cp));
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 	cp->cpu_id = cpuid;
3710Sstevel@tonic-gate 	cp->cpu_self = cp;
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 	/*
3740Sstevel@tonic-gate 	 * Initialize ptl1_panic stack
3750Sstevel@tonic-gate 	 */
3760Sstevel@tonic-gate 	ptl1_init_cpu(cp);
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	/*
3790Sstevel@tonic-gate 	 * Initialize the dispatcher for this CPU.
3800Sstevel@tonic-gate 	 */
3810Sstevel@tonic-gate 	disp_cpu_init(cp);
3820Sstevel@tonic-gate 
383414Skchow 	cpu_vm_data_init(cp);
384414Skchow 
3850Sstevel@tonic-gate 	/*
3860Sstevel@tonic-gate 	 * Now, initialize per-CPU idle thread for this CPU.
3870Sstevel@tonic-gate 	 */
3880Sstevel@tonic-gate 	tp = thread_create(NULL, 0, idle, NULL, 0, &p0, TS_ONPROC, -1);
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 	cp->cpu_idle_thread = tp;
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate 	tp->t_preempt = 1;
3930Sstevel@tonic-gate 	tp->t_bound_cpu = cp;
3940Sstevel@tonic-gate 	tp->t_affinitycnt = 1;
3950Sstevel@tonic-gate 	tp->t_cpu = cp;
3960Sstevel@tonic-gate 	tp->t_disp_queue = cp->cpu_disp;
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	/*
3990Sstevel@tonic-gate 	 * Registering a thread in the callback table is usually
4000Sstevel@tonic-gate 	 * done in the initialization code of the thread. In this
4010Sstevel@tonic-gate 	 * case, we do it right after thread creation to avoid
4020Sstevel@tonic-gate 	 * blocking idle thread while registering itself. It also
4030Sstevel@tonic-gate 	 * avoids the possibility of reregistration in case a CPU
4040Sstevel@tonic-gate 	 * restarts its idle thread.
4050Sstevel@tonic-gate 	 */
4060Sstevel@tonic-gate 	CALLB_CPR_INIT_SAFE(tp, "idle");
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate 	init_cpu_info(cp);
4090Sstevel@tonic-gate 
4100Sstevel@tonic-gate 	/*
4110Sstevel@tonic-gate 	 * Initialize the interrupt threads for this CPU
4120Sstevel@tonic-gate 	 */
4130Sstevel@tonic-gate 	init_intr_pool(cp);
4141455Sandrei 	cpu_intr_alloc(cp, NINTR_THREADS);
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 	/*
417220Sesaxe 	 * Add CPU to list of available CPUs.
418220Sesaxe 	 * It'll be on the active list after it is started.
4190Sstevel@tonic-gate 	 */
4200Sstevel@tonic-gate 	cpu_add_unit(cp);
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate 	/*
4230Sstevel@tonic-gate 	 * Allocate and init cpu module private data structures,
4240Sstevel@tonic-gate 	 * including scrubber.
4250Sstevel@tonic-gate 	 */
4260Sstevel@tonic-gate 	cpu_init_private(cp);
4270Sstevel@tonic-gate 
428220Sesaxe 	/*
429220Sesaxe 	 * Associate this CPU with a physical processor
430220Sesaxe 	 */
431220Sesaxe 	chip_cpu_init(cp);
432220Sesaxe 
4330Sstevel@tonic-gate 	cpu_intrq_setup(cp);
4340Sstevel@tonic-gate }
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate /*
4370Sstevel@tonic-gate  * Routine to clean up a CPU after shutting it down.
4380Sstevel@tonic-gate  */
4390Sstevel@tonic-gate int
4400Sstevel@tonic-gate cleanup_cpu_common(int cpuid)
4410Sstevel@tonic-gate {
4420Sstevel@tonic-gate 	struct cpu *cp;
4430Sstevel@tonic-gate #ifdef TRAPTRACE
4440Sstevel@tonic-gate 	int i;
4450Sstevel@tonic-gate 	TRAP_TRACE_CTL	*ctlp;
4460Sstevel@tonic-gate 	caddr_t	newbuf;
4470Sstevel@tonic-gate #endif /* TRAPTRACE */
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
4500Sstevel@tonic-gate 	ASSERT(cpu[cpuid] != NULL);
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate 	cp = cpu[cpuid];
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 	/* Free cpu module private data structures, including scrubber. */
4550Sstevel@tonic-gate 	cpu_uninit_private(cp);
4560Sstevel@tonic-gate 
4571670Srab 	/* Free cpu ID string and brand string. */
4581670Srab 	kmem_free(cp->cpu_idstr, strlen(cp->cpu_idstr) + 1);
4591670Srab 	kmem_free(cp->cpu_brandstr, strlen(cp->cpu_brandstr) + 1);
4601670Srab 
461414Skchow 	cpu_vm_data_destroy(cp);
462414Skchow 
4630Sstevel@tonic-gate 	/*
4640Sstevel@tonic-gate 	 * Remove CPU from list of available CPUs.
4650Sstevel@tonic-gate 	 */
4660Sstevel@tonic-gate 	cpu_del_unit(cpuid);
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	/*
4690Sstevel@tonic-gate 	 * Clean up the interrupt pool.
4700Sstevel@tonic-gate 	 */
4710Sstevel@tonic-gate 	cleanup_intr_pool(cp);
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate 	/*
474*1991Sheppo 	 * Clean any machine specific interrupt states.
475*1991Sheppo 	 */
476*1991Sheppo 	cpu_intrq_cleanup(cp);
477*1991Sheppo 
478*1991Sheppo 	/*
4790Sstevel@tonic-gate 	 * At this point, the only threads bound to this CPU should be
4800Sstevel@tonic-gate 	 * special per-cpu threads: it's idle thread, it's pause thread,
4810Sstevel@tonic-gate 	 * and it's interrupt threads.  Clean these up.
4820Sstevel@tonic-gate 	 */
4830Sstevel@tonic-gate 	cpu_destroy_bound_threads(cp);
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 	/*
4860Sstevel@tonic-gate 	 * Free the interrupt stack.
4870Sstevel@tonic-gate 	 */
4880Sstevel@tonic-gate 	segkp_release(segkp, cp->cpu_intr_stack);
4890Sstevel@tonic-gate 
4901077Ssvemuri 	/*
4911077Ssvemuri 	 * Free hv traptrace buffer for this CPU.
4921077Ssvemuri 	 */
4931077Ssvemuri 	mach_htraptrace_cleanup(cpuid);
4940Sstevel@tonic-gate #ifdef TRAPTRACE
4950Sstevel@tonic-gate 	/*
4960Sstevel@tonic-gate 	 * Free the traptrace buffer for this CPU.
4970Sstevel@tonic-gate 	 */
4980Sstevel@tonic-gate 	ctlp = &trap_trace_ctl[cpuid];
4990Sstevel@tonic-gate 	newbuf = ctlp->d.vaddr_base;
5001077Ssvemuri 	i = (newbuf - ttrace_buf) / (TRAP_TSIZE);
5011077Ssvemuri 	if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) &&
5020Sstevel@tonic-gate 	    ((i >= 0) && (i < (max_ncpus-1)))) {
5030Sstevel@tonic-gate 		/*
5040Sstevel@tonic-gate 		 * This CPU got it's trap trace buffer from the
5050Sstevel@tonic-gate 		 * boot-alloc'd bunch of them.
5060Sstevel@tonic-gate 		 */
5070Sstevel@tonic-gate 		trap_trace_inuse[i] = 0;
5081077Ssvemuri 		bzero(newbuf, (TRAP_TSIZE));
5090Sstevel@tonic-gate 	} else if (newbuf == trap_tr0) {
5100Sstevel@tonic-gate 		trap_tr0_inuse = 0;
5111077Ssvemuri 		bzero(trap_tr0, (TRAP_TSIZE));
5120Sstevel@tonic-gate 	} else {
5130Sstevel@tonic-gate 		cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d",
5140Sstevel@tonic-gate 		    cpuid);
5150Sstevel@tonic-gate 	}
5160Sstevel@tonic-gate 	bzero(ctlp, sizeof (*ctlp));
5170Sstevel@tonic-gate #endif /* TRAPTRACE */
5180Sstevel@tonic-gate 
5190Sstevel@tonic-gate 	/*
5200Sstevel@tonic-gate 	 * There is a race condition with mutex_vector_enter() which
5210Sstevel@tonic-gate 	 * caches a cpu pointer. The race is detected by checking cpu_next.
5220Sstevel@tonic-gate 	 */
5230Sstevel@tonic-gate 	disp_cpu_fini(cp);
5240Sstevel@tonic-gate 	cpu_pa[cpuid] = 0;
5250Sstevel@tonic-gate 	bzero(cp, sizeof (*cp));
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate 	/*
5280Sstevel@tonic-gate 	 * Place the freed cpu structure on the list of freed cpus.
5290Sstevel@tonic-gate 	 */
5300Sstevel@tonic-gate 	if (cp != &cpu0) {
5310Sstevel@tonic-gate 		if (cpus) {
5320Sstevel@tonic-gate 			cp->cpu_next_free = cpus;
5330Sstevel@tonic-gate 			cpus = cp;
5340Sstevel@tonic-gate 		}
5350Sstevel@tonic-gate 		else
5360Sstevel@tonic-gate 			cpus = cp;
5370Sstevel@tonic-gate 	}
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate 	return (0);
5400Sstevel@tonic-gate }
5410Sstevel@tonic-gate 
5420Sstevel@tonic-gate /*
5430Sstevel@tonic-gate  * This routine is used to start a previously powered off processor.
5440Sstevel@tonic-gate  * Note that restarted cpus are initialized into the offline state.
5450Sstevel@tonic-gate  */
5460Sstevel@tonic-gate void
5470Sstevel@tonic-gate restart_other_cpu(int cpuid)
5480Sstevel@tonic-gate {
5490Sstevel@tonic-gate 	struct cpu *cp;
5500Sstevel@tonic-gate 	kthread_id_t tp;
5510Sstevel@tonic-gate 	caddr_t	sp;
5520Sstevel@tonic-gate 	extern void idle();
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cpu_lock));
5550Sstevel@tonic-gate 	ASSERT(cpuid < NCPU && cpu[cpuid] != NULL);
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 	/*
5580Sstevel@tonic-gate 	 * Obtain pointer to the appropriate cpu structure.
5590Sstevel@tonic-gate 	 */
5600Sstevel@tonic-gate 	cp = cpu[cpuid];
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate 	common_startup_init(cp, cpuid);
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 	/*
5650Sstevel@tonic-gate 	 * idle thread t_lock is held when the idle thread is suspended.
5660Sstevel@tonic-gate 	 * Manually unlock the t_lock of idle loop so that we can resume
5670Sstevel@tonic-gate 	 * the suspended idle thread.
5680Sstevel@tonic-gate 	 * Also adjust the PC of idle thread for re-retry.
5690Sstevel@tonic-gate 	 */
5700Sstevel@tonic-gate 	cp->cpu_intr_actv = 0;	/* clear the value from previous life */
5710Sstevel@tonic-gate 	cp->cpu_m.mutex_ready = 0; /* we are not ready yet */
5720Sstevel@tonic-gate 	lock_clear(&cp->cpu_idle_thread->t_lock);
5730Sstevel@tonic-gate 	tp = cp->cpu_idle_thread;
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate 	sp = tp->t_stk;
5760Sstevel@tonic-gate 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
5770Sstevel@tonic-gate 	tp->t_pc = (uintptr_t)idle - 8;
5780Sstevel@tonic-gate 
5790Sstevel@tonic-gate 	/*
5800Sstevel@tonic-gate 	 * restart the cpu now
5810Sstevel@tonic-gate 	 */
5820Sstevel@tonic-gate 	promsafe_pause_cpus();
5830Sstevel@tonic-gate 	start_cpu(cpuid, warm_flag_set);
5840Sstevel@tonic-gate 	start_cpus();
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate 	/* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */
5870Sstevel@tonic-gate 	cmn_err(CE_CONT, "!cpu%d initialization complete - restarted\n",
5880Sstevel@tonic-gate 	    cpuid);
5890Sstevel@tonic-gate }
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate /*
5920Sstevel@tonic-gate  * Startup function executed on 'other' CPUs.  This is the first
5930Sstevel@tonic-gate  * C function after cpu_start sets up the cpu registers.
5940Sstevel@tonic-gate  */
5950Sstevel@tonic-gate static void
5960Sstevel@tonic-gate slave_startup(void)
5970Sstevel@tonic-gate {
5980Sstevel@tonic-gate 	struct cpu	*cp = CPU;
5990Sstevel@tonic-gate 	ushort_t	original_flags = cp->cpu_flags;
6000Sstevel@tonic-gate 
6011077Ssvemuri 	mach_htraptrace_configure(cp->cpu_id);
6020Sstevel@tonic-gate 	cpu_intrq_register(CPU);
6030Sstevel@tonic-gate 	cp->cpu_m.mutex_ready = 1;
6040Sstevel@tonic-gate 	cp->cpu_m.poke_cpu_outstanding = B_FALSE;
6050Sstevel@tonic-gate 
6060Sstevel@tonic-gate 	/* acknowledge that we are done with initialization */
6070Sstevel@tonic-gate 	CPUSET_ADD(proxy_ready_set, cp->cpu_id);
6080Sstevel@tonic-gate 
6090Sstevel@tonic-gate 	/* synchronize STICK */
6100Sstevel@tonic-gate 	sticksync_slave();
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate 	if (boothowto & RB_DEBUG)
6130Sstevel@tonic-gate 		kdi_dvec_cpu_init(cp);
6140Sstevel@tonic-gate 
6150Sstevel@tonic-gate 	/*
6160Sstevel@tonic-gate 	 * the slave will wait here forever -- assuming that the master
6170Sstevel@tonic-gate 	 * will get back to us.  if it doesn't we've got bigger problems
6180Sstevel@tonic-gate 	 * than a master not replying to this slave.
6190Sstevel@tonic-gate 	 * the small delay improves the slave's responsiveness to the
6200Sstevel@tonic-gate 	 * master's ack and decreases the time window between master and
6210Sstevel@tonic-gate 	 * slave operations.
6220Sstevel@tonic-gate 	 */
6230Sstevel@tonic-gate 	while (!CPU_IN_SET(cpu_ready_set, cp->cpu_id))
6240Sstevel@tonic-gate 		DELAY(1);
6250Sstevel@tonic-gate 
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 	/*
6490Sstevel@tonic-gate 	 * Notify the CMT subsystem that the slave has started
6500Sstevel@tonic-gate 	 */
6510Sstevel@tonic-gate 	chip_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 /*
6620Sstevel@tonic-gate  * 4163850 changes the allocation method for cpu structs. cpu structs
6630Sstevel@tonic-gate  * are dynamically allocated. This routine now determines if additional
6640Sstevel@tonic-gate  * per-cpu intr_req entries need to be allocated.
6650Sstevel@tonic-gate  */
6660Sstevel@tonic-gate int
6670Sstevel@tonic-gate ndata_alloc_cpus(struct memlist *ndata)
6680Sstevel@tonic-gate {
6690Sstevel@tonic-gate 	size_t real_sz;
6700Sstevel@tonic-gate 	extern int niobus;
6710Sstevel@tonic-gate 
6720Sstevel@tonic-gate 	if (niobus > 1) {
6730Sstevel@tonic-gate 
6740Sstevel@tonic-gate 		/*
6750Sstevel@tonic-gate 		 * Allocate additional intr_req entries if we have more than
6760Sstevel@tonic-gate 		 * one io bus.  The memory to allocate is calculated from four
6770Sstevel@tonic-gate 		 * variables: niobus, max_ncpus, intr_add_div, and intr_add_max.
6780Sstevel@tonic-gate 		 * Allocate multiple of INTR_POOL_SIZE bytes (512).  Each cpu
6790Sstevel@tonic-gate 		 * already reserves 512 bytes in its machcpu structure, so the
6800Sstevel@tonic-gate 		 * worst case is (512 * (niobus - 1) * max_ncpus) add'l bytes.
6810Sstevel@tonic-gate 		 *
6820Sstevel@tonic-gate 		 * While niobus and max_ncpus reflect the h/w, the following
6830Sstevel@tonic-gate 		 * may be tuned (before boot):
6840Sstevel@tonic-gate 		 *
6850Sstevel@tonic-gate 		 *	intr_add_div -	divisor for scaling the number of
6860Sstevel@tonic-gate 		 *			additional intr_req entries. use '1'
6870Sstevel@tonic-gate 		 *			for worst case memory, '2' for half,
6880Sstevel@tonic-gate 		 *			etc.
6890Sstevel@tonic-gate 		 *
6900Sstevel@tonic-gate 		 *   intr_add_max - upper limit on bytes of memory to reserve
6910Sstevel@tonic-gate 		 */
6920Sstevel@tonic-gate 
6930Sstevel@tonic-gate 		real_sz = INTR_POOL_SIZE * (niobus - 1) * max_ncpus;
6940Sstevel@tonic-gate 
6950Sstevel@tonic-gate 		/* tune memory usage by applying divisor and maximum */
6960Sstevel@tonic-gate 
6970Sstevel@tonic-gate 		if (intr_add_max == 0)
6980Sstevel@tonic-gate 			intr_add_max = max_ncpus * INTR_POOL_SIZE;
6990Sstevel@tonic-gate 		real_sz = MIN(intr_add_max, real_sz / MAX(intr_add_div, 1));
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate 		/* round down to multiple of (max_ncpus * INTR_POOL_SIZE) */
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate 		intr_add_pools = real_sz / (max_ncpus * INTR_POOL_SIZE);
7040Sstevel@tonic-gate 		real_sz = intr_add_pools * (max_ncpus * INTR_POOL_SIZE);
7050Sstevel@tonic-gate 
7060Sstevel@tonic-gate 		/* actually reserve the space */
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate 		intr_add_head = ndata_alloc(ndata, real_sz, ecache_alignsize);
7090Sstevel@tonic-gate 		if (intr_add_head == NULL)
7100Sstevel@tonic-gate 			return (-1);
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate 		PRM_DEBUG(intr_add_head);
7130Sstevel@tonic-gate #ifdef	DEBUG
7140Sstevel@tonic-gate 		intr_add_tail = (struct intr_req *)
7150Sstevel@tonic-gate 		    ((uintptr_t)intr_add_head + real_sz);
7160Sstevel@tonic-gate #endif	/* DEBUG */
7170Sstevel@tonic-gate 	}
7180Sstevel@tonic-gate 
7190Sstevel@tonic-gate 	return (0);
7200Sstevel@tonic-gate }
7210Sstevel@tonic-gate 
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate extern struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
7240Sstevel@tonic-gate 
7250Sstevel@tonic-gate extern void setup_cpu_common(int);
7260Sstevel@tonic-gate extern void common_startup_init(cpu_t *, int);
7270Sstevel@tonic-gate extern void start_cpu(int, void(*func)(int));
7280Sstevel@tonic-gate extern void cold_flag_set(int cpuid);
7290Sstevel@tonic-gate 
7300Sstevel@tonic-gate /*
7310Sstevel@tonic-gate  * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that
7320Sstevel@tonic-gate  * can be used during debugging to control which processors are brought
7330Sstevel@tonic-gate  * online at boot time.  The variable represents a bitmap of the id's
7340Sstevel@tonic-gate  * of the processors that will be brought online.  The initialization
7350Sstevel@tonic-gate  * of this variable depends on the type of cpuset_t, which varies
7360Sstevel@tonic-gate  * depending on the number of processors supported (see cpuvar.h).
7370Sstevel@tonic-gate  */
7380Sstevel@tonic-gate cpuset_t cpu_bringup_set;
7390Sstevel@tonic-gate 
7400Sstevel@tonic-gate 
7410Sstevel@tonic-gate /*
7420Sstevel@tonic-gate  * Generic start-all cpus entry.  Typically used during cold initialization.
7430Sstevel@tonic-gate  * Note that cold start cpus are initialized into the online state.
7440Sstevel@tonic-gate  */
7450Sstevel@tonic-gate /*ARGSUSED*/
7460Sstevel@tonic-gate void
7470Sstevel@tonic-gate start_other_cpus(int flag)
7480Sstevel@tonic-gate {
7490Sstevel@tonic-gate 	int cpuid;
7500Sstevel@tonic-gate 	extern void idlestop_init(void);
7510Sstevel@tonic-gate 	int bootcpu;
7520Sstevel@tonic-gate 
7530Sstevel@tonic-gate 	/*
7540Sstevel@tonic-gate 	 * Check if cpu_bringup_set has been explicitly set before
7550Sstevel@tonic-gate 	 * initializing it.
7560Sstevel@tonic-gate 	 */
7570Sstevel@tonic-gate 	if (CPUSET_ISNULL(cpu_bringup_set)) {
7580Sstevel@tonic-gate #ifdef MPSAS
7590Sstevel@tonic-gate 		/* just CPU 0 */
7600Sstevel@tonic-gate 		CPUSET_ADD(cpu_bringup_set, 0);
7610Sstevel@tonic-gate #else
7620Sstevel@tonic-gate 		CPUSET_ALL(cpu_bringup_set);
7630Sstevel@tonic-gate #endif
7640Sstevel@tonic-gate 	}
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate 	if (&cpu_feature_init)
7670Sstevel@tonic-gate 		cpu_feature_init();
7680Sstevel@tonic-gate 
7690Sstevel@tonic-gate 	/*
7700Sstevel@tonic-gate 	 * Initialize CPC.
7710Sstevel@tonic-gate 	 */
7720Sstevel@tonic-gate 	kcpc_hw_init();
7730Sstevel@tonic-gate 
7740Sstevel@tonic-gate 	mutex_enter(&cpu_lock);
7750Sstevel@tonic-gate 
7760Sstevel@tonic-gate 	/*
7770Sstevel@tonic-gate 	 * Initialize our own cpu_info.
7780Sstevel@tonic-gate 	 */
7790Sstevel@tonic-gate 	init_cpu_info(CPU);
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate 	/*
7820Sstevel@tonic-gate 	 * Initialize CPU 0 cpu module private data area, including scrubber.
7830Sstevel@tonic-gate 	 */
7840Sstevel@tonic-gate 	cpu_init_private(CPU);
7850Sstevel@tonic-gate 
7860Sstevel@tonic-gate 	/*
7870Sstevel@tonic-gate 	 * perform such initialization as is needed
7880Sstevel@tonic-gate 	 * to be able to take CPUs on- and off-line.
7890Sstevel@tonic-gate 	 */
7900Sstevel@tonic-gate 	cpu_pause_init();
7910Sstevel@tonic-gate 	xc_init();		/* initialize processor crosscalls */
7920Sstevel@tonic-gate 	idlestop_init();
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate 	if (!use_mp) {
7950Sstevel@tonic-gate 		mutex_exit(&cpu_lock);
7960Sstevel@tonic-gate 		cmn_err(CE_CONT, "?***** Not in MP mode\n");
7970Sstevel@tonic-gate 		return;
7980Sstevel@tonic-gate 	}
7990Sstevel@tonic-gate 	/*
8000Sstevel@tonic-gate 	 * should we be initializing this cpu?
8010Sstevel@tonic-gate 	 */
8020Sstevel@tonic-gate 	bootcpu = getprocessorid();
8030Sstevel@tonic-gate 
8040Sstevel@tonic-gate 	/*
8050Sstevel@tonic-gate 	 * launch all the slave cpus now
8060Sstevel@tonic-gate 	 */
8070Sstevel@tonic-gate 	for (cpuid = 0; cpuid < NCPU; cpuid++) {
808789Sahrens 		pnode_t nodeid = cpunodes[cpuid].nodeid;
8090Sstevel@tonic-gate 
810789Sahrens 		if (nodeid == (pnode_t)0)
8110Sstevel@tonic-gate 			continue;
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate 		if (cpuid == bootcpu) {
8140Sstevel@tonic-gate 			if (!CPU_IN_SET(cpu_bringup_set, cpuid)) {
8150Sstevel@tonic-gate 				cmn_err(CE_WARN, "boot cpu not a member "
8160Sstevel@tonic-gate 				    "of cpu_bringup_set, adding it");
8170Sstevel@tonic-gate 				CPUSET_ADD(cpu_bringup_set, cpuid);
8180Sstevel@tonic-gate 			}
8190Sstevel@tonic-gate 			continue;
8200Sstevel@tonic-gate 		}
8210Sstevel@tonic-gate 		if (!CPU_IN_SET(cpu_bringup_set, cpuid))
8220Sstevel@tonic-gate 			continue;
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate 		ASSERT(cpu[cpuid] == NULL);
8250Sstevel@tonic-gate 
8260Sstevel@tonic-gate 		setup_cpu_common(cpuid);
8270Sstevel@tonic-gate 
8280Sstevel@tonic-gate 		common_startup_init(cpu[cpuid], cpuid);
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate 		start_cpu(cpuid, cold_flag_set);
8310Sstevel@tonic-gate 		/*
8320Sstevel@tonic-gate 		 * Because slave_startup() gets fired off after init()
8330Sstevel@tonic-gate 		 * starts, we can't use the '?' trick to do 'boot -v'
8340Sstevel@tonic-gate 		 * printing - so we always direct the 'cpu .. online'
8350Sstevel@tonic-gate 		 * messages to the log.
8360Sstevel@tonic-gate 		 */
8370Sstevel@tonic-gate 		cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
8380Sstevel@tonic-gate 		    cpuid);
8390Sstevel@tonic-gate 
8400Sstevel@tonic-gate 		/*
8410Sstevel@tonic-gate 		 * XXX: register_cpu_setup() callbacks should be called here
8420Sstevel@tonic-gate 		 * with a new setup code, CPU_BOOT (or something).
8430Sstevel@tonic-gate 		 */
8440Sstevel@tonic-gate 		if (dtrace_cpu_init != NULL)
8450Sstevel@tonic-gate 			(*dtrace_cpu_init)(cpuid);
8460Sstevel@tonic-gate 	}
8470Sstevel@tonic-gate 
8480Sstevel@tonic-gate 	/*
8490Sstevel@tonic-gate 	 * since all the cpus are online now, redistribute interrupts to them.
8500Sstevel@tonic-gate 	 */
8510Sstevel@tonic-gate 	intr_redist_all_cpus();
8520Sstevel@tonic-gate 
8530Sstevel@tonic-gate 	mutex_exit(&cpu_lock);
8540Sstevel@tonic-gate 
8550Sstevel@tonic-gate 	/*
8560Sstevel@tonic-gate 	 * Start the Ecache scrubber.  Must be done after all calls to
8570Sstevel@tonic-gate 	 * cpu_init_private for every cpu (including CPU 0).
8580Sstevel@tonic-gate 	 */
8590Sstevel@tonic-gate 	cpu_init_cache_scrub();
8600Sstevel@tonic-gate 
8610Sstevel@tonic-gate 	if (&cpu_mp_init)
8620Sstevel@tonic-gate 		cpu_mp_init();
8630Sstevel@tonic-gate }
864