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 */ 604718Smh27603 cp->cpu_curr_clock = cpunode->clock_freq; 614667Smh27603 62*4877Smh27603 /* 63*4877Smh27603 * Supported frequencies. 64*4877Smh27603 */ 65*4877Smh27603 cpu_set_supp_freqs(cp, NULL); 66*4877Smh27603 670Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "sparcv9"); 680Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "sparcv9"); 690Sstevel@tonic-gate 700Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 710Sstevel@tonic-gate "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)", 720Sstevel@tonic-gate cpunode->name, cpunode->portid, 730Sstevel@tonic-gate cpunode->implementation, cpunode->version, pi->pi_clock); 740Sstevel@tonic-gate 750Sstevel@tonic-gate cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 760Sstevel@tonic-gate (void) strcpy(cp->cpu_idstr, buf); 770Sstevel@tonic-gate 780Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %s\n", cpuid, cp->cpu_idstr); 790Sstevel@tonic-gate 800Sstevel@tonic-gate cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP); 810Sstevel@tonic-gate (void) strcpy(cp->cpu_brandstr, cpunode->name); 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* 840Sstevel@tonic-gate * StarFire requires the signature block stuff setup here 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate CPU_SGN_MAPIN(cpuid); 870Sstevel@tonic-gate if (cpuid == cpu0.cpu_id) { 880Sstevel@tonic-gate /* 890Sstevel@tonic-gate * cpu0 starts out running. Other cpus are 900Sstevel@tonic-gate * still in OBP land and we will leave them 910Sstevel@tonic-gate * alone for now. 920Sstevel@tonic-gate */ 930Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid); 940Sstevel@tonic-gate #ifdef lint 950Sstevel@tonic-gate cpuid = cpuid; 960Sstevel@tonic-gate #endif /* lint */ 970Sstevel@tonic-gate } 980Sstevel@tonic-gate } 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * Routine used to cleanup a CPU that has been powered off. This will 1020Sstevel@tonic-gate * destroy all per-cpu information related to this cpu. 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate int 1050Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid) 1060Sstevel@tonic-gate { 1070Sstevel@tonic-gate int retval; 1080Sstevel@tonic-gate void empty_cpu(int); 1090Sstevel@tonic-gate extern int cleanup_cpu_common(int); 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate retval = cleanup_cpu_common(cpuid); 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate empty_cpu(cpuid); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate return (retval); 1180Sstevel@tonic-gate } 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate struct mp_find_cpu_arg { 1210Sstevel@tonic-gate int cpuid; /* set by mp_cpu_configure() */ 1220Sstevel@tonic-gate dev_info_t *dip; /* set by mp_find_cpu() */ 1230Sstevel@tonic-gate }; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate int 1260Sstevel@tonic-gate mp_find_cpu(dev_info_t *dip, void *arg) 1270Sstevel@tonic-gate { 1280Sstevel@tonic-gate extern int get_portid_ddi(dev_info_t *, dev_info_t **); 1290Sstevel@tonic-gate struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg; 1300Sstevel@tonic-gate char *type; 1310Sstevel@tonic-gate int rv = DDI_WALK_CONTINUE; 1320Sstevel@tonic-gate int cpuid; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 1350Sstevel@tonic-gate "device_type", &type)) 1360Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate if (strcmp(type, "cpu") != 0) 1390Sstevel@tonic-gate goto out; 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 1420Sstevel@tonic-gate DDI_PROP_DONTPASS, "cpuid", -1); 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate if (cpuid == -1) 1450Sstevel@tonic-gate cpuid = get_portid_ddi(dip, NULL); 1460Sstevel@tonic-gate if (cpuid != target->cpuid) 1470Sstevel@tonic-gate goto out; 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* Found it */ 1500Sstevel@tonic-gate rv = DDI_WALK_TERMINATE; 1510Sstevel@tonic-gate target->dip = dip; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate out: 1540Sstevel@tonic-gate ddi_prop_free(type); 1550Sstevel@tonic-gate return (rv); 1560Sstevel@tonic-gate } 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate /* 1590Sstevel@tonic-gate * Routine used to setup a newly inserted CPU in preparation for starting 1600Sstevel@tonic-gate * it running code. 1610Sstevel@tonic-gate */ 1620Sstevel@tonic-gate int 1630Sstevel@tonic-gate mp_cpu_configure(int cpuid) 1640Sstevel@tonic-gate { 1650Sstevel@tonic-gate extern void fill_cpu_ddi(dev_info_t *); 1664050Sjb145095 extern int setup_cpu_common(int); 1670Sstevel@tonic-gate struct mp_find_cpu_arg target; 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate target.dip = NULL; 1720Sstevel@tonic-gate target.cpuid = cpuid; 1730Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target); 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate if (target.dip == NULL) 1760Sstevel@tonic-gate return (ENODEV); 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * Note: uses cpu_lock to protect cpunodes and ncpunodes 1800Sstevel@tonic-gate * which will be modified inside of fill_cpu_ddi(). 1810Sstevel@tonic-gate */ 1820Sstevel@tonic-gate fill_cpu_ddi(target.dip); 1830Sstevel@tonic-gate 1844050Sjb145095 /* 1854050Sjb145095 * sun4v cpu setup may fail. sun4u assumes cpu setup to 1864050Sjb145095 * be always successful, so the return value is ignored. 1874050Sjb145095 */ 1884050Sjb145095 (void) setup_cpu_common(cpuid); 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate return (0); 1910Sstevel@tonic-gate } 192