1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2016 IBM Corporation.
10 #include "../include/asm/opal-api.h"
12 /* Global OPAL struct used by opal-call.S */
18 static u32 opal_con_id
;
20 /* see opal-wrappers.S */
21 int64_t opal_console_write(int64_t term_number
, u64
*length
, const u8
*buffer
);
22 int64_t opal_console_read(int64_t term_number
, uint64_t *length
, u8
*buffer
);
23 int64_t opal_console_write_buffer_space(uint64_t term_number
, uint64_t *length
);
24 int64_t opal_console_flush(uint64_t term_number
);
25 int64_t opal_poll_events(uint64_t *outstanding_event_mask
);
27 void opal_kentry(unsigned long fdt_addr
, void *vmlinux_addr
);
29 static int opal_con_open(void)
32 * When OPAL loads the boot kernel it stashes the OPAL base and entry
33 * address in r8 and r9 so the kernel can use the OPAL console
34 * before unflattening the devicetree. While executing the wrapper will
35 * probably trash r8 and r9 so this kentry hook restores them before
36 * entering the decompressed kernel.
38 platform_ops
.kentry
= opal_kentry
;
42 static void opal_con_putc(unsigned char c
)
48 rc
= opal_console_write_buffer_space(opal_con_id
, &olen
);
49 len
= be64_to_cpu(olen
);
52 opal_poll_events(NULL
);
56 olen
= cpu_to_be64(1);
57 opal_console_write(opal_con_id
, &olen
, &c
);
60 static void opal_con_close(void)
62 opal_console_flush(opal_con_id
);
65 static void opal_init(void)
69 opal_node
= finddevice("/ibm,opal");
72 if (getprop(opal_node
, "opal-base-address", &opal
.base
, sizeof(u64
)) < 0)
74 opal
.base
= be64_to_cpu(opal
.base
);
75 if (getprop(opal_node
, "opal-entry-address", &opal
.entry
, sizeof(u64
)) < 0)
77 opal
.entry
= be64_to_cpu(opal
.entry
);
80 int opal_console_init(void *devp
, struct serial_console_data
*scdp
)
85 int n
= getprop(devp
, "reg", &opal_con_id
, sizeof(u32
));
88 opal_con_id
= be32_to_cpu(opal_con_id
);
92 scdp
->open
= opal_con_open
;
93 scdp
->putc
= opal_con_putc
;
94 scdp
->close
= opal_con_close
;