Split device_t/softc, as following its parents zsc(4). Spotted by isaki@.

This commit is contained in:
tsutsui 2008-04-20 02:28:05 +00:00
parent ede732e020
commit 76e1faa427

View File

@ -1,4 +1,4 @@
/* $NetBSD: ms.c,v 1.27 2007/10/17 19:58:02 garbled Exp $ */
/* $NetBSD: ms.c,v 1.28 2008/04/20 02:28:05 tsutsui Exp $ */
/*
* Copyright (c) 1992, 1993
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.27 2007/10/17 19:58:02 garbled Exp $");
__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.28 2008/04/20 02:28:05 tsutsui Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@ -65,6 +65,7 @@ __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.27 2007/10/17 19:58:02 garbled Exp $");
#include <machine/vuid_event.h>
#include <arch/x68k/dev/mfp.h>
#include "ioconf.h"
#include "locators.h"
/*
@ -97,7 +98,7 @@ __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.27 2007/10/17 19:58:02 garbled Exp $");
* mouse begins the sequence. RTS assertion has no effect.
*/
struct ms_softc {
struct device ms_dev; /* required first: base device */
device_t ms_dev; /* required first: base device */
struct zs_chanstate *ms_cs;
struct callout ms_modem_ch;
@ -133,16 +134,26 @@ struct ms_softc {
struct evvar ms_events; /* event queue state */
} ms_softc;
static int ms_match(struct device *, struct cfdata *, void *);
static void ms_attach(struct device *, struct device *, void *);
static int ms_match(device_t, cfdata_t, void *);
static void ms_attach(device_t, device_t, void *);
static void ms_trigger(struct zs_chanstate *, int);
void ms_modem(void *);
CFATTACH_DECL(ms, sizeof(struct ms_softc),
CFATTACH_DECL_NEW(ms, sizeof(struct ms_softc),
ms_match, ms_attach, NULL, NULL);
extern struct zsops zsops_ms;
extern struct cfdriver ms_cd;
static void ms_rxint(struct zs_chanstate *);
static void ms_stint(struct zs_chanstate *, int);
static void ms_txint(struct zs_chanstate *);
static void ms_softint(struct zs_chanstate *);
static void ms_input(struct ms_softc *, int);
struct zsops zsops_ms = {
ms_rxint, /* receive char available */
ms_stint, /* external/status */
ms_txint, /* xmit buffer empty */
ms_softint, /* process software interrupt */
};
dev_type_open(msopen);
dev_type_close(msclose);
@ -160,10 +171,10 @@ const struct cdevsw ms_cdevsw ={
* ms_match: how is this zs channel configured?
*/
int
ms_match(struct device *parent, struct cfdata *cf, void *aux)
ms_match(device_t parent, cfdata_t cf, void *aux)
{
struct zsc_attach_args *args = aux;
struct zsc_softc *zsc = (void *)parent;
struct zsc_softc *zsc = device_private(parent);
/* Exact match required for the mouse. */
if (cf->cf_loc[ZSCCF_CHANNEL] != args->channel)
@ -177,17 +188,18 @@ ms_match(struct device *parent, struct cfdata *cf, void *aux)
}
void
ms_attach(struct device *parent, struct device *self, void *aux)
ms_attach(device_t parent, device_t self, void *aux)
{
struct zsc_softc *zsc = (void *)parent;
struct ms_softc *ms = (void *)self;
struct ms_softc *ms = device_private(self);
struct zsc_softc *zsc = device_private(parent);
struct zs_chanstate *cs;
struct cfdata *cf;
int reset, s;
ms->ms_dev = self;
callout_init(&ms->ms_modem_ch, 0);
cf = device_cfdata(&ms->ms_dev);
cf = device_cfdata(self);
cs = zsc->zsc_cs[1];
cs->cs_private = ms;
cs->cs_ops = &zsops_ms;
@ -208,7 +220,7 @@ ms_attach(struct device *parent, struct device *self, void *aux)
/* Initialize translator. */
ms->ms_ready = 0;
printf("\n");
aprint_normal("\n");
}
/****************************************************************
@ -220,18 +232,14 @@ int
msopen(dev_t dev, int flags, int mode, struct lwp *l)
{
struct ms_softc *ms;
int unit;
unit = minor(dev);
if (unit >= ms_cd.cd_ndevs)
return (ENXIO);
ms = ms_cd.cd_devs[unit];
ms = device_lookup_private(&ms_cd, minor(dev));
if (ms == NULL)
return (ENXIO);
return ENXIO;
/* This is an exclusive open device. */
if (ms->ms_events.ev_io)
return (EBUSY);
return EBUSY;
ms->ms_events.ev_io = l->l_proc;
ev_init(&ms->ms_events); /* may cause sleep */
@ -243,7 +251,7 @@ msopen(dev_t dev, int flags, int mode, struct lwp *l)
/* start sequencer */
ms_modem(ms);
return (0);
return 0;
}
int
@ -251,13 +259,13 @@ msclose(dev_t dev, int flags, int mode, struct lwp *l)
{
struct ms_softc *ms;
ms = ms_cd.cd_devs[minor(dev)];
ms = device_lookup_private(&ms_cd, minor(dev));
ms->ms_ready = 0; /* stop accepting events */
callout_stop(&ms->ms_modem_ch);
ev_fini(&ms->ms_events);
ms->ms_events.ev_io = NULL;
return (0);
return 0;
}
int
@ -265,8 +273,8 @@ msread(dev_t dev, struct uio *uio, int flags)
{
struct ms_softc *ms;
ms = ms_cd.cd_devs[minor(dev)];
return (ev_read(&ms->ms_events, uio, flags));
ms = device_lookup_private(&ms_cd, minor(dev));
return ev_read(&ms->ms_events, uio, flags);
}
int
@ -274,39 +282,39 @@ msioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
struct ms_softc *ms;
ms = ms_cd.cd_devs[minor(dev)];
ms = device_lookup_private(&ms_cd, minor(dev));
switch (cmd) {
case FIONBIO: /* we will remove this someday (soon???) */
return (0);
return 0;
case FIOASYNC:
ms->ms_events.ev_async = *(int *)data != 0;
return (0);
return 0;
case FIOSETOWN:
if (-*(int *)data != ms->ms_events.ev_io->p_pgid
&& *(int *)data != ms->ms_events.ev_io->p_pid)
return (EPERM);
return(0);
return EPERM;
return 0;
case TIOCSPGRP:
if (*(int *)data != ms->ms_events.ev_io->p_pgid)
return (EPERM);
return (0);
return EPERM;
return 0;
case VUIDGFORMAT:
/* we only do firm_events */
*(int *)data = VUID_FIRM_EVENT;
return (0);
return 0;
case VUIDSFORMAT:
if (*(int *)data != VUID_FIRM_EVENT)
return (EINVAL);
return (0);
return EINVAL;
return 0;
}
return (ENOTTY);
return ENOTTY;
}
int
@ -314,8 +322,8 @@ mspoll(dev_t dev, int events, struct lwp *l)
{
struct ms_softc *ms;
ms = ms_cd.cd_devs[minor(dev)];
return (ev_poll(&ms->ms_events, events, l));
ms = device_lookup_private(&ms_cd, minor(dev));
return ev_poll(&ms->ms_events, events, l);
}
int
@ -323,17 +331,14 @@ mskqfilter(dev_t dev, struct knote *kn)
{
struct ms_softc *ms;
ms = ms_cd.cd_devs[minor(dev)];
return (ev_kqfilter(&ms->ms_events, kn));
ms = device_lookup_private(&ms_cd, minor(dev));
return ev_kqfilter(&ms->ms_events, kn);
}
/****************************************************************
* Middle layer (translator)
****************************************************************/
static void ms_input(struct ms_softc *, int);
/*
* Called by our ms_softint() routine on input.
*/
@ -458,11 +463,6 @@ out:
* Interface to the lower layer (zscc)
****************************************************************/
static void ms_rxint(struct zs_chanstate *);
static void ms_stint(struct zs_chanstate *, int);
static void ms_txint(struct zs_chanstate *);
static void ms_softint(struct zs_chanstate *);
static void
ms_rxint(struct zs_chanstate *cs)
{
@ -577,7 +577,7 @@ ms_softint(struct zs_chanstate *cs)
intr_flags |= INTR_RX_OVERRUN;
if (ring_data & (ZSRR1_FE | ZSRR1_PE)) {
log(LOG_ERR, "%s: input error (0x%x)\n",
ms->ms_dev.dv_xname, ring_data);
device_xname(ms->ms_dev), ring_data);
c = -1; /* signal input error */
}
@ -586,7 +586,7 @@ ms_softint(struct zs_chanstate *cs)
}
if (intr_flags & INTR_RX_OVERRUN) {
log(LOG_ERR, "%s: input overrun\n",
ms->ms_dev.dv_xname);
device_xname(ms->ms_dev));
}
ms->ms_rbget = get;
@ -595,7 +595,7 @@ ms_softint(struct zs_chanstate *cs)
* Transmit done. (Not expected.)
*/
log(LOG_ERR, "%s: transmit interrupt?\n",
ms->ms_dev.dv_xname);
device_xname(ms->ms_dev));
}
if (intr_flags & INTR_ST_CHECK) {
@ -603,20 +603,13 @@ ms_softint(struct zs_chanstate *cs)
* Status line change. (Not expected.)
*/
log(LOG_ERR, "%s: status interrupt?\n",
ms->ms_dev.dv_xname);
device_xname(ms->ms_dev));
cs->cs_rr0_delta = 0;
}
splx(s);
}
struct zsops zsops_ms = {
ms_rxint, /* receive char available */
ms_stint, /* external/status */
ms_txint, /* xmit buffer empty */
ms_softint, /* process software interrupt */
};
static void
ms_trigger(struct zs_chanstate *cs, int onoff)
@ -650,7 +643,7 @@ ms_modem(void *arg)
if (ms->ms_nodata++ > 250) { /* XXX */
log(LOG_ERR, "%s: no data for 5 secs. resetting.\n",
ms->ms_dev.dv_xname);
device_xname(ms->ms_dev));
ms->ms_byteno = -1;
ms->ms_nodata = 0;
ms->ms_rts = 0;