mips-atomic.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003 by Ralf Baechle
  7. * Copyright (C) 1996 by Paul M. Antoine
  8. * Copyright (C) 1999 Silicon Graphics
  9. * Copyright (C) 2000 MIPS Technologies, Inc.
  10. */
  11. #include <asm/irqflags.h>
  12. #include <asm/hazards.h>
  13. #include <linux/compiler.h>
  14. #include <linux/preempt.h>
  15. #include <linux/export.h>
  16. #include <linux/stringify.h>
  17. #ifndef CONFIG_CPU_MIPSR2
  18. /*
  19. * For cli() we have to insert nops to make sure that the new value
  20. * has actually arrived in the status register before the end of this
  21. * macro.
  22. * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
  23. * no nops at all.
  24. */
  25. /*
  26. * For TX49, operating only IE bit is not enough.
  27. *
  28. * If mfc0 $12 follows store and the mfc0 is last instruction of a
  29. * page and fetching the next instruction causes TLB miss, the result
  30. * of the mfc0 might wrongly contain EXL bit.
  31. *
  32. * ERT-TX49H2-027, ERT-TX49H3-012, ERT-TX49HL3-006, ERT-TX49H4-008
  33. *
  34. * Workaround: mask EXL bit of the result or place a nop before mfc0.
  35. */
  36. notrace void arch_local_irq_disable(void)
  37. {
  38. preempt_disable();
  39. __asm__ __volatile__(
  40. " .set push \n"
  41. " .set noat \n"
  42. #if defined(CONFIG_CPU_MIPSR2)
  43. /* see irqflags.h for inline function */
  44. #else
  45. " mfc0 $1,$12 \n"
  46. " ori $1,0x1f \n"
  47. " xori $1,0x1f \n"
  48. " .set noreorder \n"
  49. " mtc0 $1,$12 \n"
  50. #endif
  51. " " __stringify(__irq_disable_hazard) " \n"
  52. " .set pop \n"
  53. : /* no outputs */
  54. : /* no inputs */
  55. : "memory");
  56. preempt_enable();
  57. }
  58. EXPORT_SYMBOL(arch_local_irq_disable);
  59. notrace unsigned long arch_local_irq_save(void)
  60. {
  61. unsigned long flags;
  62. preempt_disable();
  63. __asm__ __volatile__(
  64. " .set push \n"
  65. " .set reorder \n"
  66. " .set noat \n"
  67. #if defined(CONFIG_CPU_MIPSR2)
  68. /* see irqflags.h for inline function */
  69. #else
  70. " mfc0 %[flags], $12 \n"
  71. " ori $1, %[flags], 0x1f \n"
  72. " xori $1, 0x1f \n"
  73. " .set noreorder \n"
  74. " mtc0 $1, $12 \n"
  75. #endif
  76. " " __stringify(__irq_disable_hazard) " \n"
  77. " .set pop \n"
  78. : [flags] "=r" (flags)
  79. : /* no inputs */
  80. : "memory");
  81. preempt_enable();
  82. return flags;
  83. }
  84. EXPORT_SYMBOL(arch_local_irq_save);
  85. notrace void arch_local_irq_restore(unsigned long flags)
  86. {
  87. unsigned long __tmp1;
  88. preempt_disable();
  89. __asm__ __volatile__(
  90. " .set push \n"
  91. " .set noreorder \n"
  92. " .set noat \n"
  93. #if defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
  94. /* see irqflags.h for inline function */
  95. #elif defined(CONFIG_CPU_MIPSR2)
  96. /* see irqflags.h for inline function */
  97. #else
  98. " mfc0 $1, $12 \n"
  99. " andi %[flags], 1 \n"
  100. " ori $1, 0x1f \n"
  101. " xori $1, 0x1f \n"
  102. " or %[flags], $1 \n"
  103. " mtc0 %[flags], $12 \n"
  104. #endif
  105. " " __stringify(__irq_disable_hazard) " \n"
  106. " .set pop \n"
  107. : [flags] "=r" (__tmp1)
  108. : "0" (flags)
  109. : "memory");
  110. preempt_enable();
  111. }
  112. EXPORT_SYMBOL(arch_local_irq_restore);
  113. notrace void __arch_local_irq_restore(unsigned long flags)
  114. {
  115. unsigned long __tmp1;
  116. preempt_disable();
  117. __asm__ __volatile__(
  118. " .set push \n"
  119. " .set noreorder \n"
  120. " .set noat \n"
  121. #if defined(CONFIG_CPU_MIPSR2) && defined(CONFIG_IRQ_CPU)
  122. /* see irqflags.h for inline function */
  123. #elif defined(CONFIG_CPU_MIPSR2)
  124. /* see irqflags.h for inline function */
  125. #else
  126. " mfc0 $1, $12 \n"
  127. " andi %[flags], 1 \n"
  128. " ori $1, 0x1f \n"
  129. " xori $1, 0x1f \n"
  130. " or %[flags], $1 \n"
  131. " mtc0 %[flags], $12 \n"
  132. #endif
  133. " " __stringify(__irq_disable_hazard) " \n"
  134. " .set pop \n"
  135. : [flags] "=r" (__tmp1)
  136. : "0" (flags)
  137. : "memory");
  138. preempt_enable();
  139. }
  140. EXPORT_SYMBOL(__arch_local_irq_restore);
  141. #endif /* !CONFIG_CPU_MIPSR2 */