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