simmstat.c revision 07d06da50d310a325b457d6330165aebab1e0064
29949e866e40b95795203f3ee46f44a197c946e4stevel * CDDL HEADER START
29949e866e40b95795203f3ee46f44a197c946e4stevel * The contents of this file are subject to the terms of the
29949e866e40b95795203f3ee46f44a197c946e4stevel * Common Development and Distribution License (the "License").
29949e866e40b95795203f3ee46f44a197c946e4stevel * You may not use this file except in compliance with the License.
29949e866e40b95795203f3ee46f44a197c946e4stevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
29949e866e40b95795203f3ee46f44a197c946e4stevel * See the License for the specific language governing permissions
29949e866e40b95795203f3ee46f44a197c946e4stevel * and limitations under the License.
29949e866e40b95795203f3ee46f44a197c946e4stevel * When distributing Covered Code, include this CDDL HEADER in each
29949e866e40b95795203f3ee46f44a197c946e4stevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
29949e866e40b95795203f3ee46f44a197c946e4stevel * If applicable, add the following below this CDDL HEADER, with the
29949e866e40b95795203f3ee46f44a197c946e4stevel * fields enclosed by brackets "[]" replaced with your own identifying
29949e866e40b95795203f3ee46f44a197c946e4stevel * information: Portions Copyright [yyyy] [name of copyright owner]
29949e866e40b95795203f3ee46f44a197c946e4stevel * CDDL HEADER END
07d06da50d310a325b457d6330165aebab1e0064Surya Prakki * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
29949e866e40b95795203f3ee46f44a197c946e4stevel * Use is subject to license terms.
29949e866e40b95795203f3ee46f44a197c946e4stevel/* Useful debugging Stuff */
29949e866e40b95795203f3ee46f44a197c946e4stevel * Function prototypes
29949e866e40b95795203f3ee46f44a197c946e4stevelstatic int simmstat_attach(dev_info_t *, ddi_attach_cmd_t);
29949e866e40b95795203f3ee46f44a197c946e4stevelstatic int simmstat_detach(dev_info_t *, ddi_detach_cmd_t);
29949e866e40b95795203f3ee46f44a197c946e4stevelstatic void simmstat_add_kstats(struct simmstat_soft_state *);
29949e866e40b95795203f3ee46f44a197c946e4stevel * Configuration data structures
29949e866e40b95795203f3ee46f44a197c946e4stevel 0, /* streamtab */
29949e866e40b95795203f3ee46f44a197c946e4stevel D_MP | D_NEW | D_HOTPLUG, /* Driver compatibility flag */
29949e866e40b95795203f3ee46f44a197c946e4stevel 0, /* refcnt */
29949e866e40b95795203f3ee46f44a197c946e4stevel * Driver globals
29949e866e40b95795203f3ee46f44a197c946e4stevel &mod_driverops, /* module type, this one is a driver */
29949e866e40b95795203f3ee46f44a197c946e4stevel#endif /* lint */
29949e866e40b95795203f3ee46f44a197c946e4stevel * These are the module initialization routines.
29949e866e40b95795203f3ee46f44a197c946e4stevel return (0);
29949e866e40b95795203f3ee46f44a197c946e4stevelsimmstat_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
29949e866e40b95795203f3ee46f44a197c946e4stevel if (ddi_soft_state_zalloc(simmstatp, instance) != DDI_SUCCESS)
29949e866e40b95795203f3ee46f44a197c946e4stevel /* Set the dip in the soft state */
29949e866e40b95795203f3ee46f44a197c946e4stevel /* Get the board number from this nodes parent device. */
29949e866e40b95795203f3ee46f44a197c946e4stevel if ((softsp->board = (int)ddi_getprop(DDI_DEV_T_ANY, softsp->pdip,
29949e866e40b95795203f3ee46f44a197c946e4stevel cmn_err(CE_WARN, "simmstat%d: unable to retrieve %s property",
29949e866e40b95795203f3ee46f44a197c946e4stevel DPRINTF(SIMMSTAT_ATTACH_DEBUG, ("simmstat%d: devi= 0x%p\n, "
07d06da50d310a325b457d6330165aebab1e0064Surya Prakki " softsp=0x%p\n", instance, (void *)devi, (void *)softsp));
29949e866e40b95795203f3ee46f44a197c946e4stevel /* map in the registers for this device. */
29949e866e40b95795203f3ee46f44a197c946e4stevel cmn_err(CE_WARN, "simmstat%d: unable to map registers",
29949e866e40b95795203f3ee46f44a197c946e4stevel /* nothing to suspend/resume here */
29949e866e40b95795203f3ee46f44a197c946e4stevel /* create the kstats for this device */
29949e866e40b95795203f3ee46f44a197c946e4stevel/* ARGSUSED */
29949e866e40b95795203f3ee46f44a197c946e4stevelsimmstat_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
29949e866e40b95795203f3ee46f44a197c946e4stevel /* get the instance of this devi */
29949e866e40b95795203f3ee46f44a197c946e4stevel /* get the soft state pointer for this device node */
29949e866e40b95795203f3ee46f44a197c946e4stevel /* FALLTHROUGH */
29949e866e40b95795203f3ee46f44a197c946e4stevel /* remove the kstat for this board */
29949e866e40b95795203f3ee46f44a197c946e4stevel /* unmap the registers */
29949e866e40b95795203f3ee46f44a197c946e4stevel /* free up the soft state */
29949e866e40b95795203f3ee46f44a197c946e4stevelsimmstat_add_kstats(struct simmstat_soft_state *softsp)
29949e866e40b95795203f3ee46f44a197c946e4stevel if ((simmstat_ksp = kstat_create("unix", softsp->board,
29949e866e40b95795203f3ee46f44a197c946e4stevel * Kstats only need ks_update functions when they change dynamically
29949e866e40b95795203f3ee46f44a197c946e4stevel * at run time.
29949e866e40b95795203f3ee46f44a197c946e4stevel * In the case of the simmstat registers, they contain battery
29949e866e40b95795203f3ee46f44a197c946e4stevel * information for NVSIMMs. These need to be updated whenever a
29949e866e40b95795203f3ee46f44a197c946e4stevel * kstat_read asks for the data. There is currently no plan to
29949e866e40b95795203f3ee46f44a197c946e4stevel * ship NVSIMMs on this platform, but this support must be present.
29949e866e40b95795203f3ee46f44a197c946e4stevel volatile char *statp; /* pointer to hardware register */
29949e866e40b95795203f3ee46f44a197c946e4stevel softsp = (struct simmstat_soft_state *)ksp->ks_private;
29949e866e40b95795203f3ee46f44a197c946e4stevel /* this is a read-only kstat. Bail out on a write */
29949e866e40b95795203f3ee46f44a197c946e4stevel * copy current status of hardware into the kstat
29949e866e40b95795203f3ee46f44a197c946e4stevel * structure.
29949e866e40b95795203f3ee46f44a197c946e4stevel for (i = 0; i < SIMM_COUNT; i++, statp++, kstatp++) {
29949e866e40b95795203f3ee46f44a197c946e4stevel return (0);