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 /*
238390fbf8SRafael Vanoni * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27c3377ee9SJohn Levon /*
28c3377ee9SJohn Levon * Copyright 2019 Joyent, Inc.
29*9e6ea921SPeter Tribble * Copyright 2019 Peter Tribble.
30c3377ee9SJohn Levon */
31c3377ee9SJohn Levon
327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
337c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h>
347c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h>
357c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
367c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h>
377c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
387c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
397c478bd9Sstevel@tonic-gate #include <sys/callb.h>
407c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h>
41fb2f18f8Sesaxe #include <sys/pg.h>
42fb2f18f8Sesaxe #include <sys/cmt.h>
437c478bd9Sstevel@tonic-gate #include <sys/dtrace.h>
447c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
457c478bd9Sstevel@tonic-gate #include <sys/kdi.h>
467c478bd9Sstevel@tonic-gate #include <sys/traptrace.h>
47db6d2ee3Ssvemuri #ifdef TRAPTRACE
487c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
497c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
507c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
517c478bd9Sstevel@tonic-gate
52982b9107Sjb145095 extern int cpu_intrq_setup(struct cpu *);
531ae08745Sheppo extern void cpu_intrq_cleanup(struct cpu *);
547c478bd9Sstevel@tonic-gate extern void cpu_intrq_register(struct cpu *);
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate struct cpu *cpus; /* pointer to other cpus; dynamically allocate */
577c478bd9Sstevel@tonic-gate struct cpu *cpu[NCPU]; /* pointers to all CPUs */
587c478bd9Sstevel@tonic-gate uint64_t cpu_pa[NCPU]; /* pointers to all CPUs in PA */
597c478bd9Sstevel@tonic-gate cpu_core_t cpu_core[NCPU]; /* cpu_core structures */
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
62986fd29aSsetje caddr_t ttrace_buf; /* kmem64 traptrace for all cpus except 0 */
637c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate /* bit mask of cpus ready for x-calls, protected by cpu_lock */
667c478bd9Sstevel@tonic-gate cpuset_t cpu_ready_set;
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate /* bit mask used to communicate with cpus during bringup */
697c478bd9Sstevel@tonic-gate static cpuset_t proxy_ready_set;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate static void slave_startup(void);
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate * Defined in $KARCH/os/mach_mp_startup.c
757c478bd9Sstevel@tonic-gate */
767c478bd9Sstevel@tonic-gate #pragma weak init_cpu_info
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate * Amount of time (in milliseconds) we should wait before giving up on CPU
807c478bd9Sstevel@tonic-gate * initialization and assuming that the CPU we're trying to wake up is dead
817c478bd9Sstevel@tonic-gate * or out of control.
827c478bd9Sstevel@tonic-gate */
837c478bd9Sstevel@tonic-gate #define CPU_WAKEUP_GRACE_MSEC 1000
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
867c478bd9Sstevel@tonic-gate /*
87bb121940Sdp78419 * This function sets traptrace buffers for all cpus
887c478bd9Sstevel@tonic-gate * other than boot cpu.
897c478bd9Sstevel@tonic-gate */
90986fd29aSsetje size_t
calc_traptrace_sz(void)91986fd29aSsetje calc_traptrace_sz(void)
927c478bd9Sstevel@tonic-gate {
93986fd29aSsetje return (TRAP_TSIZE * (max_ncpus - 1));
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
967c478bd9Sstevel@tonic-gate
97986fd29aSsetje
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate * common slave cpu initialization code
1007c478bd9Sstevel@tonic-gate */
1017c478bd9Sstevel@tonic-gate void
common_startup_init(cpu_t * cp,int cpuid)1027c478bd9Sstevel@tonic-gate common_startup_init(cpu_t *cp, int cpuid)
1037c478bd9Sstevel@tonic-gate {
1047c478bd9Sstevel@tonic-gate kthread_id_t tp;
1057c478bd9Sstevel@tonic-gate sfmmu_t *sfmmup;
1067c478bd9Sstevel@tonic-gate caddr_t sp;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate * Allocate and initialize the startup thread for this CPU.
1107c478bd9Sstevel@tonic-gate */
1117c478bd9Sstevel@tonic-gate tp = thread_create(NULL, 0, slave_startup, NULL, 0, &p0,
1127c478bd9Sstevel@tonic-gate TS_STOPPED, maxclsyspri);
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate * Set state to TS_ONPROC since this thread will start running
1167c478bd9Sstevel@tonic-gate * as soon as the CPU comes online.
1177c478bd9Sstevel@tonic-gate *
1187c478bd9Sstevel@tonic-gate * All the other fields of the thread structure are setup by
1197c478bd9Sstevel@tonic-gate * thread_create().
1207c478bd9Sstevel@tonic-gate */
1217c478bd9Sstevel@tonic-gate THREAD_ONPROC(tp, cp);
1227c478bd9Sstevel@tonic-gate tp->t_preempt = 1;
1237c478bd9Sstevel@tonic-gate tp->t_bound_cpu = cp;
1247c478bd9Sstevel@tonic-gate tp->t_affinitycnt = 1;
1257c478bd9Sstevel@tonic-gate tp->t_cpu = cp;
1267c478bd9Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp;
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate sfmmup = astosfmmu(&kas);
1297c478bd9Sstevel@tonic-gate CPUSET_ADD(sfmmup->sfmmu_cpusran, cpuid);
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate * Setup thread to start in slave_startup.
1337c478bd9Sstevel@tonic-gate */
1347c478bd9Sstevel@tonic-gate sp = tp->t_stk;
1357c478bd9Sstevel@tonic-gate tp->t_pc = (uintptr_t)slave_startup - 8;
1367c478bd9Sstevel@tonic-gate tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate cp->cpu_id = cpuid;
1397c478bd9Sstevel@tonic-gate cp->cpu_self = cp;
1407c478bd9Sstevel@tonic-gate cp->cpu_thread = tp;
1417c478bd9Sstevel@tonic-gate cp->cpu_lwp = NULL;
1427c478bd9Sstevel@tonic-gate cp->cpu_dispthread = tp;
1437c478bd9Sstevel@tonic-gate cp->cpu_dispatch_pri = DISP_PRIO(tp);
1449d7041eeSandrei cp->cpu_startup_thread = tp;
1458390fbf8SRafael Vanoni
1468390fbf8SRafael Vanoni /*
1478390fbf8SRafael Vanoni * The dispatcher may discover the CPU before it is in cpu_ready_set
1488390fbf8SRafael Vanoni * and attempt to poke it. Before the CPU is in cpu_ready_set, any
1498390fbf8SRafael Vanoni * cross calls to it will be dropped. We initialize
1508390fbf8SRafael Vanoni * poke_cpu_outstanding to true so that poke_cpu will ignore any poke
1518390fbf8SRafael Vanoni * requests for this CPU. Pokes that come in before the CPU is in
1528390fbf8SRafael Vanoni * cpu_ready_set can be ignored because the CPU is about to come
1538390fbf8SRafael Vanoni * online.
1548390fbf8SRafael Vanoni */
1558390fbf8SRafael Vanoni cp->cpu_m.poke_cpu_outstanding = B_TRUE;
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate * parametric flag setting functions. these routines set the cpu
1607c478bd9Sstevel@tonic-gate * state just prior to releasing the slave cpu.
1617c478bd9Sstevel@tonic-gate */
1627c478bd9Sstevel@tonic-gate void
cold_flag_set(int cpuid)1637c478bd9Sstevel@tonic-gate cold_flag_set(int cpuid)
1647c478bd9Sstevel@tonic-gate {
1657c478bd9Sstevel@tonic-gate cpu_t *cp;
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate cp = cpu[cpuid];
170c3377ee9SJohn Levon
171*9e6ea921SPeter Tribble if (!(cp->cpu_flags & CPU_ENABLE))
172c3377ee9SJohn Levon ncpus_intr_enabled++;
173c3377ee9SJohn Levon
1747c478bd9Sstevel@tonic-gate cp->cpu_flags |= CPU_RUNNING | CPU_ENABLE | CPU_EXISTS;
1757c478bd9Sstevel@tonic-gate cpu_add_active(cp);
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate * Add CPU_READY after the cpu_add_active() call
1787c478bd9Sstevel@tonic-gate * to avoid pausing cp.
1797c478bd9Sstevel@tonic-gate */
1807c478bd9Sstevel@tonic-gate cp->cpu_flags |= CPU_READY; /* ready */
1817c478bd9Sstevel@tonic-gate cpu_set_state(cp);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate static void
warm_flag_set(int cpuid)1857c478bd9Sstevel@tonic-gate warm_flag_set(int cpuid)
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate cpu_t *cp;
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate * warm start activates cpus into the OFFLINE state
1937c478bd9Sstevel@tonic-gate */
1947c478bd9Sstevel@tonic-gate cp = cpu[cpuid];
1957c478bd9Sstevel@tonic-gate cp->cpu_flags |= CPU_RUNNING | CPU_READY | CPU_EXISTS
1967c478bd9Sstevel@tonic-gate | CPU_OFFLINE | CPU_QUIESCED;
1977c478bd9Sstevel@tonic-gate cpu_set_state(cp);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate * Internal cpu startup sequencer
2027c478bd9Sstevel@tonic-gate * The sequence is as follows:
2037c478bd9Sstevel@tonic-gate *
2047c478bd9Sstevel@tonic-gate * MASTER SLAVE
2057c478bd9Sstevel@tonic-gate * ------- ----------
2067c478bd9Sstevel@tonic-gate * assume the kernel data is initialized
2077c478bd9Sstevel@tonic-gate * clear the proxy bit
2087c478bd9Sstevel@tonic-gate * start the slave cpu
2097c478bd9Sstevel@tonic-gate * wait for the slave cpu to set the proxy
2107c478bd9Sstevel@tonic-gate *
2117c478bd9Sstevel@tonic-gate * the slave runs slave_startup and then sets the proxy
2127c478bd9Sstevel@tonic-gate * the slave waits for the master to add slave to the ready set
2137c478bd9Sstevel@tonic-gate *
2147c478bd9Sstevel@tonic-gate * the master finishes the initialization and
2157c478bd9Sstevel@tonic-gate * adds the slave to the ready set
2167c478bd9Sstevel@tonic-gate *
2177c478bd9Sstevel@tonic-gate * the slave exits the startup thread and is running
2187c478bd9Sstevel@tonic-gate */
2197c478bd9Sstevel@tonic-gate void
start_cpu(int cpuid,void (* flag_func)(int))2207c478bd9Sstevel@tonic-gate start_cpu(int cpuid, void(*flag_func)(int))
2217c478bd9Sstevel@tonic-gate {
22241f63f87Spetede extern void cpu_startup(int);
2237c478bd9Sstevel@tonic-gate int timout;
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate * Before we begin the dance, tell DTrace that we're about to start
2297c478bd9Sstevel@tonic-gate * a CPU.
2307c478bd9Sstevel@tonic-gate */
2317c478bd9Sstevel@tonic-gate if (dtrace_cpustart_init != NULL)
2327c478bd9Sstevel@tonic-gate (*dtrace_cpustart_init)();
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate /* start the slave cpu */
2357c478bd9Sstevel@tonic-gate CPUSET_DEL(proxy_ready_set, cpuid);
2367c478bd9Sstevel@tonic-gate if (prom_test("SUNW,start-cpu-by-cpuid") == 0) {
2377c478bd9Sstevel@tonic-gate (void) prom_startcpu_bycpuid(cpuid, (caddr_t)&cpu_startup,
2387c478bd9Sstevel@tonic-gate cpuid);
2397c478bd9Sstevel@tonic-gate } else {
2407c478bd9Sstevel@tonic-gate /* "by-cpuid" interface didn't exist. Do it the old way */
241fa9e4066Sahrens pnode_t nodeid = cpunodes[cpuid].nodeid;
2427c478bd9Sstevel@tonic-gate
243fa9e4066Sahrens ASSERT(nodeid != (pnode_t)0);
2447c478bd9Sstevel@tonic-gate (void) prom_startcpu(nodeid, (caddr_t)&cpu_startup, cpuid);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate /* wait for the slave cpu to check in. */
2487c478bd9Sstevel@tonic-gate for (timout = CPU_WAKEUP_GRACE_MSEC; timout; timout--) {
2497c478bd9Sstevel@tonic-gate if (CPU_IN_SET(proxy_ready_set, cpuid))
2507c478bd9Sstevel@tonic-gate break;
2517c478bd9Sstevel@tonic-gate DELAY(1000);
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate if (timout == 0) {
2547c478bd9Sstevel@tonic-gate panic("cpu%d failed to start (2)", cpuid);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate * The slave has started; we can tell DTrace that it's safe again.
2597c478bd9Sstevel@tonic-gate */
2607c478bd9Sstevel@tonic-gate if (dtrace_cpustart_fini != NULL)
2617c478bd9Sstevel@tonic-gate (*dtrace_cpustart_fini)();
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate /* run the master side of stick synchronization for the slave cpu */
2647c478bd9Sstevel@tonic-gate sticksync_master();
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate * deal with the cpu flags in a phase-specific manner
2687c478bd9Sstevel@tonic-gate * for various reasons, this needs to run after the slave
2697c478bd9Sstevel@tonic-gate * is checked in but before the slave is released.
2707c478bd9Sstevel@tonic-gate */
2717c478bd9Sstevel@tonic-gate (*flag_func)(cpuid);
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate /* release the slave */
2747c478bd9Sstevel@tonic-gate CPUSET_ADD(cpu_ready_set, cpuid);
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
2787c478bd9Sstevel@tonic-gate int trap_tr0_inuse = 1; /* it is always used on the boot cpu */
2797c478bd9Sstevel@tonic-gate int trap_trace_inuse[NCPU];
2807c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate #define cpu_next_free cpu_prev
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate * Routine to set up a CPU to prepare for starting it up.
2867c478bd9Sstevel@tonic-gate */
287982b9107Sjb145095 int
setup_cpu_common(int cpuid)2887c478bd9Sstevel@tonic-gate setup_cpu_common(int cpuid)
2897c478bd9Sstevel@tonic-gate {
2907c478bd9Sstevel@tonic-gate struct cpu *cp = NULL;
2917c478bd9Sstevel@tonic-gate kthread_id_t tp;
2927c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
2937c478bd9Sstevel@tonic-gate int tt_index;
2947c478bd9Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp;
2957c478bd9Sstevel@tonic-gate caddr_t newbuf;
2967c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate extern void idle();
299982b9107Sjb145095 int rval;
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
3027c478bd9Sstevel@tonic-gate ASSERT(cpu[cpuid] == NULL);
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate ASSERT(ncpus <= max_ncpus);
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate * allocate a traptrace buffer for this CPU.
3097c478bd9Sstevel@tonic-gate */
3107c478bd9Sstevel@tonic-gate ctlp = &trap_trace_ctl[cpuid];
3117c478bd9Sstevel@tonic-gate if (!trap_tr0_inuse) {
3127c478bd9Sstevel@tonic-gate trap_tr0_inuse = 1;
3137c478bd9Sstevel@tonic-gate newbuf = trap_tr0;
3147c478bd9Sstevel@tonic-gate tt_index = -1;
3157c478bd9Sstevel@tonic-gate } else {
3167c478bd9Sstevel@tonic-gate for (tt_index = 0; tt_index < (max_ncpus-1); tt_index++)
3177c478bd9Sstevel@tonic-gate if (!trap_trace_inuse[tt_index])
3187c478bd9Sstevel@tonic-gate break;
3197c478bd9Sstevel@tonic-gate ASSERT(tt_index < max_ncpus - 1);
3207c478bd9Sstevel@tonic-gate trap_trace_inuse[tt_index] = 1;
321db6d2ee3Ssvemuri newbuf = (caddr_t)(ttrace_buf + (tt_index * TRAP_TSIZE));
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate ctlp->d.vaddr_base = newbuf;
3247c478bd9Sstevel@tonic-gate ctlp->d.offset = ctlp->d.last_offset = 0;
3257c478bd9Sstevel@tonic-gate ctlp->d.limit = trap_trace_bufsize;
3267c478bd9Sstevel@tonic-gate ctlp->d.paddr_base = va_to_pa(newbuf);
3277c478bd9Sstevel@tonic-gate ASSERT(ctlp->d.paddr_base != (uint64_t)-1);
3287c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
329db6d2ee3Ssvemuri /*
330db6d2ee3Ssvemuri * initialize hv traptrace buffer for this CPU
331db6d2ee3Ssvemuri */
332db6d2ee3Ssvemuri mach_htraptrace_setup(cpuid);
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate /*
3357c478bd9Sstevel@tonic-gate * Obtain pointer to the appropriate cpu structure.
3367c478bd9Sstevel@tonic-gate */
3377c478bd9Sstevel@tonic-gate if (cpu0.cpu_flags == 0) {
3387c478bd9Sstevel@tonic-gate cp = &cpu0;
3397c478bd9Sstevel@tonic-gate } else {
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate * When dynamically allocating cpu structs,
3427c478bd9Sstevel@tonic-gate * cpus is used as a pointer to a list of freed
3437c478bd9Sstevel@tonic-gate * cpu structs.
3447c478bd9Sstevel@tonic-gate */
3457c478bd9Sstevel@tonic-gate if (cpus) {
3467c478bd9Sstevel@tonic-gate /* grab the first cpu struct on the free list */
3477c478bd9Sstevel@tonic-gate cp = cpus;
3487c478bd9Sstevel@tonic-gate if (cp->cpu_next_free)
3497c478bd9Sstevel@tonic-gate cpus = cp->cpu_next_free;
3507c478bd9Sstevel@tonic-gate else
3517c478bd9Sstevel@tonic-gate cpus = NULL;
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate if (cp == NULL)
3567c478bd9Sstevel@tonic-gate cp = vmem_xalloc(static_alloc_arena, CPU_ALLOC_SIZE,
3577c478bd9Sstevel@tonic-gate CPU_ALLOC_SIZE, 0, 0, NULL, NULL, VM_SLEEP);
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate bzero(cp, sizeof (*cp));
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate cp->cpu_id = cpuid;
3627c478bd9Sstevel@tonic-gate cp->cpu_self = cp;
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate /*
3657c478bd9Sstevel@tonic-gate * Initialize ptl1_panic stack
3667c478bd9Sstevel@tonic-gate */
3677c478bd9Sstevel@tonic-gate ptl1_init_cpu(cp);
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate * Initialize the dispatcher for this CPU.
3717c478bd9Sstevel@tonic-gate */
3727c478bd9Sstevel@tonic-gate disp_cpu_init(cp);
3737c478bd9Sstevel@tonic-gate
37447ab0c7cSEric Saxe /*
37547ab0c7cSEric Saxe * Bootstrap the CPU's PG data
37647ab0c7cSEric Saxe */
37747ab0c7cSEric Saxe pg_cpu_bootstrap(cp);
37847ab0c7cSEric Saxe
379affbd3ccSkchow cpu_vm_data_init(cp);
380affbd3ccSkchow
3817c478bd9Sstevel@tonic-gate /*
3827c478bd9Sstevel@tonic-gate * Now, initialize per-CPU idle thread for this CPU.
3837c478bd9Sstevel@tonic-gate */
3847c478bd9Sstevel@tonic-gate tp = thread_create(NULL, 0, idle, NULL, 0, &p0, TS_ONPROC, -1);
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate cp->cpu_idle_thread = tp;
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate tp->t_preempt = 1;
3897c478bd9Sstevel@tonic-gate tp->t_bound_cpu = cp;
3907c478bd9Sstevel@tonic-gate tp->t_affinitycnt = 1;
3917c478bd9Sstevel@tonic-gate tp->t_cpu = cp;
3927c478bd9Sstevel@tonic-gate tp->t_disp_queue = cp->cpu_disp;
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate /*
3957c478bd9Sstevel@tonic-gate * Registering a thread in the callback table is usually
3967c478bd9Sstevel@tonic-gate * done in the initialization code of the thread. In this
3977c478bd9Sstevel@tonic-gate * case, we do it right after thread creation to avoid
3987c478bd9Sstevel@tonic-gate * blocking idle thread while registering itself. It also
3997c478bd9Sstevel@tonic-gate * avoids the possibility of reregistration in case a CPU
4007c478bd9Sstevel@tonic-gate * restarts its idle thread.
4017c478bd9Sstevel@tonic-gate */
4027c478bd9Sstevel@tonic-gate CALLB_CPR_INIT_SAFE(tp, "idle");
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate init_cpu_info(cp);
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate /*
4077c478bd9Sstevel@tonic-gate * Initialize the interrupt threads for this CPU
4087c478bd9Sstevel@tonic-gate */
409100b72f4Sandrei cpu_intr_alloc(cp, NINTR_THREADS);
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate /*
41270f54eadSesaxe * Add CPU to list of available CPUs.
41370f54eadSesaxe * It'll be on the active list after it is started.
4147c478bd9Sstevel@tonic-gate */
4157c478bd9Sstevel@tonic-gate cpu_add_unit(cp);
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate * Allocate and init cpu module private data structures,
4197c478bd9Sstevel@tonic-gate * including scrubber.
4207c478bd9Sstevel@tonic-gate */
4217c478bd9Sstevel@tonic-gate cpu_init_private(cp);
4222f0fcb93SJason Beloro populate_idstr(cp);
4237c478bd9Sstevel@tonic-gate
42470f54eadSesaxe /*
425fb2f18f8Sesaxe * Initialize the CPUs physical ID cache, and processor groups
42670f54eadSesaxe */
427fb2f18f8Sesaxe pghw_physid_create(cp);
428023e71deSHaik Aftandilian (void) pg_cpu_init(cp, B_FALSE);
429fb2f18f8Sesaxe
430982b9107Sjb145095 if ((rval = cpu_intrq_setup(cp)) != 0) {
431982b9107Sjb145095 return (rval);
432982b9107Sjb145095 }
4331e2e7a75Shuah
4341e2e7a75Shuah /*
4351e2e7a75Shuah * Initialize MMU context domain information.
4361e2e7a75Shuah */
4371e2e7a75Shuah sfmmu_cpu_init(cp);
4381e2e7a75Shuah
439982b9107Sjb145095 return (0);
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate /*
4437c478bd9Sstevel@tonic-gate * Routine to clean up a CPU after shutting it down.
4447c478bd9Sstevel@tonic-gate */
4457c478bd9Sstevel@tonic-gate int
cleanup_cpu_common(int cpuid)4467c478bd9Sstevel@tonic-gate cleanup_cpu_common(int cpuid)
4477c478bd9Sstevel@tonic-gate {
4487c478bd9Sstevel@tonic-gate struct cpu *cp;
4497c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
4507c478bd9Sstevel@tonic-gate int i;
4517c478bd9Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp;
4527c478bd9Sstevel@tonic-gate caddr_t newbuf;
4537c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
4567c478bd9Sstevel@tonic-gate ASSERT(cpu[cpuid] != NULL);
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gate cp = cpu[cpuid];
4597c478bd9Sstevel@tonic-gate
4607c478bd9Sstevel@tonic-gate /* Free cpu module private data structures, including scrubber. */
4617c478bd9Sstevel@tonic-gate cpu_uninit_private(cp);
4627c478bd9Sstevel@tonic-gate
46351243c37Srab /* Free cpu ID string and brand string. */
464982b9107Sjb145095 if (cp->cpu_idstr)
46551243c37Srab kmem_free(cp->cpu_idstr, strlen(cp->cpu_idstr) + 1);
466982b9107Sjb145095 if (cp->cpu_brandstr)
46751243c37Srab kmem_free(cp->cpu_brandstr, strlen(cp->cpu_brandstr) + 1);
46851243c37Srab
469affbd3ccSkchow cpu_vm_data_destroy(cp);
470affbd3ccSkchow
4717c478bd9Sstevel@tonic-gate /*
4727c478bd9Sstevel@tonic-gate * Remove CPU from list of available CPUs.
4737c478bd9Sstevel@tonic-gate */
4747c478bd9Sstevel@tonic-gate cpu_del_unit(cpuid);
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate /*
4771ae08745Sheppo * Clean any machine specific interrupt states.
4781ae08745Sheppo */
4791ae08745Sheppo cpu_intrq_cleanup(cp);
4801ae08745Sheppo
4811ae08745Sheppo /*
4827c478bd9Sstevel@tonic-gate * At this point, the only threads bound to this CPU should be
4837c478bd9Sstevel@tonic-gate * special per-cpu threads: it's idle thread, it's pause thread,
4847c478bd9Sstevel@tonic-gate * and it's interrupt threads. Clean these up.
4857c478bd9Sstevel@tonic-gate */
4867c478bd9Sstevel@tonic-gate cpu_destroy_bound_threads(cp);
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate /*
4897c478bd9Sstevel@tonic-gate * Free the interrupt stack.
4907c478bd9Sstevel@tonic-gate */
4917c478bd9Sstevel@tonic-gate segkp_release(segkp, cp->cpu_intr_stack);
4927c478bd9Sstevel@tonic-gate
493db6d2ee3Ssvemuri /*
494db6d2ee3Ssvemuri * Free hv traptrace buffer for this CPU.
495db6d2ee3Ssvemuri */
496db6d2ee3Ssvemuri mach_htraptrace_cleanup(cpuid);
4977c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
4987c478bd9Sstevel@tonic-gate /*
4997c478bd9Sstevel@tonic-gate * Free the traptrace buffer for this CPU.
5007c478bd9Sstevel@tonic-gate */
5017c478bd9Sstevel@tonic-gate ctlp = &trap_trace_ctl[cpuid];
5027c478bd9Sstevel@tonic-gate newbuf = ctlp->d.vaddr_base;
503db6d2ee3Ssvemuri i = (newbuf - ttrace_buf) / (TRAP_TSIZE);
504db6d2ee3Ssvemuri if (((newbuf - ttrace_buf) % (TRAP_TSIZE) == 0) &&
5057c478bd9Sstevel@tonic-gate ((i >= 0) && (i < (max_ncpus-1)))) {
5067c478bd9Sstevel@tonic-gate /*
5077c478bd9Sstevel@tonic-gate * This CPU got it's trap trace buffer from the
5087c478bd9Sstevel@tonic-gate * boot-alloc'd bunch of them.
5097c478bd9Sstevel@tonic-gate */
5107c478bd9Sstevel@tonic-gate trap_trace_inuse[i] = 0;
511db6d2ee3Ssvemuri bzero(newbuf, (TRAP_TSIZE));
5127c478bd9Sstevel@tonic-gate } else if (newbuf == trap_tr0) {
5137c478bd9Sstevel@tonic-gate trap_tr0_inuse = 0;
514db6d2ee3Ssvemuri bzero(trap_tr0, (TRAP_TSIZE));
5157c478bd9Sstevel@tonic-gate } else {
5167c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "failed to free trap trace buffer from cpu%d",
5177c478bd9Sstevel@tonic-gate cpuid);
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate bzero(ctlp, sizeof (*ctlp));
5207c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate /*
5237c478bd9Sstevel@tonic-gate * There is a race condition with mutex_vector_enter() which
5247c478bd9Sstevel@tonic-gate * caches a cpu pointer. The race is detected by checking cpu_next.
5257c478bd9Sstevel@tonic-gate */
5267c478bd9Sstevel@tonic-gate disp_cpu_fini(cp);
5277c478bd9Sstevel@tonic-gate cpu_pa[cpuid] = 0;
528982b9107Sjb145095 if (CPU_MMU_CTXP(cp))
5291e2e7a75Shuah sfmmu_cpu_cleanup(cp);
5307c478bd9Sstevel@tonic-gate bzero(cp, sizeof (*cp));
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate /*
5337c478bd9Sstevel@tonic-gate * Place the freed cpu structure on the list of freed cpus.
5347c478bd9Sstevel@tonic-gate */
5357c478bd9Sstevel@tonic-gate if (cp != &cpu0) {
5367c478bd9Sstevel@tonic-gate if (cpus) {
5377c478bd9Sstevel@tonic-gate cp->cpu_next_free = cpus;
5387c478bd9Sstevel@tonic-gate cpus = cp;
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate else
5417c478bd9Sstevel@tonic-gate cpus = cp;
5427c478bd9Sstevel@tonic-gate }
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate return (0);
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate
5477c478bd9Sstevel@tonic-gate /*
5487c478bd9Sstevel@tonic-gate * This routine is used to start a previously powered off processor.
5497c478bd9Sstevel@tonic-gate * Note that restarted cpus are initialized into the offline state.
5507c478bd9Sstevel@tonic-gate */
5517c478bd9Sstevel@tonic-gate void
restart_other_cpu(int cpuid)5527c478bd9Sstevel@tonic-gate restart_other_cpu(int cpuid)
5537c478bd9Sstevel@tonic-gate {
5547c478bd9Sstevel@tonic-gate struct cpu *cp;
5557c478bd9Sstevel@tonic-gate kthread_id_t tp;
5567c478bd9Sstevel@tonic-gate caddr_t sp;
5577c478bd9Sstevel@tonic-gate extern void idle();
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
5607c478bd9Sstevel@tonic-gate ASSERT(cpuid < NCPU && cpu[cpuid] != NULL);
5617c478bd9Sstevel@tonic-gate
5627c478bd9Sstevel@tonic-gate /*
5637c478bd9Sstevel@tonic-gate * Obtain pointer to the appropriate cpu structure.
5647c478bd9Sstevel@tonic-gate */
5657c478bd9Sstevel@tonic-gate cp = cpu[cpuid];
5667c478bd9Sstevel@tonic-gate
5677c478bd9Sstevel@tonic-gate common_startup_init(cp, cpuid);
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate /*
5707c478bd9Sstevel@tonic-gate * idle thread t_lock is held when the idle thread is suspended.
5717c478bd9Sstevel@tonic-gate * Manually unlock the t_lock of idle loop so that we can resume
5727c478bd9Sstevel@tonic-gate * the suspended idle thread.
5737c478bd9Sstevel@tonic-gate * Also adjust the PC of idle thread for re-retry.
5747c478bd9Sstevel@tonic-gate */
5757c478bd9Sstevel@tonic-gate cp->cpu_intr_actv = 0; /* clear the value from previous life */
5767c478bd9Sstevel@tonic-gate cp->cpu_m.mutex_ready = 0; /* we are not ready yet */
5777c478bd9Sstevel@tonic-gate lock_clear(&cp->cpu_idle_thread->t_lock);
5787c478bd9Sstevel@tonic-gate tp = cp->cpu_idle_thread;
5797c478bd9Sstevel@tonic-gate
5807c478bd9Sstevel@tonic-gate sp = tp->t_stk;
5817c478bd9Sstevel@tonic-gate tp->t_sp = (uintptr_t)((struct rwindow *)sp - 1) - STACK_BIAS;
5827c478bd9Sstevel@tonic-gate tp->t_pc = (uintptr_t)idle - 8;
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate /*
5857c478bd9Sstevel@tonic-gate * restart the cpu now
5867c478bd9Sstevel@tonic-gate */
5877c478bd9Sstevel@tonic-gate promsafe_pause_cpus();
5887c478bd9Sstevel@tonic-gate start_cpu(cpuid, warm_flag_set);
5897c478bd9Sstevel@tonic-gate start_cpus();
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate /* call cmn_err outside pause_cpus/start_cpus to avoid deadlock */
5927c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "!cpu%d initialization complete - restarted\n",
5937c478bd9Sstevel@tonic-gate cpuid);
5947c478bd9Sstevel@tonic-gate }
5957c478bd9Sstevel@tonic-gate
5967c478bd9Sstevel@tonic-gate /*
5977c478bd9Sstevel@tonic-gate * Startup function executed on 'other' CPUs. This is the first
5987c478bd9Sstevel@tonic-gate * C function after cpu_start sets up the cpu registers.
5997c478bd9Sstevel@tonic-gate */
6007c478bd9Sstevel@tonic-gate static void
slave_startup(void)6017c478bd9Sstevel@tonic-gate slave_startup(void)
6027c478bd9Sstevel@tonic-gate {
6037c478bd9Sstevel@tonic-gate struct cpu *cp = CPU;
6047c478bd9Sstevel@tonic-gate ushort_t original_flags = cp->cpu_flags;
6057c478bd9Sstevel@tonic-gate
606db6d2ee3Ssvemuri mach_htraptrace_configure(cp->cpu_id);
6077c478bd9Sstevel@tonic-gate cpu_intrq_register(CPU);
6087c478bd9Sstevel@tonic-gate cp->cpu_m.mutex_ready = 1;
6097c478bd9Sstevel@tonic-gate
6107c478bd9Sstevel@tonic-gate /* acknowledge that we are done with initialization */
6117c478bd9Sstevel@tonic-gate CPUSET_ADD(proxy_ready_set, cp->cpu_id);
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate /* synchronize STICK */
6147c478bd9Sstevel@tonic-gate sticksync_slave();
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate if (boothowto & RB_DEBUG)
6177c478bd9Sstevel@tonic-gate kdi_dvec_cpu_init(cp);
6187c478bd9Sstevel@tonic-gate
6197c478bd9Sstevel@tonic-gate /*
6207c478bd9Sstevel@tonic-gate * the slave will wait here forever -- assuming that the master
6217c478bd9Sstevel@tonic-gate * will get back to us. if it doesn't we've got bigger problems
6227c478bd9Sstevel@tonic-gate * than a master not replying to this slave.
6237c478bd9Sstevel@tonic-gate * the small delay improves the slave's responsiveness to the
6247c478bd9Sstevel@tonic-gate * master's ack and decreases the time window between master and
6257c478bd9Sstevel@tonic-gate * slave operations.
6267c478bd9Sstevel@tonic-gate */
6277c478bd9Sstevel@tonic-gate while (!CPU_IN_SET(cpu_ready_set, cp->cpu_id))
6287c478bd9Sstevel@tonic-gate DELAY(1);
6297c478bd9Sstevel@tonic-gate
6308390fbf8SRafael Vanoni /*
6318390fbf8SRafael Vanoni * The CPU is now in cpu_ready_set, safely able to take pokes.
6328390fbf8SRafael Vanoni */
6338390fbf8SRafael Vanoni cp->cpu_m.poke_cpu_outstanding = B_FALSE;
6348390fbf8SRafael Vanoni
6357c478bd9Sstevel@tonic-gate /* enable interrupts */
6367c478bd9Sstevel@tonic-gate (void) spl0();
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate * Signature block update to indicate that this CPU is in OS now.
6407c478bd9Sstevel@tonic-gate * This needs to be done after the PIL is lowered since on
6417c478bd9Sstevel@tonic-gate * some platforms the update code may block.
6427c478bd9Sstevel@tonic-gate */
6437c478bd9Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cp->cpu_id);
6447c478bd9Sstevel@tonic-gate
6457c478bd9Sstevel@tonic-gate /*
6467c478bd9Sstevel@tonic-gate * park the slave thread in a safe/quiet state and wait for the master
6477c478bd9Sstevel@tonic-gate * to finish configuring this CPU before proceeding to thread_exit().
6487c478bd9Sstevel@tonic-gate */
6497c478bd9Sstevel@tonic-gate while (((volatile ushort_t)cp->cpu_flags) & CPU_QUIESCED)
6507c478bd9Sstevel@tonic-gate DELAY(1);
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate /*
6537c478bd9Sstevel@tonic-gate * Initialize CPC CPU state.
6547c478bd9Sstevel@tonic-gate */
6557c478bd9Sstevel@tonic-gate kcpc_hw_startup_cpu(original_flags);
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate /*
658fb2f18f8Sesaxe * Notify the PG subsystem that the CPU has started
6597c478bd9Sstevel@tonic-gate */
660fb2f18f8Sesaxe pg_cmt_cpu_startup(CPU);
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate /*
6637c478bd9Sstevel@tonic-gate * Now we are done with the startup thread, so free it up.
6647c478bd9Sstevel@tonic-gate */
6657c478bd9Sstevel@tonic-gate thread_exit();
6667c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "slave_startup: cannot return");
6677c478bd9Sstevel@tonic-gate /*NOTREACHED*/
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate extern struct cpu *cpu[NCPU]; /* pointers to all CPUs */
6717c478bd9Sstevel@tonic-gate
6727c478bd9Sstevel@tonic-gate /*
6737c478bd9Sstevel@tonic-gate * cpu_bringup_set is a tunable (via /etc/system, debugger, etc.) that
6747c478bd9Sstevel@tonic-gate * can be used during debugging to control which processors are brought
6757c478bd9Sstevel@tonic-gate * online at boot time. The variable represents a bitmap of the id's
6767c478bd9Sstevel@tonic-gate * of the processors that will be brought online. The initialization
6777c478bd9Sstevel@tonic-gate * of this variable depends on the type of cpuset_t, which varies
6787c478bd9Sstevel@tonic-gate * depending on the number of processors supported (see cpuvar.h).
6797c478bd9Sstevel@tonic-gate */
6807c478bd9Sstevel@tonic-gate cpuset_t cpu_bringup_set;
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate /*
6847c478bd9Sstevel@tonic-gate * Generic start-all cpus entry. Typically used during cold initialization.
6857c478bd9Sstevel@tonic-gate * Note that cold start cpus are initialized into the online state.
6867c478bd9Sstevel@tonic-gate */
6877c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6887c478bd9Sstevel@tonic-gate void
start_other_cpus(int flag)6897c478bd9Sstevel@tonic-gate start_other_cpus(int flag)
6907c478bd9Sstevel@tonic-gate {
6917c478bd9Sstevel@tonic-gate int cpuid;
6927c478bd9Sstevel@tonic-gate extern void idlestop_init(void);
6937c478bd9Sstevel@tonic-gate int bootcpu;
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate /*
6967c478bd9Sstevel@tonic-gate * Check if cpu_bringup_set has been explicitly set before
6977c478bd9Sstevel@tonic-gate * initializing it.
6987c478bd9Sstevel@tonic-gate */
6997c478bd9Sstevel@tonic-gate if (CPUSET_ISNULL(cpu_bringup_set)) {
7007c478bd9Sstevel@tonic-gate CPUSET_ALL(cpu_bringup_set);
7017c478bd9Sstevel@tonic-gate }
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate if (&cpu_feature_init)
7047c478bd9Sstevel@tonic-gate cpu_feature_init();
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate /*
7077c478bd9Sstevel@tonic-gate * Initialize CPC.
7087c478bd9Sstevel@tonic-gate */
7097c478bd9Sstevel@tonic-gate kcpc_hw_init();
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock);
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate /*
7147c478bd9Sstevel@tonic-gate * Initialize our own cpu_info.
7157c478bd9Sstevel@tonic-gate */
7167c478bd9Sstevel@tonic-gate init_cpu_info(CPU);
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate /*
7197c478bd9Sstevel@tonic-gate * Initialize CPU 0 cpu module private data area, including scrubber.
7207c478bd9Sstevel@tonic-gate */
7217c478bd9Sstevel@tonic-gate cpu_init_private(CPU);
7222f0fcb93SJason Beloro populate_idstr(CPU);
7237c478bd9Sstevel@tonic-gate
7247c478bd9Sstevel@tonic-gate /*
7257c478bd9Sstevel@tonic-gate * perform such initialization as is needed
7267c478bd9Sstevel@tonic-gate * to be able to take CPUs on- and off-line.
7277c478bd9Sstevel@tonic-gate */
7287c478bd9Sstevel@tonic-gate cpu_pause_init();
7297c478bd9Sstevel@tonic-gate xc_init(); /* initialize processor crosscalls */
7307c478bd9Sstevel@tonic-gate idlestop_init();
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate if (!use_mp) {
7337c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock);
7347c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?***** Not in MP mode\n");
7357c478bd9Sstevel@tonic-gate return;
7367c478bd9Sstevel@tonic-gate }
7377c478bd9Sstevel@tonic-gate /*
7387c478bd9Sstevel@tonic-gate * should we be initializing this cpu?
7397c478bd9Sstevel@tonic-gate */
7407c478bd9Sstevel@tonic-gate bootcpu = getprocessorid();
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate /*
7437c478bd9Sstevel@tonic-gate * launch all the slave cpus now
7447c478bd9Sstevel@tonic-gate */
7457c478bd9Sstevel@tonic-gate for (cpuid = 0; cpuid < NCPU; cpuid++) {
746fa9e4066Sahrens pnode_t nodeid = cpunodes[cpuid].nodeid;
7477c478bd9Sstevel@tonic-gate
748fa9e4066Sahrens if (nodeid == (pnode_t)0)
7497c478bd9Sstevel@tonic-gate continue;
7507c478bd9Sstevel@tonic-gate
7517c478bd9Sstevel@tonic-gate if (cpuid == bootcpu) {
7527c478bd9Sstevel@tonic-gate if (!CPU_IN_SET(cpu_bringup_set, cpuid)) {
7537c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "boot cpu not a member "
7547c478bd9Sstevel@tonic-gate "of cpu_bringup_set, adding it");
7557c478bd9Sstevel@tonic-gate CPUSET_ADD(cpu_bringup_set, cpuid);
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate continue;
7587c478bd9Sstevel@tonic-gate }
7597c478bd9Sstevel@tonic-gate if (!CPU_IN_SET(cpu_bringup_set, cpuid))
7607c478bd9Sstevel@tonic-gate continue;
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate ASSERT(cpu[cpuid] == NULL);
7637c478bd9Sstevel@tonic-gate
764982b9107Sjb145095 if (setup_cpu_common(cpuid)) {
765982b9107Sjb145095 cmn_err(CE_PANIC, "cpu%d: setup failed", cpuid);
766982b9107Sjb145095 }
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate common_startup_init(cpu[cpuid], cpuid);
7697c478bd9Sstevel@tonic-gate
7707c478bd9Sstevel@tonic-gate start_cpu(cpuid, cold_flag_set);
7717c478bd9Sstevel@tonic-gate /*
7727c478bd9Sstevel@tonic-gate * Because slave_startup() gets fired off after init()
7737c478bd9Sstevel@tonic-gate * starts, we can't use the '?' trick to do 'boot -v'
7747c478bd9Sstevel@tonic-gate * printing - so we always direct the 'cpu .. online'
7757c478bd9Sstevel@tonic-gate * messages to the log.
7767c478bd9Sstevel@tonic-gate */
7777c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "!cpu%d initialization complete - online\n",
7787c478bd9Sstevel@tonic-gate cpuid);
7797c478bd9Sstevel@tonic-gate
780b9e93c10SJonathan Haslam cpu_state_change_notify(cpuid, CPU_SETUP);
781b9e93c10SJonathan Haslam
7827c478bd9Sstevel@tonic-gate if (dtrace_cpu_init != NULL)
7837c478bd9Sstevel@tonic-gate (*dtrace_cpu_init)(cpuid);
7847c478bd9Sstevel@tonic-gate }
7857c478bd9Sstevel@tonic-gate
7867c478bd9Sstevel@tonic-gate /*
7877c478bd9Sstevel@tonic-gate * since all the cpus are online now, redistribute interrupts to them.
7887c478bd9Sstevel@tonic-gate */
7897c478bd9Sstevel@tonic-gate intr_redist_all_cpus();
7907c478bd9Sstevel@tonic-gate
7917c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock);
7927c478bd9Sstevel@tonic-gate
7937c478bd9Sstevel@tonic-gate /*
7947c478bd9Sstevel@tonic-gate * Start the Ecache scrubber. Must be done after all calls to
7957c478bd9Sstevel@tonic-gate * cpu_init_private for every cpu (including CPU 0).
7967c478bd9Sstevel@tonic-gate */
7977c478bd9Sstevel@tonic-gate cpu_init_cache_scrub();
7987c478bd9Sstevel@tonic-gate
7997c478bd9Sstevel@tonic-gate if (&cpu_mp_init)
8007c478bd9Sstevel@tonic-gate cpu_mp_init();
8017c478bd9Sstevel@tonic-gate }
802