delay.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef _ASM_POWERPC_DELAY_H
  2. #define _ASM_POWERPC_DELAY_H
  3. #ifdef __KERNEL__
  4. #include <asm/time.h>
  5. /*
  6. * Copyright 1996, Paul Mackerras.
  7. * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. *
  14. * PPC64 Support added by Dave Engebretsen, Todd Inglett, Mike Corrigan,
  15. * Anton Blanchard.
  16. */
  17. extern void __delay(unsigned long loops);
  18. extern void udelay(unsigned long usecs);
  19. /*
  20. * On shared processor machines the generic implementation of mdelay can
  21. * result in large errors. While each iteration of the loop inside mdelay
  22. * is supposed to take 1ms, the hypervisor could sleep our partition for
  23. * longer (eg 10ms). With the right timing these errors can add up.
  24. *
  25. * Since there is no 32bit overflow issue on 64bit kernels, just call
  26. * udelay directly.
  27. */
  28. #ifdef CONFIG_PPC64
  29. #define mdelay(n) udelay((n) * 1000)
  30. #endif
  31. /**
  32. * spin_event_timeout - spin until a condition gets true or a timeout elapses
  33. * @condition: a C expression to evalate
  34. * @timeout: timeout, in microseconds
  35. * @delay: the number of microseconds to delay between each evaluation of
  36. * @condition
  37. *
  38. * The process spins until the condition evaluates to true (non-zero) or the
  39. * timeout elapses. The return value of this macro is the value of
  40. * @condition when the loop terminates. This allows you to determine the cause
  41. * of the loop terminates. If the return value is zero, then you know a
  42. * timeout has occurred.
  43. *
  44. * This primary purpose of this macro is to poll on a hardware register
  45. * until a status bit changes. The timeout ensures that the loop still
  46. * terminates even if the bit never changes. The delay is for devices that
  47. * need a delay in between successive reads.
  48. *
  49. * gcc will optimize out the if-statement if @delay is a constant.
  50. */
  51. #define spin_event_timeout(condition, timeout, delay) \
  52. ({ \
  53. typeof(condition) __ret; \
  54. unsigned long __loops = tb_ticks_per_usec * timeout; \
  55. unsigned long __start = get_tbl(); \
  56. while (!(__ret = (condition)) && (tb_ticks_since(__start) <= __loops)) \
  57. if (delay) \
  58. udelay(delay); \
  59. else \
  60. cpu_relax(); \
  61. if (!__ret) \
  62. __ret = (condition); \
  63. __ret; \
  64. })
  65. #endif /* __KERNEL__ */
  66. #endif /* _ASM_POWERPC_DELAY_H */