1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * A udbg backend which logs messages and reads input from in memory
6 * The console output can be read from memcons_output which is a
7 * circular buffer whose next write position is stored in memcons.output_pos.
9 * Input may be passed by writing into the memcons_input buffer when it is
10 * empty. The input buffer is empty when both input_pos == input_start and
11 * *input_start == '\0'.
13 * Copyright (C) 2003-2005 Anton Blanchard and Milton Miller, IBM Corp
14 * Copyright (C) 2013 Alistair Popple, IBM Corp
17 #include <linux/kernel.h>
18 #include <asm/barrier.h>
20 #include <asm/processor.h>
32 static char memcons_output[CONFIG_PPC_MEMCONS_OUTPUT_SIZE];
33 static char memcons_input[CONFIG_PPC_MEMCONS_INPUT_SIZE];
35 struct memcons memcons = {
36 .output_start = memcons_output,
37 .output_pos = memcons_output,
38 .output_end = &memcons_output[CONFIG_PPC_MEMCONS_OUTPUT_SIZE],
39 .input_start = memcons_input,
40 .input_pos = memcons_input,
41 .input_end = &memcons_input[CONFIG_PPC_MEMCONS_INPUT_SIZE],
44 void memcons_putc(char c)
48 *memcons.output_pos = c;
50 new_output_pos = memcons.output_pos + 1;
51 if (new_output_pos >= memcons.output_end)
52 new_output_pos = memcons.output_start;
54 memcons.output_pos = new_output_pos;
57 int memcons_getc_poll(void)
62 if (*memcons.input_pos) {
63 c = *memcons.input_pos;
65 new_input_pos = memcons.input_pos + 1;
66 if (new_input_pos >= memcons.input_end)
67 new_input_pos = memcons.input_start;
68 else if (*new_input_pos == '\0')
69 new_input_pos = memcons.input_start;
71 *memcons.input_pos = '\0';
73 memcons.input_pos = new_input_pos;
80 int memcons_getc(void)
85 c = memcons_getc_poll();
95 void udbg_init_memcons(void)
97 udbg_putc = memcons_putc;
98 udbg_getc = memcons_getc;
99 udbg_getc_poll = memcons_getc_poll;