xref: /linux/arch/m68k/sun3x/prom.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /* Prom access routines for the sun3x */
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds #include <linux/types.h>
51da177e4SLinus Torvalds #include <linux/kernel.h>
61da177e4SLinus Torvalds #include <linux/tty.h>
71da177e4SLinus Torvalds #include <linux/console.h>
81da177e4SLinus Torvalds #include <linux/init.h>
91da177e4SLinus Torvalds #include <linux/mm.h>
101da177e4SLinus Torvalds #include <linux/string.h>
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #include <asm/page.h>
131da177e4SLinus Torvalds #include <asm/setup.h>
141da177e4SLinus Torvalds #include <asm/traps.h>
151da177e4SLinus Torvalds #include <asm/sun3xprom.h>
161da177e4SLinus Torvalds #include <asm/idprom.h>
171da177e4SLinus Torvalds #include <asm/sun3ints.h>
181da177e4SLinus Torvalds #include <asm/openprom.h>
191da177e4SLinus Torvalds #include <asm/machines.h>
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds void (*sun3x_putchar)(int);
221da177e4SLinus Torvalds int (*sun3x_getchar)(void);
231da177e4SLinus Torvalds int (*sun3x_mayget)(void);
241da177e4SLinus Torvalds int (*sun3x_mayput)(int);
251da177e4SLinus Torvalds void (*sun3x_prom_reboot)(void);
261da177e4SLinus Torvalds e_vector sun3x_prom_abort;
271da177e4SLinus Torvalds struct linux_romvec *romvec;
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds /* prom vector table */
301da177e4SLinus Torvalds e_vector *sun3x_prom_vbr;
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds /* Handle returning to the prom */
sun3x_halt(void)33*6548f013SGeert Uytterhoeven static void sun3x_halt(void)
341da177e4SLinus Torvalds {
351da177e4SLinus Torvalds 	unsigned long flags;
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds 	/* Disable interrupts while we mess with things */
381da177e4SLinus Torvalds 	local_irq_save(flags);
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds 	/* Restore prom vbr */
416ff5801aSRoman Zippel 	asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds 	/* Restore prom NMI clock */
441da177e4SLinus Torvalds //	sun3x_disable_intreg(5);
451da177e4SLinus Torvalds 	sun3_enable_irq(7);
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds 	/* Let 'er rip */
486ff5801aSRoman Zippel 	asm volatile ("trap #14");
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds 	/* Restore everything */
511da177e4SLinus Torvalds 	sun3_disable_irq(7);
521da177e4SLinus Torvalds 	sun3_enable_irq(5);
531da177e4SLinus Torvalds 
546ff5801aSRoman Zippel 	asm volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
551da177e4SLinus Torvalds 	local_irq_restore(flags);
561da177e4SLinus Torvalds }
571da177e4SLinus Torvalds 
sun3x_reboot(void)581da177e4SLinus Torvalds void sun3x_reboot(void)
591da177e4SLinus Torvalds {
601da177e4SLinus Torvalds 	/* This never returns, don't bother saving things */
611da177e4SLinus Torvalds 	local_irq_disable();
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds 	/* Restore prom vbr */
646ff5801aSRoman Zippel 	asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds 	/* Restore prom NMI clock */
671da177e4SLinus Torvalds 	sun3_disable_irq(5);
681da177e4SLinus Torvalds 	sun3_enable_irq(7);
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds 	/* Let 'er rip */
711da177e4SLinus Torvalds 	(*romvec->pv_reboot)("vmlinux");
721da177e4SLinus Torvalds }
731da177e4SLinus Torvalds 
sun3x_prom_write(struct console * co,const char * s,unsigned int count)741da177e4SLinus Torvalds static void sun3x_prom_write(struct console *co, const char *s,
751da177e4SLinus Torvalds                              unsigned int count)
761da177e4SLinus Torvalds {
771da177e4SLinus Torvalds 	while (count--) {
781da177e4SLinus Torvalds 		if (*s == '\n')
791da177e4SLinus Torvalds 			sun3x_putchar('\r');
801da177e4SLinus Torvalds 		sun3x_putchar(*s++);
811da177e4SLinus Torvalds 	}
821da177e4SLinus Torvalds }
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds /* debug console - write-only */
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds static struct console sun3x_debug = {
871da177e4SLinus Torvalds 	.name	= "debug",
881da177e4SLinus Torvalds 	.write	= sun3x_prom_write,
891da177e4SLinus Torvalds 	.flags	= CON_PRINTBUFFER,
901da177e4SLinus Torvalds 	.index	= -1,
911da177e4SLinus Torvalds };
921da177e4SLinus Torvalds 
sun3x_prom_init(void)9366a3f820SAl Viro void __init sun3x_prom_init(void)
941da177e4SLinus Torvalds {
951da177e4SLinus Torvalds 	/* Read the vector table */
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds 	sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
981da177e4SLinus Torvalds 	sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
991da177e4SLinus Torvalds 	sun3x_mayget = *(int (**)(void))  (SUN3X_P_MAYGET);
1001da177e4SLinus Torvalds 	sun3x_mayput = *(int (**)(int))   (SUN3X_P_MAYPUT);
1011da177e4SLinus Torvalds 	sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
1021da177e4SLinus Torvalds 	sun3x_prom_abort = *(e_vector *)  (SUN3X_P_ABORT);
1031da177e4SLinus Torvalds 	romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	idprom_init();
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	if (!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
1084eee1e72SGeert Uytterhoeven 		pr_warn("Machine reports strange type %02x\n",
1091da177e4SLinus Torvalds 			idprom->id_machtype);
1104eee1e72SGeert Uytterhoeven 		pr_warn("Pretending it's a 3/80, but very afraid...\n");
1111da177e4SLinus Torvalds 		idprom->id_machtype = SM_SUN3X | SM_3_80;
1121da177e4SLinus Torvalds 	}
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds 	/* point trap #14 at abort.
1151da177e4SLinus Torvalds 	 * XXX this is futile since we restore the vbr first - oops
1161da177e4SLinus Torvalds 	 */
1171da177e4SLinus Torvalds 	vectors[VEC_TRAP14] = sun3x_prom_abort;
1181da177e4SLinus Torvalds }
1191da177e4SLinus Torvalds 
sun3x_debug_setup(char * arg)120d6713b40SRoman Zippel static int __init sun3x_debug_setup(char *arg)
121d6713b40SRoman Zippel {
122d6713b40SRoman Zippel 	/* If debug=prom was specified, start the debug console */
123d6713b40SRoman Zippel 	if (MACH_IS_SUN3X && !strcmp(arg, "prom"))
124d6713b40SRoman Zippel 		register_console(&sun3x_debug);
125d6713b40SRoman Zippel 	return 0;
126d6713b40SRoman Zippel }
127d6713b40SRoman Zippel 
128d6713b40SRoman Zippel early_param("debug", sun3x_debug_setup);
129d6713b40SRoman Zippel 
1301da177e4SLinus Torvalds /* some prom functions to export */
prom_getintdefault(int node,char * property,int deflt)1311da177e4SLinus Torvalds int prom_getintdefault(int node, char *property, int deflt)
1321da177e4SLinus Torvalds {
1331da177e4SLinus Torvalds 	return deflt;
1341da177e4SLinus Torvalds }
1351da177e4SLinus Torvalds 
prom_getbool(int node,char * prop)1361da177e4SLinus Torvalds int prom_getbool (int node, char *prop)
1371da177e4SLinus Torvalds {
1381da177e4SLinus Torvalds 	return 1;
1391da177e4SLinus Torvalds }
1401da177e4SLinus Torvalds 
prom_printf(char * fmt,...)1411da177e4SLinus Torvalds void prom_printf(char *fmt, ...)
1421da177e4SLinus Torvalds {
1431da177e4SLinus Torvalds }
1441da177e4SLinus Torvalds 
prom_halt(void)1451da177e4SLinus Torvalds void prom_halt (void)
1461da177e4SLinus Torvalds {
1471da177e4SLinus Torvalds 	sun3x_halt();
1481da177e4SLinus Torvalds }
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds /* Get the idprom and stuff it into buffer 'idbuf'.  Returns the
1511da177e4SLinus Torvalds  * format type.  'num_bytes' is the number of bytes that your idbuf
1521da177e4SLinus Torvalds  * has space for.  Returns 0xff on error.
1531da177e4SLinus Torvalds  */
1541da177e4SLinus Torvalds unsigned char
prom_get_idprom(char * idbuf,int num_bytes)1551da177e4SLinus Torvalds prom_get_idprom(char *idbuf, int num_bytes)
1561da177e4SLinus Torvalds {
1571da177e4SLinus Torvalds         int i;
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds 	/* make a copy of the idprom structure */
1601da177e4SLinus Torvalds 	for (i = 0; i < num_bytes; i++)
1611da177e4SLinus Torvalds 		idbuf[i] = ((char *)SUN3X_IDPROM)[i];
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds         return idbuf[0];
1641da177e4SLinus Torvalds }
165