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