delay.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Precise Delay Loops for i386
  3. *
  4. * Copyright (C) 1993 Linus Torvalds
  5. * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  6. *
  7. * The __delay function must _NOT_ be inlined as its execution time
  8. * depends wildly on alignment on many x86 processors. The additional
  9. * jump magic is needed to get the timing stable on all the CPU's
  10. * we have to worry about.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/sched.h>
  14. #include <linux/delay.h>
  15. #include <linux/module.h>
  16. #include <asm/processor.h>
  17. #include <asm/delay.h>
  18. #include <asm/timer.h>
  19. #ifdef CONFIG_SMP
  20. #include <asm/smp.h>
  21. #endif
  22. extern struct timer_opts* timer;
  23. void __delay(unsigned long loops)
  24. {
  25. cur_timer->delay(loops);
  26. }
  27. inline void __const_udelay(unsigned long xloops)
  28. {
  29. int d0;
  30. xloops *= 4;
  31. __asm__("mull %0"
  32. :"=d" (xloops), "=&a" (d0)
  33. :"1" (xloops),"0" (cpu_data[raw_smp_processor_id()].loops_per_jiffy * (HZ/4)));
  34. __delay(++xloops);
  35. }
  36. void __udelay(unsigned long usecs)
  37. {
  38. __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
  39. }
  40. void __ndelay(unsigned long nsecs)
  41. {
  42. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  43. }
  44. EXPORT_SYMBOL(__delay);
  45. EXPORT_SYMBOL(__const_udelay);
  46. EXPORT_SYMBOL(__udelay);
  47. EXPORT_SYMBOL(__ndelay);