xref: /titanic_52/usr/src/uts/sun4u/io/todstarfire.c (revision 0eb822a1c0c2bea495647510b75f77f0e57633eb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997, 1999-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 /*
31  * tod driver module for Starfire
32  * This module implements a soft tod since
33  * starfire has no tod part.
34  */
35 
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/sysmacros.h>
39 #include <sys/systm.h>
40 #include <sys/errno.h>
41 #include <sys/modctl.h>
42 #include <sys/autoconf.h>
43 #include <sys/debug.h>
44 #include <sys/clock.h>
45 #include <sys/cmn_err.h>
46 #include <sys/promif.h>
47 #include <sys/cpuvar.h>
48 #include <sys/cpu_sgnblk_defs.h>
49 #include <starfire/sys/cpu_sgn.h>
50 
51 static timestruc_t	todsf_get(void);
52 static void		todsf_set(timestruc_t);
53 static uint_t		todsf_set_watchdog_timer(uint_t);
54 static uint_t		todsf_clear_watchdog_timer(void);
55 static void		todsf_set_power_alarm(timestruc_t);
56 static void		todsf_clear_power_alarm(void);
57 static uint64_t		todsf_get_cpufrequency(void);
58 
59 extern	timestruc_t	hrestime;
60 
61 /*
62  * Module linkage information for the kernel.
63  */
64 static struct modlmisc modlmisc = {
65 	&mod_miscops, "Soft tod module for Starfire %I%"
66 };
67 
68 static struct modlinkage modlinkage = {
69 	MODREV_1, (void *)&modlmisc, NULL
70 };
71 
72 int
73 _init(void)
74 {
75 	if (strcmp(tod_module_name, "todstarfire") == 0) {
76 		int ssp_time32;
77 		char obp_string[40];
78 
79 		/* Set the string to pass to OBP */
80 		(void) sprintf(obp_string, "h# %p unix-gettod",
81 				(void *)&ssp_time32);
82 
83 		/* Get OBP to get TOD from ssp */
84 		prom_interpret(obp_string, 0, 0, 0, 0, 0);
85 
86 		hrestime.tv_sec = (time_t)ssp_time32;
87 
88 		tod_ops.tod_get = todsf_get;
89 		tod_ops.tod_set = todsf_set;
90 		tod_ops.tod_set_watchdog_timer = todsf_set_watchdog_timer;
91 		tod_ops.tod_clear_watchdog_timer = todsf_clear_watchdog_timer;
92 		tod_ops.tod_set_power_alarm = todsf_set_power_alarm;
93 		tod_ops.tod_clear_power_alarm = todsf_clear_power_alarm;
94 		tod_ops.tod_get_cpufrequency = todsf_get_cpufrequency;
95 
96 		/*
97 		 * Flag warning if user tried to use hardware watchdog
98 		 */
99 		if (watchdog_enable) {
100 			cmn_err(CE_WARN, "Hardware watchdog unavailable");
101 		}
102 	}
103 
104 	return (mod_install(&modlinkage));
105 }
106 
107 int
108 _fini(void)
109 {
110 	if (strcmp(tod_module_name, "todstarfire") == 0)
111 		return (EBUSY);
112 	else
113 		return (mod_remove(&modlinkage));
114 }
115 
116 int
117 _info(struct modinfo *modinfop)
118 {
119 	return (mod_info(&modlinkage, modinfop));
120 }
121 
122 
123 /*
124  * Simply return hrestime value
125  * Must be called with tod_lock held.
126  */
127 static timestruc_t
128 todsf_get(void)
129 {
130 	timestruc_t ts;
131 	extern cpu_sgnblk_t *cpu_sgnblkp[];
132 
133 	ASSERT(MUTEX_HELD(&tod_lock));
134 
135 	ts = hrestime;
136 
137 	/* Update the heartbeat */
138 	if (cpu_sgnblkp[CPU->cpu_id] != NULL)
139 		cpu_sgnblkp[CPU->cpu_id]->sigb_heartbeat++;
140 	return (ts);
141 }
142 
143 /*
144  * Null function for now.
145  * Must be called with tod_lock held.
146  */
147 /* ARGSUSED */
148 static void
149 todsf_set(timestruc_t ts)
150 {
151 	ASSERT(MUTEX_HELD(&tod_lock));
152 }
153 
154 
155 /*
156  * No watchdog function.
157  */
158 /* ARGSUSED */
159 static uint_t
160 todsf_set_watchdog_timer(uint_t timeoutval)
161 {
162 	ASSERT(MUTEX_HELD(&tod_lock));
163 	return (0);
164 }
165 
166 /*
167  * No watchdog function
168  */
169 static uint_t
170 todsf_clear_watchdog_timer(void)
171 {
172 	ASSERT(MUTEX_HELD(&tod_lock));
173 	return (0);
174 }
175 
176 /*
177  * Null function.
178  */
179 /* ARGSUSED */
180 static void
181 todsf_set_power_alarm(timestruc_t ts)
182 {
183 	ASSERT(MUTEX_HELD(&tod_lock));
184 }
185 
186 /*
187  * Null function
188  */
189 static void
190 todsf_clear_power_alarm()
191 {
192 	ASSERT(MUTEX_HELD(&tod_lock));
193 }
194 
195 /*
196  * Get clock freq from the cpunode
197  */
198 uint64_t
199 todsf_get_cpufrequency(void)
200 {
201 	return (cpunodes[CPU->cpu_id].clock_freq);
202 }
203