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