sstate.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* sstate.c: System soft state support.
  2. *
  3. * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/notifier.h>
  7. #include <linux/reboot.h>
  8. #include <linux/init.h>
  9. #include <asm/hypervisor.h>
  10. #include <asm/spitfire.h>
  11. #include <asm/oplib.h>
  12. #include <asm/head.h>
  13. #include <asm/io.h>
  14. static int hv_supports_soft_state;
  15. static unsigned long kimage_addr_to_ra(const char *p)
  16. {
  17. unsigned long val = (unsigned long) p;
  18. return kern_base + (val - KERNBASE);
  19. }
  20. static void do_set_sstate(unsigned long state, const char *msg)
  21. {
  22. unsigned long err;
  23. if (!hv_supports_soft_state)
  24. return;
  25. err = sun4v_mach_set_soft_state(state, kimage_addr_to_ra(msg));
  26. if (err) {
  27. printk(KERN_WARNING "SSTATE: Failed to set soft-state to "
  28. "state[%lx] msg[%s], err=%lu\n",
  29. state, msg, err);
  30. }
  31. }
  32. static const char booting_msg[32] __attribute__((aligned(32))) =
  33. "Linux booting";
  34. static const char running_msg[32] __attribute__((aligned(32))) =
  35. "Linux running";
  36. static const char halting_msg[32] __attribute__((aligned(32))) =
  37. "Linux halting";
  38. static const char poweroff_msg[32] __attribute__((aligned(32))) =
  39. "Linux powering off";
  40. static const char rebooting_msg[32] __attribute__((aligned(32))) =
  41. "Linux rebooting";
  42. static const char panicing_msg[32] __attribute__((aligned(32))) =
  43. "Linux panicing";
  44. static int sstate_reboot_call(struct notifier_block *np, unsigned long type, void *_unused)
  45. {
  46. const char *msg;
  47. switch (type) {
  48. case SYS_DOWN:
  49. default:
  50. msg = rebooting_msg;
  51. break;
  52. case SYS_HALT:
  53. msg = halting_msg;
  54. break;
  55. case SYS_POWER_OFF:
  56. msg = poweroff_msg;
  57. break;
  58. }
  59. do_set_sstate(HV_SOFT_STATE_TRANSITION, msg);
  60. return NOTIFY_OK;
  61. }
  62. static struct notifier_block sstate_reboot_notifier = {
  63. .notifier_call = sstate_reboot_call,
  64. };
  65. static int sstate_panic_event(struct notifier_block *n, unsigned long event, void *ptr)
  66. {
  67. do_set_sstate(HV_SOFT_STATE_TRANSITION, panicing_msg);
  68. return NOTIFY_DONE;
  69. }
  70. static struct notifier_block sstate_panic_block = {
  71. .notifier_call = sstate_panic_event,
  72. .priority = INT_MAX,
  73. };
  74. static int __init sstate_init(void)
  75. {
  76. unsigned long major, minor;
  77. if (tlb_type != hypervisor)
  78. return 0;
  79. major = 1;
  80. minor = 0;
  81. if (sun4v_hvapi_register(HV_GRP_SOFT_STATE, major, &minor))
  82. return 0;
  83. hv_supports_soft_state = 1;
  84. prom_sun4v_guest_soft_state();
  85. do_set_sstate(HV_SOFT_STATE_TRANSITION, booting_msg);
  86. atomic_notifier_chain_register(&panic_notifier_list,
  87. &sstate_panic_block);
  88. register_reboot_notifier(&sstate_reboot_notifier);
  89. return 0;
  90. }
  91. core_initcall(sstate_init);
  92. static int __init sstate_running(void)
  93. {
  94. do_set_sstate(HV_SOFT_STATE_NORMAL, running_msg);
  95. return 0;
  96. }
  97. late_initcall(sstate_running);