setup.c 4.9 KB

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