diff options
author | mdodd <mdodd@FreeBSD.org> | 2002-11-06 08:08:55 +0000 |
---|---|---|
committer | mdodd <mdodd@FreeBSD.org> | 2002-11-06 08:08:55 +0000 |
commit | a349f5fa5c27e42d22b2ebacaf0d06a33f2a7550 (patch) | |
tree | bcf9433e1bb49f5522957e8ea5f471d6b3a3d431 | |
parent | 66bd92dc492692feb44700ec3ebc7f6424778af2 (diff) | |
download | FreeBSD-src-a349f5fa5c27e42d22b2ebacaf0d06a33f2a7550.zip FreeBSD-src-a349f5fa5c27e42d22b2ebacaf0d06a33f2a7550.tar.gz |
Whitespace, style fixes.
-rw-r--r-- | sys/dev/mcd/mcd.c | 589 | ||||
-rw-r--r-- | sys/dev/mcd/mcdvar.h | 1 | ||||
-rw-r--r-- | sys/dev/scd/scd.c | 223 |
3 files changed, 375 insertions, 438 deletions
diff --git a/sys/dev/mcd/mcd.c b/sys/dev/mcd/mcd.c index 19c3a45..094eda8 100644 --- a/sys/dev/mcd/mcd.c +++ b/sys/dev/mcd/mcd.c @@ -194,15 +194,13 @@ static struct cdevsw mcd_cdevsw = { int mcd_attach(struct mcd_softc *sc) { - struct mcd_data *cd; int unit; - cd = &sc->data; unit = device_get_unit(sc->dev); - cd->flags |= MCDINIT; + sc->data.flags |= MCDINIT; mcd_soft_reset(sc); - bioq_init(&cd->head); + bioq_init(&sc->data.head); #ifdef NOTYET /* wire controller for interrupts and dma */ @@ -214,99 +212,93 @@ mcd_attach(struct mcd_softc *sc) sc->mcd_dev_t->si_drv1 = (void *)sc; - return 0; + return (0); } static int mcdopen(dev_t dev, int flags, int fmt, struct thread *td) { struct mcd_softc *sc; - struct mcd_data *cd; int r,retry; sc = (struct mcd_softc *)dev->si_drv1; - cd = &sc->data; /* not initialized*/ - if (!(cd->flags & MCDINIT)) - return ENXIO; + if (!(sc->data.flags & MCDINIT)) + return (ENXIO); /* invalidated in the meantime? mark all open part's invalid */ - if (!(cd->flags & MCDVALID) && cd->openflags) - return ENXIO; + if (!(sc->data.flags & MCDVALID) && sc->data.openflags) + return (ENXIO); if (mcd_getstat(sc, 1) == -1) - return EIO; + return (EIO); - if ( (cd->status & (MCDDSKCHNG|MCDDOOROPEN)) - || !(cd->status & MCDDSKIN)) + if ( (sc->data.status & (MCDDSKCHNG|MCDDOOROPEN)) + || !(sc->data.status & MCDDSKIN)) for (retry = 0; retry < DISK_SENSE_SECS * WAIT_FRAC; retry++) { - (void) tsleep((caddr_t)cd, PSOCK | PCATCH, "mcdsn1", hz/WAIT_FRAC); + (void) tsleep((caddr_t)sc, PSOCK | PCATCH, "mcdsn1", hz/WAIT_FRAC); if ((r = mcd_getstat(sc, 1)) == -1) - return EIO; + return (EIO); if (r != -2) break; } - if (cd->status & MCDDOOROPEN) { + if (sc->data.status & MCDDOOROPEN) { device_printf(sc->dev, "door is open\n"); - return ENXIO; + return (ENXIO); } - if (!(cd->status & MCDDSKIN)) { + if (!(sc->data.status & MCDDSKIN)) { device_printf(sc->dev, "no CD inside\n"); - return ENXIO; + return (ENXIO); } - if (cd->status & MCDDSKCHNG) { + if (sc->data.status & MCDDSKCHNG) { device_printf(sc->dev, "CD not sensed\n"); - return ENXIO; + return (ENXIO); } if (mcdsize(dev) < 0) { device_printf(sc->dev, "failed to get disk size\n"); - return ENXIO; + return (ENXIO); } - dev->si_bsize_phys = cd->blksize; + dev->si_bsize_phys = sc->data.blksize; - cd->openflags = 1; - cd->partflags |= MCDREADRAW; - cd->flags |= MCDVALID; + sc->data.openflags = 1; + sc->data.partflags |= MCDREADRAW; + sc->data.flags |= MCDVALID; (void) mcd_lock_door(sc, MCD_LK_LOCK); - if (!(cd->flags & MCDVALID)) - return ENXIO; + if (!(sc->data.flags & MCDVALID)) + return (ENXIO); - return (mcd_read_toc(sc)); + return mcd_read_toc(sc); } static int mcdclose(dev_t dev, int flags, int fmt, struct thread *td) { struct mcd_softc *sc; - struct mcd_data *cd; sc = (struct mcd_softc *)dev->si_drv1; - cd = &sc->data; - if (!(cd->flags & MCDINIT) || !cd->openflags) - return ENXIO; + if (!(sc->data.flags & MCDINIT) || !sc->data.openflags) + return (ENXIO); (void) mcd_lock_door(sc, MCD_LK_UNLOCK); - cd->openflags = 0; - cd->partflags &= ~MCDREADRAW; + sc->data.openflags = 0; + sc->data.partflags &= ~MCDREADRAW; - return 0; + return (0); } static void mcdstrategy(struct bio *bp) { struct mcd_softc *sc; - struct mcd_data *cd; int s; sc = (struct mcd_softc *)bp->bio_dev->si_drv1; - cd = &sc->data; /* test validity */ /*MCD_TRACE("strategy: buf=0x%lx, unit=%ld, block#=%ld bcount=%ld\n", @@ -321,7 +313,7 @@ mcdstrategy(struct bio *bp) } /* if device invalidated (e.g. media change, door open), error */ - if (!(cd->flags & MCDVALID)) { + if (!(sc->data.flags & MCDVALID)) { device_printf(sc->dev, "media changed\n"); bp->bio_error = EIO; goto bad; @@ -337,7 +329,7 @@ mcdstrategy(struct bio *bp) if (bp->bio_bcount == 0) goto done; - if (!(cd->flags & MCDTOC)) { + if (!(sc->data.flags & MCDTOC)) { bp->bio_error = EIO; goto bad; } @@ -347,7 +339,7 @@ mcdstrategy(struct bio *bp) /* queue it */ s = splbio(); - bioqdisksort(&cd->head, bp); + bioqdisksort(&sc->data.head, bp); splx(s); /* now check whether we can perform processing */ @@ -365,21 +357,20 @@ done: static void mcd_start(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; struct bio *bp; int s = splbio(); - if (cd->flags & MCDMBXBSY) { + if (sc->data.flags & MCDMBXBSY) { splx(s); return; } - bp = bioq_first(&cd->head); + bp = bioq_first(&sc->data.head); if (bp != 0) { /* block found to process, dequeue */ /*MCD_TRACE("mcd_start: found block bp=0x%x\n",bp,0,0,0);*/ - bioq_remove(&cd->head, bp); - cd->flags |= MCDMBXBSY; + bioq_remove(&sc->data.head, bp); + sc->data.flags |= MCDMBXBSY; splx(s); } else { /* nothing to do */ @@ -387,10 +378,10 @@ mcd_start(struct mcd_softc *sc) return; } - cd->mbx.retry = MCD_RETRYS; - cd->mbx.bp = bp; + sc->data.mbx.retry = MCD_RETRYS; + sc->data.mbx.bp = bp; - mcd_doread(sc, MCD_S_BEGIN,&(cd->mbx)); + mcd_doread(sc, MCD_S_BEGIN,&(sc->data.mbx)); return; } @@ -398,14 +389,12 @@ static int mcdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) { struct mcd_softc *sc; - struct mcd_data *cd; int retry,r; sc = (struct mcd_softc *)dev->si_drv1; - cd = &sc->data; if (mcd_getstat(sc, 1) == -1) /* detect disk change too */ - return EIO; + return (EIO); MCD_TRACE("ioctl called 0x%lx\n", cmd); switch (cmd) { @@ -417,15 +406,15 @@ MCD_TRACE("ioctl called 0x%lx\n", cmd); case CDIOCSETMUTE: case CDIOCSETLEFT: case CDIOCSETRIGHT: - return EINVAL; + return (EINVAL); case CDIOCEJECT: return mcd_eject(sc); case CDIOCSETDEBUG: - cd->debug = 1; - return 0; + sc->data.debug = 1; + return (0); case CDIOCCLRDEBUG: - cd->debug = 0; - return 0; + sc->data.debug = 0; + return (0); case CDIOCRESET: return mcd_hard_reset(sc); case CDIOCALLOW: @@ -436,35 +425,35 @@ MCD_TRACE("ioctl called 0x%lx\n", cmd); return mcd_inject(sc); } - if (!(cd->flags & MCDVALID)) { - if ( (cd->status & (MCDDSKCHNG|MCDDOOROPEN)) - || !(cd->status & MCDDSKIN)) + if (!(sc->data.flags & MCDVALID)) { + if ( (sc->data.status & (MCDDSKCHNG|MCDDOOROPEN)) + || !(sc->data.status & MCDDSKIN)) for (retry = 0; retry < DISK_SENSE_SECS * WAIT_FRAC; retry++) { - (void) tsleep((caddr_t)cd, PSOCK | PCATCH, "mcdsn2", hz/WAIT_FRAC); + (void) tsleep((caddr_t)sc, PSOCK | PCATCH, "mcdsn2", hz/WAIT_FRAC); if ((r = mcd_getstat(sc, 1)) == -1) - return EIO; + return (EIO); if (r != -2) break; } - if ( (cd->status & (MCDDOOROPEN|MCDDSKCHNG)) - || !(cd->status & MCDDSKIN) + if ( (sc->data.status & (MCDDOOROPEN|MCDDSKCHNG)) + || !(sc->data.status & MCDDSKIN) || mcdsize(dev) < 0 ) - return ENXIO; - cd->flags |= MCDVALID; - cd->partflags |= MCDREADRAW; + return (ENXIO); + sc->data.flags |= MCDVALID; + sc->data.partflags |= MCDREADRAW; (void) mcd_lock_door(sc, MCD_LK_LOCK); - if (!(cd->flags & MCDVALID)) - return ENXIO; + if (!(sc->data.flags & MCDVALID)) + return (ENXIO); } switch (cmd) { case DIOCGMEDIASIZE: - *(off_t *)addr = (off_t)cd->disksize * cd->blksize; + *(off_t *)addr = (off_t)sc->data.disksize * sc->data.blksize; return (0); break; case DIOCGSECTORSIZE: - *(u_int *)addr = cd->blksize; + *(u_int *)addr = sc->data.blksize; return (0); break; @@ -486,12 +475,12 @@ MCD_TRACE("ioctl called 0x%lx\n", cmd); return mcd_pause(sc); case CDIOCSTART: if (mcd_setmode(sc, MCD_MD_COOKED) != 0) - return EIO; - return 0; + return (EIO); + return (0); case CDIOCSTOP: return mcd_stop(sc); default: - return ENOTTY; + return (ENOTTY); } /*NOTREACHED*/ } @@ -500,19 +489,17 @@ static int mcdsize(dev_t dev) { struct mcd_softc *sc; - struct mcd_data *cd; int size; sc = (struct mcd_softc *)dev->si_drv1; - cd = &sc->data; if (mcd_volinfo(sc) == 0) { - cd->blksize = MCDBLK; - size = msf2hsg(cd->volinfo.vol_msf, 0); - cd->disksize = size * (MCDBLK/DEV_BSIZE); - return 0; + sc->data.blksize = MCDBLK; + size = msf2hsg(sc->data.volinfo.vol_msf, 0); + sc->data.disksize = size * (MCDBLK/DEV_BSIZE); + return (0); } - return -1; + return (-1); } /*************************************************************** @@ -548,11 +535,11 @@ twiddle_thumbs(struct mcd_softc *sc, int count, char *whine) for (i = 0; i < count; i++) { if (!(MCD_READ(sc, MCD_FLAGS) & MFL_STATUS_NOT_AVAIL)) - return 1; + return (1); } if (bootverbose) device_printf(sc->dev, "timeout %s\n", whine); - return 0; + return (0); } /* check to see if a Mitsumi CD-ROM is attached to the ISA bus */ @@ -634,7 +621,7 @@ mcd_probe(struct mcd_softc *sc) device_printf(sc->dev, "type %s, version info: %c %x\n", sc->data.name, stbytes[1], stbytes[2]); - return 0; + return (0); } @@ -646,10 +633,10 @@ mcd_waitrdy(struct mcd_softc *sc, int dly) /* wait until flag port senses status ready */ for (i=0; i<dly; i+=MIN_DELAY) { if (!(MCD_READ(sc, MCD_FLAGS) & MFL_STATUS_NOT_AVAIL)) - return 0; + return (0); DELAY(MIN_DELAY); } - return -1; + return (-1); } static int @@ -659,53 +646,51 @@ mcd_getreply(struct mcd_softc *sc, int dly) /* wait data to become ready */ if (mcd_waitrdy(sc, dly)<0) { device_printf(sc->dev, "timeout getreply\n"); - return -1; + return (-1); } /* get the data */ - return MCD_READ(sc, MCD_REG_STATUS) & 0xFF; + return (MCD_READ(sc, MCD_REG_STATUS) & 0xFF); } static int mcd_getstat(struct mcd_softc *sc, int sflg) { int i; - struct mcd_data *cd = &sc->data; /* get the status */ if (sflg) MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDGETSTAT); i = mcd_getreply(sc, DELAY_GETREPLY); if (i<0 || (i & MCD_ST_CMDCHECK)) { - cd->curr_mode = MCD_MD_UNKNOWN; - return -1; + sc->data.curr_mode = MCD_MD_UNKNOWN; + return (-1); } - cd->status = i; + sc->data.status = i; if (mcd_setflags(sc) < 0) - return -2; - return cd->status; + return (-2); + return (sc->data.status); } static int mcd_setflags(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; /* check flags */ - if ( (cd->status & (MCDDSKCHNG|MCDDOOROPEN)) - || !(cd->status & MCDDSKIN)) { + if ( (sc->data.status & (MCDDSKCHNG|MCDDOOROPEN)) + || !(sc->data.status & MCDDSKIN)) { MCD_TRACE("setflags: sensed DSKCHNG or DOOROPEN or !DSKIN\n"); mcd_soft_reset(sc); - return -1; + return (-1); } - if (cd->status & MCDAUDIOBSY) - cd->audio_status = CD_AS_PLAY_IN_PROGRESS; - else if (cd->audio_status == CD_AS_PLAY_IN_PROGRESS) - cd->audio_status = CD_AS_PLAY_COMPLETED; - return 0; + if (sc->data.status & MCDAUDIOBSY) + sc->data.audio_status = CD_AS_PLAY_IN_PROGRESS; + else if (sc->data.audio_status == CD_AS_PLAY_IN_PROGRESS) + sc->data.audio_status = CD_AS_PLAY_COMPLETED; + return (0); } static int @@ -717,11 +702,11 @@ mcd_get(struct mcd_softc *sc, char *buf, int nmax) /* wait for data */ if ((k = mcd_getreply(sc, DELAY_GETREPLY)) < 0) { device_printf(sc->dev, "timeout mcd_get\n"); - return -1; + return (-1); } buf[i] = k; } - return i; + return (i); } static int @@ -737,14 +722,14 @@ mcd_send(struct mcd_softc *sc, int cmd,int nretrys) } if (k == -2) { device_printf(sc->dev, "media changed\n"); - return -1; + return (-1); } if (i == nretrys) { device_printf(sc->dev, "mcd_send retry cnt exceeded\n"); - return -1; + return (-1); } /*MCD_TRACE("mcd_send: done\n",0,0,0,0);*/ - return 0; + return (0); } static void @@ -768,31 +753,30 @@ msf2hsg(bcd_t *msf, int relative) static int mcd_volinfo(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; /* Just return if we already have it */ - if (cd->flags & MCDVOLINFO) return 0; + if (sc->data.flags & MCDVOLINFO) return (0); /*MCD_TRACE("mcd_volinfo: enter\n",0,0,0,0);*/ /* send volume info command */ if (mcd_send(sc, MCD_CMDGETVOLINFO,MCD_RETRYS) < 0) - return EIO; + return (EIO); /* get data */ - if (mcd_get(sc, (char*) &cd->volinfo,sizeof(struct mcd_volinfo)) < 0) { + if (mcd_get(sc, (char*) &sc->data.volinfo,sizeof(struct mcd_volinfo)) < 0) { device_printf(sc->dev, "mcd_volinfo: error read data\n"); - return EIO; + return (EIO); } - if (cd->volinfo.trk_low > 0 && - cd->volinfo.trk_high >= cd->volinfo.trk_low + if (sc->data.volinfo.trk_low > 0 && + sc->data.volinfo.trk_high >= sc->data.volinfo.trk_low ) { - cd->flags |= MCDVOLINFO; /* volinfo is OK */ - return 0; + sc->data.flags |= MCDVOLINFO; /* volinfo is OK */ + return (0); } - return EINVAL; + return (EINVAL); } /* state machine to process read requests @@ -816,7 +800,6 @@ mcd_doread(struct mcd_softc *sc, int state, struct mcd_mbx *mbxin) { struct mcd_mbx *mbx; struct bio *bp; - struct mcd_data *cd; int rm, i, k; struct mcd_read2 rbuf; int blknum; @@ -824,7 +807,6 @@ mcd_doread(struct mcd_softc *sc, int state, struct mcd_mbx *mbxin) mbx = (state!=MCD_S_BEGIN) ? sc->ch_mbxsave : mbxin; bp = mbx->bp; - cd = &sc->data; loop: switch (state) { @@ -848,35 +830,35 @@ retry_status: timeout(mcd_timeout, (caddr_t)sc, hz/100); /* XXX */ return; } - cd->status = MCD_READ(sc, MCD_REG_STATUS) & 0xFF; - if (cd->status & MCD_ST_CMDCHECK) + sc->data.status = MCD_READ(sc, MCD_REG_STATUS) & 0xFF; + if (sc->data.status & MCD_ST_CMDCHECK) goto retry_status; if (mcd_setflags(sc) < 0) goto changed; MCD_TRACE("got WAITSTAT delay=%d\n", RDELAY_WAITSTAT-mbx->count); /* reject, if audio active */ - if (cd->status & MCDAUDIOBSY) { + if (sc->data.status & MCDAUDIOBSY) { device_printf(sc->dev, "audio is active\n"); goto readerr; } retry_mode: /* to check for raw/cooked mode */ - if (cd->flags & MCDREADRAW) { + if (sc->data.flags & MCDREADRAW) { rm = MCD_MD_RAW; mbx->sz = MCDRBLK; } else { rm = MCD_MD_COOKED; - mbx->sz = cd->blksize; + mbx->sz = sc->data.blksize; } - if (rm == cd->curr_mode) + if (rm == sc->data.curr_mode) goto modedone; mbx->count = RDELAY_WAITMODE; - cd->curr_mode = MCD_MD_UNKNOWN; + sc->data.curr_mode = MCD_MD_UNKNOWN; mbx->mode = rm; MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDSETMODE); MCD_WRITE(sc, MCD_REG_COMMAND, rm); @@ -901,14 +883,14 @@ retry_mode: sc->ch = timeout(mcd_timeout, (caddr_t)sc, hz/100); return; } - cd->status = MCD_READ(sc, MCD_REG_STATUS) & 0xFF; - if (cd->status & MCD_ST_CMDCHECK) { - cd->curr_mode = MCD_MD_UNKNOWN; + sc->data.status = MCD_READ(sc, MCD_REG_STATUS) & 0xFF; + if (sc->data.status & MCD_ST_CMDCHECK) { + sc->data.curr_mode = MCD_MD_UNKNOWN; goto retry_mode; } if (mcd_setflags(sc) < 0) goto changed; - cd->curr_mode = mbx->mode; + sc->data.curr_mode = mbx->mode; MCD_TRACE("got WAITMODE delay=%d\n", RDELAY_WAITMODE-mbx->count); modedone: @@ -928,7 +910,7 @@ nextblock: retry_read: /* send the read command */ disable_intr(); - MCD_WRITE(sc, MCD_REG_COMMAND, cd->read_command); + MCD_WRITE(sc, MCD_REG_COMMAND, sc->data.read_command); MCD_WRITE(sc, MCD_REG_COMMAND, rbuf.start_msf[0]); MCD_WRITE(sc, MCD_REG_COMMAND, rbuf.start_msf[1]); MCD_WRITE(sc, MCD_REG_COMMAND, rbuf.start_msf[2]); @@ -984,13 +966,13 @@ retry_read: bp->bio_resid = 0; biodone(bp); - cd->flags &= ~(MCDMBXBSY|MCDREADRAW); + sc->data.flags &= ~(MCDMBXBSY|MCDREADRAW); mcd_start(sc); return; } if (!(k & MFL_STATUS_NOT_AVAIL)) { - cd->status = MCD_READ(sc, MCD_REG_STATUS) & 0xFF; - if (cd->status & MCD_ST_CMDCHECK) + sc->data.status = MCD_READ(sc, MCD_REG_STATUS) & 0xFF; + if (sc->data.status & MCD_ST_CMDCHECK) goto retry_read; if (mcd_setflags(sc) < 0) goto changed; @@ -1016,7 +998,7 @@ harderr: bp->bio_resid = bp->bio_bcount; biodone(bp); - cd->flags &= ~(MCDMBXBSY|MCDREADRAW); + sc->data.flags &= ~(MCDMBXBSY|MCDREADRAW); mcd_start(sc); return; @@ -1030,8 +1012,8 @@ changed: DELAY(300000); (void)mcd_getstat(sc, 1); (void)mcd_getstat(sc, 1); - /*cd->status &= ~MCDDSKCHNG; */ - cd->debug = 1; /* preventive set debug mode */ + /*sc->data.status &= ~MCDDSKCHNG; */ + sc->data.debug = 1; /* preventive set debug mode */ #endif @@ -1044,104 +1026,98 @@ mcd_lock_door(struct mcd_softc *sc, int lock) MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDLOCKDRV); MCD_WRITE(sc, MCD_REG_COMMAND, lock); if (mcd_getstat(sc, 0) == -1) - return EIO; - return 0; + return (EIO); + return (0); } static int mcd_close_tray(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; int retry, r; if (mcd_getstat(sc, 1) == -1) - return EIO; - if (cd->status & MCDDOOROPEN) { + return (EIO); + if (sc->data.status & MCDDOOROPEN) { MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDCLOSETRAY); for (retry = 0; retry < CLOSE_TRAY_SECS * WAIT_FRAC; retry++) { if (MCD_READ(sc, MCD_FLAGS) & MFL_STATUS_NOT_AVAIL) - (void) tsleep((caddr_t)cd, PSOCK | PCATCH, "mcdcls", hz/WAIT_FRAC); + (void) tsleep((caddr_t)sc, PSOCK | PCATCH, "mcdcls", hz/WAIT_FRAC); else { if ((r = mcd_getstat(sc, 0)) == -1) - return EIO; - return 0; + return (EIO); + return (0); } } - return ENXIO; + return (ENXIO); } - return 0; + return (0); } static int mcd_eject(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; int r; if (mcd_getstat(sc, 1) == -1) /* detect disk change too */ - return EIO; - if (cd->status & MCDDOOROPEN) - return 0; + return (EIO); + if (sc->data.status & MCDDOOROPEN) + return (0); if ((r = mcd_stop(sc)) == EIO) - return r; + return (r); MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDEJECTDISK); if (mcd_getstat(sc, 0) == -1) - return EIO; - return 0; + return (EIO); + return (0); } static int mcd_inject(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; if (mcd_getstat(sc, 1) == -1) /* detect disk change too */ - return EIO; - if (cd->status & MCDDOOROPEN) + return (EIO); + if (sc->data.status & MCDDOOROPEN) return mcd_close_tray(sc); - return 0; + return (0); } static int mcd_hard_reset(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; MCD_WRITE(sc, MCD_REG_RESET, MCD_CMDRESET); - cd->curr_mode = MCD_MD_UNKNOWN; - cd->audio_status = CD_AS_AUDIO_INVALID; - return 0; + sc->data.curr_mode = MCD_MD_UNKNOWN; + sc->data.audio_status = CD_AS_AUDIO_INVALID; + return (0); } static void mcd_soft_reset(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; - cd->flags &= (MCDINIT|MCDPROBING|MCDNEWMODEL); - cd->curr_mode = MCD_MD_UNKNOWN; - cd->partflags = 0; - cd->audio_status = CD_AS_AUDIO_INVALID; + sc->data.flags &= (MCDINIT|MCDPROBING|MCDNEWMODEL); + sc->data.curr_mode = MCD_MD_UNKNOWN; + sc->data.partflags = 0; + sc->data.audio_status = CD_AS_AUDIO_INVALID; } static int mcd_setmode(struct mcd_softc *sc, int mode) { - struct mcd_data *cd = &sc->data; int retry, st; - if (cd->curr_mode == mode) - return 0; - if (cd->debug) + if (sc->data.curr_mode == mode) + return (0); + if (sc->data.debug) device_printf(sc->dev, "setting mode to %d\n", mode); for(retry=0; retry<MCD_RETRYS; retry++) { - cd->curr_mode = MCD_MD_UNKNOWN; + sc->data.curr_mode = MCD_MD_UNKNOWN; MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDSETMODE); MCD_WRITE(sc, MCD_REG_COMMAND, mode); if ((st = mcd_getstat(sc, 0)) >= 0) { - cd->curr_mode = mode; - return 0; + sc->data.curr_mode = mode; + return (0); } if (st == -2) { device_printf(sc->dev, "media changed\n"); @@ -1149,117 +1125,114 @@ mcd_setmode(struct mcd_softc *sc, int mode) } } - return -1; + return (-1); } static int mcd_toc_header(struct mcd_softc *sc, struct ioc_toc_header *th) { - struct mcd_data *cd = &sc->data; int r; if ((r = mcd_volinfo(sc)) != 0) - return r; + return (r); - th->starting_track = bcd2bin(cd->volinfo.trk_low); - th->ending_track = bcd2bin(cd->volinfo.trk_high); + th->starting_track = bcd2bin(sc->data.volinfo.trk_low); + th->ending_track = bcd2bin(sc->data.volinfo.trk_high); th->len = 2 * sizeof(u_char) /* start & end tracks */ + (th->ending_track + 1 - th->starting_track + 1) * sizeof(struct cd_toc_entry); - return 0; + return (0); } static int mcd_read_toc(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; struct ioc_toc_header th; struct mcd_qchninfo q; int rc, trk, idx, retry; /* Only read TOC if needed */ - if (cd->flags & MCDTOC) - return 0; + if (sc->data.flags & MCDTOC) + return (0); - if (cd->debug) + if (sc->data.debug) device_printf(sc->dev, "reading toc header\n"); if ((rc = mcd_toc_header(sc, &th)) != 0) - return rc; + return (rc); if (mcd_send(sc, MCD_CMDSTOPAUDIO, MCD_RETRYS) < 0) - return EIO; + return (EIO); if (mcd_setmode(sc, MCD_MD_TOC) != 0) - return EIO; + return (EIO); - if (cd->debug) + if (sc->data.debug) device_printf(sc->dev, "get_toc reading qchannel info\n"); for(trk=th.starting_track; trk<=th.ending_track; trk++) - cd->toc[trk].idx_no = 0; + sc->data.toc[trk].idx_no = 0; trk = th.ending_track - th.starting_track + 1; for(retry=0; retry<600 && trk>0; retry++) { if (mcd_getqchan(sc, &q) < 0) break; idx = bcd2bin(q.idx_no); if (idx>=th.starting_track && idx<=th.ending_track && q.trk_no==0) { - if (cd->toc[idx].idx_no == 0) { - cd->toc[idx] = q; + if (sc->data.toc[idx].idx_no == 0) { + sc->data.toc[idx] = q; trk--; } } } if (mcd_setmode(sc, MCD_MD_COOKED) != 0) - return EIO; + return (EIO); if (trk != 0) - return ENXIO; + return (ENXIO); /* add a fake last+1 */ idx = th.ending_track + 1; - cd->toc[idx].control = cd->toc[idx-1].control; - cd->toc[idx].addr_type = cd->toc[idx-1].addr_type; - cd->toc[idx].trk_no = 0; - cd->toc[idx].idx_no = MCD_LASTPLUS1; - cd->toc[idx].hd_pos_msf[0] = cd->volinfo.vol_msf[0]; - cd->toc[idx].hd_pos_msf[1] = cd->volinfo.vol_msf[1]; - cd->toc[idx].hd_pos_msf[2] = cd->volinfo.vol_msf[2]; - - if (cd->debug) + sc->data.toc[idx].control = sc->data.toc[idx-1].control; + sc->data.toc[idx].addr_type = sc->data.toc[idx-1].addr_type; + sc->data.toc[idx].trk_no = 0; + sc->data.toc[idx].idx_no = MCD_LASTPLUS1; + sc->data.toc[idx].hd_pos_msf[0] = sc->data.volinfo.vol_msf[0]; + sc->data.toc[idx].hd_pos_msf[1] = sc->data.volinfo.vol_msf[1]; + sc->data.toc[idx].hd_pos_msf[2] = sc->data.volinfo.vol_msf[2]; + + if (sc->data.debug) { int i; for (i = th.starting_track; i <= idx; i++) device_printf(sc->dev, "trk %d idx %d pos %d %d %d\n", i, - cd->toc[i].idx_no > 0x99 ? cd->toc[i].idx_no : - bcd2bin(cd->toc[i].idx_no), - bcd2bin(cd->toc[i].hd_pos_msf[0]), - bcd2bin(cd->toc[i].hd_pos_msf[1]), - bcd2bin(cd->toc[i].hd_pos_msf[2])); + sc->data.toc[i].idx_no > 0x99 ? sc->data.toc[i].idx_no : + bcd2bin(sc->data.toc[i].idx_no), + bcd2bin(sc->data.toc[i].hd_pos_msf[0]), + bcd2bin(sc->data.toc[i].hd_pos_msf[1]), + bcd2bin(sc->data.toc[i].hd_pos_msf[2])); } - cd->flags |= MCDTOC; + sc->data.flags |= MCDTOC; - return 0; + return (0); } #if 0 static int mcd_toc_entry(struct mcd_softc *sc, struct ioc_read_toc_single_entry *te) { - struct mcd_data *cd = &sc->data; struct ioc_toc_header th; int rc, trk; if (te->address_format != CD_MSF_FORMAT && te->address_format != CD_LBA_FORMAT) - return EINVAL; + return (EINVAL); /* Copy the toc header */ if ((rc = mcd_toc_header(sc, &th)) != 0) - return rc; + return (rc); /* verify starting track */ trk = te->track; @@ -1268,40 +1241,39 @@ mcd_toc_entry(struct mcd_softc *sc, struct ioc_read_toc_single_entry *te) else if (trk == MCD_LASTPLUS1) trk = th.ending_track + 1; else if (trk < th.starting_track || trk > th.ending_track + 1) - return EINVAL; + return (EINVAL); /* Make sure we have a valid toc */ if ((rc=mcd_read_toc(sc)) != 0) - return rc; + return (rc); /* Copy the TOC data. */ - if (cd->toc[trk].idx_no == 0) - return EIO; + if (sc->data.toc[trk].idx_no == 0) + return (EIO); - te->entry.control = cd->toc[trk].control; - te->entry.addr_type = cd->toc[trk].addr_type; + te->entry.control = sc->data.toc[trk].control; + te->entry.addr_type = sc->data.toc[trk].addr_type; te->entry.track = - cd->toc[trk].idx_no > 0x99 ? cd->toc[trk].idx_no : - bcd2bin(cd->toc[trk].idx_no); + sc->data.toc[trk].idx_no > 0x99 ? sc->data.toc[trk].idx_no : + bcd2bin(sc->data.toc[trk].idx_no); switch (te->address_format) { case CD_MSF_FORMAT: te->entry.addr.msf.unused = 0; - te->entry.addr.msf.minute = bcd2bin(cd->toc[trk].hd_pos_msf[0]); - te->entry.addr.msf.second = bcd2bin(cd->toc[trk].hd_pos_msf[1]); - te->entry.addr.msf.frame = bcd2bin(cd->toc[trk].hd_pos_msf[2]); + te->entry.addr.msf.minute = bcd2bin(sc->data.toc[trk].hd_pos_msf[0]); + te->entry.addr.msf.second = bcd2bin(sc->data.toc[trk].hd_pos_msf[1]); + te->entry.addr.msf.frame = bcd2bin(sc->data.toc[trk].hd_pos_msf[2]); break; case CD_LBA_FORMAT: - te->entry.addr.lba = htonl(msf2hsg(cd->toc[trk].hd_pos_msf, 0)); + te->entry.addr.lba = htonl(msf2hsg(sc->data.toc[trk].hd_pos_msf, 0)); break; } - return 0; + return (0); } #endif static int mcd_toc_entrys(struct mcd_softc *sc, struct ioc_read_toc_entry *te) { - struct mcd_data *cd = &sc->data; struct cd_toc_entry entries[MCD_MAXTOCS]; struct ioc_toc_header th; int rc, n, trk, len; @@ -1311,11 +1283,11 @@ mcd_toc_entrys(struct mcd_softc *sc, struct ioc_read_toc_entry *te) || (te->address_format != CD_MSF_FORMAT && te->address_format != CD_LBA_FORMAT) ) - return EINVAL; + return (EINVAL); /* Copy the toc header */ if ((rc = mcd_toc_header(sc, &th)) != 0) - return rc; + return (rc); /* verify starting track */ trk = te->starting_track; @@ -1324,37 +1296,37 @@ mcd_toc_entrys(struct mcd_softc *sc, struct ioc_read_toc_entry *te) else if (trk == MCD_LASTPLUS1) trk = th.ending_track + 1; else if (trk < th.starting_track || trk > th.ending_track + 1) - return EINVAL; + return (EINVAL); len = ((th.ending_track + 1 - trk) + 1) * sizeof(entries[0]); if (te->data_len < len) len = te->data_len; if (len > sizeof(entries)) - return EINVAL; + return (EINVAL); /* Make sure we have a valid toc */ if ((rc=mcd_read_toc(sc)) != 0) - return rc; + return (rc); /* Copy the TOC data. */ for (n = 0; len > 0 && trk <= th.ending_track + 1; trk++) { - if (cd->toc[trk].idx_no == 0) + if (sc->data.toc[trk].idx_no == 0) continue; - entries[n].control = cd->toc[trk].control; - entries[n].addr_type = cd->toc[trk].addr_type; + entries[n].control = sc->data.toc[trk].control; + entries[n].addr_type = sc->data.toc[trk].addr_type; entries[n].track = - cd->toc[trk].idx_no > 0x99 ? cd->toc[trk].idx_no : - bcd2bin(cd->toc[trk].idx_no); + sc->data.toc[trk].idx_no > 0x99 ? sc->data.toc[trk].idx_no : + bcd2bin(sc->data.toc[trk].idx_no); switch (te->address_format) { case CD_MSF_FORMAT: entries[n].addr.msf.unused = 0; - entries[n].addr.msf.minute = bcd2bin(cd->toc[trk].hd_pos_msf[0]); - entries[n].addr.msf.second = bcd2bin(cd->toc[trk].hd_pos_msf[1]); - entries[n].addr.msf.frame = bcd2bin(cd->toc[trk].hd_pos_msf[2]); + entries[n].addr.msf.minute = bcd2bin(sc->data.toc[trk].hd_pos_msf[0]); + entries[n].addr.msf.second = bcd2bin(sc->data.toc[trk].hd_pos_msf[1]); + entries[n].addr.msf.frame = bcd2bin(sc->data.toc[trk].hd_pos_msf[2]); break; case CD_LBA_FORMAT: - entries[n].addr.lba = htonl(msf2hsg(cd->toc[trk].hd_pos_msf, 0)); + entries[n].addr.lba = htonl(msf2hsg(sc->data.toc[trk].hd_pos_msf, 0)); break; } len -= sizeof(struct cd_toc_entry); @@ -1368,35 +1340,33 @@ mcd_toc_entrys(struct mcd_softc *sc, struct ioc_read_toc_entry *te) static int mcd_stop(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; /* Verify current status */ - if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS && - cd->audio_status != CD_AS_PLAY_PAUSED && - cd->audio_status != CD_AS_PLAY_COMPLETED) { - if (cd->debug) + if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS && + sc->data.audio_status != CD_AS_PLAY_PAUSED && + sc->data.audio_status != CD_AS_PLAY_COMPLETED) { + if (sc->data.debug) device_printf(sc->dev, "stop attempted when not playing, audio status %d\n", - cd->audio_status); - return EINVAL; + sc->data.audio_status); + return (EINVAL); } - if (cd->audio_status == CD_AS_PLAY_IN_PROGRESS) + if (sc->data.audio_status == CD_AS_PLAY_IN_PROGRESS) if (mcd_send(sc, MCD_CMDSTOPAUDIO, MCD_RETRYS) < 0) - return EIO; - cd->audio_status = CD_AS_PLAY_COMPLETED; - return 0; + return (EIO); + sc->data.audio_status = CD_AS_PLAY_COMPLETED; + return (0); } static int mcd_getqchan(struct mcd_softc *sc, struct mcd_qchninfo *q) { - struct mcd_data *cd = &sc->data; if (mcd_send(sc, MCD_CMDGETQCHN, MCD_RETRYS) < 0) - return -1; + return (-1); if (mcd_get(sc, (char *) q, sizeof(struct mcd_qchninfo)) < 0) - return -1; - if (cd->debug) { + return (-1); + if (sc->data.debug) { device_printf(sc->dev, "getqchan control=0x%x addr_type=0x%x trk=%d ind=%d ttm=%d:%d.%d dtm=%d:%d.%d\n", q->control, q->addr_type, @@ -1409,37 +1379,36 @@ mcd_getqchan(struct mcd_softc *sc, struct mcd_qchninfo *q) bcd2bin(q->hd_pos_msf[1]), bcd2bin(q->hd_pos_msf[2])); } - return 0; + return (0); } static int mcd_subchan(struct mcd_softc *sc, struct ioc_read_subchannel *sch) { - struct mcd_data *cd = &sc->data; struct mcd_qchninfo q; struct cd_sub_channel_info data; int lba; - if (cd->debug) + if (sc->data.debug) device_printf(sc->dev, "subchan af=%d, df=%d\n", sch->address_format, sch->data_format); if (sch->address_format != CD_MSF_FORMAT && sch->address_format != CD_LBA_FORMAT) - return EINVAL; + return (EINVAL); if (sch->data_format != CD_CURRENT_POSITION && sch->data_format != CD_MEDIA_CATALOG) - return EINVAL; + return (EINVAL); if (mcd_setmode(sc, MCD_MD_COOKED) != 0) - return EIO; + return (EIO); if (mcd_getqchan(sc, &q) < 0) - return EIO; + return (EIO); - data.header.audio_status = cd->audio_status; + data.header.audio_status = sc->data.audio_status; data.what.position.data_format = sch->data_format; switch (sch->data_format) { @@ -1486,10 +1455,9 @@ mcd_subchan(struct mcd_softc *sc, struct ioc_read_subchannel *sch) static int mcd_playmsf(struct mcd_softc *sc, struct ioc_play_msf *p) { - struct mcd_data *cd = &sc->data; struct mcd_read2 pb; - if (cd->debug) + if (sc->data.debug) device_printf(sc->dev, "playmsf: from %d:%d.%d to %d:%d.%d\n", p->start_m, p->start_s, p->start_f, p->end_m, p->end_s, p->end_f); @@ -1497,10 +1465,10 @@ mcd_playmsf(struct mcd_softc *sc, struct ioc_play_msf *p) if ((p->start_m * 60 * 75 + p->start_s * 75 + p->start_f) >= (p->end_m * 60 * 75 + p->end_s * 75 + p->end_f) || (p->end_m * 60 * 75 + p->end_s * 75 + p->end_f) > - M_msf(cd->volinfo.vol_msf) * 60 * 75 + - S_msf(cd->volinfo.vol_msf) * 75 + - F_msf(cd->volinfo.vol_msf)) - return EINVAL; + M_msf(sc->data.volinfo.vol_msf) * 60 * 75 + + S_msf(sc->data.volinfo.vol_msf) * 75 + + F_msf(sc->data.volinfo.vol_msf)) + return (EINVAL); pb.start_msf[0] = bin2bcd(p->start_m); pb.start_msf[1] = bin2bcd(p->start_s); @@ -1510,7 +1478,7 @@ mcd_playmsf(struct mcd_softc *sc, struct ioc_play_msf *p) pb.end_msf[2] = bin2bcd(p->end_f); if (mcd_setmode(sc, MCD_MD_COOKED) != 0) - return EIO; + return (EIO); return mcd_play(sc, &pb); } @@ -1518,33 +1486,32 @@ mcd_playmsf(struct mcd_softc *sc, struct ioc_play_msf *p) static int mcd_playtracks(struct mcd_softc *sc, struct ioc_play_track *pt) { - struct mcd_data *cd = &sc->data; struct mcd_read2 pb; int a = pt->start_track; int z = pt->end_track; int rc, i; if ((rc = mcd_read_toc(sc)) != 0) - return rc; + return (rc); - if (cd->debug) + if (sc->data.debug) device_printf(sc->dev, "playtracks from %d:%d to %d:%d\n", a, pt->start_index, z, pt->end_index); - if ( a < bcd2bin(cd->volinfo.trk_low) - || a > bcd2bin(cd->volinfo.trk_high) + if ( a < bcd2bin(sc->data.volinfo.trk_low) + || a > bcd2bin(sc->data.volinfo.trk_high) || a > z - || z < bcd2bin(cd->volinfo.trk_low) - || z > bcd2bin(cd->volinfo.trk_high)) - return EINVAL; + || z < bcd2bin(sc->data.volinfo.trk_low) + || z > bcd2bin(sc->data.volinfo.trk_high)) + return (EINVAL); for (i = 0; i < 3; i++) { - pb.start_msf[i] = cd->toc[a].hd_pos_msf[i]; - pb.end_msf[i] = cd->toc[z+1].hd_pos_msf[i]; + pb.start_msf[i] = sc->data.toc[a].hd_pos_msf[i]; + pb.end_msf[i] = sc->data.toc[z+1].hd_pos_msf[i]; } if (mcd_setmode(sc, MCD_MD_COOKED) != 0) - return EIO; + return (EIO); return mcd_play(sc, &pb); } @@ -1552,23 +1519,22 @@ mcd_playtracks(struct mcd_softc *sc, struct ioc_play_track *pt) static int mcd_playblocks(struct mcd_softc *sc, struct ioc_play_blocks *p) { - struct mcd_data *cd = &sc->data; struct mcd_read2 pb; - if (cd->debug) + if (sc->data.debug) device_printf(sc->dev, "playblocks: blkno %d length %d\n", p->blk, p->len); - if (p->blk > cd->disksize || p->len > cd->disksize || + if (p->blk > sc->data.disksize || p->len > sc->data.disksize || p->blk < 0 || p->len < 0 || - (p->blk + p->len) > cd->disksize) - return EINVAL; + (p->blk + p->len) > sc->data.disksize) + return (EINVAL); hsg2msf(p->blk, pb.start_msf); hsg2msf(p->blk + p->len, pb.end_msf); if (mcd_setmode(sc, MCD_MD_COOKED) != 0) - return EIO; + return (EIO); return mcd_play(sc, &pb); } @@ -1576,10 +1542,9 @@ mcd_playblocks(struct mcd_softc *sc, struct ioc_play_blocks *p) static int mcd_play(struct mcd_softc *sc, struct mcd_read2 *pb) { - struct mcd_data *cd = &sc->data; int retry, st = -1, status; - cd->lastpb = *pb; + sc->data.lastpb = *pb; for(retry=0; retry<MCD_RETRYS; retry++) { disable_intr(); @@ -1602,58 +1567,56 @@ mcd_play(struct mcd_softc *sc, struct mcd_read2 *pb) if (status == -2) { device_printf(sc->dev, "media changed\n"); - return ENXIO; + return (ENXIO); } - if (cd->debug) + if (sc->data.debug) device_printf(sc->dev, "mcd_play retry=%d, status=0x%02x\n", retry, status); if (st < 0) - return ENXIO; - cd->audio_status = CD_AS_PLAY_IN_PROGRESS; - return 0; + return (ENXIO); + sc->data.audio_status = CD_AS_PLAY_IN_PROGRESS; + return (0); } static int mcd_pause(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; struct mcd_qchninfo q; int rc; /* Verify current status */ - if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS && - cd->audio_status != CD_AS_PLAY_PAUSED) { - if (cd->debug) + if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS && + sc->data.audio_status != CD_AS_PLAY_PAUSED) { + if (sc->data.debug) device_printf(sc->dev, "pause attempted when not playing, audio status %d\n", - cd->audio_status); - return EINVAL; + sc->data.audio_status); + return (EINVAL); } /* Get the current position */ if (mcd_getqchan(sc, &q) < 0) - return EIO; + return (EIO); /* Copy it into lastpb */ - cd->lastpb.start_msf[0] = q.hd_pos_msf[0]; - cd->lastpb.start_msf[1] = q.hd_pos_msf[1]; - cd->lastpb.start_msf[2] = q.hd_pos_msf[2]; + sc->data.lastpb.start_msf[0] = q.hd_pos_msf[0]; + sc->data.lastpb.start_msf[1] = q.hd_pos_msf[1]; + sc->data.lastpb.start_msf[2] = q.hd_pos_msf[2]; /* Stop playing */ if ((rc=mcd_stop(sc)) != 0) - return rc; + return (rc); /* Set the proper status and exit */ - cd->audio_status = CD_AS_PLAY_PAUSED; - return 0; + sc->data.audio_status = CD_AS_PLAY_PAUSED; + return (0); } static int mcd_resume(struct mcd_softc *sc) { - struct mcd_data *cd = &sc->data; - if (cd->audio_status != CD_AS_PLAY_PAUSED) - return EINVAL; - return mcd_play(sc, &cd->lastpb); + if (sc->data.audio_status != CD_AS_PLAY_PAUSED) + return (EINVAL); + return mcd_play(sc, &sc->data.lastpb); } diff --git a/sys/dev/mcd/mcdvar.h b/sys/dev/mcd/mcdvar.h index 936ac34..9f81ced 100644 --- a/sys/dev/mcd/mcdvar.h +++ b/sys/dev/mcd/mcdvar.h @@ -8,7 +8,6 @@ struct mcd_mbx { int sz; u_long skip; struct bio * bp; - int p_offset; short count; short mode; }; diff --git a/sys/dev/scd/scd.c b/sys/dev/scd/scd.c index cbcbdde..fb91ddd 100644 --- a/sys/dev/scd/scd.c +++ b/sys/dev/scd/scd.c @@ -164,17 +164,15 @@ static struct cdevsw scd_cdevsw = { int scd_attach(struct scd_softc *sc) { - struct scd_data *cd; int unit; - cd = &sc->data; unit = device_get_unit(sc->dev); init_drive(sc); - cd->flags = SCDINIT; - cd->audio_status = CD_AS_AUDIO_INVALID; - bioq_init(&cd->head); + sc->data.flags = SCDINIT; + sc->data.audio_status = CD_AS_AUDIO_INVALID; + bioq_init(&sc->data.head); sc->scd_dev_t = make_dev(&scd_cdevsw, 8 * unit, UID_ROOT, GID_OPERATOR, 0640, "scd%d", unit); @@ -188,18 +186,15 @@ scdopen(dev_t dev, int flags, int fmt, struct thread *td) { struct scd_softc *sc; int rc; - struct scd_data *cd; sc = (struct scd_softc *)dev->si_drv1; - cd = &sc->data; - /* not initialized*/ - if (!(cd->flags & SCDINIT)) + if (!(sc->data.flags & SCDINIT)) return (ENXIO); /* invalidated in the meantime? mark all open part's invalid */ - if (cd->openflag) + if (sc->data.openflag) return (ENXIO); XDEBUG(sc, 1, "DEBUG: status = 0x%x\n", SCD_READ(sc, IREG_STATUS)); @@ -208,7 +203,7 @@ scdopen(dev_t dev, int flags, int fmt, struct thread *td) print_error(sc, rc); return (EIO); } - if (!(cd->flags & SCDTOC)) { + if (!(sc->data.flags & SCDTOC)) { int loop_count = 3; while (loop_count-- > 0 && (rc = read_toc(sc)) != 0) { @@ -225,10 +220,10 @@ scdopen(dev_t dev, int flags, int fmt, struct thread *td) } } - dev->si_bsize_phys = cd->blksize; + dev->si_bsize_phys = sc->data.blksize; - cd->openflag = 1; - cd->flags |= SCDVALID; + sc->data.openflag = 1; + sc->data.flags |= SCDVALID; return (0); } @@ -237,23 +232,20 @@ static int scdclose(dev_t dev, int flags, int fmt, struct thread *td) { struct scd_softc *sc; - struct scd_data *cd; sc = (struct scd_softc *)dev->si_drv1; - cd = &sc->data; - - if (!(cd->flags & SCDINIT) || !cd->openflag) + if (!(sc->data.flags & SCDINIT) || !sc->data.openflag) return (ENXIO); - if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS) { + if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS) { (void)send_cmd(sc, CMD_SPIN_DOWN, 0); - cd->flags &= ~SCDSPINNING; + sc->data.flags &= ~SCDSPINNING; } /* close channel */ - cd->openflag = 0; + sc->data.openflag = 0; return (0); } @@ -261,12 +253,10 @@ scdclose(dev_t dev, int flags, int fmt, struct thread *td) static void scdstrategy(struct bio *bp) { - struct scd_data *cd; int s; struct scd_softc *sc; sc = (struct scd_softc *)bp->bio_dev->si_drv1; - cd = &sc->data; XDEBUG(sc, 2, "DEBUG: strategy: block=%ld, bcount=%ld\n", (long)bp->bio_blkno, bp->bio_bcount); @@ -280,7 +270,7 @@ scdstrategy(struct bio *bp) } /* if device invalidated (e.g. media change, door open), error */ - if (!(cd->flags & SCDVALID)) { + if (!(sc->data.flags & SCDVALID)) { device_printf(sc->dev, "media changed\n"); bp->bio_error = EIO; goto bad; @@ -296,7 +286,7 @@ scdstrategy(struct bio *bp) if (bp->bio_bcount == 0) goto done; - if (!(cd->flags & SCDTOC)) { + if (!(sc->data.flags & SCDTOC)) { bp->bio_error = EIO; goto bad; } @@ -306,7 +296,7 @@ scdstrategy(struct bio *bp) /* queue it */ s = splbio(); - bioqdisksort(&cd->head, bp); + bioqdisksort(&sc->data.head, bp); splx(s); /* now check whether we can perform processing */ @@ -324,20 +314,19 @@ done: static void scd_start(struct scd_softc *sc) { - struct scd_data *cd = &sc->data; struct bio *bp; int s = splbio(); - if (cd->flags & SCDMBXBSY) { + if (sc->data.flags & SCDMBXBSY) { splx(s); return; } - bp = bioq_first(&cd->head); + bp = bioq_first(&sc->data.head); if (bp != 0) { /* block found to process, dequeue */ - bioq_remove(&cd->head, bp); - cd->flags |= SCDMBXBSY; + bioq_remove(&sc->data.head, bp); + sc->data.flags |= SCDMBXBSY; splx(s); } else { /* nothing to do */ @@ -345,35 +334,33 @@ scd_start(struct scd_softc *sc) return; } - cd->mbx.retry = 3; - cd->mbx.bp = bp; + sc->data.mbx.retry = 3; + sc->data.mbx.bp = bp; splx(s); - scd_doread(sc, SCD_S_BEGIN, &(cd->mbx)); + scd_doread(sc, SCD_S_BEGIN, &(sc->data.mbx)); return; } static int scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) { - struct scd_data *cd; struct scd_softc *sc; sc = (struct scd_softc *)dev->si_drv1; - cd = &sc->data; XDEBUG(sc, 1, "ioctl: cmd=0x%lx\n", cmd); - if (!(cd->flags & SCDVALID)) + if (!(sc->data.flags & SCDVALID)) return (EIO); switch (cmd) { case DIOCGMEDIASIZE: - *(off_t *)addr = (off_t)cd->disksize * cd->blksize; + *(off_t *)addr = (off_t)sc->data.disksize * sc->data.blksize; return (0); break; case DIOCGSECTORSIZE: - *(u_int *)addr = cd->blksize; + *(u_int *)addr = sc->data.blksize; return (0); break; case CDIOCPLAYTRACKS: @@ -435,13 +422,12 @@ scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) static int scd_playtracks(struct scd_softc *sc, struct ioc_play_track *pt) { - struct scd_data *cd = &sc->data; struct ioc_play_msf msf; int a = pt->start_track; int z = pt->end_track; int rc; - if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) { + if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) { if (rc == -ERR_NOT_SPINNING) { if (spin_up(sc) != 0) return (EIO); @@ -456,14 +442,14 @@ scd_playtracks(struct scd_softc *sc, struct ioc_play_track *pt) XDEBUG(sc, 1, "playtracks from %d:%d to %d:%d\n", a, pt->start_index, z, pt->end_index); - if ( a < cd->first_track - || a > cd->last_track + if ( a < sc->data.first_track + || a > sc->data.last_track || a > z - || z > cd->last_track) + || z > sc->data.last_track) return (EINVAL); - bcopy(cd->toc[a].start_msf, &msf.start_m, 3); - hsg2msf(msf2hsg(cd->toc[z+1].start_msf)-1, &msf.end_m); + bcopy(sc->data.toc[a].start_msf, &msf.start_m, 3); + hsg2msf(msf2hsg(sc->data.toc[z+1].start_msf)-1, &msf.end_m); return scd_play(sc, &msf); } @@ -488,7 +474,6 @@ scd_playmsf(struct scd_softc *sc, struct ioc_play_msf *msfin) static int scd_play(struct scd_softc *sc, struct ioc_play_msf *msf) { - struct scd_data *cd = &sc->data; int i, rc; XDEBUG(sc, 1, "playing: %02x:%02x:%02x -> %02x:%02x:%02x\n", @@ -501,7 +486,7 @@ scd_play(struct scd_softc *sc, struct ioc_play_msf *msf) msf->start_m, msf->start_s, msf->start_f, msf->end_m, msf->end_s, msf->end_f); if (rc == -ERR_NOT_SPINNING) { - cd->flags &= ~SCDSPINNING; + sc->data.flags &= ~SCDSPINNING; if (spin_up(sc) != 0) return (EIO); } else if (rc < 0) { @@ -511,28 +496,26 @@ scd_play(struct scd_softc *sc, struct ioc_play_msf *msf) break; } } - cd->audio_status = CD_AS_PLAY_IN_PROGRESS; - bcopy((char *)msf, (char *)&cd->last_play, sizeof(struct ioc_play_msf)); + sc->data.audio_status = CD_AS_PLAY_IN_PROGRESS; + bcopy((char *)msf, (char *)&sc->data.last_play, sizeof(struct ioc_play_msf)); return (0); } static int scd_stop(struct scd_softc *sc) { - struct scd_data *cd = &sc->data; (void)send_cmd(sc, CMD_STOP_AUDIO, 0); - cd->audio_status = CD_AS_PLAY_COMPLETED; + sc->data.audio_status = CD_AS_PLAY_COMPLETED; return (0); } static int scd_pause(struct scd_softc *sc) { - struct scd_data *cd = &sc->data; struct sony_subchannel_position_data subpos; - if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS) + if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS) return (EINVAL); if (read_subcode(sc, &subpos) != 0) @@ -541,15 +524,15 @@ scd_pause(struct scd_softc *sc) if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0) return (EIO); - cd->last_play.start_m = subpos.abs_msf[0]; - cd->last_play.start_s = subpos.abs_msf[1]; - cd->last_play.start_f = subpos.abs_msf[2]; - cd->audio_status = CD_AS_PLAY_PAUSED; + sc->data.last_play.start_m = subpos.abs_msf[0]; + sc->data.last_play.start_s = subpos.abs_msf[1]; + sc->data.last_play.start_f = subpos.abs_msf[2]; + sc->data.audio_status = CD_AS_PLAY_PAUSED; XDEBUG(sc, 1, "pause @ %02x:%02x:%02x\n", - cd->last_play.start_m, - cd->last_play.start_s, - cd->last_play.start_f); + sc->data.last_play.start_m, + sc->data.last_play.start_s, + sc->data.last_play.start_f); return (0); } @@ -566,10 +549,9 @@ scd_resume(struct scd_softc *sc) static int scd_eject(struct scd_softc *sc) { - struct scd_data *cd = &sc->data; - cd->audio_status = CD_AS_AUDIO_INVALID; - cd->flags &= ~(SCDSPINNING|SCDTOC); + sc->data.audio_status = CD_AS_AUDIO_INVALID; + sc->data.flags &= ~(SCDSPINNING|SCDTOC); if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0 || send_cmd(sc, CMD_SPIN_DOWN, 0) != 0 || @@ -583,7 +565,6 @@ scd_eject(struct scd_softc *sc) static int scd_subchan(struct scd_softc *sc, struct ioc_read_subchannel *sch) { - struct scd_data *cd = &sc->data; struct sony_subchannel_position_data q; struct cd_sub_channel_info data; @@ -599,7 +580,7 @@ scd_subchan(struct scd_softc *sc, struct ioc_read_subchannel *sch) if (read_subcode(sc, &q) != 0) return (EIO); - data.header.audio_status = cd->audio_status; + data.header.audio_status = sc->data.audio_status; data.what.position.data_format = CD_MSF_FORMAT; data.what.position.track_number = bcd2bin(q.track_number); data.what.position.reladdr.msf.unused = 0; @@ -620,14 +601,12 @@ int scd_probe(struct scd_softc *sc) { struct sony_drive_configuration drive_config; - struct scd_data *cd; int rc; static char namebuf[8+16+8+3]; char *s = namebuf; int loop_count = 0; - cd = &sc->data; - cd->flags = SCDPROBING; + sc->data.flags = SCDPROBING; bzero(&drive_config, sizeof(drive_config)); @@ -670,12 +649,12 @@ again: s--; *s = 0; - cd->name = namebuf; + sc->data.name = namebuf; if (drive_config.config & 0x10) - cd->double_speed = 1; + sc->data.double_speed = 1; else - cd->double_speed = 0; + sc->data.double_speed = 0; return (0); } @@ -723,7 +702,6 @@ scd_doread(struct scd_softc *sc, int state, struct scd_mbx *mbxin) { struct scd_mbx *mbx = (state!=SCD_S_BEGIN) ? sc->ch_mbxsave : mbxin; struct bio *bp = mbx->bp; - struct scd_data *cd = &sc->data; int i; int blknum; caddr_t addr; @@ -759,19 +737,19 @@ trystat: process_attention(sc); /* reject, if audio active */ - if (cd->audio_status & CD_AS_PLAY_IN_PROGRESS) { + if (sc->data.audio_status & CD_AS_PLAY_IN_PROGRESS) { device_printf(sc->dev, "audio is active\n"); goto harderr; } - mbx->sz = cd->blksize; + mbx->sz = sc->data.blksize; /* for first block */ mbx->nblk = (bp->bio_bcount + (mbx->sz-1)) / mbx->sz; mbx->skip = 0; nextblock: - if (!(cd->flags & SCDVALID)) + if (!(sc->data.flags & SCDVALID)) goto changed; blknum = (bp->bio_blkno / (mbx->sz/DEV_BSIZE)) @@ -814,7 +792,7 @@ nextblock: goto harderr; case 0x00: (void)SCD_READ(sc, IREG_RESULT); - cd->flags |= SCDSPINNING; + sc->data.flags |= SCDSPINNING; break; } XDEBUG(sc, 1, "DEBUG: spin up complete\n"); @@ -839,7 +817,7 @@ nextblock: writeparam: /* The reason this test isn't done 'till now is to make sure */ /* that it is ok to send the SPIN_UP cmd below. */ - if (!(cd->flags & SCDSPINNING)) { + if (!(sc->data.flags & SCDSPINNING)) { XDEBUG(sc, 1, "spinning up drive ...\n"); SCD_WRITE(sc, OREG_COMMAND, CMD_SPIN_UP); mbx->count = 300; @@ -881,7 +859,7 @@ writeparam: } if (!STATUS_BIT(sc, SBIT_DATA_READY)) { process_attention(sc); - if (!(cd->flags & SCDVALID)) + if (!(sc->data.flags & SCDVALID)) goto changed; sc->ch_state = SCD_S_WAITREAD; sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */ @@ -940,7 +918,7 @@ got_param: XDEBUG(sc, 1, "read error: drive not spinning\n"); if (mbx->retry-- > 0) { state = SCD_S_BEGIN1; - cd->flags &= ~SCDSPINNING; + sc->data.flags &= ~SCDSPINNING; goto loop; } goto harderr; @@ -962,7 +940,7 @@ got_param: bp->bio_resid = 0; biodone(bp); - cd->flags &= ~SCDMBXBSY; + sc->data.flags &= ~SCDMBXBSY; scd_start(sc); return; } @@ -980,7 +958,7 @@ harderr: bp->bio_resid = bp->bio_bcount; biodone(bp); - cd->flags &= ~SCDMBXBSY; + sc->data.flags &= ~SCDMBXBSY; scd_start(sc); return; @@ -992,6 +970,7 @@ changed: static void hsg2msf(int hsg, bcd_t *msf) { + hsg += 150; M_msf(msf) = bin2bcd(hsg / 4500); hsg %= 4500; @@ -1002,6 +981,7 @@ hsg2msf(int hsg, bcd_t *msf) static int msf2hsg(bcd_t *msf) { + return (bcd2bin(M_msf(msf)) * 60 + bcd2bin(S_msf(msf))) * 75 + bcd2bin(F_msf(msf)) - 150; @@ -1117,14 +1097,11 @@ get_tl(struct sony_toc *toc, int size) static int read_toc(struct scd_softc *sc) { - struct scd_data *cd; struct sony_toc toc; struct sony_tracklist *tl; int rc, i, j; u_long first, last; - cd = &sc->data; - rc = send_cmd(sc, CMD_GET_TOC, 1, 1); if (rc < 0) return (rc); @@ -1140,19 +1117,19 @@ read_toc(struct scd_softc *sc) tl = get_tl(&toc, rc); first = msf2hsg(tl->start_msf); last = msf2hsg(toc.lead_out_start_msf); - cd->blksize = SCDBLKSIZE; - cd->disksize = last*cd->blksize/DEV_BSIZE; + sc->data.blksize = SCDBLKSIZE; + sc->data.disksize = last*sc->data.blksize/DEV_BSIZE; XDEBUG(sc, 1, "firstsector = %ld, lastsector = %ld", first, last); - cd->first_track = bcd2bin(toc.first_track); - cd->last_track = bcd2bin(toc.last_track); - if (cd->last_track > (MAX_TRACKS-2)) - cd->last_track = MAX_TRACKS-2; - for (j = 0, i = cd->first_track; i <= cd->last_track; i++, j++) { - cd->toc[i].adr = tl[j].adr; - cd->toc[i].ctl = tl[j].ctl; /* for xcdplayer */ - bcopy(tl[j].start_msf, cd->toc[i].start_msf, 3); + sc->data.first_track = bcd2bin(toc.first_track); + sc->data.last_track = bcd2bin(toc.last_track); + if (sc->data.last_track > (MAX_TRACKS-2)) + sc->data.last_track = MAX_TRACKS-2; + for (j = 0, i = sc->data.first_track; i <= sc->data.last_track; i++, j++) { + sc->data.toc[i].adr = tl[j].adr; + sc->data.toc[i].ctl = tl[j].ctl; /* for xcdplayer */ + bcopy(tl[j].start_msf, sc->data.toc[i].start_msf, 3); #ifdef SCD_DEBUG if (scd_debuglevel > 0) { if ((j % 3) == 0) { @@ -1160,24 +1137,24 @@ read_toc(struct scd_softc *sc) device_printf(sc->dev, "tracks "); } printf("[%03d: %2d %2d %2d] ", i, - bcd2bin(cd->toc[i].start_msf[0]), - bcd2bin(cd->toc[i].start_msf[1]), - bcd2bin(cd->toc[i].start_msf[2])); + bcd2bin(sc->data.toc[i].start_msf[0]), + bcd2bin(sc->data.toc[i].start_msf[1]), + bcd2bin(sc->data.toc[i].start_msf[2])); } #endif } - bcopy(toc.lead_out_start_msf, cd->toc[cd->last_track+1].start_msf, 3); + bcopy(toc.lead_out_start_msf, sc->data.toc[sc->data.last_track+1].start_msf, 3); #ifdef SCD_DEBUG if (scd_debuglevel > 0) { - i = cd->last_track+1; + i = sc->data.last_track+1; printf("[END: %2d %2d %2d]\n", - bcd2bin(cd->toc[i].start_msf[0]), - bcd2bin(cd->toc[i].start_msf[1]), - bcd2bin(cd->toc[i].start_msf[2])); + bcd2bin(sc->data.toc[i].start_msf[0]), + bcd2bin(sc->data.toc[i].start_msf[1]), + bcd2bin(sc->data.toc[i].start_msf[2])); } #endif - cd->flags |= SCDTOC; + sc->data.flags |= SCDTOC; return (0); } @@ -1277,6 +1254,7 @@ send_cmd(struct scd_softc *sc, u_char cmd, u_int nargs, ...) static void print_error(struct scd_softc *sc, int errcode) { + switch (errcode) { case -ERR_CD_NOT_LOADED: device_printf(sc->dev, "door is open\n"); @@ -1352,16 +1330,15 @@ waitfor_status_bits(struct scd_softc *sc, int bits_set, int bits_clear) static int scd_toc_header (struct scd_softc *sc, struct ioc_toc_header* th) { - struct scd_data *cd = &sc->data; int rc; - if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) { + if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) { print_error(sc, rc); return (EIO); } - th->starting_track = cd->first_track; - th->ending_track = cd->last_track; + th->starting_track = sc->data.first_track; + th->ending_track = sc->data.last_track; th->len = 0; /* not used */ return (0); @@ -1370,11 +1347,10 @@ scd_toc_header (struct scd_softc *sc, struct ioc_toc_header* th) static int scd_toc_entrys (struct scd_softc *sc, struct ioc_read_toc_entry *te) { - struct scd_data *cd = &sc->data; struct cd_toc_entry toc_entry; int rc, i, len = te->data_len; - if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) { + if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) { print_error(sc, rc); return (EIO); } @@ -1382,10 +1358,10 @@ scd_toc_entrys (struct scd_softc *sc, struct ioc_read_toc_entry *te) /* find the toc to copy*/ i = te->starting_track; if (i == SCD_LASTPLUS1) - i = cd->last_track + 1; + i = sc->data.last_track + 1; /* verify starting track */ - if (i < cd->first_track || i > cd->last_track+1) + if (i < sc->data.first_track || i > sc->data.last_track+1) return (EINVAL); /* valid length ? */ @@ -1394,14 +1370,14 @@ scd_toc_entrys (struct scd_softc *sc, struct ioc_read_toc_entry *te) return (EINVAL); /* copy the toc data */ - toc_entry.control = cd->toc[i].ctl; + toc_entry.control = sc->data.toc[i].ctl; toc_entry.addr_type = te->address_format; toc_entry.track = i; if (te->address_format == CD_MSF_FORMAT) { toc_entry.addr.msf.unused = 0; - toc_entry.addr.msf.minute = bcd2bin(cd->toc[i].start_msf[0]); - toc_entry.addr.msf.second = bcd2bin(cd->toc[i].start_msf[1]); - toc_entry.addr.msf.frame = bcd2bin(cd->toc[i].start_msf[2]); + toc_entry.addr.msf.minute = bcd2bin(sc->data.toc[i].start_msf[0]); + toc_entry.addr.msf.second = bcd2bin(sc->data.toc[i].start_msf[1]); + toc_entry.addr.msf.frame = bcd2bin(sc->data.toc[i].start_msf[2]); } /* copy the data back */ @@ -1415,11 +1391,10 @@ scd_toc_entrys (struct scd_softc *sc, struct ioc_read_toc_entry *te) static int scd_toc_entry (struct scd_softc *sc, struct ioc_read_toc_single_entry *te) { - struct scd_data *cd = &sc->data; struct cd_toc_entry toc_entry; int rc, i; - if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) { + if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) { print_error(sc, rc); return (EIO); } @@ -1427,21 +1402,21 @@ scd_toc_entry (struct scd_softc *sc, struct ioc_read_toc_single_entry *te) /* find the toc to copy*/ i = te->track; if (i == SCD_LASTPLUS1) - i = cd->last_track + 1; + i = sc->data.last_track + 1; /* verify starting track */ - if (i < cd->first_track || i > cd->last_track+1) + if (i < sc->data.first_track || i > sc->data.last_track+1) return (EINVAL); /* copy the toc data */ - toc_entry.control = cd->toc[i].ctl; + toc_entry.control = sc->data.toc[i].ctl; toc_entry.addr_type = te->address_format; toc_entry.track = i; if (te->address_format == CD_MSF_FORMAT) { toc_entry.addr.msf.unused = 0; - toc_entry.addr.msf.minute = bcd2bin(cd->toc[i].start_msf[0]); - toc_entry.addr.msf.second = bcd2bin(cd->toc[i].start_msf[1]); - toc_entry.addr.msf.frame = bcd2bin(cd->toc[i].start_msf[2]); + toc_entry.addr.msf.minute = bcd2bin(sc->data.toc[i].start_msf[0]); + toc_entry.addr.msf.second = bcd2bin(sc->data.toc[i].start_msf[1]); + toc_entry.addr.msf.frame = bcd2bin(sc->data.toc[i].start_msf[2]); } /* copy the data back */ |