xref: /openbmc/linux/arch/sh/kernel/sh_bios.c (revision 597473720f4dc69749542bfcfed4a927a43d935e)
1*5933f6d2SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *  C interface for trapping into the standard LinuxSH BIOS.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *  Copyright (C) 2000 Greg Banks, Mitch Davis
6776258dfSPaul Mundt  *  Copyright (C) 1999, 2000  Niibe Yutaka
7776258dfSPaul Mundt  *  Copyright (C) 2002  M. R. Brown
8776258dfSPaul Mundt  *  Copyright (C) 2004 - 2010  Paul Mundt
91da177e4SLinus Torvalds  */
1098d877c4SPaul Mundt #include <linux/module.h>
11776258dfSPaul Mundt #include <linux/console.h>
12776258dfSPaul Mundt #include <linux/tty.h>
13776258dfSPaul Mundt #include <linux/init.h>
14776258dfSPaul Mundt #include <linux/io.h>
15776258dfSPaul Mundt #include <linux/delay.h>
161da177e4SLinus Torvalds #include <asm/sh_bios.h>
171da177e4SLinus Torvalds 
181da177e4SLinus Torvalds #define BIOS_CALL_CONSOLE_WRITE		0
191da177e4SLinus Torvalds #define BIOS_CALL_ETH_NODE_ADDR		10
201da177e4SLinus Torvalds #define BIOS_CALL_SHUTDOWN		11
211da177e4SLinus Torvalds #define BIOS_CALL_GDB_DETACH		0xff
221da177e4SLinus Torvalds 
2394cd0495SPaul Mundt void *gdb_vbr_vector = NULL;
2494cd0495SPaul Mundt 
sh_bios_call(long func,long arg0,long arg1,long arg2,long arg3)258e32018bSPaul Mundt static inline long sh_bios_call(long func, long arg0, long arg1, long arg2,
268e32018bSPaul Mundt 				    long arg3)
271da177e4SLinus Torvalds {
281da177e4SLinus Torvalds 	register long r0 __asm__("r0") = func;
291da177e4SLinus Torvalds 	register long r4 __asm__("r4") = arg0;
301da177e4SLinus Torvalds 	register long r5 __asm__("r5") = arg1;
311da177e4SLinus Torvalds 	register long r6 __asm__("r6") = arg2;
321da177e4SLinus Torvalds 	register long r7 __asm__("r7") = arg3;
338e32018bSPaul Mundt 
3494cd0495SPaul Mundt 	if (!gdb_vbr_vector)
3594cd0495SPaul Mundt 		return -ENOSYS;
3694cd0495SPaul Mundt 
378e32018bSPaul Mundt 	__asm__ __volatile__("trapa	#0x3f":"=z"(r0)
381da177e4SLinus Torvalds 			     :"0"(r0), "r"(r4), "r"(r5), "r"(r6), "r"(r7)
391da177e4SLinus Torvalds 			     :"memory");
401da177e4SLinus Torvalds 	return r0;
411da177e4SLinus Torvalds }
421da177e4SLinus Torvalds 
sh_bios_console_write(const char * buf,unsigned int len)431da177e4SLinus Torvalds void sh_bios_console_write(const char *buf, unsigned int len)
441da177e4SLinus Torvalds {
451da177e4SLinus Torvalds 	sh_bios_call(BIOS_CALL_CONSOLE_WRITE, (long)buf, (long)len, 0, 0);
461da177e4SLinus Torvalds }
471da177e4SLinus Torvalds 
sh_bios_gdb_detach(void)481da177e4SLinus Torvalds void sh_bios_gdb_detach(void)
491da177e4SLinus Torvalds {
501da177e4SLinus Torvalds 	sh_bios_call(BIOS_CALL_GDB_DETACH, 0, 0, 0, 0);
511da177e4SLinus Torvalds }
52a9df1ed9SPaul Mundt EXPORT_SYMBOL_GPL(sh_bios_gdb_detach);
531da177e4SLinus Torvalds 
sh_bios_get_node_addr(unsigned char * node_addr)541da177e4SLinus Torvalds void sh_bios_get_node_addr(unsigned char *node_addr)
551da177e4SLinus Torvalds {
561da177e4SLinus Torvalds 	sh_bios_call(BIOS_CALL_ETH_NODE_ADDR, 0, (long)node_addr, 0, 0);
571da177e4SLinus Torvalds }
58a9df1ed9SPaul Mundt EXPORT_SYMBOL_GPL(sh_bios_get_node_addr);
591da177e4SLinus Torvalds 
sh_bios_shutdown(unsigned int how)601da177e4SLinus Torvalds void sh_bios_shutdown(unsigned int how)
611da177e4SLinus Torvalds {
621da177e4SLinus Torvalds 	sh_bios_call(BIOS_CALL_SHUTDOWN, how, 0, 0, 0);
631da177e4SLinus Torvalds }
64191d0d24SPaul Mundt 
65191d0d24SPaul Mundt /*
66191d0d24SPaul Mundt  * Read the old value of the VBR register to initialise the vector
67191d0d24SPaul Mundt  * through which debug and BIOS traps are delegated by the Linux trap
68191d0d24SPaul Mundt  * handler.
69191d0d24SPaul Mundt  */
sh_bios_vbr_init(void)70191d0d24SPaul Mundt void sh_bios_vbr_init(void)
71191d0d24SPaul Mundt {
72191d0d24SPaul Mundt 	unsigned long vbr;
73191d0d24SPaul Mundt 
74191d0d24SPaul Mundt 	if (unlikely(gdb_vbr_vector))
75191d0d24SPaul Mundt 		return;
76191d0d24SPaul Mundt 
77191d0d24SPaul Mundt 	__asm__ __volatile__ ("stc vbr, %0" : "=r" (vbr));
78191d0d24SPaul Mundt 
7994cd0495SPaul Mundt 	if (vbr) {
80191d0d24SPaul Mundt 		gdb_vbr_vector = (void *)(vbr + 0x100);
8194cd0495SPaul Mundt 		printk(KERN_NOTICE "Setting GDB trap vector to %p\n",
8294cd0495SPaul Mundt 		       gdb_vbr_vector);
8394cd0495SPaul Mundt 	} else
8494cd0495SPaul Mundt 		printk(KERN_NOTICE "SH-BIOS not detected\n");
85191d0d24SPaul Mundt }
86191d0d24SPaul Mundt 
87191d0d24SPaul Mundt /**
88191d0d24SPaul Mundt  * sh_bios_vbr_reload - Re-load the system VBR from the BIOS vector.
89191d0d24SPaul Mundt  *
90191d0d24SPaul Mundt  * This can be used by save/restore code to reinitialize the system VBR
91191d0d24SPaul Mundt  * from the fixed BIOS VBR. A no-op if no BIOS VBR is known.
92191d0d24SPaul Mundt  */
sh_bios_vbr_reload(void)93191d0d24SPaul Mundt void sh_bios_vbr_reload(void)
94191d0d24SPaul Mundt {
95191d0d24SPaul Mundt 	if (gdb_vbr_vector)
96191d0d24SPaul Mundt 		__asm__ __volatile__ (
97191d0d24SPaul Mundt 			"ldc %0, vbr"
98191d0d24SPaul Mundt 			:
99191d0d24SPaul Mundt 			: "r" (((unsigned long) gdb_vbr_vector) - 0x100)
100191d0d24SPaul Mundt 			: "memory"
101191d0d24SPaul Mundt 		);
102191d0d24SPaul Mundt }
103776258dfSPaul Mundt 
104d0380e6cSThomas Gleixner #ifdef CONFIG_EARLY_PRINTK
105776258dfSPaul Mundt /*
106776258dfSPaul Mundt  *	Print a string through the BIOS
107776258dfSPaul Mundt  */
sh_console_write(struct console * co,const char * s,unsigned count)108776258dfSPaul Mundt static void sh_console_write(struct console *co, const char *s,
109776258dfSPaul Mundt 				 unsigned count)
110776258dfSPaul Mundt {
111776258dfSPaul Mundt 	sh_bios_console_write(s, count);
112776258dfSPaul Mundt }
113776258dfSPaul Mundt 
114776258dfSPaul Mundt /*
115776258dfSPaul Mundt  *	Setup initial baud/bits/parity. We do two things here:
116776258dfSPaul Mundt  *	- construct a cflag setting for the first rs_open()
117776258dfSPaul Mundt  *	- initialize the serial port
118776258dfSPaul Mundt  *	Return non-zero if we didn't find a serial port.
119776258dfSPaul Mundt  */
sh_console_setup(struct console * co,char * options)120776258dfSPaul Mundt static int __init sh_console_setup(struct console *co, char *options)
121776258dfSPaul Mundt {
122776258dfSPaul Mundt 	int	cflag = CREAD | HUPCL | CLOCAL;
123776258dfSPaul Mundt 
124776258dfSPaul Mundt 	/*
125776258dfSPaul Mundt 	 *	Now construct a cflag setting.
126776258dfSPaul Mundt 	 *	TODO: this is a totally bogus cflag, as we have
127776258dfSPaul Mundt 	 *	no idea what serial settings the BIOS is using, or
128776258dfSPaul Mundt 	 *	even if its using the serial port at all.
129776258dfSPaul Mundt 	 */
130776258dfSPaul Mundt 	cflag |= B115200 | CS8 | /*no parity*/0;
131776258dfSPaul Mundt 
132776258dfSPaul Mundt 	co->cflag = cflag;
133776258dfSPaul Mundt 
134776258dfSPaul Mundt 	return 0;
135776258dfSPaul Mundt }
136776258dfSPaul Mundt 
137776258dfSPaul Mundt static struct console bios_console = {
138776258dfSPaul Mundt 	.name		= "bios",
139776258dfSPaul Mundt 	.write		= sh_console_write,
140776258dfSPaul Mundt 	.setup		= sh_console_setup,
141776258dfSPaul Mundt 	.flags		= CON_PRINTBUFFER,
142776258dfSPaul Mundt 	.index		= -1,
143776258dfSPaul Mundt };
144776258dfSPaul Mundt 
setup_early_printk(char * buf)145776258dfSPaul Mundt static int __init setup_early_printk(char *buf)
146776258dfSPaul Mundt {
147776258dfSPaul Mundt 	int keep_early = 0;
148776258dfSPaul Mundt 
149776258dfSPaul Mundt 	if (!buf)
150776258dfSPaul Mundt 		return 0;
151776258dfSPaul Mundt 
152776258dfSPaul Mundt 	if (strstr(buf, "keep"))
153776258dfSPaul Mundt 		keep_early = 1;
154776258dfSPaul Mundt 
155776258dfSPaul Mundt 	if (!strncmp(buf, "bios", 4))
156776258dfSPaul Mundt 		early_console = &bios_console;
157776258dfSPaul Mundt 
158776258dfSPaul Mundt 	if (likely(early_console)) {
159776258dfSPaul Mundt 		if (keep_early)
160776258dfSPaul Mundt 			early_console->flags &= ~CON_BOOT;
161776258dfSPaul Mundt 		else
162776258dfSPaul Mundt 			early_console->flags |= CON_BOOT;
163776258dfSPaul Mundt 		register_console(early_console);
164776258dfSPaul Mundt 	}
165776258dfSPaul Mundt 
166776258dfSPaul Mundt 	return 0;
167776258dfSPaul Mundt }
168776258dfSPaul Mundt early_param("earlyprintk", setup_early_printk);
169d0380e6cSThomas Gleixner #endif
170