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 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* 27 * tod driver module for Starfire 28 * This module implements a soft tod since 29 * starfire has no tod part. 30 */ 31 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> 46 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); 54 55 /* 56 * Module linkage information for the kernel. 57 */ 58 static struct modlmisc modlmisc = { 59 &mod_miscops, "Soft tod module for Starfire" 60 }; 61 62 static struct modlinkage modlinkage = { 63 MODREV_1, (void *)&modlmisc, NULL 64 }; 65 66 int 67 _init(void) 68 { 69 if (strcmp(tod_module_name, "todstarfire") == 0) { 70 int ssp_time32; 71 char obp_string[40]; 72 73 /* Set the string to pass to OBP */ 74 (void) sprintf(obp_string, "h# %p unix-gettod", 75 (void *)&ssp_time32); 76 77 /* Get OBP to get TOD from ssp */ 78 prom_interpret(obp_string, 0, 0, 0, 0, 0); 79 80 hrestime.tv_sec = (time_t)ssp_time32; 81 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; 89 90 /* 91 * Flag warning if user tried to use hardware watchdog 92 */ 93 if (watchdog_enable) { 94 cmn_err(CE_WARN, "Hardware watchdog unavailable"); 95 } 96 } 97 98 return (mod_install(&modlinkage)); 99 } 100 101 int 102 _fini(void) 103 { 104 if (strcmp(tod_module_name, "todstarfire") == 0) 105 return (EBUSY); 106 else 107 return (mod_remove(&modlinkage)); 108 } 109 110 int 111 _info(struct modinfo *modinfop) 112 { 113 return (mod_info(&modlinkage, modinfop)); 114 } 115 116 117 /* 118 * Simply return hrestime value 119 * Must be called with tod_lock held. 120 */ 121 static timestruc_t 122 todsf_get(void) 123 { 124 timestruc_t ts; 125 extern cpu_sgnblk_t *cpu_sgnblkp[]; 126 127 ASSERT(MUTEX_HELD(&tod_lock)); 128 129 ts = hrestime; 130 131 /* Update the heartbeat */ 132 if (cpu_sgnblkp[CPU->cpu_id] != NULL) 133 cpu_sgnblkp[CPU->cpu_id]->sigb_heartbeat++; 134 return (ts); 135 } 136 137 /* 138 * Null function for now. 139 * Must be called with tod_lock held. 140 */ 141 /* ARGSUSED */ 142 static void 143 todsf_set(timestruc_t ts) 144 { 145 ASSERT(MUTEX_HELD(&tod_lock)); 146 } 147 148 149 /* 150 * No watchdog function. 151 */ 152 /* ARGSUSED */ 153 static uint_t 154 todsf_set_watchdog_timer(uint_t timeoutval) 155 { 156 ASSERT(MUTEX_HELD(&tod_lock)); 157 return (0); 158 } 159 160 /* 161 * No watchdog function 162 */ 163 static uint_t 164 todsf_clear_watchdog_timer(void) 165 { 166 ASSERT(MUTEX_HELD(&tod_lock)); 167 return (0); 168 } 169 170 /* 171 * Null function. 172 */ 173 /* ARGSUSED */ 174 static void 175 todsf_set_power_alarm(timestruc_t ts) 176 { 177 ASSERT(MUTEX_HELD(&tod_lock)); 178 } 179 180 /* 181 * Null function 182 */ 183 static void 184 todsf_clear_power_alarm() 185 { 186 ASSERT(MUTEX_HELD(&tod_lock)); 187 } 188 189 /* 190 * Get clock freq from the cpunode 191 */ 192 uint64_t 193 todsf_get_cpufrequency(void) 194 { 195 return (cpunodes[CPU->cpu_id].clock_freq); 196 } 197