import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / m68k / sun3x / prom.c
1 /* 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
23 void (*sun3x_putchar)(int);
24 int (*sun3x_getchar)(void);
25 int (*sun3x_mayget)(void);
26 int (*sun3x_mayput)(int);
27 void (*sun3x_prom_reboot)(void);
28 e_vector sun3x_prom_abort;
29 struct linux_romvec *romvec;
30
31 /* prom vector table */
32 e_vector *sun3x_prom_vbr;
33
34 extern e_vector vectors[256];  /* arch/m68k/kernel/traps.c */
35
36 /* Handle returning to the prom */
37 void sun3x_halt(void)
38 {
39     unsigned long flags;
40     
41     /* Disable interrupts while we mess with things */
42     save_flags(flags); cli();
43
44     /* Restore prom vbr */
45     __asm__ volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
46
47     /* Restore prom NMI clock */
48 //    sun3x_disable_intreg(5);
49     sun3_enable_irq(7);
50
51     /* Let 'er rip */
52     __asm__ volatile ("trap #14" : : );
53
54     /* Restore everything */
55     sun3_disable_irq(7);
56     sun3_enable_irq(5);
57
58     __asm__ volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
59     restore_flags(flags);
60 }
61
62 void sun3x_reboot(void)
63 {
64     /* This never returns, don't bother saving things */
65     cli();
66
67     /* Restore prom vbr */
68     __asm__ volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
69
70     /* Restore prom NMI clock */
71     sun3_disable_irq(5);
72     sun3_enable_irq(7);
73
74     /* Let 'er rip */
75     (*romvec->pv_reboot)("vmlinux");
76 }
77
78 extern char m68k_debug_device[];
79
80 static void sun3x_prom_write(struct console *co, const char *s,
81                              unsigned int count)
82 {
83     while (count--) {
84         if (*s == '\n')
85             sun3x_putchar('\r');
86         sun3x_putchar(*s++);
87     }
88 }
89
90 /* debug console - write-only */
91
92 static struct console sun3x_debug = {
93         "debug",
94         sun3x_prom_write,       /* write */
95         NULL,                   /* read */
96         NULL,                   /* device */
97         NULL,                   /* unblank */
98         NULL,                   /* setup */
99         CON_PRINTBUFFER,
100         -1,
101         0,
102         NULL
103 };
104
105 void sun3x_prom_init(void)
106 {
107     /* Read the vector table */
108
109     sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
110     sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
111     sun3x_mayget = *(int (**)(void))  (SUN3X_P_MAYGET);
112     sun3x_mayput = *(int (**)(int))   (SUN3X_P_MAYPUT);
113     sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
114     sun3x_prom_abort = *(e_vector *)  (SUN3X_P_ABORT);
115     romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
116
117     idprom_init();
118
119     if(!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
120             printk("Warning: machine reports strange type %02x\n",
121                    idprom->id_machtype);
122             printk("Pretending it's a 3/80, but very afraid...\n");
123             idprom->id_machtype = SM_SUN3X | SM_3_80;
124     }
125
126     /* point trap #14 at abort.
127      * XXX this is futile since we restore the vbr first - oops
128      */
129     vectors[VEC_TRAP14] = sun3x_prom_abort;
130     
131     /* If debug=prom was specified, start the debug console */
132
133     if (!strcmp(m68k_debug_device, "prom"))
134         register_console(&sun3x_debug);
135
136     
137 }
138
139 /* some prom functions to export */
140 int prom_getintdefault(int node, char *property, int deflt)
141 {
142         return deflt;
143 }
144
145 int prom_getbool (int node, char *prop)
146 {
147         return 1;
148 }
149
150 void prom_printf(char *fmt, ...)
151 {
152
153 }
154
155 void prom_halt (void)
156 {
157         sun3x_halt();
158 }
159
160 /* Get the idprom and stuff it into buffer 'idbuf'.  Returns the
161  * format type.  'num_bytes' is the number of bytes that your idbuf
162  * has space for.  Returns 0xff on error.
163  */
164 unsigned char
165 prom_get_idprom(char *idbuf, int num_bytes)
166 {
167         int i;
168
169         /* make a copy of the idprom structure */
170         for(i = 0; i < num_bytes; i++) 
171                 idbuf[i] = ((char *)SUN3X_IDPROM)[i];
172
173         return idbuf[0];
174 }