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