Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / arch / powerpc / sysdev / udbg_memcons.c
blob9998c0de12d056739cf891e318ddb08b0f7cfc27
1 /*
2 * A udbg backend which logs messages and reads input from in memory
3 * buffers.
5 * The console output can be read from memcons_output which is a
6 * circular buffer whose next write position is stored in memcons.output_pos.
8 * Input may be passed by writing into the memcons_input buffer when it is
9 * empty. The input buffer is empty when both input_pos == input_start and
10 * *input_start == '\0'.
12 * Copyright (C) 2003-2005 Anton Blanchard and Milton Miller, IBM Corp
13 * Copyright (C) 2013 Alistair Popple, IBM Corp
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
21 #include <linux/kernel.h>
22 #include <asm/barrier.h>
23 #include <asm/page.h>
24 #include <asm/processor.h>
25 #include <asm/udbg.h>
27 struct memcons {
28 char *output_start;
29 char *output_pos;
30 char *output_end;
31 char *input_start;
32 char *input_pos;
33 char *input_end;
36 static char memcons_output[CONFIG_PPC_MEMCONS_OUTPUT_SIZE];
37 static char memcons_input[CONFIG_PPC_MEMCONS_INPUT_SIZE];
39 struct memcons memcons = {
40 .output_start = memcons_output,
41 .output_pos = memcons_output,
42 .output_end = &memcons_output[CONFIG_PPC_MEMCONS_OUTPUT_SIZE],
43 .input_start = memcons_input,
44 .input_pos = memcons_input,
45 .input_end = &memcons_input[CONFIG_PPC_MEMCONS_INPUT_SIZE],
48 void memcons_putc(char c)
50 char *new_output_pos;
52 *memcons.output_pos = c;
53 wmb();
54 new_output_pos = memcons.output_pos + 1;
55 if (new_output_pos >= memcons.output_end)
56 new_output_pos = memcons.output_start;
58 memcons.output_pos = new_output_pos;
61 int memcons_getc_poll(void)
63 char c;
64 char *new_input_pos;
66 if (*memcons.input_pos) {
67 c = *memcons.input_pos;
69 new_input_pos = memcons.input_pos + 1;
70 if (new_input_pos >= memcons.input_end)
71 new_input_pos = memcons.input_start;
72 else if (*new_input_pos == '\0')
73 new_input_pos = memcons.input_start;
75 *memcons.input_pos = '\0';
76 wmb();
77 memcons.input_pos = new_input_pos;
78 return c;
81 return -1;
84 int memcons_getc(void)
86 int c;
88 while (1) {
89 c = memcons_getc_poll();
90 if (c == -1)
91 cpu_relax();
92 else
93 break;
96 return c;
99 void udbg_init_memcons(void)
101 udbg_putc = memcons_putc;
102 udbg_getc = memcons_getc;
103 udbg_getc_poll = memcons_getc_poll;