1 /* $NetBSD: promcall.c,v 1.3 2011/06/12 13:40:14 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department and Ralph Campbell.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: Utah Hdr: cons.c 1.1 90/07/09
37 *
38 * @(#)cons.c 8.2 (Berkeley) 1/11/94
39 */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: promcall.c,v 1.3 2011/06/12 13:40:14 tsutsui Exp $");
43
44 #include <sys/param.h>
45 #include <sys/device.h>
46 #include <sys/reboot.h>
47 #include <sys/systm.h>
48
49 #include <dev/cons.h>
50
51 #include <mips/cpuregs.h>
52 #include <emips/stand/common/prom_iface.h>
53 #include <emips/emips/machdep.h>
54
55 static int romgetc(dev_t);
56 static void romputc(dev_t, int);
57 static void *nope(void);
58 static int nogetchar(void);
59 static void noprintf(const char *, ...);
60 static int nogetsysid(void);
61 static void nohalt(int *, int);
62
63 /*
64 * Callback vector. We keep this fall-back copy jic the bootloader is broken.
65 */
nope(void)66 static void *nope(void)
67 {
68
69 return NULL;
70 }
71
nogetchar(void)72 static int nogetchar(void)
73 {
74
75 return -1;
76 }
77
noprintf(const char * fmt,...)78 static void noprintf(const char *fmt, ...)
79 {
80 }
81
nogetsysid(void)82 static int nogetsysid(void)
83 {
84
85 /* say its an eMIPS, ML board */
86 return MAKESYSID(1, 1, XS_ML40x, MIPS_eMIPS);
87 }
88
nohalt(int * unused,int howto)89 static void nohalt(int *unused, int howto)
90 {
91
92 while (1); /* fool gcc */
93 /*NOTREACHED*/
94 }
95
96 const struct callback callvec = {
97 nope,
98 nope,
99 nope,
100 nope,
101 nope,
102 nope,
103 nope,
104 nope,
105 nope,
106 nogetchar,
107 nope,
108 nope,
109 noprintf,
110 nope,
111 nope,
112 nope,
113 nope,
114 nope,
115 nope,
116 nope,
117 nope,
118 nope,
119 nope,
120 nope,
121 nope,
122 nope,
123 nope,
124 nope,
125 nope,
126 nope,
127 nope,
128 nope,
129 nogetsysid,
130 nope,
131 nope,
132 nope,
133 nope,
134 nope,
135 nope,
136 nohalt
137 };
138
139 const struct callback *callv = &callvec;
140
141 /*
142 * Default consdev, for errors or warnings before
143 * consinit runs: use the PROM.
144 */
145 struct consdev promcd = {
146 NULL, /* probe */
147 NULL, /* init */
148 romgetc, /* getc */
149 romputc, /* putc */
150 nullcnpollc, /* pollc */
151 NULL, /* bell */
152 makedev(0, 0),
153 CN_DEAD,
154 };
155
156 /*
157 * Get character from PROM console.
158 */
159 static int
romgetc(dev_t dev)160 romgetc(dev_t dev)
161 {
162 int chr, s;
163
164 s = splhigh();
165 chr = (*callv->_getchar)();
166 splx(s);
167 return chr;
168 }
169
170 /*
171 * Print a character on PROM console.
172 */
173 static void
romputc(dev_t dev,int c)174 romputc(dev_t dev, int c)
175 {
176 int s;
177
178 s = splhigh();
179 (*callv->_printf)("%c", c);
180 splx(s);
181 }
182
183 /*
184 * Get 32bit system type:
185 * cputype, u_int8_t [3]
186 * systype, u_int8_t [2]
187 * firmware revision, u_int8_t [1]
188 * hardware revision. u_int8_t [0]
189 */
190 int
prom_systype(void)191 prom_systype(void)
192 {
193
194 return (*callv->_getsysid)();
195 }
196
197 /*
198 * Halt/reboot machine.
199 */
200 void __attribute__((__noreturn__))
prom_halt(int howto)201 prom_halt(int howto)
202 {
203
204 (*callv->_halt)((int *)0, howto);
205 while(1) ; /* fool gcc */
206 /*NOTREACHED*/
207 }
208