aboutsummaryrefslogtreecommitdiff
path: root/arch/blackfin/kernel/shadow_console.c
blob: 15819ff10573f925364cf3d116eb9fefa2ba1bd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * manage a small early shadow of the log buffer which we can pass between the
 * bootloader so early crash messages are communicated properly and easily
 *
 * Copyright 2009 Analog Devices Inc.
 *
 * Enter bugs at http://blackfin.uclinux.org/
 *
 * Licensed under the GPL-2 or later.
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/console.h>
#include <linux/string.h>
#include <asm/blackfin.h>
#include <asm/irq_handler.h>
#include <asm/early_printk.h>

#define SHADOW_CONSOLE_START		(0x500)
#define SHADOW_CONSOLE_END		(0x1000)
#define SHADOW_CONSOLE_MAGIC_LOC	(0x4F0)
#define SHADOW_CONSOLE_MAGIC		(0xDEADBEEF)

static __initdata char *shadow_console_buffer = (char *)SHADOW_CONSOLE_START;

static __init void early_shadow_write(struct console *con, const char *s,
				unsigned int n)
{
	/*
	 * save 2 bytes for the double null at the end
	 * once we fail on a long line, make sure we don't write a short line afterwards
	 */
	if ((shadow_console_buffer + n) <= (char *)(SHADOW_CONSOLE_END - 2)) {
		memcpy(shadow_console_buffer, s, n);
		shadow_console_buffer += n;
		shadow_console_buffer[0] = 0;
		shadow_console_buffer[1] = 0;
	} else
		shadow_console_buffer = (char *)SHADOW_CONSOLE_END;
}

static __initdata struct console early_shadow_console = {
	.name = "early_shadow",
	.write = early_shadow_write,
	.flags = CON_BOOT | CON_PRINTBUFFER,
	.index = -1,
	.device = 0,
};

__init void enable_shadow_console(void)
{
	int *loc = (int *)SHADOW_CONSOLE_MAGIC_LOC;

	if (!(early_shadow_console.flags & CON_ENABLED)) {
		register_console(&early_shadow_console);
		/* for now, assume things are going to fail */
		*loc = SHADOW_CONSOLE_MAGIC;
		loc++;
		*loc = SHADOW_CONSOLE_START;
	}
}

static __init int disable_shadow_console(void)
{
	/*
	 * by the time pure_initcall runs, the standard console is enabled,
	 * and the early_console is off, so unset the magic numbers
	 * unregistering the console is taken care of in common code (See
	 * ./kernel/printk:disable_boot_consoles() )
	 */
	int *loc = (int *)SHADOW_CONSOLE_MAGIC_LOC;

	*loc = 0;

	return 0;
}
pure_initcall(disable_shadow_console);