From: Neil Horman <nhorman@tuxdriver.com>
To: Jim Gettys <jg@laptop.org>
Cc: linux-kernel@vger.kernel.org, a.zummo@towertech.it,
jg@freedesktop.org, Keith Packard <keithp@keithp.com>
Subject: Re: [PATCH] RTC: Add mmap method to rtc character driver
Date: Tue, 25 Jul 2006 14:17:33 -0400 [thread overview]
Message-ID: <20060725181733.GC4608@hmsreliant.homelinux.net> (raw)
In-Reply-To: <1153850431.5872.104.camel@localhost.localdomain>
On Tue, Jul 25, 2006 at 02:00:31PM -0400, Jim Gettys wrote:
> Actually, it was Keith Packard who asked for this (and we've asked for
> it before in the past).
>
> I will note, that if my memory serves me right, the first X driver we
> ever did (1984) had this feature.
>
> Regards,
> - Jim
>
> ("X is an exercise in avoiding system calls.")
>
> P.S. my name is spelled "Gettys".
>
Sorry, my bad (fat fingers).
Neil
>
> On Tue, 2006-07-25 at 13:41 -0400, Neil Horman wrote:
> > Hey-
> > At OLS last week, During Dave Jones Userspace Sucks presentation, Jim
> > Geddys and some of the Xorg guys noted that they would be able to stop using gettimeofday
> > so frequently, if they had some other way to get a millisecond resolution timer
> > in userspace, one that they could perhaps read from a memory mapped page. I was
> > right behind them and though that seemed like a reasonable request, so I've
> > taken a stab at it. This patch allows for a page to be mmaped from /dev/rtc
> > character interface, the first 4 bytes of which provide a regularly increasing
> > count, once every rtc interrupt. The frequency is of course controlled by the
> > regular ioctls provided by the rtc driver. I've done some basic testing on it,
> > and it seems to work well.
> >
> > Thanks And Regards
> > Neil
> >
> > Signed-off-by: Neil Horman
> >
> >
> >
> > rtc.c | 41 ++++++++++++++++++++++++++++++++++++++++-
> > 1 files changed, 40 insertions(+), 1 deletion(-)
> >
> >
> > diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
> > index 6e6a7c7..4ed673e 100644
> > --- a/drivers/char/rtc.c
> > +++ b/drivers/char/rtc.c
> > @@ -48,9 +48,10 @@
> > * CONFIG_HPET_EMULATE_RTC
> > * 1.12a Maciej W. Rozycki: Handle memory-mapped chips properly.
> > * 1.12ac Alan Cox: Allow read access to the day of week register
> > + * 1.12b Neil Horman: Allow memory mapping of /dev/rtc
> > */
> >
> > -#define RTC_VERSION "1.12ac"
> > +#define RTC_VERSION "1.12b"
> >
> > /*
> > * Note that *all* calls to CMOS_READ and CMOS_WRITE are done with
> > @@ -183,6 +184,8 @@ static int rtc_proc_open(struct inode *i
> > */
> > static unsigned long rtc_status = 0; /* bitmapped status byte. */
> > static unsigned long rtc_freq = 0; /* Current periodic IRQ rate */
> > +#define BUF_SIZE (PAGE_SIZE/sizeof(unsigned long))
> > +static unsigned long rtc_irq_buf[BUF_SIZE] __attribute__ ((aligned (PAGE_SIZE)));
> > static unsigned long rtc_irq_data = 0; /* our output to the world */
> > static unsigned long rtc_max_user_freq = 64; /* > this, need CAP_SYS_RESOURCE */
> >
> > @@ -230,6 +233,7 @@ static inline unsigned char rtc_is_updat
> >
> > irqreturn_t rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
> > {
> > + unsigned long *count_ptr = (unsigned long *)rtc_irq_buf;
> > /*
> > * Can be an alarm interrupt, update complete interrupt,
> > * or a periodic interrupt. We store the status in the
> > @@ -265,6 +269,7 @@ irqreturn_t rtc_interrupt(int irq, void
> >
> > kill_fasync (&rtc_async_queue, SIGIO, POLL_IN);
> >
> > + *count_ptr = (*count_ptr)++;
> > return IRQ_HANDLED;
> > }
> > #endif
> > @@ -389,6 +394,37 @@ static ssize_t rtc_read(struct file *fil
> > #endif
> > }
> >
> > +static int rtc_mmap(struct file *file, struct vm_area_struct *vma)
> > +{
> > + unsigned long rtc_addr;
> > + unsigned long *count_ptr = rtc_irq_buf;
> > +
> > + if (vma->vm_end - vma->vm_start != PAGE_SIZE)
> > + return -EINVAL;
> > +
> > + if (vma->vm_flags & VM_WRITE)
> > + return -EPERM;
> > +
> > + if (PAGE_SIZE > (1 << 16))
> > + return -ENOSYS;
> > +
> > + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> > +
> > + rtc_addr = __pa(rtc_irq_buf);
> > + rtc_addr &= ~(PAGE_SIZE - 1);
> > + rtc_addr &= -1;
> > +
> > + if (remap_pfn_range(vma, vma->vm_start, rtc_addr >> PAGE_SHIFT,
> > + PAGE_SIZE, vma->vm_page_prot)) {
> > + printk(KERN_ERR "remap_pfn_range failed in rtc.c\n");
> > + return -EAGAIN;
> > + }
> > +
> > + *count_ptr = 0;
> > + return 0;
> > +
> > +}
> > +
> > static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
> > {
> > struct rtc_time wtime;
> > @@ -890,6 +926,7 @@ static const struct file_operations rtc_
> > .owner = THIS_MODULE,
> > .llseek = no_llseek,
> > .read = rtc_read,
> > + .mmap = rtc_mmap,
> > #ifdef RTC_IRQ
> > .poll = rtc_poll,
> > #endif
> > @@ -1082,6 +1119,8 @@ no_irq:
> > no_irq2:
> > #endif
> >
> > + memset(rtc_irq_buf,0,PAGE_SIZE);
> > +
> > (void) init_sysctl();
> >
> > printk(KERN_INFO "Real Time Clock Driver v" RTC_VERSION "\n");
> --
> Jim Gettys
> One Laptop Per Child
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
/***************************************************
*Neil Horman
*Software Engineer
*gpg keyid: 1024D / 0x92A74FA1 - http://pgp.mit.edu
***************************************************/
next prev parent reply other threads:[~2006-07-25 18:18 UTC|newest]
Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-25 17:41 Neil Horman
2006-07-25 17:55 ` Arjan van de Ven
2006-07-25 18:01 ` Jim Gettys
2006-07-25 18:22 ` Neil Horman
2006-07-25 18:32 ` Arjan van de Ven
2006-07-25 18:43 ` Neil Horman
2006-07-25 18:53 ` Arjan van de Ven
2006-07-25 19:03 ` Neil Horman
2006-07-25 19:06 ` Arjan van de Ven
2006-07-25 19:07 ` John W. Linville
2006-07-25 19:16 ` Arjan van de Ven
2006-07-25 19:08 ` H. Peter Anvin
2006-07-25 17:57 ` Segher Boessenkool
2006-07-25 18:28 ` Neil Horman
2006-07-25 18:56 ` Segher Boessenkool
2006-07-25 19:07 ` Neil Horman
2006-07-25 19:10 ` H. Peter Anvin
2006-07-25 19:21 ` Neil Horman
2006-07-25 19:31 ` Segher Boessenkool
2006-07-25 19:47 ` Neil Horman
2006-07-25 20:04 ` Dave Airlie
2006-07-25 20:24 ` H. Peter Anvin
2006-07-25 20:47 ` Neil Horman
2006-07-25 20:50 ` H. Peter Anvin
2006-07-25 22:25 ` Neil Horman
2006-07-25 22:33 ` H. Peter Anvin
2006-07-25 23:10 ` Neil Horman
2006-07-25 23:22 ` H. Peter Anvin
2006-07-26 0:03 ` Neil Horman
2006-07-25 23:29 ` David Lang
2006-07-26 0:18 ` Neil Horman
2006-07-25 23:29 ` Segher Boessenkool
2006-07-25 23:56 ` Neil Horman
2006-07-26 0:02 ` H. Peter Anvin
2006-07-26 0:20 ` Neil Horman
2006-07-26 0:36 ` H. Peter Anvin
2006-07-26 14:45 ` A better interface, perhaps: a timed signal flag Theodore Tso
2006-07-28 13:33 ` Steven Rostedt
2006-07-28 14:52 ` Theodore Tso
2006-07-28 15:05 ` Steven Rostedt
2006-07-28 16:41 ` Alan Cox
2006-07-28 16:44 ` Steven Rostedt
2006-07-28 20:01 ` Alan Cox
2006-07-28 20:12 ` Steven Rostedt
2006-07-28 20:36 ` Alan Cox
2006-07-28 20:31 ` Steven Rostedt
2006-07-28 17:11 ` H. Peter Anvin
2006-07-25 20:58 ` [PATCH] RTC: Add mmap method to rtc character driver Jim Gettys
2006-07-25 21:04 ` H. Peter Anvin
2006-07-25 21:14 ` Jim Gettys
2006-07-25 21:18 ` H. Peter Anvin
2006-07-25 21:39 ` Jim Gettys
2006-07-29 4:28 ` Bill Huey
2006-07-29 12:54 ` Neil Horman
2006-07-29 20:41 ` Bill Huey
2006-07-29 21:43 ` Neil Horman
2006-07-29 22:45 ` Keith Packard
2006-07-29 23:18 ` Edgar Toernig
2006-07-29 21:49 ` Edgar Toernig
2006-07-29 22:51 ` itimer again (Re: [PATCH] RTC: Add mmap method to rtc character driver) Bill Huey
2006-07-29 23:35 ` Nicholas Miell
2006-07-30 1:00 ` Bill Huey
2006-07-30 1:22 ` Nicholas Miell
2006-07-30 1:39 ` Bill Huey
2006-07-30 2:02 ` Nicholas Miell
2006-07-30 14:33 ` Theodore Tso
2006-07-30 22:20 ` Bill Huey
2006-07-31 15:40 ` Theodore Tso
2006-07-30 0:16 ` Edgar Toernig
2006-07-30 0:24 ` Bill Huey
2006-07-29 14:02 ` [PATCH] RTC: Add mmap method to rtc character driver Thomas Gleixner
2006-07-26 13:17 ` Martin J. Bligh
2006-08-02 3:54 ` john stultz
2006-08-02 4:26 ` H. Peter Anvin
2006-08-02 4:34 ` john stultz
2006-07-25 23:26 ` Segher Boessenkool
2006-07-26 0:10 ` Neil Horman
2006-07-25 20:03 ` Paul Mackerras
2006-07-25 23:27 ` Segher Boessenkool
2006-07-26 0:06 ` Neil Horman
2006-07-25 18:00 ` Jim Gettys
2006-07-25 18:17 ` Neil Horman [this message]
2006-07-26 15:16 ` Andi Kleen
2006-07-26 17:25 ` Jim Gettys
2006-07-27 23:53 ` Paul Mackerras
2006-07-28 3:29 ` Jim Gettys
2006-07-28 11:59 ` Neil Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060725181733.GC4608@hmsreliant.homelinux.net \
--to=nhorman@tuxdriver.com \
--cc=a.zummo@towertech.it \
--cc=jg@freedesktop.org \
--cc=jg@laptop.org \
--cc=keithp@keithp.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®