155190f88SBenjamin Herrenschmidt /* 255190f88SBenjamin Herrenschmidt * PowerNV setup code. 355190f88SBenjamin Herrenschmidt * 455190f88SBenjamin Herrenschmidt * Copyright 2011 IBM Corp. 555190f88SBenjamin Herrenschmidt * 655190f88SBenjamin Herrenschmidt * This program is free software; you can redistribute it and/or 755190f88SBenjamin Herrenschmidt * modify it under the terms of the GNU General Public License 855190f88SBenjamin Herrenschmidt * as published by the Free Software Foundation; either version 955190f88SBenjamin Herrenschmidt * 2 of the License, or (at your option) any later version. 1055190f88SBenjamin Herrenschmidt */ 1155190f88SBenjamin Herrenschmidt 1255190f88SBenjamin Herrenschmidt #undef DEBUG 1355190f88SBenjamin Herrenschmidt 1455190f88SBenjamin Herrenschmidt #include <linux/cpu.h> 1555190f88SBenjamin Herrenschmidt #include <linux/errno.h> 1655190f88SBenjamin Herrenschmidt #include <linux/sched.h> 1755190f88SBenjamin Herrenschmidt #include <linux/kernel.h> 1855190f88SBenjamin Herrenschmidt #include <linux/tty.h> 1955190f88SBenjamin Herrenschmidt #include <linux/reboot.h> 2055190f88SBenjamin Herrenschmidt #include <linux/init.h> 2155190f88SBenjamin Herrenschmidt #include <linux/console.h> 2255190f88SBenjamin Herrenschmidt #include <linux/delay.h> 2355190f88SBenjamin Herrenschmidt #include <linux/irq.h> 2455190f88SBenjamin Herrenschmidt #include <linux/seq_file.h> 2555190f88SBenjamin Herrenschmidt #include <linux/of.h> 2626a2056eSRob Herring #include <linux/of_fdt.h> 2755190f88SBenjamin Herrenschmidt #include <linux/interrupt.h> 2855190f88SBenjamin Herrenschmidt #include <linux/bug.h> 29cd15b048SBenjamin Herrenschmidt #include <linux/pci.h> 30fb5153d0SGautham R. Shenoy #include <linux/cpufreq.h> 3155190f88SBenjamin Herrenschmidt 3255190f88SBenjamin Herrenschmidt #include <asm/machdep.h> 3355190f88SBenjamin Herrenschmidt #include <asm/firmware.h> 3455190f88SBenjamin Herrenschmidt #include <asm/xics.h> 35243e2511SBenjamin Herrenschmidt #include <asm/xive.h> 36daea1175SBenjamin Herrenschmidt #include <asm/opal.h> 3713906db6SBenjamin Herrenschmidt #include <asm/kexec.h> 38b2a80878SShreyas B. Prabhu #include <asm/smp.h> 3954820530SMichael Ellerman #include <asm/tm.h> 406e032b35SOliver O'Halloran #include <asm/setup.h> 4177addf6eSMichael Ellerman #include <asm/security_features.h> 4255190f88SBenjamin Herrenschmidt 4355190f88SBenjamin Herrenschmidt #include "powernv.h" 4455190f88SBenjamin Herrenschmidt 4577addf6eSMichael Ellerman 4677addf6eSMichael Ellerman static bool fw_feature_is(const char *state, const char *name, 4777addf6eSMichael Ellerman struct device_node *fw_features) 4877addf6eSMichael Ellerman { 4977addf6eSMichael Ellerman struct device_node *np; 5077addf6eSMichael Ellerman bool rc = false; 5177addf6eSMichael Ellerman 5277addf6eSMichael Ellerman np = of_get_child_by_name(fw_features, name); 5377addf6eSMichael Ellerman if (np) { 5477addf6eSMichael Ellerman rc = of_property_read_bool(np, state); 5577addf6eSMichael Ellerman of_node_put(np); 5677addf6eSMichael Ellerman } 5777addf6eSMichael Ellerman 5877addf6eSMichael Ellerman return rc; 5977addf6eSMichael Ellerman } 6077addf6eSMichael Ellerman 6177addf6eSMichael Ellerman static void init_fw_feat_flags(struct device_node *np) 6277addf6eSMichael Ellerman { 6377addf6eSMichael Ellerman if (fw_feature_is("enabled", "inst-spec-barrier-ori31,31,0", np)) 6477addf6eSMichael Ellerman security_ftr_set(SEC_FTR_SPEC_BAR_ORI31); 6577addf6eSMichael Ellerman 6677addf6eSMichael Ellerman if (fw_feature_is("enabled", "fw-bcctrl-serialized", np)) 6777addf6eSMichael Ellerman security_ftr_set(SEC_FTR_BCCTRL_SERIALISED); 6877addf6eSMichael Ellerman 6937c0bdd0SMichael Ellerman if (fw_feature_is("enabled", "inst-l1d-flush-ori30,30,0", np)) 7077addf6eSMichael Ellerman security_ftr_set(SEC_FTR_L1D_FLUSH_ORI30); 7177addf6eSMichael Ellerman 7277addf6eSMichael Ellerman if (fw_feature_is("enabled", "inst-l1d-flush-trig2", np)) 7377addf6eSMichael Ellerman security_ftr_set(SEC_FTR_L1D_FLUSH_TRIG2); 7477addf6eSMichael Ellerman 7577addf6eSMichael Ellerman if (fw_feature_is("enabled", "fw-l1d-thread-split", np)) 7677addf6eSMichael Ellerman security_ftr_set(SEC_FTR_L1D_THREAD_PRIV); 7777addf6eSMichael Ellerman 7877addf6eSMichael Ellerman if (fw_feature_is("enabled", "fw-count-cache-disabled", np)) 7977addf6eSMichael Ellerman security_ftr_set(SEC_FTR_COUNT_CACHE_DISABLED); 8077addf6eSMichael Ellerman 8199d54754SMichael Ellerman if (fw_feature_is("enabled", "fw-count-cache-flush-bcctr2,0,0", np)) 8299d54754SMichael Ellerman security_ftr_set(SEC_FTR_BCCTR_FLUSH_ASSIST); 8399d54754SMichael Ellerman 8499d54754SMichael Ellerman if (fw_feature_is("enabled", "needs-count-cache-flush-on-context-switch", np)) 8599d54754SMichael Ellerman security_ftr_set(SEC_FTR_FLUSH_COUNT_CACHE); 8699d54754SMichael Ellerman 8777addf6eSMichael Ellerman /* 8877addf6eSMichael Ellerman * The features below are enabled by default, so we instead look to see 8977addf6eSMichael Ellerman * if firmware has *disabled* them, and clear them if so. 9077addf6eSMichael Ellerman */ 9177addf6eSMichael Ellerman if (fw_feature_is("disabled", "speculation-policy-favor-security", np)) 9277addf6eSMichael Ellerman security_ftr_clear(SEC_FTR_FAVOUR_SECURITY); 9377addf6eSMichael Ellerman 9477addf6eSMichael Ellerman if (fw_feature_is("disabled", "needs-l1d-flush-msr-pr-0-to-1", np)) 9577addf6eSMichael Ellerman security_ftr_clear(SEC_FTR_L1D_FLUSH_PR); 9677addf6eSMichael Ellerman 9777addf6eSMichael Ellerman if (fw_feature_is("disabled", "needs-l1d-flush-msr-hv-1-to-0", np)) 9877addf6eSMichael Ellerman security_ftr_clear(SEC_FTR_L1D_FLUSH_HV); 9977addf6eSMichael Ellerman 10077addf6eSMichael Ellerman if (fw_feature_is("disabled", "needs-spec-barrier-for-bound-checks", np)) 10177addf6eSMichael Ellerman security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR); 10277addf6eSMichael Ellerman } 10377addf6eSMichael Ellerman 1046e032b35SOliver O'Halloran static void pnv_setup_rfi_flush(void) 1056e032b35SOliver O'Halloran { 1066e032b35SOliver O'Halloran struct device_node *np, *fw_features; 1076e032b35SOliver O'Halloran enum l1d_flush_type type; 10837c0bdd0SMichael Ellerman bool enable; 1096e032b35SOliver O'Halloran 1106e032b35SOliver O'Halloran /* Default to fallback in case fw-features are not available */ 1116e032b35SOliver O'Halloran type = L1D_FLUSH_FALLBACK; 1126e032b35SOliver O'Halloran 1136e032b35SOliver O'Halloran np = of_find_node_by_name(NULL, "ibm,opal"); 1146e032b35SOliver O'Halloran fw_features = of_get_child_by_name(np, "fw-features"); 1156e032b35SOliver O'Halloran of_node_put(np); 1166e032b35SOliver O'Halloran 1176e032b35SOliver O'Halloran if (fw_features) { 11877addf6eSMichael Ellerman init_fw_feat_flags(fw_features); 11937c0bdd0SMichael Ellerman of_node_put(fw_features); 12077addf6eSMichael Ellerman 12137c0bdd0SMichael Ellerman if (security_ftr_enabled(SEC_FTR_L1D_FLUSH_TRIG2)) 1226e032b35SOliver O'Halloran type = L1D_FLUSH_MTTRIG; 1236e032b35SOliver O'Halloran 12437c0bdd0SMichael Ellerman if (security_ftr_enabled(SEC_FTR_L1D_FLUSH_ORI30)) 1256e032b35SOliver O'Halloran type = L1D_FLUSH_ORI; 1266e032b35SOliver O'Halloran } 1276e032b35SOliver O'Halloran 12837c0bdd0SMichael Ellerman enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && \ 12937c0bdd0SMichael Ellerman (security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR) || \ 13037c0bdd0SMichael Ellerman security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV)); 13137c0bdd0SMichael Ellerman 13237c0bdd0SMichael Ellerman setup_rfi_flush(type, enable); 13399d54754SMichael Ellerman setup_count_cache_flush(); 1346e032b35SOliver O'Halloran } 1356e032b35SOliver O'Halloran 13655190f88SBenjamin Herrenschmidt static void __init pnv_setup_arch(void) 13755190f88SBenjamin Herrenschmidt { 1384817fc32SAnton Blanchard set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT); 1394817fc32SAnton Blanchard 1406e032b35SOliver O'Halloran pnv_setup_rfi_flush(); 141a048a07dSNicholas Piggin setup_stf_barrier(); 1426e032b35SOliver O'Halloran 14355190f88SBenjamin Herrenschmidt /* Initialize SMP */ 14455190f88SBenjamin Herrenschmidt pnv_smp_init(); 14555190f88SBenjamin Herrenschmidt 14661305a96SBenjamin Herrenschmidt /* Setup PCI */ 14761305a96SBenjamin Herrenschmidt pnv_pci_init(); 14855190f88SBenjamin Herrenschmidt 149628daa8dSBenjamin Herrenschmidt /* Setup RTC and NVRAM callbacks */ 150628daa8dSBenjamin Herrenschmidt if (firmware_has_feature(FW_FEATURE_OPAL)) 151628daa8dSBenjamin Herrenschmidt opal_nvram_init(); 15255190f88SBenjamin Herrenschmidt 15355190f88SBenjamin Herrenschmidt /* Enable NAP mode */ 15455190f88SBenjamin Herrenschmidt powersave_nap = 1; 15555190f88SBenjamin Herrenschmidt 15655190f88SBenjamin Herrenschmidt /* XXX PMCS */ 15755190f88SBenjamin Herrenschmidt } 15855190f88SBenjamin Herrenschmidt 159f2d57694SBenjamin Herrenschmidt static void __init pnv_init(void) 16055190f88SBenjamin Herrenschmidt { 1613fafe9c2SBenjamin Herrenschmidt /* 1623fafe9c2SBenjamin Herrenschmidt * Initialize the LPC bus now so that legacy serial 1633fafe9c2SBenjamin Herrenschmidt * ports can be found on it 1643fafe9c2SBenjamin Herrenschmidt */ 1653fafe9c2SBenjamin Herrenschmidt opal_lpc_init(); 1663fafe9c2SBenjamin Herrenschmidt 167daea1175SBenjamin Herrenschmidt #ifdef CONFIG_HVC_OPAL 168daea1175SBenjamin Herrenschmidt if (firmware_has_feature(FW_FEATURE_OPAL)) 169daea1175SBenjamin Herrenschmidt hvc_opal_init_early(); 170daea1175SBenjamin Herrenschmidt else 171daea1175SBenjamin Herrenschmidt #endif 172daea1175SBenjamin Herrenschmidt add_preferred_console("hvc", 0, NULL); 17355190f88SBenjamin Herrenschmidt } 17455190f88SBenjamin Herrenschmidt 17555190f88SBenjamin Herrenschmidt static void __init pnv_init_IRQ(void) 17655190f88SBenjamin Herrenschmidt { 177243e2511SBenjamin Herrenschmidt /* Try using a XIVE if available, otherwise use a XICS */ 178243e2511SBenjamin Herrenschmidt if (!xive_native_init()) 17955190f88SBenjamin Herrenschmidt xics_init(); 18055190f88SBenjamin Herrenschmidt 18155190f88SBenjamin Herrenschmidt WARN_ON(!ppc_md.get_irq); 18255190f88SBenjamin Herrenschmidt } 18355190f88SBenjamin Herrenschmidt 18455190f88SBenjamin Herrenschmidt static void pnv_show_cpuinfo(struct seq_file *m) 18555190f88SBenjamin Herrenschmidt { 18655190f88SBenjamin Herrenschmidt struct device_node *root; 18755190f88SBenjamin Herrenschmidt const char *model = ""; 18855190f88SBenjamin Herrenschmidt 18955190f88SBenjamin Herrenschmidt root = of_find_node_by_path("/"); 19055190f88SBenjamin Herrenschmidt if (root) 19155190f88SBenjamin Herrenschmidt model = of_get_property(root, "model", NULL); 19255190f88SBenjamin Herrenschmidt seq_printf(m, "machine\t\t: PowerNV %s\n", model); 193e4d54f71SStewart Smith if (firmware_has_feature(FW_FEATURE_OPAL)) 194e4d54f71SStewart Smith seq_printf(m, "firmware\t: OPAL\n"); 19514a43e69SBenjamin Herrenschmidt else 19614a43e69SBenjamin Herrenschmidt seq_printf(m, "firmware\t: BML\n"); 19755190f88SBenjamin Herrenschmidt of_node_put(root); 1983a4c2601SAneesh Kumar K.V if (radix_enabled()) 1993a4c2601SAneesh Kumar K.V seq_printf(m, "MMU\t\t: Radix\n"); 2003a4c2601SAneesh Kumar K.V else 2013a4c2601SAneesh Kumar K.V seq_printf(m, "MMU\t\t: Hash\n"); 20255190f88SBenjamin Herrenschmidt } 20355190f88SBenjamin Herrenschmidt 2042196c6f1SVasant Hegde static void pnv_prepare_going_down(void) 2052196c6f1SVasant Hegde { 2062196c6f1SVasant Hegde /* 2072196c6f1SVasant Hegde * Disable all notifiers from OPAL, we can't 2082196c6f1SVasant Hegde * service interrupts anymore anyway 2092196c6f1SVasant Hegde */ 21081f2f7ceSAlistair Popple opal_event_shutdown(); 2112196c6f1SVasant Hegde 212f2748bdfSNicholas Piggin /* Print flash update message if one is scheduled. */ 213f2748bdfSNicholas Piggin opal_flash_update_print_message(); 2142196c6f1SVasant Hegde 215f2748bdfSNicholas Piggin smp_send_stop(); 216f2748bdfSNicholas Piggin 217f2748bdfSNicholas Piggin hard_irq_disable(); 2182196c6f1SVasant Hegde } 2192196c6f1SVasant Hegde 220ec27329fSBenjamin Herrenschmidt static void __noreturn pnv_restart(char *cmd) 22155190f88SBenjamin Herrenschmidt { 222*8139046aSVaibhav Jain long rc; 223ec27329fSBenjamin Herrenschmidt 2242196c6f1SVasant Hegde pnv_prepare_going_down(); 225e8e71fa4SGavin Shan 226*8139046aSVaibhav Jain do { 227*8139046aSVaibhav Jain if (!cmd) 228ec27329fSBenjamin Herrenschmidt rc = opal_cec_reboot(); 229*8139046aSVaibhav Jain else if (strcmp(cmd, "full") == 0) 230*8139046aSVaibhav Jain rc = opal_cec_reboot2(OPAL_REBOOT_FULL_IPL, NULL); 231ec27329fSBenjamin Herrenschmidt else 232*8139046aSVaibhav Jain rc = OPAL_UNSUPPORTED; 233*8139046aSVaibhav Jain 234*8139046aSVaibhav Jain if (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { 235*8139046aSVaibhav Jain /* Opal is busy wait for some time and retry */ 236*8139046aSVaibhav Jain opal_poll_events(NULL); 237ec27329fSBenjamin Herrenschmidt mdelay(10); 238*8139046aSVaibhav Jain 239*8139046aSVaibhav Jain } else if (cmd && rc) { 240*8139046aSVaibhav Jain /* Unknown error while issuing reboot */ 241*8139046aSVaibhav Jain if (rc == OPAL_UNSUPPORTED) 242*8139046aSVaibhav Jain pr_err("Unsupported '%s' reboot.\n", cmd); 243*8139046aSVaibhav Jain else 244*8139046aSVaibhav Jain pr_err("Unable to issue '%s' reboot. Err=%ld\n", 245*8139046aSVaibhav Jain cmd, rc); 246*8139046aSVaibhav Jain pr_info("Forcing a cec-reboot\n"); 247*8139046aSVaibhav Jain cmd = NULL; 248*8139046aSVaibhav Jain rc = OPAL_BUSY; 249*8139046aSVaibhav Jain 250*8139046aSVaibhav Jain } else if (rc != OPAL_SUCCESS) { 251*8139046aSVaibhav Jain /* Unknown error while issuing cec-reboot */ 252*8139046aSVaibhav Jain pr_err("Unable to reboot. Err=%ld\n", rc); 253ec27329fSBenjamin Herrenschmidt } 254*8139046aSVaibhav Jain 255*8139046aSVaibhav Jain } while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT); 256*8139046aSVaibhav Jain 257ec27329fSBenjamin Herrenschmidt for (;;) 258ec27329fSBenjamin Herrenschmidt opal_poll_events(NULL); 25955190f88SBenjamin Herrenschmidt } 26055190f88SBenjamin Herrenschmidt 261ec27329fSBenjamin Herrenschmidt static void __noreturn pnv_power_off(void) 26255190f88SBenjamin Herrenschmidt { 263ec27329fSBenjamin Herrenschmidt long rc = OPAL_BUSY; 264ec27329fSBenjamin Herrenschmidt 2652196c6f1SVasant Hegde pnv_prepare_going_down(); 266e8e71fa4SGavin Shan 267ec27329fSBenjamin Herrenschmidt while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { 268ec27329fSBenjamin Herrenschmidt rc = opal_cec_power_down(0); 269ec27329fSBenjamin Herrenschmidt if (rc == OPAL_BUSY_EVENT) 270ec27329fSBenjamin Herrenschmidt opal_poll_events(NULL); 271ec27329fSBenjamin Herrenschmidt else 272ec27329fSBenjamin Herrenschmidt mdelay(10); 273ec27329fSBenjamin Herrenschmidt } 274ec27329fSBenjamin Herrenschmidt for (;;) 275ec27329fSBenjamin Herrenschmidt opal_poll_events(NULL); 27655190f88SBenjamin Herrenschmidt } 27755190f88SBenjamin Herrenschmidt 278ec27329fSBenjamin Herrenschmidt static void __noreturn pnv_halt(void) 27955190f88SBenjamin Herrenschmidt { 280ec27329fSBenjamin Herrenschmidt pnv_power_off(); 28155190f88SBenjamin Herrenschmidt } 28255190f88SBenjamin Herrenschmidt 28355190f88SBenjamin Herrenschmidt static void pnv_progress(char *s, unsigned short hex) 28455190f88SBenjamin Herrenschmidt { 28555190f88SBenjamin Herrenschmidt } 28655190f88SBenjamin Herrenschmidt 28773ed148aSBenjamin Herrenschmidt static void pnv_shutdown(void) 28873ed148aSBenjamin Herrenschmidt { 28973ed148aSBenjamin Herrenschmidt /* Let the PCI code clear up IODA tables */ 29073ed148aSBenjamin Herrenschmidt pnv_pci_shutdown(); 29173ed148aSBenjamin Herrenschmidt 292f7d98d18SVasant Hegde /* 293f7d98d18SVasant Hegde * Stop OPAL activity: Unregister all OPAL interrupts so they 294f7d98d18SVasant Hegde * don't fire up while we kexec and make sure all potentially 295f7d98d18SVasant Hegde * DMA'ing ops are complete (such as dump retrieval). 29673ed148aSBenjamin Herrenschmidt */ 29773ed148aSBenjamin Herrenschmidt opal_shutdown(); 29873ed148aSBenjamin Herrenschmidt } 29973ed148aSBenjamin Herrenschmidt 300da665885SThiago Jung Bauermann #ifdef CONFIG_KEXEC_CORE 301298b34d7SBenjamin Herrenschmidt static void pnv_kexec_wait_secondaries_down(void) 302298b34d7SBenjamin Herrenschmidt { 303298b34d7SBenjamin Herrenschmidt int my_cpu, i, notified = -1; 304298b34d7SBenjamin Herrenschmidt 305298b34d7SBenjamin Herrenschmidt my_cpu = get_cpu(); 306298b34d7SBenjamin Herrenschmidt 307298b34d7SBenjamin Herrenschmidt for_each_online_cpu(i) { 308298b34d7SBenjamin Herrenschmidt uint8_t status; 3091b70386cSSamuel Mendoza-Jonas int64_t rc, timeout = 1000; 310298b34d7SBenjamin Herrenschmidt 311298b34d7SBenjamin Herrenschmidt if (i == my_cpu) 312298b34d7SBenjamin Herrenschmidt continue; 313298b34d7SBenjamin Herrenschmidt 314298b34d7SBenjamin Herrenschmidt for (;;) { 315298b34d7SBenjamin Herrenschmidt rc = opal_query_cpu_status(get_hard_smp_processor_id(i), 316298b34d7SBenjamin Herrenschmidt &status); 317298b34d7SBenjamin Herrenschmidt if (rc != OPAL_SUCCESS || status != OPAL_THREAD_STARTED) 318298b34d7SBenjamin Herrenschmidt break; 319298b34d7SBenjamin Herrenschmidt barrier(); 320298b34d7SBenjamin Herrenschmidt if (i != notified) { 321298b34d7SBenjamin Herrenschmidt printk(KERN_INFO "kexec: waiting for cpu %d " 322298b34d7SBenjamin Herrenschmidt "(physical %d) to enter OPAL\n", 323d2e60075SNicholas Piggin i, paca_ptrs[i]->hw_cpu_id); 324298b34d7SBenjamin Herrenschmidt notified = i; 325298b34d7SBenjamin Herrenschmidt } 3261b70386cSSamuel Mendoza-Jonas 3271b70386cSSamuel Mendoza-Jonas /* 3281b70386cSSamuel Mendoza-Jonas * On crash secondaries might be unreachable or hung, 3291b70386cSSamuel Mendoza-Jonas * so timeout if we've waited too long 3301b70386cSSamuel Mendoza-Jonas * */ 3311b70386cSSamuel Mendoza-Jonas mdelay(1); 3321b70386cSSamuel Mendoza-Jonas if (timeout-- == 0) { 3331b70386cSSamuel Mendoza-Jonas printk(KERN_ERR "kexec: timed out waiting for " 3341b70386cSSamuel Mendoza-Jonas "cpu %d (physical %d) to enter OPAL\n", 335d2e60075SNicholas Piggin i, paca_ptrs[i]->hw_cpu_id); 3361b70386cSSamuel Mendoza-Jonas break; 3371b70386cSSamuel Mendoza-Jonas } 338298b34d7SBenjamin Herrenschmidt } 339298b34d7SBenjamin Herrenschmidt } 340298b34d7SBenjamin Herrenschmidt } 341298b34d7SBenjamin Herrenschmidt 34255190f88SBenjamin Herrenschmidt static void pnv_kexec_cpu_down(int crash_shutdown, int secondary) 34355190f88SBenjamin Herrenschmidt { 3441c0eaf0fSBenjamin Herrenschmidt u64 reinit_flags; 3451c0eaf0fSBenjamin Herrenschmidt 346243e2511SBenjamin Herrenschmidt if (xive_enabled()) 347e27e0a94SBenjamin Herrenschmidt xive_teardown_cpu(); 348243e2511SBenjamin Herrenschmidt else 34955190f88SBenjamin Herrenschmidt xics_kexec_teardown_cpu(secondary); 35013906db6SBenjamin Herrenschmidt 351e4d54f71SStewart Smith /* On OPAL, we return all CPUs to firmware */ 352e4d54f71SStewart Smith if (!firmware_has_feature(FW_FEATURE_OPAL)) 353298b34d7SBenjamin Herrenschmidt return; 354298b34d7SBenjamin Herrenschmidt 355298b34d7SBenjamin Herrenschmidt if (secondary) { 35613906db6SBenjamin Herrenschmidt /* Return secondary CPUs to firmware on OPAL v3 */ 35713906db6SBenjamin Herrenschmidt mb(); 35813906db6SBenjamin Herrenschmidt get_paca()->kexec_state = KEXEC_STATE_REAL_MODE; 35913906db6SBenjamin Herrenschmidt mb(); 36013906db6SBenjamin Herrenschmidt 36113906db6SBenjamin Herrenschmidt /* Return the CPU to OPAL */ 36213906db6SBenjamin Herrenschmidt opal_return_cpu(); 363298b34d7SBenjamin Herrenschmidt } else { 364298b34d7SBenjamin Herrenschmidt /* Primary waits for the secondaries to have reached OPAL */ 365298b34d7SBenjamin Herrenschmidt pnv_kexec_wait_secondaries_down(); 366e72bb8a5SSamuel Mendoza-Jonas 367243e2511SBenjamin Herrenschmidt /* Switch XIVE back to emulation mode */ 368243e2511SBenjamin Herrenschmidt if (xive_enabled()) 369243e2511SBenjamin Herrenschmidt xive_shutdown(); 370243e2511SBenjamin Herrenschmidt 371e72bb8a5SSamuel Mendoza-Jonas /* 372e72bb8a5SSamuel Mendoza-Jonas * We might be running as little-endian - now that interrupts 373e72bb8a5SSamuel Mendoza-Jonas * are disabled, reset the HILE bit to big-endian so we don't 374e72bb8a5SSamuel Mendoza-Jonas * take interrupts in the wrong endian later 3751c0eaf0fSBenjamin Herrenschmidt * 3761c0eaf0fSBenjamin Herrenschmidt * We reinit to enable both radix and hash on P9 to ensure 3771c0eaf0fSBenjamin Herrenschmidt * the mode used by the next kernel is always supported. 378e72bb8a5SSamuel Mendoza-Jonas */ 3791c0eaf0fSBenjamin Herrenschmidt reinit_flags = OPAL_REINIT_CPUS_HILE_BE; 3801c0eaf0fSBenjamin Herrenschmidt if (cpu_has_feature(CPU_FTR_ARCH_300)) 3811c0eaf0fSBenjamin Herrenschmidt reinit_flags |= OPAL_REINIT_CPUS_MMU_RADIX | 3821c0eaf0fSBenjamin Herrenschmidt OPAL_REINIT_CPUS_MMU_HASH; 3831c0eaf0fSBenjamin Herrenschmidt opal_reinit_cpus(reinit_flags); 38413906db6SBenjamin Herrenschmidt } 38555190f88SBenjamin Herrenschmidt } 386da665885SThiago Jung Bauermann #endif /* CONFIG_KEXEC_CORE */ 38755190f88SBenjamin Herrenschmidt 3886d97d7a2SAnton Blanchard #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE 3896d97d7a2SAnton Blanchard static unsigned long pnv_memory_block_size(void) 3906d97d7a2SAnton Blanchard { 3916d97d7a2SAnton Blanchard return 256UL * 1024 * 1024; 3926d97d7a2SAnton Blanchard } 3936d97d7a2SAnton Blanchard #endif 3946d97d7a2SAnton Blanchard 395628daa8dSBenjamin Herrenschmidt static void __init pnv_setup_machdep_opal(void) 396628daa8dSBenjamin Herrenschmidt { 397628daa8dSBenjamin Herrenschmidt ppc_md.get_boot_time = opal_get_boot_time; 398628daa8dSBenjamin Herrenschmidt ppc_md.restart = pnv_restart; 3999178ba29SAlexander Graf pm_power_off = pnv_power_off; 400628daa8dSBenjamin Herrenschmidt ppc_md.halt = pnv_halt; 401e36d0a2eSNicholas Piggin /* ppc_md.system_reset_exception gets filled in by pnv_smp_init() */ 402ed79ba9eSBenjamin Herrenschmidt ppc_md.machine_check_exception = opal_machine_check; 40355672ecfSMahesh Salgaonkar ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery; 4040869b6fdSMahesh Salgaonkar ppc_md.hmi_exception_early = opal_hmi_exception_early; 4050869b6fdSMahesh Salgaonkar ppc_md.handle_hmi_exception = opal_handle_hmi_exception; 406628daa8dSBenjamin Herrenschmidt } 407628daa8dSBenjamin Herrenschmidt 40855190f88SBenjamin Herrenschmidt static int __init pnv_probe(void) 40955190f88SBenjamin Herrenschmidt { 410406b0b6aSBenjamin Herrenschmidt if (!of_machine_is_compatible("ibm,powernv")) 41155190f88SBenjamin Herrenschmidt return 0; 41255190f88SBenjamin Herrenschmidt 413628daa8dSBenjamin Herrenschmidt if (firmware_has_feature(FW_FEATURE_OPAL)) 414628daa8dSBenjamin Herrenschmidt pnv_setup_machdep_opal(); 415628daa8dSBenjamin Herrenschmidt 41655190f88SBenjamin Herrenschmidt pr_debug("PowerNV detected !\n"); 41755190f88SBenjamin Herrenschmidt 418f2d57694SBenjamin Herrenschmidt pnv_init(); 419f2d57694SBenjamin Herrenschmidt 42055190f88SBenjamin Herrenschmidt return 1; 42155190f88SBenjamin Herrenschmidt } 42255190f88SBenjamin Herrenschmidt 42354820530SMichael Ellerman #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 42454820530SMichael Ellerman void __init pnv_tm_init(void) 42554820530SMichael Ellerman { 42654820530SMichael Ellerman if (!firmware_has_feature(FW_FEATURE_OPAL) || 42754820530SMichael Ellerman !pvr_version_is(PVR_POWER9) || 42854820530SMichael Ellerman early_cpu_has_feature(CPU_FTR_TM)) 42954820530SMichael Ellerman return; 43054820530SMichael Ellerman 43154820530SMichael Ellerman if (opal_reinit_cpus(OPAL_REINIT_CPUS_TM_SUSPEND_DISABLED) != OPAL_SUCCESS) 43254820530SMichael Ellerman return; 43354820530SMichael Ellerman 43454820530SMichael Ellerman pr_info("Enabling TM (Transactional Memory) with Suspend Disabled\n"); 43554820530SMichael Ellerman cur_cpu_spec->cpu_features |= CPU_FTR_TM; 43654820530SMichael Ellerman /* Make sure "normal" HTM is off (it should be) */ 43754820530SMichael Ellerman cur_cpu_spec->cpu_user_features2 &= ~PPC_FEATURE2_HTM; 43854820530SMichael Ellerman /* Turn on no suspend mode, and HTM no SC */ 43954820530SMichael Ellerman cur_cpu_spec->cpu_user_features2 |= PPC_FEATURE2_HTM_NO_SUSPEND | \ 44054820530SMichael Ellerman PPC_FEATURE2_HTM_NOSC; 44154820530SMichael Ellerman tm_suspend_disabled = true; 44254820530SMichael Ellerman } 44354820530SMichael Ellerman #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 44454820530SMichael Ellerman 445fb5153d0SGautham R. Shenoy /* 446fb5153d0SGautham R. Shenoy * Returns the cpu frequency for 'cpu' in Hz. This is used by 447fb5153d0SGautham R. Shenoy * /proc/cpuinfo 448fb5153d0SGautham R. Shenoy */ 449e51df2c1SAnton Blanchard static unsigned long pnv_get_proc_freq(unsigned int cpu) 450fb5153d0SGautham R. Shenoy { 451fb5153d0SGautham R. Shenoy unsigned long ret_freq; 452fb5153d0SGautham R. Shenoy 453cd77b5ceSShriya ret_freq = cpufreq_get(cpu) * 1000ul; 454fb5153d0SGautham R. Shenoy 455fb5153d0SGautham R. Shenoy /* 456fb5153d0SGautham R. Shenoy * If the backend cpufreq driver does not exist, 457fb5153d0SGautham R. Shenoy * then fallback to old way of reporting the clockrate. 458fb5153d0SGautham R. Shenoy */ 459fb5153d0SGautham R. Shenoy if (!ret_freq) 460fb5153d0SGautham R. Shenoy ret_freq = ppc_proc_freq; 461fb5153d0SGautham R. Shenoy return ret_freq; 462fb5153d0SGautham R. Shenoy } 463fb5153d0SGautham R. Shenoy 464a43c1590SMahesh Salgaonkar static long pnv_machine_check_early(struct pt_regs *regs) 465a43c1590SMahesh Salgaonkar { 466a43c1590SMahesh Salgaonkar long handled = 0; 467a43c1590SMahesh Salgaonkar 468a43c1590SMahesh Salgaonkar if (cur_cpu_spec && cur_cpu_spec->machine_check_early) 469a43c1590SMahesh Salgaonkar handled = cur_cpu_spec->machine_check_early(regs); 470a43c1590SMahesh Salgaonkar 471a43c1590SMahesh Salgaonkar return handled; 472a43c1590SMahesh Salgaonkar } 473a43c1590SMahesh Salgaonkar 47455190f88SBenjamin Herrenschmidt define_machine(powernv) { 47555190f88SBenjamin Herrenschmidt .name = "PowerNV", 47655190f88SBenjamin Herrenschmidt .probe = pnv_probe, 477628daa8dSBenjamin Herrenschmidt .setup_arch = pnv_setup_arch, 47855190f88SBenjamin Herrenschmidt .init_IRQ = pnv_init_IRQ, 47955190f88SBenjamin Herrenschmidt .show_cpuinfo = pnv_show_cpuinfo, 480fb5153d0SGautham R. Shenoy .get_proc_freq = pnv_get_proc_freq, 48155190f88SBenjamin Herrenschmidt .progress = pnv_progress, 48273ed148aSBenjamin Herrenschmidt .machine_shutdown = pnv_shutdown, 4835593e303SShreyas B. Prabhu .power_save = NULL, 48455190f88SBenjamin Herrenschmidt .calibrate_decr = generic_calibrate_decr, 485a43c1590SMahesh Salgaonkar .machine_check_early = pnv_machine_check_early, 486da665885SThiago Jung Bauermann #ifdef CONFIG_KEXEC_CORE 48755190f88SBenjamin Herrenschmidt .kexec_cpu_down = pnv_kexec_cpu_down, 48855190f88SBenjamin Herrenschmidt #endif 4896d97d7a2SAnton Blanchard #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE 4906d97d7a2SAnton Blanchard .memory_block_size = pnv_memory_block_size, 4916d97d7a2SAnton Blanchard #endif 49255190f88SBenjamin Herrenschmidt }; 493