plcom.c revision 1.2.2.4 1 1.2.2.4 jdolecek /* $NetBSD: plcom.c,v 1.2.2.4 2002/10/10 18:32:23 jdolecek Exp $ */
2 1.2.2.2 thorpej
3 1.2.2.2 thorpej /*-
4 1.2.2.2 thorpej * Copyright (c) 2001 ARM Ltd
5 1.2.2.2 thorpej * All rights reserved.
6 1.2.2.2 thorpej *
7 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
8 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
9 1.2.2.2 thorpej * are met:
10 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
12 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
15 1.2.2.2 thorpej * 3. The name of the company may not be used to endorse or promote
16 1.2.2.2 thorpej * products derived from this software without specific prior written
17 1.2.2.2 thorpej * permission.
18 1.2.2.2 thorpej *
19 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 1.2.2.2 thorpej * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 1.2.2.2 thorpej * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.2.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 1.2.2.2 thorpej * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 1.2.2.2 thorpej * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 1.2.2.2 thorpej * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2.2.2 thorpej * SUCH DAMAGE.
30 1.2.2.2 thorpej *
31 1.2.2.2 thorpej * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
32 1.2.2.2 thorpej * All rights reserved.
33 1.2.2.2 thorpej *
34 1.2.2.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
35 1.2.2.2 thorpej * by Charles M. Hannum.
36 1.2.2.2 thorpej *
37 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
38 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
39 1.2.2.2 thorpej * are met:
40 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
41 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
42 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
43 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
44 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
45 1.2.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
46 1.2.2.2 thorpej * must display the following acknowledgement:
47 1.2.2.2 thorpej * This product includes software developed by the NetBSD
48 1.2.2.2 thorpej * Foundation, Inc. and its contributors.
49 1.2.2.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
50 1.2.2.2 thorpej * contributors may be used to endorse or promote products derived
51 1.2.2.2 thorpej * from this software without specific prior written permission.
52 1.2.2.2 thorpej *
53 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
54 1.2.2.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 1.2.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56 1.2.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
57 1.2.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
58 1.2.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
59 1.2.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60 1.2.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
61 1.2.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62 1.2.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
63 1.2.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
64 1.2.2.2 thorpej */
65 1.2.2.2 thorpej
66 1.2.2.2 thorpej /*
67 1.2.2.2 thorpej * Copyright (c) 1991 The Regents of the University of California.
68 1.2.2.2 thorpej * All rights reserved.
69 1.2.2.2 thorpej *
70 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
71 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
72 1.2.2.2 thorpej * are met:
73 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
74 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
75 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
76 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
77 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
78 1.2.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
79 1.2.2.2 thorpej * must display the following acknowledgement:
80 1.2.2.2 thorpej * This product includes software developed by the University of
81 1.2.2.2 thorpej * California, Berkeley and its contributors.
82 1.2.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
83 1.2.2.2 thorpej * may be used to endorse or promote products derived from this software
84 1.2.2.2 thorpej * without specific prior written permission.
85 1.2.2.2 thorpej *
86 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
87 1.2.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 1.2.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89 1.2.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
90 1.2.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91 1.2.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
92 1.2.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
93 1.2.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
94 1.2.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
95 1.2.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
96 1.2.2.2 thorpej * SUCH DAMAGE.
97 1.2.2.2 thorpej *
98 1.2.2.2 thorpej * @(#)com.c 7.5 (Berkeley) 5/16/91
99 1.2.2.2 thorpej */
100 1.2.2.2 thorpej
101 1.2.2.2 thorpej /*
102 1.2.2.2 thorpej * COM driver for the Prime Cell PL010 UART, which is similar to the 16C550,
103 1.2.2.2 thorpej * but has a completely different programmer's model.
104 1.2.2.2 thorpej * Derived from the NS16550AF com driver.
105 1.2.2.2 thorpej */
106 1.2.2.2 thorpej
107 1.2.2.2 thorpej #include "opt_plcom.h"
108 1.2.2.2 thorpej #include "opt_ddb.h"
109 1.2.2.2 thorpej #include "opt_kgdb.h"
110 1.2.2.2 thorpej
111 1.2.2.2 thorpej #include "rnd.h"
112 1.2.2.2 thorpej #if NRND > 0 && defined(RND_COM)
113 1.2.2.2 thorpej #include <sys/rnd.h>
114 1.2.2.2 thorpej #endif
115 1.2.2.2 thorpej
116 1.2.2.2 thorpej /*
117 1.2.2.2 thorpej * Override cnmagic(9) macro before including <sys/systm.h>.
118 1.2.2.2 thorpej * We need to know if cn_check_magic triggered debugger, so set a flag.
119 1.2.2.2 thorpej * Callers of cn_check_magic must declare int cn_trapped = 0;
120 1.2.2.2 thorpej * XXX: this is *ugly*!
121 1.2.2.2 thorpej */
122 1.2.2.2 thorpej #define cn_trap() \
123 1.2.2.2 thorpej do { \
124 1.2.2.2 thorpej console_debugger(); \
125 1.2.2.2 thorpej cn_trapped = 1; \
126 1.2.2.2 thorpej } while (/* CONSTCOND */ 0)
127 1.2.2.2 thorpej
128 1.2.2.2 thorpej #include <sys/param.h>
129 1.2.2.2 thorpej #include <sys/systm.h>
130 1.2.2.2 thorpej #include <sys/ioctl.h>
131 1.2.2.2 thorpej #include <sys/select.h>
132 1.2.2.2 thorpej #include <sys/tty.h>
133 1.2.2.2 thorpej #include <sys/proc.h>
134 1.2.2.2 thorpej #include <sys/user.h>
135 1.2.2.2 thorpej #include <sys/conf.h>
136 1.2.2.2 thorpej #include <sys/file.h>
137 1.2.2.2 thorpej #include <sys/uio.h>
138 1.2.2.2 thorpej #include <sys/kernel.h>
139 1.2.2.2 thorpej #include <sys/syslog.h>
140 1.2.2.2 thorpej #include <sys/types.h>
141 1.2.2.2 thorpej #include <sys/device.h>
142 1.2.2.2 thorpej #include <sys/malloc.h>
143 1.2.2.2 thorpej #include <sys/timepps.h>
144 1.2.2.2 thorpej #include <sys/vnode.h>
145 1.2.2.2 thorpej
146 1.2.2.2 thorpej #include <machine/intr.h>
147 1.2.2.2 thorpej #include <machine/bus.h>
148 1.2.2.2 thorpej
149 1.2.2.2 thorpej #include <evbarm/dev/plcomreg.h>
150 1.2.2.2 thorpej #include <evbarm/dev/plcomvar.h>
151 1.2.2.2 thorpej
152 1.2.2.2 thorpej #include <dev/cons.h>
153 1.2.2.2 thorpej
154 1.2.2.2 thorpej static void plcom_enable_debugport (struct plcom_softc *);
155 1.2.2.2 thorpej
156 1.2.2.2 thorpej void plcom_config (struct plcom_softc *);
157 1.2.2.2 thorpej void plcom_shutdown (struct plcom_softc *);
158 1.2.2.2 thorpej int plcomspeed (long, long);
159 1.2.2.2 thorpej static u_char cflag2lcr (tcflag_t);
160 1.2.2.2 thorpej int plcomparam (struct tty *, struct termios *);
161 1.2.2.2 thorpej void plcomstart (struct tty *);
162 1.2.2.2 thorpej int plcomhwiflow (struct tty *, int);
163 1.2.2.2 thorpej
164 1.2.2.2 thorpej void plcom_loadchannelregs (struct plcom_softc *);
165 1.2.2.2 thorpej void plcom_hwiflow (struct plcom_softc *);
166 1.2.2.2 thorpej void plcom_break (struct plcom_softc *, int);
167 1.2.2.2 thorpej void plcom_modem (struct plcom_softc *, int);
168 1.2.2.2 thorpej void tiocm_to_plcom (struct plcom_softc *, u_long, int);
169 1.2.2.2 thorpej int plcom_to_tiocm (struct plcom_softc *);
170 1.2.2.2 thorpej void plcom_iflush (struct plcom_softc *);
171 1.2.2.2 thorpej
172 1.2.2.2 thorpej int plcom_common_getc (dev_t, bus_space_tag_t, bus_space_handle_t);
173 1.2.2.2 thorpej void plcom_common_putc (dev_t, bus_space_tag_t, bus_space_handle_t, int);
174 1.2.2.2 thorpej
175 1.2.2.2 thorpej int plcominit (bus_space_tag_t, bus_addr_t, int, int, tcflag_t,
176 1.2.2.2 thorpej bus_space_handle_t *);
177 1.2.2.2 thorpej
178 1.2.2.4 jdolecek dev_type_open(plcomopen);
179 1.2.2.4 jdolecek dev_type_close(plcomclose);
180 1.2.2.4 jdolecek dev_type_read(plcomread);
181 1.2.2.4 jdolecek dev_type_write(plcomwrite);
182 1.2.2.4 jdolecek dev_type_ioctl(plcomioctl);
183 1.2.2.4 jdolecek dev_type_stop(plcomstop);
184 1.2.2.4 jdolecek dev_type_tty(plcomtty);
185 1.2.2.4 jdolecek dev_type_poll(plcompoll);
186 1.2.2.2 thorpej
187 1.2.2.2 thorpej int plcomcngetc (dev_t);
188 1.2.2.2 thorpej void plcomcnputc (dev_t, int);
189 1.2.2.2 thorpej void plcomcnpollc (dev_t, int);
190 1.2.2.2 thorpej
191 1.2.2.2 thorpej #define integrate static inline
192 1.2.2.2 thorpej #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
193 1.2.2.2 thorpej void plcomsoft (void *);
194 1.2.2.2 thorpej #else
195 1.2.2.2 thorpej #ifndef __NO_SOFT_SERIAL_INTERRUPT
196 1.2.2.2 thorpej void plcomsoft (void);
197 1.2.2.2 thorpej #else
198 1.2.2.2 thorpej void plcomsoft (void *);
199 1.2.2.2 thorpej struct callout plcomsoft_callout = CALLOUT_INITIALIZER;
200 1.2.2.2 thorpej #endif
201 1.2.2.2 thorpej #endif
202 1.2.2.2 thorpej integrate void plcom_rxsoft (struct plcom_softc *, struct tty *);
203 1.2.2.2 thorpej integrate void plcom_txsoft (struct plcom_softc *, struct tty *);
204 1.2.2.2 thorpej integrate void plcom_stsoft (struct plcom_softc *, struct tty *);
205 1.2.2.2 thorpej integrate void plcom_schedrx (struct plcom_softc *);
206 1.2.2.2 thorpej void plcomdiag (void *);
207 1.2.2.2 thorpej
208 1.2.2.2 thorpej extern struct cfdriver plcom_cd;
209 1.2.2.2 thorpej
210 1.2.2.4 jdolecek const struct cdevsw plcom_cdevsw = {
211 1.2.2.4 jdolecek plcomopen, plcomclose, plcomread, plcomwrite, plcomioctl,
212 1.2.2.4 jdolecek plcomstop, plcomtty, plcompoll, nommap, ttykqfilter, D_TTY
213 1.2.2.4 jdolecek };
214 1.2.2.4 jdolecek
215 1.2.2.2 thorpej /*
216 1.2.2.2 thorpej * Make this an option variable one can patch.
217 1.2.2.2 thorpej * But be warned: this must be a power of 2!
218 1.2.2.2 thorpej */
219 1.2.2.2 thorpej u_int plcom_rbuf_size = PLCOM_RING_SIZE;
220 1.2.2.2 thorpej
221 1.2.2.2 thorpej /* Stop input when 3/4 of the ring is full; restart when only 1/4 is full. */
222 1.2.2.2 thorpej u_int plcom_rbuf_hiwat = (PLCOM_RING_SIZE * 1) / 4;
223 1.2.2.2 thorpej u_int plcom_rbuf_lowat = (PLCOM_RING_SIZE * 3) / 4;
224 1.2.2.2 thorpej
225 1.2.2.2 thorpej static int plcomconsunit = -1;
226 1.2.2.2 thorpej static bus_space_tag_t plcomconstag;
227 1.2.2.2 thorpej static bus_space_handle_t plcomconsioh;
228 1.2.2.2 thorpej static int plcomconsattached;
229 1.2.2.2 thorpej static int plcomconsrate;
230 1.2.2.2 thorpej static tcflag_t plcomconscflag;
231 1.2.2.2 thorpej static struct cnm_state plcom_cnm_state;
232 1.2.2.2 thorpej
233 1.2.2.2 thorpej static int ppscap =
234 1.2.2.2 thorpej PPS_TSFMT_TSPEC |
235 1.2.2.2 thorpej PPS_CAPTUREASSERT |
236 1.2.2.2 thorpej PPS_CAPTURECLEAR |
237 1.2.2.2 thorpej #ifdef PPS_SYNC
238 1.2.2.2 thorpej PPS_HARDPPSONASSERT | PPS_HARDPPSONCLEAR |
239 1.2.2.2 thorpej #endif /* PPS_SYNC */
240 1.2.2.2 thorpej PPS_OFFSETASSERT | PPS_OFFSETCLEAR;
241 1.2.2.2 thorpej
242 1.2.2.2 thorpej #ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
243 1.2.2.2 thorpej #ifdef __NO_SOFT_SERIAL_INTERRUPT
244 1.2.2.2 thorpej volatile int plcom_softintr_scheduled;
245 1.2.2.2 thorpej #endif
246 1.2.2.2 thorpej #endif
247 1.2.2.2 thorpej
248 1.2.2.2 thorpej #ifdef KGDB
249 1.2.2.2 thorpej #include <sys/kgdb.h>
250 1.2.2.2 thorpej
251 1.2.2.2 thorpej static int plcom_kgdb_unit;
252 1.2.2.2 thorpej static bus_space_tag_t plcom_kgdb_iot;
253 1.2.2.2 thorpej static bus_space_handle_t plcom_kgdb_ioh;
254 1.2.2.2 thorpej static int plcom_kgdb_attached;
255 1.2.2.2 thorpej
256 1.2.2.2 thorpej int plcom_kgdb_getc (void *);
257 1.2.2.2 thorpej void plcom_kgdb_putc (void *, int);
258 1.2.2.2 thorpej #endif /* KGDB */
259 1.2.2.2 thorpej
260 1.2.2.2 thorpej #define PLCOMUNIT_MASK 0x7ffff
261 1.2.2.2 thorpej #define PLCOMDIALOUT_MASK 0x80000
262 1.2.2.2 thorpej
263 1.2.2.2 thorpej #define PLCOMUNIT(x) (minor(x) & PLCOMUNIT_MASK)
264 1.2.2.2 thorpej #define PLCOMDIALOUT(x) (minor(x) & PLCOMDIALOUT_MASK)
265 1.2.2.2 thorpej
266 1.2.2.2 thorpej #define PLCOM_ISALIVE(sc) ((sc)->enabled != 0 && \
267 1.2.2.2 thorpej ISSET((sc)->sc_dev.dv_flags, DVF_ACTIVE))
268 1.2.2.2 thorpej
269 1.2.2.2 thorpej #define BR BUS_SPACE_BARRIER_READ
270 1.2.2.2 thorpej #define BW BUS_SPACE_BARRIER_WRITE
271 1.2.2.2 thorpej #define PLCOM_BARRIER(t, h, f) bus_space_barrier((t), (h), 0, PLCOM_UART_SIZE, (f))
272 1.2.2.2 thorpej
273 1.2.2.2 thorpej #if (defined(MULTIPROCESSOR) || defined(LOCKDEBUG)) && defined(PLCOM_MPLOCK)
274 1.2.2.2 thorpej
275 1.2.2.2 thorpej #define PLCOM_LOCK(sc) simple_lock(&(sc)->sc_lock)
276 1.2.2.2 thorpej #define PLCOM_UNLOCK(sc) simple_unlock(&(sc)->sc_lock)
277 1.2.2.2 thorpej
278 1.2.2.2 thorpej #else
279 1.2.2.2 thorpej
280 1.2.2.2 thorpej #define PLCOM_LOCK(sc)
281 1.2.2.2 thorpej #define PLCOM_UNLOCK(sc)
282 1.2.2.2 thorpej
283 1.2.2.2 thorpej #endif
284 1.2.2.2 thorpej
285 1.2.2.2 thorpej int
286 1.2.2.2 thorpej plcomspeed(long speed, long frequency)
287 1.2.2.2 thorpej {
288 1.2.2.2 thorpej #define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
289 1.2.2.2 thorpej
290 1.2.2.2 thorpej int x, err;
291 1.2.2.2 thorpej
292 1.2.2.2 thorpej #if 0
293 1.2.2.2 thorpej if (speed == 0)
294 1.2.2.2 thorpej return 0;
295 1.2.2.2 thorpej #endif
296 1.2.2.2 thorpej if (speed <= 0)
297 1.2.2.2 thorpej return -1;
298 1.2.2.2 thorpej x = divrnd(frequency / 16, speed);
299 1.2.2.2 thorpej if (x <= 0)
300 1.2.2.2 thorpej return -1;
301 1.2.2.2 thorpej err = divrnd(((quad_t)frequency) * 1000 / 16, speed * x) - 1000;
302 1.2.2.2 thorpej if (err < 0)
303 1.2.2.2 thorpej err = -err;
304 1.2.2.2 thorpej if (err > PLCOM_TOLERANCE)
305 1.2.2.2 thorpej return -1;
306 1.2.2.2 thorpej return x;
307 1.2.2.2 thorpej
308 1.2.2.2 thorpej #undef divrnd
309 1.2.2.2 thorpej }
310 1.2.2.2 thorpej
311 1.2.2.2 thorpej #ifdef PLCOM_DEBUG
312 1.2.2.2 thorpej int plcom_debug = 0;
313 1.2.2.2 thorpej
314 1.2.2.2 thorpej void plcomstatus (struct plcom_softc *, char *);
315 1.2.2.2 thorpej void
316 1.2.2.2 thorpej plcomstatus(struct plcom_softc *sc, char *str)
317 1.2.2.2 thorpej {
318 1.2.2.2 thorpej struct tty *tp = sc->sc_tty;
319 1.2.2.2 thorpej
320 1.2.2.2 thorpej printf("%s: %s %sclocal %sdcd %sts_carr_on %sdtr %stx_stopped\n",
321 1.2.2.2 thorpej sc->sc_dev.dv_xname, str,
322 1.2.2.2 thorpej ISSET(tp->t_cflag, CLOCAL) ? "+" : "-",
323 1.2.2.2 thorpej ISSET(sc->sc_msr, MSR_DCD) ? "+" : "-",
324 1.2.2.2 thorpej ISSET(tp->t_state, TS_CARR_ON) ? "+" : "-",
325 1.2.2.2 thorpej ISSET(sc->sc_mcr, MCR_DTR) ? "+" : "-",
326 1.2.2.2 thorpej sc->sc_tx_stopped ? "+" : "-");
327 1.2.2.2 thorpej
328 1.2.2.2 thorpej printf("%s: %s %scrtscts %scts %sts_ttstop %srts %xrx_flags\n",
329 1.2.2.2 thorpej sc->sc_dev.dv_xname, str,
330 1.2.2.2 thorpej ISSET(tp->t_cflag, CRTSCTS) ? "+" : "-",
331 1.2.2.2 thorpej ISSET(sc->sc_msr, MSR_CTS) ? "+" : "-",
332 1.2.2.2 thorpej ISSET(tp->t_state, TS_TTSTOP) ? "+" : "-",
333 1.2.2.2 thorpej ISSET(sc->sc_mcr, MCR_RTS) ? "+" : "-",
334 1.2.2.2 thorpej sc->sc_rx_flags);
335 1.2.2.2 thorpej }
336 1.2.2.2 thorpej #endif
337 1.2.2.2 thorpej
338 1.2.2.2 thorpej int
339 1.2.2.2 thorpej plcomprobe1(bus_space_tag_t iot, bus_space_handle_t ioh)
340 1.2.2.2 thorpej {
341 1.2.2.2 thorpej int data;
342 1.2.2.2 thorpej
343 1.2.2.2 thorpej /* Disable the UART. */
344 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, 0);
345 1.2.2.2 thorpej /* Make sure the FIFO is off. */
346 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_lcr, LCR_8BITS);
347 1.2.2.2 thorpej /* Disable interrupts. */
348 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_iir, 0);
349 1.2.2.2 thorpej
350 1.2.2.2 thorpej /* Make sure we swallow anything in the receiving register. */
351 1.2.2.2 thorpej data = bus_space_read_1(iot, ioh, plcom_dr);
352 1.2.2.2 thorpej
353 1.2.2.2 thorpej if (bus_space_read_1(iot, ioh, plcom_lcr) != LCR_8BITS)
354 1.2.2.2 thorpej return 0;
355 1.2.2.2 thorpej
356 1.2.2.2 thorpej data = bus_space_read_1(iot, ioh, plcom_fr) & (FR_RXFF | FR_RXFE);
357 1.2.2.2 thorpej
358 1.2.2.2 thorpej if (data != FR_RXFE)
359 1.2.2.2 thorpej return 0;
360 1.2.2.2 thorpej
361 1.2.2.2 thorpej return 1;
362 1.2.2.2 thorpej }
363 1.2.2.2 thorpej
364 1.2.2.2 thorpej static void
365 1.2.2.2 thorpej plcom_enable_debugport(struct plcom_softc *sc)
366 1.2.2.2 thorpej {
367 1.2.2.2 thorpej int s;
368 1.2.2.2 thorpej
369 1.2.2.2 thorpej /* Turn on line break interrupt, set carrier. */
370 1.2.2.2 thorpej s = splserial();
371 1.2.2.2 thorpej PLCOM_LOCK(sc);
372 1.2.2.2 thorpej sc->sc_cr = CR_RIE | CR_RTIE | CR_UARTEN;
373 1.2.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, plcom_cr, sc->sc_cr);
374 1.2.2.2 thorpej SET(sc->sc_mcr, MCR_DTR | MCR_RTS);
375 1.2.2.2 thorpej sc->sc_set_mcr(sc->sc_set_mcr_arg, sc->sc_dev.dv_unit, sc->sc_mcr);
376 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
377 1.2.2.2 thorpej splx(s);
378 1.2.2.2 thorpej }
379 1.2.2.2 thorpej
380 1.2.2.2 thorpej void
381 1.2.2.2 thorpej plcom_attach_subr(struct plcom_softc *sc)
382 1.2.2.2 thorpej {
383 1.2.2.2 thorpej int unit = sc->sc_iounit;
384 1.2.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
385 1.2.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
386 1.2.2.2 thorpej struct tty *tp;
387 1.2.2.2 thorpej
388 1.2.2.2 thorpej callout_init(&sc->sc_diag_callout);
389 1.2.2.2 thorpej #if (defined(MULTIPROCESSOR) || defined(LOCKDEBUG)) && defined(PLCOM_MPLOCK)
390 1.2.2.2 thorpej simple_lock_init(&sc->sc_lock);
391 1.2.2.2 thorpej #endif
392 1.2.2.2 thorpej
393 1.2.2.2 thorpej /* Disable interrupts before configuring the device. */
394 1.2.2.2 thorpej sc->sc_cr = 0;
395 1.2.2.2 thorpej
396 1.2.2.2 thorpej if (plcomconstag && unit == plcomconsunit) {
397 1.2.2.2 thorpej plcomconsattached = 1;
398 1.2.2.2 thorpej
399 1.2.2.2 thorpej plcomconstag = iot;
400 1.2.2.2 thorpej plcomconsioh = ioh;
401 1.2.2.2 thorpej
402 1.2.2.2 thorpej /* Make sure the console is always "hardwired". */
403 1.2.2.2 thorpej delay(1000); /* wait for output to finish */
404 1.2.2.2 thorpej SET(sc->sc_hwflags, PLCOM_HW_CONSOLE);
405 1.2.2.2 thorpej SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
406 1.2.2.2 thorpej /* Must re-enable the console immediately, or we will
407 1.2.2.2 thorpej hang when trying to print. */
408 1.2.2.2 thorpej sc->sc_cr = CR_UARTEN;
409 1.2.2.2 thorpej }
410 1.2.2.2 thorpej
411 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, sc->sc_cr);
412 1.2.2.2 thorpej
413 1.2.2.2 thorpej /* The PL010 has a 16-byte fifo, but the tx interrupt triggers when
414 1.2.2.2 thorpej there is space for 8 more bytes. */
415 1.2.2.2 thorpej sc->sc_fifolen = 8;
416 1.2.2.2 thorpej printf("\n");
417 1.2.2.2 thorpej
418 1.2.2.2 thorpej if (ISSET(sc->sc_hwflags, PLCOM_HW_TXFIFO_DISABLE)) {
419 1.2.2.2 thorpej sc->sc_fifolen = 1;
420 1.2.2.2 thorpej printf("%s: txfifo disabled\n", sc->sc_dev.dv_xname);
421 1.2.2.2 thorpej }
422 1.2.2.2 thorpej
423 1.2.2.2 thorpej if (sc->sc_fifolen > 1)
424 1.2.2.2 thorpej SET(sc->sc_hwflags, PLCOM_HW_FIFO);
425 1.2.2.2 thorpej
426 1.2.2.2 thorpej tp = ttymalloc();
427 1.2.2.2 thorpej tp->t_oproc = plcomstart;
428 1.2.2.2 thorpej tp->t_param = plcomparam;
429 1.2.2.2 thorpej tp->t_hwiflow = plcomhwiflow;
430 1.2.2.2 thorpej
431 1.2.2.2 thorpej sc->sc_tty = tp;
432 1.2.2.2 thorpej sc->sc_rbuf = malloc(plcom_rbuf_size << 1, M_DEVBUF, M_NOWAIT);
433 1.2.2.2 thorpej sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
434 1.2.2.2 thorpej sc->sc_rbavail = plcom_rbuf_size;
435 1.2.2.2 thorpej if (sc->sc_rbuf == NULL) {
436 1.2.2.2 thorpej printf("%s: unable to allocate ring buffer\n",
437 1.2.2.2 thorpej sc->sc_dev.dv_xname);
438 1.2.2.2 thorpej return;
439 1.2.2.2 thorpej }
440 1.2.2.2 thorpej sc->sc_ebuf = sc->sc_rbuf + (plcom_rbuf_size << 1);
441 1.2.2.2 thorpej
442 1.2.2.2 thorpej tty_attach(tp);
443 1.2.2.2 thorpej
444 1.2.2.2 thorpej if (ISSET(sc->sc_hwflags, PLCOM_HW_CONSOLE)) {
445 1.2.2.2 thorpej int maj;
446 1.2.2.2 thorpej
447 1.2.2.2 thorpej /* locate the major number */
448 1.2.2.4 jdolecek maj = cdevsw_lookup_major(&plcom_cdevsw);
449 1.2.2.2 thorpej
450 1.2.2.2 thorpej cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit);
451 1.2.2.2 thorpej
452 1.2.2.2 thorpej printf("%s: console\n", sc->sc_dev.dv_xname);
453 1.2.2.2 thorpej }
454 1.2.2.2 thorpej
455 1.2.2.2 thorpej #ifdef KGDB
456 1.2.2.2 thorpej /*
457 1.2.2.2 thorpej * Allow kgdb to "take over" this port. If this is
458 1.2.2.2 thorpej * the kgdb device, it has exclusive use.
459 1.2.2.2 thorpej */
460 1.2.2.2 thorpej if (iot == plcom_kgdb_iot && unit == plcom_kgdb_unit) {
461 1.2.2.2 thorpej plcom_kgdb_attached = 1;
462 1.2.2.2 thorpej
463 1.2.2.2 thorpej SET(sc->sc_hwflags, PLCOM_HW_KGDB);
464 1.2.2.2 thorpej printf("%s: kgdb\n", sc->sc_dev.dv_xname);
465 1.2.2.2 thorpej }
466 1.2.2.2 thorpej #endif
467 1.2.2.2 thorpej
468 1.2.2.2 thorpej #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
469 1.2.2.2 thorpej sc->sc_si = softintr_establish(IPL_SOFTSERIAL, plcomsoft, sc);
470 1.2.2.2 thorpej #endif
471 1.2.2.2 thorpej
472 1.2.2.2 thorpej #if NRND > 0 && defined(RND_COM)
473 1.2.2.2 thorpej rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
474 1.2.2.2 thorpej RND_TYPE_TTY, 0);
475 1.2.2.2 thorpej #endif
476 1.2.2.2 thorpej
477 1.2.2.2 thorpej /* if there are no enable/disable functions, assume the device
478 1.2.2.2 thorpej is always enabled */
479 1.2.2.2 thorpej if (!sc->enable)
480 1.2.2.2 thorpej sc->enabled = 1;
481 1.2.2.2 thorpej
482 1.2.2.2 thorpej plcom_config(sc);
483 1.2.2.2 thorpej
484 1.2.2.2 thorpej SET(sc->sc_hwflags, PLCOM_HW_DEV_OK);
485 1.2.2.2 thorpej }
486 1.2.2.2 thorpej
487 1.2.2.2 thorpej void
488 1.2.2.2 thorpej plcom_config(struct plcom_softc *sc)
489 1.2.2.2 thorpej {
490 1.2.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
491 1.2.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
492 1.2.2.2 thorpej
493 1.2.2.2 thorpej /* Disable interrupts before configuring the device. */
494 1.2.2.2 thorpej sc->sc_cr = 0;
495 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, sc->sc_cr);
496 1.2.2.2 thorpej
497 1.2.2.2 thorpej if (ISSET(sc->sc_hwflags, PLCOM_HW_CONSOLE|PLCOM_HW_KGDB))
498 1.2.2.2 thorpej plcom_enable_debugport(sc);
499 1.2.2.2 thorpej }
500 1.2.2.2 thorpej
501 1.2.2.2 thorpej int
502 1.2.2.2 thorpej plcom_detach(self, flags)
503 1.2.2.2 thorpej struct device *self;
504 1.2.2.2 thorpej int flags;
505 1.2.2.2 thorpej {
506 1.2.2.2 thorpej struct plcom_softc *sc = (struct plcom_softc *)self;
507 1.2.2.2 thorpej int maj, mn;
508 1.2.2.2 thorpej
509 1.2.2.2 thorpej /* locate the major number */
510 1.2.2.4 jdolecek maj = cdevsw_lookup_major(&plcom_cdevsw);
511 1.2.2.2 thorpej
512 1.2.2.2 thorpej /* Nuke the vnodes for any open instances. */
513 1.2.2.2 thorpej mn = self->dv_unit;
514 1.2.2.2 thorpej vdevgone(maj, mn, mn, VCHR);
515 1.2.2.2 thorpej
516 1.2.2.2 thorpej mn |= PLCOMDIALOUT_MASK;
517 1.2.2.2 thorpej vdevgone(maj, mn, mn, VCHR);
518 1.2.2.2 thorpej
519 1.2.2.2 thorpej /* Free the receive buffer. */
520 1.2.2.2 thorpej free(sc->sc_rbuf, M_DEVBUF);
521 1.2.2.2 thorpej
522 1.2.2.2 thorpej /* Detach and free the tty. */
523 1.2.2.2 thorpej tty_detach(sc->sc_tty);
524 1.2.2.2 thorpej ttyfree(sc->sc_tty);
525 1.2.2.2 thorpej
526 1.2.2.2 thorpej #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
527 1.2.2.2 thorpej /* Unhook the soft interrupt handler. */
528 1.2.2.2 thorpej softintr_disestablish(sc->sc_si);
529 1.2.2.2 thorpej #endif
530 1.2.2.2 thorpej
531 1.2.2.2 thorpej #if NRND > 0 && defined(RND_COM)
532 1.2.2.2 thorpej /* Unhook the entropy source. */
533 1.2.2.2 thorpej rnd_detach_source(&sc->rnd_source);
534 1.2.2.2 thorpej #endif
535 1.2.2.2 thorpej
536 1.2.2.2 thorpej return 0;
537 1.2.2.2 thorpej }
538 1.2.2.2 thorpej
539 1.2.2.2 thorpej int
540 1.2.2.2 thorpej plcom_activate(struct device *self, enum devact act)
541 1.2.2.2 thorpej {
542 1.2.2.2 thorpej struct plcom_softc *sc = (struct plcom_softc *)self;
543 1.2.2.2 thorpej int s, rv = 0;
544 1.2.2.2 thorpej
545 1.2.2.2 thorpej s = splserial();
546 1.2.2.2 thorpej PLCOM_LOCK(sc);
547 1.2.2.2 thorpej switch (act) {
548 1.2.2.2 thorpej case DVACT_ACTIVATE:
549 1.2.2.2 thorpej rv = EOPNOTSUPP;
550 1.2.2.2 thorpej break;
551 1.2.2.2 thorpej
552 1.2.2.2 thorpej case DVACT_DEACTIVATE:
553 1.2.2.2 thorpej if (sc->sc_hwflags & (PLCOM_HW_CONSOLE|PLCOM_HW_KGDB)) {
554 1.2.2.2 thorpej rv = EBUSY;
555 1.2.2.2 thorpej break;
556 1.2.2.2 thorpej }
557 1.2.2.2 thorpej
558 1.2.2.2 thorpej if (sc->disable != NULL && sc->enabled != 0) {
559 1.2.2.2 thorpej (*sc->disable)(sc);
560 1.2.2.2 thorpej sc->enabled = 0;
561 1.2.2.2 thorpej }
562 1.2.2.2 thorpej break;
563 1.2.2.2 thorpej }
564 1.2.2.2 thorpej
565 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
566 1.2.2.2 thorpej splx(s);
567 1.2.2.2 thorpej return rv;
568 1.2.2.2 thorpej }
569 1.2.2.2 thorpej
570 1.2.2.2 thorpej void
571 1.2.2.2 thorpej plcom_shutdown(struct plcom_softc *sc)
572 1.2.2.2 thorpej {
573 1.2.2.2 thorpej struct tty *tp = sc->sc_tty;
574 1.2.2.2 thorpej int s;
575 1.2.2.2 thorpej
576 1.2.2.2 thorpej s = splserial();
577 1.2.2.2 thorpej PLCOM_LOCK(sc);
578 1.2.2.2 thorpej
579 1.2.2.2 thorpej /* If we were asserting flow control, then deassert it. */
580 1.2.2.2 thorpej SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
581 1.2.2.2 thorpej plcom_hwiflow(sc);
582 1.2.2.2 thorpej
583 1.2.2.2 thorpej /* Clear any break condition set with TIOCSBRK. */
584 1.2.2.2 thorpej plcom_break(sc, 0);
585 1.2.2.2 thorpej
586 1.2.2.2 thorpej /* Turn off PPS capture on last close. */
587 1.2.2.2 thorpej sc->sc_ppsmask = 0;
588 1.2.2.2 thorpej sc->ppsparam.mode = 0;
589 1.2.2.2 thorpej
590 1.2.2.2 thorpej /*
591 1.2.2.2 thorpej * Hang up if necessary. Wait a bit, so the other side has time to
592 1.2.2.2 thorpej * notice even if we immediately open the port again.
593 1.2.2.2 thorpej * Avoid tsleeping above splhigh().
594 1.2.2.2 thorpej */
595 1.2.2.2 thorpej if (ISSET(tp->t_cflag, HUPCL)) {
596 1.2.2.2 thorpej plcom_modem(sc, 0);
597 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
598 1.2.2.2 thorpej splx(s);
599 1.2.2.2 thorpej /* XXX tsleep will only timeout */
600 1.2.2.2 thorpej (void) tsleep(sc, TTIPRI, ttclos, hz);
601 1.2.2.2 thorpej s = splserial();
602 1.2.2.2 thorpej PLCOM_LOCK(sc);
603 1.2.2.2 thorpej }
604 1.2.2.2 thorpej
605 1.2.2.2 thorpej /* Turn off interrupts. */
606 1.2.2.2 thorpej if (ISSET(sc->sc_hwflags, PLCOM_HW_CONSOLE))
607 1.2.2.2 thorpej /* interrupt on break */
608 1.2.2.2 thorpej sc->sc_cr = CR_RIE | CR_RTIE | CR_UARTEN;
609 1.2.2.2 thorpej else
610 1.2.2.2 thorpej sc->sc_cr = 0;
611 1.2.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, plcom_cr, sc->sc_cr);
612 1.2.2.2 thorpej
613 1.2.2.2 thorpej if (sc->disable) {
614 1.2.2.2 thorpej #ifdef DIAGNOSTIC
615 1.2.2.2 thorpej if (!sc->enabled)
616 1.2.2.2 thorpej panic("plcom_shutdown: not enabled?");
617 1.2.2.2 thorpej #endif
618 1.2.2.2 thorpej (*sc->disable)(sc);
619 1.2.2.2 thorpej sc->enabled = 0;
620 1.2.2.2 thorpej }
621 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
622 1.2.2.2 thorpej splx(s);
623 1.2.2.2 thorpej }
624 1.2.2.2 thorpej
625 1.2.2.2 thorpej int
626 1.2.2.2 thorpej plcomopen(dev_t dev, int flag, int mode, struct proc *p)
627 1.2.2.2 thorpej {
628 1.2.2.2 thorpej struct plcom_softc *sc;
629 1.2.2.2 thorpej struct tty *tp;
630 1.2.2.2 thorpej int s, s2;
631 1.2.2.2 thorpej int error;
632 1.2.2.2 thorpej
633 1.2.2.2 thorpej sc = device_lookup(&plcom_cd, PLCOMUNIT(dev));
634 1.2.2.2 thorpej if (sc == NULL || !ISSET(sc->sc_hwflags, PLCOM_HW_DEV_OK) ||
635 1.2.2.2 thorpej sc->sc_rbuf == NULL)
636 1.2.2.2 thorpej return ENXIO;
637 1.2.2.2 thorpej
638 1.2.2.2 thorpej if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
639 1.2.2.2 thorpej return ENXIO;
640 1.2.2.2 thorpej
641 1.2.2.2 thorpej #ifdef KGDB
642 1.2.2.2 thorpej /*
643 1.2.2.2 thorpej * If this is the kgdb port, no other use is permitted.
644 1.2.2.2 thorpej */
645 1.2.2.2 thorpej if (ISSET(sc->sc_hwflags, PLCOM_HW_KGDB))
646 1.2.2.2 thorpej return EBUSY;
647 1.2.2.2 thorpej #endif
648 1.2.2.2 thorpej
649 1.2.2.2 thorpej tp = sc->sc_tty;
650 1.2.2.2 thorpej
651 1.2.2.2 thorpej if (ISSET(tp->t_state, TS_ISOPEN) &&
652 1.2.2.2 thorpej ISSET(tp->t_state, TS_XCLUDE) &&
653 1.2.2.2 thorpej p->p_ucred->cr_uid != 0)
654 1.2.2.2 thorpej return EBUSY;
655 1.2.2.2 thorpej
656 1.2.2.2 thorpej s = spltty();
657 1.2.2.2 thorpej
658 1.2.2.2 thorpej /*
659 1.2.2.2 thorpej * Do the following iff this is a first open.
660 1.2.2.2 thorpej */
661 1.2.2.2 thorpej if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
662 1.2.2.2 thorpej struct termios t;
663 1.2.2.2 thorpej
664 1.2.2.2 thorpej tp->t_dev = dev;
665 1.2.2.2 thorpej
666 1.2.2.2 thorpej s2 = splserial();
667 1.2.2.2 thorpej PLCOM_LOCK(sc);
668 1.2.2.2 thorpej
669 1.2.2.2 thorpej if (sc->enable) {
670 1.2.2.2 thorpej if ((*sc->enable)(sc)) {
671 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
672 1.2.2.2 thorpej splx(s2);
673 1.2.2.2 thorpej splx(s);
674 1.2.2.2 thorpej printf("%s: device enable failed\n",
675 1.2.2.2 thorpej sc->sc_dev.dv_xname);
676 1.2.2.2 thorpej return EIO;
677 1.2.2.2 thorpej }
678 1.2.2.2 thorpej sc->enabled = 1;
679 1.2.2.2 thorpej plcom_config(sc);
680 1.2.2.2 thorpej }
681 1.2.2.2 thorpej
682 1.2.2.2 thorpej /* Turn on interrupts. */
683 1.2.2.2 thorpej /* IER_ERXRDY | IER_ERLS | IER_EMSC; */
684 1.2.2.2 thorpej sc->sc_cr = CR_RIE | CR_RTIE | CR_MSIE | CR_UARTEN;
685 1.2.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, plcom_cr, sc->sc_cr);
686 1.2.2.2 thorpej
687 1.2.2.2 thorpej /* Fetch the current modem control status, needed later. */
688 1.2.2.2 thorpej sc->sc_msr = bus_space_read_1(sc->sc_iot, sc->sc_ioh, plcom_fr);
689 1.2.2.2 thorpej
690 1.2.2.2 thorpej /* Clear PPS capture state on first open. */
691 1.2.2.2 thorpej sc->sc_ppsmask = 0;
692 1.2.2.2 thorpej sc->ppsparam.mode = 0;
693 1.2.2.2 thorpej
694 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
695 1.2.2.2 thorpej splx(s2);
696 1.2.2.2 thorpej
697 1.2.2.2 thorpej /*
698 1.2.2.2 thorpej * Initialize the termios status to the defaults. Add in the
699 1.2.2.2 thorpej * sticky bits from TIOCSFLAGS.
700 1.2.2.2 thorpej */
701 1.2.2.2 thorpej t.c_ispeed = 0;
702 1.2.2.2 thorpej if (ISSET(sc->sc_hwflags, PLCOM_HW_CONSOLE)) {
703 1.2.2.2 thorpej t.c_ospeed = plcomconsrate;
704 1.2.2.2 thorpej t.c_cflag = plcomconscflag;
705 1.2.2.2 thorpej } else {
706 1.2.2.2 thorpej t.c_ospeed = TTYDEF_SPEED;
707 1.2.2.2 thorpej t.c_cflag = TTYDEF_CFLAG;
708 1.2.2.2 thorpej }
709 1.2.2.2 thorpej if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
710 1.2.2.2 thorpej SET(t.c_cflag, CLOCAL);
711 1.2.2.2 thorpej if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
712 1.2.2.2 thorpej SET(t.c_cflag, CRTSCTS);
713 1.2.2.2 thorpej if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
714 1.2.2.2 thorpej SET(t.c_cflag, MDMBUF);
715 1.2.2.2 thorpej /* Make sure plcomparam() will do something. */
716 1.2.2.2 thorpej tp->t_ospeed = 0;
717 1.2.2.2 thorpej (void) plcomparam(tp, &t);
718 1.2.2.2 thorpej tp->t_iflag = TTYDEF_IFLAG;
719 1.2.2.2 thorpej tp->t_oflag = TTYDEF_OFLAG;
720 1.2.2.2 thorpej tp->t_lflag = TTYDEF_LFLAG;
721 1.2.2.2 thorpej ttychars(tp);
722 1.2.2.2 thorpej ttsetwater(tp);
723 1.2.2.2 thorpej
724 1.2.2.2 thorpej s2 = splserial();
725 1.2.2.2 thorpej PLCOM_LOCK(sc);
726 1.2.2.2 thorpej
727 1.2.2.2 thorpej /*
728 1.2.2.2 thorpej * Turn on DTR. We must always do this, even if carrier is not
729 1.2.2.2 thorpej * present, because otherwise we'd have to use TIOCSDTR
730 1.2.2.2 thorpej * immediately after setting CLOCAL, which applications do not
731 1.2.2.2 thorpej * expect. We always assert DTR while the device is open
732 1.2.2.2 thorpej * unless explicitly requested to deassert it.
733 1.2.2.2 thorpej */
734 1.2.2.2 thorpej plcom_modem(sc, 1);
735 1.2.2.2 thorpej
736 1.2.2.2 thorpej /* Clear the input ring, and unblock. */
737 1.2.2.2 thorpej sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
738 1.2.2.2 thorpej sc->sc_rbavail = plcom_rbuf_size;
739 1.2.2.2 thorpej plcom_iflush(sc);
740 1.2.2.2 thorpej CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
741 1.2.2.2 thorpej plcom_hwiflow(sc);
742 1.2.2.2 thorpej
743 1.2.2.2 thorpej #ifdef PLCOM_DEBUG
744 1.2.2.2 thorpej if (plcom_debug)
745 1.2.2.2 thorpej plcomstatus(sc, "plcomopen ");
746 1.2.2.2 thorpej #endif
747 1.2.2.2 thorpej
748 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
749 1.2.2.2 thorpej splx(s2);
750 1.2.2.2 thorpej }
751 1.2.2.2 thorpej
752 1.2.2.2 thorpej splx(s);
753 1.2.2.2 thorpej
754 1.2.2.2 thorpej error = ttyopen(tp, PLCOMDIALOUT(dev), ISSET(flag, O_NONBLOCK));
755 1.2.2.2 thorpej if (error)
756 1.2.2.2 thorpej goto bad;
757 1.2.2.2 thorpej
758 1.2.2.2 thorpej error = (*tp->t_linesw->l_open)(dev, tp);
759 1.2.2.2 thorpej if (error)
760 1.2.2.2 thorpej goto bad;
761 1.2.2.2 thorpej
762 1.2.2.2 thorpej return 0;
763 1.2.2.2 thorpej
764 1.2.2.2 thorpej bad:
765 1.2.2.2 thorpej if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
766 1.2.2.2 thorpej /*
767 1.2.2.2 thorpej * We failed to open the device, and nobody else had it opened.
768 1.2.2.2 thorpej * Clean up the state as appropriate.
769 1.2.2.2 thorpej */
770 1.2.2.2 thorpej plcom_shutdown(sc);
771 1.2.2.2 thorpej }
772 1.2.2.2 thorpej
773 1.2.2.2 thorpej return error;
774 1.2.2.2 thorpej }
775 1.2.2.2 thorpej
776 1.2.2.2 thorpej int
777 1.2.2.2 thorpej plcomclose(dev_t dev, int flag, int mode, struct proc *p)
778 1.2.2.2 thorpej {
779 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(dev));
780 1.2.2.2 thorpej struct tty *tp = sc->sc_tty;
781 1.2.2.2 thorpej
782 1.2.2.2 thorpej /* XXX This is for cons.c. */
783 1.2.2.2 thorpej if (!ISSET(tp->t_state, TS_ISOPEN))
784 1.2.2.2 thorpej return 0;
785 1.2.2.2 thorpej
786 1.2.2.2 thorpej (*tp->t_linesw->l_close)(tp, flag);
787 1.2.2.2 thorpej ttyclose(tp);
788 1.2.2.2 thorpej
789 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
790 1.2.2.2 thorpej return 0;
791 1.2.2.2 thorpej
792 1.2.2.2 thorpej if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
793 1.2.2.2 thorpej /*
794 1.2.2.2 thorpej * Although we got a last close, the device may still be in
795 1.2.2.2 thorpej * use; e.g. if this was the dialout node, and there are still
796 1.2.2.2 thorpej * processes waiting for carrier on the non-dialout node.
797 1.2.2.2 thorpej */
798 1.2.2.2 thorpej plcom_shutdown(sc);
799 1.2.2.2 thorpej }
800 1.2.2.2 thorpej
801 1.2.2.2 thorpej return 0;
802 1.2.2.2 thorpej }
803 1.2.2.2 thorpej
804 1.2.2.2 thorpej int
805 1.2.2.2 thorpej plcomread(dev_t dev, struct uio *uio, int flag)
806 1.2.2.2 thorpej {
807 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(dev));
808 1.2.2.2 thorpej struct tty *tp = sc->sc_tty;
809 1.2.2.2 thorpej
810 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
811 1.2.2.2 thorpej return EIO;
812 1.2.2.2 thorpej
813 1.2.2.2 thorpej return (*tp->t_linesw->l_read)(tp, uio, flag);
814 1.2.2.2 thorpej }
815 1.2.2.2 thorpej
816 1.2.2.2 thorpej int
817 1.2.2.2 thorpej plcomwrite(dev_t dev, struct uio *uio, int flag)
818 1.2.2.2 thorpej {
819 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(dev));
820 1.2.2.2 thorpej struct tty *tp = sc->sc_tty;
821 1.2.2.2 thorpej
822 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
823 1.2.2.2 thorpej return EIO;
824 1.2.2.2 thorpej
825 1.2.2.2 thorpej return (*tp->t_linesw->l_write)(tp, uio, flag);
826 1.2.2.2 thorpej }
827 1.2.2.2 thorpej
828 1.2.2.2 thorpej int
829 1.2.2.2 thorpej plcompoll(dev_t dev, int events, struct proc *p)
830 1.2.2.2 thorpej {
831 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(dev));
832 1.2.2.2 thorpej struct tty *tp = sc->sc_tty;
833 1.2.2.2 thorpej
834 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
835 1.2.2.2 thorpej return EIO;
836 1.2.2.2 thorpej
837 1.2.2.2 thorpej return (*tp->t_linesw->l_poll)(tp, events, p);
838 1.2.2.2 thorpej }
839 1.2.2.2 thorpej
840 1.2.2.2 thorpej struct tty *
841 1.2.2.2 thorpej plcomtty(dev_t dev)
842 1.2.2.2 thorpej {
843 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(dev));
844 1.2.2.2 thorpej struct tty *tp = sc->sc_tty;
845 1.2.2.2 thorpej
846 1.2.2.2 thorpej return tp;
847 1.2.2.2 thorpej }
848 1.2.2.2 thorpej
849 1.2.2.2 thorpej int
850 1.2.2.2 thorpej plcomioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
851 1.2.2.2 thorpej {
852 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(dev));
853 1.2.2.2 thorpej struct tty *tp = sc->sc_tty;
854 1.2.2.2 thorpej int error;
855 1.2.2.2 thorpej int s;
856 1.2.2.2 thorpej
857 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
858 1.2.2.2 thorpej return EIO;
859 1.2.2.2 thorpej
860 1.2.2.2 thorpej error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
861 1.2.2.3 jdolecek if (error != EPASSTHROUGH)
862 1.2.2.2 thorpej return error;
863 1.2.2.2 thorpej
864 1.2.2.2 thorpej error = ttioctl(tp, cmd, data, flag, p);
865 1.2.2.3 jdolecek if (error != EPASSTHROUGH)
866 1.2.2.2 thorpej return error;
867 1.2.2.2 thorpej
868 1.2.2.2 thorpej error = 0;
869 1.2.2.2 thorpej
870 1.2.2.2 thorpej s = splserial();
871 1.2.2.2 thorpej PLCOM_LOCK(sc);
872 1.2.2.2 thorpej
873 1.2.2.2 thorpej switch (cmd) {
874 1.2.2.2 thorpej case TIOCSBRK:
875 1.2.2.2 thorpej plcom_break(sc, 1);
876 1.2.2.2 thorpej break;
877 1.2.2.2 thorpej
878 1.2.2.2 thorpej case TIOCCBRK:
879 1.2.2.2 thorpej plcom_break(sc, 0);
880 1.2.2.2 thorpej break;
881 1.2.2.2 thorpej
882 1.2.2.2 thorpej case TIOCSDTR:
883 1.2.2.2 thorpej plcom_modem(sc, 1);
884 1.2.2.2 thorpej break;
885 1.2.2.2 thorpej
886 1.2.2.2 thorpej case TIOCCDTR:
887 1.2.2.2 thorpej plcom_modem(sc, 0);
888 1.2.2.2 thorpej break;
889 1.2.2.2 thorpej
890 1.2.2.2 thorpej case TIOCGFLAGS:
891 1.2.2.2 thorpej *(int *)data = sc->sc_swflags;
892 1.2.2.2 thorpej break;
893 1.2.2.2 thorpej
894 1.2.2.2 thorpej case TIOCSFLAGS:
895 1.2.2.2 thorpej error = suser(p->p_ucred, &p->p_acflag);
896 1.2.2.2 thorpej if (error)
897 1.2.2.2 thorpej break;
898 1.2.2.2 thorpej sc->sc_swflags = *(int *)data;
899 1.2.2.2 thorpej break;
900 1.2.2.2 thorpej
901 1.2.2.2 thorpej case TIOCMSET:
902 1.2.2.2 thorpej case TIOCMBIS:
903 1.2.2.2 thorpej case TIOCMBIC:
904 1.2.2.2 thorpej tiocm_to_plcom(sc, cmd, *(int *)data);
905 1.2.2.2 thorpej break;
906 1.2.2.2 thorpej
907 1.2.2.2 thorpej case TIOCMGET:
908 1.2.2.2 thorpej *(int *)data = plcom_to_tiocm(sc);
909 1.2.2.2 thorpej break;
910 1.2.2.2 thorpej
911 1.2.2.2 thorpej case PPS_IOC_CREATE:
912 1.2.2.2 thorpej break;
913 1.2.2.2 thorpej
914 1.2.2.2 thorpej case PPS_IOC_DESTROY:
915 1.2.2.2 thorpej break;
916 1.2.2.2 thorpej
917 1.2.2.2 thorpej case PPS_IOC_GETPARAMS: {
918 1.2.2.2 thorpej pps_params_t *pp;
919 1.2.2.2 thorpej pp = (pps_params_t *)data;
920 1.2.2.2 thorpej *pp = sc->ppsparam;
921 1.2.2.2 thorpej break;
922 1.2.2.2 thorpej }
923 1.2.2.2 thorpej
924 1.2.2.2 thorpej case PPS_IOC_SETPARAMS: {
925 1.2.2.2 thorpej pps_params_t *pp;
926 1.2.2.2 thorpej int mode;
927 1.2.2.2 thorpej pp = (pps_params_t *)data;
928 1.2.2.2 thorpej if (pp->mode & ~ppscap) {
929 1.2.2.2 thorpej error = EINVAL;
930 1.2.2.2 thorpej break;
931 1.2.2.2 thorpej }
932 1.2.2.2 thorpej sc->ppsparam = *pp;
933 1.2.2.2 thorpej /*
934 1.2.2.2 thorpej * Compute msr masks from user-specified timestamp state.
935 1.2.2.2 thorpej */
936 1.2.2.2 thorpej mode = sc->ppsparam.mode;
937 1.2.2.2 thorpej #ifdef PPS_SYNC
938 1.2.2.2 thorpej if (mode & PPS_HARDPPSONASSERT) {
939 1.2.2.2 thorpej mode |= PPS_CAPTUREASSERT;
940 1.2.2.2 thorpej /* XXX revoke any previous HARDPPS source */
941 1.2.2.2 thorpej }
942 1.2.2.2 thorpej if (mode & PPS_HARDPPSONCLEAR) {
943 1.2.2.2 thorpej mode |= PPS_CAPTURECLEAR;
944 1.2.2.2 thorpej /* XXX revoke any previous HARDPPS source */
945 1.2.2.2 thorpej }
946 1.2.2.2 thorpej #endif /* PPS_SYNC */
947 1.2.2.2 thorpej switch (mode & PPS_CAPTUREBOTH) {
948 1.2.2.2 thorpej case 0:
949 1.2.2.2 thorpej sc->sc_ppsmask = 0;
950 1.2.2.2 thorpej break;
951 1.2.2.2 thorpej
952 1.2.2.2 thorpej case PPS_CAPTUREASSERT:
953 1.2.2.2 thorpej sc->sc_ppsmask = MSR_DCD;
954 1.2.2.2 thorpej sc->sc_ppsassert = MSR_DCD;
955 1.2.2.2 thorpej sc->sc_ppsclear = -1;
956 1.2.2.2 thorpej break;
957 1.2.2.2 thorpej
958 1.2.2.2 thorpej case PPS_CAPTURECLEAR:
959 1.2.2.2 thorpej sc->sc_ppsmask = MSR_DCD;
960 1.2.2.2 thorpej sc->sc_ppsassert = -1;
961 1.2.2.2 thorpej sc->sc_ppsclear = 0;
962 1.2.2.2 thorpej break;
963 1.2.2.2 thorpej
964 1.2.2.2 thorpej case PPS_CAPTUREBOTH:
965 1.2.2.2 thorpej sc->sc_ppsmask = MSR_DCD;
966 1.2.2.2 thorpej sc->sc_ppsassert = MSR_DCD;
967 1.2.2.2 thorpej sc->sc_ppsclear = 0;
968 1.2.2.2 thorpej break;
969 1.2.2.2 thorpej
970 1.2.2.2 thorpej default:
971 1.2.2.2 thorpej error = EINVAL;
972 1.2.2.2 thorpej break;
973 1.2.2.2 thorpej }
974 1.2.2.2 thorpej break;
975 1.2.2.2 thorpej }
976 1.2.2.2 thorpej
977 1.2.2.2 thorpej case PPS_IOC_GETCAP:
978 1.2.2.2 thorpej *(int*)data = ppscap;
979 1.2.2.2 thorpej break;
980 1.2.2.2 thorpej
981 1.2.2.2 thorpej case PPS_IOC_FETCH: {
982 1.2.2.2 thorpej pps_info_t *pi;
983 1.2.2.2 thorpej pi = (pps_info_t *)data;
984 1.2.2.2 thorpej *pi = sc->ppsinfo;
985 1.2.2.2 thorpej break;
986 1.2.2.2 thorpej }
987 1.2.2.2 thorpej
988 1.2.2.2 thorpej case TIOCDCDTIMESTAMP: /* XXX old, overloaded API used by xntpd v3 */
989 1.2.2.2 thorpej /*
990 1.2.2.2 thorpej * Some GPS clocks models use the falling rather than
991 1.2.2.2 thorpej * rising edge as the on-the-second signal.
992 1.2.2.2 thorpej * The old API has no way to specify PPS polarity.
993 1.2.2.2 thorpej */
994 1.2.2.2 thorpej sc->sc_ppsmask = MSR_DCD;
995 1.2.2.2 thorpej #ifndef PPS_TRAILING_EDGE
996 1.2.2.2 thorpej sc->sc_ppsassert = MSR_DCD;
997 1.2.2.2 thorpej sc->sc_ppsclear = -1;
998 1.2.2.2 thorpej TIMESPEC_TO_TIMEVAL((struct timeval *)data,
999 1.2.2.2 thorpej &sc->ppsinfo.assert_timestamp);
1000 1.2.2.2 thorpej #else
1001 1.2.2.2 thorpej sc->sc_ppsassert = -1
1002 1.2.2.2 thorpej sc->sc_ppsclear = 0;
1003 1.2.2.2 thorpej TIMESPEC_TO_TIMEVAL((struct timeval *)data,
1004 1.2.2.2 thorpej &sc->ppsinfo.clear_timestamp);
1005 1.2.2.2 thorpej #endif
1006 1.2.2.2 thorpej break;
1007 1.2.2.2 thorpej
1008 1.2.2.2 thorpej default:
1009 1.2.2.3 jdolecek error = EPASSTHROUGH;
1010 1.2.2.2 thorpej break;
1011 1.2.2.2 thorpej }
1012 1.2.2.2 thorpej
1013 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1014 1.2.2.2 thorpej splx(s);
1015 1.2.2.2 thorpej
1016 1.2.2.2 thorpej #ifdef PLCOM_DEBUG
1017 1.2.2.2 thorpej if (plcom_debug)
1018 1.2.2.2 thorpej plcomstatus(sc, "plcomioctl ");
1019 1.2.2.2 thorpej #endif
1020 1.2.2.2 thorpej
1021 1.2.2.2 thorpej return error;
1022 1.2.2.2 thorpej }
1023 1.2.2.2 thorpej
1024 1.2.2.2 thorpej integrate void
1025 1.2.2.2 thorpej plcom_schedrx(struct plcom_softc *sc)
1026 1.2.2.2 thorpej {
1027 1.2.2.2 thorpej
1028 1.2.2.2 thorpej sc->sc_rx_ready = 1;
1029 1.2.2.2 thorpej
1030 1.2.2.2 thorpej /* Wake up the poller. */
1031 1.2.2.2 thorpej #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
1032 1.2.2.2 thorpej softintr_schedule(sc->sc_si);
1033 1.2.2.2 thorpej #else
1034 1.2.2.2 thorpej #ifndef __NO_SOFT_SERIAL_INTERRUPT
1035 1.2.2.2 thorpej setsoftserial();
1036 1.2.2.2 thorpej #else
1037 1.2.2.2 thorpej if (!plcom_softintr_scheduled) {
1038 1.2.2.2 thorpej plcom_softintr_scheduled = 1;
1039 1.2.2.2 thorpej callout_reset(&plcomsoft_callout, 1, plcomsoft, NULL);
1040 1.2.2.2 thorpej }
1041 1.2.2.2 thorpej #endif
1042 1.2.2.2 thorpej #endif
1043 1.2.2.2 thorpej }
1044 1.2.2.2 thorpej
1045 1.2.2.2 thorpej void
1046 1.2.2.2 thorpej plcom_break(struct plcom_softc *sc, int onoff)
1047 1.2.2.2 thorpej {
1048 1.2.2.2 thorpej
1049 1.2.2.2 thorpej if (onoff)
1050 1.2.2.2 thorpej SET(sc->sc_lcr, LCR_BRK);
1051 1.2.2.2 thorpej else
1052 1.2.2.2 thorpej CLR(sc->sc_lcr, LCR_BRK);
1053 1.2.2.2 thorpej
1054 1.2.2.2 thorpej if (!sc->sc_heldchange) {
1055 1.2.2.2 thorpej if (sc->sc_tx_busy) {
1056 1.2.2.2 thorpej sc->sc_heldtbc = sc->sc_tbc;
1057 1.2.2.2 thorpej sc->sc_tbc = 0;
1058 1.2.2.2 thorpej sc->sc_heldchange = 1;
1059 1.2.2.2 thorpej } else
1060 1.2.2.2 thorpej plcom_loadchannelregs(sc);
1061 1.2.2.2 thorpej }
1062 1.2.2.2 thorpej }
1063 1.2.2.2 thorpej
1064 1.2.2.2 thorpej void
1065 1.2.2.2 thorpej plcom_modem(struct plcom_softc *sc, int onoff)
1066 1.2.2.2 thorpej {
1067 1.2.2.2 thorpej
1068 1.2.2.2 thorpej if (sc->sc_mcr_dtr == 0)
1069 1.2.2.2 thorpej return;
1070 1.2.2.2 thorpej
1071 1.2.2.2 thorpej if (onoff)
1072 1.2.2.2 thorpej SET(sc->sc_mcr, sc->sc_mcr_dtr);
1073 1.2.2.2 thorpej else
1074 1.2.2.2 thorpej CLR(sc->sc_mcr, sc->sc_mcr_dtr);
1075 1.2.2.2 thorpej
1076 1.2.2.2 thorpej if (!sc->sc_heldchange) {
1077 1.2.2.2 thorpej if (sc->sc_tx_busy) {
1078 1.2.2.2 thorpej sc->sc_heldtbc = sc->sc_tbc;
1079 1.2.2.2 thorpej sc->sc_tbc = 0;
1080 1.2.2.2 thorpej sc->sc_heldchange = 1;
1081 1.2.2.2 thorpej } else
1082 1.2.2.2 thorpej plcom_loadchannelregs(sc);
1083 1.2.2.2 thorpej }
1084 1.2.2.2 thorpej }
1085 1.2.2.2 thorpej
1086 1.2.2.2 thorpej void
1087 1.2.2.2 thorpej tiocm_to_plcom(struct plcom_softc *sc, u_long how, int ttybits)
1088 1.2.2.2 thorpej {
1089 1.2.2.2 thorpej u_char plcombits;
1090 1.2.2.2 thorpej
1091 1.2.2.2 thorpej plcombits = 0;
1092 1.2.2.2 thorpej if (ISSET(ttybits, TIOCM_DTR))
1093 1.2.2.2 thorpej SET(plcombits, MCR_DTR);
1094 1.2.2.2 thorpej if (ISSET(ttybits, TIOCM_RTS))
1095 1.2.2.2 thorpej SET(plcombits, MCR_RTS);
1096 1.2.2.2 thorpej
1097 1.2.2.2 thorpej switch (how) {
1098 1.2.2.2 thorpej case TIOCMBIC:
1099 1.2.2.2 thorpej CLR(sc->sc_mcr, plcombits);
1100 1.2.2.2 thorpej break;
1101 1.2.2.2 thorpej
1102 1.2.2.2 thorpej case TIOCMBIS:
1103 1.2.2.2 thorpej SET(sc->sc_mcr, plcombits);
1104 1.2.2.2 thorpej break;
1105 1.2.2.2 thorpej
1106 1.2.2.2 thorpej case TIOCMSET:
1107 1.2.2.2 thorpej CLR(sc->sc_mcr, MCR_DTR | MCR_RTS);
1108 1.2.2.2 thorpej SET(sc->sc_mcr, plcombits);
1109 1.2.2.2 thorpej break;
1110 1.2.2.2 thorpej }
1111 1.2.2.2 thorpej
1112 1.2.2.2 thorpej if (!sc->sc_heldchange) {
1113 1.2.2.2 thorpej if (sc->sc_tx_busy) {
1114 1.2.2.2 thorpej sc->sc_heldtbc = sc->sc_tbc;
1115 1.2.2.2 thorpej sc->sc_tbc = 0;
1116 1.2.2.2 thorpej sc->sc_heldchange = 1;
1117 1.2.2.2 thorpej } else
1118 1.2.2.2 thorpej plcom_loadchannelregs(sc);
1119 1.2.2.2 thorpej }
1120 1.2.2.2 thorpej }
1121 1.2.2.2 thorpej
1122 1.2.2.2 thorpej int
1123 1.2.2.2 thorpej plcom_to_tiocm(struct plcom_softc *sc)
1124 1.2.2.2 thorpej {
1125 1.2.2.2 thorpej u_char plcombits;
1126 1.2.2.2 thorpej int ttybits = 0;
1127 1.2.2.2 thorpej
1128 1.2.2.2 thorpej plcombits = sc->sc_mcr;
1129 1.2.2.2 thorpej if (ISSET(plcombits, MCR_DTR))
1130 1.2.2.2 thorpej SET(ttybits, TIOCM_DTR);
1131 1.2.2.2 thorpej if (ISSET(plcombits, MCR_RTS))
1132 1.2.2.2 thorpej SET(ttybits, TIOCM_RTS);
1133 1.2.2.2 thorpej
1134 1.2.2.2 thorpej plcombits = sc->sc_msr;
1135 1.2.2.2 thorpej if (ISSET(plcombits, MSR_DCD))
1136 1.2.2.2 thorpej SET(ttybits, TIOCM_CD);
1137 1.2.2.2 thorpej if (ISSET(plcombits, MSR_CTS))
1138 1.2.2.2 thorpej SET(ttybits, TIOCM_CTS);
1139 1.2.2.2 thorpej if (ISSET(plcombits, MSR_DSR))
1140 1.2.2.2 thorpej SET(ttybits, TIOCM_DSR);
1141 1.2.2.2 thorpej
1142 1.2.2.2 thorpej if (sc->sc_cr != 0)
1143 1.2.2.2 thorpej SET(ttybits, TIOCM_LE);
1144 1.2.2.2 thorpej
1145 1.2.2.2 thorpej return ttybits;
1146 1.2.2.2 thorpej }
1147 1.2.2.2 thorpej
1148 1.2.2.2 thorpej static u_char
1149 1.2.2.2 thorpej cflag2lcr(tcflag_t cflag)
1150 1.2.2.2 thorpej {
1151 1.2.2.2 thorpej u_char lcr = 0;
1152 1.2.2.2 thorpej
1153 1.2.2.2 thorpej switch (ISSET(cflag, CSIZE)) {
1154 1.2.2.2 thorpej case CS5:
1155 1.2.2.2 thorpej SET(lcr, LCR_5BITS);
1156 1.2.2.2 thorpej break;
1157 1.2.2.2 thorpej case CS6:
1158 1.2.2.2 thorpej SET(lcr, LCR_6BITS);
1159 1.2.2.2 thorpej break;
1160 1.2.2.2 thorpej case CS7:
1161 1.2.2.2 thorpej SET(lcr, LCR_7BITS);
1162 1.2.2.2 thorpej break;
1163 1.2.2.2 thorpej case CS8:
1164 1.2.2.2 thorpej SET(lcr, LCR_8BITS);
1165 1.2.2.2 thorpej break;
1166 1.2.2.2 thorpej }
1167 1.2.2.2 thorpej if (ISSET(cflag, PARENB)) {
1168 1.2.2.2 thorpej SET(lcr, LCR_PEN);
1169 1.2.2.2 thorpej if (!ISSET(cflag, PARODD))
1170 1.2.2.2 thorpej SET(lcr, LCR_EPS);
1171 1.2.2.2 thorpej }
1172 1.2.2.2 thorpej if (ISSET(cflag, CSTOPB))
1173 1.2.2.2 thorpej SET(lcr, LCR_STP2);
1174 1.2.2.2 thorpej
1175 1.2.2.2 thorpej return lcr;
1176 1.2.2.2 thorpej }
1177 1.2.2.2 thorpej
1178 1.2.2.2 thorpej int
1179 1.2.2.2 thorpej plcomparam(struct tty *tp, struct termios *t)
1180 1.2.2.2 thorpej {
1181 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(tp->t_dev));
1182 1.2.2.2 thorpej int ospeed;
1183 1.2.2.2 thorpej u_char lcr;
1184 1.2.2.2 thorpej int s;
1185 1.2.2.2 thorpej
1186 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
1187 1.2.2.2 thorpej return EIO;
1188 1.2.2.2 thorpej
1189 1.2.2.2 thorpej ospeed = plcomspeed(t->c_ospeed, sc->sc_frequency);
1190 1.2.2.2 thorpej
1191 1.2.2.2 thorpej /* Check requested parameters. */
1192 1.2.2.2 thorpej if (ospeed < 0)
1193 1.2.2.2 thorpej return EINVAL;
1194 1.2.2.2 thorpej if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
1195 1.2.2.2 thorpej return EINVAL;
1196 1.2.2.2 thorpej
1197 1.2.2.2 thorpej /*
1198 1.2.2.2 thorpej * For the console, always force CLOCAL and !HUPCL, so that the port
1199 1.2.2.2 thorpej * is always active.
1200 1.2.2.2 thorpej */
1201 1.2.2.2 thorpej if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
1202 1.2.2.2 thorpej ISSET(sc->sc_hwflags, PLCOM_HW_CONSOLE)) {
1203 1.2.2.2 thorpej SET(t->c_cflag, CLOCAL);
1204 1.2.2.2 thorpej CLR(t->c_cflag, HUPCL);
1205 1.2.2.2 thorpej }
1206 1.2.2.2 thorpej
1207 1.2.2.2 thorpej /*
1208 1.2.2.2 thorpej * If there were no changes, don't do anything. This avoids dropping
1209 1.2.2.2 thorpej * input and improves performance when all we did was frob things like
1210 1.2.2.2 thorpej * VMIN and VTIME.
1211 1.2.2.2 thorpej */
1212 1.2.2.2 thorpej if (tp->t_ospeed == t->c_ospeed &&
1213 1.2.2.2 thorpej tp->t_cflag == t->c_cflag)
1214 1.2.2.2 thorpej return 0;
1215 1.2.2.2 thorpej
1216 1.2.2.2 thorpej lcr = ISSET(sc->sc_lcr, LCR_BRK) | cflag2lcr(t->c_cflag);
1217 1.2.2.2 thorpej
1218 1.2.2.2 thorpej s = splserial();
1219 1.2.2.2 thorpej PLCOM_LOCK(sc);
1220 1.2.2.2 thorpej
1221 1.2.2.2 thorpej sc->sc_lcr = lcr;
1222 1.2.2.2 thorpej
1223 1.2.2.2 thorpej /*
1224 1.2.2.2 thorpej * PL010 has a fixed-length FIFO trigger point.
1225 1.2.2.2 thorpej */
1226 1.2.2.2 thorpej if (ISSET(sc->sc_hwflags, PLCOM_HW_FIFO))
1227 1.2.2.2 thorpej sc->sc_fifo = 1;
1228 1.2.2.2 thorpej else
1229 1.2.2.2 thorpej sc->sc_fifo = 0;
1230 1.2.2.2 thorpej
1231 1.2.2.2 thorpej if (sc->sc_fifo)
1232 1.2.2.2 thorpej SET(sc->sc_lcr, LCR_FEN);
1233 1.2.2.2 thorpej
1234 1.2.2.2 thorpej /*
1235 1.2.2.2 thorpej * If we're not in a mode that assumes a connection is present, then
1236 1.2.2.2 thorpej * ignore carrier changes.
1237 1.2.2.2 thorpej */
1238 1.2.2.2 thorpej if (ISSET(t->c_cflag, CLOCAL | MDMBUF))
1239 1.2.2.2 thorpej sc->sc_msr_dcd = 0;
1240 1.2.2.2 thorpej else
1241 1.2.2.2 thorpej sc->sc_msr_dcd = MSR_DCD;
1242 1.2.2.2 thorpej /*
1243 1.2.2.2 thorpej * Set the flow control pins depending on the current flow control
1244 1.2.2.2 thorpej * mode.
1245 1.2.2.2 thorpej */
1246 1.2.2.2 thorpej if (ISSET(t->c_cflag, CRTSCTS)) {
1247 1.2.2.2 thorpej sc->sc_mcr_dtr = MCR_DTR;
1248 1.2.2.2 thorpej sc->sc_mcr_rts = MCR_RTS;
1249 1.2.2.2 thorpej sc->sc_msr_cts = MSR_CTS;
1250 1.2.2.2 thorpej } else if (ISSET(t->c_cflag, MDMBUF)) {
1251 1.2.2.2 thorpej /*
1252 1.2.2.2 thorpej * For DTR/DCD flow control, make sure we don't toggle DTR for
1253 1.2.2.2 thorpej * carrier detection.
1254 1.2.2.2 thorpej */
1255 1.2.2.2 thorpej sc->sc_mcr_dtr = 0;
1256 1.2.2.2 thorpej sc->sc_mcr_rts = MCR_DTR;
1257 1.2.2.2 thorpej sc->sc_msr_cts = MSR_DCD;
1258 1.2.2.2 thorpej } else {
1259 1.2.2.2 thorpej /*
1260 1.2.2.2 thorpej * If no flow control, then always set RTS. This will make
1261 1.2.2.2 thorpej * the other side happy if it mistakenly thinks we're doing
1262 1.2.2.2 thorpej * RTS/CTS flow control.
1263 1.2.2.2 thorpej */
1264 1.2.2.2 thorpej sc->sc_mcr_dtr = MCR_DTR | MCR_RTS;
1265 1.2.2.2 thorpej sc->sc_mcr_rts = 0;
1266 1.2.2.2 thorpej sc->sc_msr_cts = 0;
1267 1.2.2.2 thorpej if (ISSET(sc->sc_mcr, MCR_DTR))
1268 1.2.2.2 thorpej SET(sc->sc_mcr, MCR_RTS);
1269 1.2.2.2 thorpej else
1270 1.2.2.2 thorpej CLR(sc->sc_mcr, MCR_RTS);
1271 1.2.2.2 thorpej }
1272 1.2.2.2 thorpej sc->sc_msr_mask = sc->sc_msr_cts | sc->sc_msr_dcd;
1273 1.2.2.2 thorpej
1274 1.2.2.2 thorpej #if 0
1275 1.2.2.2 thorpej if (ospeed == 0)
1276 1.2.2.2 thorpej CLR(sc->sc_mcr, sc->sc_mcr_dtr);
1277 1.2.2.2 thorpej else
1278 1.2.2.2 thorpej SET(sc->sc_mcr, sc->sc_mcr_dtr);
1279 1.2.2.2 thorpej #endif
1280 1.2.2.2 thorpej
1281 1.2.2.2 thorpej sc->sc_dlbl = ospeed;
1282 1.2.2.2 thorpej sc->sc_dlbh = ospeed >> 8;
1283 1.2.2.2 thorpej
1284 1.2.2.2 thorpej /* And copy to tty. */
1285 1.2.2.2 thorpej tp->t_ispeed = 0;
1286 1.2.2.2 thorpej tp->t_ospeed = t->c_ospeed;
1287 1.2.2.2 thorpej tp->t_cflag = t->c_cflag;
1288 1.2.2.2 thorpej
1289 1.2.2.2 thorpej if (!sc->sc_heldchange) {
1290 1.2.2.2 thorpej if (sc->sc_tx_busy) {
1291 1.2.2.2 thorpej sc->sc_heldtbc = sc->sc_tbc;
1292 1.2.2.2 thorpej sc->sc_tbc = 0;
1293 1.2.2.2 thorpej sc->sc_heldchange = 1;
1294 1.2.2.2 thorpej } else
1295 1.2.2.2 thorpej plcom_loadchannelregs(sc);
1296 1.2.2.2 thorpej }
1297 1.2.2.2 thorpej
1298 1.2.2.2 thorpej if (!ISSET(t->c_cflag, CHWFLOW)) {
1299 1.2.2.2 thorpej /* Disable the high water mark. */
1300 1.2.2.2 thorpej sc->sc_r_hiwat = 0;
1301 1.2.2.2 thorpej sc->sc_r_lowat = 0;
1302 1.2.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
1303 1.2.2.2 thorpej CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1304 1.2.2.2 thorpej plcom_schedrx(sc);
1305 1.2.2.2 thorpej }
1306 1.2.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED)) {
1307 1.2.2.2 thorpej CLR(sc->sc_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED);
1308 1.2.2.2 thorpej plcom_hwiflow(sc);
1309 1.2.2.2 thorpej }
1310 1.2.2.2 thorpej } else {
1311 1.2.2.2 thorpej sc->sc_r_hiwat = plcom_rbuf_hiwat;
1312 1.2.2.2 thorpej sc->sc_r_lowat = plcom_rbuf_lowat;
1313 1.2.2.2 thorpej }
1314 1.2.2.2 thorpej
1315 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1316 1.2.2.2 thorpej splx(s);
1317 1.2.2.2 thorpej
1318 1.2.2.2 thorpej /*
1319 1.2.2.2 thorpej * Update the tty layer's idea of the carrier bit, in case we changed
1320 1.2.2.2 thorpej * CLOCAL or MDMBUF. We don't hang up here; we only do that by
1321 1.2.2.2 thorpej * explicit request.
1322 1.2.2.2 thorpej */
1323 1.2.2.2 thorpej (void) (*tp->t_linesw->l_modem)(tp, ISSET(sc->sc_msr, MSR_DCD));
1324 1.2.2.2 thorpej
1325 1.2.2.2 thorpej #ifdef PLCOM_DEBUG
1326 1.2.2.2 thorpej if (plcom_debug)
1327 1.2.2.2 thorpej plcomstatus(sc, "plcomparam ");
1328 1.2.2.2 thorpej #endif
1329 1.2.2.2 thorpej
1330 1.2.2.2 thorpej if (!ISSET(t->c_cflag, CHWFLOW)) {
1331 1.2.2.2 thorpej if (sc->sc_tx_stopped) {
1332 1.2.2.2 thorpej sc->sc_tx_stopped = 0;
1333 1.2.2.2 thorpej plcomstart(tp);
1334 1.2.2.2 thorpej }
1335 1.2.2.2 thorpej }
1336 1.2.2.2 thorpej
1337 1.2.2.2 thorpej return 0;
1338 1.2.2.2 thorpej }
1339 1.2.2.2 thorpej
1340 1.2.2.2 thorpej void
1341 1.2.2.2 thorpej plcom_iflush(struct plcom_softc *sc)
1342 1.2.2.2 thorpej {
1343 1.2.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1344 1.2.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1345 1.2.2.2 thorpej #ifdef DIAGNOSTIC
1346 1.2.2.2 thorpej int reg;
1347 1.2.2.2 thorpej #endif
1348 1.2.2.2 thorpej int timo;
1349 1.2.2.2 thorpej
1350 1.2.2.2 thorpej #ifdef DIAGNOSTIC
1351 1.2.2.2 thorpej reg = 0xffff;
1352 1.2.2.2 thorpej #endif
1353 1.2.2.2 thorpej timo = 50000;
1354 1.2.2.2 thorpej /* flush any pending I/O */
1355 1.2.2.2 thorpej while (! ISSET(bus_space_read_1(iot, ioh, plcom_fr), FR_RXFE)
1356 1.2.2.2 thorpej && --timo)
1357 1.2.2.2 thorpej #ifdef DIAGNOSTIC
1358 1.2.2.2 thorpej reg =
1359 1.2.2.2 thorpej #else
1360 1.2.2.2 thorpej (void)
1361 1.2.2.2 thorpej #endif
1362 1.2.2.2 thorpej bus_space_read_1(iot, ioh, plcom_dr);
1363 1.2.2.2 thorpej #ifdef DIAGNOSTIC
1364 1.2.2.2 thorpej if (!timo)
1365 1.2.2.2 thorpej printf("%s: plcom_iflush timeout %02x\n", sc->sc_dev.dv_xname,
1366 1.2.2.2 thorpej reg);
1367 1.2.2.2 thorpej #endif
1368 1.2.2.2 thorpej }
1369 1.2.2.2 thorpej
1370 1.2.2.2 thorpej void
1371 1.2.2.2 thorpej plcom_loadchannelregs(struct plcom_softc *sc)
1372 1.2.2.2 thorpej {
1373 1.2.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1374 1.2.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1375 1.2.2.2 thorpej
1376 1.2.2.2 thorpej /* XXXXX necessary? */
1377 1.2.2.2 thorpej plcom_iflush(sc);
1378 1.2.2.2 thorpej
1379 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, 0);
1380 1.2.2.2 thorpej
1381 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_dlbl, sc->sc_dlbl);
1382 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_dlbh, sc->sc_dlbh);
1383 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_lcr, sc->sc_lcr);
1384 1.2.2.2 thorpej sc->sc_set_mcr(sc->sc_set_mcr_arg, sc->sc_dev.dv_unit,
1385 1.2.2.2 thorpej sc->sc_mcr_active = sc->sc_mcr);
1386 1.2.2.2 thorpej
1387 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, sc->sc_cr);
1388 1.2.2.2 thorpej }
1389 1.2.2.2 thorpej
1390 1.2.2.2 thorpej int
1391 1.2.2.2 thorpej plcomhwiflow(struct tty *tp, int block)
1392 1.2.2.2 thorpej {
1393 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(tp->t_dev));
1394 1.2.2.2 thorpej int s;
1395 1.2.2.2 thorpej
1396 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
1397 1.2.2.2 thorpej return 0;
1398 1.2.2.2 thorpej
1399 1.2.2.2 thorpej if (sc->sc_mcr_rts == 0)
1400 1.2.2.2 thorpej return 0;
1401 1.2.2.2 thorpej
1402 1.2.2.2 thorpej s = splserial();
1403 1.2.2.2 thorpej PLCOM_LOCK(sc);
1404 1.2.2.2 thorpej
1405 1.2.2.2 thorpej if (block) {
1406 1.2.2.2 thorpej if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1407 1.2.2.2 thorpej SET(sc->sc_rx_flags, RX_TTY_BLOCKED);
1408 1.2.2.2 thorpej plcom_hwiflow(sc);
1409 1.2.2.2 thorpej }
1410 1.2.2.2 thorpej } else {
1411 1.2.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
1412 1.2.2.2 thorpej CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1413 1.2.2.2 thorpej plcom_schedrx(sc);
1414 1.2.2.2 thorpej }
1415 1.2.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1416 1.2.2.2 thorpej CLR(sc->sc_rx_flags, RX_TTY_BLOCKED);
1417 1.2.2.2 thorpej plcom_hwiflow(sc);
1418 1.2.2.2 thorpej }
1419 1.2.2.2 thorpej }
1420 1.2.2.2 thorpej
1421 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1422 1.2.2.2 thorpej splx(s);
1423 1.2.2.2 thorpej return 1;
1424 1.2.2.2 thorpej }
1425 1.2.2.2 thorpej
1426 1.2.2.2 thorpej /*
1427 1.2.2.2 thorpej * (un)block input via hw flowcontrol
1428 1.2.2.2 thorpej */
1429 1.2.2.2 thorpej void
1430 1.2.2.2 thorpej plcom_hwiflow(struct plcom_softc *sc)
1431 1.2.2.2 thorpej {
1432 1.2.2.2 thorpej if (sc->sc_mcr_rts == 0)
1433 1.2.2.2 thorpej return;
1434 1.2.2.2 thorpej
1435 1.2.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_ANY_BLOCK)) {
1436 1.2.2.2 thorpej CLR(sc->sc_mcr, sc->sc_mcr_rts);
1437 1.2.2.2 thorpej CLR(sc->sc_mcr_active, sc->sc_mcr_rts);
1438 1.2.2.2 thorpej } else {
1439 1.2.2.2 thorpej SET(sc->sc_mcr, sc->sc_mcr_rts);
1440 1.2.2.2 thorpej SET(sc->sc_mcr_active, sc->sc_mcr_rts);
1441 1.2.2.2 thorpej }
1442 1.2.2.2 thorpej sc->sc_set_mcr(sc->sc_set_mcr_arg, sc->sc_dev.dv_unit,
1443 1.2.2.2 thorpej sc->sc_mcr_active);
1444 1.2.2.2 thorpej }
1445 1.2.2.2 thorpej
1446 1.2.2.2 thorpej
1447 1.2.2.2 thorpej void
1448 1.2.2.2 thorpej plcomstart(struct tty *tp)
1449 1.2.2.2 thorpej {
1450 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(tp->t_dev));
1451 1.2.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1452 1.2.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1453 1.2.2.2 thorpej int s;
1454 1.2.2.2 thorpej
1455 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
1456 1.2.2.2 thorpej return;
1457 1.2.2.2 thorpej
1458 1.2.2.2 thorpej s = spltty();
1459 1.2.2.2 thorpej if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
1460 1.2.2.2 thorpej goto out;
1461 1.2.2.2 thorpej if (sc->sc_tx_stopped)
1462 1.2.2.2 thorpej goto out;
1463 1.2.2.2 thorpej
1464 1.2.2.2 thorpej if (tp->t_outq.c_cc <= tp->t_lowat) {
1465 1.2.2.2 thorpej if (ISSET(tp->t_state, TS_ASLEEP)) {
1466 1.2.2.2 thorpej CLR(tp->t_state, TS_ASLEEP);
1467 1.2.2.2 thorpej wakeup(&tp->t_outq);
1468 1.2.2.2 thorpej }
1469 1.2.2.2 thorpej selwakeup(&tp->t_wsel);
1470 1.2.2.2 thorpej if (tp->t_outq.c_cc == 0)
1471 1.2.2.2 thorpej goto out;
1472 1.2.2.2 thorpej }
1473 1.2.2.2 thorpej
1474 1.2.2.2 thorpej /* Grab the first contiguous region of buffer space. */
1475 1.2.2.2 thorpej {
1476 1.2.2.2 thorpej u_char *tba;
1477 1.2.2.2 thorpej int tbc;
1478 1.2.2.2 thorpej
1479 1.2.2.2 thorpej tba = tp->t_outq.c_cf;
1480 1.2.2.2 thorpej tbc = ndqb(&tp->t_outq, 0);
1481 1.2.2.2 thorpej
1482 1.2.2.2 thorpej (void)splserial();
1483 1.2.2.2 thorpej PLCOM_LOCK(sc);
1484 1.2.2.2 thorpej
1485 1.2.2.2 thorpej sc->sc_tba = tba;
1486 1.2.2.2 thorpej sc->sc_tbc = tbc;
1487 1.2.2.2 thorpej }
1488 1.2.2.2 thorpej
1489 1.2.2.2 thorpej SET(tp->t_state, TS_BUSY);
1490 1.2.2.2 thorpej sc->sc_tx_busy = 1;
1491 1.2.2.2 thorpej
1492 1.2.2.2 thorpej /* Enable transmit completion interrupts if necessary. */
1493 1.2.2.2 thorpej if (!ISSET(sc->sc_cr, CR_TIE)) {
1494 1.2.2.2 thorpej SET(sc->sc_cr, CR_TIE);
1495 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, sc->sc_cr);
1496 1.2.2.2 thorpej }
1497 1.2.2.2 thorpej
1498 1.2.2.2 thorpej /* Output the first chunk of the contiguous buffer. */
1499 1.2.2.2 thorpej {
1500 1.2.2.2 thorpej int n;
1501 1.2.2.2 thorpej
1502 1.2.2.2 thorpej n = sc->sc_tbc;
1503 1.2.2.2 thorpej if (n > sc->sc_fifolen)
1504 1.2.2.2 thorpej n = sc->sc_fifolen;
1505 1.2.2.2 thorpej bus_space_write_multi_1(iot, ioh, plcom_dr, sc->sc_tba, n);
1506 1.2.2.2 thorpej sc->sc_tbc -= n;
1507 1.2.2.2 thorpej sc->sc_tba += n;
1508 1.2.2.2 thorpej }
1509 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1510 1.2.2.2 thorpej out:
1511 1.2.2.2 thorpej splx(s);
1512 1.2.2.2 thorpej return;
1513 1.2.2.2 thorpej }
1514 1.2.2.2 thorpej
1515 1.2.2.2 thorpej /*
1516 1.2.2.2 thorpej * Stop output on a line.
1517 1.2.2.2 thorpej */
1518 1.2.2.2 thorpej void
1519 1.2.2.2 thorpej plcomstop(struct tty *tp, int flag)
1520 1.2.2.2 thorpej {
1521 1.2.2.2 thorpej struct plcom_softc *sc = device_lookup(&plcom_cd, PLCOMUNIT(tp->t_dev));
1522 1.2.2.2 thorpej int s;
1523 1.2.2.2 thorpej
1524 1.2.2.2 thorpej s = splserial();
1525 1.2.2.2 thorpej PLCOM_LOCK(sc);
1526 1.2.2.2 thorpej if (ISSET(tp->t_state, TS_BUSY)) {
1527 1.2.2.2 thorpej /* Stop transmitting at the next chunk. */
1528 1.2.2.2 thorpej sc->sc_tbc = 0;
1529 1.2.2.2 thorpej sc->sc_heldtbc = 0;
1530 1.2.2.2 thorpej if (!ISSET(tp->t_state, TS_TTSTOP))
1531 1.2.2.2 thorpej SET(tp->t_state, TS_FLUSH);
1532 1.2.2.2 thorpej }
1533 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1534 1.2.2.2 thorpej splx(s);
1535 1.2.2.2 thorpej }
1536 1.2.2.2 thorpej
1537 1.2.2.2 thorpej void
1538 1.2.2.2 thorpej plcomdiag(void *arg)
1539 1.2.2.2 thorpej {
1540 1.2.2.2 thorpej struct plcom_softc *sc = arg;
1541 1.2.2.2 thorpej int overflows, floods;
1542 1.2.2.2 thorpej int s;
1543 1.2.2.2 thorpej
1544 1.2.2.2 thorpej s = splserial();
1545 1.2.2.2 thorpej PLCOM_LOCK(sc);
1546 1.2.2.2 thorpej overflows = sc->sc_overflows;
1547 1.2.2.2 thorpej sc->sc_overflows = 0;
1548 1.2.2.2 thorpej floods = sc->sc_floods;
1549 1.2.2.2 thorpej sc->sc_floods = 0;
1550 1.2.2.2 thorpej sc->sc_errors = 0;
1551 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1552 1.2.2.2 thorpej splx(s);
1553 1.2.2.2 thorpej
1554 1.2.2.2 thorpej log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf flood%s\n",
1555 1.2.2.2 thorpej sc->sc_dev.dv_xname,
1556 1.2.2.2 thorpej overflows, overflows == 1 ? "" : "s",
1557 1.2.2.2 thorpej floods, floods == 1 ? "" : "s");
1558 1.2.2.2 thorpej }
1559 1.2.2.2 thorpej
1560 1.2.2.2 thorpej integrate void
1561 1.2.2.2 thorpej plcom_rxsoft(struct plcom_softc *sc, struct tty *tp)
1562 1.2.2.2 thorpej {
1563 1.2.2.2 thorpej int (*rint) (int, struct tty *) = tp->t_linesw->l_rint;
1564 1.2.2.2 thorpej u_char *get, *end;
1565 1.2.2.2 thorpej u_int cc, scc;
1566 1.2.2.2 thorpej u_char rsr;
1567 1.2.2.2 thorpej int code;
1568 1.2.2.2 thorpej int s;
1569 1.2.2.2 thorpej
1570 1.2.2.2 thorpej end = sc->sc_ebuf;
1571 1.2.2.2 thorpej get = sc->sc_rbget;
1572 1.2.2.2 thorpej scc = cc = plcom_rbuf_size - sc->sc_rbavail;
1573 1.2.2.2 thorpej
1574 1.2.2.2 thorpej if (cc == plcom_rbuf_size) {
1575 1.2.2.2 thorpej sc->sc_floods++;
1576 1.2.2.2 thorpej if (sc->sc_errors++ == 0)
1577 1.2.2.2 thorpej callout_reset(&sc->sc_diag_callout, 60 * hz,
1578 1.2.2.2 thorpej plcomdiag, sc);
1579 1.2.2.2 thorpej }
1580 1.2.2.2 thorpej
1581 1.2.2.2 thorpej while (cc) {
1582 1.2.2.2 thorpej code = get[0];
1583 1.2.2.2 thorpej rsr = get[1];
1584 1.2.2.2 thorpej if (ISSET(rsr, RSR_OE | RSR_BE | RSR_FE | RSR_PE)) {
1585 1.2.2.2 thorpej if (ISSET(rsr, RSR_OE)) {
1586 1.2.2.2 thorpej sc->sc_overflows++;
1587 1.2.2.2 thorpej if (sc->sc_errors++ == 0)
1588 1.2.2.2 thorpej callout_reset(&sc->sc_diag_callout,
1589 1.2.2.2 thorpej 60 * hz, plcomdiag, sc);
1590 1.2.2.2 thorpej }
1591 1.2.2.2 thorpej if (ISSET(rsr, RSR_BE | RSR_FE))
1592 1.2.2.2 thorpej SET(code, TTY_FE);
1593 1.2.2.2 thorpej if (ISSET(rsr, RSR_PE))
1594 1.2.2.2 thorpej SET(code, TTY_PE);
1595 1.2.2.2 thorpej }
1596 1.2.2.2 thorpej if ((*rint)(code, tp) == -1) {
1597 1.2.2.2 thorpej /*
1598 1.2.2.2 thorpej * The line discipline's buffer is out of space.
1599 1.2.2.2 thorpej */
1600 1.2.2.2 thorpej if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1601 1.2.2.2 thorpej /*
1602 1.2.2.2 thorpej * We're either not using flow control, or the
1603 1.2.2.2 thorpej * line discipline didn't tell us to block for
1604 1.2.2.2 thorpej * some reason. Either way, we have no way to
1605 1.2.2.2 thorpej * know when there's more space available, so
1606 1.2.2.2 thorpej * just drop the rest of the data.
1607 1.2.2.2 thorpej */
1608 1.2.2.2 thorpej get += cc << 1;
1609 1.2.2.2 thorpej if (get >= end)
1610 1.2.2.2 thorpej get -= plcom_rbuf_size << 1;
1611 1.2.2.2 thorpej cc = 0;
1612 1.2.2.2 thorpej } else {
1613 1.2.2.2 thorpej /*
1614 1.2.2.2 thorpej * Don't schedule any more receive processing
1615 1.2.2.2 thorpej * until the line discipline tells us there's
1616 1.2.2.2 thorpej * space available (through plcomhwiflow()).
1617 1.2.2.2 thorpej * Leave the rest of the data in the input
1618 1.2.2.2 thorpej * buffer.
1619 1.2.2.2 thorpej */
1620 1.2.2.2 thorpej SET(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1621 1.2.2.2 thorpej }
1622 1.2.2.2 thorpej break;
1623 1.2.2.2 thorpej }
1624 1.2.2.2 thorpej get += 2;
1625 1.2.2.2 thorpej if (get >= end)
1626 1.2.2.2 thorpej get = sc->sc_rbuf;
1627 1.2.2.2 thorpej cc--;
1628 1.2.2.2 thorpej }
1629 1.2.2.2 thorpej
1630 1.2.2.2 thorpej if (cc != scc) {
1631 1.2.2.2 thorpej sc->sc_rbget = get;
1632 1.2.2.2 thorpej s = splserial();
1633 1.2.2.2 thorpej PLCOM_LOCK(sc);
1634 1.2.2.2 thorpej
1635 1.2.2.2 thorpej cc = sc->sc_rbavail += scc - cc;
1636 1.2.2.2 thorpej /* Buffers should be ok again, release possible block. */
1637 1.2.2.2 thorpej if (cc >= sc->sc_r_lowat) {
1638 1.2.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1639 1.2.2.2 thorpej CLR(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1640 1.2.2.2 thorpej SET(sc->sc_cr, CR_RIE | CR_RTIE);
1641 1.2.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, plcom_cr, sc->sc_cr);
1642 1.2.2.2 thorpej }
1643 1.2.2.2 thorpej if (ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED)) {
1644 1.2.2.2 thorpej CLR(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1645 1.2.2.2 thorpej plcom_hwiflow(sc);
1646 1.2.2.2 thorpej }
1647 1.2.2.2 thorpej }
1648 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1649 1.2.2.2 thorpej splx(s);
1650 1.2.2.2 thorpej }
1651 1.2.2.2 thorpej }
1652 1.2.2.2 thorpej
1653 1.2.2.2 thorpej integrate void
1654 1.2.2.2 thorpej plcom_txsoft(struct plcom_softc *sc, struct tty *tp)
1655 1.2.2.2 thorpej {
1656 1.2.2.2 thorpej
1657 1.2.2.2 thorpej CLR(tp->t_state, TS_BUSY);
1658 1.2.2.2 thorpej if (ISSET(tp->t_state, TS_FLUSH))
1659 1.2.2.2 thorpej CLR(tp->t_state, TS_FLUSH);
1660 1.2.2.2 thorpej else
1661 1.2.2.2 thorpej ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
1662 1.2.2.2 thorpej (*tp->t_linesw->l_start)(tp);
1663 1.2.2.2 thorpej }
1664 1.2.2.2 thorpej
1665 1.2.2.2 thorpej integrate void
1666 1.2.2.2 thorpej plcom_stsoft(struct plcom_softc *sc, struct tty *tp)
1667 1.2.2.2 thorpej {
1668 1.2.2.2 thorpej u_char msr, delta;
1669 1.2.2.2 thorpej int s;
1670 1.2.2.2 thorpej
1671 1.2.2.2 thorpej s = splserial();
1672 1.2.2.2 thorpej PLCOM_LOCK(sc);
1673 1.2.2.2 thorpej msr = sc->sc_msr;
1674 1.2.2.2 thorpej delta = sc->sc_msr_delta;
1675 1.2.2.2 thorpej sc->sc_msr_delta = 0;
1676 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1677 1.2.2.2 thorpej splx(s);
1678 1.2.2.2 thorpej
1679 1.2.2.2 thorpej if (ISSET(delta, sc->sc_msr_dcd)) {
1680 1.2.2.2 thorpej /*
1681 1.2.2.2 thorpej * Inform the tty layer that carrier detect changed.
1682 1.2.2.2 thorpej */
1683 1.2.2.2 thorpej (void) (*tp->t_linesw->l_modem)(tp, ISSET(msr, MSR_DCD));
1684 1.2.2.2 thorpej }
1685 1.2.2.2 thorpej
1686 1.2.2.2 thorpej if (ISSET(delta, sc->sc_msr_cts)) {
1687 1.2.2.2 thorpej /* Block or unblock output according to flow control. */
1688 1.2.2.2 thorpej if (ISSET(msr, sc->sc_msr_cts)) {
1689 1.2.2.2 thorpej sc->sc_tx_stopped = 0;
1690 1.2.2.2 thorpej (*tp->t_linesw->l_start)(tp);
1691 1.2.2.2 thorpej } else {
1692 1.2.2.2 thorpej sc->sc_tx_stopped = 1;
1693 1.2.2.2 thorpej }
1694 1.2.2.2 thorpej }
1695 1.2.2.2 thorpej
1696 1.2.2.2 thorpej #ifdef PLCOM_DEBUG
1697 1.2.2.2 thorpej if (plcom_debug)
1698 1.2.2.2 thorpej plcomstatus(sc, "plcom_stsoft");
1699 1.2.2.2 thorpej #endif
1700 1.2.2.2 thorpej }
1701 1.2.2.2 thorpej
1702 1.2.2.2 thorpej #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
1703 1.2.2.2 thorpej void
1704 1.2.2.2 thorpej plcomsoft(void *arg)
1705 1.2.2.2 thorpej {
1706 1.2.2.2 thorpej struct plcom_softc *sc = arg;
1707 1.2.2.2 thorpej struct tty *tp;
1708 1.2.2.2 thorpej
1709 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
1710 1.2.2.2 thorpej return;
1711 1.2.2.2 thorpej
1712 1.2.2.2 thorpej {
1713 1.2.2.2 thorpej #else
1714 1.2.2.2 thorpej void
1715 1.2.2.2 thorpej #ifndef __NO_SOFT_SERIAL_INTERRUPT
1716 1.2.2.2 thorpej plcomsoft(void)
1717 1.2.2.2 thorpej #else
1718 1.2.2.2 thorpej plcomsoft(void *arg)
1719 1.2.2.2 thorpej #endif
1720 1.2.2.2 thorpej {
1721 1.2.2.2 thorpej struct plcom_softc *sc;
1722 1.2.2.2 thorpej struct tty *tp;
1723 1.2.2.2 thorpej int unit;
1724 1.2.2.2 thorpej #ifdef __NO_SOFT_SERIAL_INTERRUPT
1725 1.2.2.2 thorpej int s;
1726 1.2.2.2 thorpej
1727 1.2.2.2 thorpej s = splsoftserial();
1728 1.2.2.2 thorpej plcom_softintr_scheduled = 0;
1729 1.2.2.2 thorpej #endif
1730 1.2.2.2 thorpej
1731 1.2.2.2 thorpej for (unit = 0; unit < plcom_cd.cd_ndevs; unit++) {
1732 1.2.2.2 thorpej sc = device_lookup(&plcom_cd, unit);
1733 1.2.2.2 thorpej if (sc == NULL || !ISSET(sc->sc_hwflags, PLCOM_HW_DEV_OK))
1734 1.2.2.2 thorpej continue;
1735 1.2.2.2 thorpej
1736 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
1737 1.2.2.2 thorpej continue;
1738 1.2.2.2 thorpej
1739 1.2.2.2 thorpej tp = sc->sc_tty;
1740 1.2.2.2 thorpej if (tp == NULL)
1741 1.2.2.2 thorpej continue;
1742 1.2.2.2 thorpej if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0)
1743 1.2.2.2 thorpej continue;
1744 1.2.2.2 thorpej #endif
1745 1.2.2.2 thorpej tp = sc->sc_tty;
1746 1.2.2.2 thorpej
1747 1.2.2.2 thorpej if (sc->sc_rx_ready) {
1748 1.2.2.2 thorpej sc->sc_rx_ready = 0;
1749 1.2.2.2 thorpej plcom_rxsoft(sc, tp);
1750 1.2.2.2 thorpej }
1751 1.2.2.2 thorpej
1752 1.2.2.2 thorpej if (sc->sc_st_check) {
1753 1.2.2.2 thorpej sc->sc_st_check = 0;
1754 1.2.2.2 thorpej plcom_stsoft(sc, tp);
1755 1.2.2.2 thorpej }
1756 1.2.2.2 thorpej
1757 1.2.2.2 thorpej if (sc->sc_tx_done) {
1758 1.2.2.2 thorpej sc->sc_tx_done = 0;
1759 1.2.2.2 thorpej plcom_txsoft(sc, tp);
1760 1.2.2.2 thorpej }
1761 1.2.2.2 thorpej }
1762 1.2.2.2 thorpej
1763 1.2.2.2 thorpej #ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
1764 1.2.2.2 thorpej #ifdef __NO_SOFT_SERIAL_INTERRUPT
1765 1.2.2.2 thorpej splx(s);
1766 1.2.2.2 thorpej #endif
1767 1.2.2.2 thorpej #endif
1768 1.2.2.2 thorpej }
1769 1.2.2.2 thorpej
1770 1.2.2.2 thorpej #ifdef __ALIGN_BRACKET_LEVEL_FOR_CTAGS
1771 1.2.2.2 thorpej /* there has got to be a better way to do plcomsoft() */
1772 1.2.2.2 thorpej }}
1773 1.2.2.2 thorpej #endif
1774 1.2.2.2 thorpej
1775 1.2.2.2 thorpej int
1776 1.2.2.2 thorpej plcomintr(void *arg)
1777 1.2.2.2 thorpej {
1778 1.2.2.2 thorpej struct plcom_softc *sc = arg;
1779 1.2.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1780 1.2.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1781 1.2.2.2 thorpej u_char *put, *end;
1782 1.2.2.2 thorpej u_int cc;
1783 1.2.2.2 thorpej u_char rsr, iir;
1784 1.2.2.2 thorpej
1785 1.2.2.2 thorpej if (PLCOM_ISALIVE(sc) == 0)
1786 1.2.2.2 thorpej return 0;
1787 1.2.2.2 thorpej
1788 1.2.2.2 thorpej PLCOM_LOCK(sc);
1789 1.2.2.2 thorpej iir = bus_space_read_1(iot, ioh, plcom_iir);
1790 1.2.2.2 thorpej if (! ISSET(iir, IIR_IMASK)) {
1791 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
1792 1.2.2.2 thorpej return 0;
1793 1.2.2.2 thorpej }
1794 1.2.2.2 thorpej
1795 1.2.2.2 thorpej end = sc->sc_ebuf;
1796 1.2.2.2 thorpej put = sc->sc_rbput;
1797 1.2.2.2 thorpej cc = sc->sc_rbavail;
1798 1.2.2.2 thorpej
1799 1.2.2.2 thorpej do {
1800 1.2.2.2 thorpej u_char msr, delta, fr;
1801 1.2.2.2 thorpej
1802 1.2.2.2 thorpej fr = bus_space_read_1(iot, ioh, plcom_fr);
1803 1.2.2.2 thorpej
1804 1.2.2.2 thorpej if (!ISSET(fr, FR_RXFE) &&
1805 1.2.2.2 thorpej !ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1806 1.2.2.2 thorpej while (cc > 0) {
1807 1.2.2.2 thorpej int cn_trapped = 0;
1808 1.2.2.2 thorpej put[0] = bus_space_read_1(iot, ioh,
1809 1.2.2.2 thorpej plcom_dr);
1810 1.2.2.2 thorpej rsr = bus_space_read_1(iot, ioh, plcom_rsr);
1811 1.2.2.2 thorpej /* Clear any error status. */
1812 1.2.2.2 thorpej if (ISSET(rsr,
1813 1.2.2.2 thorpej (RSR_BE | RSR_OE | RSR_PE | RSR_FE)))
1814 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_ecr,
1815 1.2.2.2 thorpej 0);
1816 1.2.2.2 thorpej if (ISSET(rsr, RSR_BE)) {
1817 1.2.2.2 thorpej int cn_trapped = 0;
1818 1.2.2.2 thorpej cn_check_magic(sc->sc_tty->t_dev,
1819 1.2.2.2 thorpej CNC_BREAK, plcom_cnm_state);
1820 1.2.2.2 thorpej if (cn_trapped)
1821 1.2.2.2 thorpej continue;
1822 1.2.2.2 thorpej #if defined(KGDB)
1823 1.2.2.2 thorpej if (ISSET(sc->sc_hwflags,
1824 1.2.2.2 thorpej PLCOM_HW_KGDB)) {
1825 1.2.2.2 thorpej kgdb_connect(1);
1826 1.2.2.2 thorpej continue;
1827 1.2.2.2 thorpej }
1828 1.2.2.2 thorpej #endif
1829 1.2.2.2 thorpej }
1830 1.2.2.2 thorpej
1831 1.2.2.2 thorpej put[1] = rsr;
1832 1.2.2.2 thorpej cn_check_magic(sc->sc_tty->t_dev,
1833 1.2.2.2 thorpej put[0], plcom_cnm_state);
1834 1.2.2.2 thorpej if (cn_trapped) {
1835 1.2.2.2 thorpej fr = bus_space_read_1(iot, ioh,
1836 1.2.2.2 thorpej plcom_fr);
1837 1.2.2.2 thorpej if (ISSET(fr, FR_RXFE))
1838 1.2.2.2 thorpej break;
1839 1.2.2.2 thorpej
1840 1.2.2.2 thorpej continue;
1841 1.2.2.2 thorpej }
1842 1.2.2.2 thorpej put += 2;
1843 1.2.2.2 thorpej if (put >= end)
1844 1.2.2.2 thorpej put = sc->sc_rbuf;
1845 1.2.2.2 thorpej cc--;
1846 1.2.2.2 thorpej
1847 1.2.2.2 thorpej fr = bus_space_read_1(iot, ioh, plcom_fr);
1848 1.2.2.2 thorpej if (ISSET(fr, FR_RXFE))
1849 1.2.2.2 thorpej break;
1850 1.2.2.2 thorpej }
1851 1.2.2.2 thorpej
1852 1.2.2.2 thorpej /*
1853 1.2.2.2 thorpej * Current string of incoming characters ended because
1854 1.2.2.2 thorpej * no more data was available or we ran out of space.
1855 1.2.2.2 thorpej * Schedule a receive event if any data was received.
1856 1.2.2.2 thorpej * If we're out of space, turn off receive interrupts.
1857 1.2.2.2 thorpej */
1858 1.2.2.2 thorpej sc->sc_rbput = put;
1859 1.2.2.2 thorpej sc->sc_rbavail = cc;
1860 1.2.2.2 thorpej if (!ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED))
1861 1.2.2.2 thorpej sc->sc_rx_ready = 1;
1862 1.2.2.2 thorpej
1863 1.2.2.2 thorpej /*
1864 1.2.2.2 thorpej * See if we are in danger of overflowing a buffer. If
1865 1.2.2.2 thorpej * so, use hardware flow control to ease the pressure.
1866 1.2.2.2 thorpej */
1867 1.2.2.2 thorpej if (!ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED) &&
1868 1.2.2.2 thorpej cc < sc->sc_r_hiwat) {
1869 1.2.2.2 thorpej SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1870 1.2.2.2 thorpej plcom_hwiflow(sc);
1871 1.2.2.2 thorpej }
1872 1.2.2.2 thorpej
1873 1.2.2.2 thorpej /*
1874 1.2.2.2 thorpej * If we're out of space, disable receive interrupts
1875 1.2.2.2 thorpej * until the queue has drained a bit.
1876 1.2.2.2 thorpej */
1877 1.2.2.2 thorpej if (!cc) {
1878 1.2.2.2 thorpej SET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1879 1.2.2.2 thorpej CLR(sc->sc_cr, CR_RIE | CR_RTIE);
1880 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr,
1881 1.2.2.2 thorpej sc->sc_cr);
1882 1.2.2.2 thorpej }
1883 1.2.2.2 thorpej } else {
1884 1.2.2.2 thorpej if (ISSET(iir, IIR_RIS)) {
1885 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, 0);
1886 1.2.2.2 thorpej delay(10);
1887 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr,
1888 1.2.2.2 thorpej sc->sc_cr);
1889 1.2.2.2 thorpej continue;
1890 1.2.2.2 thorpej }
1891 1.2.2.2 thorpej }
1892 1.2.2.2 thorpej
1893 1.2.2.2 thorpej msr = bus_space_read_1(iot, ioh, plcom_fr);
1894 1.2.2.2 thorpej delta = msr ^ sc->sc_msr;
1895 1.2.2.2 thorpej sc->sc_msr = msr;
1896 1.2.2.2 thorpej /* Clear any pending modem status interrupt. */
1897 1.2.2.2 thorpej if (iir & IIR_MIS)
1898 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_icr, 0);
1899 1.2.2.2 thorpej /*
1900 1.2.2.2 thorpej * Pulse-per-second (PSS) signals on edge of DCD?
1901 1.2.2.2 thorpej * Process these even if line discipline is ignoring DCD.
1902 1.2.2.2 thorpej */
1903 1.2.2.2 thorpej if (delta & sc->sc_ppsmask) {
1904 1.2.2.2 thorpej struct timeval tv;
1905 1.2.2.2 thorpej if ((msr & sc->sc_ppsmask) == sc->sc_ppsassert) {
1906 1.2.2.2 thorpej /* XXX nanotime() */
1907 1.2.2.2 thorpej microtime(&tv);
1908 1.2.2.2 thorpej TIMEVAL_TO_TIMESPEC(&tv,
1909 1.2.2.2 thorpej &sc->ppsinfo.assert_timestamp);
1910 1.2.2.2 thorpej if (sc->ppsparam.mode & PPS_OFFSETASSERT) {
1911 1.2.2.2 thorpej timespecadd(&sc->ppsinfo.assert_timestamp,
1912 1.2.2.2 thorpej &sc->ppsparam.assert_offset,
1913 1.2.2.2 thorpej &sc->ppsinfo.assert_timestamp);
1914 1.2.2.2 thorpej }
1915 1.2.2.2 thorpej
1916 1.2.2.2 thorpej #ifdef PPS_SYNC
1917 1.2.2.2 thorpej if (sc->ppsparam.mode & PPS_HARDPPSONASSERT)
1918 1.2.2.2 thorpej hardpps(&tv, tv.tv_usec);
1919 1.2.2.2 thorpej #endif
1920 1.2.2.2 thorpej sc->ppsinfo.assert_sequence++;
1921 1.2.2.2 thorpej sc->ppsinfo.current_mode = sc->ppsparam.mode;
1922 1.2.2.2 thorpej
1923 1.2.2.2 thorpej } else if ((msr & sc->sc_ppsmask) == sc->sc_ppsclear) {
1924 1.2.2.2 thorpej /* XXX nanotime() */
1925 1.2.2.2 thorpej microtime(&tv);
1926 1.2.2.2 thorpej TIMEVAL_TO_TIMESPEC(&tv,
1927 1.2.2.2 thorpej &sc->ppsinfo.clear_timestamp);
1928 1.2.2.2 thorpej if (sc->ppsparam.mode & PPS_OFFSETCLEAR) {
1929 1.2.2.2 thorpej timespecadd(&sc->ppsinfo.clear_timestamp,
1930 1.2.2.2 thorpej &sc->ppsparam.clear_offset,
1931 1.2.2.2 thorpej &sc->ppsinfo.clear_timestamp);
1932 1.2.2.2 thorpej }
1933 1.2.2.2 thorpej
1934 1.2.2.2 thorpej #ifdef PPS_SYNC
1935 1.2.2.2 thorpej if (sc->ppsparam.mode & PPS_HARDPPSONCLEAR)
1936 1.2.2.2 thorpej hardpps(&tv, tv.tv_usec);
1937 1.2.2.2 thorpej #endif
1938 1.2.2.2 thorpej sc->ppsinfo.clear_sequence++;
1939 1.2.2.2 thorpej sc->ppsinfo.current_mode = sc->ppsparam.mode;
1940 1.2.2.2 thorpej }
1941 1.2.2.2 thorpej }
1942 1.2.2.2 thorpej
1943 1.2.2.2 thorpej /*
1944 1.2.2.2 thorpej * Process normal status changes
1945 1.2.2.2 thorpej */
1946 1.2.2.2 thorpej if (ISSET(delta, sc->sc_msr_mask)) {
1947 1.2.2.2 thorpej SET(sc->sc_msr_delta, delta);
1948 1.2.2.2 thorpej
1949 1.2.2.2 thorpej /*
1950 1.2.2.2 thorpej * Stop output immediately if we lose the output
1951 1.2.2.2 thorpej * flow control signal or carrier detect.
1952 1.2.2.2 thorpej */
1953 1.2.2.2 thorpej if (ISSET(~msr, sc->sc_msr_mask)) {
1954 1.2.2.2 thorpej sc->sc_tbc = 0;
1955 1.2.2.2 thorpej sc->sc_heldtbc = 0;
1956 1.2.2.2 thorpej #ifdef PLCOM_DEBUG
1957 1.2.2.2 thorpej if (plcom_debug)
1958 1.2.2.2 thorpej plcomstatus(sc, "plcomintr ");
1959 1.2.2.2 thorpej #endif
1960 1.2.2.2 thorpej }
1961 1.2.2.2 thorpej
1962 1.2.2.2 thorpej sc->sc_st_check = 1;
1963 1.2.2.2 thorpej }
1964 1.2.2.2 thorpej
1965 1.2.2.2 thorpej /*
1966 1.2.2.2 thorpej * Done handling any receive interrupts. See if data
1967 1.2.2.2 thorpej * can be * transmitted as well. Schedule tx done
1968 1.2.2.2 thorpej * event if no data left * and tty was marked busy.
1969 1.2.2.2 thorpej */
1970 1.2.2.2 thorpej if (ISSET(iir, IIR_TIS)) {
1971 1.2.2.2 thorpej /*
1972 1.2.2.2 thorpej * If we've delayed a parameter change, do it
1973 1.2.2.2 thorpej * now, and restart * output.
1974 1.2.2.2 thorpej */
1975 1.2.2.2 thorpej if (sc->sc_heldchange) {
1976 1.2.2.2 thorpej plcom_loadchannelregs(sc);
1977 1.2.2.2 thorpej sc->sc_heldchange = 0;
1978 1.2.2.2 thorpej sc->sc_tbc = sc->sc_heldtbc;
1979 1.2.2.2 thorpej sc->sc_heldtbc = 0;
1980 1.2.2.2 thorpej }
1981 1.2.2.2 thorpej
1982 1.2.2.2 thorpej /*
1983 1.2.2.2 thorpej * Output the next chunk of the contiguous
1984 1.2.2.2 thorpej * buffer, if any.
1985 1.2.2.2 thorpej */
1986 1.2.2.2 thorpej if (sc->sc_tbc > 0) {
1987 1.2.2.2 thorpej int n;
1988 1.2.2.2 thorpej
1989 1.2.2.2 thorpej n = sc->sc_tbc;
1990 1.2.2.2 thorpej if (n > sc->sc_fifolen)
1991 1.2.2.2 thorpej n = sc->sc_fifolen;
1992 1.2.2.2 thorpej bus_space_write_multi_1(iot, ioh, plcom_dr,
1993 1.2.2.2 thorpej sc->sc_tba, n);
1994 1.2.2.2 thorpej sc->sc_tbc -= n;
1995 1.2.2.2 thorpej sc->sc_tba += n;
1996 1.2.2.2 thorpej } else {
1997 1.2.2.2 thorpej /*
1998 1.2.2.2 thorpej * Disable transmit plcompletion
1999 1.2.2.2 thorpej * interrupts if necessary.
2000 1.2.2.2 thorpej */
2001 1.2.2.2 thorpej if (ISSET(sc->sc_cr, CR_TIE)) {
2002 1.2.2.2 thorpej CLR(sc->sc_cr, CR_TIE);
2003 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr,
2004 1.2.2.2 thorpej sc->sc_cr);
2005 1.2.2.2 thorpej }
2006 1.2.2.2 thorpej if (sc->sc_tx_busy) {
2007 1.2.2.2 thorpej sc->sc_tx_busy = 0;
2008 1.2.2.2 thorpej sc->sc_tx_done = 1;
2009 1.2.2.2 thorpej }
2010 1.2.2.2 thorpej }
2011 1.2.2.2 thorpej }
2012 1.2.2.2 thorpej } while (ISSET((iir = bus_space_read_1(iot, ioh, plcom_iir)),
2013 1.2.2.2 thorpej IIR_IMASK));
2014 1.2.2.2 thorpej
2015 1.2.2.2 thorpej PLCOM_UNLOCK(sc);
2016 1.2.2.2 thorpej
2017 1.2.2.2 thorpej /* Wake up the poller. */
2018 1.2.2.2 thorpej #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
2019 1.2.2.2 thorpej softintr_schedule(sc->sc_si);
2020 1.2.2.2 thorpej #else
2021 1.2.2.2 thorpej #ifndef __NO_SOFT_SERIAL_INTERRUPT
2022 1.2.2.2 thorpej setsoftserial();
2023 1.2.2.2 thorpej #else
2024 1.2.2.2 thorpej if (!plcom_softintr_scheduled) {
2025 1.2.2.2 thorpej plcom_softintr_scheduled = 1;
2026 1.2.2.2 thorpej callout_reset(&plcomsoft_callout, 1, plcomsoft, NULL);
2027 1.2.2.2 thorpej }
2028 1.2.2.2 thorpej #endif
2029 1.2.2.2 thorpej #endif
2030 1.2.2.2 thorpej
2031 1.2.2.2 thorpej #if NRND > 0 && defined(RND_COM)
2032 1.2.2.2 thorpej rnd_add_uint32(&sc->rnd_source, iir | rsr);
2033 1.2.2.2 thorpej #endif
2034 1.2.2.2 thorpej
2035 1.2.2.2 thorpej return 1;
2036 1.2.2.2 thorpej }
2037 1.2.2.2 thorpej
2038 1.2.2.2 thorpej /*
2039 1.2.2.2 thorpej * The following functions are polled getc and putc routines, shared
2040 1.2.2.2 thorpej * by the console and kgdb glue.
2041 1.2.2.2 thorpej *
2042 1.2.2.2 thorpej * The read-ahead code is so that you can detect pending in-band
2043 1.2.2.2 thorpej * cn_magic in polled mode while doing output rather than having to
2044 1.2.2.2 thorpej * wait until the kernel decides it needs input.
2045 1.2.2.2 thorpej */
2046 1.2.2.2 thorpej
2047 1.2.2.2 thorpej #define MAX_READAHEAD 20
2048 1.2.2.2 thorpej static int plcom_readahead[MAX_READAHEAD];
2049 1.2.2.2 thorpej static int plcom_readaheadcount = 0;
2050 1.2.2.2 thorpej
2051 1.2.2.2 thorpej int
2052 1.2.2.2 thorpej plcom_common_getc(dev_t dev, bus_space_tag_t iot, bus_space_handle_t ioh)
2053 1.2.2.2 thorpej {
2054 1.2.2.2 thorpej int s = splserial();
2055 1.2.2.2 thorpej u_char stat, c;
2056 1.2.2.2 thorpej
2057 1.2.2.2 thorpej /* got a character from reading things earlier */
2058 1.2.2.2 thorpej if (plcom_readaheadcount > 0) {
2059 1.2.2.2 thorpej int i;
2060 1.2.2.2 thorpej
2061 1.2.2.2 thorpej c = plcom_readahead[0];
2062 1.2.2.2 thorpej for (i = 1; i < plcom_readaheadcount; i++) {
2063 1.2.2.2 thorpej plcom_readahead[i-1] = plcom_readahead[i];
2064 1.2.2.2 thorpej }
2065 1.2.2.2 thorpej plcom_readaheadcount--;
2066 1.2.2.2 thorpej splx(s);
2067 1.2.2.2 thorpej return c;
2068 1.2.2.2 thorpej }
2069 1.2.2.2 thorpej
2070 1.2.2.2 thorpej /* block until a character becomes available */
2071 1.2.2.2 thorpej while (ISSET(stat = bus_space_read_1(iot, ioh, plcom_fr), FR_RXFE))
2072 1.2.2.2 thorpej ;
2073 1.2.2.2 thorpej
2074 1.2.2.2 thorpej c = bus_space_read_1(iot, ioh, plcom_dr);
2075 1.2.2.2 thorpej stat = bus_space_read_1(iot, ioh, plcom_iir);
2076 1.2.2.2 thorpej {
2077 1.2.2.2 thorpej int cn_trapped = 0; /* unused */
2078 1.2.2.2 thorpej #ifdef DDB
2079 1.2.2.2 thorpej extern int db_active;
2080 1.2.2.2 thorpej if (!db_active)
2081 1.2.2.2 thorpej #endif
2082 1.2.2.2 thorpej cn_check_magic(dev, c, plcom_cnm_state);
2083 1.2.2.2 thorpej }
2084 1.2.2.2 thorpej splx(s);
2085 1.2.2.2 thorpej return c;
2086 1.2.2.2 thorpej }
2087 1.2.2.2 thorpej
2088 1.2.2.2 thorpej void
2089 1.2.2.2 thorpej plcom_common_putc(dev_t dev, bus_space_tag_t iot, bus_space_handle_t ioh,
2090 1.2.2.2 thorpej int c)
2091 1.2.2.2 thorpej {
2092 1.2.2.2 thorpej int s = splserial();
2093 1.2.2.2 thorpej int timo;
2094 1.2.2.2 thorpej
2095 1.2.2.2 thorpej int cin, stat;
2096 1.2.2.2 thorpej if (plcom_readaheadcount < MAX_READAHEAD
2097 1.2.2.2 thorpej && !ISSET(stat = bus_space_read_1(iot, ioh, plcom_fr), FR_RXFE)) {
2098 1.2.2.2 thorpej int cn_trapped = 0;
2099 1.2.2.2 thorpej cin = bus_space_read_1(iot, ioh, plcom_dr);
2100 1.2.2.2 thorpej stat = bus_space_read_1(iot, ioh, plcom_iir);
2101 1.2.2.2 thorpej cn_check_magic(dev, cin, plcom_cnm_state);
2102 1.2.2.2 thorpej plcom_readahead[plcom_readaheadcount++] = cin;
2103 1.2.2.2 thorpej }
2104 1.2.2.2 thorpej
2105 1.2.2.2 thorpej /* wait for any pending transmission to finish */
2106 1.2.2.2 thorpej timo = 150000;
2107 1.2.2.2 thorpej while (!ISSET(bus_space_read_1(iot, ioh, plcom_fr), FR_TXFE) && --timo)
2108 1.2.2.2 thorpej continue;
2109 1.2.2.2 thorpej
2110 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_dr, c);
2111 1.2.2.2 thorpej PLCOM_BARRIER(iot, ioh, BR | BW);
2112 1.2.2.2 thorpej
2113 1.2.2.2 thorpej /* wait for this transmission to complete */
2114 1.2.2.2 thorpej timo = 1500000;
2115 1.2.2.2 thorpej while (!ISSET(bus_space_read_1(iot, ioh, plcom_fr), FR_TXFE) && --timo)
2116 1.2.2.2 thorpej continue;
2117 1.2.2.2 thorpej
2118 1.2.2.2 thorpej splx(s);
2119 1.2.2.2 thorpej }
2120 1.2.2.2 thorpej
2121 1.2.2.2 thorpej /*
2122 1.2.2.2 thorpej * Initialize UART for use as console or KGDB line.
2123 1.2.2.2 thorpej */
2124 1.2.2.2 thorpej int
2125 1.2.2.2 thorpej plcominit(bus_space_tag_t iot, bus_addr_t iobase, int rate, int frequency,
2126 1.2.2.2 thorpej tcflag_t cflag, bus_space_handle_t *iohp)
2127 1.2.2.2 thorpej {
2128 1.2.2.2 thorpej bus_space_handle_t ioh;
2129 1.2.2.2 thorpej
2130 1.2.2.2 thorpej if (bus_space_map(iot, iobase, PLCOM_UART_SIZE, 0, &ioh))
2131 1.2.2.2 thorpej return ENOMEM; /* ??? */
2132 1.2.2.2 thorpej
2133 1.2.2.2 thorpej rate = plcomspeed(rate, frequency);
2134 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, 0);
2135 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_dlbl, rate);
2136 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_dlbh, rate >> 8);
2137 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_lcr, cflag2lcr(cflag) | LCR_FEN);
2138 1.2.2.2 thorpej bus_space_write_1(iot, ioh, plcom_cr, CR_UARTEN);
2139 1.2.2.2 thorpej
2140 1.2.2.2 thorpej #if 0
2141 1.2.2.2 thorpej /* Ought to do something like this, but we have no sc to
2142 1.2.2.2 thorpej dereference. */
2143 1.2.2.2 thorpej sc->sc_set_mcr(sc->sc_set_mcr_arg, sc->sc_dev.dv_unit,
2144 1.2.2.2 thorpej MCR_DTR | MCR_RTS);
2145 1.2.2.2 thorpej #endif
2146 1.2.2.2 thorpej
2147 1.2.2.2 thorpej *iohp = ioh;
2148 1.2.2.2 thorpej return 0;
2149 1.2.2.2 thorpej }
2150 1.2.2.2 thorpej
2151 1.2.2.2 thorpej /*
2152 1.2.2.2 thorpej * Following are all routines needed for PLCOM to act as console
2153 1.2.2.2 thorpej */
2154 1.2.2.2 thorpej struct consdev plcomcons = {
2155 1.2.2.2 thorpej NULL, NULL, plcomcngetc, plcomcnputc, plcomcnpollc, NULL,
2156 1.2.2.2 thorpej NODEV, CN_NORMAL
2157 1.2.2.2 thorpej };
2158 1.2.2.2 thorpej
2159 1.2.2.2 thorpej
2160 1.2.2.2 thorpej int
2161 1.2.2.2 thorpej plcomcnattach(bus_space_tag_t iot, bus_addr_t iobase, int rate, int frequency,
2162 1.2.2.2 thorpej tcflag_t cflag, int unit)
2163 1.2.2.2 thorpej {
2164 1.2.2.2 thorpej int res;
2165 1.2.2.2 thorpej
2166 1.2.2.2 thorpej res = plcominit(iot, iobase, rate, frequency, cflag, &plcomconsioh);
2167 1.2.2.2 thorpej if (res)
2168 1.2.2.2 thorpej return res;
2169 1.2.2.2 thorpej
2170 1.2.2.2 thorpej cn_tab = &plcomcons;
2171 1.2.2.2 thorpej cn_init_magic(&plcom_cnm_state);
2172 1.2.2.2 thorpej cn_set_magic("\047\001"); /* default magic is BREAK */
2173 1.2.2.2 thorpej
2174 1.2.2.2 thorpej plcomconstag = iot;
2175 1.2.2.2 thorpej plcomconsunit = unit;
2176 1.2.2.2 thorpej plcomconsrate = rate;
2177 1.2.2.2 thorpej plcomconscflag = cflag;
2178 1.2.2.2 thorpej
2179 1.2.2.2 thorpej return 0;
2180 1.2.2.2 thorpej }
2181 1.2.2.2 thorpej
2182 1.2.2.2 thorpej void
2183 1.2.2.2 thorpej plcomcndetach(void)
2184 1.2.2.2 thorpej {
2185 1.2.2.2 thorpej bus_space_unmap(plcomconstag, plcomconsioh, PLCOM_UART_SIZE);
2186 1.2.2.2 thorpej plcomconstag = NULL;
2187 1.2.2.2 thorpej
2188 1.2.2.2 thorpej cn_tab = NULL;
2189 1.2.2.2 thorpej }
2190 1.2.2.2 thorpej
2191 1.2.2.2 thorpej int
2192 1.2.2.2 thorpej plcomcngetc(dev_t dev)
2193 1.2.2.2 thorpej {
2194 1.2.2.2 thorpej return plcom_common_getc(dev, plcomconstag, plcomconsioh);
2195 1.2.2.2 thorpej }
2196 1.2.2.2 thorpej
2197 1.2.2.2 thorpej /*
2198 1.2.2.2 thorpej * Console kernel output character routine.
2199 1.2.2.2 thorpej */
2200 1.2.2.2 thorpej void
2201 1.2.2.2 thorpej plcomcnputc(dev_t dev, int c)
2202 1.2.2.2 thorpej {
2203 1.2.2.2 thorpej plcom_common_putc(dev, plcomconstag, plcomconsioh, c);
2204 1.2.2.2 thorpej }
2205 1.2.2.2 thorpej
2206 1.2.2.2 thorpej void
2207 1.2.2.2 thorpej plcomcnpollc(dev_t dev, int on)
2208 1.2.2.2 thorpej {
2209 1.2.2.2 thorpej
2210 1.2.2.2 thorpej }
2211 1.2.2.2 thorpej
2212 1.2.2.2 thorpej #ifdef KGDB
2213 1.2.2.2 thorpej int
2214 1.2.2.2 thorpej plcom_kgdb_attach(bus_space_tag_t iot, bus_addr_t iobase, int rate,
2215 1.2.2.2 thorpej int frequency, tcflag_t cflag, int unit)
2216 1.2.2.2 thorpej {
2217 1.2.2.2 thorpej int res;
2218 1.2.2.2 thorpej
2219 1.2.2.2 thorpej if (iot == plcomconstag && iobase == plcomconsunit)
2220 1.2.2.2 thorpej return EBUSY; /* cannot share with console */
2221 1.2.2.2 thorpej
2222 1.2.2.2 thorpej res = plcominit(iot, iobase, rate, frequency, cflag, &plcom_kgdb_ioh);
2223 1.2.2.2 thorpej if (res)
2224 1.2.2.2 thorpej return res;
2225 1.2.2.2 thorpej
2226 1.2.2.2 thorpej kgdb_attach(plcom_kgdb_getc, plcom_kgdb_putc, NULL);
2227 1.2.2.2 thorpej kgdb_dev = 123; /* unneeded, only to satisfy some tests */
2228 1.2.2.2 thorpej
2229 1.2.2.2 thorpej plcom_kgdb_iot = iot;
2230 1.2.2.2 thorpej plcom_kgdb_unit = unit;
2231 1.2.2.2 thorpej
2232 1.2.2.2 thorpej return 0;
2233 1.2.2.2 thorpej }
2234 1.2.2.2 thorpej
2235 1.2.2.2 thorpej /* ARGSUSED */
2236 1.2.2.2 thorpej int
2237 1.2.2.2 thorpej plcom_kgdb_getc(void *arg)
2238 1.2.2.2 thorpej {
2239 1.2.2.2 thorpej return plcom_common_getc(NODEV, plcom_kgdb_iot, plcom_kgdb_ioh);
2240 1.2.2.2 thorpej }
2241 1.2.2.2 thorpej
2242 1.2.2.2 thorpej /* ARGSUSED */
2243 1.2.2.2 thorpej void
2244 1.2.2.2 thorpej plcom_kgdb_putc(void *arg, int c)
2245 1.2.2.2 thorpej {
2246 1.2.2.2 thorpej plcom_common_putc(NODEV, plcom_kgdb_iot, plcom_kgdb_ioh, c);
2247 1.2.2.2 thorpej }
2248 1.2.2.2 thorpej #endif /* KGDB */
2249 1.2.2.2 thorpej
2250 1.2.2.2 thorpej /* helper function to identify the plcom ports used by
2251 1.2.2.2 thorpej console or KGDB (and not yet autoconf attached) */
2252 1.2.2.2 thorpej int
2253 1.2.2.2 thorpej plcom_is_console(bus_space_tag_t iot, int unit,
2254 1.2.2.2 thorpej bus_space_handle_t *ioh)
2255 1.2.2.2 thorpej {
2256 1.2.2.2 thorpej bus_space_handle_t help;
2257 1.2.2.2 thorpej
2258 1.2.2.2 thorpej if (!plcomconsattached &&
2259 1.2.2.2 thorpej iot == plcomconstag && unit == plcomconsunit)
2260 1.2.2.2 thorpej help = plcomconsioh;
2261 1.2.2.2 thorpej #ifdef KGDB
2262 1.2.2.2 thorpej else if (!plcom_kgdb_attached &&
2263 1.2.2.2 thorpej iot == plcom_kgdb_iot && unit == plcom_kgdb_unit)
2264 1.2.2.2 thorpej help = plcom_kgdb_ioh;
2265 1.2.2.2 thorpej #endif
2266 1.2.2.2 thorpej else
2267 1.2.2.2 thorpej return 0;
2268 1.2.2.2 thorpej
2269 1.2.2.2 thorpej if (ioh)
2270 1.2.2.2 thorpej *ioh = help;
2271 1.2.2.2 thorpej return 1;
2272 1.2.2.2 thorpej }
2273