sstate.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* sstate.c: System soft state support.
  2. *
  3. * Copyright (C) 2007 David S. Miller <davem@davemloft.net>
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/notifier.h>
  7. #include <linux/init.h>
  8. #include <asm/hypervisor.h>
  9. #include <asm/sstate.h>
  10. #include <asm/oplib.h>
  11. #include <asm/head.h>
  12. #include <asm/io.h>
  13. static int hv_supports_soft_state;
  14. static unsigned long kimage_addr_to_ra(const char *p)
  15. {
  16. unsigned long val = (unsigned long) p;
  17. return kern_base + (val - KERNBASE);
  18. }
  19. static void do_set_sstate(unsigned long state, const char *msg)
  20. {
  21. unsigned long err;
  22. if (!hv_supports_soft_state)
  23. return;
  24. err = sun4v_mach_set_soft_state(state, kimage_addr_to_ra(msg));
  25. if (err) {
  26. printk(KERN_WARNING "SSTATE: Failed to set soft-state to "
  27. "state[%lx] msg[%s], err=%lu\n",
  28. state, msg, err);
  29. }
  30. }
  31. static const char booting_msg[32] __attribute__((aligned(32))) =
  32. "Linux booting";
  33. static const char running_msg[32] __attribute__((aligned(32))) =
  34. "Linux running";
  35. static const char halting_msg[32] __attribute__((aligned(32))) =
  36. "Linux halting";
  37. static const char poweroff_msg[32] __attribute__((aligned(32))) =
  38. "Linux powering off";
  39. static const char rebooting_msg[32] __attribute__((aligned(32))) =
  40. "Linux rebooting";
  41. static const char panicing_msg[32] __attribute__((aligned(32))) =
  42. "Linux panicing";
  43. void sstate_booting(void)
  44. {
  45. do_set_sstate(HV_SOFT_STATE_TRANSITION, booting_msg);
  46. }
  47. void sstate_running(void)
  48. {
  49. do_set_sstate(HV_SOFT_STATE_NORMAL, running_msg);
  50. }
  51. void sstate_halt(void)
  52. {
  53. do_set_sstate(HV_SOFT_STATE_TRANSITION, halting_msg);
  54. }
  55. void sstate_poweroff(void)
  56. {
  57. do_set_sstate(HV_SOFT_STATE_TRANSITION, poweroff_msg);
  58. }
  59. void sstate_reboot(void)
  60. {
  61. do_set_sstate(HV_SOFT_STATE_TRANSITION, rebooting_msg);
  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, panicing_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. void __init sun4v_sstate_init(void)
  73. {
  74. unsigned long major, minor;
  75. major = 1;
  76. minor = 0;
  77. if (sun4v_hvapi_register(HV_GRP_SOFT_STATE, major, &minor))
  78. return;
  79. hv_supports_soft_state = 1;
  80. prom_sun4v_guest_soft_state();
  81. atomic_notifier_chain_register(&panic_notifier_list,
  82. &sstate_panic_block);
  83. }