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