xref: /titanic_41/usr/src/uts/sun4/os/mp_startup.c (revision 56a424cca6b3f91f31bdab72a4626c48c779fe8b)
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 	 * Initialize MMU context domain information.
437 	 */
438 	sfmmu_cpu_init(cp);
439 
440 }
441 
442 /*
443  * Routine to clean up a CPU after shutting it down.
444  */
445 int
446 cleanup_cpu_common(int cpuid)
447 {
448 	struct cpu *cp;
449 #ifdef TRAPTRACE
450 	int i;
451 	TRAP_TRACE_CTL	*ctlp;
452 	caddr_t	newbuf;
453 #endif /* TRAPTRACE */
454 
455 	ASSERT(MUTEX_HELD(&cpu_lock));
456 	ASSERT(cpu[cpuid] != NULL);
457 
458 	cp = cpu[cpuid];
459 
460 	/* Free cpu module private data structures, including scrubber. */
461 	cpu_uninit_private(cp);
462 
463 	/* Free cpu ID string and brand string. */
464 	kmem_free(cp->cpu_idstr, strlen(cp->cpu_idstr) + 1);
465 	kmem_free(cp->cpu_brandstr, strlen(cp->cpu_brandstr) + 1);
466 
467 	cpu_vm_data_destroy(cp);
468 
469 	/*
470 	 * Remove CPU from list of available CPUs.
471 	 */
472 	cpu_del_unit(cpuid);
473 
474 	/*
475 	 * Clean up the interrupt pool.
476 	 */
477 	cleanup_intr_pool(cp);
478 
479 	/*
480 	 * Clean any machine specific interrupt states.
481 	 */
482 	cpu_intrq_cleanup(cp);
483 
484 	/*
485 	 * At this point, the only threads bound to this CPU should be
486 	 * special per-cpu threads: it's idle thread, it's pause thread,
487 	 * and it's interrupt threads.  Clean these up.
488 	 */
489 	cpu_destroy_bound_threads(cp);
490 
491 	/*
492 	 * Free the interrupt stack.
493 	 */
494 	segkp_release(segkp, cp->cpu_intr_stack);
495 
496 	/*
497 	 * Free hv traptrace buffer for this CPU.
498 	 */
499 	mach_htraptrace_cleanup(cpuid);
500 #ifdef TRAPTRACE
501 	/*
502 	 * Free the traptrace buffer for this CPU.
503 	 */
504 	ctlp = &trap_trace_ctl[cpuid];
505 	newbuf = ctlp->d.vaddr_base;
506 	i = (newbuf - ttrace_buf) / (TRAP_TSIZE);
507 	if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) &&
508 	    ((i >= 0) && (i < (max_ncpus-1)))) {
509 		/*
510 		 * This CPU got it's trap trace buffer from the
511 		 * boot-alloc'd bunch of them.
512 		 */
513 		trap_trace_inuse[i] = 0;
514 		bzero(newbuf, (TRAP_TSIZE));
515 	} else if (newbuf == trap_tr0) {
516 		trap_tr0_inuse = 0;
517 		bzero(trap_tr0, (TRAP_TSIZE));
518 	} else {
519 		cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d",
520 		    cpuid);
521 	}
522 	bzero(ctlp, sizeof (*ctlp));
523 #endif /* TRAPTRACE */
524 
525 	/*
526 	 * There is a race condition with mutex_vector_enter() which
527 	 * caches a cpu pointer. The race is detected by checking cpu_next.
528 	 */
529 	disp_cpu_fini(cp);
530 	cpu_pa[cpuid] = 0;
531 	sfmmu_cpu_cleanup(cp);
532 	bzero(cp, sizeof (*cp));
533 
534 	/*
535 	 * Place the freed cpu structure on the list of freed cpus.
536 	 */
537 	if (cp != &cpu0) {
538 		if (cpus) {
539 			cp->cpu_next_free = cpus;
540 			cpus = cp;
541 		}
542 		else
543 			cpus = cp;
544 	}
545 
546 	return (0);
547 }
548 
549 /*
550  * This routine is used to start a previously powered off processor.
551  * Note that restarted cpus are initialized into the offline state.
552  */
553 void
554 restart_other_cpu(int cpuid)
555 {
556 	struct cpu *cp;
557 	kthread_id_t tp;
558 	caddr_t	sp;
559 	extern void idle();
560 
561 	ASSERT(MUTEX_HELD(&cpu_lock));
562 	ASSERT(cpuid < NCPU && cpu[cpuid] != NULL);
563 
564 	/*
565 	 * Obtain pointer to the appropriate cpu structure.
566 	 */
567 	cp = cpu[cpuid];
568 
569 	common_startup_init(cp, cpuid);
570 
571 	/*
572 	 * idle thread t_lock is held when the idle thread is suspended.
573 	 * Manually unlock the t_lock of idle loop so that we can resume
574 	 * the suspended idle thread.
575 	 * Also adjust the PC of idle thread for re-retry.
576 	 */
577 	cp->cpu_intr_actv = 0;	/* clear the value from previous life */
578 	cp->cpu_m.mutex_ready = 0; /* we are not ready yet */
579 	lock_clear(&cp->cpu_idle_thread->t_lock);
580 	tp = cp->cpu_idle_thread;
581 
582 	sp = tp->t_stk;
583 	tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
584 	tp->t_pc = (uintptr_t)idle - 8;
585 
586 	/*
587 	 * restart the cpu now
588 	 */
589 	promsafe_pause_cpus();
590 	start_cpu(cpuid, warm_flag_set);
591 	start_cpus();
592 
593 	/* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */
594 	cmn_err(CE_CONT, "!cpu%d initialization complete - restarted\n",
595 	    cpuid);
596 }
597 
598 /*
599  * Startup function executed on 'other' CPUs.  This is the first
600  * C function after cpu_start sets up the cpu registers.
601  */
602 static void
603 slave_startup(void)
604 {
605 	struct cpu	*cp = CPU;
606 	ushort_t	original_flags = cp->cpu_flags;
607 
608 	mach_htraptrace_configure(cp->cpu_id);
609 	cpu_intrq_register(CPU);
610 	cp->cpu_m.mutex_ready = 1;
611 	cp->cpu_m.poke_cpu_outstanding = B_FALSE;
612 
613 	/* acknowledge that we are done with initialization */
614 	CPUSET_ADD(proxy_ready_set, cp->cpu_id);
615 
616 	/* synchronize STICK */
617 	sticksync_slave();
618 
619 	if (boothowto & RB_DEBUG)
620 		kdi_dvec_cpu_init(cp);
621 
622 	/*
623 	 * the slave will wait here forever -- assuming that the master
624 	 * will get back to us.  if it doesn't we've got bigger problems
625 	 * than a master not replying to this slave.
626 	 * the small delay improves the slave's responsiveness to the
627 	 * master's ack and decreases the time window between master and
628 	 * slave operations.
629 	 */
630 	while (!CPU_IN_SET(cpu_ready_set, cp->cpu_id))
631 		DELAY(1);
632 
633 	/* enable interrupts */
634 	(void) spl0();
635 
636 	/*
637 	 * Signature block update to indicate that this CPU is in OS now.
638 	 * This needs to be done after the PIL is lowered since on
639 	 * some platforms the update code may block.
640 	 */
641 	CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cp->cpu_id);
642 
643 	/*
644 	 * park the slave thread in a safe/quiet state and wait for the master
645 	 * to finish configuring this CPU before proceeding to thread_exit().
646 	 */
647 	while (((volatile ushort_t)cp->cpu_flags) & CPU_QUIESCED)
648 		DELAY(1);
649 
650 	/*
651 	 * Initialize CPC CPU state.
652 	 */
653 	kcpc_hw_startup_cpu(original_flags);
654 
655 	/*
656 	 * Notify the CMT subsystem that the slave has started
657 	 */
658 	chip_cpu_startup(CPU);
659 
660 	/*
661 	 * Now we are done with the startup thread, so free it up.
662 	 */
663 	thread_exit();
664 	cmn_err(CE_PANIC, "slave_startup: cannot return");
665 	/*NOTREACHED*/
666 }
667 
668 /*
669  * 4163850 changes the allocation method for cpu structs. cpu structs
670  * are dynamically allocated. This routine now determines if additional
671  * per-cpu intr_req entries need to be allocated.
672  */
673 int
674 ndata_alloc_cpus(struct memlist *ndata)
675 {
676 	size_t real_sz;
677 	extern int niobus;
678 
679 	if (niobus > 1) {
680 
681 		/*
682 		 * Allocate additional intr_req entries if we have more than
683 		 * one io bus.  The memory to allocate is calculated from four
684 		 * variables: niobus, max_ncpus, intr_add_div, and intr_add_max.
685 		 * Allocate multiple of INTR_POOL_SIZE bytes (512).  Each cpu
686 		 * already reserves 512 bytes in its machcpu structure, so the
687 		 * worst case is (512 * (niobus - 1) * max_ncpus) add'l bytes.
688 		 *
689 		 * While niobus and max_ncpus reflect the h/w, the following
690 		 * may be tuned (before boot):
691 		 *
692 		 *	intr_add_div -	divisor for scaling the number of
693 		 *			additional intr_req entries. use '1'
694 		 *			for worst case memory, '2' for half,
695 		 *			etc.
696 		 *
697 		 *   intr_add_max - upper limit on bytes of memory to reserve
698 		 */
699 
700 		real_sz = INTR_POOL_SIZE * (niobus - 1) * max_ncpus;
701 
702 		/* tune memory usage by applying divisor and maximum */
703 
704 		if (intr_add_max == 0)
705 			intr_add_max = max_ncpus * INTR_POOL_SIZE;
706 		real_sz = MIN(intr_add_max, real_sz / MAX(intr_add_div, 1));
707 
708 		/* round down to multiple of (max_ncpus * INTR_POOL_SIZE) */
709 
710 		intr_add_pools = real_sz / (max_ncpus * INTR_POOL_SIZE);
711 		real_sz = intr_add_pools * (max_ncpus * INTR_POOL_SIZE);
712 
713 		/* actually reserve the space */
714 
715 		intr_add_head = ndata_alloc(ndata, real_sz, ecache_alignsize);
716 		if (intr_add_head == NULL)
717 			return (-1);
718 
719 		PRM_DEBUG(intr_add_head);
720 #ifdef	DEBUG
721 		intr_add_tail = (struct intr_req *)
722 		    ((uintptr_t)intr_add_head + real_sz);
723 #endif	/* DEBUG */
724 	}
725 
726 	return (0);
727 }
728 
729 
730 extern struct cpu	*cpu[NCPU];	/* pointers to all CPUs */
731 
732 extern void setup_cpu_common(int);
733 extern void common_startup_init(cpu_t *, int);
734 extern void start_cpu(int, void(*func)(int));
735 extern void cold_flag_set(int cpuid);
736 
737 /*
738  * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that
739  * can be used during debugging to control which processors are brought
740  * online at boot time.  The variable represents a bitmap of the id's
741  * of the processors that will be brought online.  The initialization
742  * of this variable depends on the type of cpuset_t, which varies
743  * depending on the number of processors supported (see cpuvar.h).
744  */
745 cpuset_t cpu_bringup_set;
746 
747 
748 /*
749  * Generic start-all cpus entry.  Typically used during cold initialization.
750  * Note that cold start cpus are initialized into the online state.
751  */
752 /*ARGSUSED*/
753 void
754 start_other_cpus(int flag)
755 {
756 	int cpuid;
757 	extern void idlestop_init(void);
758 	int bootcpu;
759 
760 	/*
761 	 * Check if cpu_bringup_set has been explicitly set before
762 	 * initializing it.
763 	 */
764 	if (CPUSET_ISNULL(cpu_bringup_set)) {
765 #ifdef MPSAS
766 		/* just CPU 0 */
767 		CPUSET_ADD(cpu_bringup_set, 0);
768 #else
769 		CPUSET_ALL(cpu_bringup_set);
770 #endif
771 	}
772 
773 	if (&cpu_feature_init)
774 		cpu_feature_init();
775 
776 	/*
777 	 * Initialize CPC.
778 	 */
779 	kcpc_hw_init();
780 
781 	mutex_enter(&cpu_lock);
782 
783 	/*
784 	 * Initialize our own cpu_info.
785 	 */
786 	init_cpu_info(CPU);
787 
788 	/*
789 	 * Initialize CPU 0 cpu module private data area, including scrubber.
790 	 */
791 	cpu_init_private(CPU);
792 
793 	/*
794 	 * perform such initialization as is needed
795 	 * to be able to take CPUs on- and off-line.
796 	 */
797 	cpu_pause_init();
798 	xc_init();		/* initialize processor crosscalls */
799 	idlestop_init();
800 
801 	if (!use_mp) {
802 		mutex_exit(&cpu_lock);
803 		cmn_err(CE_CONT, "?***** Not in MP mode\n");
804 		return;
805 	}
806 	/*
807 	 * should we be initializing this cpu?
808 	 */
809 	bootcpu = getprocessorid();
810 
811 	/*
812 	 * launch all the slave cpus now
813 	 */
814 	for (cpuid = 0; cpuid < NCPU; cpuid++) {
815 		pnode_t nodeid = cpunodes[cpuid].nodeid;
816 
817 		if (nodeid == (pnode_t)0)
818 			continue;
819 
820 		if (cpuid == bootcpu) {
821 			if (!CPU_IN_SET(cpu_bringup_set, cpuid)) {
822 				cmn_err(CE_WARN, "boot cpu not a member "
823 				    "of cpu_bringup_set, adding it");
824 				CPUSET_ADD(cpu_bringup_set, cpuid);
825 			}
826 			continue;
827 		}
828 		if (!CPU_IN_SET(cpu_bringup_set, cpuid))
829 			continue;
830 
831 		ASSERT(cpu[cpuid] == NULL);
832 
833 		setup_cpu_common(cpuid);
834 
835 		common_startup_init(cpu[cpuid], cpuid);
836 
837 		start_cpu(cpuid, cold_flag_set);
838 		/*
839 		 * Because slave_startup() gets fired off after init()
840 		 * starts, we can't use the '?' trick to do 'boot -v'
841 		 * printing - so we always direct the 'cpu .. online'
842 		 * messages to the log.
843 		 */
844 		cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
845 		    cpuid);
846 
847 		/*
848 		 * XXX: register_cpu_setup() callbacks should be called here
849 		 * with a new setup code, CPU_BOOT (or something).
850 		 */
851 		if (dtrace_cpu_init != NULL)
852 			(*dtrace_cpu_init)(cpuid);
853 	}
854 
855 	/*
856 	 * since all the cpus are online now, redistribute interrupts to them.
857 	 */
858 	intr_redist_all_cpus();
859 
860 	mutex_exit(&cpu_lock);
861 
862 	/*
863 	 * Start the Ecache scrubber.  Must be done after all calls to
864 	 * cpu_init_private for every cpu (including CPU 0).
865 	 */
866 	cpu_init_cache_scrub();
867 
868 	if (&cpu_mp_init)
869 		cpu_mp_init();
870 }
871