blob: 8c20f0fb8651f23b204f455bbf75a23581bef746 [file] [log] [blame]
Arnd Bergmannc902be72006-01-04 19:55:53 +00001/*
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
24#undef DEBUG
25
Arnd Bergmannc902be72006-01-04 19:55:53 +000026#include <linux/interrupt.h>
27#include <linux/irq.h>
28#include <linux/percpu.h>
29#include <linux/types.h>
30#include <linux/kallsyms.h>
31
32#include <asm/io.h>
33#include <asm/machdep.h>
34#include <asm/prom.h>
35#include <asm/pgtable.h>
36#include <asm/reg.h>
37
38#include "pervasive.h"
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +020039#include "cbe_regs.h"
Arnd Bergmannc902be72006-01-04 19:55:53 +000040
arnd@arndb.de302eca12006-10-24 18:31:26 +020041static void cbe_power_save(void)
Arnd Bergmannc902be72006-01-04 19:55:53 +000042{
arnd@arndb.de302eca12006-10-24 18:31:26 +020043 unsigned long ctrl, thread_switch_control;
Benjamin Herrenschmidt5850dd82006-11-23 00:46:38 +010044
45 /*
46 * We need to hard disable interrupts, but we also need to mark them
47 * hard disabled in the PACA so that the local_irq_enable() done by
48 * our caller upon return propertly hard enables.
49 */
50 hard_irq_disable();
51 get_paca()->hard_enabled = 0;
52
arnd@arndb.de302eca12006-10-24 18:31:26 +020053 ctrl = mfspr(SPRN_CTRLF);
Arnd Bergmannc902be72006-01-04 19:55:53 +000054
55 /* Enable DEC and EE interrupt request */
56 thread_switch_control = mfspr(SPRN_TSC_CELL);
57 thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST;
58
arnd@arndb.de302eca12006-10-24 18:31:26 +020059 switch (ctrl & CTRL_CT) {
Arnd Bergmannc902be72006-01-04 19:55:53 +000060 case CTRL_CT0:
61 thread_switch_control |= TSC_CELL_DEC_ENABLE_0;
Arnd Bergmannc902be72006-01-04 19:55:53 +000062 break;
63 case CTRL_CT1:
64 thread_switch_control |= TSC_CELL_DEC_ENABLE_1;
Arnd Bergmannc902be72006-01-04 19:55:53 +000065 break;
66 default:
67 printk(KERN_WARNING "%s: unknown configuration\n",
68 __FUNCTION__);
Arnd Bergmannc902be72006-01-04 19:55:53 +000069 break;
70 }
Arnd Bergmannc902be72006-01-04 19:55:53 +000071 mtspr(SPRN_TSC_CELL, thread_switch_control);
72
arnd@arndb.de302eca12006-10-24 18:31:26 +020073 /*
74 * go into low thread priority, medium priority will be
75 * restored for us after wake-up.
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +020076 */
arnd@arndb.de302eca12006-10-24 18:31:26 +020077 HMT_low();
Arnd Bergmannc902be72006-01-04 19:55:53 +000078
arnd@arndb.de302eca12006-10-24 18:31:26 +020079 /*
80 * atomically disable thread execution and runlatch.
81 * External and Decrementer exceptions are still handled when the
82 * thread is disabled but now enter in cbe_system_reset_exception()
83 */
84 ctrl &= ~(CTRL_RUNLATCH | CTRL_TE);
85 mtspr(SPRN_CTRLT, ctrl);
Arnd Bergmannc902be72006-01-04 19:55:53 +000086}
87
Arnd Bergmann8fce10a2006-01-11 23:07:11 +000088static int cbe_system_reset_exception(struct pt_regs *regs)
Arnd Bergmannc902be72006-01-04 19:55:53 +000089{
90 switch (regs->msr & SRR1_WAKEMASK) {
91 case SRR1_WAKEEE:
92 do_IRQ(regs);
93 break;
94 case SRR1_WAKEDEC:
95 timer_interrupt(regs);
96 break;
97 case SRR1_WAKEMT:
Arnd Bergmannc902be72006-01-04 19:55:53 +000098 break;
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +020099#ifdef CONFIG_CBE_RAS
100 case SRR1_WAKESYSERR:
101 cbe_system_error_exception(regs);
102 break;
103 case SRR1_WAKETHERM:
104 cbe_thermal_exception(regs);
105 break;
106#endif /* CONFIG_CBE_RAS */
Arnd Bergmannc902be72006-01-04 19:55:53 +0000107 default:
108 /* do system reset */
109 return 0;
110 }
111 /* everything handled */
112 return 1;
113}
114
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200115void __init cbe_pervasive_init(void)
Arnd Bergmannc902be72006-01-04 19:55:53 +0000116{
arnd@arndb.de302eca12006-10-24 18:31:26 +0200117 int cpu;
Arnd Bergmannc902be72006-01-04 19:55:53 +0000118 if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO))
119 return;
120
arnd@arndb.de302eca12006-10-24 18:31:26 +0200121 for_each_possible_cpu(cpu) {
122 struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu);
123 if (!regs)
124 continue;
125
126 /* Enable Pause(0) control bit */
127 out_be64(&regs->pmcr, in_be64(&regs->pmcr) |
128 CBE_PMD_PAUSE_ZERO_CONTROL);
129 }
130
131 ppc_md.power_save = cbe_power_save;
Arnd Bergmannc902be72006-01-04 19:55:53 +0000132 ppc_md.system_reset_exception = cbe_system_reset_exception;
133}