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