2003-07-15 05:31:38 +04:00
|
|
|
/* $NetBSD: gdrom.c,v 1.16 2003/07/15 01:31:39 lukem Exp $ */
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 Marcus Comstedt
|
|
|
|
* 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 Marcus Comstedt.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
2003-07-15 05:31:38 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: gdrom.c,v 1.16 2003/07/15 01:31:39 lukem Exp $");
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/disk.h>
|
2001-01-25 04:41:47 +03:00
|
|
|
#include <sys/cdio.h>
|
2001-02-20 03:04:40 +03:00
|
|
|
#include <sys/proc.h>
|
2002-09-06 17:18:43 +04:00
|
|
|
#include <sys/conf.h>
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2001-04-24 23:43:23 +04:00
|
|
|
#include <machine/sysasicvar.h>
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
int gdrommatch(struct device *, struct cfdata *, void *);
|
|
|
|
void gdromattach(struct device *, struct device *, void *);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
dev_type_open(gdromopen);
|
|
|
|
dev_type_close(gdromclose);
|
|
|
|
dev_type_read(gdromread);
|
|
|
|
dev_type_write(gdromwrite);
|
|
|
|
dev_type_ioctl(gdromioctl);
|
|
|
|
dev_type_strategy(gdromstrategy);
|
|
|
|
|
|
|
|
const struct bdevsw gdrom_bdevsw = {
|
|
|
|
gdromopen, gdromclose, gdromstrategy, gdromioctl, nodump,
|
|
|
|
nosize, D_DISK
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw gdrom_cdevsw = {
|
|
|
|
gdromopen, gdromclose, gdromread, gdromwrite, gdromioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, nopoll, nommap, nokqfilter, D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
struct gdrom_softc {
|
|
|
|
struct device sc_dv; /* generic device info; must come first */
|
|
|
|
struct disk dkdev; /* generic disk info */
|
|
|
|
struct buf curbuf; /* state of current I/O operation */
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
int is_open, is_busy;
|
2001-01-22 02:30:28 +03:00
|
|
|
int openpart_start; /* start sector of currently open partition */
|
2001-02-20 03:04:40 +03:00
|
|
|
|
|
|
|
int cmd_active;
|
|
|
|
void *cmd_result_buf; /* where to store result data (16 bit aligned) */
|
|
|
|
int cmd_result_size; /* number of bytes allocated for buf */
|
|
|
|
int cmd_actual; /* number of bytes actually read */
|
|
|
|
int cmd_cond; /* resulting condition of command */
|
2001-01-22 02:30:28 +03:00
|
|
|
};
|
|
|
|
|
2002-10-02 08:55:47 +04:00
|
|
|
CFATTACH_DECL(gdrom, sizeof(struct gdrom_softc),
|
|
|
|
gdrommatch, gdromattach, NULL, NULL);
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
struct dkdriver gdromdkdriver = { gdromstrategy };
|
|
|
|
|
|
|
|
extern struct cfdriver gdrom_cd;
|
|
|
|
|
|
|
|
|
|
|
|
struct gd_toc {
|
2002-03-25 21:59:39 +03:00
|
|
|
unsigned int entry[99];
|
|
|
|
unsigned int first, last;
|
|
|
|
unsigned int leadout;
|
2001-01-22 02:30:28 +03:00
|
|
|
};
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
#define TOC_LBA(n) ((n) & 0xffffff00)
|
|
|
|
#define TOC_ADR(n) ((n) & 0x0f)
|
|
|
|
#define TOC_CTRL(n) (((n) & 0xf0) >> 4)
|
|
|
|
#define TOC_TRACK(n) (((n) & 0x0000ff00) >> 8)
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
#define GDROM(o) (*(volatile unsigned char *)(0xa05f7000 + (o)))
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
#define GDSTATSTAT(n) ((n) & 0xf)
|
|
|
|
#define GDSTATDISK(n) (((n) >> 4) & 0xf)
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
#define GDROM_BUSY GDROM(0x18)
|
|
|
|
#define GDROM_DATA (*(volatile short *) & GDROM(0x80))
|
|
|
|
#define GDROM_REGX GDROM(0x84)
|
|
|
|
#define GDROM_STAT GDROM(0x8c)
|
|
|
|
#define GDROM_CNTLO GDROM(0x90)
|
|
|
|
#define GDROM_CNTHI GDROM(0x94)
|
|
|
|
#define GDROM_COND GDROM(0x9c)
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
int gdrom_getstat(void);
|
|
|
|
int gdrom_do_command(struct gdrom_softc *, void *, void *, unsigned int);
|
|
|
|
int gdrom_command_sense(struct gdrom_softc *, void *, void *, unsigned int);
|
|
|
|
int gdrom_read_toc(struct gdrom_softc *, struct gd_toc *);
|
|
|
|
int gdrom_read_sectors(struct gdrom_softc *, void *, int, int);
|
|
|
|
int gdrom_mount_disk(struct gdrom_softc *);
|
|
|
|
int gdrom_intr(void *);
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
int gdrom_getstat()
|
|
|
|
{
|
|
|
|
int s1, s2, s3;
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
if (GDROM_BUSY & 0x80)
|
|
|
|
return (-1);
|
2001-01-22 02:30:28 +03:00
|
|
|
s1 = GDROM_STAT;
|
|
|
|
s2 = GDROM_STAT;
|
|
|
|
s3 = GDROM_STAT;
|
2002-03-25 21:59:39 +03:00
|
|
|
if(GDROM_BUSY & 0x80)
|
|
|
|
return (-1);
|
2001-01-22 02:30:28 +03:00
|
|
|
if(s1 == s2)
|
2002-03-25 21:59:39 +03:00
|
|
|
return (s1);
|
2001-01-22 02:30:28 +03:00
|
|
|
else if(s2 == s3)
|
2002-03-25 21:59:39 +03:00
|
|
|
return (s2);
|
2001-01-22 02:30:28 +03:00
|
|
|
else
|
2002-03-25 21:59:39 +03:00
|
|
|
return (-1);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
int
|
2002-03-25 21:59:39 +03:00
|
|
|
gdrom_intr(void *arg)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
2001-02-20 03:04:40 +03:00
|
|
|
struct gdrom_softc *sc = arg;
|
|
|
|
int s, cond;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
cond = GDROM_COND;
|
|
|
|
#ifdef GDROMDEBUG
|
|
|
|
printf("GDROM: cond = %x\n", cond);
|
|
|
|
#endif
|
|
|
|
if(!sc->cmd_active) {
|
|
|
|
#ifdef GDROMDEBUG
|
2002-03-25 21:59:39 +03:00
|
|
|
printf("GDROM: inactive IRQ!?\n");
|
2001-02-20 03:04:40 +03:00
|
|
|
#endif
|
2002-03-25 21:59:39 +03:00
|
|
|
splx(s);
|
|
|
|
return (0);
|
2001-02-20 03:04:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if((cond & 8)) {
|
2002-03-25 21:59:39 +03:00
|
|
|
int cnt = (GDROM_CNTHI << 8) | GDROM_CNTLO;
|
2001-02-20 03:04:40 +03:00
|
|
|
#ifdef GDROMDEBUG
|
|
|
|
printf("GDROM: cnt = %d\n", cnt);
|
|
|
|
#endif
|
|
|
|
sc->cmd_actual += cnt;
|
|
|
|
if(cnt > 0 && sc->cmd_result_size > 0) {
|
2002-03-25 21:59:39 +03:00
|
|
|
int subcnt = (cnt > sc->cmd_result_size ?
|
|
|
|
sc->cmd_result_size : cnt);
|
2001-02-20 03:04:40 +03:00
|
|
|
int16_t *ptr = sc->cmd_result_buf;
|
2002-03-25 21:59:39 +03:00
|
|
|
sc->cmd_result_buf = ((char *)sc->cmd_result_buf) +
|
|
|
|
subcnt;
|
2001-02-20 03:04:40 +03:00
|
|
|
sc->cmd_result_size -= subcnt;
|
|
|
|
cnt -= subcnt;
|
2002-03-25 21:59:39 +03:00
|
|
|
while (subcnt > 0) {
|
|
|
|
*ptr++ = GDROM_DATA;
|
|
|
|
subcnt -= 2;
|
2001-02-20 03:04:40 +03:00
|
|
|
}
|
|
|
|
}
|
2002-03-25 21:59:39 +03:00
|
|
|
while (cnt > 0) {
|
|
|
|
__volatile int16_t tmp;
|
|
|
|
tmp = GDROM_DATA;
|
|
|
|
cnt -= 2;
|
2001-02-20 03:04:40 +03:00
|
|
|
}
|
|
|
|
}
|
2002-03-25 21:59:39 +03:00
|
|
|
while (GDROM_BUSY & 0x80);
|
2001-02-20 03:04:40 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
if ((cond & 8) == 0) {
|
2001-02-20 03:04:40 +03:00
|
|
|
sc->cmd_cond = cond;
|
|
|
|
sc->cmd_active = 0;
|
|
|
|
wakeup(&sc->cmd_active);
|
|
|
|
}
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
splx(s);
|
2002-11-15 16:29:26 +03:00
|
|
|
return (1);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
int gdrom_do_command(struct gdrom_softc *sc, void *req, void *buf,
|
|
|
|
unsigned int nbyt)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
2001-02-20 03:04:40 +03:00
|
|
|
int i, s;
|
|
|
|
short *ptr = req;
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
while (GDROM_BUSY & 0x88)
|
|
|
|
;
|
|
|
|
if (buf != NULL) {
|
|
|
|
GDROM_CNTLO = nbyt & 0xff;
|
|
|
|
GDROM_CNTHI = (nbyt >> 8) & 0xff;
|
|
|
|
GDROM_REGX = 0;
|
2001-02-20 03:04:40 +03:00
|
|
|
}
|
|
|
|
sc->cmd_result_buf = buf;
|
|
|
|
sc->cmd_result_size = nbyt;
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
if (GDSTATSTAT(GDROM_STAT) == 6)
|
|
|
|
return (-1);
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
GDROM_COND = 0xa0;
|
2002-03-25 21:59:39 +03:00
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
;
|
|
|
|
while ((GDROM_BUSY & 0x88) != 8)
|
|
|
|
;
|
2001-02-20 03:04:40 +03:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
sc->cmd_actual = 0;
|
|
|
|
sc->cmd_active = 1;
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
for (i = 0; i< 6; i++)
|
|
|
|
GDROM_DATA = ptr[i];
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
while (sc->cmd_active)
|
|
|
|
tsleep(&sc->cmd_active, PRIBIO, "gdrom", 0);
|
2001-02-20 03:04:40 +03:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
return (sc->cmd_cond);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
int gdrom_command_sense(struct gdrom_softc *sc, void *req, void *buf,
|
|
|
|
unsigned int nbyt)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
/* 76543210 76543210
|
2002-03-25 21:59:39 +03:00
|
|
|
0 0x13 -
|
|
|
|
2 - bufsz(hi)
|
|
|
|
4 bufsz(lo) -
|
|
|
|
6 - -
|
|
|
|
8 - -
|
|
|
|
10 - - */
|
2001-01-22 02:30:28 +03:00
|
|
|
unsigned short sense_data[5];
|
|
|
|
unsigned char cmd[12];
|
|
|
|
int sense_key, sense_specific;
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
int cond = gdrom_do_command(sc, req, buf, nbyt);
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
if (cond < 0) {
|
2001-01-22 02:30:28 +03:00
|
|
|
#ifdef GDROMDEBUG
|
2002-03-25 21:59:39 +03:00
|
|
|
printf("GDROM: not ready (2:58)\n");
|
2001-01-22 02:30:28 +03:00
|
|
|
#endif
|
2002-03-25 21:59:39 +03:00
|
|
|
return (EIO);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
if ((cond & 1) == 0) {
|
2001-01-22 02:30:28 +03:00
|
|
|
#ifdef GDROMDEBUG
|
2002-03-25 21:59:39 +03:00
|
|
|
printf("GDROM: no sense. 0:0\n");
|
2001-01-22 02:30:28 +03:00
|
|
|
#endif
|
2002-03-25 21:59:39 +03:00
|
|
|
return (0);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2001-07-22 19:46:41 +04:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
cmd[0] = 0x13;
|
|
|
|
cmd[4] = sizeof(sense_data);
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
gdrom_do_command(sc, cmd, sense_data, sizeof(sense_data));
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
sense_key = sense_data[1] & 0xf;
|
|
|
|
sense_specific = sense_data[4];
|
2002-03-25 21:59:39 +03:00
|
|
|
if (sense_key == 11 && sense_specific == 0) {
|
2001-01-22 02:30:28 +03:00
|
|
|
#ifdef GDROMDEBUG
|
2002-03-25 21:59:39 +03:00
|
|
|
printf("GDROM: aborted (ignored). 0:0\n");
|
2001-01-22 02:30:28 +03:00
|
|
|
#endif
|
2002-03-25 21:59:39 +03:00
|
|
|
return (0);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GDROMDEBUG
|
2001-02-20 03:04:40 +03:00
|
|
|
printf("GDROM: SENSE %d:", sense_key);
|
|
|
|
printf("GDROM: %d\n", sense_specific);
|
2001-01-22 02:30:28 +03:00
|
|
|
#endif
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
return (sense_key == 0 ? 0 : EIO);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
int gdrom_read_toc(struct gdrom_softc *sc, struct gd_toc *toc)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
/* 76543210 76543210
|
2002-03-25 21:59:39 +03:00
|
|
|
0 0x14 -
|
|
|
|
2 - bufsz(hi)
|
|
|
|
4 bufsz(lo) -
|
|
|
|
6 - -
|
|
|
|
8 - -
|
|
|
|
10 - - */
|
2001-01-22 02:30:28 +03:00
|
|
|
unsigned char cmd[12];
|
|
|
|
|
2001-07-22 19:46:41 +04:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
cmd[0] = 0x14;
|
2002-03-25 21:59:39 +03:00
|
|
|
cmd[3] = sizeof(struct gd_toc) >> 8;
|
|
|
|
cmd[4] = sizeof(struct gd_toc) & 0xff;
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
return (gdrom_command_sense(sc, cmd, toc, sizeof(struct gd_toc)));
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
int gdrom_read_sectors(struct gdrom_softc *sc, void *buf, int sector, int cnt)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
/* 76543210 76543210
|
2002-03-25 21:59:39 +03:00
|
|
|
0 0x30 datafmt
|
|
|
|
2 sec(hi) sec(mid)
|
|
|
|
4 sec(lo) -
|
|
|
|
6 - -
|
|
|
|
8 cnt(hi) cnt(mid)
|
|
|
|
10 cnt(lo) - */
|
2001-01-22 02:30:28 +03:00
|
|
|
unsigned char cmd[12];
|
|
|
|
|
2001-07-22 19:46:41 +04:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
cmd[0] = 0x30;
|
|
|
|
cmd[1] = 0x20;
|
|
|
|
cmd[2] = sector>>16;
|
|
|
|
cmd[3] = sector>>8;
|
|
|
|
cmd[4] = sector;
|
|
|
|
cmd[8] = cnt>>16;
|
|
|
|
cmd[9] = cnt>>8;
|
|
|
|
cmd[10] = cnt;
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
return (gdrom_command_sense(sc, cmd, buf, cnt << 11));
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
int gdrom_mount_disk(struct gdrom_softc *sc)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
/* 76543210 76543210
|
2002-03-25 21:59:39 +03:00
|
|
|
0 0x70 -
|
|
|
|
2 0x1f -
|
|
|
|
4 - -
|
|
|
|
6 - -
|
|
|
|
8 - -
|
|
|
|
10 - - */
|
2001-01-22 02:30:28 +03:00
|
|
|
unsigned char cmd[12];
|
|
|
|
|
2001-07-22 19:46:41 +04:00
|
|
|
memset(cmd, 0, sizeof(cmd));
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
cmd[0] = 0x70;
|
|
|
|
cmd[1] = 0x1f;
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
return (gdrom_command_sense(sc, cmd, NULL, 0));
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-03-25 21:59:39 +03:00
|
|
|
gdrommatch(struct device *parent, struct cfdata *cf, void *aux)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
static int gdrom_matched = 0;
|
|
|
|
|
|
|
|
/* Allow only once instance. */
|
2002-09-27 06:16:28 +04:00
|
|
|
if (gdrom_matched)
|
2002-03-25 21:59:39 +03:00
|
|
|
return (0);
|
2001-01-22 02:30:28 +03:00
|
|
|
gdrom_matched = 1;
|
2002-03-24 21:21:08 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
return (1);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-25 21:59:39 +03:00
|
|
|
gdromattach(struct device *parent, struct device *self, void *aux)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
struct gdrom_softc *sc;
|
2002-03-25 21:59:39 +03:00
|
|
|
u_int32_t p, x;
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
sc = (struct gdrom_softc *)self;
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize and attach the disk structure.
|
|
|
|
*/
|
|
|
|
sc->dkdev.dk_name = sc->sc_dv.dv_xname;
|
|
|
|
sc->dkdev.dk_driver = &gdromdkdriver;
|
|
|
|
disk_attach(&sc->dkdev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reenable disabled drive
|
|
|
|
*/
|
2002-03-25 21:59:39 +03:00
|
|
|
*((__volatile u_int32_t *)0xa05f74e4) = 0x1fffff;
|
|
|
|
for (p = 0; p < 0x200000 / 4; p++)
|
|
|
|
x = ((__volatile u_int32_t *)0xa0000000)[p];
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2002-11-15 16:29:26 +03:00
|
|
|
printf(": %s\n", sysasic_intr_string(IPL_BIO));
|
|
|
|
sysasic_intr_establish(SYSASIC_EVENT_GDROM, IPL_BIO, gdrom_intr, sc);
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-03-25 21:59:39 +03:00
|
|
|
gdromopen(dev_t dev, int flags, int devtype, struct proc *p)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
struct gdrom_softc *sc;
|
2001-02-20 03:04:40 +03:00
|
|
|
int s, error, unit, cnt;
|
2001-01-22 02:30:28 +03:00
|
|
|
struct gd_toc toc;
|
|
|
|
|
|
|
|
#ifdef GDROMDEBUG
|
|
|
|
printf("GDROM: open\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
|
|
|
if (unit >= gdrom_cd.cd_ndevs)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
sc = gdrom_cd.cd_devs[unit];
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (sc->is_open)
|
|
|
|
return (EBUSY);
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
s = splbio();
|
|
|
|
while(sc->is_busy)
|
2002-03-25 21:59:39 +03:00
|
|
|
tsleep(&sc->is_busy, PRIBIO, "gdbusy", 0);
|
2001-02-20 03:04:40 +03:00
|
|
|
sc->is_busy = 1;
|
|
|
|
splx(s);
|
|
|
|
|
2001-01-22 02:30:28 +03:00
|
|
|
for (cnt = 0; cnt < 5; cnt++)
|
2002-03-25 21:59:39 +03:00
|
|
|
if ((error = gdrom_mount_disk(sc)) == 0)
|
|
|
|
break;
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
if (!error)
|
|
|
|
error = gdrom_read_toc(sc, &toc);
|
|
|
|
|
|
|
|
sc->is_busy = 0;
|
|
|
|
wakeup(&sc->is_busy);
|
|
|
|
|
2001-01-22 02:30:28 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
sc->is_open = 1;
|
2001-01-25 04:41:47 +03:00
|
|
|
sc->openpart_start = 150;
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
#ifdef GDROMDEBUG
|
2001-02-20 03:04:40 +03:00
|
|
|
printf("GDROM: open OK\n");
|
2001-01-22 02:30:28 +03:00
|
|
|
#endif
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-03-25 21:59:39 +03:00
|
|
|
gdromclose(dev_t dev, int flags, int devtype, struct proc *p)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
struct gdrom_softc *sc;
|
|
|
|
int unit;
|
|
|
|
#ifdef GDROMDEBUG
|
|
|
|
printf("GDROM: close\n");
|
|
|
|
#endif
|
|
|
|
unit = DISKUNIT(dev);
|
|
|
|
sc = gdrom_cd.cd_devs[unit];
|
|
|
|
|
|
|
|
sc->is_open = 0;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-25 21:59:39 +03:00
|
|
|
gdromstrategy(struct buf *bp)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
struct gdrom_softc *sc;
|
2001-02-20 03:04:40 +03:00
|
|
|
int s, unit, error;
|
2001-01-22 02:30:28 +03:00
|
|
|
#ifdef GDROMDEBUG
|
|
|
|
printf("GDROM: strategy\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
unit = DISKUNIT(bp->b_dev);
|
|
|
|
sc = gdrom_cd.cd_devs[unit];
|
|
|
|
|
|
|
|
if (bp->b_bcount == 0)
|
2002-03-25 21:59:39 +03:00
|
|
|
goto done;
|
2001-01-22 02:30:28 +03:00
|
|
|
|
|
|
|
bp->b_rawblkno = bp->b_blkno / (2048 / DEV_BSIZE) + sc->openpart_start;
|
|
|
|
|
|
|
|
#ifdef GDROMDEBUG
|
2001-02-20 03:04:40 +03:00
|
|
|
printf("GDROM: read_sectors(%p, %d, %ld) [%ld bytes]\n",
|
2002-03-25 21:59:39 +03:00
|
|
|
bp->b_data, bp->b_rawblkno,
|
|
|
|
bp->b_bcount>>11, bp->b_bcount);
|
2001-01-22 02:30:28 +03:00
|
|
|
#endif
|
2001-02-20 03:04:40 +03:00
|
|
|
s = splbio();
|
2002-03-25 21:59:39 +03:00
|
|
|
while (sc->is_busy)
|
|
|
|
tsleep(&sc->is_busy, PRIBIO, "gdbusy", 0);
|
2001-02-20 03:04:40 +03:00
|
|
|
sc->is_busy = 1;
|
|
|
|
splx(s);
|
2001-01-22 02:30:28 +03:00
|
|
|
|
2001-12-04 18:27:35 +03:00
|
|
|
if ((error = gdrom_read_sectors(sc, bp->b_data, bp->b_rawblkno,
|
2002-03-25 21:59:39 +03:00
|
|
|
bp->b_bcount >> 11))) {
|
|
|
|
bp->b_error = error;
|
|
|
|
bp->b_flags |= B_ERROR;
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
sc->is_busy = 0;
|
|
|
|
wakeup(&sc->is_busy);
|
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
done:
|
2001-01-22 02:30:28 +03:00
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-03-25 21:59:39 +03:00
|
|
|
gdromioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
2001-01-25 04:41:47 +03:00
|
|
|
struct gdrom_softc *sc;
|
|
|
|
int unit, error;
|
2001-01-22 02:30:28 +03:00
|
|
|
#ifdef GDROMDEBUG
|
|
|
|
printf("GDROM: ioctl %lx\n", cmd);
|
|
|
|
#endif
|
2001-01-25 04:41:47 +03:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
|
|
|
sc = gdrom_cd.cd_devs[unit];
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CDIOREADMSADDR: {
|
2002-03-25 21:59:39 +03:00
|
|
|
int s, track, sessno = *(int *)addr;
|
2001-01-25 04:41:47 +03:00
|
|
|
struct gd_toc toc;
|
|
|
|
|
|
|
|
if (sessno != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2001-02-20 03:04:40 +03:00
|
|
|
s = splbio();
|
2002-03-25 21:59:39 +03:00
|
|
|
while (sc->is_busy)
|
|
|
|
tsleep(&sc->is_busy, PRIBIO, "gdbusy", 0);
|
2001-02-20 03:04:40 +03:00
|
|
|
sc->is_busy = 1;
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
error = gdrom_read_toc(sc, &toc);
|
|
|
|
|
|
|
|
sc->is_busy = 0;
|
|
|
|
wakeup(&sc->is_busy);
|
|
|
|
|
|
|
|
if (error)
|
2002-03-25 21:59:39 +03:00
|
|
|
return error;
|
2001-01-25 04:41:47 +03:00
|
|
|
|
|
|
|
for (track = TOC_TRACK(toc.last);
|
2002-03-25 21:59:39 +03:00
|
|
|
track >= TOC_TRACK(toc.first);
|
|
|
|
--track)
|
|
|
|
if (TOC_CTRL(toc.entry[track-1]))
|
|
|
|
break;
|
2001-01-25 04:41:47 +03:00
|
|
|
|
|
|
|
if (track < TOC_TRACK(toc.first) || track > 100)
|
2002-03-25 21:59:39 +03:00
|
|
|
return (ENXIO);
|
2001-01-25 04:41:47 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
*(int *)addr = htonl(TOC_LBA(toc.entry[track-1])) -
|
|
|
|
sc->openpart_start;
|
2001-01-25 04:41:47 +03:00
|
|
|
|
2002-03-25 21:59:39 +03:00
|
|
|
return (0);
|
2001-01-25 04:41:47 +03:00
|
|
|
}
|
2002-03-25 21:59:39 +03:00
|
|
|
default:
|
|
|
|
return (EINVAL);
|
2001-01-25 04:41:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("gdromioctl: impossible");
|
|
|
|
#endif
|
2001-01-22 02:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2002-03-25 21:59:39 +03:00
|
|
|
gdromread(dev_t dev, struct uio *uio, int flags)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
|
|
|
#ifdef GDROMDEBUG
|
|
|
|
printf("GDROM: read\n");
|
|
|
|
#endif
|
|
|
|
return (physio(gdromstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-03-25 21:59:39 +03:00
|
|
|
gdromwrite(dev_t dev, struct uio *uio, int flags)
|
2001-01-22 02:30:28 +03:00
|
|
|
{
|
2002-03-25 21:59:39 +03:00
|
|
|
|
2001-01-22 02:30:28 +03:00
|
|
|
return (EROFS);
|
|
|
|
}
|