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 /* 224050Sjb145095 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/machsystm.h> 290Sstevel@tonic-gate #include <sys/cpu_module.h> 300Sstevel@tonic-gate #include <sys/dtrace.h> 310Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 320Sstevel@tonic-gate 330Sstevel@tonic-gate /* 340Sstevel@tonic-gate * Useful for disabling MP bring-up for an MP capable kernel 350Sstevel@tonic-gate * (a kernel that was built with MP defined) 360Sstevel@tonic-gate */ 370Sstevel@tonic-gate int use_mp = 1; /* set to come up mp */ 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * Init CPU info - get CPU type info for processor_info system call. 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate void 430Sstevel@tonic-gate init_cpu_info(struct cpu *cp) 440Sstevel@tonic-gate { 450Sstevel@tonic-gate processor_info_t *pi = &cp->cpu_type_info; 460Sstevel@tonic-gate int cpuid = cp->cpu_id; 470Sstevel@tonic-gate struct cpu_node *cpunode = &cpunodes[cpuid]; 480Sstevel@tonic-gate char buf[CPU_IDSTRLEN]; 490Sstevel@tonic-gate 500Sstevel@tonic-gate cp->cpu_fpowner = NULL; /* not used for V9 */ 510Sstevel@tonic-gate 520Sstevel@tonic-gate /* 530Sstevel@tonic-gate * Get clock-frequency property from cpunodes[] for the CPU. 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000; 560Sstevel@tonic-gate 574667Smh27603 /* 584667Smh27603 * Current frequency in Hz. 594667Smh27603 */ 60*4718Smh27603 cp->cpu_curr_clock = cpunode->clock_freq; 614667Smh27603 620Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "sparcv9"); 630Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "sparcv9"); 640Sstevel@tonic-gate 650Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 660Sstevel@tonic-gate "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)", 670Sstevel@tonic-gate cpunode->name, cpunode->portid, 680Sstevel@tonic-gate cpunode->implementation, cpunode->version, pi->pi_clock); 690Sstevel@tonic-gate 700Sstevel@tonic-gate cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 710Sstevel@tonic-gate (void) strcpy(cp->cpu_idstr, buf); 720Sstevel@tonic-gate 730Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %s\n", cpuid, cp->cpu_idstr); 740Sstevel@tonic-gate 750Sstevel@tonic-gate cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP); 760Sstevel@tonic-gate (void) strcpy(cp->cpu_brandstr, cpunode->name); 770Sstevel@tonic-gate 780Sstevel@tonic-gate /* 790Sstevel@tonic-gate * StarFire requires the signature block stuff setup here 800Sstevel@tonic-gate */ 810Sstevel@tonic-gate CPU_SGN_MAPIN(cpuid); 820Sstevel@tonic-gate if (cpuid == cpu0.cpu_id) { 830Sstevel@tonic-gate /* 840Sstevel@tonic-gate * cpu0 starts out running. Other cpus are 850Sstevel@tonic-gate * still in OBP land and we will leave them 860Sstevel@tonic-gate * alone for now. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid); 890Sstevel@tonic-gate #ifdef lint 900Sstevel@tonic-gate cpuid = cpuid; 910Sstevel@tonic-gate #endif /* lint */ 920Sstevel@tonic-gate } 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * Routine used to cleanup a CPU that has been powered off. This will 970Sstevel@tonic-gate * destroy all per-cpu information related to this cpu. 980Sstevel@tonic-gate */ 990Sstevel@tonic-gate int 1000Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid) 1010Sstevel@tonic-gate { 1020Sstevel@tonic-gate int retval; 1030Sstevel@tonic-gate void empty_cpu(int); 1040Sstevel@tonic-gate extern int cleanup_cpu_common(int); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate retval = cleanup_cpu_common(cpuid); 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate empty_cpu(cpuid); 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate return (retval); 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate struct mp_find_cpu_arg { 1160Sstevel@tonic-gate int cpuid; /* set by mp_cpu_configure() */ 1170Sstevel@tonic-gate dev_info_t *dip; /* set by mp_find_cpu() */ 1180Sstevel@tonic-gate }; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate int 1210Sstevel@tonic-gate mp_find_cpu(dev_info_t *dip, void *arg) 1220Sstevel@tonic-gate { 1230Sstevel@tonic-gate extern int get_portid_ddi(dev_info_t *, dev_info_t **); 1240Sstevel@tonic-gate struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg; 1250Sstevel@tonic-gate char *type; 1260Sstevel@tonic-gate int rv = DDI_WALK_CONTINUE; 1270Sstevel@tonic-gate int cpuid; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 1300Sstevel@tonic-gate "device_type", &type)) 1310Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate if (strcmp(type, "cpu") != 0) 1340Sstevel@tonic-gate goto out; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 1370Sstevel@tonic-gate DDI_PROP_DONTPASS, "cpuid", -1); 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate if (cpuid == -1) 1400Sstevel@tonic-gate cpuid = get_portid_ddi(dip, NULL); 1410Sstevel@tonic-gate if (cpuid != target->cpuid) 1420Sstevel@tonic-gate goto out; 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* Found it */ 1450Sstevel@tonic-gate rv = DDI_WALK_TERMINATE; 1460Sstevel@tonic-gate target->dip = dip; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate out: 1490Sstevel@tonic-gate ddi_prop_free(type); 1500Sstevel@tonic-gate return (rv); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate /* 1540Sstevel@tonic-gate * Routine used to setup a newly inserted CPU in preparation for starting 1550Sstevel@tonic-gate * it running code. 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate int 1580Sstevel@tonic-gate mp_cpu_configure(int cpuid) 1590Sstevel@tonic-gate { 1600Sstevel@tonic-gate extern void fill_cpu_ddi(dev_info_t *); 1614050Sjb145095 extern int setup_cpu_common(int); 1620Sstevel@tonic-gate struct mp_find_cpu_arg target; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate target.dip = NULL; 1670Sstevel@tonic-gate target.cpuid = cpuid; 1680Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate if (target.dip == NULL) 1710Sstevel@tonic-gate return (ENODEV); 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate /* 1740Sstevel@tonic-gate * Note: uses cpu_lock to protect cpunodes and ncpunodes 1750Sstevel@tonic-gate * which will be modified inside of fill_cpu_ddi(). 1760Sstevel@tonic-gate */ 1770Sstevel@tonic-gate fill_cpu_ddi(target.dip); 1780Sstevel@tonic-gate 1794050Sjb145095 /* 1804050Sjb145095 * sun4v cpu setup may fail. sun4u assumes cpu setup to 1814050Sjb145095 * be always successful, so the return value is ignored. 1824050Sjb145095 */ 1834050Sjb145095 (void) setup_cpu_common(cpuid); 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate return (0); 1860Sstevel@tonic-gate } 187