opal-kmsg.c 1.2 KB

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