Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * PowerNV setup code. |
| 3 | * |
| 4 | * Copyright 2011 IBM Corp. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #undef DEBUG |
| 13 | |
| 14 | #include <linux/cpu.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/tty.h> |
| 19 | #include <linux/reboot.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/console.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/irq.h> |
| 24 | #include <linux/seq_file.h> |
| 25 | #include <linux/of.h> |
Rob Herring | 26a2056 | 2013-09-26 07:40:04 -0500 | [diff] [blame] | 26 | #include <linux/of_fdt.h> |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/bug.h> |
| 29 | |
| 30 | #include <asm/machdep.h> |
| 31 | #include <asm/firmware.h> |
| 32 | #include <asm/xics.h> |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 33 | #include <asm/rtas.h> |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 34 | #include <asm/opal.h> |
Benjamin Herrenschmidt | 13906db | 2013-08-21 13:03:20 +1000 | [diff] [blame] | 35 | #include <asm/kexec.h> |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 36 | |
| 37 | #include "powernv.h" |
| 38 | |
| 39 | static void __init pnv_setup_arch(void) |
| 40 | { |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 41 | /* Initialize SMP */ |
| 42 | pnv_smp_init(); |
| 43 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 44 | /* Setup PCI */ |
| 45 | pnv_pci_init(); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 46 | |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 47 | /* Setup RTC and NVRAM callbacks */ |
| 48 | if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 49 | opal_nvram_init(); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 50 | |
| 51 | /* Enable NAP mode */ |
| 52 | powersave_nap = 1; |
| 53 | |
| 54 | /* XXX PMCS */ |
| 55 | } |
| 56 | |
| 57 | static void __init pnv_init_early(void) |
| 58 | { |
Benjamin Herrenschmidt | 3fafe9c | 2013-07-15 13:03:11 +1000 | [diff] [blame] | 59 | /* |
| 60 | * Initialize the LPC bus now so that legacy serial |
| 61 | * ports can be found on it |
| 62 | */ |
| 63 | opal_lpc_init(); |
| 64 | |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 65 | #ifdef CONFIG_HVC_OPAL |
| 66 | if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 67 | hvc_opal_init_early(); |
| 68 | else |
| 69 | #endif |
| 70 | add_preferred_console("hvc", 0, NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static void __init pnv_init_IRQ(void) |
| 74 | { |
| 75 | xics_init(); |
| 76 | |
| 77 | WARN_ON(!ppc_md.get_irq); |
| 78 | } |
| 79 | |
| 80 | static void pnv_show_cpuinfo(struct seq_file *m) |
| 81 | { |
| 82 | struct device_node *root; |
| 83 | const char *model = ""; |
| 84 | |
| 85 | root = of_find_node_by_path("/"); |
| 86 | if (root) |
| 87 | model = of_get_property(root, "model", NULL); |
| 88 | seq_printf(m, "machine\t\t: PowerNV %s\n", model); |
Benjamin Herrenschmidt | 75b93da | 2013-05-14 15:10:02 +1000 | [diff] [blame] | 89 | if (firmware_has_feature(FW_FEATURE_OPALv3)) |
| 90 | seq_printf(m, "firmware\t: OPAL v3\n"); |
| 91 | else if (firmware_has_feature(FW_FEATURE_OPALv2)) |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 92 | seq_printf(m, "firmware\t: OPAL v2\n"); |
| 93 | else if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 94 | seq_printf(m, "firmware\t: OPAL v1\n"); |
| 95 | else |
| 96 | seq_printf(m, "firmware\t: BML\n"); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 97 | of_node_put(root); |
| 98 | } |
| 99 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 100 | static void __noreturn pnv_restart(char *cmd) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 101 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 102 | long rc = OPAL_BUSY; |
| 103 | |
Gavin Shan | e8e71fa | 2013-06-20 18:13:23 +0800 | [diff] [blame] | 104 | opal_notifier_disable(); |
| 105 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 106 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
| 107 | rc = opal_cec_reboot(); |
| 108 | if (rc == OPAL_BUSY_EVENT) |
| 109 | opal_poll_events(NULL); |
| 110 | else |
| 111 | mdelay(10); |
| 112 | } |
| 113 | for (;;) |
| 114 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 117 | static void __noreturn pnv_power_off(void) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 118 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 119 | long rc = OPAL_BUSY; |
| 120 | |
Gavin Shan | e8e71fa | 2013-06-20 18:13:23 +0800 | [diff] [blame] | 121 | opal_notifier_disable(); |
| 122 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 123 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
| 124 | rc = opal_cec_power_down(0); |
| 125 | if (rc == OPAL_BUSY_EVENT) |
| 126 | opal_poll_events(NULL); |
| 127 | else |
| 128 | mdelay(10); |
| 129 | } |
| 130 | for (;;) |
| 131 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 134 | static void __noreturn pnv_halt(void) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 135 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 136 | pnv_power_off(); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 139 | static void pnv_progress(char *s, unsigned short hex) |
| 140 | { |
| 141 | } |
| 142 | |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 143 | static void pnv_shutdown(void) |
| 144 | { |
| 145 | /* Let the PCI code clear up IODA tables */ |
| 146 | pnv_pci_shutdown(); |
| 147 | |
Vasant Hegde | f7d98d1 | 2014-01-15 17:02:04 +1100 | [diff] [blame] | 148 | /* |
| 149 | * Stop OPAL activity: Unregister all OPAL interrupts so they |
| 150 | * don't fire up while we kexec and make sure all potentially |
| 151 | * DMA'ing ops are complete (such as dump retrieval). |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 152 | */ |
| 153 | opal_shutdown(); |
| 154 | } |
| 155 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 156 | #ifdef CONFIG_KEXEC |
| 157 | static void pnv_kexec_cpu_down(int crash_shutdown, int secondary) |
| 158 | { |
| 159 | xics_kexec_teardown_cpu(secondary); |
Benjamin Herrenschmidt | 13906db | 2013-08-21 13:03:20 +1000 | [diff] [blame] | 160 | |
| 161 | /* Return secondary CPUs to firmware on OPAL v3 */ |
| 162 | if (firmware_has_feature(FW_FEATURE_OPALv3) && secondary) { |
| 163 | mb(); |
| 164 | get_paca()->kexec_state = KEXEC_STATE_REAL_MODE; |
| 165 | mb(); |
| 166 | |
| 167 | /* Return the CPU to OPAL */ |
| 168 | opal_return_cpu(); |
| 169 | } |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 170 | } |
| 171 | #endif /* CONFIG_KEXEC */ |
| 172 | |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 173 | static void __init pnv_setup_machdep_opal(void) |
| 174 | { |
| 175 | ppc_md.get_boot_time = opal_get_boot_time; |
| 176 | ppc_md.get_rtc_time = opal_get_rtc_time; |
| 177 | ppc_md.set_rtc_time = opal_set_rtc_time; |
| 178 | ppc_md.restart = pnv_restart; |
| 179 | ppc_md.power_off = pnv_power_off; |
| 180 | ppc_md.halt = pnv_halt; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 181 | ppc_md.machine_check_exception = opal_machine_check; |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | #ifdef CONFIG_PPC_POWERNV_RTAS |
| 185 | static void __init pnv_setup_machdep_rtas(void) |
| 186 | { |
| 187 | if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) { |
| 188 | ppc_md.get_boot_time = rtas_get_boot_time; |
| 189 | ppc_md.get_rtc_time = rtas_get_rtc_time; |
| 190 | ppc_md.set_rtc_time = rtas_set_rtc_time; |
| 191 | } |
| 192 | ppc_md.restart = rtas_restart; |
| 193 | ppc_md.power_off = rtas_power_off; |
| 194 | ppc_md.halt = rtas_halt; |
| 195 | } |
| 196 | #endif /* CONFIG_PPC_POWERNV_RTAS */ |
| 197 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 198 | static int __init pnv_probe(void) |
| 199 | { |
| 200 | unsigned long root = of_get_flat_dt_root(); |
| 201 | |
| 202 | if (!of_flat_dt_is_compatible(root, "ibm,powernv")) |
| 203 | return 0; |
| 204 | |
| 205 | hpte_init_native(); |
| 206 | |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 207 | if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 208 | pnv_setup_machdep_opal(); |
| 209 | #ifdef CONFIG_PPC_POWERNV_RTAS |
| 210 | else if (rtas.base) |
| 211 | pnv_setup_machdep_rtas(); |
| 212 | #endif /* CONFIG_PPC_POWERNV_RTAS */ |
| 213 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 214 | pr_debug("PowerNV detected !\n"); |
| 215 | |
| 216 | return 1; |
| 217 | } |
| 218 | |
| 219 | define_machine(powernv) { |
| 220 | .name = "PowerNV", |
| 221 | .probe = pnv_probe, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 222 | .init_early = pnv_init_early, |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 223 | .setup_arch = pnv_setup_arch, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 224 | .init_IRQ = pnv_init_IRQ, |
| 225 | .show_cpuinfo = pnv_show_cpuinfo, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 226 | .progress = pnv_progress, |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 227 | .machine_shutdown = pnv_shutdown, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 228 | .power_save = power7_idle, |
| 229 | .calibrate_decr = generic_calibrate_decr, |
| 230 | #ifdef CONFIG_KEXEC |
| 231 | .kexec_cpu_down = pnv_kexec_cpu_down, |
| 232 | #endif |
| 233 | }; |