use device_lookup_private to get softc

This commit is contained in:
cegger 2008-06-13 12:08:01 +00:00
parent 175e9cfe68
commit 27309530b4
2 changed files with 30 additions and 37 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sbjcn.c,v 1.20 2008/04/28 20:23:28 martin Exp $ */
/* $NetBSD: sbjcn.c,v 1.21 2008/06/13 12:08:01 cegger Exp $ */
/*
* Copyright 2000, 2001
@ -103,7 +103,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sbjcn.c,v 1.20 2008/04/28 20:23:28 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: sbjcn.c,v 1.21 2008/06/13 12:08:01 cegger Exp $");
#define SBJCN_DEBUG
@ -485,7 +485,6 @@ sbjcn_shutdown(struct sbjcn_channel *ch)
int
sbjcnopen(dev_t dev, int flag, int mode, struct lwp *l)
{
int unit = SBJCN_UNIT(dev);
int chan = SBJCN_CHAN(dev);
struct sbjcn_softc *sc;
struct sbjcn_channel *ch;
@ -493,11 +492,10 @@ sbjcnopen(dev_t dev, int flag, int mode, struct lwp *l)
int s, s2;
int error;
if (unit >= sbjcn_cd.cd_ndevs)
return (ENXIO);
sc = sbjcn_cd.cd_devs[unit];
if (sc == 0)
sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(dev));
if (sc == NULL)
return (ENXIO);
ch = &sc->sc_channels[chan];
if (!ISSET(ch->ch_hwflags, SBJCN_HW_DEV_OK) || ch->ch_rbuf == NULL)
return (ENXIO);
@ -615,7 +613,7 @@ bad:
int
sbjcnclose(dev_t dev, int flag, int mode, struct proc *p)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -641,7 +639,7 @@ sbjcnclose(dev_t dev, int flag, int mode, struct proc *p)
int
sbjcnread(dev_t dev, struct uio *uio, int flag)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -651,7 +649,7 @@ sbjcnread(dev_t dev, struct uio *uio, int flag)
int
sbjcnwrite(dev_t dev, struct uio *uio, int flag)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -661,7 +659,7 @@ sbjcnwrite(dev_t dev, struct uio *uio, int flag)
struct tty *
sbjcntty(dev_t dev)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -671,7 +669,7 @@ sbjcntty(dev_t dev)
int
sbjcnioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
int error;
@ -890,7 +888,7 @@ cflag2modes(cflag, mode1p, mode2p)
int
sbjcn_param(struct tty *tp, struct termios *t)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(tp->t_dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(tp->t_dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(tp->t_dev)];
long brc;
u_char mode1, mode2;
@ -1061,7 +1059,7 @@ sbjcn_loadchannelregs(struct sbjcn_channel *ch)
int
sbjcn_hwiflow(struct tty *tp, int block)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(tp->t_dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(tp->t_dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(tp->t_dev)];
int s;
@ -1110,7 +1108,7 @@ sbjcn_dohwiflow(struct sbjcn_channel *ch)
void
sbjcn_start(struct tty *tp)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(tp->t_dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(tp->t_dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(tp->t_dev)];
int s;
@ -1170,7 +1168,7 @@ out:
void
sbjcnstop(struct tty *tp, int flag)
{
struct sbjcn_softc *sc = sbjcn_cd.cd_devs[SBJCN_UNIT(tp->t_dev)];
struct sbjcn_softc *sc = device_lookup_private(&sbjcn_cd, SBJCN_UNIT(tp->t_dev));
struct sbjcn_channel *ch = &sc->sc_channels[SBJCN_CHAN(tp->t_dev)];
int s;
@ -1186,8 +1184,7 @@ sbjcnstop(struct tty *tp, int flag)
}
void
sbjcn_diag(arg)
void *arg;
sbjcn_diag(void *arg)
{
struct sbjcn_channel *ch = arg;
struct sbjcn_softc *sc = ch->ch_sc;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sbscn.c,v 1.26 2008/04/28 20:23:28 martin Exp $ */
/* $NetBSD: sbscn.c,v 1.27 2008/06/13 12:08:01 cegger Exp $ */
/*
* Copyright 2000, 2001
@ -109,7 +109,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sbscn.c,v 1.26 2008/04/28 20:23:28 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: sbscn.c,v 1.27 2008/06/13 12:08:01 cegger Exp $");
#define SBSCN_DEBUG
@ -537,7 +537,6 @@ sbscn_shutdown(struct sbscn_channel *ch)
int
sbscnopen(dev_t dev, int flag, int mode, struct lwp *l)
{
int unit = SBSCN_UNIT(dev);
int chan = SBSCN_CHAN(dev);
struct sbscn_softc *sc;
struct sbscn_channel *ch;
@ -545,10 +544,8 @@ sbscnopen(dev_t dev, int flag, int mode, struct lwp *l)
int s, s2;
int error;
if (unit >= sbscn_cd.cd_ndevs)
return (ENXIO);
sc = sbscn_cd.cd_devs[unit];
if (sc == 0)
sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(dev));
if (sc == NULL)
return (ENXIO);
ch = &sc->sc_channels[chan];
if (!ISSET(ch->ch_hwflags, SBSCN_HW_DEV_OK) || ch->ch_rbuf == NULL)
@ -672,7 +669,7 @@ bad:
int
sbscnclose(dev_t dev, int flag, int mode, struct lwp *l)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -698,7 +695,7 @@ sbscnclose(dev_t dev, int flag, int mode, struct lwp *l)
int
sbscnread(dev_t dev, struct uio *uio, int flag)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -708,7 +705,7 @@ sbscnread(dev_t dev, struct uio *uio, int flag)
int
sbscnwrite(dev_t dev, struct uio *uio, int flag)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -718,7 +715,7 @@ sbscnwrite(dev_t dev, struct uio *uio, int flag)
int
sbscnpoll(dev_t dev, int events, struct lwp *l)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -728,7 +725,7 @@ sbscnpoll(dev_t dev, int events, struct lwp *l)
struct tty *
sbscntty(dev_t dev)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
@ -738,7 +735,7 @@ sbscntty(dev_t dev)
int
sbscnioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(dev)];
struct tty *tp = ch->ch_tty;
int error;
@ -974,7 +971,7 @@ cflag2modes(cflag, mode1p, mode2p)
int
sbscn_param(struct tty *tp, struct termios *t)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(tp->t_dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(tp->t_dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(tp->t_dev)];
long brc;
u_char mode1, mode2;
@ -1170,7 +1167,7 @@ sbscn_loadchannelregs(struct sbscn_channel *ch)
int
sbscn_hwiflow(struct tty *tp, int block)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(tp->t_dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(tp->t_dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(tp->t_dev)];
int s;
@ -1220,7 +1217,7 @@ sbscn_dohwiflow(struct sbscn_channel *ch)
void
sbscn_start(struct tty *tp)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(tp->t_dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(tp->t_dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(tp->t_dev)];
int s;
@ -1276,7 +1273,7 @@ out:
void
sbscnstop(struct tty *tp, int flag)
{
struct sbscn_softc *sc = sbscn_cd.cd_devs[SBSCN_UNIT(tp->t_dev)];
struct sbscn_softc *sc = device_lookup_private(&sbscn_cd, SBSCN_UNIT(tp->t_dev));
struct sbscn_channel *ch = &sc->sc_channels[SBSCN_CHAN(tp->t_dev)];
int s;
@ -1292,8 +1289,7 @@ sbscnstop(struct tty *tp, int flag)
}
void
sbscn_diag(arg)
void *arg;
sbscn_diag(void *arg)
{
struct sbscn_channel *ch = arg;
struct sbscn_softc *sc = ch->ch_sc;