irqflags.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. : "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. }
  47. /*
  48. * Unconditionally Enable IRQs
  49. */
  50. extern void arch_local_irq_enable(void);
  51. /*
  52. * Unconditionally Disable IRQs
  53. */
  54. static inline void arch_local_irq_disable(void)
  55. {
  56. unsigned long temp;
  57. __asm__ __volatile__(
  58. " lr %0, [status32] \n"
  59. " and %0, %0, %1 \n"
  60. " flag %0 \n"
  61. : "=&r"(temp)
  62. : "n"(~(STATUS_E1_MASK | STATUS_E2_MASK)));
  63. }
  64. /*
  65. * save IRQ state
  66. */
  67. static inline long arch_local_save_flags(void)
  68. {
  69. unsigned long temp;
  70. __asm__ __volatile__(
  71. " lr %0, [status32] \n"
  72. : "=&r"(temp));
  73. return temp;
  74. }
  75. /*
  76. * Query IRQ state
  77. */
  78. static inline int arch_irqs_disabled_flags(unsigned long flags)
  79. {
  80. return !(flags & (STATUS_E1_MASK
  81. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  82. | STATUS_E2_MASK
  83. #endif
  84. ));
  85. }
  86. static inline int arch_irqs_disabled(void)
  87. {
  88. return arch_irqs_disabled_flags(arch_local_save_flags());
  89. }
  90. static inline void arch_mask_irq(unsigned int irq)
  91. {
  92. unsigned int ienb;
  93. ienb = read_aux_reg(AUX_IENABLE);
  94. ienb &= ~(1 << irq);
  95. write_aux_reg(AUX_IENABLE, ienb);
  96. }
  97. static inline void arch_unmask_irq(unsigned int irq)
  98. {
  99. unsigned int ienb;
  100. ienb = read_aux_reg(AUX_IENABLE);
  101. ienb |= (1 << irq);
  102. write_aux_reg(AUX_IENABLE, ienb);
  103. }
  104. #else
  105. .macro IRQ_DISABLE scratch
  106. lr \scratch, [status32]
  107. bic \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  108. flag \scratch
  109. .endm
  110. .macro IRQ_DISABLE_SAVE scratch, save
  111. lr \scratch, [status32]
  112. mov \save, \scratch /* Make a copy */
  113. bic \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  114. flag \scratch
  115. .endm
  116. .macro IRQ_ENABLE scratch
  117. lr \scratch, [status32]
  118. or \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
  119. flag \scratch
  120. .endm
  121. #endif /* __ASSEMBLY__ */
  122. #endif /* KERNEL */
  123. #endif