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