Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/snp/snp.c
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | snp_read(struct cdev *dev, struct uio *uio, int flag) | ||||
if (uio->uio_resid == 0) | if (uio->uio_resid == 0) | ||||
return (0); | return (0); | ||||
error = devfs_get_cdevpriv((void **)&ss); | error = devfs_get_cdevpriv((void **)&ss); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
tp = ss->snp_tty; | tp = ss->snp_tty; | ||||
if (tp == NULL || tty_gone(tp)) | if (tp == NULL) | ||||
return (EIO); | return (EIO); | ||||
ttydisc_lock(tp); | |||||
if (tty_gone(tp)) { | |||||
ttydisc_unlock(tp); | |||||
return (EIO); | |||||
} | |||||
tty_lock(tp); | |||||
for (;;) { | for (;;) { | ||||
error = ttyoutq_read_uio(&ss->snp_outq, tp, uio); | error = ttyoutq_read_uio(&ss->snp_outq, tp, uio); | ||||
if (error != 0 || uio->uio_resid != oresid) | if (error != 0 || uio->uio_resid != oresid) | ||||
break; | break; | ||||
/* Wait for more data. */ | /* Wait for more data. */ | ||||
if (flag & O_NONBLOCK) { | if (flag & O_NONBLOCK) { | ||||
error = EWOULDBLOCK; | error = EWOULDBLOCK; | ||||
break; | break; | ||||
} | } | ||||
error = cv_wait_sig(&ss->snp_outwait, tty_getlock(tp)); | error = cv_wait_sig(&ss->snp_outwait, ttydisc_getlock(tp)); | ||||
if (error != 0) | if (error != 0) | ||||
break; | break; | ||||
if (tty_gone(tp)) { | if (tty_gone(tp)) { | ||||
error = EIO; | error = EIO; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
tty_unlock(tp); | ttydisc_unlock(tp); | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
snp_write(struct cdev *dev, struct uio *uio, int flag) | snp_write(struct cdev *dev, struct uio *uio, int flag) | ||||
{ | { | ||||
struct snp_softc *ss; | struct snp_softc *ss; | ||||
Show All 11 Lines | snp_write(struct cdev *dev, struct uio *uio, int flag) | ||||
while (uio->uio_resid > 0) { | while (uio->uio_resid > 0) { | ||||
/* Read new data. */ | /* Read new data. */ | ||||
len = imin(uio->uio_resid, sizeof in); | len = imin(uio->uio_resid, sizeof in); | ||||
error = uiomove(in, len, uio); | error = uiomove(in, len, uio); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
tty_lock(tp); | ttydisc_lock(tp); | ||||
/* Driver could have abandoned the TTY in the mean time. */ | /* Driver could have abandoned the TTY in the mean time. */ | ||||
if (tty_gone(tp)) { | if (tty_gone(tp)) { | ||||
tty_unlock(tp); | ttydisc_unlock(tp); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
/* | /* | ||||
* Deliver data to the TTY. Ignore errors for now, | * Deliver data to the TTY. Ignore errors for now, | ||||
* because we shouldn't bail out when we're running | * because we shouldn't bail out when we're running | ||||
* close to the watermarks. | * close to the watermarks. | ||||
*/ | */ | ||||
ttydisc_rint_simple(tp, in, len); | ttydisc_rint_simple(tp, in, len); | ||||
ttydisc_rint_done(tp); | ttydisc_rint_done(tp); | ||||
tty_unlock(tp); | ttydisc_unlock(tp); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
snp_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, | snp_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, | ||||
struct thread *td) | struct thread *td) | ||||
Show All 31 Lines | error = ttyhook_register(&ss->snp_tty, td->td_proc, | ||||
*(int *)data, &snp_hook, ss); | *(int *)data, &snp_hook, ss); | ||||
SNP_UNLOCK(); | SNP_UNLOCK(); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
/* Now that went okay, allocate a buffer for the queue. */ | /* Now that went okay, allocate a buffer for the queue. */ | ||||
tp = ss->snp_tty; | tp = ss->snp_tty; | ||||
tty_lock(tp); | tty_lock(tp); | ||||
ttydisc_lock(tp); | |||||
ttyoutq_setsize(&ss->snp_outq, tp, SNP_OUTPUT_BUFSIZE); | ttyoutq_setsize(&ss->snp_outq, tp, SNP_OUTPUT_BUFSIZE); | ||||
ttydisc_unlock(tp); | |||||
tty_unlock(tp); | tty_unlock(tp); | ||||
return (0); | return (0); | ||||
case SNPGTTY: | case SNPGTTY: | ||||
/* Obtain device number of associated TTY. */ | /* Obtain device number of associated TTY. */ | ||||
if (ss->snp_tty == NULL) | if (ss->snp_tty == NULL) | ||||
*(dev_t *)data = NODEV; | *(dev_t *)data = NODEV; | ||||
else | else | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |