pmc.c revision 6c9bfa0b39999e3f2c9448ede1e4cbd8bfaca728
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Driver for the Power Management Controller (logical unit 8) of the
* PC87317 SuperI/O chip. The PMC contains the hardware watchdog timer.
*/
#ifdef DEBUG
int pmc_debug_flag = 0;
#else
#endif /* DEBUG */
/* Driver soft state structure */
typedef struct pmc {
} pmc_t;
static void *pmc_soft_state;
static int instance = -1;
/* dev_ops and cb_ops entry point function declarations */
/* hardware watchdog parameters */
static uint_t pmc_clear_watchdog_timer(void);
extern volatile uint8_t *v_pmc_addr_reg;
extern volatile uint8_t *v_pmc_data_reg;
extern int watchdog_enable;
extern int watchdog_available;
extern int watchdog_activated;
extern int boothowto;
extern uint_t watchdog_timeout_seconds;
/*
* Power Management Registers and values
*/
#define PMC_CLEAR_WDTO 0x00
struct cb_ops pmc_cb_ops = {
nodev, /* dump */
nodev, /* devmap */
NULL, /* for STREAMS drivers */
};
static struct dev_ops pmc_dev_ops = {
DEVO_REV, /* driver build version */
0, /* device reference count */
nulldev, /* probe */
nulldev, /* reset */
nulldev /* power */
};
/* module configuration stuff */
extern struct mod_ops mod_driverops;
"pmc driver %I%",
};
static struct modlinkage modlinkage = {
&modldrv,
0
};
int
_init(void)
{
int e;
if (e != 0) {
DPRINTF(("_init: ddi_soft_state_init failed\n"));
return (e);
}
e = mod_install(&modlinkage);
if (e != 0) {
DPRINTF(("_init: mod_install failed\n"));
return (e);
}
if (v_pmc_addr_reg != NULL) {
/*
* See if the user has enabled the watchdog timer, and if
* it's available.
*/
if (watchdog_enable) {
if (!watchdog_available) {
"unavailable");
watchdog_available = 0;
"detected: hardware watchdog disabled");
}
}
}
return (e);
}
int
_fini(void)
{
int e;
if (v_pmc_addr_reg != NULL)
return (DDI_FAILURE);
else {
e = mod_remove(&modlinkage);
if (e != 0)
return (e);
return (DDI_SUCCESS);
}
}
int
{
}
static int
{
int instance;
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
case DDI_INFO_DEVT2INSTANCE:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
static int
{
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
int ret = 0;
if (ret == 0)
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
if (instance != -1) {
DPRINTF(("pmc_attach: Another instance is already attached."));
return (DDI_FAILURE);
}
DPRINTF(("pmc_attach: Failed to allocate soft state."));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
{
switch (cmd) {
case DDI_DETACH:
/* allow detach if no hardware watchdog */
instance);
return (ENXIO);
return (DDI_SUCCESS);
} else
return (DDI_FAILURE);
case DDI_SUSPEND:
(void) tod_ops.tod_clear_watchdog_timer();
}
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
/*
* Set the hardware watchdog timer; returning what we set it to.
*/
static uint_t
{
/* sanity checks */
if (watchdog_enable == 0 || watchdog_available == 0 ||
timeoutval == 0)
return (0);
/*
* Historically the timer has been counted out in seconds.
* The PC87317 counts the timeout in minutes. The default
* timeout is 10 seconds; the least we can do is one minute.
*/
if (timeoutval_minutes > UINT8_MAX)
return (0);
watchdog_activated = 1;
/* we'll still return seconds */
return (timeoutval_minutes * 60);
}
/*
* Clear the hardware watchdog timer; returning what it was set to.
*/
static uint_t
pmc_clear_watchdog_timer(void)
{
if (watchdog_activated == 0)
return (0);
watchdog_activated = 0;
/* return seconds */
return (wd_timeout * 60);
}