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> 2655190f88SBenjamin Herrenschmidt #include <linux/interrupt.h> 2755190f88SBenjamin Herrenschmidt #include <linux/bug.h> 2855190f88SBenjamin Herrenschmidt 2955190f88SBenjamin Herrenschmidt #include <asm/machdep.h> 3055190f88SBenjamin Herrenschmidt #include <asm/firmware.h> 3155190f88SBenjamin Herrenschmidt #include <asm/xics.h> 32628daa8dSBenjamin Herrenschmidt #include <asm/rtas.h> 33daea1175SBenjamin Herrenschmidt #include <asm/opal.h> 34628daa8dSBenjamin Herrenschmidt #include <asm/xics.h> 3555190f88SBenjamin Herrenschmidt 3655190f88SBenjamin Herrenschmidt #include "powernv.h" 3755190f88SBenjamin Herrenschmidt 3855190f88SBenjamin Herrenschmidt static void __init pnv_setup_arch(void) 3955190f88SBenjamin Herrenschmidt { 4055190f88SBenjamin Herrenschmidt /* Initialize SMP */ 4155190f88SBenjamin Herrenschmidt pnv_smp_init(); 4255190f88SBenjamin Herrenschmidt 43*61305a96SBenjamin Herrenschmidt /* Setup PCI */ 44*61305a96SBenjamin Herrenschmidt pnv_pci_init(); 4555190f88SBenjamin Herrenschmidt 46628daa8dSBenjamin Herrenschmidt /* Setup RTC and NVRAM callbacks */ 47628daa8dSBenjamin Herrenschmidt if (firmware_has_feature(FW_FEATURE_OPAL)) 48628daa8dSBenjamin Herrenschmidt opal_nvram_init(); 4955190f88SBenjamin Herrenschmidt 5055190f88SBenjamin Herrenschmidt /* Enable NAP mode */ 5155190f88SBenjamin Herrenschmidt powersave_nap = 1; 5255190f88SBenjamin Herrenschmidt 5355190f88SBenjamin Herrenschmidt /* XXX PMCS */ 5455190f88SBenjamin Herrenschmidt } 5555190f88SBenjamin Herrenschmidt 5655190f88SBenjamin Herrenschmidt static void __init pnv_init_early(void) 5755190f88SBenjamin Herrenschmidt { 58daea1175SBenjamin Herrenschmidt #ifdef CONFIG_HVC_OPAL 59daea1175SBenjamin Herrenschmidt if (firmware_has_feature(FW_FEATURE_OPAL)) 60daea1175SBenjamin Herrenschmidt hvc_opal_init_early(); 61daea1175SBenjamin Herrenschmidt else 62daea1175SBenjamin Herrenschmidt #endif 63daea1175SBenjamin Herrenschmidt add_preferred_console("hvc", 0, NULL); 6455190f88SBenjamin Herrenschmidt } 6555190f88SBenjamin Herrenschmidt 6655190f88SBenjamin Herrenschmidt static void __init pnv_init_IRQ(void) 6755190f88SBenjamin Herrenschmidt { 6855190f88SBenjamin Herrenschmidt xics_init(); 6955190f88SBenjamin Herrenschmidt 7055190f88SBenjamin Herrenschmidt WARN_ON(!ppc_md.get_irq); 7155190f88SBenjamin Herrenschmidt } 7255190f88SBenjamin Herrenschmidt 7355190f88SBenjamin Herrenschmidt static void pnv_show_cpuinfo(struct seq_file *m) 7455190f88SBenjamin Herrenschmidt { 7555190f88SBenjamin Herrenschmidt struct device_node *root; 7655190f88SBenjamin Herrenschmidt const char *model = ""; 7755190f88SBenjamin Herrenschmidt 7855190f88SBenjamin Herrenschmidt root = of_find_node_by_path("/"); 7955190f88SBenjamin Herrenschmidt if (root) 8055190f88SBenjamin Herrenschmidt model = of_get_property(root, "model", NULL); 8155190f88SBenjamin Herrenschmidt seq_printf(m, "machine\t\t: PowerNV %s\n", model); 8214a43e69SBenjamin Herrenschmidt if (firmware_has_feature(FW_FEATURE_OPALv2)) 8314a43e69SBenjamin Herrenschmidt seq_printf(m, "firmware\t: OPAL v2\n"); 8414a43e69SBenjamin Herrenschmidt else if (firmware_has_feature(FW_FEATURE_OPAL)) 8514a43e69SBenjamin Herrenschmidt seq_printf(m, "firmware\t: OPAL v1\n"); 8614a43e69SBenjamin Herrenschmidt else 8714a43e69SBenjamin Herrenschmidt seq_printf(m, "firmware\t: BML\n"); 8855190f88SBenjamin Herrenschmidt of_node_put(root); 8955190f88SBenjamin Herrenschmidt } 9055190f88SBenjamin Herrenschmidt 91ec27329fSBenjamin Herrenschmidt static void __noreturn pnv_restart(char *cmd) 9255190f88SBenjamin Herrenschmidt { 93ec27329fSBenjamin Herrenschmidt long rc = OPAL_BUSY; 94ec27329fSBenjamin Herrenschmidt 95ec27329fSBenjamin Herrenschmidt while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { 96ec27329fSBenjamin Herrenschmidt rc = opal_cec_reboot(); 97ec27329fSBenjamin Herrenschmidt if (rc == OPAL_BUSY_EVENT) 98ec27329fSBenjamin Herrenschmidt opal_poll_events(NULL); 99ec27329fSBenjamin Herrenschmidt else 100ec27329fSBenjamin Herrenschmidt mdelay(10); 101ec27329fSBenjamin Herrenschmidt } 102ec27329fSBenjamin Herrenschmidt for (;;) 103ec27329fSBenjamin Herrenschmidt opal_poll_events(NULL); 10455190f88SBenjamin Herrenschmidt } 10555190f88SBenjamin Herrenschmidt 106ec27329fSBenjamin Herrenschmidt static void __noreturn pnv_power_off(void) 10755190f88SBenjamin Herrenschmidt { 108ec27329fSBenjamin Herrenschmidt long rc = OPAL_BUSY; 109ec27329fSBenjamin Herrenschmidt 110ec27329fSBenjamin Herrenschmidt while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { 111ec27329fSBenjamin Herrenschmidt rc = opal_cec_power_down(0); 112ec27329fSBenjamin Herrenschmidt if (rc == OPAL_BUSY_EVENT) 113ec27329fSBenjamin Herrenschmidt opal_poll_events(NULL); 114ec27329fSBenjamin Herrenschmidt else 115ec27329fSBenjamin Herrenschmidt mdelay(10); 116ec27329fSBenjamin Herrenschmidt } 117ec27329fSBenjamin Herrenschmidt for (;;) 118ec27329fSBenjamin Herrenschmidt opal_poll_events(NULL); 11955190f88SBenjamin Herrenschmidt } 12055190f88SBenjamin Herrenschmidt 121ec27329fSBenjamin Herrenschmidt static void __noreturn pnv_halt(void) 12255190f88SBenjamin Herrenschmidt { 123ec27329fSBenjamin Herrenschmidt pnv_power_off(); 12455190f88SBenjamin Herrenschmidt } 12555190f88SBenjamin Herrenschmidt 12655190f88SBenjamin Herrenschmidt static void pnv_progress(char *s, unsigned short hex) 12755190f88SBenjamin Herrenschmidt { 12855190f88SBenjamin Herrenschmidt } 12955190f88SBenjamin Herrenschmidt 13055190f88SBenjamin Herrenschmidt #ifdef CONFIG_KEXEC 13155190f88SBenjamin Herrenschmidt static void pnv_kexec_cpu_down(int crash_shutdown, int secondary) 13255190f88SBenjamin Herrenschmidt { 13355190f88SBenjamin Herrenschmidt xics_kexec_teardown_cpu(secondary); 13455190f88SBenjamin Herrenschmidt } 13555190f88SBenjamin Herrenschmidt #endif /* CONFIG_KEXEC */ 13655190f88SBenjamin Herrenschmidt 137628daa8dSBenjamin Herrenschmidt static void __init pnv_setup_machdep_opal(void) 138628daa8dSBenjamin Herrenschmidt { 139628daa8dSBenjamin Herrenschmidt ppc_md.get_boot_time = opal_get_boot_time; 140628daa8dSBenjamin Herrenschmidt ppc_md.get_rtc_time = opal_get_rtc_time; 141628daa8dSBenjamin Herrenschmidt ppc_md.set_rtc_time = opal_set_rtc_time; 142628daa8dSBenjamin Herrenschmidt ppc_md.restart = pnv_restart; 143628daa8dSBenjamin Herrenschmidt ppc_md.power_off = pnv_power_off; 144628daa8dSBenjamin Herrenschmidt ppc_md.halt = pnv_halt; 145ed79ba9eSBenjamin Herrenschmidt ppc_md.machine_check_exception = opal_machine_check; 146628daa8dSBenjamin Herrenschmidt } 147628daa8dSBenjamin Herrenschmidt 148628daa8dSBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV_RTAS 149628daa8dSBenjamin Herrenschmidt static void __init pnv_setup_machdep_rtas(void) 150628daa8dSBenjamin Herrenschmidt { 151628daa8dSBenjamin Herrenschmidt if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) { 152628daa8dSBenjamin Herrenschmidt ppc_md.get_boot_time = rtas_get_boot_time; 153628daa8dSBenjamin Herrenschmidt ppc_md.get_rtc_time = rtas_get_rtc_time; 154628daa8dSBenjamin Herrenschmidt ppc_md.set_rtc_time = rtas_set_rtc_time; 155628daa8dSBenjamin Herrenschmidt } 156628daa8dSBenjamin Herrenschmidt ppc_md.restart = rtas_restart; 157628daa8dSBenjamin Herrenschmidt ppc_md.power_off = rtas_power_off; 158628daa8dSBenjamin Herrenschmidt ppc_md.halt = rtas_halt; 159628daa8dSBenjamin Herrenschmidt } 160628daa8dSBenjamin Herrenschmidt #endif /* CONFIG_PPC_POWERNV_RTAS */ 161628daa8dSBenjamin Herrenschmidt 16255190f88SBenjamin Herrenschmidt static int __init pnv_probe(void) 16355190f88SBenjamin Herrenschmidt { 16455190f88SBenjamin Herrenschmidt unsigned long root = of_get_flat_dt_root(); 16555190f88SBenjamin Herrenschmidt 16655190f88SBenjamin Herrenschmidt if (!of_flat_dt_is_compatible(root, "ibm,powernv")) 16755190f88SBenjamin Herrenschmidt return 0; 16855190f88SBenjamin Herrenschmidt 16955190f88SBenjamin Herrenschmidt hpte_init_native(); 17055190f88SBenjamin Herrenschmidt 171628daa8dSBenjamin Herrenschmidt if (firmware_has_feature(FW_FEATURE_OPAL)) 172628daa8dSBenjamin Herrenschmidt pnv_setup_machdep_opal(); 173628daa8dSBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV_RTAS 174628daa8dSBenjamin Herrenschmidt else if (rtas.base) 175628daa8dSBenjamin Herrenschmidt pnv_setup_machdep_rtas(); 176628daa8dSBenjamin Herrenschmidt #endif /* CONFIG_PPC_POWERNV_RTAS */ 177628daa8dSBenjamin Herrenschmidt 17855190f88SBenjamin Herrenschmidt pr_debug("PowerNV detected !\n"); 17955190f88SBenjamin Herrenschmidt 18055190f88SBenjamin Herrenschmidt return 1; 18155190f88SBenjamin Herrenschmidt } 18255190f88SBenjamin Herrenschmidt 18355190f88SBenjamin Herrenschmidt define_machine(powernv) { 18455190f88SBenjamin Herrenschmidt .name = "PowerNV", 18555190f88SBenjamin Herrenschmidt .probe = pnv_probe, 18655190f88SBenjamin Herrenschmidt .init_early = pnv_init_early, 187628daa8dSBenjamin Herrenschmidt .setup_arch = pnv_setup_arch, 18855190f88SBenjamin Herrenschmidt .init_IRQ = pnv_init_IRQ, 18955190f88SBenjamin Herrenschmidt .show_cpuinfo = pnv_show_cpuinfo, 19055190f88SBenjamin Herrenschmidt .progress = pnv_progress, 19155190f88SBenjamin Herrenschmidt .power_save = power7_idle, 19255190f88SBenjamin Herrenschmidt .calibrate_decr = generic_calibrate_decr, 19355190f88SBenjamin Herrenschmidt #ifdef CONFIG_KEXEC 19455190f88SBenjamin Herrenschmidt .kexec_cpu_down = pnv_kexec_cpu_down, 19555190f88SBenjamin Herrenschmidt #endif 19655190f88SBenjamin Herrenschmidt }; 197