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