sh_bios.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * C interface for trapping into the standard LinuxSH BIOS.
  3. *
  4. * Copyright (C) 2000 Greg Banks, Mitch Davis
  5. * Copyright (C) 1999, 2000 Niibe Yutaka
  6. * Copyright (C) 2002 M. R. Brown
  7. * Copyright (C) 2004 - 2010 Paul Mundt
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/console.h>
  15. #include <linux/tty.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/delay.h>
  19. #include <asm/sh_bios.h>
  20. #define BIOS_CALL_CONSOLE_WRITE 0
  21. #define BIOS_CALL_ETH_NODE_ADDR 10
  22. #define BIOS_CALL_SHUTDOWN 11
  23. #define BIOS_CALL_GDB_DETACH 0xff
  24. void *gdb_vbr_vector = NULL;
  25. static inline long sh_bios_call(long func, long arg0, long arg1, long arg2,
  26. long arg3)
  27. {
  28. register long r0 __asm__("r0") = func;
  29. register long r4 __asm__("r4") = arg0;
  30. register long r5 __asm__("r5") = arg1;
  31. register long r6 __asm__("r6") = arg2;
  32. register long r7 __asm__("r7") = arg3;
  33. if (!gdb_vbr_vector)
  34. return -ENOSYS;
  35. __asm__ __volatile__("trapa #0x3f":"=z"(r0)
  36. :"0"(r0), "r"(r4), "r"(r5), "r"(r6), "r"(r7)
  37. :"memory");
  38. return r0;
  39. }
  40. void sh_bios_console_write(const char *buf, unsigned int len)
  41. {
  42. sh_bios_call(BIOS_CALL_CONSOLE_WRITE, (long)buf, (long)len, 0, 0);
  43. }
  44. void sh_bios_gdb_detach(void)
  45. {
  46. sh_bios_call(BIOS_CALL_GDB_DETACH, 0, 0, 0, 0);
  47. }
  48. EXPORT_SYMBOL_GPL(sh_bios_gdb_detach);
  49. void sh_bios_get_node_addr(unsigned char *node_addr)
  50. {
  51. sh_bios_call(BIOS_CALL_ETH_NODE_ADDR, 0, (long)node_addr, 0, 0);
  52. }
  53. EXPORT_SYMBOL_GPL(sh_bios_get_node_addr);
  54. void sh_bios_shutdown(unsigned int how)
  55. {
  56. sh_bios_call(BIOS_CALL_SHUTDOWN, how, 0, 0, 0);
  57. }
  58. /*
  59. * Read the old value of the VBR register to initialise the vector
  60. * through which debug and BIOS traps are delegated by the Linux trap
  61. * handler.
  62. */
  63. void sh_bios_vbr_init(void)
  64. {
  65. unsigned long vbr;
  66. if (unlikely(gdb_vbr_vector))
  67. return;
  68. __asm__ __volatile__ ("stc vbr, %0" : "=r" (vbr));
  69. if (vbr) {
  70. gdb_vbr_vector = (void *)(vbr + 0x100);
  71. printk(KERN_NOTICE "Setting GDB trap vector to %p\n",
  72. gdb_vbr_vector);
  73. } else
  74. printk(KERN_NOTICE "SH-BIOS not detected\n");
  75. }
  76. /**
  77. * sh_bios_vbr_reload - Re-load the system VBR from the BIOS vector.
  78. *
  79. * This can be used by save/restore code to reinitialize the system VBR
  80. * from the fixed BIOS VBR. A no-op if no BIOS VBR is known.
  81. */
  82. void sh_bios_vbr_reload(void)
  83. {
  84. if (gdb_vbr_vector)
  85. __asm__ __volatile__ (
  86. "ldc %0, vbr"
  87. :
  88. : "r" (((unsigned long) gdb_vbr_vector) - 0x100)
  89. : "memory"
  90. );
  91. }
  92. #ifdef CONFIG_EARLY_PRINTK
  93. /*
  94. * Print a string through the BIOS
  95. */
  96. static void sh_console_write(struct console *co, const char *s,
  97. unsigned count)
  98. {
  99. sh_bios_console_write(s, count);
  100. }
  101. /*
  102. * Setup initial baud/bits/parity. We do two things here:
  103. * - construct a cflag setting for the first rs_open()
  104. * - initialize the serial port
  105. * Return non-zero if we didn't find a serial port.
  106. */
  107. static int __init sh_console_setup(struct console *co, char *options)
  108. {
  109. int cflag = CREAD | HUPCL | CLOCAL;
  110. /*
  111. * Now construct a cflag setting.
  112. * TODO: this is a totally bogus cflag, as we have
  113. * no idea what serial settings the BIOS is using, or
  114. * even if its using the serial port at all.
  115. */
  116. cflag |= B115200 | CS8 | /*no parity*/0;
  117. co->cflag = cflag;
  118. return 0;
  119. }
  120. static struct console bios_console = {
  121. .name = "bios",
  122. .write = sh_console_write,
  123. .setup = sh_console_setup,
  124. .flags = CON_PRINTBUFFER,
  125. .index = -1,
  126. };
  127. static int __init setup_early_printk(char *buf)
  128. {
  129. int keep_early = 0;
  130. if (!buf)
  131. return 0;
  132. if (strstr(buf, "keep"))
  133. keep_early = 1;
  134. if (!strncmp(buf, "bios", 4))
  135. early_console = &bios_console;
  136. if (likely(early_console)) {
  137. if (keep_early)
  138. early_console->flags &= ~CON_BOOT;
  139. else
  140. early_console->flags |= CON_BOOT;
  141. register_console(early_console);
  142. }
  143. return 0;
  144. }
  145. early_param("earlyprintk", setup_early_printk);
  146. #endif