Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * kmsg dumper that ensures the OPAL console fully flushes panic messages
0004  *
0005  * Author: Russell Currey <ruscur@russell.cc>
0006  *
0007  * Copyright 2015 IBM Corporation.
0008  */
0009 
0010 #include <linux/kmsg_dump.h>
0011 
0012 #include <asm/opal.h>
0013 #include <asm/opal-api.h>
0014 
0015 /*
0016  * Console output is controlled by OPAL firmware.  The kernel regularly calls
0017  * OPAL_POLL_EVENTS, which flushes some console output.  In a panic state,
0018  * however, the kernel no longer calls OPAL_POLL_EVENTS and the panic message
0019  * may not be completely printed.  This function does not actually dump the
0020  * message, it just ensures that OPAL completely flushes the console buffer.
0021  */
0022 static void kmsg_dump_opal_console_flush(struct kmsg_dumper *dumper,
0023                      enum kmsg_dump_reason reason)
0024 {
0025     /*
0026      * Outside of a panic context the pollers will continue to run,
0027      * so we don't need to do any special flushing.
0028      */
0029     if (reason != KMSG_DUMP_PANIC)
0030         return;
0031 
0032     opal_flush_console(0);
0033 }
0034 
0035 static struct kmsg_dumper opal_kmsg_dumper = {
0036     .dump = kmsg_dump_opal_console_flush
0037 };
0038 
0039 void __init opal_kmsg_init(void)
0040 {
0041     int rc;
0042 
0043     /* Add our dumper to the list */
0044     rc = kmsg_dump_register(&opal_kmsg_dumper);
0045     if (rc != 0)
0046         pr_err("opal: kmsg_dump_register failed; returned %d\n", rc);
0047 }