10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
54050Sjb145095 * Common Development and Distribution License (the "License").
64050Sjb145095 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7718SJason.Beloro@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/machsystm.h>
270Sstevel@tonic-gate #include <sys/cpu_module.h>
280Sstevel@tonic-gate #include <sys/dtrace.h>
290Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
300Sstevel@tonic-gate
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate * Useful for disabling MP bring-up for an MP capable kernel
330Sstevel@tonic-gate * (a kernel that was built with MP defined)
340Sstevel@tonic-gate */
350Sstevel@tonic-gate int use_mp = 1; /* set to come up mp */
360Sstevel@tonic-gate
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate * Init CPU info - get CPU type info for processor_info system call.
390Sstevel@tonic-gate */
400Sstevel@tonic-gate void
init_cpu_info(struct cpu * cp)410Sstevel@tonic-gate init_cpu_info(struct cpu *cp)
420Sstevel@tonic-gate {
430Sstevel@tonic-gate processor_info_t *pi = &cp->cpu_type_info;
440Sstevel@tonic-gate int cpuid = cp->cpu_id;
450Sstevel@tonic-gate struct cpu_node *cpunode = &cpunodes[cpuid];
460Sstevel@tonic-gate
470Sstevel@tonic-gate cp->cpu_fpowner = NULL; /* not used for V9 */
480Sstevel@tonic-gate
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate * Get clock-frequency property from cpunodes[] for the CPU.
510Sstevel@tonic-gate */
520Sstevel@tonic-gate pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000;
530Sstevel@tonic-gate
544667Smh27603 /*
554667Smh27603 * Current frequency in Hz.
564667Smh27603 */
574718Smh27603 cp->cpu_curr_clock = cpunode->clock_freq;
584667Smh27603
594877Smh27603 /*
604877Smh27603 * Supported frequencies.
614877Smh27603 */
624877Smh27603 cpu_set_supp_freqs(cp, NULL);
634877Smh27603
640Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "sparcv9");
650Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "sparcv9");
660Sstevel@tonic-gate
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate * StarFire requires the signature block stuff setup here
690Sstevel@tonic-gate */
700Sstevel@tonic-gate CPU_SGN_MAPIN(cpuid);
710Sstevel@tonic-gate if (cpuid == cpu0.cpu_id) {
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate * cpu0 starts out running. Other cpus are
740Sstevel@tonic-gate * still in OBP land and we will leave them
750Sstevel@tonic-gate * alone for now.
760Sstevel@tonic-gate */
770Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid);
780Sstevel@tonic-gate #ifdef lint
790Sstevel@tonic-gate cpuid = cpuid;
800Sstevel@tonic-gate #endif /* lint */
810Sstevel@tonic-gate }
820Sstevel@tonic-gate }
830Sstevel@tonic-gate
840Sstevel@tonic-gate /*
850Sstevel@tonic-gate * Routine used to cleanup a CPU that has been powered off. This will
860Sstevel@tonic-gate * destroy all per-cpu information related to this cpu.
870Sstevel@tonic-gate */
880Sstevel@tonic-gate int
mp_cpu_unconfigure(int cpuid)890Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid)
900Sstevel@tonic-gate {
910Sstevel@tonic-gate int retval;
920Sstevel@tonic-gate void empty_cpu(int);
930Sstevel@tonic-gate extern int cleanup_cpu_common(int);
940Sstevel@tonic-gate
950Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
960Sstevel@tonic-gate
970Sstevel@tonic-gate retval = cleanup_cpu_common(cpuid);
980Sstevel@tonic-gate
990Sstevel@tonic-gate empty_cpu(cpuid);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate return (retval);
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate struct mp_find_cpu_arg {
1050Sstevel@tonic-gate int cpuid; /* set by mp_cpu_configure() */
1060Sstevel@tonic-gate dev_info_t *dip; /* set by mp_find_cpu() */
1070Sstevel@tonic-gate };
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate int
mp_find_cpu(dev_info_t * dip,void * arg)1100Sstevel@tonic-gate mp_find_cpu(dev_info_t *dip, void *arg)
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate extern int get_portid_ddi(dev_info_t *, dev_info_t **);
1130Sstevel@tonic-gate struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg;
1140Sstevel@tonic-gate char *type;
1150Sstevel@tonic-gate int rv = DDI_WALK_CONTINUE;
1160Sstevel@tonic-gate int cpuid;
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
1190Sstevel@tonic-gate "device_type", &type))
1200Sstevel@tonic-gate return (DDI_WALK_CONTINUE);
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate if (strcmp(type, "cpu") != 0)
1230Sstevel@tonic-gate goto out;
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
1260Sstevel@tonic-gate DDI_PROP_DONTPASS, "cpuid", -1);
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate if (cpuid == -1)
1290Sstevel@tonic-gate cpuid = get_portid_ddi(dip, NULL);
1300Sstevel@tonic-gate if (cpuid != target->cpuid)
1310Sstevel@tonic-gate goto out;
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate /* Found it */
1340Sstevel@tonic-gate rv = DDI_WALK_TERMINATE;
1350Sstevel@tonic-gate target->dip = dip;
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate out:
1380Sstevel@tonic-gate ddi_prop_free(type);
1390Sstevel@tonic-gate return (rv);
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate /*
1430Sstevel@tonic-gate * Routine used to setup a newly inserted CPU in preparation for starting
1440Sstevel@tonic-gate * it running code.
1450Sstevel@tonic-gate */
1460Sstevel@tonic-gate int
mp_cpu_configure(int cpuid)1470Sstevel@tonic-gate mp_cpu_configure(int cpuid)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate extern void fill_cpu_ddi(dev_info_t *);
1504050Sjb145095 extern int setup_cpu_common(int);
1510Sstevel@tonic-gate struct mp_find_cpu_arg target;
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock));
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate target.dip = NULL;
1560Sstevel@tonic-gate target.cpuid = cpuid;
1570Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target);
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate if (target.dip == NULL)
1600Sstevel@tonic-gate return (ENODEV);
1610Sstevel@tonic-gate
1620Sstevel@tonic-gate /*
1630Sstevel@tonic-gate * Note: uses cpu_lock to protect cpunodes and ncpunodes
1640Sstevel@tonic-gate * which will be modified inside of fill_cpu_ddi().
1650Sstevel@tonic-gate */
1660Sstevel@tonic-gate fill_cpu_ddi(target.dip);
1670Sstevel@tonic-gate
1684050Sjb145095 /*
1694050Sjb145095 * sun4v cpu setup may fail. sun4u assumes cpu setup to
1704050Sjb145095 * be always successful, so the return value is ignored.
1714050Sjb145095 */
1724050Sjb145095 (void) setup_cpu_common(cpuid);
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate return (0);
1750Sstevel@tonic-gate }
176*7718SJason.Beloro@Sun.COM
177*7718SJason.Beloro@Sun.COM void
populate_idstr(struct cpu * cp)178*7718SJason.Beloro@Sun.COM populate_idstr(struct cpu *cp)
179*7718SJason.Beloro@Sun.COM {
180*7718SJason.Beloro@Sun.COM char buf[CPU_IDSTRLEN];
181*7718SJason.Beloro@Sun.COM struct cpu_node *cpunode;
182*7718SJason.Beloro@Sun.COM processor_info_t *pi;
183*7718SJason.Beloro@Sun.COM
184*7718SJason.Beloro@Sun.COM cpunode = &cpunodes[cp->cpu_id];
185*7718SJason.Beloro@Sun.COM pi = &cp->cpu_type_info;
186*7718SJason.Beloro@Sun.COM (void) snprintf(buf, sizeof (buf),
187*7718SJason.Beloro@Sun.COM "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)",
188*7718SJason.Beloro@Sun.COM cpunode->name, cpunode->portid, cpunode->implementation,
189*7718SJason.Beloro@Sun.COM cpunode->version, pi->pi_clock);
190*7718SJason.Beloro@Sun.COM cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
191*7718SJason.Beloro@Sun.COM (void) strcpy(cp->cpu_idstr, buf);
192*7718SJason.Beloro@Sun.COM
193*7718SJason.Beloro@Sun.COM cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP);
194*7718SJason.Beloro@Sun.COM (void) strcpy(cp->cpu_brandstr, cpunode->name);
195*7718SJason.Beloro@Sun.COM
196*7718SJason.Beloro@Sun.COM cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr);
197*7718SJason.Beloro@Sun.COM }
198