diff --git a/emulators/rtc/Makefile b/emulators/rtc/Makefile index f0ee5b917243..b20472e72e61 100644 --- a/emulators/rtc/Makefile +++ b/emulators/rtc/Makefile @@ -2,43 +2,29 @@ # $FreeBSD$ PORTNAME= rtc -PORTVERSION= 2004.02.24.1 -PORTREVISION= 8 +PORTVERSION= 2020.07.07.1 CATEGORIES= emulators linux MASTER_SITES= # none DISTFILES= # none -MAINTAINER= emulation@FreeBSD.org +MAINTAINER= jamie@catflap.org COMMENT= Kernel module which provides /dev/rtc device support -BROKEN_FreeBSD_12= fails to compile: rtc.c:166:2: implicit declaration of function 'MALLOC' is invalid in C99 -BROKEN_FreeBSD_13= fails to compile: rtc.c:166:2: implicit declaration of function 'MALLOC' is invalid in C99 +LICENSE= BSD2CLAUSE + +USES= kmod WRKSRC= ${WRKDIR}/files -KMODDIR= ${PREFIX}/modules - -CDEV_MAJOR= 202 -DEVDIR= ${LINUXBASE}/dev - -STARTUP= rtc.sh -MAKE_ARGS= KMODDIR="${KMODDIR}" CDEV_MAJOR="${CDEV_MAJOR}" -PLIST_SUB= DEVDIR="${DEVDIR}" CDEV_MAJOR="${CDEV_MAJOR}" \ - RTC_H_DIR="${RTC_H_DIR}" - -USES= kmod linux uidfix +MAKE_ARGS= KMODDIR="${KMODDIR}" do-extract: @${MKDIR} ${WRKSRC} - @${SED} -e 's,@@PREFIX@@,${PREFIX},' \ - ${FILESDIR}/${STARTUP} > ${WRKDIR}/${STARTUP} @cd ${FILESDIR} && ${CP} Makefile *.[ch] ${WRKSRC}/ post-install: ${INSTALL_DATA} ${WRKSRC}/rtc.h ${STAGEDIR}${PREFIX}/include ${MKDIR} ${STAGEDIR}${EXAMPLESDIR} ${INSTALL_DATA} ${WRKSRC}/test.c ${STAGEDIR}${EXAMPLESDIR} - @${ECHO} "Installing ${PREFIX}/etc/rc.d/${STARTUP} startup file."; - ${INSTALL_SCRIPT} ${WRKDIR}/${STARTUP} ${STAGEDIR}${PREFIX}/etc/rc.d .include diff --git a/emulators/rtc/files/Makefile b/emulators/rtc/files/Makefile index 25d4f702cf52..78cb82c8737b 100644 --- a/emulators/rtc/files/Makefile +++ b/emulators/rtc/files/Makefile @@ -26,23 +26,13 @@ # SYS?= /sys -NOMAN= YES KMOD= rtc -MODULE_DEPEND= linux -CDEV_MAJOR?= 202 -DEVNAME= ${KMOD} SRCS= rtc.c rtc_linux.c vnode_if.h INCLUDE= -I${.CURDIR} -I${SYS} -CFLAGS+= ${INCLUDE} -DCDEV_MAJOR_=${CDEV_MAJOR} +CFLAGS+= ${INCLUDE} all: vnode_if.h -#afterinstall: device - -device: - rm -f /dev/${DEVNAME} - mknod /dev/${DEVNAME} c ${CDEV_MAJOR} 0 - .include diff --git a/emulators/rtc/files/rtc.c b/emulators/rtc/files/rtc.c index c038575e4d18..6b4d26d55683 100644 --- a/emulators/rtc/files/rtc.c +++ b/emulators/rtc/files/rtc.c @@ -50,11 +50,6 @@ MODULE_DEPEND(rtc, linux, 1, 1, 1); #endif -#define CDEV_MAJOR 202 -#if defined(CDEV_MAJOR_) && CDEV_MAJOR != CDEV_MAJOR_ -#error "CDEV_MAJOR != CDEV_MAJOR_" -#endif - #define DEVICE_NAME "rtc" enum rtc_log_level {Lenter=0, Lexit=1, Linfo, Lwarning, Lfail}; @@ -68,11 +63,7 @@ enum rtc_log_level {Lenter=0, Lexit=1, Linfo, Lwarning, Lfail}; #endif /* DEBUG */ struct rtc_softc { -#if __FreeBSD_version >= 502117 struct cdev *dev; /* Back reference to device */ -#else - dev_t dev; /* Back reference to device */ -#endif struct { int freq; struct { @@ -97,40 +88,14 @@ static void rtc_callback(void *xtp); static int rtc_modeevent(module_t mod, int cmd, void *arg); static struct cdevsw rtc_cdevsw = { -#if __FreeBSD_version >= 500104 -#if __FreeBSD_version >= 502103 .d_version = D_VERSION, .d_flags = D_NEEDGIANT, -#else - .d_maj = CDEV_MAJOR, -#endif .d_open = rtc_open, .d_close = rtc_close, .d_ioctl = rtc_ioctl, .d_poll = rtc_poll, .d_read = rtc_read, .d_name = DEVICE_NAME, -#else - /* open */ rtc_open, - /* close */ rtc_close, - /* read */ rtc_read, - /* write */ nowrite, - /* ioctl */ rtc_ioctl, - /* poll */ rtc_poll, - /* mmap */ nommap, - /* strategy */ nostrategy, - /* name */ DEVICE_NAME, - /* maj */ CDEV_MAJOR, - /* dump */ nodump, - /* psize */ nopsize, - /* flags */ 0, -#if __FreeBSD_version <= 500018 - /* bmaj */ -1, -#endif -#if __FreeBSD_version >= 500018 || __FreeBSD_version >= 430000 - /* kqfilter */ nokqfilter, -#endif -#endif }; /* @@ -139,31 +104,22 @@ static struct cdevsw rtc_cdevsw = { */ DEV_MODULE(rtc, rtc_modeevent, 0); - /* -=-=-=-=-=-=-=-=-= attach/detach device stuff -=-=-=-=-=-=-=-=-= */ static struct rtc_softc * -#if __FreeBSD_version >= 502017 rtc_attach(struct cdev *dev) -#else -rtc_attach(dev_t dev) -#endif { struct rtc_softc *sc; int unit; -#if __FreeBSD_version >= 500014 unit = dev2unit(dev); -#else - unit = lminor(dev); -#endif DLog(Lenter, "%d %p", unit, dev); if (dev->si_drv1) { DLog(Lexit, "old %p, %p", dev, dev->si_drv1); return dev->si_drv1; } - MALLOC(sc, struct rtc_softc*, sizeof(*sc), M_DEVBUF, M_WAITOK); + sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK); if (sc==NULL) return NULL; @@ -172,22 +128,14 @@ rtc_attach(dev_t dev) sc->dev = dev; sc->var.freq = 1; -#if __FreeBSD_version >= 500000 callout_init(&sc->var.rtc_handle, 1); -#else - callout_init(&sc->var.rtc_handle); -#endif DLog(Lexit, "new %p,%p", dev, sc); return sc; } static int -#if __FreeBSD_version >= 502017 rtc_detach(struct cdev *dev, struct rtc_softc *sc) -#else -rtc_detach(dev_t dev, struct rtc_softc *sc) -#endif { int error=0; @@ -196,7 +144,7 @@ rtc_detach(dev_t dev, struct rtc_softc *sc) } callout_stop(&sc->var.rtc_handle); - FREE(sc, M_DEVBUF); + free(sc, M_DEVBUF); dev->si_drv1 = NULL; return error; } @@ -204,13 +152,7 @@ rtc_detach(dev_t dev, struct rtc_softc *sc) /* -=-=-=-=-=-=-=-=-= character device stuff -=-=-=-=-=-=-=-=-= */ static int -#if __FreeBSD_version >= 502017 rtc_open(struct cdev *dev, int oflag, int otyp, struct thread *p) -#elif __FreeBSD_version >= 500023 -rtc_open(dev_t dev, int oflag, int otyp, struct thread *p) -#else -rtc_open(dev_t dev, int oflag, int otyp, struct proc *p) -#endif { struct rtc_softc *sc; @@ -228,13 +170,7 @@ rtc_open(dev_t dev, int oflag, int otyp, struct proc *p) } int -#if __FreeBSD_version >= 502017 rtc_close(struct cdev *dev, int fflag, int otyp, struct thread *p) -#elif __FreeBSD_version >= 500023 -rtc_close(dev_t dev, int fflag, int otyp, struct thread *p) -#else -rtc_close(dev_t dev, int fflag, int otyp, struct proc *p) -#endif { struct rtc_softc *sc = (struct rtc_softc *) dev->si_drv1; @@ -244,13 +180,7 @@ rtc_close(dev_t dev, int fflag, int otyp, struct proc *p) } int -#if __FreeBSD_version >= 502017 rtc_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode, struct thread *p) -#elif __FreeBSD_version >= 500023 -rtc_ioctl(dev_t dev, u_long cmd, caddr_t arg, int mode, struct thread *p) -#else -rtc_ioctl(dev_t dev, u_long cmd, caddr_t arg, int mode, struct proc *p) -#endif { struct rtc_softc *sc = (struct rtc_softc *) dev->si_drv1; int error=0, freq, sleep; @@ -292,13 +222,7 @@ rtc_ioctl(dev_t dev, u_long cmd, caddr_t arg, int mode, struct proc *p) } int -#if __FreeBSD_version >= 502017 rtc_poll(struct cdev *dev, int events, struct thread *p) -#elif __FreeBSD_version >= 500023 -rtc_poll(dev_t dev, int events, struct thread *p) -#else -rtc_poll(dev_t dev, int events, struct proc *p) -#endif { struct rtc_softc *sc = (struct rtc_softc *) dev->si_drv1; int revents = 0; @@ -318,11 +242,7 @@ rtc_poll(dev_t dev, int events, struct proc *p) } int -#if __FreeBSD_version >= 502017 rtc_read(struct cdev *dev, struct uio *uio, int flags __unused) -#else -rtc_read(dev_t dev, struct uio *uio, int flags __unused) -#endif { struct rtc_softc *sc = (struct rtc_softc *) dev->si_drv1; int error = 0; @@ -351,23 +271,13 @@ rtc_read(dev_t dev, struct uio *uio, int flags __unused) } /* -=-=-=-=-=-=-=-=-= module load/unload stuff -=-=-=-=-=-=-=-=-= */ -#if __FreeBSD_version >= 502017 static struct cdev *rtc_dev = NULL; -#else -static dev_t rtc_dev = NULL; -#endif static int init_module(void) { int error = 0; -#if __FreeBSD_version < 500104 - error = cdevsw_add(&rtc_cdevsw); - if (error) - return error; -#endif - rtc_dev = make_dev(&rtc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0644, DEVICE_NAME); if (rtc_dev==NULL) error = ENOMEM; @@ -375,17 +285,12 @@ init_module(void) return error; } - - static int cleanup_module(void) { int error = 0; destroy_dev(rtc_dev); -#if __FreeBSD_version < 500104 - error = cdevsw_remove(&rtc_cdevsw); -#endif DLog(Linfo, "return %d", error); return error; } @@ -433,23 +338,37 @@ rtc_callback(void *xtp) restart: increment.tv_sec = 0; increment.tv_nsec = 1000000000 / sc->var.freq; +#if P_OSREL_MAJOR(__FreeBSD_version) >= 12 + timespecadd(&sc->var.lasttime, &increment, &sc->var.lasttime); + timespecadd(&sc->var.lasttime, &increment, &nexttime); +#else timespecadd(&sc->var.lasttime, &increment); nexttime.tv_sec = sc->var.lasttime.tv_sec; nexttime.tv_nsec = sc->var.lasttime.tv_nsec; timespecadd(&nexttime, &increment); +#endif if (timespeccmp(&nexttime, &curtime, <)) { /* Catch up if we lag curtime */ - sc->var.lasttime.tv_sec = curtime.tv_sec; - sc->var.lasttime.tv_nsec = curtime.tv_nsec; - timespecsub(&sc->var.lasttime, &increment); - timespecsub(&nexttime, &curtime); +#if P_OSREL_MAJOR(__FreeBSD_version) >= 12 + timespecsub(&curtime, &increment, &sc->var.lasttime); + timespecsub(&nexttime, &curtime, &nexttime); +#else + sc->var.lasttime.tv_sec = curtime.tv_sec; + sc->var.lasttime.tv_nsec = curtime.tv_nsec; + timespecsub(&sc->var.lasttime, &increment); + timespecsub(&nexttime, &curtime); +#endif #if 0 printf("lagging curtime by %d.%ld\n", nexttime.tv_sec, nexttime.tv_nsec); #endif goto restart; } else { +#if P_OSREL_MAJOR(__FreeBSD_version) >= 12 + timespecsub(&nexttime, &curtime, &nexttime); +#else timespecsub(&nexttime, &curtime); - sleep = nexttime.tv_nsec / (1000000000 / hz); - } - callout_reset(&sc->var.rtc_handle, sleep, &rtc_callback, xtp); +#endif + sleep = nexttime.tv_nsec / (1000000000 / hz); + } + callout_reset(&sc->var.rtc_handle, sleep, &rtc_callback, xtp); } diff --git a/emulators/rtc/files/rtc.sh b/emulators/rtc/files/rtc.sh deleted file mode 100644 index ac92bc1b1974..000000000000 --- a/emulators/rtc/files/rtc.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -kmoddir=@@PREFIX@@/modules -kmod=rtc.ko - -case "$1" in -start) - if [ -x $kmoddir/$kmod ]; then - echo -n ' rtc' - /sbin/kldload $kmoddir/$kmod - fi - ;; -stop) - /sbin/kldunload $kmod && echo -n ' rtc' - ;; -*) - echo "Usage: `basename $0` {start|stop}" >&2 - exit 64 - ;; -esac diff --git a/emulators/rtc/files/rtc_linux.c b/emulators/rtc/files/rtc_linux.c index e443d53bb70a..8e32bb8f5480 100644 --- a/emulators/rtc/files/rtc_linux.c +++ b/emulators/rtc/files/rtc_linux.c @@ -35,11 +35,7 @@ #include #include -#if __FreeBSD_version >= 500012 || __FreeBSD_version >= 430000 #include -#else -#include -#endif #include "rtc.h" @@ -62,27 +58,15 @@ SYSUNINIT(n##unregister, SI_SUB_KLD, SI_ORDER_MIDDLE, linux_ioctl_unregister_han LINUX_IOCTL_SET(rtc, 0x7000, 0x70ff); static int -#if __FreeBSD_version >= 500023 linux_ioctl_rtc(struct thread *p, struct linux_ioctl_args *args) -#else -linux_ioctl_rtc(struct proc *p, struct linux_ioctl_args *args) -#endif { switch (args->cmd & 0xffff) { case LINUX_RTC_PIE_ON: args->cmd=RTCIO_PIE_ON; -#if __FreeBSD_version >= 900044 return sys_ioctl(p, (struct ioctl_args*)args); -#else - return ioctl(p, (struct ioctl_args*)args); -#endif case LINUX_RTC_IRQP_SET: args->cmd=RTCIO_IRQP_SET; -#if __FreeBSD_version >= 900044 return sys_ioctl(p, (struct ioctl_args*)args); -#else - return ioctl(p, (struct ioctl_args*)args); -#endif } return (ENOIOCTL); } diff --git a/emulators/rtc/files/test.c b/emulators/rtc/files/test.c index 664441c20663..5e7b3b1b6b47 100644 --- a/emulators/rtc/files/test.c +++ b/emulators/rtc/files/test.c @@ -6,7 +6,7 @@ #include #include -#include "rtc.h" +#include int main(void) @@ -21,7 +21,7 @@ int main(void) rtc = open("/dev/rtc", O_RDONLY); if (rtc<0) { - perror("/dec/rtc"); + perror("/dev/rtc"); return 1; } diff --git a/emulators/rtc/pkg-message b/emulators/rtc/pkg-message new file mode 100644 index 000000000000..14d3cce7f776 --- /dev/null +++ b/emulators/rtc/pkg-message @@ -0,0 +1,19 @@ +[ +{ type: install + message: <