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. EXPORT_SYMBOL(__delay);
  31. #ifdef CONFIG_SMP
  32. #define LPJ cpu_data[smp_processor_id()].loops_per_jiffy
  33. #else
  34. #define LPJ loops_per_jiffy
  35. #endif
  36. void
  37. udelay(unsigned long usecs)
  38. {
  39. usecs *= (((unsigned long)HZ << 32) / 1000000) * LPJ;
  40. __delay((long)usecs >> 32);
  41. }
  42. EXPORT_SYMBOL(udelay);
  43. void
  44. ndelay(unsigned long nsecs)
  45. {
  46. nsecs *= (((unsigned long)HZ << 32) / 1000000000) * LPJ;
  47. __delay((long)nsecs >> 32);
  48. }
  49. EXPORT_SYMBOL(ndelay);