x86/efi: Enforce CONFIG_RELOCATABLE for EFI boot stub
[linux/fpc-iii.git] / arch / powerpc / sysdev / udbg_memcons.c
blobce5a7b489e4b4282b7b0ac4d5f75ffd66c00ff36
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/init.h>
22 #include <linux/kernel.h>
23 #include <asm/barrier.h>
24 #include <asm/page.h>
25 #include <asm/processor.h>
26 #include <asm/udbg.h>
28 struct memcons {
29 char *output_start;
30 char *output_pos;
31 char *output_end;
32 char *input_start;
33 char *input_pos;
34 char *input_end;
37 static char memcons_output[CONFIG_PPC_MEMCONS_OUTPUT_SIZE];
38 static char memcons_input[CONFIG_PPC_MEMCONS_INPUT_SIZE];
40 struct memcons memcons = {
41 .output_start = memcons_output,
42 .output_pos = memcons_output,
43 .output_end = &memcons_output[CONFIG_PPC_MEMCONS_OUTPUT_SIZE],
44 .input_start = memcons_input,
45 .input_pos = memcons_input,
46 .input_end = &memcons_input[CONFIG_PPC_MEMCONS_INPUT_SIZE],
49 void memcons_putc(char c)
51 char *new_output_pos;
53 *memcons.output_pos = c;
54 wmb();
55 new_output_pos = memcons.output_pos + 1;
56 if (new_output_pos >= memcons.output_end)
57 new_output_pos = memcons.output_start;
59 memcons.output_pos = new_output_pos;
62 int memcons_getc_poll(void)
64 char c;
65 char *new_input_pos;
67 if (*memcons.input_pos) {
68 c = *memcons.input_pos;
70 new_input_pos = memcons.input_pos + 1;
71 if (new_input_pos >= memcons.input_end)
72 new_input_pos = memcons.input_start;
73 else if (*new_input_pos == '\0')
74 new_input_pos = memcons.input_start;
76 *memcons.input_pos = '\0';
77 wmb();
78 memcons.input_pos = new_input_pos;
79 return c;
82 return -1;
85 int memcons_getc(void)
87 int c;
89 while (1) {
90 c = memcons_getc_poll();
91 if (c == -1)
92 cpu_relax();
93 else
94 break;
97 return c;
100 void udbg_init_memcons(void)
102 udbg_putc = memcons_putc;
103 udbg_getc = memcons_getc;
104 udbg_getc_poll = memcons_getc_poll;