Date: Tue, 21 Oct 2008 18:30:10 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r184130 - in head/sys/dev: ppbus ppc Message-ID: <200810211830.m9LIUAKB005537@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Tue Oct 21 18:30:10 2008 New Revision: 184130 URL: http://svn.freebsd.org/changeset/base/184130 Log: 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@ Modified: head/sys/dev/ppbus/if_plip.c head/sys/dev/ppbus/immio.c head/sys/dev/ppbus/lpbb.c head/sys/dev/ppbus/lpt.c head/sys/dev/ppbus/pcfclock.c head/sys/dev/ppbus/ppb_base.c head/sys/dev/ppbus/ppb_msq.c head/sys/dev/ppbus/ppbconf.c head/sys/dev/ppbus/ppbconf.h head/sys/dev/ppbus/ppi.c head/sys/dev/ppbus/pps.c head/sys/dev/ppbus/vpo.c head/sys/dev/ppbus/vpoio.c head/sys/dev/ppbus/vpoio.h head/sys/dev/ppc/ppc.c head/sys/dev/ppc/ppcreg.h Modified: head/sys/dev/ppbus/if_plip.c ============================================================================== --- head/sys/dev/ppbus/if_plip.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/if_plip.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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; Modified: head/sys/dev/ppbus/immio.c ============================================================================== --- head/sys/dev/ppbus/immio.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/immio.c Tue Oct 21 18:30:10 2008 (r184130) @@ -298,8 +298,9 @@ imm_disconnect(struct vpoio_data *vpo, i 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 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); Modified: head/sys/dev/ppbus/lpbb.c ============================================================================== --- head/sys/dev/ppbus/lpbb.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/lpbb.c Tue Oct 21 18:30:10 2008 (r184130) @@ -62,7 +62,7 @@ lpbb_identify(driver_t *driver, device_t 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); } Modified: head/sys/dev/ppbus/lpt.c ============================================================================== --- head/sys/dev/ppbus/lpt.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/lpt.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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 { 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 } 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 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 *u { 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 *u 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, c } 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)? Modified: head/sys/dev/ppbus/pcfclock.c ============================================================================== --- head/sys/dev/ppbus/pcfclock.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/pcfclock.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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, devi 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, devi 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 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 fla 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, uns 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, 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, cha 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 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 u 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); Modified: head/sys/dev/ppbus/ppb_base.c ============================================================================== --- head/sys/dev/ppbus/ppb_base.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/ppb_base.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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: Modified: head/sys/dev/ppbus/ppb_msq.c ============================================================================== --- head/sys/dev/ppbus/ppb_msq.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/ppb_msq.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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_devic } /* 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_devic index = ECP_MSQ; break; default: - panic("%s: unknown mode (%d)", __func__, ppbdev->mode); + panic("%s: unknown mode (%d)", __func__, mode); } return (&table[index]); Modified: head/sys/dev/ppbus/ppbconf.c ============================================================================== --- head/sys/dev/ppbus/ppbconf.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/ppbconf.c Tue Oct 21 18:30:10 2008 (r184130) @@ -54,21 +54,22 @@ static MALLOC_DEFINE(M_PPBUSDEV, "ppbusd * 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, 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 d 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)) { Modified: head/sys/dev/ppbus/ppbconf.h ============================================================================== --- head/sys/dev/ppbus/ppbconf.h Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/ppbconf.h Tue Oct 21 18:30:10 2008 (r184130) @@ -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 *, i * 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 Modified: head/sys/dev/ppbus/ppi.c ============================================================================== --- head/sys/dev/ppbus/ppi.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/ppi.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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 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; Modified: head/sys/dev/ppbus/pps.c ============================================================================== --- head/sys/dev/ppbus/pps.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/pps.c Tue Oct 21 18:30:10 2008 (r184130) @@ -77,7 +77,7 @@ ppsidentify(driver_t *driver, device_t p 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); } Modified: head/sys/dev/ppbus/vpo.c ============================================================================== --- head/sys/dev/ppbus/vpo.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/vpo.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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 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 cc /* 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 cc 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 cc 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 cc { #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 cc 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; Modified: head/sys/dev/ppbus/vpoio.c ============================================================================== --- head/sys/dev/ppbus/vpoio.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/vpoio.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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); Modified: head/sys/dev/ppbus/vpoio.h ============================================================================== --- head/sys/dev/ppbus/vpoio.h Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppbus/vpoio.h Tue Oct 21 18:30:10 2008 (r184130) @@ -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); Modified: head/sys/dev/ppc/ppc.c ============================================================================== --- head/sys/dev/ppc/ppc.c Tue Oct 21 16:46:50 2008 (r184129) +++ head/sys/dev/ppc/ppc.c Tue Oct 21 18:30:10 2008 (r184130) @@ -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, *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810211830.m9LIUAKB005537>