a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CDDL HEADER START
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * The contents of this file are subject to the terms of the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Common Development and Distribution License (the "License").
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * You may not use this file except in compliance with the License.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * See the License for the specific language governing permissions
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * and limitations under the License.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * When distributing Covered Code, include this CDDL HEADER in each
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If applicable, add the following below this CDDL HEADER, with the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * fields enclosed by brackets "[]" replaced with your own identifying
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * information: Portions Copyright [yyyy] [name of copyright owner]
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CDDL HEADER END
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Use is subject to license terms.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright (c) 2010, Intel Corporation.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * All rights reserved.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CPU support routines for DR
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/* for the DR*INTERNAL_ERROR macros. see sys/dr.h. */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_cpu_unit_is_sane(dr_board_t *bp, dr_cpu_unit_t *cp)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * On x86, the "clock-frequency" and cache size device properties may be
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * unavailable before CPU starts. If they are unavailabe, just set them to zero.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* read in the CPU speed */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu clock_freq = (unsigned int)ddi_prop_get_int(DDI_DEV_T_ANY, dip,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * The ecache property string is not the same
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * for all CPU implementations.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu cmn_err(CE_WARN, "Unknown cpu implementation=0x%x",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* read in the ecache size */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If the property is not found in the CPU node,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * it has to be kept in the core or cmp node so
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * we just keep looking.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ecache_size = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 0,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* convert to the proper units */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu err = drmach_cpu_get_id(cp->sbc_cm.sbdev_id, &cpuid);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu err = drmach_cpu_get_impl(cp->sbc_cm.sbdev_id, &impl);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* if true at init time, it must always be true */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(dr_cpu_unit_is_sane(cp->sbc_cm.sbdev_bp, cp));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* delay transition until fully initialized */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_pre_attach_cpu(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < devnum; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Print a console message for each attachment
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * point. For CMP devices, this means that only
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * one message should be printed, no matter how
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * many cores are actually present.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((up->sbc_cm.sbdev_unum % MAX_CORES_PER_CMP) == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Block out status threads while creating
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * devinfo tree branches
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ndi_devi_enter(ddi_root_node(), (int *)(&hp->h_ndi));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_attach_cpu(dr_handle_t *hp, dr_common_unit_t *cp)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu err = drmach_unconfigure(cp->sbdev_id, DEVI_BRANCH_DESTROY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu err = drmach_unconfigure(cp->sbdev_id, DEVI_BRANCH_DESTROY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * dr_post_attach_cpu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * sbd error policy: Does not stop on error. Processes all units in list.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_post_attach_cpu(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Startup and online newly-attached CPUs */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < devnum; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_CPU("%s: cpu %d powered ON\n", f, up->sbc_cpu_id);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_CPU("%s: onlining cpu %d...\n", f, up->sbc_cpu_id);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * dr_pre_release_cpu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * sbd error policy: Stops on first error.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_pre_release_cpu(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* allocate status struct storage. */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ds = (sbd_dev_stat_t *) kmem_zalloc(sizeof (sbd_dev_stat_t) *
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < devnum; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * On x86 systems, some CPUs can't be unconfigured.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * For example, CPU0 can't be unconfigured because many other
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * components have a dependency on it.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * This check determines if a CPU is currently in use and
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * returns a "Device busy" error if so.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (c = 0; c < cix; c++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ds[c].d_cpu.cs_unit == up->sbc_cm.sbdev_unum) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* used by dr_cancel_cpu during error flow */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Need to unwind others since at this level (pre-release)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the device state has not yet transitioned and failures
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * will prevent us from reaching the "post" release
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * function where states are normally transitioned.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = lastoffline; i >= 0; i--) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu kmem_free(ds, sizeof (sbd_dev_stat_t) * MAX_CPU_UNITS_PER_BOARD);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * dr_pre_detach_cpu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * sbd error policy: Stops on first error.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_pre_detach_cpu(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Block out status threads while destroying devinfo tree
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < devnum; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Print a console message for each attachment
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * point. For CMP devices, this means that only
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * one message should be printed, no matter how
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * many cores are actually present.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((up->sbc_cm.sbdev_unum % MAX_CORES_PER_CMP) == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CPUs were offlined during Release.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* cpu was onlined after release. Offline it again */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_CPU("%s: offlining cpu %d\n", f, up->sbc_cpu_id);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_CPU("%s: cpu %d powered OFF\n", f, up->sbc_cpu_id);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_detach_cpu(dr_handle_t *hp, dr_common_unit_t *cp)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu err = drmach_unconfigure(cp->sbdev_id, DEVI_BRANCH_DESTROY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/*ARGSUSED1*/
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_post_detach_cpu(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_fill_cpu_stat(dr_cpu_unit_t *cp, drmach_status_t *pstat, sbd_cpu_stat_t *csp)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Fill in the common status information */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) strlcpy(csp->cs_name, pstat->type, sizeof (csp->cs_name));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu csp->cs_busy = cp->sbc_cm.sbdev_busy | pstat->busy;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* CPU specific status data */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If the speed and ecache properties have not been
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * cached yet, read them in from the device tree.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((cp->sbc_speed == 0) || (cp->sbc_ecache == 0))
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* use the cached speed and ecache values */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* ostate must be UNCONFIGURED */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/*ARGSUSED2*/
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_fill_cmp_stat(sbd_cpu_stat_t *csp, int ncores, int impl, sbd_cmp_stat_t *psp)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Fill in the common status information based
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * on the data for the first core.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu psp->ps_unit = DR_UNUM2SBD_UNUM(csp->cs_unit, SBD_COMP_CMP);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) strlcpy(psp->ps_name, csp->cs_name, sizeof (psp->ps_name));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* CMP specific status data */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Walk through the data for the remaining cores.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Make any adjustments to the common status data,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * or the shared CMP specific data if necessary.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * The following properties should be the same
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * for all the cores of the CMP.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(psp->ps_unit == DR_UNUM2SBD_UNUM(csp[core].cs_unit,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* adjust time if necessary */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If any of the cores are configured, the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * entire CMP is marked as configured.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_cpu_status(dr_handle_t *hp, dr_devset_t devset, sbd_dev_stat_t *dsp)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu cstat = kmem_zalloc(sizeof (sbd_cpu_stat_t) * MAX_CORES_PER_CMP,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Treat every CPU as a CMP. In the case where the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * device is not a CMP, treat it as a CMP with only
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (cmp = 0; cmp < MAX_CMP_UNITS_PER_BOARD; cmp++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (core = 0; core < MAX_CORES_PER_CMP; core++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu cp = dr_get_cpu_unit(bp, DR_CMP_CORE_UNUM(cmp, core));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* present, but not fully initialized */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* skip if not present */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* fetch platform status */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * We should set impl here because the last core
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * found might be EMPTY or not present.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Store the data to the outgoing array. If the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * device is a CMP, combine all the data for the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * cores into a single stat structure.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * The check for a CMP device uses the last core
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * found, assuming that all cores will have the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * same implementation.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu kmem_free(cstat, sizeof (sbd_cpu_stat_t) * MAX_CORES_PER_CMP);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Cancel previous release operation for cpu.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * For cpus this means simply bringing cpus that
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * were offline back online. Note that they had
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * to have been online at the time there were
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(dr_cpu_unit_is_sane(up->sbc_cm.sbdev_bp, up));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CPU had been online, go ahead
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * bring it back online.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_CPU("%s: bringing cpu %d back ONLINE\n", f, up->sbc_cpu_id);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "disable interrupts on cpu %d", f,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT((up->sbc_cm.sbdev_state == DR_STATE_CONNECTED) ||
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (up->sbc_cm.sbdev_state == DR_STATE_UNCONFIGURED));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(dr_cpu_unit_is_sane(up->sbc_cm.sbdev_bp, up));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (up->sbc_cm.sbdev_state == DR_STATE_CONNECTED) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Cpus were never brought in and so are still
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * effectively disconnected, so nothing to do here.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_CPU("%s: cpu %d never brought in\n", f, up->sbc_cpu_id);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*NOTREACHED*/