delay.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * arch/s390/lib/delay.c
  3. * Precise Delay Loops for S390
  4. *
  5. * S390 version
  6. * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  7. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  8. *
  9. * Derived from "arch/i386/lib/delay.c"
  10. * Copyright (C) 1993 Linus Torvalds
  11. * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  12. */
  13. #include <linux/sched.h>
  14. #include <linux/delay.h>
  15. #include <linux/timex.h>
  16. #include <linux/irqflags.h>
  17. void __delay(unsigned long loops)
  18. {
  19. /*
  20. * To end the bloody studid and useless discussion about the
  21. * BogoMips number I took the liberty to define the __delay
  22. * function in a way that that resulting BogoMips number will
  23. * yield the megahertz number of the cpu. The important function
  24. * is udelay and that is done using the tod clock. -- martin.
  25. */
  26. asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
  27. }
  28. /*
  29. * Waits for 'usecs' microseconds using the TOD clock comparator.
  30. */
  31. void __udelay(unsigned long usecs)
  32. {
  33. u64 end, time, jiffy_timer = 0;
  34. unsigned long flags, cr0, mask, dummy;
  35. local_irq_save(flags);
  36. if (raw_irqs_disabled_flags(flags)) {
  37. jiffy_timer = S390_lowcore.jiffy_timer;
  38. S390_lowcore.jiffy_timer = -1ULL - (4096 << 12);
  39. __ctl_store(cr0, 0, 0);
  40. dummy = (cr0 & 0xffff00e0) | 0x00000800;
  41. __ctl_load(dummy , 0, 0);
  42. mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
  43. } else
  44. mask = psw_kernel_bits | PSW_MASK_WAIT |
  45. PSW_MASK_EXT | PSW_MASK_IO;
  46. end = get_clock() + ((u64) usecs << 12);
  47. do {
  48. time = end < S390_lowcore.jiffy_timer ?
  49. end : S390_lowcore.jiffy_timer;
  50. set_clock_comparator(time);
  51. trace_hardirqs_on();
  52. __load_psw_mask(mask);
  53. local_irq_disable();
  54. } while (get_clock() < end);
  55. if (raw_irqs_disabled_flags(flags)) {
  56. __ctl_load(cr0, 0, 0);
  57. S390_lowcore.jiffy_timer = jiffy_timer;
  58. }
  59. set_clock_comparator(S390_lowcore.jiffy_timer);
  60. local_irq_restore(flags);
  61. }