Home | History | Annotate | Line # | Download | only in dev
clockctl.c revision 1.2
      1 /*      $NetBSD: clockctl.c,v 1.2 2001/11/13 05:32:49 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.2 2001/11/13 05:32:49 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 #include <sys/types.h>
     44 #ifdef NTP
     45 #include <sys/timex.h>
     46 #endif /* NTP */
     47 
     48 #include <sys/clockctl.h>
     49 
     50 struct clockctl_softc {
     51 	struct device   clockctl_dev;
     52 };
     53 
     54 
     55 void
     56 clockctlattach(parent, self, aux)
     57 	struct device *self;
     58 	struct device *parent;
     59 	void *aux;
     60 {
     61 	/* Nothing to set up before open is called */
     62 	return;
     63 }
     64 
     65 int
     66 clockctlopen(dev, flags, fmt, p)
     67 	dev_t dev;
     68 	int flags, fmt;
     69 	struct proc *p;
     70 {
     71 	return 0;
     72 }
     73 
     74 int
     75 clockctlclose(dev, flags, fmt, p)
     76 	dev_t dev;
     77 	int flags, fmt;
     78 	struct proc *p;
     79 {
     80 	return 0;
     81 }
     82 
     83 int
     84 clockctlioctl(dev, cmd, data, flags, p)
     85 	dev_t dev;
     86 	u_long cmd;
     87 	caddr_t data;
     88 	int flags;
     89 	struct proc *p;
     90 {
     91 	int error = 0;
     92 
     93 	switch (cmd) {
     94 		case CLOCKCTL_SETTIMEOFDAY: {
     95 			struct clockctl_settimeofday_args *args =
     96 			    (struct clockctl_settimeofday_args *)&data;
     97 
     98 			error = settimeofday1(&args->tv, &args->tzp, p);
     99 			if (error)
    100 				return (error);
    101 			break;
    102 		}
    103 		case CLOCKCTL_ADJTIME: {
    104 			struct clockctl_adjtime_args *args =
    105 			    (struct clockctl_adjtime_args *)&data;
    106 
    107 			error = adjtime1(&args->delta, &args->olddelta, p);
    108 			if (error)
    109 				return (error);
    110 			break;
    111 		}
    112 		case CLOCKCTL_CLOCK_SETTIME: {
    113 			struct clockctl_clock_settime_args *args =
    114 			    (struct clockctl_clock_settime_args *)&data;
    115 
    116 			error = clock_settime1(args->clock_id, &args->tp);
    117 			if (error)
    118 				return (error);
    119 			break;
    120 		}
    121 #ifdef NTP
    122 		case CLOCKCTL_NTP_ADJTIME: {
    123 			struct clockctl_ntp_adjtime_args *args =
    124 			    (struct clockctl_ntp_adjtime_args *)&data;
    125 
    126 			(void*)ntp_adjtime1(&args->tp, &error);
    127 			return (error);
    128 		}
    129 #endif /* NTP */
    130 		default:
    131 			error = EINVAL;
    132 	}
    133 
    134 	return (error);
    135 }
    136 
    137 
    138