[PATCH 8/9] Patching USB serial drivers and Termios for use in RTEMS

Kevin Kirspel kevin-kirspel at idexx.com
Thu Feb 9 03:21:39 UTC 2017


---
 freebsd/sys/dev/usb/serial/uplcom.c        |  22 ++++
 freebsd/sys/dev/usb/serial/usb_serial.c    |  24 ++++
 freebsd/sys/dev/usb/usb_dev.c              |  18 +++
 freebsd/sys/fs/devfs/devfs_int.h           |   2 +-
 freebsd/sys/kern/kern_conf.c               |  16 +--
 freebsd/sys/kern/subr_taskqueue.c          |  10 --
 freebsd/sys/kern/tty.c                     | 179 ++++++++++++++++++++++++++++-
 freebsd/sys/kern/tty_ttydisc.c             |  22 ++++
 freebsd/sys/sys/_termios.h                 |  30 +++++
 freebsd/sys/sys/conf.h                     |   2 +
 freebsd/sys/sys/file.h                     |   4 +
 freebsd/sys/sys/proc.h                     |   2 +
 freebsd/sys/sys/ttydefaults.h              |  15 +++
 rtemsbsd/include/rtems/bsd/local/opt_gdb.h |   1 +
 rtemsbsd/include/rtems/bsd/local/opt_usb.h |   2 +-
 rtemsbsd/sys/fs/devfs/devfs_devs.c         |  86 +++++++++++++-
 16 files changed, 406 insertions(+), 29 deletions(-)
 mode change 100644 => 100755 freebsd/sys/dev/usb/serial/uplcom.c
 mode change 100644 => 100755 freebsd/sys/dev/usb/serial/usb_serial.c
 mode change 100644 => 100755 freebsd/sys/dev/usb/usb_dev.c
 mode change 100644 => 100755 freebsd/sys/fs/devfs/devfs_int.h
 mode change 100644 => 100755 freebsd/sys/kern/kern_conf.c
 mode change 100644 => 100755 freebsd/sys/kern/subr_taskqueue.c
 mode change 100644 => 100755 freebsd/sys/kern/tty.c
 mode change 100644 => 100755 freebsd/sys/kern/tty_ttydisc.c
 mode change 100644 => 100755 freebsd/sys/sys/_termios.h
 mode change 100644 => 100755 freebsd/sys/sys/conf.h
 mode change 100644 => 100755 freebsd/sys/sys/file.h
 mode change 100644 => 100755 freebsd/sys/sys/proc.h
 mode change 100644 => 100755 freebsd/sys/sys/ttydefaults.h
 create mode 100755 rtemsbsd/include/rtems/bsd/local/opt_gdb.h
 mode change 100644 => 100755 rtemsbsd/include/rtems/bsd/local/opt_usb.h

diff --git a/freebsd/sys/dev/usb/serial/uplcom.c b/freebsd/sys/dev/usb/serial/uplcom.c
old mode 100644
new mode 100755
index 31b5867..9ad11b7
--- a/freebsd/sys/dev/usb/serial/uplcom.c
+++ b/freebsd/sys/dev/usb/serial/uplcom.c
@@ -651,6 +651,9 @@ uplcom_pre_param(struct ucom_softc *ucom, struct termios *t)
 {
 	struct uplcom_softc *sc = ucom->sc_parent;
 	uint8_t i;
+#ifdef __rtems__
+	uint32_t c_ospeed = rtems_bsd_get_output_speed(t);
+#endif /* __rtems__ */
 
 	DPRINTF("\n");
 
@@ -666,15 +669,27 @@ uplcom_pre_param(struct ucom_softc *ucom, struct termios *t)
 	 */
 	if (sc->sc_chiptype != TYPE_PL2303HX) {
 		for (i = 0; i < N_UPLCOM_RATES; i++) {
+#ifndef __rtems__
 			if (uplcom_rates[i] == t->c_ospeed)
+#else /* __rtems__ */
+			if (uplcom_rates[i] == c_ospeed)
+#endif /* __rtems__ */
 				return (0);
 		}
  	} else {
+#ifndef __rtems__
 		if (t->c_ospeed <= 6000000)
+#else /* __rtems__ */
+		if (c_ospeed <= 6000000)
+#endif /* __rtems__ */
 			return (0);
 	}
 
+#ifndef __rtems__
 	DPRINTF("uplcom_param: bad baud rate (%d)\n", t->c_ospeed);
+#else /* __rtems__ */
+	DPRINTF("uplcom_param: bad baud rate (%d)\n", c_ospeed);
+#endif /* __rtems__ */
 	return (EIO);
 }
 
@@ -684,12 +699,19 @@ uplcom_cfg_param(struct ucom_softc *ucom, struct termios *t)
 	struct uplcom_softc *sc = ucom->sc_parent;
 	struct usb_cdc_line_state ls;
 	struct usb_device_request req;
+#ifdef __rtems__
+	uint32_t c_ospeed = rtems_bsd_get_output_speed(t);
+#endif /* __rtems__ */
 
 	DPRINTF("sc = %p\n", sc);
 
 	memset(&ls, 0, sizeof(ls));
 
+#ifndef __rtems__
 	USETDW(ls.dwDTERate, t->c_ospeed);
+#else /* __rtems__ */
+	USETDW(ls.dwDTERate, c_ospeed);
+#endif /* __rtems__ */
 
 	if (t->c_cflag & CSTOPB) {
 		ls.bCharFormat = UCDC_STOP_BIT_2;
diff --git a/freebsd/sys/dev/usb/serial/usb_serial.c b/freebsd/sys/dev/usb/serial/usb_serial.c
old mode 100644
new mode 100755
index f425a16..f9f735a
--- a/freebsd/sys/dev/usb/serial/usb_serial.c
+++ b/freebsd/sys/dev/usb/serial/usb_serial.c
@@ -82,7 +82,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/priv.h>
 #include <sys/cons.h>
 
+#ifndef __rtems__
 #include <dev/uart/uart_ppstypes.h>
+#endif /* __rtems__ */
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -99,11 +101,13 @@ __FBSDID("$FreeBSD$");
 
 static SYSCTL_NODE(_hw_usb, OID_AUTO, ucom, CTLFLAG_RW, 0, "USB ucom");
 
+#ifndef __rtems__
 static int ucom_pps_mode;
 
 SYSCTL_INT(_hw_usb_ucom, OID_AUTO, pps_mode, CTLFLAG_RWTUN,
     &ucom_pps_mode, 0, 
     "pulse capture mode: 0/1/2=disabled/CTS/DCD; add 0x10 to invert");
+#endif /* __rtems__ */
 
 #ifdef USB_DEBUG
 static int ucom_debug = 0;
@@ -418,10 +422,12 @@ ucom_attach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc)
 
 	sc->sc_tty = tp;
 
+#ifndef __rtems__
 	sc->sc_pps.ppscap = PPS_CAPTUREBOTH;
 	sc->sc_pps.driver_abi = PPS_ABI_VERSION;
 	sc->sc_pps.driver_mtx = sc->sc_mtx;
 	pps_init_abi(&sc->sc_pps);
+#endif /* __rtems__ */
 
 	DPRINTF("ttycreate: %s\n", buf);
 
@@ -872,8 +878,10 @@ ucom_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
 		} else {
 			error = ENOIOCTL;
 		}
+#ifndef __rtems__
 		if (error == ENOIOCTL)
 			error = pps_ioctl(cmd, data, &sc->sc_pps);
+#endif /* __rtems__ */
 		break;
 	}
 	return (error);
@@ -1080,7 +1088,9 @@ ucom_cfg_status_change(struct usb_proc_msg *_task)
 	uint8_t new_lsr;
 	uint8_t msr_delta;
 	uint8_t lsr_delta;
+#ifndef __rtems__
 	uint8_t pps_signal;
+#endif /* __rtems__ */
 
 	tp = sc->sc_tty;
 
@@ -1109,6 +1119,7 @@ ucom_cfg_status_change(struct usb_proc_msg *_task)
 	sc->sc_msr = new_msr;
 	sc->sc_lsr = new_lsr;
 
+#ifndef __rtems__
 	/*
 	 * Time pulse counting support.
 	 */
