clean up and fix irframe attachment as a line discipline:

make it a regular "bus frontend" in terms of configuration attachment
(this is something new: a device which can be real or pseudo device),
and use only autoconf functions considered exported.
This suffers a bit from the fact that pseudo-devices don't get "aux"
context data passed to the xxx_attach() function. This can be changed
easily; the differences between real and pseudo devices are diminishing...
This commit is contained in:
drochner 2007-03-06 20:45:59 +00:00
parent 603c9278cd
commit e612542ff1
3 changed files with 60 additions and 69 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: irframe.c,v 1.38 2007/03/05 20:23:14 drochner Exp $ */
/* $NetBSD: irframe.c,v 1.39 2007/03/06 20:45:59 drochner Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irframe.c,v 1.38 2007/03/05 20:23:14 drochner Exp $");
__KERNEL_RCSID(0, "$NetBSD: irframe.c,v 1.39 2007/03/06 20:45:59 drochner Exp $");
#include "irframe.h"
@ -79,9 +79,7 @@ const struct cdevsw irframe_cdevsw = {
};
int irframe_match(struct device *parent, struct cfdata *match, void *aux);
void irframe_attach(struct device *parent, struct device *self, void *aux);
int irframe_activate(struct device *self, enum devact act);
int irframe_detach(struct device *self, int flags);
Static int irf_set_params(struct irframe_softc *sc, struct irda_params *p);
Static int irf_reset_params(struct irframe_softc *sc);
@ -406,57 +404,3 @@ irframekqfilter(dev_t dev, struct knote *kn)
return (sc->sc_methods->im_kqfilter(sc->sc_handle, kn));
}
/*********/
struct device *
irframe_alloc(size_t size, const struct irframe_methods *m, void *h)
{
struct cfdriver *cd = &irframe_cd;
struct cfdata *cfdata;
struct device *dev;
struct ir_attach_args ia;
int unit;
/* XXX This is wrong */
cfdata = malloc(sizeof(struct cfdata), M_DEVBUF, M_WAITOK);
for (unit = 0; unit < cd->cd_ndevs; unit++)
if (cd->cd_devs[unit] == NULL)
break;
cfdata->cf_name = "irframe";
cfdata->cf_atname = "irframe"; /* ??? */
cfdata->cf_unit = unit;
cfdata->cf_fstate = FSTATE_STAR;
dev = config_attach_pseudo(cfdata);
ia.ia_methods = m;
ia.ia_handle = h;
printf("%s", dev->dv_xname);
return (dev);
}
void
irframe_dealloc(struct device *dev)
{
struct cfdriver *cd = &irframe_cd;
int unit;
/*
* XXXJRT This is wrong -- needs to be done using regular
* XXXJRT autoconfiguration code.
*/
for (unit = 0; unit < cd->cd_ndevs; unit++) {
if (cd->cd_devs[unit] == dev) {
cd->cd_devs[unit] = NULL;
free(dev, M_DEVBUF);
return;
}
}
panic("irframe_dealloc: device not found");
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: irframe_tty.c,v 1.41 2007/03/04 06:02:09 christos Exp $ */
/* $NetBSD: irframe_tty.c,v 1.42 2007/03/06 20:45:59 drochner Exp $ */
/*
* TODO
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irframe_tty.c,v 1.41 2007/03/04 06:02:09 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: irframe_tty.c,v 1.42 2007/03/06 20:45:59 drochner Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@ -201,11 +201,43 @@ static struct linesw irframet_disc = {
.l_poll = ttyerrpoll
};
/* glue to attach irframe device */
static void irframet_attach(struct device *, struct device *, void *);
static int irframet_detach(struct device *, int);
CFATTACH_DECL(irframet, sizeof(struct irframet_softc),
NULL, irframet_attach, irframet_detach, NULL);
void
irframettyattach(int n)
{
(void) ttyldisc_attach(&irframet_disc);
config_cfattach_attach("irframe", &irframet_ca);
}
static void
irframet_attach(struct device *parent, struct device *self, void *aux)
{
/* pseudo-device attachment does not print name */
printf("%s", self->dv_xname);
#if 0 /* XXX can't do it yet because pseudo-devices don't get aux */
struct ir_attach_args ia;
ia.ia_methods = &irframet_methods;
ia.ia_handle = aux->xxx;
irframe_attach(parent, self, &ia);
#endif
}
static int
irframet_detach(struct device *dev, int flags)
{
return (irframe_detach(dev, flags));
}
/*
@ -220,6 +252,8 @@ irframetopen(dev_t dev, struct tty *tp)
struct lwp *l = curlwp; /* XXX */
struct irframet_softc *sc;
int error, s;
struct cfdata *cfdata;
struct ir_attach_args ia;
DPRINTF(("%s\n", __FUNCTION__));
@ -240,9 +274,19 @@ irframetopen(dev_t dev, struct tty *tp)
}
}
tp->t_sc = irframe_alloc(sizeof (struct irframet_softc),
&irframet_methods, tp);
sc = (struct irframet_softc *)tp->t_sc;
cfdata = malloc(sizeof(struct cfdata), M_DEVBUF, M_WAITOK);
cfdata->cf_name = "irframe";
cfdata->cf_atname = "irframet";
cfdata->cf_fstate = FSTATE_STAR;
cfdata->cf_unit = 0;
sc = (struct irframet_softc *)config_attach_pseudo(cfdata);
/* XXX should be done in irframet_attach() */
ia.ia_methods = &irframet_methods;
ia.ia_handle = tp;
irframe_attach(0, (struct device *)sc, &ia);
tp->t_sc = sc;
sc->sc_tp = tp;
printf("%s attached at tty%02d\n", sc->sc_irp.sc_dev.dv_xname,
minor(tp->t_dev));
@ -270,6 +314,7 @@ irframetclose(struct tty *tp, int flag)
{
struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc;
int s;
struct cfdata *cfdata;
DPRINTF(("%s: tp=%p\n", __FUNCTION__, tp));
@ -282,8 +327,11 @@ irframetclose(struct tty *tp, int flag)
printf("%s detached from tty%02d\n", sc->sc_irp.sc_dev.dv_xname,
minor(tp->t_dev));
if (sc->sc_tp == tp)
irframe_dealloc(&sc->sc_irp.sc_dev);
if (sc->sc_tp == tp) {
cfdata = sc->sc_irp.sc_dev.dv_cfdata;
config_detach(&sc->sc_irp.sc_dev, 0);
free(cfdata, M_DEVBUF);
}
}
splx(s);
return (0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: irframevar.h,v 1.15 2005/12/27 04:06:46 chs Exp $ */
/* $NetBSD: irframevar.h,v 1.16 2007/03/06 20:45:59 drochner Exp $ */
/*
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -65,6 +65,5 @@ struct irframe_softc {
#define IRDA_MAX_FRAME_SIZE 2048
#define IRDA_MAX_EBOFS 64
struct device *irframe_alloc(size_t, const struct irframe_methods *, void *);
void irframe_dealloc(struct device *);
void irframe_attach(struct device *, struct device *, void *);
int irframe_detach(struct device *, int);