Loading...
1// SPDX-License-Identifier: GPL-2.0
2/* Prom access routines for the sun3x */
3
4#include <linux/types.h>
5#include <linux/kernel.h>
6#include <linux/tty.h>
7#include <linux/console.h>
8#include <linux/init.h>
9#include <linux/mm.h>
10#include <linux/string.h>
11
12#include <asm/page.h>
13#include <asm/setup.h>
14#include <asm/traps.h>
15#include <asm/sun3xprom.h>
16#include <asm/idprom.h>
17#include <asm/segment.h>
18#include <asm/sun3ints.h>
19#include <asm/openprom.h>
20#include <asm/machines.h>
21
22void (*sun3x_putchar)(int);
23int (*sun3x_getchar)(void);
24int (*sun3x_mayget)(void);
25int (*sun3x_mayput)(int);
26void (*sun3x_prom_reboot)(void);
27e_vector sun3x_prom_abort;
28struct linux_romvec *romvec;
29
30/* prom vector table */
31e_vector *sun3x_prom_vbr;
32
33/* Handle returning to the prom */
34void sun3x_halt(void)
35{
36 unsigned long flags;
37
38 /* Disable interrupts while we mess with things */
39 local_irq_save(flags);
40
41 /* Restore prom vbr */
42 asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
43
44 /* Restore prom NMI clock */
45// sun3x_disable_intreg(5);
46 sun3_enable_irq(7);
47
48 /* Let 'er rip */
49 asm volatile ("trap #14");
50
51 /* Restore everything */
52 sun3_disable_irq(7);
53 sun3_enable_irq(5);
54
55 asm volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
56 local_irq_restore(flags);
57}
58
59void sun3x_reboot(void)
60{
61 /* This never returns, don't bother saving things */
62 local_irq_disable();
63
64 /* Restore prom vbr */
65 asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
66
67 /* Restore prom NMI clock */
68 sun3_disable_irq(5);
69 sun3_enable_irq(7);
70
71 /* Let 'er rip */
72 (*romvec->pv_reboot)("vmlinux");
73}
74
75static void sun3x_prom_write(struct console *co, const char *s,
76 unsigned int count)
77{
78 while (count--) {
79 if (*s == '\n')
80 sun3x_putchar('\r');
81 sun3x_putchar(*s++);
82 }
83}
84
85/* debug console - write-only */
86
87static struct console sun3x_debug = {
88 .name = "debug",
89 .write = sun3x_prom_write,
90 .flags = CON_PRINTBUFFER,
91 .index = -1,
92};
93
94void __init sun3x_prom_init(void)
95{
96 /* Read the vector table */
97
98 sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
99 sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
100 sun3x_mayget = *(int (**)(void)) (SUN3X_P_MAYGET);
101 sun3x_mayput = *(int (**)(int)) (SUN3X_P_MAYPUT);
102 sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
103 sun3x_prom_abort = *(e_vector *) (SUN3X_P_ABORT);
104 romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
105
106 idprom_init();
107
108 if (!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
109 pr_warn("Machine reports strange type %02x\n",
110 idprom->id_machtype);
111 pr_warn("Pretending it's a 3/80, but very afraid...\n");
112 idprom->id_machtype = SM_SUN3X | SM_3_80;
113 }
114
115 /* point trap #14 at abort.
116 * XXX this is futile since we restore the vbr first - oops
117 */
118 vectors[VEC_TRAP14] = sun3x_prom_abort;
119}
120
121static int __init sun3x_debug_setup(char *arg)
122{
123 /* If debug=prom was specified, start the debug console */
124 if (MACH_IS_SUN3X && !strcmp(arg, "prom"))
125 register_console(&sun3x_debug);
126 return 0;
127}
128
129early_param("debug", sun3x_debug_setup);
130
131/* some prom functions to export */
132int prom_getintdefault(int node, char *property, int deflt)
133{
134 return deflt;
135}
136
137int prom_getbool (int node, char *prop)
138{
139 return 1;
140}
141
142void prom_printf(char *fmt, ...)
143{
144}
145
146void prom_halt (void)
147{
148 sun3x_halt();
149}
150
151/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
152 * format type. 'num_bytes' is the number of bytes that your idbuf
153 * has space for. Returns 0xff on error.
154 */
155unsigned char
156prom_get_idprom(char *idbuf, int num_bytes)
157{
158 int i;
159
160 /* make a copy of the idprom structure */
161 for (i = 0; i < num_bytes; i++)
162 idbuf[i] = ((char *)SUN3X_IDPROM)[i];
163
164 return idbuf[0];
165}
1// SPDX-License-Identifier: GPL-2.0
2/* Prom access routines for the sun3x */
3
4#include <linux/types.h>
5#include <linux/kernel.h>
6#include <linux/tty.h>
7#include <linux/console.h>
8#include <linux/init.h>
9#include <linux/mm.h>
10#include <linux/string.h>
11
12#include <asm/page.h>
13#include <asm/setup.h>
14#include <asm/traps.h>
15#include <asm/sun3xprom.h>
16#include <asm/idprom.h>
17#include <asm/sun3ints.h>
18#include <asm/openprom.h>
19#include <asm/machines.h>
20
21void (*sun3x_putchar)(int);
22int (*sun3x_getchar)(void);
23int (*sun3x_mayget)(void);
24int (*sun3x_mayput)(int);
25void (*sun3x_prom_reboot)(void);
26e_vector sun3x_prom_abort;
27struct linux_romvec *romvec;
28
29/* prom vector table */
30e_vector *sun3x_prom_vbr;
31
32/* Handle returning to the prom */
33static void sun3x_halt(void)
34{
35 unsigned long flags;
36
37 /* Disable interrupts while we mess with things */
38 local_irq_save(flags);
39
40 /* Restore prom vbr */
41 asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
42
43 /* Restore prom NMI clock */
44// sun3x_disable_intreg(5);
45 sun3_enable_irq(7);
46
47 /* Let 'er rip */
48 asm volatile ("trap #14");
49
50 /* Restore everything */
51 sun3_disable_irq(7);
52 sun3_enable_irq(5);
53
54 asm volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
55 local_irq_restore(flags);
56}
57
58void sun3x_reboot(void)
59{
60 /* This never returns, don't bother saving things */
61 local_irq_disable();
62
63 /* Restore prom vbr */
64 asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
65
66 /* Restore prom NMI clock */
67 sun3_disable_irq(5);
68 sun3_enable_irq(7);
69
70 /* Let 'er rip */
71 (*romvec->pv_reboot)("vmlinux");
72}
73
74static void sun3x_prom_write(struct console *co, const char *s,
75 unsigned int count)
76{
77 while (count--) {
78 if (*s == '\n')
79 sun3x_putchar('\r');
80 sun3x_putchar(*s++);
81 }
82}
83
84/* debug console - write-only */
85
86static struct console sun3x_debug = {
87 .name = "debug",
88 .write = sun3x_prom_write,
89 .flags = CON_PRINTBUFFER,
90 .index = -1,
91};
92
93void __init sun3x_prom_init(void)
94{
95 /* Read the vector table */
96
97 sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
98 sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
99 sun3x_mayget = *(int (**)(void)) (SUN3X_P_MAYGET);
100 sun3x_mayput = *(int (**)(int)) (SUN3X_P_MAYPUT);
101 sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
102 sun3x_prom_abort = *(e_vector *) (SUN3X_P_ABORT);
103 romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
104
105 idprom_init();
106
107 if (!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
108 pr_warn("Machine reports strange type %02x\n",
109 idprom->id_machtype);
110 pr_warn("Pretending it's a 3/80, but very afraid...\n");
111 idprom->id_machtype = SM_SUN3X | SM_3_80;
112 }
113
114 /* point trap #14 at abort.
115 * XXX this is futile since we restore the vbr first - oops
116 */
117 vectors[VEC_TRAP14] = sun3x_prom_abort;
118}
119
120static int __init sun3x_debug_setup(char *arg)
121{
122 /* If debug=prom was specified, start the debug console */
123 if (MACH_IS_SUN3X && !strcmp(arg, "prom"))
124 register_console(&sun3x_debug);
125 return 0;
126}
127
128early_param("debug", sun3x_debug_setup);
129
130/* some prom functions to export */
131int prom_getintdefault(int node, char *property, int deflt)
132{
133 return deflt;
134}
135
136int prom_getbool (int node, char *prop)
137{
138 return 1;
139}
140
141void prom_printf(char *fmt, ...)
142{
143}
144
145void prom_halt (void)
146{
147 sun3x_halt();
148}
149
150/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
151 * format type. 'num_bytes' is the number of bytes that your idbuf
152 * has space for. Returns 0xff on error.
153 */
154unsigned char
155prom_get_idprom(char *idbuf, int num_bytes)
156{
157 int i;
158
159 /* make a copy of the idprom structure */
160 for (i = 0; i < num_bytes; i++)
161 idbuf[i] = ((char *)SUN3X_IDPROM)[i];
162
163 return idbuf[0];
164}