treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / powerpc / sysdev / udbg_memcons.c
blobd38bbeed219b8174c2176171ca483b98e77d9804
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * A udbg backend which logs messages and reads input from in memory
4 * buffers.
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>
19 #include <asm/page.h>
20 #include <asm/processor.h>
21 #include <asm/udbg.h>
23 struct memcons {
24 char *output_start;
25 char *output_pos;
26 char *output_end;
27 char *input_start;
28 char *input_pos;
29 char *input_end;
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)
46 char *new_output_pos;
48 *memcons.output_pos = c;
49 wmb();
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)
59 char c;
60 char *new_input_pos;
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';
72 wmb();
73 memcons.input_pos = new_input_pos;
74 return c;
77 return -1;
80 int memcons_getc(void)
82 int c;
84 while (1) {
85 c = memcons_getc_poll();
86 if (c == -1)
87 cpu_relax();
88 else
89 break;
92 return c;
95 void udbg_init_memcons(void)
97 udbg_putc = memcons_putc;
98 udbg_getc = memcons_getc;
99 udbg_getc_poll = memcons_getc_poll;