Device megapatch 3/6:

Add missing D_TTY flags to various drivers.

Complete asserts that dev_t's passed to ttyread(), ttywrite(),
ttypoll() and ttykqwrite() have (d_flags & D_TTY) and a struct tty
pointer.

Make ttyread(), ttywrite(), ttypoll() and ttykqwrite() the default
cdevsw methods for D_TTY drivers and remove the explicit initializations
in various drivers cdevsw structures.
This commit is contained in:
Poul-Henning Kamp 2004-02-21 20:41:11 +00:00
parent b0b0334878
commit 8e1f1df080
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=126078
29 changed files with 31 additions and 76 deletions

View File

@ -66,11 +66,9 @@ static d_ioctl_t promioctl;
static struct cdevsw prom_cdevsw = {
.d_open = promopen,
.d_close = promclose,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = promioctl,
.d_poll = ttypoll,
.d_name = "prom",
.d_flags = D_TTY,
};

View File

@ -73,11 +73,9 @@ static d_ioctl_t zsioctl;
static struct cdevsw zs_cdevsw = {
.d_open = zsopen,
.d_close = zsclose,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = zsioctl,
.d_poll = ttypoll,
.d_name = "zs",
.d_flags = D_TTY,
};
static void zsstart(struct tty *);

View File

@ -2555,7 +2555,6 @@ static struct cdevsw cx_cdevsw = {
.d_read = cx_read,
.d_write = cx_write,
.d_ioctl = cx_ioctl,
.d_poll = ttypoll,
.d_name = "cx",
.d_maj = CDEV_MAJOR,
.d_flags = D_TTY,

View File

@ -388,13 +388,10 @@ static d_ioctl_t sioioctl;
static struct cdevsw sio_cdevsw = {
.d_open = sioopen,
.d_close = sioclose,
.d_read = ttyread,
.d_write = siowrite,
.d_ioctl = sioioctl,
.d_poll = ttypoll,
.d_name = driver_name,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static int comconsole = -1;

View File

@ -388,13 +388,10 @@ static d_ioctl_t sioioctl;
static struct cdevsw sio_cdevsw = {
.d_open = sioopen,
.d_close = sioclose,
.d_read = ttyread,
.d_write = siowrite,
.d_ioctl = sioioctl,
.d_poll = ttypoll,
.d_name = driver_name,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static int comconsole = -1;

View File

@ -90,11 +90,9 @@ static struct cdevsw dcons_cdevsw = {
#if __FreeBSD_version >= 500104
.d_open = dcons_open,
.d_close = dcons_close,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = dcons_ioctl,
.d_poll = ttypoll,
.d_name = "dcons",
.d_flags = D_TTY,
#else
/* open */ dcons_open,
/* close */ dcons_close,

View File

@ -147,10 +147,8 @@ static struct cdevsw digi_sw = {
.d_read = digiread,
.d_write = digiwrite,
.d_ioctl = digiioctl,
.d_poll = ttypoll,
.d_name = driver_name,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter
};
static void

View File

@ -77,7 +77,6 @@ static struct cdevsw nmdm_cdevsw = {
.d_read = nmdmread,
.d_write = nmdmwrite,
.d_ioctl = nmdmioctl,
.d_poll = ttypoll,
.d_name = "nmdm",
.d_flags = D_TTY | D_PSEUDO,
};

View File

@ -55,11 +55,9 @@ static d_ioctl_t ofw_dev_ioctl;
static struct cdevsw ofw_cdevsw = {
.d_open = ofw_dev_open,
.d_close = ofw_dev_close,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = ofw_dev_ioctl,
.d_poll = ttypoll,
.d_name = "ofw",
.d_flags = D_TTY,
};
static struct tty *ofw_tp = NULL;

View File

@ -149,13 +149,9 @@ static d_ioctl_t rcioctl;
static struct cdevsw rc_cdevsw = {
.d_open = rcopen,
.d_close = rcclose,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = rcioctl,
.d_poll = ttypoll,
.d_name = "rc",
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static devclass_t rc_devclass;

View File

@ -574,10 +574,8 @@ static d_ioctl_t rpioctl;
struct cdevsw rp_cdevsw = {
.d_open = rpopen,
.d_close = rpclose,
.d_read = ttyread,
.d_write = rpwrite,
.d_ioctl = rpioctl,
.d_poll = ttypoll,
.d_name = "rp",
.d_flags = D_TTY,
};

View File

@ -163,13 +163,9 @@ static int sabttyparam(struct tty *tp, struct termios *t);
static struct cdevsw sabtty_cdevsw = {
.d_open = sabttyopen,
.d_close = sabttyclose,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = sabttyioctl,
.d_poll = ttypoll,
.d_name = "sabtty",
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static device_method_t sab_methods[] = {

View File

@ -120,13 +120,10 @@ static d_ioctl_t siioctl;
static struct cdevsw si_cdevsw = {
.d_open = siopen,
.d_close = siclose,
.d_read = ttyread,
.d_write = siwrite,
.d_ioctl = siioctl,
.d_poll = ttypoll,
.d_name = "si",
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static int si_Nports;

View File

@ -328,10 +328,8 @@ static struct cdevsw sio_cdevsw = {
.d_read = sioread,
.d_write = siowrite,
.d_ioctl = sioioctl,
.d_poll = ttypoll,
.d_name = sio_driver_name,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
int comconsole = -1;

View File

@ -221,14 +221,11 @@ static struct cdevsw sc_cdevsw = {
.d_open = scopen,
.d_close = scclose,
.d_read = scread,
.d_write = ttywrite,
.d_ioctl = scioctl,
.d_poll = ttypoll,
.d_mmap = scmmap,
.d_name = "sc",
.d_maj = CDEV_MAJOR,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter
};
int

View File

@ -51,9 +51,7 @@ static d_ioctl_t smioctl;
static struct cdevsw sm_cdevsw = {
.d_open = smopen,
.d_close = smclose,
.d_read = ttyread,
.d_ioctl = smioctl,
.d_poll = ttypoll,
.d_name = "sysmouse",
.d_flags = D_TTY,
};

View File

@ -69,13 +69,9 @@ static d_ioctl_t uart_tty_ioctl;
static struct cdevsw uart_cdevsw = {
.d_open = uart_tty_open,
.d_close = uart_tty_close,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = uart_tty_ioctl,
.d_poll = ttypoll,
.d_name = uart_driver_name,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static struct uart_devinfo uart_console;

View File

@ -133,13 +133,11 @@ static struct cdevsw ucom_cdevsw = {
.d_read = ucomread,
.d_write = ucomwrite,
.d_ioctl = ucomioctl,
.d_poll = ttypoll,
.d_name = "ucom",
.d_flags = D_TTY,
#if __FreeBSD_version < 500014
.d_bmaj = -1,
#endif
.d_kqfilter = ttykqfilter,
};
Static void ucom_cleanup(struct ucom_softc *);

View File

@ -154,13 +154,9 @@ static int zsttyparam(struct tty *tp, struct termios *t);
static struct cdevsw zstty_cdevsw = {
.d_open = zsttyopen,
.d_close = zsttyclose,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = zsttyioctl,
.d_poll = ttypoll,
.d_name = "zstty",
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static struct zstty_softc *zstty_cons;

View File

@ -388,13 +388,10 @@ static d_ioctl_t sioioctl;
static struct cdevsw sio_cdevsw = {
.d_open = sioopen,
.d_close = sioclose,
.d_read = ttyread,
.d_write = siowrite,
.d_ioctl = sioioctl,
.d_poll = ttypoll,
.d_name = driver_name,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static int comconsole = -1;

View File

@ -648,10 +648,8 @@ static struct cdevsw stli_cdevsw = {
.d_read = stliread,
.d_write = stliwrite,
.d_ioctl = stliioctl,
.d_poll = ttypoll,
.d_name = stli_drvname,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
#endif

View File

@ -97,14 +97,10 @@ static d_mmap_t pcvt_mmap;
static struct cdevsw vt_cdevsw = {
.d_open = pcvt_open,
.d_close = pcvt_close,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = pcvt_ioctl,
.d_poll = ttypoll,
.d_mmap = pcvt_mmap,
.d_name = "vt",
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
static int pcvt_probe(device_t dev);

View File

@ -539,13 +539,9 @@ COMPAT_PCI_DRIVER (stlpci, stlpcidriver);
static struct cdevsw stl_cdevsw = {
.d_open = stlopen,
.d_close = stlclose,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = stlioctl,
.d_poll = ttypoll,
.d_name = "stl",
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
#endif

View File

@ -60,11 +60,9 @@ static d_ioctl_t sscioctl;
static struct cdevsw ssc_cdevsw = {
.d_open = sscopen,
.d_close = sscclose,
.d_read = ttyread,
.d_write = ttywrite,
.d_ioctl = sscioctl,
.d_poll = ttypoll,
.d_name = "ssc",
.d_flags = D_TTY,
};
static struct tty *ssc_tp = NULL;

View File

@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
#include <sys/queue.h>
#include <sys/poll.h>
#include <sys/ctype.h>
#include <sys/tty.h>
#include <machine/stdarg.h>
static MALLOC_DEFINE(M_DEVT, "dev_t", "dev_t storage");
@ -340,6 +341,13 @@ static void
prep_cdevsw(struct cdevsw *devsw)
{
if (devsw->d_flags & D_TTY) {
if (devsw->d_read == NULL) devsw->d_read = ttyread;
if (devsw->d_write == NULL) devsw->d_write = ttywrite;
if (devsw->d_kqfilter == NULL) devsw->d_kqfilter = ttykqfilter;
if (devsw->d_poll == NULL) devsw->d_poll = ttypoll;
}
if (devsw->d_open == NULL) devsw->d_open = null_open;
if (devsw->d_close == NULL) devsw->d_close = null_close;
if (devsw->d_read == NULL) devsw->d_read = no_read;

View File

@ -1142,7 +1142,11 @@ ttypoll(dev_t dev, int events, struct thread *td)
int revents = 0;
struct tty *tp;
KASSERT(devsw(dev)->d_flags & D_TTY,
("ttypoll() called on non D_TTY device (%s)", devtoname(dev)));
tp = dev->si_tty;
KASSERT(tp != NULL,
("ttypoll(): no tty pointer on device (%s)", devtoname(dev)));
if (tp == NULL) /* XXX used to return ENXIO, but that means true! */
return ((events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM))
| POLLHUP);
@ -1174,10 +1178,15 @@ static struct filterops ttywrite_filtops =
int
ttykqfilter(dev_t dev, struct knote *kn)
{
struct tty *tp = dev->si_tty;
struct tty *tp;
struct klist *klist;
int s;
KASSERT(devsw(dev)->d_flags & D_TTY,
("ttykqfilter() called on non D_TTY device (%s)", devtoname(dev)));
tp = dev->si_tty;
KASSERT(tp != NULL,
("ttykqfilter(): no tty pointer on device (%s)", devtoname(dev)));
switch (kn->kn_filter) {
case EVFILT_READ:
klist = &tp->t_rsel.si_note;
@ -2722,7 +2731,11 @@ ttyread(dev_t dev, struct uio *uio, int flag)
{
struct tty *tp;
KASSERT(devsw(dev)->d_flags & D_TTY,
("ttyread() called on non D_TTY device (%s)", devtoname(dev)));
tp = dev->si_tty;
KASSERT(tp != NULL,
("ttyread(): no tty pointer on device (%s)", devtoname(dev)));
if (tp == NULL)
return (ENODEV);
return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
@ -2733,7 +2746,11 @@ ttywrite(dev_t dev, struct uio *uio, int flag)
{
struct tty *tp;
KASSERT(devsw(dev)->d_flags & D_TTY,
("ttywrite() called on non D_TTY device (%s)", devtoname(dev)));
tp = dev->si_tty;
KASSERT(tp != NULL,
("ttywrite(): no tty pointer on device (%s)", devtoname(dev)));
if (tp == NULL)
return (ENODEV);
return ((*linesw[tp->t_line].l_write)(tp, uio, flag));

View File

@ -85,11 +85,9 @@ static struct cdevsw pts_cdevsw = {
.d_read = ptsread,
.d_write = ptswrite,
.d_ioctl = ptyioctl,
.d_poll = ttypoll,
.d_name = "pts",
.d_maj = CDEV_MAJOR_S,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
#define CDEV_MAJOR_C 6
@ -103,7 +101,6 @@ static struct cdevsw ptc_cdevsw = {
.d_name = "ptc",
.d_maj = CDEV_MAJOR_C,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
#define BUFSIZ 100 /* Chunk size iomoved to/from user */

View File

@ -421,10 +421,8 @@ static struct cdevsw sio_cdevsw = {
.d_read = sioread,
.d_write = siowrite,
.d_ioctl = sioioctl,
.d_poll = ttypoll,
.d_name = sio_driver_name,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
int comconsole = -1;

View File

@ -421,10 +421,8 @@ static struct cdevsw sio_cdevsw = {
.d_read = sioread,
.d_write = siowrite,
.d_ioctl = sioioctl,
.d_poll = ttypoll,
.d_name = sio_driver_name,
.d_flags = D_TTY,
.d_kqfilter = ttykqfilter,
};
int comconsole = -1;