pmtimer_64.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Ported over from i386 by AK, original copyright was:
  2. *
  3. * (C) Dominik Brodowski <linux@brodo.de> 2003
  4. *
  5. * Driver to use the Power Management Timer (PMTMR) available in some
  6. * southbridges as primary timing source for the Linux kernel.
  7. *
  8. * Based on parts of linux/drivers/acpi/hardware/hwtimer.c, timer_pit.c,
  9. * timer_hpet.c, and on Arjan van de Ven's implementation for 2.4.
  10. *
  11. * This file is licensed under the GPL v2.
  12. *
  13. * Dropped all the hardware bug workarounds for now. Hopefully they
  14. * are not needed on 64bit chipsets.
  15. */
  16. #include <linux/jiffies.h>
  17. #include <linux/kernel.h>
  18. #include <linux/time.h>
  19. #include <linux/init.h>
  20. #include <linux/cpumask.h>
  21. #include <linux/acpi_pmtmr.h>
  22. #include <asm/io.h>
  23. #include <asm/proto.h>
  24. #include <asm/msr.h>
  25. #include <asm/vsyscall.h>
  26. static inline u32 cyc2us(u32 cycles)
  27. {
  28. /* The Power Management Timer ticks at 3.579545 ticks per microsecond.
  29. * 1 / PM_TIMER_FREQUENCY == 0.27936511 =~ 286/1024 [error: 0.024%]
  30. *
  31. * Even with HZ = 100, delta is at maximum 35796 ticks, so it can
  32. * easily be multiplied with 286 (=0x11E) without having to fear
  33. * u32 overflows.
  34. */
  35. cycles *= 286;
  36. return (cycles >> 10);
  37. }
  38. static unsigned pmtimer_wait_tick(void)
  39. {
  40. u32 a, b;
  41. for (a = b = inl(pmtmr_ioport) & ACPI_PM_MASK;
  42. a == b;
  43. b = inl(pmtmr_ioport) & ACPI_PM_MASK)
  44. cpu_relax();
  45. return b;
  46. }
  47. /* note: wait time is rounded up to one tick */
  48. void pmtimer_wait(unsigned us)
  49. {
  50. u32 a, b;
  51. a = pmtimer_wait_tick();
  52. do {
  53. b = inl(pmtmr_ioport);
  54. cpu_relax();
  55. } while (cyc2us(b - a) < us);
  56. }
  57. static int __init nopmtimer_setup(char *s)
  58. {
  59. pmtmr_ioport = 0;
  60. return 1;
  61. }
  62. __setup("nopmtimer", nopmtimer_setup);