Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/luna68k Refactor and cleanup sio (uPD7201) drivers.



details:   https://anonhg.NetBSD.org/src/rev/e4edab999f06
branches:  trunk
changeset: 1023750:e4edab999f06
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sat Sep 25 15:18:38 2021 +0000

description:
Refactor and cleanup sio (uPD7201) drivers.

- remove confusing syscn*() functions (and its header) and prepare
  explicit siottycninit(), siottycnget() and siottycnput() functions
- use exported struct consdev and cn_tab to initialize siotty console
- enable and handle E/S interrupts to make BREAK signal detected properly
- make CSR (status regsiters) access functions inline static
- make single byte read/write (i.e. cnputc() and cngetc()) functions
  static inline and take struct sio_register rather than sio channel
- use proper integer type (uint16_t) for getsiocsr() as siotty.c
- handle channel dependent CR2A and CR2B registers properly
- use more explicit definitions for RR_* macro used by getsiocsr()
- define and use proper RR0 (read register) values
  (there is no isStatusReg(r) macro used on 4.4BSD/luna68k)

Tested on LUNA with both wscons console and serial console.

diffstat:

 sys/arch/luna68k/dev/lunaws.c      |  25 ++++++---
 sys/arch/luna68k/dev/sio.c         |   5 +-
 sys/arch/luna68k/dev/sioreg.h      |  52 +++++++++----------
 sys/arch/luna68k/dev/siotty.c      |  99 +++++++++++++------------------------
 sys/arch/luna68k/dev/siottyvar.h   |   3 +
 sys/arch/luna68k/dev/siovar.h      |  57 ++++++++++++++++++++-
 sys/arch/luna68k/dev/syscn.h       |   6 --
 sys/arch/luna68k/luna68k/machdep.c |  16 +++---
 8 files changed, 146 insertions(+), 117 deletions(-)

diffs (truncated from 516 to 300 lines):

diff -r ff27c36d2c16 -r e4edab999f06 sys/arch/luna68k/dev/lunaws.c
--- a/sys/arch/luna68k/dev/lunaws.c     Sat Sep 25 15:16:36 2021 +0000
+++ b/sys/arch/luna68k/dev/lunaws.c     Sat Sep 25 15:18:38 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lunaws.c,v 1.38 2021/09/20 08:31:09 tsutsui Exp $ */
+/* $NetBSD: lunaws.c,v 1.39 2021/09/25 15:18:38 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: lunaws.c,v 1.38 2021/09/20 08:31:09 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lunaws.c,v 1.39 2021/09/25 15:18:38 tsutsui Exp $");
 
 #include "opt_wsdisplay_compat.h"
 #include "wsmouse.h"
@@ -50,7 +50,8 @@
 #include <luna68k/dev/omkbdmap.h>
 #include <luna68k/dev/sioreg.h>
 #include <luna68k/dev/siovar.h>
-#include <luna68k/dev/syscn.h>
+
+#include <machine/board.h>
 
 #include "ioconf.h"
 
@@ -261,7 +262,7 @@
        struct ws_softc *sc = arg;
        struct sioreg *sio = sc->sc_ctl;
        uint8_t code;
-       int rr;
+       uint16_t rr;
        bool handled = false;
 
        rr = getsiocsr(sio);
@@ -513,10 +514,14 @@
 static void
 ws_cngetc(void *cookie, u_int *type, int *data)
 {
-       struct ws_softc *sc = cookie;
+       struct ws_softc *sc = cookie;   /* currently unused */
+       struct sioreg *sio, *sio_base;
        int code;
 
-       code = syscngetc((dev_t)1);
+       sio_base = (struct sioreg *)OBIO_SIO;
+       sio = &sio_base[1];     /* channel B */
+
+       code = siogetc(sio);
        omkbd_decode(sc, code, type, data);
 }
 
