sstate.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include "kernel.h"
  15. static int hv_supports_soft_state;
  16. static void do_set_sstate(unsigned long state, const char *msg)
  17. {
  18. unsigned long err;
  19. if (!hv_supports_soft_state)
  20. return;
  21. err = sun4v_mach_set_soft_state(state, kimage_addr_to_ra(msg));
  22. if (err) {
  23. printk(KERN_WARNING "SSTATE: Failed to set soft-state to "
  24. "state[%lx] msg[%s], err=%lu\n",
  25. state, msg, err);
  26. }
  27. }
  28. static const char booting_msg[32] __attribute__((aligned(32))) =
  29. "Linux booting";
  30. static const char running_msg[32] __attribute__((aligned(32))) =
  31. "Linux running";
  32. static const char halting_msg[32] __attribute__((aligned(32))) =
  33. "Linux halting";
  34. static const char poweroff_msg[32] __attribute__((aligned(32))) =
  35. "Linux powering off";
  36. static const char rebooting_msg[32] __attribute__((aligned(32))) =
  37. "Linux rebooting";
  38. static const char panicing_msg[32] __attribute__((aligned(32))) =
  39. "Linux panicing";
  40. static int sstate_reboot_call(struct notifier_block *np, unsigned long type, void *_unused)
  41. {
  42. const char *msg;
  43. switch (type) {
  44. case SYS_DOWN:
  45. default:
  46. msg = rebooting_msg;
  47. break;
  48. case SYS_HALT:
  49. msg = halting_msg;
  50. break;
  51. case SYS_POWER_OFF:
  52. msg = poweroff_msg;
  53. break;
  54. }
  55. do_set_sstate(HV_SOFT_STATE_TRANSITION, msg);
  56. return NOTIFY_OK;
  57. }
  58. static struct notifier_block sstate_reboot_notifier = {
  59. .notifier_call = sstate_reboot_call,
  60. };
  61. static int sstate_panic_event(struct notifier_block *n, unsigned long event, void *ptr)
  62. {
  63. do_set_sstate(HV_SOFT_STATE_TRANSITION, panicing_msg);
  64. return NOTIFY_DONE;
  65. }
  66. static struct notifier_block sstate_panic_block = {
  67. .notifier_call = sstate_panic_event,
  68. .priority = INT_MAX,
  69. };
  70. static int __init sstate_init(void)
  71. {
  72. unsigned long major, minor;
  73. if (tlb_type != hypervisor)
  74. return 0;
  75. major = 1;
  76. minor = 0;
  77. if (sun4v_hvapi_register(HV_GRP_SOFT_STATE, major, &minor))
  78. return 0;
  79. hv_supports_soft_state = 1;
  80. prom_sun4v_guest_soft_state();
  81. do_set_sstate(HV_SOFT_STATE_TRANSITION, booting_msg);
  82. atomic_notifier_chain_register(&panic_notifier_list,
  83. &sstate_panic_block);
  84. register_reboot_notifier(&sstate_reboot_notifier);
  85. return 0;
  86. }
  87. core_initcall(sstate_init);
  88. static int __init sstate_running(void)
  89. {
  90. do_set_sstate(HV_SOFT_STATE_NORMAL, running_msg);
  91. return 0;
  92. }
  93. late_initcall(sstate_running);