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]
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
69 if (strcmp(tod_module_name
, "todstarfire") == 0) {
73 /* Set the string to pass to OBP */
74 (void) sprintf(obp_string
, "h# %p unix-gettod",
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
));
104 if (strcmp(tod_module_name
, "todstarfire") == 0)
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.
125 extern cpu_sgnblk_t
*cpu_sgnblkp
[];
127 ASSERT(MUTEX_HELD(&tod_lock
));
131 /* Update the heartbeat */
132 if (cpu_sgnblkp
[CPU
->cpu_id
] != NULL
)
133 cpu_sgnblkp
[CPU
->cpu_id
]->sigb_heartbeat
++;
138 * Null function for now.
139 * Must be called with tod_lock held.
143 todsf_set(timestruc_t ts
)
145 ASSERT(MUTEX_HELD(&tod_lock
));
150 * No watchdog function.
154 todsf_set_watchdog_timer(uint_t timeoutval
)
156 ASSERT(MUTEX_HELD(&tod_lock
));
161 * No watchdog function
164 todsf_clear_watchdog_timer(void)
166 ASSERT(MUTEX_HELD(&tod_lock
));
175 todsf_set_power_alarm(timestruc_t ts
)
177 ASSERT(MUTEX_HELD(&tod_lock
));
184 todsf_clear_power_alarm()
186 ASSERT(MUTEX_HELD(&tod_lock
));
190 * Get clock freq from the cpunode
193 todsf_get_cpufrequency(void)
195 return (cpunodes
[CPU
->cpu_id
].clock_freq
);