pdc_cons.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * PDC Console support - ie use firmware to dump text via boot console
  3. *
  4. * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
  5. * Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>
  6. * Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>
  7. * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
  8. * Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>
  9. * Copyright (C) 2000 Michael Ang <mang with subcarrier.org>
  10. * Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>
  11. * Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>
  12. * Copyright (C) 2001 Helge Deller <deller at parisc-linux.org>
  13. * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
  14. * Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
  15. *
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. */
  31. /*
  32. * The PDC console is a simple console, which can be used for debugging
  33. * boot related problems on HP PA-RISC machines.
  34. *
  35. * This code uses the ROM (=PDC) based functions to read and write characters
  36. * from and to PDC's boot path.
  37. * Since all character read from that path must be polled, this code never
  38. * can or will be a fully functional linux console.
  39. */
  40. /* Define EARLY_BOOTUP_DEBUG to debug kernel related boot problems.
  41. * On production kernels EARLY_BOOTUP_DEBUG should be undefined. */
  42. #define EARLY_BOOTUP_DEBUG
  43. #include <linux/kernel.h>
  44. #include <linux/console.h>
  45. #include <linux/string.h>
  46. #include <linux/init.h>
  47. #include <linux/major.h>
  48. #include <linux/tty.h>
  49. #include <asm/pdc.h> /* for iodc_call() proto and friends */
  50. static spinlock_t pdc_console_lock = SPIN_LOCK_UNLOCKED;
  51. static void pdc_console_write(struct console *co, const char *s, unsigned count)
  52. {
  53. int i = 0;
  54. unsigned long flags;
  55. spin_lock_irqsave(&pdc_console_lock, flags);
  56. do {
  57. i += pdc_iodc_print(s + i, count - i);
  58. } while (i < count);
  59. spin_unlock_irqrestore(&pdc_console_lock, flags);
  60. }
  61. int pdc_console_poll_key(struct console *co)
  62. {
  63. int c;
  64. unsigned long flags;
  65. spin_lock_irqsave(&pdc_console_lock, flags);
  66. c = pdc_iodc_getc();
  67. spin_unlock_irqrestore(&pdc_console_lock, flags);
  68. return c;
  69. }
  70. static int pdc_console_setup(struct console *co, char *options)
  71. {
  72. return 0;
  73. }
  74. #if defined(CONFIG_PDC_CONSOLE)
  75. #include <linux/vt_kern.h>
  76. static struct tty_driver * pdc_console_device (struct console *c, int *index)
  77. {
  78. extern struct tty_driver console_driver;
  79. *index = c->index ? c->index-1 : fg_console;
  80. return &console_driver;
  81. }
  82. #else
  83. #define pdc_console_device NULL
  84. #endif
  85. static struct console pdc_cons = {
  86. .name = "ttyB",
  87. .write = pdc_console_write,
  88. .device = pdc_console_device,
  89. .setup = pdc_console_setup,
  90. .flags = CON_BOOT | CON_PRINTBUFFER | CON_ENABLED,
  91. .index = -1,
  92. };
  93. static int pdc_console_initialized;
  94. static void pdc_console_init_force(void)
  95. {
  96. if (pdc_console_initialized)
  97. return;
  98. ++pdc_console_initialized;
  99. /* If the console is duplex then copy the COUT parameters to CIN. */
  100. if (PAGE0->mem_cons.cl_class == CL_DUPLEX)
  101. memcpy(&PAGE0->mem_kbd, &PAGE0->mem_cons, sizeof(PAGE0->mem_cons));
  102. /* register the pdc console */
  103. register_console(&pdc_cons);
  104. }
  105. void __init pdc_console_init(void)
  106. {
  107. #if defined(EARLY_BOOTUP_DEBUG) || defined(CONFIG_PDC_CONSOLE)
  108. pdc_console_init_force();
  109. #endif
  110. #ifdef EARLY_BOOTUP_DEBUG
  111. printk(KERN_INFO "Initialized PDC Console for debugging.\n");
  112. #endif
  113. }
  114. /*
  115. * Used for emergencies. Currently only used if an HPMC occurs. If an
  116. * HPMC occurs, it is possible that the current console may not be
  117. * properly initialised after the PDC IO reset. This routine unregisters
  118. * all of the current consoles, reinitializes the pdc console and
  119. * registers it.
  120. */
  121. void pdc_console_restart(void)
  122. {
  123. struct console *console;
  124. if (pdc_console_initialized)
  125. return;
  126. /* If we've already seen the output, don't bother to print it again */
  127. if (console_drivers != NULL)
  128. pdc_cons.flags &= ~CON_PRINTBUFFER;
  129. while ((console = console_drivers) != NULL)
  130. unregister_console(console_drivers);
  131. /* force registering the pdc console */
  132. pdc_console_init_force();
  133. }