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