delay.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include <linux/interrupt.h>
  18. void __delay(unsigned long loops)
  19. {
  20. /*
  21. * To end the bloody studid and useless discussion about the
  22. * BogoMips number I took the liberty to define the __delay
  23. * function in a way that that resulting BogoMips number will
  24. * yield the megahertz number of the cpu. The important function
  25. * is udelay and that is done using the tod clock. -- martin.
  26. */
  27. asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
  28. }
  29. /*
  30. * Waits for 'usecs' microseconds using the TOD clock comparator.
  31. */
  32. void __udelay(unsigned long usecs)
  33. {
  34. u64 end, time, jiffy_timer = 0;
  35. unsigned long flags, cr0, mask, dummy;
  36. int irq_context;
  37. irq_context = in_interrupt();
  38. if (!irq_context)
  39. local_bh_disable();
  40. local_irq_save(flags);
  41. if (raw_irqs_disabled_flags(flags)) {
  42. jiffy_timer = S390_lowcore.jiffy_timer;
  43. S390_lowcore.jiffy_timer = -1ULL - (4096 << 12);
  44. __ctl_store(cr0, 0, 0);
  45. dummy = (cr0 & 0xffff00e0) | 0x00000800;
  46. __ctl_load(dummy , 0, 0);
  47. mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
  48. } else
  49. mask = psw_kernel_bits | PSW_MASK_WAIT |
  50. PSW_MASK_EXT | PSW_MASK_IO;
  51. end = get_clock() + ((u64) usecs << 12);
  52. do {
  53. time = end < S390_lowcore.jiffy_timer ?
  54. end : S390_lowcore.jiffy_timer;
  55. set_clock_comparator(time);
  56. trace_hardirqs_on();
  57. __load_psw_mask(mask);
  58. local_irq_disable();
  59. } while (get_clock() < end);
  60. if (raw_irqs_disabled_flags(flags)) {
  61. __ctl_load(cr0, 0, 0);
  62. S390_lowcore.jiffy_timer = jiffy_timer;
  63. }
  64. if (!irq_context)
  65. _local_bh_enable();
  66. set_clock_comparator(S390_lowcore.jiffy_timer);
  67. local_irq_restore(flags);
  68. }