Home | History | Annotate | Line # | Download | only in dev
clockctl.c revision 1.4.2.3
      1  1.4.2.3  jdolecek /*      $NetBSD: clockctl.c,v 1.4.2.3 2002/03/16 16:00:48 jdolecek Exp $ */
      2  1.4.2.2   thorpej 
      3  1.4.2.2   thorpej /*-
      4  1.4.2.2   thorpej  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.4.2.2   thorpej  * All rights reserved.
      6  1.4.2.2   thorpej  *
      7  1.4.2.2   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.4.2.2   thorpej  * by Emmanuel Dreyfus.
      9  1.4.2.2   thorpej  *
     10  1.4.2.2   thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.4.2.2   thorpej  * modification, are permitted provided that the following conditions
     12  1.4.2.2   thorpej  * are met:
     13  1.4.2.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.4.2.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.4.2.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.4.2.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.4.2.2   thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.4.2.2   thorpej  * 3. The name of the author may not be used to endorse or promote products
     19  1.4.2.2   thorpej  *    derived from this software without specific prior written permission.
     20  1.4.2.2   thorpej  *
     21  1.4.2.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.4.2.2   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.4.2.2   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.4.2.2   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.4.2.2   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.4.2.2   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.4.2.2   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.4.2.2   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.4.2.2   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.4.2.2   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.4.2.2   thorpej  */
     32  1.4.2.2   thorpej 
     33  1.4.2.2   thorpej #include <sys/cdefs.h>
     34  1.4.2.3  jdolecek __KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.4.2.3 2002/03/16 16:00:48 jdolecek Exp $");
     35  1.4.2.3  jdolecek 
     36  1.4.2.3  jdolecek #include "opt_ntp.h"
     37  1.4.2.2   thorpej 
     38  1.4.2.2   thorpej #include <sys/param.h>
     39  1.4.2.2   thorpej #include <sys/systm.h>
     40  1.4.2.2   thorpej #include <sys/proc.h>
     41  1.4.2.2   thorpej #include <sys/errno.h>
     42  1.4.2.2   thorpej #include <sys/ioctl.h>
     43  1.4.2.2   thorpej #include <sys/device.h>
     44  1.4.2.2   thorpej #include <sys/time.h>
     45  1.4.2.2   thorpej #ifdef NTP
     46  1.4.2.2   thorpej #include <sys/timex.h>
     47  1.4.2.2   thorpej #endif /* NTP */
     48  1.4.2.2   thorpej 
     49  1.4.2.2   thorpej #include <sys/clockctl.h>
     50  1.4.2.2   thorpej 
     51  1.4.2.2   thorpej struct clockctl_softc {
     52  1.4.2.2   thorpej 	struct device   clockctl_dev;
     53  1.4.2.2   thorpej };
     54  1.4.2.2   thorpej 
     55  1.4.2.2   thorpej 
     56  1.4.2.2   thorpej void
     57  1.4.2.2   thorpej clockctlattach(parent, self, aux)
     58  1.4.2.2   thorpej 	struct device *self;
     59  1.4.2.2   thorpej 	struct device *parent;
     60  1.4.2.2   thorpej 	void *aux;
     61  1.4.2.2   thorpej {
     62  1.4.2.2   thorpej 	/* Nothing to set up before open is called */
     63  1.4.2.2   thorpej 	return;
     64  1.4.2.2   thorpej }
     65  1.4.2.2   thorpej 
     66  1.4.2.2   thorpej int
     67  1.4.2.2   thorpej clockctlopen(dev, flags, fmt, p)
     68  1.4.2.2   thorpej 	dev_t dev;
     69  1.4.2.2   thorpej 	int flags, fmt;
     70  1.4.2.2   thorpej 	struct proc *p;
     71  1.4.2.2   thorpej {
     72  1.4.2.2   thorpej 	return 0;
     73  1.4.2.2   thorpej }
     74  1.4.2.2   thorpej 
     75  1.4.2.2   thorpej int
     76  1.4.2.2   thorpej clockctlclose(dev, flags, fmt, p)
     77  1.4.2.2   thorpej 	dev_t dev;
     78  1.4.2.2   thorpej 	int flags, fmt;
     79  1.4.2.2   thorpej 	struct proc *p;
     80  1.4.2.2   thorpej {
     81  1.4.2.2   thorpej 	return 0;
     82  1.4.2.2   thorpej }
     83  1.4.2.2   thorpej 
     84  1.4.2.2   thorpej int
     85  1.4.2.2   thorpej clockctlioctl(dev, cmd, data, flags, p)
     86  1.4.2.2   thorpej 	dev_t dev;
     87  1.4.2.2   thorpej 	u_long cmd;
     88  1.4.2.2   thorpej 	caddr_t data;
     89  1.4.2.2   thorpej 	int flags;
     90  1.4.2.2   thorpej 	struct proc *p;
     91  1.4.2.2   thorpej {
     92  1.4.2.2   thorpej 	int error = 0;
     93  1.4.2.2   thorpej 
     94  1.4.2.2   thorpej 	switch (cmd) {
     95  1.4.2.2   thorpej 		case CLOCKCTL_SETTIMEOFDAY: {
     96  1.4.2.2   thorpej 			struct sys_settimeofday_args *args =
     97  1.4.2.2   thorpej 			    (struct sys_settimeofday_args *)data;
     98  1.4.2.2   thorpej 
     99  1.4.2.2   thorpej 			error = settimeofday1(SCARG(args, tv),
    100  1.4.2.2   thorpej 			    SCARG(args, tzp), p);
    101  1.4.2.2   thorpej 			if (error)
    102  1.4.2.2   thorpej 				return (error);
    103  1.4.2.2   thorpej 			break;
    104  1.4.2.2   thorpej 		}
    105  1.4.2.2   thorpej 		case CLOCKCTL_ADJTIME: {
    106  1.4.2.2   thorpej 			struct sys_adjtime_args *args =
    107  1.4.2.2   thorpej 			    (struct sys_adjtime_args *)data;
    108  1.4.2.2   thorpej 
    109  1.4.2.2   thorpej 			error = adjtime1(SCARG(args, delta),
    110  1.4.2.2   thorpej 			    SCARG(args, olddelta), p);
    111  1.4.2.2   thorpej 			if (error)
    112  1.4.2.2   thorpej 				return (error);
    113  1.4.2.2   thorpej 			break;
    114  1.4.2.2   thorpej 		}
    115  1.4.2.2   thorpej 		case CLOCKCTL_CLOCK_SETTIME: {
    116  1.4.2.2   thorpej 			struct sys_clock_settime_args *args =
    117  1.4.2.2   thorpej 			    (struct sys_clock_settime_args *)data;
    118  1.4.2.2   thorpej 
    119  1.4.2.2   thorpej 			error = clock_settime1(SCARG(args, clock_id),
    120  1.4.2.2   thorpej 			    SCARG(args, tp));
    121  1.4.2.2   thorpej 			if (error)
    122  1.4.2.2   thorpej 				return (error);
    123  1.4.2.2   thorpej 			break;
    124  1.4.2.2   thorpej 		}
    125  1.4.2.2   thorpej #ifdef NTP
    126  1.4.2.2   thorpej 		case CLOCKCTL_NTP_ADJTIME: {
    127  1.4.2.2   thorpej 			struct clockctl_ntp_adjtime_args *args =
    128  1.4.2.2   thorpej 			    (struct clockctl_ntp_adjtime_args *)data;
    129  1.4.2.3  jdolecek 			struct timex ntv;
    130  1.4.2.2   thorpej 
    131  1.4.2.3  jdolecek 			error = copyin((caddr_t)SCARG(args,uas.tp),
    132  1.4.2.3  jdolecek 			    (caddr_t)&ntv, sizeof(ntv));
    133  1.4.2.3  jdolecek 			if (error)
    134  1.4.2.3  jdolecek 				return (error);
    135  1.4.2.3  jdolecek 
    136  1.4.2.3  jdolecek 			error = ntp_adjtime1(&ntv, args, &args->retval);
    137  1.4.2.3  jdolecek 			return (error);
    138  1.4.2.3  jdolecek 			break;
    139  1.4.2.2   thorpej 		}
    140  1.4.2.2   thorpej #endif /* NTP */
    141  1.4.2.2   thorpej 		default:
    142  1.4.2.2   thorpej 			error = EINVAL;
    143  1.4.2.2   thorpej 	}
    144  1.4.2.2   thorpej 
    145  1.4.2.2   thorpej 	return (error);
    146  1.4.2.2   thorpej }
    147  1.4.2.2   thorpej 
    148  1.4.2.2   thorpej 
    149