mcd.c (58934) | mcd.c (59249) |
---|---|
1/* 2 * Copyright 1993 by Holger Veit (data part) 3 * Copyright 1993 by Brian Moore (audio part) 4 * Changes Copyright 1993 by Gary Clark II 5 * Changes Copyright (C) 1994-1995 by Andrey A. Chernov, Moscow, Russia 6 * 7 * Rewrote probe routine to work on newer Mitsumi drives. 8 * Additional changes (C) 1994 by Jordan K. Hubbard --- 26 unchanged lines hidden (view full) --- 35 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 36 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 37 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 38 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 * | 1/* 2 * Copyright 1993 by Holger Veit (data part) 3 * Copyright 1993 by Brian Moore (audio part) 4 * Changes Copyright 1993 by Gary Clark II 5 * Changes Copyright (C) 1994-1995 by Andrey A. Chernov, Moscow, Russia 6 * 7 * Rewrote probe routine to work on newer Mitsumi drives. 8 * Additional changes (C) 1994 by Jordan K. Hubbard --- 26 unchanged lines hidden (view full) --- 35 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 36 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 37 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 38 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 * |
43 * $FreeBSD: head/sys/dev/mcd/mcd.c 58934 2000-04-02 15:24:56Z phk $ | 43 * $FreeBSD: head/sys/dev/mcd/mcd.c 59249 2000-04-15 05:54:02Z phk $ |
44 */ 45static const char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore"; 46 47#include "mcd.h" 48#include <sys/param.h> 49#include <sys/systm.h> 50#include <sys/conf.h> 51#include <sys/fcntl.h> --- 59 unchanged lines hidden (view full) --- 111 112struct mcd_mbx { 113 short unit; 114 short port; 115 short retry; 116 short nblk; 117 int sz; 118 u_long skip; | 44 */ 45static const char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore"; 46 47#include "mcd.h" 48#include <sys/param.h> 49#include <sys/systm.h> 50#include <sys/conf.h> 51#include <sys/fcntl.h> --- 59 unchanged lines hidden (view full) --- 111 112struct mcd_mbx { 113 short unit; 114 short port; 115 short retry; 116 short nblk; 117 int sz; 118 u_long skip; |
119 struct buf *bp; | 119 struct bio *bp; |
120 int p_offset; 121 short count; 122 short mode; 123}; 124 125static struct mcd_data { 126 short type; 127 char *name; --- 8 unchanged lines hidden (view full) --- 136 int partflags[MAXPARTITIONS]; 137 int openflags; 138 struct mcd_volinfo volinfo; 139 struct mcd_qchninfo toc[MCD_MAXTOCS]; 140 short audio_status; 141 short curr_mode; 142 struct mcd_read2 lastpb; 143 short debug; | 120 int p_offset; 121 short count; 122 short mode; 123}; 124 125static struct mcd_data { 126 short type; 127 char *name; --- 8 unchanged lines hidden (view full) --- 136 int partflags[MAXPARTITIONS]; 137 int openflags; 138 struct mcd_volinfo volinfo; 139 struct mcd_qchninfo toc[MCD_MAXTOCS]; 140 short audio_status; 141 short curr_mode; 142 struct mcd_read2 lastpb; 143 short debug; |
144 struct buf_queue_head head; /* head of buf queue */ | 144 struct bio_queue_head head; /* head of bio queue */ |
145 struct mcd_mbx mbx; 146} mcd_data[NMCD]; 147 148/* reader state machine */ 149#define MCD_S_BEGIN 0 150#define MCD_S_BEGIN1 1 151#define MCD_S_WAITSTAT 2 152#define MCD_S_WAITMODE 3 --- 92 unchanged lines hidden (view full) --- 245{ 246 int unit = dev->id_unit; 247 struct mcd_data *cd = mcd_data + unit; 248 249 dev->id_ointr = mcdintr; 250 cd->iobase = dev->id_iobase; 251 cd->flags |= MCDINIT; 252 mcd_soft_reset(unit); | 145 struct mcd_mbx mbx; 146} mcd_data[NMCD]; 147 148/* reader state machine */ 149#define MCD_S_BEGIN 0 150#define MCD_S_BEGIN1 1 151#define MCD_S_WAITSTAT 2 152#define MCD_S_WAITMODE 3 --- 92 unchanged lines hidden (view full) --- 245{ 246 int unit = dev->id_unit; 247 struct mcd_data *cd = mcd_data + unit; 248 249 dev->id_ointr = mcdintr; 250 cd->iobase = dev->id_iobase; 251 cd->flags |= MCDINIT; 252 mcd_soft_reset(unit); |
253 bufq_init(&cd->head); | 253 bioq_init(&cd->head); |
254 255#ifdef NOTYET 256 /* wire controller for interrupts and dma */ 257 mcd_configure(cd); 258#endif 259 /* name filled in probe */ 260 make_dev(&mcd_cdevsw, dkmakeminor(unit, 0, 0), 261 UID_ROOT, GID_OPERATOR, 0640, "rmcd%da", unit); --- 118 unchanged lines hidden (view full) --- 380 (void) mcd_lock_door(unit, MCD_LK_UNLOCK); 381 cd->openflags &= ~(1<<part); 382 cd->partflags[part] &= ~MCDREADRAW; 383 384 return 0; 385} 386 387void | 254 255#ifdef NOTYET 256 /* wire controller for interrupts and dma */ 257 mcd_configure(cd); 258#endif 259 /* name filled in probe */ 260 make_dev(&mcd_cdevsw, dkmakeminor(unit, 0, 0), 261 UID_ROOT, GID_OPERATOR, 0640, "rmcd%da", unit); --- 118 unchanged lines hidden (view full) --- 380 (void) mcd_lock_door(unit, MCD_LK_UNLOCK); 381 cd->openflags &= ~(1<<part); 382 cd->partflags[part] &= ~MCDREADRAW; 383 384 return 0; 385} 386 387void |
388mcdstrategy(struct buf *bp) | 388mcdstrategy(struct bio *bp) |
389{ 390 struct mcd_data *cd; 391 int s; 392 | 389{ 390 struct mcd_data *cd; 391 int s; 392 |
393 int unit = mcd_unit(bp->b_dev); | 393 int unit = mcd_unit(bp->bio_dev); |
394 395 cd = mcd_data + unit; 396 397 /* test validity */ 398/*MCD_TRACE("strategy: buf=0x%lx, unit=%ld, block#=%ld bcount=%ld\n", | 394 395 cd = mcd_data + unit; 396 397 /* test validity */ 398/*MCD_TRACE("strategy: buf=0x%lx, unit=%ld, block#=%ld bcount=%ld\n", |
399 bp,unit,bp->b_blkno,bp->b_bcount);*/ 400 if (unit >= NMCD || bp->b_blkno < 0) { | 399 bp,unit,bp->bio_blkno,bp->bio_bcount);*/ 400 if (unit >= NMCD || bp->bio_blkno < 0) { |
401 printf("mcdstrategy: unit = %d, blkno = %ld, bcount = %ld\n", | 401 printf("mcdstrategy: unit = %d, blkno = %ld, bcount = %ld\n", |
402 unit, (long)bp->b_blkno, bp->b_bcount); | 402 unit, (long)bp->bio_blkno, bp->bio_bcount); |
403 printf("mcd: mcdstratregy failure"); | 403 printf("mcd: mcdstratregy failure"); |
404 bp->b_error = EINVAL; 405 bp->b_ioflags |= BIO_ERROR; | 404 bp->bio_error = EINVAL; 405 bp->bio_flags |= BIO_ERROR; |
406 goto bad; 407 } 408 409 /* if device invalidated (e.g. media change, door open), error */ 410 if (!(cd->flags & MCDVALID)) { 411MCD_TRACE("strategy: drive not valid\n"); | 406 goto bad; 407 } 408 409 /* if device invalidated (e.g. media change, door open), error */ 410 if (!(cd->flags & MCDVALID)) { 411MCD_TRACE("strategy: drive not valid\n"); |
412 bp->b_error = EIO; | 412 bp->bio_error = EIO; |
413 goto bad; 414 } 415 416 /* read only */ | 413 goto bad; 414 } 415 416 /* read only */ |
417 if (!(bp->b_iocmd == BIO_READ)) { 418 bp->b_error = EROFS; | 417 if (!(bp->bio_cmd == BIO_READ)) { 418 bp->bio_error = EROFS; |
419 goto bad; 420 } 421 422 /* no data to read */ | 419 goto bad; 420 } 421 422 /* no data to read */ |
423 if (bp->b_bcount == 0) | 423 if (bp->bio_bcount == 0) |
424 goto done; 425 426 /* for non raw access, check partition limits */ | 424 goto done; 425 426 /* for non raw access, check partition limits */ |
427 if (mcd_part(bp->b_dev) != RAW_PART) { | 427 if (mcd_part(bp->bio_dev) != RAW_PART) { |
428 if (!(cd->flags & MCDLABEL)) { | 428 if (!(cd->flags & MCDLABEL)) { |
429 bp->b_error = EIO; | 429 bp->bio_error = EIO; |
430 goto bad; 431 } 432 /* adjust transfer if necessary */ 433 if (bounds_check_with_label(bp,&cd->dlabel,1) <= 0) { 434 goto done; 435 } 436 } else { | 430 goto bad; 431 } 432 /* adjust transfer if necessary */ 433 if (bounds_check_with_label(bp,&cd->dlabel,1) <= 0) { 434 goto done; 435 } 436 } else { |
437 bp->b_pblkno = bp->b_blkno; 438 bp->b_resid = 0; | 437 bp->bio_pblkno = bp->bio_blkno; 438 bp->bio_resid = 0; |
439 } 440 441 /* queue it */ 442 s = splbio(); | 439 } 440 441 /* queue it */ 442 s = splbio(); |
443 bufqdisksort(&cd->head, bp); | 443 bioqdisksort(&cd->head, bp); |
444 splx(s); 445 446 /* now check whether we can perform processing */ 447 mcd_start(unit); 448 return; 449 450bad: | 444 splx(s); 445 446 /* now check whether we can perform processing */ 447 mcd_start(unit); 448 return; 449 450bad: |
451 bp->b_ioflags |= BIO_ERROR; | 451 bp->bio_flags |= BIO_ERROR; |
452done: | 452done: |
453 bp->b_resid = bp->b_bcount; | 453 bp->bio_resid = bp->bio_bcount; |
454 biodone(bp); 455 return; 456} 457 458static void mcd_start(int unit) 459{ 460 struct mcd_data *cd = mcd_data + unit; 461 struct partition *p; | 454 biodone(bp); 455 return; 456} 457 458static void mcd_start(int unit) 459{ 460 struct mcd_data *cd = mcd_data + unit; 461 struct partition *p; |
462 struct buf *bp; | 462 struct bio *bp; |
463 int s = splbio(); 464 465 if (cd->flags & MCDMBXBSY) { 466 splx(s); 467 return; 468 } 469 | 463 int s = splbio(); 464 465 if (cd->flags & MCDMBXBSY) { 466 splx(s); 467 return; 468 } 469 |
470 bp = bufq_first(&cd->head); | 470 bp = bioq_first(&cd->head); |
471 if (bp != 0) { 472 /* block found to process, dequeue */ 473 /*MCD_TRACE("mcd_start: found block bp=0x%x\n",bp,0,0,0);*/ | 471 if (bp != 0) { 472 /* block found to process, dequeue */ 473 /*MCD_TRACE("mcd_start: found block bp=0x%x\n",bp,0,0,0);*/ |
474 bufq_remove(&cd->head, bp); | 474 bioq_remove(&cd->head, bp); |
475 splx(s); 476 } else { 477 /* nothing to do */ 478 splx(s); 479 return; 480 } 481 482 /* changed media? */ 483 if (!(cd->flags & MCDVALID)) { 484 MCD_TRACE("mcd_start: drive not valid\n"); 485 return; 486 } 487 | 475 splx(s); 476 } else { 477 /* nothing to do */ 478 splx(s); 479 return; 480 } 481 482 /* changed media? */ 483 if (!(cd->flags & MCDVALID)) { 484 MCD_TRACE("mcd_start: drive not valid\n"); 485 return; 486 } 487 |
488 p = cd->dlabel.d_partitions + mcd_part(bp->b_dev); | 488 p = cd->dlabel.d_partitions + mcd_part(bp->bio_dev); |
489 490 cd->flags |= MCDMBXBSY; | 489 490 cd->flags |= MCDMBXBSY; |
491 if (cd->partflags[mcd_part(bp->b_dev)] & MCDREADRAW) | 491 if (cd->partflags[mcd_part(bp->bio_dev)] & MCDREADRAW) |
492 cd->flags |= MCDREADRAW; 493 cd->mbx.unit = unit; 494 cd->mbx.port = cd->iobase; 495 cd->mbx.retry = MCD_RETRYS; 496 cd->mbx.bp = bp; 497 cd->mbx.p_offset = p->p_offset; 498 499 /* calling the read routine */ --- 488 unchanged lines hidden (view full) --- 988static void 989mcd_doread(int state, struct mcd_mbx *mbxin) 990{ 991 struct mcd_mbx *mbx = (state!=MCD_S_BEGIN) ? mbxsave : mbxin; 992 int unit = mbx->unit; 993 int port = mbx->port; 994 int com_port = mbx->port + mcd_command; 995 int data_port = mbx->port + mcd_rdata; | 492 cd->flags |= MCDREADRAW; 493 cd->mbx.unit = unit; 494 cd->mbx.port = cd->iobase; 495 cd->mbx.retry = MCD_RETRYS; 496 cd->mbx.bp = bp; 497 cd->mbx.p_offset = p->p_offset; 498 499 /* calling the read routine */ --- 488 unchanged lines hidden (view full) --- 988static void 989mcd_doread(int state, struct mcd_mbx *mbxin) 990{ 991 struct mcd_mbx *mbx = (state!=MCD_S_BEGIN) ? mbxsave : mbxin; 992 int unit = mbx->unit; 993 int port = mbx->port; 994 int com_port = mbx->port + mcd_command; 995 int data_port = mbx->port + mcd_rdata; |
996 struct buf *bp = mbx->bp; | 996 struct bio *bp = mbx->bp; |
997 struct mcd_data *cd = mcd_data + unit; 998 999 int rm,i,k; 1000 struct mcd_read2 rbuf; 1001 int blknum; 1002 caddr_t addr; 1003 1004loop: --- 76 unchanged lines hidden (view full) --- 1081 } 1082 if (mcd_setflags(unit,cd) < 0) 1083 goto changed; 1084 cd->curr_mode = mbx->mode; 1085 MCD_TRACE("got WAITMODE delay=%d\n", 1086 RDELAY_WAITMODE-mbx->count); 1087modedone: 1088 /* for first block */ | 997 struct mcd_data *cd = mcd_data + unit; 998 999 int rm,i,k; 1000 struct mcd_read2 rbuf; 1001 int blknum; 1002 caddr_t addr; 1003 1004loop: --- 76 unchanged lines hidden (view full) --- 1081 } 1082 if (mcd_setflags(unit,cd) < 0) 1083 goto changed; 1084 cd->curr_mode = mbx->mode; 1085 MCD_TRACE("got WAITMODE delay=%d\n", 1086 RDELAY_WAITMODE-mbx->count); 1087modedone: 1088 /* for first block */ |
1089 mbx->nblk = (bp->b_bcount + (mbx->sz-1)) / mbx->sz; | 1089 mbx->nblk = (bp->bio_bcount + (mbx->sz-1)) / mbx->sz; |
1090 mbx->skip = 0; 1091 1092nextblock: | 1090 mbx->skip = 0; 1091 1092nextblock: |
1093 blknum = (bp->b_blkno / (mbx->sz/DEV_BSIZE)) | 1093 blknum = (bp->bio_blkno / (mbx->sz/DEV_BSIZE)) |
1094 + mbx->p_offset + mbx->skip/mbx->sz; 1095 1096 MCD_TRACE("mcd_doread: read blknum=%d for bp=%p\n", 1097 blknum, bp); 1098 1099 /* build parameter block */ 1100 hsg2msf(blknum,rbuf.start_msf); 1101retry_read: --- 24 unchanged lines hidden (view full) --- 1126 untimeout(mcd_timeout,(caddr_t)MCD_S_WAITREAD, tohandle); 1127 if (mbx->count-- > 0) { 1128 k = inb(port+MCD_FLAGS); 1129 if (!(k & MFL_DATA_NOT_AVAIL)) { /* XXX */ 1130 MCD_TRACE("got data delay=%d\n", 1131 RDELAY_WAITREAD-mbx->count); 1132 got_it: 1133 /* data is ready */ | 1094 + mbx->p_offset + mbx->skip/mbx->sz; 1095 1096 MCD_TRACE("mcd_doread: read blknum=%d for bp=%p\n", 1097 blknum, bp); 1098 1099 /* build parameter block */ 1100 hsg2msf(blknum,rbuf.start_msf); 1101retry_read: --- 24 unchanged lines hidden (view full) --- 1126 untimeout(mcd_timeout,(caddr_t)MCD_S_WAITREAD, tohandle); 1127 if (mbx->count-- > 0) { 1128 k = inb(port+MCD_FLAGS); 1129 if (!(k & MFL_DATA_NOT_AVAIL)) { /* XXX */ 1130 MCD_TRACE("got data delay=%d\n", 1131 RDELAY_WAITREAD-mbx->count); 1132 got_it: 1133 /* data is ready */ |
1134 addr = bp->b_data + mbx->skip; | 1134 addr = bp->bio_data + mbx->skip; |
1135 1136 outb(port+mcd_ctl2,0x04); /* XXX */ 1137 for (i=0; i<mbx->sz; i++) 1138 *addr++ = inb(data_port); 1139 outb(port+mcd_ctl2,0x0c); /* XXX */ 1140 1141 k = inb(port+MCD_FLAGS); 1142 /* If we still have some junk, read it too */ --- 5 unchanged lines hidden (view full) --- 1148 } 1149 1150 if (--mbx->nblk > 0) { 1151 mbx->skip += mbx->sz; 1152 goto nextblock; 1153 } 1154 1155 /* return buffer */ | 1135 1136 outb(port+mcd_ctl2,0x04); /* XXX */ 1137 for (i=0; i<mbx->sz; i++) 1138 *addr++ = inb(data_port); 1139 outb(port+mcd_ctl2,0x0c); /* XXX */ 1140 1141 k = inb(port+MCD_FLAGS); 1142 /* If we still have some junk, read it too */ --- 5 unchanged lines hidden (view full) --- 1148 } 1149 1150 if (--mbx->nblk > 0) { 1151 mbx->skip += mbx->sz; 1152 goto nextblock; 1153 } 1154 1155 /* return buffer */ |
1156 bp->b_resid = 0; | 1156 bp->bio_resid = 0; |
1157 biodone(bp); 1158 1159 cd->flags &= ~(MCDMBXBSY|MCDREADRAW); 1160 mcd_start(mbx->unit); 1161 return; 1162 } 1163 if (!(k & MFL_STATUS_NOT_AVAIL)) { 1164 cd->status = inb(port+mcd_status) & 0xFF; --- 14 unchanged lines hidden (view full) --- 1179readerr: 1180 if (mbx->retry-- > 0) { 1181 printf("mcd%d: retrying\n",unit); 1182 state = MCD_S_BEGIN1; 1183 goto loop; 1184 } 1185harderr: 1186 /* invalidate the buffer */ | 1157 biodone(bp); 1158 1159 cd->flags &= ~(MCDMBXBSY|MCDREADRAW); 1160 mcd_start(mbx->unit); 1161 return; 1162 } 1163 if (!(k & MFL_STATUS_NOT_AVAIL)) { 1164 cd->status = inb(port+mcd_status) & 0xFF; --- 14 unchanged lines hidden (view full) --- 1179readerr: 1180 if (mbx->retry-- > 0) { 1181 printf("mcd%d: retrying\n",unit); 1182 state = MCD_S_BEGIN1; 1183 goto loop; 1184 } 1185harderr: 1186 /* invalidate the buffer */ |
1187 bp->b_ioflags |= BIO_ERROR; 1188 bp->b_resid = bp->b_bcount; | 1187 bp->bio_flags |= BIO_ERROR; 1188 bp->bio_resid = bp->bio_bcount; |
1189 biodone(bp); 1190 1191 cd->flags &= ~(MCDMBXBSY|MCDREADRAW); 1192 mcd_start(mbx->unit); 1193 return; 1194 1195changed: 1196 printf("mcd%d: media changed\n", unit); --- 637 unchanged lines hidden --- | 1189 biodone(bp); 1190 1191 cd->flags &= ~(MCDMBXBSY|MCDREADRAW); 1192 mcd_start(mbx->unit); 1193 return; 1194 1195changed: 1196 printf("mcd%d: media changed\n", unit); --- 637 unchanged lines hidden --- |