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