@@ -528,10 +533,14 @@
 static void
 ws_cnbell(void *cookie, u_int pitch, u_int period, u_int volume)
 {
-       struct ws_softc *sc = cookie;
+       struct ws_softc *sc = cookie;   /* currently unused */
+       struct sioreg *sio, *sio_base;
        struct wskbd_bell_data wbd;
        uint8_t buzcmd;
 
+       sio_base = (struct sioreg *)OBIO_SIO;
+       sio = &sio_base[1];     /* channel B */
+
        /*
         * XXX cnbell(9) man page should describe each args..
         *     (it looks similar to the struct wskbd_bell_data)
@@ -545,7 +554,7 @@
        wbd.volume = volume;
        buzcmd = omkbd_get_buzcmd(sc, &wbd, OMKBD_BUZZER_DEFAULT);
 
-       syscnputc((dev_t)1, buzcmd);
+       sioputc(sio, buzcmd);
 }
 
 /* EXPORT */ void
diff -r ff27c36d2c16 -r e4edab999f06 sys/arch/luna68k/dev/sio.c
--- a/sys/arch/luna68k/dev/sio.c        Sat Sep 25 15:16:36 2021 +0000
+++ b/sys/arch/luna68k/dev/sio.c        Sat Sep 25 15:18:38 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sio.c,v 1.15 2021/08/07 16:18:57 thorpej Exp $ */
+/* $NetBSD: sio.c,v 1.16 2021/09/25 15:18:38 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.15 2021/08/07 16:18:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.16 2021/09/25 15:18:38 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -41,6 +41,7 @@
 #include <machine/autoconf.h>
 
 #include <luna68k/luna68k/isr.h>
+#include <luna68k/dev/sioreg.h>
 #include <luna68k/dev/siovar.h>
 
 #include "ioconf.h"
diff -r ff27c36d2c16 -r e4edab999f06 sys/arch/luna68k/dev/sioreg.h
--- a/sys/arch/luna68k/dev/sioreg.h     Sat Sep 25 15:16:36 2021 +0000
+++ b/sys/arch/luna68k/dev/sioreg.h     Sat Sep 25 15:18:38 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sioreg.h,v 1.4 2011/07/27 14:17:54 tsutsui Exp $ */
+/* $NetBSD: sioreg.h,v 1.5 2021/09/25 15:18:38 tsutsui Exp $ */
 /*
  * Copyright (c) 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -79,17 +79,12 @@
 #define WR6            0x06
 #define WR7            0x07
 
-#define WR2A           WR2
-#define WR2B           (WR2|0x10)
+#define WR2A           WR2     /* on channel A */
+#define WR2B           WR2     /* on channel B */
 
-#define RR0            0x08
-#define RR1            0x09
-#define RR2            0x0A
-#define RR3            0x0B
-#define RR4            0x0C
-
-#define RR2A           RR2
-#define RR2B           (RR2|0x10)
+#define RR0            0x00
+#define RR1            0x01
+#define RR2            0x02    /* only on channel B */
 
 #define WR0_NOP                0x00    /* No Operation */
 #define WR0_SNDABRT    0x08    /* Send Abort (HDLC) */
@@ -108,12 +103,14 @@
 #define WR1_RXALLS     0x10    /* Interrupt Every Characters Received (with Special Char.) */
 #define WR1_RXALL      0x18    /* Interrupt Every Characters Received (without Special Char.) */
 
-#define WR2_INTR_0     0x00    /* Interrupt Priority: RxA TxA RxB TxB E/SA E/SA */
-#define WR2_INTR_1     0x04    /* Interrupt Priority: RxA RxB TxA TxB E/SA E/SA */
-#define WR2_VEC85_1    0x00    /* 8085 Vectored Mode - 1 */
-#define WR2_VEC85_2    0x08    /* 8085 Vectored Mode - 2 */
-#define WR2_VEC86      0x10    /* 8086 Vectored */
-#define WR2_VEC85_3    0x18    /* 8085 Vectored Mode - 3 */
+#define WR2A_INTR_0    0x00    /* Interrupt Priority: RxA TxA RxB TxB E/SA E/SA */
+#define WR2A_INTR_1    0x04    /* Interrupt Priority: RxA RxB TxA TxB E/SA E/SA */
+#define WR2A_VEC85_1   0x00    /* 8085 Vectored Mode - 1 */
+#define WR2A_VEC85_2   0x08    /* 8085 Vectored Mode - 2 */
+#define WR2A_VEC86     0x10    /* 8086 Vectored */
+#define WR2A_VEC85_3   0x18    /* 8085 Vectored Mode - 3 */
+
+/* WR2B has interrupt vector value */
 
 #define WR3_RXENBL     0x01    /* Rx Enable */
 #define WR3_RXCRC      0x08    /* Rx CRC Check */
@@ -156,13 +153,14 @@
 #define RR1_OVERRUN    0x20    /* Data Over Run */
 #define RR1_FRAMING    0x40    /* Framing Error */
 
-#define RR_RXRDY       0x0100  /* Rx Character Available */
-#define RR_INTRPEND    0x0200  /* Interrupt Pending (Channel-A Only) */
-#define RR_TXRDY       0x0400  /* Tx Buffer Empty */
-#define RR_DCD         0x0800  /* Data Carrier Detect [DCD] */
-#define RR_SYNC                0x1000  /* Synchronization */
-#define RR_CTS         0x2000  /* Clear To Send       [CTS] */
-#define RR_BREAK       0x8000  /* Break Detected */
-#define RR_PARITY      0x0010  /* Parity Error */
-#define RR_OVERRUN     0x0020  /* Data Over Run */
-#define RR_FRAMING     0x0040  /* Framing Error */
+/* for getsiocsr() */
+#define RR_RXRDY       (RR0_RXAVAIL  << 8)
+#define RR_INTRPEND    (RR0_INTRPEND << 8)
+#define RR_TXRDY       (RR0_TXEMPTY  << 8)
+#define RR_DCD         (RR0_DCD      << 8)
+#define RR_SYNC                (RR0_SYNC     << 8)
+#define RR_CTS         (RR0_CTS      << 8)
+#define RR_BREAK       (RR0_BREAK    << 8)
+#define RR_PARITY      (RR1_PARITY)
+#define RR_OVERRUN     (RR1_OVERRUN)
+#define RR_FRAMING     (RR1_FRAMING)
diff -r ff27c36d2c16 -r e4edab999f06 sys/arch/luna68k/dev/siotty.c
--- a/sys/arch/luna68k/dev/siotty.c     Sat Sep 25 15:16:36 2021 +0000
+++ b/sys/arch/luna68k/dev/siotty.c     Sat Sep 25 15:18:38 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: siotty.c,v 1.50 2021/09/04 12:54:19 tsutsui Exp $ */
+/* $NetBSD: siotty.c,v 1.51 2021/09/25 15:18:38 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: siotty.c,v 1.50 2021/09/04 12:54:19 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siotty.c,v 1.51 2021/09/25 15:18:38 tsutsui Exp $");
 
 #include "opt_ddb.h"
 #include "siotty.h"
@@ -55,7 +55,6 @@
 
 #include <luna68k/dev/sioreg.h>
 #include <luna68k/dev/siovar.h>
-#include <luna68k/dev/syscn.h>
 
 #include "ioconf.h"
 
@@ -63,7 +62,7 @@
 
 static const uint8_t ch0_regs[6] = {
        WR0_RSTINT,                             /* reset E/S interrupt */
-       WR1_RXALLS | WR1_TXENBL,                /* Rx per char, Tx */
+       WR1_RXALLS | WR1_TXENBL | WR1_ESENBL,   /* Rx per char, Tx, E/S */
        0,                                      /* */
        WR3_RX8BIT | WR3_RXENBL,                /* Rx */
        WR4_BAUD96 | WR4_STOP1,                 /* Tx/Rx */
@@ -129,6 +128,10 @@
 static dev_type_tty(siotty);
 static dev_type_poll(siopoll);
 
+static dev_type_cninit(siottycninit);
+static dev_type_cngetc(siottycngetc);
+static dev_type_cnputc(siottycnputc);
+
 const struct cdevsw siotty_cdevsw = {
        .d_open = sioopen,
        .d_close = sioclose,
@@ -177,8 +180,8 @@
                sc->sc_flags = TIOCFLAG_SOFTCAR;
        } else {
                setsioreg(sc->sc_ctl, WR0, WR0_CHANRST);
-               setsioreg(sc->sc_ctl, WR2A, WR2_VEC86 | WR2_INTR_1);
-               setsioreg(sc->sc_ctl, WR2B, 0);
+               setsioreg(&siosc->sc_ctl[0], WR2A, WR2A_VEC86 | WR2A_INTR_1);
+               setsioreg(&siosc->sc_ctl[1], WR2B, 0);
                setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
                setsioreg(sc->sc_ctl, WR4, sc->sc_wr[WR4]);
                setsioreg(sc->sc_ctl, WR3, sc->sc_wr[WR3]);
@@ -227,9 +230,11 @@
        sio = sc->sc_ctl;
        rr = getsiocsr(sio);
        if ((rr & RR_BREAK) != 0) {
-               sio->sio_cmd = WR0_RSTINT;
                cn_check_magic(sc->sc_tty->t_dev, CNC_BREAK, siotty_cnm_state);
        }
+       /* XXX should handle RR_DCD and RR_CTS */
+       sio->sio_cmd = WR0_RSTINT;
+
        if ((rr & RR_RXRDY) != 0) {
                do {
                        if (cc > 0) {
@@ -669,35 +674,13 @@
        return sc->sc_tty;
 }
 
-/*--------------------  miscelleneous routine --------------------*/
-
-/* EXPORT */ void
-setsioreg(struct sioreg *sio, int regno, int val)
-{
-
-       if (regno != 0)
-               sio->sio_cmd = regno;   /* DELAY(); */
-       sio->sio_cmd = val;             /* DELAY(); */
-}
-
-/* EXPORT */ uint16_t
-getsiocsr(struct sioreg *sio)
-{
-       int val;
-
-       val = sio->sio_stat << 8;       /* DELAY(); */
-       sio->sio_cmd = 1;               /* DELAY(); */
-       val |= sio->sio_stat;           /* DELAY(); */
-       return val;
-}
-
 /*---------------------  console interface ----------------------*/
 
-struct consdev syscons = {
+struct consdev siottycons = {
        .cn_probe = NULL,
-       .cn_init  = NULL,
-       .cn_getc  = syscngetc,
-       .cn_putc  = syscnputc,
+       .cn_init  = siottycninit,
+       .cn_getc  = siottycngetc,
+       .cn_putc  = siottycnputc,
        .cn_pollc = nullcnpollc,
        .cn_bell  = NULL,
        .cn_halt  = NULL,
@@ -706,25 +689,28 @@
        .cn_pri   = CN_REMOTE,
 };
 
-/* EXPORT */ void
-syscninit(int channel)
+static void



Home | Main Index | Thread Index | Old Index