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 /* 234050Sjb145095 * Copyright 2007 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> 352957Sjm22469 #include <sys/ldoms.h> 363266Sjb145095 #include <sys/hypervisor_api.h> 373266Sjb145095 #include <sys/soft_state.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * Useful for disabling MP bring-up for an MP capable kernel 410Sstevel@tonic-gate * (a kernel that was built with MP defined) 420Sstevel@tonic-gate */ 430Sstevel@tonic-gate int use_mp = 1; /* set to come up mp */ 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * Init CPU info - get CPU type info for processor_info system call. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate void 490Sstevel@tonic-gate init_cpu_info(struct cpu *cp) 500Sstevel@tonic-gate { 510Sstevel@tonic-gate processor_info_t *pi = &cp->cpu_type_info; 520Sstevel@tonic-gate int cpuid = cp->cpu_id; 530Sstevel@tonic-gate struct cpu_node *cpunode = &cpunodes[cpuid]; 540Sstevel@tonic-gate char buf[CPU_IDSTRLEN]; 550Sstevel@tonic-gate 560Sstevel@tonic-gate cp->cpu_fpowner = NULL; /* not used for V9 */ 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * Get clock-frequency property from cpunodes[] for the CPU. 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000; 620Sstevel@tonic-gate 634667Smh27603 /* 644667Smh27603 * Current frequency in Hz. 654667Smh27603 */ 664718Smh27603 cp->cpu_curr_clock = cpunode->clock_freq; 674667Smh27603 680Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "sparcv9"); 690Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "sparcv9"); 700Sstevel@tonic-gate 710Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), 720Sstevel@tonic-gate "%s (cpuid %d clock %d MHz)", 730Sstevel@tonic-gate cpunode->name, cpunode->cpuid, 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); 943266Sjb145095 /* 953266Sjb145095 * On first cpu setup, tell hv we are booting 963266Sjb145095 */ 973266Sjb145095 mach_set_soft_state(SIS_TRANSITION, 984677Szx151605 &SOLARIS_SOFT_STATE_BOOT_MSG); 990Sstevel@tonic-gate #ifdef lint 1000Sstevel@tonic-gate cpuid = cpuid; 1010Sstevel@tonic-gate #endif /* lint */ 1020Sstevel@tonic-gate } 1030Sstevel@tonic-gate } 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* 1061991Sheppo * Routine used to cleanup a CPU that has been powered off. This will 1070Sstevel@tonic-gate * destroy all per-cpu information related to this cpu. 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate int 1100Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid) 1110Sstevel@tonic-gate { 1121991Sheppo int retval; 1131991Sheppo extern void empty_cpu(int); 1141991Sheppo extern int cleanup_cpu_common(int); 1151991Sheppo 1161991Sheppo ASSERT(MUTEX_HELD(&cpu_lock)); 1171991Sheppo 1181991Sheppo retval = cleanup_cpu_common(cpuid); 1191991Sheppo 1201991Sheppo empty_cpu(cpuid); 1211991Sheppo 1221991Sheppo return (retval); 1230Sstevel@tonic-gate } 1240Sstevel@tonic-gate 1251991Sheppo struct mp_find_cpu_arg { 1261991Sheppo int cpuid; /* set by mp_cpu_configure() */ 1271991Sheppo dev_info_t *dip; /* set by mp_find_cpu() */ 1281991Sheppo }; 1291991Sheppo 1300Sstevel@tonic-gate int 1310Sstevel@tonic-gate mp_find_cpu(dev_info_t *dip, void *arg) 1320Sstevel@tonic-gate { 1331991Sheppo struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg; 1341991Sheppo char *type; 1351991Sheppo int rv = DDI_WALK_CONTINUE; 1361991Sheppo int cpuid; 1371991Sheppo 1381991Sheppo if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 1391991Sheppo DDI_PROP_DONTPASS, "device_type", &type)) 1401991Sheppo return (DDI_WALK_CONTINUE); 1411991Sheppo 1421991Sheppo if (strcmp(type, "cpu") != 0) 1431991Sheppo goto out; 1441991Sheppo 1451991Sheppo cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 1461991Sheppo DDI_PROP_DONTPASS, "reg", -1); 1471991Sheppo 1481991Sheppo if (cpuid == -1) { 1491991Sheppo cmn_err(CE_PANIC, "reg prop not found in cpu node"); 1501991Sheppo } 1511991Sheppo 1521991Sheppo cpuid = PROM_CFGHDL_TO_CPUID(cpuid); 1531991Sheppo 1541991Sheppo if (cpuid != target->cpuid) 1551991Sheppo goto out; 1561991Sheppo 1571991Sheppo /* Found it */ 1581991Sheppo rv = DDI_WALK_TERMINATE; 1591991Sheppo target->dip = dip; 1601991Sheppo 1611991Sheppo out: 1621991Sheppo ddi_prop_free(type); 1631991Sheppo return (rv); 1640Sstevel@tonic-gate } 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate /* 1670Sstevel@tonic-gate * Routine used to setup a newly inserted CPU in preparation for starting 1680Sstevel@tonic-gate * it running code. 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate int 1710Sstevel@tonic-gate mp_cpu_configure(int cpuid) 1720Sstevel@tonic-gate { 1731991Sheppo extern void fill_cpu(md_t *, mde_cookie_t); 1744050Sjb145095 extern int setup_cpu_common(int); 1754050Sjb145095 extern int cleanup_cpu_common(int); 1761991Sheppo extern void setup_exec_unit_mappings(md_t *); 1771991Sheppo 1784203Srsmaeda md_t *mdp; 1794203Srsmaeda mde_cookie_t rootnode, cpunode = MDE_INVAL_ELEM_COOKIE; 1804203Srsmaeda int listsz, i; 1814203Srsmaeda mde_cookie_t *listp = NULL; 1824203Srsmaeda int num_nodes; 1834203Srsmaeda uint64_t cpuid_prop; 1844203Srsmaeda cpu_t *cpu; 1854203Srsmaeda processorid_t id; 1861991Sheppo 1871991Sheppo ASSERT(MUTEX_HELD(&cpu_lock)); 1881991Sheppo 1891991Sheppo if ((mdp = md_get_handle()) == NULL) 1901991Sheppo return (ENODEV); 1911991Sheppo 1921991Sheppo rootnode = md_root_node(mdp); 1931991Sheppo 1941991Sheppo ASSERT(rootnode != MDE_INVAL_ELEM_COOKIE); 1951991Sheppo 1961991Sheppo num_nodes = md_node_count(mdp); 1971991Sheppo 1981991Sheppo ASSERT(num_nodes > 0); 1991991Sheppo 2001991Sheppo listsz = num_nodes * sizeof (mde_cookie_t); 2011991Sheppo listp = kmem_zalloc(listsz, KM_SLEEP); 2021991Sheppo 2031991Sheppo num_nodes = md_scan_dag(mdp, rootnode, md_find_name(mdp, "cpu"), 2041991Sheppo md_find_name(mdp, "fwd"), listp); 2051991Sheppo 2061991Sheppo if (num_nodes < 0) 2071991Sheppo return (ENODEV); 2081991Sheppo 2091991Sheppo for (i = 0; i < num_nodes; i++) { 2101991Sheppo if (md_get_prop_val(mdp, listp[i], "id", &cpuid_prop)) 2111991Sheppo break; 2121991Sheppo if (cpuid_prop == (uint64_t)cpuid) { 2131991Sheppo cpunode = listp[i]; 2141991Sheppo break; 2151991Sheppo } 2161991Sheppo } 2171991Sheppo 2181991Sheppo if (cpunode == MDE_INVAL_ELEM_COOKIE) 2191991Sheppo return (ENODEV); 2201991Sheppo 2211991Sheppo kmem_free(listp, listsz); 2221991Sheppo 2231991Sheppo /* 2244677Szx151605 * Note: uses cpu_lock to protect cpunodes 2251991Sheppo * which will be modified inside of fill_cpu and 2261991Sheppo * setup_exec_unit_mappings. 2271991Sheppo */ 2281991Sheppo fill_cpu(mdp, cpunode); 2291991Sheppo 2301991Sheppo /* 2314203Srsmaeda * Adding a CPU may cause the execution unit sharing 2324203Srsmaeda * relationships to change. Update the mappings in 2334203Srsmaeda * the cpunode structures. 2341991Sheppo */ 2351991Sheppo setup_exec_unit_mappings(mdp); 2361991Sheppo 2374203Srsmaeda /* propagate the updated mappings to the CPU structures */ 2384203Srsmaeda for (id = 0; id < NCPU; id++) { 2394203Srsmaeda if ((cpu = cpu_get(id)) == NULL) 2404203Srsmaeda continue; 2414203Srsmaeda 2424203Srsmaeda cpu_map_exec_units(cpu); 2434203Srsmaeda } 2444203Srsmaeda 2451991Sheppo (void) md_fini_handle(mdp); 2461991Sheppo 2474050Sjb145095 if ((i = setup_cpu_common(cpuid)) != 0) { 2484050Sjb145095 (void) cleanup_cpu_common(cpuid); 2494050Sjb145095 return (i); 2504050Sjb145095 } 2514203Srsmaeda 2520Sstevel@tonic-gate return (0); 2530Sstevel@tonic-gate } 2542957Sjm22469 2552957Sjm22469 /* 2562957Sjm22469 * Platform-specific actions to be taken when all cpus are running 2572957Sjm22469 * in the OS. 2582957Sjm22469 */ 2592957Sjm22469 void 2602957Sjm22469 cpu_mp_init(void) 2612957Sjm22469 { 2622957Sjm22469 extern void recalc_xc_timeouts(); 2632957Sjm22469 extern int cif_cpu_mp_ready; 2642957Sjm22469 2652957Sjm22469 /* N.B. This must happen after xc_init() has run. */ 2662957Sjm22469 recalc_xc_timeouts(); 2672957Sjm22469 268*4776Sjm22469 if (!domaining_enabled()) 2692957Sjm22469 return; 2702957Sjm22469 2712957Sjm22469 cif_cpu_mp_ready = 1; 2722957Sjm22469 } 273