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 
45be2cf20aSBenjamin Herrenschmidt 	/* Ensure our interrupt state is properly tracked */
46be2cf20aSBenjamin Herrenschmidt 	if (!prep_irq_for_idle())
47be2cf20aSBenjamin Herrenschmidt 		return;
485850dd8fSBenjamin Herrenschmidt 
49302eca18Sarnd@arndb.de 	ctrl = mfspr(SPRN_CTRLF);
50c902be71SArnd Bergmann 
51c902be71SArnd Bergmann 	/* Enable DEC and EE interrupt request */
52c902be71SArnd Bergmann 	thread_switch_control  = mfspr(SPRN_TSC_CELL);
53c902be71SArnd Bergmann 	thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST;
54c902be71SArnd Bergmann 
55302eca18Sarnd@arndb.de 	switch (ctrl & CTRL_CT) {
56c902be71SArnd Bergmann 	case CTRL_CT0:
57c902be71SArnd Bergmann 		thread_switch_control |= TSC_CELL_DEC_ENABLE_0;
58c902be71SArnd Bergmann 		break;
59c902be71SArnd Bergmann 	case CTRL_CT1:
60c902be71SArnd Bergmann 		thread_switch_control |= TSC_CELL_DEC_ENABLE_1;
61c902be71SArnd Bergmann 		break;
62c902be71SArnd Bergmann 	default:
63c902be71SArnd Bergmann 		printk(KERN_WARNING "%s: unknown configuration\n",
64e48b1b45SHarvey Harrison 			__func__);
65c902be71SArnd Bergmann 		break;
66c902be71SArnd Bergmann 	}
67c902be71SArnd Bergmann 	mtspr(SPRN_TSC_CELL, thread_switch_control);
68c902be71SArnd Bergmann 
69302eca18Sarnd@arndb.de 	/*
70302eca18Sarnd@arndb.de 	 * go into low thread priority, medium priority will be
71302eca18Sarnd@arndb.de 	 * restored for us after wake-up.
72acf7d768SBenjamin Herrenschmidt 	 */
73c902be71SArnd Bergmann 	HMT_low();
74c902be71SArnd Bergmann 
75c902be71SArnd Bergmann 	/*
76302eca18Sarnd@arndb.de 	 * atomically disable thread execution and runlatch.
77302eca18Sarnd@arndb.de 	 * External and Decrementer exceptions are still handled when the
78302eca18Sarnd@arndb.de 	 * thread is disabled but now enter in cbe_system_reset_exception()
79c902be71SArnd Bergmann 	 */
80c902be71SArnd Bergmann 	ctrl &= ~(CTRL_RUNLATCH | CTRL_TE);
81c902be71SArnd Bergmann 	mtspr(SPRN_CTRLT, ctrl);
82be2cf20aSBenjamin Herrenschmidt 
83be2cf20aSBenjamin Herrenschmidt 	/* Re-enable interrupts in MSR */
84be2cf20aSBenjamin Herrenschmidt 	__hard_irq_enable();
85c902be71SArnd Bergmann }
86c902be71SArnd Bergmann 
878fce10a3SArnd Bergmann static int cbe_system_reset_exception(struct pt_regs *regs)
88c902be71SArnd Bergmann {
89c902be71SArnd Bergmann 	switch (regs->msr & SRR1_WAKEMASK) {
90c902be71SArnd Bergmann 	case SRR1_WAKEEE:
91c902be71SArnd Bergmann 		do_IRQ(regs);
92c902be71SArnd Bergmann 		break;
93c902be71SArnd Bergmann 	case SRR1_WAKEDEC:
94c902be71SArnd Bergmann 		timer_interrupt(regs);
95c902be71SArnd Bergmann 		break;
96c902be71SArnd Bergmann 	case SRR1_WAKEMT:
9770694a8bSChristian Krafft 		return cbe_sysreset_hack();
98acf7d768SBenjamin Herrenschmidt #ifdef CONFIG_CBE_RAS
99acf7d768SBenjamin Herrenschmidt 	case SRR1_WAKESYSERR:
100acf7d768SBenjamin Herrenschmidt 		cbe_system_error_exception(regs);
101acf7d768SBenjamin Herrenschmidt 		break;
102acf7d768SBenjamin Herrenschmidt 	case SRR1_WAKETHERM:
103acf7d768SBenjamin Herrenschmidt 		cbe_thermal_exception(regs);
104acf7d768SBenjamin Herrenschmidt 		break;
105acf7d768SBenjamin Herrenschmidt #endif /* CONFIG_CBE_RAS */
106c902be71SArnd Bergmann 	default:
107c902be71SArnd Bergmann 		/* do system reset */
108c902be71SArnd Bergmann 		return 0;
109c902be71SArnd Bergmann 	}
110c902be71SArnd Bergmann 	/* everything handled */
111c902be71SArnd Bergmann 	return 1;
112c902be71SArnd Bergmann }
113c902be71SArnd Bergmann 
114acf7d768SBenjamin Herrenschmidt void __init cbe_pervasive_init(void)
115c902be71SArnd Bergmann {
116302eca18Sarnd@arndb.de 	int cpu;
1173addf55cSArnd Bergmann 
118c902be71SArnd Bergmann 	if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO))
119c902be71SArnd Bergmann 		return;
120c902be71SArnd Bergmann 
121302eca18Sarnd@arndb.de 	for_each_possible_cpu(cpu) {
122302eca18Sarnd@arndb.de 		struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu);
123302eca18Sarnd@arndb.de 		if (!regs)
124302eca18Sarnd@arndb.de 			continue;
125302eca18Sarnd@arndb.de 
126302eca18Sarnd@arndb.de 		 /* Enable Pause(0) control bit */
127302eca18Sarnd@arndb.de 		out_be64(&regs->pmcr, in_be64(&regs->pmcr) |
128302eca18Sarnd@arndb.de 					    CBE_PMD_PAUSE_ZERO_CONTROL);
129302eca18Sarnd@arndb.de 	}
130302eca18Sarnd@arndb.de 
131302eca18Sarnd@arndb.de 	ppc_md.power_save = cbe_power_save;
132c902be71SArnd Bergmann 	ppc_md.system_reset_exception = cbe_system_reset_exception;
133c902be71SArnd Bergmann }
134