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> |
Benjamin Herrenschmidt | cd15b04 | 2014-02-11 11:32:38 +1100 | [diff] [blame] | 29 | #include <linux/pci.h> |
Gautham R. Shenoy | fb5153d | 2014-03-11 17:01:19 +0530 | [diff] [blame] | 30 | #include <linux/cpufreq.h> |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 31 | |
| 32 | #include <asm/machdep.h> |
| 33 | #include <asm/firmware.h> |
| 34 | #include <asm/xics.h> |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 35 | #include <asm/rtas.h> |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 36 | #include <asm/opal.h> |
Benjamin Herrenschmidt | 13906db | 2013-08-21 13:03:20 +1000 | [diff] [blame] | 37 | #include <asm/kexec.h> |
Shreyas B. Prabhu | b2a8087 | 2014-06-06 15:51:05 +0530 | [diff] [blame] | 38 | #include <asm/smp.h> |
Shreyas B. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 39 | #include <asm/cputhreads.h> |
| 40 | #include <asm/cpuidle.h> |
| 41 | #include <asm/code-patching.h> |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 42 | |
| 43 | #include "powernv.h" |
Shreyas B. Prabhu | 77b54e9 | 2014-12-10 00:26:53 +0530 | [diff] [blame] | 44 | #include "subcore.h" |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 45 | |
| 46 | static void __init pnv_setup_arch(void) |
| 47 | { |
Anton Blanchard | 4817fc3 | 2014-05-01 07:20:04 +1000 | [diff] [blame] | 48 | set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT); |
| 49 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 50 | /* Initialize SMP */ |
| 51 | pnv_smp_init(); |
| 52 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 53 | /* Setup PCI */ |
| 54 | pnv_pci_init(); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 55 | |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 56 | /* Setup RTC and NVRAM callbacks */ |
| 57 | if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 58 | opal_nvram_init(); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 59 | |
| 60 | /* Enable NAP mode */ |
| 61 | powersave_nap = 1; |
| 62 | |
| 63 | /* XXX PMCS */ |
| 64 | } |
| 65 | |
| 66 | static void __init pnv_init_early(void) |
| 67 | { |
Benjamin Herrenschmidt | 3fafe9c | 2013-07-15 13:03:11 +1000 | [diff] [blame] | 68 | /* |
| 69 | * Initialize the LPC bus now so that legacy serial |
| 70 | * ports can be found on it |
| 71 | */ |
| 72 | opal_lpc_init(); |
| 73 | |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 74 | #ifdef CONFIG_HVC_OPAL |
| 75 | if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 76 | hvc_opal_init_early(); |
| 77 | else |
| 78 | #endif |
| 79 | add_preferred_console("hvc", 0, NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void __init pnv_init_IRQ(void) |
| 83 | { |
| 84 | xics_init(); |
| 85 | |
| 86 | WARN_ON(!ppc_md.get_irq); |
| 87 | } |
| 88 | |
| 89 | static void pnv_show_cpuinfo(struct seq_file *m) |
| 90 | { |
| 91 | struct device_node *root; |
| 92 | const char *model = ""; |
| 93 | |
| 94 | root = of_find_node_by_path("/"); |
| 95 | if (root) |
| 96 | model = of_get_property(root, "model", NULL); |
| 97 | seq_printf(m, "machine\t\t: PowerNV %s\n", model); |
Benjamin Herrenschmidt | 75b93da | 2013-05-14 15:10:02 +1000 | [diff] [blame] | 98 | if (firmware_has_feature(FW_FEATURE_OPALv3)) |
| 99 | seq_printf(m, "firmware\t: OPAL v3\n"); |
| 100 | else if (firmware_has_feature(FW_FEATURE_OPALv2)) |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 101 | seq_printf(m, "firmware\t: OPAL v2\n"); |
| 102 | else if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 103 | seq_printf(m, "firmware\t: OPAL v1\n"); |
| 104 | else |
| 105 | seq_printf(m, "firmware\t: BML\n"); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 106 | of_node_put(root); |
| 107 | } |
| 108 | |
Vasant Hegde | 2196c6f | 2014-04-09 22:48:55 +0530 | [diff] [blame] | 109 | static void pnv_prepare_going_down(void) |
| 110 | { |
| 111 | /* |
| 112 | * Disable all notifiers from OPAL, we can't |
| 113 | * service interrupts anymore anyway |
| 114 | */ |
| 115 | opal_notifier_disable(); |
| 116 | |
| 117 | /* Soft disable interrupts */ |
| 118 | local_irq_disable(); |
| 119 | |
| 120 | /* |
| 121 | * Return secondary CPUs to firwmare if a flash update |
| 122 | * is pending otherwise we will get all sort of error |
| 123 | * messages about CPU being stuck etc.. This will also |
| 124 | * have the side effect of hard disabling interrupts so |
| 125 | * past this point, the kernel is effectively dead. |
| 126 | */ |
| 127 | opal_flash_term_callback(); |
| 128 | } |
| 129 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 130 | static void __noreturn pnv_restart(char *cmd) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 131 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 132 | long rc = OPAL_BUSY; |
| 133 | |
Vasant Hegde | 2196c6f | 2014-04-09 22:48:55 +0530 | [diff] [blame] | 134 | pnv_prepare_going_down(); |
Gavin Shan | e8e71fa | 2013-06-20 18:13:23 +0800 | [diff] [blame] | 135 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 136 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
| 137 | rc = opal_cec_reboot(); |
| 138 | if (rc == OPAL_BUSY_EVENT) |
| 139 | opal_poll_events(NULL); |
| 140 | else |
| 141 | mdelay(10); |
| 142 | } |
| 143 | for (;;) |
| 144 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 147 | static void __noreturn pnv_power_off(void) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 148 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 149 | long rc = OPAL_BUSY; |
| 150 | |
Vasant Hegde | 2196c6f | 2014-04-09 22:48:55 +0530 | [diff] [blame] | 151 | pnv_prepare_going_down(); |
Gavin Shan | e8e71fa | 2013-06-20 18:13:23 +0800 | [diff] [blame] | 152 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 153 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
| 154 | rc = opal_cec_power_down(0); |
| 155 | if (rc == OPAL_BUSY_EVENT) |
| 156 | opal_poll_events(NULL); |
| 157 | else |
| 158 | mdelay(10); |
| 159 | } |
| 160 | for (;;) |
| 161 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 164 | static void __noreturn pnv_halt(void) |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 165 | { |
Benjamin Herrenschmidt | ec27329 | 2011-09-19 18:28:03 +0000 | [diff] [blame] | 166 | pnv_power_off(); |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 169 | static void pnv_progress(char *s, unsigned short hex) |
| 170 | { |
| 171 | } |
| 172 | |
Benjamin Herrenschmidt | cd15b04 | 2014-02-11 11:32:38 +1100 | [diff] [blame] | 173 | static int pnv_dma_set_mask(struct device *dev, u64 dma_mask) |
| 174 | { |
| 175 | if (dev_is_pci(dev)) |
| 176 | return pnv_pci_dma_set_mask(to_pci_dev(dev), dma_mask); |
| 177 | return __dma_set_mask(dev, dma_mask); |
| 178 | } |
| 179 | |
Gavin Shan | fe7e85c | 2014-09-30 12:39:10 +1000 | [diff] [blame] | 180 | static u64 pnv_dma_get_required_mask(struct device *dev) |
| 181 | { |
| 182 | if (dev_is_pci(dev)) |
| 183 | return pnv_pci_dma_get_required_mask(to_pci_dev(dev)); |
| 184 | |
| 185 | return __dma_get_required_mask(dev); |
| 186 | } |
| 187 | |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 188 | static void pnv_shutdown(void) |
| 189 | { |
| 190 | /* Let the PCI code clear up IODA tables */ |
| 191 | pnv_pci_shutdown(); |
| 192 | |
Vasant Hegde | f7d98d1 | 2014-01-15 17:02:04 +1100 | [diff] [blame] | 193 | /* |
| 194 | * Stop OPAL activity: Unregister all OPAL interrupts so they |
| 195 | * don't fire up while we kexec and make sure all potentially |
| 196 | * DMA'ing ops are complete (such as dump retrieval). |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 197 | */ |
| 198 | opal_shutdown(); |
| 199 | } |
| 200 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 201 | #ifdef CONFIG_KEXEC |
Benjamin Herrenschmidt | 298b34d | 2014-04-24 16:14:25 +1000 | [diff] [blame] | 202 | static void pnv_kexec_wait_secondaries_down(void) |
| 203 | { |
| 204 | int my_cpu, i, notified = -1; |
| 205 | |
| 206 | my_cpu = get_cpu(); |
| 207 | |
| 208 | for_each_online_cpu(i) { |
| 209 | uint8_t status; |
| 210 | int64_t rc; |
| 211 | |
| 212 | if (i == my_cpu) |
| 213 | continue; |
| 214 | |
| 215 | for (;;) { |
| 216 | rc = opal_query_cpu_status(get_hard_smp_processor_id(i), |
| 217 | &status); |
| 218 | if (rc != OPAL_SUCCESS || status != OPAL_THREAD_STARTED) |
| 219 | break; |
| 220 | barrier(); |
| 221 | if (i != notified) { |
| 222 | printk(KERN_INFO "kexec: waiting for cpu %d " |
| 223 | "(physical %d) to enter OPAL\n", |
| 224 | i, paca[i].hw_cpu_id); |
| 225 | notified = i; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 231 | static void pnv_kexec_cpu_down(int crash_shutdown, int secondary) |
| 232 | { |
| 233 | xics_kexec_teardown_cpu(secondary); |
Benjamin Herrenschmidt | 13906db | 2013-08-21 13:03:20 +1000 | [diff] [blame] | 234 | |
Benjamin Herrenschmidt | 298b34d | 2014-04-24 16:14:25 +1000 | [diff] [blame] | 235 | /* On OPAL v3, we return all CPUs to firmware */ |
| 236 | |
| 237 | if (!firmware_has_feature(FW_FEATURE_OPALv3)) |
| 238 | return; |
| 239 | |
| 240 | if (secondary) { |
| 241 | /* Return secondary CPUs to firmware on OPAL v3 */ |
Benjamin Herrenschmidt | 13906db | 2013-08-21 13:03:20 +1000 | [diff] [blame] | 242 | mb(); |
| 243 | get_paca()->kexec_state = KEXEC_STATE_REAL_MODE; |
| 244 | mb(); |
| 245 | |
| 246 | /* Return the CPU to OPAL */ |
| 247 | opal_return_cpu(); |
Benjamin Herrenschmidt | 298b34d | 2014-04-24 16:14:25 +1000 | [diff] [blame] | 248 | } else if (crash_shutdown) { |
| 249 | /* |
| 250 | * On crash, we don't wait for secondaries to go |
| 251 | * down as they might be unreachable or hung, so |
| 252 | * instead we just wait a bit and move on. |
| 253 | */ |
| 254 | mdelay(1); |
| 255 | } else { |
| 256 | /* Primary waits for the secondaries to have reached OPAL */ |
| 257 | pnv_kexec_wait_secondaries_down(); |
Benjamin Herrenschmidt | 13906db | 2013-08-21 13:03:20 +1000 | [diff] [blame] | 258 | } |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 259 | } |
| 260 | #endif /* CONFIG_KEXEC */ |
| 261 | |
Anton Blanchard | 6d97d7a | 2014-06-04 17:52:42 +1000 | [diff] [blame] | 262 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
| 263 | static unsigned long pnv_memory_block_size(void) |
| 264 | { |
| 265 | return 256UL * 1024 * 1024; |
| 266 | } |
| 267 | #endif |
| 268 | |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 269 | static void __init pnv_setup_machdep_opal(void) |
| 270 | { |
| 271 | ppc_md.get_boot_time = opal_get_boot_time; |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 272 | ppc_md.restart = pnv_restart; |
Alexander Graf | 9178ba2 | 2014-10-13 16:01:09 +0200 | [diff] [blame] | 273 | pm_power_off = pnv_power_off; |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 274 | ppc_md.halt = pnv_halt; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 275 | ppc_md.machine_check_exception = opal_machine_check; |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 276 | ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery; |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 277 | ppc_md.hmi_exception_early = opal_hmi_exception_early; |
| 278 | ppc_md.handle_hmi_exception = opal_handle_hmi_exception; |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | #ifdef CONFIG_PPC_POWERNV_RTAS |
| 282 | static void __init pnv_setup_machdep_rtas(void) |
| 283 | { |
| 284 | if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) { |
| 285 | ppc_md.get_boot_time = rtas_get_boot_time; |
| 286 | ppc_md.get_rtc_time = rtas_get_rtc_time; |
| 287 | ppc_md.set_rtc_time = rtas_set_rtc_time; |
| 288 | } |
| 289 | ppc_md.restart = rtas_restart; |
Alexander Graf | 9178ba2 | 2014-10-13 16:01:09 +0200 | [diff] [blame] | 290 | pm_power_off = rtas_power_off; |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 291 | ppc_md.halt = rtas_halt; |
| 292 | } |
| 293 | #endif /* CONFIG_PPC_POWERNV_RTAS */ |
| 294 | |
Shreyas B. Prabhu | 8eb8ac8 | 2014-12-10 00:26:51 +0530 | [diff] [blame] | 295 | static u32 supported_cpuidle_states; |
| 296 | |
Shreyas B. Prabhu | 77b54e9 | 2014-12-10 00:26:53 +0530 | [diff] [blame] | 297 | int pnv_save_sprs_for_winkle(void) |
| 298 | { |
| 299 | int cpu; |
| 300 | int rc; |
| 301 | |
| 302 | /* |
| 303 | * hid0, hid1, hid4, hid5, hmeer and lpcr values are symmetric accross |
| 304 | * all cpus at boot. Get these reg values of current cpu and use the |
| 305 | * same accross all cpus. |
| 306 | */ |
Shreyas B. Prabhu | 0eb1320 | 2015-01-14 16:43:21 +0530 | [diff] [blame] | 307 | uint64_t lpcr_val = mfspr(SPRN_LPCR) & ~(u64)LPCR_PECE1; |
Shreyas B. Prabhu | 77b54e9 | 2014-12-10 00:26:53 +0530 | [diff] [blame] | 308 | uint64_t hid0_val = mfspr(SPRN_HID0); |
| 309 | uint64_t hid1_val = mfspr(SPRN_HID1); |
| 310 | uint64_t hid4_val = mfspr(SPRN_HID4); |
| 311 | uint64_t hid5_val = mfspr(SPRN_HID5); |
| 312 | uint64_t hmeer_val = mfspr(SPRN_HMEER); |
| 313 | |
| 314 | for_each_possible_cpu(cpu) { |
| 315 | uint64_t pir = get_hard_smp_processor_id(cpu); |
| 316 | uint64_t hsprg0_val = (uint64_t)&paca[cpu]; |
| 317 | |
| 318 | /* |
| 319 | * HSPRG0 is used to store the cpu's pointer to paca. Hence last |
| 320 | * 3 bits are guaranteed to be 0. Program slw to restore HSPRG0 |
| 321 | * with 63rd bit set, so that when a thread wakes up at 0x100 we |
| 322 | * can use this bit to distinguish between fastsleep and |
| 323 | * deep winkle. |
| 324 | */ |
| 325 | hsprg0_val |= 1; |
| 326 | |
| 327 | rc = opal_slw_set_reg(pir, SPRN_HSPRG0, hsprg0_val); |
| 328 | if (rc != 0) |
| 329 | return rc; |
| 330 | |
| 331 | rc = opal_slw_set_reg(pir, SPRN_LPCR, lpcr_val); |
| 332 | if (rc != 0) |
| 333 | return rc; |
| 334 | |
| 335 | /* HIDs are per core registers */ |
| 336 | if (cpu_thread_in_core(cpu) == 0) { |
| 337 | |
| 338 | rc = opal_slw_set_reg(pir, SPRN_HMEER, hmeer_val); |
| 339 | if (rc != 0) |
| 340 | return rc; |
| 341 | |
| 342 | rc = opal_slw_set_reg(pir, SPRN_HID0, hid0_val); |
| 343 | if (rc != 0) |
| 344 | return rc; |
| 345 | |
| 346 | rc = opal_slw_set_reg(pir, SPRN_HID1, hid1_val); |
| 347 | if (rc != 0) |
| 348 | return rc; |
| 349 | |
| 350 | rc = opal_slw_set_reg(pir, SPRN_HID4, hid4_val); |
| 351 | if (rc != 0) |
| 352 | return rc; |
| 353 | |
| 354 | rc = opal_slw_set_reg(pir, SPRN_HID5, hid5_val); |
| 355 | if (rc != 0) |
| 356 | return rc; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
Shreyas B. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 363 | static void pnv_alloc_idle_core_states(void) |
| 364 | { |
| 365 | int i, j; |
| 366 | int nr_cores = cpu_nr_cores(); |
| 367 | u32 *core_idle_state; |
| 368 | |
| 369 | /* |
| 370 | * core_idle_state - First 8 bits track the idle state of each thread |
| 371 | * of the core. The 8th bit is the lock bit. Initially all thread bits |
| 372 | * are set. They are cleared when the thread enters deep idle state |
| 373 | * like sleep and winkle. Initially the lock bit is cleared. |
| 374 | * The lock bit has 2 purposes |
| 375 | * a. While the first thread is restoring core state, it prevents |
| 376 | * other threads in the core from switching to process context. |
| 377 | * b. While the last thread in the core is saving the core state, it |
| 378 | * prevents a different thread from waking up. |
| 379 | */ |
| 380 | for (i = 0; i < nr_cores; i++) { |
| 381 | int first_cpu = i * threads_per_core; |
| 382 | int node = cpu_to_node(first_cpu); |
| 383 | |
| 384 | core_idle_state = kmalloc_node(sizeof(u32), GFP_KERNEL, node); |
| 385 | *core_idle_state = PNV_CORE_IDLE_THREAD_BITS; |
| 386 | |
| 387 | for (j = 0; j < threads_per_core; j++) { |
| 388 | int cpu = first_cpu + j; |
| 389 | |
| 390 | paca[cpu].core_idle_state_ptr = core_idle_state; |
| 391 | paca[cpu].thread_idle_state = PNV_THREAD_RUNNING; |
| 392 | paca[cpu].thread_mask = 1 << j; |
| 393 | } |
| 394 | } |
Shreyas B. Prabhu | 77b54e9 | 2014-12-10 00:26:53 +0530 | [diff] [blame] | 395 | |
| 396 | update_subcore_sibling_mask(); |
| 397 | |
| 398 | if (supported_cpuidle_states & OPAL_PM_WINKLE_ENABLED) |
| 399 | pnv_save_sprs_for_winkle(); |
Shreyas B. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 400 | } |
| 401 | |
Shreyas B. Prabhu | 8eb8ac8 | 2014-12-10 00:26:51 +0530 | [diff] [blame] | 402 | u32 pnv_get_supported_cpuidle_states(void) |
| 403 | { |
| 404 | return supported_cpuidle_states; |
| 405 | } |
Shreyas B. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 406 | EXPORT_SYMBOL_GPL(pnv_get_supported_cpuidle_states); |
Shreyas B. Prabhu | 8eb8ac8 | 2014-12-10 00:26:51 +0530 | [diff] [blame] | 407 | |
| 408 | static int __init pnv_init_idle_states(void) |
| 409 | { |
| 410 | struct device_node *power_mgt; |
| 411 | int dt_idle_states; |
| 412 | const __be32 *idle_state_flags; |
| 413 | u32 len_flags, flags; |
| 414 | int i; |
| 415 | |
| 416 | supported_cpuidle_states = 0; |
| 417 | |
| 418 | if (cpuidle_disable != IDLE_NO_OVERRIDE) |
| 419 | return 0; |
| 420 | |
| 421 | if (!firmware_has_feature(FW_FEATURE_OPALv3)) |
| 422 | return 0; |
| 423 | |
| 424 | power_mgt = of_find_node_by_path("/ibm,opal/power-mgt"); |
| 425 | if (!power_mgt) { |
| 426 | pr_warn("opal: PowerMgmt Node not found\n"); |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | idle_state_flags = of_get_property(power_mgt, |
| 431 | "ibm,cpu-idle-state-flags", &len_flags); |
| 432 | if (!idle_state_flags) { |
| 433 | pr_warn("DT-PowerMgmt: missing ibm,cpu-idle-state-flags\n"); |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | dt_idle_states = len_flags / sizeof(u32); |
| 438 | |
| 439 | for (i = 0; i < dt_idle_states; i++) { |
| 440 | flags = be32_to_cpu(idle_state_flags[i]); |
| 441 | supported_cpuidle_states |= flags; |
| 442 | } |
Shreyas B. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 443 | if (!(supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED_ER1)) { |
| 444 | patch_instruction( |
| 445 | (unsigned int *)pnv_fastsleep_workaround_at_entry, |
| 446 | PPC_INST_NOP); |
| 447 | patch_instruction( |
| 448 | (unsigned int *)pnv_fastsleep_workaround_at_exit, |
| 449 | PPC_INST_NOP); |
| 450 | } |
| 451 | pnv_alloc_idle_core_states(); |
Shreyas B. Prabhu | 8eb8ac8 | 2014-12-10 00:26:51 +0530 | [diff] [blame] | 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | subsys_initcall(pnv_init_idle_states); |
| 456 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 457 | static int __init pnv_probe(void) |
| 458 | { |
| 459 | unsigned long root = of_get_flat_dt_root(); |
| 460 | |
| 461 | if (!of_flat_dt_is_compatible(root, "ibm,powernv")) |
| 462 | return 0; |
| 463 | |
| 464 | hpte_init_native(); |
| 465 | |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 466 | if (firmware_has_feature(FW_FEATURE_OPAL)) |
| 467 | pnv_setup_machdep_opal(); |
| 468 | #ifdef CONFIG_PPC_POWERNV_RTAS |
| 469 | else if (rtas.base) |
| 470 | pnv_setup_machdep_rtas(); |
| 471 | #endif /* CONFIG_PPC_POWERNV_RTAS */ |
| 472 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 473 | pr_debug("PowerNV detected !\n"); |
| 474 | |
| 475 | return 1; |
| 476 | } |
| 477 | |
Gautham R. Shenoy | fb5153d | 2014-03-11 17:01:19 +0530 | [diff] [blame] | 478 | /* |
| 479 | * Returns the cpu frequency for 'cpu' in Hz. This is used by |
| 480 | * /proc/cpuinfo |
| 481 | */ |
Anton Blanchard | e51df2c | 2014-08-20 08:55:18 +1000 | [diff] [blame] | 482 | static unsigned long pnv_get_proc_freq(unsigned int cpu) |
Gautham R. Shenoy | fb5153d | 2014-03-11 17:01:19 +0530 | [diff] [blame] | 483 | { |
| 484 | unsigned long ret_freq; |
| 485 | |
| 486 | ret_freq = cpufreq_quick_get(cpu) * 1000ul; |
| 487 | |
| 488 | /* |
| 489 | * If the backend cpufreq driver does not exist, |
| 490 | * then fallback to old way of reporting the clockrate. |
| 491 | */ |
| 492 | if (!ret_freq) |
| 493 | ret_freq = ppc_proc_freq; |
| 494 | return ret_freq; |
| 495 | } |
| 496 | |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 497 | define_machine(powernv) { |
| 498 | .name = "PowerNV", |
| 499 | .probe = pnv_probe, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 500 | .init_early = pnv_init_early, |
Benjamin Herrenschmidt | 628daa8 | 2011-09-19 17:45:01 +0000 | [diff] [blame] | 501 | .setup_arch = pnv_setup_arch, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 502 | .init_IRQ = pnv_init_IRQ, |
| 503 | .show_cpuinfo = pnv_show_cpuinfo, |
Gautham R. Shenoy | fb5153d | 2014-03-11 17:01:19 +0530 | [diff] [blame] | 504 | .get_proc_freq = pnv_get_proc_freq, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 505 | .progress = pnv_progress, |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 506 | .machine_shutdown = pnv_shutdown, |
Nicolas Pitre | 591ac0c | 2014-02-17 10:59:29 -0500 | [diff] [blame] | 507 | .power_save = power7_idle, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 508 | .calibrate_decr = generic_calibrate_decr, |
Benjamin Herrenschmidt | cd15b04 | 2014-02-11 11:32:38 +1100 | [diff] [blame] | 509 | .dma_set_mask = pnv_dma_set_mask, |
Gavin Shan | fe7e85c | 2014-09-30 12:39:10 +1000 | [diff] [blame] | 510 | .dma_get_required_mask = pnv_dma_get_required_mask, |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 511 | #ifdef CONFIG_KEXEC |
| 512 | .kexec_cpu_down = pnv_kexec_cpu_down, |
| 513 | #endif |
Anton Blanchard | 6d97d7a | 2014-06-04 17:52:42 +1000 | [diff] [blame] | 514 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
| 515 | .memory_block_size = pnv_memory_block_size, |
| 516 | #endif |
Benjamin Herrenschmidt | 55190f8 | 2011-09-19 17:44:52 +0000 | [diff] [blame] | 517 | }; |