early_printk.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Early printk support for Microblaze.
  3. *
  4. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  5. * Copyright (C) 2007-2009 PetaLogix
  6. * Copyright (C) 2003-2006 Yasushi SHOJI <yashi@atmark-techno.com>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/console.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/string.h>
  16. #include <linux/tty.h>
  17. #include <linux/io.h>
  18. #include <asm/processor.h>
  19. #include <linux/fcntl.h>
  20. #include <asm/setup.h>
  21. #include <asm/prom.h>
  22. static u32 early_console_initialized;
  23. static u32 base_addr;
  24. #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
  25. static void early_printk_uartlite_putc(char c)
  26. {
  27. /*
  28. * Limit how many times we'll spin waiting for TX FIFO status.
  29. * This will prevent lockups if the base address is incorrectly
  30. * set, or any other issue on the UARTLITE.
  31. * This limit is pretty arbitrary, unless we are at about 10 baud
  32. * we'll never timeout on a working UART.
  33. */
  34. unsigned retries = 10000;
  35. /* read status bit - 0x8 offset */
  36. while (--retries && (in_be32(base_addr + 8) & (1 << 3)))
  37. ;
  38. /* Only attempt the iowrite if we didn't timeout */
  39. /* write to TX_FIFO - 0x4 offset */
  40. if (retries)
  41. out_be32(base_addr + 4, c & 0xff);
  42. }
  43. static void early_printk_uartlite_write(struct console *unused,
  44. const char *s, unsigned n)
  45. {
  46. while (*s && n-- > 0) {
  47. early_printk_uartlite_putc(*s);
  48. if (*s == '\n')
  49. early_printk_uartlite_putc('\r');
  50. s++;
  51. }
  52. }
  53. static struct console early_serial_uartlite_console = {
  54. .name = "earlyser",
  55. .write = early_printk_uartlite_write,
  56. .flags = CON_PRINTBUFFER,
  57. .index = -1,
  58. };
  59. #endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */
  60. static struct console *early_console;
  61. void early_printk(const char *fmt, ...)
  62. {
  63. char buf[512];
  64. int n;
  65. va_list ap;
  66. if (early_console_initialized) {
  67. va_start(ap, fmt);
  68. n = vscnprintf(buf, 512, fmt, ap);
  69. early_console->write(early_console, buf, n);
  70. va_end(ap);
  71. }
  72. }
  73. int __init setup_early_printk(char *opt)
  74. {
  75. if (early_console_initialized)
  76. return 1;
  77. #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
  78. base_addr = early_uartlite_console();
  79. if (base_addr) {
  80. early_console_initialized = 1;
  81. #ifdef CONFIG_MMU
  82. early_console_reg_tlb_alloc(base_addr);
  83. #endif
  84. early_console = &early_serial_uartlite_console;
  85. early_printk("early_printk_console is enabled at 0x%08x\n",
  86. base_addr);
  87. /* register_console(early_console); */
  88. return 0;
  89. }
  90. #endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */
  91. return 1;
  92. }
  93. void __init disable_early_printk(void)
  94. {
  95. if (!early_console_initialized || !early_console)
  96. return;
  97. printk(KERN_WARNING "disabling early console\n");
  98. unregister_console(early_console);
  99. early_console_initialized = 0;
  100. }