udelay.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 1993, 2000 Linus Torvalds
  3. *
  4. * Delay routines, using a pre-computed "loops_per_jiffy" value.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/sched.h> /* for udelay's use of smp_processor_id */
  8. #include <asm/param.h>
  9. #include <asm/smp.h>
  10. #include <linux/delay.h>
  11. /*
  12. * Use only for very small delays (< 1 msec).
  13. *
  14. * The active part of our cycle counter is only 32-bits wide, and
  15. * we're treating the difference between two marks as signed. On
  16. * a 1GHz box, that's about 2 seconds.
  17. */
  18. void
  19. __delay(int loops)
  20. {
  21. int tmp;
  22. __asm__ __volatile__(
  23. " rpcc %0\n"
  24. " addl %1,%0,%1\n"
  25. "1: rpcc %0\n"
  26. " subl %1,%0,%0\n"
  27. " bgt %0,1b"
  28. : "=&r" (tmp), "=r" (loops) : "1"(loops));
  29. }
  30. #ifdef CONFIG_SMP
  31. #define LPJ cpu_data[smp_processor_id()].loops_per_jiffy
  32. #else
  33. #define LPJ loops_per_jiffy
  34. #endif
  35. void
  36. udelay(unsigned long usecs)
  37. {
  38. usecs *= (((unsigned long)HZ << 32) / 1000000) * LPJ;
  39. __delay((long)usecs >> 32);
  40. }
  41. EXPORT_SYMBOL(udelay);
  42. void
  43. ndelay(unsigned long nsecs)
  44. {
  45. nsecs *= (((unsigned long)HZ << 32) / 1000000000) * LPJ;
  46. __delay((long)nsecs >> 32);
  47. }
  48. EXPORT_SYMBOL(ndelay);