blob: a7b7e818d6279450119f4a8da5e76cf1c6746466 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Prom access routines for the sun3x */
2
3#include <linux/types.h>
4#include <linux/kernel.h>
5#include <linux/tty.h>
6#include <linux/console.h>
7#include <linux/init.h>
8#include <linux/mm.h>
9#include <linux/string.h>
10
11#include <asm/page.h>
12#include <asm/pgtable.h>
13#include <asm/bootinfo.h>
14#include <asm/setup.h>
15#include <asm/traps.h>
16#include <asm/sun3xprom.h>
17#include <asm/idprom.h>
18#include <asm/segment.h>
19#include <asm/sun3ints.h>
20#include <asm/openprom.h>
21#include <asm/machines.h>
22
23void (*sun3x_putchar)(int);
24int (*sun3x_getchar)(void);
25int (*sun3x_mayget)(void);
26int (*sun3x_mayput)(int);
27void (*sun3x_prom_reboot)(void);
28e_vector sun3x_prom_abort;
29struct linux_romvec *romvec;
30
31/* prom vector table */
32e_vector *sun3x_prom_vbr;
33
34/* Handle returning to the prom */
35void sun3x_halt(void)
36{
Roman Zippel6ff58012007-05-01 22:32:43 +020037 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Roman Zippel6ff58012007-05-01 22:32:43 +020039 /* Disable interrupts while we mess with things */
40 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Roman Zippel6ff58012007-05-01 22:32:43 +020042 /* Restore prom vbr */
43 asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Roman Zippel6ff58012007-05-01 22:32:43 +020045 /* Restore prom NMI clock */
46// sun3x_disable_intreg(5);
47 sun3_enable_irq(7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Roman Zippel6ff58012007-05-01 22:32:43 +020049 /* Let 'er rip */
50 asm volatile ("trap #14");
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Roman Zippel6ff58012007-05-01 22:32:43 +020052 /* Restore everything */
53 sun3_disable_irq(7);
54 sun3_enable_irq(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Roman Zippel6ff58012007-05-01 22:32:43 +020056 asm volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
57 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
60void sun3x_reboot(void)
61{
Roman Zippel6ff58012007-05-01 22:32:43 +020062 /* This never returns, don't bother saving things */
63 local_irq_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Roman Zippel6ff58012007-05-01 22:32:43 +020065 /* Restore prom vbr */
66 asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Roman Zippel6ff58012007-05-01 22:32:43 +020068 /* Restore prom NMI clock */
69 sun3_disable_irq(5);
70 sun3_enable_irq(7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Roman Zippel6ff58012007-05-01 22:32:43 +020072 /* Let 'er rip */
73 (*romvec->pv_reboot)("vmlinux");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076static void sun3x_prom_write(struct console *co, const char *s,
77 unsigned int count)
78{
Roman Zippel6ff58012007-05-01 22:32:43 +020079 while (count--) {
80 if (*s == '\n')
81 sun3x_putchar('\r');
82 sun3x_putchar(*s++);
83 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
86/* debug console - write-only */
87
88static struct console sun3x_debug = {
Roman Zippel6ff58012007-05-01 22:32:43 +020089 .name = "debug",
90 .write = sun3x_prom_write,
91 .flags = CON_PRINTBUFFER,
92 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093};
94
Al Viro66a3f822007-07-20 04:33:28 +010095void __init sun3x_prom_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Roman Zippel6ff58012007-05-01 22:32:43 +020097 /* Read the vector table */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Roman Zippel6ff58012007-05-01 22:32:43 +020099 sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
100 sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
101 sun3x_mayget = *(int (**)(void)) (SUN3X_P_MAYGET);
102 sun3x_mayput = *(int (**)(int)) (SUN3X_P_MAYPUT);
103 sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
104 sun3x_prom_abort = *(e_vector *) (SUN3X_P_ABORT);
105 romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Roman Zippel6ff58012007-05-01 22:32:43 +0200107 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Roman Zippel6ff58012007-05-01 22:32:43 +0200109 if (!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
110 printk("Warning: machine reports strange type %02x\n",
111 idprom->id_machtype);
112 printk("Pretending it's a 3/80, but very afraid...\n");
113 idprom->id_machtype = SM_SUN3X | SM_3_80;
114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Roman Zippel6ff58012007-05-01 22:32:43 +0200116 /* point trap #14 at abort.
117 * XXX this is futile since we restore the vbr first - oops
118 */
119 vectors[VEC_TRAP14] = sun3x_prom_abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
Roman Zippeld6713b42007-05-01 22:32:45 +0200122static int __init sun3x_debug_setup(char *arg)
123{
124 /* If debug=prom was specified, start the debug console */
125 if (MACH_IS_SUN3X && !strcmp(arg, "prom"))
126 register_console(&sun3x_debug);
127 return 0;
128}
129
130early_param("debug", sun3x_debug_setup);
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* some prom functions to export */
133int prom_getintdefault(int node, char *property, int deflt)
134{
135 return deflt;
136}
137
138int prom_getbool (int node, char *prop)
139{
140 return 1;
141}
142
143void prom_printf(char *fmt, ...)
144{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
147void prom_halt (void)
148{
149 sun3x_halt();
150}
151
152/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
153 * format type. 'num_bytes' is the number of bytes that your idbuf
154 * has space for. Returns 0xff on error.
155 */
156unsigned char
157prom_get_idprom(char *idbuf, int num_bytes)
158{
159 int i;
160
161 /* make a copy of the idprom structure */
Roman Zippel6ff58012007-05-01 22:32:43 +0200162 for (i = 0; i < num_bytes; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 idbuf[i] = ((char *)SUN3X_IDPROM)[i];
164
165 return idbuf[0];
166}