@@ -1133,6 +1144,7 @@ ucom_cfg_status_change(struct usb_proc_msg *_task)
 		pps_event(&sc->sc_pps, onoff ? PPS_CAPTUREASSERT :
 		    PPS_CAPTURECLEAR);
 	}
+#endif /* __rtems__ */
 
 	if (msr_delta & SER_DCD) {
 
@@ -1212,6 +1224,10 @@ ucom_param(struct tty *tp, struct termios *t)
 	struct ucom_softc *sc = tty_softc(tp);
 	uint8_t opened;
 	int error;
+#ifdef __rtems__
+	uint32_t c_ispeed = rtems_bsd_get_input_speed(t);
+	uint32_t c_ospeed = rtems_bsd_get_output_speed(t);
+#endif /* __rtems__ */
 
 	UCOM_MTX_ASSERT(sc, MA_OWNED);
 
@@ -1235,13 +1251,21 @@ ucom_param(struct tty *tp, struct termios *t)
 	DPRINTF("sc = %p\n", sc);
 
 	/* Check requested parameters. */
+#ifndef __rtems__
 	if (t->c_ispeed && (t->c_ispeed != t->c_ospeed)) {
+#else /* __rtems__ */
+	if (c_ispeed && (c_ispeed != c_ospeed)) {
+#endif /* __rtems__ */
 		/* XXX c_ospeed == 0 is perfectly valid. */
 		DPRINTF("mismatch ispeed and ospeed\n");
 		error = EINVAL;
 		goto done;
 	}
+#ifndef __rtems__
 	t->c_ispeed = t->c_ospeed;
+#else /* __rtems__ */
+	cfsetispeed(t, c_ospeed);
+#endif /* __rtems__ */
 
 	if (sc->sc_callback->ucom_pre_param) {
 		/* Let the lower layer verify the parameters */
diff --git a/freebsd/sys/dev/usb/usb_dev.c b/freebsd/sys/dev/usb/usb_dev.c
old mode 100644
new mode 100755
index fe249c2..4d2321a
--- a/freebsd/sys/dev/usb/usb_dev.c
+++ b/freebsd/sys/dev/usb/usb_dev.c
@@ -804,9 +804,11 @@ usb_fifo_close(struct usb_fifo *f, int fflags)
 	}
 	/* check if a thread wants SIGIO */
 	if (f->async_p != NULL) {
+#ifndef __rtems__
 		PROC_LOCK(f->async_p);
 		kern_psignal(f->async_p, SIGIO);
 		PROC_UNLOCK(f->async_p);
+#endif /* __rtems__ */
 		f->async_p = NULL;
 	}
 	/* remove FWRITE and FREAD flags */
@@ -1025,6 +1027,7 @@ usb_ioctl_f_sub(struct usb_fifo *f, u_long cmd, void *addr,
 		break;
 
 	case FIOASYNC:
+#ifndef __rtems__
 		if (*(int *)addr) {
 			if (f->async_p != NULL) {
 				error = EBUSY;
@@ -1034,6 +1037,9 @@ usb_ioctl_f_sub(struct usb_fifo *f, u_long cmd, void *addr,
 		} else {
 			f->async_p = NULL;
 		}
+#else /* __rtems__ */
+			f->async_p = NULL;
+#endif /* __rtems__ */
 		break;
 
 		/* XXX this is not the most general solution */
@@ -1042,10 +1048,12 @@ usb_ioctl_f_sub(struct usb_fifo *f, u_long cmd, void *addr,
 			error = EINVAL;
 			break;
 		}
+#ifndef __rtems__
 		if (*(int *)addr != USB_PROC_GET_GID(f->async_p)) {
 			error = EPERM;
 			break;
 		}
+#endif /* __rtems__ */
 		break;
 	default:
 		return (ENOIOCTL);
@@ -1463,7 +1471,11 @@ usb_read(struct cdev *dev, struct uio *uio, int ioflag)
 
 			(f->methods->f_start_read) (f);
 
+#ifndef __rtems__
 			if (ioflag & IO_NDELAY) {
+#else /* __rtems__ */
+			if (ioflag & O_NONBLOCK) {
+#endif /* __rtems__ */
 				if (tr_data) {
 					/* return length before error */
 					break;
@@ -1588,7 +1600,11 @@ usb_write(struct cdev *dev, struct uio *uio, int ioflag)
 
 		if (m == NULL) {
 
+#ifndef __rtems__
 			if (ioflag & IO_NDELAY) {
+#else /* __rtems__ */
+			if (ioflag & O_NONBLOCK) {
+#endif /* __rtems__ */
 				if (tr_data) {
 					/* return length before error */
 					break;
@@ -1770,9 +1786,11 @@ usb_fifo_wakeup(struct usb_fifo *f)
 		f->flag_isselect = 0;
 	}
 	if (f->async_p != NULL) {
+#ifndef __rtems__
 		PROC_LOCK(f->async_p);
 		kern_psignal(f->async_p, SIGIO);
 		PROC_UNLOCK(f->async_p);
+#endif /* __rtems__ */
 	}
 }
 
diff --git a/freebsd/sys/fs/devfs/devfs_int.h b/freebsd/sys/fs/devfs/devfs_int.h
old mode 100644
new mode 100755
index 670aba1..9e16b40
--- a/freebsd/sys/fs/devfs/devfs_int.h
+++ b/freebsd/sys/fs/devfs/devfs_int.h
@@ -63,13 +63,13 @@ struct cdev_priv {
 	u_int			cdp_maxdirent;
 	struct devfs_dirent	**cdp_dirents;
 	struct devfs_dirent	*cdp_dirent0;
+#endif /* __rtems__ */
 
 	TAILQ_ENTRY(cdev_priv)	cdp_dtr_list;
 	void			(*cdp_dtr_cb)(void *);
 	void			*cdp_dtr_cb_arg;
 
 	LIST_HEAD(, cdev_privdata) cdp_fdpriv;
-#endif /* __rtems__ */
 };
 
 #define	cdev2priv(c)	__containerof(c, struct cdev_priv, cdp_c)
diff --git a/freebsd/sys/kern/kern_conf.c b/freebsd/sys/kern/kern_conf.c
old mode 100644
new mode 100755
index fb43c24..20f2e2c
--- a/freebsd/sys/kern/kern_conf.c
+++ b/freebsd/sys/kern/kern_conf.c
@@ -59,11 +59,9 @@ static MALLOC_DEFINE(M_DEVT, "cdev", "cdev storage");
 
 struct mtx devmtx;
 static void destroy_devl(struct cdev *dev);
-#ifndef __rtems__
 static int destroy_dev_sched_cbl(struct cdev *dev,
     void (*cb)(void *), void *arg);
 static void destroy_dev_tq(void *ctx, int pending);
-#endif /* __rtems__ */
 static int make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw,
     int unit, struct ucred *cr, uid_t uid, gid_t gid, int mode, const char *fmt,
     va_list ap);
@@ -164,7 +162,6 @@ dev_refl(struct cdev *dev)
 	dev->si_refcount++;
 }
 
-#ifndef __rtems__
 void
 dev_rel(struct cdev *dev)
 {
@@ -189,7 +186,6 @@ dev_rel(struct cdev *dev)
 	if (flag)
 		devfs_free(dev);
 }
-#endif /* __rtems__ */
 
 struct cdevsw *
 dev_refthread(struct cdev *dev, int *ref)
@@ -971,6 +967,7 @@ make_dev_p(int flags, struct cdev **cdev, struct cdevsw *devsw,
 	    ("make_dev_p: failed make_dev_credv (error=%d)", res));
 	return (res);
 }
+#endif /* __rtems__ */
 
 static void
 dev_dependsl(struct cdev *pdev, struct cdev *cdev)
@@ -1050,6 +1047,7 @@ make_dev_alias(struct cdev *pdev, const char *fmt, ...)
 	return (dev);
 }
 
+#ifndef __rtems__
 int
 make_dev_alias_p(int flags, struct cdev **cdev, struct cdev *pdev,
     const char *fmt, ...)
@@ -1156,7 +1154,6 @@ destroy_devl(struct cdev *dev)
 	/* Remove name marking */
 	dev->si_flags &= ~SI_NAMED;
 
-#ifndef __rtems__
 	/* If we are a child, remove us from the parents list */
 	if (dev->si_flags & SI_CHILD) {
 		LIST_REMOVE(dev, si_siblings);
@@ -1167,6 +1164,7 @@ destroy_devl(struct cdev *dev)
 	while (!LIST_EMPTY(&dev->si_children))
 		destroy_devl(LIST_FIRST(&dev->si_children));
 
+#ifndef __rtems__
 	/* Remove from clone list */
 	if (dev->si_flags & SI_CLONELIST) {
 		LIST_REMOVE(dev, si_clone);
@@ -1195,14 +1193,12 @@ destroy_devl(struct cdev *dev)
 		/* avoid out of order notify events */
 		notify_destroy(dev);
 	}
-#ifndef __rtems__
 	mtx_lock(&cdevpriv_mtx);
 	while ((p = LIST_FIRST(&cdp->cdp_fdpriv)) != NULL) {
 		devfs_destroy_cdevpriv(p);
 		mtx_lock(&cdevpriv_mtx);
 	}
 	mtx_unlock(&cdevpriv_mtx);
-#endif /* __rtems__ */
 	dev_lock();
 
 	dev->si_drv1 = 0;
@@ -1231,7 +1227,6 @@ destroy_devl(struct cdev *dev)
 		dev_free_devlocked(dev);
 }
 
-#ifndef __rtems__
 static void
 delist_dev_locked(struct cdev *dev)
 {
@@ -1270,7 +1265,6 @@ delist_dev(struct cdev *dev)
 	delist_dev_locked(dev);
 	dev_unlock();
 }
-#endif /* __rtems__ */
 
 void
 destroy_dev(struct cdev *dev)
@@ -1282,7 +1276,6 @@ destroy_dev(struct cdev *dev)
 	dev_unlock_and_free();
 }
 
-#ifndef __rtems__
 const char *
 devtoname(struct cdev *dev)
 {
@@ -1290,6 +1283,7 @@ devtoname(struct cdev *dev)
 	return (dev->si_name);
 }
 
+#ifndef __rtems__
 int
 dev_stdclone(char *name, char **namep, const char *stem, int *unit)
 {
@@ -1464,6 +1458,7 @@ clone_cleanup(struct clonedevs **cdp)
 	free(cd, M_DEVBUF);
 	*cdp = NULL;
 }
+#endif /* __rtems__ */
 
 static TAILQ_HEAD(, cdev_priv) dev_ddtr =
 	TAILQ_HEAD_INITIALIZER(dev_ddtr);
@@ -1536,6 +1531,7 @@ destroy_dev_sched(struct cdev *dev)
 	return (destroy_dev_sched_cb(dev, NULL, NULL));
 }
 
+#ifndef __rtems__
 void
 destroy_dev_drain(struct cdevsw *csw)
 {
diff --git a/freebsd/sys/kern/subr_taskqueue.c b/freebsd/sys/kern/subr_taskqueue.c
old mode 100644
new mode 100755
index 5ef8683..f9737a5
--- a/freebsd/sys/kern/subr_taskqueue.c
+++ b/freebsd/sys/kern/subr_taskqueue.c
@@ -49,15 +49,11 @@ __FBSDID("$FreeBSD$");
 #include <machine/stdarg.h>
 
 static MALLOC_DEFINE(M_TASKQUEUE, "taskqueue", "Task Queues");
-#ifndef __rtems__
 static void	*taskqueue_giant_ih;
-#endif /* __rtems__ */
 static void	*taskqueue_ih;
 static void	 taskqueue_fast_enqueue(void *);
 static void	 taskqueue_swi_enqueue(void *);
-#ifndef __rtems__
 static void	 taskqueue_swi_giant_enqueue(void *);
-#endif /* __rtems__ */
 
 struct taskqueue_busy {
 	struct task	*tb_running;
@@ -182,9 +178,7 @@ _taskqueue_create(const char *name, int mflags,
 	queue->tq_flags |= TQ_FLAGS_ACTIVE;
 	if (enqueue == taskqueue_fast_enqueue ||
 	    enqueue == taskqueue_swi_enqueue ||
-#ifndef __rtems__
 	    enqueue == taskqueue_swi_giant_enqueue ||
-#endif /* __rtems__ */
 	    enqueue == taskqueue_thread_enqueue)
 		queue->tq_flags |= TQ_FLAGS_UNLOCKED_ENQUEUE;
 	mtx_init(&queue->tq_mutex, tq_name, NULL, mtxflags);
@@ -635,7 +629,6 @@ taskqueue_swi_run(void *dummy)
 	taskqueue_run(taskqueue_swi);
 }
 
-#ifndef __rtems__
 static void
 taskqueue_swi_giant_enqueue(void *context)
 {
@@ -647,7 +640,6 @@ taskqueue_swi_giant_run(void *dummy)
 {
 	taskqueue_run(taskqueue_swi_giant);
 }
-#endif /* __rtems__ */
 
 static int
 _taskqueue_start_threads(struct taskqueue **tqp, int count, int pri,
@@ -812,11 +804,9 @@ TASKQUEUE_DEFINE(swi, taskqueue_swi_enqueue, NULL,
 		 swi_add(NULL, "task queue", taskqueue_swi_run, NULL, SWI_TQ,
 		     INTR_MPSAFE, &taskqueue_ih));
 
-#ifndef __rtems__
 TASKQUEUE_DEFINE(swi_giant, taskqueue_swi_giant_enqueue, NULL,
 		 swi_add(NULL, "Giant taskq", taskqueue_swi_giant_run,
 		     NULL, SWI_TQ_GIANT, 0, &taskqueue_giant_ih));
-#endif /* __rtems__ */
 
 TASKQUEUE_DEFINE_THREAD(thread);
 
diff --git a/freebsd/sys/kern/tty.c b/freebsd/sys/kern/tty.c
old mode 100644
new mode 100755
index 47932ee..9a833f9
--- a/freebsd/sys/kern/tty.c
+++ b/freebsd/sys/kern/tty.c
@@ -68,6 +68,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/vnode.h>
 
 #include <machine/stdarg.h>
+#ifdef __rtems__
+#include <machine/rtems-bsd-termios.h>
+#endif /* __rtems__ */
 
 static MALLOC_DEFINE(M_TTY, "tty", "tty device");
 
@@ -91,9 +94,15 @@ static const char	*dev_console_filename;
 #define TTYSUP_LFLAG	(ECHOKE|ECHOE|ECHOK|ECHO|ECHONL|ECHOPRT|\
 			ECHOCTL|ISIG|ICANON|ALTWERASE|IEXTEN|TOSTOP|\
 			FLUSHO|NOKERNINFO|NOFLSH)
+#ifndef __rtems__
 #define TTYSUP_CFLAG	(CIGNORE|CSIZE|CSTOPB|CREAD|PARENB|PARODD|\
 			HUPCL|CLOCAL|CCTS_OFLOW|CRTS_IFLOW|CDTR_IFLOW|\
 			CDSR_OFLOW|CCAR_OFLOW)
+#else /* __rtems__ */
+#define TTYSUP_CFLAG  (CIGNORE|CSIZE|CSTOPB|CREAD|PARENB|PARODD|\
+      HUPCL|CLOCAL|CCTS_OFLOW|CRTS_IFLOW|CDTR_IFLOW|\
+      CDSR_OFLOW|CCAR_OFLOW|CBAUD|CIBAUD)
+#endif /* __rtems__ */
 
 #define	TTY_CALLOUT(tp,d) (dev2unit(d) & TTYUNIT_CALLOUT)
 
@@ -107,17 +116,29 @@ static void
 tty_watermarks(struct tty *tp)
 {
 	size_t bs = 0;
+#ifdef __rtems__
+	uint32_t c_ispeed = rtems_bsd_get_input_speed(&tp->t_termios);
+	uint32_t c_ospeed = rtems_bsd_get_output_speed(&tp->t_termios);
+#endif /* __rtems__ */
 
 	/* Provide an input buffer for 0.2 seconds of data. */
 	if (tp->t_termios.c_cflag & CREAD)
+#ifndef __rtems__
 		bs = MIN(tp->t_termios.c_ispeed / 5, TTYBUF_MAX);
+#else /* __rtems__ */
+		bs = MIN(c_ispeed / 5, TTYBUF_MAX);
+#endif /* __rtems__ */
 	ttyinq_setsize(&tp->t_inq, tp, bs);
 
 	/* Set low watermark at 10% (when 90% is available). */
 	tp->t_inlow = (ttyinq_getallocatedsize(&tp->t_inq) * 9) / 10;
 
 	/* Provide an output buffer for 0.2 seconds of data. */
+#ifndef __rtems__
 	bs = MIN(tp->t_termios.c_ospeed / 5, TTYBUF_MAX);
+#else /* __rtems__ */
+	bs = MIN(c_ospeed / 5, TTYBUF_MAX);
+#endif /* __rtems__ */
 	ttyoutq_setsize(&tp->t_outq, tp, bs);
 
 	/* Set low watermark at 10% (when 90% is available). */
@@ -198,9 +219,11 @@ ttydev_leave(struct tty *tp)
 	/* Stop asynchronous I/O. */
 	funsetown(&tp->t_sigio);
 
+#ifndef __rtems__
 	/* Remove console TTY. */
 	if (constty == tp)
 		constty_clear();
+#endif /* __rtems__ */
 
 	/* Drain any output. */
 	if (!tty_gone(tp))
@@ -349,9 +372,11 @@ ttydev_close(struct cdev *dev, int fflag, int devtype __unused,
 		return (0);
 	}
 
+#ifndef __rtems__
 	/* If revoking, flush output now to avoid draining it later. */
 	if (fflag & FREVOKE)
 		tty_flush(tp, FWRITE);
+#endif /* __rtems__ */
 
 	tp->t_flags &= ~TF_EXCLUDE;
 
@@ -366,6 +391,7 @@ ttydev_close(struct cdev *dev, int fflag, int devtype __unused,
 	return (0);
 }
 
+#ifndef __rtems__
 static __inline int
 tty_is_ctty(struct tty *tp, struct proc *p)
 {
@@ -374,10 +400,12 @@ tty_is_ctty(struct tty *tp, struct proc *p)
 
 	return (p->p_session == tp->t_session && p->p_flag & P_CONTROLT);
 }
+#endif /* __rtems__ */
 
 int
 tty_wait_background(struct tty *tp, struct thread *td, int sig)
 {
+#ifndef __rtems__
 	struct proc *p = td->td_proc;
 	struct pgrp *pg;
 	ksiginfo_t ksi;
@@ -436,6 +464,9 @@ tty_wait_background(struct tty *tp, struct thread *td, int sig)
 		if (error)
 			return (error);
 	}
+#else /* __rtems__ */
+	return (0);
+#endif /* __rtems__ */
 }
 
 static int
@@ -475,7 +506,11 @@ ttydev_write(struct cdev *dev, struct uio *uio, int ioflag)
 			goto done;
 	}
 
+#ifndef __rtems__
 	if (ioflag & IO_NDELAY && tp->t_flags & TF_BUSY_OUT) {
+#else /* __rtems__ */
+	if (ioflag & O_NONBLOCK && tp->t_flags & TF_BUSY_OUT) {
+#endif /* __rtems__ */
 		/* Allow non-blocking writes to bypass serialization. */
 		error = ttydisc_write(tp, uio, ioflag);
 	} else {
@@ -502,11 +537,25 @@ ttydev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
 {
 	struct tty *tp = dev->si_drv1;
 	int error;
+#ifdef __rtems__
+	int flush_flags;
+#endif /* __rtems__ */
 
 	error = ttydev_enter(tp);
 	if (error)
 		return (error);
 
+#ifdef __rtems__
+	cmd = rtems_bsd_ioctl_cmd_to_bsd((struct termios *)data, cmd, data, &flush_flags);
+	if (cmd == TIOCFLUSH) {
+		if (flush_flags != 0) {
+			data = (caddr_t)&flush_flags;
+		} else {
+			error = EINVAL;
+			goto done;
+		}
+	}
+#endif /* __rtems__ */
 	switch (cmd) {
 	case TIOCCBRK:
 	case TIOCCONS:
@@ -554,6 +603,12 @@ ttydev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
 		struct termios *lock = TTY_CALLOUT(tp, dev) ?
 		    &tp->t_termios_lock_out : &tp->t_termios_lock_in;
 		int cc;
+#ifdef __rtems__
+		uint32_t lock_c_ispeed = cfgetispeed(lock);
+		uint32_t lock_c_ospeed = cfgetospeed(lock);
+		uint32_t old_c_ispeed = cfgetispeed(old);
+		uint32_t old_c_ospeed = cfgetospeed(old);
+#endif /* __rtems__ */
 
 		/*
 		 * Lock state devices.  Just overwrite the values of the
@@ -570,10 +625,17 @@ ttydev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
 		for (cc = 0; cc < NCCS; ++cc)
 			if (lock->c_cc[cc])
 				new->c_cc[cc] = old->c_cc[cc];
+#ifndef __rtems__
 		if (lock->c_ispeed)
 			new->c_ispeed = old->c_ispeed;
 		if (lock->c_ospeed)
 			new->c_ospeed = old->c_ospeed;
+#else /* __rtems__ */
+		if (lock_c_ispeed)
+			cfsetispeed(new, old_c_ispeed);
+		if (lock_c_ospeed)
+			cfsetospeed(new, old_c_ospeed);
+#endif /* __rtems__ */
 	}
 
 	error = tty_ioctl(tp, cmd, data, fflag, td);
@@ -740,7 +802,9 @@ static struct cdevsw ttydev_cdevsw = {
 	.d_ioctl	= ttydev_ioctl,
 	.d_kqfilter	= ttydev_kqfilter,
 	.d_poll		= ttydev_poll,
+#ifndef __rtems__
 	.d_mmap		= ttydev_mmap,
+#endif /* __rtems__ */
 	.d_name		= "ttydev",
 	.d_flags	= D_TTY,
 };
@@ -788,7 +852,21 @@ ttyil_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
 {
 	struct tty *tp = dev->si_drv1;
 	int error;
-
+#ifdef __rtems__
+	int flush_flags;
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+	cmd = rtems_bsd_ioctl_cmd_to_bsd((struct termios *)data, cmd, data, &flush_flags);
+	if (cmd == TIOCFLUSH) {
+		if (flush_flags != 0) {
+			data = (caddr_t)&flush_flags;
+		} else {
+			error = EINVAL;
+			goto done;
+		}
+	}
+#endif /* __rtems__ */
 	tty_lock(tp);
 	if (tty_gone(tp)) {
 		error = ENODEV;
@@ -846,8 +924,13 @@ tty_init_termios(struct tty *tp)
 	t->c_iflag = TTYDEF_IFLAG;
 	t->c_lflag = TTYDEF_LFLAG;
 	t->c_oflag = TTYDEF_OFLAG;
+#ifndef __rtems__
 	t->c_ispeed = TTYDEF_SPEED;
 	t->c_ospeed = TTYDEF_SPEED;
+#else /* __rtems__ */
+	cfsetispeed(t, TTYDEF_SPEED);
+	cfsetospeed(t, TTYDEF_SPEED);
+#endif /* __rtems__ */
 	memcpy(&t->c_cc, ttydefchars, sizeof ttydefchars);
 
 	tp->t_termios_init_out = *t;
@@ -858,10 +941,20 @@ tty_init_console(struct tty *tp, speed_t s)
 {
 	struct termios *ti = &tp->t_termios_init_in;
 	struct termios *to = &tp->t_termios_init_out;
+#ifdef __rtems__
+	speed_t s_speed = rtems_bsd_bsd_speed_to_rtems_speed(s);
+#endif /* __rtems__ */
 
 	if (s != 0) {
+#ifndef __rtems__
 		ti->c_ispeed = ti->c_ospeed = s;
 		to->c_ispeed = to->c_ospeed = s;
+#else /* __rtems__ */
+		cfsetispeed(ti, s_speed);
+		cfsetospeed(ti, s_speed);
+		cfsetispeed(to, s_speed);
+		cfsetospeed(to, s_speed);
+#endif /* __rtems__ */
 	}
 
 	ti->c_cflag |= CLOCAL;
@@ -919,12 +1012,17 @@ ttydevsw_defcioctl(struct tty *tp __unused, int unit __unused,
 static int
 ttydevsw_defparam(struct tty *tp __unused, struct termios *t)
 {
+#ifdef __rtems__
+	speed_t c_ispeed = cfgetispeed(t);
+	speed_t c_ospeed = cfgetospeed(t);
+#endif /* __rtems__ */
 
 	/*
 	 * Allow the baud rate to be adjusted for pseudo-devices, but at
 	 * least restrict it to 115200 to prevent excessive buffer
 	 * usage.  Also disallow 0, to prevent foot shooting.
 	 */
+#ifndef __rtems__
 	if (t->c_ispeed < B50)
 		t->c_ispeed = B50;
 	else if (t->c_ispeed > B115200)
@@ -933,6 +1031,16 @@ ttydevsw_defparam(struct tty *tp __unused, struct termios *t)
 		t->c_ospeed = B50;
 	else if (t->c_ospeed > B115200)
 		t->c_ospeed = B115200;
+#else /* __rtems__ */
+	if (c_ispeed < B50)
+		cfsetispeed(t, B50);
+	else if (c_ispeed > B115200)
+		cfsetispeed(t, B115200);
+	if (c_ospeed < B50)
+		cfsetospeed(t, B50);
+	else if (c_ospeed > B115200)
+		cfsetospeed(t, B115200);
+#endif /* __rtems__ */
 	t->c_cflag |= CREAD;
 
 	return (0);
@@ -1149,6 +1257,7 @@ tty_rel_gone(struct tty *tp)
  * Exposing information about current TTY's through sysctl
  */
 
+#ifndef __rtems__
 static void
 tty_to_xtty(struct tty *tp, struct xtty *xt)
 {
@@ -1202,6 +1311,7 @@ sysctl_kern_ttys(SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC(_kern, OID_AUTO, ttys, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE,
 	0, 0, sysctl_kern_ttys, "S,xtty", "List of TTYs");
+#endif /* __rtems__ */
 
 /*
  * Device node creation. Device has been set up, now we can expose it to
@@ -1230,6 +1340,7 @@ tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
 	vsnrprintf(name, sizeof name, 32, fmt, ap);
 	va_end(ap);
 
+#ifndef __rtems__
 	if (cred == NULL) {
 		/* System device. */
 		uid = UID_ROOT;
@@ -1241,6 +1352,11 @@ tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
 		gid = GID_TTY;
 		mode = S_IRUSR|S_IWUSR|S_IWGRP;
 	}
+#else /* __rtems__ */
+	uid = BSD_DEFAULT_UID;
+	gid = BSD_DEFAULT_GID;
+	mode = S_IRUSR|S_IWUSR|S_IWGRP;
+#endif /* __rtems__ */
 
 	flags = flags & TTYMK_CLONING ? MAKEDEV_REF : 0;
 	flags |= MAKEDEV_CHECKNAME;
@@ -1351,12 +1467,14 @@ tty_signal_sessleader(struct tty *tp, int sig)
 	/* Make signals start output again. */
 	tp->t_flags &= ~TF_STOPPED;
 
+#ifndef __rtems__
 	if (tp->t_session != NULL && tp->t_session->s_leader != NULL) {
 		p = tp->t_session->s_leader;
 		PROC_LOCK(p);
 		kern_psignal(p, sig);
 		PROC_UNLOCK(p);
 	}
+#endif /* __rtems__ */
 }
 
 void
@@ -1370,6 +1488,7 @@ tty_signal_pgrp(struct tty *tp, int sig)
 	/* Make signals start output again. */
 	tp->t_flags &= ~TF_STOPPED;
 
+#ifndef __rtems__
 	if (sig == SIGINFO && !(tp->t_termios.c_lflag & NOKERNINFO))
 		tty_info(tp);
 	if (tp->t_pgrp != NULL) {
@@ -1380,6 +1499,7 @@ tty_signal_pgrp(struct tty *tp, int sig)
 		pgsignal(tp->t_pgrp, sig, 1, &ksi);
 		PGRP_UNLOCK(tp->t_pgrp);
 	}
+#endif /* __rtems__ */
 }
 
 void
@@ -1476,7 +1596,9 @@ tty_set_winsize(struct tty *tp, const struct winsize *wsz)
 	if (memcmp(&tp->t_winsize, wsz, sizeof(*wsz)) == 0)
 		return;
 	tp->t_winsize = *wsz;
+#ifndef __rtems__
 	tty_signal_pgrp(tp, SIGWINCH);
+#endif /* __rtems__ */
 }
 
 static int
@@ -1535,9 +1657,11 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		*(int *)data = ttyoutq_bytesused(&tp->t_outq);
 		return (0);
 	case FIOSETOWN:
+#ifndef __rtems__
 		if (tp->t_session != NULL && !tty_is_ctty(tp, td->td_proc))
 			/* Not allowed to set ownership. */
 			return (ENOTTY);
+#endif /* __rtems__ */
 
 		/* Temporarily unlock the TTY to set ownership. */
 		tty_unlock(tp);
@@ -1545,9 +1669,11 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		tty_lock(tp);
 		return (error);
 	case FIOGETOWN:
+#ifndef __rtems__
 		if (tp->t_session != NULL && !tty_is_ctty(tp, td->td_proc))
 			/* Not allowed to set ownership. */
 			return (ENOTTY);
+#endif /* __rtems__ */
 
 		/* Get ownership. */
 		*(int *)data = fgetown(&tp->t_sigio);
@@ -1566,8 +1692,15 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		 * input baud rate is set equal to the output baud rate
 		 * when zero.
 		 */
+#ifndef __rtems__
 		if (t->c_ispeed == 0)
 			t->c_ispeed = t->c_ospeed;
+#else /* __rtems__ */
+		speed_t c_ispeed = cfgetispeed(t);
+		speed_t c_ospeed = cfgetospeed(t);
+		if (c_ispeed == B0)
+			cfsetispeed(t, c_ospeed);
+#endif /* __rtems__ */
 
 		/* Discard any unsupported bits. */
 		t->c_iflag &= TTYSUP_IFLAG;
@@ -1587,21 +1720,33 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		/*
 		 * Only call param() when the flags really change.
 		 */
+#ifndef __rtems__
 		if ((t->c_cflag & CIGNORE) == 0 &&
 		    (tp->t_termios.c_cflag != t->c_cflag ||
 		    ((tp->t_termios.c_iflag ^ t->c_iflag) &
 		    (IXON|IXOFF|IXANY)) ||
 		    tp->t_termios.c_ispeed != t->c_ispeed ||
 		    tp->t_termios.c_ospeed != t->c_ospeed)) {
+#else /* __rtems__ */
+		if ((t->c_cflag & CIGNORE) == 0 &&
+		    (tp->t_termios.c_cflag != t->c_cflag ||
+		    ((tp->t_termios.c_iflag ^ t->c_iflag) &
+		    (IXON|IXOFF|IXANY)))) {
+#endif /* __rtems__ */
 			error = ttydevsw_param(tp, t);
 			if (error)
 				return (error);
 
 			/* XXX: CLOCAL? */
 
+#ifndef __rtems__
 			tp->t_termios.c_cflag = t->c_cflag & ~CIGNORE;
 			tp->t_termios.c_ispeed = t->c_ispeed;
 			tp->t_termios.c_ospeed = t->c_ospeed;
+#else /* __rtems__ */
+			cfsetispeed(&tp->t_termios, cfgetispeed(t));
+			cfsetospeed(&tp->t_termios, cfgetospeed(t));
+#endif /* __rtems__ */
 
 			/* Baud rate has changed - update watermarks. */
 			tty_watermarks(tp);
@@ -1642,6 +1787,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		*(int *)data = TTYDISC;
 		return (0);
 	case TIOCGPGRP:
+#ifndef __rtems__
 		if (!tty_is_ctty(tp, td->td_proc))
 			return (ENOTTY);
 
@@ -1649,15 +1795,23 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 			*(int *)data = tp->t_pgrp->pg_id;
 		else
 			*(int *)data = NO_PID;
+#else /* __rtems__ */
+		*(int *)data = NO_PID;
+#endif /* __rtems__ */
 		return (0);
 	case TIOCGSID:
+#ifndef __rtems__
 		if (!tty_is_ctty(tp, td->td_proc))
 			return (ENOTTY);
 
 		MPASS(tp->t_session);
 		*(int *)data = tp->t_session->s_sid;
+#else /* __rtems__ */
+		*(int *)data = NO_PID;
+#endif /* __rtems__ */
 		return (0);
 	case TIOCSCTTY: {
+#ifndef __rtems__
 		struct proc *p = td->td_proc;
 
 		/* XXX: This looks awful. */
@@ -1706,10 +1860,12 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		PROC_LOCK(p);
 		p->p_flag |= P_CONTROLT;
 		PROC_UNLOCK(p);
+#endif /* __rtems__ */
 
 		return (0);
 	}
 	case TIOCSPGRP: {
+#ifndef __rtems__
 		struct pgrp *pg;
 
 		/*
@@ -1742,6 +1898,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 
 		/* Wake up the background process groups. */
 		cv_broadcast(&tp->t_bgwait);
+#endif /* __rtems__ */
 		return (0);
 	}
 	case TIOCFLUSH: {
@@ -1758,6 +1915,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		/* Drain TTY output. */
 		return tty_drain(tp, 0);
 	case TIOCCONS:
+#ifndef __rtems__
 		/* Set terminal as console TTY. */
 		if (*(int *)data) {
 			error = priv_check(td, PRIV_TTY_CONSOLE);
@@ -1780,6 +1938,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		} else if (constty == tp) {
 			constty_clear();
 		}
+#endif /* __rtems__ */
 		return (0);
 	case TIOCGWINSZ:
 		/* Obtain window size. */
@@ -1805,14 +1964,18 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
 		ttydevsw_pktnotify(tp, TIOCPKT_START);
 		return (0);
 	case TIOCSTAT:
+#ifndef __rtems__
 		tty_info(tp);
+#endif /* __rtems__ */
 		return (0);
 	case TIOCSTI:
+#ifndef __rtems__
 		if ((fflag & FREAD) == 0 && priv_check(td, PRIV_TTY_STI))
 			return (EPERM);
 		if (!tty_is_ctty(tp, td->td_proc) &&
 		    priv_check(td, PRIV_TTY_STI))
 			return (EACCES);
+#endif /* __rtems__ */
 		ttydisc_rint(tp, *(char *)data, 0);
 		ttydisc_rint_done(tp);
 		return (0);
@@ -1891,9 +2054,17 @@ tty_hiwat_in_unblock(struct tty *tp)
 		 * Input flow control. Only leave the high watermark when we
 		 * can successfully store the VSTART character.
 		 */
+#ifndef __rtems__
 		if (ttyoutq_write_nofrag(&tp->t_outq,
 		    &tp->t_termios.c_cc[VSTART], 1) == 0)
 			tp->t_flags &= ~TF_HIWAT_IN;
+#else /* __rtems__ */
+		if (ttyoutq_write_nofrag(&tp->t_outq,
+		    &tp->t_termios.c_cc[VSTART], 1) == 0) {
+			tp->t_flags &= ~TF_HIWAT_IN;
+			ttydevsw_outwakeup(tp);
+		}
+#endif /* __rtems__ */
 	} else {
 		/* No input flow control. */
 		tp->t_flags &= ~TF_HIWAT_IN;
@@ -1917,6 +2088,7 @@ ttyhook_defrint(struct tty *tp, char c, int flags)
 	return (0);
 }
 
+#ifndef __rtems__
 int
 ttyhook_register(struct tty **rtp, struct proc *p, int fd, struct ttyhook *th,
     void *softc)
@@ -2010,6 +2182,7 @@ ttyhook_unregister(struct tty *tp)
 	/* Maybe deallocate the TTY as well. */
 	tty_rel_free(tp);
 }
+#endif /* __rtems__ */
 
 /*
  * /dev/console handling.
@@ -2064,11 +2237,14 @@ static struct cdevsw ttyconsdev_cdevsw = {
 	.d_ioctl	= ttydev_ioctl,
 	.d_kqfilter	= ttydev_kqfilter,
 	.d_poll		= ttydev_poll,
+#ifndef __rtems__
 	.d_mmap		= ttydev_mmap,
+#endif /* __rtems__ */
 	.d_name		= "ttyconsdev",
 	.d_flags	= D_TTY,
 };
 
+#ifndef __rtems__
 static void
 ttyconsdev_init(void *unused __unused)
 {
@@ -2085,6 +2261,7 @@ ttyconsdev_select(const char *name)
 
 	dev_console_filename = name;
 }
+#endif /* __rtems__ */
 
 /*
  * Debugging routines.
diff --git a/freebsd/sys/kern/tty_ttydisc.c b/freebsd/sys/kern/tty_ttydisc.c
old mode 100644
new mode 100755
index edb1d15..f601e7c
--- a/freebsd/sys/kern/tty_ttydisc.c
+++ b/freebsd/sys/kern/tty_ttydisc.c
@@ -154,7 +154,11 @@ ttydisc_read_canonical(struct tty *tp, struct uio *uio, int ioflag)
 		if (clen == 0) {
 			if (tp->t_flags & TF_ZOMBIE)
 				return (0);
+#ifndef __rtems__
 			else if (ioflag & IO_NDELAY)
+#else /* __rtems__ */
+			else if (ioflag & O_NONBLOCK)
+#endif /* __rtems__ */
 				return (EWOULDBLOCK);
 
 			error = tty_wait(tp, &tp->t_inwait);
@@ -209,7 +213,11 @@ ttydisc_read_raw_no_timer(struct tty *tp, struct uio *uio, int ioflag)
 		/* We have to wait for more. */
 		if (tp->t_flags & TF_ZOMBIE)
 			return (0);
+#ifndef __rtems__
 		else if (ioflag & IO_NDELAY)
+#else /* __rtems__ */
+		else if (ioflag & O_NONBLOCK)
+#endif /* __rtems__ */
 			return (EWOULDBLOCK);
 
 		error = tty_wait(tp, &tp->t_inwait);
@@ -261,7 +269,11 @@ ttydisc_read_raw_read_timer(struct tty *tp, struct uio *uio, int ioflag,
 		 */
 		if (tp->t_flags & TF_ZOMBIE)
 			return (0);
+#ifndef __rtems__
 		else if (ioflag & IO_NDELAY)
+#else /* __rtems__ */
+		else if (ioflag & O_NONBLOCK)
+#endif /* __rtems__ */
 			return (EWOULDBLOCK);
 
 		error = tty_timedwait(tp, &tp->t_inwait, hz);
@@ -310,7 +322,11 @@ ttydisc_read_raw_interbyte_timer(struct tty *tp, struct uio *uio, int ioflag)
 		/* We have to wait for more. */
 		if (tp->t_flags & TF_ZOMBIE)
 			return (0);
+#ifndef __rtems__
 		else if (ioflag & IO_NDELAY)
+#else /* __rtems__ */
+		else if (ioflag & O_NONBLOCK)
+#endif /* __rtems__ */
 			return (EWOULDBLOCK);
 
 		error = tty_wait(tp, &tp->t_inwait);
@@ -532,7 +548,11 @@ ttydisc_write(struct tty *tp, struct uio *uio, int ioflag)
 			/* Watermark reached. Try to sleep. */
 			tp->t_flags |= TF_HIWAT_OUT;
 
+#ifndef __rtems__
 			if (ioflag & IO_NDELAY) {
+#else /* __rtems__ */
+			if (ioflag & O_NONBLOCK) {
+#endif /* __rtems__ */
 				error = EWOULDBLOCK;
 				goto done;
 			}
@@ -914,7 +934,9 @@ ttydisc_rint(struct tty *tp, char c, int flags)
 	if (CMP_FLAG(l, ISIG)) {
 		if (CMP_FLAG(l, ICANON|IEXTEN) == (ICANON|IEXTEN)) {
 			if (CMP_CC(VSTATUS, c)) {
+#ifndef __rtems__
 				tty_signal_pgrp(tp, SIGINFO);
+#endif /* __rtems__ */
 				return (0);
 			}
 		}
diff --git a/freebsd/sys/sys/_termios.h b/freebsd/sys/sys/_termios.h
old mode 100644
new mode 100755
index 3fb5bf4..45104ed
--- a/freebsd/sys/sys/_termios.h
+++ b/freebsd/sys/sys/_termios.h
@@ -33,6 +33,35 @@
 #ifndef _SYS__TERMIOS_H_
 #define	_SYS__TERMIOS_H_
 
+#ifdef __rtems__
+#include <termios.h>
+
+/* c_cflag bit meaning */
+#define CIGNORE     0020000     /* ignore control flags */
+#define CCTS_OFLOW  04000000    /* CTS flow control of output */
+#define CRTS_IFLOW  010000000   /* RTS flow control of input */
+#define CDTR_IFLOW  020000000   /* DTR flow control of input */
+#define CDSR_OFLOW  040000000   /* DSR flow control of output */
+#define CCAR_OFLOW  0100000000  /* DCD flow control of output */
+#define CRTSCTS     (CCTS_OFLOW | CRTS_IFLOW)
+
+/* c_oflag bits */
+#define ONOEOT      0200000     /* discard EOT's (^D) on output) */
+
+/* c_lflag bits */
+#define ALTWERASE   0200000     /* use alternate WERASE algorithm */
+#define EXTPROC     0400000     /* external processing */
+#define NOKERNINFO  01000000    /* no kernel output from VSTATUS */
+
+/* c_cc characters */
+#define VERASE2     17          /* ICANON */
+#define VSTATUS     18          /* ICANON together with IEXTEN */
+
+__BEGIN_DECLS
+void  cfmakesane(struct termios *);
+__END_DECLS
+
+#else /* __rtems__ */
 /*
  * Special Control Characters
  *
@@ -218,5 +247,6 @@ struct termios {
 	speed_t		c_ispeed;	/* input speed */
 	speed_t		c_ospeed;	/* output speed */
 };
+#endif /* __rtems__ */
 
 #endif /* !_SYS__TERMIOS_H_ */
diff --git a/freebsd/sys/sys/conf.h b/freebsd/sys/sys/conf.h
old mode 100644
new mode 100755
index 084cab2..0af1999
--- a/freebsd/sys/sys/conf.h
+++ b/freebsd/sys/sys/conf.h
@@ -84,9 +84,11 @@ struct cdev {
 	LIST_ENTRY(cdev)	si_list;
 #ifndef __rtems__
 	LIST_ENTRY(cdev)	si_clone;
+#endif /* __rtems__ */
 	LIST_HEAD(, cdev)	si_children;
 	LIST_ENTRY(cdev)	si_siblings;
 	struct cdev *si_parent;
+#ifndef __rtems__
 	struct mount	*si_mountpt;
 #endif /* __rtems__ */
 	void		*si_drv1, *si_drv2;
diff --git a/freebsd/sys/sys/file.h b/freebsd/sys/sys/file.h
old mode 100644
new mode 100755
index 4fcbbde..90378ca
--- a/freebsd/sys/sys/file.h
+++ b/freebsd/sys/sys/file.h
@@ -199,6 +199,10 @@ struct file {
 	void		*f_label;	/* Place-holder for MAC label. */
 #else /* __rtems__ */
 	rtems_libio_t	f_io;
+	union {
+		struct cdev_privdata *fvn_cdevpriv;
+					/* (d) Private data for the cdev. */
+	} f_vnun;
 #endif /* __rtems__ */
 };
 #ifdef __rtems__
diff --git a/freebsd/sys/sys/proc.h b/freebsd/sys/sys/proc.h
old mode 100644
new mode 100755
index ee43997..4808c75
--- a/freebsd/sys/sys/proc.h
+++ b/freebsd/sys/sys/proc.h
@@ -300,7 +300,9 @@ struct thread {
 	u_long		td_profil_addr;	/* (k) Temporary addr until AST. */
 	u_int		td_profil_ticks; /* (k) Temporary ticks until AST. */
 	char		td_name[MAXCOMLEN + 1];	/* (*) Thread name. */
+#endif /* __rtems__ */
 	struct file	*td_fpop;	/* (k) file referencing cdev under op */
+#ifndef __rtems__
 	int		td_dbgflags;	/* (c) Userland debugger flags */
 	struct ksiginfo td_dbgksi;	/* (c) ksi reflected to debugger. */
 	int		td_ng_outbound;	/* (k) Thread entered ng from above. */
diff --git a/freebsd/sys/sys/ttydefaults.h b/freebsd/sys/sys/ttydefaults.h
old mode 100644
new mode 100755
index 82929f9..0eb839b
--- a/freebsd/sys/sys/ttydefaults.h
+++ b/freebsd/sys/sys/ttydefaults.h
@@ -44,6 +44,7 @@
 /*
  * Defaults on "first" open.
  */
+#ifndef __rtems__
 #define	TTYDEF_IFLAG	(BRKINT	| ICRNL	| IMAXBEL | IXON | IXANY)
 #define	TTYDEF_OFLAG	(OPOST | ONLCR)
 #define	TTYDEF_LFLAG_NOECHO (ICANON | ISIG | IEXTEN)
@@ -51,6 +52,12 @@
 	| ECHO | ECHOE | ECHOKE | ECHOCTL)
 #define	TTYDEF_LFLAG TTYDEF_LFLAG_ECHO
 #define	TTYDEF_CFLAG	(CREAD | CS8 | HUPCL)
+#else /* __rtems__ */
+#define	TTYDEF_IFLAG	(BRKINT	| ICRNL	| IMAXBEL | IXON)
+#define	TTYDEF_OFLAG	(OPOST | ONLCR | XTABS)
+#define	TTYDEF_LFLAG  (ISIG | ICANON | IEXTEN | ECHO | ECHOK | ECHOE | ECHOCTL)
+#define	TTYDEF_CFLAG	(B9600 | CS8 | CREAD | CLOCAL)
+#endif /* __rtems__ */
 #define	TTYDEF_SPEED	(B9600)
 
 /*
@@ -99,11 +106,19 @@
 #include <sys/cdefs.h>
 #include <sys/_termios.h>
 
+#ifndef __rtems__
 static const cc_t ttydefchars[] = {
 	CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT, CERASE2, CINTR,
 	CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT, CDISCARD, CMIN, CTIME,
 	CSTATUS, _POSIX_VDISABLE
 };
+#else /* __rtems__ */
+static const cc_t ttydefchars[] = {
+	CINTR, CQUIT, CERASE, CKILL, CEOF, CTIME, 0, 0, CSTART,
+	CSTOP, 0, CREPRINT, CDISCARD, CWERASE, CLNEXT, 0, CERASE2,
+	CSTATUS, _POSIX_VDISABLE
+};
+#endif /* __rtems__ */
 _Static_assert(sizeof(ttydefchars) / sizeof(cc_t) == NCCS,
     "Size of ttydefchars does not match NCCS");
 
diff --git a/rtemsbsd/include/rtems/bsd/local/opt_gdb.h b/rtemsbsd/include/rtems/bsd/local/opt_gdb.h
new file mode 100755
index 0000000..936ffd8
--- /dev/null
+++ b/rtemsbsd/include/rtems/bsd/local/opt_gdb.h
@@ -0,0 +1 @@
+/* EMPTY */
diff --git a/rtemsbsd/include/rtems/bsd/local/opt_usb.h b/rtemsbsd/include/rtems/bsd/local/opt_usb.h
old mode 100644
new mode 100755
index 7eb6148..2b7227b
--- a/rtemsbsd/include/rtems/bsd/local/opt_usb.h
+++ b/rtemsbsd/include/rtems/bsd/local/opt_usb.h
@@ -1,6 +1,6 @@
 #define USB_HAVE_CONDVAR 1
 
-#define USB_HAVE_UGEN 0
+#define USB_HAVE_UGEN 1
 
 #define USB_HAVE_BUSDMA 1
 
diff --git a/rtemsbsd/sys/fs/devfs/devfs_devs.c b/rtemsbsd/sys/fs/devfs/devfs_devs.c
index 0ee71ff..a91a02e 100755
--- a/rtemsbsd/sys/fs/devfs/devfs_devs.c
+++ b/rtemsbsd/sys/fs/devfs/devfs_devs.c
@@ -36,6 +36,7 @@
 #include <sys/kernel.h>
 #include <sys/file.h>
 #include <sys/malloc.h>
+#include <sys/proc.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -50,8 +51,16 @@
 
 const char rtems_cdev_directory[] = RTEMS_CDEV_DIRECTORY;
 
+/*
+ * The one true (but secret) list of active devices in the system.
+ * Locked by dev_lock()/devmtx
+ */
+struct cdev_priv_list cdevp_list = TAILQ_HEAD_INITIALIZER(cdevp_list);
+
 struct unrhdr *devfs_inos;
 
+static MALLOC_DEFINE(M_CDEVP, "DEVFS1", "DEVFS cdev_priv storage");
+
 static struct cdev *
 devfs_imfs_get_context_by_iop(rtems_libio_t *iop)
 {
@@ -62,11 +71,19 @@ static int
 devfs_imfs_open(rtems_libio_t *iop, const char *path, int oflag, mode_t mode)
 {
 	struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
+	struct file *fp = rtems_bsd_iop_to_fp(iop);
 	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct file *fpop;
 	int error;
 
 	if (td != NULL) {
+		fpop = td->td_fpop;
+		curthread->td_fpop = fp;
 		error = cdev->si_devsw->d_open(cdev, oflag, 0, td);
+		/* Clean up any cdevpriv upon error. */
+		if (error != 0)
+			devfs_clear_cdevpriv();
+		curthread->td_fpop = fpop;
 	} else {
 		error = ENOMEM;
 	}
@@ -78,12 +95,17 @@ static int
 devfs_imfs_close(rtems_libio_t *iop)
 {
 	struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
+	struct file *fp = rtems_bsd_iop_to_fp(iop);
 	struct thread *td = rtems_bsd_get_curthread_or_null();
 	int flags = rtems_libio_to_fcntl_flags(iop->flags);
+	struct file *fpop;
 	int error;
 
 	if (td != NULL) {
+		fpop = td->td_fpop;
+		curthread->td_fpop = fp;
 		error = cdev->si_devsw->d_close(cdev, flags, 0, td);
+		curthread->td_fpop = fpop;
 	} else {
 		error = ENOMEM;
 	}
@@ -96,6 +118,7 @@ devfs_imfs_readv(rtems_libio_t *iop, const struct iovec *iov, int iovcnt,
     ssize_t total)
 {
 	struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
+	struct file *fp = rtems_bsd_iop_to_fp(iop);
 	struct thread *td = rtems_bsd_get_curthread_or_null();
 	struct uio uio = {
 		.uio_iov = __DECONST(struct iovec *, iov),
@@ -106,11 +129,15 @@ devfs_imfs_readv(rtems_libio_t *iop, const struct iovec *iov, int iovcnt,
 		.uio_rw = UIO_READ,
 		.uio_td = td
 	};
+	struct file *fpop;
 	int error;
 
 	if (td != NULL) {
+		fpop = td->td_fpop;
+		curthread->td_fpop = fp;
 		error = cdev->si_devsw->d_read(cdev, &uio,
 		    rtems_libio_to_fcntl_flags(iop->flags));
+		td->td_fpop = fpop;
 	} else {
 		error = ENOMEM;
 	}
@@ -138,6 +165,7 @@ devfs_imfs_writev(rtems_libio_t *iop, const struct iovec *iov, int iovcnt,
     ssize_t total)
 {
 	struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
+	struct file *fp = rtems_bsd_iop_to_fp(iop);
 	struct thread *td = rtems_bsd_get_curthread_or_null();
 	struct uio uio = {
 		.uio_iov = __DECONST(struct iovec *, iov),
@@ -148,11 +176,15 @@ devfs_imfs_writev(rtems_libio_t *iop, const struct iovec *iov, int iovcnt,
 		.uio_rw = UIO_WRITE,
 		.uio_td = td
 	};
+	struct file *fpop;
 	int error;
 
 	if (td != NULL) {
+		fpop = td->td_fpop;
+		curthread->td_fpop = fp;
 		error = cdev->si_devsw->d_write(cdev, &uio,
 		    rtems_libio_to_fcntl_flags(iop->flags));
+		td->td_fpop = fpop;
 	} else {
 		error = ENOMEM;
 	}
@@ -179,13 +211,18 @@ static int
 devfs_imfs_ioctl(rtems_libio_t *iop, ioctl_command_t request, void *buffer)
 {
 	struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
+	struct file *fp = rtems_bsd_iop_to_fp(iop);
 	struct thread *td = rtems_bsd_get_curthread_or_null();
+	struct file *fpop;
 	int error;
 	int flags = rtems_libio_to_fcntl_flags(iop->flags);
 
 	if (td != 0) {
+		fpop = td->td_fpop;
+		curthread->td_fpop = fp;
 		error = cdev->si_devsw->d_ioctl(cdev, request, buffer, flags,
 		    td);
+		td->td_fpop = fpop;
 	} else {
 		error = ENOMEM;
 	}
@@ -197,17 +234,34 @@ static int
 devfs_imfs_poll(rtems_libio_t *iop, int events)
 {
 	struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
+	struct file *fp = rtems_bsd_iop_to_fp(iop);
+	struct thread *td = rtems_bsd_get_curthread_or_wait_forever();
+	struct file *fpop;
+	int error;
+
+	fpop = td->td_fpop;
+	curthread->td_fpop = fp;
+	error = cdev->si_devsw->d_poll(cdev, events, td);
+	td->td_fpop = fpop;
 
-	return (cdev->si_devsw->d_poll(cdev, events,
-	    rtems_bsd_get_curthread_or_wait_forever()));
+	return error;
 }
 
 static int
 devfs_imfs_kqfilter(rtems_libio_t *iop, struct knote *kn)
 {
 	struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
+	struct file *fp = rtems_bsd_iop_to_fp(iop);
+	struct thread *td = rtems_bsd_get_curthread_or_wait_forever();
+	struct file *fpop;
+	int error;
+
+	fpop = td->td_fpop;
+	curthread->td_fpop = fp;
+	error = cdev->si_devsw->d_kqfilter(cdev, kn);
+	td->td_fpop = fpop;
 
-	return (cdev->si_devsw->d_kqfilter(cdev, kn));
+	return error;
 }
 
 static const rtems_filesystem_file_handlers_r devfs_imfs_handlers = {
@@ -235,12 +289,17 @@ static const IMFS_node_control devfs_imfs_control = IMFS_GENERIC_INITIALIZER(
 struct cdev *
 devfs_alloc(int flags)
 {
+	struct cdev_priv *cdp;
 	struct cdev *cdev;
 
-	cdev = malloc(sizeof *cdev, M_TEMP, M_ZERO);
-	if (cdev == NULL)
+	cdp = malloc(sizeof *cdp, M_CDEVP, M_ZERO |
+	    ((flags & MAKEDEV_NOWAIT) ? M_NOWAIT : M_WAITOK));
+	if (cdp == NULL)
 		return (NULL);
 
+	cdev = &cdp->cdp_c;
+	LIST_INIT(&cdev->si_children);
+
 	memcpy(cdev->si_path, rtems_cdev_directory, sizeof(cdev->si_path));
 	return (cdev);
 }
@@ -248,7 +307,11 @@ devfs_alloc(int flags)
 void
 devfs_free(struct cdev *cdev)
 {
-	free(cdev, M_TEMP);
+	struct cdev_priv *cdp;
+
+	cdp = cdev2priv(cdev);
+	devfs_free_cdp_inode(cdp->cdp_inode);
+	free(cdp, M_CDEVP);
 }
 
 /*
@@ -286,6 +349,7 @@ devfs_create_directory(const char *devname)
 void
 devfs_create(struct cdev *dev)
 {
+	struct cdev_priv *cdp;
 	int rv;
 	mode_t mode = S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO;
 
@@ -294,13 +358,23 @@ devfs_create(struct cdev *dev)
 	rv = IMFS_make_generic_node(dev->si_path, mode, &devfs_imfs_control,
 	    dev);
 	BSD_ASSERT(rv == 0);
+
+	cdp = cdev2priv(dev);
+	cdp->cdp_flags |= CDP_ACTIVE;
+	cdp->cdp_inode = alloc_unrl(devfs_inos);
+	dev_refl(dev);
+	TAILQ_INSERT_TAIL(&cdevp_list, cdp, cdp_list);
 }
 
 void
 devfs_destroy(struct cdev *dev)
 {
+	struct cdev_priv *cdp;
 	int rv;
 
+	cdp = cdev2priv(dev);
+	cdp->cdp_flags &= ~CDP_ACTIVE;
+
 	rv = unlink(dev->si_path);
 	BSD_ASSERT(rv == 0);
 
-- 
1.9.1



More information about the devel mailing list