17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5100b72f4Sandrei * Common Development and Distribution License (the "License"). 6100b72f4Sandrei * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 211ae08745Sheppo 227c478bd9Sstevel@tonic-gate /* 23*8390fbf8SRafael Vanoni * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 287c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 297c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h> 307c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 317c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h> 327c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 337c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 347c478bd9Sstevel@tonic-gate #include <sys/callb.h> 357c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h> 36fb2f18f8Sesaxe #include <sys/pg.h> 37fb2f18f8Sesaxe #include <sys/cmt.h> 387c478bd9Sstevel@tonic-gate #include <sys/dtrace.h> 397c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 407c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 417c478bd9Sstevel@tonic-gate #include <sys/traptrace.h> 42db6d2ee3Ssvemuri #ifdef TRAPTRACE 437c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 447c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 457c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 467c478bd9Sstevel@tonic-gate 47982b9107Sjb145095 extern int cpu_intrq_setup(struct cpu *); 481ae08745Sheppo extern void cpu_intrq_cleanup(struct cpu *); 497c478bd9Sstevel@tonic-gate extern void cpu_intrq_register(struct cpu *); 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate struct cpu *cpus; /* pointer to other cpus; dynamically allocate */ 527c478bd9Sstevel@tonic-gate struct cpu *cpu[NCPU]; /* pointers to all CPUs */ 537c478bd9Sstevel@tonic-gate uint64_t cpu_pa[NCPU]; /* pointers to all CPUs in PA */ 547c478bd9Sstevel@tonic-gate cpu_core_t cpu_core[NCPU]; /* cpu_core structures */ 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 57986fd29aSsetje caddr_t ttrace_buf; /* kmem64 traptrace for all cpus except 0 */ 587c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* bit mask of cpus ready for x-calls, protected by cpu_lock */ 617c478bd9Sstevel@tonic-gate cpuset_t cpu_ready_set; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* bit mask used to communicate with cpus during bringup */ 647c478bd9Sstevel@tonic-gate static cpuset_t proxy_ready_set; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate static void slave_startup(void); 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * Defined in $KARCH/os/mach_mp_startup.c 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate #pragma weak init_cpu_info 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * Amount of time (in milliseconds) we should wait before giving up on CPU 757c478bd9Sstevel@tonic-gate * initialization and assuming that the CPU we're trying to wake up is dead 767c478bd9Sstevel@tonic-gate * or out of control. 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate #define CPU_WAKEUP_GRACE_MSEC 1000 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 817c478bd9Sstevel@tonic-gate /* 82bb121940Sdp78419 * This function sets traptrace buffers for all cpus 837c478bd9Sstevel@tonic-gate * other than boot cpu. 847c478bd9Sstevel@tonic-gate */ 85986fd29aSsetje size_t 86986fd29aSsetje calc_traptrace_sz(void) 877c478bd9Sstevel@tonic-gate { 88986fd29aSsetje return (TRAP_TSIZE * (max_ncpus - 1)); 897c478bd9Sstevel@tonic-gate } 907c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 917c478bd9Sstevel@tonic-gate 92986fd29aSsetje 937c478bd9Sstevel@tonic-gate /* 947c478bd9Sstevel@tonic-gate * common slave cpu initialization code 957c478bd9Sstevel@tonic-gate */ 967c478bd9Sstevel@tonic-gate void 977c478bd9Sstevel@tonic-gate common_startup_init(cpu_t *cp, int cpuid) 987c478bd9Sstevel@tonic-gate { 997c478bd9Sstevel@tonic-gate kthread_id_t tp; 1007c478bd9Sstevel@tonic-gate sfmmu_t *sfmmup; 1017c478bd9Sstevel@tonic-gate caddr_t sp; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Allocate and initialize the startup thread for this CPU. 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate tp = thread_create(NULL, 0, slave_startup, NULL, 0, &p0, 1077c478bd9Sstevel@tonic-gate TS_STOPPED, maxclsyspri); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* 1107c478bd9Sstevel@tonic-gate * Set state to TS_ONPROC since this thread will start running 1117c478bd9Sstevel@tonic-gate * as soon as the CPU comes online. 1127c478bd9Sstevel@tonic-gate * 1137c478bd9Sstevel@tonic-gate * All the other fields of the thread structure are setup by 1147c478bd9Sstevel@tonic-gate * thread_create(). 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate THREAD_ONPROC(tp, cp); 1177c478bd9Sstevel@tonic-gate tp->t_preempt = 1; 1187c478bd9Sstevel@tonic-gate tp->t_bound_cpu = cp; 1197c478bd9Sstevel@tonic-gate tp->t_affinitycnt = 1; 1207c478bd9Sstevel@tonic-gate tp->t_cpu = cp; 1217c478bd9Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate sfmmup = astosfmmu(&kas); 1247c478bd9Sstevel@tonic-gate CPUSET_ADD(sfmmup->sfmmu_cpusran, cpuid); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * Setup thread to start in slave_startup. 1287c478bd9Sstevel@tonic-gate */ 1297c478bd9Sstevel@tonic-gate sp = tp->t_stk; 1307c478bd9Sstevel@tonic-gate tp->t_pc = (uintptr_t)slave_startup - 8; 1317c478bd9Sstevel@tonic-gate tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate cp->cpu_id = cpuid; 1347c478bd9Sstevel@tonic-gate cp->cpu_self = cp; 1357c478bd9Sstevel@tonic-gate cp->cpu_thread = tp; 1367c478bd9Sstevel@tonic-gate cp->cpu_lwp = NULL; 1377c478bd9Sstevel@tonic-gate cp->cpu_dispthread = tp; 1387c478bd9Sstevel@tonic-gate cp->cpu_dispatch_pri = DISP_PRIO(tp); 1399d7041eeSandrei cp->cpu_startup_thread = tp; 140*8390fbf8SRafael Vanoni 141*8390fbf8SRafael Vanoni /* 142*8390fbf8SRafael Vanoni * The dispatcher may discover the CPU before it is in cpu_ready_set 143*8390fbf8SRafael Vanoni * and attempt to poke it. Before the CPU is in cpu_ready_set, any 144*8390fbf8SRafael Vanoni * cross calls to it will be dropped. We initialize 145*8390fbf8SRafael Vanoni * poke_cpu_outstanding to true so that poke_cpu will ignore any poke 146*8390fbf8SRafael Vanoni * requests for this CPU. Pokes that come in before the CPU is in 147*8390fbf8SRafael Vanoni * cpu_ready_set can be ignored because the CPU is about to come 148*8390fbf8SRafael Vanoni * online. 149*8390fbf8SRafael Vanoni */ 150*8390fbf8SRafael Vanoni cp->cpu_m.poke_cpu_outstanding = B_TRUE; 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* 1547c478bd9Sstevel@tonic-gate * parametric flag setting functions. these routines set the cpu 1557c478bd9Sstevel@tonic-gate * state just prior to releasing the slave cpu. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate void 1587c478bd9Sstevel@tonic-gate cold_flag_set(int cpuid) 1597c478bd9Sstevel@tonic-gate { 1607c478bd9Sstevel@tonic-gate cpu_t *cp; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate cp = cpu[cpuid]; 1657c478bd9Sstevel@tonic-gate cp->cpu_flags |= CPU_RUNNING | CPU_ENABLE | CPU_EXISTS; 1667c478bd9Sstevel@tonic-gate cpu_add_active(cp); 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * Add CPU_READY after the cpu_add_active() call 1697c478bd9Sstevel@tonic-gate * to avoid pausing cp. 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate cp->cpu_flags |= CPU_READY; /* ready */ 1727c478bd9Sstevel@tonic-gate cpu_set_state(cp); 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate static void 1767c478bd9Sstevel@tonic-gate warm_flag_set(int cpuid) 1777c478bd9Sstevel@tonic-gate { 1787c478bd9Sstevel@tonic-gate cpu_t *cp; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate /* 1837c478bd9Sstevel@tonic-gate * warm start activates cpus into the OFFLINE state 1847c478bd9Sstevel@tonic-gate */ 1857c478bd9Sstevel@tonic-gate cp = cpu[cpuid]; 1867c478bd9Sstevel@tonic-gate cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_EXISTS 1877c478bd9Sstevel@tonic-gate | CPU_OFFLINE | CPU_QUIESCED; 1887c478bd9Sstevel@tonic-gate cpu_set_state(cp); 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Internal cpu startup sequencer 1937c478bd9Sstevel@tonic-gate * The sequence is as follows: 1947c478bd9Sstevel@tonic-gate * 1957c478bd9Sstevel@tonic-gate * MASTER SLAVE 1967c478bd9Sstevel@tonic-gate * ------- ---------- 1977c478bd9Sstevel@tonic-gate * assume the kernel data is initialized 1987c478bd9Sstevel@tonic-gate * clear the proxy bit 1997c478bd9Sstevel@tonic-gate * start the slave cpu 2007c478bd9Sstevel@tonic-gate * wait for the slave cpu to set the proxy 2017c478bd9Sstevel@tonic-gate * 2027c478bd9Sstevel@tonic-gate * the slave runs slave_startup and then sets the proxy 2037c478bd9Sstevel@tonic-gate * the slave waits for the master to add slave to the ready set 2047c478bd9Sstevel@tonic-gate * 2057c478bd9Sstevel@tonic-gate * the master finishes the initialization and 2067c478bd9Sstevel@tonic-gate * adds the slave to the ready set 2077c478bd9Sstevel@tonic-gate * 2087c478bd9Sstevel@tonic-gate * the slave exits the startup thread and is running 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate void 2117c478bd9Sstevel@tonic-gate start_cpu(int cpuid, void(*flag_func)(int)) 2127c478bd9Sstevel@tonic-gate { 21341f63f87Spetede extern void cpu_startup(int); 2147c478bd9Sstevel@tonic-gate int timout; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate /* 2197c478bd9Sstevel@tonic-gate * Before we begin the dance, tell DTrace that we're about to start 2207c478bd9Sstevel@tonic-gate * a CPU. 2217c478bd9Sstevel@tonic-gate */ 2227c478bd9Sstevel@tonic-gate if (dtrace_cpustart_init != NULL) 2237c478bd9Sstevel@tonic-gate (*dtrace_cpustart_init)(); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate /* start the slave cpu */ 2267c478bd9Sstevel@tonic-gate CPUSET_DEL(proxy_ready_set, cpuid); 2277c478bd9Sstevel@tonic-gate if (prom_test("SUNW,start-cpu-by-cpuid") == 0) { 2287c478bd9Sstevel@tonic-gate (void) prom_startcpu_bycpuid(cpuid, (caddr_t)&cpu_startup, 2297c478bd9Sstevel@tonic-gate cpuid); 2307c478bd9Sstevel@tonic-gate } else { 2317c478bd9Sstevel@tonic-gate /* "by-cpuid" interface didn't exist. Do it the old way */ 232fa9e4066Sahrens pnode_t nodeid = cpunodes[cpuid].nodeid; 2337c478bd9Sstevel@tonic-gate 234fa9e4066Sahrens ASSERT(nodeid != (pnode_t)0); 2357c478bd9Sstevel@tonic-gate (void) prom_startcpu(nodeid, (caddr_t)&cpu_startup, cpuid); 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* wait for the slave cpu to check in. */ 2397c478bd9Sstevel@tonic-gate for (timout = CPU_WAKEUP_GRACE_MSEC; timout; timout--) { 2407c478bd9Sstevel@tonic-gate if (CPU_IN_SET(proxy_ready_set, cpuid)) 2417c478bd9Sstevel@tonic-gate break; 2427c478bd9Sstevel@tonic-gate DELAY(1000); 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate if (timout == 0) { 2457c478bd9Sstevel@tonic-gate panic("cpu%d failed to start (2)", cpuid); 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /* 2497c478bd9Sstevel@tonic-gate * The slave has started; we can tell DTrace that it's safe again. 2507c478bd9Sstevel@tonic-gate */ 2517c478bd9Sstevel@tonic-gate if (dtrace_cpustart_fini != NULL) 2527c478bd9Sstevel@tonic-gate (*dtrace_cpustart_fini)(); 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate /* run the master side of stick synchronization for the slave cpu */ 2557c478bd9Sstevel@tonic-gate sticksync_master(); 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate /* 2587c478bd9Sstevel@tonic-gate * deal with the cpu flags in a phase-specific manner 2597c478bd9Sstevel@tonic-gate * for various reasons, this needs to run after the slave 2607c478bd9Sstevel@tonic-gate * is checked in but before the slave is released. 2617c478bd9Sstevel@tonic-gate */ 2627c478bd9Sstevel@tonic-gate (*flag_func)(cpuid); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* release the slave */ 2657c478bd9Sstevel@tonic-gate CPUSET_ADD(cpu_ready_set, cpuid); 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 2697c478bd9Sstevel@tonic-gate int trap_tr0_inuse = 1; /* it is always used on the boot cpu */ 2707c478bd9Sstevel@tonic-gate int trap_trace_inuse[NCPU]; 2717c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate #define cpu_next_free cpu_prev 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate /* 2767c478bd9Sstevel@tonic-gate * Routine to set up a CPU to prepare for starting it up. 2777c478bd9Sstevel@tonic-gate */ 278982b9107Sjb145095 int 2797c478bd9Sstevel@tonic-gate setup_cpu_common(int cpuid) 2807c478bd9Sstevel@tonic-gate { 2817c478bd9Sstevel@tonic-gate struct cpu *cp = NULL; 2827c478bd9Sstevel@tonic-gate kthread_id_t tp; 2837c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 2847c478bd9Sstevel@tonic-gate int tt_index; 2857c478bd9Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp; 2867c478bd9Sstevel@tonic-gate caddr_t newbuf; 2877c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate extern void idle(); 290982b9107Sjb145095 int rval; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 2937c478bd9Sstevel@tonic-gate ASSERT(cpu[cpuid] == NULL); 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate ASSERT(ncpus <= max_ncpus); 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 2987c478bd9Sstevel@tonic-gate /* 2997c478bd9Sstevel@tonic-gate * allocate a traptrace buffer for this CPU. 3007c478bd9Sstevel@tonic-gate */ 3017c478bd9Sstevel@tonic-gate ctlp = &trap_trace_ctl[cpuid]; 3027c478bd9Sstevel@tonic-gate if (!trap_tr0_inuse) { 3037c478bd9Sstevel@tonic-gate trap_tr0_inuse = 1; 3047c478bd9Sstevel@tonic-gate newbuf = trap_tr0; 3057c478bd9Sstevel@tonic-gate tt_index = -1; 3067c478bd9Sstevel@tonic-gate } else { 3077c478bd9Sstevel@tonic-gate for (tt_index = 0; tt_index < (max_ncpus-1); tt_index++) 3087c478bd9Sstevel@tonic-gate if (!trap_trace_inuse[tt_index]) 3097c478bd9Sstevel@tonic-gate break; 3107c478bd9Sstevel@tonic-gate ASSERT(tt_index < max_ncpus - 1); 3117c478bd9Sstevel@tonic-gate trap_trace_inuse[tt_index] = 1; 312db6d2ee3Ssvemuri newbuf = (caddr_t)(ttrace_buf + (tt_index * TRAP_TSIZE)); 3137c478bd9Sstevel@tonic-gate } 3147c478bd9Sstevel@tonic-gate ctlp->d.vaddr_base = newbuf; 3157c478bd9Sstevel@tonic-gate ctlp->d.offset = ctlp->d.last_offset = 0; 3167c478bd9Sstevel@tonic-gate ctlp->d.limit = trap_trace_bufsize; 3177c478bd9Sstevel@tonic-gate ctlp->d.paddr_base = va_to_pa(newbuf); 3187c478bd9Sstevel@tonic-gate ASSERT(ctlp->d.paddr_base != (uint64_t)-1); 3197c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 320db6d2ee3Ssvemuri /* 321db6d2ee3Ssvemuri * initialize hv traptrace buffer for this CPU 322db6d2ee3Ssvemuri */ 323db6d2ee3Ssvemuri mach_htraptrace_setup(cpuid); 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* 3267c478bd9Sstevel@tonic-gate * Obtain pointer to the appropriate cpu structure. 3277c478bd9Sstevel@tonic-gate */ 3287c478bd9Sstevel@tonic-gate if (cpu0.cpu_flags == 0) { 3297c478bd9Sstevel@tonic-gate cp = &cpu0; 3307c478bd9Sstevel@tonic-gate } else { 3317c478bd9Sstevel@tonic-gate /* 3327c478bd9Sstevel@tonic-gate * When dynamically allocating cpu structs, 3337c478bd9Sstevel@tonic-gate * cpus is used as a pointer to a list of freed 3347c478bd9Sstevel@tonic-gate * cpu structs. 3357c478bd9Sstevel@tonic-gate */ 3367c478bd9Sstevel@tonic-gate if (cpus) { 3377c478bd9Sstevel@tonic-gate /* grab the first cpu struct on the free list */ 3387c478bd9Sstevel@tonic-gate cp = cpus; 3397c478bd9Sstevel@tonic-gate if (cp->cpu_next_free) 3407c478bd9Sstevel@tonic-gate cpus = cp->cpu_next_free; 3417c478bd9Sstevel@tonic-gate else 3427c478bd9Sstevel@tonic-gate cpus = NULL; 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate if (cp == NULL) 3477c478bd9Sstevel@tonic-gate cp = vmem_xalloc(static_alloc_arena, CPU_ALLOC_SIZE, 3487c478bd9Sstevel@tonic-gate CPU_ALLOC_SIZE, 0, 0, NULL, NULL, VM_SLEEP); 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate bzero(cp, sizeof (*cp)); 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate cp->cpu_id = cpuid; 3537c478bd9Sstevel@tonic-gate cp->cpu_self = cp; 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate /* 3567c478bd9Sstevel@tonic-gate * Initialize ptl1_panic stack 3577c478bd9Sstevel@tonic-gate */ 3587c478bd9Sstevel@tonic-gate ptl1_init_cpu(cp); 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate /* 3617c478bd9Sstevel@tonic-gate * Initialize the dispatcher for this CPU. 3627c478bd9Sstevel@tonic-gate */ 3637c478bd9Sstevel@tonic-gate disp_cpu_init(cp); 3647c478bd9Sstevel@tonic-gate 36547ab0c7cSEric Saxe /* 36647ab0c7cSEric Saxe * Bootstrap the CPU's PG data 36747ab0c7cSEric Saxe */ 36847ab0c7cSEric Saxe pg_cpu_bootstrap(cp); 36947ab0c7cSEric Saxe 370affbd3ccSkchow cpu_vm_data_init(cp); 371affbd3ccSkchow 3727c478bd9Sstevel@tonic-gate /* 3737c478bd9Sstevel@tonic-gate * Now, initialize per-CPU idle thread for this CPU. 3747c478bd9Sstevel@tonic-gate */ 3757c478bd9Sstevel@tonic-gate tp = thread_create(NULL, 0, idle, NULL, 0, &p0, TS_ONPROC, -1); 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate cp->cpu_idle_thread = tp; 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate tp->t_preempt = 1; 3807c478bd9Sstevel@tonic-gate tp->t_bound_cpu = cp; 3817c478bd9Sstevel@tonic-gate tp->t_affinitycnt = 1; 3827c478bd9Sstevel@tonic-gate tp->t_cpu = cp; 3837c478bd9Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp; 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate /* 3867c478bd9Sstevel@tonic-gate * Registering a thread in the callback table is usually 3877c478bd9Sstevel@tonic-gate * done in the initialization code of the thread. In this 3887c478bd9Sstevel@tonic-gate * case, we do it right after thread creation to avoid 3897c478bd9Sstevel@tonic-gate * blocking idle thread while registering itself. It also 3907c478bd9Sstevel@tonic-gate * avoids the possibility of reregistration in case a CPU 3917c478bd9Sstevel@tonic-gate * restarts its idle thread. 3927c478bd9Sstevel@tonic-gate */ 3937c478bd9Sstevel@tonic-gate CALLB_CPR_INIT_SAFE(tp, "idle"); 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate init_cpu_info(cp); 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate /* 3987c478bd9Sstevel@tonic-gate * Initialize the interrupt threads for this CPU 3997c478bd9Sstevel@tonic-gate */ 400100b72f4Sandrei cpu_intr_alloc(cp, NINTR_THREADS); 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate /* 40370f54eadSesaxe * Add CPU to list of available CPUs. 40470f54eadSesaxe * It'll be on the active list after it is started. 4057c478bd9Sstevel@tonic-gate */ 4067c478bd9Sstevel@tonic-gate cpu_add_unit(cp); 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate /* 4097c478bd9Sstevel@tonic-gate * Allocate and init cpu module private data structures, 4107c478bd9Sstevel@tonic-gate * including scrubber. 4117c478bd9Sstevel@tonic-gate */ 4127c478bd9Sstevel@tonic-gate cpu_init_private(cp); 4132f0fcb93SJason Beloro populate_idstr(cp); 4147c478bd9Sstevel@tonic-gate 41570f54eadSesaxe /* 416fb2f18f8Sesaxe * Initialize the CPUs physical ID cache, and processor groups 41770f54eadSesaxe */ 418fb2f18f8Sesaxe pghw_physid_create(cp); 419023e71deSHaik Aftandilian (void) pg_cpu_init(cp, B_FALSE); 420fb2f18f8Sesaxe 421982b9107Sjb145095 if ((rval = cpu_intrq_setup(cp)) != 0) { 422982b9107Sjb145095 return (rval); 423982b9107Sjb145095 } 4241e2e7a75Shuah 4251e2e7a75Shuah /* 4261e2e7a75Shuah * Initialize MMU context domain information. 4271e2e7a75Shuah */ 4281e2e7a75Shuah sfmmu_cpu_init(cp); 4291e2e7a75Shuah 430982b9107Sjb145095 return (0); 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate /* 4347c478bd9Sstevel@tonic-gate * Routine to clean up a CPU after shutting it down. 4357c478bd9Sstevel@tonic-gate */ 4367c478bd9Sstevel@tonic-gate int 4377c478bd9Sstevel@tonic-gate cleanup_cpu_common(int cpuid) 4387c478bd9Sstevel@tonic-gate { 4397c478bd9Sstevel@tonic-gate struct cpu *cp; 4407c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 4417c478bd9Sstevel@tonic-gate int i; 4427c478bd9Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp; 4437c478bd9Sstevel@tonic-gate caddr_t newbuf; 4447c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 4477c478bd9Sstevel@tonic-gate ASSERT(cpu[cpuid] != NULL); 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate cp = cpu[cpuid]; 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate /* Free cpu module private data structures, including scrubber. */ 4527c478bd9Sstevel@tonic-gate cpu_uninit_private(cp); 4537c478bd9Sstevel@tonic-gate 45451243c37Srab /* Free cpu ID string and brand string. */ 455982b9107Sjb145095 if (cp->cpu_idstr) 45651243c37Srab kmem_free(cp->cpu_idstr, strlen(cp->cpu_idstr) + 1); 457982b9107Sjb145095 if (cp->cpu_brandstr) 45851243c37Srab kmem_free(cp->cpu_brandstr, strlen(cp->cpu_brandstr) + 1); 45951243c37Srab 460affbd3ccSkchow cpu_vm_data_destroy(cp); 461affbd3ccSkchow 4627c478bd9Sstevel@tonic-gate /* 4637c478bd9Sstevel@tonic-gate * Remove CPU from list of available CPUs. 4647c478bd9Sstevel@tonic-gate */ 4657c478bd9Sstevel@tonic-gate cpu_del_unit(cpuid); 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate /* 4681ae08745Sheppo * Clean any machine specific interrupt states. 4691ae08745Sheppo */ 4701ae08745Sheppo cpu_intrq_cleanup(cp); 4711ae08745Sheppo 4721ae08745Sheppo /* 4737c478bd9Sstevel@tonic-gate * At this point, the only threads bound to this CPU should be 4747c478bd9Sstevel@tonic-gate * special per-cpu threads: it's idle thread, it's pause thread, 4757c478bd9Sstevel@tonic-gate * and it's interrupt threads. Clean these up. 4767c478bd9Sstevel@tonic-gate */ 4777c478bd9Sstevel@tonic-gate cpu_destroy_bound_threads(cp); 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /* 4807c478bd9Sstevel@tonic-gate * Free the interrupt stack. 4817c478bd9Sstevel@tonic-gate */ 4827c478bd9Sstevel@tonic-gate segkp_release(segkp, cp->cpu_intr_stack); 4837c478bd9Sstevel@tonic-gate 484db6d2ee3Ssvemuri /* 485db6d2ee3Ssvemuri * Free hv traptrace buffer for this CPU. 486db6d2ee3Ssvemuri */ 487db6d2ee3Ssvemuri mach_htraptrace_cleanup(cpuid); 4887c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 4897c478bd9Sstevel@tonic-gate /* 4907c478bd9Sstevel@tonic-gate * Free the traptrace buffer for this CPU. 4917c478bd9Sstevel@tonic-gate */ 4927c478bd9Sstevel@tonic-gate ctlp = &trap_trace_ctl[cpuid]; 4937c478bd9Sstevel@tonic-gate newbuf = ctlp->d.vaddr_base; 494db6d2ee3Ssvemuri i = (newbuf - ttrace_buf) / (TRAP_TSIZE); 495db6d2ee3Ssvemuri if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) && 4967c478bd9Sstevel@tonic-gate ((i >= 0) && (i < (max_ncpus-1)))) { 4977c478bd9Sstevel@tonic-gate /* 4987c478bd9Sstevel@tonic-gate * This CPU got it's trap trace buffer from the 4997c478bd9Sstevel@tonic-gate * boot-alloc'd bunch of them. 5007c478bd9Sstevel@tonic-gate */ 5017c478bd9Sstevel@tonic-gate trap_trace_inuse[i] = 0; 502db6d2ee3Ssvemuri bzero(newbuf, (TRAP_TSIZE)); 5037c478bd9Sstevel@tonic-gate } else if (newbuf == trap_tr0) { 5047c478bd9Sstevel@tonic-gate trap_tr0_inuse = 0; 505db6d2ee3Ssvemuri bzero(trap_tr0, (TRAP_TSIZE)); 5067c478bd9Sstevel@tonic-gate } else { 5077c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d", 5087c478bd9Sstevel@tonic-gate cpuid); 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate bzero(ctlp, sizeof (*ctlp)); 5117c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate /* 5147c478bd9Sstevel@tonic-gate * There is a race condition with mutex_vector_enter() which 5157c478bd9Sstevel@tonic-gate * caches a cpu pointer. The race is detected by checking cpu_next. 5167c478bd9Sstevel@tonic-gate */ 5177c478bd9Sstevel@tonic-gate disp_cpu_fini(cp); 5187c478bd9Sstevel@tonic-gate cpu_pa[cpuid] = 0; 519982b9107Sjb145095 if (CPU_MMU_CTXP(cp)) 5201e2e7a75Shuah sfmmu_cpu_cleanup(cp); 5217c478bd9Sstevel@tonic-gate bzero(cp, sizeof (*cp)); 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate /* 5247c478bd9Sstevel@tonic-gate * Place the freed cpu structure on the list of freed cpus. 5257c478bd9Sstevel@tonic-gate */ 5267c478bd9Sstevel@tonic-gate if (cp != &cpu0) { 5277c478bd9Sstevel@tonic-gate if (cpus) { 5287c478bd9Sstevel@tonic-gate cp->cpu_next_free = cpus; 5297c478bd9Sstevel@tonic-gate cpus = cp; 5307c478bd9Sstevel@tonic-gate } 5317c478bd9Sstevel@tonic-gate else 5327c478bd9Sstevel@tonic-gate cpus = cp; 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate return (0); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate /* 5397c478bd9Sstevel@tonic-gate * This routine is used to start a previously powered off processor. 5407c478bd9Sstevel@tonic-gate * Note that restarted cpus are initialized into the offline state. 5417c478bd9Sstevel@tonic-gate */ 5427c478bd9Sstevel@tonic-gate void 5437c478bd9Sstevel@tonic-gate restart_other_cpu(int cpuid) 5447c478bd9Sstevel@tonic-gate { 5457c478bd9Sstevel@tonic-gate struct cpu *cp; 5467c478bd9Sstevel@tonic-gate kthread_id_t tp; 5477c478bd9Sstevel@tonic-gate caddr_t sp; 5487c478bd9Sstevel@tonic-gate extern void idle(); 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 5517c478bd9Sstevel@tonic-gate ASSERT(cpuid < NCPU && cpu[cpuid] != NULL); 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate /* 5547c478bd9Sstevel@tonic-gate * Obtain pointer to the appropriate cpu structure. 5557c478bd9Sstevel@tonic-gate */ 5567c478bd9Sstevel@tonic-gate cp = cpu[cpuid]; 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate common_startup_init(cp, cpuid); 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate /* 5617c478bd9Sstevel@tonic-gate * idle thread t_lock is held when the idle thread is suspended. 5627c478bd9Sstevel@tonic-gate * Manually unlock the t_lock of idle loop so that we can resume 5637c478bd9Sstevel@tonic-gate * the suspended idle thread. 5647c478bd9Sstevel@tonic-gate * Also adjust the PC of idle thread for re-retry. 5657c478bd9Sstevel@tonic-gate */ 5667c478bd9Sstevel@tonic-gate cp->cpu_intr_actv = 0; /* clear the value from previous life */ 5677c478bd9Sstevel@tonic-gate cp->cpu_m.mutex_ready = 0; /* we are not ready yet */ 5687c478bd9Sstevel@tonic-gate lock_clear(&cp->cpu_idle_thread->t_lock); 5697c478bd9Sstevel@tonic-gate tp = cp->cpu_idle_thread; 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate sp = tp->t_stk; 5727c478bd9Sstevel@tonic-gate tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS; 5737c478bd9Sstevel@tonic-gate tp->t_pc = (uintptr_t)idle - 8; 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate /* 5767c478bd9Sstevel@tonic-gate * restart the cpu now 5777c478bd9Sstevel@tonic-gate */ 5787c478bd9Sstevel@tonic-gate promsafe_pause_cpus(); 5797c478bd9Sstevel@tonic-gate start_cpu(cpuid, warm_flag_set); 5807c478bd9Sstevel@tonic-gate start_cpus(); 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate /* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */ 5837c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "!cpu%d initialization complete - restarted\n", 5847c478bd9Sstevel@tonic-gate cpuid); 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate /* 5887c478bd9Sstevel@tonic-gate * Startup function executed on 'other' CPUs. This is the first 5897c478bd9Sstevel@tonic-gate * C function after cpu_start sets up the cpu registers. 5907c478bd9Sstevel@tonic-gate */ 5917c478bd9Sstevel@tonic-gate static void 5927c478bd9Sstevel@tonic-gate slave_startup(void) 5937c478bd9Sstevel@tonic-gate { 5947c478bd9Sstevel@tonic-gate struct cpu *cp = CPU; 5957c478bd9Sstevel@tonic-gate ushort_t original_flags = cp->cpu_flags; 5967c478bd9Sstevel@tonic-gate 597db6d2ee3Ssvemuri mach_htraptrace_configure(cp->cpu_id); 5987c478bd9Sstevel@tonic-gate cpu_intrq_register(CPU); 5997c478bd9Sstevel@tonic-gate cp->cpu_m.mutex_ready = 1; 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate /* acknowledge that we are done with initialization */ 6027c478bd9Sstevel@tonic-gate CPUSET_ADD(proxy_ready_set, cp->cpu_id); 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* synchronize STICK */ 6057c478bd9Sstevel@tonic-gate sticksync_slave(); 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate if (boothowto & RB_DEBUG) 6087c478bd9Sstevel@tonic-gate kdi_dvec_cpu_init(cp); 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate /* 6117c478bd9Sstevel@tonic-gate * the slave will wait here forever -- assuming that the master 6127c478bd9Sstevel@tonic-gate * will get back to us. if it doesn't we've got bigger problems 6137c478bd9Sstevel@tonic-gate * than a master not replying to this slave. 6147c478bd9Sstevel@tonic-gate * the small delay improves the slave's responsiveness to the 6157c478bd9Sstevel@tonic-gate * master's ack and decreases the time window between master and 6167c478bd9Sstevel@tonic-gate * slave operations. 6177c478bd9Sstevel@tonic-gate */ 6187c478bd9Sstevel@tonic-gate while (!CPU_IN_SET(cpu_ready_set, cp->cpu_id)) 6197c478bd9Sstevel@tonic-gate DELAY(1); 6207c478bd9Sstevel@tonic-gate 621*8390fbf8SRafael Vanoni /* 622*8390fbf8SRafael Vanoni * The CPU is now in cpu_ready_set, safely able to take pokes. 623*8390fbf8SRafael Vanoni */ 624*8390fbf8SRafael Vanoni cp->cpu_m.poke_cpu_outstanding = B_FALSE; 625*8390fbf8SRafael Vanoni 6267c478bd9Sstevel@tonic-gate /* enable interrupts */ 6277c478bd9Sstevel@tonic-gate (void) spl0(); 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate /* 6307c478bd9Sstevel@tonic-gate * Signature block update to indicate that this CPU is in OS now. 6317c478bd9Sstevel@tonic-gate * This needs to be done after the PIL is lowered since on 6327c478bd9Sstevel@tonic-gate * some platforms the update code may block. 6337c478bd9Sstevel@tonic-gate */ 6347c478bd9Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cp->cpu_id); 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate /* 6377c478bd9Sstevel@tonic-gate * park the slave thread in a safe/quiet state and wait for the master 6387c478bd9Sstevel@tonic-gate * to finish configuring this CPU before proceeding to thread_exit(). 6397c478bd9Sstevel@tonic-gate */ 6407c478bd9Sstevel@tonic-gate while (((volatile ushort_t)cp->cpu_flags) & CPU_QUIESCED) 6417c478bd9Sstevel@tonic-gate DELAY(1); 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate /* 6447c478bd9Sstevel@tonic-gate * Initialize CPC CPU state. 6457c478bd9Sstevel@tonic-gate */ 6467c478bd9Sstevel@tonic-gate kcpc_hw_startup_cpu(original_flags); 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate /* 649fb2f18f8Sesaxe * Notify the PG subsystem that the CPU has started 6507c478bd9Sstevel@tonic-gate */ 651fb2f18f8Sesaxe pg_cmt_cpu_startup(CPU); 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate /* 6547c478bd9Sstevel@tonic-gate * Now we are done with the startup thread, so free it up. 6557c478bd9Sstevel@tonic-gate */ 6567c478bd9Sstevel@tonic-gate thread_exit(); 6577c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "slave_startup: cannot return"); 6587c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate extern struct cpu *cpu[NCPU]; /* pointers to all CPUs */ 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate /* 6647c478bd9Sstevel@tonic-gate * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that 6657c478bd9Sstevel@tonic-gate * can be used during debugging to control which processors are brought 6667c478bd9Sstevel@tonic-gate * online at boot time. The variable represents a bitmap of the id's 6677c478bd9Sstevel@tonic-gate * of the processors that will be brought online. The initialization 6687c478bd9Sstevel@tonic-gate * of this variable depends on the type of cpuset_t, which varies 6697c478bd9Sstevel@tonic-gate * depending on the number of processors supported (see cpuvar.h). 6707c478bd9Sstevel@tonic-gate */ 6717c478bd9Sstevel@tonic-gate cpuset_t cpu_bringup_set; 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate /* 6757c478bd9Sstevel@tonic-gate * Generic start-all cpus entry. Typically used during cold initialization. 6767c478bd9Sstevel@tonic-gate * Note that cold start cpus are initialized into the online state. 6777c478bd9Sstevel@tonic-gate */ 6787c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6797c478bd9Sstevel@tonic-gate void 6807c478bd9Sstevel@tonic-gate start_other_cpus(int flag) 6817c478bd9Sstevel@tonic-gate { 6827c478bd9Sstevel@tonic-gate int cpuid; 6837c478bd9Sstevel@tonic-gate extern void idlestop_init(void); 6847c478bd9Sstevel@tonic-gate int bootcpu; 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate /* 6877c478bd9Sstevel@tonic-gate * Check if cpu_bringup_set has been explicitly set before 6887c478bd9Sstevel@tonic-gate * initializing it. 6897c478bd9Sstevel@tonic-gate */ 6907c478bd9Sstevel@tonic-gate if (CPUSET_ISNULL(cpu_bringup_set)) { 6917c478bd9Sstevel@tonic-gate CPUSET_ALL(cpu_bringup_set); 6927c478bd9Sstevel@tonic-gate } 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate if (&cpu_feature_init) 6957c478bd9Sstevel@tonic-gate cpu_feature_init(); 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate /* 6987c478bd9Sstevel@tonic-gate * Initialize CPC. 6997c478bd9Sstevel@tonic-gate */ 7007c478bd9Sstevel@tonic-gate kcpc_hw_init(); 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate /* 7057c478bd9Sstevel@tonic-gate * Initialize our own cpu_info. 7067c478bd9Sstevel@tonic-gate */ 7077c478bd9Sstevel@tonic-gate init_cpu_info(CPU); 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate /* 7107c478bd9Sstevel@tonic-gate * Initialize CPU 0 cpu module private data area, including scrubber. 7117c478bd9Sstevel@tonic-gate */ 7127c478bd9Sstevel@tonic-gate cpu_init_private(CPU); 7132f0fcb93SJason Beloro populate_idstr(CPU); 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate /* 7167c478bd9Sstevel@tonic-gate * perform such initialization as is needed 7177c478bd9Sstevel@tonic-gate * to be able to take CPUs on- and off-line. 7187c478bd9Sstevel@tonic-gate */ 7197c478bd9Sstevel@tonic-gate cpu_pause_init(); 7207c478bd9Sstevel@tonic-gate xc_init(); /* initialize processor crosscalls */ 7217c478bd9Sstevel@tonic-gate idlestop_init(); 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate if (!use_mp) { 7247c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 7257c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?***** Not in MP mode\n"); 7267c478bd9Sstevel@tonic-gate return; 7277c478bd9Sstevel@tonic-gate } 7287c478bd9Sstevel@tonic-gate /* 7297c478bd9Sstevel@tonic-gate * should we be initializing this cpu? 7307c478bd9Sstevel@tonic-gate */ 7317c478bd9Sstevel@tonic-gate bootcpu = getprocessorid(); 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate /* 7347c478bd9Sstevel@tonic-gate * launch all the slave cpus now 7357c478bd9Sstevel@tonic-gate */ 7367c478bd9Sstevel@tonic-gate for (cpuid = 0; cpuid < NCPU; cpuid++) { 737fa9e4066Sahrens pnode_t nodeid = cpunodes[cpuid].nodeid; 7387c478bd9Sstevel@tonic-gate 739fa9e4066Sahrens if (nodeid == (pnode_t)0) 7407c478bd9Sstevel@tonic-gate continue; 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate if (cpuid == bootcpu) { 7437c478bd9Sstevel@tonic-gate if (!CPU_IN_SET(cpu_bringup_set, cpuid)) { 7447c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "boot cpu not a member " 7457c478bd9Sstevel@tonic-gate "of cpu_bringup_set, adding it"); 7467c478bd9Sstevel@tonic-gate CPUSET_ADD(cpu_bringup_set, cpuid); 7477c478bd9Sstevel@tonic-gate } 7487c478bd9Sstevel@tonic-gate continue; 7497c478bd9Sstevel@tonic-gate } 7507c478bd9Sstevel@tonic-gate if (!CPU_IN_SET(cpu_bringup_set, cpuid)) 7517c478bd9Sstevel@tonic-gate continue; 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate ASSERT(cpu[cpuid] == NULL); 7547c478bd9Sstevel@tonic-gate 755982b9107Sjb145095 if (setup_cpu_common(cpuid)) { 756982b9107Sjb145095 cmn_err(CE_PANIC, "cpu%d: setup failed", cpuid); 757982b9107Sjb145095 } 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate common_startup_init(cpu[cpuid], cpuid); 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate start_cpu(cpuid, cold_flag_set); 7627c478bd9Sstevel@tonic-gate /* 7637c478bd9Sstevel@tonic-gate * Because slave_startup() gets fired off after init() 7647c478bd9Sstevel@tonic-gate * starts, we can't use the '?' trick to do 'boot -v' 7657c478bd9Sstevel@tonic-gate * printing - so we always direct the 'cpu .. online' 7667c478bd9Sstevel@tonic-gate * messages to the log. 7677c478bd9Sstevel@tonic-gate */ 7687c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "!cpu%d initialization complete - online\n", 7697c478bd9Sstevel@tonic-gate cpuid); 7707c478bd9Sstevel@tonic-gate 771b9e93c10SJonathan Haslam cpu_state_change_notify(cpuid, CPU_SETUP); 772b9e93c10SJonathan Haslam 7737c478bd9Sstevel@tonic-gate if (dtrace_cpu_init != NULL) 7747c478bd9Sstevel@tonic-gate (*dtrace_cpu_init)(cpuid); 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate /* 7787c478bd9Sstevel@tonic-gate * since all the cpus are online now, redistribute interrupts to them. 7797c478bd9Sstevel@tonic-gate */ 7807c478bd9Sstevel@tonic-gate intr_redist_all_cpus(); 7817c478bd9Sstevel@tonic-gate 7827c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate /* 7857c478bd9Sstevel@tonic-gate * Start the Ecache scrubber. Must be done after all calls to 7867c478bd9Sstevel@tonic-gate * cpu_init_private for every cpu (including CPU 0). 7877c478bd9Sstevel@tonic-gate */ 7887c478bd9Sstevel@tonic-gate cpu_init_cache_scrub(); 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate if (&cpu_mp_init) 7917c478bd9Sstevel@tonic-gate cpu_mp_init(); 7927c478bd9Sstevel@tonic-gate } 793