early_printk.c 6.7 KB

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