xref: /onnv-gate/usr/src/uts/sun4u/io/todstarfire.c (revision 7696:21f5c73c0c15)
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
54551Ssudheer  * Common Development and Distribution License (the "License").
64551Ssudheer  * 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*7696SRichard.Bean@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * tod driver module for Starfire
280Sstevel@tonic-gate  * This module implements a soft tod since
290Sstevel@tonic-gate  * starfire has no tod part.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/param.h>
340Sstevel@tonic-gate #include <sys/sysmacros.h>
350Sstevel@tonic-gate #include <sys/systm.h>
360Sstevel@tonic-gate #include <sys/errno.h>
370Sstevel@tonic-gate #include <sys/modctl.h>
380Sstevel@tonic-gate #include <sys/autoconf.h>
390Sstevel@tonic-gate #include <sys/debug.h>
400Sstevel@tonic-gate #include <sys/clock.h>
410Sstevel@tonic-gate #include <sys/cmn_err.h>
420Sstevel@tonic-gate #include <sys/promif.h>
430Sstevel@tonic-gate #include <sys/cpuvar.h>
440Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
450Sstevel@tonic-gate #include <starfire/sys/cpu_sgn.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate static timestruc_t	todsf_get(void);
480Sstevel@tonic-gate static void		todsf_set(timestruc_t);
490Sstevel@tonic-gate static uint_t		todsf_set_watchdog_timer(uint_t);
500Sstevel@tonic-gate static uint_t		todsf_clear_watchdog_timer(void);
510Sstevel@tonic-gate static void		todsf_set_power_alarm(timestruc_t);
520Sstevel@tonic-gate static void		todsf_clear_power_alarm(void);
530Sstevel@tonic-gate static uint64_t		todsf_get_cpufrequency(void);
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * Module linkage information for the kernel.
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate static struct modlmisc modlmisc = {
59*7696SRichard.Bean@Sun.COM 	&mod_miscops, "Soft tod module for Starfire"
600Sstevel@tonic-gate };
610Sstevel@tonic-gate 
620Sstevel@tonic-gate static struct modlinkage modlinkage = {
630Sstevel@tonic-gate 	MODREV_1, (void *)&modlmisc, NULL
640Sstevel@tonic-gate };
650Sstevel@tonic-gate 
660Sstevel@tonic-gate int
_init(void)670Sstevel@tonic-gate _init(void)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate 	if (strcmp(tod_module_name, "todstarfire") == 0) {
700Sstevel@tonic-gate 		int ssp_time32;
710Sstevel@tonic-gate 		char obp_string[40];
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 		/* Set the string to pass to OBP */
740Sstevel@tonic-gate 		(void) sprintf(obp_string, "h# %p unix-gettod",
754551Ssudheer 		    (void *)&ssp_time32);
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 		/* Get OBP to get TOD from ssp */
780Sstevel@tonic-gate 		prom_interpret(obp_string, 0, 0, 0, 0, 0);
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 		hrestime.tv_sec = (time_t)ssp_time32;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 		tod_ops.tod_get = todsf_get;
830Sstevel@tonic-gate 		tod_ops.tod_set = todsf_set;
840Sstevel@tonic-gate 		tod_ops.tod_set_watchdog_timer = todsf_set_watchdog_timer;
850Sstevel@tonic-gate 		tod_ops.tod_clear_watchdog_timer = todsf_clear_watchdog_timer;
860Sstevel@tonic-gate 		tod_ops.tod_set_power_alarm = todsf_set_power_alarm;
870Sstevel@tonic-gate 		tod_ops.tod_clear_power_alarm = todsf_clear_power_alarm;
880Sstevel@tonic-gate 		tod_ops.tod_get_cpufrequency = todsf_get_cpufrequency;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 		/*
910Sstevel@tonic-gate 		 * Flag warning if user tried to use hardware watchdog
920Sstevel@tonic-gate 		 */
930Sstevel@tonic-gate 		if (watchdog_enable) {
940Sstevel@tonic-gate 			cmn_err(CE_WARN, "Hardware watchdog unavailable");
950Sstevel@tonic-gate 		}
960Sstevel@tonic-gate 	}
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	return (mod_install(&modlinkage));
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate int
_fini(void)1020Sstevel@tonic-gate _fini(void)
1030Sstevel@tonic-gate {
1040Sstevel@tonic-gate 	if (strcmp(tod_module_name, "todstarfire") == 0)
1050Sstevel@tonic-gate 		return (EBUSY);
1060Sstevel@tonic-gate 	else
1070Sstevel@tonic-gate 		return (mod_remove(&modlinkage));
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1110Sstevel@tonic-gate _info(struct modinfo *modinfop)
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate  * Simply return hrestime value
1190Sstevel@tonic-gate  * Must be called with tod_lock held.
1200Sstevel@tonic-gate  */
1210Sstevel@tonic-gate static timestruc_t
todsf_get(void)1220Sstevel@tonic-gate todsf_get(void)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate 	timestruc_t ts;
1250Sstevel@tonic-gate 	extern cpu_sgnblk_t *cpu_sgnblkp[];
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	ts = hrestime;
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	/* Update the heartbeat */
1320Sstevel@tonic-gate 	if (cpu_sgnblkp[CPU->cpu_id] != NULL)
1330Sstevel@tonic-gate 		cpu_sgnblkp[CPU->cpu_id]->sigb_heartbeat++;
1340Sstevel@tonic-gate 	return (ts);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate  * Null function for now.
1390Sstevel@tonic-gate  * Must be called with tod_lock held.
1400Sstevel@tonic-gate  */
1410Sstevel@tonic-gate /* ARGSUSED */
1420Sstevel@tonic-gate static void
todsf_set(timestruc_t ts)1430Sstevel@tonic-gate todsf_set(timestruc_t ts)
1440Sstevel@tonic-gate {
1450Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
1460Sstevel@tonic-gate }
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate  * No watchdog function.
1510Sstevel@tonic-gate  */
1520Sstevel@tonic-gate /* ARGSUSED */
1530Sstevel@tonic-gate static uint_t
todsf_set_watchdog_timer(uint_t timeoutval)1540Sstevel@tonic-gate todsf_set_watchdog_timer(uint_t timeoutval)
1550Sstevel@tonic-gate {
1560Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
1570Sstevel@tonic-gate 	return (0);
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate /*
1610Sstevel@tonic-gate  * No watchdog function
1620Sstevel@tonic-gate  */
1630Sstevel@tonic-gate static uint_t
todsf_clear_watchdog_timer(void)1640Sstevel@tonic-gate todsf_clear_watchdog_timer(void)
1650Sstevel@tonic-gate {
1660Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
1670Sstevel@tonic-gate 	return (0);
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /*
1710Sstevel@tonic-gate  * Null function.
1720Sstevel@tonic-gate  */
1730Sstevel@tonic-gate /* ARGSUSED */
1740Sstevel@tonic-gate static void
todsf_set_power_alarm(timestruc_t ts)1750Sstevel@tonic-gate todsf_set_power_alarm(timestruc_t ts)
1760Sstevel@tonic-gate {
1770Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate /*
1810Sstevel@tonic-gate  * Null function
1820Sstevel@tonic-gate  */
1830Sstevel@tonic-gate static void
todsf_clear_power_alarm()1840Sstevel@tonic-gate todsf_clear_power_alarm()
1850Sstevel@tonic-gate {
1860Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&tod_lock));
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate /*
1900Sstevel@tonic-gate  * Get clock freq from the cpunode
1910Sstevel@tonic-gate  */
1920Sstevel@tonic-gate uint64_t
todsf_get_cpufrequency(void)1930Sstevel@tonic-gate todsf_get_cpufrequency(void)
1940Sstevel@tonic-gate {
1950Sstevel@tonic-gate 	return (cpunodes[CPU->cpu_id].clock_freq);
1960Sstevel@tonic-gate }
197