Thomas Gleixner | de6cc65 | 2019-05-27 08:55:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 2 | /* |
| 3 | * CBE Pervasive Monitor and Debug |
| 4 | * |
| 5 | * (C) Copyright IBM Corporation 2005 |
| 6 | * |
| 7 | * Authors: Maximino Aguilar (maguilar@us.ibm.com) |
| 8 | * Michael N. Day (mnday@us.ibm.com) |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #undef DEBUG |
| 12 | |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/irq.h> |
| 15 | #include <linux/percpu.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/kallsyms.h> |
Mike Rapoport | 65fddcf | 2020-06-08 21:32:42 -0700 | [diff] [blame] | 18 | #include <linux/pgtable.h> |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 19 | |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/machdep.h> |
| 22 | #include <asm/prom.h> |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 23 | #include <asm/reg.h> |
Benjamin Herrenschmidt | eef686a0 | 2007-10-04 15:40:42 +1000 | [diff] [blame] | 24 | #include <asm/cell-regs.h> |
Kevin Hao | b92a226 | 2016-07-23 14:42:40 +0530 | [diff] [blame] | 25 | #include <asm/cpu_has_feature.h> |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 26 | |
| 27 | #include "pervasive.h" |
Nicholas Piggin | dcdb4f1 | 2021-01-30 23:08:32 +1000 | [diff] [blame] | 28 | #include "ras.h" |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 29 | |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 30 | static void cbe_power_save(void) |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 31 | { |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 32 | unsigned long ctrl, thread_switch_control; |
Benjamin Herrenschmidt | 5850dd8 | 2006-11-23 00:46:38 +0100 | [diff] [blame] | 33 | |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 34 | /* Ensure our interrupt state is properly tracked */ |
| 35 | if (!prep_irq_for_idle()) |
| 36 | return; |
Benjamin Herrenschmidt | 5850dd8 | 2006-11-23 00:46:38 +0100 | [diff] [blame] | 37 | |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 38 | ctrl = mfspr(SPRN_CTRLF); |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 39 | |
| 40 | /* Enable DEC and EE interrupt request */ |
| 41 | thread_switch_control = mfspr(SPRN_TSC_CELL); |
| 42 | thread_switch_control |= TSC_CELL_EE_ENABLE | TSC_CELL_EE_BOOST; |
| 43 | |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 44 | switch (ctrl & CTRL_CT) { |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 45 | case CTRL_CT0: |
| 46 | thread_switch_control |= TSC_CELL_DEC_ENABLE_0; |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 47 | break; |
| 48 | case CTRL_CT1: |
| 49 | thread_switch_control |= TSC_CELL_DEC_ENABLE_1; |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 50 | break; |
| 51 | default: |
| 52 | printk(KERN_WARNING "%s: unknown configuration\n", |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 53 | __func__); |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 54 | break; |
| 55 | } |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 56 | mtspr(SPRN_TSC_CELL, thread_switch_control); |
| 57 | |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 58 | /* |
| 59 | * go into low thread priority, medium priority will be |
| 60 | * restored for us after wake-up. |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 61 | */ |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 62 | HMT_low(); |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 63 | |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 64 | /* |
| 65 | * atomically disable thread execution and runlatch. |
| 66 | * External and Decrementer exceptions are still handled when the |
| 67 | * thread is disabled but now enter in cbe_system_reset_exception() |
| 68 | */ |
| 69 | ctrl &= ~(CTRL_RUNLATCH | CTRL_TE); |
| 70 | mtspr(SPRN_CTRLT, ctrl); |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 71 | |
| 72 | /* Re-enable interrupts in MSR */ |
| 73 | __hard_irq_enable(); |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Arnd Bergmann | 8fce10a | 2006-01-11 23:07:11 +0000 | [diff] [blame] | 76 | static int cbe_system_reset_exception(struct pt_regs *regs) |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 77 | { |
| 78 | switch (regs->msr & SRR1_WAKEMASK) { |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 79 | case SRR1_WAKEDEC: |
Nicholas Piggin | 6e83985 | 2017-03-20 16:31:49 +1000 | [diff] [blame] | 80 | set_dec(1); |
| 81 | case SRR1_WAKEEE: |
| 82 | /* |
| 83 | * Handle these when interrupts get re-enabled and we take |
| 84 | * them as regular exceptions. We are in an NMI context |
| 85 | * and can't handle these here. |
| 86 | */ |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 87 | break; |
| 88 | case SRR1_WAKEMT: |
Christian Krafft | 70694a8 | 2008-07-16 05:51:44 +1000 | [diff] [blame] | 89 | return cbe_sysreset_hack(); |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_CBE_RAS |
| 91 | case SRR1_WAKESYSERR: |
| 92 | cbe_system_error_exception(regs); |
| 93 | break; |
| 94 | case SRR1_WAKETHERM: |
| 95 | cbe_thermal_exception(regs); |
| 96 | break; |
| 97 | #endif /* CONFIG_CBE_RAS */ |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 98 | default: |
| 99 | /* do system reset */ |
| 100 | return 0; |
| 101 | } |
| 102 | /* everything handled */ |
| 103 | return 1; |
| 104 | } |
| 105 | |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 106 | void __init cbe_pervasive_init(void) |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 107 | { |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 108 | int cpu; |
Arnd Bergmann | 3addf55 | 2007-08-23 03:01:26 +1000 | [diff] [blame] | 109 | |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 110 | if (!cpu_has_feature(CPU_FTR_PAUSE_ZERO)) |
| 111 | return; |
| 112 | |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 113 | for_each_possible_cpu(cpu) { |
| 114 | struct cbe_pmd_regs __iomem *regs = cbe_get_cpu_pmd_regs(cpu); |
| 115 | if (!regs) |
| 116 | continue; |
| 117 | |
| 118 | /* Enable Pause(0) control bit */ |
| 119 | out_be64(®s->pmcr, in_be64(®s->pmcr) | |
| 120 | CBE_PMD_PAUSE_ZERO_CONTROL); |
| 121 | } |
| 122 | |
| 123 | ppc_md.power_save = cbe_power_save; |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 124 | ppc_md.system_reset_exception = cbe_system_reset_exception; |
| 125 | } |