todsg.c revision 03831d35f7499c87d51205817c93e9a8d42c4bae
/*
* 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"
/*
* tod driver module for Serengeti
* This module implements a soft tod since
* Serengeti has no tod part.
*/
#include <sys/sgsbbc_iosram.h>
#include <sys/sysmacros.h>
static int todsg_debug = 0;
#else
#define DCMNERR
#endif /* DEBUG */
#define SC_DOWN_COUNT_THRESHOLD 2
#define SC_TOD_MIN_REV 2
static timestruc_t todsg_get(void);
static void todsg_set(timestruc_t);
static uint32_t todsg_clear_watchdog_timer(void);
static void todsg_set_power_alarm(timestruc_t);
static void todsg_clear_power_alarm(void);
static uint64_t todsg_get_cpufrequency(void);
static int update_heartbeat(void);
static int verify_sc_tod_version(void);
static uint32_t i_am_alive = 0;
static uint32_t sc_tod_version = 0;
static time_t skew_adjust = 0;
static int is_sc_down = 0;
static int adjust_sc_down = 0;
/*
* Module linkage information for the kernel.
*/
&mod_miscops, "Serengeti tod module v.%I%"
};
static struct modlinkage modlinkage = {
};
int
_init(void)
{
char obp_string[80];
/*
* To obtain the initial start of day time, we use an
* OBP callback; this is because the iosram is not yet
* accessible from the OS at this early stage of startup.
*/
/*
* Set the string to pass to OBP
*/
(void) sprintf(obp_string,
"h# %p \" unix-get-tod\" $find if execute else "
"3drop then",
(void *)&ssc_time);
prom_interpret(obp_string, 0, 0, 0, 0, 0);
"This can be caused by older firmware.");
"Controller firmware to the latest version.\n");
"based on the last shutdown.\n");
"correct if necessary.\n");
}
ssc_time);
/*
* an integer(32bit), so that we capture any corrupted
* date from SC, thereby preventing boot failure.
*/
if (TIMESPEC_OVERFLOW(&hrestime)) {
"based on the last shutdown.\n");
"correct if necessary.\n");
/*
* By setting hrestime.tv_sec to zero
* we force the vfs_mountroot() to set
* the date from the last shutdown.
*/
/*
* Save the skew so that we can update
* IOSRAM when it becomes accessible.
*/
skew_adjust = -ssc_time;
}
}
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (EBUSY);
else
return (mod_remove(&modlinkage));
}
int
{
}
static int
update_heartbeat(void)
{
int complained = 0;
/* Update the heartbeat */
if (i_am_alive == UINT32_MAX)
i_am_alive = 0;
else
i_am_alive++;
(char *)&i_am_alive, sizeof (uint32_t))) {
complained++;
}
return (complained);
}
static int
verify_sc_tod_version(void)
{
if (!todsg_use_sc)
return (FALSE);
/*
* read tod_version only when the first time and
* when there has been a previous sc down time
*/
magic != TODSG_MAGIC) {
"TOD SRAM magic error");
return (FALSE);
}
(char *)&sc_tod_version, sizeof (uint32_t))) {
"read tod version failed");
sc_tod_version = 0;
return (FALSE);
}
}
if (sc_tod_version >= SC_TOD_MIN_REV) {
return (TRUE);
} else {
todsg_use_sc = 0;
"todsg_get(): incorrect firmware version, "
"(%d): expected version >= %d.",
}
return (FALSE);
}
static int
{
int complained = 0;
(char *)&domain_skew, sizeof (time_t))) {
complained++;
"read tod domain skew failed");
}
domain_skew += skew;
/* we shall update the skew_adjust too now */
(char *)&domain_skew, sizeof (time_t))) {
complained++;
"write domain skew failed");
}
if (!complained)
skew_adjust = 0;
return (complained);
}
/*
* Return time value read from IOSRAM.
* Must be called with tod_lock held.
*/
static timestruc_t
todsg_get(void)
{
int complained = 0;
if (!verify_sc_tod_version()) {
/* if we can't use SC */
goto return_hrestime;
}
if (watchdog_activated != 0 || watchdog_enable != 0)
complained++;
}
if (!complained && skew_adjust) {
/*
* This is our first chance to update IOSRAM
* with local copy of the skew, so update it.
*/
complained = update_tod_skew(0);
}
(char *)&domain_skew, sizeof (time_t))) {
complained++;
}
if (complained) {
todsg_use_sc = 0;
goto return_hrestime;
}
/*
* If the SC gets rebooted, and we are using NTP, then we need
* to sync the IOSRAM to hrestime when the SC comes back. We
* can determine that either NTP slew (or date -a) was called if
* the global timedelta was non-zero at any point while the SC
* was away. If timedelta remains zero throughout, then the
* default action will be to sync hrestime to IOSRAM
*/
complained = update_tod_skew(0);
(char *)&domain_skew, sizeof (time_t)))) {
complained++;
"read tod domain skew failed");
}
}
is_sc_down = 0;
adjust_sc_down = 0;
/*
* If complained then domain_skew is invalid.
* Hand back hrestime instead.
*/
if (!complained) {
timestruc_t ts = {0, 0};
return (ts);
} else {
goto return_hrestime;
}
}
is_sc_down++;
if (timedelta != 0) {
adjust_sc_down = 1;
}
/*
* We need to inform the tod_validate code to stop checking till
* SC come back up again. Note that we will return hrestime below
* which can be different that the previous TOD value we returned
*/
return (hrestime);
}
static void
{
int complained = 0;
if (!verify_sc_tod_version()) {
/* if we can't use SC */
return;
}
/*
* If the SC is down just note the fact that we should
* have adjusted the hardware skew which caters for calls
* to stime(). (eg NTP step, as opposed to NTP skew)
*/
if (is_sc_down) {
adjust_sc_down = 1;
return;
}
/*
* reason to update i_am_alive here:
* To work around a generic Solaris bug that can
* cause tod_get() to be starved by too frequent
* calls to the stime() system call.
*/
if (watchdog_activated != 0 || watchdog_enable != 0)
/*
* We are passed hrestime from clock.c so we need to read the
* IOSRAM for the hardware's idea of the time to see if we need
* to update the skew.
*/
complained++;
}
(char *)&domain_skew, sizeof (time_t))) {
complained++;
}
/*
* Only update the skew if the time passed differs from
* what the hardware thinks & no errors talking to SC
*/
}
if (complained) {
todsg_use_sc = 0;
}
}
static uint32_t
{
if (!verify_sc_tod_version()) {
"verify_sc_tod_version failed");
return (0);
}
"set watchdog timer value = %d", timeoutval);
(char *)&timeoutval, sizeof (uint32_t))) {
"write new timeout value failed");
return (0);
}
watchdog_activated = 1;
return (timeoutval);
}
static uint32_t
{
if ((watchdog_activated == 0) || !verify_sc_tod_version()) {
"either watchdog not activated or "
"verify_sc_tod_version failed");
return (0);
}
(char *)&r_timeout_period, sizeof (uint32_t))) {
"read timeout value failed");
return (0);
}
"clear watchdog timer (old value=%d)", r_timeout_period);
w_timeout_period = 0;
(char *)&w_timeout_period, sizeof (uint32_t))) {
"write zero timeout value failed");
return (0);
}
watchdog_activated = 0;
return (r_timeout_period);
}
/*
* Null function.
*/
/* ARGSUSED */
static void
{
}
/*
* Null function
*/
static void
{
}
/*
* Get clock freq from the cpunode
*/
todsg_get_cpufrequency(void)
{
}