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 5*b5b48cc1Ssudheer * Common Development and Distribution License (the "License"). 6*b5b48cc1Ssudheer * 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*b5b48cc1Ssudheer * Copyright 2007 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 #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * tod driver module for Starfire 317c478bd9Sstevel@tonic-gate * This module implements a soft tod since 327c478bd9Sstevel@tonic-gate * starfire has no tod part. 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <sys/types.h> 367c478bd9Sstevel@tonic-gate #include <sys/param.h> 377c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 387c478bd9Sstevel@tonic-gate #include <sys/systm.h> 397c478bd9Sstevel@tonic-gate #include <sys/errno.h> 407c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 417c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 427c478bd9Sstevel@tonic-gate #include <sys/debug.h> 437c478bd9Sstevel@tonic-gate #include <sys/clock.h> 447c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 457c478bd9Sstevel@tonic-gate #include <sys/promif.h> 467c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 477c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 487c478bd9Sstevel@tonic-gate #include <starfire/sys/cpu_sgn.h> 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate static timestruc_t todsf_get(void); 517c478bd9Sstevel@tonic-gate static void todsf_set(timestruc_t); 527c478bd9Sstevel@tonic-gate static uint_t todsf_set_watchdog_timer(uint_t); 537c478bd9Sstevel@tonic-gate static uint_t todsf_clear_watchdog_timer(void); 547c478bd9Sstevel@tonic-gate static void todsf_set_power_alarm(timestruc_t); 557c478bd9Sstevel@tonic-gate static void todsf_clear_power_alarm(void); 567c478bd9Sstevel@tonic-gate static uint64_t todsf_get_cpufrequency(void); 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = { 627c478bd9Sstevel@tonic-gate &mod_miscops, "Soft tod module for Starfire %I%" 637c478bd9Sstevel@tonic-gate }; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 667c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modlmisc, NULL 677c478bd9Sstevel@tonic-gate }; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate int 707c478bd9Sstevel@tonic-gate _init(void) 717c478bd9Sstevel@tonic-gate { 727c478bd9Sstevel@tonic-gate if (strcmp(tod_module_name, "todstarfire") == 0) { 737c478bd9Sstevel@tonic-gate int ssp_time32; 747c478bd9Sstevel@tonic-gate char obp_string[40]; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* Set the string to pass to OBP */ 777c478bd9Sstevel@tonic-gate (void) sprintf(obp_string, "h# %p unix-gettod", 787c478bd9Sstevel@tonic-gate (void *)&ssp_time32); 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* Get OBP to get TOD from ssp */ 817c478bd9Sstevel@tonic-gate prom_interpret(obp_string, 0, 0, 0, 0, 0); 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate hrestime.tv_sec = (time_t)ssp_time32; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate tod_ops.tod_get = todsf_get; 867c478bd9Sstevel@tonic-gate tod_ops.tod_set = todsf_set; 877c478bd9Sstevel@tonic-gate tod_ops.tod_set_watchdog_timer = todsf_set_watchdog_timer; 887c478bd9Sstevel@tonic-gate tod_ops.tod_clear_watchdog_timer = todsf_clear_watchdog_timer; 897c478bd9Sstevel@tonic-gate tod_ops.tod_set_power_alarm = todsf_set_power_alarm; 907c478bd9Sstevel@tonic-gate tod_ops.tod_clear_power_alarm = todsf_clear_power_alarm; 917c478bd9Sstevel@tonic-gate tod_ops.tod_get_cpufrequency = todsf_get_cpufrequency; 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate /* 947c478bd9Sstevel@tonic-gate * Flag warning if user tried to use hardware watchdog 957c478bd9Sstevel@tonic-gate */ 967c478bd9Sstevel@tonic-gate if (watchdog_enable) { 977c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Hardware watchdog unavailable"); 987c478bd9Sstevel@tonic-gate } 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate int 1057c478bd9Sstevel@tonic-gate _fini(void) 1067c478bd9Sstevel@tonic-gate { 1077c478bd9Sstevel@tonic-gate if (strcmp(tod_module_name, "todstarfire") == 0) 1087c478bd9Sstevel@tonic-gate return (EBUSY); 1097c478bd9Sstevel@tonic-gate else 1107c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate int 1147c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1157c478bd9Sstevel@tonic-gate { 1167c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* 1217c478bd9Sstevel@tonic-gate * Simply return hrestime value 1227c478bd9Sstevel@tonic-gate * Must be called with tod_lock held. 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate static timestruc_t 1257c478bd9Sstevel@tonic-gate todsf_get(void) 1267c478bd9Sstevel@tonic-gate { 1277c478bd9Sstevel@tonic-gate timestruc_t ts; 1287c478bd9Sstevel@tonic-gate extern cpu_sgnblk_t *cpu_sgnblkp[]; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate ts = hrestime; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* Update the heartbeat */ 1357c478bd9Sstevel@tonic-gate if (cpu_sgnblkp[CPU->cpu_id] != NULL) 1367c478bd9Sstevel@tonic-gate cpu_sgnblkp[CPU->cpu_id]->sigb_heartbeat++; 1377c478bd9Sstevel@tonic-gate return (ts); 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate /* 1417c478bd9Sstevel@tonic-gate * Null function for now. 1427c478bd9Sstevel@tonic-gate * Must be called with tod_lock held. 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1457c478bd9Sstevel@tonic-gate static void 1467c478bd9Sstevel@tonic-gate todsf_set(timestruc_t ts) 1477c478bd9Sstevel@tonic-gate { 1487c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* 1537c478bd9Sstevel@tonic-gate * No watchdog function. 1547c478bd9Sstevel@tonic-gate */ 1557c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1567c478bd9Sstevel@tonic-gate static uint_t 1577c478bd9Sstevel@tonic-gate todsf_set_watchdog_timer(uint_t timeoutval) 1587c478bd9Sstevel@tonic-gate { 1597c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1607c478bd9Sstevel@tonic-gate return (0); 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * No watchdog function 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate static uint_t 1677c478bd9Sstevel@tonic-gate todsf_clear_watchdog_timer(void) 1687c478bd9Sstevel@tonic-gate { 1697c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1707c478bd9Sstevel@tonic-gate return (0); 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * Null function. 1757c478bd9Sstevel@tonic-gate */ 1767c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1777c478bd9Sstevel@tonic-gate static void 1787c478bd9Sstevel@tonic-gate todsf_set_power_alarm(timestruc_t ts) 1797c478bd9Sstevel@tonic-gate { 1807c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* 1847c478bd9Sstevel@tonic-gate * Null function 1857c478bd9Sstevel@tonic-gate */ 1867c478bd9Sstevel@tonic-gate static void 1877c478bd9Sstevel@tonic-gate todsf_clear_power_alarm() 1887c478bd9Sstevel@tonic-gate { 1897c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tod_lock)); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * Get clock freq from the cpunode 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate uint64_t 1967c478bd9Sstevel@tonic-gate todsf_get_cpufrequency(void) 1977c478bd9Sstevel@tonic-gate { 1987c478bd9Sstevel@tonic-gate return (cpunodes[CPU->cpu_id].clock_freq); 1997c478bd9Sstevel@tonic-gate } 200