setup.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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/interrupt.h>
  25. #include <linux/bug.h>
  26. #include <asm/machdep.h>
  27. #include <asm/firmware.h>
  28. #include <asm/xics.h>
  29. #include <asm/rtas.h>
  30. #include <asm/opal.h>
  31. #include <asm/kexec.h>
  32. #include "powernv.h"
  33. static void __init pnv_setup_arch(void)
  34. {
  35. /* Initialize SMP */
  36. pnv_smp_init();
  37. /* Setup PCI */
  38. pnv_pci_init();
  39. /* Setup RTC and NVRAM callbacks */
  40. if (firmware_has_feature(FW_FEATURE_OPAL))
  41. opal_nvram_init();
  42. /* Enable NAP mode */
  43. powersave_nap = 1;
  44. /* XXX PMCS */
  45. }
  46. static void __init pnv_init_early(void)
  47. {
  48. /*
  49. * Initialize the LPC bus now so that legacy serial
  50. * ports can be found on it
  51. */
  52. opal_lpc_init();
  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);
  59. }
  60. static void __init pnv_init_IRQ(void)
  61. {
  62. xics_init();
  63. WARN_ON(!ppc_md.get_irq);
  64. }
  65. static void pnv_show_cpuinfo(struct seq_file *m)
  66. {
  67. struct device_node *root;
  68. const char *model = "";
  69. root = of_find_node_by_path("/");
  70. if (root)
  71. model = of_get_property(root, "model", NULL);
  72. seq_printf(m, "machine\t\t: PowerNV %s\n", model);
  73. if (firmware_has_feature(FW_FEATURE_OPALv3))
  74. seq_printf(m, "firmware\t: OPAL v3\n");
  75. else if (firmware_has_feature(FW_FEATURE_OPALv2))
  76. seq_printf(m, "firmware\t: OPAL v2\n");
  77. else if (firmware_has_feature(FW_FEATURE_OPAL))
  78. seq_printf(m, "firmware\t: OPAL v1\n");
  79. else
  80. seq_printf(m, "firmware\t: BML\n");
  81. of_node_put(root);
  82. }
  83. static void __noreturn pnv_restart(char *cmd)
  84. {
  85. long rc = OPAL_BUSY;
  86. opal_notifier_disable();
  87. while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
  88. rc = opal_cec_reboot();
  89. if (rc == OPAL_BUSY_EVENT)
  90. opal_poll_events(NULL);
  91. else
  92. mdelay(10);
  93. }
  94. for (;;)
  95. opal_poll_events(NULL);
  96. }
  97. static void __noreturn pnv_power_off(void)
  98. {
  99. long rc = OPAL_BUSY;
  100. opal_notifier_disable();
  101. while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
  102. rc = opal_cec_power_down(0);
  103. if (rc == OPAL_BUSY_EVENT)
  104. opal_poll_events(NULL);
  105. else
  106. mdelay(10);
  107. }
  108. for (;;)
  109. opal_poll_events(NULL);
  110. }
  111. static void __noreturn pnv_halt(void)
  112. {
  113. pnv_power_off();
  114. }
  115. static void pnv_progress(char *s, unsigned short hex)
  116. {
  117. }
  118. static void pnv_shutdown(void)
  119. {
  120. /* Let the PCI code clear up IODA tables */
  121. pnv_pci_shutdown();
  122. /* And unregister all OPAL interrupts so they don't fire
  123. * up while we kexec
  124. */
  125. opal_shutdown();
  126. }
  127. #ifdef CONFIG_KEXEC
  128. static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
  129. {
  130. xics_kexec_teardown_cpu(secondary);
  131. /* Return secondary CPUs to firmware on OPAL v3 */
  132. if (firmware_has_feature(FW_FEATURE_OPALv3) && secondary) {
  133. mb();
  134. get_paca()->kexec_state = KEXEC_STATE_REAL_MODE;
  135. mb();
  136. /* Return the CPU to OPAL */
  137. opal_return_cpu();
  138. }
  139. }
  140. #endif /* CONFIG_KEXEC */
  141. static void __init pnv_setup_machdep_opal(void)
  142. {
  143. ppc_md.get_boot_time = opal_get_boot_time;
  144. ppc_md.get_rtc_time = opal_get_rtc_time;
  145. ppc_md.set_rtc_time = opal_set_rtc_time;
  146. ppc_md.restart = pnv_restart;
  147. ppc_md.power_off = pnv_power_off;
  148. ppc_md.halt = pnv_halt;
  149. ppc_md.machine_check_exception = opal_machine_check;
  150. }
  151. #ifdef CONFIG_PPC_POWERNV_RTAS
  152. static void __init pnv_setup_machdep_rtas(void)
  153. {
  154. if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
  155. ppc_md.get_boot_time = rtas_get_boot_time;
  156. ppc_md.get_rtc_time = rtas_get_rtc_time;
  157. ppc_md.set_rtc_time = rtas_set_rtc_time;
  158. }
  159. ppc_md.restart = rtas_restart;
  160. ppc_md.power_off = rtas_power_off;
  161. ppc_md.halt = rtas_halt;
  162. }
  163. #endif /* CONFIG_PPC_POWERNV_RTAS */
  164. static int __init pnv_probe(void)
  165. {
  166. unsigned long root = of_get_flat_dt_root();
  167. if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
  168. return 0;
  169. hpte_init_native();
  170. if (firmware_has_feature(FW_FEATURE_OPAL))
  171. pnv_setup_machdep_opal();
  172. #ifdef CONFIG_PPC_POWERNV_RTAS
  173. else if (rtas.base)
  174. pnv_setup_machdep_rtas();
  175. #endif /* CONFIG_PPC_POWERNV_RTAS */
  176. pr_debug("PowerNV detected !\n");
  177. return 1;
  178. }
  179. define_machine(powernv) {
  180. .name = "PowerNV",
  181. .probe = pnv_probe,
  182. .init_early = pnv_init_early,
  183. .setup_arch = pnv_setup_arch,
  184. .init_IRQ = pnv_init_IRQ,
  185. .show_cpuinfo = pnv_show_cpuinfo,
  186. .progress = pnv_progress,
  187. .machine_shutdown = pnv_shutdown,
  188. .power_save = power7_idle,
  189. .calibrate_decr = generic_calibrate_decr,
  190. #ifdef CONFIG_KEXEC
  191. .kexec_cpu_down = pnv_kexec_cpu_down,
  192. #endif
  193. };