mach_mp_startup.c revision 2f0fcb93196badcdd803715656c809058d9f3114
1N/A/*
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License (the "License").
1N/A * You may not use this file except in compliance with the License.
1N/A *
1N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * When distributing Covered Code, include this CDDL HEADER in each
1N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A * If applicable, add the following below this CDDL HEADER, with the
1N/A * fields enclosed by brackets "[]" replaced with your own identifying
1N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1N/A *
1N/A * CDDL HEADER END
1N/A */
1N/A
1N/A/*
1N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A */
1N/A
1N/A#include <sys/machsystm.h>
1N/A#include <sys/cpu_module.h>
1N/A#include <sys/dtrace.h>
1N/A#include <sys/cpu_sgnblk_defs.h>
1N/A#include <sys/mach_descrip.h>
1N/A#include <sys/ldoms.h>
1N/A#include <sys/hypervisor_api.h>
1N/A#include <sys/soft_state.h>
1N/A#include <sys/mpo.h>
1N/A
1N/A/*
1N/A * Useful for disabling MP bring-up for an MP capable kernel
1N/A * (a kernel that was built with MP defined)
1N/A */
1N/Aint use_mp = 1; /* set to come up mp */
1N/A
1N/A/*
1N/A * Init CPU info - get CPU type info for processor_info system call.
1N/A */
1N/Avoid
1N/Ainit_cpu_info(struct cpu *cp)
1N/A{
1N/A processor_info_t *pi = &cp->cpu_type_info;
1N/A int cpuid = cp->cpu_id;
1N/A struct cpu_node *cpunode = &cpunodes[cpuid];
1N/A
1N/A cp->cpu_fpowner = NULL; /* not used for V9 */
1N/A
1N/A /*
1N/A * Get clock-frequency property from cpunodes[] for the CPU.
1N/A */
1N/A pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000;
1N/A
1N/A /*
1N/A * Current frequency in Hz.
1N/A */
1N/A cp->cpu_curr_clock = cpunode->clock_freq;
1N/A
1N/A /*
1N/A * Supported frequencies.
1N/A */
1N/A cpu_set_supp_freqs(cp, NULL);
1N/A
1N/A (void) strcpy(pi->pi_processor_type, "sparcv9");
1N/A (void) strcpy(pi->pi_fputypes, "sparcv9");
1N/A
1N/A /*
1N/A * StarFire requires the signature block stuff setup here
1N/A */
1N/A CPU_SGN_MAPIN(cpuid);
1N/A if (cpuid == cpu0.cpu_id) {
1N/A /*
1N/A * cpu0 starts out running. Other cpus are
1N/A * still in OBP land and we will leave them
1N/A * alone for now.
1N/A */
1N/A CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid);
1N/A /*
1N/A * On first cpu setup, tell hv we are booting
1N/A */
1N/A mach_set_soft_state(SIS_TRANSITION,
1N/A &SOLARIS_SOFT_STATE_BOOT_MSG);
1N/A#ifdef lint
1N/A cpuid = cpuid;
1N/A#endif /* lint */
1N/A }
1N/A}
1N/A
1N/A/*
1N/A * Routine used to cleanup a CPU that has been powered off. This will
1N/A * destroy all per-cpu information related to this cpu.
1N/A */
1N/Aint
1N/Amp_cpu_unconfigure(int cpuid)
1N/A{
1N/A int retval;
1N/A extern void empty_cpu(int);
1N/A extern int cleanup_cpu_common(int);
1N/A
1N/A ASSERT(MUTEX_HELD(&cpu_lock));
1N/A
1N/A retval = cleanup_cpu_common(cpuid);
1N/A
1N/A empty_cpu(cpuid);
1N/A
1N/A mpo_cpu_remove(cpuid);
1N/A
1N/A return (retval);
1N/A}
1N/A
1N/Astruct mp_find_cpu_arg {
1N/A int cpuid; /* set by mp_cpu_configure() */
1N/A dev_info_t *dip; /* set by mp_find_cpu() */
1N/A};
1N/A
1N/Aint
1N/Amp_find_cpu(dev_info_t *dip, void *arg)
1N/A{
1N/A struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg;
1N/A char *type;
1N/A int rv = DDI_WALK_CONTINUE;
1N/A int cpuid;
1N/A
1N/A if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip,
1N/A DDI_PROP_DONTPASS, "device_type", &type))
1N/A return (DDI_WALK_CONTINUE);
1N/A
1N/A if (strcmp(type, "cpu") != 0)
1N/A goto out;
1N/A
1N/A cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
1N/A DDI_PROP_DONTPASS, "reg", -1);
1N/A
1N/A if (cpuid == -1) {
1N/A cmn_err(CE_PANIC, "reg prop not found in cpu node");
1N/A }
1N/A
1N/A cpuid = PROM_CFGHDL_TO_CPUID(cpuid);
1N/A
1N/A if (cpuid != target->cpuid)
1N/A goto out;
1N/A
1N/A /* Found it */
1N/A rv = DDI_WALK_TERMINATE;
1N/A target->dip = dip;
1N/A
1N/Aout:
1N/A ddi_prop_free(type);
1N/A return (rv);
1N/A}
1N/A
1N/A/*
1N/A * Routine used to setup a newly inserted CPU in preparation for starting
1N/A * it running code.
1N/A */
1N/Aint
1N/Amp_cpu_configure(int cpuid)
1N/A{
1N/A md_t *mdp;
1N/A mde_cookie_t rootnode, cpunode = MDE_INVAL_ELEM_COOKIE;
1N/A int listsz, i;
1N/A mde_cookie_t *listp = NULL;
1N/A int num_nodes;
1N/A uint64_t cpuid_prop;
1N/A cpu_t *cpu;
1N/A processorid_t id;
1N/A
1N/A ASSERT(MUTEX_HELD(&cpu_lock));
1N/A
1N/A if ((mdp = md_get_handle()) == NULL)
1N/A return (ENODEV);
1N/A
1N/A rootnode = md_root_node(mdp);
1N/A
1N/A ASSERT(rootnode != MDE_INVAL_ELEM_COOKIE);
1N/A
1N/A num_nodes = md_node_count(mdp);
1N/A
1N/A ASSERT(num_nodes > 0);
1N/A
1N/A listsz = num_nodes * sizeof (mde_cookie_t);
1N/A listp = kmem_zalloc(listsz, KM_SLEEP);
1N/A
1N/A num_nodes = md_scan_dag(mdp, rootnode, md_find_name(mdp, "cpu"),
1N/A md_find_name(mdp, "fwd"), listp);
1N/A
1N/A if (num_nodes < 0)
1N/A return (ENODEV);
1N/A
1N/A for (i = 0; i < num_nodes; i++) {
1N/A if (md_get_prop_val(mdp, listp[i], "id", &cpuid_prop))
1N/A break;
1N/A if (cpuid_prop == (uint64_t)cpuid) {
1N/A cpunode = listp[i];
1N/A break;
1N/A }
1N/A }
1N/A
1N/A if (cpunode == MDE_INVAL_ELEM_COOKIE)
1N/A return (ENODEV);
1N/A
1N/A kmem_free(listp, listsz);
1N/A
1N/A mpo_cpu_add(cpuid);
1N/A
1N/A /*
1N/A * Note: uses cpu_lock to protect cpunodes
1N/A * which will be modified inside of fill_cpu and
1N/A * setup_exec_unit_mappings.
1N/A */
1N/A fill_cpu(mdp, cpunode);
1N/A
1N/A /*
1N/A * Adding a CPU may cause the execution unit sharing
1N/A * relationships to change. Update the mappings in
1N/A * the cpunode structures.
1N/A */
1N/A setup_chip_mappings(mdp);
1N/A setup_exec_unit_mappings(mdp);
1N/A
1N/A /* propagate the updated mappings to the CPU structures */
1N/A for (id = 0; id < NCPU; id++) {
1N/A if ((cpu = cpu_get(id)) == NULL)
1N/A continue;
1N/A
1N/A cpu_map_exec_units(cpu);
1N/A }
1N/A
1N/A (void) md_fini_handle(mdp);
1N/A
1N/A if ((i = setup_cpu_common(cpuid)) != 0) {
1N/A (void) cleanup_cpu_common(cpuid);
1N/A return (i);
1N/A }
1N/A
1N/A return (0);
1N/A}
1N/A
1N/A/*
1N/A * Platform-specific actions to be taken when all cpus are running
1N/A * in the OS.
1N/A */
1N/Avoid
1N/Acpu_mp_init(void)
1N/A{
1N/A extern void recalc_xc_timeouts();
1N/A extern int cif_cpu_mp_ready;
1N/A
1N/A /* N.B. This must happen after xc_init() has run. */
1N/A recalc_xc_timeouts();
1N/A
1N/A if (!domaining_enabled())
1N/A return;
1N/A
1N/A cif_cpu_mp_ready = 1;
1N/A}
1N/A
1N/Avoid
1N/Apopulate_idstr(struct cpu *cp)
1N/A{
1N/A char buf[CPU_IDSTRLEN];
1N/A struct cpu_node *cpunode;
1N/A processor_info_t *pi;
1N/A
1N/A cpunode = &cpunodes[cp->cpu_id];
1N/A pi = &cp->cpu_type_info;
1N/A if (cp->cpu_m.cpu_chip == CPU_CHIPID_INVALID) {
1N/A (void) snprintf(buf, sizeof (buf),
1N/A "%s (cpuid %d, clock %d MHz)",
1N/A cpunode->name, cpunode->cpuid, pi->pi_clock);
1N/A } else {
1N/A (void) snprintf(buf, sizeof (buf),
1N/A "%s (chipid %d, clock %d MHz)",
1N/A cpunode->name, cp->cpu_m.cpu_chip, pi->pi_clock);
1N/A }
1N/A
1N/A cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP);
1N/A (void) strcpy(cp->cpu_idstr, buf);
1N/A
1N/A cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP);
1N/A (void) strcpy(cp->cpu_brandstr, cpunode->name);
1N/A
1N/A cmn_err(CE_CONT, "?cpu%d: %s\n", cp->cpu_id, cp->cpu_idstr);
1N/A}
1N/A