irqflags.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef __ASM_ARC_IRQFLAGS_H
  9. #define __ASM_ARC_IRQFLAGS_H
  10. /* vineetg: March 2010 : local_irq_save( ) optimisation
  11. * -Remove explicit mov of current status32 into reg, that is not needed
  12. * -Use BIC insn instead of INVERTED + AND
  13. * -Conditionally disable interrupts (if they are not enabled, don't disable)
  14. */
  15. #ifdef __KERNEL__
  16. #include <asm/arcregs.h>
  17. #ifndef __ASSEMBLY__
  18. /******************************************************************
  19. * IRQ Control Macros
  20. ******************************************************************/
  21. /*
  22. * Save IRQ state and disable IRQs
  23. */
  24. static inline long arch_local_irq_save(void)
  25. {
  26. unsigned long temp, flags;
  27. __asm__ __volatile__(
  28. " lr %1, [status32] \n"
  29. " bic %0, %1, %2 \n"
  30. " and.f 0, %1, %2 \n"
  31. " flag.nz %0 \n"
  32. : "=r"(temp), "=r"(flags)
  33. : "n"((STATUS_E1_MASK | STATUS_E2_MASK))
  34. : "memory", "cc");
  35. return flags;
  36. }
  37. /*
  38. * restore saved IRQ state
  39. */
  40. static inline void arch_local_irq_restore(unsigned long flags)
  41. {
  42. __asm__ __volatile__(
  43. " flag %0 \n"
  44. :
  45. : "r"(flags)
  46. : "memory");
  47. }
  48. /*
  49. * Unconditionally Enable IRQs
  50. */
  51. extern void arch_local_irq_enable(void);
  52. /*
  53. * Unconditionally Disable IRQs
  54. */
  55. static inline void arch_local_irq_disable(void)
  56. {
  57. unsigned long temp;
  58. __asm__ __volatile__(
  59. " lr %0, [status32] \n"
  60. " and %0, %0, %1 \n"
  61. " flag %0 \n"
  62. : "=&r"(temp)
  63. : "n"(~(STATUS_E1_MASK | STATUS_E2_MASK))
  64. : "memory");
  65. }
  66. /*
  67. * save IRQ state
  68. */
  69. static inline long arch_local_save_flags(void)
  70. {
  71. unsigned long temp;
  72. __asm__ __volatile__(
  73. " lr %0, [status32] \n"
  74. : "=&r"(temp)
  75. :
  76. : "memory");
  77. return temp;
  78. }
  79. /*
  80. * Query IRQ state
  81. */
  82. static inline int arch_irqs_disabled_flags(unsigned long flags)
  83. {
  84. return !(flags & (STATUS_E1_MASK
  85. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  86. | STATUS_E2_MASK
  87. #endif
  88. ));
  89. }
  90. static inline int arch_irqs_disabled(void)
  91. {
  92. return arch_irqs_disabled_flags(arch_local_save_flags());
  93. }
  94. static inline void arch_mask_irq(unsigned int irq)
  95. {
  96. unsigned int ienb;
  97. ienb = read_aux_reg(AUX_IENABLE);
  98. ienb &= ~(1 << irq);
  99. write_aux_reg(AUX_IENABLE, ienb);
  100. }
  101. static inline void arch_unmask_irq(unsigned int irq)
  102. {
  103. unsigned int ienb;
  104. ienb = read_aux_reg(AUX_IENABLE);
  105. ienb |= (1 << irq);
  106. write_aux_reg(AUX_IENABLE, ienb);
  107. }
  108. #else
  109. .macro IRQ_DISABLE scratch
  110. lr \scratch, [status32]
  111. bic \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  112. flag \scratch
  113. .endm
  114. .macro IRQ_DISABLE_SAVE scratch, save
  115. lr \scratch, [status32]
  116. mov \save, \scratch /* Make a copy */
  117. bic \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  118. flag \scratch
  119. .endm
  120. .macro IRQ_ENABLE scratch
  121. lr \scratch, [status32]
  122. or \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  123. flag \scratch
  124. .endm
  125. #endif /* __ASSEMBLY__ */
  126. #endif /* KERNEL */
  127. #endif