delay.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <asm/processor.h>
  16. #include <asm/delay.h>
  17. #include <asm/timer.h>
  18. #ifdef CONFIG_SMP
  19. #include <asm/smp.h>
  20. #endif
  21. extern struct timer_opts* timer;
  22. void __delay(unsigned long loops)
  23. {
  24. cur_timer->delay(loops);
  25. }
  26. inline void __const_udelay(unsigned long xloops)
  27. {
  28. int d0;
  29. xloops *= 4;
  30. __asm__("mull %0"
  31. :"=d" (xloops), "=&a" (d0)
  32. :"1" (xloops),"0" (cpu_data[raw_smp_processor_id()].loops_per_jiffy * (HZ/4)));
  33. __delay(++xloops);
  34. }
  35. void __udelay(unsigned long usecs)
  36. {
  37. __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
  38. }
  39. void __ndelay(unsigned long nsecs)
  40. {
  41. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  42. }