Commit 17cc1dd4 authored by Nicholas Piggin's avatar Nicholas Piggin Committed by Michael Ellerman

powerpc/powernv: implement opal_put_chars_atomic

The RAW console does not need writes to be atomic, so relax
opal_put_chars to be able to do partial writes, and implement an
_atomic variant which does not take a spinlock. This API is used
in xmon, so the less locking that is used, the better chance there
is that a crash can be debugged.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent ac4ac788
...@@ -305,6 +305,7 @@ extern void opal_configure_cores(void); ...@@ -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_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_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);
......
...@@ -344,9 +344,9 @@ int opal_get_chars(uint32_t vtermno, char *buf, int count) ...@@ -344,9 +344,9 @@ int opal_get_chars(uint32_t vtermno, char *buf, int count)
return 0; return 0;
} }
int opal_put_chars(uint32_t vtermno, const char *data, int total_len) static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, bool atomic)
{ {
unsigned long flags; unsigned long flags = 0 /* shut up gcc */;
int written; int written;
__be64 olen; __be64 olen;
s64 rc; s64 rc;
...@@ -354,11 +354,8 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len) ...@@ -354,11 +354,8 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
if (!opal.entry) if (!opal.entry)
return -ENODEV; return -ENODEV;
/* We want put_chars to be atomic to avoid mangling of hvsi if (atomic)
* packets. To do that, we first test for room and return spin_lock_irqsave(&opal_write_lock, flags);
* -EAGAIN if there isn't enough.
*/
spin_lock_irqsave(&opal_write_lock, flags);
rc = opal_console_write_buffer_space(vtermno, &olen); rc = opal_console_write_buffer_space(vtermno, &olen);
if (rc || be64_to_cpu(olen) < total_len) { if (rc || be64_to_cpu(olen) < total_len) {
/* Closed -> drop characters */ /* Closed -> drop characters */
...@@ -391,14 +388,18 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len) ...@@ -391,14 +388,18 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
written = be64_to_cpu(olen); written = be64_to_cpu(olen);
if (written < total_len) { if (written < total_len) {
/* Should not happen */ if (atomic) {
pr_warn("atomic console write returned partial len=%d written=%d\n", total_len, written); /* Should not happen */
pr_warn("atomic console write returned partial "
"len=%d written=%d\n", total_len, written);
}
if (!written) if (!written)
written = -EAGAIN; written = -EAGAIN;
} }
out: out:
spin_unlock_irqrestore(&opal_write_lock, flags); if (atomic)
spin_unlock_irqrestore(&opal_write_lock, flags);
/* In the -EAGAIN case, callers loop, so we have to flush the console /* 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 * here in case they have interrupts off (and we don't want to wait
...@@ -412,6 +413,22 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len) ...@@ -412,6 +413,22 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
return written; return written;
} }
int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
{
return __opal_put_chars(vtermno, data, total_len, false);
}
/*
* opal_put_chars_atomic will not perform partial-writes. Data will be
* atomically written to the terminal or not at all. This is not strictly
* true at the moment because console space can race with OPAL's console
* writes.
*/
int opal_put_chars_atomic(uint32_t vtermno, const char *data, int total_len)
{
return __opal_put_chars(vtermno, data, total_len, true);
}
int opal_flush_console(uint32_t vtermno) int opal_flush_console(uint32_t vtermno)
{ {
s64 rc; s64 rc;
......
...@@ -183,9 +183,15 @@ static int hvc_opal_probe(struct platform_device *dev) ...@@ -183,9 +183,15 @@ static int hvc_opal_probe(struct platform_device *dev)
return -ENOMEM; return -ENOMEM;
pv->proto = proto; pv->proto = proto;
hvc_opal_privs[termno] = pv; hvc_opal_privs[termno] = pv;
if (proto == HV_PROTOCOL_HVSI) if (proto == HV_PROTOCOL_HVSI) {
hvsilib_init(&pv->hvsi, opal_get_chars, opal_put_chars, /*
* We want put_chars to be atomic to avoid mangling of
* hvsi packets.
*/
hvsilib_init(&pv->hvsi,
opal_get_chars, opal_put_chars_atomic,
termno, 0); termno, 0);
}
/* Instanciate now to establish a mapping index==vtermno */ /* Instanciate now to establish a mapping index==vtermno */
hvc_instantiate(termno, termno, ops); hvc_instantiate(termno, termno, ops);
...@@ -375,8 +381,9 @@ void __init hvc_opal_init_early(void) ...@@ -375,8 +381,9 @@ void __init hvc_opal_init_early(void)
else if (of_device_is_compatible(stdout_node,"ibm,opal-console-hvsi")) { else if (of_device_is_compatible(stdout_node,"ibm,opal-console-hvsi")) {
hvc_opal_boot_priv.proto = HV_PROTOCOL_HVSI; hvc_opal_boot_priv.proto = HV_PROTOCOL_HVSI;
ops = &hvc_opal_hvsi_ops; ops = &hvc_opal_hvsi_ops;
hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, hvsilib_init(&hvc_opal_boot_priv.hvsi,
opal_put_chars, index, 1); opal_get_chars, opal_put_chars_atomic,
index, 1);
/* HVSI, perform the handshake now */ /* HVSI, perform the handshake now */
hvsilib_establish(&hvc_opal_boot_priv.hvsi); hvsilib_establish(&hvc_opal_boot_priv.hvsi);
pr_devel("hvc_opal: Found HVSI console\n"); pr_devel("hvc_opal: Found HVSI console\n");
...@@ -408,7 +415,8 @@ void __init udbg_init_debug_opal_hvsi(void) ...@@ -408,7 +415,8 @@ void __init udbg_init_debug_opal_hvsi(void)
hvc_opal_privs[index] = &hvc_opal_boot_priv; hvc_opal_privs[index] = &hvc_opal_boot_priv;
hvc_opal_boot_termno = index; hvc_opal_boot_termno = index;
udbg_init_opal_common(); udbg_init_opal_common();
hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, opal_put_chars, hvsilib_init(&hvc_opal_boot_priv.hvsi,
opal_get_chars, opal_put_chars_atomic,
index, 1); index, 1);
hvsilib_establish(&hvc_opal_boot_priv.hvsi); hvsilib_establish(&hvc_opal_boot_priv.hvsi);
} }
......
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