123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- /*
- * PowerNV setup code.
- *
- * Copyright 2011 IBM Corp.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
- #undef DEBUG
- #include <linux/cpu.h>
- #include <linux/errno.h>
- #include <linux/sched.h>
- #include <linux/kernel.h>
- #include <linux/tty.h>
- #include <linux/reboot.h>
- #include <linux/init.h>
- #include <linux/console.h>
- #include <linux/delay.h>
- #include <linux/irq.h>
- #include <linux/seq_file.h>
- #include <linux/of.h>
- #include <linux/of_fdt.h>
- #include <linux/interrupt.h>
- #include <linux/bug.h>
- #include <linux/pci.h>
- #include <linux/cpufreq.h>
- #include <asm/machdep.h>
- #include <asm/firmware.h>
- #include <asm/xics.h>
- #include <asm/opal.h>
- #include <asm/kexec.h>
- #include <asm/smp.h>
- #include <asm/tm.h>
- #include <asm/setup.h>
- #include "powernv.h"
- static void pnv_setup_rfi_flush(void)
- {
- struct device_node *np, *fw_features;
- enum l1d_flush_type type;
- int enable;
- /* Default to fallback in case fw-features are not available */
- type = L1D_FLUSH_FALLBACK;
- enable = 1;
- np = of_find_node_by_name(NULL, "ibm,opal");
- fw_features = of_get_child_by_name(np, "fw-features");
- of_node_put(np);
- if (fw_features) {
- np = of_get_child_by_name(fw_features, "inst-l1d-flush-trig2");
- if (np && of_property_read_bool(np, "enabled"))
- type = L1D_FLUSH_MTTRIG;
- of_node_put(np);
- np = of_get_child_by_name(fw_features, "inst-l1d-flush-ori30,30,0");
- if (np && of_property_read_bool(np, "enabled"))
- type = L1D_FLUSH_ORI;
- of_node_put(np);
- /* Enable unless firmware says NOT to */
- enable = 2;
- np = of_get_child_by_name(fw_features, "needs-l1d-flush-msr-hv-1-to-0");
- if (np && of_property_read_bool(np, "disabled"))
- enable--;
- of_node_put(np);
- np = of_get_child_by_name(fw_features, "needs-l1d-flush-msr-pr-0-to-1");
- if (np && of_property_read_bool(np, "disabled"))
- enable--;
- of_node_put(np);
- of_node_put(fw_features);
- }
- setup_rfi_flush(type, enable > 0);
- }
- static void __init pnv_setup_arch(void)
- {
- set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
- pnv_setup_rfi_flush();
- /* Initialize SMP */
- pnv_smp_init();
- /* Setup PCI */
- pnv_pci_init();
- /* Setup RTC and NVRAM callbacks */
- if (firmware_has_feature(FW_FEATURE_OPAL))
- opal_nvram_init();
- /* Enable NAP mode */
- powersave_nap = 1;
- /* XXX PMCS */
- }
- static void __init pnv_init_early(void)
- {
- /*
- * Initialize the LPC bus now so that legacy serial
- * ports can be found on it
- */
- opal_lpc_init();
- #ifdef CONFIG_HVC_OPAL
- if (firmware_has_feature(FW_FEATURE_OPAL))
- hvc_opal_init_early();
- else
- #endif
- add_preferred_console("hvc", 0, NULL);
- }
- static void __init pnv_init_IRQ(void)
- {
- xics_init();
- WARN_ON(!ppc_md.get_irq);
- }
- static void pnv_show_cpuinfo(struct seq_file *m)
- {
- struct device_node *root;
- const char *model = "";
- root = of_find_node_by_path("/");
- if (root)
- model = of_get_property(root, "model", NULL);
- seq_printf(m, "machine\t\t: PowerNV %s\n", model);
- if (firmware_has_feature(FW_FEATURE_OPAL))
- seq_printf(m, "firmware\t: OPAL\n");
- else
- seq_printf(m, "firmware\t: BML\n");
- of_node_put(root);
- }
- static void pnv_prepare_going_down(void)
- {
- /*
- * Disable all notifiers from OPAL, we can't
- * service interrupts anymore anyway
- */
- opal_event_shutdown();
- /* Soft disable interrupts */
- local_irq_disable();
- /*
- * Return secondary CPUs to firwmare if a flash update
- * is pending otherwise we will get all sort of error
- * messages about CPU being stuck etc.. This will also
- * have the side effect of hard disabling interrupts so
- * past this point, the kernel is effectively dead.
- */
- opal_flash_term_callback();
- }
- static void __noreturn pnv_restart(char *cmd)
- {
- long rc = OPAL_BUSY;
- pnv_prepare_going_down();
- while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
- rc = opal_cec_reboot();
- if (rc == OPAL_BUSY_EVENT)
- opal_poll_events(NULL);
- else
- mdelay(10);
- }
- for (;;)
- opal_poll_events(NULL);
- }
- static void __noreturn pnv_power_off(void)
- {
- long rc = OPAL_BUSY;
- pnv_prepare_going_down();
- while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
- rc = opal_cec_power_down(0);
- if (rc == OPAL_BUSY_EVENT)
- opal_poll_events(NULL);
- else
- mdelay(10);
- }
- for (;;)
- opal_poll_events(NULL);
- }
- static void __noreturn pnv_halt(void)
- {
- pnv_power_off();
- }
- static void pnv_progress(char *s, unsigned short hex)
- {
- }
- static void pnv_shutdown(void)
- {
- /* Let the PCI code clear up IODA tables */
- pnv_pci_shutdown();
- /*
- * Stop OPAL activity: Unregister all OPAL interrupts so they
- * don't fire up while we kexec and make sure all potentially
- * DMA'ing ops are complete (such as dump retrieval).
- */
- opal_shutdown();
- }
- #ifdef CONFIG_KEXEC
- static void pnv_kexec_wait_secondaries_down(void)
- {
- int my_cpu, i, notified = -1;
- my_cpu = get_cpu();
- for_each_online_cpu(i) {
- uint8_t status;
- int64_t rc, timeout = 1000;
- if (i == my_cpu)
- continue;
- for (;;) {
- rc = opal_query_cpu_status(get_hard_smp_processor_id(i),
- &status);
- if (rc != OPAL_SUCCESS || status != OPAL_THREAD_STARTED)
- break;
- barrier();
- if (i != notified) {
- printk(KERN_INFO "kexec: waiting for cpu %d "
- "(physical %d) to enter OPAL\n",
- i, paca[i].hw_cpu_id);
- notified = i;
- }
- /*
- * On crash secondaries might be unreachable or hung,
- * so timeout if we've waited too long
- * */
- mdelay(1);
- if (timeout-- == 0) {
- printk(KERN_ERR "kexec: timed out waiting for "
- "cpu %d (physical %d) to enter OPAL\n",
- i, paca[i].hw_cpu_id);
- break;
- }
- }
- }
- }
- static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
- {
- xics_kexec_teardown_cpu(secondary);
- /* On OPAL, we return all CPUs to firmware */
- if (!firmware_has_feature(FW_FEATURE_OPAL))
- return;
- if (secondary) {
- /* Return secondary CPUs to firmware on OPAL v3 */
- mb();
- get_paca()->kexec_state = KEXEC_STATE_REAL_MODE;
- mb();
- /* Return the CPU to OPAL */
- opal_return_cpu();
- } else {
- /* Primary waits for the secondaries to have reached OPAL */
- pnv_kexec_wait_secondaries_down();
- /*
- * We might be running as little-endian - now that interrupts
- * are disabled, reset the HILE bit to big-endian so we don't
- * take interrupts in the wrong endian later
- */
- opal_reinit_cpus(OPAL_REINIT_CPUS_HILE_BE);
- }
- }
- #endif /* CONFIG_KEXEC */
- #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
- static unsigned long pnv_memory_block_size(void)
- {
- return 256UL * 1024 * 1024;
- }
- #endif
- static void __init pnv_setup_machdep_opal(void)
- {
- ppc_md.get_boot_time = opal_get_boot_time;
- ppc_md.restart = pnv_restart;
- pm_power_off = pnv_power_off;
- ppc_md.halt = pnv_halt;
- ppc_md.machine_check_exception = opal_machine_check;
- ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery;
- ppc_md.hmi_exception_early = opal_hmi_exception_early;
- ppc_md.handle_hmi_exception = opal_handle_hmi_exception;
- }
- static int __init pnv_probe(void)
- {
- unsigned long root = of_get_flat_dt_root();
- if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
- return 0;
- hpte_init_native();
- if (firmware_has_feature(FW_FEATURE_OPAL))
- pnv_setup_machdep_opal();
- pr_debug("PowerNV detected !\n");
- return 1;
- }
- /*
- * Returns the cpu frequency for 'cpu' in Hz. This is used by
- * /proc/cpuinfo
- */
- static unsigned long pnv_get_proc_freq(unsigned int cpu)
- {
- unsigned long ret_freq;
- ret_freq = cpufreq_get(cpu) * 1000ul;
- /*
- * If the backend cpufreq driver does not exist,
- * then fallback to old way of reporting the clockrate.
- */
- if (!ret_freq)
- ret_freq = ppc_proc_freq;
- return ret_freq;
- }
- define_machine(powernv) {
- .name = "PowerNV",
- .probe = pnv_probe,
- .init_early = pnv_init_early,
- .setup_arch = pnv_setup_arch,
- .init_IRQ = pnv_init_IRQ,
- .show_cpuinfo = pnv_show_cpuinfo,
- .get_proc_freq = pnv_get_proc_freq,
- .progress = pnv_progress,
- .machine_shutdown = pnv_shutdown,
- .power_save = power7_idle,
- .calibrate_decr = generic_calibrate_decr,
- #ifdef CONFIG_KEXEC
- .kexec_cpu_down = pnv_kexec_cpu_down,
- #endif
- #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
- .memory_block_size = pnv_memory_block_size,
- #endif
- };
|