time.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /*
  2. * linux/arch/x86-64/kernel/time.c
  3. *
  4. * "High Precision Event Timer" based timekeeping.
  5. *
  6. * Copyright (c) 1991,1992,1995 Linus Torvalds
  7. * Copyright (c) 1994 Alan Modra
  8. * Copyright (c) 1995 Markus Kuhn
  9. * Copyright (c) 1996 Ingo Molnar
  10. * Copyright (c) 1998 Andrea Arcangeli
  11. * Copyright (c) 2002 Vojtech Pavlik
  12. * Copyright (c) 2003 Andi Kleen
  13. * RTC support code taken from arch/i386/kernel/timers/time_hpet.c
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/sched.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/init.h>
  19. #include <linux/mc146818rtc.h>
  20. #include <linux/irq.h>
  21. #include <linux/time.h>
  22. #include <linux/ioport.h>
  23. #include <linux/module.h>
  24. #include <linux/device.h>
  25. #include <linux/sysdev.h>
  26. #include <linux/bcd.h>
  27. #include <linux/kallsyms.h>
  28. #include <linux/acpi.h>
  29. #ifdef CONFIG_ACPI
  30. #include <acpi/achware.h> /* for PM timer frequency */
  31. #endif
  32. #include <asm/8253pit.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/vsyscall.h>
  35. #include <asm/timex.h>
  36. #include <asm/proto.h>
  37. #include <asm/hpet.h>
  38. #include <asm/sections.h>
  39. #include <linux/cpufreq.h>
  40. #include <linux/hpet.h>
  41. #ifdef CONFIG_X86_LOCAL_APIC
  42. #include <asm/apic.h>
  43. #endif
  44. u64 jiffies_64 = INITIAL_JIFFIES;
  45. EXPORT_SYMBOL(jiffies_64);
  46. #ifdef CONFIG_CPU_FREQ
  47. static void cpufreq_delayed_get(void);
  48. #endif
  49. extern void i8254_timer_resume(void);
  50. extern int using_apic_timer;
  51. DEFINE_SPINLOCK(rtc_lock);
  52. DEFINE_SPINLOCK(i8253_lock);
  53. static int nohpet __initdata = 0;
  54. static int notsc __initdata = 0;
  55. #undef HPET_HACK_ENABLE_DANGEROUS
  56. unsigned int cpu_khz; /* TSC clocks / usec, not used here */
  57. static unsigned long hpet_period; /* fsecs / HPET clock */
  58. unsigned long hpet_tick; /* HPET clocks / interrupt */
  59. static int hpet_use_timer;
  60. unsigned long vxtime_hz = PIT_TICK_RATE;
  61. int report_lost_ticks; /* command line option */
  62. unsigned long long monotonic_base;
  63. struct vxtime_data __vxtime __section_vxtime; /* for vsyscalls */
  64. volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
  65. unsigned long __wall_jiffies __section_wall_jiffies = INITIAL_JIFFIES;
  66. struct timespec __xtime __section_xtime;
  67. struct timezone __sys_tz __section_sys_tz;
  68. static inline void rdtscll_sync(unsigned long *tsc)
  69. {
  70. #ifdef CONFIG_SMP
  71. sync_core();
  72. #endif
  73. rdtscll(*tsc);
  74. }
  75. /*
  76. * do_gettimeoffset() returns microseconds since last timer interrupt was
  77. * triggered by hardware. A memory read of HPET is slower than a register read
  78. * of TSC, but much more reliable. It's also synchronized to the timer
  79. * interrupt. Note that do_gettimeoffset() may return more than hpet_tick, if a
  80. * timer interrupt has happened already, but vxtime.trigger wasn't updated yet.
  81. * This is not a problem, because jiffies hasn't updated either. They are bound
  82. * together by xtime_lock.
  83. */
  84. static inline unsigned int do_gettimeoffset_tsc(void)
  85. {
  86. unsigned long t;
  87. unsigned long x;
  88. rdtscll_sync(&t);
  89. if (t < vxtime.last_tsc) t = vxtime.last_tsc; /* hack */
  90. x = ((t - vxtime.last_tsc) * vxtime.tsc_quot) >> 32;
  91. return x;
  92. }
  93. static inline unsigned int do_gettimeoffset_hpet(void)
  94. {
  95. /* cap counter read to one tick to avoid inconsistencies */
  96. unsigned long counter = hpet_readl(HPET_COUNTER) - vxtime.last;
  97. return (min(counter,hpet_tick) * vxtime.quot) >> 32;
  98. }
  99. unsigned int (*do_gettimeoffset)(void) = do_gettimeoffset_tsc;
  100. /*
  101. * This version of gettimeofday() has microsecond resolution and better than
  102. * microsecond precision, as we're using at least a 10 MHz (usually 14.31818
  103. * MHz) HPET timer.
  104. */
  105. void do_gettimeofday(struct timeval *tv)
  106. {
  107. unsigned long seq, t;
  108. unsigned int sec, usec;
  109. do {
  110. seq = read_seqbegin(&xtime_lock);
  111. sec = xtime.tv_sec;
  112. usec = xtime.tv_nsec / 1000;
  113. /* i386 does some correction here to keep the clock
  114. monotonous even when ntpd is fixing drift.
  115. But they didn't work for me, there is a non monotonic
  116. clock anyways with ntp.
  117. I dropped all corrections now until a real solution can
  118. be found. Note when you fix it here you need to do the same
  119. in arch/x86_64/kernel/vsyscall.c and export all needed
  120. variables in vmlinux.lds. -AK */
  121. t = (jiffies - wall_jiffies) * (1000000L / HZ) +
  122. do_gettimeoffset();
  123. usec += t;
  124. } while (read_seqretry(&xtime_lock, seq));
  125. tv->tv_sec = sec + usec / 1000000;
  126. tv->tv_usec = usec % 1000000;
  127. }
  128. EXPORT_SYMBOL(do_gettimeofday);
  129. /*
  130. * settimeofday() first undoes the correction that gettimeofday would do
  131. * on the time, and then saves it. This is ugly, but has been like this for
  132. * ages already.
  133. */
  134. int do_settimeofday(struct timespec *tv)
  135. {
  136. time_t wtm_sec, sec = tv->tv_sec;
  137. long wtm_nsec, nsec = tv->tv_nsec;
  138. if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
  139. return -EINVAL;
  140. write_seqlock_irq(&xtime_lock);
  141. nsec -= do_gettimeoffset() * 1000 +
  142. (jiffies - wall_jiffies) * (NSEC_PER_SEC/HZ);
  143. wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
  144. wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
  145. set_normalized_timespec(&xtime, sec, nsec);
  146. set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
  147. ntp_clear();
  148. write_sequnlock_irq(&xtime_lock);
  149. clock_was_set();
  150. return 0;
  151. }
  152. EXPORT_SYMBOL(do_settimeofday);
  153. unsigned long profile_pc(struct pt_regs *regs)
  154. {
  155. unsigned long pc = instruction_pointer(regs);
  156. /* Assume the lock function has either no stack frame or only a single word.
  157. This checks if the address on the stack looks like a kernel text address.
  158. There is a small window for false hits, but in that case the tick
  159. is just accounted to the spinlock function.
  160. Better would be to write these functions in assembler again
  161. and check exactly. */
  162. if (in_lock_functions(pc)) {
  163. char *v = *(char **)regs->rsp;
  164. if ((v >= _stext && v <= _etext) ||
  165. (v >= _sinittext && v <= _einittext) ||
  166. (v >= (char *)MODULES_VADDR && v <= (char *)MODULES_END))
  167. return (unsigned long)v;
  168. return ((unsigned long *)regs->rsp)[1];
  169. }
  170. return pc;
  171. }
  172. EXPORT_SYMBOL(profile_pc);
  173. /*
  174. * In order to set the CMOS clock precisely, set_rtc_mmss has to be called 500
  175. * ms after the second nowtime has started, because when nowtime is written
  176. * into the registers of the CMOS clock, it will jump to the next second
  177. * precisely 500 ms later. Check the Motorola MC146818A or Dallas DS12887 data
  178. * sheet for details.
  179. */
  180. static void set_rtc_mmss(unsigned long nowtime)
  181. {
  182. int real_seconds, real_minutes, cmos_minutes;
  183. unsigned char control, freq_select;
  184. /*
  185. * IRQs are disabled when we're called from the timer interrupt,
  186. * no need for spin_lock_irqsave()
  187. */
  188. spin_lock(&rtc_lock);
  189. /*
  190. * Tell the clock it's being set and stop it.
  191. */
  192. control = CMOS_READ(RTC_CONTROL);
  193. CMOS_WRITE(control | RTC_SET, RTC_CONTROL);
  194. freq_select = CMOS_READ(RTC_FREQ_SELECT);
  195. CMOS_WRITE(freq_select | RTC_DIV_RESET2, RTC_FREQ_SELECT);
  196. cmos_minutes = CMOS_READ(RTC_MINUTES);
  197. BCD_TO_BIN(cmos_minutes);
  198. /*
  199. * since we're only adjusting minutes and seconds, don't interfere with hour
  200. * overflow. This avoids messing with unknown time zones but requires your RTC
  201. * not to be off by more than 15 minutes. Since we're calling it only when
  202. * our clock is externally synchronized using NTP, this shouldn't be a problem.
  203. */
  204. real_seconds = nowtime % 60;
  205. real_minutes = nowtime / 60;
  206. if (((abs(real_minutes - cmos_minutes) + 15) / 30) & 1)
  207. real_minutes += 30; /* correct for half hour time zone */
  208. real_minutes %= 60;
  209. #if 0
  210. /* AMD 8111 is a really bad time keeper and hits this regularly.
  211. It probably was an attempt to avoid screwing up DST, but ignore
  212. that for now. */
  213. if (abs(real_minutes - cmos_minutes) >= 30) {
  214. printk(KERN_WARNING "time.c: can't update CMOS clock "
  215. "from %d to %d\n", cmos_minutes, real_minutes);
  216. } else
  217. #endif
  218. {
  219. BIN_TO_BCD(real_seconds);
  220. BIN_TO_BCD(real_minutes);
  221. CMOS_WRITE(real_seconds, RTC_SECONDS);
  222. CMOS_WRITE(real_minutes, RTC_MINUTES);
  223. }
  224. /*
  225. * The following flags have to be released exactly in this order, otherwise the
  226. * DS12887 (popular MC146818A clone with integrated battery and quartz) will
  227. * not reset the oscillator and will not update precisely 500 ms later. You
  228. * won't find this mentioned in the Dallas Semiconductor data sheets, but who
  229. * believes data sheets anyway ... -- Markus Kuhn
  230. */
  231. CMOS_WRITE(control, RTC_CONTROL);
  232. CMOS_WRITE(freq_select, RTC_FREQ_SELECT);
  233. spin_unlock(&rtc_lock);
  234. }
  235. /* monotonic_clock(): returns # of nanoseconds passed since time_init()
  236. * Note: This function is required to return accurate
  237. * time even in the absence of multiple timer ticks.
  238. */
  239. unsigned long long monotonic_clock(void)
  240. {
  241. unsigned long seq;
  242. u32 last_offset, this_offset, offset;
  243. unsigned long long base;
  244. if (vxtime.mode == VXTIME_HPET) {
  245. do {
  246. seq = read_seqbegin(&xtime_lock);
  247. last_offset = vxtime.last;
  248. base = monotonic_base;
  249. this_offset = hpet_readl(HPET_COUNTER);
  250. } while (read_seqretry(&xtime_lock, seq));
  251. offset = (this_offset - last_offset);
  252. offset *=(NSEC_PER_SEC/HZ)/hpet_tick;
  253. return base + offset;
  254. }else{
  255. do {
  256. seq = read_seqbegin(&xtime_lock);
  257. last_offset = vxtime.last_tsc;
  258. base = monotonic_base;
  259. } while (read_seqretry(&xtime_lock, seq));
  260. sync_core();
  261. rdtscll(this_offset);
  262. offset = (this_offset - last_offset)*1000/cpu_khz;
  263. return base + offset;
  264. }
  265. }
  266. EXPORT_SYMBOL(monotonic_clock);
  267. static noinline void handle_lost_ticks(int lost, struct pt_regs *regs)
  268. {
  269. static long lost_count;
  270. static int warned;
  271. if (report_lost_ticks) {
  272. printk(KERN_WARNING "time.c: Lost %d timer "
  273. "tick(s)! ", lost);
  274. print_symbol("rip %s)\n", regs->rip);
  275. }
  276. if (lost_count == 1000 && !warned) {
  277. printk(KERN_WARNING
  278. "warning: many lost ticks.\n"
  279. KERN_WARNING "Your time source seems to be instable or "
  280. "some driver is hogging interupts\n");
  281. print_symbol("rip %s\n", regs->rip);
  282. if (vxtime.mode == VXTIME_TSC && vxtime.hpet_address) {
  283. printk(KERN_WARNING "Falling back to HPET\n");
  284. vxtime.last = hpet_readl(HPET_T0_CMP) - hpet_tick;
  285. vxtime.mode = VXTIME_HPET;
  286. do_gettimeoffset = do_gettimeoffset_hpet;
  287. }
  288. /* else should fall back to PIT, but code missing. */
  289. warned = 1;
  290. } else
  291. lost_count++;
  292. #ifdef CONFIG_CPU_FREQ
  293. /* In some cases the CPU can change frequency without us noticing
  294. (like going into thermal throttle)
  295. Give cpufreq a change to catch up. */
  296. if ((lost_count+1) % 25 == 0) {
  297. cpufreq_delayed_get();
  298. }
  299. #endif
  300. }
  301. static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  302. {
  303. static unsigned long rtc_update = 0;
  304. unsigned long tsc;
  305. int delay, offset = 0, lost = 0;
  306. /*
  307. * Here we are in the timer irq handler. We have irqs locally disabled (so we
  308. * don't need spin_lock_irqsave()) but we don't know if the timer_bh is running
  309. * on the other CPU, so we need a lock. We also need to lock the vsyscall
  310. * variables, because both do_timer() and us change them -arca+vojtech
  311. */
  312. write_seqlock(&xtime_lock);
  313. if (vxtime.hpet_address)
  314. offset = hpet_readl(HPET_COUNTER);
  315. if (hpet_use_timer) {
  316. /* if we're using the hpet timer functionality,
  317. * we can more accurately know the counter value
  318. * when the timer interrupt occured.
  319. */
  320. offset = hpet_readl(HPET_T0_CMP) - hpet_tick;
  321. delay = hpet_readl(HPET_COUNTER) - offset;
  322. } else {
  323. spin_lock(&i8253_lock);
  324. outb_p(0x00, 0x43);
  325. delay = inb_p(0x40);
  326. delay |= inb(0x40) << 8;
  327. spin_unlock(&i8253_lock);
  328. delay = LATCH - 1 - delay;
  329. }
  330. rdtscll_sync(&tsc);
  331. if (vxtime.mode == VXTIME_HPET) {
  332. if (offset - vxtime.last > hpet_tick) {
  333. lost = (offset - vxtime.last) / hpet_tick - 1;
  334. }
  335. monotonic_base +=
  336. (offset - vxtime.last)*(NSEC_PER_SEC/HZ) / hpet_tick;
  337. vxtime.last = offset;
  338. #ifdef CONFIG_X86_PM_TIMER
  339. } else if (vxtime.mode == VXTIME_PMTMR) {
  340. lost = pmtimer_mark_offset();
  341. #endif
  342. } else {
  343. offset = (((tsc - vxtime.last_tsc) *
  344. vxtime.tsc_quot) >> 32) - (USEC_PER_SEC / HZ);
  345. if (offset < 0)
  346. offset = 0;
  347. if (offset > (USEC_PER_SEC / HZ)) {
  348. lost = offset / (USEC_PER_SEC / HZ);
  349. offset %= (USEC_PER_SEC / HZ);
  350. }
  351. monotonic_base += (tsc - vxtime.last_tsc)*1000000/cpu_khz ;
  352. vxtime.last_tsc = tsc - vxtime.quot * delay / vxtime.tsc_quot;
  353. if ((((tsc - vxtime.last_tsc) *
  354. vxtime.tsc_quot) >> 32) < offset)
  355. vxtime.last_tsc = tsc -
  356. (((long) offset << 32) / vxtime.tsc_quot) - 1;
  357. }
  358. if (lost > 0) {
  359. handle_lost_ticks(lost, regs);
  360. jiffies += lost;
  361. }
  362. /*
  363. * Do the timer stuff.
  364. */
  365. do_timer(regs);
  366. #ifndef CONFIG_SMP
  367. update_process_times(user_mode(regs));
  368. #endif
  369. /*
  370. * In the SMP case we use the local APIC timer interrupt to do the profiling,
  371. * except when we simulate SMP mode on a uniprocessor system, in that case we
  372. * have to call the local interrupt handler.
  373. */
  374. #ifndef CONFIG_X86_LOCAL_APIC
  375. profile_tick(CPU_PROFILING, regs);
  376. #else
  377. if (!using_apic_timer)
  378. smp_local_timer_interrupt(regs);
  379. #endif
  380. /*
  381. * If we have an externally synchronized Linux clock, then update CMOS clock
  382. * accordingly every ~11 minutes. set_rtc_mmss() will be called in the jiffy
  383. * closest to exactly 500 ms before the next second. If the update fails, we
  384. * don't care, as it'll be updated on the next turn, and the problem (time way
  385. * off) isn't likely to go away much sooner anyway.
  386. */
  387. if (ntp_synced() && xtime.tv_sec > rtc_update &&
  388. abs(xtime.tv_nsec - 500000000) <= tick_nsec / 2) {
  389. set_rtc_mmss(xtime.tv_sec);
  390. rtc_update = xtime.tv_sec + 660;
  391. }
  392. write_sequnlock(&xtime_lock);
  393. return IRQ_HANDLED;
  394. }
  395. static unsigned int cyc2ns_scale;
  396. #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */
  397. static inline void set_cyc2ns_scale(unsigned long cpu_mhz)
  398. {
  399. cyc2ns_scale = (1000 << CYC2NS_SCALE_FACTOR)/cpu_mhz;
  400. }
  401. static inline unsigned long long cycles_2_ns(unsigned long long cyc)
  402. {
  403. return (cyc * cyc2ns_scale) >> CYC2NS_SCALE_FACTOR;
  404. }
  405. unsigned long long sched_clock(void)
  406. {
  407. unsigned long a = 0;
  408. #if 0
  409. /* Don't do a HPET read here. Using TSC always is much faster
  410. and HPET may not be mapped yet when the scheduler first runs.
  411. Disadvantage is a small drift between CPUs in some configurations,
  412. but that should be tolerable. */
  413. if (__vxtime.mode == VXTIME_HPET)
  414. return (hpet_readl(HPET_COUNTER) * vxtime.quot) >> 32;
  415. #endif
  416. /* Could do CPU core sync here. Opteron can execute rdtsc speculatively,
  417. which means it is not completely exact and may not be monotonous between
  418. CPUs. But the errors should be too small to matter for scheduling
  419. purposes. */
  420. rdtscll(a);
  421. return cycles_2_ns(a);
  422. }
  423. unsigned long get_cmos_time(void)
  424. {
  425. unsigned int timeout, year, mon, day, hour, min, sec;
  426. unsigned char last, this;
  427. unsigned long flags;
  428. /*
  429. * The Linux interpretation of the CMOS clock register contents: When the
  430. * Update-In-Progress (UIP) flag goes from 1 to 0, the RTC registers show the
  431. * second which has precisely just started. Waiting for this can take up to 1
  432. * second, we timeout approximately after 2.4 seconds on a machine with
  433. * standard 8.3 MHz ISA bus.
  434. */
  435. spin_lock_irqsave(&rtc_lock, flags);
  436. timeout = 1000000;
  437. last = this = 0;
  438. while (timeout && last && !this) {
  439. last = this;
  440. this = CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP;
  441. timeout--;
  442. }
  443. /*
  444. * Here we are safe to assume the registers won't change for a whole second, so
  445. * we just go ahead and read them.
  446. */
  447. sec = CMOS_READ(RTC_SECONDS);
  448. min = CMOS_READ(RTC_MINUTES);
  449. hour = CMOS_READ(RTC_HOURS);
  450. day = CMOS_READ(RTC_DAY_OF_MONTH);
  451. mon = CMOS_READ(RTC_MONTH);
  452. year = CMOS_READ(RTC_YEAR);
  453. spin_unlock_irqrestore(&rtc_lock, flags);
  454. /*
  455. * We know that x86-64 always uses BCD format, no need to check the config
  456. * register.
  457. */
  458. BCD_TO_BIN(sec);
  459. BCD_TO_BIN(min);
  460. BCD_TO_BIN(hour);
  461. BCD_TO_BIN(day);
  462. BCD_TO_BIN(mon);
  463. BCD_TO_BIN(year);
  464. /*
  465. * x86-64 systems only exists since 2002.
  466. * This will work up to Dec 31, 2100
  467. */
  468. year += 2000;
  469. return mktime(year, mon, day, hour, min, sec);
  470. }
  471. #ifdef CONFIG_CPU_FREQ
  472. /* Frequency scaling support. Adjust the TSC based timer when the cpu frequency
  473. changes.
  474. RED-PEN: On SMP we assume all CPUs run with the same frequency. It's
  475. not that important because current Opteron setups do not support
  476. scaling on SMP anyroads.
  477. Should fix up last_tsc too. Currently gettimeofday in the
  478. first tick after the change will be slightly wrong. */
  479. #include <linux/workqueue.h>
  480. static unsigned int cpufreq_delayed_issched = 0;
  481. static unsigned int cpufreq_init = 0;
  482. static struct work_struct cpufreq_delayed_get_work;
  483. static void handle_cpufreq_delayed_get(void *v)
  484. {
  485. unsigned int cpu;
  486. for_each_online_cpu(cpu) {
  487. cpufreq_get(cpu);
  488. }
  489. cpufreq_delayed_issched = 0;
  490. }
  491. /* if we notice lost ticks, schedule a call to cpufreq_get() as it tries
  492. * to verify the CPU frequency the timing core thinks the CPU is running
  493. * at is still correct.
  494. */
  495. static void cpufreq_delayed_get(void)
  496. {
  497. static int warned;
  498. if (cpufreq_init && !cpufreq_delayed_issched) {
  499. cpufreq_delayed_issched = 1;
  500. if (!warned) {
  501. warned = 1;
  502. printk(KERN_DEBUG "Losing some ticks... checking if CPU frequency changed.\n");
  503. }
  504. schedule_work(&cpufreq_delayed_get_work);
  505. }
  506. }
  507. static unsigned int ref_freq = 0;
  508. static unsigned long loops_per_jiffy_ref = 0;
  509. static unsigned long cpu_khz_ref = 0;
  510. static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
  511. void *data)
  512. {
  513. struct cpufreq_freqs *freq = data;
  514. unsigned long *lpj, dummy;
  515. if (cpu_has(&cpu_data[freq->cpu], X86_FEATURE_CONSTANT_TSC))
  516. return 0;
  517. lpj = &dummy;
  518. if (!(freq->flags & CPUFREQ_CONST_LOOPS))
  519. #ifdef CONFIG_SMP
  520. lpj = &cpu_data[freq->cpu].loops_per_jiffy;
  521. #else
  522. lpj = &boot_cpu_data.loops_per_jiffy;
  523. #endif
  524. if (!ref_freq) {
  525. ref_freq = freq->old;
  526. loops_per_jiffy_ref = *lpj;
  527. cpu_khz_ref = cpu_khz;
  528. }
  529. if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) ||
  530. (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) ||
  531. (val == CPUFREQ_RESUMECHANGE)) {
  532. *lpj =
  533. cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new);
  534. cpu_khz = cpufreq_scale(cpu_khz_ref, ref_freq, freq->new);
  535. if (!(freq->flags & CPUFREQ_CONST_LOOPS))
  536. vxtime.tsc_quot = (1000L << 32) / cpu_khz;
  537. }
  538. set_cyc2ns_scale(cpu_khz_ref / 1000);
  539. return 0;
  540. }
  541. static struct notifier_block time_cpufreq_notifier_block = {
  542. .notifier_call = time_cpufreq_notifier
  543. };
  544. static int __init cpufreq_tsc(void)
  545. {
  546. INIT_WORK(&cpufreq_delayed_get_work, handle_cpufreq_delayed_get, NULL);
  547. if (!cpufreq_register_notifier(&time_cpufreq_notifier_block,
  548. CPUFREQ_TRANSITION_NOTIFIER))
  549. cpufreq_init = 1;
  550. return 0;
  551. }
  552. core_initcall(cpufreq_tsc);
  553. #endif
  554. /*
  555. * calibrate_tsc() calibrates the processor TSC in a very simple way, comparing
  556. * it to the HPET timer of known frequency.
  557. */
  558. #define TICK_COUNT 100000000
  559. static unsigned int __init hpet_calibrate_tsc(void)
  560. {
  561. int tsc_start, hpet_start;
  562. int tsc_now, hpet_now;
  563. unsigned long flags;
  564. local_irq_save(flags);
  565. local_irq_disable();
  566. hpet_start = hpet_readl(HPET_COUNTER);
  567. rdtscl(tsc_start);
  568. do {
  569. local_irq_disable();
  570. hpet_now = hpet_readl(HPET_COUNTER);
  571. sync_core();
  572. rdtscl(tsc_now);
  573. local_irq_restore(flags);
  574. } while ((tsc_now - tsc_start) < TICK_COUNT &&
  575. (hpet_now - hpet_start) < TICK_COUNT);
  576. return (tsc_now - tsc_start) * 1000000000L
  577. / ((hpet_now - hpet_start) * hpet_period / 1000);
  578. }
  579. /*
  580. * pit_calibrate_tsc() uses the speaker output (channel 2) of
  581. * the PIT. This is better than using the timer interrupt output,
  582. * because we can read the value of the speaker with just one inb(),
  583. * where we need three i/o operations for the interrupt channel.
  584. * We count how many ticks the TSC does in 50 ms.
  585. */
  586. static unsigned int __init pit_calibrate_tsc(void)
  587. {
  588. unsigned long start, end;
  589. unsigned long flags;
  590. spin_lock_irqsave(&i8253_lock, flags);
  591. outb((inb(0x61) & ~0x02) | 0x01, 0x61);
  592. outb(0xb0, 0x43);
  593. outb((PIT_TICK_RATE / (1000 / 50)) & 0xff, 0x42);
  594. outb((PIT_TICK_RATE / (1000 / 50)) >> 8, 0x42);
  595. rdtscll(start);
  596. sync_core();
  597. while ((inb(0x61) & 0x20) == 0);
  598. sync_core();
  599. rdtscll(end);
  600. spin_unlock_irqrestore(&i8253_lock, flags);
  601. return (end - start) / 50;
  602. }
  603. #ifdef CONFIG_HPET
  604. static __init int late_hpet_init(void)
  605. {
  606. struct hpet_data hd;
  607. unsigned int ntimer;
  608. if (!vxtime.hpet_address)
  609. return -1;
  610. memset(&hd, 0, sizeof (hd));
  611. ntimer = hpet_readl(HPET_ID);
  612. ntimer = (ntimer & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT;
  613. ntimer++;
  614. /*
  615. * Register with driver.
  616. * Timer0 and Timer1 is used by platform.
  617. */
  618. hd.hd_phys_address = vxtime.hpet_address;
  619. hd.hd_address = (void *)fix_to_virt(FIX_HPET_BASE);
  620. hd.hd_nirqs = ntimer;
  621. hd.hd_flags = HPET_DATA_PLATFORM;
  622. hpet_reserve_timer(&hd, 0);
  623. #ifdef CONFIG_HPET_EMULATE_RTC
  624. hpet_reserve_timer(&hd, 1);
  625. #endif
  626. hd.hd_irq[0] = HPET_LEGACY_8254;
  627. hd.hd_irq[1] = HPET_LEGACY_RTC;
  628. if (ntimer > 2) {
  629. struct hpet *hpet;
  630. struct hpet_timer *timer;
  631. int i;
  632. hpet = (struct hpet *) fix_to_virt(FIX_HPET_BASE);
  633. for (i = 2, timer = &hpet->hpet_timers[2]; i < ntimer;
  634. timer++, i++)
  635. hd.hd_irq[i] = (timer->hpet_config &
  636. Tn_INT_ROUTE_CNF_MASK) >>
  637. Tn_INT_ROUTE_CNF_SHIFT;
  638. }
  639. hpet_alloc(&hd);
  640. return 0;
  641. }
  642. fs_initcall(late_hpet_init);
  643. #endif
  644. static int hpet_timer_stop_set_go(unsigned long tick)
  645. {
  646. unsigned int cfg;
  647. /*
  648. * Stop the timers and reset the main counter.
  649. */
  650. cfg = hpet_readl(HPET_CFG);
  651. cfg &= ~(HPET_CFG_ENABLE | HPET_CFG_LEGACY);
  652. hpet_writel(cfg, HPET_CFG);
  653. hpet_writel(0, HPET_COUNTER);
  654. hpet_writel(0, HPET_COUNTER + 4);
  655. /*
  656. * Set up timer 0, as periodic with first interrupt to happen at hpet_tick,
  657. * and period also hpet_tick.
  658. */
  659. if (hpet_use_timer) {
  660. hpet_writel(HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL |
  661. HPET_TN_32BIT, HPET_T0_CFG);
  662. hpet_writel(hpet_tick, HPET_T0_CMP);
  663. hpet_writel(hpet_tick, HPET_T0_CMP); /* AK: why twice? */
  664. cfg |= HPET_CFG_LEGACY;
  665. }
  666. /*
  667. * Go!
  668. */
  669. cfg |= HPET_CFG_ENABLE;
  670. hpet_writel(cfg, HPET_CFG);
  671. return 0;
  672. }
  673. static int hpet_init(void)
  674. {
  675. unsigned int id;
  676. if (!vxtime.hpet_address)
  677. return -1;
  678. set_fixmap_nocache(FIX_HPET_BASE, vxtime.hpet_address);
  679. __set_fixmap(VSYSCALL_HPET, vxtime.hpet_address, PAGE_KERNEL_VSYSCALL_NOCACHE);
  680. /*
  681. * Read the period, compute tick and quotient.
  682. */
  683. id = hpet_readl(HPET_ID);
  684. if (!(id & HPET_ID_VENDOR) || !(id & HPET_ID_NUMBER))
  685. return -1;
  686. hpet_period = hpet_readl(HPET_PERIOD);
  687. if (hpet_period < 100000 || hpet_period > 100000000)
  688. return -1;
  689. hpet_tick = (1000000000L * (USEC_PER_SEC / HZ) + hpet_period / 2) /
  690. hpet_period;
  691. hpet_use_timer = (id & HPET_ID_LEGSUP);
  692. return hpet_timer_stop_set_go(hpet_tick);
  693. }
  694. static int hpet_reenable(void)
  695. {
  696. return hpet_timer_stop_set_go(hpet_tick);
  697. }
  698. void __init pit_init(void)
  699. {
  700. unsigned long flags;
  701. spin_lock_irqsave(&i8253_lock, flags);
  702. outb_p(0x34, 0x43); /* binary, mode 2, LSB/MSB, ch 0 */
  703. outb_p(LATCH & 0xff, 0x40); /* LSB */
  704. outb_p(LATCH >> 8, 0x40); /* MSB */
  705. spin_unlock_irqrestore(&i8253_lock, flags);
  706. }
  707. int __init time_setup(char *str)
  708. {
  709. report_lost_ticks = 1;
  710. return 1;
  711. }
  712. static struct irqaction irq0 = {
  713. timer_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "timer", NULL, NULL
  714. };
  715. extern void __init config_acpi_tables(void);
  716. void __init time_init(void)
  717. {
  718. char *timename;
  719. #ifdef HPET_HACK_ENABLE_DANGEROUS
  720. if (!vxtime.hpet_address) {
  721. printk(KERN_WARNING "time.c: WARNING: Enabling HPET base "
  722. "manually!\n");
  723. outl(0x800038a0, 0xcf8);
  724. outl(0xff000001, 0xcfc);
  725. outl(0x800038a0, 0xcf8);
  726. vxtime.hpet_address = inl(0xcfc) & 0xfffffffe;
  727. printk(KERN_WARNING "time.c: WARNING: Enabled HPET "
  728. "at %#lx.\n", vxtime.hpet_address);
  729. }
  730. #endif
  731. if (nohpet)
  732. vxtime.hpet_address = 0;
  733. xtime.tv_sec = get_cmos_time();
  734. xtime.tv_nsec = 0;
  735. set_normalized_timespec(&wall_to_monotonic,
  736. -xtime.tv_sec, -xtime.tv_nsec);
  737. if (!hpet_init())
  738. vxtime_hz = (1000000000000000L + hpet_period / 2) /
  739. hpet_period;
  740. if (hpet_use_timer) {
  741. cpu_khz = hpet_calibrate_tsc();
  742. timename = "HPET";
  743. #ifdef CONFIG_X86_PM_TIMER
  744. } else if (pmtmr_ioport) {
  745. vxtime_hz = PM_TIMER_FREQUENCY;
  746. timename = "PM";
  747. pit_init();
  748. cpu_khz = pit_calibrate_tsc();
  749. #endif
  750. } else {
  751. pit_init();
  752. cpu_khz = pit_calibrate_tsc();
  753. timename = "PIT";
  754. }
  755. printk(KERN_INFO "time.c: Using %ld.%06ld MHz %s timer.\n",
  756. vxtime_hz / 1000000, vxtime_hz % 1000000, timename);
  757. printk(KERN_INFO "time.c: Detected %d.%03d MHz processor.\n",
  758. cpu_khz / 1000, cpu_khz % 1000);
  759. vxtime.mode = VXTIME_TSC;
  760. vxtime.quot = (1000000L << 32) / vxtime_hz;
  761. vxtime.tsc_quot = (1000L << 32) / cpu_khz;
  762. vxtime.hz = vxtime_hz;
  763. rdtscll_sync(&vxtime.last_tsc);
  764. setup_irq(0, &irq0);
  765. set_cyc2ns_scale(cpu_khz / 1000);
  766. #ifndef CONFIG_SMP
  767. time_init_gtod();
  768. #endif
  769. }
  770. /*
  771. * Make an educated guess if the TSC is trustworthy and synchronized
  772. * over all CPUs.
  773. */
  774. static __init int unsynchronized_tsc(void)
  775. {
  776. #ifdef CONFIG_SMP
  777. if (oem_force_hpet_timer())
  778. return 1;
  779. /* Intel systems are normally all synchronized. Exceptions
  780. are handled in the OEM check above. */
  781. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
  782. return 0;
  783. /* All in a single socket - should be synchronized */
  784. if (cpus_weight(cpu_core_map[0]) == num_online_cpus())
  785. return 0;
  786. #endif
  787. /* Assume multi socket systems are not synchronized */
  788. return num_online_cpus() > 1;
  789. }
  790. /*
  791. * Decide after all CPUs are booted what mode gettimeofday should use.
  792. */
  793. void __init time_init_gtod(void)
  794. {
  795. char *timetype;
  796. if (unsynchronized_tsc())
  797. notsc = 1;
  798. if (vxtime.hpet_address && notsc) {
  799. timetype = hpet_use_timer ? "HPET" : "PIT/HPET";
  800. vxtime.last = hpet_readl(HPET_T0_CMP) - hpet_tick;
  801. vxtime.mode = VXTIME_HPET;
  802. do_gettimeoffset = do_gettimeoffset_hpet;
  803. #ifdef CONFIG_X86_PM_TIMER
  804. /* Using PM for gettimeofday is quite slow, but we have no other
  805. choice because the TSC is too unreliable on some systems. */
  806. } else if (pmtmr_ioport && !vxtime.hpet_address && notsc) {
  807. timetype = "PM";
  808. do_gettimeoffset = do_gettimeoffset_pm;
  809. vxtime.mode = VXTIME_PMTMR;
  810. sysctl_vsyscall = 0;
  811. printk(KERN_INFO "Disabling vsyscall due to use of PM timer\n");
  812. #endif
  813. } else {
  814. timetype = hpet_use_timer ? "HPET/TSC" : "PIT/TSC";
  815. vxtime.mode = VXTIME_TSC;
  816. }
  817. printk(KERN_INFO "time.c: Using %s based timekeeping.\n", timetype);
  818. }
  819. __setup("report_lost_ticks", time_setup);
  820. static long clock_cmos_diff;
  821. static unsigned long sleep_start;
  822. static int timer_suspend(struct sys_device *dev, pm_message_t state)
  823. {
  824. /*
  825. * Estimate time zone so that set_time can update the clock
  826. */
  827. long cmos_time = get_cmos_time();
  828. clock_cmos_diff = -cmos_time;
  829. clock_cmos_diff += get_seconds();
  830. sleep_start = cmos_time;
  831. return 0;
  832. }
  833. static int timer_resume(struct sys_device *dev)
  834. {
  835. unsigned long flags;
  836. unsigned long sec;
  837. unsigned long ctime = get_cmos_time();
  838. unsigned long sleep_length = (ctime - sleep_start) * HZ;
  839. if (vxtime.hpet_address)
  840. hpet_reenable();
  841. else
  842. i8254_timer_resume();
  843. sec = ctime + clock_cmos_diff;
  844. write_seqlock_irqsave(&xtime_lock,flags);
  845. xtime.tv_sec = sec;
  846. xtime.tv_nsec = 0;
  847. write_sequnlock_irqrestore(&xtime_lock,flags);
  848. jiffies += sleep_length;
  849. wall_jiffies += sleep_length;
  850. touch_softlockup_watchdog();
  851. return 0;
  852. }
  853. static struct sysdev_class timer_sysclass = {
  854. .resume = timer_resume,
  855. .suspend = timer_suspend,
  856. set_kset_name("timer"),
  857. };
  858. /* XXX this driverfs stuff should probably go elsewhere later -john */
  859. static struct sys_device device_timer = {
  860. .id = 0,
  861. .cls = &timer_sysclass,
  862. };
  863. static int time_init_device(void)
  864. {
  865. int error = sysdev_class_register(&timer_sysclass);
  866. if (!error)
  867. error = sysdev_register(&device_timer);
  868. return error;
  869. }
  870. device_initcall(time_init_device);
  871. #ifdef CONFIG_HPET_EMULATE_RTC
  872. /* HPET in LegacyReplacement Mode eats up RTC interrupt line. When, HPET
  873. * is enabled, we support RTC interrupt functionality in software.
  874. * RTC has 3 kinds of interrupts:
  875. * 1) Update Interrupt - generate an interrupt, every sec, when RTC clock
  876. * is updated
  877. * 2) Alarm Interrupt - generate an interrupt at a specific time of day
  878. * 3) Periodic Interrupt - generate periodic interrupt, with frequencies
  879. * 2Hz-8192Hz (2Hz-64Hz for non-root user) (all freqs in powers of 2)
  880. * (1) and (2) above are implemented using polling at a frequency of
  881. * 64 Hz. The exact frequency is a tradeoff between accuracy and interrupt
  882. * overhead. (DEFAULT_RTC_INT_FREQ)
  883. * For (3), we use interrupts at 64Hz or user specified periodic
  884. * frequency, whichever is higher.
  885. */
  886. #include <linux/rtc.h>
  887. extern irqreturn_t rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  888. #define DEFAULT_RTC_INT_FREQ 64
  889. #define RTC_NUM_INTS 1
  890. static unsigned long UIE_on;
  891. static unsigned long prev_update_sec;
  892. static unsigned long AIE_on;
  893. static struct rtc_time alarm_time;
  894. static unsigned long PIE_on;
  895. static unsigned long PIE_freq = DEFAULT_RTC_INT_FREQ;
  896. static unsigned long PIE_count;
  897. static unsigned long hpet_rtc_int_freq; /* RTC interrupt frequency */
  898. int is_hpet_enabled(void)
  899. {
  900. return vxtime.hpet_address != 0;
  901. }
  902. /*
  903. * Timer 1 for RTC, we do not use periodic interrupt feature,
  904. * even if HPET supports periodic interrupts on Timer 1.
  905. * The reason being, to set up a periodic interrupt in HPET, we need to
  906. * stop the main counter. And if we do that everytime someone diables/enables
  907. * RTC, we will have adverse effect on main kernel timer running on Timer 0.
  908. * So, for the time being, simulate the periodic interrupt in software.
  909. *
  910. * hpet_rtc_timer_init() is called for the first time and during subsequent
  911. * interuppts reinit happens through hpet_rtc_timer_reinit().
  912. */
  913. int hpet_rtc_timer_init(void)
  914. {
  915. unsigned int cfg, cnt;
  916. unsigned long flags;
  917. if (!is_hpet_enabled())
  918. return 0;
  919. /*
  920. * Set the counter 1 and enable the interrupts.
  921. */
  922. if (PIE_on && (PIE_freq > DEFAULT_RTC_INT_FREQ))
  923. hpet_rtc_int_freq = PIE_freq;
  924. else
  925. hpet_rtc_int_freq = DEFAULT_RTC_INT_FREQ;
  926. local_irq_save(flags);
  927. cnt = hpet_readl(HPET_COUNTER);
  928. cnt += ((hpet_tick*HZ)/hpet_rtc_int_freq);
  929. hpet_writel(cnt, HPET_T1_CMP);
  930. local_irq_restore(flags);
  931. cfg = hpet_readl(HPET_T1_CFG);
  932. cfg |= HPET_TN_ENABLE | HPET_TN_SETVAL | HPET_TN_32BIT;
  933. hpet_writel(cfg, HPET_T1_CFG);
  934. return 1;
  935. }
  936. static void hpet_rtc_timer_reinit(void)
  937. {
  938. unsigned int cfg, cnt;
  939. if (!(PIE_on | AIE_on | UIE_on))
  940. return;
  941. if (PIE_on && (PIE_freq > DEFAULT_RTC_INT_FREQ))
  942. hpet_rtc_int_freq = PIE_freq;
  943. else
  944. hpet_rtc_int_freq = DEFAULT_RTC_INT_FREQ;
  945. /* It is more accurate to use the comparator value than current count.*/
  946. cnt = hpet_readl(HPET_T1_CMP);
  947. cnt += hpet_tick*HZ/hpet_rtc_int_freq;
  948. hpet_writel(cnt, HPET_T1_CMP);
  949. cfg = hpet_readl(HPET_T1_CFG);
  950. cfg |= HPET_TN_ENABLE | HPET_TN_SETVAL | HPET_TN_32BIT;
  951. hpet_writel(cfg, HPET_T1_CFG);
  952. return;
  953. }
  954. /*
  955. * The functions below are called from rtc driver.
  956. * Return 0 if HPET is not being used.
  957. * Otherwise do the necessary changes and return 1.
  958. */
  959. int hpet_mask_rtc_irq_bit(unsigned long bit_mask)
  960. {
  961. if (!is_hpet_enabled())
  962. return 0;
  963. if (bit_mask & RTC_UIE)
  964. UIE_on = 0;
  965. if (bit_mask & RTC_PIE)
  966. PIE_on = 0;
  967. if (bit_mask & RTC_AIE)
  968. AIE_on = 0;
  969. return 1;
  970. }
  971. int hpet_set_rtc_irq_bit(unsigned long bit_mask)
  972. {
  973. int timer_init_reqd = 0;
  974. if (!is_hpet_enabled())
  975. return 0;
  976. if (!(PIE_on | AIE_on | UIE_on))
  977. timer_init_reqd = 1;
  978. if (bit_mask & RTC_UIE) {
  979. UIE_on = 1;
  980. }
  981. if (bit_mask & RTC_PIE) {
  982. PIE_on = 1;
  983. PIE_count = 0;
  984. }
  985. if (bit_mask & RTC_AIE) {
  986. AIE_on = 1;
  987. }
  988. if (timer_init_reqd)
  989. hpet_rtc_timer_init();
  990. return 1;
  991. }
  992. int hpet_set_alarm_time(unsigned char hrs, unsigned char min, unsigned char sec)
  993. {
  994. if (!is_hpet_enabled())
  995. return 0;
  996. alarm_time.tm_hour = hrs;
  997. alarm_time.tm_min = min;
  998. alarm_time.tm_sec = sec;
  999. return 1;
  1000. }
  1001. int hpet_set_periodic_freq(unsigned long freq)
  1002. {
  1003. if (!is_hpet_enabled())
  1004. return 0;
  1005. PIE_freq = freq;
  1006. PIE_count = 0;
  1007. return 1;
  1008. }
  1009. int hpet_rtc_dropped_irq(void)
  1010. {
  1011. if (!is_hpet_enabled())
  1012. return 0;
  1013. return 1;
  1014. }
  1015. irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1016. {
  1017. struct rtc_time curr_time;
  1018. unsigned long rtc_int_flag = 0;
  1019. int call_rtc_interrupt = 0;
  1020. hpet_rtc_timer_reinit();
  1021. if (UIE_on | AIE_on) {
  1022. rtc_get_rtc_time(&curr_time);
  1023. }
  1024. if (UIE_on) {
  1025. if (curr_time.tm_sec != prev_update_sec) {
  1026. /* Set update int info, call real rtc int routine */
  1027. call_rtc_interrupt = 1;
  1028. rtc_int_flag = RTC_UF;
  1029. prev_update_sec = curr_time.tm_sec;
  1030. }
  1031. }
  1032. if (PIE_on) {
  1033. PIE_count++;
  1034. if (PIE_count >= hpet_rtc_int_freq/PIE_freq) {
  1035. /* Set periodic int info, call real rtc int routine */
  1036. call_rtc_interrupt = 1;
  1037. rtc_int_flag |= RTC_PF;
  1038. PIE_count = 0;
  1039. }
  1040. }
  1041. if (AIE_on) {
  1042. if ((curr_time.tm_sec == alarm_time.tm_sec) &&
  1043. (curr_time.tm_min == alarm_time.tm_min) &&
  1044. (curr_time.tm_hour == alarm_time.tm_hour)) {
  1045. /* Set alarm int info, call real rtc int routine */
  1046. call_rtc_interrupt = 1;
  1047. rtc_int_flag |= RTC_AF;
  1048. }
  1049. }
  1050. if (call_rtc_interrupt) {
  1051. rtc_int_flag |= (RTC_IRQF | (RTC_NUM_INTS << 8));
  1052. rtc_interrupt(rtc_int_flag, dev_id, regs);
  1053. }
  1054. return IRQ_HANDLED;
  1055. }
  1056. #endif
  1057. static int __init nohpet_setup(char *s)
  1058. {
  1059. nohpet = 1;
  1060. return 0;
  1061. }
  1062. __setup("nohpet", nohpet_setup);
  1063. static int __init notsc_setup(char *s)
  1064. {
  1065. notsc = 1;
  1066. return 0;
  1067. }
  1068. __setup("notsc", notsc_setup);