From: Markus Pfeiffer Date: Wed, 5 Feb 2014 23:01:44 +0000 (+0000) Subject: Start porting ucom. X-Git-Tag: v3.9.0~399 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/fd10b026aaf1eff68b3a11f3c306a3978900d3aa Start porting ucom. * import serial.h from freebsd * comment almost everything out in usb_serial.c * make the whole thing compile --- diff --git a/sys/bus/u4b/Makefile b/sys/bus/u4b/Makefile index 2728343903..6203b10bed 100644 --- a/sys/bus/u4b/Makefile +++ b/sys/bus/u4b/Makefile @@ -1,5 +1,5 @@ #SUBDIR= misc serial template -SUBDIR= usb audio controller input net quirk storage wlan +SUBDIR= usb audio controller input net quirk serial storage wlan .include diff --git a/sys/bus/u4b/serial/Makefile b/sys/bus/u4b/serial/Makefile index f5d0dad2dc..a6fe4f746b 100644 --- a/sys/bus/u4b/serial/Makefile +++ b/sys/bus/u4b/serial/Makefile @@ -1,5 +1,5 @@ # MISSING: ucom -SUBDIR= u3g uark ubsa ubser uchcom ucom ucycom ufoma uftdi ugensa uipaq ulpt \ +SUBDIR= ucom u3g uark ubsa ubser uchcom ucom ucycom ufoma uftdi ugensa uipaq ulpt \ umcs umct umodem umoscom uplcom uslcom uvisor uvscom .include diff --git a/sys/bus/u4b/serial/ubser.c b/sys/bus/u4b/serial/ubser.c index 14f131cfb0..7f0b3f9a04 100644 --- a/sys/bus/u4b/serial/ubser.c +++ b/sys/bus/u4b/serial/ubser.c @@ -88,6 +88,7 @@ #include #include #include +#include #include #include diff --git a/sys/bus/u4b/serial/ufoma.c b/sys/bus/u4b/serial/ufoma.c index 5398d9893b..b764dd7def 100644 --- a/sys/bus/u4b/serial/ufoma.c +++ b/sys/bus/u4b/serial/ufoma.c @@ -96,6 +96,7 @@ #include #include #include +#include #include #include diff --git a/sys/bus/u4b/serial/uftdi.c b/sys/bus/u4b/serial/uftdi.c index 07e1e03d44..472b121bef 100644 --- a/sys/bus/u4b/serial/uftdi.c +++ b/sys/bus/u4b/serial/uftdi.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include diff --git a/sys/bus/u4b/serial/umodem.c b/sys/bus/u4b/serial/umodem.c index 2587164a54..19507801d1 100644 --- a/sys/bus/u4b/serial/umodem.c +++ b/sys/bus/u4b/serial/umodem.c @@ -92,6 +92,7 @@ #include #include #include +#include #include #include diff --git a/sys/bus/u4b/serial/umoscom.c b/sys/bus/u4b/serial/umoscom.c index 8e07ecb9e1..1e223018b0 100644 --- a/sys/bus/u4b/serial/umoscom.c +++ b/sys/bus/u4b/serial/umoscom.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/sys/bus/u4b/serial/uplcom.c b/sys/bus/u4b/serial/uplcom.c index efde7f80b3..65e571f445 100644 --- a/sys/bus/u4b/serial/uplcom.c +++ b/sys/bus/u4b/serial/uplcom.c @@ -96,6 +96,7 @@ #include #include #include +#include #include #include diff --git a/sys/bus/u4b/serial/usb_serial.c b/sys/bus/u4b/serial/usb_serial.c index ec1e9834c1..789f876ac9 100644 --- a/sys/bus/u4b/serial/usb_serial.c +++ b/sys/bus/u4b/serial/usb_serial.c @@ -80,6 +80,7 @@ #include #include #include +#include #include #include @@ -149,6 +150,27 @@ static void ucom_break(struct ucom_softc *, uint8_t); static void ucom_dtr(struct ucom_softc *, uint8_t); static void ucom_rts(struct ucom_softc *, uint8_t); + +static d_open_t ucom_open; +static d_close_t ucom_close; +static d_read_t ucom_read; +static d_write_t ucom_write; +static d_ioctl_t ucom_ioctl; +static int ucom_param(struct tty *tp, struct termios *t); +static int ucom_modem(struct tty *tp, int sigon, int sigoff); + +static struct dev_ops ucom_ops = { + { "ucom", 0, D_TTY }, + .d_open = ucom_open, + .d_close = ucom_close, + .d_read = ucom_read, + .d_write = ucom_write, + .d_ioctl = ucom_ioctl, + .d_kqfilter = ttykqfilter, + .d_revoke = ttyrevoke +}; + +#if XXX static tsw_open_t ucom_open; static tsw_close_t ucom_close; static tsw_ioctl_t ucom_ioctl; @@ -169,6 +191,8 @@ static struct ttydevsw ucom_class = { .tsw_modem = ucom_modem, .tsw_free = ucom_free, }; +#endif + MODULE_DEPEND(ucom, usb, 1, 1, 1); MODULE_VERSION(ucom, 1); @@ -187,7 +211,7 @@ ucom_init(void *arg) ucom_unrhdr = new_unrhdr(0, UCOM_UNIT_MAX - 1, NULL); lockinit(&ucom_lock, "UCOM LOCK", 0, 0); } -SYSINIT(ucom_init, SI_SUB_KLD - 1, SI_ORDER_ANY, ucom_init, NULL); +SYSINIT(ucom_init, SI_BOOT2_KLD - 1, SI_ORDER_ANY, ucom_init, NULL); static void ucom_uninit(void *arg) @@ -203,7 +227,7 @@ ucom_uninit(void *arg) lockuninit(&ucom_lock); } -SYSUNINIT(ucom_uninit, SI_SUB_KLD - 2, SI_ORDER_ANY, ucom_uninit, NULL); +SYSUNINIT(ucom_uninit, SI_BOOT2_KLD - 2, SI_ORDER_ANY, ucom_uninit, NULL); /* * Mark a unit number (the X in cuaUX) as in use. @@ -362,7 +386,7 @@ ucom_drain(struct ucom_super_softc *ssc) { lockmgr(&ucom_lock, LK_EXCLUSIVE); while (ssc->sc_refs > 0) { - printf("ucom: Waiting for a TTY device to close.\n"); + kprintf("ucom: Waiting for a TTY device to close.\n"); usb_pause_mtx(&ucom_lock, hz); } lockmgr(&ucom_lock, LK_RELEASE); @@ -371,13 +395,15 @@ ucom_drain(struct ucom_super_softc *ssc) void ucom_drain_all(void *arg) { +#if XXX lockmgr(&ucom_lock, LK_EXCLUSIVE); while (ucom_close_refs > 0) { - printf("ucom: Waiting for all detached TTY " + kprintf("ucom: Waiting for all detached TTY " "devices to have open fds closed.\n"); usb_pause_mtx(&ucom_lock, hz); } lockmgr(&ucom_lock, LK_RELEASE); +#endif } static int @@ -386,7 +412,10 @@ ucom_attach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc) struct tty *tp; char buf[32]; /* temporary TTY device name buffer */ + /* tp = tty_alloc_mutex(&ucom_class, sc, sc->sc_lock); + */ + tp = NULL; if (tp == NULL) return (ENOMEM); @@ -408,8 +437,9 @@ ucom_attach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc) ssc->sc_unit); } } + /* tty_makedev(tp, NULL, "%s", buf); - + */ sc->sc_tty = tp; DPRINTF("ttycreate: %s\n", buf); @@ -424,7 +454,9 @@ ucom_attach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc) ucom_cons_softc = sc; + /* tty_init_console(tp, ucom_cons_baud); + */ UCOM_MTX_LOCK(ucom_cons_softc); ucom_cons_rx_low = 0; @@ -432,8 +464,10 @@ ucom_attach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc) ucom_cons_tx_low = 0; ucom_cons_tx_high = 0; sc->sc_flag |= UCOM_FLAG_CONSOLE; + /* ucom_open(ucom_cons_softc->sc_tty); ucom_param(ucom_cons_softc->sc_tty, &tp->t_termios_init_in); + */ UCOM_MTX_UNLOCK(ucom_cons_softc); } @@ -449,7 +483,9 @@ ucom_detach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc) if (sc->sc_flag & UCOM_FLAG_CONSOLE) { UCOM_MTX_LOCK(ucom_cons_softc); + #if XXX ucom_close(ucom_cons_softc->sc_tty); + #endif sc->sc_flag &= ~UCOM_FLAG_CONSOLE; UCOM_MTX_UNLOCK(ucom_cons_softc); ucom_cons_softc = NULL; @@ -467,11 +503,15 @@ ucom_detach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc) ucom_close_refs++; lockmgr(&ucom_lock, LK_RELEASE); + /* tty_lock(tp); + */ - ucom_close(tp); /* close, if any */ + /* + ucom_close(tp); *//* close, if any */ - tty_rel_gone(tp); + /*tty_rel_gone(tp); + */ UCOM_MTX_LOCK(sc); /* @@ -509,16 +549,20 @@ ucom_set_pnpinfo_usb(struct ucom_super_softc *ssc, device_t dev) * string which is registered above: */ if (ssc->sc_sysctl_ttyname == NULL) { + /* ssc->sc_sysctl_ttyname = SYSCTL_ADD_STRING(NULL, SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "ttyname", CTLFLAG_RD, ssc->sc_ttyname, 0, "TTY device basename"); + */ } if (ssc->sc_sysctl_ttyports == NULL) { + /* ssc->sc_sysctl_ttyports = SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "ttyports", CTLFLAG_RD, NULL, ssc->sc_subunits, "Number of ports"); + */ } } @@ -670,10 +714,15 @@ ucom_cfg_open(struct usb_proc_msg *_task) } static int -ucom_open(struct tty *tp) +ucom_open(struct dev_open_args *ap) { - struct ucom_softc *sc = tty_softc(tp); + #if XXX + cdev_t dev = ap->a_head.a_dev; + struct ucom_softc *sc; +// = tty_softc(tp); int error; + + sc = devclass_get_softc(ucom_devclass, unit); UCOM_MTX_ASSERT(sc, MA_OWNED); @@ -730,6 +779,7 @@ ucom_open(struct tty *tp) ucom_break(sc, 0); ucom_status_change(sc); + #endif return (0); } @@ -752,9 +802,10 @@ ucom_cfg_close(struct usb_proc_msg *_task) } } -static void -ucom_close(struct tty *tp) +static int +ucom_close(struct dev_close_args *ap) { + #if XXX struct ucom_softc *sc = tty_softc(tp); UCOM_MTX_ASSERT(sc, MA_OWNED); @@ -776,11 +827,14 @@ ucom_close(struct tty *tp) if (sc->sc_callback->ucom_stop_read) { (sc->sc_callback->ucom_stop_read) (sc); } +#endif + return (0); } static void ucom_inwakeup(struct tty *tp) { +#if XXX struct ucom_softc *sc = tty_softc(tp); uint16_t pos; @@ -822,11 +876,25 @@ ucom_inwakeup(struct tty *tp) ucom_rts(sc, 0); sc->sc_flag &= ~UCOM_FLAG_INWAKEUP; +#endif +} + +static int +ucom_read(struct dev_read_args *ap) +{ + return (0); } static int -ucom_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) +ucom_write(struct dev_write_args *ap) { + return (0); +} + +static int +ucom_ioctl(struct dev_ioctl_args *ap) +{ +#if XXX struct ucom_softc *sc = tty_softc(tp); int error; @@ -866,12 +934,15 @@ ucom_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) break; } return (error); +#endif + return (0); } static int ucom_modem(struct tty *tp, int sigon, int sigoff) { - struct ucom_softc *sc = tty_softc(tp); + struct ucom_softc *sc; +// = tty_softc(tp); uint8_t onoff; UCOM_MTX_ASSERT(sc, MA_OWNED); @@ -1102,31 +1173,39 @@ ucom_cfg_status_change(struct usb_proc_msg *_task) DPRINTF("DCD changed to %d\n", onoff); + /* ttydisc_modem(tp, onoff); + */ } if ((lsr_delta & ULSR_BI) && (sc->sc_lsr & ULSR_BI)) { DPRINTF("BREAK detected\n"); + /* ttydisc_rint(tp, 0, TRE_BREAK); ttydisc_rint_done(tp); + */ } if ((lsr_delta & ULSR_FE) && (sc->sc_lsr & ULSR_FE)) { DPRINTF("Frame error detected\n"); + /* ttydisc_rint(tp, 0, TRE_FRAMING); ttydisc_rint_done(tp); + */ } if ((lsr_delta & ULSR_PE) && (sc->sc_lsr & ULSR_PE)) { DPRINTF("Parity error detected\n"); + /* ttydisc_rint(tp, 0, TRE_PARITY); ttydisc_rint_done(tp); + */ } } @@ -1171,7 +1250,8 @@ ucom_cfg_param(struct usb_proc_msg *_task) static int ucom_param(struct tty *tp, struct termios *t) { - struct ucom_softc *sc = tty_softc(tp); + struct ucom_softc *sc; +// = tty_softc(tp); uint8_t opened; int error; @@ -1188,7 +1268,9 @@ ucom_param(struct tty *tp, struct termios *t) * some parameters must be set early in ttydev_open(), * possibly before calling ttydevsw_open(). */ + /* error = ucom_open(tp); + */ if (error) { goto done; } @@ -1236,7 +1318,9 @@ ucom_param(struct tty *tp, struct termios *t) done: if (error) { if (opened) { + /* ucom_close(tp); + */ } } return (error); @@ -1245,6 +1329,7 @@ done: static void ucom_outwakeup(struct tty *tp) { + #if XXX struct ucom_softc *sc = tty_softc(tp); UCOM_MTX_ASSERT(sc, MA_OWNED); @@ -1256,6 +1341,7 @@ ucom_outwakeup(struct tty *tp) return; } ucom_start_transfers(sc); + #endif } /*------------------------------------------------------------------------* @@ -1269,6 +1355,7 @@ uint8_t ucom_get_data(struct ucom_softc *sc, struct usb_page_cache *pc, uint32_t offset, uint32_t len, uint32_t *actlen) { + #if XXX struct usb_page_search res; struct tty *tp = sc->sc_tty; uint32_t cnt; @@ -1323,8 +1410,9 @@ ucom_get_data(struct ucom_softc *sc, struct usb_page_cache *pc, res.length = len; } /* copy data directly into USB buffer */ + /* cnt = ttydisc_getc(tp, res.buffer, res.length); - + */ offset += cnt; len -= cnt; @@ -1341,6 +1429,7 @@ ucom_get_data(struct ucom_softc *sc, struct usb_page_cache *pc, if (actlen[0] == 0) { return (0); } + #endif return (1); } @@ -1348,6 +1437,7 @@ void ucom_put_data(struct ucom_softc *sc, struct usb_page_cache *pc, uint32_t offset, uint32_t len) { + #if XXX struct usb_page_search res; struct tty *tp = sc->sc_tty; char *buf; @@ -1455,6 +1545,7 @@ ucom_put_data(struct ucom_softc *sc, struct usb_page_cache *pc, } } ttydisc_rint_done(tp); + #endif } static void @@ -1477,10 +1568,13 @@ static cn_init_t ucom_cninit; static cn_term_t ucom_cnterm; static cn_getc_t ucom_cngetc; static cn_putc_t ucom_cnputc; + +#if XXX +/* static cn_grab_t ucom_cngrab; static cn_ungrab_t ucom_cnungrab; - CONSOLE_DRIVER(ucom); +*/ static void ucom_cnprobe(struct consdev *cp) @@ -1490,7 +1584,9 @@ ucom_cnprobe(struct consdev *cp) else cp->cn_pri = CN_DEAD; + /* strlcpy(cp->cn_name, "ucom", sizeof(cp->cn_name)); + */ } static void @@ -1538,14 +1634,19 @@ ucom_cngetc(struct consdev *cd) UCOM_MTX_UNLOCK(sc); /* poll if necessary */ + /* if (kdb_active && sc->sc_callback->ucom_poll) (sc->sc_callback->ucom_poll) (sc); - + */ return (c); } static void +ucom_cnputc(void *cd, int c) + /* ucom_cnputc(struct consdev *cd, int c) + */ + { struct ucom_softc *sc = ucom_cons_softc; unsigned int temp; @@ -1574,14 +1675,16 @@ ucom_cnputc(struct consdev *cd, int c) UCOM_MTX_UNLOCK(sc); /* poll if necessary */ + #if XXX if (kdb_active && sc->sc_callback->ucom_poll) { (sc->sc_callback->ucom_poll) (sc); /* simple flow control */ if (temp == 0) goto repeat; } + #endif } - +#endif /*------------------------------------------------------------------------* * ucom_ref * diff --git a/sys/bus/u4b/serial/usb_serial.h b/sys/bus/u4b/serial/usb_serial.h index 8ab6c04025..55b97ee9f7 100644 --- a/sys/bus/u4b/serial/usb_serial.h +++ b/sys/bus/u4b/serial/usb_serial.h @@ -197,7 +197,7 @@ struct ucom_softc { uint8_t sc_jitterbuf[UCOM_JITTERBUF_SIZE]; }; -#define UCOM_MTX_ASSERT(sc, what) KKASSERT(lockowned((sc)->sc_lock)==what) +#define UCOM_MTX_ASSERT(sc, what) KKASSERT(lockowned((sc)->sc_lock)) #define UCOM_MTX_LOCK(sc) lockmgr((sc)->sc_lock, LK_EXCLUSIVE) #define UCOM_MTX_UNLOCK(sc) lockmgr((sc)->sc_lock, LK_RELEASE) #define UCOM_UNLOAD_DRAIN(x) \ diff --git a/sys/bus/u4b/serial/uslcom.c b/sys/bus/u4b/serial/uslcom.c index aa266665b3..13150b686f 100644 --- a/sys/bus/u4b/serial/uslcom.c +++ b/sys/bus/u4b/serial/uslcom.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include diff --git a/sys/bus/u4b/serial/uvscom.c b/sys/bus/u4b/serial/uvscom.c index 62f201c428..be22593e3c 100644 --- a/sys/bus/u4b/serial/uvscom.c +++ b/sys/bus/u4b/serial/uvscom.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include diff --git a/sys/sys/serial.h b/sys/sys/serial.h new file mode 100644 index 0000000000..1a149a9625 --- /dev/null +++ b/sys/sys/serial.h @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2004 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file contains definitions which pertain to serial ports as such, + * (both async and sync), but which do not necessarily have anything to + * do with tty processing. + * + * $FreeBSD$ + */ + +#ifndef _SYS_SERIAL_H_ +#define _SYS_SERIAL_H_ + + +/* + * Indentification of modem control signals. These definitions match + * the TIOCMGET definitions in shifted a bit down, and + * that identity is enforced with CTASSERT at the bottom of kern/tty.c + * Both the modem bits and delta bits must fit in 16 bit. + */ +#define SER_DTR 0x0001 /* data terminal ready */ +#define SER_RTS 0x0002 /* request to send */ +#define SER_STX 0x0004 /* secondary transmit */ +#define SER_SRX 0x0008 /* secondary receive */ +#define SER_CTS 0x0010 /* clear to send */ +#define SER_DCD 0x0020 /* data carrier detect */ +#define SER_RI 0x0040 /* ring indicate */ +#define SER_DSR 0x0080 /* data set ready */ + +#define SER_MASK_STATE 0x00ff + +/* Delta bits, used to indicate which signals should/was affected */ +#define SER_DELTA(x) ((x) << 8) + +#define SER_DDTR SER_DELTA(SER_DTR) +#define SER_DRTS SER_DELTA(SER_RTS) +#define SER_DSTX SER_DELTA(SER_STX) +#define SER_DSRX SER_DELTA(SER_SRX) +#define SER_DCTS SER_DELTA(SER_CTS) +#define SER_DDCD SER_DELTA(SER_DCD) +#define SER_DRI SER_DELTA(SER_RI) +#define SER_DDSR SER_DELTA(SER_DSR) + +#define SER_MASK_DELTA SER_DELTA(SER_MASK_STATE) + +#ifdef _KERNEL +/* + * Specification of interrupt sources typical for serial ports. These are + * useful when some umbrella driver like scc(4) has enough knowledge of + * the hardware to obtain the set of pending interrupts but does not itself + * handle the interrupt. Each interrupt source can be given an interrupt + * resource for which inferior drivers can install handlers. The lower 16 + * bits are kept free for the signals above. + */ +#define SER_INT_OVERRUN 0x010000 +#define SER_INT_BREAK 0x020000 +#define SER_INT_RXREADY 0x040000 +#define SER_INT_SIGCHG 0x080000 +#define SER_INT_TXIDLE 0x100000 + +#define SER_INT_MASK 0xff0000 +#define SER_INT_SIGMASK (SER_MASK_DELTA | SER_MASK_STATE) + +#ifndef LOCORE +typedef int serdev_intr_t(void*); +#endif + +#endif /* _KERNEL */ + +#endif /* !_SYS_SERIAL_H_ */