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*19397407SSherry Moore * Common Development and Distribution License (the "License"). 6*19397407SSherry Moore * 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*19397407SSherry Moore * 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 #include <sys/types.h> 287c478bd9Sstevel@tonic-gate #include <sys/time.h> 297c478bd9Sstevel@tonic-gate #include <sys/errno.h> 307c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 317c478bd9Sstevel@tonic-gate #include <sys/param.h> 327c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 337c478bd9Sstevel@tonic-gate #include <sys/conf.h> 347c478bd9Sstevel@tonic-gate #include <sys/open.h> 357c478bd9Sstevel@tonic-gate #include <sys/stat.h> 367c478bd9Sstevel@tonic-gate #include <sys/clock.h> 377c478bd9Sstevel@tonic-gate #include <sys/tod.h> 387c478bd9Sstevel@tonic-gate #include <sys/todio.h> 397c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 407c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 417c478bd9Sstevel@tonic-gate #include <sys/file.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #define getsoftc(minor) \ 457c478bd9Sstevel@tonic-gate ((struct tod_softc *)ddi_get_soft_state(statep, (minor))) 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* dev_ops and cb_ops entry point function declarations */ 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate static int tod_attach(dev_info_t *, ddi_attach_cmd_t); 507c478bd9Sstevel@tonic-gate static int tod_detach(dev_info_t *, ddi_detach_cmd_t); 517c478bd9Sstevel@tonic-gate static int tod_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate static int tod_open(dev_t *, int, int, cred_t *); 547c478bd9Sstevel@tonic-gate static int tod_close(dev_t, int, int, cred_t *); 557c478bd9Sstevel@tonic-gate static int tod_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate struct cb_ops tod_cb_ops = { 587c478bd9Sstevel@tonic-gate tod_open, 597c478bd9Sstevel@tonic-gate tod_close, 607c478bd9Sstevel@tonic-gate nodev, 617c478bd9Sstevel@tonic-gate nodev, 627c478bd9Sstevel@tonic-gate nodev, /* dump */ 637c478bd9Sstevel@tonic-gate nodev, 647c478bd9Sstevel@tonic-gate nodev, 657c478bd9Sstevel@tonic-gate tod_ioctl, 667c478bd9Sstevel@tonic-gate nodev, /* devmap */ 677c478bd9Sstevel@tonic-gate nodev, 687c478bd9Sstevel@tonic-gate ddi_segmap, /* segmap */ 697c478bd9Sstevel@tonic-gate nochpoll, 707c478bd9Sstevel@tonic-gate ddi_prop_op, 717c478bd9Sstevel@tonic-gate NULL, /* for STREAMS drivers */ 727c478bd9Sstevel@tonic-gate D_NEW | D_MP /* driver compatibility flag */ 737c478bd9Sstevel@tonic-gate }; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate static struct dev_ops tod_dev_ops = { 767c478bd9Sstevel@tonic-gate DEVO_REV, /* driver build version */ 777c478bd9Sstevel@tonic-gate 0, /* device reference count */ 787c478bd9Sstevel@tonic-gate tod_getinfo, 797c478bd9Sstevel@tonic-gate nulldev, 807c478bd9Sstevel@tonic-gate nulldev, /* probe */ 817c478bd9Sstevel@tonic-gate tod_attach, 827c478bd9Sstevel@tonic-gate tod_detach, 837c478bd9Sstevel@tonic-gate nulldev, /* reset */ 847c478bd9Sstevel@tonic-gate &tod_cb_ops, 857c478bd9Sstevel@tonic-gate (struct bus_ops *)NULL, 86*19397407SSherry Moore nulldev, /* power */ 87*19397407SSherry Moore ddi_quiesce_not_supported, /* devo_quiesce */ 887c478bd9Sstevel@tonic-gate }; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* module configuration stuff */ 917c478bd9Sstevel@tonic-gate static void *statep; 927c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 957c478bd9Sstevel@tonic-gate &mod_driverops, 96*19397407SSherry Moore "tod driver", 977c478bd9Sstevel@tonic-gate &tod_dev_ops 987c478bd9Sstevel@tonic-gate }; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1017c478bd9Sstevel@tonic-gate MODREV_1, 1027c478bd9Sstevel@tonic-gate &modldrv, 1037c478bd9Sstevel@tonic-gate 0 1047c478bd9Sstevel@tonic-gate }; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate int 1087c478bd9Sstevel@tonic-gate _init(void) 1097c478bd9Sstevel@tonic-gate { 1107c478bd9Sstevel@tonic-gate int e; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate if (e = ddi_soft_state_init(&statep, sizeof (struct tod_softc), 1)) { 1137c478bd9Sstevel@tonic-gate return (e); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate if ((e = mod_install(&modlinkage)) != 0) { 1177c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&statep); 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate return (e); 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate int 1257c478bd9Sstevel@tonic-gate _fini(void) 1267c478bd9Sstevel@tonic-gate { 1277c478bd9Sstevel@tonic-gate int e; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate if ((e = mod_remove(&modlinkage)) != 0) { 1307c478bd9Sstevel@tonic-gate return (e); 1317c478bd9Sstevel@tonic-gate } 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&statep); 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate int 1407c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1417c478bd9Sstevel@tonic-gate { 1427c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1477c478bd9Sstevel@tonic-gate static int 1487c478bd9Sstevel@tonic-gate tod_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 1497c478bd9Sstevel@tonic-gate { 1507c478bd9Sstevel@tonic-gate int inst = getminor((dev_t)arg); 1517c478bd9Sstevel@tonic-gate int retval = DDI_SUCCESS; 1527c478bd9Sstevel@tonic-gate struct tod_softc *softc; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate switch (cmd) { 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 1577c478bd9Sstevel@tonic-gate if ((softc = getsoftc(inst)) == NULL) { 1587c478bd9Sstevel@tonic-gate *result = (void *)NULL; 1597c478bd9Sstevel@tonic-gate retval = DDI_FAILURE; 1607c478bd9Sstevel@tonic-gate } else { 1617c478bd9Sstevel@tonic-gate *result = (void *)softc->dip; 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate break; 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 166b0b35aceSmike_s *result = (void *)(uintptr_t)inst; 1677c478bd9Sstevel@tonic-gate break; 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate default: 1707c478bd9Sstevel@tonic-gate retval = DDI_FAILURE; 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate return (retval); 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate static int 1777c478bd9Sstevel@tonic-gate tod_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 1787c478bd9Sstevel@tonic-gate { 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate int inst; 1817c478bd9Sstevel@tonic-gate struct tod_softc *softc = NULL; 1827c478bd9Sstevel@tonic-gate char name[80]; 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate switch (cmd) { 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate case DDI_ATTACH: 1877c478bd9Sstevel@tonic-gate inst = ddi_get_instance(dip); 1887c478bd9Sstevel@tonic-gate /* 1897c478bd9Sstevel@tonic-gate * Create minor node. The minor device number, inst, has no 1907c478bd9Sstevel@tonic-gate * meaning. The model number above, which will be added to 1917c478bd9Sstevel@tonic-gate * the device's softc, is used to direct peculiar behavior. 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate (void) sprintf(name, "tod%d", inst); 1947c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, name, S_IFCHR, inst, 1957c478bd9Sstevel@tonic-gate DDI_PSEUDO, NULL) == DDI_FAILURE) 1967c478bd9Sstevel@tonic-gate goto attach_failed; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * Allocate a soft state structure for this instance. 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(statep, inst) != DDI_SUCCESS) 2027c478bd9Sstevel@tonic-gate goto attach_failed; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate softc = getsoftc(inst); 2057c478bd9Sstevel@tonic-gate softc->dip = dip; 2067c478bd9Sstevel@tonic-gate softc->cpr_stage = ~TOD_SUSPENDED; 2077c478bd9Sstevel@tonic-gate mutex_init(&softc->mutex, NULL, MUTEX_DRIVER, NULL); 2087c478bd9Sstevel@tonic-gate ddi_report_dev(dip); 2097c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate case DDI_RESUME: 2127c478bd9Sstevel@tonic-gate inst = ddi_get_instance(dip); 2137c478bd9Sstevel@tonic-gate softc = getsoftc(inst); 2147c478bd9Sstevel@tonic-gate mutex_enter(&softc->mutex); 2157c478bd9Sstevel@tonic-gate softc->cpr_stage = ~TOD_SUSPENDED; 2167c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 2177c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate default: 2207c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate attach_failed: 2247c478bd9Sstevel@tonic-gate /* Free soft state, if allocated. remove minor node if added earlier */ 2257c478bd9Sstevel@tonic-gate if (softc) 2267c478bd9Sstevel@tonic-gate ddi_soft_state_free(statep, inst); 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate static int 2347c478bd9Sstevel@tonic-gate tod_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 2357c478bd9Sstevel@tonic-gate { 2367c478bd9Sstevel@tonic-gate int inst; 2377c478bd9Sstevel@tonic-gate struct tod_softc *softc; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate switch (cmd) { 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate case DDI_DETACH: 2427c478bd9Sstevel@tonic-gate inst = ddi_get_instance(dip); 2437c478bd9Sstevel@tonic-gate if ((softc = getsoftc(inst)) == NULL) 2447c478bd9Sstevel@tonic-gate return (ENXIO); 2457c478bd9Sstevel@tonic-gate /* 2467c478bd9Sstevel@tonic-gate * Free the soft state and remove minor node added earlier. 2477c478bd9Sstevel@tonic-gate */ 2487c478bd9Sstevel@tonic-gate mutex_destroy(&softc->mutex); 2497c478bd9Sstevel@tonic-gate ddi_soft_state_free(statep, inst); 2507c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 2517c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 2547c478bd9Sstevel@tonic-gate inst = ddi_get_instance(dip); 2557c478bd9Sstevel@tonic-gate softc = getsoftc(inst); 2567c478bd9Sstevel@tonic-gate mutex_enter(&softc->mutex); 2577c478bd9Sstevel@tonic-gate softc->cpr_stage = TOD_SUSPENDED; 2587c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 2597c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate default: 2627c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate } 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2687c478bd9Sstevel@tonic-gate static int 2697c478bd9Sstevel@tonic-gate tod_open(dev_t *devp, int flag, int otyp, cred_t *credp) 2707c478bd9Sstevel@tonic-gate { 2717c478bd9Sstevel@tonic-gate int inst = getminor(*devp); 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate return (getsoftc(inst) == NULL ? ENXIO : 0); 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2787c478bd9Sstevel@tonic-gate static int 2797c478bd9Sstevel@tonic-gate tod_close(dev_t dev, int flag, int otyp, cred_t *credp) 2807c478bd9Sstevel@tonic-gate { 2817c478bd9Sstevel@tonic-gate int inst = getminor(dev); 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate return (getsoftc(inst) == NULL ? ENXIO : 0); 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2887c478bd9Sstevel@tonic-gate static int 2897c478bd9Sstevel@tonic-gate tod_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp) 2907c478bd9Sstevel@tonic-gate { 2917c478bd9Sstevel@tonic-gate int inst = getminor(dev); 2927c478bd9Sstevel@tonic-gate struct tod_softc *softc; 2937c478bd9Sstevel@tonic-gate timestruc_t ts; 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate if ((softc = getsoftc(inst)) == NULL) 2967c478bd9Sstevel@tonic-gate return (ENXIO); 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate mutex_enter(&softc->mutex); 2997c478bd9Sstevel@tonic-gate while (softc->cpr_stage == TOD_SUSPENDED) { 3007c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 3017c478bd9Sstevel@tonic-gate (void) ddi_dev_is_needed(softc->dip, 0, 1); 3027c478bd9Sstevel@tonic-gate mutex_enter(&softc->mutex); 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate switch (cmd) { 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate case TOD_CLEAR_ALARM: 3087c478bd9Sstevel@tonic-gate mutex_enter(&tod_lock); 3097c478bd9Sstevel@tonic-gate tod_ops.tod_clear_power_alarm(); 3107c478bd9Sstevel@tonic-gate mutex_exit(&tod_lock); 3117c478bd9Sstevel@tonic-gate break; 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate case TOD_SET_ALARM: 3147c478bd9Sstevel@tonic-gate if ((mode & FMODELS) == FNATIVE) { 3157c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&ts.tv_sec, 3167c478bd9Sstevel@tonic-gate sizeof (ts.tv_sec), mode) != 0) { 3177c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 3187c478bd9Sstevel@tonic-gate return (EFAULT); 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate } else { 3217c478bd9Sstevel@tonic-gate time32_t time32; 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, 3247c478bd9Sstevel@tonic-gate &time32, sizeof (time32), mode) != 0) { 3257c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 3267c478bd9Sstevel@tonic-gate return (EFAULT); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate ts.tv_sec = (time_t)time32; 3297c478bd9Sstevel@tonic-gate } 3307c478bd9Sstevel@tonic-gate ts.tv_nsec = 0; 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate mutex_enter(&tod_lock); 3337c478bd9Sstevel@tonic-gate tod_ops.tod_set_power_alarm(ts); 3347c478bd9Sstevel@tonic-gate mutex_exit(&tod_lock); 3357c478bd9Sstevel@tonic-gate break; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate case TOD_GET_DATE: 3387c478bd9Sstevel@tonic-gate mutex_enter(&tod_lock); 3397c478bd9Sstevel@tonic-gate ts = tod_ops.tod_get(); 3407c478bd9Sstevel@tonic-gate mutex_exit(&tod_lock); 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate if ((mode & FMODELS) == FNATIVE) { 3437c478bd9Sstevel@tonic-gate if (ddi_copyout((caddr_t)&ts.tv_sec, (caddr_t)arg, 3447c478bd9Sstevel@tonic-gate sizeof (ts.tv_sec), mode) != 0) { 3457c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 3467c478bd9Sstevel@tonic-gate return (EFAULT); 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate } else { 3497c478bd9Sstevel@tonic-gate time32_t time32; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate if (TIMEVAL_OVERFLOW(&ts)) { 3527c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 3537c478bd9Sstevel@tonic-gate return (EOVERFLOW); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate time32 = (time32_t)ts.tv_sec; 3577c478bd9Sstevel@tonic-gate if (ddi_copyout(&time32, 3587c478bd9Sstevel@tonic-gate (caddr_t)arg, sizeof (time32), mode) != 0) { 3597c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 3607c478bd9Sstevel@tonic-gate return (EFAULT); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate break; 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate default: 3667c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 3677c478bd9Sstevel@tonic-gate return (EINVAL); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate mutex_exit(&softc->mutex); 3717c478bd9Sstevel@tonic-gate return (0); 3727c478bd9Sstevel@tonic-gate } 373