10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57696SRichard.Bean@Sun.COM * Common Development and Distribution License (the "License").
67696SRichard.Bean@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*11752STrevor.Thompson@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/conf.h>
280Sstevel@tonic-gate #include <sys/kmem.h>
290Sstevel@tonic-gate #include <sys/open.h>
300Sstevel@tonic-gate #include <sys/ddi.h>
310Sstevel@tonic-gate #include <sys/sunddi.h>
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <sys/todm5819.h>
340Sstevel@tonic-gate #include <sys/modctl.h>
350Sstevel@tonic-gate #include <sys/stat.h>
360Sstevel@tonic-gate #include <sys/clock.h>
370Sstevel@tonic-gate #include <sys/reboot.h>
380Sstevel@tonic-gate #include <sys/machsystm.h>
390Sstevel@tonic-gate #include <sys/poll.h>
400Sstevel@tonic-gate #include <sys/pbio.h>
410Sstevel@tonic-gate #include <sys/lom_priv.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate #define WDOG_ON 1
440Sstevel@tonic-gate #define WDOG_OFF 0
450Sstevel@tonic-gate
460Sstevel@tonic-gate static timestruc_t todbl_get(void);
470Sstevel@tonic-gate static void todbl_set(timestruc_t);
480Sstevel@tonic-gate static uint_t todbl_set_watchdog_timer(uint_t);
490Sstevel@tonic-gate static uint_t todbl_clear_watchdog_timer(void);
500Sstevel@tonic-gate static void todbl_set_power_alarm(timestruc_t);
510Sstevel@tonic-gate static void todbl_clear_power_alarm(void);
520Sstevel@tonic-gate static uint64_t todbl_get_cpufrequency(void);
530Sstevel@tonic-gate
540Sstevel@tonic-gate static todinfo_t rtc_to_tod(struct rtc_t *);
550Sstevel@tonic-gate static uint_t read_rtc(struct rtc_t *);
560Sstevel@tonic-gate static void write_rtc_time(struct rtc_t *);
570Sstevel@tonic-gate static uint_t configure_wdog(uint8_t new_state);
580Sstevel@tonic-gate
590Sstevel@tonic-gate extern uint64_t find_cpufrequency(volatile uint8_t *);
600Sstevel@tonic-gate
610Sstevel@tonic-gate /*
620Sstevel@tonic-gate * External variables
630Sstevel@tonic-gate */
640Sstevel@tonic-gate extern int watchdog_enable;
650Sstevel@tonic-gate extern int watchdog_available;
660Sstevel@tonic-gate extern int watchdog_activated;
670Sstevel@tonic-gate extern uint_t watchdog_timeout_seconds;
680Sstevel@tonic-gate extern int boothowto;
690Sstevel@tonic-gate extern void (*bsc_drv_func_ptr)(struct bscv_idi_info *);
700Sstevel@tonic-gate
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate * Global variables
730Sstevel@tonic-gate */
740Sstevel@tonic-gate int m5819_debug_flags;
750Sstevel@tonic-gate uint8_t wdog_reset_on_timeout = 1;
760Sstevel@tonic-gate static clock_t last_pat_lbt;
770Sstevel@tonic-gate
780Sstevel@tonic-gate
790Sstevel@tonic-gate static struct modlmisc modlmisc = {
807696SRichard.Bean@Sun.COM &mod_miscops, "todblade module",
810Sstevel@tonic-gate };
820Sstevel@tonic-gate
830Sstevel@tonic-gate static struct modlinkage modlinkage = {
840Sstevel@tonic-gate MODREV_1, &modlmisc, NULL
850Sstevel@tonic-gate };
860Sstevel@tonic-gate
870Sstevel@tonic-gate
880Sstevel@tonic-gate int
_init(void)890Sstevel@tonic-gate _init(void)
900Sstevel@tonic-gate {
910Sstevel@tonic-gate if (strcmp(tod_module_name, "todblade") == 0) {
920Sstevel@tonic-gate RTC_PUT8(RTC_B, (RTC_DM | RTC_HM));
930Sstevel@tonic-gate
940Sstevel@tonic-gate tod_ops.tod_get = todbl_get;
950Sstevel@tonic-gate tod_ops.tod_set = todbl_set;
96*11752STrevor.Thompson@Sun.COM tod_ops.tod_set_watchdog_timer = todbl_set_watchdog_timer;
97*11752STrevor.Thompson@Sun.COM tod_ops.tod_clear_watchdog_timer = todbl_clear_watchdog_timer;
980Sstevel@tonic-gate tod_ops.tod_set_power_alarm = todbl_set_power_alarm;
990Sstevel@tonic-gate tod_ops.tod_clear_power_alarm = todbl_clear_power_alarm;
1000Sstevel@tonic-gate tod_ops.tod_get_cpufrequency = todbl_get_cpufrequency;
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate if (watchdog_enable && (boothowto & RB_DEBUG)) {
1030Sstevel@tonic-gate watchdog_available = 0;
1040Sstevel@tonic-gate cmn_err(CE_WARN, "todblade: kernel debugger "
1050Sstevel@tonic-gate "detected: hardware watchdog disabled");
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate return (mod_install(&modlinkage));
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate int
_fini(void)1120Sstevel@tonic-gate _fini(void)
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate if (strcmp(tod_module_name, "todblade") == 0) {
1150Sstevel@tonic-gate return (EBUSY);
1160Sstevel@tonic-gate } else {
1170Sstevel@tonic-gate return (mod_remove(&modlinkage));
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate }
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate * The loadable-module _info(9E) entry point
1230Sstevel@tonic-gate */
1240Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1250Sstevel@tonic-gate _info(struct modinfo *modinfop)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate * Read the current time from the clock chip and convert to UNIX form.
1330Sstevel@tonic-gate * Assumes that the year in the clock chip is valid.
1340Sstevel@tonic-gate * Must be called with tod_lock held.
1350Sstevel@tonic-gate */
1360Sstevel@tonic-gate static timestruc_t
todbl_get(void)1370Sstevel@tonic-gate todbl_get(void)
1380Sstevel@tonic-gate {
1390Sstevel@tonic-gate int i;
1400Sstevel@tonic-gate timestruc_t ts;
1410Sstevel@tonic-gate struct rtc_t rtc;
1420Sstevel@tonic-gate struct bscv_idi_info bscv_info;
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock));
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate * We must check that the value of watchdog enable hasnt changed
1480Sstevel@tonic-gate * as its a user knob for turning it on and off
1490Sstevel@tonic-gate */
1500Sstevel@tonic-gate if (watchdog_available) {
1510Sstevel@tonic-gate if (watchdog_activated && !watchdog_enable) {
1520Sstevel@tonic-gate (void) configure_wdog(WDOG_OFF);
1530Sstevel@tonic-gate } else if (!watchdog_activated && watchdog_enable) {
1540Sstevel@tonic-gate (void) configure_wdog(WDOG_ON);
1550Sstevel@tonic-gate } else if (watchdog_activated &&
156*11752STrevor.Thompson@Sun.COM (ddi_get_lbolt() - last_pat_lbt) >= SEC_TO_TICK(1)) {
1570Sstevel@tonic-gate /*
1580Sstevel@tonic-gate * PAT THE WATCHDOG!!
1590Sstevel@tonic-gate * We dont want to accelerate the pat frequency
1600Sstevel@tonic-gate * when userland calls to the TOD_GET_DATE ioctl
1610Sstevel@tonic-gate * pass through here.
1620Sstevel@tonic-gate */
1630Sstevel@tonic-gate bscv_info.type = BSCV_IDI_WDOG_PAT;
1640Sstevel@tonic-gate bscv_info.data = NULL;
1650Sstevel@tonic-gate bscv_info.size = 0;
1660Sstevel@tonic-gate if (bsc_drv_func_ptr != NULL) {
1670Sstevel@tonic-gate (*bsc_drv_func_ptr)(&bscv_info);
1680Sstevel@tonic-gate last_pat_lbt = ddi_get_lbolt();
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate /*
1740Sstevel@tonic-gate * Read from the tod, and if it isnt accessible wait
1750Sstevel@tonic-gate * before retrying.
1760Sstevel@tonic-gate */
1770Sstevel@tonic-gate for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) {
1780Sstevel@tonic-gate if (read_rtc(&rtc))
1790Sstevel@tonic-gate break;
1800Sstevel@tonic-gate drv_usecwait(TODM5819_UIP_WAIT_USEC);
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate if (i == TODM5819_UIP_RETRY_THRESH) {
1830Sstevel@tonic-gate /*
184*11752STrevor.Thompson@Sun.COM * We couldn't read from the TOD.
1850Sstevel@tonic-gate */
186*11752STrevor.Thompson@Sun.COM tod_status_set(TOD_GET_FAILED);
1870Sstevel@tonic-gate return (hrestime);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate DPRINTF("todbl_get: century=%d year=%d dom=%d hrs=%d\n",
1910Sstevel@tonic-gate rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs);
1920Sstevel@tonic-gate
193*11752STrevor.Thompson@Sun.COM /* read was successful so ensure failure flag is clear */
194*11752STrevor.Thompson@Sun.COM tod_status_clear(TOD_GET_FAILED);
195*11752STrevor.Thompson@Sun.COM
1960Sstevel@tonic-gate ts.tv_sec = tod_to_utc(rtc_to_tod(&rtc));
1970Sstevel@tonic-gate ts.tv_nsec = 0;
1980Sstevel@tonic-gate return (ts);
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate static todinfo_t
rtc_to_tod(struct rtc_t * rtc)2020Sstevel@tonic-gate rtc_to_tod(struct rtc_t *rtc)
2030Sstevel@tonic-gate {
2040Sstevel@tonic-gate todinfo_t tod;
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate /*
2070Sstevel@tonic-gate * tod_year is base 1900 so this code needs to adjust the true
2080Sstevel@tonic-gate * year retrieved from the rtc's century and year fields.
2090Sstevel@tonic-gate */
2100Sstevel@tonic-gate tod.tod_year = rtc->rtc_year + (rtc->rtc_century * 100) - 1900;
2110Sstevel@tonic-gate tod.tod_month = rtc->rtc_mon;
2120Sstevel@tonic-gate tod.tod_day = rtc->rtc_dom;
2130Sstevel@tonic-gate tod.tod_dow = rtc->rtc_dow;
2140Sstevel@tonic-gate tod.tod_hour = rtc->rtc_hrs;
2150Sstevel@tonic-gate tod.tod_min = rtc->rtc_min;
2160Sstevel@tonic-gate tod.tod_sec = rtc->rtc_sec;
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate return (tod);
2190Sstevel@tonic-gate }
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate static uint_t
read_rtc(struct rtc_t * rtc)2230Sstevel@tonic-gate read_rtc(struct rtc_t *rtc)
2240Sstevel@tonic-gate {
2250Sstevel@tonic-gate int s;
2260Sstevel@tonic-gate uint_t rtc_readable = 0;
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate s = splhi();
2290Sstevel@tonic-gate /*
2300Sstevel@tonic-gate * If UIP bit is not set we have at least 274us
2310Sstevel@tonic-gate * to read the values.
2320Sstevel@tonic-gate */
2330Sstevel@tonic-gate if (!(RTC_GET8(RTC_A) & RTC_UIP)) {
2340Sstevel@tonic-gate rtc_readable = 1;
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate rtc->rtc_sec = RTC_GET8(RTC_SEC);
2370Sstevel@tonic-gate rtc->rtc_asec = RTC_GET8(RTC_ASEC);
2380Sstevel@tonic-gate rtc->rtc_min = RTC_GET8(RTC_MIN);
2390Sstevel@tonic-gate rtc->rtc_amin = RTC_GET8(RTC_AMIN);
2400Sstevel@tonic-gate
2410Sstevel@tonic-gate rtc->rtc_hrs = RTC_GET8(RTC_HRS);
2420Sstevel@tonic-gate rtc->rtc_ahrs = RTC_GET8(RTC_AHRS);
2430Sstevel@tonic-gate rtc->rtc_dow = RTC_GET8(RTC_DOW);
2440Sstevel@tonic-gate rtc->rtc_dom = RTC_GET8(RTC_DOM);
2450Sstevel@tonic-gate rtc->rtc_adom = RTC_GET8(RTC_D) & 0x3f;
2460Sstevel@tonic-gate
2470Sstevel@tonic-gate rtc->rtc_mon = RTC_GET8(RTC_MON);
2480Sstevel@tonic-gate rtc->rtc_year = RTC_GET8(RTC_YEAR);
2490Sstevel@tonic-gate rtc->rtc_century = RTC_GET8(RTC_CENTURY);
2500Sstevel@tonic-gate rtc->rtc_amon = 0;
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate /* Clear wakeup data */
2530Sstevel@tonic-gate rtc->apc_wdwr = 0;
2540Sstevel@tonic-gate rtc->apc_wdmr = 0;
2550Sstevel@tonic-gate rtc->apc_wmr = 0;
2560Sstevel@tonic-gate rtc->apc_wyr = 0;
2570Sstevel@tonic-gate rtc->apc_wcr = 0;
2580Sstevel@tonic-gate }
2590Sstevel@tonic-gate
2600Sstevel@tonic-gate splx(s);
2610Sstevel@tonic-gate return (rtc_readable);
2620Sstevel@tonic-gate }
2630Sstevel@tonic-gate
2640Sstevel@tonic-gate /*
2650Sstevel@tonic-gate * Write the specified time into the clock chip.
2660Sstevel@tonic-gate * Must be called with tod_lock held.
2670Sstevel@tonic-gate */
2680Sstevel@tonic-gate static void
todbl_set(timestruc_t ts)2690Sstevel@tonic-gate todbl_set(timestruc_t ts)
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate struct rtc_t rtc;
2720Sstevel@tonic-gate todinfo_t tod = utc_to_tod(ts.tv_sec);
2730Sstevel@tonic-gate struct bscv_idi_info bscv_info;
2740Sstevel@tonic-gate int year;
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock));
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate /* tod_year is base 1900 so this code needs to adjust */
2790Sstevel@tonic-gate year = 1900 + tod.tod_year;
2800Sstevel@tonic-gate rtc.rtc_year = year % 100;
2810Sstevel@tonic-gate rtc.rtc_century = year / 100;
2820Sstevel@tonic-gate rtc.rtc_mon = (uint8_t)tod.tod_month;
2830Sstevel@tonic-gate rtc.rtc_dom = (uint8_t)tod.tod_day;
2840Sstevel@tonic-gate rtc.rtc_dow = (uint8_t)tod.tod_dow;
2850Sstevel@tonic-gate rtc.rtc_hrs = (uint8_t)tod.tod_hour;
2860Sstevel@tonic-gate rtc.rtc_min = (uint8_t)tod.tod_min;
2870Sstevel@tonic-gate rtc.rtc_sec = (uint8_t)tod.tod_sec;
2880Sstevel@tonic-gate DPRINTF("todbl_set: century=%d year=%d dom=%d hrs=%d\n",
2890Sstevel@tonic-gate rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs);
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate write_rtc_time(&rtc);
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate /*
2940Sstevel@tonic-gate * Because of a generic solaris problem where calls to stime()
2950Sstevel@tonic-gate * starve calls to tod_get(), we need to check to see when the
2960Sstevel@tonic-gate * watchdog was last patted and pat it if necessary.
2970Sstevel@tonic-gate */
2980Sstevel@tonic-gate if (watchdog_activated &&
2990Sstevel@tonic-gate (ddi_get_lbolt() - last_pat_lbt) >= SEC_TO_TICK(1)) {
3000Sstevel@tonic-gate /*
3010Sstevel@tonic-gate * Pat the watchdog!
3020Sstevel@tonic-gate */
3030Sstevel@tonic-gate bscv_info.type = BSCV_IDI_WDOG_PAT;
3040Sstevel@tonic-gate bscv_info.data = NULL;
3050Sstevel@tonic-gate bscv_info.size = 0;
3060Sstevel@tonic-gate if (bsc_drv_func_ptr != NULL) {
3070Sstevel@tonic-gate (*bsc_drv_func_ptr)(&bscv_info);
3080Sstevel@tonic-gate last_pat_lbt = ddi_get_lbolt();
3090Sstevel@tonic-gate }
3100Sstevel@tonic-gate }
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate
3130Sstevel@tonic-gate static void
write_rtc_time(struct rtc_t * rtc)3140Sstevel@tonic-gate write_rtc_time(struct rtc_t *rtc)
3150Sstevel@tonic-gate {
3160Sstevel@tonic-gate uint8_t regb;
317*11752STrevor.Thompson@Sun.COM int i;
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate /*
3200Sstevel@tonic-gate * Freeze
3210Sstevel@tonic-gate */
3220Sstevel@tonic-gate regb = RTC_GET8(RTC_B);
3230Sstevel@tonic-gate RTC_PUT8(RTC_B, (regb | RTC_SET));
3240Sstevel@tonic-gate
325*11752STrevor.Thompson@Sun.COM /*
326*11752STrevor.Thompson@Sun.COM * If an update is in progress wait for the UIP flag to clear.
327*11752STrevor.Thompson@Sun.COM * If we write whilst UIP is still set there is a slight but real
328*11752STrevor.Thompson@Sun.COM * possibility of corrupting the RTC date and time registers.
329*11752STrevor.Thompson@Sun.COM *
330*11752STrevor.Thompson@Sun.COM * The expected wait is one internal cycle of the chip. We could
331*11752STrevor.Thompson@Sun.COM * simply spin but this may hang a CPU if we were to have a broken
332*11752STrevor.Thompson@Sun.COM * RTC chip where UIP is stuck, so we use a retry loop instead.
333*11752STrevor.Thompson@Sun.COM * No critical section is needed here as the UIP flag will not be
334*11752STrevor.Thompson@Sun.COM * re-asserted until we clear RTC_SET.
335*11752STrevor.Thompson@Sun.COM */
336*11752STrevor.Thompson@Sun.COM for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) {
337*11752STrevor.Thompson@Sun.COM if (!(RTC_GET8(RTC_A) & RTC_UIP)) {
338*11752STrevor.Thompson@Sun.COM break;
339*11752STrevor.Thompson@Sun.COM }
340*11752STrevor.Thompson@Sun.COM drv_usecwait(TODM5819_UIP_WAIT_USEC);
341*11752STrevor.Thompson@Sun.COM }
342*11752STrevor.Thompson@Sun.COM if (i < TODM5819_UIP_RETRY_THRESH) {
343*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_SEC, (rtc->rtc_sec));
344*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_ASEC, (rtc->rtc_asec));
345*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_MIN, (rtc->rtc_min));
346*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_AMIN, (rtc->rtc_amin));
3470Sstevel@tonic-gate
348*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_HRS, (rtc->rtc_hrs));
349*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_AHRS, (rtc->rtc_ahrs));
350*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_DOW, (rtc->rtc_dow));
351*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_DOM, (rtc->rtc_dom));
3520Sstevel@tonic-gate
353*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_MON, (rtc->rtc_mon));
354*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_YEAR, (rtc->rtc_year));
355*11752STrevor.Thompson@Sun.COM RTC_PUT8(RTC_CENTURY, (rtc->rtc_century));
356*11752STrevor.Thompson@Sun.COM } else {
357*11752STrevor.Thompson@Sun.COM cmn_err(CE_WARN, "todblade: Could not write the RTC\n");
358*11752STrevor.Thompson@Sun.COM }
3590Sstevel@tonic-gate
3600Sstevel@tonic-gate /*
3610Sstevel@tonic-gate * Unfreeze
3620Sstevel@tonic-gate */
3630Sstevel@tonic-gate RTC_PUT8(RTC_B, regb);
3640Sstevel@tonic-gate }
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate /*
3690Sstevel@tonic-gate * The TOD alarm functionality is not supported on our platform
3700Sstevel@tonic-gate * as the interrupt is not wired, so do nothing.
3710Sstevel@tonic-gate */
3720Sstevel@tonic-gate /*ARGSUSED*/
3730Sstevel@tonic-gate static void
todbl_set_power_alarm(timestruc_t ts)3740Sstevel@tonic-gate todbl_set_power_alarm(timestruc_t ts)
3750Sstevel@tonic-gate {
3760Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock));
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate /*
3800Sstevel@tonic-gate * clear alarm interrupt
3810Sstevel@tonic-gate */
3820Sstevel@tonic-gate static void
todbl_clear_power_alarm(void)3830Sstevel@tonic-gate todbl_clear_power_alarm(void)
3840Sstevel@tonic-gate {
3850Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock));
3860Sstevel@tonic-gate }
3870Sstevel@tonic-gate
3880Sstevel@tonic-gate /*
3890Sstevel@tonic-gate * Determine the cpu frequency by watching the TOD chip rollover twice.
3900Sstevel@tonic-gate * Cpu clock rate is determined by computing the ticks added (in tick register)
3910Sstevel@tonic-gate * during one second interval on TOD.
3920Sstevel@tonic-gate */
3930Sstevel@tonic-gate uint64_t
todbl_get_cpufrequency(void)3940Sstevel@tonic-gate todbl_get_cpufrequency(void)
3950Sstevel@tonic-gate {
3960Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock));
3970Sstevel@tonic-gate M5819_ADDR_REG = RTC_SEC;
3980Sstevel@tonic-gate return (find_cpufrequency(v_rtc_data_reg));
3990Sstevel@tonic-gate }
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate static uint_t
todbl_set_watchdog_timer(uint_t timeoutval)4030Sstevel@tonic-gate todbl_set_watchdog_timer(uint_t timeoutval)
4040Sstevel@tonic-gate {
4050Sstevel@tonic-gate /*
4060Sstevel@tonic-gate * We get started during kernel intilaisation only
4070Sstevel@tonic-gate * if watchdog_enable is set.
4080Sstevel@tonic-gate */
4090Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock));
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate if (watchdog_available && (!watchdog_activated ||
4120Sstevel@tonic-gate (watchdog_activated && (timeoutval != watchdog_timeout_seconds)))) {
4130Sstevel@tonic-gate watchdog_timeout_seconds = timeoutval;
4140Sstevel@tonic-gate if (configure_wdog(WDOG_ON))
4150Sstevel@tonic-gate return (watchdog_timeout_seconds);
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate return (0);
4180Sstevel@tonic-gate }
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate static uint_t
todbl_clear_watchdog_timer(void)4210Sstevel@tonic-gate todbl_clear_watchdog_timer(void)
4220Sstevel@tonic-gate {
4230Sstevel@tonic-gate /*
4240Sstevel@tonic-gate * The core kernel will call us here to disable the wdog when:
4250Sstevel@tonic-gate * 1. we're panicing
4260Sstevel@tonic-gate * 2. we're entering debug
4270Sstevel@tonic-gate * 3. we're rebooting
4280Sstevel@tonic-gate */
4290Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock));
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate if (watchdog_available && watchdog_activated) {
4320Sstevel@tonic-gate watchdog_enable = 0;
4330Sstevel@tonic-gate if (!configure_wdog(WDOG_OFF))
4340Sstevel@tonic-gate return (0);
4350Sstevel@tonic-gate }
4360Sstevel@tonic-gate return (watchdog_timeout_seconds);
4370Sstevel@tonic-gate }
4380Sstevel@tonic-gate
4390Sstevel@tonic-gate static uint_t
configure_wdog(uint8_t new_state)4400Sstevel@tonic-gate configure_wdog(uint8_t new_state)
4410Sstevel@tonic-gate {
4420Sstevel@tonic-gate bscv_wdog_t wdog_cmd;
4430Sstevel@tonic-gate struct bscv_idi_info bscv_info;
4440Sstevel@tonic-gate
4450Sstevel@tonic-gate if (new_state == WDOG_ON || new_state == WDOG_OFF) {
4460Sstevel@tonic-gate
4470Sstevel@tonic-gate wdog_cmd.enable_wdog = new_state;
4480Sstevel@tonic-gate wdog_cmd.wdog_timeout_s = watchdog_timeout_seconds;
4490Sstevel@tonic-gate wdog_cmd.reset_system_on_timeout = wdog_reset_on_timeout;
4500Sstevel@tonic-gate bscv_info.type = BSCV_IDI_WDOG_CFG;
4510Sstevel@tonic-gate bscv_info.data = &wdog_cmd;
4520Sstevel@tonic-gate bscv_info.size = sizeof (wdog_cmd);
4530Sstevel@tonic-gate
4540Sstevel@tonic-gate if (bsc_drv_func_ptr != NULL) {
4550Sstevel@tonic-gate watchdog_activated = new_state;
4560Sstevel@tonic-gate (*bsc_drv_func_ptr)(&bscv_info);
4570Sstevel@tonic-gate return (1);
4580Sstevel@tonic-gate }
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate return (0);
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate }
463