sci.c revision 1.4 1 /* $NetBSD: sci.c,v 1.4 1999/09/17 01:23:00 msaitoh Exp $ */
2
3 /*-
4 * Copyright (C) 1999 T.Horiuchi and SAITOH Masanobu. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /*-
30 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
31 * All rights reserved.
32 *
33 * This code is derived from software contributed to The NetBSD Foundation
34 * by Charles M. Hannum.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the NetBSD
47 * Foundation, Inc. and its contributors.
48 * 4. Neither the name of The NetBSD Foundation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
53 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
54 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
56 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
57 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
58 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
59 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
60 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
61 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
62 * POSSIBILITY OF SUCH DAMAGE.
63 */
64
65 /*
66 * Copyright (c) 1991 The Regents of the University of California.
67 * All rights reserved.
68 *
69 * Redistribution and use in source and binary forms, with or without
70 * modification, are permitted provided that the following conditions
71 * are met:
72 * 1. Redistributions of source code must retain the above copyright
73 * notice, this list of conditions and the following disclaimer.
74 * 2. Redistributions in binary form must reproduce the above copyright
75 * notice, this list of conditions and the following disclaimer in the
76 * documentation and/or other materials provided with the distribution.
77 * 3. All advertising materials mentioning features or use of this software
78 * must display the following acknowledgement:
79 * This product includes software developed by the University of
80 * California, Berkeley and its contributors.
81 * 4. Neither the name of the University nor the names of its contributors
82 * may be used to endorse or promote products derived from this software
83 * without specific prior written permission.
84 *
85 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
86 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
87 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
88 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
89 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
90 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
91 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
92 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
93 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
94 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
95 * SUCH DAMAGE.
96 *
97 * @(#)com.c 7.5 (Berkeley) 5/16/91
98 */
99
100 /*
101 * SH internal serial driver
102 *
103 * This code is derived from both z8530tty.c and com.c
104 */
105
106 #include "opt_pclock.h"
107 #include "opt_sci.h"
108
109 #include <sys/param.h>
110 #include <sys/systm.h>
111 #include <sys/tty.h>
112 #include <sys/proc.h>
113 #include <sys/conf.h>
114 #include <sys/file.h>
115 #include <sys/syslog.h>
116 #include <sys/kernel.h>
117 #include <sys/device.h>
118 #include <sys/malloc.h>
119
120 #include <dev/cons.h>
121
122 #include <machine/cpu.h>
123 #include <sh3/scireg.h>
124 #include <sh3/tmureg.h>
125
126 #include <machine/shbvar.h>
127
128 static void scistart __P((struct tty *));
129 static int sciparam __P((struct tty *, struct termios *));
130
131 void scicnprobe __P((struct consdev *));
132 void scicninit __P((struct consdev *));
133 void scicnputc __P((dev_t, int));
134 int scicngetc __P((dev_t));
135 void scicnpoolc __P((dev_t, int));
136 int sciintr __P((void *));
137
138 struct sci_softc {
139 struct device sc_dev; /* boilerplate */
140 struct tty *sc_tty;
141 void *sc_ih;
142
143 #if 0
144 bus_space_tag_t sc_iot; /* ISA i/o space identifier */
145 bus_space_handle_t sc_ioh; /* ISA io handle */
146
147 int sc_drq;
148
149 int sc_frequency;
150 #endif
151
152 u_int sc_overflows,
153 sc_floods,
154 sc_errors; /* number of retries so far */
155 u_char sc_status[7]; /* copy of registers */
156
157 int sc_hwflags;
158 int sc_swflags;
159 u_int sc_fifolen; /* XXX always 0? */
160
161 u_int sc_r_hiwat,
162 sc_r_lowat;
163 u_char *volatile sc_rbget,
164 *volatile sc_rbput;
165 volatile u_int sc_rbavail;
166 u_char *sc_rbuf,
167 *sc_ebuf;
168
169 u_char *sc_tba; /* transmit buffer address */
170 u_int sc_tbc, /* transmit byte count */
171 sc_heldtbc;
172
173 volatile u_char sc_rx_flags, /* receiver blocked */
174 #define RX_TTY_BLOCKED 0x01
175 #define RX_TTY_OVERFLOWED 0x02
176 #define RX_IBUF_BLOCKED 0x04
177 #define RX_IBUF_OVERFLOWED 0x08
178 #define RX_ANY_BLOCK 0x0f
179 sc_tx_busy, /* working on an output chunk */
180 sc_tx_done, /* done with one output chunk */
181 sc_tx_stopped, /* H/W level stop (lost CTS) */
182 sc_st_check, /* got a status interrupt */
183 sc_rx_ready;
184
185 volatile u_char sc_heldchange;
186 };
187
188 /* controller driver configuration */
189 static int sci_match __P((struct device *, struct cfdata *, void *));
190 static void sci_attach __P((struct device *, struct device *, void *));
191
192 void sci_iflush __P((struct sci_softc *));
193
194 #define integrate static inline
195 #ifdef __GENERIC_SOFT_INTERRUPTS
196 void scisoft __P((void *));
197 #else
198 #ifndef __NO_SOFT_SERIAL_INTERRUPT
199 void scisoft __P((void));
200 #else
201 void scisoft __P((void *));
202 #endif
203 #endif
204 integrate void sci_rxsoft __P((struct sci_softc *, struct tty *));
205 integrate void sci_txsoft __P((struct sci_softc *, struct tty *));
206 integrate void sci_stsoft __P((struct sci_softc *, struct tty *));
207 integrate void sci_schedrx __P((struct sci_softc *));
208 void scidiag __P((void *));
209
210 #define SCIUNIT_MASK 0x7ffff
211 #define SCIDIALOUT_MASK 0x80000
212
213 #define SCIUNIT(x) (minor(x) & SCIUNIT_MASK)
214 #define SCIDIALOUT(x) (minor(x) & SCIDIALOUT_MASK)
215
216 /* Macros to clear/set/test flags. */
217 #define SET(t, f) (t) |= (f)
218 #define CLR(t, f) (t) &= ~(f)
219 #define ISSET(t, f) ((t) & (f))
220
221 /* Hardware flag masks */
222 #define SCI_HW_NOIEN 0x01
223 #define SCI_HW_FIFO 0x02
224 #define SCI_HW_FLOW 0x08
225 #define SCI_HW_DEV_OK 0x20
226 #define SCI_HW_CONSOLE 0x40
227 #define SCI_HW_KGDB 0x80
228
229 /* Buffer size for character buffer */
230 #define SCI_RING_SIZE 2048
231
232 /* Stop input when 3/4 of the ring is full; restart when only 1/4 is full. */
233 u_int sci_rbuf_hiwat = (SCI_RING_SIZE * 1) / 4;
234 u_int sci_rbuf_lowat = (SCI_RING_SIZE * 3) / 4;
235
236 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
237 int sciconscflag = CONMODE;
238
239 #define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
240
241 #ifndef __GENERIC_SOFT_INTERRUPTS
242 #ifdef __NO_SOFT_SERIAL_INTERRUPT
243 volatile int sci_softintr_scheduled;
244 #endif
245 #endif
246
247 u_int sci_rbuf_size = SCI_RING_SIZE;
248
249 struct cfattach sci_ca = {
250 sizeof(struct sci_softc), sci_match, sci_attach
251 };
252
253 extern struct cfdriver sci_cd;
254
255 cdev_decl(sci);
256
257 void InitializeSci __P((unsigned int));
258
259 /*
260 * following functions are debugging prupose only
261 */
262 #define CR 0x0D
263 #define I2C_ADRS (*(volatile unsigned int *)0xa8000000)
264 #define USART_ON (unsigned int)~0x08
265
266 static void WaitFor __P((int));
267 void PutcSci __P((unsigned char));
268 void PutStrSci __P((unsigned char *));
269 int SciErrCheck __P((void));
270 unsigned char GetcSci __P((void));
271 int GetStrSci __P((unsigned char *, int));
272
273 /*
274 * WaitFor
275 * : int mSec;
276 */
277 static void
278 WaitFor(mSec)
279 int mSec;
280 {
281
282 /* using clock = Internal RTC */
283 SHREG_TOCR = 0x01;
284
285 /* Disable Under Flow interrupt, rising edge, 1/4 */
286 SHREG_TCR0 = 0x0000;
287
288 /* Set counter value (count down with 4 KHz) */
289 SHREG_TCNT0 = mSec * 4;
290
291 /* start Channel0 */
292 SHREG_TSTR |= TSTR_STR0;
293
294 /* wait for under flag ON of channel0 */
295 while ((SHREG_TCR0 & 0x0100) == 0)
296 ;
297
298 /* stop channel0 */
299 SHREG_TSTR &= ~TSTR_STR0;
300 }
301
302 /*
303 * InitializeSci
304 * : unsigned int bps;
305 * : SCI(Serial Communication Interface)
306 */
307
308 void
309 InitializeSci(bps)
310 unsigned int bps;
311 {
312
313 /* Initialize SCR */
314 SHREG_SCSCR = 0x00;
315
316 /* Serial Mode Register */
317 SHREG_SCSMR = 0x00; /* Async,8bit,NonParity,Even,1Stop,NoMulti */
318
319 /* Bit Rate Register */
320 SHREG_SCBRR = divrnd(PCLOCK, 32 * bps) -1;
321
322 /*
323 * wait 1mSec, because Send/Recv must begin 1 bit period after
324 * BRR is set.
325 */
326 WaitFor(1);
327
328 /* Send permission, Recieve permission ON */
329 SHREG_SCSCR = SCSCR_TE | SCSCR_RE;
330
331 /*Serial Status Register */
332 SHREG_SCSSR &= SCSSR_TDRE; /* Clear Status */
333
334 #if 0
335 I2C_ADRS &= ~0x08; /* enable RS-232C */
336 #endif
337 }
338
339
340 /*
341 * PutcSci
342 * : unsigned char c;
343 */
344 void
345 PutcSci(c)
346 unsigned char c;
347 {
348
349 /* wait for ready */
350 while ((SHREG_SCSSR & SCSSR_TDRE) == NULL)
351 ;
352
353 /* write send data to send register */
354 SHREG_SCTDR = c;
355
356 /* clear ready flag */
357 SHREG_SCSSR &= ~SCSSR_TDRE;
358
359 if (c == '\n'){
360 while ((SHREG_SCSSR & SCSSR_TDRE) == NULL)
361 ;
362
363 SHREG_SCTDR = '\r';
364
365 SHREG_SCSSR &= ~SCSSR_TDRE;
366 }
367 }
368
369 /*
370 * PutStrSci
371 * : unsigned char *s;
372 */
373 void
374 PutStrSci(s)
375 unsigned char *s;
376 {
377 #if 0
378 static int SciInit = 0;
379 if (SciInit == 0) {
380 InitializeSci(SCICN_SPEED);
381 SciInit = 1;
382 }
383 #endif
384
385 while (*s)
386 PutcSci(*s++);
387 }
388
389 /*
390 * : SciErrCheck
391 * 0x20 = over run
392 * 0x10 = frame error
393 * 0x80 = parity error
394 */
395 int
396 SciErrCheck(void)
397 {
398
399 return(SHREG_SCSSR & (SCSSR_ORER | SCSSR_FER | SCSSR_PER));
400 }
401
402 /*
403 * GetcSci
404 */
405 unsigned char
406 GetcSci(void)
407 {
408 unsigned char c, err_c;
409
410 while (((err_c = SHREG_SCSSR)
411 & (SCSSR_RDRF | SCSSR_ORER | SCSSR_FER | SCSSR_PER)) == 0)
412 ;
413 if ((err_c & (SCSSR_ORER | SCSSR_FER | SCSSR_PER)) != 0)
414 return(err_c |= 0x80);
415
416 c = SHREG_SCRDR;
417
418 SHREG_SCSSR &= ~SCSSR_RDRF;
419
420 return(c);
421 }
422
423 /*
424 * GetStrSci
425 * : unsigned char *s;
426 * : int size;
427 */
428 int
429 GetStrSci(s, size)
430 unsigned char *s;
431 int size;
432 {
433
434 for(; size ; size--){
435 *s = GetcSci();
436 if (*s & 0x80)
437 return -1;
438 if (*s == CR){
439 *s = 0;
440 break;
441 }
442 s++;
443 }
444 if (size == 0)
445 *s = 0;
446 return 0;
447 }
448
449 #if 0
450 #define SCI_MAX_UNITS 2
451 #else
452 #define SCI_MAX_UNITS 1
453 #endif
454
455
456 static int
457 sci_match(parent, cfp, aux)
458 struct device *parent;
459 struct cfdata *cfp;
460 void *aux;
461 {
462 #if 0
463 struct shb_attach_args *ia = aux;
464 #endif
465
466 if (strcmp(cfp->cf_driver->cd_name, "sci")
467 || cfp->cf_unit >= SCI_MAX_UNITS)
468 return 0;
469
470 return 1;
471 }
472
473 static void
474 sci_attach(parent, self, aux)
475 struct device *parent, *self;
476 void *aux;
477 {
478 struct sci_softc *sc = (struct sci_softc *)self;
479 struct tty *tp;
480 int irq;
481 struct shb_attach_args *ia = aux;
482
483 sc->sc_hwflags = 0; /* XXX */
484 sc->sc_swflags = 0; /* XXX */
485 sc->sc_fifolen = 0; /* XXX */
486
487 irq = ia->ia_irq;
488
489 SET(sc->sc_hwflags, SCI_HW_DEV_OK);
490 SET(sc->sc_hwflags, SCI_HW_CONSOLE);
491
492 #if 0
493 if (irq != IRQUNK) {
494 sc->sc_ih = shb_intr_establish(irq,
495 IST_EDGE, IPL_SERIAL, sciintr, sc);
496 }
497 #else
498 if (irq != IRQUNK) {
499 sc->sc_ih = shb_intr_establish(SCI_IRQ,
500 IST_EDGE, IPL_SERIAL, sciintr, sc);
501 }
502 #endif
503
504 printf("\n");
505
506 printf("%s: console\n", sc->sc_dev.dv_xname);
507
508 tp = ttymalloc();
509 tp->t_oproc = scistart;
510 tp->t_param = sciparam;
511 tp->t_hwiflow = NULL;
512
513 sc->sc_tty = tp;
514 sc->sc_rbuf = malloc(sci_rbuf_size << 1, M_DEVBUF, M_NOWAIT);
515 if (sc->sc_rbuf == NULL) {
516 printf("%s: unable to allocate ring buffer\n",
517 sc->sc_dev.dv_xname);
518 return;
519 }
520 sc->sc_ebuf = sc->sc_rbuf + (sci_rbuf_size << 1);
521
522 tty_attach(tp);
523 }
524
525 /*
526 * Start or restart transmission.
527 */
528 static void
529 scistart(tp)
530 struct tty *tp;
531 {
532 struct sci_softc *sc = sci_cd.cd_devs[SCIUNIT(tp->t_dev)];
533 int s;
534
535 s = spltty();
536 if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
537 goto out;
538 if (sc->sc_tx_stopped)
539 goto out;
540
541 if (tp->t_outq.c_cc <= tp->t_lowat) {
542 if (ISSET(tp->t_state, TS_ASLEEP)) {
543 CLR(tp->t_state, TS_ASLEEP);
544 wakeup(&tp->t_outq);
545 }
546 selwakeup(&tp->t_wsel);
547 if (tp->t_outq.c_cc == 0)
548 goto out;
549 }
550
551 /* Grab the first contiguous region of buffer space. */
552 {
553 u_char *tba;
554 int tbc;
555
556 tba = tp->t_outq.c_cf;
557 tbc = ndqb(&tp->t_outq, 0);
558
559 (void)splserial();
560
561 sc->sc_tba = tba;
562 sc->sc_tbc = tbc;
563 }
564
565 SET(tp->t_state, TS_BUSY);
566 sc->sc_tx_busy = 1;
567
568 /* Enable transmit completion interrupts if necessary. */
569 SHREG_SCSCR |= SCSCR_TIE | SCSCR_RIE;
570
571 /* Output the first byte of the contiguous buffer. */
572 {
573 if (sc->sc_tbc > 0) {
574 PutcSci(*(sc->sc_tba));
575 sc->sc_tba++;
576 sc->sc_tbc--;
577 }
578 }
579 out:
580 splx(s);
581 return;
582 }
583
584 /*
585 * Set SCI tty parameters from termios.
586 * XXX - Should just copy the whole termios after
587 * making sure all the changes could be done.
588 */
589 static int
590 sciparam(tp, t)
591 struct tty *tp;
592 struct termios *t;
593 {
594 struct sci_softc *sc = sci_cd.cd_devs[SCIUNIT(tp->t_dev)];
595 int ospeed = t->c_ospeed;
596 int s;
597
598 if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
599 return (EIO);
600
601 /* Check requested parameters. */
602 if (ospeed < 0)
603 return (EINVAL);
604 if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
605 return (EINVAL);
606
607 /*
608 * For the console, always force CLOCAL and !HUPCL, so that the port
609 * is always active.
610 */
611 if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
612 ISSET(sc->sc_hwflags, SCI_HW_CONSOLE)) {
613 SET(t->c_cflag, CLOCAL);
614 CLR(t->c_cflag, HUPCL);
615 }
616
617 /*
618 * If there were no changes, don't do anything. This avoids dropping
619 * input and improves performance when all we did was frob things like
620 * VMIN and VTIME.
621 */
622 if (tp->t_ospeed == t->c_ospeed &&
623 tp->t_cflag == t->c_cflag)
624 return (0);
625
626 #if 0
627 /* XXX (msaitoh) */
628 lcr = ISSET(sc->sc_lcr, LCR_SBREAK) | cflag2lcr(t->c_cflag);
629 #endif
630
631 s = splserial();
632
633 /*
634 * Set the FIFO threshold based on the receive speed.
635 *
636 * * If it's a low speed, it's probably a mouse or some other
637 * interactive device, so set the threshold low.
638 * * If it's a high speed, trim the trigger level down to prevent
639 * overflows.
640 * * Otherwise set it a bit higher.
641 */
642 #if 0
643 /* XXX (msaitoh) */
644 if (ISSET(sc->sc_hwflags, SCI_HW_HAYESP))
645 sc->sc_fifo = FIFO_DMA_MODE | FIFO_ENABLE | FIFO_TRIGGER_8;
646 else if (ISSET(sc->sc_hwflags, SCI_HW_FIFO))
647 sc->sc_fifo = FIFO_ENABLE |
648 (t->c_ospeed <= 1200 ? FIFO_TRIGGER_1 :
649 t->c_ospeed <= 38400 ? FIFO_TRIGGER_8 : FIFO_TRIGGER_4);
650 else
651 sc->sc_fifo = 0;
652 #endif
653
654 /* And copy to tty. */
655 tp->t_ispeed = 0;
656 tp->t_ospeed = t->c_ospeed;
657 tp->t_cflag = t->c_cflag;
658
659 if (!sc->sc_heldchange) {
660 if (sc->sc_tx_busy) {
661 sc->sc_heldtbc = sc->sc_tbc;
662 sc->sc_tbc = 0;
663 sc->sc_heldchange = 1;
664 }
665 #if 0
666 /* XXX (msaitoh) */
667 else
668 sci_loadchannelregs(sc);
669 #endif
670 }
671
672 if (!ISSET(t->c_cflag, CHWFLOW)) {
673 /* Disable the high water mark. */
674 sc->sc_r_hiwat = 0;
675 sc->sc_r_lowat = 0;
676 if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
677 CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
678 sci_schedrx(sc);
679 }
680 } else {
681 sc->sc_r_hiwat = sci_rbuf_hiwat;
682 sc->sc_r_lowat = sci_rbuf_lowat;
683 }
684
685 splx(s);
686
687 #ifdef SCI_DEBUG
688 if (sci_debug)
689 scistatus(sc, "sciparam ");
690 #endif
691
692 if (!ISSET(t->c_cflag, CHWFLOW)) {
693 if (sc->sc_tx_stopped) {
694 sc->sc_tx_stopped = 0;
695 scistart(tp);
696 }
697 }
698
699 return (0);
700 }
701
702 void
703 sci_iflush(sc)
704 struct sci_softc *sc;
705 {
706 unsigned char err_c;
707 volatile unsigned char c;
708
709 if (((err_c = SHREG_SCSSR)
710 & (SCSSR_RDRF | SCSSR_ORER | SCSSR_FER | SCSSR_PER)) != 0) {
711
712 if ((err_c & (SCSSR_ORER | SCSSR_FER | SCSSR_PER)) != 0)
713 return;
714
715 c = SHREG_SCRDR;
716
717 SHREG_SCSSR &= ~SCSSR_RDRF;
718 }
719 }
720
721 int sci_getc __P((void));
722 void sci_putc __P((int));
723
724 int
725 sci_getc()
726 {
727
728 return (GetcSci());
729 }
730
731 void
732 sci_putc(int c)
733 {
734
735 PutcSci(c);
736 }
737
738 int
739 sciopen(dev, flag, mode, p)
740 dev_t dev;
741 int flag, mode;
742 struct proc *p;
743 {
744 int unit = SCIUNIT(dev);
745 struct sci_softc *sc;
746 struct tty *tp;
747 int s, s2;
748 int error;
749
750 if (unit >= sci_cd.cd_ndevs)
751 return (ENXIO);
752 sc = sci_cd.cd_devs[unit];
753 if (sc == 0 || !ISSET(sc->sc_hwflags, SCI_HW_DEV_OK) ||
754 sc->sc_rbuf == NULL)
755 return (ENXIO);
756
757 if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
758 return (ENXIO);
759
760 #ifdef KGDB
761 /*
762 * If this is the kgdb port, no other use is permitted.
763 */
764 if (ISSET(sc->sc_hwflags, SCI_HW_KGDB))
765 return (EBUSY);
766 #endif
767
768 tp = sc->sc_tty;
769
770 if (ISSET(tp->t_state, TS_ISOPEN) &&
771 ISSET(tp->t_state, TS_XCLUDE) &&
772 p->p_ucred->cr_uid != 0)
773 return (EBUSY);
774
775 s = spltty();
776
777 /*
778 * Do the following iff this is a first open.
779 */
780 if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
781 struct termios t;
782
783 tp->t_dev = dev;
784
785 s2 = splserial();
786
787 /* Turn on interrupts. */
788 SHREG_SCSCR |= SCSCR_TIE | SCSCR_RIE;
789
790 splx(s2);
791
792 /*
793 * Initialize the termios status to the defaults. Add in the
794 * sticky bits from TIOCSFLAGS.
795 */
796 t.c_ispeed = 0;
797 if (ISSET(sc->sc_hwflags, SCI_HW_CONSOLE)) {
798 t.c_ospeed = SCICN_SPEED;
799 t.c_cflag = sciconscflag;
800 } else {
801 t.c_ospeed = TTYDEF_SPEED;
802 t.c_cflag = TTYDEF_CFLAG;
803 }
804 if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
805 SET(t.c_cflag, CLOCAL);
806 if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
807 SET(t.c_cflag, CRTSCTS);
808 if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
809 SET(t.c_cflag, MDMBUF);
810 /* Make sure sciparam() will do something. */
811 tp->t_ospeed = 0;
812 (void) sciparam(tp, &t);
813 tp->t_iflag = TTYDEF_IFLAG;
814 tp->t_oflag = TTYDEF_OFLAG;
815 tp->t_lflag = TTYDEF_LFLAG;
816 ttychars(tp);
817 ttsetwater(tp);
818
819 s2 = splserial();
820
821 /* Clear the input ring, and unblock. */
822 sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
823 sc->sc_rbavail = sci_rbuf_size;
824 sci_iflush(sc);
825 CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
826 #if 0
827 /* XXX (msaitoh) */
828 sci_hwiflow(sc);
829 #endif
830
831 #ifdef SCI_DEBUG
832 if (sci_debug)
833 scistatus(sc, "sciopen ");
834 #endif
835
836 splx(s2);
837 }
838
839 splx(s);
840
841 error = ttyopen(tp, SCIDIALOUT(dev), ISSET(flag, O_NONBLOCK));
842 if (error)
843 goto bad;
844
845 error = (*linesw[tp->t_line].l_open)(dev, tp);
846 if (error)
847 goto bad;
848
849 return (0);
850
851 bad:
852
853 return (error);
854 }
855
856 int
857 sciclose(dev, flag, mode, p)
858 dev_t dev;
859 int flag, mode;
860 struct proc *p;
861 {
862 struct sci_softc *sc = sci_cd.cd_devs[SCIUNIT(dev)];
863 struct tty *tp = sc->sc_tty;
864
865 /* XXX This is for cons.c. */
866 if (!ISSET(tp->t_state, TS_ISOPEN))
867 return (0);
868
869 (*linesw[tp->t_line].l_close)(tp, flag);
870 ttyclose(tp);
871
872 if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
873 return (0);
874
875 return (0);
876 }
877
878 int
879 sciread(dev, uio, flag)
880 dev_t dev;
881 struct uio *uio;
882 int flag;
883 {
884 struct sci_softc *sc = sci_cd.cd_devs[SCIUNIT(dev)];
885 struct tty *tp = sc->sc_tty;
886
887 return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
888 }
889
890 int
891 sciwrite(dev, uio, flag)
892 dev_t dev;
893 struct uio *uio;
894 int flag;
895 {
896 struct sci_softc *sc = sci_cd.cd_devs[SCIUNIT(dev)];
897 struct tty *tp = sc->sc_tty;
898
899 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
900 }
901
902 struct tty *
903 scitty(dev)
904 dev_t dev;
905 {
906 struct sci_softc *sc = sci_cd.cd_devs[SCIUNIT(dev)];
907 struct tty *tp = sc->sc_tty;
908
909 return (tp);
910 }
911
912 int
913 sciioctl(dev, cmd, data, flag, p)
914 dev_t dev;
915 u_long cmd;
916 caddr_t data;
917 int flag;
918 struct proc *p;
919 {
920 struct sci_softc *sc = sci_cd.cd_devs[SCIUNIT(dev)];
921 struct tty *tp = sc->sc_tty;
922 int error;
923 int s;
924
925 if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
926 return (EIO);
927
928 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
929 if (error >= 0)
930 return (error);
931
932 error = ttioctl(tp, cmd, data, flag, p);
933 if (error >= 0)
934 return (error);
935
936 error = 0;
937
938 s = splserial();
939
940 switch (cmd) {
941 #if 0
942 case TIOCSBRK:
943 scif_break(sc, 1);
944 break;
945
946 case TIOCCBRK:
947 scif_break(sc, 0);
948 break;
949 #endif
950 case TIOCGFLAGS:
951 *(int *)data = sc->sc_swflags;
952 break;
953
954 case TIOCSFLAGS:
955 error = suser(p->p_ucred, &p->p_acflag);
956 if (error)
957 break;
958 sc->sc_swflags = *(int *)data;
959 break;
960
961 default:
962 error = ENOTTY;
963 break;
964 }
965
966 splx(s);
967
968 return (error);
969 }
970
971 integrate void
972 sci_schedrx(sc)
973 struct sci_softc *sc;
974 {
975
976 sc->sc_rx_ready = 1;
977
978 /* Wake up the poller. */
979 #ifdef __GENERIC_SOFT_INTERRUPTS
980 softintr_schedule(sc->sc_si);
981 #else
982 #ifndef __NO_SOFT_SERIAL_INTERRUPT
983 setsoftserial();
984 #else
985 if (!sci_softintr_scheduled) {
986 sci_softintr_scheduled = 1;
987 timeout(scisoft, NULL, 1);
988 }
989 #endif
990 #endif
991 }
992
993 /*
994 * Stop output, e.g., for ^S or output flush.
995 */
996 void
997 scistop(tp, flag)
998 struct tty *tp;
999 int flag;
1000 {
1001 struct sci_softc *sc = sci_cd.cd_devs[SCIUNIT(tp->t_dev)];
1002 int s;
1003
1004 s = splserial();
1005 if (ISSET(tp->t_state, TS_BUSY)) {
1006 /* Stop transmitting at the next chunk. */
1007 sc->sc_tbc = 0;
1008 sc->sc_heldtbc = 0;
1009 if (!ISSET(tp->t_state, TS_TTSTOP))
1010 SET(tp->t_state, TS_FLUSH);
1011 }
1012 splx(s);
1013 }
1014
1015 void
1016 scidiag(arg)
1017 void *arg;
1018 {
1019 struct sci_softc *sc = arg;
1020 int overflows, floods;
1021 int s;
1022
1023 s = splserial();
1024 overflows = sc->sc_overflows;
1025 sc->sc_overflows = 0;
1026 floods = sc->sc_floods;
1027 sc->sc_floods = 0;
1028 sc->sc_errors = 0;
1029 splx(s);
1030
1031 log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf flood%s\n",
1032 sc->sc_dev.dv_xname,
1033 overflows, overflows == 1 ? "" : "s",
1034 floods, floods == 1 ? "" : "s");
1035 }
1036
1037 integrate void
1038 sci_rxsoft(sc, tp)
1039 struct sci_softc *sc;
1040 struct tty *tp;
1041 {
1042 int (*rint) __P((int c, struct tty *tp)) = linesw[tp->t_line].l_rint;
1043 u_char *get, *end;
1044 u_int cc, scc;
1045 u_char ssr;
1046 int code;
1047 int s;
1048
1049 end = sc->sc_ebuf;
1050 get = sc->sc_rbget;
1051 scc = cc = sci_rbuf_size - sc->sc_rbavail;
1052
1053 if (cc == sci_rbuf_size) {
1054 sc->sc_floods++;
1055 if (sc->sc_errors++ == 0)
1056 timeout(scidiag, sc, 60 * hz);
1057 }
1058
1059 while (cc) {
1060 code = get[0];
1061 ssr = get[1];
1062 if (ISSET(ssr, SCSSR_FER | SCSSR_PER)) {
1063 if (ISSET(ssr, SCSSR_FER))
1064 SET(code, TTY_FE);
1065 if (ISSET(ssr, SCSSR_PER))
1066 SET(code, TTY_PE);
1067 }
1068 if ((*rint)(code, tp) == -1) {
1069 /*
1070 * The line discipline's buffer is out of space.
1071 */
1072 if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1073 /*
1074 * We're either not using flow control, or the
1075 * line discipline didn't tell us to block for
1076 * some reason. Either way, we have no way to
1077 * know when there's more space available, so
1078 * just drop the rest of the data.
1079 */
1080 get += cc << 1;
1081 if (get >= end)
1082 get -= sci_rbuf_size << 1;
1083 cc = 0;
1084 } else {
1085 /*
1086 * Don't schedule any more receive processing
1087 * until the line discipline tells us there's
1088 * space available (through scihwiflow()).
1089 * Leave the rest of the data in the input
1090 * buffer.
1091 */
1092 SET(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1093 }
1094 break;
1095 }
1096 get += 2;
1097 if (get >= end)
1098 get = sc->sc_rbuf;
1099 cc--;
1100 }
1101
1102 if (cc != scc) {
1103 sc->sc_rbget = get;
1104 s = splserial();
1105 cc = sc->sc_rbavail += scc - cc;
1106 /* Buffers should be ok again, release possible block. */
1107 if (cc >= sc->sc_r_lowat) {
1108 if (ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1109 CLR(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1110 SHREG_SCSCR |= SCSCR_RIE;
1111 }
1112 #if 0
1113 if (ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED)) {
1114 CLR(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1115 sci_hwiflow(sc);
1116 }
1117 #endif
1118 }
1119 splx(s);
1120 }
1121 }
1122
1123 integrate void
1124 sci_txsoft(sc, tp)
1125 struct sci_softc *sc;
1126 struct tty *tp;
1127 {
1128
1129 CLR(tp->t_state, TS_BUSY);
1130 if (ISSET(tp->t_state, TS_FLUSH))
1131 CLR(tp->t_state, TS_FLUSH);
1132 else
1133 ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
1134 (*linesw[tp->t_line].l_start)(tp);
1135 }
1136
1137 integrate void
1138 sci_stsoft(sc, tp)
1139 struct sci_softc *sc;
1140 struct tty *tp;
1141 {
1142 #if 0
1143 /* XXX (msaitoh) */
1144 u_char msr, delta;
1145 int s;
1146
1147 s = splserial();
1148 msr = sc->sc_msr;
1149 delta = sc->sc_msr_delta;
1150 sc->sc_msr_delta = 0;
1151 splx(s);
1152
1153 if (ISSET(delta, sc->sc_msr_dcd)) {
1154 /*
1155 * Inform the tty layer that carrier detect changed.
1156 */
1157 (void) (*linesw[tp->t_line].l_modem)(tp, ISSET(msr, MSR_DCD));
1158 }
1159
1160 if (ISSET(delta, sc->sc_msr_cts)) {
1161 /* Block or unblock output according to flow control. */
1162 if (ISSET(msr, sc->sc_msr_cts)) {
1163 sc->sc_tx_stopped = 0;
1164 (*linesw[tp->t_line].l_start)(tp);
1165 } else {
1166 sc->sc_tx_stopped = 1;
1167 }
1168 }
1169
1170 #ifdef SCI_DEBUG
1171 if (sci_debug)
1172 scistatus(sc, "sci_stsoft");
1173 #endif
1174 #endif
1175 }
1176
1177 #ifdef __GENERIC_SOFT_INTERRUPTS
1178 void
1179 scisoft(arg)
1180 void *arg;
1181 {
1182 struct sci_softc *sc = arg;
1183 struct tty *tp;
1184
1185 if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
1186 return;
1187
1188 {
1189 #else
1190 void
1191 #ifndef __NO_SOFT_SERIAL_INTERRUPT
1192 scisoft()
1193 #else
1194 scisoft(arg)
1195 void *arg;
1196 #endif
1197 {
1198 struct sci_softc *sc;
1199 struct tty *tp;
1200 int unit;
1201 #ifdef __NO_SOFT_SERIAL_INTERRUPT
1202 int s;
1203
1204 s = splsoftserial();
1205 sci_softintr_scheduled = 0;
1206 #endif
1207
1208 for (unit = 0; unit < sci_cd.cd_ndevs; unit++) {
1209 sc = sci_cd.cd_devs[unit];
1210 if (sc == NULL || !ISSET(sc->sc_hwflags, SCI_HW_DEV_OK))
1211 continue;
1212
1213 if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
1214 continue;
1215
1216 tp = sc->sc_tty;
1217 if (tp == NULL)
1218 continue;
1219 if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0)
1220 continue;
1221 #endif
1222 tp = sc->sc_tty;
1223
1224 if (sc->sc_rx_ready) {
1225 sc->sc_rx_ready = 0;
1226 sci_rxsoft(sc, tp);
1227 }
1228
1229 #if 0
1230 if (sc->sc_st_check) {
1231 sc->sc_st_check = 0;
1232 sci_stsoft(sc, tp);
1233 }
1234 #endif
1235
1236 if (sc->sc_tx_done) {
1237 sc->sc_tx_done = 0;
1238 sci_txsoft(sc, tp);
1239 }
1240 }
1241
1242 #ifndef __GENERIC_SOFT_INTERRUPTS
1243 #ifdef __NO_SOFT_SERIAL_INTERRUPT
1244 splx(s);
1245 #endif
1246 #endif
1247 }
1248
1249 int
1250 sciintr(arg)
1251 void *arg;
1252 {
1253 struct sci_softc *sc = arg;
1254 u_char *put, *end;
1255 u_int cc;
1256 u_short ssr;
1257
1258 if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
1259 return (0);
1260
1261 end = sc->sc_ebuf;
1262 put = sc->sc_rbput;
1263 cc = sc->sc_rbavail;
1264
1265 do {
1266
1267 ssr = SHREG_SCSSR;
1268 #if defined(DDB) || defined(KGDB)
1269 if (ISSET(ssr, SCSSR_BRK)) {
1270 #ifdef DDB
1271 if (ISSET(sc->sc_hwflags, SCI_HW_CONSOLE)) {
1272 console_debugger();
1273 continue;
1274 }
1275 #endif
1276 #ifdef KGDB
1277 if (ISSET(sc->sc_hwflags, SCI_HW_KGDB)) {
1278 kgdb_connect(1);
1279 continue;
1280 }
1281 #endif
1282 }
1283 #endif /* DDB || KGDB */
1284 if ((SHREG_SCSSR & SCSSR_RDRF) != 0) {
1285 if (cc > 0){
1286 put[0] = SHREG_SCRDR;
1287 put[1] = SHREG_SCSSR & 0x00ff;
1288
1289 SHREG_SCSSR &= ~SCSSR_RDRF;
1290
1291 put += 2;
1292 if (put >= end)
1293 put = sc->sc_rbuf;
1294 cc--;
1295 }
1296
1297 /*
1298 * Current string of incoming characters ended because
1299 * no more data was available or we ran out of space.
1300 * Schedule a receive event if any data was received.
1301 * If we're out of space, turn off receive interrupts.
1302 */
1303 sc->sc_rbput = put;
1304 sc->sc_rbavail = cc;
1305 if (!ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED))
1306 sc->sc_rx_ready = 1;
1307
1308 /*
1309 * See if we are in danger of overflowing a buffer. If
1310 * so, use hardware flow control to ease the pressure.
1311 */
1312 if (!ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED) &&
1313 cc < sc->sc_r_hiwat) {
1314 SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1315 #if 0
1316 sci_hwiflow(sc);
1317 #endif
1318 }
1319
1320 /*
1321 * If we're out of space, disable receive interrupts
1322 * until the queue has drained a bit.
1323 */
1324 if (!cc) {
1325 SHREG_SCSCR &= ~SCSCR_RIE;
1326 }
1327 } else {
1328 if (SHREG_SCSSR & SCSSR_RDRF) {
1329 SHREG_SCSCR &= ~(SCSCR_TIE | SCSCR_RIE);
1330 continue;
1331 }
1332 }
1333
1334 #if 0
1335 msr = bus_space_read_1(iot, ioh, sci_msr);
1336 delta = msr ^ sc->sc_msr;
1337 sc->sc_msr = msr;
1338 if (ISSET(delta, sc->sc_msr_mask)) {
1339 SET(sc->sc_msr_delta, delta);
1340
1341 /*
1342 * Pulse-per-second clock signal on edge of DCD?
1343 */
1344 if (ISSET(delta, sc->sc_ppsmask)) {
1345 struct timeval tv;
1346 if (ISSET(msr, sc->sc_ppsmask) ==
1347 sc->sc_ppsassert) {
1348 /* XXX nanotime() */
1349 microtime(&tv);
1350 TIMEVAL_TO_TIMESPEC(&tv,
1351 &sc->ppsinfo.assert_timestamp);
1352 if (sc->ppsparam.mode & PPS_OFFSETASSERT) {
1353 timespecadd(&sc->ppsinfo.assert_timestamp,
1354 &sc->ppsparam.assert_offset,
1355 &sc->ppsinfo.assert_timestamp);
1356 TIMESPEC_TO_TIMEVAL(&tv, &sc->ppsinfo.assert_timestamp);
1357 }
1358
1359 #ifdef PPS_SYNC
1360 if (sc->ppsparam.mode & PPS_HARDPPSONASSERT)
1361 hardpps(&tv, tv.tv_usec);
1362 #endif
1363 sc->ppsinfo.assert_sequence++;
1364 sc->ppsinfo.current_mode =
1365 sc->ppsparam.mode;
1366
1367 } else if (ISSET(msr, sc->sc_ppsmask) ==
1368 sc->sc_ppsclear) {
1369 /* XXX nanotime() */
1370 microtime(&tv);
1371 TIMEVAL_TO_TIMESPEC(&tv,
1372 &sc->ppsinfo.clear_timestamp);
1373 if (sc->ppsparam.mode & PPS_OFFSETCLEAR) {
1374 timespecadd(&sc->ppsinfo.clear_timestamp,
1375 &sc->ppsparam.clear_offset,
1376 &sc->ppsinfo.clear_timestamp);
1377 TIMESPEC_TO_TIMEVAL(&tv, &sc->ppsinfo.clear_timestamp);
1378 }
1379
1380 #ifdef PPS_SYNC
1381 if (sc->ppsparam.mode & PPS_HARDPPSONCLEAR)
1382 hardpps(&tv, tv.tv_usec);
1383 #endif
1384 sc->ppsinfo.clear_sequence++;
1385 sc->ppsinfo.current_mode =
1386 sc->ppsparam.mode;
1387 }
1388 }
1389
1390 /*
1391 * Stop output immediately if we lose the output
1392 * flow control signal or carrier detect.
1393 */
1394 if (ISSET(~msr, sc->sc_msr_mask)) {
1395 sc->sc_tbc = 0;
1396 sc->sc_heldtbc = 0;
1397 #ifdef SCI_DEBUG
1398 if (sci_debug)
1399 scistatus(sc, "sciintr ");
1400 #endif
1401 }
1402
1403 sc->sc_st_check = 1;
1404 }
1405 #endif
1406 } while (SHREG_SCSSR & SCSSR_RDRF);
1407
1408 /*
1409 * Done handling any receive interrupts. See if data can be
1410 * transmitted as well. Schedule tx done event if no data left
1411 * and tty was marked busy.
1412 */
1413 if ((SHREG_SCSSR & SCSSR_TDRE) != 0) {
1414 /*
1415 * If we've delayed a parameter change, do it now, and restart
1416 * output.
1417 */
1418 if (sc->sc_heldchange) {
1419 sc->sc_heldchange = 0;
1420 sc->sc_tbc = sc->sc_heldtbc;
1421 sc->sc_heldtbc = 0;
1422 }
1423
1424 /* Output the next chunk of the contiguous buffer, if any. */
1425 if (sc->sc_tbc > 0) {
1426 PutcSci(*(sc->sc_tba));
1427 sc->sc_tba++;
1428 sc->sc_tbc--;
1429 } else {
1430 /* Disable transmit completion interrupts if necessary. */
1431 #if 0
1432 if (ISSET(sc->sc_ier, IER_ETXRDY))
1433 #endif
1434 SHREG_SCSCR &= ~SCSCR_TIE;
1435
1436 if (sc->sc_tx_busy) {
1437 sc->sc_tx_busy = 0;
1438 sc->sc_tx_done = 1;
1439 }
1440 }
1441 }
1442
1443 /* Wake up the poller. */
1444 #ifdef __GENERIC_SOFT_INTERRUPTS
1445 softintr_schedule(sc->sc_si);
1446 #else
1447 #ifndef __NO_SOFT_SERIAL_INTERRUPT
1448 setsoftserial();
1449 #else
1450 if (!sci_softintr_scheduled) {
1451 sci_softintr_scheduled = 1;
1452 timeout(scisoft, NULL, 1);
1453 }
1454 #endif
1455 #endif
1456
1457 #if NRND > 0 && defined(RND_SCI)
1458 rnd_add_uint32(&sc->rnd_source, iir | lsr);
1459 #endif
1460
1461 return (1);
1462 }
1463
1464 void
1465 scicnprobe(cp)
1466 struct consdev *cp;
1467 {
1468 int maj;
1469
1470 /* locate the major number */
1471 for (maj = 0; maj < nchrdev; maj++)
1472 if (cdevsw[maj].d_open == sciopen)
1473 break;
1474
1475 /* Initialize required fields. */
1476 cp->cn_dev = makedev(maj, 0);
1477 #ifdef SCICONSOLE
1478 cp->cn_pri = CN_REMOTE;
1479 #else
1480 cp->cn_pri = CN_NORMAL;
1481 #endif
1482 }
1483
1484 #define sci_gets GetStrSci
1485 #define sci_puts PutStrSci
1486
1487 void
1488 scicninit(cp)
1489 struct consdev *cp;
1490 {
1491
1492 InitializeSci(SCICN_SPEED);
1493
1494 #if 0
1495 sci_intr_init(); /* XXX msaitoh */
1496 #endif
1497
1498 sci_puts("sci initialized.\n\r");
1499 }
1500
1501 #define sci_getc GetcSci
1502 #define sci_putc PutcSci
1503
1504 int
1505 scicngetc(dev)
1506 dev_t dev;
1507 {
1508 int c;
1509 int s;
1510
1511 s = splserial();
1512 c = sci_getc();
1513 splx(s);
1514
1515 return (c);
1516 }
1517
1518 void
1519 scicnputc(dev, c)
1520 dev_t dev;
1521 int c;
1522 {
1523 int s;
1524
1525 s = splserial();
1526 sci_putc(c);
1527 splx(s);
1528 }
1529