summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2008-10-21 18:30:10 +0000
committerjhb <jhb@FreeBSD.org>2008-10-21 18:30:10 +0000
commit03f7a1b892756cd78ff85f138ffdb94cd4216670 (patch)
tree7de1b18022c6338570a93ecf78a487c8a9820918
parentddfa987b872f81817a11a48d9b97c719ef1e48d3 (diff)
downloadFreeBSD-src-03f7a1b892756cd78ff85f138ffdb94cd4216670.zip
FreeBSD-src-03f7a1b892756cd78ff85f138ffdb94cd4216670.tar.gz
Several cleanups to remove the need for explicit unit numbers and a few
other fixes: - Add pointers back to device_t objects in softc structures instead of storing the unit and using devclass_get_device(). - Add 'lpbb', 'pcf', 'pps', and 'vpo' child devices to every 'ppbus' device instead of just the first one. - Store softc pointers in si_drv1 of character devices instead of pulling the unit number from the minor number and using devclass_get_softc() and devclass_get_device(). - Store the LP_BYPASS flag in si_drv2 instead of encoding it in the minor number. - Destroy character devices for lpt(4) when detaching the device. - Use bus_print_child_footer() instead of duplicating it in ppbus_print_child() and fix ppbus_print_child()'s return value. - Remove unused AVM ivar from ppbus. - Don't store the 'mode' ivar in the ppbus ivars since we always fetch it from the parent anyway. - Try to detach all the child devices before deleting them in ppbus_detach(). - Use pause() instead of a tsleep() on a dummy address when polling the ppbus. - Use if_printf() and device_printf() instead of explicit names with unit numbers. Silence on: current@
-rw-r--r--sys/dev/ppbus/if_plip.c14
-rw-r--r--sys/dev/ppbus/immio.c23
-rw-r--r--sys/dev/ppbus/lpbb.c2
-rw-r--r--sys/dev/ppbus/lpt.c57
-rw-r--r--sys/dev/ppbus/pcfclock.c64
-rw-r--r--sys/dev/ppbus/ppb_base.c2
-rw-r--r--sys/dev/ppbus/ppb_msq.c7
-rw-r--r--sys/dev/ppbus/ppbconf.c40
-rw-r--r--sys/dev/ppbus/ppbconf.h7
-rw-r--r--sys/dev/ppbus/ppi.c46
-rw-r--r--sys/dev/ppbus/pps.c2
-rw-r--r--sys/dev/ppbus/vpo.c27
-rw-r--r--sys/dev/ppbus/vpoio.c14
-rw-r--r--sys/dev/ppbus/vpoio.h3
-rw-r--r--sys/dev/ppc/ppc.c39
-rw-r--r--sys/dev/ppc/ppcreg.h3
16 files changed, 156 insertions, 194 deletions
diff --git a/sys/dev/ppbus/if_plip.c b/sys/dev/ppbus/if_plip.c
index 291c2db..fd17ed9 100644
--- a/sys/dev/ppbus/if_plip.c
+++ b/sys/dev/ppbus/if_plip.c
@@ -147,6 +147,7 @@ static int volatile lptflag = 0;
struct lp_data {
struct ifnet *sc_ifp;
+ device_t sc_dev;
u_char *sc_ifbuf;
int sc_iferrs;
@@ -173,8 +174,6 @@ static void lp_intr(void *);
#define DEVTOSOFTC(dev) \
((struct lp_data *)device_get_softc(dev))
-#define UNITODEVICE(unit) \
- (devclass_get_device(lp_devclass, (unit)))
static devclass_t lp_devclass;
@@ -206,6 +205,8 @@ lp_attach (device_t dev)
struct ifnet *ifp;
int rid = 0;
+ lp->sc_dev = dev;
+
/*
* Reserve the interrupt resource. If we don't have one, the
* attach fails.
@@ -284,9 +285,9 @@ lpinittables (void)
static int
lpioctl (struct ifnet *ifp, u_long cmd, caddr_t data)
{
- device_t dev = UNITODEVICE(ifp->if_dunit);
+ struct lp_data *sc = ifp->if_softc;
+ device_t dev = sc->sc_dev;
device_t ppbus = device_get_parent(dev);
- struct lp_data *sc = DEVTOSOFTC(dev);
struct ifaddr *ifa = (struct ifaddr *)data;
struct ifreq *ifr = (struct ifreq *)data;
u_char *ptr;
@@ -560,7 +561,7 @@ lp_intr (void *arg)
* so stop wasting our time
*/
if (sc->sc_iferrs > LPMAXERRS) {
- printf("lp%d: Too many errors, Going off-line.\n", device_get_unit(dev));
+ if_printf(sc->sc_ifp, "Too many errors, Going off-line.\n");
ppb_wctr(ppbus, 0x00);
sc->sc_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
sc->sc_iferrs=0;
@@ -589,7 +590,8 @@ static int
lpoutput (struct ifnet *ifp, struct mbuf *m,
struct sockaddr *dst, struct rtentry *rt)
{
- device_t dev = UNITODEVICE(ifp->if_dunit);
+ struct lp_data *sc = ifp->if_softc;
+ device_t dev = sc->sc_dev;
device_t ppbus = device_get_parent(dev);
int s, err;
struct mbuf *mm;
diff --git a/sys/dev/ppbus/immio.c b/sys/dev/ppbus/immio.c
index 6dc30cc..3a0e1e5 100644
--- a/sys/dev/ppbus/immio.c
+++ b/sys/dev/ppbus/immio.c
@@ -298,8 +298,9 @@ imm_disconnect(struct vpoio_data *vpo, int *connected, int release_bus)
if ((s1 != (char)0xb8 || s2 != (char)0x18 || s3 != (char)0x38)) {
if (bootverbose)
- printf("imm%d: (disconnect) s1=0x%x s2=0x%x, s3=0x%x\n",
- vpo->vpo_unit, s1 & 0xff, s2 & 0xff, s3 & 0xff);
+ device_printf(vpo->vpo_dev,
+ "(disconnect) s1=0x%x s2=0x%x, s3=0x%x\n",
+ s1 & 0xff, s2 & 0xff, s3 & 0xff);
if (connected)
*connected = VP0_ECONNECT;
}
@@ -351,8 +352,9 @@ imm_connect(struct vpoio_data *vpo, int how, int *disconnected, int request_bus)
if ((s1 != (char)0xb8 || s2 != (char)0x18 || s3 != (char)0x30)) {
if (bootverbose)
- printf("imm%d: (connect) s1=0x%x s2=0x%x, s3=0x%x\n",
- vpo->vpo_unit, s1 & 0xff, s2 & 0xff, s3 & 0xff);
+ device_printf(vpo->vpo_dev,
+ "(connect) s1=0x%x s2=0x%x, s3=0x%x\n",
+ s1 & 0xff, s2 & 0xff, s3 & 0xff);
if (disconnected)
*disconnected = VP0_ECONNECT;
}
@@ -397,7 +399,8 @@ imm_detect(struct vpoio_data *vpo)
goto error;
vpo->vpo_mode_found = VP0_MODE_NIBBLE;
} else {
- printf("imm%d: NIBBLE mode unavailable!\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev,
+ "NIBBLE mode unavailable!\n");
goto error;
}
} else {
@@ -418,8 +421,8 @@ imm_detect(struct vpoio_data *vpo)
if (error) {
if (bootverbose)
- printf("imm%d: can't disconnect from the drive\n",
- vpo->vpo_unit);
+ device_printf(vpo->vpo_dev,
+ "can't disconnect from the drive\n");
goto error;
}
@@ -611,17 +614,17 @@ imm_attach(struct vpoio_data *vpo)
case VP0_MODE_EPP:
ppb_MS_GET_init(ppbus, vpo->vpo_dev, epp17_instr);
ppb_MS_PUT_init(ppbus, vpo->vpo_dev, epp17_outstr);
- printf("imm%d: EPP mode\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev, "EPP mode\n");
break;
case VP0_MODE_PS2:
ppb_MS_GET_init(ppbus, vpo->vpo_dev, ps2_inbyte_submicroseq);
ppb_MS_PUT_init(ppbus, vpo->vpo_dev, spp_outbyte_submicroseq);
- printf("imm%d: PS2 mode\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev, "PS2 mode\n");
break;
case VP0_MODE_NIBBLE:
ppb_MS_GET_init(ppbus, vpo->vpo_dev, vpo->vpo_nibble_inbyte_msq);
ppb_MS_PUT_init(ppbus, vpo->vpo_dev, spp_outbyte_submicroseq);
- printf("imm%d: NIBBLE mode\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev, "NIBBLE mode\n");
break;
default:
panic("imm: unknown mode %d", vpo->vpo_mode_found);
diff --git a/sys/dev/ppbus/lpbb.c b/sys/dev/ppbus/lpbb.c
index 51d3398..fe4a212 100644
--- a/sys/dev/ppbus/lpbb.c
+++ b/sys/dev/ppbus/lpbb.c
@@ -62,7 +62,7 @@ lpbb_identify(driver_t *driver, device_t parent)
device_t dev;
- dev = device_find_child(parent, "lpbb", 0);
+ dev = device_find_child(parent, "lpbb", -1);
if (!dev)
BUS_ADD_CHILD(parent, 0, "lpbb", -1);
}
diff --git a/sys/dev/ppbus/lpt.c b/sys/dev/ppbus/lpt.c
index c3253a2..9bd92be 100644
--- a/sys/dev/ppbus/lpt.c
+++ b/sys/dev/ppbus/lpt.c
@@ -104,11 +104,10 @@ static int volatile lptflag = 1;
#define BUFSIZE 1024
#define BUFSTATSIZE 32
-#define LPTUNIT(s) ((s)&0x03)
-#define LPTFLAGS(s) ((s)&0xfc)
-
struct lpt_data {
-
+ device_t dev;
+ struct cdev *cdev;
+ struct cdev *cdev_bypass;
short sc_state;
/* default case: negative prime, negative ack, handshake strobe,
prime once */
@@ -145,10 +144,6 @@ static int lpt_detect(device_t dev);
#define DEVTOSOFTC(dev) \
((struct lpt_data *)device_get_softc(dev))
-#define UNITOSOFTC(unit) \
- ((struct lpt_data *)devclass_get_softc(lpt_devclass, (unit)))
-#define UNITODEVICE(unit) \
- (devclass_get_device(lpt_devclass, (unit)))
static void lptintr(device_t dev);
static void lpt_intr(void *arg); /* without spls */
@@ -396,10 +391,15 @@ lpt_attach(device_t dev)
lpt_release_ppbus(dev);
- make_dev(&lpt_cdevsw, unit,
+ sc->dev = dev;
+ sc->cdev = make_dev(&lpt_cdevsw, unit,
UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d", unit);
- make_dev(&lpt_cdevsw, unit | LP_BYPASS,
+ sc->cdev->si_drv1 = sc;
+ sc->cdev->si_drv2 = 0;
+ sc->cdev_bypass = make_dev(&lpt_cdevsw, unit,
UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d.ctl", unit);
+ sc->cdev_bypass->si_drv1 = sc;
+ sc->cdev_bypass->si_drv2 = LP_BYPASS;
return (0);
}
@@ -408,6 +408,8 @@ lpt_detach(device_t dev)
{
struct lpt_data *sc = DEVTOSOFTC(dev);
+ destroy_dev(sc->cdev);
+ destroy_dev(sc->cdev_bypass);
lpt_release_ppbus(dev);
if (sc->intr_resource != 0) {
BUS_TEARDOWN_INTR(device_get_parent(dev), dev,
@@ -461,9 +463,8 @@ lptopen(struct cdev *dev, int flags, int fmt, struct thread *td)
{
int s;
int trys, err;
- u_int unit = LPTUNIT(dev2unit(dev));
- struct lpt_data *sc = UNITOSOFTC(unit);
- device_t lptdev = UNITODEVICE(unit);
+ struct lpt_data *sc = dev->si_drv1;
+ device_t lptdev = sc->dev;
device_t ppbus = device_get_parent(lptdev);
if (!sc)
@@ -475,7 +476,7 @@ lptopen(struct cdev *dev, int flags, int fmt, struct thread *td)
} else
sc->sc_state |= LPTINIT;
- sc->sc_flags = LPTFLAGS(dev2unit(dev));
+ sc->sc_flags = dev->si_drv2;
/* Check for open with BYPASS flag set. */
if (sc->sc_flags & LP_BYPASS) {
@@ -579,13 +580,12 @@ lptopen(struct cdev *dev, int flags, int fmt, struct thread *td)
static int
lptclose(struct cdev *dev, int flags, int fmt, struct thread *td)
{
- u_int unit = LPTUNIT(dev2unit(dev));
- struct lpt_data *sc = UNITOSOFTC(unit);
- device_t lptdev = UNITODEVICE(unit);
+ struct lpt_data *sc = dev->si_drv1;
+ device_t lptdev = sc->dev;
device_t ppbus = device_get_parent(lptdev);
int err;
- if(sc->sc_flags & LP_BYPASS)
+ if (sc->sc_flags & LP_BYPASS)
goto end_close;
if ((err = lpt_request_ppbus(lptdev, PPB_WAIT|PPB_INTR)) != 0)
@@ -688,9 +688,8 @@ lpt_pushbytes(device_t dev)
static int
lptread(struct cdev *dev, struct uio *uio, int ioflag)
{
- u_int unit = LPTUNIT(dev2unit(dev));
- struct lpt_data *sc = UNITOSOFTC(unit);
- device_t lptdev = UNITODEVICE(unit);
+ struct lpt_data *sc = dev->si_drv1;
+ device_t lptdev = sc->dev;
device_t ppbus = device_get_parent(lptdev);
int error = 0, len;
@@ -735,9 +734,8 @@ lptwrite(struct cdev *dev, struct uio *uio, int ioflag)
{
register unsigned n;
int err;
- u_int unit = LPTUNIT(dev2unit(dev));
- struct lpt_data *sc = UNITOSOFTC(unit);
- device_t lptdev = UNITODEVICE(unit);
+ struct lpt_data *sc = dev->si_drv1;
+ device_t lptdev = sc->dev;
device_t ppbus = device_get_parent(lptdev);
if(sc->sc_flags & LP_BYPASS) {
@@ -783,7 +781,9 @@ lptwrite(struct cdev *dev, struct uio *uio, int ioflag)
return(err);
case EINVAL:
/* advanced mode not avail */
- log(LOG_NOTICE, LPT_NAME "%d: advanced mode not avail, polling\n", unit);
+ log(LOG_NOTICE,
+ "%s: advanced mode not avail, polling\n",
+ device_get_nameunit(sc->dev));
break;
default:
return(err);
@@ -902,8 +902,7 @@ static int
lptioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
{
int error = 0;
- u_int unit = LPTUNIT(dev2unit(dev));
- struct lpt_data *sc = UNITOSOFTC(unit);
+ struct lpt_data *sc = dev->si_drv1;
u_char old_sc_irq; /* old printer IRQ status */
switch (cmd) {
@@ -942,8 +941,8 @@ lptioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *t
}
if (old_sc_irq != sc->sc_irq )
- log(LOG_NOTICE, LPT_NAME "%d: switched to %s %s mode\n",
- unit,
+ log(LOG_NOTICE, "%s: switched to %s %s mode\n",
+ device_get_nameunit(sc->dev),
(sc->sc_irq & LP_ENABLE_IRQ)?
"interrupt-driven":"polled",
(sc->sc_irq & LP_ENABLE_EXT)?
diff --git a/sys/dev/ppbus/pcfclock.c b/sys/dev/ppbus/pcfclock.c
index c7562fc..94a230c 100644
--- a/sys/dev/ppbus/pcfclock.c
+++ b/sys/dev/ppbus/pcfclock.c
@@ -52,16 +52,11 @@ __FBSDID("$FreeBSD$");
#define PCFCLOCK_NAME "pcfclock"
struct pcfclock_data {
+ device_t dev;
+ struct cdev *cdev;
int count;
};
-#define DEVTOSOFTC(dev) \
- ((struct pcfclock_data *)device_get_softc(dev))
-#define UNITOSOFTC(unit) \
- ((struct pcfclock_data *)devclass_get_softc(pcfclock_devclass, (unit)))
-#define UNITODEVICE(unit) \
- (devclass_get_device(pcfclock_devclass, (unit)))
-
static devclass_t pcfclock_devclass;
static d_open_t pcfclock_open;
@@ -120,7 +115,7 @@ pcfclock_identify(driver_t *driver, device_t parent)
device_t dev;
- dev = device_find_child(parent, PCFCLOCK_NAME, 0);
+ dev = device_find_child(parent, PCFCLOCK_NAME, -1);
if (!dev)
BUS_ADD_CHILD(parent, 0, PCFCLOCK_NAME, -1);
}
@@ -128,24 +123,27 @@ pcfclock_identify(driver_t *driver, device_t parent)
static int
pcfclock_probe(device_t dev)
{
- struct pcfclock_data *sc;
device_set_desc(dev, "PCF-1.0");
-
- sc = DEVTOSOFTC(dev);
-
return (0);
}
static int
pcfclock_attach(device_t dev)
{
+ struct pcfclock_data *sc = device_get_softc(dev);
int unit;
unit = device_get_unit(dev);
- make_dev(&pcfclock_cdevsw, unit,
+ sc->dev = dev;
+ sc->cdev = make_dev(&pcfclock_cdevsw, unit,
UID_ROOT, GID_WHEEL, 0400, PCFCLOCK_NAME "%d", unit);
+ if (sc->cdev == NULL) {
+ device_printf(dev, "Failed to create character device\n");
+ return (ENXIO);
+ }
+ sc->cdev->si_drv1 = sc;
return (0);
}
@@ -153,9 +151,8 @@ pcfclock_attach(device_t dev)
static int
pcfclock_open(struct cdev *dev, int flag, int fms, struct thread *td)
{
- u_int unit = dev2unit(dev);
- struct pcfclock_data *sc = UNITOSOFTC(unit);
- device_t pcfclockdev = UNITODEVICE(unit);
+ struct pcfclock_data *sc = dev->si_drv1;
+ device_t pcfclockdev = sc->dev;
device_t ppbus = device_get_parent(pcfclockdev);
int res;
@@ -174,9 +171,8 @@ pcfclock_open(struct cdev *dev, int flag, int fms, struct thread *td)
static int
pcfclock_close(struct cdev *dev, int flags, int fmt, struct thread *td)
{
- u_int unit = dev2unit(dev);
- struct pcfclock_data *sc = UNITOSOFTC(unit);
- device_t pcfclockdev = UNITODEVICE(unit);
+ struct pcfclock_data *sc = dev->si_drv1;
+ device_t pcfclockdev = sc->dev;
device_t ppbus = device_get_parent(pcfclockdev);
sc->count--;
@@ -189,9 +185,9 @@ pcfclock_close(struct cdev *dev, int flags, int fmt, struct thread *td)
static void
pcfclock_write_cmd(struct cdev *dev, unsigned char command)
{
- u_int unit = dev2unit(dev);
- device_t ppidev = UNITODEVICE(unit);
- device_t ppbus = device_get_parent(ppidev);
+ struct pcfclock_data *sc = dev->si_drv1;
+ device_t pcfclockdev = sc->dev;
+ device_t ppbus = device_get_parent(pcfclockdev);
unsigned char ctr = 14;
char i;
@@ -209,7 +205,7 @@ pcfclock_write_cmd(struct cdev *dev, unsigned char command)
static void
pcfclock_display_data(struct cdev *dev, char buf[18])
{
- u_int unit = dev2unit(dev);
+ struct pcfclock_data *sc = dev->si_drv1;
#ifdef PCFCLOCK_VERBOSE
int year;
@@ -217,25 +213,23 @@ pcfclock_display_data(struct cdev *dev, char buf[18])
if (year < 70)
year += 100;
- printf(PCFCLOCK_NAME "%d: %02d.%02d.%4d %02d:%02d:%02d, "
+ device_printf(sc->dev, "%02d.%02d.%4d %02d:%02d:%02d, "
"battery status: %s\n",
- unit,
NR(buf, 10), NR(buf, 12), 1900 + year,
NR(buf, 6), NR(buf, 4), NR(buf, 2),
PCFCLOCK_BATTERY_STATUS_LOW(buf) ? "LOW" : "ok");
#else
if (PCFCLOCK_BATTERY_STATUS_LOW(buf))
- printf(PCFCLOCK_NAME "%d: BATTERY STATUS LOW ON\n",
- unit);
+ device_printf(sc->dev, "BATTERY STATUS LOW ON\n");
#endif
}
static int
pcfclock_read_data(struct cdev *dev, char *buf, ssize_t bits)
{
- u_int unit = dev2unit(dev);
- device_t ppidev = UNITODEVICE(unit);
- device_t ppbus = device_get_parent(ppidev);
+ struct pcfclock_data *sc = dev->si_drv1;
+ device_t pcfclockdev = sc->dev;
+ device_t ppbus = device_get_parent(pcfclockdev);
int i;
char waitfor;
int offset;
@@ -272,9 +266,9 @@ pcfclock_read_data(struct cdev *dev, char *buf, ssize_t bits)
static int
pcfclock_read_dev(struct cdev *dev, char *buf, int maxretries)
{
- u_int unit = dev2unit(dev);
- device_t ppidev = UNITODEVICE(unit);
- device_t ppbus = device_get_parent(ppidev);
+ struct pcfclock_data *sc = dev->si_drv1;
+ device_t pcfclockdev = sc->dev;
+ device_t ppbus = device_get_parent(pcfclockdev);
int error = 0;
ppb_set_mode(ppbus, PPB_COMPATIBLE);
@@ -302,7 +296,7 @@ pcfclock_read_dev(struct cdev *dev, char *buf, int maxretries)
static int
pcfclock_read(struct cdev *dev, struct uio *uio, int ioflag)
{
- u_int unit = dev2unit(dev);
+ struct pcfclock_data *sc = dev->si_drv1;
char buf[18];
int error = 0;
@@ -312,7 +306,7 @@ pcfclock_read(struct cdev *dev, struct uio *uio, int ioflag)
error = pcfclock_read_dev(dev, buf, PCFCLOCK_MAX_RETRIES);
if (error) {
- printf(PCFCLOCK_NAME "%d: no PCF found\n", unit);
+ device_printf(sc->dev, "no PCF found\n");
} else {
pcfclock_display_data(dev, buf);
diff --git a/sys/dev/ppbus/ppb_base.c b/sys/dev/ppbus/ppb_base.c
index f54dae1..dd91a01 100644
--- a/sys/dev/ppbus/ppb_base.c
+++ b/sys/dev/ppbus/ppb_base.c
@@ -75,7 +75,7 @@ ppb_poll_bus(device_t bus, int max,
switch (how) {
case PPB_NOINTR:
/* wait 10 ms */
- tsleep((caddr_t)bus, PPBPRI, "ppbpoll", hz/100);
+ pause("ppbpoll", hz/100);
break;
case PPB_INTR:
diff --git a/sys/dev/ppbus/ppb_msq.c b/sys/dev/ppbus/ppb_msq.c
index 533ab5f..6b8e070 100644
--- a/sys/dev/ppbus/ppb_msq.c
+++ b/sys/dev/ppbus/ppb_msq.c
@@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$");
static struct ppb_xfer *
mode2xfer(device_t bus, struct ppb_device *ppbdev, int opcode)
{
- int index, epp;
+ int index, epp, mode;
struct ppb_xfer *table;
switch (opcode) {
@@ -72,7 +72,8 @@ mode2xfer(device_t bus, struct ppb_device *ppbdev, int opcode)
}
/* retrieve the device operating mode */
- switch (ppb_get_mode(bus)) {
+ mode = ppb_get_mode(bus);
+ switch (mode) {
case PPB_COMPATIBLE:
index = COMPAT_MSQ;
break;
@@ -99,7 +100,7 @@ mode2xfer(device_t bus, struct ppb_device *ppbdev, int opcode)
index = ECP_MSQ;
break;
default:
- panic("%s: unknown mode (%d)", __func__, ppbdev->mode);
+ panic("%s: unknown mode (%d)", __func__, mode);
}
return (&table[index]);
diff --git a/sys/dev/ppbus/ppbconf.c b/sys/dev/ppbus/ppbconf.c
index c0401c8..8877d34 100644
--- a/sys/dev/ppbus/ppbconf.c
+++ b/sys/dev/ppbus/ppbconf.c
@@ -54,21 +54,22 @@ static MALLOC_DEFINE(M_PPBUSDEV, "ppbusdev", "Parallel Port bus device");
* Device methods
*/
-static void
+static int
ppbus_print_child(device_t bus, device_t dev)
{
struct ppb_device *ppbdev;
+ int retval;
- bus_print_child_header(bus, dev);
+ retval = bus_print_child_header(bus, dev);
ppbdev = (struct ppb_device *)device_get_ivars(dev);
if (ppbdev->flags != 0)
- printf(" flags 0x%x", ppbdev->flags);
+ retval += printf(" flags 0x%x", ppbdev->flags);
- printf(" on %s%d\n", device_get_name(bus), device_get_unit(bus));
+ retval += bus_print_child_footer(bus, dev);
- return;
+ return (retval);
}
static int
@@ -110,16 +111,11 @@ ppbus_add_child(device_t dev, int order, const char *name, int unit)
static int
ppbus_read_ivar(device_t bus, device_t dev, int index, uintptr_t* val)
{
- struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
switch (index) {
case PPBUS_IVAR_MODE:
/* XXX yet device mode = ppbus mode = chipset mode */
*val = (u_long)ppb_get_mode(bus);
- ppbdev->mode = (u_short)*val;
- break;
- case PPBUS_IVAR_AVM:
- *val = (u_long)ppbdev->avm;
break;
default:
return (ENOENT);
@@ -131,13 +127,11 @@ ppbus_read_ivar(device_t bus, device_t dev, int index, uintptr_t* val)
static int
ppbus_write_ivar(device_t bus, device_t dev, int index, u_long val)
{
- struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
switch (index) {
case PPBUS_IVAR_MODE:
/* XXX yet device mode = ppbus mode = chipset mode */
- ppb_set_mode(bus,val);
- ppbdev->mode = ppb_get_mode(bus);
+ ppb_set_mode(bus, val);
break;
default:
return (ENOENT);
@@ -212,16 +206,15 @@ ppb_pnp_detect(device_t bus)
int i, len, error;
int class_id = -1;
char str[PPB_PnP_STRING_SIZE+1];
- int unit = device_get_unit(bus);
- printf("Probing for PnP devices on ppbus%d:\n", unit);
+ device_printf(bus, "Probing for PnP devices:\n");
if ((error = ppb_1284_read_id(bus, PPB_NIBBLE, str,
PPB_PnP_STRING_SIZE, &len)))
goto end_detect;
#ifdef DEBUG_1284
- printf("ppb: <PnP> %d characters: ", len);
+ device_printf(bus, "<PnP> %d characters: ", len);
for (i = 0; i < len; i++)
printf("%c(0x%x) ", str[i], str[i]);
printf("\n");
@@ -233,10 +226,10 @@ ppb_pnp_detect(device_t bus)
if ((token = search_token(str, len, "MFG")) != NULL ||
(token = search_token(str, len, "MANUFACTURER")) != NULL)
- printf("ppbus%d: <%s", unit,
+ device_printf(bus, "<%s",
search_token(token, UNKNOWN_LENGTH, ":") + 1);
else
- printf("ppbus%d: <unknown", unit);
+ device_printf(bus, "<unknown");
if ((token = search_token(str, len, "MDL")) != NULL ||
(token = search_token(str, len, "MODEL")) != NULL)
@@ -292,7 +285,6 @@ ppb_scan_bus(device_t bus)
{
struct ppb_data * ppb = (struct ppb_data *)device_get_softc(bus);
int error = 0;
- int unit = device_get_unit(bus);
/* try all IEEE1284 modes, for one device only
*
@@ -307,7 +299,7 @@ ppb_scan_bus(device_t bus)
ppb_1284_terminate(bus);
- printf("ppbus%d: IEEE1284 device found ", unit);
+ device_printf(bus, "IEEE1284 device found ");
if (!(error = ppb_1284_negociate(bus, PPB_NIBBLE, 0))) {
printf("/NIBBLE");
@@ -395,14 +387,18 @@ ppbus_attach(device_t dev)
/* launch attachement of the added children */
bus_generic_attach(dev);
- return 0;
+ return (0);
}
static int
ppbus_detach(device_t dev)
{
device_t *children;
- int nchildren, i;
+ int error, nchildren, i;
+
+ error = bus_generic_detach(dev);
+ if (error)
+ return (error);
/* detach & delete all children */
if (!device_get_children(dev, &children, &nchildren)) {
diff --git a/sys/dev/ppbus/ppbconf.h b/sys/dev/ppbus/ppbconf.h
index 88e4a1f..2050937 100644
--- a/sys/dev/ppbus/ppbconf.h
+++ b/sys/dev/ppbus/ppbconf.h
@@ -178,7 +178,6 @@ struct ppb_context {
* List of IVARS available to ppb device drivers
*/
#define PPBUS_IVAR_MODE 0
-#define PPBUS_IVAR_AVM 1
/* other fields are reserved to the ppbus internals */
@@ -186,9 +185,6 @@ struct ppb_device {
const char *name; /* name of the device */
- u_short mode; /* current mode of the device */
- u_short avm; /* available IEEE1284 modes of
- * the device */
u_int flags; /* flags */
struct ppb_context ctx; /* context of the device */
@@ -205,8 +201,6 @@ struct ppb_device {
struct resource *intr_resource;
void *intr_cookie;
-
- void *drv1, *drv2; /* drivers private data */
};
/* EPP standards */
@@ -268,7 +262,6 @@ extern int ppb_write(device_t, char *, int, int);
* These are defined as macros for speedup.
#define ppb_get_base_addr(dev) ((dev)->ppb->ppb_link->base)
#define ppb_get_epp_protocol(dev) ((dev)->ppb->ppb_link->epp_protocol)
-#define ppb_get_irq(dev) ((dev)->ppb->ppb_link->id_irq)
*/
#endif
diff --git a/sys/dev/ppbus/ppi.c b/sys/dev/ppbus/ppi.c
index e3e329f..e28b3cd 100644
--- a/sys/dev/ppbus/ppi.c
+++ b/sys/dev/ppbus/ppi.c
@@ -59,8 +59,8 @@ __FBSDID("$FreeBSD$");
#define BUFSIZE 512
struct ppi_data {
-
- int ppi_unit;
+ device_t ppi_device;
+ struct cdev *ppi_cdev;
int ppi_flags;
#define HAVE_PPBUS (1<<0)
#define HAD_PPBUS (1<<1)
@@ -77,10 +77,6 @@ struct ppi_data {
#define DEVTOSOFTC(dev) \
((struct ppi_data *)device_get_softc(dev))
-#define UNITOSOFTC(unit) \
- ((struct ppi_data *)devclass_get_softc(ppi_devclass, (unit)))
-#define UNITODEVICE(unit) \
- (devclass_get_device(ppi_devclass, (unit)))
static devclass_t ppi_devclass;
@@ -162,18 +158,24 @@ ppi_probe(device_t dev)
static int
ppi_attach(device_t dev)
{
+ struct ppi_data *ppi = DEVTOSOFTC(dev);
#ifdef PERIPH_1284
int rid = 0;
- struct ppi_data *ppi = DEVTOSOFTC(dev);
/* declare our interrupt handler */
ppi->intr_resource = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
RF_ACTIVE);
#endif /* PERIPH_1284 */
- make_dev(&ppi_cdevsw, device_get_unit(dev), /* XXX cleanup */
+ ppi->ppi_cdev = make_dev(&ppi_cdevsw, device_get_unit(dev),
UID_ROOT, GID_WHEEL,
0600, "ppi%d", device_get_unit(dev));
+ if (ppi->ppi_cdev == NULL) {
+ device_printf("Failed to create character device\n");
+ return (ENXIO);
+ }
+ ppi->ppi_cdev->si_drv1 = ppi;
+ ppi->ppi_device = dev;
return (0);
}
@@ -252,15 +254,11 @@ ppiintr(void *arg)
static int
ppiopen(struct cdev *dev, int flags, int fmt, struct thread *td)
{
- u_int unit = dev2unit(dev);
- struct ppi_data *ppi = UNITOSOFTC(unit);
- device_t ppidev = UNITODEVICE(unit);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
device_t ppbus = device_get_parent(ppidev);
int res;
- if (!ppi)
- return (ENXIO);
-
if (!(ppi->ppi_flags & HAVE_PPBUS)) {
if ((res = ppb_request_bus(ppbus, ppidev,
(flags & O_NONBLOCK) ? PPB_DONTWAIT :
@@ -286,9 +284,8 @@ ppiopen(struct cdev *dev, int flags, int fmt, struct thread *td)
static int
ppiclose(struct cdev *dev, int flags, int fmt, struct thread *td)
{
- u_int unit = dev2unit(dev);
- struct ppi_data *ppi = UNITOSOFTC(unit);
- device_t ppidev = UNITODEVICE(unit);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
device_t ppbus = device_get_parent(ppidev);
ppi->ppi_count --;
@@ -329,9 +326,8 @@ static int
ppiread(struct cdev *dev, struct uio *uio, int ioflag)
{
#ifdef PERIPH_1284
- u_int unit = dev2unit(dev);
- struct ppi_data *ppi = UNITOSOFTC(unit);
- device_t ppidev = UNITODEVICE(unit);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
device_t ppbus = device_get_parent(ppidev);
int len, error = 0;
@@ -413,9 +409,8 @@ static int
ppiwrite(struct cdev *dev, struct uio *uio, int ioflag)
{
#ifdef PERIPH_1284
- u_int unit = dev2unit(dev);
- struct ppi_data *ppi = UNITOSOFTC(unit);
- device_t ppidev = UNITODEVICE(unit);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
device_t ppbus = device_get_parent(ppidev);
int len, error = 0, sent;
@@ -499,9 +494,8 @@ error:
static int
ppiioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
{
- u_int unit = dev2unit(dev);
- device_t ppidev = UNITODEVICE(unit);
- device_t ppbus = device_get_parent(ppidev);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
int error = 0;
u_int8_t *val = (u_int8_t *)data;
diff --git a/sys/dev/ppbus/pps.c b/sys/dev/ppbus/pps.c
index 6ab904c..931fc47 100644
--- a/sys/dev/ppbus/pps.c
+++ b/sys/dev/ppbus/pps.c
@@ -77,7 +77,7 @@ ppsidentify(driver_t *driver, device_t parent)
device_t dev;
- dev = device_find_child(parent, PPS_NAME, 0);
+ dev = device_find_child(parent, PPS_NAME, -1);
if (!dev)
BUS_ADD_CHILD(parent, 0, PPS_NAME, -1);
}
diff --git a/sys/dev/ppbus/vpo.c b/sys/dev/ppbus/vpo.c
index 189a58c..3602664 100644
--- a/sys/dev/ppbus/vpo.c
+++ b/sys/dev/ppbus/vpo.c
@@ -63,8 +63,7 @@ struct vpo_sense {
};
struct vpo_data {
- unsigned short vpo_unit;
-
+ device_t vpo_dev;
int vpo_stat;
int vpo_count;
int vpo_error;
@@ -94,7 +93,7 @@ vpo_identify(driver_t *driver, device_t parent)
device_t dev;
- dev = device_find_child(parent, "vpo", 0);
+ dev = device_find_child(parent, "vpo", -1);
if (!dev)
BUS_ADD_CHILD(parent, 0, "vpo", -1);
}
@@ -109,12 +108,7 @@ vpo_probe(device_t dev)
int error;
vpo = DEVTOSOFTC(dev);
-
- /* vpo dependent initialisation */
- vpo->vpo_unit = device_get_unit(dev);
-
- /* low level probe */
- vpoio_set_unit(&vpo->vpo_io, vpo->vpo_unit);
+ vpo->vpo_dev = dev;
/* check ZIP before ZIP+ or imm_probe() will send controls to
* the printer or whatelse connected to the port */
@@ -257,8 +251,8 @@ vpo_intr(struct vpo_data *vpo, struct ccb_scsiio *csio)
/* if a timeout occured, no sense */
if (vpo->vpo_error) {
if (vpo->vpo_error != VP0_ESELECT_TIMEOUT)
- printf("vpo%d: VP0 error/timeout (%d)\n",
- vpo->vpo_unit, vpo->vpo_error);
+ device_printf(vpo->vpo_dev, "VP0 error/timeout (%d)\n",
+ vpo->vpo_error);
csio->ccb_h.status = CAM_CMD_TIMEOUT;
goto error;
@@ -348,8 +342,8 @@ vpo_action(struct cam_sim *sim, union ccb *ccb)
csio = &ccb->csio;
#ifdef VP0_DEBUG
- printf("vpo%d: XPT_SCSI_IO (0x%x) request\n",
- vpo->vpo_unit, csio->cdb_io.cdb_bytes[0]);
+ device_printf(vpo->vpo_dev, "XPT_SCSI_IO (0x%x) request\n",
+ csio->cdb_io.cdb_bytes[0]);
#endif
vpo_intr(vpo, csio);
@@ -365,8 +359,7 @@ vpo_action(struct cam_sim *sim, union ccb *ccb)
ccg = &ccb->ccg;
#ifdef VP0_DEBUG
- printf("vpo%d: XPT_CALC_GEOMETRY (bs=%d,vs=%jd,c=%d,h=%d,spt=%d) request\n",
- vpo->vpo_unit,
+ device_printf(vpo->vpo_dev, "XPT_CALC_GEOMETRY (bs=%d,vs=%jd,c=%d,h=%d,spt=%d) request\n",
ccg->block_size,
(intmax_t)ccg->volume_size,
ccg->cylinders,
@@ -387,7 +380,7 @@ vpo_action(struct cam_sim *sim, union ccb *ccb)
{
#ifdef VP0_DEBUG
- printf("vpo%d: XPT_RESET_BUS request\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev, "XPT_RESET_BUS request\n");
#endif
if (vpo->vpo_isplus) {
@@ -413,7 +406,7 @@ vpo_action(struct cam_sim *sim, union ccb *ccb)
struct ccb_pathinq *cpi = &ccb->cpi;
#ifdef VP0_DEBUG
- printf("vpo%d: XPT_PATH_INQ request\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev, "XPT_PATH_INQ request\n");
#endif
cpi->version_num = 1; /* XXX??? */
cpi->hba_inquiry = 0;
diff --git a/sys/dev/ppbus/vpoio.c b/sys/dev/ppbus/vpoio.c
index 7ff515f..2913495 100644
--- a/sys/dev/ppbus/vpoio.c
+++ b/sys/dev/ppbus/vpoio.c
@@ -399,8 +399,8 @@ vpoio_detect(struct vpoio_data *vpo)
if (!vpoio_in_disk_mode(vpo)) {
vpo->vpo_mode_found = VP0_MODE_UNDEFINED;
if (bootverbose)
- printf("vpo%d: can't connect to the drive\n",
- vpo->vpo_unit);
+ device_printf(vpo->vpo_dev,
+ "can't connect to the drive\n");
/* disconnect and release the bus */
ppb_MS_microseq(ppbus, vpo->vpo_dev, disconnect_microseq,
@@ -420,8 +420,8 @@ vpoio_detect(struct vpoio_data *vpo)
* may cause serious problem to the disk */
if (vpoio_in_disk_mode(vpo)) {
if (bootverbose)
- printf("vpo%d: can't disconnect from the drive\n",
- vpo->vpo_unit);
+ device_printf(vpo->vpo_dev,
+ "can't disconnect from the drive\n");
goto error;
}
@@ -617,17 +617,17 @@ vpoio_attach(struct vpoio_data *vpo)
case VP0_MODE_EPP:
ppb_MS_GET_init(ppbus, vpo->vpo_dev, epp17_instr_body);
ppb_MS_PUT_init(ppbus, vpo->vpo_dev, epp17_outstr_body);
- printf("vpo%d: EPP mode\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev, "EPP mode\n");
break;
case VP0_MODE_PS2:
ppb_MS_GET_init(ppbus, vpo->vpo_dev, ps2_inbyte_submicroseq);
ppb_MS_PUT_init(ppbus, vpo->vpo_dev, spp_outbyte_submicroseq);
- printf("vpo%d: PS2 mode\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev, "PS2 mode\n");
break;
case VP0_MODE_NIBBLE:
ppb_MS_GET_init(ppbus, vpo->vpo_dev, vpo->vpo_nibble_inbyte_msq);
ppb_MS_PUT_init(ppbus, vpo->vpo_dev, spp_outbyte_submicroseq);
- printf("vpo%d: NIBBLE mode\n", vpo->vpo_unit);
+ device_printf(vpo->vpo_dev, "NIBBLE mode\n");
break;
default:
panic("vpo: unknown mode %d", vpo->vpo_mode_found);
diff --git a/sys/dev/ppbus/vpoio.h b/sys/dev/ppbus/vpoio.h
index fe66fa5..acf7265 100644
--- a/sys/dev/ppbus/vpoio.h
+++ b/sys/dev/ppbus/vpoio.h
@@ -66,7 +66,6 @@ struct vpo_nibble {
#define VP0_MODE_EPP 0x3
struct vpoio_data {
- unsigned short int vpo_unit;
int vpo_mode_found; /* Mode found during init */
struct vpo_nibble vpo_nibble;
@@ -77,8 +76,6 @@ struct vpoio_data {
device_t vpo_dev;
};
-#define vpoio_set_unit(vpo,unit) ((vpo)->vpo_unit = unit)
-
int vpoio_probe(device_t dev, struct vpoio_data *vpo);
int vpoio_attach(struct vpoio_data *vpo);
diff --git a/sys/dev/ppc/ppc.c b/sys/dev/ppc/ppc.c
index a372403..ac9a916 100644
--- a/sys/dev/ppc/ppc.c
+++ b/sys/dev/ppc/ppc.c
@@ -133,8 +133,7 @@ ppc_ecp_sync(device_t dev) {
DELAY(100);
}
- printf("ppc%d: ECP sync failed as data still " \
- "present in FIFO.\n", ppc->ppc_unit);
+ device_printf(dev, "ECP sync failed as data still present in FIFO.\n");
return;
}
@@ -752,8 +751,7 @@ config:
if (bootverbose) {
outb(csr, 0x1);
- printf("ppc%d: SMC registers CR1=0x%x", ppc->ppc_unit,
- inb(cio) & 0xff);
+ device_printf(dev, "SMC registers CR1=0x%x", inb(cio) & 0xff);
outb(csr, 0x4);
printf(" CR4=0x%x", inb(cio) & 0xff);
@@ -1046,7 +1044,7 @@ found:
if (bootverbose) {
/* dump of registers */
- printf("ppc%d: 0x%x - ", ppc->ppc_unit, w83877f_keys[i]);
+ device_printf(dev, "0x%x - ", w83877f_keys[i]);
for (i = 0; i <= 0xd; i ++) {
outb(efir, i);
printf("0x%x ", inb(efdr));
@@ -1062,7 +1060,6 @@ found:
printf("0x%x ", inb(efdr));
}
printf("\n");
- printf("ppc%d:", ppc->ppc_unit);
}
ppc->ppc_type = PPC_TYPE_GENERIC;
@@ -1081,8 +1078,7 @@ found:
switch (r) {
case WINB_W83757:
if (bootverbose)
- printf("ppc%d: W83757 compatible mode\n",
- ppc->ppc_unit);
+ device_printf(dev, "W83757 compatible mode\n");
return (-1); /* generic or SMC-like */
case WINB_EXTFDC:
@@ -1090,19 +1086,20 @@ found:
case WINB_EXT2FDD:
case WINB_JOYSTICK:
if (bootverbose)
- printf(" not in parallel port mode\n");
+ device_printf(dev,
+ "not in parallel port mode\n");
return (-1);
case (WINB_PARALLEL | WINB_EPP_SPP):
ppc->ppc_avm |= PPB_EPP | PPB_SPP;
if (bootverbose)
- printf(" EPP SPP");
+ device_printf(dev, "EPP SPP\n");
break;
case (WINB_PARALLEL | WINB_ECP):
ppc->ppc_avm |= PPB_ECP | PPB_SPP;
if (bootverbose)
- printf(" ECP SPP");
+ device_printf(dev, "ECP SPP\n");
break;
case (WINB_PARALLEL | WINB_ECP_EPP):
@@ -1110,7 +1107,7 @@ found:
ppc->ppc_type = PPC_TYPE_SMCLIKE;
if (bootverbose)
- printf(" ECP+EPP SPP");
+ device_printf(dev, "ECP+EPP SPP\n");
break;
default:
printf("%s: unknown case (0x%x)!\n", __func__, r);
@@ -1131,27 +1128,24 @@ found:
if (chipset_mode & PPB_EPP) {
outb(efdr, inb(efdr) | WINB_ECP_EPP);
if (bootverbose)
- printf(" ECP+EPP");
+ device_printf(dev, "ECP+EPP\n");
ppc->ppc_type = PPC_TYPE_SMCLIKE;
} else {
outb(efdr, inb(efdr) | WINB_ECP);
if (bootverbose)
- printf(" ECP");
+ device_printf(dev, "ECP\n");
}
} else {
/* select EPP_SPP otherwise */
outb(efdr, inb(efdr) | WINB_EPP_SPP);
if (bootverbose)
- printf(" EPP SPP");
+ device_printf(dev, "EPP SPP\n");
}
ppc->ppc_avm = chipset_mode;
}
- if (bootverbose)
- printf("\n");
-
/* exit configuration mode */
outb(efer, 0xaa);
@@ -1178,14 +1172,14 @@ ppc_generic_detect(struct ppc_data *ppc, int chipset_mode)
ppc->ppc_type = PPC_TYPE_GENERIC;
if (bootverbose)
- printf("ppc%d:", ppc->ppc_unit);
+ device_printf(ppc->ppc_dev, "SPP");
/* first, check for ECP */
w_ecr(ppc, PPC_ECR_PS2);
if ((r_ecr(ppc) & 0xe0) == PPC_ECR_PS2) {
ppc->ppc_dtm |= PPB_ECP | PPB_SPP;
if (bootverbose)
- printf(" ECP SPP");
+ printf(" ECP ");
/* search for SMC style ECP+EPP mode */
w_ecr(ppc, PPC_ECR_EPP);
@@ -1214,9 +1208,6 @@ ppc_generic_detect(struct ppc_data *ppc, int chipset_mode)
/* XXX try to detect NIBBLE and PS2 modes */
ppc->ppc_dtm |= PPB_NIBBLE;
- if (bootverbose)
- printf(" SPP");
-
if (chipset_mode)
ppc->ppc_avm = chipset_mode;
else
@@ -1737,7 +1728,7 @@ ppc_probe(device_t dev, int rid)
if (ppc->res_drq)
ppc->ppc_dmachan = rman_get_start(ppc->res_drq);
- ppc->ppc_unit = device_get_unit(dev);
+ ppc->ppc_dev = dev;
ppc->ppc_model = GENERIC;
ppc->ppc_mode = PPB_COMPATIBLE;
diff --git a/sys/dev/ppc/ppcreg.h b/sys/dev/ppc/ppcreg.h
index 8464f9c..0e69dd9 100644
--- a/sys/dev/ppc/ppcreg.h
+++ b/sys/dev/ppc/ppcreg.h
@@ -56,8 +56,7 @@
* Generic structure to hold parallel port chipset info.
*/
struct ppc_data {
-
- int ppc_unit;
+ device_t ppc_dev;
int ppc_model; /* chipset model if detected */
int ppc_type; /* generic or smclike chipset type */
OpenPOWER on IntegriCloud