xref: /illumos-gate/usr/src/uts/sun4/os/mp_startup.c (revision f998c95e3b7029fe5f7542e115f7474ddb8024d7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/sysmacros.h>
30 #include <sys/prom_plat.h>
31 #include <sys/prom_debug.h>
32 #include <vm/hat_sfmmu.h>
33 #include <vm/seg_kp.h>
34 #include <vm/seg_kmem.h>
35 #include <sys/machsystm.h>
36 #include <sys/callb.h>
37 #include <sys/cpu_module.h>
38 #include <sys/pg.h>
39 #include <sys/cmt.h>
40 #include <sys/dtrace.h>
41 #include <sys/reboot.h>
42 #include <sys/kdi.h>
43 #include <sys/traptrace.h>
44 #ifdef TRAPTRACE
45 #include <sys/bootconf.h>
46 #endif /* TRAPTRACE */
47 #include <sys/cpu_sgnblk_defs.h>
48 
49 extern int cpu_intrq_setup(struct cpu *);
50 extern void cpu_intrq_cleanup(struct cpu *);
51 extern void cpu_intrq_register(struct cpu *);
52 
53 struct cpu	*cpus;	/* pointer to other cpus; dynamically allocate */
54 struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
55 uint64_t	cpu_pa[NCPU];	/* pointers to all CPUs in PA */
56 cpu_core_t	cpu_core[NCPU];	/* cpu_core structures */
57 
58 #ifdef TRAPTRACE
59 caddr_t	ttrace_buf;	/* kmem64 traptrace for all cpus except 0 */
60 #endif /* TRAPTRACE */
61 
62 /* bit mask of cpus ready for x-calls, protected by cpu_lock */
63 cpuset_t cpu_ready_set;
64 
65 /* bit mask used to communicate with cpus during bringup */
66 static cpuset_t proxy_ready_set;
67 
68 static void	slave_startup(void);
69 
70 /*
71  * Defined in $KARCH/os/mach_mp_startup.c
72  */
73 #pragma weak init_cpu_info
74 
75 /*
76  * Amount of time (in milliseconds) we should wait before giving up on CPU
77  * initialization and assuming that the CPU we're trying to wake up is dead
78  * or out of control.
79  */
80 #define	CPU_WAKEUP_GRACE_MSEC 1000
81 
82 #ifdef	TRAPTRACE
83 /*
84  * This function sets traptrace buffers for all cpus
85  * other than boot cpu.
86  */
87 size_t
88 calc_traptrace_sz(void)
89 {
90 	return (TRAP_TSIZE * (max_ncpus - 1));
91 }
92 #endif	/* TRAPTRACE */
93 
94 
95 /*
96  * common slave cpu initialization code
97  */
98 void
99 common_startup_init(cpu_t *cp, int cpuid)
100 {
101 	kthread_id_t tp;
102 	sfmmu_t *sfmmup;
103 	caddr_t	sp;
104 
105 	/*
106 	 * Allocate and initialize the startup thread for this CPU.
107 	 */
108 	tp = thread_create(NULL, 0, slave_startup, NULL, 0, &p0,
109 	    TS_STOPPED, maxclsyspri);
110 
111 	/*
112 	 * Set state to TS_ONPROC since this thread will start running
113 	 * as soon as the CPU comes online.
114 	 *
115 	 * All the other fields of the thread structure are setup by
116 	 * thread_create().
117 	 */
118 	THREAD_ONPROC(tp, cp);
119 	tp->t_preempt = 1;
120 	tp->t_bound_cpu = cp;
121 	tp->t_affinitycnt = 1;
122 	tp->t_cpu = cp;
123 	tp->t_disp_queue = cp->cpu_disp;
124 
125 	sfmmup = astosfmmu(&kas);
126 	CPUSET_ADD(sfmmup->sfmmu_cpusran, cpuid);
127 
128 	/*
129 	 * Setup thread to start in slave_startup.
130 	 */
131 	sp = tp->t_stk;
132 	tp->t_pc = (uintptr_t)slave_startup - 8;
133 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
134 
135 	cp->cpu_id = cpuid;
136 	cp->cpu_self = cp;
137 	cp->cpu_thread = tp;
138 	cp->cpu_lwp = NULL;
139 	cp->cpu_dispthread = tp;
140 	cp->cpu_dispatch_pri = DISP_PRIO(tp);
141 	cp->cpu_startup_thread = tp;
142 }
143 
144 /*
145  * parametric flag setting functions.  these routines set the cpu
146  * state just prior to releasing the slave cpu.
147  */
148 void
149 cold_flag_set(int cpuid)
150 {
151 	cpu_t *cp;
152 
153 	ASSERT(MUTEX_HELD(&cpu_lock));
154 
155 	cp = cpu[cpuid];
156 	cp->cpu_flags |= CPU_RUNNING | CPU_ENABLE | CPU_EXISTS;
157 	cpu_add_active(cp);
158 	/*
159 	 * Add CPU_READY after the cpu_add_active() call
160 	 * to avoid pausing cp.
161 	 */
162 	cp->cpu_flags |= CPU_READY;		/* ready */
163 	cpu_set_state(cp);
164 }
165 
166 static void
167 warm_flag_set(int cpuid)
168 {
169 	cpu_t *cp;
170 
171 	ASSERT(MUTEX_HELD(&cpu_lock));
172 
173 	/*
174 	 * warm start activates cpus into the OFFLINE state
175 	 */
176 	cp = cpu[cpuid];
177 	cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_EXISTS
178 	    | CPU_OFFLINE | CPU_QUIESCED;
179 	cpu_set_state(cp);
180 }
181 
182 /*
183  * Internal cpu startup sequencer
184  * The sequence is as follows:
185  *
186  * MASTER	SLAVE
187  * -------	----------
188  * assume the kernel data is initialized
189  * clear the proxy bit
190  * start the slave cpu
191  * wait for the slave cpu to set the proxy
192  *
193  *		the slave runs slave_startup and then sets the proxy
194  *		the slave waits for the master to add slave to the ready set
195  *
196  * the master finishes the initialization and
197  * adds the slave to the ready set
198  *
199  *		the slave exits the startup thread and is running
200  */
201 void
202 start_cpu(int cpuid, void(*flag_func)(int))
203 {
204 	extern void cpu_startup(int);
205 	int timout;
206 
207 	ASSERT(MUTEX_HELD(&cpu_lock));
208 
209 	/*
210 	 * Before we begin the dance, tell DTrace that we're about to start
211 	 * a CPU.
212 	 */
213 	if (dtrace_cpustart_init != NULL)
214 		(*dtrace_cpustart_init)();
215 
216 	/* start the slave cpu */
217 	CPUSET_DEL(proxy_ready_set, cpuid);
218 	if (prom_test("SUNW,start-cpu-by-cpuid") == 0) {
219 		(void) prom_startcpu_bycpuid(cpuid, (caddr_t)&cpu_startup,
220 		    cpuid);
221 	} else {
222 		/* "by-cpuid" interface didn't exist.  Do it the old way */
223 		pnode_t nodeid = cpunodes[cpuid].nodeid;
224 
225 		ASSERT(nodeid != (pnode_t)0);
226 		(void) prom_startcpu(nodeid, (caddr_t)&cpu_startup, cpuid);
227 	}
228 
229 	/* wait for the slave cpu to check in. */
230 	for (timout = CPU_WAKEUP_GRACE_MSEC; timout; timout--) {
231 		if (CPU_IN_SET(proxy_ready_set, cpuid))
232 			break;
233 		DELAY(1000);
234 	}
235 	if (timout == 0) {
236 		panic("cpu%d failed to start (2)", cpuid);
237 	}
238 
239 	/*
240 	 * The slave has started; we can tell DTrace that it's safe again.
241 	 */
242 	if (dtrace_cpustart_fini != NULL)
243 		(*dtrace_cpustart_fini)();
244 
245 	/* run the master side of stick synchronization for the slave cpu */
246 	sticksync_master();
247 
248 	/*
249 	 * deal with the cpu flags in a phase-specific manner
250 	 * for various reasons, this needs to run after the slave
251 	 * is checked in but before the slave is released.
252 	 */
253 	(*flag_func)(cpuid);
254 
255 	/* release the slave */
256 	CPUSET_ADD(cpu_ready_set, cpuid);
257 }
258 
259 #ifdef TRAPTRACE
260 int trap_tr0_inuse = 1;	/* it is always used on the boot cpu */
261 int trap_trace_inuse[NCPU];
262 #endif /* TRAPTRACE */
263 
264 #define	cpu_next_free	cpu_prev
265 
266 /*
267  * Routine to set up a CPU to prepare for starting it up.
268  */
269 int
270 setup_cpu_common(int cpuid)
271 {
272 	struct cpu *cp = NULL;
273 	kthread_id_t tp;
274 #ifdef TRAPTRACE
275 	int tt_index;
276 	TRAP_TRACE_CTL	*ctlp;
277 	caddr_t	newbuf;
278 #endif /* TRAPTRACE */
279 
280 	extern void idle();
281 	int	rval;
282 
283 	ASSERT(MUTEX_HELD(&cpu_lock));
284 	ASSERT(cpu[cpuid] == NULL);
285 
286 	ASSERT(ncpus <= max_ncpus);
287 
288 #ifdef TRAPTRACE
289 	/*
290 	 * allocate a traptrace buffer for this CPU.
291 	 */
292 	ctlp = &trap_trace_ctl[cpuid];
293 	if (!trap_tr0_inuse) {
294 		trap_tr0_inuse = 1;
295 		newbuf = trap_tr0;
296 		tt_index = -1;
297 	} else {
298 		for (tt_index = 0; tt_index < (max_ncpus-1); tt_index++)
299 			if (!trap_trace_inuse[tt_index])
300 				break;
301 		ASSERT(tt_index < max_ncpus - 1);
302 		trap_trace_inuse[tt_index] = 1;
303 		newbuf = (caddr_t)(ttrace_buf + (tt_index * TRAP_TSIZE));
304 	}
305 	ctlp->d.vaddr_base = newbuf;
306 	ctlp->d.offset = ctlp->d.last_offset = 0;
307 	ctlp->d.limit = trap_trace_bufsize;
308 	ctlp->d.paddr_base = va_to_pa(newbuf);
309 	ASSERT(ctlp->d.paddr_base != (uint64_t)-1);
310 #endif /* TRAPTRACE */
311 	/*
312 	 * initialize hv traptrace buffer for this CPU
313 	 */
314 	mach_htraptrace_setup(cpuid);
315 
316 	/*
317 	 * Obtain pointer to the appropriate cpu structure.
318 	 */
319 	if (cpu0.cpu_flags == 0) {
320 		cp = &cpu0;
321 	} else {
322 		/*
323 		 *  When dynamically allocating cpu structs,
324 		 *  cpus is used as a pointer to a list of freed
325 		 *  cpu structs.
326 		 */
327 		if (cpus) {
328 			/* grab the first cpu struct on the free list */
329 			cp = cpus;
330 			if (cp->cpu_next_free)
331 				cpus = cp->cpu_next_free;
332 			else
333 				cpus = NULL;
334 		}
335 	}
336 
337 	if (cp == NULL)
338 		cp = vmem_xalloc(static_alloc_arena, CPU_ALLOC_SIZE,
339 		    CPU_ALLOC_SIZE, 0, 0, NULL, NULL, VM_SLEEP);
340 
341 	bzero(cp, sizeof (*cp));
342 
343 	cp->cpu_id = cpuid;
344 	cp->cpu_self = cp;
345 
346 	/*
347 	 * Initialize ptl1_panic stack
348 	 */
349 	ptl1_init_cpu(cp);
350 
351 	/*
352 	 * Initialize the dispatcher for this CPU.
353 	 */
354 	disp_cpu_init(cp);
355 
356 	cpu_vm_data_init(cp);
357 
358 	/*
359 	 * Now, initialize per-CPU idle thread for this CPU.
360 	 */
361 	tp = thread_create(NULL, 0, idle, NULL, 0, &p0, TS_ONPROC, -1);
362 
363 	cp->cpu_idle_thread = tp;
364 
365 	tp->t_preempt = 1;
366 	tp->t_bound_cpu = cp;
367 	tp->t_affinitycnt = 1;
368 	tp->t_cpu = cp;
369 	tp->t_disp_queue = cp->cpu_disp;
370 
371 	/*
372 	 * Registering a thread in the callback table is usually
373 	 * done in the initialization code of the thread. In this
374 	 * case, we do it right after thread creation to avoid
375 	 * blocking idle thread while registering itself. It also
376 	 * avoids the possibility of reregistration in case a CPU
377 	 * restarts its idle thread.
378 	 */
379 	CALLB_CPR_INIT_SAFE(tp, "idle");
380 
381 	init_cpu_info(cp);
382 
383 	/*
384 	 * Initialize the interrupt threads for this CPU
385 	 */
386 	cpu_intr_alloc(cp, NINTR_THREADS);
387 
388 	/*
389 	 * Add CPU to list of available CPUs.
390 	 * It'll be on the active list after it is started.
391 	 */
392 	cpu_add_unit(cp);
393 
394 	/*
395 	 * Allocate and init cpu module private data structures,
396 	 * including scrubber.
397 	 */
398 	cpu_init_private(cp);
399 
400 	/*
401 	 * Initialize the CPUs physical ID cache, and processor groups
402 	 */
403 	pghw_physid_create(cp);
404 	pg_cpu_init(cp);
405 
406 	if ((rval = cpu_intrq_setup(cp)) != 0) {
407 		return (rval);
408 	}
409 
410 	/*
411 	 * Initialize MMU context domain information.
412 	 */
413 	sfmmu_cpu_init(cp);
414 
415 	return (0);
416 }
417 
418 /*
419  * Routine to clean up a CPU after shutting it down.
420  */
421 int
422 cleanup_cpu_common(int cpuid)
423 {
424 	struct cpu *cp;
425 #ifdef TRAPTRACE
426 	int i;
427 	TRAP_TRACE_CTL	*ctlp;
428 	caddr_t	newbuf;
429 #endif /* TRAPTRACE */
430 
431 	ASSERT(MUTEX_HELD(&cpu_lock));
432 	ASSERT(cpu[cpuid] != NULL);
433 
434 	cp = cpu[cpuid];
435 
436 	/* Free cpu module private data structures, including scrubber. */
437 	cpu_uninit_private(cp);
438 
439 	/* Free cpu ID string and brand string. */
440 	if (cp->cpu_idstr)
441 		kmem_free(cp->cpu_idstr, strlen(cp->cpu_idstr) + 1);
442 	if (cp->cpu_brandstr)
443 		kmem_free(cp->cpu_brandstr, strlen(cp->cpu_brandstr) + 1);
444 
445 	cpu_vm_data_destroy(cp);
446 
447 	/*
448 	 * Remove CPU from list of available CPUs.
449 	 */
450 	cpu_del_unit(cpuid);
451 
452 	/*
453 	 * Clean any machine specific interrupt states.
454 	 */
455 	cpu_intrq_cleanup(cp);
456 
457 	/*
458 	 * At this point, the only threads bound to this CPU should be
459 	 * special per-cpu threads: it's idle thread, it's pause thread,
460 	 * and it's interrupt threads.  Clean these up.
461 	 */
462 	cpu_destroy_bound_threads(cp);
463 
464 	/*
465 	 * Free the interrupt stack.
466 	 */
467 	segkp_release(segkp, cp->cpu_intr_stack);
468 
469 	/*
470 	 * Free hv traptrace buffer for this CPU.
471 	 */
472 	mach_htraptrace_cleanup(cpuid);
473 #ifdef TRAPTRACE
474 	/*
475 	 * Free the traptrace buffer for this CPU.
476 	 */
477 	ctlp = &trap_trace_ctl[cpuid];
478 	newbuf = ctlp->d.vaddr_base;
479 	i = (newbuf - ttrace_buf) / (TRAP_TSIZE);
480 	if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) &&
481 	    ((i >= 0) && (i < (max_ncpus-1)))) {
482 		/*
483 		 * This CPU got it's trap trace buffer from the
484 		 * boot-alloc'd bunch of them.
485 		 */
486 		trap_trace_inuse[i] = 0;
487 		bzero(newbuf, (TRAP_TSIZE));
488 	} else if (newbuf == trap_tr0) {
489 		trap_tr0_inuse = 0;
490 		bzero(trap_tr0, (TRAP_TSIZE));
491 	} else {
492 		cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d",
493 		    cpuid);
494 	}
495 	bzero(ctlp, sizeof (*ctlp));
496 #endif /* TRAPTRACE */
497 
498 	/*
499 	 * There is a race condition with mutex_vector_enter() which
500 	 * caches a cpu pointer. The race is detected by checking cpu_next.
501 	 */
502 	disp_cpu_fini(cp);
503 	cpu_pa[cpuid] = 0;
504 	if (CPU_MMU_CTXP(cp))
505 		sfmmu_cpu_cleanup(cp);
506 	bzero(cp, sizeof (*cp));
507 
508 	/*
509 	 * Place the freed cpu structure on the list of freed cpus.
510 	 */
511 	if (cp != &cpu0) {
512 		if (cpus) {
513 			cp->cpu_next_free = cpus;
514 			cpus = cp;
515 		}
516 		else
517 			cpus = cp;
518 	}
519 
520 	return (0);
521 }
522 
523 /*
524  * This routine is used to start a previously powered off processor.
525  * Note that restarted cpus are initialized into the offline state.
526  */
527 void
528 restart_other_cpu(int cpuid)
529 {
530 	struct cpu *cp;
531 	kthread_id_t tp;
532 	caddr_t	sp;
533 	extern void idle();
534 
535 	ASSERT(MUTEX_HELD(&cpu_lock));
536 	ASSERT(cpuid < NCPU && cpu[cpuid] != NULL);
537 
538 	/*
539 	 * Obtain pointer to the appropriate cpu structure.
540 	 */
541 	cp = cpu[cpuid];
542 
543 	common_startup_init(cp, cpuid);
544 
545 	/*
546 	 * idle thread t_lock is held when the idle thread is suspended.
547 	 * Manually unlock the t_lock of idle loop so that we can resume
548 	 * the suspended idle thread.
549 	 * Also adjust the PC of idle thread for re-retry.
550 	 */
551 	cp->cpu_intr_actv = 0;	/* clear the value from previous life */
552 	cp->cpu_m.mutex_ready = 0; /* we are not ready yet */
553 	lock_clear(&cp->cpu_idle_thread->t_lock);
554 	tp = cp->cpu_idle_thread;
555 
556 	sp = tp->t_stk;
557 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
558 	tp->t_pc = (uintptr_t)idle - 8;
559 
560 	/*
561 	 * restart the cpu now
562 	 */
563 	promsafe_pause_cpus();
564 	start_cpu(cpuid, warm_flag_set);
565 	start_cpus();
566 
567 	/* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */
568 	cmn_err(CE_CONT, "!cpu%d initialization complete - restarted\n",
569 	    cpuid);
570 }
571 
572 /*
573  * Startup function executed on 'other' CPUs.  This is the first
574  * C function after cpu_start sets up the cpu registers.
575  */
576 static void
577 slave_startup(void)
578 {
579 	struct cpu	*cp = CPU;
580 	ushort_t	original_flags = cp->cpu_flags;
581 
582 	mach_htraptrace_configure(cp->cpu_id);
583 	cpu_intrq_register(CPU);
584 	cp->cpu_m.mutex_ready = 1;
585 	cp->cpu_m.poke_cpu_outstanding = B_FALSE;
586 
587 	/* acknowledge that we are done with initialization */
588 	CPUSET_ADD(proxy_ready_set, cp->cpu_id);
589 
590 	/* synchronize STICK */
591 	sticksync_slave();
592 
593 	if (boothowto & RB_DEBUG)
594 		kdi_dvec_cpu_init(cp);
595 
596 	/*
597 	 * the slave will wait here forever -- assuming that the master
598 	 * will get back to us.  if it doesn't we've got bigger problems
599 	 * than a master not replying to this slave.
600 	 * the small delay improves the slave's responsiveness to the
601 	 * master's ack and decreases the time window between master and
602 	 * slave operations.
603 	 */
604 	while (!CPU_IN_SET(cpu_ready_set, cp->cpu_id))
605 		DELAY(1);
606 
607 	/* enable interrupts */
608 	(void) spl0();
609 
610 	/*
611 	 * Signature block update to indicate that this CPU is in OS now.
612 	 * This needs to be done after the PIL is lowered since on
613 	 * some platforms the update code may block.
614 	 */
615 	CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cp->cpu_id);
616 
617 	/*
618 	 * park the slave thread in a safe/quiet state and wait for the master
619 	 * to finish configuring this CPU before proceeding to thread_exit().
620 	 */
621 	while (((volatile ushort_t)cp->cpu_flags) & CPU_QUIESCED)
622 		DELAY(1);
623 
624 	/*
625 	 * Initialize CPC CPU state.
626 	 */
627 	kcpc_hw_startup_cpu(original_flags);
628 
629 	/*
630 	 * Notify the PG subsystem that the CPU  has started
631 	 */
632 	pg_cmt_cpu_startup(CPU);
633 
634 	/*
635 	 * Now we are done with the startup thread, so free it up.
636 	 */
637 	thread_exit();
638 	cmn_err(CE_PANIC, "slave_startup: cannot return");
639 	/*NOTREACHED*/
640 }
641 
642 extern struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
643 
644 /*
645  * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that
646  * can be used during debugging to control which processors are brought
647  * online at boot time.  The variable represents a bitmap of the id's
648  * of the processors that will be brought online.  The initialization
649  * of this variable depends on the type of cpuset_t, which varies
650  * depending on the number of processors supported (see cpuvar.h).
651  */
652 cpuset_t cpu_bringup_set;
653 
654 
655 /*
656  * Generic start-all cpus entry.  Typically used during cold initialization.
657  * Note that cold start cpus are initialized into the online state.
658  */
659 /*ARGSUSED*/
660 void
661 start_other_cpus(int flag)
662 {
663 	int cpuid;
664 	extern void idlestop_init(void);
665 	int bootcpu;
666 
667 	/*
668 	 * Check if cpu_bringup_set has been explicitly set before
669 	 * initializing it.
670 	 */
671 	if (CPUSET_ISNULL(cpu_bringup_set)) {
672 #ifdef MPSAS
673 		/* just CPU 0 */
674 		CPUSET_ADD(cpu_bringup_set, 0);
675 #else
676 		CPUSET_ALL(cpu_bringup_set);
677 #endif
678 	}
679 
680 	if (&cpu_feature_init)
681 		cpu_feature_init();
682 
683 	/*
684 	 * Initialize CPC.
685 	 */
686 	kcpc_hw_init();
687 
688 	mutex_enter(&cpu_lock);
689 
690 	/*
691 	 * Initialize our own cpu_info.
692 	 */
693 	init_cpu_info(CPU);
694 
695 	/*
696 	 * Initialize CPU 0 cpu module private data area, including scrubber.
697 	 */
698 	cpu_init_private(CPU);
699 
700 	/*
701 	 * perform such initialization as is needed
702 	 * to be able to take CPUs on- and off-line.
703 	 */
704 	cpu_pause_init();
705 	xc_init();		/* initialize processor crosscalls */
706 	idlestop_init();
707 
708 	if (!use_mp) {
709 		mutex_exit(&cpu_lock);
710 		cmn_err(CE_CONT, "?***** Not in MP mode\n");
711 		return;
712 	}
713 	/*
714 	 * should we be initializing this cpu?
715 	 */
716 	bootcpu = getprocessorid();
717 
718 	/*
719 	 * launch all the slave cpus now
720 	 */
721 	for (cpuid = 0; cpuid < NCPU; cpuid++) {
722 		pnode_t nodeid = cpunodes[cpuid].nodeid;
723 
724 		if (nodeid == (pnode_t)0)
725 			continue;
726 
727 		if (cpuid == bootcpu) {
728 			if (!CPU_IN_SET(cpu_bringup_set, cpuid)) {
729 				cmn_err(CE_WARN, "boot cpu not a member "
730 				    "of cpu_bringup_set, adding it");
731 				CPUSET_ADD(cpu_bringup_set, cpuid);
732 			}
733 			continue;
734 		}
735 		if (!CPU_IN_SET(cpu_bringup_set, cpuid))
736 			continue;
737 
738 		ASSERT(cpu[cpuid] == NULL);
739 
740 		if (setup_cpu_common(cpuid)) {
741 			cmn_err(CE_PANIC, "cpu%d: setup failed", cpuid);
742 		}
743 
744 		common_startup_init(cpu[cpuid], cpuid);
745 
746 		start_cpu(cpuid, cold_flag_set);
747 		/*
748 		 * Because slave_startup() gets fired off after init()
749 		 * starts, we can't use the '?' trick to do 'boot -v'
750 		 * printing - so we always direct the 'cpu .. online'
751 		 * messages to the log.
752 		 */
753 		cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
754 		    cpuid);
755 
756 		/*
757 		 * XXX: register_cpu_setup() callbacks should be called here
758 		 * with a new setup code, CPU_BOOT (or something).
759 		 */
760 		if (dtrace_cpu_init != NULL)
761 			(*dtrace_cpu_init)(cpuid);
762 	}
763 
764 	/*
765 	 * since all the cpus are online now, redistribute interrupts to them.
766 	 */
767 	intr_redist_all_cpus();
768 
769 	mutex_exit(&cpu_lock);
770 
771 	/*
772 	 * Start the Ecache scrubber.  Must be done after all calls to
773 	 * cpu_init_private for every cpu (including CPU 0).
774 	 */
775 	cpu_init_cache_scrub();
776 
777 	if (&cpu_mp_init)
778 		cpu_mp_init();
779 }
780