delay.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef _ASM_POWERPC_DELAY_H
  2. #define _ASM_POWERPC_DELAY_H
  3. /*
  4. * Copyright 1996, Paul Mackerras.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * PPC64 Support added by Dave Engebretsen, Todd Inglett, Mike Corrigan,
  12. * Anton Blanchard.
  13. */
  14. extern unsigned long tb_ticks_per_usec;
  15. #ifdef CONFIG_PPC64
  16. /* define these here to prevent circular dependencies */
  17. /* these instructions control the thread priority on multi-threaded cpus */
  18. #define __HMT_low() asm volatile("or 1,1,1")
  19. #define __HMT_medium() asm volatile("or 2,2,2")
  20. #else
  21. #define __HMT_low()
  22. #define __HMT_medium()
  23. #endif
  24. #define __barrier() asm volatile("" ::: "memory")
  25. static inline unsigned long __get_tb(void)
  26. {
  27. unsigned long rval;
  28. asm volatile("mftb %0" : "=r" (rval));
  29. return rval;
  30. }
  31. static inline void __delay(unsigned long loops)
  32. {
  33. unsigned long start = __get_tb();
  34. while((__get_tb() - start) < loops)
  35. __HMT_low();
  36. __HMT_medium();
  37. __barrier();
  38. }
  39. static inline void udelay(unsigned long usecs)
  40. {
  41. unsigned long loops = tb_ticks_per_usec * usecs;
  42. __delay(loops);
  43. }
  44. #endif /* _ASM_POWERPC_DELAY_H */