mips-atomic.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #endif /* !CONFIG_CPU_MIPSR2 && !CONFIG_CPU_MIPSR6 */