2 * allow a console to be used for early printk
3 * derived from arch/x86/kernel/early_printk.c
5 * Copyright 2007-2009 Analog Devices Inc.
7 * Licensed under the GPL-2
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/serial_core.h>
13 #include <linux/console.h>
14 #include <linux/string.h>
15 #include <linux/reboot.h>
16 #include <asm/blackfin.h>
17 #include <asm/irq_handler.h>
18 #include <asm/early_printk.h>
20 #ifdef CONFIG_SERIAL_BFIN
21 extern struct console *bfin_earlyserial_init(unsigned int port,
24 #ifdef CONFIG_BFIN_JTAG_COMM
25 extern struct console *bfin_jc_early_init(void);
28 static struct console *early_console;
31 #define DEFAULT_PORT 0
32 #define DEFAULT_CFLAG CS8|B57600
34 /* Default console for early crashes */
35 #define DEFAULT_EARLY_PORT "serial,uart0,57600"
37 #ifdef CONFIG_SERIAL_CORE
38 /* What should get here is "0,57600" */
39 static struct console * __init earlyserial_init(char *buf)
43 unsigned int serial_port = DEFAULT_PORT;
44 unsigned int cflag = DEFAULT_CFLAG;
46 serial_port = simple_strtoul(buf, &buf, 10);
50 baud = simple_strtoul(buf, &buf, 10);
88 bit = simple_strtoul(buf, &buf, 10);
103 #ifdef CONFIG_SERIAL_BFIN
104 return bfin_earlyserial_init(serial_port, cflag);
112 int __init setup_early_printk(char *buf)
115 /* Crashing in here would be really bad, so check both the var
116 and the pointer before we start using it
124 if (early_console != NULL)
127 #ifdef CONFIG_SERIAL_BFIN
128 /* Check for Blackfin Serial */
129 if (!strncmp(buf, "serial,uart", 11)) {
131 early_console = earlyserial_init(buf);
135 #ifdef CONFIG_BFIN_JTAG_COMM
136 /* Check for Blackfin JTAG */
137 if (!strncmp(buf, "jtag", 4)) {
139 early_console = bfin_jc_early_init();
144 /* TODO: add framebuffer console support */
147 if (likely(early_console)) {
148 early_console->flags |= CON_BOOT;
150 register_console(early_console);
151 printk(KERN_INFO "early printk enabled on %s%d\n",
153 early_console->index);
160 * Set up a temporary Event Vector Table, so if something bad happens before
161 * the kernel is fully started, it doesn't vector off into somewhere we don't
165 asmlinkage void __init init_early_exception_vectors(void)
171 * This starts up the shadow buffer, incase anything crashes before
175 early_shadow_puts(linux_banner);
176 early_shadow_stamp();
178 if (CPUID != bfin_cpuid()) {
179 early_shadow_puts("Running on wrong machine type, expected");
180 early_shadow_reg(CPUID, 16);
181 early_shadow_puts(", but running on");
182 early_shadow_reg(bfin_cpuid(), 16);
183 early_shadow_puts("\n");
186 /* cannot program in software:
187 * evt0 - emulation (jtag)
190 for (evt = EVT2; evt <= EVT15; evt += 4)
191 bfin_write32(evt, early_trap);
194 /* Set all the return from interrupt, exception, NMI to a known place
195 * so if we do a RETI, RETX or RETN by mistake - we go somewhere known
196 * Note - don't change RETS - we are in a subroutine, or
197 * RETE - since it might screw up if emulator is attached
199 asm("\tRETI = %0; RETX = %0; RETN = %0;\n"
200 : : "p"(early_trap));
204 __attribute__((__noreturn__))
205 asmlinkage void __init early_trap_c(struct pt_regs *fp, void *retaddr)
207 /* This can happen before the uart is initialized, so initialize
208 * the UART now (but only if we are running on the processor we think
209 * we are compiled for - otherwise we write to MMRs that don't exist,
210 * and cause other problems. Nothing comes out the UART, but it does
211 * end up in the __buf_log.
213 if (likely(early_console == NULL) && CPUID == bfin_cpuid())
214 setup_early_printk(DEFAULT_EARLY_PORT);
216 if (!shadow_console_enabled()) {
217 /* crap - we crashed before setup_arch() */
218 early_shadow_puts("panic before setup_arch\n");
219 early_shadow_puts("IPEND:");
220 early_shadow_reg(fp->ipend, 16);
221 if (fp->seqstat & SEQSTAT_EXCAUSE) {
222 early_shadow_puts("\nEXCAUSE:");
223 early_shadow_reg(fp->seqstat & SEQSTAT_EXCAUSE, 8);
225 if (fp->seqstat & SEQSTAT_HWERRCAUSE) {
226 early_shadow_puts("\nHWERRCAUSE:");
228 (fp->seqstat & SEQSTAT_HWERRCAUSE) >> 14, 8);
230 early_shadow_puts("\nErr @");
231 if (fp->ipend & EVT_EVX)
232 early_shadow_reg(fp->retx, 32);
234 early_shadow_reg(fp->pc, 32);
235 #ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
236 early_shadow_puts("\nTrace:");
237 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
238 while (bfin_read_TBUFSTAT() & TBUFCNT) {
239 early_shadow_puts("\nT :");
240 early_shadow_reg(bfin_read_TBUF(), 32);
241 early_shadow_puts("\n S :");
242 early_shadow_reg(bfin_read_TBUF(), 32);
246 early_shadow_puts("\nUse bfin-elf-addr2line to determine "
249 * We should panic(), but we can't - since panic calls printk,
250 * and printk uses memcpy.
251 * we want to reboot, but if the machine type is different,
252 * can't due to machine specific reboot sequences
254 if (CPUID == bfin_cpuid()) {
255 early_shadow_puts("Trying to restart\n");
259 early_shadow_puts("Halting, since it is not safe to restart\n");
261 asm volatile ("EMUEXCPT; IDLE;\n");
264 printk(KERN_EMERG "Early panic\n");
266 dump_bfin_trace_buffer();
272 early_param("earlyprintk", setup_early_printk);