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