sstate.c 2.7 KB

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