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 /*
23*12804SAlexandre.Chartre@oracle.com * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
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>
301991Sheppo #include <sys/mach_descrip.h>
312957Sjm22469 #include <sys/ldoms.h>
323266Sjb145095 #include <sys/hypervisor_api.h>
333266Sjb145095 #include <sys/soft_state.h>
345468Sjc25722 #include <sys/mpo.h>
350Sstevel@tonic-gate
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate * Useful for disabling MP bring-up for an MP capable kernel
380Sstevel@tonic-gate * (a kernel that was built with MP defined)
390Sstevel@tonic-gate */
400Sstevel@tonic-gate int use_mp = 1; /* set to come up mp */
410Sstevel@tonic-gate
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate * Init CPU info - get CPU type info for processor_info system call.
440Sstevel@tonic-gate */
450Sstevel@tonic-gate void
init_cpu_info(struct cpu * cp)460Sstevel@tonic-gate init_cpu_info(struct cpu *cp)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate processor_info_t *pi = &cp->cpu_type_info;
490Sstevel@tonic-gate int cpuid = cp->cpu_id;
500Sstevel@tonic-gate struct cpu_node *cpunode = &cpunodes[cpuid];
510Sstevel@tonic-gate
520Sstevel@tonic-gate cp->cpu_fpowner = NULL; /* not used for V9 */
530Sstevel@tonic-gate
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate * Get clock-frequency property from cpunodes[] for the CPU.
560Sstevel@tonic-gate */
570Sstevel@tonic-gate pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000;
580Sstevel@tonic-gate
594667Smh27603 /*
604667Smh27603 * Current frequency in Hz.
614667Smh27603 */
624718Smh27603 cp->cpu_curr_clock = cpunode->clock_freq;
634667Smh27603
644877Smh27603 /*
654877Smh27603 * Supported frequencies.
664877Smh27603 */
674877Smh27603 cpu_set_supp_freqs(cp, NULL);
684877Smh27603
690Sstevel@tonic-gate (void) strcpy(pi->pi_processor_type, "sparcv9");
700Sstevel@tonic-gate (void) strcpy(pi->pi_fputypes, "sparcv9");
710Sstevel@tonic-gate
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate * StarFire requires the signature block stuff setup here
740Sstevel@tonic-gate */
750Sstevel@tonic-gate CPU_SGN_MAPIN(cpuid);
76*12804SAlexandre.Chartre@oracle.com
77*12804SAlexandre.Chartre@oracle.com /*
78*12804SAlexandre.Chartre@oracle.com * cpu0 is always initialized at boot time, but it can be initialized
79*12804SAlexandre.Chartre@oracle.com * again if it is dynamically removed and then re-added. We check if
80*12804SAlexandre.Chartre@oracle.com * we are booting by verifying cpu_list. During boot, cpu0 is already
81*12804SAlexandre.Chartre@oracle.com * in cpu_list when this function is called. When a cpu is dynamically
82*12804SAlexandre.Chartre@oracle.com * added (after the boot) then it is added to cpu_list after this
83*12804SAlexandre.Chartre@oracle.com * function is called.
84*12804SAlexandre.Chartre@oracle.com */
85*12804SAlexandre.Chartre@oracle.com if (cpuid == cpu0.cpu_id && ncpus == 1 && cpu_list[0].cpu_id == cpuid) {
860Sstevel@tonic-gate /*
870Sstevel@tonic-gate * cpu0 starts out running. Other cpus are
880Sstevel@tonic-gate * still in OBP land and we will leave them
890Sstevel@tonic-gate * alone for now.
900Sstevel@tonic-gate */
910Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid);
923266Sjb145095 /*
933266Sjb145095 * On first cpu setup, tell hv we are booting
943266Sjb145095 */
953266Sjb145095 mach_set_soft_state(SIS_TRANSITION,
964677Szx151605 &SOLARIS_SOFT_STATE_BOOT_MSG);
970Sstevel@tonic-gate #ifdef lint
980Sstevel@tonic-gate cpuid = cpuid;
990Sstevel@tonic-gate #endif /* lint */
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate /*
1041991Sheppo * Routine used to cleanup a CPU that has been powered off. This will
1050Sstevel@tonic-gate * destroy all per-cpu information related to this cpu.
1060Sstevel@tonic-gate */
1070Sstevel@tonic-gate int
mp_cpu_unconfigure(int cpuid)1080Sstevel@tonic-gate mp_cpu_unconfigure(int cpuid)
1090Sstevel@tonic-gate {
1101991Sheppo int retval;
1111991Sheppo extern void empty_cpu(int);
1121991Sheppo extern int cleanup_cpu_common(int);
1131991Sheppo
1141991Sheppo ASSERT(MUTEX_HELD(&cpu_lock));
1151991Sheppo
1161991Sheppo retval = cleanup_cpu_common(cpuid);
1171991Sheppo
1181991Sheppo empty_cpu(cpuid);
1191991Sheppo
1205468Sjc25722 mpo_cpu_remove(cpuid);
1215468Sjc25722
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
mp_find_cpu(dev_info_t * dip,void * arg)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
mp_cpu_configure(int cpuid)1710Sstevel@tonic-gate mp_cpu_configure(int cpuid)
1720Sstevel@tonic-gate {
1734203Srsmaeda md_t *mdp;
1744203Srsmaeda mde_cookie_t rootnode, cpunode = MDE_INVAL_ELEM_COOKIE;
1754203Srsmaeda int listsz, i;
1764203Srsmaeda mde_cookie_t *listp = NULL;
1774203Srsmaeda int num_nodes;
1784203Srsmaeda uint64_t cpuid_prop;
1794203Srsmaeda cpu_t *cpu;
1804203Srsmaeda processorid_t id;
1811991Sheppo
1821991Sheppo ASSERT(MUTEX_HELD(&cpu_lock));
1831991Sheppo
1841991Sheppo if ((mdp = md_get_handle()) == NULL)
1851991Sheppo return (ENODEV);
1861991Sheppo
1871991Sheppo rootnode = md_root_node(mdp);
1881991Sheppo
1891991Sheppo ASSERT(rootnode != MDE_INVAL_ELEM_COOKIE);
1901991Sheppo
1911991Sheppo num_nodes = md_node_count(mdp);
1921991Sheppo
1931991Sheppo ASSERT(num_nodes > 0);
1941991Sheppo
1951991Sheppo listsz = num_nodes * sizeof (mde_cookie_t);
1961991Sheppo listp = kmem_zalloc(listsz, KM_SLEEP);
1971991Sheppo
1981991Sheppo num_nodes = md_scan_dag(mdp, rootnode, md_find_name(mdp, "cpu"),
1991991Sheppo md_find_name(mdp, "fwd"), listp);
2001991Sheppo
2011991Sheppo if (num_nodes < 0)
2021991Sheppo return (ENODEV);
2031991Sheppo
2041991Sheppo for (i = 0; i < num_nodes; i++) {
2051991Sheppo if (md_get_prop_val(mdp, listp[i], "id", &cpuid_prop))
2061991Sheppo break;
2071991Sheppo if (cpuid_prop == (uint64_t)cpuid) {
2081991Sheppo cpunode = listp[i];
2091991Sheppo break;
2101991Sheppo }
2111991Sheppo }
2121991Sheppo
2131991Sheppo if (cpunode == MDE_INVAL_ELEM_COOKIE)
2141991Sheppo return (ENODEV);
2151991Sheppo
2161991Sheppo kmem_free(listp, listsz);
2171991Sheppo
21812013SHaik.Aftandilian@Sun.COM mpo_cpu_add(mdp, cpuid);
2195468Sjc25722
2201991Sheppo /*
2214677Szx151605 * Note: uses cpu_lock to protect cpunodes
2221991Sheppo * which will be modified inside of fill_cpu and
2231991Sheppo * setup_exec_unit_mappings.
2241991Sheppo */
2251991Sheppo fill_cpu(mdp, cpunode);
2261991Sheppo
2271991Sheppo /*
2284203Srsmaeda * Adding a CPU may cause the execution unit sharing
2294203Srsmaeda * relationships to change. Update the mappings in
2304203Srsmaeda * the cpunode structures.
2311991Sheppo */
2325000Sjc25722 setup_chip_mappings(mdp);
2331991Sheppo setup_exec_unit_mappings(mdp);
2341991Sheppo
2354203Srsmaeda /* propagate the updated mappings to the CPU structures */
2364203Srsmaeda for (id = 0; id < NCPU; id++) {
2374203Srsmaeda if ((cpu = cpu_get(id)) == NULL)
2384203Srsmaeda continue;
2394203Srsmaeda
2404203Srsmaeda cpu_map_exec_units(cpu);
2414203Srsmaeda }
2424203Srsmaeda
2431991Sheppo (void) md_fini_handle(mdp);
2441991Sheppo
2454050Sjb145095 if ((i = setup_cpu_common(cpuid)) != 0) {
2464050Sjb145095 (void) cleanup_cpu_common(cpuid);
2474050Sjb145095 return (i);
2484050Sjb145095 }
2494203Srsmaeda
2500Sstevel@tonic-gate return (0);
2510Sstevel@tonic-gate }
2522957Sjm22469
2532957Sjm22469 /*
2542957Sjm22469 * Platform-specific actions to be taken when all cpus are running
2552957Sjm22469 * in the OS.
2562957Sjm22469 */
2572957Sjm22469 void
cpu_mp_init(void)2582957Sjm22469 cpu_mp_init(void)
2592957Sjm22469 {
2602957Sjm22469 extern void recalc_xc_timeouts();
2612957Sjm22469 extern int cif_cpu_mp_ready;
2622957Sjm22469
2632957Sjm22469 /* N.B. This must happen after xc_init() has run. */
2642957Sjm22469 recalc_xc_timeouts();
2652957Sjm22469
2664776Sjm22469 if (!domaining_enabled())
2672957Sjm22469 return;
2682957Sjm22469
2692957Sjm22469 cif_cpu_mp_ready = 1;
2702957Sjm22469 }
2717718SJason.Beloro@Sun.COM
2727718SJason.Beloro@Sun.COM void
populate_idstr(struct cpu * cp)2737718SJason.Beloro@Sun.COM populate_idstr(struct cpu *cp)
2747718SJason.Beloro@Sun.COM {
2757718SJason.Beloro@Sun.COM char buf[CPU_IDSTRLEN];
2767718SJason.Beloro@Sun.COM struct cpu_node *cpunode;
2777718SJason.Beloro@Sun.COM processor_info_t *pi;
2787718SJason.Beloro@Sun.COM
2797718SJason.Beloro@Sun.COM cpunode = &cpunodes[cp->cpu_id];
2807718SJason.Beloro@Sun.COM pi = &cp->cpu_type_info;
2817718SJason.Beloro@Sun.COM if (cp->cpu_m.cpu_chip == CPU_CHIPID_INVALID) {
2827718SJason.Beloro@Sun.COM (void) snprintf(buf, sizeof (buf),
2837718SJason.Beloro@Sun.COM "%s (cpuid %d, clock %d MHz)",
2847718SJason.Beloro@Sun.COM cpunode->name, cpunode->cpuid, pi->pi_clock);
2857718SJason.Beloro@Sun.COM } else {
2867718SJason.Beloro@Sun.COM (void) snprintf(buf, sizeof (buf),
2877718SJason.Beloro@Sun.COM "%s (chipid %d, clock %d MHz)",
2887718SJason.Beloro@Sun.COM cpunode->name, cp->cpu_m.cpu_chip, pi->pi_clock);
2897718SJason.Beloro@Sun.COM }
2907718SJason.Beloro@Sun.COM
2917718SJason.Beloro@Sun.COM cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
2927718SJason.Beloro@Sun.COM (void) strcpy(cp->cpu_idstr, buf);
2937718SJason.Beloro@Sun.COM
2947718SJason.Beloro@Sun.COM cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP);
2957718SJason.Beloro@Sun.COM (void) strcpy(cp->cpu_brandstr, cpunode->name);
2967718SJason.Beloro@Sun.COM
2977718SJason.Beloro@Sun.COM cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr);
2987718SJason.Beloro@Sun.COM }
299