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