]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/blackfin/kernel/early_printk.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-artful-kernel.git] / arch / blackfin / kernel / early_printk.c
1 /*
2 * allow a console to be used for early printk
3 * derived from arch/x86/kernel/early_printk.c
4 *
5 * Copyright 2007-2009 Analog Devices Inc.
6 *
7 * Licensed under the GPL-2
8 */
9
10 #include <linux/kernel.h>
11 #include <linux/sched/debug.h>
12 #include <linux/init.h>
13 #include <linux/serial_core.h>
14 #include <linux/console.h>
15 #include <linux/string.h>
16 #include <linux/reboot.h>
17 #include <asm/blackfin.h>
18 #include <asm/irq_handler.h>
19 #include <asm/early_printk.h>
20
21 #ifdef CONFIG_SERIAL_BFIN
22 extern struct console *bfin_earlyserial_init(unsigned int port,
23 unsigned int cflag);
24 #endif
25 #ifdef CONFIG_BFIN_JTAG_COMM
26 extern struct console *bfin_jc_early_init(void);
27 #endif
28
29 /* Default console */
30 #define DEFAULT_PORT 0
31 #define DEFAULT_CFLAG CS8|B57600
32
33 /* Default console for early crashes */
34 #define DEFAULT_EARLY_PORT "serial,uart0,57600"
35
36 #ifdef CONFIG_SERIAL_CORE
37 /* What should get here is "0,57600" */
38 static struct console * __init earlyserial_init(char *buf)
39 {
40 int baud, bit;
41 char parity;
42 unsigned int serial_port = DEFAULT_PORT;
43 unsigned int cflag = DEFAULT_CFLAG;
44
45 serial_port = simple_strtoul(buf, &buf, 10);
46 buf++;
47
48 cflag = 0;
49 baud = simple_strtoul(buf, &buf, 10);
50 switch (baud) {
51 case 1200:
52 cflag |= B1200;
53 break;
54 case 2400:
55 cflag |= B2400;
56 break;
57 case 4800:
58 cflag |= B4800;
59 break;
60 case 9600:
61 cflag |= B9600;
62 break;
63 case 19200:
64 cflag |= B19200;
65 break;
66 case 38400:
67 cflag |= B38400;
68 break;
69 case 115200:
70 cflag |= B115200;
71 break;
72 default:
73 cflag |= B57600;
74 }
75
76 parity = buf[0];
77 buf++;
78 switch (parity) {
79 case 'e':
80 cflag |= PARENB;
81 break;
82 case 'o':
83 cflag |= PARODD;
84 break;
85 }
86
87 bit = simple_strtoul(buf, &buf, 10);
88 switch (bit) {
89 case 5:
90 cflag |= CS5;
91 break;
92 case 6:
93 cflag |= CS6;
94 break;
95 case 7:
96 cflag |= CS7;
97 break;
98 default:
99 cflag |= CS8;
100 }
101
102 #ifdef CONFIG_SERIAL_BFIN
103 return bfin_earlyserial_init(serial_port, cflag);
104 #else
105 return NULL;
106 #endif
107
108 }
109 #endif
110
111 int __init setup_early_printk(char *buf)
112 {
113
114 /* Crashing in here would be really bad, so check both the var
115 and the pointer before we start using it
116 */
117 if (!buf)
118 return 0;
119
120 if (!*buf)
121 return 0;
122
123 if (early_console != NULL)
124 return 0;
125
126 #ifdef CONFIG_SERIAL_BFIN
127 /* Check for Blackfin Serial */
128 if (!strncmp(buf, "serial,uart", 11)) {
129 buf += 11;
130 early_console = earlyserial_init(buf);
131 }
132 #endif
133
134 #ifdef CONFIG_BFIN_JTAG_COMM
135 /* Check for Blackfin JTAG */
136 if (!strncmp(buf, "jtag", 4)) {
137 buf += 4;
138 early_console = bfin_jc_early_init();
139 }
140 #endif
141
142 #ifdef CONFIG_FB
143 /* TODO: add framebuffer console support */
144 #endif
145
146 if (likely(early_console)) {
147 early_console->flags |= CON_BOOT;
148
149 register_console(early_console);
150 printk(KERN_INFO "early printk enabled on %s%d\n",
151 early_console->name,
152 early_console->index);
153 }
154
155 return 0;
156 }
157
158 /*
159 * Set up a temporary Event Vector Table, so if something bad happens before
160 * the kernel is fully started, it doesn't vector off into somewhere we don't
161 * know
162 */
163
164 asmlinkage void __init init_early_exception_vectors(void)
165 {
166 u32 evt;
167 SSYNC();
168
169 /*
170 * This starts up the shadow buffer, incase anything crashes before
171 * setup arch
172 */
173 mark_shadow_error();
174 early_shadow_puts(linux_banner);
175 early_shadow_stamp();
176
177 if (CPUID != bfin_cpuid()) {
178 early_shadow_puts("Running on wrong machine type, expected");
179 early_shadow_reg(CPUID, 16);
180 early_shadow_puts(", but running on");
181 early_shadow_reg(bfin_cpuid(), 16);
182 early_shadow_puts("\n");
183 }
184
185 /* cannot program in software:
186 * evt0 - emulation (jtag)
187 * evt1 - reset
188 */
189 for (evt = EVT2; evt <= EVT15; evt += 4)
190 bfin_write32(evt, early_trap);
191 CSYNC();
192
193 /* Set all the return from interrupt, exception, NMI to a known place
194 * so if we do a RETI, RETX or RETN by mistake - we go somewhere known
195 * Note - don't change RETS - we are in a subroutine, or
196 * RETE - since it might screw up if emulator is attached
197 */
198 asm("\tRETI = %0; RETX = %0; RETN = %0;\n"
199 : : "p"(early_trap));
200
201 }
202
203 __attribute__((__noreturn__))
204 asmlinkage void __init early_trap_c(struct pt_regs *fp, void *retaddr)
205 {
206 /* This can happen before the uart is initialized, so initialize
207 * the UART now (but only if we are running on the processor we think
208 * we are compiled for - otherwise we write to MMRs that don't exist,
209 * and cause other problems. Nothing comes out the UART, but it does
210 * end up in the __buf_log.
211 */
212 if (likely(early_console == NULL) && CPUID == bfin_cpuid())
213 setup_early_printk(DEFAULT_EARLY_PORT);
214
215 if (!shadow_console_enabled()) {
216 /* crap - we crashed before setup_arch() */
217 early_shadow_puts("panic before setup_arch\n");
218 early_shadow_puts("IPEND:");
219 early_shadow_reg(fp->ipend, 16);
220 if (fp->seqstat & SEQSTAT_EXCAUSE) {
221 early_shadow_puts("\nEXCAUSE:");
222 early_shadow_reg(fp->seqstat & SEQSTAT_EXCAUSE, 8);
223 }
224 if (fp->seqstat & SEQSTAT_HWERRCAUSE) {
225 early_shadow_puts("\nHWERRCAUSE:");
226 early_shadow_reg(
227 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14, 8);
228 }
229 early_shadow_puts("\nErr @");
230 if (fp->ipend & EVT_EVX)
231 early_shadow_reg(fp->retx, 32);
232 else
233 early_shadow_reg(fp->pc, 32);
234 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
235 early_shadow_puts("\nTrace:");
236 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
237 while (bfin_read_TBUFSTAT() & TBUFCNT) {
238 early_shadow_puts("\nT :");
239 early_shadow_reg(bfin_read_TBUF(), 32);
240 early_shadow_puts("\n S :");
241 early_shadow_reg(bfin_read_TBUF(), 32);
242 }
243 }
244 #endif
245 early_shadow_puts("\nUse bfin-elf-addr2line to determine "
246 "function names\n");
247 /*
248 * We should panic(), but we can't - since panic calls printk,
249 * and printk uses memcpy.
250 * we want to reboot, but if the machine type is different,
251 * can't due to machine specific reboot sequences
252 */
253 if (CPUID == bfin_cpuid()) {
254 early_shadow_puts("Trying to restart\n");
255 machine_restart("");
256 }
257
258 early_shadow_puts("Halting, since it is not safe to restart\n");
259 while (1)
260 asm volatile ("EMUEXCPT; IDLE;\n");
261
262 } else {
263 printk(KERN_EMERG "Early panic\n");
264 show_regs(fp);
265 dump_bfin_trace_buffer();
266 }
267
268 panic("Died early");
269 }
270
271 early_param("earlyprintk", setup_early_printk);