setup.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 "powernv.h"
  36. static void __init pnv_setup_arch(void)
  37. {
  38. set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
  39. /* Initialize SMP */
  40. pnv_smp_init();
  41. /* Setup PCI */
  42. pnv_pci_init();
  43. /* Setup RTC and NVRAM callbacks */
  44. if (firmware_has_feature(FW_FEATURE_OPAL))
  45. opal_nvram_init();
  46. /* Enable NAP mode */
  47. powersave_nap = 1;
  48. /* XXX PMCS */
  49. }
  50. static void __init pnv_init_early(void)
  51. {
  52. /*
  53. * Initialize the LPC bus now so that legacy serial
  54. * ports can be found on it
  55. */
  56. opal_lpc_init();
  57. #ifdef CONFIG_HVC_OPAL
  58. if (firmware_has_feature(FW_FEATURE_OPAL))
  59. hvc_opal_init_early();
  60. else
  61. #endif
  62. add_preferred_console("hvc", 0, NULL);
  63. }
  64. static void __init pnv_init_IRQ(void)
  65. {
  66. xics_init();
  67. WARN_ON(!ppc_md.get_irq);
  68. }
  69. static void pnv_show_cpuinfo(struct seq_file *m)
  70. {
  71. struct device_node *root;
  72. const char *model = "";
  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);
  77. if (firmware_has_feature(FW_FEATURE_OPALv3))
  78. seq_printf(m, "firmware\t: OPAL v3\n");
  79. else if (firmware_has_feature(FW_FEATURE_OPALv2))
  80. seq_printf(m, "firmware\t: OPAL v2\n");
  81. else if (firmware_has_feature(FW_FEATURE_OPAL))
  82. seq_printf(m, "firmware\t: OPAL v1\n");
  83. else
  84. seq_printf(m, "firmware\t: BML\n");
  85. of_node_put(root);
  86. }
  87. static void pnv_prepare_going_down(void)
  88. {
  89. /*
  90. * Disable all notifiers from OPAL, we can't
  91. * service interrupts anymore anyway
  92. */
  93. opal_event_shutdown();
  94. /* Soft disable interrupts */
  95. local_irq_disable();
  96. /*
  97. * Return secondary CPUs to firwmare if a flash update
  98. * is pending otherwise we will get all sort of error
  99. * messages about CPU being stuck etc.. This will also
  100. * have the side effect of hard disabling interrupts so
  101. * past this point, the kernel is effectively dead.
  102. */
  103. opal_flash_term_callback();
  104. }
  105. static void __noreturn pnv_restart(char *cmd)
  106. {
  107. long rc = OPAL_BUSY;
  108. pnv_prepare_going_down();
  109. while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
  110. rc = opal_cec_reboot();
  111. if (rc == OPAL_BUSY_EVENT)
  112. opal_poll_events(NULL);
  113. else
  114. mdelay(10);
  115. }
  116. for (;;)
  117. opal_poll_events(NULL);
  118. }
  119. static void __noreturn pnv_power_off(void)
  120. {
  121. long rc = OPAL_BUSY;
  122. pnv_prepare_going_down();
  123. while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
  124. rc = opal_cec_power_down(0);
  125. if (rc == OPAL_BUSY_EVENT)
  126. opal_poll_events(NULL);
  127. else
  128. mdelay(10);
  129. }
  130. for (;;)
  131. opal_poll_events(NULL);
  132. }
  133. static void __noreturn pnv_halt(void)
  134. {
  135. pnv_power_off();
  136. }
  137. static void pnv_progress(char *s, unsigned short hex)
  138. {
  139. }
  140. static void pnv_shutdown(void)
  141. {
  142. /* Let the PCI code clear up IODA tables */
  143. pnv_pci_shutdown();
  144. /*
  145. * Stop OPAL activity: Unregister all OPAL interrupts so they
  146. * don't fire up while we kexec and make sure all potentially
  147. * DMA'ing ops are complete (such as dump retrieval).
  148. */
  149. opal_shutdown();
  150. }
  151. #ifdef CONFIG_KEXEC
  152. static void pnv_kexec_wait_secondaries_down(void)
  153. {
  154. int my_cpu, i, notified = -1;
  155. my_cpu = get_cpu();
  156. for_each_online_cpu(i) {
  157. uint8_t status;
  158. int64_t rc;
  159. if (i == my_cpu)
  160. continue;
  161. for (;;) {
  162. rc = opal_query_cpu_status(get_hard_smp_processor_id(i),
  163. &status);
  164. if (rc != OPAL_SUCCESS || status != OPAL_THREAD_STARTED)
  165. break;
  166. barrier();
  167. if (i != notified) {
  168. printk(KERN_INFO "kexec: waiting for cpu %d "
  169. "(physical %d) to enter OPAL\n",
  170. i, paca[i].hw_cpu_id);
  171. notified = i;
  172. }
  173. }
  174. }
  175. }
  176. static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
  177. {
  178. xics_kexec_teardown_cpu(secondary);
  179. /* On OPAL v3, we return all CPUs to firmware */
  180. if (!firmware_has_feature(FW_FEATURE_OPALv3))
  181. return;
  182. if (secondary) {
  183. /* Return secondary CPUs to firmware on OPAL v3 */
  184. mb();
  185. get_paca()->kexec_state = KEXEC_STATE_REAL_MODE;
  186. mb();
  187. /* Return the CPU to OPAL */
  188. opal_return_cpu();
  189. } else if (crash_shutdown) {
  190. /*
  191. * On crash, we don't wait for secondaries to go
  192. * down as they might be unreachable or hung, so
  193. * instead we just wait a bit and move on.
  194. */
  195. mdelay(1);
  196. } else {
  197. /* Primary waits for the secondaries to have reached OPAL */
  198. pnv_kexec_wait_secondaries_down();
  199. /*
  200. * We might be running as little-endian - now that interrupts
  201. * are disabled, reset the HILE bit to big-endian so we don't
  202. * take interrupts in the wrong endian later
  203. */
  204. opal_reinit_cpus(OPAL_REINIT_CPUS_HILE_BE);
  205. }
  206. }
  207. #endif /* CONFIG_KEXEC */
  208. #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
  209. static unsigned long pnv_memory_block_size(void)
  210. {
  211. return 256UL * 1024 * 1024;
  212. }
  213. #endif
  214. static void __init pnv_setup_machdep_opal(void)
  215. {
  216. ppc_md.get_boot_time = opal_get_boot_time;
  217. ppc_md.restart = pnv_restart;
  218. pm_power_off = pnv_power_off;
  219. ppc_md.halt = pnv_halt;
  220. ppc_md.machine_check_exception = opal_machine_check;
  221. ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery;
  222. ppc_md.hmi_exception_early = opal_hmi_exception_early;
  223. ppc_md.handle_hmi_exception = opal_handle_hmi_exception;
  224. }
  225. static int __init pnv_probe(void)
  226. {
  227. unsigned long root = of_get_flat_dt_root();
  228. if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
  229. return 0;
  230. hpte_init_native();
  231. if (firmware_has_feature(FW_FEATURE_OPAL))
  232. pnv_setup_machdep_opal();
  233. pr_debug("PowerNV detected !\n");
  234. return 1;
  235. }
  236. /*
  237. * Returns the cpu frequency for 'cpu' in Hz. This is used by
  238. * /proc/cpuinfo
  239. */
  240. static unsigned long pnv_get_proc_freq(unsigned int cpu)
  241. {
  242. unsigned long ret_freq;
  243. ret_freq = cpufreq_quick_get(cpu) * 1000ul;
  244. /*
  245. * If the backend cpufreq driver does not exist,
  246. * then fallback to old way of reporting the clockrate.
  247. */
  248. if (!ret_freq)
  249. ret_freq = ppc_proc_freq;
  250. return ret_freq;
  251. }
  252. define_machine(powernv) {
  253. .name = "PowerNV",
  254. .probe = pnv_probe,
  255. .init_early = pnv_init_early,
  256. .setup_arch = pnv_setup_arch,
  257. .init_IRQ = pnv_init_IRQ,
  258. .show_cpuinfo = pnv_show_cpuinfo,
  259. .get_proc_freq = pnv_get_proc_freq,
  260. .progress = pnv_progress,
  261. .machine_shutdown = pnv_shutdown,
  262. .power_save = power7_idle,
  263. .calibrate_decr = generic_calibrate_decr,
  264. #ifdef CONFIG_KEXEC
  265. .kexec_cpu_down = pnv_kexec_cpu_down,
  266. #endif
  267. #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
  268. .memory_block_size = pnv_memory_block_size,
  269. #endif
  270. };