1995-04-01 14:27:56 +04:00
|
|
|
/* $NetBSD: mcd.c,v 1.35 1995/04/01 10:27:56 mycroft Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
/*
|
1995-03-27 19:45:20 +04:00
|
|
|
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum. 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 product includes software developed by Charles M. Hannum.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
1993-11-04 12:12:30 +03:00
|
|
|
* Copyright 1993 by Holger Veit (data part)
|
|
|
|
* Copyright 1993 by Brian Moore (audio part)
|
|
|
|
* 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.
|
|
|
|
*/
|
1993-11-17 15:22:50 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/*static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";*/
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-02-21 18:23:11 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/cdio.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/disklabel.h>
|
1994-02-21 18:23:11 +03:00
|
|
|
#include <sys/device.h>
|
1994-10-29 02:39:59 +03:00
|
|
|
#include <sys/disk.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#include <machine/cpu.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <machine/pio.h>
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
#include <i386/isa/isavar.h>
|
1995-01-29 10:36:54 +03:00
|
|
|
#include <dev/isa/mcdreg.h>
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifndef MCDDEBUG
|
1993-11-04 12:12:30 +03:00
|
|
|
#define MCD_TRACE(fmt,a,b,c,d)
|
|
|
|
#else
|
1994-02-21 18:23:11 +03:00
|
|
|
#define MCD_TRACE(fmt,a,b,c,d) {if (sc->debug) {printf("%s: st=%02x: ", sc->sc_dev.dv_xname, sc->status); printf(fmt,a,b,c,d);}}
|
1993-11-04 12:12:30 +03:00
|
|
|
#endif
|
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
#define MCDPART(dev) DISKPART(dev)
|
|
|
|
#define MCDUNIT(dev) DISKUNIT(dev)
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
/* toc */
|
|
|
|
#define MCD_MAXTOCS 104 /* from the Linux driver */
|
|
|
|
|
|
|
|
struct mcd_mbx {
|
1995-03-27 19:45:20 +04:00
|
|
|
int retry, count;
|
|
|
|
struct buf *bp;
|
|
|
|
daddr_t blkno;
|
|
|
|
int nblk;
|
1993-11-04 12:12:30 +03:00
|
|
|
int sz;
|
|
|
|
u_long skip;
|
1995-03-27 19:45:20 +04:00
|
|
|
int state;
|
|
|
|
#define MCD_S_IDLE 0
|
|
|
|
#define MCD_S_BEGIN 1
|
1995-03-27 20:48:45 +04:00
|
|
|
#define MCD_S_WAITMODE 2
|
|
|
|
#define MCD_S_WAITREAD 3
|
1995-03-27 19:45:20 +04:00
|
|
|
int mode;
|
1993-11-04 12:12:30 +03:00
|
|
|
};
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc {
|
|
|
|
struct device sc_dev;
|
1994-10-29 02:39:59 +03:00
|
|
|
struct dkdevice sc_dk;
|
1994-04-07 10:48:19 +04:00
|
|
|
struct intrhand sc_ih;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase;
|
1995-03-27 19:45:20 +04:00
|
|
|
int irq, drq;
|
|
|
|
|
|
|
|
char *type;
|
|
|
|
int flags;
|
|
|
|
#define MCDF_LOCKED 0x01
|
|
|
|
#define MCDF_WANTED 0x02
|
|
|
|
#define MCDF_WLABEL 0x04 /* label is writable */
|
|
|
|
#define MCDF_LABELLING 0x08 /* writing label */
|
|
|
|
#define MCDF_LOADED 0x10 /* parameters loaded */
|
1993-11-04 12:12:30 +03:00
|
|
|
short status;
|
1995-03-27 19:45:20 +04:00
|
|
|
short audio_status;
|
1993-11-04 12:12:30 +03:00
|
|
|
int blksize;
|
|
|
|
u_long disksize;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_volinfo volinfo;
|
1995-03-27 19:45:20 +04:00
|
|
|
union mcd_qchninfo toc[MCD_MAXTOCS];
|
|
|
|
struct mcd_command lastpb;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_mbx mbx;
|
1995-03-27 19:45:20 +04:00
|
|
|
int lastmode;
|
|
|
|
#define MCD_MD_UNKNOWN -1
|
|
|
|
int lastupc;
|
|
|
|
#define MCD_UPC_UNKNOWN -1
|
|
|
|
int debug;
|
|
|
|
struct buf buf_queue;
|
1994-03-29 08:35:37 +04:00
|
|
|
};
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
/* prototypes */
|
1994-10-29 02:39:59 +03:00
|
|
|
int mcdopen __P((dev_t, int, int, struct proc *));
|
|
|
|
int mcdclose __P((dev_t, int, int));
|
1994-10-31 00:43:03 +03:00
|
|
|
int mcdioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
|
1994-02-21 18:23:11 +03:00
|
|
|
int mcdsize __P((dev_t));
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
static int bcd2bin __P((bcd_t));
|
|
|
|
static bcd_t bin2bcd __P((int));
|
|
|
|
static void hsg2msf __P((int, bcd_t *));
|
|
|
|
static daddr_t msf2hsg __P((bcd_t *, int));
|
|
|
|
|
|
|
|
int mcd_playtracks __P((struct mcd_softc *, struct ioc_play_track *));
|
|
|
|
int mcd_playmsf __P((struct mcd_softc *, struct ioc_play_msf *));
|
|
|
|
int mcd_playblocks __P((struct mcd_softc *, struct ioc_play_blocks *));
|
|
|
|
int mcd_stop __P((struct mcd_softc *));
|
|
|
|
int mcd_eject __P((struct mcd_softc *));
|
|
|
|
int mcd_read_subchannel __P((struct mcd_softc *, struct ioc_read_subchannel *));
|
|
|
|
int mcd_pause __P((struct mcd_softc *));
|
|
|
|
int mcd_resume __P((struct mcd_softc *));
|
|
|
|
int mcd_toc_header __P((struct mcd_softc *, struct ioc_toc_header *));
|
|
|
|
int mcd_toc_entries __P((struct mcd_softc *, struct ioc_read_toc_entry *));
|
|
|
|
|
|
|
|
int mcd_getreply __P((struct mcd_softc *));
|
|
|
|
int mcd_getstat __P((struct mcd_softc *));
|
|
|
|
int mcd_getresult __P((struct mcd_softc *, struct mcd_result *));
|
1994-02-21 18:23:11 +03:00
|
|
|
void mcd_setflags __P((struct mcd_softc *));
|
|
|
|
int mcd_get __P((struct mcd_softc *, char *, int));
|
1995-03-27 19:45:20 +04:00
|
|
|
int mcd_send __P((struct mcd_softc *, struct mcd_mbox *, int));
|
1995-03-27 20:04:07 +04:00
|
|
|
int mcdintr __P((void *));
|
1995-03-27 19:45:20 +04:00
|
|
|
void mcd_soft_reset __P((struct mcd_softc *));
|
|
|
|
int mcd_hard_reset __P((struct mcd_softc *));
|
1994-02-21 18:23:11 +03:00
|
|
|
int mcd_setmode __P((struct mcd_softc *, int));
|
1995-03-27 19:45:20 +04:00
|
|
|
int mcd_setupc __P((struct mcd_softc *, int));
|
1994-02-21 18:23:11 +03:00
|
|
|
int mcd_read_toc __P((struct mcd_softc *));
|
1995-03-27 19:45:20 +04:00
|
|
|
int mcd_getqchan __P((struct mcd_softc *, union mcd_qchninfo *, int));
|
|
|
|
int mcd_setlock __P((struct mcd_softc *, int));
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1994-11-04 01:55:58 +03:00
|
|
|
int mcdprobe __P((struct device *, void *, void *));
|
|
|
|
void mcdattach __P((struct device *, struct device *, void *));
|
1994-03-29 08:35:37 +04:00
|
|
|
|
|
|
|
struct cfdriver mcdcd = {
|
|
|
|
NULL, "mcd", mcdprobe, mcdattach, DV_DISK, sizeof(struct mcd_softc)
|
1994-02-21 18:23:11 +03:00
|
|
|
};
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
void mcdgetdisklabel __P((struct mcd_softc *));
|
|
|
|
int mcd_get_parms __P((struct mcd_softc *));
|
|
|
|
void mcdstrategy __P((struct buf *));
|
|
|
|
void mcdstart __P((struct mcd_softc *));
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
struct dkdriver mcddkdriver = { mcdstrategy };
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
#define MCD_RETRIES 3
|
|
|
|
#define MCD_RDRETRIES 3
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
/* several delays */
|
|
|
|
#define RDELAY_WAITMODE 300
|
|
|
|
#define RDELAY_WAITREAD 800
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
#define DELAY_GRANULARITY 25 /* 25us */
|
|
|
|
#define DELAY_GETREPLY 100000 /* 100000 * 25us */
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
void
|
|
|
|
mcdattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
printf(": model %s\n", sc->type != 0 ? sc->type : "unknown");
|
|
|
|
|
1995-03-27 22:08:34 +04:00
|
|
|
(void) mcd_setlock(sc, MCD_LK_UNLOCK);
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDCONFIGDRIVE;
|
|
|
|
mbx.cmd.length = sizeof(mbx.cmd.data.config) - 1;
|
|
|
|
mbx.cmd.data.config.subcommand = MCD_CF_IRQENABLE;
|
|
|
|
mbx.cmd.data.config.data1 = 0x01;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
(void) mcd_send(sc, &mbx, 0);
|
|
|
|
|
|
|
|
mcd_soft_reset(sc);
|
1994-04-08 22:57:24 +04:00
|
|
|
|
1994-11-04 01:55:58 +03:00
|
|
|
sc->sc_dk.dk_driver = &mcddkdriver;
|
1994-04-07 10:48:19 +04:00
|
|
|
|
|
|
|
sc->sc_ih.ih_fun = mcdintr;
|
|
|
|
sc->sc_ih.ih_arg = sc;
|
|
|
|
sc->sc_ih.ih_level = IPL_BIO;
|
1995-01-03 04:30:14 +03:00
|
|
|
intr_establish(ia->ia_irq, IST_EDGE, &sc->sc_ih);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
/*
|
|
|
|
* Wait interruptibly for an exclusive lock.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* Several drivers do this; it should be abstracted and made MP-safe.
|
|
|
|
*/
|
1995-03-27 19:45:20 +04:00
|
|
|
int
|
1995-04-01 12:45:33 +04:00
|
|
|
mcdlock(sc)
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_softc *sc;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
while ((sc->flags & MCDF_LOCKED) != 0) {
|
|
|
|
sc->flags |= MCDF_WANTED;
|
|
|
|
if ((error = tsleep(sc, PRIBIO | PCATCH, "mcdlck", 0)) != 0)
|
|
|
|
return error;
|
|
|
|
}
|
1995-04-01 12:45:33 +04:00
|
|
|
sc->flags |= MCDF_LOCKED;
|
1995-03-27 19:45:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
/*
|
|
|
|
* Unlock and wake up any waiters.
|
|
|
|
*/
|
1995-03-27 19:45:20 +04:00
|
|
|
void
|
|
|
|
mcdunlock(sc)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
sc->flags &= ~MCDF_LOCKED;
|
|
|
|
if ((sc->flags & MCDF_WANTED) != 0) {
|
|
|
|
sc->flags &= ~MCDF_WANTED;
|
|
|
|
wakeup(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1994-10-29 02:39:59 +03:00
|
|
|
mcdopen(dev, flag, fmt, p)
|
1994-02-21 18:23:11 +03:00
|
|
|
dev_t dev;
|
1994-10-29 02:39:59 +03:00
|
|
|
int flag, fmt;
|
|
|
|
struct proc *p;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
int error;
|
1994-10-29 02:39:59 +03:00
|
|
|
int unit, part;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
unit = MCDUNIT(dev);
|
1994-03-29 08:35:37 +04:00
|
|
|
if (unit >= mcdcd.cd_ndevs)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
1994-03-29 08:35:37 +04:00
|
|
|
sc = mcdcd.cd_devs[unit];
|
|
|
|
if (!sc)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
if (error = mcdlock(sc))
|
1995-03-27 19:45:20 +04:00
|
|
|
return error;
|
|
|
|
|
|
|
|
if (sc->sc_dk.dk_openmask != 0) {
|
|
|
|
/*
|
|
|
|
* If any partition is open, but the disk has been invalidated,
|
|
|
|
* disallow further opens.
|
|
|
|
*/
|
1995-04-01 14:27:56 +04:00
|
|
|
if ((sc->flags & MCDF_LOADED) == 0) {
|
|
|
|
error = EIO;
|
|
|
|
goto bad3;
|
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Lock the drawer. This will also notice any pending disk
|
|
|
|
* change or door open indicator and clear the MCDF_LOADED bit
|
|
|
|
* if necessary.
|
|
|
|
*/
|
|
|
|
(void) mcd_setlock(sc, MCD_LK_LOCK);
|
|
|
|
|
|
|
|
if ((sc->flags & MCDF_LOADED) == 0) {
|
|
|
|
/* Partially reset the state. */
|
|
|
|
sc->lastmode = MCD_MD_UNKNOWN;
|
|
|
|
sc->lastupc = MCD_UPC_UNKNOWN;
|
|
|
|
|
|
|
|
sc->flags |= MCDF_LOADED;
|
|
|
|
|
|
|
|
/* Set the mode, causing the disk to spin up. */
|
|
|
|
if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
|
|
|
|
goto bad2;
|
|
|
|
|
|
|
|
/* Load the physical device parameters. */
|
|
|
|
if (mcd_get_parms(sc) != 0) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad2;
|
|
|
|
}
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-04-01 12:40:11 +04:00
|
|
|
/* Read the table of contents. */
|
|
|
|
if ((error = mcd_read_toc(sc)) != 0)
|
|
|
|
goto bad2;
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Fabricate a disk label. */
|
|
|
|
mcdgetdisklabel(sc);
|
|
|
|
}
|
1994-10-29 02:39:59 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("open: partition=%d disksize=%d blksize=%d\n", part,
|
|
|
|
sc->disksize, sc->blksize, 0);
|
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
part = MCDPART(dev);
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Check that the partition exists. */
|
1994-02-21 18:23:11 +03:00
|
|
|
if (part != RAW_PART &&
|
1994-10-29 02:39:59 +03:00
|
|
|
(part >= sc->sc_dk.dk_label.d_npartitions ||
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
/* Insure only one open at a time. */
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
sc->sc_dk.dk_copenmask |= (1 << part);
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
sc->sc_dk.dk_bopenmask |= (1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_dk.dk_openmask = sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
|
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
mcdunlock(sc);
|
1994-02-21 18:23:11 +03:00
|
|
|
return 0;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
bad2:
|
|
|
|
sc->flags &= ~MCDF_LOADED;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
if (sc->sc_dk.dk_openmask == 0) {
|
|
|
|
#if 0
|
|
|
|
(void) mcd_setmode(sc, MCD_MD_SLEEP);
|
|
|
|
#endif
|
|
|
|
(void) mcd_setlock(sc, MCD_LK_UNLOCK);
|
|
|
|
}
|
|
|
|
|
1995-04-01 14:27:56 +04:00
|
|
|
bad3:
|
1995-04-01 12:45:33 +04:00
|
|
|
mcdunlock(sc);
|
1995-03-27 19:45:20 +04:00
|
|
|
return error;
|
1994-02-21 18:23:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-10-29 02:39:59 +03:00
|
|
|
mcdclose(dev, flag, fmt)
|
1994-02-21 18:23:11 +03:00
|
|
|
dev_t dev;
|
1994-10-29 02:39:59 +03:00
|
|
|
int flag, fmt;
|
1994-02-21 18:23:11 +03:00
|
|
|
{
|
1994-10-29 02:39:59 +03:00
|
|
|
struct mcd_softc *sc = mcdcd.cd_devs[MCDUNIT(dev)];
|
|
|
|
int part = MCDPART(dev);
|
1995-04-01 12:45:33 +04:00
|
|
|
int error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
MCD_TRACE("close: partition=%d\n", part, 0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
if (error = mcdlock(sc))
|
|
|
|
return error;
|
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
sc->sc_dk.dk_copenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
sc->sc_dk.dk_bopenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_dk.dk_openmask = sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->sc_dk.dk_openmask == 0) {
|
1995-04-01 12:45:33 +04:00
|
|
|
/* XXXX Must wait for I/O to complete! */
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
(void) mcd_setmode(sc, MCD_MD_SLEEP);
|
|
|
|
#endif
|
|
|
|
(void) mcd_setlock(sc, MCD_LK_UNLOCK);
|
|
|
|
}
|
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
mcdunlock(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
void
|
|
|
|
mcdstrategy(bp)
|
|
|
|
struct buf *bp;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = mcdcd.cd_devs[MCDUNIT(bp->b_dev)];
|
1993-11-04 12:12:30 +03:00
|
|
|
int s;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Test validity. */
|
|
|
|
MCD_TRACE("strategy: buf=0x%lx blkno=%ld bcount=%ld\n", bp,
|
|
|
|
bp->b_blkno, bp->b_bcount, 0);
|
1995-03-27 19:45:20 +04:00
|
|
|
if (bp->b_blkno < 0 ||
|
|
|
|
(bp->b_bcount % sc->blksize) != 0) {
|
|
|
|
printf("%s: strategy: blkno = %d bcount = %d\n",
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->sc_dev.dv_xname, bp->b_blkno, bp->b_bcount);
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* If device invalidated (e.g. media change, door open), error. */
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((sc->flags & MCDF_LOADED) == 0) {
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("strategy: drive not valid\n", 0, 0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* No data to read. */
|
1993-11-04 12:12:30 +03:00
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/*
|
|
|
|
* Do bounds checking, adjust transfer. if error, process.
|
|
|
|
* If end of partition, just return.
|
|
|
|
*/
|
|
|
|
if (bounds_check_with_label(bp, &sc->sc_dk.dk_label,
|
|
|
|
(sc->flags & (MCDF_WLABEL|MCDF_LABELLING)) != 0) <= 0)
|
|
|
|
goto done;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Queue it. */
|
1993-11-04 12:12:30 +03:00
|
|
|
s = splbio();
|
1995-03-27 19:45:20 +04:00
|
|
|
disksort(&sc->buf_queue, bp);
|
1993-11-04 12:12:30 +03:00
|
|
|
splx(s);
|
1995-03-27 19:45:20 +04:00
|
|
|
if (!sc->buf_queue.b_active)
|
|
|
|
mcdstart(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
void
|
|
|
|
mcdstart(sc)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct buf *bp, *dp = &sc->buf_queue;
|
1994-10-29 02:39:59 +03:00
|
|
|
int s;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
loop:
|
|
|
|
s = splbio();
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
bp = dp->b_actf;
|
|
|
|
if (bp == NULL) {
|
|
|
|
/* Nothing to do. */
|
|
|
|
dp->b_active = 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
/* Block found to process; dequeue. */
|
|
|
|
MCD_TRACE("start: found block bp=0x%x\n", bp, 0, 0, 0);
|
1995-03-27 19:45:20 +04:00
|
|
|
dp->b_actf = bp->b_actf;
|
1994-10-29 02:39:59 +03:00
|
|
|
splx(s);
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Changed media? */
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((sc->flags & MCDF_LOADED) == 0) {
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("start: drive not valid\n", 0, 0, 0, 0);
|
1994-10-29 02:39:59 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
goto loop;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
dp->b_active = 1;
|
|
|
|
|
|
|
|
sc->mbx.retry = MCD_RDRETRIES;
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->mbx.bp = bp;
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->mbx.blkno = bp->b_blkno / (sc->blksize / DEV_BSIZE);
|
|
|
|
if (MCDPART(bp->b_dev) != RAW_PART) {
|
|
|
|
struct partition *p;
|
|
|
|
p = &sc->sc_dk.dk_label.d_partitions[MCDPART(bp->b_dev)];
|
|
|
|
sc->mbx.blkno += p->p_offset;
|
|
|
|
}
|
|
|
|
sc->mbx.nblk = bp->b_bcount / sc->blksize;
|
|
|
|
sc->mbx.sz = sc->blksize;
|
|
|
|
sc->mbx.skip = 0;
|
1994-05-05 12:26:13 +04:00
|
|
|
sc->mbx.state = MCD_S_BEGIN;
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->mbx.mode = MCD_MD_COOKED;
|
|
|
|
|
|
|
|
s = splbio();
|
1995-03-27 20:04:07 +04:00
|
|
|
(void) mcdintr(sc);
|
1995-03-27 19:45:20 +04:00
|
|
|
splx(s);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcdioctl(dev, cmd, addr, flag, p)
|
1994-02-21 18:23:11 +03:00
|
|
|
dev_t dev;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1994-02-21 18:23:11 +03:00
|
|
|
caddr_t addr;
|
1995-03-27 19:45:20 +04:00
|
|
|
int flag;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct proc *p;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = mcdcd.cd_devs[MCDUNIT(dev)];
|
1995-03-27 19:45:20 +04:00
|
|
|
int error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("ioctl: cmd=0x%x\n", cmd, 0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((sc->flags & MCDF_LOADED) == 0)
|
|
|
|
return EIO;
|
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
switch (cmd) {
|
1995-03-27 19:45:20 +04:00
|
|
|
case DIOCGDINFO:
|
|
|
|
*(struct disklabel *)addr = sc->sc_dk.dk_label;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCGPART:
|
|
|
|
((struct partinfo *)addr)->disklab = &sc->sc_dk.dk_label;
|
|
|
|
((struct partinfo *)addr)->part =
|
|
|
|
&sc->sc_dk.dk_label.d_partitions[MCDPART(dev)];
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
if (error = mcdlock(sc))
|
1995-03-27 19:45:20 +04:00
|
|
|
return error;
|
1995-04-01 12:45:33 +04:00
|
|
|
sc->flags |= MCDF_LABELLING;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
error = setdisklabel(&sc->sc_dk.dk_label,
|
|
|
|
(struct disklabel *)addr, /*sc->sc_dk.dk_openmask : */0,
|
|
|
|
&sc->sc_dk.dk_cpulabel);
|
|
|
|
if (error == 0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->flags &= ~MCDF_LABELLING;
|
|
|
|
mcdunlock(sc);
|
|
|
|
return error;
|
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
return EBADF;
|
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCPLAYTRACKS:
|
1994-10-29 02:39:59 +03:00
|
|
|
return mcd_playtracks(sc, (struct ioc_play_track *)addr);
|
1995-03-27 19:45:20 +04:00
|
|
|
case CDIOCPLAYMSF:
|
|
|
|
return mcd_playmsf(sc, (struct ioc_play_msf *)addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCPLAYBLOCKS:
|
1995-03-27 19:45:20 +04:00
|
|
|
return mcd_playblocks(sc, (struct ioc_play_blocks *)addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCREADSUBCHANNEL:
|
1995-03-27 19:45:20 +04:00
|
|
|
return mcd_read_subchannel(sc, (struct ioc_read_subchannel *)addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOREADTOCHEADER:
|
1994-10-29 02:39:59 +03:00
|
|
|
return mcd_toc_header(sc, (struct ioc_toc_header *)addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOREADTOCENTRYS:
|
1995-03-27 19:45:20 +04:00
|
|
|
return mcd_toc_entries(sc, (struct ioc_read_toc_entry *)addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCSETPATCH:
|
|
|
|
case CDIOCGETVOL:
|
|
|
|
case CDIOCSETVOL:
|
|
|
|
case CDIOCSETMONO:
|
1994-08-06 02:56:19 +04:00
|
|
|
case CDIOCSETSTEREO:
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCSETMUTE:
|
|
|
|
case CDIOCSETLEFT:
|
|
|
|
case CDIOCSETRIGHT:
|
|
|
|
return EINVAL;
|
|
|
|
case CDIOCRESUME:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_resume(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCPAUSE:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_pause(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCSTART:
|
|
|
|
return EINVAL;
|
|
|
|
case CDIOCSTOP:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_stop(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCEJECT:
|
1995-03-27 19:45:20 +04:00
|
|
|
return mcd_eject(sc);
|
|
|
|
case CDIOCALLOW:
|
|
|
|
return mcd_setlock(sc, MCD_LK_UNLOCK);
|
|
|
|
case CDIOCPREVENT:
|
|
|
|
return mcd_setlock(sc, MCD_LK_LOCK);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCSETDEBUG:
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->debug = 1;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
case CDIOCCLRDEBUG:
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->debug = 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
case CDIOCRESET:
|
1995-03-27 19:45:20 +04:00
|
|
|
return mcd_hard_reset(sc);
|
1995-03-27 20:04:07 +04:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("mcdioctl: impossible");
|
|
|
|
#endif
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/*
|
|
|
|
* This could have been taken from scsi/cd.c, but it is not clear
|
|
|
|
* whether the scsi cd driver is linked in.
|
1993-11-04 12:12:30 +03:00
|
|
|
*/
|
1995-03-27 19:45:20 +04:00
|
|
|
void
|
|
|
|
mcdgetdisklabel(sc)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
bzero(&sc->sc_dk.dk_label, sizeof(struct disklabel));
|
|
|
|
bzero(&sc->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
sc->sc_dk.dk_label.d_secsize = sc->blksize;
|
|
|
|
sc->sc_dk.dk_label.d_ntracks = 1;
|
|
|
|
sc->sc_dk.dk_label.d_nsectors = 100;
|
|
|
|
sc->sc_dk.dk_label.d_ncylinders = (sc->disksize / 100) + 1;
|
|
|
|
sc->sc_dk.dk_label.d_secpercyl =
|
|
|
|
sc->sc_dk.dk_label.d_ntracks * sc->sc_dk.dk_label.d_nsectors;
|
|
|
|
|
|
|
|
strncpy(sc->sc_dk.dk_label.d_typename, "Mitsumi CD-ROM", 16);
|
|
|
|
sc->sc_dk.dk_label.d_type = 0; /* XXX */
|
|
|
|
strncpy(sc->sc_dk.dk_label.d_packname, "fictitious", 16);
|
|
|
|
sc->sc_dk.dk_label.d_secperunit = sc->disksize;
|
|
|
|
sc->sc_dk.dk_label.d_rpm = 300;
|
|
|
|
sc->sc_dk.dk_label.d_interleave = 1;
|
|
|
|
sc->sc_dk.dk_label.d_flags = D_REMOVABLE;
|
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
sc->sc_dk.dk_label.d_partitions[0].p_offset = 0;
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->sc_dk.dk_label.d_partitions[0].p_size =
|
|
|
|
sc->sc_dk.dk_label.d_secperunit *
|
|
|
|
(sc->sc_dk.dk_label.d_secsize / DEV_BSIZE);
|
|
|
|
sc->sc_dk.dk_label.d_partitions[0].p_fstype = FS_ISO9660;
|
|
|
|
sc->sc_dk.dk_label.d_npartitions = 1;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->sc_dk.dk_label.d_magic = DISKMAGIC;
|
|
|
|
sc->sc_dk.dk_label.d_magic2 = DISKMAGIC;
|
|
|
|
sc->sc_dk.dk_label.d_checksum = dkcksum(&sc->sc_dk.dk_label);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mcd_get_parms(sc)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
daddr_t size;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* Send volume info command. */
|
|
|
|
mbx.cmd.opcode = MCD_CMDGETVOLINFO;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = sizeof(mbx.res.data.volinfo);
|
|
|
|
if ((error = mcd_send(sc, &mbx, 1)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if (mbx.res.data.volinfo.trk_low == 0x00 &&
|
|
|
|
mbx.res.data.volinfo.trk_high == 0x00)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* Volinfo is OK. */
|
|
|
|
sc->volinfo = mbx.res.data.volinfo;
|
|
|
|
sc->blksize = MCD_BLKSIZE_COOKED;
|
|
|
|
size = msf2hsg(sc->volinfo.vol_msf, 0);
|
|
|
|
sc->disksize = size * (MCD_BLKSIZE_COOKED / DEV_BSIZE);
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcdsize(dev)
|
|
|
|
dev_t dev;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* CD-ROMs are read-only. */
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1994-05-11 13:49:17 +04:00
|
|
|
int
|
|
|
|
mcddump()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Not implemented. */
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1994-11-04 01:55:58 +03:00
|
|
|
mcdprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-11-04 01:55:58 +03:00
|
|
|
struct mcd_softc *sc = match;
|
1994-03-29 08:35:37 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = ia->ia_iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
int i;
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->iobase = iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Send a reset. */
|
1995-03-27 19:45:20 +04:00
|
|
|
outb(iobase + MCD_RESET, 0);
|
1994-08-03 12:57:59 +04:00
|
|
|
delay(1000000);
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get any pending status and throw away. */
|
|
|
|
for (i = 10; i; i--)
|
1995-03-27 19:45:20 +04:00
|
|
|
inb(iobase + MCD_STATUS);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(1000);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Send get status command. */
|
1995-03-27 19:45:20 +04:00
|
|
|
mbx.cmd.opcode = MCD_CMDGETSTAT;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
if (mcd_send(sc, &mbx, 0) != 0)
|
1994-02-21 18:23:11 +03:00
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Get info about the drive. */
|
|
|
|
mbx.cmd.opcode = MCD_CMDCONTINFO;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = sizeof(mbx.res.data.continfo);
|
|
|
|
if (mcd_send(sc, &mbx, 0) != 0)
|
1994-08-03 12:57:59 +04:00
|
|
|
return 0;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The following is code which is not guaranteed to work for all
|
|
|
|
* drives, because the meaning of the expected 'M' is not clear
|
|
|
|
* (M_itsumi is an obvious assumption, but I don't trust that).
|
|
|
|
* Also, the original hack had a bogus condition that always
|
|
|
|
* returned true.
|
1995-03-27 19:45:20 +04:00
|
|
|
*
|
|
|
|
* Note: Which models support interrupts? >=LU005S?
|
1994-02-21 18:23:11 +03:00
|
|
|
*/
|
1995-03-27 19:45:20 +04:00
|
|
|
switch (mbx.res.data.continfo.code) {
|
|
|
|
case 'M':
|
|
|
|
if (mbx.res.data.continfo.version <= 2)
|
|
|
|
sc->type = "LU002S";
|
|
|
|
else if (mbx.res.data.continfo.version <= 5)
|
|
|
|
sc->type = "LU005S";
|
|
|
|
else
|
|
|
|
sc->type = "LU006S";
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
sc->type = "FX001";
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
sc->type = "FX001D";
|
|
|
|
break;
|
|
|
|
default:
|
1994-08-03 12:57:59 +04:00
|
|
|
printf("%s: unrecognized drive version %c%02x; will try to use it anyway\n",
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
mbx.res.data.continfo.code, mbx.res.data.continfo.version);
|
|
|
|
sc->type = 0;
|
|
|
|
break;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
ia->ia_iosize = 4;
|
|
|
|
ia->ia_msize = 0;
|
|
|
|
return 1;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_getreply(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
int iobase = sc->iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
int i;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Wait until xfer port senses data ready. */
|
1995-03-27 19:45:20 +04:00
|
|
|
for (i = DELAY_GETREPLY; i; i--) {
|
|
|
|
if ((inb(iobase + MCD_XFER) & MCD_XF_STATUSUNAVAIL) == 0)
|
|
|
|
break;
|
|
|
|
delay(DELAY_GRANULARITY);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
if (!i)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Get the data. */
|
|
|
|
return inb(iobase + MCD_STATUS);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_getstat(sc)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
mbx.cmd.opcode = MCD_CMDGETSTAT;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 1);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_getresult(sc, res)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_result *res;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
int i, x;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: mcd_getresult: %d", sc->sc_dev.dv_xname,
|
|
|
|
res->length);
|
|
|
|
|
|
|
|
if ((x = mcd_getreply(sc)) < 0) {
|
|
|
|
if (sc->debug)
|
|
|
|
printf(" timeout\n");
|
|
|
|
else
|
|
|
|
printf("%s: timeout in getresult\n", sc->sc_dev.dv_xname);
|
|
|
|
return EIO;
|
1994-02-21 18:23:11 +03:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->debug)
|
|
|
|
printf(" %02x", (u_int)x);
|
|
|
|
sc->status = x;
|
|
|
|
mcd_setflags(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((sc->status & MCD_ST_CMDCHECK) != 0)
|
|
|
|
return EINVAL;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
for (i = 0; i < res->length; i++) {
|
|
|
|
if ((x = mcd_getreply(sc)) < 0) {
|
|
|
|
if (sc->debug)
|
|
|
|
printf(" timeout\n");
|
|
|
|
else
|
|
|
|
printf("%s: timeout in getresult\n", sc->sc_dev.dv_xname);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
if (sc->debug)
|
|
|
|
printf(" %02x", (u_int)x);
|
|
|
|
res->data.raw.data[i] = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->debug)
|
|
|
|
printf(" succeeded\n");
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
delay(10);
|
|
|
|
while ((inb(sc->iobase + MCD_XFER) & MCD_XF_STATUSUNAVAIL) == 0) {
|
|
|
|
x = inb(sc->iobase + MCD_STATUS);
|
|
|
|
printf("%s: got extra byte %02x during getstatus\n",
|
|
|
|
sc->sc_dev.dv_xname, (u_int)x);
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
void
|
|
|
|
mcd_setflags(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
|
|
|
/* Check flags. */
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((sc->flags & MCDF_LOADED) != 0 &&
|
|
|
|
(sc->status & (MCD_ST_DSKCHNG | MCD_ST_DSKIN | MCD_ST_DOOROPEN)) !=
|
|
|
|
MCD_ST_DSKIN) {
|
|
|
|
if ((sc->status & MCD_ST_DOOROPEN) != 0)
|
|
|
|
printf("%s: door open\n", sc->sc_dev.dv_xname);
|
|
|
|
else if ((sc->status & MCD_ST_DSKIN) == 0)
|
|
|
|
printf("%s: no disk present\n", sc->sc_dev.dv_xname);
|
|
|
|
else if ((sc->status & MCD_ST_DSKCHNG) != 0)
|
|
|
|
printf("%s: media change\n", sc->sc_dev.dv_xname);
|
|
|
|
sc->flags &= ~MCDF_LOADED;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((sc->status & MCD_ST_AUDIOBSY) != 0)
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->audio_status = CD_AS_PLAY_IN_PROGRESS;
|
1995-03-27 19:45:20 +04:00
|
|
|
else if (sc->audio_status == CD_AS_PLAY_IN_PROGRESS ||
|
|
|
|
sc->audio_status == CD_AS_AUDIO_INVALID)
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->audio_status = CD_AS_PLAY_COMPLETED;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_send(sc, mbx, diskin)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox *mbx;
|
|
|
|
int diskin;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = sc->iobase;
|
1995-03-27 19:45:20 +04:00
|
|
|
int retry, i, error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->debug) {
|
|
|
|
printf("%s: mcd_send: %d %02x", sc->sc_dev.dv_xname,
|
|
|
|
mbx->cmd.length, (u_int)mbx->cmd.opcode);
|
|
|
|
for (i = 0; i < mbx->cmd.length; i++)
|
|
|
|
printf(" %02x", (u_int)mbx->cmd.data.raw.data[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
for (retry = MCD_RETRIES; retry; retry--) {
|
|
|
|
outb(iobase + MCD_COMMAND, mbx->cmd.opcode);
|
|
|
|
for (i = 0; i < mbx->cmd.length; i++)
|
|
|
|
outb(iobase + MCD_COMMAND, mbx->cmd.data.raw.data[i]);
|
|
|
|
if ((error = mcd_getresult(sc, &mbx->res)) == 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
break;
|
1995-03-27 19:45:20 +04:00
|
|
|
if (error == EINVAL)
|
|
|
|
return error;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
if (!retry)
|
|
|
|
return error;
|
|
|
|
if (diskin && (sc->flags & MCDF_LOADED) == 0)
|
|
|
|
return EIO;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
static int
|
1994-02-21 18:23:11 +03:00
|
|
|
bcd2bin(b)
|
|
|
|
bcd_t b;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
return (b >> 4) * 10 + (b & 15);
|
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
static bcd_t
|
1994-02-21 18:23:11 +03:00
|
|
|
bin2bcd(b)
|
|
|
|
int b;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
return ((b / 10) << 4) | (b % 10);
|
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
static void
|
1994-02-21 18:23:11 +03:00
|
|
|
hsg2msf(hsg, msf)
|
|
|
|
int hsg;
|
|
|
|
bcd_t *msf;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
hsg += 150;
|
|
|
|
F_msf(msf) = bin2bcd(hsg % 75);
|
1995-03-27 19:45:20 +04:00
|
|
|
hsg /= 75;
|
|
|
|
S_msf(msf) = bin2bcd(hsg % 60);
|
|
|
|
hsg /= 60;
|
|
|
|
M_msf(msf) = bin2bcd(hsg);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
static daddr_t
|
|
|
|
msf2hsg(msf, relative)
|
1994-02-21 18:23:11 +03:00
|
|
|
bcd_t *msf;
|
1995-03-27 19:45:20 +04:00
|
|
|
int relative;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
daddr_t blkno;
|
|
|
|
|
|
|
|
blkno = bcd2bin(M_msf(msf)) * 75 * 60 +
|
|
|
|
bcd2bin(S_msf(msf)) * 75 +
|
|
|
|
bcd2bin(F_msf(msf));
|
|
|
|
if (!relative)
|
|
|
|
blkno -= 150;
|
|
|
|
return blkno;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
void
|
|
|
|
mcd_pseudointr(sc)
|
1994-04-07 10:48:19 +04:00
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
int s;
|
1994-04-08 22:22:15 +04:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
s = splbio();
|
1995-03-27 20:04:07 +04:00
|
|
|
(void) mcdintr(sc);
|
1995-03-27 19:45:20 +04:00
|
|
|
splx(s);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/*
|
|
|
|
* State machine to process read requests.
|
1995-03-27 20:48:45 +04:00
|
|
|
* Initialize with MCD_S_BEGIN: calculate sizes, and set mode
|
1993-11-04 12:12:30 +03:00
|
|
|
* MCD_S_WAITMODE: waits for status reply from set mode, set read command
|
1994-02-21 18:23:11 +03:00
|
|
|
* MCD_S_WAITREAD: wait for read ready, read data.
|
1993-11-04 12:12:30 +03:00
|
|
|
*/
|
1995-03-27 20:04:07 +04:00
|
|
|
int
|
|
|
|
mcdintr(arg)
|
1994-05-05 09:35:42 +04:00
|
|
|
void *arg;
|
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_softc *sc = arg;
|
|
|
|
struct mcd_mbx *mbx = &sc->mbx;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = sc->iobase;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct buf *bp = mbx->bp;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
int i;
|
|
|
|
u_char x;
|
|
|
|
bcd_t msf[3];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-05-05 12:26:13 +04:00
|
|
|
switch (mbx->state) {
|
1995-03-27 19:45:20 +04:00
|
|
|
case MCD_S_IDLE:
|
1995-03-27 20:04:07 +04:00
|
|
|
return 0;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
case MCD_S_BEGIN:
|
1995-03-27 19:45:20 +04:00
|
|
|
tryagain:
|
|
|
|
if (mbx->mode == sc->lastmode)
|
|
|
|
goto firstblock;
|
|
|
|
|
|
|
|
sc->lastmode = MCD_MD_UNKNOWN;
|
|
|
|
outb(iobase + MCD_COMMAND, MCD_CMDSETMODE);
|
|
|
|
outb(iobase + MCD_COMMAND, mbx->mode);
|
1994-05-05 12:26:13 +04:00
|
|
|
|
|
|
|
mbx->count = RDELAY_WAITMODE;
|
|
|
|
mbx->state = MCD_S_WAITMODE;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
case MCD_S_WAITMODE:
|
1995-03-27 19:45:20 +04:00
|
|
|
untimeout(mcd_pseudointr, sc);
|
|
|
|
for (i = 20; i; i--) {
|
|
|
|
x = inb(iobase + MCD_XFER);
|
|
|
|
if ((x & MCD_XF_STATUSUNAVAIL) == 0)
|
|
|
|
break;
|
|
|
|
delay(50);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
if (i == 0)
|
|
|
|
goto hold;
|
|
|
|
sc->status = inb(iobase + MCD_STATUS);
|
1994-02-21 18:23:11 +03:00
|
|
|
mcd_setflags(sc);
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((sc->flags & MCDF_LOADED) == 0)
|
|
|
|
goto changed;
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("doread: got WAITMODE delay=%d\n",
|
|
|
|
RDELAY_WAITMODE - mbx->count, 0, 0, 0);
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->lastmode = mbx->mode;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
firstblock:
|
|
|
|
MCD_TRACE("doread: read blkno=%d for bp=0x%x\n", mbx->blkno,
|
|
|
|
bp, 0, 0);
|
1994-02-21 18:23:11 +03:00
|
|
|
|
|
|
|
/* Build parameter block. */
|
1995-03-27 19:45:20 +04:00
|
|
|
hsg2msf(mbx->blkno, msf);
|
1994-02-21 18:23:11 +03:00
|
|
|
|
|
|
|
/* Send the read command. */
|
1995-03-27 19:45:20 +04:00
|
|
|
outb(iobase + MCD_COMMAND, MCD_CMDREAD2);
|
|
|
|
outb(iobase + MCD_COMMAND, msf[0]);
|
|
|
|
outb(iobase + MCD_COMMAND, msf[1]);
|
|
|
|
outb(iobase + MCD_COMMAND, msf[2]);
|
|
|
|
outb(iobase + MCD_COMMAND, 0);
|
|
|
|
outb(iobase + MCD_COMMAND, 0);
|
|
|
|
outb(iobase + MCD_COMMAND, mbx->nblk);
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
mbx->count = RDELAY_WAITREAD;
|
1994-05-05 12:26:13 +04:00
|
|
|
mbx->state = MCD_S_WAITREAD;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
case MCD_S_WAITREAD:
|
1995-03-27 19:45:20 +04:00
|
|
|
untimeout(mcd_pseudointr, sc);
|
|
|
|
nextblock:
|
|
|
|
loop:
|
|
|
|
for (i = 20; i; i--) {
|
|
|
|
x = inb(iobase + MCD_XFER);
|
|
|
|
if ((x & MCD_XF_DATAUNAVAIL) == 0)
|
|
|
|
goto gotblock;
|
|
|
|
if ((x & MCD_XF_STATUSUNAVAIL) == 0)
|
|
|
|
break;
|
|
|
|
delay(50);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
if (i == 0)
|
|
|
|
goto hold;
|
|
|
|
sc->status = inb(iobase + MCD_STATUS);
|
|
|
|
mcd_setflags(sc);
|
|
|
|
if ((sc->flags & MCDF_LOADED) == 0)
|
|
|
|
goto changed;
|
|
|
|
#if 0
|
|
|
|
printf("%s: got status byte %02x during read\n",
|
|
|
|
sc->sc_dev.dv_xname, (u_int)sc->status);
|
|
|
|
#endif
|
|
|
|
goto loop;
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
gotblock:
|
|
|
|
MCD_TRACE("doread: got data delay=%d\n",
|
|
|
|
RDELAY_WAITREAD - mbx->count, 0, 0, 0);
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Data is ready. */
|
|
|
|
outb(iobase + MCD_CTL2, 0x04); /* XXX */
|
|
|
|
insb(iobase + MCD_RDATA, bp->b_data + mbx->skip, mbx->sz);
|
|
|
|
outb(iobase + MCD_CTL2, 0x0c); /* XXX */
|
|
|
|
mbx->blkno += 1;
|
|
|
|
mbx->skip += mbx->sz;
|
|
|
|
if (--mbx->nblk > 0)
|
|
|
|
goto nextblock;
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
mbx->state = MCD_S_IDLE;
|
|
|
|
|
|
|
|
/* Return buffer. */
|
|
|
|
bp->b_resid = 0;
|
|
|
|
biodone(bp);
|
|
|
|
|
|
|
|
mcdstart(sc);
|
1995-03-27 20:04:07 +04:00
|
|
|
return 1;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
hold:
|
|
|
|
if (mbx->count-- < 0) {
|
|
|
|
printf("%s: timeout in state %d",
|
|
|
|
sc->sc_dev.dv_xname, mbx->state);
|
|
|
|
goto readerr;
|
1994-05-05 12:26:13 +04:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("%s: sleep in state %d\n", sc->sc_dev.dv_xname,
|
|
|
|
mbx->state);
|
|
|
|
#endif
|
|
|
|
timeout(mcd_pseudointr, sc, hz / 100);
|
1995-03-27 20:04:07 +04:00
|
|
|
return -1;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
readerr:
|
|
|
|
if (mbx->retry-- > 0) {
|
1995-03-27 19:45:20 +04:00
|
|
|
printf("; retrying\n");
|
|
|
|
goto tryagain;
|
|
|
|
} else
|
|
|
|
printf("; giving up\n");
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
changed:
|
|
|
|
harderr:
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Invalidate the buffer. */
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_flags |= B_ERROR;
|
1995-03-27 19:45:20 +04:00
|
|
|
bp->b_resid = bp->b_bcount - mbx->skip;
|
1993-11-04 12:12:30 +03:00
|
|
|
biodone(bp);
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
mcdstart(sc);
|
1995-03-27 20:04:07 +04:00
|
|
|
return -1;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifdef notyet
|
|
|
|
printf("%s: unit timeout; resetting\n", sc->sc_dev.dv_xname);
|
1995-03-27 19:45:20 +04:00
|
|
|
outb(mbx->iobase + MCD_RESET, MCD_CMDRESET);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(300000);
|
1995-03-27 19:45:20 +04:00
|
|
|
(void) mcd_getstat(sc, 1);
|
|
|
|
(void) mcd_getstat(sc, 1);
|
|
|
|
/*sc->status &= ~MCD_ST_DSKCHNG; */
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->debug = 1; /* preventive set debug mode */
|
1993-11-04 12:12:30 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
void
|
|
|
|
mcd_soft_reset(sc)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
{
|
|
|
|
|
1995-03-27 20:04:07 +04:00
|
|
|
sc->debug = 0;
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->flags = 0;
|
|
|
|
sc->lastmode = MCD_MD_UNKNOWN;
|
|
|
|
sc->lastupc = MCD_UPC_UNKNOWN;
|
|
|
|
sc->audio_status = CD_AS_AUDIO_INVALID;
|
|
|
|
outb(sc->iobase + MCD_CTL2, 0x0c); /* XXX */
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mcd_hard_reset(sc)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
|
|
|
|
mcd_soft_reset(sc);
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDRESET;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 0);
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_setmode(sc, mode)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
int mode;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->lastmode == mode)
|
|
|
|
return 0;
|
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: setting mode to %d\n", sc->sc_dev.dv_xname, mode);
|
|
|
|
sc->lastmode = MCD_MD_UNKNOWN;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
mbx.cmd.opcode = MCD_CMDSETMODE;
|
|
|
|
mbx.cmd.length = sizeof(mbx.cmd.data.datamode);
|
|
|
|
mbx.cmd.data.datamode.mode = mode;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
if ((error = mcd_send(sc, &mbx, 1)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
sc->lastmode = mode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mcd_setupc(sc, upc)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
int upc;
|
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->lastupc == upc)
|
|
|
|
return 0;
|
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: setting upc to %d\n", sc->sc_dev.dv_xname, upc);
|
|
|
|
sc->lastupc = MCD_UPC_UNKNOWN;
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDCONFIGDRIVE;
|
|
|
|
mbx.cmd.length = sizeof(mbx.cmd.data.config) - 1;
|
|
|
|
mbx.cmd.data.config.subcommand = MCD_CF_READUPC;
|
|
|
|
mbx.cmd.data.config.data1 = upc;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
if ((error = mcd_send(sc, &mbx, 1)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
sc->lastupc = upc;
|
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_toc_header(sc, th)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct ioc_toc_header *th;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: mcd_toc_header: reading toc header\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
th->len = msf2hsg(sc->volinfo.vol_msf, 0);
|
1994-02-21 18:23:11 +03:00
|
|
|
th->starting_track = bcd2bin(sc->volinfo.trk_low);
|
|
|
|
th->ending_track = bcd2bin(sc->volinfo.trk_high);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_read_toc(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
struct ioc_toc_header th;
|
1995-03-27 19:45:20 +04:00
|
|
|
union mcd_qchninfo q;
|
|
|
|
int error, trk, idx, retry;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((error = mcd_toc_header(sc, &th)) != 0)
|
|
|
|
return error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((error = mcd_stop(sc)) != 0)
|
|
|
|
return error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: read_toc: reading qchannel info\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1995-03-27 19:45:20 +04:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
for (trk = th.starting_track; trk <= th.ending_track; trk++)
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->toc[trk].toc.idx_no = 0x00;
|
1993-11-04 12:12:30 +03:00
|
|
|
trk = th.ending_track - th.starting_track + 1;
|
1994-02-21 18:23:11 +03:00
|
|
|
for (retry = 300; retry && trk > 0; retry--) {
|
1995-03-27 19:45:20 +04:00
|
|
|
if (mcd_getqchan(sc, &q, CD_TRACK_INFO) != 0)
|
1994-02-21 18:23:11 +03:00
|
|
|
break;
|
1995-03-27 19:45:20 +04:00
|
|
|
if (q.toc.trk_no != 0x00 || q.toc.idx_no == 0x00)
|
|
|
|
continue;
|
|
|
|
idx = bcd2bin(q.toc.idx_no);
|
|
|
|
if (idx < MCD_MAXTOCS &&
|
|
|
|
sc->toc[idx].toc.idx_no == 0x00) {
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->toc[idx] = q;
|
|
|
|
trk--;
|
|
|
|
}
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1995-04-01 12:40:11 +04:00
|
|
|
/* Inform the drive that we're finished so it turns off the light. */
|
|
|
|
if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
|
|
|
|
return error;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (trk != 0)
|
1995-03-27 19:45:20 +04:00
|
|
|
return EINVAL;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Add a fake last+1 for mcd_playtracks(). */
|
1993-11-04 12:12:30 +03:00
|
|
|
idx = th.ending_track + 1;
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->toc[idx].toc.control = sc->toc[idx-1].toc.control;
|
|
|
|
sc->toc[idx].toc.addr_type = sc->toc[idx-1].toc.addr_type;
|
|
|
|
sc->toc[idx].toc.trk_no = 0x00;
|
|
|
|
sc->toc[idx].toc.idx_no = 0xaa;
|
|
|
|
sc->toc[idx].toc.absolute_pos[0] = sc->volinfo.vol_msf[0];
|
|
|
|
sc->toc[idx].toc.absolute_pos[1] = sc->volinfo.vol_msf[1];
|
|
|
|
sc->toc[idx].toc.absolute_pos[2] = sc->volinfo.vol_msf[2];
|
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_toc_entries(sc, te)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct ioc_read_toc_entry *te;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
int len = te->data_len;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct ret_toc {
|
1995-03-27 19:45:20 +04:00
|
|
|
struct ioc_toc_header header;
|
|
|
|
struct cd_toc_entry entries[MCD_MAXTOCS];
|
|
|
|
} data;
|
|
|
|
u_char trk;
|
|
|
|
daddr_t lba;
|
|
|
|
int error, n;
|
|
|
|
|
|
|
|
if (len > sizeof(data.entries) ||
|
|
|
|
len < sizeof(struct cd_toc_entry))
|
|
|
|
return EINVAL;
|
|
|
|
if (te->address_format != CD_MSF_FORMAT &&
|
|
|
|
te->address_format != CD_LBA_FORMAT)
|
|
|
|
return EINVAL;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Copy the TOC header. */
|
|
|
|
if ((error = mcd_toc_header(sc, &data.header)) != 0)
|
|
|
|
return error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Verify starting track. */
|
1995-03-27 19:45:20 +04:00
|
|
|
trk = te->starting_track;
|
|
|
|
if (trk == 0x00)
|
|
|
|
trk = data.header.starting_track;
|
|
|
|
else if (trk == 0xaa)
|
|
|
|
trk = data.header.ending_track + 1;
|
|
|
|
else if (trk < data.header.starting_track ||
|
|
|
|
trk > data.header.ending_track + 1)
|
1994-02-21 18:23:11 +03:00
|
|
|
return EINVAL;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Copy the TOC data. */
|
1995-03-27 19:45:20 +04:00
|
|
|
for (n = 0; trk <= data.header.ending_track + 1; trk++) {
|
|
|
|
if (sc->toc[trk].toc.idx_no == 0x00)
|
|
|
|
continue;
|
|
|
|
data.entries[n].control = sc->toc[trk].toc.control;
|
|
|
|
data.entries[n].addr_type = sc->toc[trk].toc.addr_type;
|
|
|
|
data.entries[n].track = bcd2bin(sc->toc[trk].toc.idx_no);
|
|
|
|
switch (te->address_format) {
|
|
|
|
case CD_MSF_FORMAT:
|
|
|
|
data.entries[n].addr[0] = 0;
|
|
|
|
data.entries[n].addr[1] = bcd2bin(sc->toc[trk].toc.absolute_pos[0]);
|
|
|
|
data.entries[n].addr[2] = bcd2bin(sc->toc[trk].toc.absolute_pos[1]);
|
|
|
|
data.entries[n].addr[3] = bcd2bin(sc->toc[trk].toc.absolute_pos[2]);
|
|
|
|
break;
|
|
|
|
case CD_LBA_FORMAT:
|
|
|
|
lba = msf2hsg(sc->toc[trk].toc.absolute_pos, 0);
|
|
|
|
data.entries[n].addr[0] = lba >> 24;
|
|
|
|
data.entries[n].addr[1] = lba >> 16;
|
|
|
|
data.entries[n].addr[2] = lba >> 8;
|
|
|
|
data.entries[n].addr[3] = lba;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n++;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
len = min(len, n * sizeof(struct cd_toc_entry));
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Copy the data back. */
|
|
|
|
return copyout(&data.entries[0], te->data, len);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_stop(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: mcd_stop: stopping play\n", sc->sc_dev.dv_xname);
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDSTOPAUDIO;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
if ((error = mcd_send(sc, &mbx, 1)) != 0)
|
|
|
|
return error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->audio_status = CD_AS_PLAY_COMPLETED;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_getqchan(sc, q, qchn)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1995-03-27 19:45:20 +04:00
|
|
|
union mcd_qchninfo *q;
|
|
|
|
int qchn;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (qchn == CD_TRACK_INFO) {
|
|
|
|
if ((error = mcd_setmode(sc, MCD_MD_TOC)) != 0)
|
|
|
|
return error;
|
|
|
|
} else {
|
|
|
|
if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (qchn == CD_MEDIA_CATALOG) {
|
|
|
|
if ((error = mcd_setupc(sc, MCD_UPC_ENABLE)) != 0)
|
|
|
|
return error;
|
|
|
|
} else {
|
|
|
|
if ((error = mcd_setupc(sc, MCD_UPC_DISABLE)) != 0)
|
|
|
|
return error;
|
|
|
|
}
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
mbx.cmd.opcode = MCD_CMDGETQCHN;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = sizeof(mbx.res.data.qchninfo);
|
|
|
|
if ((error = mcd_send(sc, &mbx, 1)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
*q = mbx.res.data.qchninfo;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_read_subchannel(sc, ch)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct ioc_read_subchannel *ch;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
int len = ch->data_len;
|
|
|
|
union mcd_qchninfo q;
|
1993-11-04 12:12:30 +03:00
|
|
|
struct cd_sub_channel_info data;
|
1995-03-27 19:45:20 +04:00
|
|
|
daddr_t lba;
|
|
|
|
int error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: subchan: af=%d df=%d\n", sc->sc_dev.dv_xname,
|
|
|
|
ch->address_format, ch->data_format);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (len > sizeof(data) ||
|
|
|
|
len < sizeof(struct cd_sub_channel_header))
|
|
|
|
return EINVAL;
|
|
|
|
if (ch->address_format != CD_MSF_FORMAT &&
|
|
|
|
ch->address_format != CD_LBA_FORMAT)
|
|
|
|
return EINVAL;
|
|
|
|
if (ch->data_format != CD_CURRENT_POSITION &&
|
|
|
|
ch->data_format != CD_MEDIA_CATALOG)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if ((error = mcd_getqchan(sc, &q, ch->data_format)) != 0)
|
|
|
|
return error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
data.header.audio_status = sc->audio_status;
|
1995-03-27 19:45:20 +04:00
|
|
|
data.what.media_catalog.data_format = ch->data_format;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
switch (ch->data_format) {
|
|
|
|
case CD_MEDIA_CATALOG:
|
|
|
|
data.what.media_catalog.mc_valid = 1;
|
|
|
|
#if 0
|
|
|
|
data.what.media_catalog.mc_number =
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CD_CURRENT_POSITION:
|
|
|
|
data.what.position.track_number = bcd2bin(q.current.trk_no);
|
|
|
|
data.what.position.index_number = bcd2bin(q.current.idx_no);
|
|
|
|
switch (ch->address_format) {
|
|
|
|
case CD_MSF_FORMAT:
|
|
|
|
data.what.position.reladdr[0] = 0;
|
|
|
|
data.what.position.reladdr[1] = bcd2bin(q.current.relative_pos[0]);
|
|
|
|
data.what.position.reladdr[2] = bcd2bin(q.current.relative_pos[1]);
|
|
|
|
data.what.position.reladdr[3] = bcd2bin(q.current.relative_pos[2]);
|
|
|
|
data.what.position.absaddr[0] = 0;
|
|
|
|
data.what.position.absaddr[1] = bcd2bin(q.current.absolute_pos[0]);
|
|
|
|
data.what.position.absaddr[2] = bcd2bin(q.current.absolute_pos[1]);
|
|
|
|
data.what.position.absaddr[3] = bcd2bin(q.current.absolute_pos[2]);
|
|
|
|
break;
|
|
|
|
case CD_LBA_FORMAT:
|
|
|
|
lba = msf2hsg(q.current.relative_pos, 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 == 0x00)
|
|
|
|
lba = -lba;
|
|
|
|
data.what.position.reladdr[0] = lba >> 24;
|
|
|
|
data.what.position.reladdr[1] = lba >> 16;
|
|
|
|
data.what.position.reladdr[2] = lba >> 8;
|
|
|
|
data.what.position.reladdr[3] = lba;
|
|
|
|
lba = msf2hsg(q.current.absolute_pos, 0);
|
|
|
|
data.what.position.absaddr[0] = lba >> 24;
|
|
|
|
data.what.position.absaddr[1] = lba >> 16;
|
|
|
|
data.what.position.absaddr[2] = lba >> 8;
|
|
|
|
data.what.position.absaddr[3] = lba;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copyout(&data, ch->data, len);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_playtracks(sc, p)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1995-03-27 19:45:20 +04:00
|
|
|
struct ioc_play_track *p;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int a = p->start_track;
|
|
|
|
int z = p->end_track;
|
|
|
|
int error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: playtracks: from %d:%d to %d:%d\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
a, p->start_index, z, p->end_index);
|
|
|
|
|
|
|
|
if (a < bcd2bin(sc->volinfo.trk_low) ||
|
|
|
|
a > bcd2bin(sc->volinfo.trk_high) ||
|
|
|
|
a > z ||
|
|
|
|
z < bcd2bin(sc->volinfo.trk_low) ||
|
|
|
|
z > bcd2bin(sc->volinfo.trk_high))
|
1993-11-04 12:12:30 +03:00
|
|
|
return EINVAL;
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDREAD2;
|
|
|
|
mbx.cmd.length = sizeof(mbx.cmd.data.play);
|
|
|
|
mbx.cmd.data.play.start_msf[0] = sc->toc[a].toc.absolute_pos[0];
|
|
|
|
mbx.cmd.data.play.start_msf[1] = sc->toc[a].toc.absolute_pos[1];
|
|
|
|
mbx.cmd.data.play.start_msf[2] = sc->toc[a].toc.absolute_pos[2];
|
|
|
|
mbx.cmd.data.play.end_msf[0] = sc->toc[z+1].toc.absolute_pos[0];
|
|
|
|
mbx.cmd.data.play.end_msf[1] = sc->toc[z+1].toc.absolute_pos[1];
|
|
|
|
mbx.cmd.data.play.end_msf[2] = sc->toc[z+1].toc.absolute_pos[2];
|
|
|
|
sc->lastpb = mbx.cmd;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mcd_playmsf(sc, p)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct ioc_play_msf *p;
|
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: playmsf: from %d:%d.%d to %d:%d.%d\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
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))
|
|
|
|
return EINVAL;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDREAD2;
|
|
|
|
mbx.cmd.length = sizeof(mbx.cmd.data.play);
|
|
|
|
mbx.cmd.data.play.start_msf[0] = bin2bcd(p->start_m);
|
|
|
|
mbx.cmd.data.play.start_msf[1] = bin2bcd(p->start_s);
|
|
|
|
mbx.cmd.data.play.start_msf[2] = bin2bcd(p->start_f);
|
|
|
|
mbx.cmd.data.play.end_msf[0] = bin2bcd(p->end_m);
|
|
|
|
mbx.cmd.data.play.end_msf[1] = bin2bcd(p->end_s);
|
|
|
|
mbx.cmd.data.play.end_msf[2] = bin2bcd(p->end_f);
|
|
|
|
sc->lastpb = mbx.cmd;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 1);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_playblocks(sc, p)
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1995-03-27 19:45:20 +04:00
|
|
|
struct ioc_play_blocks *p;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
1995-03-27 19:45:20 +04:00
|
|
|
printf("%s: playblocks: blkno %d length %d\n",
|
|
|
|
sc->sc_dev.dv_xname, p->blk, p->len);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (p->blk > sc->disksize || p->len > sc->disksize ||
|
|
|
|
(p->blk + p->len) > sc->disksize)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDREAD2;
|
|
|
|
mbx.cmd.length = sizeof(mbx.cmd.data.play);
|
|
|
|
hsg2msf(p->blk, mbx.cmd.data.play.start_msf);
|
|
|
|
hsg2msf(p->blk + p->len, mbx.cmd.data.play.end_msf);
|
|
|
|
sc->lastpb = mbx.cmd;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 1);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_pause(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
union mcd_qchninfo q;
|
|
|
|
int error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Verify current status. */
|
|
|
|
if (sc->audio_status != CD_AS_PLAY_IN_PROGRESS) {
|
|
|
|
printf("%s: pause: attempted when not playing\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get the current position. */
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((error = mcd_getqchan(sc, &q, CD_CURRENT_POSITION)) != 0)
|
|
|
|
return error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Copy it into lastpb. */
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->lastpb.data.seek.start_msf[0] = q.current.absolute_pos[0];
|
|
|
|
sc->lastpb.data.seek.start_msf[1] = q.current.absolute_pos[1];
|
|
|
|
sc->lastpb.data.seek.start_msf[2] = q.current.absolute_pos[2];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Stop playing. */
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((error = mcd_stop(sc)) != 0)
|
|
|
|
return error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Set the proper status and exit. */
|
|
|
|
sc->audio_status = CD_AS_PLAY_PAUSED;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_resume(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->audio_status != CD_AS_PLAY_PAUSED)
|
|
|
|
return EINVAL;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
mbx.cmd = sc->lastpb;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mcd_eject(sc)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDEJECTDISK;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mcd_setlock(sc, mode)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDSETLOCK;
|
|
|
|
mbx.cmd.length = sizeof(mbx.cmd.data.lockmode);
|
|
|
|
mbx.cmd.data.lockmode.mode = mode;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 1);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|