irqflags.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* FR-V interrupt handling
  2. *
  3. * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_IRQFLAGS_H
  12. #define _ASM_IRQFLAGS_H
  13. /*
  14. * interrupt flag manipulation
  15. * - use virtual interrupt management since touching the PSR is slow
  16. * - ICC2.Z: T if interrupts virtually disabled
  17. * - ICC2.C: F if interrupts really disabled
  18. * - if Z==1 upon interrupt:
  19. * - C is set to 0
  20. * - interrupts are really disabled
  21. * - entry.S returns immediately
  22. * - uses TIHI (TRAP if Z==0 && C==0) #2 to really reenable interrupts
  23. * - if taken, the trap:
  24. * - sets ICC2.C
  25. * - enables interrupts
  26. */
  27. static inline void arch_local_irq_disable(void)
  28. {
  29. /* set Z flag, but don't change the C flag */
  30. asm volatile(" andcc gr0,gr0,gr0,icc2 \n"
  31. :
  32. :
  33. : "memory", "icc2"
  34. );
  35. }
  36. static inline void arch_local_irq_enable(void)
  37. {
  38. /* clear Z flag and then test the C flag */
  39. asm volatile(" oricc gr0,#1,gr0,icc2 \n"
  40. " tihi icc2,gr0,#2 \n"
  41. :
  42. :
  43. : "memory", "icc2"
  44. );
  45. }
  46. static inline unsigned long arch_local_save_flags(void)
  47. {
  48. unsigned long flags;
  49. asm volatile("movsg ccr,%0"
  50. : "=r"(flags)
  51. :
  52. : "memory");
  53. /* shift ICC2.Z to bit 0 */
  54. flags >>= 26;
  55. /* make flags 1 if interrupts disabled, 0 otherwise */
  56. return flags & 1UL;
  57. }
  58. static inline unsigned long arch_local_irq_save(void)
  59. {
  60. unsigned long flags = arch_local_save_flags();
  61. arch_local_irq_disable();
  62. return flags;
  63. }
  64. static inline void arch_local_irq_restore(unsigned long flags)
  65. {
  66. /* load the Z flag by turning 1 if disabled into 0 if disabled
  67. * and thus setting the Z flag but not the C flag */
  68. asm volatile(" xoricc %0,#1,gr0,icc2 \n"
  69. /* then trap if Z=0 and C=0 */
  70. " tihi icc2,gr0,#2 \n"
  71. :
  72. : "r"(flags)
  73. : "memory", "icc2"
  74. );
  75. }
  76. static inline bool arch_irqs_disabled_flags(unsigned long flags)
  77. {
  78. return flags;
  79. }
  80. static inline bool arch_irqs_disabled(void)
  81. {
  82. return arch_irqs_disabled_flags(arch_local_save_flags());
  83. }
  84. /*
  85. * real interrupt flag manipulation
  86. */
  87. #define __arch_local_irq_disable() \
  88. do { \
  89. unsigned long psr; \
  90. asm volatile(" movsg psr,%0 \n" \
  91. " andi %0,%2,%0 \n" \
  92. " ori %0,%1,%0 \n" \
  93. " movgs %0,psr \n" \
  94. : "=r"(psr) \
  95. : "i" (PSR_PIL_14), "i" (~PSR_PIL) \
  96. : "memory"); \
  97. } while (0)
  98. #define __arch_local_irq_enable() \
  99. do { \
  100. unsigned long psr; \
  101. asm volatile(" movsg psr,%0 \n" \
  102. " andi %0,%1,%0 \n" \
  103. " movgs %0,psr \n" \
  104. : "=r"(psr) \
  105. : "i" (~PSR_PIL) \
  106. : "memory"); \
  107. } while (0)
  108. #define __arch_local_save_flags(flags) \
  109. do { \
  110. typecheck(unsigned long, flags); \
  111. asm("movsg psr,%0" \
  112. : "=r"(flags) \
  113. : \
  114. : "memory"); \
  115. } while (0)
  116. #define __arch_local_irq_save(flags) \
  117. do { \
  118. unsigned long npsr; \
  119. typecheck(unsigned long, flags); \
  120. asm volatile(" movsg psr,%0 \n" \
  121. " andi %0,%3,%1 \n" \
  122. " ori %1,%2,%1 \n" \
  123. " movgs %1,psr \n" \
  124. : "=r"(flags), "=r"(npsr) \
  125. : "i" (PSR_PIL_14), "i" (~PSR_PIL) \
  126. : "memory"); \
  127. } while (0)
  128. #define __arch_local_irq_restore(flags) \
  129. do { \
  130. typecheck(unsigned long, flags); \
  131. asm volatile(" movgs %0,psr \n" \
  132. : \
  133. : "r" (flags) \
  134. : "memory"); \
  135. } while (0)
  136. #define __arch_irqs_disabled() \
  137. ((__get_PSR() & PSR_PIL) >= PSR_PIL_14)
  138. #endif /* _ASM_IRQFLAGS_H */