diff mbox

[v3,07/10] console: add opal_con_ops structure

Message ID 1482295952-30060-8-git-send-email-oohall@gmail.com
State Accepted
Headers show

Commit Message

Oliver O'Halloran Dec. 21, 2016, 4:52 a.m. UTC
Adds a separate structure to house the operations for the OPAL console.
This is used to define a new API for dealing with the OPAL console in
the next patch.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 core/console.c       | 14 ++++++++++++++
 hw/fsp/fsp-console.c | 15 +++++++++++++++
 hw/lpc-uart.c        | 17 +++++++++++++++++
 include/console.h    | 27 +++++++++++++++++++++++++++
 4 files changed, 73 insertions(+)

Comments

Andrew Donnellan Jan. 3, 2017, 7:33 a.m. UTC | #1
On 21/12/16 15:52, Oliver O'Halloran wrote:
> Adds a separate structure to house the operations for the OPAL console.
> This is used to define a new API for dealing with the OPAL console in
> the next patch.
>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>

Looks good

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
diff mbox

Patch

diff --git a/core/console.c b/core/console.c
index be5aa6211ce4..4267a6bb0190 100644
--- a/core/console.c
+++ b/core/console.c
@@ -373,6 +373,11 @@  static int64_t dummy_console_read(int64_t term_number, int64_t *length,
 }
 opal_call(OPAL_CONSOLE_READ, dummy_console_read, 3);
 
+static int64_t dummy_console_flush(int64_t term_number __unused)
+{
+	return OPAL_UNSUPPORTED;
+}
+
 static void dummy_console_poll(void *data __unused)
 {
 	bool has_data = false;
@@ -406,3 +411,12 @@  void dummy_console_add_nodes(void)
 
 	opal_add_poller(dummy_console_poll, NULL);
 }
+
+struct opal_con_ops dummy_opal_con = {
+	.name = "Dummy Console",
+	.init = dummy_console_add_nodes,
+	.read = dummy_console_read,
+	.write = dummy_console_write,
+	.space = dummy_console_write_buffer_space,
+	.flush = dummy_console_flush,
+};
diff --git a/hw/fsp/fsp-console.c b/hw/fsp/fsp-console.c
index 8fd18d1a8f03..8589e8c031f7 100644
--- a/hw/fsp/fsp-console.c
+++ b/hw/fsp/fsp-console.c
@@ -818,6 +818,21 @@  void fsp_console_init(void)
 	op_display(OP_LOG, OP_MOD_FSPCON, 0x0005);
 }
 
+static int64_t fsp_console_flush(int64_t terminal __unused)
+{
+	/* FIXME: There's probably something we can do here... */
+	return OPAL_PARAMETER;
+}
+
+struct opal_con_ops fsp_opal_con = {
+	.name = "FSP OPAL console",
+	.init = NULL, /* all the required setup is done in fsp_console_init() */
+	.read = fsp_console_read,
+	.write = fsp_console_write,
+	.space = fsp_console_write_buffer_space,
+	.flush = fsp_console_flush,
+};
+
 static void flush_all_input(void)
 {
 	unsigned int i;
diff --git a/hw/lpc-uart.c b/hw/lpc-uart.c
index 2383ff54ee32..cc1c16506a47 100644
--- a/hw/lpc-uart.c
+++ b/hw/lpc-uart.c
@@ -375,6 +375,14 @@  static int64_t uart_opal_read(int64_t term_number, int64_t *length,
 	return OPAL_SUCCESS;
 }
 
+static int64_t uart_opal_flush(int64_t term_number)
+{
+	if (term_number != 0)
+		return OPAL_PARAMETER;
+
+	return uart_con_flush();
+}
+
 static void __uart_do_poll(u8 trace_ctx)
 {
 	if (!in_buf)
@@ -453,6 +461,15 @@  void uart_setup_opal_console(void)
 	opal_add_poller(uart_console_poll, NULL);
 }
 
+struct opal_con_ops uart_opal_con = {
+	.name = "OPAL UART console",
+	.init = uart_setup_opal_console,
+	.read = uart_opal_read,
+	.write = uart_opal_write,
+	.space = uart_opal_write_buffer_space,
+	.flush = uart_opal_flush,
+};
+
 static bool uart_init_hw(unsigned int speed, unsigned int clock)
 {
 	unsigned int dll = (clock / 16) / speed;
diff --git a/include/console.h b/include/console.h
index 08d2961e527a..e821ce703898 100644
--- a/include/console.h
+++ b/include/console.h
@@ -54,6 +54,28 @@  struct con_ops {
 	int64_t (*flush)(void);
 };
 
+struct opal_con_ops {
+	const char *name;
+
+	/*
+	 * OPAL console driver specific init function.
+	 */
+	void (*init)(void);
+
+	int64_t (*write)(int64_t term, int64_t *len, const uint8_t *buf);
+	int64_t (*read)(int64_t term, int64_t *len, uint8_t *buf);
+
+	/*
+	 * returns the amount of space available in the console write buffer
+	 */
+	int64_t (*space)(int64_t term_number, int64_t *length);
+
+	/*
+	 * Forces the write buffer to be flushed by the driver
+	 */
+	int64_t (*flush)(int64_t term_number);
+};
+
 extern bool dummy_console_enabled(void);
 extern void force_dummy_console(void);
 extern bool flush_console(void);
@@ -73,4 +95,9 @@  extern void dummy_console_add_nodes(void);
 struct dt_node *add_opal_console_node(int index, const char *type,
 	uint32_t write_buffer_size);
 
+/* OPAL console drivers */
+extern struct opal_con_ops uart_opal_con;
+extern struct opal_con_ops fsp_opal_con;
+extern struct opal_con_ops dummy_opal_con;
+
 #endif /* __CONSOLE_H */