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> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/bug.h> |
| 28 | |
| 29 | #include <asm/machdep.h> |
| 30 | #include <asm/firmware.h> |
| 31 | #include <asm/xics.h> |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 32 | #include <asm/opal.h> |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 33 | |
| 34 | #include "powernv.h" |
| 35 | |
| 36 | static void __init pnv_setup_arch(void) |
| 37 | { |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 38 | /* Initialize SMP */ |
| 39 | pnv_smp_init(); |
| 40 | |
| 41 | /* XXX PCI */ |
| 42 | |
| 43 | /* XXX NVRAM */ |
| 44 | |
| 45 | /* Enable NAP mode */ |
| 46 | powersave_nap = 1; |
| 47 | |
| 48 | /* XXX PMCS */ |
| 49 | } |
| 50 | |
| 51 | static void __init pnv_init_early(void) |
| 52 | { |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 53 | #ifdef CONFIG_HVC_OPAL |
| 54 | if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 55 | hvc_opal_init_early(); |
| 56 | else |
| 57 | #endif |
| 58 | add_preferred_console("hvc", 0, NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static void __init pnv_init_IRQ(void) |
| 62 | { |
| 63 | xics_init(); |
| 64 | |
| 65 | WARN_ON(!ppc_md.get_irq); |
| 66 | } |
| 67 | |
| 68 | static void pnv_show_cpuinfo(struct seq_file *m) |
| 69 | { |
| 70 | struct device_node *root; |
| 71 | const char *model = ""; |
| 72 | |
| 73 | root = of_find_node_by_path("/"); |
| 74 | if (root) |
| 75 | model = of_get_property(root, "model", NULL); |
| 76 | seq_printf(m, "machine\t\t: PowerNV %s\n", model); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 77 | if (firmware_has_feature(FW_FEATURE_OPALv2)) |
| 78 | seq_printf(m, "firmware\t: OPAL v2\n"); |
| 79 | else if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 80 | seq_printf(m, "firmware\t: OPAL v1\n"); |
| 81 | else |
| 82 | seq_printf(m, "firmware\t: BML\n"); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 83 | of_node_put(root); |
| 84 | } |
| 85 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame^] | 86 | static void __noreturn pnv_restart(char *cmd) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 87 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame^] | 88 | long rc = OPAL_BUSY; |
| 89 | |
| 90 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
| 91 | rc = opal_cec_reboot(); |
| 92 | if (rc == OPAL_BUSY_EVENT) |
| 93 | opal_poll_events(NULL); |
| 94 | else |
| 95 | mdelay(10); |
| 96 | } |
| 97 | for (;;) |
| 98 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame^] | 101 | static void __noreturn pnv_power_off(void) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 102 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame^] | 103 | long rc = OPAL_BUSY; |
| 104 | |
| 105 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
| 106 | rc = opal_cec_power_down(0); |
| 107 | if (rc == OPAL_BUSY_EVENT) |
| 108 | opal_poll_events(NULL); |
| 109 | else |
| 110 | mdelay(10); |
| 111 | } |
| 112 | for (;;) |
| 113 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame^] | 116 | static void __noreturn pnv_halt(void) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 117 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame^] | 118 | pnv_power_off(); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static unsigned long __init pnv_get_boot_time(void) |
| 122 | { |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static void pnv_get_rtc_time(struct rtc_time *rtc_tm) |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | static int pnv_set_rtc_time(struct rtc_time *tm) |
| 131 | { |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static void pnv_progress(char *s, unsigned short hex) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | #ifdef CONFIG_KEXEC |
| 140 | static void pnv_kexec_cpu_down(int crash_shutdown, int secondary) |
| 141 | { |
| 142 | xics_kexec_teardown_cpu(secondary); |
| 143 | } |
| 144 | #endif /* CONFIG_KEXEC */ |
| 145 | |
| 146 | static int __init pnv_probe(void) |
| 147 | { |
| 148 | unsigned long root = of_get_flat_dt_root(); |
| 149 | |
| 150 | if (!of_flat_dt_is_compatible(root, "ibm,powernv")) |
| 151 | return 0; |
| 152 | |
| 153 | hpte_init_native(); |
| 154 | |
| 155 | pr_debug("PowerNV detected !\n"); |
| 156 | |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | define_machine(powernv) { |
| 161 | .name = "PowerNV", |
| 162 | .probe = pnv_probe, |
| 163 | .setup_arch = pnv_setup_arch, |
| 164 | .init_early = pnv_init_early, |
| 165 | .init_IRQ = pnv_init_IRQ, |
| 166 | .show_cpuinfo = pnv_show_cpuinfo, |
| 167 | .restart = pnv_restart, |
| 168 | .power_off = pnv_power_off, |
| 169 | .halt = pnv_halt, |
| 170 | .get_boot_time = pnv_get_boot_time, |
| 171 | .get_rtc_time = pnv_get_rtc_time, |
| 172 | .set_rtc_time = pnv_set_rtc_time, |
| 173 | .progress = pnv_progress, |
| 174 | .power_save = power7_idle, |
| 175 | .calibrate_decr = generic_calibrate_decr, |
| 176 | #ifdef CONFIG_KEXEC |
| 177 | .kexec_cpu_down = pnv_kexec_cpu_down, |
| 178 | #endif |
| 179 | }; |