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