setup.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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/xics.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. #ifdef CONFIG_HVC_OPAL
  49. if (firmware_has_feature(FW_FEATURE_OPAL))
  50. hvc_opal_init_early();
  51. else
  52. #endif
  53. add_preferred_console("hvc", 0, NULL);
  54. }
  55. static void __init pnv_init_IRQ(void)
  56. {
  57. xics_init();
  58. WARN_ON(!ppc_md.get_irq);
  59. }
  60. static void pnv_show_cpuinfo(struct seq_file *m)
  61. {
  62. struct device_node *root;
  63. const char *model = "";
  64. root = of_find_node_by_path("/");
  65. if (root)
  66. model = of_get_property(root, "model", NULL);
  67. seq_printf(m, "machine\t\t: PowerNV %s\n", model);
  68. if (firmware_has_feature(FW_FEATURE_OPALv2))
  69. seq_printf(m, "firmware\t: OPAL v2\n");
  70. else if (firmware_has_feature(FW_FEATURE_OPAL))
  71. seq_printf(m, "firmware\t: OPAL v1\n");
  72. else
  73. seq_printf(m, "firmware\t: BML\n");
  74. of_node_put(root);
  75. }
  76. static void __noreturn pnv_restart(char *cmd)
  77. {
  78. long rc = OPAL_BUSY;
  79. while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
  80. rc = opal_cec_reboot();
  81. if (rc == OPAL_BUSY_EVENT)
  82. opal_poll_events(NULL);
  83. else
  84. mdelay(10);
  85. }
  86. for (;;)
  87. opal_poll_events(NULL);
  88. }
  89. static void __noreturn pnv_power_off(void)
  90. {
  91. long rc = OPAL_BUSY;
  92. while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
  93. rc = opal_cec_power_down(0);
  94. if (rc == OPAL_BUSY_EVENT)
  95. opal_poll_events(NULL);
  96. else
  97. mdelay(10);
  98. }
  99. for (;;)
  100. opal_poll_events(NULL);
  101. }
  102. static void __noreturn pnv_halt(void)
  103. {
  104. pnv_power_off();
  105. }
  106. static void pnv_progress(char *s, unsigned short hex)
  107. {
  108. }
  109. #ifdef CONFIG_KEXEC
  110. static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
  111. {
  112. xics_kexec_teardown_cpu(secondary);
  113. }
  114. #endif /* CONFIG_KEXEC */
  115. static void __init pnv_setup_machdep_opal(void)
  116. {
  117. ppc_md.get_boot_time = opal_get_boot_time;
  118. ppc_md.get_rtc_time = opal_get_rtc_time;
  119. ppc_md.set_rtc_time = opal_set_rtc_time;
  120. ppc_md.restart = pnv_restart;
  121. ppc_md.power_off = pnv_power_off;
  122. ppc_md.halt = pnv_halt;
  123. ppc_md.machine_check_exception = opal_machine_check;
  124. }
  125. #ifdef CONFIG_PPC_POWERNV_RTAS
  126. static void __init pnv_setup_machdep_rtas(void)
  127. {
  128. if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
  129. ppc_md.get_boot_time = rtas_get_boot_time;
  130. ppc_md.get_rtc_time = rtas_get_rtc_time;
  131. ppc_md.set_rtc_time = rtas_set_rtc_time;
  132. }
  133. ppc_md.restart = rtas_restart;
  134. ppc_md.power_off = rtas_power_off;
  135. ppc_md.halt = rtas_halt;
  136. }
  137. #endif /* CONFIG_PPC_POWERNV_RTAS */
  138. static int __init pnv_probe(void)
  139. {
  140. unsigned long root = of_get_flat_dt_root();
  141. if (!of_flat_dt_is_compatible(root, "ibm,powernv"))
  142. return 0;
  143. hpte_init_native();
  144. if (firmware_has_feature(FW_FEATURE_OPAL))
  145. pnv_setup_machdep_opal();
  146. #ifdef CONFIG_PPC_POWERNV_RTAS
  147. else if (rtas.base)
  148. pnv_setup_machdep_rtas();
  149. #endif /* CONFIG_PPC_POWERNV_RTAS */
  150. pr_debug("PowerNV detected !\n");
  151. return 1;
  152. }
  153. define_machine(powernv) {
  154. .name = "PowerNV",
  155. .probe = pnv_probe,
  156. .init_early = pnv_init_early,
  157. .setup_arch = pnv_setup_arch,
  158. .init_IRQ = pnv_init_IRQ,
  159. .show_cpuinfo = pnv_show_cpuinfo,
  160. .progress = pnv_progress,
  161. .power_save = power7_idle,
  162. .calibrate_decr = generic_calibrate_decr,
  163. #ifdef CONFIG_KEXEC
  164. .kexec_cpu_down = pnv_kexec_cpu_down,
  165. #endif
  166. };