opal-kmsg.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * kmsg dumper that ensures the OPAL console fully flushes panic messages
  3. *
  4. * Author: Russell Currey <ruscur@russell.cc>
  5. *
  6. * Copyright 2015 IBM Corporation.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/kmsg_dump.h>
  14. #include <asm/opal.h>
  15. #include <asm/opal-api.h>
  16. /*
  17. * Console output is controlled by OPAL firmware. The kernel regularly calls
  18. * OPAL_POLL_EVENTS, which flushes some console output. In a panic state,
  19. * however, the kernel no longer calls OPAL_POLL_EVENTS and the panic message
  20. * may not be completely printed. This function does not actually dump the
  21. * message, it just ensures that OPAL completely flushes the console buffer.
  22. */
  23. static void kmsg_dump_opal_console_flush(struct kmsg_dumper *dumper,
  24. enum kmsg_dump_reason reason)
  25. {
  26. /*
  27. * Outside of a panic context the pollers will continue to run,
  28. * so we don't need to do any special flushing.
  29. */
  30. if (reason != KMSG_DUMP_PANIC)
  31. return;
  32. opal_flush_console(0);
  33. }
  34. static struct kmsg_dumper opal_kmsg_dumper = {
  35. .dump = kmsg_dump_opal_console_flush
  36. };
  37. void __init opal_kmsg_init(void)
  38. {
  39. int rc;
  40. /* Add our dumper to the list */
  41. rc = kmsg_dump_register(&opal_kmsg_dumper);
  42. if (rc != 0)
  43. pr_err("opal: kmsg_dump_register failed; returned %d\n", rc);
  44. }