sstate.c 2.6 KB

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