setup.c 7.5 KB

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