early_printk.c 6.0 KB

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