setup.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. #undef DEBUG
  12. #include <linux/cpu.h>
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/kernel.h>
  16. #include <linux/tty.h>
  17. #include <linux/reboot.h>
  18. #include <linux/init.h>
  19. #include <linux/console.h>
  20. #include <linux/delay.h>
  21. #include <linux/irq.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/of.h>
  24. #include <linux/of_fdt.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/bug.h>
  27. #include <linux/pci.h>
  28. #include <linux/cpufreq.h>
  29. #include <asm/machdep.h>
  30. #include <asm/firmware.h>
  31. #include <asm/xics.h>
  32. #include <asm/opal.h>
  33. #include <asm/kexec.h>
  34. #include <asm/smp.h>
  35. #include <asm/tm.h>
  36. #include <asm/setup.h>
  37. #include "powernv.h"
  38. static void pnv_setup_rfi_flush(void)
  39. {
  40. struct device_node *np, *fw_features;
  41. enum l1d_flush_type type;
  42. int enable;
  43. /* Default to fallback in case fw-features are not available */
  44. type = L1D_FLUSH_FALLBACK;
  45. enable = 1;
  46. np = of_find_node_by_name(NULL, "ibm,opal");
  47. fw_features = of_get_child_by_name(np, "fw-features");
  48. of_node_put(np);
  49. if (fw_features) {
  50. np = of_get_child_by_name(fw_features, "inst-l1d-flush-trig2");
  51. if (np && of_property_read_bool(np, "enabled"))
  52. type = L1D_FLUSH_MTTRIG;
  53. of_node_put(np);
  54. np = of_get_child_by_name(fw_features, "inst-l1d-flush-ori30,30,0");
  55. if (np && of_property_read_bool(np, "enabled"))
  56. type = L1D_FLUSH_ORI;
  57. of_node_put(np);
  58. /* Enable unless firmware says NOT to */
  59. enable = 2;
  60. np = of_get_child_by_name(fw_features, "needs-l1d-flush-msr-hv-1-to-0");
  61. if (np && of_property_read_bool(np, "disabled"))
  62. enable--;
  63. of_node_put(np);
  64. np = of_get_child_by_name(fw_features, "needs-l1d-flush-msr-pr-0-to-1");
  65. if (np && of_property_read_bool(np, "disabled"))
  66. enable--;
  67. of_node_put(np);
  68. of_node_put(fw_features);
  69. }
  70. setup_rfi_flush(type, enable > 0);
  71. }
  72. static void __init pnv_setup_arch(void)
  73. {
  74. set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
  75. pnv_setup_rfi_flush();
  76. /* Initialize SMP */
  77. pnv_smp_init();
  78. /* Setup PCI */
  79. pnv_pci_init();
  80. /* Setup RTC and NVRAM callbacks */
  81. if (firmware_has_feature(FW_FEATURE_OPAL))
  82. opal_nvram_init();
  83. /* Enable NAP mode */
  84. powersave_nap = 1;
  85. /* XXX PMCS */
  86. }
  87. static void __init pnv_init_early(void)
  88. {
  89. /*
  90. * Initialize the LPC bus now so that legacy serial
  91. * ports can be found on it
  92. */
  93. opal_lpc_init();
  94. #ifdef CONFIG_HVC_OPAL
  95. if (firmware_has_feature(FW_FEATURE_OPAL))
  96. hvc_opal_init_early();
  97. else
  98. #endif
  99. add_preferred_console("hvc", 0, NULL);
  100. }
  101. static void __init pnv_init_IRQ(void)
  102. {
  103. xics_init();
  104. WARN_ON(!ppc_md.get_irq);
  105. }
  106. static void pnv_show_cpuinfo(struct seq_file *m)
  107. {
  108. struct device_node *root;
  109. const char *model = "";
  110. root = of_find_node_by_path("/");
  111. if (root)
  112. model = of_get_property(root, "model", NULL);
  113. seq_printf(m, "machine\t\t: PowerNV %s\n", model);
  114. if (firmware_has_feature(FW_FEATURE_OPAL))
  115. seq_printf(m, "firmware\t: OPAL\n");
  116. else
  117. seq_printf(m, "firmware\t: BML\n");
  118. of_node_put(root);
  119. }
  120. static void pnv_prepare_going_down(void)
  121. {
  122. /*
  123. * Disable all notifiers from OPAL, we can't
  124. * service interrupts anymore anyway
  125. */
  126. opal_event_shutdown();
  127. /* Soft disable interrupts */
  128. local_irq_disable();
  129. /*
  130. * Return secondary CPUs to firwmare if a flash update
  131. * is pending otherwise we will get all sort of error
  132. * messages about CPU being stuck etc.. This will also
  133. * have the side effect of hard disabling interrupts so
  134. * past this point, the kernel is effectively dead.
  135. */
  136. opal_flash_term_callback();
  137. }
  138. static void __noreturn pnv_restart(char *cmd)
  139. {
  140. long rc = OPAL_BUSY;
  141. pnv_prepare_going_down();
  142. while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
  143. rc = opal_cec_reboot();
  144. if (rc == OPAL_BUSY_EVENT)
  145. opal_poll_events(NULL);
  146. else
  147. mdelay(10);
  148. }
  149. for (;;)
  150. opal_poll_events(NULL);
  151. }
  152. static void __noreturn pnv_power_off(void)
  153. {
  154. long rc = OPAL_BUSY;
  155. pnv_prepare_going_down();
  156. while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
  157. rc = opal_cec_power_down(0);
  158. if (rc == OPAL_BUSY_EVENT)
  159. opal_poll_events(NULL);
  160. else
  161. mdelay(10);
  162. }
  163. for (;;)
  164. opal_poll_events(NULL);
  165. }
  166. static void __noreturn pnv_halt(void)
  167. {
  168. pnv_power_off();
  169. }
  170. static void pnv_progress(char *s, unsigned short hex)
  171. {
  172. }
  173. static void pnv_shutdown(void)
  174. {
  175. /* Let the PCI code clear up IODA tables */
  176. pnv_pci_shutdown();
  177. /*
  178. * Stop OPAL activity: Unregister all OPAL interrupts so they
  179. * don't fire up while we kexec and make sure all potentially
  180. * DMA'ing ops are complete (such as dump retrieval).
  181. */
  182. opal_shutdown();
  183. }
  184. #ifdef CONFIG_KEXEC
  185. static void pnv_kexec_wait_secondaries_down(void)
  186. {
  187. int my_cpu, i, notified = -1;
  188. my_cpu = get_cpu();
  189. for_each_online_cpu(i) {
  190. uint8_t status;
  191. int64_t rc, timeout = 1000;
  192. if (i == my_cpu)
  193. continue;
  194. for (;;) {
  195. rc = opal_query_cpu_status(get_hard_smp_processor_id(i),
  196. &status);
  197. if (rc != OPAL_SUCCESS || status != OPAL_THREAD_STARTED)
  198. break;
  199. barrier();
  200. if (i != notified) {
  201. printk(KERN_INFO "kexec: waiting for cpu %d "
  202. "(physical %d) to enter OPAL\n",
  203. i, paca[i].hw_cpu_id);
  204. notified = i;
  205. }
  206. /*
  207. * On crash secondaries might be unreachable or hung,
  208. * so timeout if we've waited too long
  209. * */
  210. mdelay(1);
  211. if (timeout-- == 0) {
  212. printk(KERN_ERR "kexec: timed out waiting for "
  213. "cpu %d (physical %d) to enter OPAL\n",
  214. i, paca[i].hw_cpu_id);
  215. break;
  216. }
  217. }
  218. }
  219. }
  220. static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
  221. {
  222. xics_kexec_teardown_cpu(secondary);
  223. /* On OPAL, we return all CPUs to firmware */
  224. if (!firmware_has_feature(FW_FEATURE_OPAL))
  225. return;
  226. if (secondary) {
  227. /* Return secondary CPUs to firmware on OPAL v3 */
  228. mb();
  229. get_paca()->kexec_state = KEXEC_STATE_REAL_MODE;
  230. mb();
  231. /* Return the CPU to OPAL */
  232. opal_return_cpu();
  233. } else {
  234. /* Primary waits for the secondaries to have reached OPAL */
  235. pnv_kexec_wait_secondaries_down();
  236. /*
  237. * We might be running as little-endian - now that interrupts
  238. * are disabled, reset the HILE bit to big-endian so we don't
  239. * take interrupts in the wrong endian later
  240. */
  241. opal_reinit_cpus(OPAL_REINIT_CPUS_HILE_BE);
  242. }
  243. }
  244. #endif /* CONFIG_KEXEC */
  245. #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
  246. static unsigned long pnv_memory_block_size(void)
  247. {
  248. return 256UL * 1024 * 1024;
  249. }
  250. #endif
  251. static void __init pnv_setup_machdep_opal(void)
  252. {
  253. ppc_md.get_boot_time = opal_get_boot_time;
  254. ppc_md.restart = pnv_restart;
  255. pm_power_off = pnv_power_off;
  256. ppc_md.halt = pnv_halt;
  257. ppc_md.machine_check_exception = opal_machine_check;
  258. ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery;
  259. ppc_md.hmi_exception_early = opal_hmi_exception_early;
  260. ppc_md.handle_hmi_exception = opal_handle_hmi_exception;
  261. }
  262. static int __init pnv_probe(void)
  263. {
  264. unsigned long root = of_get_flat_dt_root();
  265. if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
  266. return 0;
  267. hpte_init_native();
  268. if (firmware_has_feature(FW_FEATURE_OPAL))
  269. pnv_setup_machdep_opal();
  270. pr_debug("PowerNV detected !\n");
  271. return 1;
  272. }
  273. /*
  274. * Returns the cpu frequency for 'cpu' in Hz. This is used by
  275. * /proc/cpuinfo
  276. */
  277. static unsigned long pnv_get_proc_freq(unsigned int cpu)
  278. {
  279. unsigned long ret_freq;
  280. ret_freq = cpufreq_get(cpu) * 1000ul;
  281. /*
  282. * If the backend cpufreq driver does not exist,
  283. * then fallback to old way of reporting the clockrate.
  284. */
  285. if (!ret_freq)
  286. ret_freq = ppc_proc_freq;
  287. return ret_freq;
  288. }
  289. define_machine(powernv) {
  290. .name = "PowerNV",
  291. .probe = pnv_probe,
  292. .init_early = pnv_init_early,
  293. .setup_arch = pnv_setup_arch,
  294. .init_IRQ = pnv_init_IRQ,
  295. .show_cpuinfo = pnv_show_cpuinfo,
  296. .get_proc_freq = pnv_get_proc_freq,
  297. .progress = pnv_progress,
  298. .machine_shutdown = pnv_shutdown,
  299. .power_save = power7_idle,
  300. .calibrate_decr = generic_calibrate_decr,
  301. #ifdef CONFIG_KEXEC
  302. .kexec_cpu_down = pnv_kexec_cpu_down,
  303. #endif
  304. #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
  305. .memory_block_size = pnv_memory_block_size,
  306. #endif
  307. };