sead_time.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Carsten Langgaard, carstenl@mips.com
  3.  * Copyright (C) 2002 MIPS Technologies, Inc.  All rights reserved.
  4.  *
  5.  * ########################################################################
  6.  *
  7.  *  This program is free software; you can distribute it and/or modify it
  8.  *  under the terms of the GNU General Public License (Version 2) as
  9.  *  published by the Free Software Foundation.
  10.  *
  11.  *  This program is distributed in the hope it will be useful, but WITHOUT
  12.  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13.  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14.  *  for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License along
  17.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  18.  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  19.  *
  20.  * ########################################################################
  21.  *
  22.  * Setting up the clock on the MIPS boards.
  23.  *
  24.  */
  25. #include <linux/config.h>
  26. #include <linux/init.h>
  27. #include <linux/kernel_stat.h>
  28. #include <linux/sched.h>
  29. #include <linux/spinlock.h>
  30. #include <asm/mipsregs.h>
  31. #include <asm/ptrace.h>
  32. #include <asm/hardirq.h>
  33. #include <asm/cpu.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/timex.h>
  36. #include <asm/mips-boards/generic.h>
  37. #include <asm/mips-boards/prom.h>
  38. extern volatile unsigned long wall_jiffies;
  39. static unsigned long r4k_offset; /* Amount to increment compare reg each time */
  40. static unsigned long r4k_cur;    /* What counter should be at next timer irq */
  41. extern rwlock_t xtime_lock;
  42. #define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ5)
  43. static char display_string[] = "        LINUX ON SEAD       ";
  44. static unsigned int display_count = 0;
  45. #define MAX_DISPLAY_COUNT (sizeof(display_string) - 8)
  46. #define MIPS_CPU_TIMER_IRQ 7
  47. static unsigned int timer_tick_count=0;
  48. static inline void ack_r4ktimer(unsigned long newval)
  49. {
  50. write_32bit_cp0_register(CP0_COMPARE, newval);
  51. }
  52. /*
  53.  * There are a lot of conceptually broken versions of the MIPS timer interrupt
  54.  * handler floating around.  This one is rather different, but the algorithm
  55.  * is provably more robust.
  56.  */
  57. void mips_timer_interrupt(struct pt_regs *regs)
  58. {
  59. int cpu = smp_processor_id();
  60. int irq = MIPS_CPU_TIMER_IRQ;
  61. irq_enter(cpu, irq);
  62. do {
  63. kstat.irqs[cpu][irq]++;
  64. do_timer(regs);
  65. if ((timer_tick_count++ % HZ) == 0) {
  66.     mips_display_message(&display_string[display_count++]);
  67.     if (display_count == MAX_DISPLAY_COUNT)
  68.         display_count = 0;
  69. }
  70. r4k_cur += r4k_offset;
  71. ack_r4ktimer(r4k_cur);
  72. } while (((unsigned long)read_32bit_cp0_register(CP0_COUNT)
  73.          - r4k_cur) < 0x7fffffff);
  74. irq_exit(cpu, irq);
  75. if (softirq_pending(cpu))
  76. do_softirq();
  77. }
  78. /*
  79.  * Figure out the r4k offset, the amount to increment the compare
  80.  * register for each time tick.
  81.  */
  82. static unsigned long __init cal_r4koff(void)
  83. {
  84. /*
  85.  * The SEAD board doesn't have a real time clock, so we can't
  86.  * really calculate the timer offset.
  87.  * For now we hardwire the SEAD board frequency to 12MHz.
  88.  */
  89. return(6000000/HZ);
  90. }
  91. void __init mips_time_init(void)
  92. {
  93.         unsigned int est_freq, flags;
  94. __save_and_cli(flags);
  95.         /* Start r4k counter. */
  96.         write_32bit_cp0_register(CP0_COUNT, 0);
  97. printk("calculating r4koff... ");
  98. r4k_offset = cal_r4koff();
  99. printk("%08lx(%d)n", r4k_offset, (int) r4k_offset);
  100.         if ((read_32bit_cp0_register(CP0_PRID) & 0xffff00) ==
  101.     (PRID_COMP_MIPS | PRID_IMP_20KC))
  102. est_freq = r4k_offset*HZ;
  103. else
  104. est_freq = 2*r4k_offset*HZ;
  105. est_freq += 5000;    /* round */
  106. est_freq -= est_freq%10000;
  107. printk("CPU frequency %d.%02d MHzn", est_freq/1000000,
  108.        (est_freq%1000000)*100/1000000);
  109. __restore_flags(flags);
  110. }
  111. void __init mips_timer_setup(struct irqaction *irq)
  112. {
  113. /* we are using the cpu counter for timer interrupts */
  114. irq->handler = no_action;     /* we use our own handler */
  115. setup_irq(MIPS_CPU_TIMER_IRQ, irq);
  116.         /* to generate the first timer interrupt */
  117. r4k_cur = (read_32bit_cp0_register(CP0_COUNT) + r4k_offset);
  118. write_32bit_cp0_register(CP0_COMPARE, r4k_cur);
  119. set_cp0_status(ALLINTS);
  120. }