blob: 29cd2526e5c4dc0c5c0f6d026756ce61f476b6a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * C interface for trapping into the standard LinuxSH BIOS.
3 *
4 * Copyright (C) 2000 Greg Banks, Mitch Davis
Paul Mundt776258d2010-01-12 15:31:20 +09005 * Copyright (C) 1999, 2000 Niibe Yutaka
6 * Copyright (C) 2002 M. R. Brown
7 * Copyright (C) 2004 - 2010 Paul Mundt
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Paul Mundt776258d2010-01-12 15:31:20 +09009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070012 */
Paul Mundt98d877c2007-07-20 16:59:49 +090013#include <linux/module.h>
Paul Mundt776258d2010-01-12 15:31:20 +090014#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 Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/sh_bios.h>
20
Paul Mundt8e320182008-12-17 11:37:51 +090021#define BIOS_CALL_CONSOLE_WRITE 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#define BIOS_CALL_ETH_NODE_ADDR 10
23#define BIOS_CALL_SHUTDOWN 11
Paul Mundt8e320182008-12-17 11:37:51 +090024#define BIOS_CALL_GDB_DETACH 0xff
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Paul Mundt8e320182008-12-17 11:37:51 +090026static inline long sh_bios_call(long func, long arg0, long arg1, long arg2,
27 long arg3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Paul Mundt8e320182008-12-17 11:37:51 +090029 register long r0 __asm__("r0") = func;
30 register long r4 __asm__("r4") = arg0;
31 register long r5 __asm__("r5") = arg1;
32 register long r6 __asm__("r6") = arg2;
33 register long r7 __asm__("r7") = arg3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Paul Mundt8e320182008-12-17 11:37:51 +090035 __asm__ __volatile__("trapa #0x3f":"=z"(r0)
36 :"0"(r0), "r"(r4), "r"(r5), "r"(r6), "r"(r7)
37 :"memory");
38 return r0;
39}
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41void sh_bios_console_write(const char *buf, unsigned int len)
42{
Paul Mundt8e320182008-12-17 11:37:51 +090043 sh_bios_call(BIOS_CALL_CONSOLE_WRITE, (long)buf, (long)len, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046void sh_bios_gdb_detach(void)
47{
Paul Mundt8e320182008-12-17 11:37:51 +090048 sh_bios_call(BIOS_CALL_GDB_DETACH, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
Paul Mundta9df1ed2008-12-17 11:39:33 +090050EXPORT_SYMBOL_GPL(sh_bios_gdb_detach);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Paul Mundt8e320182008-12-17 11:37:51 +090052void sh_bios_get_node_addr(unsigned char *node_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Paul Mundt8e320182008-12-17 11:37:51 +090054 sh_bios_call(BIOS_CALL_ETH_NODE_ADDR, 0, (long)node_addr, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
Paul Mundta9df1ed2008-12-17 11:39:33 +090056EXPORT_SYMBOL_GPL(sh_bios_get_node_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58void sh_bios_shutdown(unsigned int how)
59{
Paul Mundt8e320182008-12-17 11:37:51 +090060 sh_bios_call(BIOS_CALL_SHUTDOWN, how, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
Paul Mundt191d0d22010-01-12 14:50:43 +090062
63void *gdb_vbr_vector = NULL;
64
65/*
66 * Read the old value of the VBR register to initialise the vector
67 * through which debug and BIOS traps are delegated by the Linux trap
68 * handler.
69 */
70void sh_bios_vbr_init(void)
71{
72 unsigned long vbr;
73
74 if (unlikely(gdb_vbr_vector))
75 return;
76
77 __asm__ __volatile__ ("stc vbr, %0" : "=r" (vbr));
78
79 gdb_vbr_vector = (void *)(vbr + 0x100);
80 printk(KERN_NOTICE "Setting GDB trap vector to %p\n", gdb_vbr_vector);
81}
82
83/**
84 * sh_bios_vbr_reload - Re-load the system VBR from the BIOS vector.
85 *
86 * This can be used by save/restore code to reinitialize the system VBR
87 * from the fixed BIOS VBR. A no-op if no BIOS VBR is known.
88 */
89void sh_bios_vbr_reload(void)
90{
91 if (gdb_vbr_vector)
92 __asm__ __volatile__ (
93 "ldc %0, vbr"
94 :
95 : "r" (((unsigned long) gdb_vbr_vector) - 0x100)
96 : "memory"
97 );
98}
Paul Mundt776258d2010-01-12 15:31:20 +090099
100/*
101 * Print a string through the BIOS
102 */
103static void sh_console_write(struct console *co, const char *s,
104 unsigned count)
105{
106 sh_bios_console_write(s, count);
107}
108
109/*
110 * Setup initial baud/bits/parity. We do two things here:
111 * - construct a cflag setting for the first rs_open()
112 * - initialize the serial port
113 * Return non-zero if we didn't find a serial port.
114 */
115static int __init sh_console_setup(struct console *co, char *options)
116{
117 int cflag = CREAD | HUPCL | CLOCAL;
118
119 /*
120 * Now construct a cflag setting.
121 * TODO: this is a totally bogus cflag, as we have
122 * no idea what serial settings the BIOS is using, or
123 * even if its using the serial port at all.
124 */
125 cflag |= B115200 | CS8 | /*no parity*/0;
126
127 co->cflag = cflag;
128
129 return 0;
130}
131
132static struct console bios_console = {
133 .name = "bios",
134 .write = sh_console_write,
135 .setup = sh_console_setup,
136 .flags = CON_PRINTBUFFER,
137 .index = -1,
138};
139
140static struct console *early_console;
141
142static int __init setup_early_printk(char *buf)
143{
144 int keep_early = 0;
145
146 if (!buf)
147 return 0;
148
149 if (strstr(buf, "keep"))
150 keep_early = 1;
151
152 if (!strncmp(buf, "bios", 4))
153 early_console = &bios_console;
154
155 if (likely(early_console)) {
156 if (keep_early)
157 early_console->flags &= ~CON_BOOT;
158 else
159 early_console->flags |= CON_BOOT;
160 register_console(early_console);
161 }
162
163 return 0;
164}
165early_param("earlyprintk", setup_early_printk);