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