Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / char / mmtimer.c
blobe60a74c66e3dfa05c00eb45596829e77932ce5c1
1 /*
2 * Timer device implementation for SGI SN platforms.
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
8 * Copyright (c) 2001-2006 Silicon Graphics, Inc. All rights reserved.
10 * This driver exports an API that should be supportable by any HPET or IA-PC
11 * multimedia timer. The code below is currently specific to the SGI Altix
12 * SHub RTC, however.
14 * 11/01/01 - jbarnes - initial revision
15 * 9/10/04 - Christoph Lameter - remove interrupt support for kernel inclusion
16 * 10/1/04 - Christoph Lameter - provide posix clock CLOCK_SGI_CYCLE
17 * 10/13/04 - Christoph Lameter, Dimitri Sivanich - provide timer interrupt
18 * support via the posix timer interface
21 #include <linux/types.h>
22 #include <linux/kernel.h>
23 #include <linux/ioctl.h>
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/errno.h>
27 #include <linux/mm.h>
28 #include <linux/fs.h>
29 #include <linux/mmtimer.h>
30 #include <linux/miscdevice.h>
31 #include <linux/posix-timers.h>
32 #include <linux/interrupt.h>
34 #include <asm/uaccess.h>
35 #include <asm/sn/addrs.h>
36 #include <asm/sn/intr.h>
37 #include <asm/sn/shub_mmr.h>
38 #include <asm/sn/nodepda.h>
39 #include <asm/sn/shubio.h>
41 MODULE_AUTHOR("Jesse Barnes <jbarnes@sgi.com>");
42 MODULE_DESCRIPTION("SGI Altix RTC Timer");
43 MODULE_LICENSE("GPL");
45 /* name of the device, usually in /dev */
46 #define MMTIMER_NAME "mmtimer"
47 #define MMTIMER_DESC "SGI Altix RTC Timer"
48 #define MMTIMER_VERSION "2.1"
50 #define RTC_BITS 55 /* 55 bits for this implementation */
52 extern unsigned long sn_rtc_cycles_per_second;
54 #define RTC_COUNTER_ADDR ((long *)LOCAL_MMR_ADDR(SH_RTC))
56 #define rtc_time() (*RTC_COUNTER_ADDR)
58 static int mmtimer_ioctl(struct inode *inode, struct file *file,
59 unsigned int cmd, unsigned long arg);
60 static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma);
63 * Period in femtoseconds (10^-15 s)
65 static unsigned long mmtimer_femtoperiod = 0;
67 static const struct file_operations mmtimer_fops = {
68 .owner = THIS_MODULE,
69 .mmap = mmtimer_mmap,
70 .ioctl = mmtimer_ioctl,
74 * We only have comparison registers RTC1-4 currently available per
75 * node. RTC0 is used by SAL.
77 #define NUM_COMPARATORS 3
78 /* Check for an RTC interrupt pending */
79 static int inline mmtimer_int_pending(int comparator)
81 if (HUB_L((unsigned long *)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED)) &
82 SH_EVENT_OCCURRED_RTC1_INT_MASK << comparator)
83 return 1;
84 else
85 return 0;
87 /* Clear the RTC interrupt pending bit */
88 static void inline mmtimer_clr_int_pending(int comparator)
90 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED_ALIAS),
91 SH_EVENT_OCCURRED_RTC1_INT_MASK << comparator);
94 /* Setup timer on comparator RTC1 */
95 static void inline mmtimer_setup_int_0(u64 expires)
97 u64 val;
99 /* Disable interrupt */
100 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC1_INT_ENABLE), 0UL);
102 /* Initialize comparator value */
103 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPB), -1L);
105 /* Clear pending bit */
106 mmtimer_clr_int_pending(0);
108 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC1_INT_CONFIG_IDX_SHFT) |
109 ((u64)cpu_physical_id(smp_processor_id()) <<
110 SH_RTC1_INT_CONFIG_PID_SHFT);
112 /* Set configuration */
113 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC1_INT_CONFIG), val);
115 /* Enable RTC interrupts */
116 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC1_INT_ENABLE), 1UL);
118 /* Initialize comparator value */
119 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPB), expires);
124 /* Setup timer on comparator RTC2 */
125 static void inline mmtimer_setup_int_1(u64 expires)
127 u64 val;
129 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_ENABLE), 0UL);
131 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPC), -1L);
133 mmtimer_clr_int_pending(1);
135 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC2_INT_CONFIG_IDX_SHFT) |
136 ((u64)cpu_physical_id(smp_processor_id()) <<
137 SH_RTC2_INT_CONFIG_PID_SHFT);
139 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_CONFIG), val);
141 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_ENABLE), 1UL);
143 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPC), expires);
146 /* Setup timer on comparator RTC3 */
147 static void inline mmtimer_setup_int_2(u64 expires)
149 u64 val;
151 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_ENABLE), 0UL);
153 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPD), -1L);
155 mmtimer_clr_int_pending(2);
157 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC3_INT_CONFIG_IDX_SHFT) |
158 ((u64)cpu_physical_id(smp_processor_id()) <<
159 SH_RTC3_INT_CONFIG_PID_SHFT);
161 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_CONFIG), val);
163 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_ENABLE), 1UL);
165 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPD), expires);
169 * This function must be called with interrupts disabled and preemption off
170 * in order to insure that the setup succeeds in a deterministic time frame.
171 * It will check if the interrupt setup succeeded.
173 static int inline mmtimer_setup(int comparator, unsigned long expires)
176 switch (comparator) {
177 case 0:
178 mmtimer_setup_int_0(expires);
179 break;
180 case 1:
181 mmtimer_setup_int_1(expires);
182 break;
183 case 2:
184 mmtimer_setup_int_2(expires);
185 break;
187 /* We might've missed our expiration time */
188 if (rtc_time() < expires)
189 return 1;
192 * If an interrupt is already pending then its okay
193 * if not then we failed
195 return mmtimer_int_pending(comparator);
198 static int inline mmtimer_disable_int(long nasid, int comparator)
200 switch (comparator) {
201 case 0:
202 nasid == -1 ? HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC1_INT_ENABLE),
203 0UL) : REMOTE_HUB_S(nasid, SH_RTC1_INT_ENABLE, 0UL);
204 break;
205 case 1:
206 nasid == -1 ? HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_ENABLE),
207 0UL) : REMOTE_HUB_S(nasid, SH_RTC2_INT_ENABLE, 0UL);
208 break;
209 case 2:
210 nasid == -1 ? HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_ENABLE),
211 0UL) : REMOTE_HUB_S(nasid, SH_RTC3_INT_ENABLE, 0UL);
212 break;
213 default:
214 return -EFAULT;
216 return 0;
219 #define TIMER_OFF 0xbadcabLL
221 /* There is one of these for each comparator */
222 typedef struct mmtimer {
223 spinlock_t lock ____cacheline_aligned;
224 struct k_itimer *timer;
225 int i;
226 int cpu;
227 struct tasklet_struct tasklet;
228 } mmtimer_t;
230 static mmtimer_t ** timers;
233 * mmtimer_ioctl - ioctl interface for /dev/mmtimer
234 * @inode: inode of the device
235 * @file: file structure for the device
236 * @cmd: command to execute
237 * @arg: optional argument to command
239 * Executes the command specified by @cmd. Returns 0 for success, < 0 for
240 * failure.
242 * Valid commands:
244 * %MMTIMER_GETOFFSET - Should return the offset (relative to the start
245 * of the page where the registers are mapped) for the counter in question.
247 * %MMTIMER_GETRES - Returns the resolution of the clock in femto (10^-15)
248 * seconds
250 * %MMTIMER_GETFREQ - Copies the frequency of the clock in Hz to the address
251 * specified by @arg
253 * %MMTIMER_GETBITS - Returns the number of bits in the clock's counter
255 * %MMTIMER_MMAPAVAIL - Returns 1 if the registers can be mmap'd into userspace
257 * %MMTIMER_GETCOUNTER - Gets the current value in the counter and places it
258 * in the address specified by @arg.
260 static int mmtimer_ioctl(struct inode *inode, struct file *file,
261 unsigned int cmd, unsigned long arg)
263 int ret = 0;
265 switch (cmd) {
266 case MMTIMER_GETOFFSET: /* offset of the counter */
268 * SN RTC registers are on their own 64k page
270 if(PAGE_SIZE <= (1 << 16))
271 ret = (((long)RTC_COUNTER_ADDR) & (PAGE_SIZE-1)) / 8;
272 else
273 ret = -ENOSYS;
274 break;
276 case MMTIMER_GETRES: /* resolution of the clock in 10^-15 s */
277 if(copy_to_user((unsigned long __user *)arg,
278 &mmtimer_femtoperiod, sizeof(unsigned long)))
279 return -EFAULT;
280 break;
282 case MMTIMER_GETFREQ: /* frequency in Hz */
283 if(copy_to_user((unsigned long __user *)arg,
284 &sn_rtc_cycles_per_second,
285 sizeof(unsigned long)))
286 return -EFAULT;
287 ret = 0;
288 break;
290 case MMTIMER_GETBITS: /* number of bits in the clock */
291 ret = RTC_BITS;
292 break;
294 case MMTIMER_MMAPAVAIL: /* can we mmap the clock into userspace? */
295 ret = (PAGE_SIZE <= (1 << 16)) ? 1 : 0;
296 break;
298 case MMTIMER_GETCOUNTER:
299 if(copy_to_user((unsigned long __user *)arg,
300 RTC_COUNTER_ADDR, sizeof(unsigned long)))
301 return -EFAULT;
302 break;
303 default:
304 ret = -ENOSYS;
305 break;
308 return ret;
312 * mmtimer_mmap - maps the clock's registers into userspace
313 * @file: file structure for the device
314 * @vma: VMA to map the registers into
316 * Calls remap_pfn_range() to map the clock's registers into
317 * the calling process' address space.
319 static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma)
321 unsigned long mmtimer_addr;
323 if (vma->vm_end - vma->vm_start != PAGE_SIZE)
324 return -EINVAL;
326 if (vma->vm_flags & VM_WRITE)
327 return -EPERM;
329 if (PAGE_SIZE > (1 << 16))
330 return -ENOSYS;
332 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
334 mmtimer_addr = __pa(RTC_COUNTER_ADDR);
335 mmtimer_addr &= ~(PAGE_SIZE - 1);
336 mmtimer_addr &= 0xfffffffffffffffUL;
338 if (remap_pfn_range(vma, vma->vm_start, mmtimer_addr >> PAGE_SHIFT,
339 PAGE_SIZE, vma->vm_page_prot)) {
340 printk(KERN_ERR "remap_pfn_range failed in mmtimer.c\n");
341 return -EAGAIN;
344 return 0;
347 static struct miscdevice mmtimer_miscdev = {
348 SGI_MMTIMER,
349 MMTIMER_NAME,
350 &mmtimer_fops
353 static struct timespec sgi_clock_offset;
354 static int sgi_clock_period;
357 * Posix Timer Interface
360 static struct timespec sgi_clock_offset;
361 static int sgi_clock_period;
363 static int sgi_clock_get(clockid_t clockid, struct timespec *tp)
365 u64 nsec;
367 nsec = rtc_time() * sgi_clock_period
368 + sgi_clock_offset.tv_nsec;
369 tp->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tp->tv_nsec)
370 + sgi_clock_offset.tv_sec;
371 return 0;
374 static int sgi_clock_set(clockid_t clockid, struct timespec *tp)
377 u64 nsec;
378 u64 rem;
380 nsec = rtc_time() * sgi_clock_period;
382 sgi_clock_offset.tv_sec = tp->tv_sec - div_long_long_rem(nsec, NSEC_PER_SEC, &rem);
384 if (rem <= tp->tv_nsec)
385 sgi_clock_offset.tv_nsec = tp->tv_sec - rem;
386 else {
387 sgi_clock_offset.tv_nsec = tp->tv_sec + NSEC_PER_SEC - rem;
388 sgi_clock_offset.tv_sec--;
390 return 0;
394 * Schedule the next periodic interrupt. This function will attempt
395 * to schedule a periodic interrupt later if necessary. If the scheduling
396 * of an interrupt fails then the time to skip is lengthened
397 * exponentially in order to ensure that the next interrupt
398 * can be properly scheduled..
400 static int inline reschedule_periodic_timer(mmtimer_t *x)
402 int n;
403 struct k_itimer *t = x->timer;
405 t->it.mmtimer.clock = x->i;
406 t->it_overrun--;
408 n = 0;
409 do {
411 t->it.mmtimer.expires += t->it.mmtimer.incr << n;
412 t->it_overrun += 1 << n;
413 n++;
414 if (n > 20)
415 return 1;
417 } while (!mmtimer_setup(x->i, t->it.mmtimer.expires));
419 return 0;
423 * mmtimer_interrupt - timer interrupt handler
424 * @irq: irq received
425 * @dev_id: device the irq came from
427 * Called when one of the comarators matches the counter, This
428 * routine will send signals to processes that have requested
429 * them.
431 * This interrupt is run in an interrupt context
432 * by the SHUB. It is therefore safe to locally access SHub
433 * registers.
435 static irqreturn_t
436 mmtimer_interrupt(int irq, void *dev_id)
438 int i;
439 unsigned long expires = 0;
440 int result = IRQ_NONE;
441 unsigned indx = cpu_to_node(smp_processor_id());
444 * Do this once for each comparison register
446 for (i = 0; i < NUM_COMPARATORS; i++) {
447 mmtimer_t *base = timers[indx] + i;
448 /* Make sure this doesn't get reused before tasklet_sched */
449 spin_lock(&base->lock);
450 if (base->cpu == smp_processor_id()) {
451 if (base->timer)
452 expires = base->timer->it.mmtimer.expires;
453 /* expires test won't work with shared irqs */
454 if ((mmtimer_int_pending(i) > 0) ||
455 (expires && (expires < rtc_time()))) {
456 mmtimer_clr_int_pending(i);
457 tasklet_schedule(&base->tasklet);
458 result = IRQ_HANDLED;
461 spin_unlock(&base->lock);
462 expires = 0;
464 return result;
467 void mmtimer_tasklet(unsigned long data) {
468 mmtimer_t *x = (mmtimer_t *)data;
469 struct k_itimer *t = x->timer;
470 unsigned long flags;
472 if (t == NULL)
473 return;
475 /* Send signal and deal with periodic signals */
476 spin_lock_irqsave(&t->it_lock, flags);
477 spin_lock(&x->lock);
478 /* If timer was deleted between interrupt and here, leave */
479 if (t != x->timer)
480 goto out;
481 t->it_overrun = 0;
483 if (posix_timer_event(t, 0) != 0) {
485 // printk(KERN_WARNING "mmtimer: cannot deliver signal.\n");
487 t->it_overrun++;
489 if(t->it.mmtimer.incr) {
490 /* Periodic timer */
491 if (reschedule_periodic_timer(x)) {
492 printk(KERN_WARNING "mmtimer: unable to reschedule\n");
493 x->timer = NULL;
495 } else {
496 /* Ensure we don't false trigger in mmtimer_interrupt */
497 t->it.mmtimer.expires = 0;
499 t->it_overrun_last = t->it_overrun;
500 out:
501 spin_unlock(&x->lock);
502 spin_unlock_irqrestore(&t->it_lock, flags);
505 static int sgi_timer_create(struct k_itimer *timer)
507 /* Insure that a newly created timer is off */
508 timer->it.mmtimer.clock = TIMER_OFF;
509 return 0;
512 /* This does not really delete a timer. It just insures
513 * that the timer is not active
515 * Assumption: it_lock is already held with irq's disabled
517 static int sgi_timer_del(struct k_itimer *timr)
519 int i = timr->it.mmtimer.clock;
520 cnodeid_t nodeid = timr->it.mmtimer.node;
521 mmtimer_t *t = timers[nodeid] + i;
522 unsigned long irqflags;
524 if (i != TIMER_OFF) {
525 spin_lock_irqsave(&t->lock, irqflags);
526 mmtimer_disable_int(cnodeid_to_nasid(nodeid),i);
527 t->timer = NULL;
528 timr->it.mmtimer.clock = TIMER_OFF;
529 timr->it.mmtimer.expires = 0;
530 spin_unlock_irqrestore(&t->lock, irqflags);
532 return 0;
535 #define timespec_to_ns(x) ((x).tv_nsec + (x).tv_sec * NSEC_PER_SEC)
536 #define ns_to_timespec(ts, nsec) (ts).tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &(ts).tv_nsec)
538 /* Assumption: it_lock is already held with irq's disabled */
539 static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
542 if (timr->it.mmtimer.clock == TIMER_OFF) {
543 cur_setting->it_interval.tv_nsec = 0;
544 cur_setting->it_interval.tv_sec = 0;
545 cur_setting->it_value.tv_nsec = 0;
546 cur_setting->it_value.tv_sec =0;
547 return;
550 ns_to_timespec(cur_setting->it_interval, timr->it.mmtimer.incr * sgi_clock_period);
551 ns_to_timespec(cur_setting->it_value, (timr->it.mmtimer.expires - rtc_time())* sgi_clock_period);
552 return;
556 static int sgi_timer_set(struct k_itimer *timr, int flags,
557 struct itimerspec * new_setting,
558 struct itimerspec * old_setting)
561 int i;
562 unsigned long when, period, irqflags;
563 int err = 0;
564 cnodeid_t nodeid;
565 mmtimer_t *base;
567 if (old_setting)
568 sgi_timer_get(timr, old_setting);
570 sgi_timer_del(timr);
571 when = timespec_to_ns(new_setting->it_value);
572 period = timespec_to_ns(new_setting->it_interval);
574 if (when == 0)
575 /* Clear timer */
576 return 0;
578 if (flags & TIMER_ABSTIME) {
579 struct timespec n;
580 unsigned long now;
582 getnstimeofday(&n);
583 now = timespec_to_ns(n);
584 if (when > now)
585 when -= now;
586 else
587 /* Fire the timer immediately */
588 when = 0;
592 * Convert to sgi clock period. Need to keep rtc_time() as near as possible
593 * to getnstimeofday() in order to be as faithful as possible to the time
594 * specified.
596 when = (when + sgi_clock_period - 1) / sgi_clock_period + rtc_time();
597 period = (period + sgi_clock_period - 1) / sgi_clock_period;
600 * We are allocating a local SHub comparator. If we would be moved to another
601 * cpu then another SHub may be local to us. Prohibit that by switching off
602 * preemption.
604 preempt_disable();
606 nodeid = cpu_to_node(smp_processor_id());
607 retry:
608 /* Don't use an allocated timer, or a deleted one that's pending */
609 for(i = 0; i< NUM_COMPARATORS; i++) {
610 base = timers[nodeid] + i;
611 if (!base->timer && !base->tasklet.state) {
612 break;
616 if (i == NUM_COMPARATORS) {
617 preempt_enable();
618 return -EBUSY;
621 spin_lock_irqsave(&base->lock, irqflags);
623 if (base->timer || base->tasklet.state != 0) {
624 spin_unlock_irqrestore(&base->lock, irqflags);
625 goto retry;
627 base->timer = timr;
628 base->cpu = smp_processor_id();
630 timr->it.mmtimer.clock = i;
631 timr->it.mmtimer.node = nodeid;
632 timr->it.mmtimer.incr = period;
633 timr->it.mmtimer.expires = when;
635 if (period == 0) {
636 if (!mmtimer_setup(i, when)) {
637 mmtimer_disable_int(-1, i);
638 posix_timer_event(timr, 0);
639 timr->it.mmtimer.expires = 0;
641 } else {
642 timr->it.mmtimer.expires -= period;
643 if (reschedule_periodic_timer(base))
644 err = -EINVAL;
647 spin_unlock_irqrestore(&base->lock, irqflags);
649 preempt_enable();
651 return err;
654 static struct k_clock sgi_clock = {
655 .res = 0,
656 .clock_set = sgi_clock_set,
657 .clock_get = sgi_clock_get,
658 .timer_create = sgi_timer_create,
659 .nsleep = do_posix_clock_nonanosleep,
660 .timer_set = sgi_timer_set,
661 .timer_del = sgi_timer_del,
662 .timer_get = sgi_timer_get
666 * mmtimer_init - device initialization routine
668 * Does initial setup for the mmtimer device.
670 static int __init mmtimer_init(void)
672 unsigned i;
673 cnodeid_t node, maxn = -1;
675 if (!ia64_platform_is("sn2"))
676 return 0;
679 * Sanity check the cycles/sec variable
681 if (sn_rtc_cycles_per_second < 100000) {
682 printk(KERN_ERR "%s: unable to determine clock frequency\n",
683 MMTIMER_NAME);
684 goto out1;
687 mmtimer_femtoperiod = ((unsigned long)1E15 + sn_rtc_cycles_per_second /
688 2) / sn_rtc_cycles_per_second;
690 if (request_irq(SGI_MMTIMER_VECTOR, mmtimer_interrupt, IRQF_PERCPU, MMTIMER_NAME, NULL)) {
691 printk(KERN_WARNING "%s: unable to allocate interrupt.",
692 MMTIMER_NAME);
693 goto out1;
696 if (misc_register(&mmtimer_miscdev)) {
697 printk(KERN_ERR "%s: failed to register device\n",
698 MMTIMER_NAME);
699 goto out2;
702 /* Get max numbered node, calculate slots needed */
703 for_each_online_node(node) {
704 maxn = node;
706 maxn++;
708 /* Allocate list of node ptrs to mmtimer_t's */
709 timers = kzalloc(sizeof(mmtimer_t *)*maxn, GFP_KERNEL);
710 if (timers == NULL) {
711 printk(KERN_ERR "%s: failed to allocate memory for device\n",
712 MMTIMER_NAME);
713 goto out3;
716 /* Allocate mmtimer_t's for each online node */
717 for_each_online_node(node) {
718 timers[node] = kmalloc_node(sizeof(mmtimer_t)*NUM_COMPARATORS, GFP_KERNEL, node);
719 if (timers[node] == NULL) {
720 printk(KERN_ERR "%s: failed to allocate memory for device\n",
721 MMTIMER_NAME);
722 goto out4;
724 for (i=0; i< NUM_COMPARATORS; i++) {
725 mmtimer_t * base = timers[node] + i;
727 spin_lock_init(&base->lock);
728 base->timer = NULL;
729 base->cpu = 0;
730 base->i = i;
731 tasklet_init(&base->tasklet, mmtimer_tasklet,
732 (unsigned long) (base));
736 sgi_clock_period = sgi_clock.res = NSEC_PER_SEC / sn_rtc_cycles_per_second;
737 register_posix_clock(CLOCK_SGI_CYCLE, &sgi_clock);
739 printk(KERN_INFO "%s: v%s, %ld MHz\n", MMTIMER_DESC, MMTIMER_VERSION,
740 sn_rtc_cycles_per_second/(unsigned long)1E6);
742 return 0;
744 out4:
745 for_each_online_node(node) {
746 kfree(timers[node]);
748 out3:
749 misc_deregister(&mmtimer_miscdev);
750 out2:
751 free_irq(SGI_MMTIMER_VECTOR, NULL);
752 out1:
753 return -1;
756 module_init(mmtimer_init);