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