2 * Copyright (c) 2016 IBM Corporation.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
14 #include "../include/asm/opal-api.h"
16 /* Global OPAL struct used by opal-call.S */
22 static u32 opal_con_id;
24 /* see opal-wrappers.S */
25 int64_t opal_console_write(int64_t term_number, u64 *length, const u8 *buffer);
26 int64_t opal_console_read(int64_t term_number, uint64_t *length, u8 *buffer);
27 int64_t opal_console_write_buffer_space(uint64_t term_number, uint64_t *length);
28 int64_t opal_console_flush(uint64_t term_number);
29 int64_t opal_poll_events(uint64_t *outstanding_event_mask);
31 void opal_kentry(unsigned long fdt_addr, void *vmlinux_addr);
33 static int opal_con_open(void)
36 * When OPAL loads the boot kernel it stashes the OPAL base and entry
37 * address in r8 and r9 so the kernel can use the OPAL console
38 * before unflattening the devicetree. While executing the wrapper will
39 * probably trash r8 and r9 so this kentry hook restores them before
40 * entering the decompressed kernel.
42 platform_ops.kentry = opal_kentry;
46 static void opal_con_putc(unsigned char c)
52 rc = opal_console_write_buffer_space(opal_con_id, &olen);
53 len = be64_to_cpu(olen);
56 opal_poll_events(NULL);
60 olen = cpu_to_be64(1);
61 opal_console_write(opal_con_id, &olen, &c);
64 static void opal_con_close(void)
66 opal_console_flush(opal_con_id);
69 static void opal_init(void)
73 opal_node = finddevice("/ibm,opal");
76 if (getprop(opal_node, "opal-base-address", &opal.base, sizeof(u64)) < 0)
78 opal.base = be64_to_cpu(opal.base);
79 if (getprop(opal_node, "opal-entry-address", &opal.entry, sizeof(u64)) < 0)
81 opal.entry = be64_to_cpu(opal.entry);
84 int opal_console_init(void *devp, struct serial_console_data *scdp)
89 int n = getprop(devp, "reg", &opal_con_id, sizeof(u32));
92 opal_con_id = be32_to_cpu(opal_con_id);
96 scdp->open = opal_con_open;
97 scdp->putc = opal_con_putc;
98 scdp->close = opal_con_close;