From efff149988e6b71416abbe1f8c692a2cc27989f1 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 11 Feb 2011 17:43:56 +0100 Subject: [PATCH] Use system headers for Linux RTC support --- configure | 14 +++++++--- io_linux.h | 75 ----------------------------------------------------- rtc_linux.c | 16 ++---------- 3 files changed, 12 insertions(+), 93 deletions(-) delete mode 100644 io_linux.h diff --git a/configure b/configure index 718c13d..8fe84b3 100755 --- a/configure +++ b/configure @@ -152,6 +152,7 @@ feat_readline=1 try_readline=1 try_editline=1 feat_rtc=1 +try_rtc=0 feat_linuxcaps=1 try_linuxcaps=0 readline_lib="" @@ -269,11 +270,8 @@ case $SYSTEM in ;; Linux* ) EXTRA_OBJECTS="sys_linux.o wrap_adjtimex.o" - if [ $feat_rtc -eq 1 ] ; then - EXTRA_OBJECTS="$EXTRA_OBJECTS rtc_linux.o" - EXTRA_DEFS="$EXTRA_DEFS -DFEAT_RTC=1" - fi try_linuxcaps=1 + try_rtc=1 try_setsched=1 try_lockmem=1 SYSDEFS="-DLINUX" @@ -371,6 +369,14 @@ then EXTRA_LIBS="-lcap" fi +if [ $feat_rtc = "1" ] && [ $try_rtc = "1" ] && \ + test_code '' 'sys/ioctl.h linux/rtc.h' '' '' \ + 'ioctl(1, RTC_UIE_ON&RTC_UIE_OFF&RTC_RD_TIME&RTC_SET_TIME, 0&RTC_UF);' +then + EXTRA_OBJECTS="$EXTRA_OBJECTS rtc_linux.o" + EXTRA_DEFS="$EXTRA_DEFS -DFEAT_RTC=1" +fi + if [ $try_setsched = "1" ] && \ test_code \ 'sched_setscheduler()' \ diff --git a/io_linux.h b/io_linux.h deleted file mode 100644 index 2c3b03c..0000000 --- a/io_linux.h +++ /dev/null @@ -1,75 +0,0 @@ -/* Taken from in the Linux kernel sources. - * The ioctl.h file is pretty similar from one architecture to another. - * */ -#ifndef IO_LINUX_H -#define IO_LINUX_H - -/* Hmm. These constants vary a bit between systems. */ -/* (__sh__ includes both sh and sh64) */ -/* (__s390__ includes both s390 and s390x) */ -#if defined(__i386__) || defined(__sh__) || defined(__arm__) || defined(__x86_64__) || defined(__s390__) -#define CHRONY_IOC_NRBITS 8 -#define CHRONY_IOC_TYPEBITS 8 -#define CHRONY_IOC_SIZEBITS 14 -#define CHRONY_IOC_DIRBITS 2 - -#define CHRONY_IOC_NONE 0U -#define CHRONY_IOC_WRITE 1U -#define CHRONY_IOC_READ 2U - -#elif defined(__alpha__) || defined(__sparc__) || defined(__ppc__) || defined(__ppc64__) || defined(__sparc64__) -#define CHRONY_IOC_NRBITS 8 -#define CHRONY_IOC_TYPEBITS 8 -#define CHRONY_IOC_SIZEBITS 13 -#define CHRONY_IOC_DIRBITS 2 - -#define CHRONY_IOC_NONE 1U -#define CHRONY_IOC_READ 2U -#define CHRONY_IOC_WRITE 4U - -#elif defined(__mips__) || defined(__mips32__) || defined(__powerpc__) -#define CHRONY_IOC_NRBITS 8 -#define CHRONY_IOC_TYPEBITS 8 -#define CHRONY_IOC_SIZEBITS 13 -#define CHRONY_IOC_DIRBITS 3 -#define CHRONY_IOC_NONE 1U -#define CHRONY_IOC_READ 2U -#define CHRONY_IOC_WRITE 4U - -#else -#error "I don't know the values of the _IOC_* constants for your architecture" -#endif - -#define CHRONY_IOC_NRMASK ((1 << CHRONY_IOC_NRBITS)-1) -#define CHRONY_IOC_TYPEMASK ((1 << CHRONY_IOC_TYPEBITS)-1) -#define CHRONY_IOC_SIZEMASK ((1 << CHRONY_IOC_SIZEBITS)-1) -#define CHRONY_IOC_DIRMASK ((1 << CHRONY_IOC_DIRBITS)-1) - -#define CHRONY_IOC_NRSHIFT 0 -#define CHRONY_IOC_TYPESHIFT (CHRONY_IOC_NRSHIFT+CHRONY_IOC_NRBITS) -#define CHRONY_IOC_SIZESHIFT (CHRONY_IOC_TYPESHIFT+CHRONY_IOC_TYPEBITS) -#define CHRONY_IOC_DIRSHIFT (CHRONY_IOC_SIZESHIFT+CHRONY_IOC_SIZEBITS) - -#define CHRONY_IOC(dir,type,nr,size) \ - (((dir) << CHRONY_IOC_DIRSHIFT) | \ - ((type) << CHRONY_IOC_TYPESHIFT) | \ - ((nr) << CHRONY_IOC_NRSHIFT) | \ - ((size) << CHRONY_IOC_SIZESHIFT)) - -/* used to create numbers */ -#define CHRONY_IO(type,nr) CHRONY_IOC(CHRONY_IOC_NONE,(type),(nr),0) -#define CHRONY_IOR(type,nr,size) CHRONY_IOC(CHRONY_IOC_READ,(type),(nr),sizeof(size)) -#define CHRONY_IOW(type,nr,size) CHRONY_IOC(CHRONY_IOC_WRITE,(type),(nr),sizeof(size)) -#define CHRONY_IOWR(type,nr,size) CHRONY_IOC(CHRONY_IOC_READ|CHRONY_IOC_WRITE,(type),(nr),sizeof(size)) - -#define RTC_UIE_ON CHRONY_IO('p', 0x03) /* Update int. enable on */ -#define RTC_UIE_OFF CHRONY_IO('p', 0x04) /* ... off */ - -#define RTC_RD_TIME CHRONY_IOR('p', 0x09, struct rtc_time) /* Read RTC time */ -#define RTC_SET_TIME CHRONY_IOW('p', 0x0a, struct rtc_time) /* Set RTC time */ - -/* From mc146818.h */ -#define RTC_UIE 0x10 /* update-finished interrupt enable */ - -#endif - diff --git a/rtc_linux.c b/rtc_linux.c index fd6db27..c3a6f08 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "logging.h" #include "sched.h" @@ -54,22 +55,9 @@ #include "regress.h" #include "rtc.h" #include "rtc_linux.h" -#include "io_linux.h" #include "conf.h" #include "memory.h" -struct rtc_time { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; -}; - /* ================================================== */ /* Forward prototypes */ @@ -846,7 +834,7 @@ read_from_device(void *any) return; } - if ((data & RTC_UIE) == RTC_UIE) { + if ((data & RTC_UF) == RTC_UF) { /* Update interrupt detected */ /* Read RTC time, sandwiched between two polls of the system clock