delay.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef _PPC64_DELAY_H
  2. #define _PPC64_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. /* define these here to prevent circular dependencies */
  16. #define __HMT_low() asm volatile("or 1,1,1")
  17. #define __HMT_medium() asm volatile("or 2,2,2")
  18. #define __barrier() asm volatile("":::"memory")
  19. static inline unsigned long __get_tb(void)
  20. {
  21. unsigned long rval;
  22. asm volatile("mftb %0" : "=r" (rval));
  23. return rval;
  24. }
  25. static inline void __delay(unsigned long loops)
  26. {
  27. unsigned long start = __get_tb();
  28. while((__get_tb()-start) < loops)
  29. __HMT_low();
  30. __HMT_medium();
  31. __barrier();
  32. }
  33. static inline void udelay(unsigned long usecs)
  34. {
  35. unsigned long loops = tb_ticks_per_usec * usecs;
  36. __delay(loops);
  37. }
  38. #endif /* _PPC64_DELAY_H */