cons.c revision 1.1 1 1.1 garbled /* $NetBSD: cons.c,v 1.1 2007/12/17 19:09:47 garbled Exp $ */
2 1.1 garbled
3 1.1 garbled /*
4 1.1 garbled * Copyright (c) 1990, 1993
5 1.1 garbled * The Regents of the University of California. All rights reserved.
6 1.1 garbled *
7 1.1 garbled * This code is derived from software contributed to Berkeley by
8 1.1 garbled * the Systems Programming Group of the University of Utah Computer
9 1.1 garbled * Science Department.
10 1.1 garbled *
11 1.1 garbled * Redistribution and use in source and binary forms, with or without
12 1.1 garbled * modification, are permitted provided that the following conditions
13 1.1 garbled * are met:
14 1.1 garbled * 1. Redistributions of source code must retain the above copyright
15 1.1 garbled * notice, this list of conditions and the following disclaimer.
16 1.1 garbled * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 garbled * notice, this list of conditions and the following disclaimer in the
18 1.1 garbled * documentation and/or other materials provided with the distribution.
19 1.1 garbled * 3. Neither the name of the University nor the names of its contributors
20 1.1 garbled * may be used to endorse or promote products derived from this software
21 1.1 garbled * without specific prior written permission.
22 1.1 garbled *
23 1.1 garbled * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 garbled * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 garbled * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 garbled * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 garbled * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 garbled * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 garbled * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 garbled * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 garbled * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 garbled * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 garbled * SUCH DAMAGE.
34 1.1 garbled *
35 1.1 garbled * from: Utah Hdr: cons.c 1.7 92/02/28
36 1.1 garbled *
37 1.1 garbled * @(#)cons.c 8.1 (Berkeley) 6/10/93
38 1.1 garbled */
39 1.1 garbled /*
40 1.1 garbled * Copyright (c) 1988 University of Utah.
41 1.1 garbled *
42 1.1 garbled * This code is derived from software contributed to Berkeley by
43 1.1 garbled * the Systems Programming Group of the University of Utah Computer
44 1.1 garbled * Science Department.
45 1.1 garbled *
46 1.1 garbled * Redistribution and use in source and binary forms, with or without
47 1.1 garbled * modification, are permitted provided that the following conditions
48 1.1 garbled * are met:
49 1.1 garbled * 1. Redistributions of source code must retain the above copyright
50 1.1 garbled * notice, this list of conditions and the following disclaimer.
51 1.1 garbled * 2. Redistributions in binary form must reproduce the above copyright
52 1.1 garbled * notice, this list of conditions and the following disclaimer in the
53 1.1 garbled * documentation and/or other materials provided with the distribution.
54 1.1 garbled * 3. All advertising materials mentioning features or use of this software
55 1.1 garbled * must display the following acknowledgement:
56 1.1 garbled * This product includes software developed by the University of
57 1.1 garbled * California, Berkeley and its contributors.
58 1.1 garbled * 4. Neither the name of the University nor the names of its contributors
59 1.1 garbled * may be used to endorse or promote products derived from this software
60 1.1 garbled * without specific prior written permission.
61 1.1 garbled *
62 1.1 garbled * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.1 garbled * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.1 garbled * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.1 garbled * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.1 garbled * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.1 garbled * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.1 garbled * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.1 garbled * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.1 garbled * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.1 garbled * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.1 garbled * SUCH DAMAGE.
73 1.1 garbled *
74 1.1 garbled * from: Utah Hdr: cons.c 1.7 92/02/28
75 1.1 garbled *
76 1.1 garbled * @(#)cons.c 8.1 (Berkeley) 6/10/93
77 1.1 garbled */
78 1.1 garbled
79 1.1 garbled #include <lib/libsa/stand.h>
80 1.1 garbled
81 1.1 garbled #include "boot.h"
82 1.1 garbled #include "cons.h"
83 1.1 garbled
84 1.1 garbled #ifdef CONS_SERIAL
85 1.1 garbled void siocnprobe(struct consdev *);
86 1.1 garbled void siocninit(struct consdev *);
87 1.1 garbled void siocnputchar(void *, int);
88 1.1 garbled int siocngetchar(void *);
89 1.1 garbled int siocnscan(void *);
90 1.1 garbled # include "ns16550.h"
91 1.1 garbled # ifndef COMPORT
92 1.1 garbled # define COMPORT COM1
93 1.1 garbled # endif
94 1.1 garbled # ifndef COMSPEED
95 1.1 garbled # define COMSPEED 9600
96 1.1 garbled # endif
97 1.1 garbled #endif
98 1.1 garbled
99 1.1 garbled struct consdev constab[] = {
100 1.1 garbled #ifdef CONS_SERIAL
101 1.1 garbled { "com", COMPORT, COMSPEED,
102 1.1 garbled siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
103 1.1 garbled #endif
104 1.1 garbled { 0 }
105 1.1 garbled };
106 1.1 garbled
107 1.1 garbled struct consdev *cn_tab;
108 1.1 garbled
109 1.1 garbled char *
110 1.1 garbled cninit(int *addr, int *speed)
111 1.1 garbled {
112 1.1 garbled register struct consdev *cp;
113 1.1 garbled
114 1.1 garbled cn_tab = NULL;
115 1.1 garbled for (cp = constab; cp->cn_probe; cp++) {
116 1.1 garbled (*cp->cn_probe)(cp);
117 1.1 garbled if (cp->cn_pri > CN_DEAD &&
118 1.1 garbled (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
119 1.1 garbled cn_tab = cp;
120 1.1 garbled }
121 1.1 garbled if (cn_tab) {
122 1.1 garbled (*cn_tab->cn_init)(cn_tab);
123 1.1 garbled *addr = cn_tab->address;
124 1.1 garbled *speed = cn_tab->speed;
125 1.1 garbled return (cn_tab->cn_name);
126 1.1 garbled }
127 1.1 garbled
128 1.1 garbled return (NULL);
129 1.1 garbled }
130 1.1 garbled
131 1.1 garbled int
132 1.1 garbled cngetc(void)
133 1.1 garbled {
134 1.1 garbled
135 1.1 garbled if (cn_tab)
136 1.1 garbled return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
137 1.1 garbled return (0);
138 1.1 garbled }
139 1.1 garbled
140 1.1 garbled void
141 1.1 garbled cnputc(int c)
142 1.1 garbled {
143 1.1 garbled
144 1.1 garbled if (cn_tab)
145 1.1 garbled (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
146 1.1 garbled }
147 1.1 garbled
148 1.1 garbled int
149 1.1 garbled cnscan(void)
150 1.1 garbled {
151 1.1 garbled
152 1.1 garbled if (cn_tab)
153 1.1 garbled return ((*cn_tab->cn_scan)(cn_tab->cn_dev));
154 1.1 garbled return (0);
155 1.1 garbled }
156 1.1 garbled
157 1.1 garbled #ifdef CONS_SERIAL
158 1.1 garbled /*
159 1.1 garbled * serial console
160 1.1 garbled */
161 1.1 garbled void
162 1.1 garbled siocnprobe(struct consdev *cp)
163 1.1 garbled {
164 1.1 garbled
165 1.1 garbled cp->cn_pri = CN_REMOTE;
166 1.1 garbled }
167 1.1 garbled
168 1.1 garbled void
169 1.1 garbled siocninit(struct consdev *cp)
170 1.1 garbled {
171 1.1 garbled
172 1.1 garbled cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed);
173 1.1 garbled }
174 1.1 garbled
175 1.1 garbled int
176 1.1 garbled siocngetchar(void *dev)
177 1.1 garbled {
178 1.1 garbled
179 1.1 garbled return (NS16550_getc((struct NS16550 *)dev));
180 1.1 garbled }
181 1.1 garbled
182 1.1 garbled void
183 1.1 garbled siocnputchar(void *dev, register int c)
184 1.1 garbled {
185 1.1 garbled
186 1.1 garbled if (c == '\n')
187 1.1 garbled NS16550_putc((struct NS16550 *)dev, '\r');
188 1.1 garbled NS16550_putc((struct NS16550 *)dev, c);
189 1.1 garbled }
190 1.1 garbled
191 1.1 garbled int
192 1.1 garbled siocnscan(void *dev)
193 1.1 garbled {
194 1.1 garbled
195 1.1 garbled return (NS16550_scankbd((struct NS16550 *)dev));
196 1.1 garbled }
197 1.1 garbled #endif /* CONS_SERIAL */
198