17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5b5b48cc1Ssudheer * Common Development and Distribution License (the "License"). 6b5b48cc1Ssudheer * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*88294e09SRichard Bean * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * tod driver module for Starfire 287c478bd9Sstevel@tonic-gate * This module implements a soft tod since 297c478bd9Sstevel@tonic-gate * starfire has no tod part. 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/param.h> 347c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 357c478bd9Sstevel@tonic-gate #include <sys/systm.h> 367c478bd9Sstevel@tonic-gate #include <sys/errno.h> 377c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 387c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 397c478bd9Sstevel@tonic-gate #include <sys/debug.h> 407c478bd9Sstevel@tonic-gate #include <sys/clock.h> 417c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 427c478bd9Sstevel@tonic-gate #include <sys/promif.h> 437c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 447c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 457c478bd9Sstevel@tonic-gate #include <starfire/sys/cpu_sgn.h> 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate static timestruc_t todsf_get(void); 487c478bd9Sstevel@tonic-gate static void todsf_set(timestruc_t); 497c478bd9Sstevel@tonic-gate static uint_t todsf_set_watchdog_timer(uint_t); 507c478bd9Sstevel@tonic-gate static uint_t todsf_clear_watchdog_timer(void); 517c478bd9Sstevel@tonic-gate static void todsf_set_power_alarm(timestruc_t); 527c478bd9Sstevel@tonic-gate static void todsf_clear_power_alarm(void); 537c478bd9Sstevel@tonic-gate static uint64_t todsf_get_cpufrequency(void); 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = { 59*88294e09SRichard Bean &mod_miscops, "Soft tod module for Starfire" 607c478bd9Sstevel@tonic-gate }; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 637c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modlmisc, NULL 647c478bd9Sstevel@tonic-gate }; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate int 677c478bd9Sstevel@tonic-gate _init(void) 687c478bd9Sstevel@tonic-gate { 697c478bd9Sstevel@tonic-gate if (strcmp(tod_module_name, "todstarfire") == 0) { 707c478bd9Sstevel@tonic-gate int ssp_time32; 717c478bd9Sstevel@tonic-gate char obp_string[40]; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* Set the string to pass to OBP */ 747c478bd9Sstevel@tonic-gate (void) sprintf(obp_string, "h# %p unix-gettod", 757c478bd9Sstevel@tonic-gate (void *)&ssp_time32); 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* Get OBP to get TOD from ssp */ 787c478bd9Sstevel@tonic-gate prom_interpret(obp_string, 0, 0, 0, 0, 0); 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate hrestime.tv_sec = (time_t)ssp_time32; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate tod_ops.tod_get = todsf_get; 837c478bd9Sstevel@tonic-gate tod_ops.tod_set = todsf_set; 847c478bd9Sstevel@tonic-gate tod_ops.tod_set_watchdog_timer = todsf_set_watchdog_timer; 857c478bd9Sstevel@tonic-gate tod_ops.tod_clear_watchdog_timer = todsf_clear_watchdog_timer; 867c478bd9Sstevel@tonic-gate tod_ops.tod_set_power_alarm = todsf_set_power_alarm; 877c478bd9Sstevel@tonic-gate tod_ops.tod_clear_power_alarm = todsf_clear_power_alarm; 887c478bd9Sstevel@tonic-gate tod_ops.tod_get_cpufrequency = todsf_get_cpufrequency; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * Flag warning if user tried to use hardware watchdog 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate if (watchdog_enable) { 947c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Hardware watchdog unavailable"); 957c478bd9Sstevel@tonic-gate } 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate int 1027c478bd9Sstevel@tonic-gate _fini(void) 1037c478bd9Sstevel@tonic-gate { 1047c478bd9Sstevel@tonic-gate if (strcmp(tod_module_name, "todstarfire") == 0) 1057c478bd9Sstevel@tonic-gate return (EBUSY); 1067c478bd9Sstevel@tonic-gate else 1077c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate int 1117c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1127c478bd9Sstevel@tonic-gate { 1137c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * Simply return hrestime value 1197c478bd9Sstevel@tonic-gate * Must be called with tod_lock held. 1207c478bd9Sstevel@tonic-gate */ 1217c478bd9Sstevel@tonic-gate static timestruc_t 1227c478bd9Sstevel@tonic-gate todsf_get(void) 1237c478bd9Sstevel@tonic-gate { 1247c478bd9Sstevel@tonic-gate timestruc_t ts; 1257c478bd9Sstevel@tonic-gate extern cpu_sgnblk_t *cpu_sgnblkp[]; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate ts = hrestime; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* Update the heartbeat */ 1327c478bd9Sstevel@tonic-gate if (cpu_sgnblkp[CPU->cpu_id] != NULL) 1337c478bd9Sstevel@tonic-gate cpu_sgnblkp[CPU->cpu_id]->sigb_heartbeat++; 1347c478bd9Sstevel@tonic-gate return (ts); 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * Null function for now. 1397c478bd9Sstevel@tonic-gate * Must be called with tod_lock held. 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1427c478bd9Sstevel@tonic-gate static void 1437c478bd9Sstevel@tonic-gate todsf_set(timestruc_t ts) 1447c478bd9Sstevel@tonic-gate { 1457c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * No watchdog function. 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1537c478bd9Sstevel@tonic-gate static uint_t 1547c478bd9Sstevel@tonic-gate todsf_set_watchdog_timer(uint_t timeoutval) 1557c478bd9Sstevel@tonic-gate { 1567c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1577c478bd9Sstevel@tonic-gate return (0); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate /* 1617c478bd9Sstevel@tonic-gate * No watchdog function 1627c478bd9Sstevel@tonic-gate */ 1637c478bd9Sstevel@tonic-gate static uint_t 1647c478bd9Sstevel@tonic-gate todsf_clear_watchdog_timer(void) 1657c478bd9Sstevel@tonic-gate { 1667c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1677c478bd9Sstevel@tonic-gate return (0); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * Null function. 1727c478bd9Sstevel@tonic-gate */ 1737c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1747c478bd9Sstevel@tonic-gate static void 1757c478bd9Sstevel@tonic-gate todsf_set_power_alarm(timestruc_t ts) 1767c478bd9Sstevel@tonic-gate { 1777c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* 1817c478bd9Sstevel@tonic-gate * Null function 1827c478bd9Sstevel@tonic-gate */ 1837c478bd9Sstevel@tonic-gate static void 1847c478bd9Sstevel@tonic-gate todsf_clear_power_alarm() 1857c478bd9Sstevel@tonic-gate { 1867c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1877c478bd9Sstevel@tonic-gate } 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate /* 1907c478bd9Sstevel@tonic-gate * Get clock freq from the cpunode 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate uint64_t 1937c478bd9Sstevel@tonic-gate todsf_get_cpufrequency(void) 1947c478bd9Sstevel@tonic-gate { 1957c478bd9Sstevel@tonic-gate return (cpunodes[CPU->cpu_id].clock_freq); 1967c478bd9Sstevel@tonic-gate } 197