xref: /titanic_44/usr/src/uts/sun4/os/mp_startup.c (revision 5151fb1220e0ceafdc172203863c73da4285c170)
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 void 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 void
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 
296 	ASSERT(MUTEX_HELD(&cpu_lock));
297 	ASSERT(cpu[cpuid] == NULL);
298 
299 	ASSERT(ncpus <= max_ncpus);
300 
301 #ifdef TRAPTRACE
302 	/*
303 	 * allocate a traptrace buffer for this CPU.
304 	 */
305 	ctlp = &trap_trace_ctl[cpuid];
306 	if (!trap_tr0_inuse) {
307 		trap_tr0_inuse = 1;
308 		newbuf = trap_tr0;
309 		tt_index = -1;
310 	} else {
311 		for (tt_index = 0; tt_index < (max_ncpus-1); tt_index++)
312 			if (!trap_trace_inuse[tt_index])
313 			    break;
314 		ASSERT(tt_index < max_ncpus - 1);
315 		trap_trace_inuse[tt_index] = 1;
316 		newbuf = (caddr_t)(ttrace_buf + (tt_index * TRAP_TSIZE));
317 	}
318 	ctlp->d.vaddr_base = newbuf;
319 	ctlp->d.offset = ctlp->d.last_offset = 0;
320 	ctlp->d.limit = trap_trace_bufsize;
321 	ctlp->d.paddr_base = va_to_pa(newbuf);
322 	ASSERT(ctlp->d.paddr_base != (uint64_t)-1);
323 #endif /* TRAPTRACE */
324 	/*
325 	 * initialize hv traptrace buffer for this CPU
326 	 */
327 	mach_htraptrace_setup(cpuid);
328 
329 	/*
330 	 * Obtain pointer to the appropriate cpu structure.
331 	 */
332 	if (cpu0.cpu_flags == 0) {
333 		cp = &cpu0;
334 	} else {
335 		/*
336 		 *  When dynamically allocating cpu structs,
337 		 *  cpus is used as a pointer to a list of freed
338 		 *  cpu structs.
339 		 */
340 		if (cpus) {
341 			/* grab the first cpu struct on the free list */
342 			cp = cpus;
343 			if (cp->cpu_next_free)
344 				cpus = cp->cpu_next_free;
345 			else
346 				cpus = NULL;
347 		}
348 	}
349 
350 	if (cp == NULL)
351 		cp = vmem_xalloc(static_alloc_arena, CPU_ALLOC_SIZE,
352 		    CPU_ALLOC_SIZE, 0, 0, NULL, NULL, VM_SLEEP);
353 
354 	bzero(cp, sizeof (*cp));
355 
356 	cp->cpu_id = cpuid;
357 	cp->cpu_self = cp;
358 
359 	/*
360 	 * Initialize ptl1_panic stack
361 	 */
362 	ptl1_init_cpu(cp);
363 
364 	/*
365 	 * Initialize the dispatcher for this CPU.
366 	 */
367 	disp_cpu_init(cp);
368 
369 	cpu_vm_data_init(cp);
370 
371 	/*
372 	 * Now, initialize per-CPU idle thread for this CPU.
373 	 */
374 	tp = thread_create(NULL, 0, idle, NULL, 0, &p0, TS_ONPROC, -1);
375 
376 	cp->cpu_idle_thread = tp;
377 
378 	tp->t_preempt = 1;
379 	tp->t_bound_cpu = cp;
380 	tp->t_affinitycnt = 1;
381 	tp->t_cpu = cp;
382 	tp->t_disp_queue = cp->cpu_disp;
383 
384 	/*
385 	 * Registering a thread in the callback table is usually
386 	 * done in the initialization code of the thread. In this
387 	 * case, we do it right after thread creation to avoid
388 	 * blocking idle thread while registering itself. It also
389 	 * avoids the possibility of reregistration in case a CPU
390 	 * restarts its idle thread.
391 	 */
392 	CALLB_CPR_INIT_SAFE(tp, "idle");
393 
394 	init_cpu_info(cp);
395 
396 	/*
397 	 * Initialize the interrupt threads for this CPU
398 	 */
399 	cpu_intr_alloc(cp, NINTR_THREADS);
400 
401 	/*
402 	 * Add CPU to list of available CPUs.
403 	 * It'll be on the active list after it is started.
404 	 */
405 	cpu_add_unit(cp);
406 
407 	/*
408 	 * Allocate and init cpu module private data structures,
409 	 * including scrubber.
410 	 */
411 	cpu_init_private(cp);
412 
413 	/*
414 	 * Initialize the CPUs physical ID cache, and processor groups
415 	 */
416 	pghw_physid_create(cp);
417 	pg_cpu_init(cp);
418 
419 	if (nosteal_nsec == -1)
420 		cmp_set_nosteal_interval();
421 
422 	cpu_intrq_setup(cp);
423 
424 	/*
425 	 * Initialize MMU context domain information.
426 	 */
427 	sfmmu_cpu_init(cp);
428 
429 }
430 
431 /*
432  * Routine to clean up a CPU after shutting it down.
433  */
434 int
435 cleanup_cpu_common(int cpuid)
436 {
437 	struct cpu *cp;
438 #ifdef TRAPTRACE
439 	int i;
440 	TRAP_TRACE_CTL	*ctlp;
441 	caddr_t	newbuf;
442 #endif /* TRAPTRACE */
443 
444 	ASSERT(MUTEX_HELD(&cpu_lock));
445 	ASSERT(cpu[cpuid] != NULL);
446 
447 	cp = cpu[cpuid];
448 
449 	/* Free cpu module private data structures, including scrubber. */
450 	cpu_uninit_private(cp);
451 
452 	/* Free cpu ID string and brand string. */
453 	kmem_free(cp->cpu_idstr, strlen(cp->cpu_idstr) + 1);
454 	kmem_free(cp->cpu_brandstr, strlen(cp->cpu_brandstr) + 1);
455 
456 	cpu_vm_data_destroy(cp);
457 
458 	/*
459 	 * Remove CPU from list of available CPUs.
460 	 */
461 	cpu_del_unit(cpuid);
462 
463 	/*
464 	 * Clean any machine specific interrupt states.
465 	 */
466 	cpu_intrq_cleanup(cp);
467 
468 	/*
469 	 * At this point, the only threads bound to this CPU should be
470 	 * special per-cpu threads: it's idle thread, it's pause thread,
471 	 * and it's interrupt threads.  Clean these up.
472 	 */
473 	cpu_destroy_bound_threads(cp);
474 
475 	/*
476 	 * Free the interrupt stack.
477 	 */
478 	segkp_release(segkp, cp->cpu_intr_stack);
479 
480 	/*
481 	 * Free hv traptrace buffer for this CPU.
482 	 */
483 	mach_htraptrace_cleanup(cpuid);
484 #ifdef TRAPTRACE
485 	/*
486 	 * Free the traptrace buffer for this CPU.
487 	 */
488 	ctlp = &trap_trace_ctl[cpuid];
489 	newbuf = ctlp->d.vaddr_base;
490 	i = (newbuf - ttrace_buf) / (TRAP_TSIZE);
491 	if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) &&
492 	    ((i >= 0) && (i < (max_ncpus-1)))) {
493 		/*
494 		 * This CPU got it's trap trace buffer from the
495 		 * boot-alloc'd bunch of them.
496 		 */
497 		trap_trace_inuse[i] = 0;
498 		bzero(newbuf, (TRAP_TSIZE));
499 	} else if (newbuf == trap_tr0) {
500 		trap_tr0_inuse = 0;
501 		bzero(trap_tr0, (TRAP_TSIZE));
502 	} else {
503 		cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d",
504 		    cpuid);
505 	}
506 	bzero(ctlp, sizeof (*ctlp));
507 #endif /* TRAPTRACE */
508 
509 	/*
510 	 * There is a race condition with mutex_vector_enter() which
511 	 * caches a cpu pointer. The race is detected by checking cpu_next.
512 	 */
513 	disp_cpu_fini(cp);
514 	cpu_pa[cpuid] = 0;
515 	sfmmu_cpu_cleanup(cp);
516 	bzero(cp, sizeof (*cp));
517 
518 	/*
519 	 * Place the freed cpu structure on the list of freed cpus.
520 	 */
521 	if (cp != &cpu0) {
522 		if (cpus) {
523 			cp->cpu_next_free = cpus;
524 			cpus = cp;
525 		}
526 		else
527 			cpus = cp;
528 	}
529 
530 	return (0);
531 }
532 
533 /*
534  * This routine is used to start a previously powered off processor.
535  * Note that restarted cpus are initialized into the offline state.
536  */
537 void
538 restart_other_cpu(int cpuid)
539 {
540 	struct cpu *cp;
541 	kthread_id_t tp;
542 	caddr_t	sp;
543 	extern void idle();
544 
545 	ASSERT(MUTEX_HELD(&cpu_lock));
546 	ASSERT(cpuid < NCPU && cpu[cpuid] != NULL);
547 
548 	/*
549 	 * Obtain pointer to the appropriate cpu structure.
550 	 */
551 	cp = cpu[cpuid];
552 
553 	common_startup_init(cp, cpuid);
554 
555 	/*
556 	 * idle thread t_lock is held when the idle thread is suspended.
557 	 * Manually unlock the t_lock of idle loop so that we can resume
558 	 * the suspended idle thread.
559 	 * Also adjust the PC of idle thread for re-retry.
560 	 */
561 	cp->cpu_intr_actv = 0;	/* clear the value from previous life */
562 	cp->cpu_m.mutex_ready = 0; /* we are not ready yet */
563 	lock_clear(&cp->cpu_idle_thread->t_lock);
564 	tp = cp->cpu_idle_thread;
565 
566 	sp = tp->t_stk;
567 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
568 	tp->t_pc = (uintptr_t)idle - 8;
569 
570 	/*
571 	 * restart the cpu now
572 	 */
573 	promsafe_pause_cpus();
574 	start_cpu(cpuid, warm_flag_set);
575 	start_cpus();
576 
577 	/* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */
578 	cmn_err(CE_CONT, "!cpu%d initialization complete - restarted\n",
579 	    cpuid);
580 }
581 
582 /*
583  * Startup function executed on 'other' CPUs.  This is the first
584  * C function after cpu_start sets up the cpu registers.
585  */
586 static void
587 slave_startup(void)
588 {
589 	struct cpu	*cp = CPU;
590 	ushort_t	original_flags = cp->cpu_flags;
591 
592 	mach_htraptrace_configure(cp->cpu_id);
593 	cpu_intrq_register(CPU);
594 	cp->cpu_m.mutex_ready = 1;
595 	cp->cpu_m.poke_cpu_outstanding = B_FALSE;
596 
597 	/* acknowledge that we are done with initialization */
598 	CPUSET_ADD(proxy_ready_set, cp->cpu_id);
599 
600 	/* synchronize STICK */
601 	sticksync_slave();
602 
603 	if (boothowto & RB_DEBUG)
604 		kdi_dvec_cpu_init(cp);
605 
606 	/*
607 	 * the slave will wait here forever -- assuming that the master
608 	 * will get back to us.  if it doesn't we've got bigger problems
609 	 * than a master not replying to this slave.
610 	 * the small delay improves the slave's responsiveness to the
611 	 * master's ack and decreases the time window between master and
612 	 * slave operations.
613 	 */
614 	while (!CPU_IN_SET(cpu_ready_set, cp->cpu_id))
615 		DELAY(1);
616 
617 	/* enable interrupts */
618 	(void) spl0();
619 
620 	/*
621 	 * Signature block update to indicate that this CPU is in OS now.
622 	 * This needs to be done after the PIL is lowered since on
623 	 * some platforms the update code may block.
624 	 */
625 	CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cp->cpu_id);
626 
627 	/*
628 	 * park the slave thread in a safe/quiet state and wait for the master
629 	 * to finish configuring this CPU before proceeding to thread_exit().
630 	 */
631 	while (((volatile ushort_t)cp->cpu_flags) & CPU_QUIESCED)
632 		DELAY(1);
633 
634 	/*
635 	 * Initialize CPC CPU state.
636 	 */
637 	kcpc_hw_startup_cpu(original_flags);
638 
639 	/*
640 	 * Notify the PG subsystem that the CPU  has started
641 	 */
642 	pg_cmt_cpu_startup(CPU);
643 
644 	/*
645 	 * Now we are done with the startup thread, so free it up.
646 	 */
647 	thread_exit();
648 	cmn_err(CE_PANIC, "slave_startup: cannot return");
649 	/*NOTREACHED*/
650 }
651 
652 extern struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
653 
654 extern void setup_cpu_common(int);
655 extern void common_startup_init(cpu_t *, int);
656 extern void start_cpu(int, void(*func)(int));
657 extern void cold_flag_set(int cpuid);
658 
659 /*
660  * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that
661  * can be used during debugging to control which processors are brought
662  * online at boot time.  The variable represents a bitmap of the id's
663  * of the processors that will be brought online.  The initialization
664  * of this variable depends on the type of cpuset_t, which varies
665  * depending on the number of processors supported (see cpuvar.h).
666  */
667 cpuset_t cpu_bringup_set;
668 
669 
670 /*
671  * Generic start-all cpus entry.  Typically used during cold initialization.
672  * Note that cold start cpus are initialized into the online state.
673  */
674 /*ARGSUSED*/
675 void
676 start_other_cpus(int flag)
677 {
678 	int cpuid;
679 	extern void idlestop_init(void);
680 	int bootcpu;
681 
682 	/*
683 	 * Check if cpu_bringup_set has been explicitly set before
684 	 * initializing it.
685 	 */
686 	if (CPUSET_ISNULL(cpu_bringup_set)) {
687 #ifdef MPSAS
688 		/* just CPU 0 */
689 		CPUSET_ADD(cpu_bringup_set, 0);
690 #else
691 		CPUSET_ALL(cpu_bringup_set);
692 #endif
693 	}
694 
695 	if (&cpu_feature_init)
696 		cpu_feature_init();
697 
698 	/*
699 	 * Initialize CPC.
700 	 */
701 	kcpc_hw_init();
702 
703 	mutex_enter(&cpu_lock);
704 
705 	/*
706 	 * Initialize our own cpu_info.
707 	 */
708 	init_cpu_info(CPU);
709 
710 	/*
711 	 * Initialize CPU 0 cpu module private data area, including scrubber.
712 	 */
713 	cpu_init_private(CPU);
714 
715 	/*
716 	 * perform such initialization as is needed
717 	 * to be able to take CPUs on- and off-line.
718 	 */
719 	cpu_pause_init();
720 	xc_init();		/* initialize processor crosscalls */
721 	idlestop_init();
722 
723 	if (!use_mp) {
724 		mutex_exit(&cpu_lock);
725 		cmn_err(CE_CONT, "?***** Not in MP mode\n");
726 		return;
727 	}
728 	/*
729 	 * should we be initializing this cpu?
730 	 */
731 	bootcpu = getprocessorid();
732 
733 	/*
734 	 * launch all the slave cpus now
735 	 */
736 	for (cpuid = 0; cpuid < NCPU; cpuid++) {
737 		pnode_t nodeid = cpunodes[cpuid].nodeid;
738 
739 		if (nodeid == (pnode_t)0)
740 			continue;
741 
742 		if (cpuid == bootcpu) {
743 			if (!CPU_IN_SET(cpu_bringup_set, cpuid)) {
744 				cmn_err(CE_WARN, "boot cpu not a member "
745 				    "of cpu_bringup_set, adding it");
746 				CPUSET_ADD(cpu_bringup_set, cpuid);
747 			}
748 			continue;
749 		}
750 		if (!CPU_IN_SET(cpu_bringup_set, cpuid))
751 			continue;
752 
753 		ASSERT(cpu[cpuid] == NULL);
754 
755 		setup_cpu_common(cpuid);
756 
757 		common_startup_init(cpu[cpuid], cpuid);
758 
759 		start_cpu(cpuid, cold_flag_set);
760 		/*
761 		 * Because slave_startup() gets fired off after init()
762 		 * starts, we can't use the '?' trick to do 'boot -v'
763 		 * printing - so we always direct the 'cpu .. online'
764 		 * messages to the log.
765 		 */
766 		cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
767 		    cpuid);
768 
769 		/*
770 		 * XXX: register_cpu_setup() callbacks should be called here
771 		 * with a new setup code, CPU_BOOT (or something).
772 		 */
773 		if (dtrace_cpu_init != NULL)
774 			(*dtrace_cpu_init)(cpuid);
775 	}
776 
777 	/*
778 	 * since all the cpus are online now, redistribute interrupts to them.
779 	 */
780 	intr_redist_all_cpus();
781 
782 	mutex_exit(&cpu_lock);
783 
784 	/*
785 	 * Start the Ecache scrubber.  Must be done after all calls to
786 	 * cpu_init_private for every cpu (including CPU 0).
787 	 */
788 	cpu_init_cache_scrub();
789 
790 	if (&cpu_mp_init)
791 		cpu_mp_init();
792 }
793