powerpc/powernv: Add a kmsg_dumper that flushes console output on panic
[deliverable/linux.git] / arch / powerpc / platforms / powernv / opal-kmsg.c
CommitLineData
affddff6
RC
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
14#include <linux/kmsg_dump.h>
15
16#include <asm/opal.h>
17#include <asm/opal-api.h>
18
19/*
20 * Console output is controlled by OPAL firmware. The kernel regularly calls
21 * OPAL_POLL_EVENTS, which flushes some console output. In a panic state,
22 * however, the kernel no longer calls OPAL_POLL_EVENTS and the panic message
23 * may not be completely printed. This function does not actually dump the
24 * message, it just ensures that OPAL completely flushes the console buffer.
25 */
26static void force_opal_console_flush(struct kmsg_dumper *dumper,
27 enum kmsg_dump_reason reason)
28{
29 int i;
30
31 /*
32 * Outside of a panic context the pollers will continue to run,
33 * so we don't need to do any special flushing.
34 */
35 if (reason != KMSG_DUMP_PANIC)
36 return;
37
38 if (opal_check_token(OPAL_CONSOLE_FLUSH)) {
39 opal_console_flush();
40 } else {
41 /*
42 * If OPAL_CONSOLE_FLUSH is not implemented in the firmware,
43 * the console can still be flushed by calling the polling
44 * function enough times to flush the buffer. We don't know
45 * how much output still needs to be flushed, but we can be
46 * generous since the kernel is in panic and doesn't need
47 * to do much else.
48 */
49 printk(KERN_NOTICE "opal: OPAL_CONSOLE_FLUSH missing.\n");
50 for (i = 0; i < 1024; i++) {
51 opal_poll_events(NULL);
52 }
53 }
54}
55
56static struct kmsg_dumper opal_kmsg_dumper = {
57 .dump = force_opal_console_flush
58};
59
60void __init opal_kmsg_init(void)
61{
62 int rc;
63
64 /* Add our dumper to the list */
65 rc = kmsg_dump_register(&opal_kmsg_dumper);
66 if (rc != 0)
67 pr_err("opal: kmsg_dump_register failed; returned %d\n", rc);
68}
This page took 0.026691 seconds and 5 git commands to generate.