pervasive.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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/config.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/irq.h>
  27. #include <linux/percpu.h>
  28. #include <linux/types.h>
  29. #include <linux/kallsyms.h>
  30. #include <asm/io.h>
  31. #include <asm/machdep.h>
  32. #include <asm/prom.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/reg.h>
  35. #include "pervasive.h"
  36. #include "cbe_regs.h"
  37. static DEFINE_SPINLOCK(cbe_pervasive_lock);
  38. static void __init cbe_enable_pause_zero(void)
  39. {
  40. unsigned long thread_switch_control;
  41. unsigned long temp_register;
  42. struct cbe_pmd_regs __iomem *pregs;
  43. spin_lock_irq(&cbe_pervasive_lock);
  44. pregs = cbe_get_cpu_pmd_regs(smp_processor_id());
  45. if (pregs == NULL)
  46. goto out;
  47. pr_debug("Power Management: CPU %d\n", smp_processor_id());
  48. /* Enable Pause(0) control bit */
  49. temp_register = in_be64(&pregs->pm_control);
  50. out_be64(&pregs->pm_control,
  51. temp_register | CBE_PMD_PAUSE_ZERO_CONTROL);
  52. /* Enable DEC and EE interrupt request */
  53. thread_switch_control = mfspr(SPRN_TSC_CELL);
  54. thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST;
  55. switch ((mfspr(SPRN_CTRLF) & CTRL_CT)) {
  56. case CTRL_CT0:
  57. thread_switch_control |= TSC_CELL_DEC_ENABLE_0;
  58. break;
  59. case CTRL_CT1:
  60. thread_switch_control |= TSC_CELL_DEC_ENABLE_1;
  61. break;
  62. default:
  63. printk(KERN_WARNING "%s: unknown configuration\n",
  64. __FUNCTION__);
  65. break;
  66. }
  67. mtspr(SPRN_TSC_CELL, thread_switch_control);
  68. out:
  69. spin_unlock_irq(&cbe_pervasive_lock);
  70. }
  71. static void cbe_idle(void)
  72. {
  73. unsigned long ctrl;
  74. /* Why do we do that on every idle ? Couldn't that be done once for
  75. * all or do we lose the state some way ? Also, the pm_control
  76. * register setting, that can't be set once at boot ? We really want
  77. * to move that away in order to implement a simple powersave
  78. */
  79. cbe_enable_pause_zero();
  80. while (1) {
  81. if (!need_resched()) {
  82. local_irq_disable();
  83. while (!need_resched()) {
  84. /* go into low thread priority */
  85. HMT_low();
  86. /*
  87. * atomically disable thread execution
  88. * and runlatch.
  89. * External and Decrementer exceptions
  90. * are still handled when the thread
  91. * is disabled but now enter in
  92. * cbe_system_reset_exception()
  93. */
  94. ctrl = mfspr(SPRN_CTRLF);
  95. ctrl &= ~(CTRL_RUNLATCH | CTRL_TE);
  96. mtspr(SPRN_CTRLT, ctrl);
  97. }
  98. /* restore thread prio */
  99. HMT_medium();
  100. local_irq_enable();
  101. }
  102. /*
  103. * turn runlatch on again before scheduling the
  104. * process we just woke up
  105. */
  106. ppc64_runlatch_on();
  107. preempt_enable_no_resched();
  108. schedule();
  109. preempt_disable();
  110. }
  111. }
  112. static int cbe_system_reset_exception(struct pt_regs *regs)
  113. {
  114. switch (regs->msr & SRR1_WAKEMASK) {
  115. case SRR1_WAKEEE:
  116. do_IRQ(regs);
  117. break;
  118. case SRR1_WAKEDEC:
  119. timer_interrupt(regs);
  120. break;
  121. case SRR1_WAKEMT:
  122. break;
  123. #ifdef CONFIG_CBE_RAS
  124. case SRR1_WAKESYSERR:
  125. cbe_system_error_exception(regs);
  126. break;
  127. case SRR1_WAKETHERM:
  128. cbe_thermal_exception(regs);
  129. break;
  130. #endif /* CONFIG_CBE_RAS */
  131. default:
  132. /* do system reset */
  133. return 0;
  134. }
  135. /* everything handled */
  136. return 1;
  137. }
  138. void __init cbe_pervasive_init(void)
  139. {
  140. if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO))
  141. return;
  142. ppc_md.idle_loop = cbe_idle;
  143. ppc_md.system_reset_exception = cbe_system_reset_exception;
  144. }