Commit 95b861a7 authored by Nicholas Piggin's avatar Nicholas Piggin Committed by Michael Ellerman

powerpc/powernv: provide a console flush operation for opal hvc driver

Provide the flush hv_op for the opal hvc driver. This will flush the
firmware console buffers without spinning with interrupts disabled.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 997dd26c
...@@ -308,6 +308,7 @@ extern void opal_configure_cores(void); ...@@ -308,6 +308,7 @@ extern void opal_configure_cores(void);
extern int opal_get_chars(uint32_t vtermno, char *buf, int count); 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_put_chars(uint32_t vtermno, const char *buf, int total_len);
extern int opal_put_chars_atomic(uint32_t vtermno, const char *buf, int total_len); extern int opal_put_chars_atomic(uint32_t vtermno, const char *buf, int total_len);
extern int opal_flush_chars(uint32_t vtermno, bool wait);
extern int opal_flush_console(uint32_t vtermno); extern int opal_flush_console(uint32_t vtermno);
extern void hvc_opal_init_early(void); extern void hvc_opal_init_early(void);
......
...@@ -370,12 +370,8 @@ static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, b ...@@ -370,12 +370,8 @@ static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, b
olen = cpu_to_be64(total_len); olen = cpu_to_be64(total_len);
rc = opal_console_write(vtermno, &olen, data); rc = opal_console_write(vtermno, &olen, data);
if (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { if (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
if (rc == OPAL_BUSY_EVENT) { if (rc == OPAL_BUSY_EVENT)
mdelay(OPAL_BUSY_DELAY_MS);
opal_poll_events(NULL); opal_poll_events(NULL);
} else if (rc == OPAL_BUSY_EVENT) {
mdelay(OPAL_BUSY_DELAY_MS);
}
written = -EAGAIN; written = -EAGAIN;
goto out; goto out;
} }
...@@ -401,15 +397,6 @@ static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, b ...@@ -401,15 +397,6 @@ static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, b
if (atomic) if (atomic)
spin_unlock_irqrestore(&opal_write_lock, flags); spin_unlock_irqrestore(&opal_write_lock, flags);
/* In the -EAGAIN case, callers loop, so we have to flush the console
* here in case they have interrupts off (and we don't want to wait
* for async flushing if we can make immediate progress here). If
* necessary the API could be made entirely non-flushing if the
* callers had a ->flush API to use.
*/
if (written == -EAGAIN)
opal_flush_console(vtermno);
return written; return written;
} }
...@@ -429,40 +416,74 @@ int opal_put_chars_atomic(uint32_t vtermno, const char *data, int total_len) ...@@ -429,40 +416,74 @@ int opal_put_chars_atomic(uint32_t vtermno, const char *data, int total_len)
return __opal_put_chars(vtermno, data, total_len, true); return __opal_put_chars(vtermno, data, total_len, true);
} }
int opal_flush_console(uint32_t vtermno) static s64 __opal_flush_console(uint32_t vtermno)
{ {
s64 rc; s64 rc;
if (!opal_check_token(OPAL_CONSOLE_FLUSH)) { if (!opal_check_token(OPAL_CONSOLE_FLUSH)) {
__be64 evt; __be64 evt;
WARN_ONCE(1, "opal: OPAL_CONSOLE_FLUSH missing.\n");
/* /*
* If OPAL_CONSOLE_FLUSH is not implemented in the firmware, * If OPAL_CONSOLE_FLUSH is not implemented in the firmware,
* the console can still be flushed by calling the polling * the console can still be flushed by calling the polling
* function while it has OPAL_EVENT_CONSOLE_OUTPUT events. * function while it has OPAL_EVENT_CONSOLE_OUTPUT events.
*/ */
do { WARN_ONCE(1, "opal: OPAL_CONSOLE_FLUSH missing.\n");
opal_poll_events(&evt);
} while (be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT); opal_poll_events(&evt);
if (!(be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT))
return OPAL_SUCCESS;
return OPAL_BUSY;
return OPAL_SUCCESS; } else {
rc = opal_console_flush(vtermno);
if (rc == OPAL_BUSY_EVENT) {
opal_poll_events(NULL);
rc = OPAL_BUSY;
}
return rc;
} }
do { }
rc = OPAL_BUSY;
while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { /*
rc = opal_console_flush(vtermno); * opal_flush_console spins until the console is flushed
if (rc == OPAL_BUSY_EVENT) { */
mdelay(OPAL_BUSY_DELAY_MS); int opal_flush_console(uint32_t vtermno)
opal_poll_events(NULL); {
} else if (rc == OPAL_BUSY) { for (;;) {
mdelay(OPAL_BUSY_DELAY_MS); s64 rc = __opal_flush_console(vtermno);
if (rc == OPAL_BUSY || rc == OPAL_PARTIAL) {
mdelay(1);
continue;
}
return opal_error_code(rc);
}
}
/*
* opal_flush_chars is an hvc interface that sleeps until the console is
* flushed if wait, otherwise it will return -EBUSY if the console has data,
* -EAGAIN if it has data and some of it was flushed.
*/
int opal_flush_chars(uint32_t vtermno, bool wait)
{
for (;;) {
s64 rc = __opal_flush_console(vtermno);
if (rc == OPAL_BUSY || rc == OPAL_PARTIAL) {
if (wait) {
msleep(OPAL_BUSY_DELAY_MS);
continue;
} }
if (rc == OPAL_PARTIAL)
return -EAGAIN;
} }
} while (rc == OPAL_PARTIAL); /* More to flush */
return opal_error_code(rc); return opal_error_code(rc);
}
} }
static int opal_recover_mce(struct pt_regs *regs, static int opal_recover_mce(struct pt_regs *regs,
......
...@@ -52,6 +52,7 @@ static u32 hvc_opal_boot_termno; ...@@ -52,6 +52,7 @@ static u32 hvc_opal_boot_termno;
static const struct hv_ops hvc_opal_raw_ops = { static const struct hv_ops hvc_opal_raw_ops = {
.get_chars = opal_get_chars, .get_chars = opal_get_chars,
.put_chars = opal_put_chars, .put_chars = opal_put_chars,
.flush = opal_flush_chars,
.notifier_add = notifier_add_irq, .notifier_add = notifier_add_irq,
.notifier_del = notifier_del_irq, .notifier_del = notifier_del_irq,
.notifier_hangup = notifier_hangup_irq, .notifier_hangup = notifier_hangup_irq,
...@@ -141,6 +142,7 @@ static int hvc_opal_hvsi_tiocmset(struct hvc_struct *hp, unsigned int set, ...@@ -141,6 +142,7 @@ static int hvc_opal_hvsi_tiocmset(struct hvc_struct *hp, unsigned int set,
static const struct hv_ops hvc_opal_hvsi_ops = { static const struct hv_ops hvc_opal_hvsi_ops = {
.get_chars = hvc_opal_hvsi_get_chars, .get_chars = hvc_opal_hvsi_get_chars,
.put_chars = hvc_opal_hvsi_put_chars, .put_chars = hvc_opal_hvsi_put_chars,
.flush = opal_flush_chars,
.notifier_add = hvc_opal_hvsi_open, .notifier_add = hvc_opal_hvsi_open,
.notifier_del = hvc_opal_hvsi_close, .notifier_del = hvc_opal_hvsi_close,
.notifier_hangup = hvc_opal_hvsi_hangup, .notifier_hangup = hvc_opal_hvsi_hangup,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment