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>
37eef686a0SBenjamin Herrenschmidt #include <asm/cell-regs.h>
38c902be71SArnd Bergmann 
39c902be71SArnd Bergmann #include "pervasive.h"
40c902be71SArnd Bergmann 
41302eca18Sarnd@arndb.de static void cbe_power_save(void)
42c902be71SArnd Bergmann {
43302eca18Sarnd@arndb.de 	unsigned long ctrl, thread_switch_control;
445850dd8fSBenjamin Herrenschmidt 
455850dd8fSBenjamin Herrenschmidt 	/*
46e1fa2e13SBenjamin Herrenschmidt 	 * We need to hard disable interrupts, the local_irq_enable() done by
47e1fa2e13SBenjamin Herrenschmidt 	 * our caller upon return will hard re-enable.
485850dd8fSBenjamin Herrenschmidt 	 */
495850dd8fSBenjamin Herrenschmidt 	hard_irq_disable();
505850dd8fSBenjamin Herrenschmidt 
51302eca18Sarnd@arndb.de 	ctrl = mfspr(SPRN_CTRLF);
52c902be71SArnd Bergmann 
53c902be71SArnd Bergmann 	/* Enable DEC and EE interrupt request */
54c902be71SArnd Bergmann 	thread_switch_control  = mfspr(SPRN_TSC_CELL);
55c902be71SArnd Bergmann 	thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST;
56c902be71SArnd Bergmann 
57302eca18Sarnd@arndb.de 	switch (ctrl & CTRL_CT) {
58c902be71SArnd Bergmann 	case CTRL_CT0:
59c902be71SArnd Bergmann 		thread_switch_control |= TSC_CELL_DEC_ENABLE_0;
60c902be71SArnd Bergmann 		break;
61c902be71SArnd Bergmann 	case CTRL_CT1:
62c902be71SArnd Bergmann 		thread_switch_control |= TSC_CELL_DEC_ENABLE_1;
63c902be71SArnd Bergmann 		break;
64c902be71SArnd Bergmann 	default:
65c902be71SArnd Bergmann 		printk(KERN_WARNING "%s: unknown configuration\n",
66e48b1b45SHarvey Harrison 			__func__);
67c902be71SArnd Bergmann 		break;
68c902be71SArnd Bergmann 	}
69c902be71SArnd Bergmann 	mtspr(SPRN_TSC_CELL, thread_switch_control);
70c902be71SArnd Bergmann 
71302eca18Sarnd@arndb.de 	/*
72302eca18Sarnd@arndb.de 	 * go into low thread priority, medium priority will be
73302eca18Sarnd@arndb.de 	 * restored for us after wake-up.
74acf7d768SBenjamin Herrenschmidt 	 */
75c902be71SArnd Bergmann 	HMT_low();
76c902be71SArnd Bergmann 
77c902be71SArnd Bergmann 	/*
78302eca18Sarnd@arndb.de 	 * atomically disable thread execution and runlatch.
79302eca18Sarnd@arndb.de 	 * External and Decrementer exceptions are still handled when the
80302eca18Sarnd@arndb.de 	 * thread is disabled but now enter in cbe_system_reset_exception()
81c902be71SArnd Bergmann 	 */
82c902be71SArnd Bergmann 	ctrl &= ~(CTRL_RUNLATCH | CTRL_TE);
83c902be71SArnd Bergmann 	mtspr(SPRN_CTRLT, ctrl);
84c902be71SArnd Bergmann }
85c902be71SArnd Bergmann 
868fce10a3SArnd Bergmann static int cbe_system_reset_exception(struct pt_regs *regs)
87c902be71SArnd Bergmann {
88c902be71SArnd Bergmann 	switch (regs->msr & SRR1_WAKEMASK) {
89c902be71SArnd Bergmann 	case SRR1_WAKEEE:
90c902be71SArnd Bergmann 		do_IRQ(regs);
91c902be71SArnd Bergmann 		break;
92c902be71SArnd Bergmann 	case SRR1_WAKEDEC:
93c902be71SArnd Bergmann 		timer_interrupt(regs);
94c902be71SArnd Bergmann 		break;
95c902be71SArnd Bergmann 	case SRR1_WAKEMT:
9670694a8bSChristian Krafft 		return cbe_sysreset_hack();
97acf7d768SBenjamin Herrenschmidt #ifdef CONFIG_CBE_RAS
98acf7d768SBenjamin Herrenschmidt 	case SRR1_WAKESYSERR:
99acf7d768SBenjamin Herrenschmidt 		cbe_system_error_exception(regs);
100acf7d768SBenjamin Herrenschmidt 		break;
101acf7d768SBenjamin Herrenschmidt 	case SRR1_WAKETHERM:
102acf7d768SBenjamin Herrenschmidt 		cbe_thermal_exception(regs);
103acf7d768SBenjamin Herrenschmidt 		break;
104acf7d768SBenjamin Herrenschmidt #endif /* CONFIG_CBE_RAS */
105c902be71SArnd Bergmann 	default:
106c902be71SArnd Bergmann 		/* do system reset */
107c902be71SArnd Bergmann 		return 0;
108c902be71SArnd Bergmann 	}
109c902be71SArnd Bergmann 	/* everything handled */
110c902be71SArnd Bergmann 	return 1;
111c902be71SArnd Bergmann }
112c902be71SArnd Bergmann 
113acf7d768SBenjamin Herrenschmidt void __init cbe_pervasive_init(void)
114c902be71SArnd Bergmann {
115302eca18Sarnd@arndb.de 	int cpu;
1163addf55cSArnd Bergmann 
117c902be71SArnd Bergmann 	if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO))
118c902be71SArnd Bergmann 		return;
119c902be71SArnd Bergmann 
120302eca18Sarnd@arndb.de 	for_each_possible_cpu(cpu) {
121302eca18Sarnd@arndb.de 		struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu);
122302eca18Sarnd@arndb.de 		if (!regs)
123302eca18Sarnd@arndb.de 			continue;
124302eca18Sarnd@arndb.de 
125302eca18Sarnd@arndb.de 		 /* Enable Pause(0) control bit */
126302eca18Sarnd@arndb.de 		out_be64(&regs->pmcr, in_be64(&regs->pmcr) |
127302eca18Sarnd@arndb.de 					    CBE_PMD_PAUSE_ZERO_CONTROL);
128302eca18Sarnd@arndb.de 	}
129302eca18Sarnd@arndb.de 
130302eca18Sarnd@arndb.de 	ppc_md.power_save = cbe_power_save;
131c902be71SArnd Bergmann 	ppc_md.system_reset_exception = cbe_system_reset_exception;
132c902be71SArnd Bergmann }
133