shadow_console.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * manage a small early shadow of the log buffer which we can pass between the
  3. * bootloader so early crash messages are communicated properly and easily
  4. *
  5. * Copyright 2009 Analog Devices Inc.
  6. *
  7. * Enter bugs at http://blackfin.uclinux.org/
  8. *
  9. * Licensed under the GPL-2 or later.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/console.h>
  14. #include <linux/string.h>
  15. #include <asm/blackfin.h>
  16. #include <asm/irq_handler.h>
  17. #include <asm/early_printk.h>
  18. #define SHADOW_CONSOLE_START (0x500)
  19. #define SHADOW_CONSOLE_END (0x1000)
  20. #define SHADOW_CONSOLE_MAGIC_LOC (0x4F0)
  21. #define SHADOW_CONSOLE_MAGIC (0xDEADBEEF)
  22. static __initdata char *shadow_console_buffer = (char *)SHADOW_CONSOLE_START;
  23. static __init void early_shadow_write(struct console *con, const char *s,
  24. unsigned int n)
  25. {
  26. /*
  27. * save 2 bytes for the double null at the end
  28. * once we fail on a long line, make sure we don't write a short line afterwards
  29. */
  30. if ((shadow_console_buffer + n) <= (char *)(SHADOW_CONSOLE_END - 2)) {
  31. memcpy(shadow_console_buffer, s, n);
  32. shadow_console_buffer += n;
  33. shadow_console_buffer[0] = 0;
  34. shadow_console_buffer[1] = 0;
  35. } else
  36. shadow_console_buffer = (char *)SHADOW_CONSOLE_END;
  37. }
  38. static __initdata struct console early_shadow_console = {
  39. .name = "early_shadow",
  40. .write = early_shadow_write,
  41. .flags = CON_BOOT | CON_PRINTBUFFER,
  42. .index = -1,
  43. .device = 0,
  44. };
  45. __init void enable_shadow_console(void)
  46. {
  47. int *loc = (int *)SHADOW_CONSOLE_MAGIC_LOC;
  48. if (!(early_shadow_console.flags & CON_ENABLED)) {
  49. register_console(&early_shadow_console);
  50. /* for now, assume things are going to fail */
  51. *loc = SHADOW_CONSOLE_MAGIC;
  52. loc++;
  53. *loc = SHADOW_CONSOLE_START;
  54. }
  55. }
  56. static __init int disable_shadow_console(void)
  57. {
  58. /*
  59. * by the time pure_initcall runs, the standard console is enabled,
  60. * and the early_console is off, so unset the magic numbers
  61. * unregistering the console is taken care of in common code (See
  62. * ./kernel/printk:disable_boot_consoles() )
  63. */
  64. int *loc = (int *)SHADOW_CONSOLE_MAGIC_LOC;
  65. *loc = 0;
  66. return 0;
  67. }
  68. pure_initcall(disable_shadow_console);