freebsd-skq/sys/dev/mcd/mcd.c

1653 lines
40 KiB
C
Raw Normal View History

/*-
* Copyright 1993 by Holger Veit (data part)
* Copyright 1993 by Brian Moore (audio part)
* Changes Copyright 1993 by Gary Clark II
* Changes Copyright (C) 1994-1995 by Andrey A. Chernov, Moscow, Russia
*
* Rewrote probe routine to work on newer Mitsumi drives.
* Additional changes (C) 1994 by Jordan K. Hubbard
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This software was developed by Holger Veit and Brian Moore
* for use with "386BSD" and similar operating systems.
* "Similar operating systems" includes mainly non-profit oriented
* systems for research and education, including but not restricted to
* "NetBSD", "FreeBSD", "Mach" (by CMU).
* 4. Neither the name of the developer(s) nor the name "386BSD"
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER(S) BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
static const char __used COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/bio.h>
#include <sys/cdio.h>
2002-10-06 00:19:38 +00:00
#include <sys/disk.h>
#include <sys/bus.h>
2002-10-04 07:14:19 +00:00
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
2002-10-04 07:14:19 +00:00
#include <isa/isavar.h>
#include <dev/mcd/mcdreg.h>
#include <dev/mcd/mcdvar.h>
#define MCD_TRACE(format, args...) \
{ \
2002-10-04 07:14:19 +00:00
if (sc->debug) { \
device_printf(sc->dev, "status=0x%02x: ", \
sc->data.status); \
printf(format, ## args); \
} \
}
1994-08-29 21:19:27 +00:00
#define RAW_PART 2
/* flags */
#define MCDVALID 0x0001 /* parameters loaded */
#define MCDINIT 0x0002 /* device is init'd */
#define MCDNEWMODEL 0x0004 /* device is new model */
#define MCDLABEL 0x0008 /* label is read */
#define MCDPROBING 0x0010 /* probing */
#define MCDREADRAW 0x0020 /* read raw mode (2352 bytes) */
#define MCDVOLINFO 0x0040 /* already read volinfo */
#define MCDTOC 0x0080 /* already read toc */
#define MCDMBXBSY 0x0100 /* local mbx is busy */
/* status */
#define MCDAUDIOBSY MCD_ST_AUDIOBSY /* playing audio */
#define MCDDSKCHNG MCD_ST_DSKCHNG /* sensed change of disk */
#define MCDDSKIN MCD_ST_DSKIN /* sensed disk in drive */
#define MCDDOOROPEN MCD_ST_DOOROPEN /* sensed door open */
/* These are apparently the different states a mitsumi can get up to */
#define MCDCDABSENT 0x0030
#define MCDCDPRESENT 0x0020
#define MCDSCLOSED 0x0080
#define MCDSOPEN 0x00a0
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
#define MCD_MD_UNKNOWN (-1)
#define MCD_TYPE_UNKNOWN 0
#define MCD_TYPE_LU002S 1
#define MCD_TYPE_LU005S 2
#define MCD_TYPE_LU006S 3
#define MCD_TYPE_FX001 4
#define MCD_TYPE_FX001D 5
/* reader state machine */
#define MCD_S_BEGIN 0
#define MCD_S_BEGIN1 1
#define MCD_S_WAITSTAT 2
#define MCD_S_WAITMODE 3
#define MCD_S_WAITREAD 4
/* prototypes */
2002-10-04 07:14:19 +00:00
static void mcd_start(struct mcd_softc *);
#ifdef NOTYET
2002-10-04 07:14:19 +00:00
static void mcd_configure(struct mcd_softc *sc);
#endif
2002-10-04 07:14:19 +00:00
static int mcd_get(struct mcd_softc *, char *buf, int nmax);
static int mcd_setflags(struct mcd_softc *);
static int mcd_getstat(struct mcd_softc *,int sflg);
static int mcd_send(struct mcd_softc *, int cmd,int nretrys);
static void hsg2msf(int hsg, bcd_t *msf);
static int msf2hsg(bcd_t *msf, int relative);
static int mcd_volinfo(struct mcd_softc *);
static int mcd_waitrdy(struct mcd_softc *,int dly);
static void mcd_timeout(void *arg);
2002-10-04 07:14:19 +00:00
static void mcd_doread(struct mcd_softc *, int state, struct mcd_mbx *mbxin);
static void mcd_soft_reset(struct mcd_softc *);
static int mcd_hard_reset(struct mcd_softc *);
static int mcd_setmode(struct mcd_softc *, int mode);
static int mcd_getqchan(struct mcd_softc *, struct mcd_qchninfo *q);
static int mcd_subchan(struct mcd_softc *, struct ioc_read_subchannel *sc,
int nocopyout);
2002-10-04 07:14:19 +00:00
static int mcd_toc_header(struct mcd_softc *, struct ioc_toc_header *th);
static int mcd_read_toc(struct mcd_softc *);
static int mcd_toc_entrys(struct mcd_softc *, struct ioc_read_toc_entry *te);
#if 0
2002-10-04 07:14:19 +00:00
static int mcd_toc_entry(struct mcd_softc *, struct ioc_read_toc_single_entry *te);
#endif
2002-10-04 07:14:19 +00:00
static int mcd_stop(struct mcd_softc *);
static int mcd_eject(struct mcd_softc *);
static int mcd_inject(struct mcd_softc *);
static int mcd_playtracks(struct mcd_softc *, struct ioc_play_track *pt);
static int mcd_play(struct mcd_softc *, struct mcd_read2 *pb);
static int mcd_playmsf(struct mcd_softc *, struct ioc_play_msf *pt);
static int mcd_playblocks(struct mcd_softc *, struct ioc_play_blocks *);
static int mcd_pause(struct mcd_softc *);
static int mcd_resume(struct mcd_softc *);
static int mcd_lock_door(struct mcd_softc *, int lock);
static int mcd_close_tray(struct mcd_softc *);
static int mcd_size(struct cdev *dev);
2002-10-04 07:14:19 +00:00
static d_open_t mcdopen;
static d_close_t mcdclose;
static d_ioctl_t mcdioctl;
static d_strategy_t mcdstrategy;
static struct cdevsw mcd_cdevsw = {
.d_version = D_VERSION,
.d_open = mcdopen,
.d_close = mcdclose,
.d_read = physread,
.d_ioctl = mcdioctl,
.d_strategy = mcdstrategy,
.d_name = "mcd",
.d_flags = D_DISK,
};
#define MCD_RETRYS 5
#define MCD_RDRETRYS 8
#define CLOSE_TRAY_SECS 8
#define DISK_SENSE_SECS 3
#define WAIT_FRAC 4
/* several delays */
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
#define RDELAY_WAITSTAT 300
#define RDELAY_WAITMODE 300
#define RDELAY_WAITREAD 800
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
#define MIN_DELAY 15
#define DELAY_GETREPLY 5000000
2002-10-04 07:14:19 +00:00
int
mcd_attach(struct mcd_softc *sc)
{
2002-10-04 07:14:19 +00:00
int unit;
unit = device_get_unit(sc->dev);
1995-05-30 08:16:23 +00:00
MCD_LOCK(sc);
2002-11-06 08:08:55 +00:00
sc->data.flags |= MCDINIT;
2002-10-04 07:14:19 +00:00
mcd_soft_reset(sc);
2002-11-06 08:08:55 +00:00
bioq_init(&sc->data.head);
#ifdef NOTYET
/* wire controller for interrupts and dma */
2002-10-04 07:14:19 +00:00
mcd_configure(sc);
#endif
MCD_UNLOCK(sc);
/* name filled in probe */
2002-10-06 00:19:38 +00:00
sc->mcd_dev_t = make_dev(&mcd_cdevsw, 8 * unit,
2002-10-04 07:14:19 +00:00
UID_ROOT, GID_OPERATOR, 0640, "mcd%d", unit);
2002-10-06 00:19:38 +00:00
sc->mcd_dev_t->si_drv1 = (void *)sc;
callout_init_mtx(&sc->timer, &sc->mtx, 0);
2002-10-04 07:14:19 +00:00
2002-11-06 08:08:55 +00:00
return (0);
}
2002-10-04 02:21:26 +00:00
static int
mcdopen(struct cdev *dev, int flags, int fmt, struct thread *td)
{
2002-10-04 07:14:19 +00:00
struct mcd_softc *sc;
2002-10-06 00:19:38 +00:00
int r,retry;
1995-05-30 08:16:23 +00:00
2002-10-04 07:14:19 +00:00
sc = (struct mcd_softc *)dev->si_drv1;
1995-05-30 08:16:23 +00:00
/* invalidated in the meantime? mark all open part's invalid */
MCD_LOCK(sc);
if (!(sc->data.flags & MCDVALID) && sc->data.openflags) {
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (ENXIO);
}
if (mcd_getstat(sc, 1) == -1) {
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (EIO);
}
2002-11-06 08:08:55 +00:00
if ( (sc->data.status & (MCDDSKCHNG|MCDDOOROPEN))
|| !(sc->data.status & MCDDSKIN))
for (retry = 0; retry < DISK_SENSE_SECS * WAIT_FRAC; retry++) {
(void) mtx_sleep(sc, &sc->mtx, PSOCK | PCATCH,
"mcdsn1", hz/WAIT_FRAC);
if ((r = mcd_getstat(sc, 1)) == -1) {
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (EIO);
}
if (r != -2)
break;
}
2002-11-06 08:08:55 +00:00
if (sc->data.status & MCDDOOROPEN) {
MCD_UNLOCK(sc);
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "door is open\n");
2002-11-06 08:08:55 +00:00
return (ENXIO);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
2002-11-06 08:08:55 +00:00
if (!(sc->data.status & MCDDSKIN)) {
MCD_UNLOCK(sc);
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "no CD inside\n");
2002-11-06 08:08:55 +00:00
return (ENXIO);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
2002-11-06 08:08:55 +00:00
if (sc->data.status & MCDDSKCHNG) {
MCD_UNLOCK(sc);
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "CD not sensed\n");
2002-11-06 08:08:55 +00:00
return (ENXIO);
}
if (mcd_size(dev) < 0) {
MCD_UNLOCK(sc);
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "failed to get disk size\n");
2002-11-06 08:08:55 +00:00
return (ENXIO);
2002-10-06 00:19:38 +00:00
}
2002-11-06 08:08:55 +00:00
sc->data.openflags = 1;
sc->data.partflags |= MCDREADRAW;
sc->data.flags |= MCDVALID;
2002-10-06 00:19:38 +00:00
(void) mcd_lock_door(sc, MCD_LK_LOCK);
if (!(sc->data.flags & MCDVALID)) {
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (ENXIO);
}
1995-05-30 08:16:23 +00:00
r = mcd_read_toc(sc);
MCD_UNLOCK(sc);
return (r);
}
2002-10-04 02:21:26 +00:00
static int
mcdclose(struct cdev *dev, int flags, int fmt, struct thread *td)
{
2002-10-04 07:14:19 +00:00
struct mcd_softc *sc;
1995-05-30 08:16:23 +00:00
2002-10-04 07:14:19 +00:00
sc = (struct mcd_softc *)dev->si_drv1;
1995-05-30 08:16:23 +00:00
MCD_LOCK(sc);
KASSERT(sc->data.openflags, ("device not open"));
2002-10-04 07:14:19 +00:00
(void) mcd_lock_door(sc, MCD_LK_UNLOCK);
2002-11-06 08:08:55 +00:00
sc->data.openflags = 0;
sc->data.partflags &= ~MCDREADRAW;
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (0);
}
2002-10-04 02:21:26 +00:00
static void
mcdstrategy(struct bio *bp)
{
2002-10-04 07:14:19 +00:00
struct mcd_softc *sc;
1995-05-30 08:16:23 +00:00
2002-10-04 07:14:19 +00:00
sc = (struct mcd_softc *)bp->bio_dev->si_drv1;
/* if device invalidated (e.g. media change, door open), error */
MCD_LOCK(sc);
2002-11-06 08:08:55 +00:00
if (!(sc->data.flags & MCDVALID)) {
2002-10-06 00:19:38 +00:00
device_printf(sc->dev, "media changed\n");
bp->bio_error = EIO;
goto bad;
}
/* read only */
if (!(bp->bio_cmd == BIO_READ)) {
bp->bio_error = EROFS;
goto bad;
}
1995-05-30 08:16:23 +00:00
/* no data to read */
if (bp->bio_bcount == 0)
goto done;
1995-05-30 08:16:23 +00:00
2002-11-06 08:08:55 +00:00
if (!(sc->data.flags & MCDTOC)) {
2002-10-06 00:19:38 +00:00
bp->bio_error = EIO;
goto bad;
}
1995-05-30 08:16:23 +00:00
2002-10-06 00:19:38 +00:00
bp->bio_resid = 0;
/* queue it */
bioq_disksort(&sc->data.head, bp);
1995-05-30 08:16:23 +00:00
/* now check whether we can perform processing */
2002-10-04 07:14:19 +00:00
mcd_start(sc);
MCD_UNLOCK(sc);
return;
bad:
bp->bio_flags |= BIO_ERROR;
done:
MCD_UNLOCK(sc);
bp->bio_resid = bp->bio_bcount;
biodone(bp);
return;
}
2002-10-04 02:21:26 +00:00
static void
2002-10-04 07:14:19 +00:00
mcd_start(struct mcd_softc *sc)
{
struct bio *bp;
1995-05-30 08:16:23 +00:00
MCD_ASSERT_LOCKED(sc);
2002-11-06 08:08:55 +00:00
if (sc->data.flags & MCDMBXBSY) {
return;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
bp = bioq_takefirst(&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);*/
2002-11-06 08:08:55 +00:00
sc->data.flags |= MCDMBXBSY;
} else {
/* nothing to do */
return;
}
2002-11-06 08:08:55 +00:00
sc->data.mbx.retry = MCD_RETRYS;
sc->data.mbx.bp = bp;
2002-11-06 08:08:55 +00:00
mcd_doread(sc, MCD_S_BEGIN,&(sc->data.mbx));
return;
}
2002-10-04 02:21:26 +00:00
static int
mcdioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
{
2002-10-04 07:14:19 +00:00
struct mcd_softc *sc;
2002-10-06 00:19:38 +00:00
int retry,r;
1995-05-30 08:16:23 +00:00
2002-10-04 07:14:19 +00:00
sc = (struct mcd_softc *)dev->si_drv1;
MCD_LOCK(sc);
if (mcd_getstat(sc, 1) == -1) { /* detect disk change too */
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (EIO);
}
MCD_TRACE("ioctl called 0x%lx\n", cmd);
switch (cmd) {
case CDIOCSETPATCH:
case CDIOCGETVOL:
case CDIOCSETVOL:
case CDIOCSETMONO:
case CDIOCSETSTERIO:
case CDIOCSETMUTE:
case CDIOCSETLEFT:
case CDIOCSETRIGHT:
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (EINVAL);
case CDIOCEJECT:
r = mcd_eject(sc);
MCD_UNLOCK(sc);
return (r);
case CDIOCSETDEBUG:
2002-11-06 08:08:55 +00:00
sc->data.debug = 1;
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (0);
case CDIOCCLRDEBUG:
2002-11-06 08:08:55 +00:00
sc->data.debug = 0;
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (0);
case CDIOCRESET:
r = mcd_hard_reset(sc);
MCD_UNLOCK(sc);
return (r);
case CDIOCALLOW:
r = mcd_lock_door(sc, MCD_LK_UNLOCK);
MCD_UNLOCK(sc);
return (r);
case CDIOCPREVENT:
r = mcd_lock_door(sc, MCD_LK_LOCK);
MCD_UNLOCK(sc);
return (r);
case CDIOCCLOSE:
r = mcd_inject(sc);
MCD_UNLOCK(sc);
return (r);
}
2002-11-06 08:08:55 +00:00
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) mtx_sleep(sc, &sc->mtx, PSOCK | PCATCH,
"mcdsn2", hz/WAIT_FRAC);
if ((r = mcd_getstat(sc, 1)) == -1) {
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (EIO);
}
if (r != -2)
break;
}
2002-11-06 08:08:55 +00:00
if ( (sc->data.status & (MCDDOOROPEN|MCDDSKCHNG))
|| !(sc->data.status & MCDDSKIN)
|| mcd_size(dev) < 0
) {
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (ENXIO);
}
2002-11-06 08:08:55 +00:00
sc->data.flags |= MCDVALID;
sc->data.partflags |= MCDREADRAW;
2002-10-04 07:14:19 +00:00
(void) mcd_lock_door(sc, MCD_LK_LOCK);
if (!(sc->data.flags & MCDVALID)) {
MCD_UNLOCK(sc);
2002-11-06 08:08:55 +00:00
return (ENXIO);
}
}
switch (cmd) {
2002-10-06 00:19:38 +00:00
case DIOCGMEDIASIZE:
2002-11-06 08:08:55 +00:00
*(off_t *)addr = (off_t)sc->data.disksize * sc->data.blksize;
r = 0;
break;
2002-10-06 00:19:38 +00:00
case DIOCGSECTORSIZE:
2002-11-06 08:08:55 +00:00
*(u_int *)addr = sc->data.blksize;
r = 0;
break;
case CDIOCPLAYTRACKS:
r = mcd_playtracks(sc, (struct ioc_play_track *) addr);
break;
case CDIOCPLAYBLOCKS:
r = mcd_playblocks(sc, (struct ioc_play_blocks *) addr);
break;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
case CDIOCPLAYMSF:
r = mcd_playmsf(sc, (struct ioc_play_msf *) addr);
break;
case CDIOCREADSUBCHANNEL_SYSSPACE:
return mcd_subchan(sc, (struct ioc_read_subchannel *) addr, 1);
case CDIOCREADSUBCHANNEL:
return mcd_subchan(sc, (struct ioc_read_subchannel *) addr, 0);
case CDIOREADTOCHEADER:
r = mcd_toc_header(sc, (struct ioc_toc_header *) addr);
break;
case CDIOREADTOCENTRYS:
2002-10-04 07:14:19 +00:00
return mcd_toc_entrys(sc, (struct ioc_read_toc_entry *) addr);
case CDIOCRESUME:
r = mcd_resume(sc);
break;
case CDIOCPAUSE:
r = mcd_pause(sc);
break;
case CDIOCSTART:
2002-10-04 07:14:19 +00:00
if (mcd_setmode(sc, MCD_MD_COOKED) != 0)
r = EIO;
else
r = 0;
break;
case CDIOCSTOP:
r = mcd_stop(sc);
break;
default:
r = ENOTTY;
}
MCD_UNLOCK(sc);
return (r);
}
2002-10-04 02:21:26 +00:00
static int
mcd_size(struct cdev *dev)
{
2002-10-04 07:14:19 +00:00
struct mcd_softc *sc;
int size;
2002-10-04 07:14:19 +00:00
sc = (struct mcd_softc *)dev->si_drv1;
if (mcd_volinfo(sc) == 0) {
2002-11-06 08:08:55 +00:00
sc->data.blksize = MCDBLK;
size = msf2hsg(sc->data.volinfo.vol_msf, 0);
sc->data.disksize = size * (MCDBLK/DEV_BSIZE);
return (0);
}
2002-11-06 08:08:55 +00:00
return (-1);
}
/***************************************************************
* lower level of driver starts here
**************************************************************/
#ifdef NOTDEF
static char
irqs[] = {
0x00,0x00,0x10,0x20,0x00,0x30,0x00,0x00,
0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00
};
static char
drqs[] = {
0x00,0x01,0x00,0x03,0x00,0x05,0x06,0x07,
};
#endif
#ifdef NOT_YET
static void
2002-10-04 07:14:19 +00:00
mcd_configure(struct mcd_softc *sc)
{
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_CONFIG, sc->data.config);
}
#endif
/* Wait for non-busy - return 0 on timeout */
static int
2002-10-04 07:14:19 +00:00
twiddle_thumbs(struct mcd_softc *sc, int count, char *whine)
{
int i;
for (i = 0; i < count; i++) {
2002-10-04 07:14:19 +00:00
if (!(MCD_READ(sc, MCD_FLAGS) & MFL_STATUS_NOT_AVAIL))
2002-11-06 08:08:55 +00:00
return (1);
}
if (bootverbose)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "timeout %s\n", whine);
2002-11-06 08:08:55 +00:00
return (0);
}
/* check to see if a Mitsumi CD-ROM is attached to the ISA bus */
2002-10-04 07:14:19 +00:00
int
mcd_probe(struct mcd_softc *sc)
{
int i, j;
unsigned char stbytes[3];
2002-10-04 07:14:19 +00:00
sc->data.flags = MCDPROBING;
#ifdef NOTDEF
/* get irq/drq configuration word */
2002-10-04 07:14:19 +00:00
sc->data.config = irqs[dev->id_irq]; /* | drqs[dev->id_drq];*/
#else
2002-10-04 07:14:19 +00:00
sc->data.config = 0;
#endif
/* send a reset */
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_FLAGS, M_RESET);
/*
* delay awhile by getting any pending garbage (old data) and
* throwing it away.
*/
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
for (i = 1000000; i != 0; i--)
2002-10-04 07:14:19 +00:00
(void)MCD_READ(sc, MCD_FLAGS);
/* Get status */
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_DATA, MCD_CMDGETSTAT);
if (!twiddle_thumbs(sc, 1000000, "getting status"))
return (ENXIO); /* Timeout */
/* Get version information */
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_DATA, MCD_CMDCONTINFO);
for (j = 0; j < 3; j++) {
2002-10-04 07:14:19 +00:00
if (!twiddle_thumbs(sc, 3000, "getting version info"))
return (ENXIO);
stbytes[j] = (MCD_READ(sc, MCD_DATA) & 0xFF);
}
if (stbytes[1] == stbytes[2])
2002-10-04 07:14:19 +00:00
return (ENXIO);
if (stbytes[2] >= 4 || stbytes[1] != 'M') {
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_CTRL, M_PICKLE);
sc->data.flags |= MCDNEWMODEL;
}
2002-10-04 07:14:19 +00:00
sc->data.read_command = MCD_CMDSINGLESPEEDREAD;
switch (stbytes[1]) {
case 'M':
if (stbytes[2] <= 2) {
2002-10-04 07:14:19 +00:00
sc->data.type = MCD_TYPE_LU002S;
sc->data.name = "Mitsumi LU002S";
} else if (stbytes[2] <= 5) {
2002-10-04 07:14:19 +00:00
sc->data.type = MCD_TYPE_LU005S;
sc->data.name = "Mitsumi LU005S";
} else {
2002-10-04 07:14:19 +00:00
sc->data.type = MCD_TYPE_LU006S;
sc->data.name = "Mitsumi LU006S";
}
break;
case 'F':
2002-10-04 07:14:19 +00:00
sc->data.type = MCD_TYPE_FX001;
sc->data.name = "Mitsumi FX001";
break;
case 'D':
2002-10-04 07:14:19 +00:00
sc->data.type = MCD_TYPE_FX001D;
sc->data.name = "Mitsumi FX001D";
sc->data.read_command = MCD_CMDDOUBLESPEEDREAD;
break;
default:
2002-10-04 07:14:19 +00:00
sc->data.type = MCD_TYPE_UNKNOWN;
sc->data.name = "Mitsumi ???";
break;
}
2002-10-04 07:14:19 +00:00
if (bootverbose)
device_printf(sc->dev, "type %s, version info: %c %x\n",
sc->data.name, stbytes[1], stbytes[2]);
2002-11-06 08:08:55 +00:00
return (0);
}
static int
2002-10-04 07:14:19 +00:00
mcd_waitrdy(struct mcd_softc *sc, int dly)
{
int i;
/* wait until flag port senses status ready */
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
for (i=0; i<dly; i+=MIN_DELAY) {
2002-10-04 07:14:19 +00:00
if (!(MCD_READ(sc, MCD_FLAGS) & MFL_STATUS_NOT_AVAIL))
2002-11-06 08:08:55 +00:00
return (0);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
DELAY(MIN_DELAY);
}
2002-11-06 08:08:55 +00:00
return (-1);
}
static int
2002-10-04 07:14:19 +00:00
mcd_getreply(struct mcd_softc *sc, int dly)
{
/* wait data to become ready */
2002-10-04 07:14:19 +00:00
if (mcd_waitrdy(sc, dly)<0) {
device_printf(sc->dev, "timeout getreply\n");
2002-11-06 08:08:55 +00:00
return (-1);
}
/* get the data */
2002-11-06 08:08:55 +00:00
return (MCD_READ(sc, MCD_REG_STATUS) & 0xFF);
}
static int
2002-10-04 07:14:19 +00:00
mcd_getstat(struct mcd_softc *sc, int sflg)
{
int i;
/* get the status */
if (sflg)
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDGETSTAT);
i = mcd_getreply(sc, DELAY_GETREPLY);
if (i<0 || (i & MCD_ST_CMDCHECK)) {
2002-11-06 08:08:55 +00:00
sc->data.curr_mode = MCD_MD_UNKNOWN;
return (-1);
}
2002-11-06 08:08:55 +00:00
sc->data.status = i;
2002-10-04 07:14:19 +00:00
if (mcd_setflags(sc) < 0)
2002-11-06 08:08:55 +00:00
return (-2);
return (sc->data.status);
}
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
static int
2002-10-04 07:14:19 +00:00
mcd_setflags(struct mcd_softc *sc)
{
2002-10-04 07:14:19 +00:00
/* check flags */
2002-11-06 08:08:55 +00:00
if ( (sc->data.status & (MCDDSKCHNG|MCDDOOROPEN))
|| !(sc->data.status & MCDDSKIN)) {
MCD_TRACE("setflags: sensed DSKCHNG or DOOROPEN or !DSKIN\n");
2002-10-04 07:14:19 +00:00
mcd_soft_reset(sc);
2002-11-06 08:08:55 +00:00
return (-1);
}
2002-11-06 08:08:55 +00:00
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
2002-10-04 07:14:19 +00:00
mcd_get(struct mcd_softc *sc, char *buf, int nmax)
{
int i,k;
1995-05-30 08:16:23 +00:00
for (i=0; i<nmax; i++) {
/* wait for data */
2002-10-04 07:14:19 +00:00
if ((k = mcd_getreply(sc, DELAY_GETREPLY)) < 0) {
device_printf(sc->dev, "timeout mcd_get\n");
2002-11-06 08:08:55 +00:00
return (-1);
}
buf[i] = k;
}
2002-11-06 08:08:55 +00:00
return (i);
}
static int
2002-10-04 07:14:19 +00:00
mcd_send(struct mcd_softc *sc, int cmd,int nretrys)
{
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
int i,k=0;
1995-05-30 08:16:23 +00:00
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
/*MCD_TRACE("mcd_send: command = 0x%02x\n",cmd,0,0,0);*/
for (i=0; i<nretrys; i++) {
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, cmd);
if ((k=mcd_getstat(sc, 0)) != -1)
break;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
if (k == -2) {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "media changed\n");
2002-11-06 08:08:55 +00:00
return (-1);
}
if (i == nretrys) {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "mcd_send retry cnt exceeded\n");
2002-11-06 08:08:55 +00:00
return (-1);
}
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
/*MCD_TRACE("mcd_send: done\n",0,0,0,0);*/
2002-11-06 08:08:55 +00:00
return (0);
}
static void
hsg2msf(int hsg, bcd_t *msf)
{
hsg += 150;
F_msf(msf) = bin2bcd(hsg % 75);
hsg /= 75;
S_msf(msf) = bin2bcd(hsg % 60);
hsg /= 60;
M_msf(msf) = bin2bcd(hsg);
}
static int
msf2hsg(bcd_t *msf, int relative)
{
return (bcd2bin(M_msf(msf)) * 60 + bcd2bin(S_msf(msf))) * 75 +
bcd2bin(F_msf(msf)) - (!relative) * 150;
}
static int
2002-10-04 07:14:19 +00:00
mcd_volinfo(struct mcd_softc *sc)
{
/* Just return if we already have it */
2002-11-06 08:08:55 +00:00
if (sc->data.flags & MCDVOLINFO) return (0);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
/*MCD_TRACE("mcd_volinfo: enter\n",0,0,0,0);*/
/* send volume info command */
2002-10-04 07:14:19 +00:00
if (mcd_send(sc, MCD_CMDGETVOLINFO,MCD_RETRYS) < 0)
2002-11-06 08:08:55 +00:00
return (EIO);
/* get data */
2002-11-06 08:08:55 +00:00
if (mcd_get(sc, (char*) &sc->data.volinfo,sizeof(struct mcd_volinfo)) < 0) {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "mcd_volinfo: error read data\n");
2002-11-06 08:08:55 +00:00
return (EIO);
}
2002-11-06 08:08:55 +00:00
if (sc->data.volinfo.trk_low > 0 &&
sc->data.volinfo.trk_high >= sc->data.volinfo.trk_low
) {
2002-11-06 08:08:55 +00:00
sc->data.flags |= MCDVOLINFO; /* volinfo is OK */
return (0);
}
2002-11-06 08:08:55 +00:00
return (EINVAL);
}
/* state machine to process read requests
* initialize with MCD_S_BEGIN: calculate sizes, and read status
* MCD_S_WAITSTAT: wait for status reply, set mode
* MCD_S_WAITMODE: waits for status reply from set mode, set read command
* MCD_S_WAITREAD: wait for read ready, read data
*/
static void
mcd_timeout(void *arg)
{
2002-10-04 07:14:19 +00:00
struct mcd_softc *sc;
sc = (struct mcd_softc *)arg;
MCD_ASSERT_LOCKED(sc);
2002-10-04 07:14:19 +00:00
mcd_doread(sc, sc->ch_state, sc->ch_mbxsave);
}
static void
2002-10-04 07:14:19 +00:00
mcd_doread(struct mcd_softc *sc, int state, struct mcd_mbx *mbxin)
{
2002-10-04 07:14:19 +00:00
struct mcd_mbx *mbx;
struct bio *bp;
int rm, i, k;
struct mcd_read2 rbuf;
2002-10-04 07:14:19 +00:00
int blknum;
caddr_t addr;
MCD_ASSERT_LOCKED(sc);
2002-10-04 07:14:19 +00:00
mbx = (state!=MCD_S_BEGIN) ? sc->ch_mbxsave : mbxin;
bp = mbx->bp;
loop:
switch (state) {
case MCD_S_BEGIN:
2002-10-04 07:14:19 +00:00
mbx = sc->ch_mbxsave = mbxin;
case MCD_S_BEGIN1:
retry_status:
/* get status */
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDGETSTAT);
mbx->count = RDELAY_WAITSTAT;
2002-10-04 07:14:19 +00:00
sc->ch_state = MCD_S_WAITSTAT;
callout_reset(&sc->timer, hz/100, mcd_timeout, sc); /* XXX */
return;
case MCD_S_WAITSTAT:
2002-10-04 07:14:19 +00:00
sc->ch_state = MCD_S_WAITSTAT;
callout_stop(&sc->timer);
if (mbx->count-- >= 0) {
2002-10-04 07:14:19 +00:00
if (MCD_READ(sc, MCD_FLAGS) & MFL_STATUS_NOT_AVAIL) {
sc->ch_state = MCD_S_WAITSTAT;
callout_reset(&sc->timer, hz/100,
mcd_timeout, sc); /* XXX */
return;
}
2002-11-06 08:08:55 +00:00
sc->data.status = MCD_READ(sc, MCD_REG_STATUS) & 0xFF;
if (sc->data.status & MCD_ST_CMDCHECK)
goto retry_status;
2002-10-04 07:14:19 +00:00
if (mcd_setflags(sc) < 0)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
goto changed;
MCD_TRACE("got WAITSTAT delay=%d\n",
RDELAY_WAITSTAT-mbx->count);
/* reject, if audio active */
2002-11-06 08:08:55 +00:00
if (sc->data.status & MCDAUDIOBSY) {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "audio is active\n");
goto readerr;
}
retry_mode:
/* to check for raw/cooked mode */
2002-11-06 08:08:55 +00:00
if (sc->data.flags & MCDREADRAW) {
rm = MCD_MD_RAW;
mbx->sz = MCDRBLK;
} else {
rm = MCD_MD_COOKED;
2002-11-06 08:08:55 +00:00
mbx->sz = sc->data.blksize;
}
2002-11-06 08:08:55 +00:00
if (rm == sc->data.curr_mode)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
goto modedone;
mbx->count = RDELAY_WAITMODE;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-11-06 08:08:55 +00:00
sc->data.curr_mode = MCD_MD_UNKNOWN;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
mbx->mode = rm;
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDSETMODE);
MCD_WRITE(sc, MCD_REG_COMMAND, rm);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
sc->ch_state = MCD_S_WAITMODE;
callout_reset(&sc->timer, hz / 100, mcd_timeout, sc); /* XXX */
return;
} else {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "timeout getstatus\n");
goto readerr;
}
case MCD_S_WAITMODE:
2002-10-04 07:14:19 +00:00
sc->ch_state = MCD_S_WAITMODE;
callout_stop(&sc->timer);
if (mbx->count-- < 0) {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "timeout set mode\n");
goto readerr;
}
2002-10-04 07:14:19 +00:00
if (MCD_READ(sc, MCD_FLAGS) & MFL_STATUS_NOT_AVAIL) {
sc->ch_state = MCD_S_WAITMODE;
callout_reset(&sc->timer, hz / 100, mcd_timeout, sc);
return;
}
2002-11-06 08:08:55 +00:00
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;
}
2002-10-04 07:14:19 +00:00
if (mcd_setflags(sc) < 0)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
goto changed;
2002-11-06 08:08:55 +00:00
sc->data.curr_mode = mbx->mode;
MCD_TRACE("got WAITMODE delay=%d\n",
RDELAY_WAITMODE-mbx->count);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
modedone:
/* for first block */
mbx->nblk = (bp->bio_bcount + (mbx->sz-1)) / mbx->sz;
mbx->skip = 0;
nextblock:
blknum = bp->bio_offset / mbx->sz + mbx->skip/mbx->sz;
MCD_TRACE("mcd_doread: read blknum=%d for bp=%p\n",
blknum, bp);
/* build parameter block */
hsg2msf(blknum,rbuf.start_msf);
retry_read:
/* send the read command */
2002-11-06 08:08:55 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, sc->data.read_command);
2002-10-04 07:14:19 +00:00
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]);
MCD_WRITE(sc, MCD_REG_COMMAND, 0);
MCD_WRITE(sc, MCD_REG_COMMAND, 0);
MCD_WRITE(sc, MCD_REG_COMMAND, 1);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
/* Spin briefly (<= 2ms) to avoid missing next block */
for (i = 0; i < 20; i++) {
2002-10-04 07:14:19 +00:00
k = MCD_READ(sc, MCD_FLAGS);
if (!(k & MFL_DATA_NOT_AVAIL))
goto got_it;
DELAY(100);
}
mbx->count = RDELAY_WAITREAD;
2002-10-04 07:14:19 +00:00
sc->ch_state = MCD_S_WAITREAD;
callout_reset(&sc->timer, hz / 100, mcd_timeout, sc); /* XXX */
return;
case MCD_S_WAITREAD:
2002-10-04 07:14:19 +00:00
sc->ch_state = MCD_S_WAITREAD;
callout_stop(&sc->timer);
if (mbx->count-- > 0) {
2002-10-04 07:14:19 +00:00
k = MCD_READ(sc, MCD_FLAGS);
if (!(k & MFL_DATA_NOT_AVAIL)) { /* XXX */
MCD_TRACE("got data delay=%d\n",
RDELAY_WAITREAD-mbx->count);
got_it:
/* data is ready */
addr = bp->bio_data + mbx->skip;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_CTL2,0x04); /* XXX */
for (i=0; i<mbx->sz; i++)
2002-10-04 07:14:19 +00:00
*addr++ = MCD_READ(sc, MCD_REG_RDATA);
MCD_WRITE(sc, MCD_REG_CTL2,0x0c); /* XXX */
2002-10-04 07:14:19 +00:00
k = MCD_READ(sc, MCD_FLAGS);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
/* If we still have some junk, read it too */
if (!(k & MFL_DATA_NOT_AVAIL)) {
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_CTL2, 0x04); /* XXX */
(void)MCD_READ(sc, MCD_REG_RDATA);
(void)MCD_READ(sc, MCD_REG_RDATA);
MCD_WRITE(sc, MCD_REG_CTL2, 0x0c); /* XXX */
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
if (--mbx->nblk > 0) {
mbx->skip += mbx->sz;
goto nextblock;
}
/* return buffer */
bp->bio_resid = 0;
biodone(bp);
2002-11-06 08:08:55 +00:00
sc->data.flags &= ~(MCDMBXBSY|MCDREADRAW);
2002-10-04 07:14:19 +00:00
mcd_start(sc);
return;
}
if (!(k & MFL_STATUS_NOT_AVAIL)) {
2002-11-06 08:08:55 +00:00
sc->data.status = MCD_READ(sc, MCD_REG_STATUS) & 0xFF;
if (sc->data.status & MCD_ST_CMDCHECK)
goto retry_read;
2002-10-04 07:14:19 +00:00
if (mcd_setflags(sc) < 0)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
goto changed;
}
2002-10-04 07:14:19 +00:00
sc->ch_state = MCD_S_WAITREAD;
callout_reset(&sc->timer, hz / 100, mcd_timeout, sc); /* XXX */
return;
} else {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "timeout read data\n");
goto readerr;
}
}
readerr:
if (mbx->retry-- > 0) {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "retrying\n");
state = MCD_S_BEGIN1;
goto loop;
}
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
harderr:
/* invalidate the buffer */
bp->bio_flags |= BIO_ERROR;
bp->bio_resid = bp->bio_bcount;
biodone(bp);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-11-06 08:08:55 +00:00
sc->data.flags &= ~(MCDMBXBSY|MCDREADRAW);
2002-10-04 07:14:19 +00:00
mcd_start(sc);
return;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
changed:
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "media changed\n");
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
goto harderr;
#ifdef NOTDEF
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "unit timeout, resetting\n");
MCD_WRITE(sc, MCD_REG_RESET, MCD_CMDRESET);
DELAY(300000);
2002-10-04 07:14:19 +00:00
(void)mcd_getstat(sc, 1);
(void)mcd_getstat(sc, 1);
2002-11-06 08:08:55 +00:00
/*sc->data.status &= ~MCDDSKCHNG; */
sc->data.debug = 1; /* preventive set debug mode */
#endif
}
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
static int
2002-10-04 07:14:19 +00:00
mcd_lock_door(struct mcd_softc *sc, int lock)
{
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDLOCKDRV);
MCD_WRITE(sc, MCD_REG_COMMAND, lock);
if (mcd_getstat(sc, 0) == -1)
2002-11-06 08:08:55 +00:00
return (EIO);
return (0);
}
static int
2002-10-04 07:14:19 +00:00
mcd_close_tray(struct mcd_softc *sc)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
{
int retry, r;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
if (mcd_getstat(sc, 1) == -1)
2002-11-06 08:08:55 +00:00
return (EIO);
if (sc->data.status & MCDDOOROPEN) {
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDCLOSETRAY);
for (retry = 0; retry < CLOSE_TRAY_SECS * WAIT_FRAC; retry++) {
2002-10-04 07:14:19 +00:00
if (MCD_READ(sc, MCD_FLAGS) & MFL_STATUS_NOT_AVAIL)
(void) mtx_sleep(sc, &sc->mtx, PSOCK | PCATCH,
"mcdcls", hz/WAIT_FRAC);
else {
2002-10-04 07:14:19 +00:00
if ((r = mcd_getstat(sc, 0)) == -1)
2002-11-06 08:08:55 +00:00
return (EIO);
return (0);
}
}
2002-11-06 08:08:55 +00:00
return (ENXIO);
}
2002-11-06 08:08:55 +00:00
return (0);
}
static int
2002-10-04 07:14:19 +00:00
mcd_eject(struct mcd_softc *sc)
{
2002-10-04 07:14:19 +00:00
int r;
2002-10-04 07:14:19 +00:00
if (mcd_getstat(sc, 1) == -1) /* detect disk change too */
2002-11-06 08:08:55 +00:00
return (EIO);
if (sc->data.status & MCDDOOROPEN)
return (0);
2002-10-04 07:14:19 +00:00
if ((r = mcd_stop(sc)) == EIO)
2002-11-06 08:08:55 +00:00
return (r);
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDEJECTDISK);
if (mcd_getstat(sc, 0) == -1)
2002-11-06 08:08:55 +00:00
return (EIO);
return (0);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
1996-02-02 22:08:28 +00:00
static int
2002-10-04 07:14:19 +00:00
mcd_inject(struct mcd_softc *sc)
1996-02-02 22:08:28 +00:00
{
2002-10-04 07:14:19 +00:00
if (mcd_getstat(sc, 1) == -1) /* detect disk change too */
2002-11-06 08:08:55 +00:00
return (EIO);
if (sc->data.status & MCDDOOROPEN)
2002-10-04 07:14:19 +00:00
return mcd_close_tray(sc);
2002-11-06 08:08:55 +00:00
return (0);
1996-02-02 22:08:28 +00:00
}
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
static int
2002-10-04 07:14:19 +00:00
mcd_hard_reset(struct mcd_softc *sc)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
{
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_RESET, MCD_CMDRESET);
2002-11-06 08:08:55 +00:00
sc->data.curr_mode = MCD_MD_UNKNOWN;
sc->data.audio_status = CD_AS_AUDIO_INVALID;
return (0);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
static void
2002-10-04 07:14:19 +00:00
mcd_soft_reset(struct mcd_softc *sc)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
{
2002-11-06 08:08:55 +00:00
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;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
static int
2002-10-04 07:14:19 +00:00
mcd_setmode(struct mcd_softc *sc, int mode)
{
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
int retry, st;
2002-11-06 08:08:55 +00:00
if (sc->data.curr_mode == mode)
return (0);
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "setting mode to %d\n", mode);
for(retry=0; retry<MCD_RETRYS; retry++)
{
2002-11-06 08:08:55 +00:00
sc->data.curr_mode = MCD_MD_UNKNOWN;
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDSETMODE);
MCD_WRITE(sc, MCD_REG_COMMAND, mode);
if ((st = mcd_getstat(sc, 0)) >= 0) {
2002-11-06 08:08:55 +00:00
sc->data.curr_mode = mode;
return (0);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
if (st == -2) {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "media changed\n");
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
break;
}
}
2002-11-06 08:08:55 +00:00
return (-1);
}
static int
2002-10-04 07:14:19 +00:00
mcd_toc_header(struct mcd_softc *sc, struct ioc_toc_header *th)
{
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
int r;
2002-10-04 07:14:19 +00:00
if ((r = mcd_volinfo(sc)) != 0)
2002-11-06 08:08:55 +00:00
return (r);
2002-11-06 08:08:55 +00:00
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);
2002-11-06 08:08:55 +00:00
return (0);
}
static int
2002-10-04 07:14:19 +00:00
mcd_read_toc(struct mcd_softc *sc)
{
struct ioc_toc_header th;
struct mcd_qchninfo q;
int rc, trk, idx, retry;
/* Only read TOC if needed */
2002-11-06 08:08:55 +00:00
if (sc->data.flags & MCDTOC)
return (0);
2002-11-06 08:08:55 +00:00
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "reading toc header\n");
2002-10-04 07:14:19 +00:00
if ((rc = mcd_toc_header(sc, &th)) != 0)
2002-11-06 08:08:55 +00:00
return (rc);
2002-10-04 07:14:19 +00:00
if (mcd_send(sc, MCD_CMDSTOPAUDIO, MCD_RETRYS) < 0)
2002-11-06 08:08:55 +00:00
return (EIO);
2002-10-04 07:14:19 +00:00
if (mcd_setmode(sc, MCD_MD_TOC) != 0)
2002-11-06 08:08:55 +00:00
return (EIO);
2002-11-06 08:08:55 +00:00
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "get_toc reading qchannel info\n");
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
for(trk=th.starting_track; trk<=th.ending_track; trk++)
2002-11-06 08:08:55 +00:00
sc->data.toc[trk].idx_no = 0;
trk = th.ending_track - th.starting_track + 1;
for(retry=0; retry<600 && trk>0; retry++)
{
2002-10-04 07:14:19 +00:00
if (mcd_getqchan(sc, &q) < 0) break;
idx = bcd2bin(q.idx_no);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
if (idx>=th.starting_track && idx<=th.ending_track && q.trk_no==0) {
2002-11-06 08:08:55 +00:00
if (sc->data.toc[idx].idx_no == 0) {
sc->data.toc[idx] = q;
trk--;
}
}
}
2002-10-04 07:14:19 +00:00
if (mcd_setmode(sc, MCD_MD_COOKED) != 0)
2002-11-06 08:08:55 +00:00
return (EIO);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
if (trk != 0)
2002-11-06 08:08:55 +00:00
return (ENXIO);
/* add a fake last+1 */
idx = th.ending_track + 1;
2002-11-06 08:08:55 +00:00
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)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
{ int i;
for (i = th.starting_track; i <= idx; i++)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "trk %d idx %d pos %d %d %d\n",
i,
2002-11-06 08:08:55 +00:00
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]));
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
2002-11-06 08:08:55 +00:00
sc->data.flags |= MCDTOC;
2002-11-06 08:08:55 +00:00
return (0);
}
#if 0
static int
2002-10-04 07:14:19 +00:00
mcd_toc_entry(struct mcd_softc *sc, struct ioc_read_toc_single_entry *te)
{
struct ioc_toc_header th;
int rc, trk;
if (te->address_format != CD_MSF_FORMAT
&& te->address_format != CD_LBA_FORMAT)
2002-11-06 08:08:55 +00:00
return (EINVAL);
/* Copy the toc header */
2002-10-04 07:14:19 +00:00
if ((rc = mcd_toc_header(sc, &th)) != 0)
2002-11-06 08:08:55 +00:00
return (rc);
/* verify starting track */
trk = te->track;
if (trk == 0)
trk = th.starting_track;
else if (trk == MCD_LASTPLUS1)
trk = th.ending_track + 1;
else if (trk < th.starting_track || trk > th.ending_track + 1)
2002-11-06 08:08:55 +00:00
return (EINVAL);
/* Make sure we have a valid toc */
2002-10-04 07:14:19 +00:00
if ((rc=mcd_read_toc(sc)) != 0)
2002-11-06 08:08:55 +00:00
return (rc);
/* Copy the TOC data. */
2002-11-06 08:08:55 +00:00
if (sc->data.toc[trk].idx_no == 0)
return (EIO);
2002-11-06 08:08:55 +00:00
te->entry.control = sc->data.toc[trk].control;
te->entry.addr_type = sc->data.toc[trk].addr_type;
te->entry.track =
2002-11-06 08:08:55 +00:00
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;
2002-11-06 08:08:55 +00:00
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:
2002-11-06 08:08:55 +00:00
te->entry.addr.lba = htonl(msf2hsg(sc->data.toc[trk].hd_pos_msf, 0));
break;
}
2002-11-06 08:08:55 +00:00
return (0);
}
#endif
static int
2002-10-04 07:14:19 +00:00
mcd_toc_entrys(struct mcd_softc *sc, struct ioc_read_toc_entry *te)
{
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
struct cd_toc_entry entries[MCD_MAXTOCS];
struct ioc_toc_header th;
int rc, n, trk, len;
if ( te->data_len < sizeof(entries[0])
|| (te->data_len % sizeof(entries[0])) != 0
|| (te->address_format != CD_MSF_FORMAT
&& te->address_format != CD_LBA_FORMAT)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
)
2002-11-06 08:08:55 +00:00
return (EINVAL);
/* Copy the toc header */
2002-10-04 07:14:19 +00:00
if ((rc = mcd_toc_header(sc, &th)) != 0)
2002-11-06 08:08:55 +00:00
return (rc);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
/* verify starting track */
trk = te->starting_track;
if (trk == 0)
trk = th.starting_track;
else if (trk == MCD_LASTPLUS1)
trk = th.ending_track + 1;
else if (trk < th.starting_track || trk > th.ending_track + 1)
2002-11-06 08:08:55 +00:00
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))
2002-11-06 08:08:55 +00:00
return (EINVAL);
/* Make sure we have a valid toc */
2002-10-04 07:14:19 +00:00
if ((rc=mcd_read_toc(sc)) != 0)
2002-11-06 08:08:55 +00:00
return (rc);
/* Copy the TOC data. */
for (n = 0; len > 0 && trk <= th.ending_track + 1; trk++) {
2002-11-06 08:08:55 +00:00
if (sc->data.toc[trk].idx_no == 0)
continue;
2002-11-06 08:08:55 +00:00
entries[n].control = sc->data.toc[trk].control;
entries[n].addr_type = sc->data.toc[trk].addr_type;
entries[n].track =
2002-11-06 08:08:55 +00:00
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;
2002-11-06 08:08:55 +00:00
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:
2002-11-06 08:08:55 +00:00
entries[n].addr.lba = htonl(msf2hsg(sc->data.toc[trk].hd_pos_msf, 0));
break;
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
len -= sizeof(struct cd_toc_entry);
n++;
}
/* copy the data back */
MCD_UNLOCK(sc);
return copyout(entries, te->data, n * sizeof(struct cd_toc_entry));
}
static int
2002-10-04 07:14:19 +00:00
mcd_stop(struct mcd_softc *sc)
{
/* Verify current status */
2002-11-06 08:08:55 +00:00
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)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev,
"stop attempted when not playing, audio status %d\n",
2002-11-06 08:08:55 +00:00
sc->data.audio_status);
return (EINVAL);
}
2002-11-06 08:08:55 +00:00
if (sc->data.audio_status == CD_AS_PLAY_IN_PROGRESS)
2002-10-04 07:14:19 +00:00
if (mcd_send(sc, MCD_CMDSTOPAUDIO, MCD_RETRYS) < 0)
2002-11-06 08:08:55 +00:00
return (EIO);
sc->data.audio_status = CD_AS_PLAY_COMPLETED;
return (0);
}
static int
2002-10-04 07:14:19 +00:00
mcd_getqchan(struct mcd_softc *sc, struct mcd_qchninfo *q)
{
2002-10-04 07:14:19 +00:00
if (mcd_send(sc, MCD_CMDGETQCHN, MCD_RETRYS) < 0)
2002-11-06 08:08:55 +00:00
return (-1);
2002-10-04 07:14:19 +00:00
if (mcd_get(sc, (char *) q, sizeof(struct mcd_qchninfo)) < 0)
2002-11-06 08:08:55 +00:00
return (-1);
if (sc->data.debug) {
2002-10-04 07:14:19 +00:00
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,
bcd2bin(q->trk_no),
bcd2bin(q->idx_no),
bcd2bin(q->trk_size_msf[0]),
bcd2bin(q->trk_size_msf[1]),
bcd2bin(q->trk_size_msf[2]),
bcd2bin(q->hd_pos_msf[0]),
bcd2bin(q->hd_pos_msf[1]),
bcd2bin(q->hd_pos_msf[2]));
}
2002-11-06 08:08:55 +00:00
return (0);
}
static int
mcd_subchan(struct mcd_softc *sc, struct ioc_read_subchannel *sch, int nocopyout)
{
struct mcd_qchninfo q;
struct cd_sub_channel_info data;
int lba;
2002-11-06 08:08:55 +00:00
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "subchan af=%d, df=%d\n",
sch->address_format,
sch->data_format);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
if (sch->address_format != CD_MSF_FORMAT &&
sch->address_format != CD_LBA_FORMAT)
2002-11-06 08:08:55 +00:00
return (EINVAL);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
if (sch->data_format != CD_CURRENT_POSITION &&
sch->data_format != CD_MEDIA_CATALOG)
2002-11-06 08:08:55 +00:00
return (EINVAL);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
if (mcd_setmode(sc, MCD_MD_COOKED) != 0)
2002-11-06 08:08:55 +00:00
return (EIO);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
if (mcd_getqchan(sc, &q) < 0)
2002-11-06 08:08:55 +00:00
return (EIO);
2002-11-06 08:08:55 +00:00
data.header.audio_status = sc->data.audio_status;
2002-10-04 07:14:19 +00:00
data.what.position.data_format = sch->data_format;
2002-10-04 07:14:19 +00:00
switch (sch->data_format) {
case CD_MEDIA_CATALOG:
data.what.media_catalog.mc_valid = 1;
data.what.media_catalog.mc_number[0] = '\0';
break;
case CD_CURRENT_POSITION:
data.what.position.control = q.control;
data.what.position.addr_type = q.addr_type;
data.what.position.track_number = bcd2bin(q.trk_no);
data.what.position.index_number = bcd2bin(q.idx_no);
2002-10-04 07:14:19 +00:00
switch (sch->address_format) {
case CD_MSF_FORMAT:
data.what.position.reladdr.msf.unused = 0;
data.what.position.reladdr.msf.minute = bcd2bin(q.trk_size_msf[0]);
data.what.position.reladdr.msf.second = bcd2bin(q.trk_size_msf[1]);
data.what.position.reladdr.msf.frame = bcd2bin(q.trk_size_msf[2]);
data.what.position.absaddr.msf.unused = 0;
data.what.position.absaddr.msf.minute = bcd2bin(q.hd_pos_msf[0]);
data.what.position.absaddr.msf.second = bcd2bin(q.hd_pos_msf[1]);
data.what.position.absaddr.msf.frame = bcd2bin(q.hd_pos_msf[2]);
break;
case CD_LBA_FORMAT:
lba = msf2hsg(q.trk_size_msf, 1);
/*
* Pre-gap has index number of 0, and decreasing MSF
* address. Must be converted to negative LBA, per
* SCSI spec.
*/
if (data.what.position.index_number == 0)
lba = -lba;
data.what.position.reladdr.lba = htonl(lba);
data.what.position.absaddr.lba = htonl(msf2hsg(q.hd_pos_msf, 0));
break;
}
break;
}
MCD_UNLOCK(sc);
if (nocopyout == 0)
return copyout(&data, sch->data, min(sizeof(struct cd_sub_channel_info), sch->data_len));
bcopy(&data, sch->data, min(sizeof(struct cd_sub_channel_info), sch->data_len));
return (0);
}
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
static int
2002-10-04 07:14:19 +00:00
mcd_playmsf(struct mcd_softc *sc, struct ioc_play_msf *p)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
{
struct mcd_read2 pb;
2002-11-06 08:08:55 +00:00
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
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);
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) >
2002-11-06 08:08:55 +00:00
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);
pb.start_msf[2] = bin2bcd(p->start_f);
pb.end_msf[0] = bin2bcd(p->end_m);
pb.end_msf[1] = bin2bcd(p->end_s);
pb.end_msf[2] = bin2bcd(p->end_f);
2002-10-04 07:14:19 +00:00
if (mcd_setmode(sc, MCD_MD_COOKED) != 0)
2002-11-06 08:08:55 +00:00
return (EIO);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
return mcd_play(sc, &pb);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
}
static int
2002-10-04 07:14:19 +00:00
mcd_playtracks(struct mcd_softc *sc, struct ioc_play_track *pt)
{
struct mcd_read2 pb;
int a = pt->start_track;
int z = pt->end_track;
int rc, i;
2002-10-04 07:14:19 +00:00
if ((rc = mcd_read_toc(sc)) != 0)
2002-11-06 08:08:55 +00:00
return (rc);
2002-11-06 08:08:55 +00:00
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "playtracks from %d:%d to %d:%d\n",
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
a, pt->start_index, z, pt->end_index);
2002-11-06 08:08:55 +00:00
if ( a < bcd2bin(sc->data.volinfo.trk_low)
|| a > bcd2bin(sc->data.volinfo.trk_high)
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
|| a > z
2002-11-06 08:08:55 +00:00
|| z < bcd2bin(sc->data.volinfo.trk_low)
|| z > bcd2bin(sc->data.volinfo.trk_high))
return (EINVAL);
for (i = 0; i < 3; i++) {
2002-11-06 08:08:55 +00:00
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];
}
2002-10-04 07:14:19 +00:00
if (mcd_setmode(sc, MCD_MD_COOKED) != 0)
2002-11-06 08:08:55 +00:00
return (EIO);
2002-10-04 07:14:19 +00:00
return mcd_play(sc, &pb);
}
static int
2002-10-04 07:14:19 +00:00
mcd_playblocks(struct mcd_softc *sc, struct ioc_play_blocks *p)
{
struct mcd_read2 pb;
2002-11-06 08:08:55 +00:00
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "playblocks: blkno %d length %d\n",
p->blk, p->len);
2002-11-06 08:08:55 +00:00
if (p->blk > sc->data.disksize || p->len > sc->data.disksize ||
p->blk < 0 || p->len < 0 ||
2002-11-06 08:08:55 +00:00
(p->blk + p->len) > sc->data.disksize)
return (EINVAL);
hsg2msf(p->blk, pb.start_msf);
hsg2msf(p->blk + p->len, pb.end_msf);
2002-10-04 07:14:19 +00:00
if (mcd_setmode(sc, MCD_MD_COOKED) != 0)
2002-11-06 08:08:55 +00:00
return (EIO);
2002-10-04 07:14:19 +00:00
return mcd_play(sc, &pb);
}
static int
2002-10-04 07:14:19 +00:00
mcd_play(struct mcd_softc *sc, struct mcd_read2 *pb)
{
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
int retry, st = -1, status;
2002-11-06 08:08:55 +00:00
sc->data.lastpb = *pb;
for(retry=0; retry<MCD_RETRYS; retry++) {
critical_enter();
2002-10-04 07:14:19 +00:00
MCD_WRITE(sc, MCD_REG_COMMAND, MCD_CMDSINGLESPEEDREAD);
MCD_WRITE(sc, MCD_REG_COMMAND, pb->start_msf[0]);
MCD_WRITE(sc, MCD_REG_COMMAND, pb->start_msf[1]);
MCD_WRITE(sc, MCD_REG_COMMAND, pb->start_msf[2]);
MCD_WRITE(sc, MCD_REG_COMMAND, pb->end_msf[0]);
MCD_WRITE(sc, MCD_REG_COMMAND, pb->end_msf[1]);
MCD_WRITE(sc, MCD_REG_COMMAND, pb->end_msf[2]);
critical_exit();
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
2002-10-04 07:14:19 +00:00
status=mcd_getstat(sc, 0);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
if (status == -1)
continue;
else if (status != -2)
st = 0;
break;
}
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
if (status == -2) {
2002-10-04 07:14:19 +00:00
device_printf(sc->dev, "media changed\n");
2002-11-06 08:08:55 +00:00
return (ENXIO);
}
2002-11-06 08:08:55 +00:00
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev,
"mcd_play retry=%d, status=0x%02x\n", retry, status);
Newly implemented ioctls list: DIOCGDINFO, DIOCGPART, DIOCWDINFO, DIOCSDINFO, CDIOCPLAYMSF, CDIOCRESET, CDIOCEJECT. CDIOCPLAYBLOCKS removed (old implementation completely wrong and I don't know how to implement it correctly). All routines now detects media change correctly. DELAY_GETREPLAY increased for long time access from first track to last. mcd_waitrdy() now use MIN_DELAY=15 as minimal delay which independs of machine speed. mcd_doread() now uses real status (old code uses obsoleted soft copy of it). clear XBSY on error in mcd_doread() mcd_statrt(): add missing splx(s), cause dead hang with unmatched slpbio() optimize mcd_doread(), don't set CD mode each time, keep soft copy of mode. call getdisklabel() _after_ mcdsize() for proper sizes mcdopen(): old code forget to set MCDREADRAW in flags when open RAW partition, doread check it for setting RAW CD mode. Do nothing on stray interrupt (which sometimes occurse, because driver read data block too slow, DOS driver use 'insb' here). Old stray code cause timeouts. Read toc entries code rewritten to return many requested entries (as supposed) instead of one entry with incorrect structure. CMDREAD2 requests covered with disable_intr()/enable_intr() (from DOS driver) Read junk code added after read block code in doread (from DOS driver) mcd_read_toc() code fixed to read all needed entries, old code cause some audio tracks is not played. mcd_playtracks() code fixed to proper check valid track range. New binary read modes implemented (from DOS driver).
1994-09-03 16:48:13 +00:00
if (st < 0)
2002-11-06 08:08:55 +00:00
return (ENXIO);
sc->data.audio_status = CD_AS_PLAY_IN_PROGRESS;
return (0);
}
static int
2002-10-04 07:14:19 +00:00
mcd_pause(struct mcd_softc *sc)
{
struct mcd_qchninfo q;
int rc;
/* Verify current status */
2002-11-06 08:08:55 +00:00
if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS &&
sc->data.audio_status != CD_AS_PLAY_PAUSED) {
if (sc->data.debug)
2002-10-04 07:14:19 +00:00
device_printf(sc->dev,
"pause attempted when not playing, audio status %d\n",
2002-11-06 08:08:55 +00:00
sc->data.audio_status);
return (EINVAL);
}
/* Get the current position */
2002-10-04 07:14:19 +00:00
if (mcd_getqchan(sc, &q) < 0)
2002-11-06 08:08:55 +00:00
return (EIO);
/* Copy it into lastpb */
2002-11-06 08:08:55 +00:00
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 */
2002-10-04 07:14:19 +00:00
if ((rc=mcd_stop(sc)) != 0)
2002-11-06 08:08:55 +00:00
return (rc);
/* Set the proper status and exit */
2002-11-06 08:08:55 +00:00
sc->data.audio_status = CD_AS_PLAY_PAUSED;
return (0);
}
static int
2002-10-04 07:14:19 +00:00
mcd_resume(struct mcd_softc *sc)
{
2002-11-06 08:08:55 +00:00
if (sc->data.audio_status != CD_AS_PLAY_PAUSED)
return (EINVAL);
return mcd_play(sc, &sc->data.lastpb);
}