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 51991Sheppo * Common Development and Distribution License (the "License"). 61991Sheppo * 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 */ 211991Sheppo 220Sstevel@tonic-gate /* 231991Sheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/machsystm.h> 300Sstevel@tonic-gate #include <sys/cpu_module.h> 310Sstevel@tonic-gate #include <sys/dtrace.h> 320Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 331991Sheppo #include <sys/mdesc.h> 341991Sheppo #include <sys/mach_descrip.h> 35*2957Sjm22469 #include <sys/ldoms.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate /* 380Sstevel@tonic-gate * Useful for disabling MP bring-up for an MP capable kernel 390Sstevel@tonic-gate * (a kernel that was built with MP defined) 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate int use_mp = 1; /* set to come up mp */ 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * Init CPU info - get CPU type info for processor_info system call. 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate void 470Sstevel@tonic-gate init_cpu_info(struct cpu *cp) 480Sstevel@tonic-gate { 490Sstevel@tonic-gate processor_info_t *pi = &cp->cpu_type_info; 500Sstevel@tonic-gate int cpuid = cp->cpu_id; 510Sstevel@tonic-gate struct cpu_node *cpunode = &cpunodes[cpuid]; 520Sstevel@tonic-gate char buf[CPU_IDSTRLEN]; 530Sstevel@tonic-gate 540Sstevel@tonic-gate cp->cpu_fpowner = NULL; /* not used for V9 */ 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* 570Sstevel@tonic-gate * Get clock-frequency property from cpunodes[] for the CPU. 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000; 600Sstevel@tonic-gate 610Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "sparcv9"); 620Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "sparcv9"); 630Sstevel@tonic-gate 640Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 650Sstevel@tonic-gate "%s (cpuid %d clock %d MHz)", 660Sstevel@tonic-gate cpunode->name, cpunode->cpuid, pi->pi_clock); 670Sstevel@tonic-gate 680Sstevel@tonic-gate cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 690Sstevel@tonic-gate (void) strcpy(cp->cpu_idstr, buf); 700Sstevel@tonic-gate 710Sstevel@tonic-gate cmn_err(CE_CONT, "?cpu%d: %s\n", cpuid, cp->cpu_idstr); 720Sstevel@tonic-gate 730Sstevel@tonic-gate cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP); 740Sstevel@tonic-gate (void) strcpy(cp->cpu_brandstr, cpunode->name); 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* 770Sstevel@tonic-gate * StarFire requires the signature block stuff setup here 780Sstevel@tonic-gate */ 790Sstevel@tonic-gate CPU_SGN_MAPIN(cpuid); 800Sstevel@tonic-gate if (cpuid == cpu0.cpu_id) { 810Sstevel@tonic-gate /* 820Sstevel@tonic-gate * cpu0 starts out running. Other cpus are 830Sstevel@tonic-gate * still in OBP land and we will leave them 840Sstevel@tonic-gate * alone for now. 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid); 870Sstevel@tonic-gate #ifdef lint 880Sstevel@tonic-gate cpuid = cpuid; 890Sstevel@tonic-gate #endif /* lint */ 900Sstevel@tonic-gate } 910Sstevel@tonic-gate } 920Sstevel@tonic-gate 930Sstevel@tonic-gate /* 941991Sheppo * Routine used to cleanup a CPU that has been powered off. This will 950Sstevel@tonic-gate * destroy all per-cpu information related to this cpu. 960Sstevel@tonic-gate */ 970Sstevel@tonic-gate int 980Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid) 990Sstevel@tonic-gate { 1001991Sheppo int retval; 1011991Sheppo extern void empty_cpu(int); 1021991Sheppo extern int cleanup_cpu_common(int); 1031991Sheppo 1041991Sheppo ASSERT(MUTEX_HELD(&cpu_lock)); 1051991Sheppo 1061991Sheppo retval = cleanup_cpu_common(cpuid); 1071991Sheppo 1081991Sheppo empty_cpu(cpuid); 1091991Sheppo 1101991Sheppo return (retval); 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate 1131991Sheppo struct mp_find_cpu_arg { 1141991Sheppo int cpuid; /* set by mp_cpu_configure() */ 1151991Sheppo dev_info_t *dip; /* set by mp_find_cpu() */ 1161991Sheppo }; 1171991Sheppo 1180Sstevel@tonic-gate int 1190Sstevel@tonic-gate mp_find_cpu(dev_info_t *dip, void *arg) 1200Sstevel@tonic-gate { 1211991Sheppo struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg; 1221991Sheppo char *type; 1231991Sheppo int rv = DDI_WALK_CONTINUE; 1241991Sheppo int cpuid; 1251991Sheppo 1261991Sheppo if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 1271991Sheppo DDI_PROP_DONTPASS, "device_type", &type)) 1281991Sheppo return (DDI_WALK_CONTINUE); 1291991Sheppo 1301991Sheppo if (strcmp(type, "cpu") != 0) 1311991Sheppo goto out; 1321991Sheppo 1331991Sheppo cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 1341991Sheppo DDI_PROP_DONTPASS, "reg", -1); 1351991Sheppo 1361991Sheppo if (cpuid == -1) { 1371991Sheppo cmn_err(CE_PANIC, "reg prop not found in cpu node"); 1381991Sheppo } 1391991Sheppo 1401991Sheppo cpuid = PROM_CFGHDL_TO_CPUID(cpuid); 1411991Sheppo 1421991Sheppo if (cpuid != target->cpuid) 1431991Sheppo goto out; 1441991Sheppo 1451991Sheppo /* Found it */ 1461991Sheppo rv = DDI_WALK_TERMINATE; 1471991Sheppo target->dip = dip; 1481991Sheppo 1491991Sheppo out: 1501991Sheppo ddi_prop_free(type); 1511991Sheppo return (rv); 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * Routine used to setup a newly inserted CPU in preparation for starting 1560Sstevel@tonic-gate * it running code. 1570Sstevel@tonic-gate */ 1580Sstevel@tonic-gate int 1590Sstevel@tonic-gate mp_cpu_configure(int cpuid) 1600Sstevel@tonic-gate { 1611991Sheppo extern void fill_cpu(md_t *, mde_cookie_t); 1621991Sheppo extern void setup_cpu_common(int); 1631991Sheppo extern void setup_exec_unit_mappings(md_t *); 1641991Sheppo md_t *mdp; 1651991Sheppo mde_cookie_t rootnode, cpunode = MDE_INVAL_ELEM_COOKIE; 1661991Sheppo int listsz, i; 1671991Sheppo mde_cookie_t *listp = NULL; 1681991Sheppo int num_nodes; 1691991Sheppo uint64_t cpuid_prop; 1701991Sheppo 1711991Sheppo 1721991Sheppo ASSERT(MUTEX_HELD(&cpu_lock)); 1731991Sheppo 1741991Sheppo if ((mdp = md_get_handle()) == NULL) 1751991Sheppo return (ENODEV); 1761991Sheppo 1771991Sheppo rootnode = md_root_node(mdp); 1781991Sheppo 1791991Sheppo ASSERT(rootnode != MDE_INVAL_ELEM_COOKIE); 1801991Sheppo 1811991Sheppo num_nodes = md_node_count(mdp); 1821991Sheppo 1831991Sheppo ASSERT(num_nodes > 0); 1841991Sheppo 1851991Sheppo listsz = num_nodes * sizeof (mde_cookie_t); 1861991Sheppo listp = kmem_zalloc(listsz, KM_SLEEP); 1871991Sheppo 1881991Sheppo num_nodes = md_scan_dag(mdp, rootnode, md_find_name(mdp, "cpu"), 1891991Sheppo md_find_name(mdp, "fwd"), listp); 1901991Sheppo 1911991Sheppo if (num_nodes < 0) 1921991Sheppo return (ENODEV); 1931991Sheppo 1941991Sheppo for (i = 0; i < num_nodes; i++) { 1951991Sheppo if (md_get_prop_val(mdp, listp[i], "id", &cpuid_prop)) 1961991Sheppo break; 1971991Sheppo if (cpuid_prop == (uint64_t)cpuid) { 1981991Sheppo cpunode = listp[i]; 1991991Sheppo break; 2001991Sheppo } 2011991Sheppo } 2021991Sheppo 2031991Sheppo if (cpunode == MDE_INVAL_ELEM_COOKIE) 2041991Sheppo return (ENODEV); 2051991Sheppo 2061991Sheppo kmem_free(listp, listsz); 2071991Sheppo 2081991Sheppo /* 2091991Sheppo * Note: uses cpu_lock to protect cpunodes and ncpunodes 2101991Sheppo * which will be modified inside of fill_cpu and 2111991Sheppo * setup_exec_unit_mappings. 2121991Sheppo */ 2131991Sheppo fill_cpu(mdp, cpunode); 2141991Sheppo 2151991Sheppo /* 2161991Sheppo * Remap all the cpunodes' execunit mappings. 2171991Sheppo */ 2181991Sheppo setup_exec_unit_mappings(mdp); 2191991Sheppo 2201991Sheppo (void) md_fini_handle(mdp); 2211991Sheppo 2221991Sheppo setup_cpu_common(cpuid); 2231991Sheppo 2240Sstevel@tonic-gate return (0); 2250Sstevel@tonic-gate } 226*2957Sjm22469 227*2957Sjm22469 /* 228*2957Sjm22469 * Platform-specific actions to be taken when all cpus are running 229*2957Sjm22469 * in the OS. 230*2957Sjm22469 */ 231*2957Sjm22469 void 232*2957Sjm22469 cpu_mp_init(void) 233*2957Sjm22469 { 234*2957Sjm22469 extern void recalc_xc_timeouts(); 235*2957Sjm22469 extern int cif_cpu_mp_ready; 236*2957Sjm22469 237*2957Sjm22469 /* N.B. This must happen after xc_init() has run. */ 238*2957Sjm22469 recalc_xc_timeouts(); 239*2957Sjm22469 240*2957Sjm22469 if (!(domaining_capabilities & DOMAINING_ENABLED)) 241*2957Sjm22469 return; 242*2957Sjm22469 243*2957Sjm22469 cif_cpu_mp_ready = 1; 244*2957Sjm22469 } 245