pervasive.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * CBE Pervasive Monitor and Debug
  3. *
  4. * (C) Copyright IBM Corporation 2005
  5. *
  6. * Authors: Maximino Aguilar (maguilar@us.ibm.com)
  7. * Michael N. Day (mnday@us.ibm.com)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #undef DEBUG
  24. #include <linux/interrupt.h>
  25. #include <linux/irq.h>
  26. #include <linux/percpu.h>
  27. #include <linux/types.h>
  28. #include <linux/kallsyms.h>
  29. #include <asm/io.h>
  30. #include <asm/machdep.h>
  31. #include <asm/prom.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/reg.h>
  34. #include <asm/cell-regs.h>
  35. #include "pervasive.h"
  36. static int sysreset_hack;
  37. static void cbe_power_save(void)
  38. {
  39. unsigned long ctrl, thread_switch_control;
  40. /*
  41. * We need to hard disable interrupts, the local_irq_enable() done by
  42. * our caller upon return will hard re-enable.
  43. */
  44. hard_irq_disable();
  45. ctrl = mfspr(SPRN_CTRLF);
  46. /* Enable DEC and EE interrupt request */
  47. thread_switch_control = mfspr(SPRN_TSC_CELL);
  48. thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST;
  49. switch (ctrl & CTRL_CT) {
  50. case CTRL_CT0:
  51. thread_switch_control |= TSC_CELL_DEC_ENABLE_0;
  52. break;
  53. case CTRL_CT1:
  54. thread_switch_control |= TSC_CELL_DEC_ENABLE_1;
  55. break;
  56. default:
  57. printk(KERN_WARNING "%s: unknown configuration\n",
  58. __FUNCTION__);
  59. break;
  60. }
  61. mtspr(SPRN_TSC_CELL, thread_switch_control);
  62. /*
  63. * go into low thread priority, medium priority will be
  64. * restored for us after wake-up.
  65. */
  66. HMT_low();
  67. /*
  68. * atomically disable thread execution and runlatch.
  69. * External and Decrementer exceptions are still handled when the
  70. * thread is disabled but now enter in cbe_system_reset_exception()
  71. */
  72. ctrl &= ~(CTRL_RUNLATCH | CTRL_TE);
  73. mtspr(SPRN_CTRLT, ctrl);
  74. }
  75. static int cbe_system_reset_exception(struct pt_regs *regs)
  76. {
  77. int cpu;
  78. struct cbe_pmd_regs __iomem *pmd;
  79. switch (regs->msr & SRR1_WAKEMASK) {
  80. case SRR1_WAKEEE:
  81. do_IRQ(regs);
  82. break;
  83. case SRR1_WAKEDEC:
  84. timer_interrupt(regs);
  85. break;
  86. case SRR1_WAKEMT:
  87. /*
  88. * The BMC can inject user triggered system reset exceptions,
  89. * but cannot set the system reset reason in srr1,
  90. * so check an extra register here.
  91. */
  92. if (sysreset_hack && (cpu = smp_processor_id()) == 0) {
  93. pmd = cbe_get_cpu_pmd_regs(cpu);
  94. if (in_be64(&pmd->ras_esc_0) & 0xffff) {
  95. out_be64(&pmd->ras_esc_0, 0);
  96. return 0;
  97. }
  98. }
  99. break;
  100. #ifdef CONFIG_CBE_RAS
  101. case SRR1_WAKESYSERR:
  102. cbe_system_error_exception(regs);
  103. break;
  104. case SRR1_WAKETHERM:
  105. cbe_thermal_exception(regs);
  106. break;
  107. #endif /* CONFIG_CBE_RAS */
  108. default:
  109. /* do system reset */
  110. return 0;
  111. }
  112. /* everything handled */
  113. return 1;
  114. }
  115. void __init cbe_pervasive_init(void)
  116. {
  117. int cpu;
  118. if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO))
  119. return;
  120. sysreset_hack = machine_is_compatible("IBM,CBPLUS-1.0");
  121. for_each_possible_cpu(cpu) {
  122. struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu);
  123. if (!regs)
  124. continue;
  125. /* Enable Pause(0) control bit */
  126. out_be64(&regs->pmcr, in_be64(&regs->pmcr) |
  127. CBE_PMD_PAUSE_ZERO_CONTROL);
  128. /* Enable JTAG system-reset hack */
  129. if (sysreset_hack)
  130. out_be32(&regs->fir_mode_reg,
  131. in_be32(&regs->fir_mode_reg) |
  132. CBE_PMD_FIR_MODE_M8);
  133. }
  134. ppc_md.power_save = cbe_power_save;
  135. ppc_md.system_reset_exception = cbe_system_reset_exception;
  136. }