emulators/rtc: update 2004.02.24.1 -> 2020.07.07.1
- submitter becomes maintainer - Install kmod into /boot/modules instead of /usr/local - Cleared out bits dating back to pre-devfs - Removed #ifdef bits related to FreeBSD <= 4.X and FreeBSD <= 8.X - Olegs fixes for FreeBSD 11.X and FreeBSD 12.X+ - Removed "USES= linux uidfix" - whilst this provides functionality that is "often" used by linux programs, that's not necessarily the case, and this module doesn't require any linux subsystem or kernel MOD to operate. - Removed oldstyle rtc.sh - include pkg-message showing how to load from the rc.conf "kld_list" mechanism. - Fixed typo in "test.c" -> /dec -> /dev - Fixed path to "rtc.h" in "test.c" PR: 233057 Submitted by: Jamie Landeg-Jones <jamie@catflap.org>
This commit is contained in:
parent
fe0a40a484
commit
75ce806e1e
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=547249
@ -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 <bsd.port.mk>
|
||||
|
@ -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 <bsd.kmod.mk>
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
@ -35,11 +35,7 @@
|
||||
|
||||
#include <i386/linux/linux.h>
|
||||
#include <i386/linux/linux_proto.h>
|
||||
#if __FreeBSD_version >= 500012 || __FreeBSD_version >= 430000
|
||||
#include <compat/linux/linux_ioctl.h>
|
||||
#else
|
||||
#include <i386/linux/linux_ioctl.h>
|
||||
#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);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/ioccom.h>
|
||||
|
||||
#include "rtc.h"
|
||||
#include <rtc.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
19
emulators/rtc/pkg-message
Normal file
19
emulators/rtc/pkg-message
Normal file
@ -0,0 +1,19 @@
|
||||
[
|
||||
{ type: install
|
||||
message: <<EOM
|
||||
This module can be enabled with:
|
||||
|
||||
# kldload rtc
|
||||
|
||||
and disabled with:
|
||||
|
||||
# kldunload rtc
|
||||
|
||||
For it to be loaded automatically at boottime, add "rtc" to your
|
||||
kld_list entry in /etc/rc.conf . One way to do this is with the
|
||||
one-off command:
|
||||
|
||||
# sysrc kld_list+="rtc"
|
||||
EOM
|
||||
}
|
||||
]
|
@ -1,6 +1,3 @@
|
||||
etc/rc.d/rtc.sh
|
||||
include/rtc.h
|
||||
modules/rtc.ko
|
||||
/%%KMODDIR%%/rtc.ko
|
||||
%%EXAMPLESDIR%%/test.c
|
||||
@postexec rm -f %%DEVDIR%%/rtc
|
||||
@postunexec rm -f /dev/rtc
|
||||
|
Loading…
Reference in New Issue
Block a user