2021-09-10 02:26:36 +03:00
|
|
|
/* $NetBSD: mcd.c,v 1.121 2021/09/09 23:26:36 riastradh 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
|
|
|
|
2001-11-13 11:01:09 +03:00
|
|
|
#include <sys/cdefs.h>
|
2021-09-10 02:26:36 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mcd.c,v 1.121 2021/09/09 23:26:36 riastradh Exp $");
|
2001-11-13 11:01:09 +03:00
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.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>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#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>
|
2007-12-05 10:58:29 +03:00
|
|
|
#include <sys/mutex.h>
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/cpu.h>
|
|
|
|
#include <sys/intr.h>
|
|
|
|
#include <sys/bus.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/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
|
2006-04-14 03:16:33 +04:00
|
|
|
#define MCD_TRACE(fmt,...)
|
1993-11-04 12:12:30 +03:00
|
|
|
#else
|
2012-10-27 21:17:22 +04:00
|
|
|
#define MCD_TRACE(fmt,...) {if (sc->debug) {printf("%s: st=%02x: ", device_xname(sc->sc_dev), sc->status); printf(fmt,__VA_ARGS__);}}
|
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 */
|
|
|
|
|
1998-06-23 07:26:18 +04:00
|
|
|
/* control promiscuous match */
|
|
|
|
#include "opt_mcd_promisc.h"
|
|
|
|
|
|
|
|
#ifdef MCD_PROMISC
|
|
|
|
int mcd_promisc = 1;
|
|
|
|
#else
|
|
|
|
int mcd_promisc = 0;
|
|
|
|
#endif
|
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
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 {
|
2012-10-27 21:17:22 +04:00
|
|
|
device_t sc_dev;
|
1996-01-08 01:01:38 +03:00
|
|
|
struct disk sc_dk;
|
2007-12-05 10:58:29 +03:00
|
|
|
kmutex_t sc_lock;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_t sc_pintr_ch;
|
2000-03-23 10:01:25 +03:00
|
|
|
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_tag_t sc_iot;
|
|
|
|
bus_space_handle_t sc_ioh;
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
int irq, drq;
|
|
|
|
|
2006-04-14 03:16:33 +04:00
|
|
|
const char *type;
|
1995-03-27 19:45:20 +04:00
|
|
|
int flags;
|
|
|
|
#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
|
2005-10-15 21:29:10 +04:00
|
|
|
struct bufq_state *buf_queue;
|
2000-01-22 02:39:55 +03:00
|
|
|
int active;
|
1997-04-04 22:59:35 +04:00
|
|
|
u_char readcmd;
|
|
|
|
u_char debug;
|
|
|
|
u_char probe;
|
1994-03-29 08:35:37 +04:00
|
|
|
};
|
1993-11-04 12:12:30 +03:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
static int bcd2bin(bcd_t);
|
|
|
|
static bcd_t bin2bcd(int);
|
|
|
|
static void hsg2msf(int, bcd_t *);
|
|
|
|
static daddr_t msf2hsg(bcd_t *, int);
|
|
|
|
|
|
|
|
int mcd_playtracks(struct mcd_softc *, struct ioc_play_track *);
|
|
|
|
int mcd_playmsf(struct mcd_softc *, struct ioc_play_msf *);
|
|
|
|
int mcd_playblocks(struct mcd_softc *, struct ioc_play_blocks *);
|
|
|
|
int mcd_stop(struct mcd_softc *);
|
|
|
|
int mcd_eject(struct mcd_softc *);
|
2007-07-01 02:16:38 +04:00
|
|
|
int mcd_read_subchannel(struct mcd_softc *, struct ioc_read_subchannel *,
|
|
|
|
struct cd_sub_channel_info *);
|
2005-02-04 05:10:35 +03:00
|
|
|
int mcd_pause(struct mcd_softc *);
|
|
|
|
int mcd_resume(struct mcd_softc *);
|
|
|
|
int mcd_toc_header(struct mcd_softc *, struct ioc_toc_header *);
|
2007-07-01 02:16:38 +04:00
|
|
|
int mcd_toc_entries(struct mcd_softc *, struct ioc_read_toc_entry *,
|
|
|
|
struct cd_toc_entry *, int *);
|
2005-02-04 05:10:35 +03:00
|
|
|
|
|
|
|
int mcd_getreply(struct mcd_softc *);
|
|
|
|
int mcd_getstat(struct mcd_softc *);
|
|
|
|
int mcd_getresult(struct mcd_softc *, struct mcd_result *);
|
|
|
|
void mcd_setflags(struct mcd_softc *);
|
|
|
|
int mcd_get(struct mcd_softc *, char *, int);
|
|
|
|
int mcd_send(struct mcd_softc *, struct mcd_mbox *, int);
|
|
|
|
int mcdintr(void *);
|
|
|
|
void mcd_soft_reset(struct mcd_softc *);
|
|
|
|
int mcd_hard_reset(struct mcd_softc *);
|
|
|
|
int mcd_setmode(struct mcd_softc *, int);
|
|
|
|
int mcd_setupc(struct mcd_softc *, int);
|
|
|
|
int mcd_read_toc(struct mcd_softc *);
|
|
|
|
int mcd_getqchan(struct mcd_softc *, union mcd_qchninfo *, int);
|
|
|
|
int mcd_setlock(struct mcd_softc *, int);
|
|
|
|
|
|
|
|
int mcd_find(bus_space_tag_t, bus_space_handle_t, struct mcd_softc *);
|
2009-05-12 13:10:15 +04:00
|
|
|
int mcdprobe(device_t, cfdata_t, void *);
|
|
|
|
void mcdattach(device_t, device_t, void *);
|
1994-03-29 08:35:37 +04:00
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
CFATTACH_DECL_NEW(mcd, sizeof(struct mcd_softc),
|
2002-10-02 07:10:45 +04:00
|
|
|
mcdprobe, mcdattach, NULL, NULL);
|
1996-03-17 03:43:52 +03:00
|
|
|
|
1998-01-12 12:39:57 +03:00
|
|
|
extern struct cfdriver mcd_cd;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(mcdopen);
|
|
|
|
dev_type_close(mcdclose);
|
|
|
|
dev_type_read(mcdread);
|
|
|
|
dev_type_write(mcdwrite);
|
|
|
|
dev_type_ioctl(mcdioctl);
|
|
|
|
dev_type_strategy(mcdstrategy);
|
|
|
|
dev_type_dump(mcddump);
|
|
|
|
dev_type_size(mcdsize);
|
|
|
|
|
|
|
|
const struct bdevsw mcd_bdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = mcdopen,
|
|
|
|
.d_close = mcdclose,
|
|
|
|
.d_strategy = mcdstrategy,
|
|
|
|
.d_ioctl = mcdioctl,
|
|
|
|
.d_dump = mcddump,
|
|
|
|
.d_psize = mcdsize,
|
2014-07-25 12:02:18 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw mcd_cdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = mcdopen,
|
|
|
|
.d_close = mcdclose,
|
|
|
|
.d_read = mcdread,
|
|
|
|
.d_write = mcdwrite,
|
|
|
|
.d_ioctl = mcdioctl,
|
|
|
|
.d_stop = nostop,
|
|
|
|
.d_tty = notty,
|
|
|
|
.d_poll = nopoll,
|
|
|
|
.d_mmap = nommap,
|
|
|
|
.d_kqfilter = nokqfilter,
|
2014-07-25 12:10:31 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
void mcdgetdefaultlabel(struct mcd_softc *, struct disklabel *);
|
|
|
|
void mcdgetdisklabel(struct mcd_softc *);
|
|
|
|
int mcd_get_parms(struct mcd_softc *);
|
|
|
|
void mcdstart(struct mcd_softc *);
|
|
|
|
void mcd_pseudointr(void *);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
2015-04-26 18:15:19 +03:00
|
|
|
struct dkdriver mcddkdriver = {
|
|
|
|
.d_strategy = 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
|
2009-05-12 13:10:15 +04:00
|
|
|
mcdattach(device_t parent, device_t self, void *aux)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
2012-10-27 21:17:22 +04:00
|
|
|
struct mcd_softc *sc = device_private(self);
|
1994-03-29 08:35:37 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_mbox mbx;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
2019-11-12 16:17:43 +03:00
|
|
|
sc->sc_dev = self;
|
2016-07-14 13:19:05 +03:00
|
|
|
aprint_naive("\n");
|
|
|
|
|
1997-04-04 22:59:35 +04:00
|
|
|
/* Map i/o space */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(iot, ia->ia_io[0].ir_addr, MCD_NPORT, 0, &ioh)) {
|
2016-07-14 13:19:05 +03:00
|
|
|
aprint_error(": can't map i/o space\n");
|
1997-10-20 22:43:03 +04:00
|
|
|
return;
|
|
|
|
}
|
1997-04-04 22:59:35 +04:00
|
|
|
|
2007-12-05 10:58:29 +03:00
|
|
|
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
|
2003-11-07 07:10:56 +03:00
|
|
|
|
1997-04-04 22:59:35 +04:00
|
|
|
sc->sc_iot = iot;
|
|
|
|
sc->sc_ioh = ioh;
|
|
|
|
|
|
|
|
sc->probe = 0;
|
|
|
|
sc->debug = 0;
|
|
|
|
|
1997-10-20 22:43:03 +04:00
|
|
|
if (!mcd_find(iot, ioh, sc)) {
|
2016-07-14 13:19:05 +03:00
|
|
|
aprint_error(": mcd_find failed\n");
|
1997-11-12 01:43:51 +03:00
|
|
|
return;
|
1997-10-20 22:43:03 +04:00
|
|
|
}
|
1997-04-04 22:59:35 +04:00
|
|
|
|
2005-10-15 21:29:10 +04:00
|
|
|
bufq_alloc(&sc->buf_queue, "disksort", BUFQ_SORT_RAWBLOCK);
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_init(&sc->sc_pintr_ch, 0);
|
2000-01-22 02:39:55 +03:00
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/*
|
|
|
|
* Initialize and attach the disk structure.
|
|
|
|
*/
|
2012-10-27 21:17:22 +04:00
|
|
|
disk_init(&sc->sc_dk, device_xname(sc->sc_dev), &mcddkdriver);
|
1996-01-08 01:01:38 +03:00
|
|
|
disk_attach(&sc->sc_dk);
|
|
|
|
|
2016-07-14 13:19:05 +03:00
|
|
|
aprint_normal(": model %s\n", sc->type != 0 ? sc->type : "unknown");
|
1995-03-27 19:45:20 +04:00
|
|
|
|
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
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
|
|
|
|
IST_EDGE, IPL_BIO, mcdintr, sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
mcdopen(dev_t dev, int flag, int fmt, struct lwp *l)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
2000-07-06 06:02:48 +04:00
|
|
|
int error, part;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc *sc;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
2008-06-08 16:43:51 +04:00
|
|
|
sc = device_lookup_private(&mcd_cd, MCDUNIT(dev));
|
2000-07-06 06:02:48 +04:00
|
|
|
if (sc == NULL)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
2007-12-05 10:58:29 +03:00
|
|
|
mutex_enter(&sc->sc_lock);
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1995-04-01 12:45:33 +04:00
|
|
|
part = MCDPART(dev);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2006-04-14 03:16:33 +04:00
|
|
|
MCD_TRACE("open: partition=%d disksize=%ld blksize=%d\n", part,
|
|
|
|
sc->disksize, sc->blksize);
|
|
|
|
|
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 &&
|
1996-01-08 01:01:38 +03:00
|
|
|
(part >= sc->sc_dk.dk_label->d_npartitions ||
|
|
|
|
sc->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
|
1995-03-27 19:45:20 +04:00
|
|
|
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;
|
|
|
|
|
2007-12-05 10:58:29 +03:00
|
|
|
mutex_exit(&sc->sc_lock);
|
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:
|
2007-12-05 10:58:29 +03:00
|
|
|
mutex_exit(&sc->sc_lock);
|
1995-03-27 19:45:20 +04:00
|
|
|
return error;
|
1994-02-21 18:23:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
mcdclose(dev_t dev, int flag, int fmt, struct lwp *l)
|
1994-02-21 18:23:11 +03:00
|
|
|
{
|
2008-06-08 16:43:51 +04:00
|
|
|
struct mcd_softc *sc = device_lookup_private(&mcd_cd, MCDUNIT(dev));
|
1994-10-29 02:39:59 +03:00
|
|
|
int part = MCDPART(dev);
|
2016-07-14 13:19:05 +03:00
|
|
|
|
2006-04-14 03:16:33 +04:00
|
|
|
MCD_TRACE("close: partition=%d\n", part);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
2007-12-05 10:58:29 +03:00
|
|
|
mutex_enter(&sc->sc_lock);
|
1995-04-01 12:45:33 +04:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-12-05 10:58:29 +03:00
|
|
|
mutex_exit(&sc->sc_lock);
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
mcdstrategy(struct buf *bp)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
2008-06-08 16:43:51 +04:00
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct disklabel *lp;
|
2000-02-07 23:16:47 +03:00
|
|
|
daddr_t blkno;
|
1993-11-04 12:12:30 +03:00
|
|
|
int s;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2008-06-08 16:43:51 +04:00
|
|
|
sc = device_lookup_private(&mcd_cd, MCDUNIT(bp->b_dev));
|
|
|
|
lp = sc->sc_dk.dk_label;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Test validity. */
|
2020-02-24 15:20:29 +03:00
|
|
|
MCD_TRACE("strategy: buf=%p blkno=%d bcount=%d\n", bp,
|
2006-04-14 03:16:33 +04:00
|
|
|
(int) bp->b_blkno, bp->b_bcount);
|
1995-03-27 19:45:20 +04:00
|
|
|
if (bp->b_blkno < 0 ||
|
|
|
|
(bp->b_bcount % sc->blksize) != 0) {
|
2006-04-14 03:16:33 +04:00
|
|
|
printf("%s: strategy: blkno = %" PRId64 " bcount = %d\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev), bp->b_blkno, bp->b_bcount);
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_error = EINVAL;
|
2007-07-29 16:50:17 +04:00
|
|
|
goto done;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
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) {
|
2006-04-14 03:16:33 +04:00
|
|
|
MCD_TRACE("strategy: drive not valid%s", "\n");
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_error = EIO;
|
2007-07-29 16:50:17 +04:00
|
|
|
goto done;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
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;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/*
|
|
|
|
* Do bounds checking, adjust transfer. if error, process.
|
|
|
|
* If end of partition, just return.
|
|
|
|
*/
|
1995-04-15 09:01:26 +04:00
|
|
|
if (MCDPART(bp->b_dev) != RAW_PART &&
|
2003-05-11 03:12:28 +04:00
|
|
|
bounds_check_with_label(&sc->sc_dk, bp,
|
1995-03-27 19:45:20 +04:00
|
|
|
(sc->flags & (MCDF_WLABEL|MCDF_LABELLING)) != 0) <= 0)
|
|
|
|
goto done;
|
2000-02-07 23:16:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now convert the block number to absolute and put it in
|
|
|
|
* terms of the device's logical block size.
|
|
|
|
*/
|
|
|
|
blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
|
|
|
|
if (MCDPART(bp->b_dev) != RAW_PART)
|
|
|
|
blkno += lp->d_partitions[MCDPART(bp->b_dev)].p_offset;
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
bp->b_rawblkno = blkno;
|
2000-02-07 23:16:47 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Queue it. */
|
1993-11-04 12:12:30 +03:00
|
|
|
s = splbio();
|
2009-01-13 16:33:58 +03:00
|
|
|
bufq_put(sc->buf_queue, bp);
|
1993-11-04 12:12:30 +03:00
|
|
|
splx(s);
|
2000-01-22 02:39:55 +03:00
|
|
|
if (!sc->active)
|
1995-03-27 19:45:20 +04:00
|
|
|
mcdstart(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
done:
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
mcdstart(struct mcd_softc *sc)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
2000-01-22 02:39:55 +03:00
|
|
|
struct buf *bp;
|
1994-10-29 02:39:59 +03:00
|
|
|
int s;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1994-10-29 02:39:59 +03:00
|
|
|
loop:
|
|
|
|
s = splbio();
|
|
|
|
|
2009-01-13 16:33:58 +03:00
|
|
|
if ((bp = bufq_get(sc->buf_queue)) == NULL) {
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Nothing to do. */
|
2000-01-22 02:39:55 +03:00
|
|
|
sc->active = 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-24 23:34:57 +04:00
|
|
|
/* Block found to process. */
|
2020-02-24 15:20:29 +03:00
|
|
|
MCD_TRACE("start: found block bp=%p\n", bp);
|
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) {
|
2006-04-14 03:16:33 +04:00
|
|
|
MCD_TRACE("start: drive not valid%s", "\n");
|
1994-10-29 02:39:59 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
biodone(bp);
|
|
|
|
goto loop;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
2000-01-22 02:39:55 +03:00
|
|
|
sc->active = 1;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/* Instrumentation. */
|
|
|
|
s = splbio();
|
|
|
|
disk_busy(&sc->sc_dk);
|
|
|
|
splx(s);
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
sc->mbx.retry = MCD_RDRETRIES;
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->mbx.bp = bp;
|
2000-02-07 23:16:47 +03:00
|
|
|
sc->mbx.blkno = bp->b_rawblkno;
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
1995-07-05 06:32:53 +04:00
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
mcdread(dev_t dev, struct uio *uio, int flags)
|
1995-07-05 06:32:53 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(mcdstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
mcdwrite(dev_t dev, struct uio *uio, int flags)
|
1995-07-05 06:32:53 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(mcdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
mcdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
2008-06-08 16:43:51 +04:00
|
|
|
struct mcd_softc *sc = device_lookup_private(&mcd_cd, MCDUNIT(dev));
|
1995-03-27 19:45:20 +04:00
|
|
|
int error;
|
1999-02-08 19:33:16 +03:00
|
|
|
int part;
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
struct disklabel newlabel;
|
|
|
|
#endif
|
2016-07-14 13:19:05 +03:00
|
|
|
|
2006-04-14 03:16:33 +04:00
|
|
|
MCD_TRACE("ioctl: cmd=0x%lx\n", cmd);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((sc->flags & MCDF_LOADED) == 0)
|
|
|
|
return EIO;
|
|
|
|
|
2014-12-31 22:52:04 +03:00
|
|
|
error = disk_ioctl(&sc->sc_dk, dev, cmd, addr, flag, l);
|
|
|
|
if (error != EPASSTHROUGH)
|
|
|
|
return error;
|
|
|
|
|
1999-02-08 19:33:16 +03:00
|
|
|
part = MCDPART(dev);
|
1993-11-04 12:12:30 +03:00
|
|
|
switch (cmd) {
|
1995-03-27 19:45:20 +04:00
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
case ODIOCSDINFO:
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct disklabel *lp;
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
|
|
|
|
memset(&newlabel, 0, sizeof newlabel);
|
|
|
|
memcpy(&newlabel, addr, sizeof (struct olddisklabel));
|
|
|
|
lp = &newlabel;
|
|
|
|
} else
|
|
|
|
#endif
|
2007-07-01 02:16:38 +04:00
|
|
|
lp = addr;
|
2001-01-07 21:09:01 +03:00
|
|
|
|
2007-12-05 10:58:29 +03:00
|
|
|
mutex_enter(&sc->sc_lock);
|
1995-04-01 12:45:33 +04:00
|
|
|
sc->flags |= MCDF_LABELLING;
|
1995-03-27 19:45:20 +04:00
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
error = setdisklabel(sc->sc_dk.dk_label,
|
2001-01-07 21:09:01 +03:00
|
|
|
lp, /*sc->sc_dk.dk_openmask : */0,
|
1996-01-08 01:01:38 +03:00
|
|
|
sc->sc_dk.dk_cpulabel);
|
1995-03-27 19:45:20 +04:00
|
|
|
if (error == 0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->flags &= ~MCDF_LABELLING;
|
2007-12-05 10:58:29 +03:00
|
|
|
mutex_exit(&sc->sc_lock);
|
1995-03-27 19:45:20 +04:00
|
|
|
return error;
|
2001-01-07 21:09:01 +03:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
return EBADF;
|
|
|
|
|
1997-10-09 03:05:22 +04:00
|
|
|
case DIOCGDEFLABEL:
|
2007-07-01 02:16:38 +04:00
|
|
|
mcdgetdefaultlabel(sc, addr);
|
1997-10-09 03:05:22 +04:00
|
|
|
return 0;
|
|
|
|
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDEFLABEL:
|
|
|
|
mcdgetdefaultlabel(sc, &newlabel);
|
|
|
|
if (newlabel.d_npartitions > OLDMAXPARTITIONS)
|
2001-01-08 05:03:45 +03:00
|
|
|
return ENOTTY;
|
2001-01-07 21:09:01 +03:00
|
|
|
memcpy(addr, &newlabel, sizeof (struct olddisklabel));
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCPLAYTRACKS:
|
2007-07-01 02:16:38 +04:00
|
|
|
return mcd_playtracks(sc, addr);
|
1995-03-27 19:45:20 +04:00
|
|
|
case CDIOCPLAYMSF:
|
2007-07-01 02:16:38 +04:00
|
|
|
return mcd_playmsf(sc, addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCPLAYBLOCKS:
|
2007-07-01 02:16:38 +04:00
|
|
|
return mcd_playblocks(sc, addr);
|
|
|
|
case CDIOCREADSUBCHANNEL: {
|
|
|
|
struct cd_sub_channel_info info;
|
|
|
|
error = mcd_read_subchannel(sc, addr, &info);
|
|
|
|
if (error != 0) {
|
|
|
|
struct ioc_read_subchannel *ch = addr;
|
|
|
|
error = copyout(&info, ch->data, ch->data_len);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
case CDIOCREADSUBCHANNEL_BUF:
|
|
|
|
return mcd_read_subchannel(sc, addr,
|
|
|
|
&((struct ioc_read_subchannel_buf *)addr)->info);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOREADTOCHEADER:
|
2007-07-01 02:16:38 +04:00
|
|
|
return mcd_toc_header(sc, addr);
|
|
|
|
case CDIOREADTOCENTRYS: {
|
|
|
|
struct cd_toc_entry entries[MCD_MAXTOCS];
|
|
|
|
struct ioc_read_toc_entry *te = addr;
|
|
|
|
int count;
|
|
|
|
if (te->data_len > sizeof entries)
|
|
|
|
return EINVAL;
|
|
|
|
error = mcd_toc_entries(sc, te, entries, &count);
|
|
|
|
if (error == 0)
|
|
|
|
/* Copy the data back. */
|
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.
To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 19:29:22 +03:00
|
|
|
error = copyout(entries, te->data, uimin(te->data_len,
|
2007-07-01 02:16:38 +04:00
|
|
|
count * sizeof(struct cd_toc_entry)));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
case CDIOREADTOCENTRIES_BUF: {
|
|
|
|
struct ioc_read_toc_entry_buf *te = addr;
|
|
|
|
int count;
|
|
|
|
if (te->req.data_len > sizeof te->entry)
|
|
|
|
return EINVAL;
|
|
|
|
return mcd_toc_entries(sc, &te->req, te->entry, &count);
|
|
|
|
}
|
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);
|
1996-01-30 21:28:02 +03:00
|
|
|
case DIOCEJECT:
|
1999-02-08 19:33:16 +03:00
|
|
|
if (*(int *)addr == 0) {
|
|
|
|
/*
|
|
|
|
* Don't force eject: check that we are the only
|
|
|
|
* partition open. If so, unlock it.
|
|
|
|
*/
|
|
|
|
if ((sc->sc_dk.dk_openmask & ~(1 << part)) == 0 &&
|
|
|
|
sc->sc_dk.dk_bopenmask + sc->sc_dk.dk_copenmask ==
|
|
|
|
sc->sc_dk.dk_openmask) {
|
|
|
|
error = mcd_setlock(sc, MCD_LK_UNLOCK);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
} else {
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case CDIOCEJECT: /* FALLTHROUGH */
|
|
|
|
case ODIOCEJECT:
|
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);
|
1996-01-30 21:28:02 +03:00
|
|
|
case DIOCLOCK:
|
|
|
|
return mcd_setlock(sc,
|
|
|
|
(*(int *)addr) ? MCD_LK_LOCK : MCD_LK_UNLOCK);
|
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
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
mcdgetdefaultlabel(struct mcd_softc *sc, struct disklabel *lp)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1997-10-09 03:05:22 +04:00
|
|
|
|
2001-07-19 00:39:53 +04:00
|
|
|
memset(lp, 0, sizeof(struct disklabel));
|
1995-03-27 19:45:20 +04:00
|
|
|
|
1995-08-06 03:47:52 +04:00
|
|
|
lp->d_secsize = sc->blksize;
|
|
|
|
lp->d_ntracks = 1;
|
|
|
|
lp->d_nsectors = 100;
|
|
|
|
lp->d_ncylinders = (sc->disksize / 100) + 1;
|
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
|
|
|
|
|
|
|
strncpy(lp->d_typename, "Mitsumi CD-ROM", 16);
|
|
|
|
lp->d_type = 0; /* XXX */
|
|
|
|
strncpy(lp->d_packname, "fictitious", 16);
|
|
|
|
lp->d_secperunit = sc->disksize;
|
|
|
|
lp->d_rpm = 300;
|
|
|
|
lp->d_interleave = 1;
|
|
|
|
lp->d_flags = D_REMOVABLE;
|
|
|
|
|
|
|
|
lp->d_partitions[0].p_offset = 0;
|
|
|
|
lp->d_partitions[0].p_size =
|
|
|
|
lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
|
|
|
|
lp->d_partitions[0].p_fstype = FS_ISO9660;
|
|
|
|
lp->d_partitions[RAW_PART].p_offset = 0;
|
|
|
|
lp->d_partitions[RAW_PART].p_size =
|
|
|
|
lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
|
|
|
|
lp->d_partitions[RAW_PART].p_fstype = FS_ISO9660;
|
|
|
|
lp->d_npartitions = RAW_PART + 1;
|
1997-10-09 03:05:22 +04:00
|
|
|
|
1995-08-06 03:47:52 +04:00
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
1995-03-27 19:45:20 +04:00
|
|
|
}
|
|
|
|
|
1997-10-09 03:05:22 +04:00
|
|
|
/*
|
|
|
|
* This could have been taken from scsi/cd.c, but it is not clear
|
|
|
|
* whether the scsi cd driver is linked in.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
mcdgetdisklabel(struct mcd_softc *sc)
|
1997-10-09 03:05:22 +04:00
|
|
|
{
|
|
|
|
struct disklabel *lp = sc->sc_dk.dk_label;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2001-07-19 00:39:53 +04:00
|
|
|
memset(sc->sc_dk.dk_cpulabel, 0, sizeof(struct cpu_disklabel));
|
1997-10-09 03:05:22 +04:00
|
|
|
|
|
|
|
mcdgetdefaultlabel(sc, lp);
|
|
|
|
}
|
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_get_parms(struct mcd_softc *sc)
|
1995-03-27 19:45:20 +04:00
|
|
|
{
|
|
|
|
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
|
2006-11-16 04:32:37 +03:00
|
|
|
mcdsize(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
|
2007-03-04 08:59:00 +03:00
|
|
|
mcddump(dev_t dev, daddr_t blkno, void *va,
|
2006-11-16 04:32:37 +03:00
|
|
|
size_t size)
|
1994-05-11 13:49:17 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Not implemented. */
|
1995-06-26 09:34:44 +04:00
|
|
|
return ENXIO;
|
1994-05-11 13:49:17 +04:00
|
|
|
}
|
|
|
|
|
1997-04-04 22:59:35 +04:00
|
|
|
/*
|
|
|
|
* Find the board and fill in the softc.
|
|
|
|
*/
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_find(bus_space_tag_t iot, bus_space_handle_t ioh, struct mcd_softc *sc)
|
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
|
|
|
|
1997-04-04 22:59:35 +04:00
|
|
|
sc->sc_iot = iot;
|
|
|
|
sc->sc_ioh = ioh;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Send a reset. */
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_write_1(iot, ioh, 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--)
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_read_1(iot, ioh, 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-07-10 05:27:24 +04:00
|
|
|
sc->readcmd = MCD_CMDREADSINGLESPEED;
|
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";
|
1995-07-10 05:27:24 +04:00
|
|
|
sc->readcmd = MCD_CMDREADDOUBLESPEED;
|
1995-03-27 19:45:20 +04:00
|
|
|
break;
|
|
|
|
default:
|
1998-06-23 07:26:18 +04:00
|
|
|
/*
|
|
|
|
* mcd_send() says the response looked OK but the
|
|
|
|
* drive type is unknown. If mcd_promisc, match anyway.
|
|
|
|
*/
|
|
|
|
if (mcd_promisc != 0)
|
|
|
|
return 0;
|
|
|
|
|
1996-11-05 10:17:23 +03:00
|
|
|
#ifdef MCDDEBUG
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: unrecognized drive version %c%02x; will try to use it anyway\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev),
|
1995-03-27 19:45:20 +04:00
|
|
|
mbx.res.data.continfo.code, mbx.res.data.continfo.version);
|
1996-11-05 10:17:23 +03:00
|
|
|
#endif
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
|
|
return 1;
|
1997-04-04 22:59:35 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-05-12 13:10:15 +04:00
|
|
|
mcdprobe(device_t parent, cfdata_t match, void *aux)
|
1997-04-04 22:59:35 +04:00
|
|
|
{
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
struct mcd_softc sc;
|
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
int rv;
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_nio < 1)
|
|
|
|
return (0);
|
|
|
|
if (ia->ia_nirq < 1)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (ISA_DIRECT_CONFIG(ia))
|
|
|
|
return (0);
|
|
|
|
|
1997-10-19 22:56:39 +04:00
|
|
|
/* Disallow wildcarded i/o address. */
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
|
2002-01-08 00:46:56 +03:00
|
|
|
return (0);
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
|
1997-10-19 22:56:39 +04:00
|
|
|
return (0);
|
|
|
|
|
1997-04-04 22:59:35 +04:00
|
|
|
/* Map i/o space */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(iot, ia->ia_io[0].ir_addr, MCD_NPORT, 0, &ioh))
|
1997-04-04 22:59:35 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
sc.debug = 0;
|
|
|
|
sc.probe = 1;
|
|
|
|
|
|
|
|
rv = mcd_find(iot, ioh, &sc);
|
|
|
|
|
|
|
|
bus_space_unmap(iot, ioh, MCD_NPORT);
|
|
|
|
|
|
|
|
if (rv) {
|
2002-01-08 00:46:56 +03:00
|
|
|
ia->ia_nio = 1;
|
2005-03-13 01:54:48 +03:00
|
|
|
ia->ia_io[0].ir_size = MCD_NPORT;
|
2002-01-08 00:46:56 +03:00
|
|
|
|
|
|
|
ia->ia_nirq = 1;
|
|
|
|
|
|
|
|
ia->ia_niomem = 0;
|
|
|
|
ia->ia_ndrq = 0;
|
1997-04-04 22:59:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (rv);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_getreply(struct mcd_softc *sc)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
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--) {
|
1997-04-04 22:59:35 +04:00
|
|
|
if ((bus_space_read_1(iot, ioh, MCD_XFER) &
|
|
|
|
MCD_XF_STATUSUNAVAIL) == 0)
|
1995-03-27 19:45:20 +04:00
|
|
|
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. */
|
1997-04-04 22:59:35 +04:00
|
|
|
return bus_space_read_1(iot, ioh, MCD_STATUS);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_getstat(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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_getresult(struct mcd_softc *sc, 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)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: mcd_getresult: %d", device_xname(sc->sc_dev),
|
1995-03-27 19:45:20 +04:00
|
|
|
res->length);
|
|
|
|
|
|
|
|
if ((x = mcd_getreply(sc)) < 0) {
|
|
|
|
if (sc->debug)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" timeout\n");
|
1997-04-04 22:59:35 +04:00
|
|
|
else if (!sc->probe)
|
2016-07-14 13:19:05 +03:00
|
|
|
printf("%s: timeout in getresult\n",
|
|
|
|
device_xname(sc->sc_dev));
|
1995-03-27 19:45:20 +04:00
|
|
|
return EIO;
|
1994-02-21 18:23:11 +03:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->debug)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" %02x", (u_int)x);
|
1995-03-27 19:45:20 +04:00
|
|
|
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)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" timeout\n");
|
1995-03-27 19:45:20 +04:00
|
|
|
else
|
2016-07-14 13:19:05 +03:00
|
|
|
printf("%s: timeout in getresult\n",
|
|
|
|
device_xname(sc->sc_dev));
|
1995-03-27 19:45:20 +04:00
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
if (sc->debug)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" %02x", (u_int)x);
|
1995-03-27 19:45:20 +04:00
|
|
|
res->data.raw.data[i] = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->debug)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" succeeded\n");
|
1995-03-27 19:45:20 +04:00
|
|
|
|
1995-04-27 05:46:47 +04:00
|
|
|
#ifdef MCDDEBUG
|
1995-03-27 19:45:20 +04:00
|
|
|
delay(10);
|
1997-04-04 22:59:35 +04:00
|
|
|
while ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, MCD_XFER) &
|
|
|
|
MCD_XF_STATUSUNAVAIL) == 0) {
|
|
|
|
x = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MCD_STATUS);
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: got extra byte %02x during getstatus\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev), (u_int)x);
|
1995-03-27 19:45:20 +04:00
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_setflags(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)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: door open\n", device_xname(sc->sc_dev));
|
1995-03-27 19:45:20 +04:00
|
|
|
else if ((sc->status & MCD_ST_DSKIN) == 0)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: no disk present\n", device_xname(sc->sc_dev));
|
1995-03-27 19:45:20 +04:00
|
|
|
else if ((sc->status & MCD_ST_DSKCHNG) != 0)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: media change\n", device_xname(sc->sc_dev));
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_send(struct mcd_softc *sc, struct mcd_mbox *mbx, int diskin)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
int retry, i, error;
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->debug) {
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: mcd_send: %d %02x", device_xname(sc->sc_dev),
|
1995-03-27 19:45:20 +04:00
|
|
|
mbx->cmd.length, (u_int)mbx->cmd.opcode);
|
|
|
|
for (i = 0; i < mbx->cmd.length; i++)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" %02x", (u_int)mbx->cmd.data.raw.data[i]);
|
|
|
|
printf("\n");
|
1995-03-27 19:45:20 +04:00
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
for (retry = MCD_RETRIES; retry; retry--) {
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->cmd.opcode);
|
1995-03-27 19:45:20 +04:00
|
|
|
for (i = 0; i < mbx->cmd.length; i++)
|
2016-07-14 13:19:05 +03:00
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND,
|
|
|
|
mbx->cmd.data.raw.data[i]);
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
bcd2bin(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
|
2009-03-14 18:35:58 +03:00
|
|
|
bin2bcd(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
|
2009-03-14 18:35:58 +03:00
|
|
|
hsg2msf(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
|
2009-03-14 18:35:58 +03:00
|
|
|
msf2hsg(bcd_t *msf, 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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_pseudointr(void *v)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1996-04-30 00:28:40 +04:00
|
|
|
struct mcd_softc *sc = v;
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcdintr(void *arg)
|
1994-05-05 09:35:42 +04:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
struct mcd_softc *sc = arg;
|
|
|
|
struct mcd_mbx *mbx = &sc->mbx;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct buf *bp = mbx->bp;
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
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;
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND, MCD_CMDSETMODE);
|
|
|
|
bus_space_write_1(iot, ioh, 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
|
|
|
|
2019-02-24 23:50:03 +03:00
|
|
|
/* FALLTHROUGH */
|
1993-11-04 12:12:30 +03:00
|
|
|
case MCD_S_WAITMODE:
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_pintr_ch);
|
1995-03-27 19:45:20 +04:00
|
|
|
for (i = 20; i; i--) {
|
1997-04-04 22:59:35 +04:00
|
|
|
x = bus_space_read_1(iot, ioh, MCD_XFER);
|
1995-03-27 19:45:20 +04:00
|
|
|
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;
|
1997-04-04 22:59:35 +04:00
|
|
|
sc->status = bus_space_read_1(iot, ioh, 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",
|
2006-04-14 03:16:33 +04:00
|
|
|
RDELAY_WAITMODE - mbx->count);
|
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:
|
2020-02-24 15:20:29 +03:00
|
|
|
MCD_TRACE("doread: read blkno=%d for bp=%p\n",
|
2006-04-14 03:16:33 +04:00
|
|
|
(int) mbx->blkno, bp);
|
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. */
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND, sc->readcmd);
|
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND, msf[0]);
|
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND, msf[1]);
|
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND, msf[2]);
|
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND, 0);
|
|
|
|
bus_space_write_1(iot, ioh, MCD_COMMAND, 0);
|
|
|
|
bus_space_write_1(iot, ioh, 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
|
|
|
|
2019-02-24 23:50:03 +03:00
|
|
|
/* FALLTHROUGH */
|
1993-11-04 12:12:30 +03:00
|
|
|
case MCD_S_WAITREAD:
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_pintr_ch);
|
1995-03-27 19:45:20 +04:00
|
|
|
nextblock:
|
|
|
|
loop:
|
|
|
|
for (i = 20; i; i--) {
|
1997-04-04 22:59:35 +04:00
|
|
|
x = bus_space_read_1(iot, ioh, MCD_XFER);
|
1995-03-27 19:45:20 +04:00
|
|
|
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;
|
1997-04-04 22:59:35 +04:00
|
|
|
sc->status = bus_space_read_1(iot, ioh, MCD_STATUS);
|
1995-03-27 19:45:20 +04:00
|
|
|
mcd_setflags(sc);
|
|
|
|
if ((sc->flags & MCDF_LOADED) == 0)
|
|
|
|
goto changed;
|
|
|
|
#if 0
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: got status byte %02x during read\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev), (u_int)sc->status);
|
1995-03-27 19:45:20 +04:00
|
|
|
#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",
|
2006-04-14 03:16:33 +04:00
|
|
|
RDELAY_WAITREAD - mbx->count);
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
/* Data is ready. */
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_write_1(iot, ioh, MCD_CTL2, 0x04); /* XXX */
|
|
|
|
bus_space_read_multi_1(iot, ioh, MCD_RDATA,
|
2007-03-04 08:59:00 +03:00
|
|
|
(char *)bp->b_data + mbx->skip, mbx->sz);
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_write_1(iot, ioh, MCD_CTL2, 0x0c); /* XXX */
|
1995-03-27 19:45:20 +04:00
|
|
|
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;
|
2002-11-01 14:31:50 +03:00
|
|
|
disk_unbusy(&sc->sc_dk, bp->b_bcount, (bp->b_flags & B_READ));
|
1995-03-27 19:45:20 +04:00
|
|
|
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) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: timeout in state %d",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev), mbx->state);
|
1995-03-27 19:45:20 +04:00
|
|
|
goto readerr;
|
1994-05-05 12:26:13 +04:00
|
|
|
}
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
#if 0
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: sleep in state %d\n", device_xname(sc->sc_dev),
|
1995-03-27 19:45:20 +04:00
|
|
|
mbx->state);
|
|
|
|
#endif
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_pintr_ch, hz / 100,
|
|
|
|
mcd_pseudointr, sc);
|
1995-03-27 20:04:07 +04:00
|
|
|
return -1;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
readerr:
|
|
|
|
if (mbx->retry-- > 0) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("; retrying\n");
|
1995-03-27 19:45:20 +04:00
|
|
|
goto tryagain;
|
|
|
|
} else
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("; giving up\n");
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
changed:
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Invalidate the buffer. */
|
2007-07-29 16:50:17 +04:00
|
|
|
bp->b_error = EIO;
|
1995-03-27 19:45:20 +04:00
|
|
|
bp->b_resid = bp->b_bcount - mbx->skip;
|
2002-11-01 14:31:50 +03:00
|
|
|
disk_unbusy(&sc->sc_dk, (bp->b_bcount - bp->b_resid),
|
|
|
|
(bp->b_flags & B_READ));
|
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
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: unit timeout; resetting\n", device_xname(sc->sc_dev));
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_write_1(iot, ioh, 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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_soft_reset(struct mcd_softc *sc)
|
1995-03-27 19:45:20 +04:00
|
|
|
{
|
|
|
|
|
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;
|
1997-04-04 22:59:35 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MCD_CTL2, 0x0c); /* XXX */
|
1995-03-27 19:45:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_hard_reset(struct mcd_softc *sc)
|
1995-03-27 19:45:20 +04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_setmode(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)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: setting mode to %d\n", device_xname(sc->sc_dev), mode);
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_setupc(struct mcd_softc *sc, int upc)
|
1995-03-27 19:45:20 +04:00
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->lastupc == upc)
|
|
|
|
return 0;
|
|
|
|
if (sc->debug)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: setting upc to %d\n", device_xname(sc->sc_dev), upc);
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_toc_header(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)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: mcd_toc_header: reading toc header\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev));
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_read_toc(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)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: read_toc: reading qchannel info\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev));
|
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
|
2016-07-14 13:19:05 +03:00
|
|
|
mcd_toc_entries(struct mcd_softc *sc, struct ioc_read_toc_entry *te,
|
|
|
|
struct cd_toc_entry *entries, int *count)
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1995-03-27 19:45:20 +04:00
|
|
|
int len = te->data_len;
|
2007-07-01 02:16:38 +04:00
|
|
|
struct ioc_toc_header header;
|
1995-03-27 19:45:20 +04:00
|
|
|
u_char trk;
|
|
|
|
daddr_t lba;
|
|
|
|
int error, n;
|
|
|
|
|
2007-07-01 02:16:38 +04:00
|
|
|
if (len < sizeof(struct cd_toc_entry))
|
1995-03-27 19:45:20 +04:00
|
|
|
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. */
|
2007-07-01 02:16:38 +04:00
|
|
|
if ((error = mcd_toc_header(sc, &header)) != 0)
|
1995-03-27 19:45:20 +04:00
|
|
|
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)
|
2007-07-01 02:16:38 +04:00
|
|
|
trk = header.starting_track;
|
1995-03-27 19:45:20 +04:00
|
|
|
else if (trk == 0xaa)
|
2007-07-01 02:16:38 +04:00
|
|
|
trk = header.ending_track + 1;
|
|
|
|
else if (trk < header.starting_track ||
|
|
|
|
trk > 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. */
|
2007-07-01 02:16:38 +04:00
|
|
|
for (n = 0; trk <= header.ending_track + 1; n++, trk++) {
|
|
|
|
if (n * sizeof entries[0] > len)
|
|
|
|
break;
|
1995-03-27 19:45:20 +04:00
|
|
|
if (sc->toc[trk].toc.idx_no == 0x00)
|
|
|
|
continue;
|
2007-07-01 02:16:38 +04:00
|
|
|
entries[n].control = sc->toc[trk].toc.control;
|
|
|
|
entries[n].addr_type = sc->toc[trk].toc.addr_type;
|
|
|
|
entries[n].track = bcd2bin(sc->toc[trk].toc.idx_no);
|
1995-03-27 19:45:20 +04:00
|
|
|
switch (te->address_format) {
|
|
|
|
case CD_MSF_FORMAT:
|
2007-07-01 02:16:38 +04:00
|
|
|
entries[n].addr.addr[0] = 0;
|
|
|
|
entries[n].addr.addr[1] = bcd2bin(sc->toc[trk].toc.absolute_pos[0]);
|
|
|
|
entries[n].addr.addr[2] = bcd2bin(sc->toc[trk].toc.absolute_pos[1]);
|
|
|
|
entries[n].addr.addr[3] = bcd2bin(sc->toc[trk].toc.absolute_pos[2]);
|
1995-03-27 19:45:20 +04:00
|
|
|
break;
|
|
|
|
case CD_LBA_FORMAT:
|
|
|
|
lba = msf2hsg(sc->toc[trk].toc.absolute_pos, 0);
|
2007-07-01 02:16:38 +04:00
|
|
|
entries[n].addr.addr[0] = lba >> 24;
|
|
|
|
entries[n].addr.addr[1] = lba >> 16;
|
|
|
|
entries[n].addr.addr[2] = lba >> 8;
|
|
|
|
entries[n].addr.addr[3] = lba;
|
1995-03-27 19:45:20 +04:00
|
|
|
break;
|
|
|
|
}
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
2007-07-01 02:16:38 +04:00
|
|
|
*count = n;
|
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_stop(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)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: mcd_stop: stopping play\n", device_xname(sc->sc_dev));
|
1995-03-27 19:45:20 +04:00
|
|
|
|
|
|
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_getqchan(struct mcd_softc *sc, 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
|
2016-07-14 13:19:05 +03:00
|
|
|
mcd_read_subchannel(struct mcd_softc *sc, struct ioc_read_subchannel *ch,
|
|
|
|
struct cd_sub_channel_info *info)
|
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;
|
|
|
|
daddr_t lba;
|
|
|
|
int error;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: subchan: af=%d df=%d\n", device_xname(sc->sc_dev),
|
1994-02-21 18:23:11 +03:00
|
|
|
ch->address_format, ch->data_format);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
2007-07-01 02:16:38 +04:00
|
|
|
if (len > sizeof(*info) || len < sizeof(info->header))
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
|
|
|
2021-09-10 02:26:36 +03:00
|
|
|
memset(info, 0, sizeof(*info));
|
2007-07-01 02:16:38 +04:00
|
|
|
info->header.audio_status = sc->audio_status;
|
|
|
|
info->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:
|
2007-07-01 02:16:38 +04:00
|
|
|
info->what.media_catalog.mc_valid = 1;
|
1995-03-27 19:45:20 +04:00
|
|
|
#if 0
|
2007-07-01 02:16:38 +04:00
|
|
|
info->what.media_catalog.mc_number =
|
1995-03-27 19:45:20 +04:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CD_CURRENT_POSITION:
|
2007-07-01 02:16:38 +04:00
|
|
|
info->what.position.track_number = bcd2bin(q.current.trk_no);
|
|
|
|
info->what.position.index_number = bcd2bin(q.current.idx_no);
|
1995-03-27 19:45:20 +04:00
|
|
|
switch (ch->address_format) {
|
|
|
|
case CD_MSF_FORMAT:
|
2007-07-01 02:16:38 +04:00
|
|
|
info->what.position.reladdr.addr[0] = 0;
|
|
|
|
info->what.position.reladdr.addr[1] = bcd2bin(q.current.relative_pos[0]);
|
|
|
|
info->what.position.reladdr.addr[2] = bcd2bin(q.current.relative_pos[1]);
|
|
|
|
info->what.position.reladdr.addr[3] = bcd2bin(q.current.relative_pos[2]);
|
|
|
|
info->what.position.absaddr.addr[0] = 0;
|
|
|
|
info->what.position.absaddr.addr[1] = bcd2bin(q.current.absolute_pos[0]);
|
|
|
|
info->what.position.absaddr.addr[2] = bcd2bin(q.current.absolute_pos[1]);
|
|
|
|
info->what.position.absaddr.addr[3] = bcd2bin(q.current.absolute_pos[2]);
|
1995-03-27 19:45:20 +04:00
|
|
|
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.
|
|
|
|
*/
|
2007-07-01 02:16:38 +04:00
|
|
|
if (info->what.position.index_number == 0x00)
|
1995-03-27 19:45:20 +04:00
|
|
|
lba = -lba;
|
2007-07-01 02:16:38 +04:00
|
|
|
info->what.position.reladdr.addr[0] = lba >> 24;
|
|
|
|
info->what.position.reladdr.addr[1] = lba >> 16;
|
|
|
|
info->what.position.reladdr.addr[2] = lba >> 8;
|
|
|
|
info->what.position.reladdr.addr[3] = lba;
|
1995-03-27 19:45:20 +04:00
|
|
|
lba = msf2hsg(q.current.absolute_pos, 0);
|
2007-07-01 02:16:38 +04:00
|
|
|
info->what.position.absaddr.addr[0] = lba >> 24;
|
|
|
|
info->what.position.absaddr.addr[1] = lba >> 16;
|
|
|
|
info->what.position.absaddr.addr[2] = lba >> 8;
|
|
|
|
info->what.position.absaddr.addr[3] = lba;
|
1995-03-27 19:45:20 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-01 02:16:38 +04:00
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_playtracks(struct mcd_softc *sc, 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)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: playtracks: from %d:%d to %d:%d\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev),
|
1995-03-27 19:45:20 +04:00
|
|
|
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;
|
|
|
|
|
1995-07-10 05:27:24 +04:00
|
|
|
mbx.cmd.opcode = MCD_CMDREADSINGLESPEED;
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_playmsf(struct mcd_softc *sc, struct ioc_play_msf *p)
|
1995-03-27 19:45:20 +04:00
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->debug)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: playmsf: from %d:%d.%d to %d:%d.%d\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev),
|
1995-03-27 19:45:20 +04:00
|
|
|
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;
|
|
|
|
|
1995-07-10 05:27:24 +04:00
|
|
|
mbx.cmd.opcode = MCD_CMDREADSINGLESPEED;
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_playblocks(struct mcd_softc *sc, 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)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: playblocks: blkno %d length %d\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev), 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;
|
|
|
|
|
1995-07-10 05:27:24 +04:00
|
|
|
mbx.cmd.opcode = MCD_CMDREADSINGLESPEED;
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_pause(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) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: pause: attempted when not playing\n",
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(sc->sc_dev));
|
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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_resume(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
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_eject(struct mcd_softc *sc)
|
1995-03-27 19:45:20 +04:00
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
|
|
|
|
|
|
|
mbx.cmd.opcode = MCD_CMDEJECTDISK;
|
|
|
|
mbx.cmd.length = 0;
|
|
|
|
mbx.res.length = 0;
|
|
|
|
return mcd_send(sc, &mbx, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
mcd_setlock(struct mcd_softc *sc, int mode)
|
1995-03-27 19:45:20 +04:00
|
|
|
{
|
|
|
|
struct mcd_mbox mbx;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1995-03-27 19:45:20 +04:00
|
|
|
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
|
|
|
}
|