pervasive.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. static DEFINE_SPINLOCK(cbe_pervasive_lock);
  37. struct cbe_pervasive {
  38. struct pmd_regs __iomem *regs;
  39. unsigned int thread;
  40. };
  41. /* can't use per_cpu from setup_arch */
  42. static struct cbe_pervasive cbe_pervasive[NR_CPUS];
  43. static void __init cbe_enable_pause_zero(void)
  44. {
  45. unsigned long thread_switch_control;
  46. unsigned long temp_register;
  47. struct cbe_pervasive *p;
  48. int thread;
  49. spin_lock_irq(&cbe_pervasive_lock);
  50. p = &cbe_pervasive[smp_processor_id()];
  51. if (!cbe_pervasive->regs)
  52. goto out;
  53. pr_debug("Power Management: CPU %d\n", smp_processor_id());
  54. /* Enable Pause(0) control bit */
  55. temp_register = in_be64(&p->regs->pm_control);
  56. out_be64(&p->regs->pm_control,
  57. temp_register|PMD_PAUSE_ZERO_CONTROL);
  58. /* Enable DEC and EE interrupt request */
  59. thread_switch_control = mfspr(SPRN_TSC_CELL);
  60. thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST;
  61. switch ((mfspr(SPRN_CTRLF) & CTRL_CT)) {
  62. case CTRL_CT0:
  63. thread_switch_control |= TSC_CELL_DEC_ENABLE_0;
  64. thread = 0;
  65. break;
  66. case CTRL_CT1:
  67. thread_switch_control |= TSC_CELL_DEC_ENABLE_1;
  68. thread = 1;
  69. break;
  70. default:
  71. printk(KERN_WARNING "%s: unknown configuration\n",
  72. __FUNCTION__);
  73. thread = -1;
  74. break;
  75. }
  76. if (p->thread != thread)
  77. printk(KERN_WARNING "%s: device tree inconsistant, "
  78. "cpu %i: %d/%d\n", __FUNCTION__,
  79. smp_processor_id(),
  80. p->thread, thread);
  81. mtspr(SPRN_TSC_CELL, thread_switch_control);
  82. out:
  83. spin_unlock_irq(&cbe_pervasive_lock);
  84. }
  85. static void cbe_idle(void)
  86. {
  87. unsigned long ctrl;
  88. cbe_enable_pause_zero();
  89. while (1) {
  90. if (!need_resched()) {
  91. local_irq_disable();
  92. while (!need_resched()) {
  93. /* go into low thread priority */
  94. HMT_low();
  95. /*
  96. * atomically disable thread execution
  97. * and runlatch.
  98. * External and Decrementer exceptions
  99. * are still handled when the thread
  100. * is disabled but now enter in
  101. * cbe_system_reset_exception()
  102. */
  103. ctrl = mfspr(SPRN_CTRLF);
  104. ctrl &= ~(CTRL_RUNLATCH | CTRL_TE);
  105. mtspr(SPRN_CTRLT, ctrl);
  106. }
  107. /* restore thread prio */
  108. HMT_medium();
  109. local_irq_enable();
  110. }
  111. /*
  112. * turn runlatch on again before scheduling the
  113. * process we just woke up
  114. */
  115. ppc64_runlatch_on();
  116. preempt_enable_no_resched();
  117. schedule();
  118. preempt_disable();
  119. }
  120. }
  121. static int cbe_system_reset_exception(struct pt_regs *regs)
  122. {
  123. switch (regs->msr & SRR1_WAKEMASK) {
  124. case SRR1_WAKEEE:
  125. do_IRQ(regs);
  126. break;
  127. case SRR1_WAKEDEC:
  128. timer_interrupt(regs);
  129. break;
  130. case SRR1_WAKEMT:
  131. /* no action required */
  132. break;
  133. default:
  134. /* do system reset */
  135. return 0;
  136. }
  137. /* everything handled */
  138. return 1;
  139. }
  140. static int __init cbe_find_pmd_mmio(int cpu, struct cbe_pervasive *p)
  141. {
  142. struct device_node *node;
  143. unsigned int *int_servers;
  144. char *addr;
  145. unsigned long real_address;
  146. unsigned int size;
  147. struct pmd_regs __iomem *pmd_mmio_area;
  148. int hardid, thread;
  149. int proplen;
  150. pmd_mmio_area = NULL;
  151. hardid = get_hard_smp_processor_id(cpu);
  152. for (node = NULL; (node = of_find_node_by_type(node, "cpu"));) {
  153. int_servers = (void *) get_property(node,
  154. "ibm,ppc-interrupt-server#s", &proplen);
  155. if (!int_servers) {
  156. printk(KERN_WARNING "%s misses "
  157. "ibm,ppc-interrupt-server#s property",
  158. node->full_name);
  159. continue;
  160. }
  161. for (thread = 0; thread < proplen / sizeof (int); thread++) {
  162. if (hardid == int_servers[thread]) {
  163. addr = get_property(node, "pervasive", NULL);
  164. goto found;
  165. }
  166. }
  167. }
  168. printk(KERN_WARNING "%s: CPU %d not found\n", __FUNCTION__, cpu);
  169. return -EINVAL;
  170. found:
  171. real_address = *(unsigned long*) addr;
  172. addr += sizeof (unsigned long);
  173. size = *(unsigned int*) addr;
  174. pr_debug("pervasive area for CPU %d at %lx, size %x\n",
  175. cpu, real_address, size);
  176. p->regs = ioremap(real_address, size);
  177. p->thread = thread;
  178. return 0;
  179. }
  180. void __init cell_pervasive_init(void)
  181. {
  182. struct cbe_pervasive *p;
  183. int cpu;
  184. int ret;
  185. if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO))
  186. return;
  187. for_each_possible_cpu(cpu) {
  188. p = &cbe_pervasive[cpu];
  189. ret = cbe_find_pmd_mmio(cpu, p);
  190. if (ret)
  191. return;
  192. }
  193. ppc_md.idle_loop = cbe_idle;
  194. ppc_md.system_reset_exception = cbe_system_reset_exception;
  195. }