]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
powerpc/powernv: Implement and use opal_flush_console
authorNicholas Piggin <npiggin@gmail.com>
Mon, 30 Apr 2018 14:55:48 +0000 (00:55 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 24 Jul 2018 12:09:56 +0000 (22:09 +1000)
A new console flushing firmware API was introduced to replace event
polling loops, and implemented in opal-kmsg with affddff69c55e
("powerpc/powernv: Add a kmsg_dumper that flushes console output on
panic"), to flush the console in the panic path.

The OPAL console driver has other situations where interrupts are off
and it needs to flush the console synchronously. These still use a
polling loop.

So move the opal-kmsg flush code to opal_flush_console, and use the
new function in opal-kmsg and opal_put_chars.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/opal.h
arch/powerpc/platforms/powernv/opal-kmsg.c
arch/powerpc/platforms/powernv/opal.c

index e1b2910c6e818f16d992466e3fc28669c37e36c9..33ab95a4ac0f1eb8e6f3ca2d7cea0aa03283db9a 100644 (file)
@@ -305,6 +305,7 @@ extern void opal_configure_cores(void);
 
 extern int opal_get_chars(uint32_t vtermno, char *buf, int count);
 extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);
+extern int opal_flush_console(uint32_t vtermno);
 
 extern void hvc_opal_init_early(void);
 
index fd2bbf4fd6dc61df9e79a10dfac0494d992e1406..55691950d981c659fec9122483e9f7689cf1d867 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include <linux/kmsg_dump.h>
-#include <linux/delay.h>
 
 #include <asm/opal.h>
 #include <asm/opal-api.h>
  * may not be completely printed.  This function does not actually dump the
  * message, it just ensures that OPAL completely flushes the console buffer.
  */
-static void force_opal_console_flush(struct kmsg_dumper *dumper,
+static void kmsg_dump_opal_console_flush(struct kmsg_dumper *dumper,
                                     enum kmsg_dump_reason reason)
 {
-       s64 rc;
-
        /*
         * Outside of a panic context the pollers will continue to run,
         * so we don't need to do any special flushing.
@@ -36,37 +33,11 @@ static void force_opal_console_flush(struct kmsg_dumper *dumper,
        if (reason != KMSG_DUMP_PANIC)
                return;
 
-       if (opal_check_token(OPAL_CONSOLE_FLUSH)) {
-               do  {
-                       rc = OPAL_BUSY;
-                       while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
-                               rc = opal_console_flush(0);
-                               if (rc == OPAL_BUSY_EVENT) {
-                                       mdelay(OPAL_BUSY_DELAY_MS);
-                                       opal_poll_events(NULL);
-                               } else if (rc == OPAL_BUSY) {
-                                       mdelay(OPAL_BUSY_DELAY_MS);
-                               }
-                       }
-               } while (rc == OPAL_PARTIAL); /* More to flush */
-
-       } else {
-               __be64 evt;
-
-               WARN_ONCE(1, "opal: OPAL_CONSOLE_FLUSH missing.\n");
-               /*
-                * If OPAL_CONSOLE_FLUSH is not implemented in the firmware,
-                * the console can still be flushed by calling the polling
-                * function while it has OPAL_EVENT_CONSOLE_OUTPUT events.
-                */
-               do {
-                       opal_poll_events(&evt);
-               } while (be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT);
-       }
+       opal_flush_console(0);
 }
 
 static struct kmsg_dumper opal_kmsg_dumper = {
-       .dump = force_opal_console_flush
+       .dump = kmsg_dump_opal_console_flush
 };
 
 void __init opal_kmsg_init(void)
index a9773a6190818147bf109747b966c5f165993896..b007d3ff1445fe4aed00478b3bd20677f23b3ea9 100644 (file)
@@ -350,7 +350,6 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
        __be64 olen;
        s64 len, rc;
        unsigned long flags;
-       __be64 evt;
 
        if (!opal.entry)
                return -ENODEV;
@@ -371,7 +370,7 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
                /* Closed -> drop characters */
                if (rc)
                        return total_len;
-               opal_poll_events(NULL);
+               opal_flush_console(vtermno);
                return -EAGAIN;
        }
 
@@ -410,12 +409,47 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
                 * things a bit later to limit that to synchronous path
                 * such as the kernel console and xmon/udbg
                 */
+               opal_flush_console(vtermno);
+       }
+       spin_unlock_irqrestore(&opal_write_lock, flags);
+
+       return written;
+}
+
+int opal_flush_console(uint32_t vtermno)
+{
+       s64 rc;
+
+       if (!opal_check_token(OPAL_CONSOLE_FLUSH)) {
+               __be64 evt;
+
+               WARN_ONCE(1, "opal: OPAL_CONSOLE_FLUSH missing.\n");
+               /*
+                * If OPAL_CONSOLE_FLUSH is not implemented in the firmware,
+                * the console can still be flushed by calling the polling
+                * function while it has OPAL_EVENT_CONSOLE_OUTPUT events.
+                */
                do {
                        opal_poll_events(&evt);
                } while (be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT);
+
+               return OPAL_SUCCESS;
        }
-       spin_unlock_irqrestore(&opal_write_lock, flags);
-       return written;
+
+       do  {
+               rc = OPAL_BUSY;
+               while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
+                       rc = opal_console_flush(vtermno);
+                       if (rc == OPAL_BUSY_EVENT) {
+                               mdelay(OPAL_BUSY_DELAY_MS);
+                               opal_poll_events(NULL);
+                       } else if (rc == OPAL_BUSY) {
+                               mdelay(OPAL_BUSY_DELAY_MS);
+                       }
+               }
+       } while (rc == OPAL_PARTIAL); /* More to flush */
+
+       return opal_error_code(rc);
 }
 
 static int opal_recover_mce(struct pt_regs *regs,