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