xref: /illumos-gate/usr/src/uts/sun4/os/mp_startup.c (revision 7f7322febbcfe774b7270abc3b191c094bfcc517)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 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/chip.h>
39 #include <sys/dtrace.h>
40 #include <sys/reboot.h>
41 #include <sys/kdi.h>
42 #include <sys/traptrace.h>
43 #ifdef TRAPTRACE
44 #include <sys/bootconf.h>
45 #endif /* TRAPTRACE */
46 #include <sys/cpu_sgnblk_defs.h>
47 
48 extern void cpu_intrq_setup(struct cpu *);
49 extern void cpu_intrq_register(struct cpu *);
50 
51 struct cpu	*cpus;	/* pointer to other cpus; dynamically allocate */
52 struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
53 uint64_t	cpu_pa[NCPU];	/* pointers to all CPUs in PA */
54 cpu_core_t	cpu_core[NCPU];	/* cpu_core structures */
55 
56 #ifdef TRAPTRACE
57 caddr_t	ttrace_buf;	/* bop alloced traptrace for all cpus except 0 */
58 #endif /* TRAPTRACE */
59 
60 /* bit mask of cpus ready for x-calls, protected by cpu_lock */
61 cpuset_t cpu_ready_set;
62 
63 /* bit mask used to communicate with cpus during bringup */
64 static cpuset_t proxy_ready_set;
65 
66 static void	slave_startup(void);
67 
68 /*
69  * Defined in $KARCH/os/mach_mp_startup.c
70  */
71 #pragma weak init_cpu_info
72 
73 /*
74  * Amount of time (in milliseconds) we should wait before giving up on CPU
75  * initialization and assuming that the CPU we're trying to wake up is dead
76  * or out of control.
77  */
78 #define	CPU_WAKEUP_GRACE_MSEC 1000
79 
80 /*
81  * MP configurations may reserve additional interrupt request entries.
82  * intr_add_{div,max} can be modified to tune memory usage.
83  */
84 
85 uint_t	intr_add_div = 1;			/* 1=worst case memory usage */
86 size_t	intr_add_max = 0;
87 
88 /* intr_add_{pools,head,tail} calculated based on intr_add_{div,max} */
89 
90 size_t	intr_add_pools = 0;			/* additional pools per cpu */
91 struct intr_req	*intr_add_head = (struct intr_req *)NULL;
92 #ifdef	DEBUG
93 struct intr_req	*intr_add_tail = (struct intr_req *)NULL;
94 #endif	/* DEBUG */
95 
96 
97 #ifdef	TRAPTRACE
98 /*
99  * This function bop allocs traptrace buffers for all cpus
100  * other than boot cpu.
101  */
102 caddr_t
103 trap_trace_alloc(caddr_t base)
104 {
105 	caddr_t	vaddr;
106 	extern int max_ncpus;
107 
108 	if (max_ncpus == 1) {
109 		return (base);
110 	}
111 
112 	if ((vaddr = (caddr_t)BOP_ALLOC(bootops, base, (TRAP_TSIZE *
113 		(max_ncpus - 1)), TRAP_TSIZE)) == NULL) {
114 		panic("traptrace_alloc: can't bop alloc");
115 	}
116 	ttrace_buf = vaddr;
117 	PRM_DEBUG(ttrace_buf);
118 	return (vaddr + (TRAP_TSIZE * (max_ncpus - 1)));
119 }
120 #endif	/* TRAPTRACE */
121 
122 /*
123  * common slave cpu initialization code
124  */
125 void
126 common_startup_init(cpu_t *cp, int cpuid)
127 {
128 	kthread_id_t tp;
129 	sfmmu_t *sfmmup;
130 	caddr_t	sp;
131 
132 	/*
133 	 * Allocate and initialize the startup thread for this CPU.
134 	 */
135 	tp = thread_create(NULL, 0, slave_startup, NULL, 0, &p0,
136 	    TS_STOPPED, maxclsyspri);
137 
138 	/*
139 	 * Set state to TS_ONPROC since this thread will start running
140 	 * as soon as the CPU comes online.
141 	 *
142 	 * All the other fields of the thread structure are setup by
143 	 * thread_create().
144 	 */
145 	THREAD_ONPROC(tp, cp);
146 	tp->t_preempt = 1;
147 	tp->t_bound_cpu = cp;
148 	tp->t_affinitycnt = 1;
149 	tp->t_cpu = cp;
150 	tp->t_disp_queue = cp->cpu_disp;
151 
152 	sfmmup = astosfmmu(&kas);
153 	CPUSET_ADD(sfmmup->sfmmu_cpusran, cpuid);
154 
155 	/*
156 	 * Setup thread to start in slave_startup.
157 	 */
158 	sp = tp->t_stk;
159 	tp->t_pc = (uintptr_t)slave_startup - 8;
160 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
161 
162 	cp->cpu_id = cpuid;
163 	cp->cpu_self = cp;
164 	cp->cpu_thread = tp;
165 	cp->cpu_lwp = NULL;
166 	cp->cpu_dispthread = tp;
167 	cp->cpu_dispatch_pri = DISP_PRIO(tp);
168 	cp->cpu_startup_thread = tp;
169 }
170 
171 /*
172  * parametric flag setting functions.  these routines set the cpu
173  * state just prior to releasing the slave cpu.
174  */
175 void
176 cold_flag_set(int cpuid)
177 {
178 	cpu_t *cp;
179 
180 	ASSERT(MUTEX_HELD(&cpu_lock));
181 
182 	cp = cpu[cpuid];
183 	cp->cpu_flags |= CPU_RUNNING | CPU_ENABLE | CPU_EXISTS;
184 	cpu_add_active(cp);
185 	/*
186 	 * Add CPU_READY after the cpu_add_active() call
187 	 * to avoid pausing cp.
188 	 */
189 	cp->cpu_flags |= CPU_READY;		/* ready */
190 	cpu_set_state(cp);
191 }
192 
193 static void
194 warm_flag_set(int cpuid)
195 {
196 	cpu_t *cp;
197 
198 	ASSERT(MUTEX_HELD(&cpu_lock));
199 
200 	/*
201 	 * warm start activates cpus into the OFFLINE state
202 	 */
203 	cp = cpu[cpuid];
204 	cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_EXISTS
205 		| CPU_OFFLINE | CPU_QUIESCED;
206 	cpu_set_state(cp);
207 }
208 
209 /*
210  * Internal cpu startup sequencer
211  * The sequence is as follows:
212  *
213  * MASTER	SLAVE
214  * -------	----------
215  * assume the kernel data is initialized
216  * clear the proxy bit
217  * start the slave cpu
218  * wait for the slave cpu to set the proxy
219  *
220  *		the slave runs slave_startup and then sets the proxy
221  *		the slave waits for the master to add slave to the ready set
222  *
223  * the master finishes the initialization and
224  * adds the slave to the ready set
225  *
226  *		the slave exits the startup thread and is running
227  */
228 void
229 start_cpu(int cpuid, void(*flag_func)(int))
230 {
231 	extern caddr_t cpu_startup;
232 	int timout;
233 
234 	ASSERT(MUTEX_HELD(&cpu_lock));
235 
236 	/*
237 	 * Before we begin the dance, tell DTrace that we're about to start
238 	 * a CPU.
239 	 */
240 	if (dtrace_cpustart_init != NULL)
241 		(*dtrace_cpustart_init)();
242 
243 	/* start the slave cpu */
244 	CPUSET_DEL(proxy_ready_set, cpuid);
245 	if (prom_test("SUNW,start-cpu-by-cpuid") == 0) {
246 		(void) prom_startcpu_bycpuid(cpuid, (caddr_t)&cpu_startup,
247 		    cpuid);
248 	} else {
249 		/* "by-cpuid" interface didn't exist.  Do it the old way */
250 		pnode_t nodeid = cpunodes[cpuid].nodeid;
251 
252 		ASSERT(nodeid != (pnode_t)0);
253 		(void) prom_startcpu(nodeid, (caddr_t)&cpu_startup, cpuid);
254 	}
255 
256 	/* wait for the slave cpu to check in. */
257 	for (timout = CPU_WAKEUP_GRACE_MSEC; timout; timout--) {
258 		if (CPU_IN_SET(proxy_ready_set, cpuid))
259 			break;
260 		DELAY(1000);
261 	}
262 	if (timout == 0) {
263 		panic("cpu%d failed to start (2)", cpuid);
264 	}
265 
266 	/*
267 	 * The slave has started; we can tell DTrace that it's safe again.
268 	 */
269 	if (dtrace_cpustart_fini != NULL)
270 		(*dtrace_cpustart_fini)();
271 
272 	/* run the master side of stick synchronization for the slave cpu */
273 	sticksync_master();
274 
275 	/*
276 	 * deal with the cpu flags in a phase-specific manner
277 	 * for various reasons, this needs to run after the slave
278 	 * is checked in but before the slave is released.
279 	 */
280 	(*flag_func)(cpuid);
281 
282 	/* release the slave */
283 	CPUSET_ADD(cpu_ready_set, cpuid);
284 }
285 
286 #ifdef TRAPTRACE
287 int trap_tr0_inuse = 1;	/* it is always used on the boot cpu */
288 int trap_trace_inuse[NCPU];
289 #endif /* TRAPTRACE */
290 
291 #define	cpu_next_free	cpu_prev
292 
293 /*
294  * Routine to set up a CPU to prepare for starting it up.
295  */
296 void
297 setup_cpu_common(int cpuid)
298 {
299 	struct cpu *cp = NULL;
300 	kthread_id_t tp;
301 #ifdef TRAPTRACE
302 	int tt_index;
303 	TRAP_TRACE_CTL	*ctlp;
304 	caddr_t	newbuf;
305 #endif /* TRAPTRACE */
306 
307 	extern void idle();
308 	extern void init_intr_threads(struct cpu *);
309 
310 	ASSERT(MUTEX_HELD(&cpu_lock));
311 	ASSERT(cpu[cpuid] == NULL);
312 
313 	ASSERT(ncpus <= max_ncpus);
314 
315 #ifdef TRAPTRACE
316 	/*
317 	 * allocate a traptrace buffer for this CPU.
318 	 */
319 	ctlp = &trap_trace_ctl[cpuid];
320 	if (!trap_tr0_inuse) {
321 		trap_tr0_inuse = 1;
322 		newbuf = trap_tr0;
323 		tt_index = -1;
324 	} else {
325 		for (tt_index = 0; tt_index < (max_ncpus-1); tt_index++)
326 			if (!trap_trace_inuse[tt_index])
327 			    break;
328 		ASSERT(tt_index < max_ncpus - 1);
329 		trap_trace_inuse[tt_index] = 1;
330 		newbuf = (caddr_t)(ttrace_buf + (tt_index * TRAP_TSIZE));
331 	}
332 	ctlp->d.vaddr_base = newbuf;
333 	ctlp->d.offset = ctlp->d.last_offset = 0;
334 	ctlp->d.limit = trap_trace_bufsize;
335 	ctlp->d.paddr_base = va_to_pa(newbuf);
336 	ASSERT(ctlp->d.paddr_base != (uint64_t)-1);
337 #endif /* TRAPTRACE */
338 	/*
339 	 * initialize hv traptrace buffer for this CPU
340 	 */
341 	mach_htraptrace_setup(cpuid);
342 
343 	/*
344 	 * Obtain pointer to the appropriate cpu structure.
345 	 */
346 	if (cpu0.cpu_flags == 0) {
347 		cp = &cpu0;
348 	} else {
349 		/*
350 		 *  When dynamically allocating cpu structs,
351 		 *  cpus is used as a pointer to a list of freed
352 		 *  cpu structs.
353 		 */
354 		if (cpus) {
355 			/* grab the first cpu struct on the free list */
356 			cp = cpus;
357 			if (cp->cpu_next_free)
358 				cpus = cp->cpu_next_free;
359 			else
360 				cpus = NULL;
361 		}
362 	}
363 
364 	if (cp == NULL)
365 		cp = vmem_xalloc(static_alloc_arena, CPU_ALLOC_SIZE,
366 		    CPU_ALLOC_SIZE, 0, 0, NULL, NULL, VM_SLEEP);
367 
368 	bzero(cp, sizeof (*cp));
369 
370 	cp->cpu_id = cpuid;
371 	cp->cpu_self = cp;
372 
373 	/*
374 	 * Initialize ptl1_panic stack
375 	 */
376 	ptl1_init_cpu(cp);
377 
378 	/*
379 	 * Initialize the dispatcher for this CPU.
380 	 */
381 	disp_cpu_init(cp);
382 
383 	cpu_vm_data_init(cp);
384 
385 	/*
386 	 * Now, initialize per-CPU idle thread for this CPU.
387 	 */
388 	tp = thread_create(NULL, 0, idle, NULL, 0, &p0, TS_ONPROC, -1);
389 
390 	cp->cpu_idle_thread = tp;
391 
392 	tp->t_preempt = 1;
393 	tp->t_bound_cpu = cp;
394 	tp->t_affinitycnt = 1;
395 	tp->t_cpu = cp;
396 	tp->t_disp_queue = cp->cpu_disp;
397 
398 	/*
399 	 * Registering a thread in the callback table is usually
400 	 * done in the initialization code of the thread. In this
401 	 * case, we do it right after thread creation to avoid
402 	 * blocking idle thread while registering itself. It also
403 	 * avoids the possibility of reregistration in case a CPU
404 	 * restarts its idle thread.
405 	 */
406 	CALLB_CPR_INIT_SAFE(tp, "idle");
407 
408 	init_cpu_info(cp);
409 
410 	/*
411 	 * Initialize the interrupt threads for this CPU
412 	 */
413 	init_intr_pool(cp);
414 	init_intr_threads(cp);
415 
416 	/*
417 	 * Add CPU to list of available CPUs.
418 	 * It'll be on the active list after it is started.
419 	 */
420 	cpu_add_unit(cp);
421 
422 	/*
423 	 * Allocate and init cpu module private data structures,
424 	 * including scrubber.
425 	 */
426 	cpu_init_private(cp);
427 
428 	/*
429 	 * Associate this CPU with a physical processor
430 	 */
431 	chip_cpu_init(cp);
432 
433 	cpu_intrq_setup(cp);
434 }
435 
436 /*
437  * Routine to clean up a CPU after shutting it down.
438  */
439 int
440 cleanup_cpu_common(int cpuid)
441 {
442 	struct cpu *cp;
443 #ifdef TRAPTRACE
444 	int i;
445 	TRAP_TRACE_CTL	*ctlp;
446 	caddr_t	newbuf;
447 #endif /* TRAPTRACE */
448 
449 	ASSERT(MUTEX_HELD(&cpu_lock));
450 	ASSERT(cpu[cpuid] != NULL);
451 
452 	cp = cpu[cpuid];
453 
454 	/* Free cpu module private data structures, including scrubber. */
455 	cpu_uninit_private(cp);
456 
457 	cpu_vm_data_destroy(cp);
458 
459 	/*
460 	 * Remove CPU from list of available CPUs.
461 	 */
462 	cpu_del_unit(cpuid);
463 
464 	/*
465 	 * Clean up the interrupt pool.
466 	 */
467 	cleanup_intr_pool(cp);
468 
469 	/*
470 	 * At this point, the only threads bound to this CPU should be
471 	 * special per-cpu threads: it's idle thread, it's pause thread,
472 	 * and it's interrupt threads.  Clean these up.
473 	 */
474 	cpu_destroy_bound_threads(cp);
475 
476 	/*
477 	 * Free the interrupt stack.
478 	 */
479 	segkp_release(segkp, cp->cpu_intr_stack);
480 
481 	/*
482 	 * Free hv traptrace buffer for this CPU.
483 	 */
484 	mach_htraptrace_cleanup(cpuid);
485 #ifdef TRAPTRACE
486 	/*
487 	 * Free the traptrace buffer for this CPU.
488 	 */
489 	ctlp = &trap_trace_ctl[cpuid];
490 	newbuf = ctlp->d.vaddr_base;
491 	i = (newbuf - ttrace_buf) / (TRAP_TSIZE);
492 	if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) &&
493 	    ((i >= 0) && (i < (max_ncpus-1)))) {
494 		/*
495 		 * This CPU got it's trap trace buffer from the
496 		 * boot-alloc'd bunch of them.
497 		 */
498 		trap_trace_inuse[i] = 0;
499 		bzero(newbuf, (TRAP_TSIZE));
500 	} else if (newbuf == trap_tr0) {
501 		trap_tr0_inuse = 0;
502 		bzero(trap_tr0, (TRAP_TSIZE));
503 	} else {
504 		cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d",
505 		    cpuid);
506 	}
507 	bzero(ctlp, sizeof (*ctlp));
508 #endif /* TRAPTRACE */
509 
510 	/*
511 	 * There is a race condition with mutex_vector_enter() which
512 	 * caches a cpu pointer. The race is detected by checking cpu_next.
513 	 */
514 	disp_cpu_fini(cp);
515 	cpu_pa[cpuid] = 0;
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 CMT subsystem that the slave has started
641 	 */
642 	chip_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 /*
653  * 4163850 changes the allocation method for cpu structs. cpu structs
654  * are dynamically allocated. This routine now determines if additional
655  * per-cpu intr_req entries need to be allocated.
656  */
657 int
658 ndata_alloc_cpus(struct memlist *ndata)
659 {
660 	size_t real_sz;
661 	extern int niobus;
662 
663 	if (niobus > 1) {
664 
665 		/*
666 		 * Allocate additional intr_req entries if we have more than
667 		 * one io bus.  The memory to allocate is calculated from four
668 		 * variables: niobus, max_ncpus, intr_add_div, and intr_add_max.
669 		 * Allocate multiple of INTR_POOL_SIZE bytes (512).  Each cpu
670 		 * already reserves 512 bytes in its machcpu structure, so the
671 		 * worst case is (512 * (niobus - 1) * max_ncpus) add'l bytes.
672 		 *
673 		 * While niobus and max_ncpus reflect the h/w, the following
674 		 * may be tuned (before boot):
675 		 *
676 		 *	intr_add_div -	divisor for scaling the number of
677 		 *			additional intr_req entries. use '1'
678 		 *			for worst case memory, '2' for half,
679 		 *			etc.
680 		 *
681 		 *   intr_add_max - upper limit on bytes of memory to reserve
682 		 */
683 
684 		real_sz = INTR_POOL_SIZE * (niobus - 1) * max_ncpus;
685 
686 		/* tune memory usage by applying divisor and maximum */
687 
688 		if (intr_add_max == 0)
689 			intr_add_max = max_ncpus * INTR_POOL_SIZE;
690 		real_sz = MIN(intr_add_max, real_sz / MAX(intr_add_div, 1));
691 
692 		/* round down to multiple of (max_ncpus * INTR_POOL_SIZE) */
693 
694 		intr_add_pools = real_sz / (max_ncpus * INTR_POOL_SIZE);
695 		real_sz = intr_add_pools * (max_ncpus * INTR_POOL_SIZE);
696 
697 		/* actually reserve the space */
698 
699 		intr_add_head = ndata_alloc(ndata, real_sz, ecache_alignsize);
700 		if (intr_add_head == NULL)
701 			return (-1);
702 
703 		PRM_DEBUG(intr_add_head);
704 #ifdef	DEBUG
705 		intr_add_tail = (struct intr_req *)
706 		    ((uintptr_t)intr_add_head + real_sz);
707 #endif	/* DEBUG */
708 	}
709 
710 	return (0);
711 }
712 
713 
714 extern struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
715 
716 extern void setup_cpu_common(int);
717 extern void common_startup_init(cpu_t *, int);
718 extern void start_cpu(int, void(*func)(int));
719 extern void cold_flag_set(int cpuid);
720 
721 /*
722  * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that
723  * can be used during debugging to control which processors are brought
724  * online at boot time.  The variable represents a bitmap of the id's
725  * of the processors that will be brought online.  The initialization
726  * of this variable depends on the type of cpuset_t, which varies
727  * depending on the number of processors supported (see cpuvar.h).
728  */
729 cpuset_t cpu_bringup_set;
730 
731 
732 /*
733  * Generic start-all cpus entry.  Typically used during cold initialization.
734  * Note that cold start cpus are initialized into the online state.
735  */
736 /*ARGSUSED*/
737 void
738 start_other_cpus(int flag)
739 {
740 	int cpuid;
741 	extern void idlestop_init(void);
742 	int bootcpu;
743 
744 	/*
745 	 * Check if cpu_bringup_set has been explicitly set before
746 	 * initializing it.
747 	 */
748 	if (CPUSET_ISNULL(cpu_bringup_set)) {
749 #ifdef MPSAS
750 		/* just CPU 0 */
751 		CPUSET_ADD(cpu_bringup_set, 0);
752 #else
753 		CPUSET_ALL(cpu_bringup_set);
754 #endif
755 	}
756 
757 	if (&cpu_feature_init)
758 		cpu_feature_init();
759 
760 	/*
761 	 * Initialize CPC.
762 	 */
763 	kcpc_hw_init();
764 
765 	mutex_enter(&cpu_lock);
766 
767 	/*
768 	 * Initialize our own cpu_info.
769 	 */
770 	init_cpu_info(CPU);
771 
772 	/*
773 	 * Initialize CPU 0 cpu module private data area, including scrubber.
774 	 */
775 	cpu_init_private(CPU);
776 
777 	/*
778 	 * perform such initialization as is needed
779 	 * to be able to take CPUs on- and off-line.
780 	 */
781 	cpu_pause_init();
782 	xc_init();		/* initialize processor crosscalls */
783 	idlestop_init();
784 
785 	if (!use_mp) {
786 		mutex_exit(&cpu_lock);
787 		cmn_err(CE_CONT, "?***** Not in MP mode\n");
788 		return;
789 	}
790 	/*
791 	 * should we be initializing this cpu?
792 	 */
793 	bootcpu = getprocessorid();
794 
795 	/*
796 	 * launch all the slave cpus now
797 	 */
798 	for (cpuid = 0; cpuid < NCPU; cpuid++) {
799 		pnode_t nodeid = cpunodes[cpuid].nodeid;
800 
801 		if (nodeid == (pnode_t)0)
802 			continue;
803 
804 		if (cpuid == bootcpu) {
805 			if (!CPU_IN_SET(cpu_bringup_set, cpuid)) {
806 				cmn_err(CE_WARN, "boot cpu not a member "
807 				    "of cpu_bringup_set, adding it");
808 				CPUSET_ADD(cpu_bringup_set, cpuid);
809 			}
810 			continue;
811 		}
812 		if (!CPU_IN_SET(cpu_bringup_set, cpuid))
813 			continue;
814 
815 		ASSERT(cpu[cpuid] == NULL);
816 
817 		setup_cpu_common(cpuid);
818 
819 		common_startup_init(cpu[cpuid], cpuid);
820 
821 		start_cpu(cpuid, cold_flag_set);
822 		/*
823 		 * Because slave_startup() gets fired off after init()
824 		 * starts, we can't use the '?' trick to do 'boot -v'
825 		 * printing - so we always direct the 'cpu .. online'
826 		 * messages to the log.
827 		 */
828 		cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
829 		    cpuid);
830 
831 		/*
832 		 * XXX: register_cpu_setup() callbacks should be called here
833 		 * with a new setup code, CPU_BOOT (or something).
834 		 */
835 		if (dtrace_cpu_init != NULL)
836 			(*dtrace_cpu_init)(cpuid);
837 	}
838 
839 	/*
840 	 * since all the cpus are online now, redistribute interrupts to them.
841 	 */
842 	intr_redist_all_cpus();
843 
844 	mutex_exit(&cpu_lock);
845 
846 	/*
847 	 * Start the Ecache scrubber.  Must be done after all calls to
848 	 * cpu_init_private for every cpu (including CPU 0).
849 	 */
850 	cpu_init_cache_scrub();
851 
852 	if (&cpu_mp_init)
853 		cpu_mp_init();
854 }
855