1c902be71SArnd Bergmann /*
2c902be71SArnd Bergmann  * CBE Pervasive Monitor and Debug
3c902be71SArnd Bergmann  *
4c902be71SArnd Bergmann  * (C) Copyright IBM Corporation 2005
5c902be71SArnd Bergmann  *
6c902be71SArnd Bergmann  * Authors: Maximino Aguilar (maguilar@us.ibm.com)
7c902be71SArnd Bergmann  *          Michael N. Day (mnday@us.ibm.com)
8c902be71SArnd Bergmann  *
9c902be71SArnd Bergmann  * This program is free software; you can redistribute it and/or modify
10c902be71SArnd Bergmann  * it under the terms of the GNU General Public License as published by
11c902be71SArnd Bergmann  * the Free Software Foundation; either version 2, or (at your option)
12c902be71SArnd Bergmann  * any later version.
13c902be71SArnd Bergmann  *
14c902be71SArnd Bergmann  * This program is distributed in the hope that it will be useful,
15c902be71SArnd Bergmann  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16c902be71SArnd Bergmann  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17c902be71SArnd Bergmann  * GNU General Public License for more details.
18c902be71SArnd Bergmann  *
19c902be71SArnd Bergmann  * You should have received a copy of the GNU General Public License
20c902be71SArnd Bergmann  * along with this program; if not, write to the Free Software
21c902be71SArnd Bergmann  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22c902be71SArnd Bergmann  */
23c902be71SArnd Bergmann 
24c902be71SArnd Bergmann #undef DEBUG
25c902be71SArnd Bergmann 
26c902be71SArnd Bergmann #include <linux/interrupt.h>
27c902be71SArnd Bergmann #include <linux/irq.h>
28c902be71SArnd Bergmann #include <linux/percpu.h>
29c902be71SArnd Bergmann #include <linux/types.h>
30c902be71SArnd Bergmann #include <linux/kallsyms.h>
31c902be71SArnd Bergmann 
32c902be71SArnd Bergmann #include <asm/io.h>
33c902be71SArnd Bergmann #include <asm/machdep.h>
34c902be71SArnd Bergmann #include <asm/prom.h>
35c902be71SArnd Bergmann #include <asm/pgtable.h>
36c902be71SArnd Bergmann #include <asm/reg.h>
37c902be71SArnd Bergmann 
38c902be71SArnd Bergmann #include "pervasive.h"
39acf7d768SBenjamin Herrenschmidt #include "cbe_regs.h"
40c902be71SArnd Bergmann 
41302eca18Sarnd@arndb.de static void cbe_power_save(void)
42c902be71SArnd Bergmann {
43302eca18Sarnd@arndb.de 	unsigned long ctrl, thread_switch_control;
44302eca18Sarnd@arndb.de 	ctrl = mfspr(SPRN_CTRLF);
45c902be71SArnd Bergmann 
46c902be71SArnd Bergmann 	/* Enable DEC and EE interrupt request */
47c902be71SArnd Bergmann 	thread_switch_control  = mfspr(SPRN_TSC_CELL);
48c902be71SArnd Bergmann 	thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST;
49c902be71SArnd Bergmann 
50302eca18Sarnd@arndb.de 	switch (ctrl & CTRL_CT) {
51c902be71SArnd Bergmann 	case CTRL_CT0:
52c902be71SArnd Bergmann 		thread_switch_control |= TSC_CELL_DEC_ENABLE_0;
53c902be71SArnd Bergmann 		break;
54c902be71SArnd Bergmann 	case CTRL_CT1:
55c902be71SArnd Bergmann 		thread_switch_control |= TSC_CELL_DEC_ENABLE_1;
56c902be71SArnd Bergmann 		break;
57c902be71SArnd Bergmann 	default:
58c902be71SArnd Bergmann 		printk(KERN_WARNING "%s: unknown configuration\n",
59c902be71SArnd Bergmann 			__FUNCTION__);
60c902be71SArnd Bergmann 		break;
61c902be71SArnd Bergmann 	}
62c902be71SArnd Bergmann 	mtspr(SPRN_TSC_CELL, thread_switch_control);
63c902be71SArnd Bergmann 
64302eca18Sarnd@arndb.de 	/*
65302eca18Sarnd@arndb.de 	 * go into low thread priority, medium priority will be
66302eca18Sarnd@arndb.de 	 * restored for us after wake-up.
67acf7d768SBenjamin Herrenschmidt 	 */
68c902be71SArnd Bergmann 	HMT_low();
69c902be71SArnd Bergmann 
70c902be71SArnd Bergmann 	/*
71302eca18Sarnd@arndb.de 	 * atomically disable thread execution and runlatch.
72302eca18Sarnd@arndb.de 	 * External and Decrementer exceptions are still handled when the
73302eca18Sarnd@arndb.de 	 * thread is disabled but now enter in cbe_system_reset_exception()
74c902be71SArnd Bergmann 	 */
75c902be71SArnd Bergmann 	ctrl &= ~(CTRL_RUNLATCH | CTRL_TE);
76c902be71SArnd Bergmann 	mtspr(SPRN_CTRLT, ctrl);
77c902be71SArnd Bergmann }
78c902be71SArnd Bergmann 
798fce10a3SArnd Bergmann static int cbe_system_reset_exception(struct pt_regs *regs)
80c902be71SArnd Bergmann {
81c902be71SArnd Bergmann 	switch (regs->msr & SRR1_WAKEMASK) {
82c902be71SArnd Bergmann 	case SRR1_WAKEEE:
83c902be71SArnd Bergmann 		do_IRQ(regs);
84c902be71SArnd Bergmann 		break;
85c902be71SArnd Bergmann 	case SRR1_WAKEDEC:
86c902be71SArnd Bergmann 		timer_interrupt(regs);
87c902be71SArnd Bergmann 		break;
88c902be71SArnd Bergmann 	case SRR1_WAKEMT:
89c902be71SArnd Bergmann 		break;
90acf7d768SBenjamin Herrenschmidt #ifdef CONFIG_CBE_RAS
91acf7d768SBenjamin Herrenschmidt 	case SRR1_WAKESYSERR:
92acf7d768SBenjamin Herrenschmidt 		cbe_system_error_exception(regs);
93acf7d768SBenjamin Herrenschmidt 		break;
94acf7d768SBenjamin Herrenschmidt 	case SRR1_WAKETHERM:
95acf7d768SBenjamin Herrenschmidt 		cbe_thermal_exception(regs);
96acf7d768SBenjamin Herrenschmidt 		break;
97acf7d768SBenjamin Herrenschmidt #endif /* CONFIG_CBE_RAS */
98c902be71SArnd Bergmann 	default:
99c902be71SArnd Bergmann 		/* do system reset */
100c902be71SArnd Bergmann 		return 0;
101c902be71SArnd Bergmann 	}
102c902be71SArnd Bergmann 	/* everything handled */
103c902be71SArnd Bergmann 	return 1;
104c902be71SArnd Bergmann }
105c902be71SArnd Bergmann 
106acf7d768SBenjamin Herrenschmidt void __init cbe_pervasive_init(void)
107c902be71SArnd Bergmann {
108302eca18Sarnd@arndb.de 	int cpu;
109c902be71SArnd Bergmann 	if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO))
110c902be71SArnd Bergmann 		return;
111c902be71SArnd Bergmann 
112302eca18Sarnd@arndb.de 	for_each_possible_cpu(cpu) {
113302eca18Sarnd@arndb.de 		struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu);
114302eca18Sarnd@arndb.de 		if (!regs)
115302eca18Sarnd@arndb.de 			continue;
116302eca18Sarnd@arndb.de 
117302eca18Sarnd@arndb.de 		 /* Enable Pause(0) control bit */
118302eca18Sarnd@arndb.de 		out_be64(&regs->pmcr, in_be64(&regs->pmcr) |
119302eca18Sarnd@arndb.de 					    CBE_PMD_PAUSE_ZERO_CONTROL);
120302eca18Sarnd@arndb.de 	}
121302eca18Sarnd@arndb.de 
122302eca18Sarnd@arndb.de 	ppc_md.power_save = cbe_power_save;
123c902be71SArnd Bergmann 	ppc_md.system_reset_exception = cbe_system_reset_exception;
124c902be71SArnd Bergmann }
125