mips-atomic.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #if !defined(CONFIG_CPU_MIPSR2) && !defined(CONFIG_CPU_MIPSR6)
  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. " mfc0 $1,$12 \n"
  43. " ori $1,0x1f \n"
  44. " xori $1,0x1f \n"
  45. " .set noreorder \n"
  46. " mtc0 $1,$12 \n"
  47. " " __stringify(__irq_disable_hazard) " \n"
  48. " .set pop \n"
  49. : /* no outputs */
  50. : /* no inputs */
  51. : "memory");
  52. preempt_enable();
  53. }
  54. EXPORT_SYMBOL(arch_local_irq_disable);
  55. notrace unsigned long arch_local_irq_save(void)
  56. {
  57. unsigned long flags;
  58. preempt_disable();
  59. __asm__ __volatile__(
  60. " .set push \n"
  61. " .set reorder \n"
  62. " .set noat \n"
  63. " mfc0 %[flags], $12 \n"
  64. " ori $1, %[flags], 0x1f \n"
  65. " xori $1, 0x1f \n"
  66. " .set noreorder \n"
  67. " mtc0 $1, $12 \n"
  68. " " __stringify(__irq_disable_hazard) " \n"
  69. " .set pop \n"
  70. : [flags] "=r" (flags)
  71. : /* no inputs */
  72. : "memory");
  73. preempt_enable();
  74. return flags;
  75. }
  76. EXPORT_SYMBOL(arch_local_irq_save);
  77. notrace void arch_local_irq_restore(unsigned long flags)
  78. {
  79. unsigned long __tmp1;
  80. preempt_disable();
  81. __asm__ __volatile__(
  82. " .set push \n"
  83. " .set noreorder \n"
  84. " .set noat \n"
  85. " mfc0 $1, $12 \n"
  86. " andi %[flags], 1 \n"
  87. " ori $1, 0x1f \n"
  88. " xori $1, 0x1f \n"
  89. " or %[flags], $1 \n"
  90. " mtc0 %[flags], $12 \n"
  91. " " __stringify(__irq_disable_hazard) " \n"
  92. " .set pop \n"
  93. : [flags] "=r" (__tmp1)
  94. : "0" (flags)
  95. : "memory");
  96. preempt_enable();
  97. }
  98. EXPORT_SYMBOL(arch_local_irq_restore);
  99. notrace void __arch_local_irq_restore(unsigned long flags)
  100. {
  101. unsigned long __tmp1;
  102. preempt_disable();
  103. __asm__ __volatile__(
  104. " .set push \n"
  105. " .set noreorder \n"
  106. " .set noat \n"
  107. " mfc0 $1, $12 \n"
  108. " andi %[flags], 1 \n"
  109. " ori $1, 0x1f \n"
  110. " xori $1, 0x1f \n"
  111. " or %[flags], $1 \n"
  112. " mtc0 %[flags], $12 \n"
  113. " " __stringify(__irq_disable_hazard) " \n"
  114. " .set pop \n"
  115. : [flags] "=r" (__tmp1)
  116. : "0" (flags)
  117. : "memory");
  118. preempt_enable();
  119. }
  120. EXPORT_SYMBOL(__arch_local_irq_restore);
  121. #endif /* !CONFIG_CPU_MIPSR2 */