clockctl_50.c revision 1.1.2.5 1 1.1.2.5 pgoyette /* $NetBSD: clockctl_50.c,v 1.1.2.5 2019/01/23 03:34:14 pgoyette Exp $ */
2 1.1.2.1 pgoyette
3 1.1.2.1 pgoyette /*-
4 1.1.2.1 pgoyette * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1.2.1 pgoyette * All rights reserved.
6 1.1.2.1 pgoyette *
7 1.1.2.1 pgoyette * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.1 pgoyette * by Emmanuel Dreyfus.
9 1.1.2.1 pgoyette *
10 1.1.2.1 pgoyette * Redistribution and use in source and binary forms, with or without
11 1.1.2.1 pgoyette * modification, are permitted provided that the following conditions
12 1.1.2.1 pgoyette * are met:
13 1.1.2.1 pgoyette * 1. Redistributions of source code must retain the above copyright
14 1.1.2.1 pgoyette * notice, this list of conditions and the following disclaimer.
15 1.1.2.1 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.1 pgoyette * notice, this list of conditions and the following disclaimer in the
17 1.1.2.1 pgoyette * documentation and/or other materials provided with the distribution.
18 1.1.2.1 pgoyette * 3. The name of the author may not be used to endorse or promote products
19 1.1.2.1 pgoyette * derived from this software without specific prior written permission.
20 1.1.2.1 pgoyette *
21 1.1.2.1 pgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1.2.1 pgoyette * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1.2.1 pgoyette * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1.2.1 pgoyette * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1.2.1 pgoyette * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1.2.1 pgoyette * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1.2.1 pgoyette * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1.2.1 pgoyette * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1.2.1 pgoyette * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1.2.1 pgoyette * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1.2.1 pgoyette */
32 1.1.2.1 pgoyette
33 1.1.2.1 pgoyette #include <sys/cdefs.h>
34 1.1.2.5 pgoyette __KERNEL_RCSID(0, "$NetBSD: clockctl_50.c,v 1.1.2.5 2019/01/23 03:34:14 pgoyette Exp $");
35 1.1.2.4 pgoyette
36 1.1.2.4 pgoyette #if defined(_KERNEL_OPT)
37 1.1.2.4 pgoyette #include "opt_compat_netbsd.h"
38 1.1.2.4 pgoyette #endif
39 1.1.2.1 pgoyette
40 1.1.2.1 pgoyette #include <sys/param.h>
41 1.1.2.1 pgoyette #include <sys/systm.h>
42 1.1.2.1 pgoyette #include <sys/proc.h>
43 1.1.2.1 pgoyette #include <sys/errno.h>
44 1.1.2.1 pgoyette #include <sys/ioctl.h>
45 1.1.2.1 pgoyette #include <sys/device.h>
46 1.1.2.1 pgoyette #include <sys/time.h>
47 1.1.2.1 pgoyette #include <sys/conf.h>
48 1.1.2.1 pgoyette #include <sys/timex.h>
49 1.1.2.1 pgoyette #include <sys/kauth.h>
50 1.1.2.1 pgoyette #include <sys/module.h>
51 1.1.2.1 pgoyette #include <sys/mutex.h>
52 1.1.2.1 pgoyette #include <sys/compat_stub.h>
53 1.1.2.1 pgoyette
54 1.1.2.1 pgoyette #include <sys/clockctl.h>
55 1.1.2.1 pgoyette #include <compat/sys/clockctl.h>
56 1.1.2.1 pgoyette #include <compat/sys/time_types.h>
57 1.1.2.1 pgoyette
58 1.1.2.1 pgoyette int
59 1.1.2.1 pgoyette compat50_clockctlioctl(dev_t dev, u_long cmd, void *data, int flags,
60 1.1.2.1 pgoyette struct lwp *l)
61 1.1.2.1 pgoyette {
62 1.1.2.1 pgoyette int error = 0;
63 1.1.2.1 pgoyette const struct cdevsw *cd = cdevsw_lookup(dev);
64 1.1.2.1 pgoyette
65 1.1.2.1 pgoyette if (cd == NULL || cd->d_ioctl == NULL)
66 1.1.2.1 pgoyette return ENXIO;
67 1.1.2.1 pgoyette
68 1.1.2.1 pgoyette switch (cmd) {
69 1.1.2.1 pgoyette case CLOCKCTL_OSETTIMEOFDAY: {
70 1.1.2.1 pgoyette struct timeval50 tv50;
71 1.1.2.1 pgoyette struct timeval tv;
72 1.1.2.1 pgoyette struct clockctl50_settimeofday *args = data;
73 1.1.2.1 pgoyette
74 1.1.2.1 pgoyette error = copyin(args->tv, &tv50, sizeof(tv50));
75 1.1.2.1 pgoyette if (error)
76 1.1.2.1 pgoyette return (error);
77 1.1.2.1 pgoyette timeval50_to_timeval(&tv50, &tv);
78 1.1.2.1 pgoyette error = settimeofday1(&tv, false, args->tzp, l, false);
79 1.1.2.1 pgoyette break;
80 1.1.2.1 pgoyette }
81 1.1.2.1 pgoyette case CLOCKCTL_OADJTIME: {
82 1.1.2.1 pgoyette struct timeval atv, oldatv;
83 1.1.2.1 pgoyette struct timeval50 atv50;
84 1.1.2.1 pgoyette struct clockctl50_adjtime *args = data;
85 1.1.2.1 pgoyette
86 1.1.2.1 pgoyette if (args->delta) {
87 1.1.2.1 pgoyette error = copyin(args->delta, &atv50, sizeof(atv50));
88 1.1.2.1 pgoyette if (error)
89 1.1.2.1 pgoyette return (error);
90 1.1.2.1 pgoyette timeval50_to_timeval(&atv50, &atv);
91 1.1.2.1 pgoyette }
92 1.1.2.1 pgoyette adjtime1(args->delta ? &atv : NULL,
93 1.1.2.1 pgoyette args->olddelta ? &oldatv : NULL, l->l_proc);
94 1.1.2.1 pgoyette if (args->olddelta) {
95 1.1.2.1 pgoyette timeval_to_timeval50(&oldatv, &atv50);
96 1.1.2.1 pgoyette error = copyout(&atv50, args->olddelta, sizeof(atv50));
97 1.1.2.1 pgoyette }
98 1.1.2.1 pgoyette break;
99 1.1.2.1 pgoyette }
100 1.1.2.1 pgoyette case CLOCKCTL_OCLOCK_SETTIME: {
101 1.1.2.1 pgoyette struct timespec50 tp50;
102 1.1.2.1 pgoyette struct timespec tp;
103 1.1.2.1 pgoyette struct clockctl50_clock_settime *args = data;
104 1.1.2.1 pgoyette
105 1.1.2.1 pgoyette error = copyin(args->tp, &tp50, sizeof(tp50));
106 1.1.2.1 pgoyette if (error)
107 1.1.2.1 pgoyette return (error);
108 1.1.2.1 pgoyette timespec50_to_timespec(&tp50, &tp);
109 1.1.2.1 pgoyette error = clock_settime1(l->l_proc, args->clock_id, &tp, true);
110 1.1.2.1 pgoyette break;
111 1.1.2.1 pgoyette }
112 1.1.2.1 pgoyette case CLOCKCTL_ONTP_ADJTIME: {
113 1.1.2.1 pgoyette if (vec_ntp_timestatus == NULL) {
114 1.1.2.1 pgoyette error = ENOTTY;
115 1.1.2.1 pgoyette break;
116 1.1.2.1 pgoyette }
117 1.1.2.1 pgoyette /* The ioctl number changed but the data did not change. */
118 1.1.2.1 pgoyette error = (cd->d_ioctl)(dev, CLOCKCTL_NTP_ADJTIME,
119 1.1.2.1 pgoyette data, flags, l);
120 1.1.2.1 pgoyette break;
121 1.1.2.1 pgoyette }
122 1.1.2.1 pgoyette default:
123 1.1.2.1 pgoyette error = ENOTTY;
124 1.1.2.1 pgoyette }
125 1.1.2.1 pgoyette
126 1.1.2.1 pgoyette return (error);
127 1.1.2.1 pgoyette }
128 1.1.2.1 pgoyette
129 1.1.2.1 pgoyette void
130 1.1.2.1 pgoyette clockctl_50_init(void)
131 1.1.2.1 pgoyette {
132 1.1.2.1 pgoyette
133 1.1.2.5 pgoyette MODULE_SET_HOOK(clockctl_ioctl_50_hook, "clk_50",
134 1.1.2.5 pgoyette compat50_clockctlioctl);
135 1.1.2.1 pgoyette }
136 1.1.2.1 pgoyette
137 1.1.2.1 pgoyette void
138 1.1.2.1 pgoyette clockctl_50_fini(void)
139 1.1.2.1 pgoyette {
140 1.1.2.1 pgoyette
141 1.1.2.5 pgoyette MODULE_UNSET_HOOK(clockctl_ioctl_50_hook);
142 1.1.2.1 pgoyette }
143