18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * CBE Pervasive Monitor and Debug 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * (C) Copyright IBM Corporation 2005 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Authors: Maximino Aguilar (maguilar@us.ibm.com) 88c2ecf20Sopenharmony_ci * Michael N. Day (mnday@us.ibm.com) 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#undef DEBUG 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 148c2ecf20Sopenharmony_ci#include <linux/irq.h> 158c2ecf20Sopenharmony_ci#include <linux/percpu.h> 168c2ecf20Sopenharmony_ci#include <linux/types.h> 178c2ecf20Sopenharmony_ci#include <linux/kallsyms.h> 188c2ecf20Sopenharmony_ci#include <linux/pgtable.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include <asm/io.h> 218c2ecf20Sopenharmony_ci#include <asm/machdep.h> 228c2ecf20Sopenharmony_ci#include <asm/prom.h> 238c2ecf20Sopenharmony_ci#include <asm/reg.h> 248c2ecf20Sopenharmony_ci#include <asm/cell-regs.h> 258c2ecf20Sopenharmony_ci#include <asm/cpu_has_feature.h> 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include "pervasive.h" 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic void cbe_power_save(void) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci unsigned long ctrl, thread_switch_control; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci /* Ensure our interrupt state is properly tracked */ 348c2ecf20Sopenharmony_ci if (!prep_irq_for_idle()) 358c2ecf20Sopenharmony_ci return; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci ctrl = mfspr(SPRN_CTRLF); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci /* Enable DEC and EE interrupt request */ 408c2ecf20Sopenharmony_ci thread_switch_control = mfspr(SPRN_TSC_CELL); 418c2ecf20Sopenharmony_ci thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci switch (ctrl & CTRL_CT) { 448c2ecf20Sopenharmony_ci case CTRL_CT0: 458c2ecf20Sopenharmony_ci thread_switch_control |= TSC_CELL_DEC_ENABLE_0; 468c2ecf20Sopenharmony_ci break; 478c2ecf20Sopenharmony_ci case CTRL_CT1: 488c2ecf20Sopenharmony_ci thread_switch_control |= TSC_CELL_DEC_ENABLE_1; 498c2ecf20Sopenharmony_ci break; 508c2ecf20Sopenharmony_ci default: 518c2ecf20Sopenharmony_ci printk(KERN_WARNING "%s: unknown configuration\n", 528c2ecf20Sopenharmony_ci __func__); 538c2ecf20Sopenharmony_ci break; 548c2ecf20Sopenharmony_ci } 558c2ecf20Sopenharmony_ci mtspr(SPRN_TSC_CELL, thread_switch_control); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci /* 588c2ecf20Sopenharmony_ci * go into low thread priority, medium priority will be 598c2ecf20Sopenharmony_ci * restored for us after wake-up. 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_ci HMT_low(); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci /* 648c2ecf20Sopenharmony_ci * atomically disable thread execution and runlatch. 658c2ecf20Sopenharmony_ci * External and Decrementer exceptions are still handled when the 668c2ecf20Sopenharmony_ci * thread is disabled but now enter in cbe_system_reset_exception() 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_ci ctrl &= ~(CTRL_RUNLATCH | CTRL_TE); 698c2ecf20Sopenharmony_ci mtspr(SPRN_CTRLT, ctrl); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci /* Re-enable interrupts in MSR */ 728c2ecf20Sopenharmony_ci __hard_irq_enable(); 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic int cbe_system_reset_exception(struct pt_regs *regs) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci switch (regs->msr & SRR1_WAKEMASK) { 788c2ecf20Sopenharmony_ci case SRR1_WAKEDEC: 798c2ecf20Sopenharmony_ci set_dec(1); 808c2ecf20Sopenharmony_ci break; 818c2ecf20Sopenharmony_ci case SRR1_WAKEEE: 828c2ecf20Sopenharmony_ci /* 838c2ecf20Sopenharmony_ci * Handle these when interrupts get re-enabled and we take 848c2ecf20Sopenharmony_ci * them as regular exceptions. We are in an NMI context 858c2ecf20Sopenharmony_ci * and can't handle these here. 868c2ecf20Sopenharmony_ci */ 878c2ecf20Sopenharmony_ci break; 888c2ecf20Sopenharmony_ci case SRR1_WAKEMT: 898c2ecf20Sopenharmony_ci return cbe_sysreset_hack(); 908c2ecf20Sopenharmony_ci#ifdef CONFIG_CBE_RAS 918c2ecf20Sopenharmony_ci case SRR1_WAKESYSERR: 928c2ecf20Sopenharmony_ci cbe_system_error_exception(regs); 938c2ecf20Sopenharmony_ci break; 948c2ecf20Sopenharmony_ci case SRR1_WAKETHERM: 958c2ecf20Sopenharmony_ci cbe_thermal_exception(regs); 968c2ecf20Sopenharmony_ci break; 978c2ecf20Sopenharmony_ci#endif /* CONFIG_CBE_RAS */ 988c2ecf20Sopenharmony_ci default: 998c2ecf20Sopenharmony_ci /* do system reset */ 1008c2ecf20Sopenharmony_ci return 0; 1018c2ecf20Sopenharmony_ci } 1028c2ecf20Sopenharmony_ci /* everything handled */ 1038c2ecf20Sopenharmony_ci return 1; 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_civoid __init cbe_pervasive_init(void) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci int cpu; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO)) 1118c2ecf20Sopenharmony_ci return; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci for_each_possible_cpu(cpu) { 1148c2ecf20Sopenharmony_ci struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu); 1158c2ecf20Sopenharmony_ci if (!regs) 1168c2ecf20Sopenharmony_ci continue; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci /* Enable Pause(0) control bit */ 1198c2ecf20Sopenharmony_ci out_be64(®s->pmcr, in_be64(®s->pmcr) | 1208c2ecf20Sopenharmony_ci CBE_PMD_PAUSE_ZERO_CONTROL); 1218c2ecf20Sopenharmony_ci } 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci ppc_md.power_save = cbe_power_save; 1248c2ecf20Sopenharmony_ci ppc_md.system_reset_exception = cbe_system_reset_exception; 1258c2ecf20Sopenharmony_ci} 126