xref: /illumos-gate/usr/src/uts/sun4/os/mp_startup.c (revision 560f878bce5cdf0661659001415019ca5c8a01b4)
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 2006 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_cleanup(struct cpu *);
50 extern void cpu_intrq_register(struct cpu *);
51 
52 struct cpu	*cpus;	/* pointer to other cpus; dynamically allocate */
53 struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
54 uint64_t	cpu_pa[NCPU];	/* pointers to all CPUs in PA */
55 cpu_core_t	cpu_core[NCPU];	/* cpu_core structures */
56 
57 #ifdef TRAPTRACE
58 caddr_t	ttrace_buf;	/* bop alloced traptrace for all cpus except 0 */
59 #endif /* TRAPTRACE */
60 
61 /* bit mask of cpus ready for x-calls, protected by cpu_lock */
62 cpuset_t cpu_ready_set;
63 
64 /* bit mask used to communicate with cpus during bringup */
65 static cpuset_t proxy_ready_set;
66 
67 static void	slave_startup(void);
68 
69 /*
70  * Defined in $KARCH/os/mach_mp_startup.c
71  */
72 #pragma weak init_cpu_info
73 
74 /*
75  * Amount of time (in milliseconds) we should wait before giving up on CPU
76  * initialization and assuming that the CPU we're trying to wake up is dead
77  * or out of control.
78  */
79 #define	CPU_WAKEUP_GRACE_MSEC 1000
80 
81 /*
82  * MP configurations may reserve additional interrupt request entries.
83  * intr_add_{div,max} can be modified to tune memory usage.
84  */
85 
86 uint_t	intr_add_div = 1;			/* 1=worst case memory usage */
87 size_t	intr_add_max = 0;
88 
89 /* intr_add_{pools,head,tail} calculated based on intr_add_{div,max} */
90 
91 size_t	intr_add_pools = 0;			/* additional pools per cpu */
92 struct intr_req	*intr_add_head = (struct intr_req *)NULL;
93 #ifdef	DEBUG
94 struct intr_req	*intr_add_tail = (struct intr_req *)NULL;
95 #endif	/* DEBUG */
96 
97 
98 #ifdef	TRAPTRACE
99 /*
100  * This function bop allocs traptrace buffers for all cpus
101  * other than boot cpu.
102  */
103 caddr_t
104 trap_trace_alloc(caddr_t base)
105 {
106 	caddr_t	vaddr;
107 	extern int max_ncpus;
108 
109 	if (max_ncpus == 1) {
110 		return (base);
111 	}
112 
113 	if ((vaddr = (caddr_t)BOP_ALLOC(bootops, base, (TRAP_TSIZE *
114 		(max_ncpus - 1)), TRAP_TSIZE)) == NULL) {
115 		panic("traptrace_alloc: can't bop alloc");
116 	}
117 	ttrace_buf = vaddr;
118 	PRM_DEBUG(ttrace_buf);
119 	return (vaddr + (TRAP_TSIZE * (max_ncpus - 1)));
120 }
121 #endif	/* TRAPTRACE */
122 
123 /*
124  * common slave cpu initialization code
125  */
126 void
127 common_startup_init(cpu_t *cp, int cpuid)
128 {
129 	kthread_id_t tp;
130 	sfmmu_t *sfmmup;
131 	caddr_t	sp;
132 
133 	/*
134 	 * Allocate and initialize the startup thread for this CPU.
135 	 */
136 	tp = thread_create(NULL, 0, slave_startup, NULL, 0, &p0,
137 	    TS_STOPPED, maxclsyspri);
138 
139 	/*
140 	 * Set state to TS_ONPROC since this thread will start running
141 	 * as soon as the CPU comes online.
142 	 *
143 	 * All the other fields of the thread structure are setup by
144 	 * thread_create().
145 	 */
146 	THREAD_ONPROC(tp, cp);
147 	tp->t_preempt = 1;
148 	tp->t_bound_cpu = cp;
149 	tp->t_affinitycnt = 1;
150 	tp->t_cpu = cp;
151 	tp->t_disp_queue = cp->cpu_disp;
152 
153 	sfmmup = astosfmmu(&kas);
154 	CPUSET_ADD(sfmmup->sfmmu_cpusran, cpuid);
155 
156 	/*
157 	 * Setup thread to start in slave_startup.
158 	 */
159 	sp = tp->t_stk;
160 	tp->t_pc = (uintptr_t)slave_startup - 8;
161 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
162 
163 	cp->cpu_id = cpuid;
164 	cp->cpu_self = cp;
165 	cp->cpu_thread = tp;
166 	cp->cpu_lwp = NULL;
167 	cp->cpu_dispthread = tp;
168 	cp->cpu_dispatch_pri = DISP_PRIO(tp);
169 	cp->cpu_startup_thread = 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 void cpu_startup(int);
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 		pnode_t nodeid = cpunodes[cpuid].nodeid;
252 
253 		ASSERT(nodeid != (pnode_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 
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 	cpu_intr_alloc(cp, NINTR_THREADS);
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 	/* Free cpu ID string and brand string. */
458 	kmem_free(cp->cpu_idstr, strlen(cp->cpu_idstr) + 1);
459 	kmem_free(cp->cpu_brandstr, strlen(cp->cpu_brandstr) + 1);
460 
461 	cpu_vm_data_destroy(cp);
462 
463 	/*
464 	 * Remove CPU from list of available CPUs.
465 	 */
466 	cpu_del_unit(cpuid);
467 
468 	/*
469 	 * Clean up the interrupt pool.
470 	 */
471 	cleanup_intr_pool(cp);
472 
473 	/*
474 	 * Clean any machine specific interrupt states.
475 	 */
476 	cpu_intrq_cleanup(cp);
477 
478 	/*
479 	 * At this point, the only threads bound to this CPU should be
480 	 * special per-cpu threads: it's idle thread, it's pause thread,
481 	 * and it's interrupt threads.  Clean these up.
482 	 */
483 	cpu_destroy_bound_threads(cp);
484 
485 	/*
486 	 * Free the interrupt stack.
487 	 */
488 	segkp_release(segkp, cp->cpu_intr_stack);
489 
490 	/*
491 	 * Free hv traptrace buffer for this CPU.
492 	 */
493 	mach_htraptrace_cleanup(cpuid);
494 #ifdef TRAPTRACE
495 	/*
496 	 * Free the traptrace buffer for this CPU.
497 	 */
498 	ctlp = &trap_trace_ctl[cpuid];
499 	newbuf = ctlp->d.vaddr_base;
500 	i = (newbuf - ttrace_buf) / (TRAP_TSIZE);
501 	if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) &&
502 	    ((i >= 0) && (i < (max_ncpus-1)))) {
503 		/*
504 		 * This CPU got it's trap trace buffer from the
505 		 * boot-alloc'd bunch of them.
506 		 */
507 		trap_trace_inuse[i] = 0;
508 		bzero(newbuf, (TRAP_TSIZE));
509 	} else if (newbuf == trap_tr0) {
510 		trap_tr0_inuse = 0;
511 		bzero(trap_tr0, (TRAP_TSIZE));
512 	} else {
513 		cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d",
514 		    cpuid);
515 	}
516 	bzero(ctlp, sizeof (*ctlp));
517 #endif /* TRAPTRACE */
518 
519 	/*
520 	 * There is a race condition with mutex_vector_enter() which
521 	 * caches a cpu pointer. The race is detected by checking cpu_next.
522 	 */
523 	disp_cpu_fini(cp);
524 	cpu_pa[cpuid] = 0;
525 	bzero(cp, sizeof (*cp));
526 
527 	/*
528 	 * Place the freed cpu structure on the list of freed cpus.
529 	 */
530 	if (cp != &cpu0) {
531 		if (cpus) {
532 			cp->cpu_next_free = cpus;
533 			cpus = cp;
534 		}
535 		else
536 			cpus = cp;
537 	}
538 
539 	return (0);
540 }
541 
542 /*
543  * This routine is used to start a previously powered off processor.
544  * Note that restarted cpus are initialized into the offline state.
545  */
546 void
547 restart_other_cpu(int cpuid)
548 {
549 	struct cpu *cp;
550 	kthread_id_t tp;
551 	caddr_t	sp;
552 	extern void idle();
553 
554 	ASSERT(MUTEX_HELD(&cpu_lock));
555 	ASSERT(cpuid < NCPU && cpu[cpuid] != NULL);
556 
557 	/*
558 	 * Obtain pointer to the appropriate cpu structure.
559 	 */
560 	cp = cpu[cpuid];
561 
562 	common_startup_init(cp, cpuid);
563 
564 	/*
565 	 * idle thread t_lock is held when the idle thread is suspended.
566 	 * Manually unlock the t_lock of idle loop so that we can resume
567 	 * the suspended idle thread.
568 	 * Also adjust the PC of idle thread for re-retry.
569 	 */
570 	cp->cpu_intr_actv = 0;	/* clear the value from previous life */
571 	cp->cpu_m.mutex_ready = 0; /* we are not ready yet */
572 	lock_clear(&cp->cpu_idle_thread->t_lock);
573 	tp = cp->cpu_idle_thread;
574 
575 	sp = tp->t_stk;
576 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
577 	tp->t_pc = (uintptr_t)idle - 8;
578 
579 	/*
580 	 * restart the cpu now
581 	 */
582 	promsafe_pause_cpus();
583 	start_cpu(cpuid, warm_flag_set);
584 	start_cpus();
585 
586 	/* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */
587 	cmn_err(CE_CONT, "!cpu%d initialization complete - restarted\n",
588 	    cpuid);
589 }
590 
591 /*
592  * Startup function executed on 'other' CPUs.  This is the first
593  * C function after cpu_start sets up the cpu registers.
594  */
595 static void
596 slave_startup(void)
597 {
598 	struct cpu	*cp = CPU;
599 	ushort_t	original_flags = cp->cpu_flags;
600 
601 	mach_htraptrace_configure(cp->cpu_id);
602 	cpu_intrq_register(CPU);
603 	cp->cpu_m.mutex_ready = 1;
604 	cp->cpu_m.poke_cpu_outstanding = B_FALSE;
605 
606 	/* acknowledge that we are done with initialization */
607 	CPUSET_ADD(proxy_ready_set, cp->cpu_id);
608 
609 	/* synchronize STICK */
610 	sticksync_slave();
611 
612 	if (boothowto & RB_DEBUG)
613 		kdi_dvec_cpu_init(cp);
614 
615 	/*
616 	 * the slave will wait here forever -- assuming that the master
617 	 * will get back to us.  if it doesn't we've got bigger problems
618 	 * than a master not replying to this slave.
619 	 * the small delay improves the slave's responsiveness to the
620 	 * master's ack and decreases the time window between master and
621 	 * slave operations.
622 	 */
623 	while (!CPU_IN_SET(cpu_ready_set, cp->cpu_id))
624 		DELAY(1);
625 
626 	/* enable interrupts */
627 	(void) spl0();
628 
629 	/*
630 	 * Signature block update to indicate that this CPU is in OS now.
631 	 * This needs to be done after the PIL is lowered since on
632 	 * some platforms the update code may block.
633 	 */
634 	CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cp->cpu_id);
635 
636 	/*
637 	 * park the slave thread in a safe/quiet state and wait for the master
638 	 * to finish configuring this CPU before proceeding to thread_exit().
639 	 */
640 	while (((volatile ushort_t)cp->cpu_flags) & CPU_QUIESCED)
641 		DELAY(1);
642 
643 	/*
644 	 * Initialize CPC CPU state.
645 	 */
646 	kcpc_hw_startup_cpu(original_flags);
647 
648 	/*
649 	 * Notify the CMT subsystem that the slave has started
650 	 */
651 	chip_cpu_startup(CPU);
652 
653 	/*
654 	 * Now we are done with the startup thread, so free it up.
655 	 */
656 	thread_exit();
657 	cmn_err(CE_PANIC, "slave_startup: cannot return");
658 	/*NOTREACHED*/
659 }
660 
661 /*
662  * 4163850 changes the allocation method for cpu structs. cpu structs
663  * are dynamically allocated. This routine now determines if additional
664  * per-cpu intr_req entries need to be allocated.
665  */
666 int
667 ndata_alloc_cpus(struct memlist *ndata)
668 {
669 	size_t real_sz;
670 	extern int niobus;
671 
672 	if (niobus > 1) {
673 
674 		/*
675 		 * Allocate additional intr_req entries if we have more than
676 		 * one io bus.  The memory to allocate is calculated from four
677 		 * variables: niobus, max_ncpus, intr_add_div, and intr_add_max.
678 		 * Allocate multiple of INTR_POOL_SIZE bytes (512).  Each cpu
679 		 * already reserves 512 bytes in its machcpu structure, so the
680 		 * worst case is (512 * (niobus - 1) * max_ncpus) add'l bytes.
681 		 *
682 		 * While niobus and max_ncpus reflect the h/w, the following
683 		 * may be tuned (before boot):
684 		 *
685 		 *	intr_add_div -	divisor for scaling the number of
686 		 *			additional intr_req entries. use '1'
687 		 *			for worst case memory, '2' for half,
688 		 *			etc.
689 		 *
690 		 *   intr_add_max - upper limit on bytes of memory to reserve
691 		 */
692 
693 		real_sz = INTR_POOL_SIZE * (niobus - 1) * max_ncpus;
694 
695 		/* tune memory usage by applying divisor and maximum */
696 
697 		if (intr_add_max == 0)
698 			intr_add_max = max_ncpus * INTR_POOL_SIZE;
699 		real_sz = MIN(intr_add_max, real_sz / MAX(intr_add_div, 1));
700 
701 		/* round down to multiple of (max_ncpus * INTR_POOL_SIZE) */
702 
703 		intr_add_pools = real_sz / (max_ncpus * INTR_POOL_SIZE);
704 		real_sz = intr_add_pools * (max_ncpus * INTR_POOL_SIZE);
705 
706 		/* actually reserve the space */
707 
708 		intr_add_head = ndata_alloc(ndata, real_sz, ecache_alignsize);
709 		if (intr_add_head == NULL)
710 			return (-1);
711 
712 		PRM_DEBUG(intr_add_head);
713 #ifdef	DEBUG
714 		intr_add_tail = (struct intr_req *)
715 		    ((uintptr_t)intr_add_head + real_sz);
716 #endif	/* DEBUG */
717 	}
718 
719 	return (0);
720 }
721 
722 
723 extern struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
724 
725 extern void setup_cpu_common(int);
726 extern void common_startup_init(cpu_t *, int);
727 extern void start_cpu(int, void(*func)(int));
728 extern void cold_flag_set(int cpuid);
729 
730 /*
731  * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that
732  * can be used during debugging to control which processors are brought
733  * online at boot time.  The variable represents a bitmap of the id's
734  * of the processors that will be brought online.  The initialization
735  * of this variable depends on the type of cpuset_t, which varies
736  * depending on the number of processors supported (see cpuvar.h).
737  */
738 cpuset_t cpu_bringup_set;
739 
740 
741 /*
742  * Generic start-all cpus entry.  Typically used during cold initialization.
743  * Note that cold start cpus are initialized into the online state.
744  */
745 /*ARGSUSED*/
746 void
747 start_other_cpus(int flag)
748 {
749 	int cpuid;
750 	extern void idlestop_init(void);
751 	int bootcpu;
752 
753 	/*
754 	 * Check if cpu_bringup_set has been explicitly set before
755 	 * initializing it.
756 	 */
757 	if (CPUSET_ISNULL(cpu_bringup_set)) {
758 #ifdef MPSAS
759 		/* just CPU 0 */
760 		CPUSET_ADD(cpu_bringup_set, 0);
761 #else
762 		CPUSET_ALL(cpu_bringup_set);
763 #endif
764 	}
765 
766 	if (&cpu_feature_init)
767 		cpu_feature_init();
768 
769 	/*
770 	 * Initialize CPC.
771 	 */
772 	kcpc_hw_init();
773 
774 	mutex_enter(&cpu_lock);
775 
776 	/*
777 	 * Initialize our own cpu_info.
778 	 */
779 	init_cpu_info(CPU);
780 
781 	/*
782 	 * Initialize CPU 0 cpu module private data area, including scrubber.
783 	 */
784 	cpu_init_private(CPU);
785 
786 	/*
787 	 * perform such initialization as is needed
788 	 * to be able to take CPUs on- and off-line.
789 	 */
790 	cpu_pause_init();
791 	xc_init();		/* initialize processor crosscalls */
792 	idlestop_init();
793 
794 	if (!use_mp) {
795 		mutex_exit(&cpu_lock);
796 		cmn_err(CE_CONT, "?***** Not in MP mode\n");
797 		return;
798 	}
799 	/*
800 	 * should we be initializing this cpu?
801 	 */
802 	bootcpu = getprocessorid();
803 
804 	/*
805 	 * launch all the slave cpus now
806 	 */
807 	for (cpuid = 0; cpuid < NCPU; cpuid++) {
808 		pnode_t nodeid = cpunodes[cpuid].nodeid;
809 
810 		if (nodeid == (pnode_t)0)
811 			continue;
812 
813 		if (cpuid == bootcpu) {
814 			if (!CPU_IN_SET(cpu_bringup_set, cpuid)) {
815 				cmn_err(CE_WARN, "boot cpu not a member "
816 				    "of cpu_bringup_set, adding it");
817 				CPUSET_ADD(cpu_bringup_set, cpuid);
818 			}
819 			continue;
820 		}
821 		if (!CPU_IN_SET(cpu_bringup_set, cpuid))
822 			continue;
823 
824 		ASSERT(cpu[cpuid] == NULL);
825 
826 		setup_cpu_common(cpuid);
827 
828 		common_startup_init(cpu[cpuid], cpuid);
829 
830 		start_cpu(cpuid, cold_flag_set);
831 		/*
832 		 * Because slave_startup() gets fired off after init()
833 		 * starts, we can't use the '?' trick to do 'boot -v'
834 		 * printing - so we always direct the 'cpu .. online'
835 		 * messages to the log.
836 		 */
837 		cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
838 		    cpuid);
839 
840 		/*
841 		 * XXX: register_cpu_setup() callbacks should be called here
842 		 * with a new setup code, CPU_BOOT (or something).
843 		 */
844 		if (dtrace_cpu_init != NULL)
845 			(*dtrace_cpu_init)(cpuid);
846 	}
847 
848 	/*
849 	 * since all the cpus are online now, redistribute interrupts to them.
850 	 */
851 	intr_redist_all_cpus();
852 
853 	mutex_exit(&cpu_lock);
854 
855 	/*
856 	 * Start the Ecache scrubber.  Must be done after all calls to
857 	 * cpu_init_private for every cpu (including CPU 0).
858 	 */
859 	cpu_init_cache_scrub();
860 
861 	if (&cpu_mp_init)
862 		cpu_mp_init();
863 }
864