8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / uts / sun4u / io / todstarfire.c
blobb8571c49f8258372d1685f4ea1b9d3a8d79101f2
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * tod driver module for Starfire
28 * This module implements a soft tod since
29 * starfire has no tod part.
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/sysmacros.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/modctl.h>
38 #include <sys/autoconf.h>
39 #include <sys/debug.h>
40 #include <sys/clock.h>
41 #include <sys/cmn_err.h>
42 #include <sys/promif.h>
43 #include <sys/cpuvar.h>
44 #include <sys/cpu_sgnblk_defs.h>
45 #include <starfire/sys/cpu_sgn.h>
47 static timestruc_t todsf_get(void);
48 static void todsf_set(timestruc_t);
49 static uint_t todsf_set_watchdog_timer(uint_t);
50 static uint_t todsf_clear_watchdog_timer(void);
51 static void todsf_set_power_alarm(timestruc_t);
52 static void todsf_clear_power_alarm(void);
53 static uint64_t todsf_get_cpufrequency(void);
56 * Module linkage information for the kernel.
58 static struct modlmisc modlmisc = {
59 &mod_miscops, "Soft tod module for Starfire"
62 static struct modlinkage modlinkage = {
63 MODREV_1, (void *)&modlmisc, NULL
66 int
67 _init(void)
69 if (strcmp(tod_module_name, "todstarfire") == 0) {
70 int ssp_time32;
71 char obp_string[40];
73 /* Set the string to pass to OBP */
74 (void) sprintf(obp_string, "h# %p unix-gettod",
75 (void *)&ssp_time32);
77 /* Get OBP to get TOD from ssp */
78 prom_interpret(obp_string, 0, 0, 0, 0, 0);
80 hrestime.tv_sec = (time_t)ssp_time32;
82 tod_ops.tod_get = todsf_get;
83 tod_ops.tod_set = todsf_set;
84 tod_ops.tod_set_watchdog_timer = todsf_set_watchdog_timer;
85 tod_ops.tod_clear_watchdog_timer = todsf_clear_watchdog_timer;
86 tod_ops.tod_set_power_alarm = todsf_set_power_alarm;
87 tod_ops.tod_clear_power_alarm = todsf_clear_power_alarm;
88 tod_ops.tod_get_cpufrequency = todsf_get_cpufrequency;
91 * Flag warning if user tried to use hardware watchdog
93 if (watchdog_enable) {
94 cmn_err(CE_WARN, "Hardware watchdog unavailable");
98 return (mod_install(&modlinkage));
102 _fini(void)
104 if (strcmp(tod_module_name, "todstarfire") == 0)
105 return (EBUSY);
106 else
107 return (mod_remove(&modlinkage));
111 _info(struct modinfo *modinfop)
113 return (mod_info(&modlinkage, modinfop));
118 * Simply return hrestime value
119 * Must be called with tod_lock held.
121 static timestruc_t
122 todsf_get(void)
124 timestruc_t ts;
125 extern cpu_sgnblk_t *cpu_sgnblkp[];
127 ASSERT(MUTEX_HELD(&tod_lock));
129 ts = hrestime;
131 /* Update the heartbeat */
132 if (cpu_sgnblkp[CPU->cpu_id] != NULL)
133 cpu_sgnblkp[CPU->cpu_id]->sigb_heartbeat++;
134 return (ts);
138 * Null function for now.
139 * Must be called with tod_lock held.
141 /* ARGSUSED */
142 static void
143 todsf_set(timestruc_t ts)
145 ASSERT(MUTEX_HELD(&tod_lock));
150 * No watchdog function.
152 /* ARGSUSED */
153 static uint_t
154 todsf_set_watchdog_timer(uint_t timeoutval)
156 ASSERT(MUTEX_HELD(&tod_lock));
157 return (0);
161 * No watchdog function
163 static uint_t
164 todsf_clear_watchdog_timer(void)
166 ASSERT(MUTEX_HELD(&tod_lock));
167 return (0);
171 * Null function.
173 /* ARGSUSED */
174 static void
175 todsf_set_power_alarm(timestruc_t ts)
177 ASSERT(MUTEX_HELD(&tod_lock));
181 * Null function
183 static void
184 todsf_clear_power_alarm()
186 ASSERT(MUTEX_HELD(&tod_lock));
190 * Get clock freq from the cpunode
192 uint64_t
193 todsf_get_cpufrequency(void)
195 return (cpunodes[CPU->cpu_id].clock_freq);