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
5982b9107Sjb145095 * Common Development and Distribution License (the "License").
6982b9107Sjb145095 * 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 */
217c478bd9Sstevel@tonic-gate /*
22*2f0fcb93SJason Beloro * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
277c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h>
287c478bd9Sstevel@tonic-gate #include <sys/dtrace.h>
297c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate * Useful for disabling MP bring-up for an MP capable kernel
337c478bd9Sstevel@tonic-gate * (a kernel that was built with MP defined)
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate int use_mp = 1; /* set to come up mp */
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate * Init CPU info - get CPU type info for processor_info system call.
397c478bd9Sstevel@tonic-gate */
407c478bd9Sstevel@tonic-gate void
init_cpu_info(struct cpu * cp)417c478bd9Sstevel@tonic-gate init_cpu_info(struct cpu *cp)
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate processor_info_t *pi = &cp->cpu_type_info;
447c478bd9Sstevel@tonic-gate int cpuid = cp->cpu_id;
457c478bd9Sstevel@tonic-gate struct cpu_node *cpunode = &cpunodes[cpuid];
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate cp->cpu_fpowner = NULL; /* not used for V9 */
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate * Get clock-frequency property from cpunodes[] for the CPU.
517c478bd9Sstevel@tonic-gate */
527c478bd9Sstevel@tonic-gate pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000;
537c478bd9Sstevel@tonic-gate
545cff7825Smh27603 /*
555cff7825Smh27603 * Current frequency in Hz.
565cff7825Smh27603 */
57cf74e62bSmh27603 cp->cpu_curr_clock = cpunode->clock_freq;
585cff7825Smh27603
5968afbec1Smh27603 /*
6068afbec1Smh27603 * Supported frequencies.
6168afbec1Smh27603 */
6268afbec1Smh27603 cpu_set_supp_freqs(cp, NULL);
6368afbec1Smh27603
647c478bd9Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "sparcv9");
657c478bd9Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "sparcv9");
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate * StarFire requires the signature block stuff setup here
697c478bd9Sstevel@tonic-gate */
707c478bd9Sstevel@tonic-gate CPU_SGN_MAPIN(cpuid);
717c478bd9Sstevel@tonic-gate if (cpuid == cpu0.cpu_id) {
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate * cpu0 starts out running. Other cpus are
747c478bd9Sstevel@tonic-gate * still in OBP land and we will leave them
757c478bd9Sstevel@tonic-gate * alone for now.
767c478bd9Sstevel@tonic-gate */
777c478bd9Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid);
787c478bd9Sstevel@tonic-gate #ifdef lint
797c478bd9Sstevel@tonic-gate cpuid = cpuid;
807c478bd9Sstevel@tonic-gate #endif /* lint */
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate * Routine used to cleanup a CPU that has been powered off. This will
867c478bd9Sstevel@tonic-gate * destroy all per-cpu information related to this cpu.
877c478bd9Sstevel@tonic-gate */
887c478bd9Sstevel@tonic-gate int
mp_cpu_unconfigure(int cpuid)897c478bd9Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate int retval;
927c478bd9Sstevel@tonic-gate void empty_cpu(int);
937c478bd9Sstevel@tonic-gate extern int cleanup_cpu_common(int);
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate retval = cleanup_cpu_common(cpuid);
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate empty_cpu(cpuid);
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate return (retval);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate struct mp_find_cpu_arg {
1057c478bd9Sstevel@tonic-gate int cpuid; /* set by mp_cpu_configure() */
1067c478bd9Sstevel@tonic-gate dev_info_t *dip; /* set by mp_find_cpu() */
1077c478bd9Sstevel@tonic-gate };
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate int
mp_find_cpu(dev_info_t * dip,void * arg)1107c478bd9Sstevel@tonic-gate mp_find_cpu(dev_info_t *dip, void *arg)
1117c478bd9Sstevel@tonic-gate {
1127c478bd9Sstevel@tonic-gate extern int get_portid_ddi(dev_info_t *, dev_info_t **);
1137c478bd9Sstevel@tonic-gate struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg;
1147c478bd9Sstevel@tonic-gate char *type;
1157c478bd9Sstevel@tonic-gate int rv = DDI_WALK_CONTINUE;
1167c478bd9Sstevel@tonic-gate int cpuid;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
1197c478bd9Sstevel@tonic-gate "device_type", &type))
1207c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE);
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate if (strcmp(type, "cpu") != 0)
1237c478bd9Sstevel@tonic-gate goto out;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
1267c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "cpuid", -1);
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate if (cpuid == -1)
1297c478bd9Sstevel@tonic-gate cpuid = get_portid_ddi(dip, NULL);
1307c478bd9Sstevel@tonic-gate if (cpuid != target->cpuid)
1317c478bd9Sstevel@tonic-gate goto out;
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate /* Found it */
1347c478bd9Sstevel@tonic-gate rv = DDI_WALK_TERMINATE;
1357c478bd9Sstevel@tonic-gate target->dip = dip;
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate out:
1387c478bd9Sstevel@tonic-gate ddi_prop_free(type);
1397c478bd9Sstevel@tonic-gate return (rv);
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate * Routine used to setup a newly inserted CPU in preparation for starting
1447c478bd9Sstevel@tonic-gate * it running code.
1457c478bd9Sstevel@tonic-gate */
1467c478bd9Sstevel@tonic-gate int
mp_cpu_configure(int cpuid)1477c478bd9Sstevel@tonic-gate mp_cpu_configure(int cpuid)
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate extern void fill_cpu_ddi(dev_info_t *);
150982b9107Sjb145095 extern int setup_cpu_common(int);
1517c478bd9Sstevel@tonic-gate struct mp_find_cpu_arg target;
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate target.dip = NULL;
1567c478bd9Sstevel@tonic-gate target.cpuid = cpuid;
1577c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target);
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate if (target.dip == NULL)
1607c478bd9Sstevel@tonic-gate return (ENODEV);
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate * Note: uses cpu_lock to protect cpunodes and ncpunodes
1647c478bd9Sstevel@tonic-gate * which will be modified inside of fill_cpu_ddi().
1657c478bd9Sstevel@tonic-gate */
1667c478bd9Sstevel@tonic-gate fill_cpu_ddi(target.dip);
1677c478bd9Sstevel@tonic-gate
168982b9107Sjb145095 /*
169982b9107Sjb145095 * sun4v cpu setup may fail. sun4u assumes cpu setup to
170982b9107Sjb145095 * be always successful, so the return value is ignored.
171982b9107Sjb145095 */
172982b9107Sjb145095 (void) setup_cpu_common(cpuid);
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate return (0);
1757c478bd9Sstevel@tonic-gate }
176*2f0fcb93SJason Beloro
177*2f0fcb93SJason Beloro void
populate_idstr(struct cpu * cp)178*2f0fcb93SJason Beloro populate_idstr(struct cpu *cp)
179*2f0fcb93SJason Beloro {
180*2f0fcb93SJason Beloro char buf[CPU_IDSTRLEN];
181*2f0fcb93SJason Beloro struct cpu_node *cpunode;
182*2f0fcb93SJason Beloro processor_info_t *pi;
183*2f0fcb93SJason Beloro
184*2f0fcb93SJason Beloro cpunode = &cpunodes[cp->cpu_id];
185*2f0fcb93SJason Beloro pi = &cp->cpu_type_info;
186*2f0fcb93SJason Beloro (void) snprintf(buf, sizeof (buf),
187*2f0fcb93SJason Beloro "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)",
188*2f0fcb93SJason Beloro cpunode->name, cpunode->portid, cpunode->implementation,
189*2f0fcb93SJason Beloro cpunode->version, pi->pi_clock);
190*2f0fcb93SJason Beloro cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
191*2f0fcb93SJason Beloro (void) strcpy(cp->cpu_idstr, buf);
192*2f0fcb93SJason Beloro
193*2f0fcb93SJason Beloro cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP);
194*2f0fcb93SJason Beloro (void) strcpy(cp->cpu_brandstr, cpunode->name);
195*2f0fcb93SJason Beloro
196*2f0fcb93SJason Beloro cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr);
197*2f0fcb93SJason Beloro }
198