Lines Matching defs:fdc
85 #include <dev/fdc/fdcvar.h>
239 struct fdc_data *fdc; /* pointer to controller structure */
270 static SYSCTL_NODE(_debug, OID_AUTO, fdc, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
271 "fdc driver");
319 fdregwr(struct fdc_data *fdc, int reg, uint8_t v)
322 bus_space_write_1(fdc->iot, fdc->ioh[reg], fdc->ioff[reg], v);
326 fdregrd(struct fdc_data *fdc, int reg)
329 return bus_space_read_1(fdc->iot, fdc->ioh[reg], fdc->ioff[reg]);
333 fdctl_wr(struct fdc_data *fdc, u_int8_t v)
336 fdregwr(fdc, FDCTL, v);
340 fdout_wr(struct fdc_data *fdc, u_int8_t v)
343 fdregwr(fdc, FDOUT, v);
347 fdsts_rd(struct fdc_data *fdc)
350 return fdregrd(fdc, FDSTS);
354 fddsr_wr(struct fdc_data *fdc, u_int8_t v)
357 fdregwr(fdc, FDDSR, v);
361 fddata_wr(struct fdc_data *fdc, u_int8_t v)
364 fdregwr(fdc, FDDATA, v);
368 fddata_rd(struct fdc_data *fdc)
371 return fdregrd(fdc, FDDATA);
375 fdin_rd(struct fdc_data *fdc)
378 return fdregrd(fdc, FDCTL);
386 fdbcdr_wr(struct fdc_data *fdc, int iswrite, uint16_t count)
388 fdregwr(fdc, FDBCDR, (count - 1) & 0xff);
389 fdregwr(fdc, FDBCDR + 1,
394 fdc_err(struct fdc_data *fdc, const char *s)
396 fdc->fdc_errs++;
398 if (fdc->fdc_errs < FDC_ERRMAX)
399 device_printf(fdc->fdc_dev, "%s", s);
400 else if (fdc->fdc_errs == FDC_ERRMAX)
401 device_printf(fdc->fdc_dev, "too many errors, not "
417 fdc_in(struct fdc_data *fdc, int *ptr)
423 i = fdsts_rd(fdc) & (NE7_DIO | NE7_RQM);
425 i = fddata_rd(fdc);
431 return (fdc_err(fdc, "ready for output in input\n"));
435 return (fdc_err(fdc, bootverbose? "input ready timeout\n": 0));
439 fdc_out(struct fdc_data *fdc, int x)
445 i = fdsts_rd(fdc) & (NE7_DIO | NE7_RQM);
447 fddata_wr(fdc, x);
451 return (fdc_err(fdc, "ready for input in output\n"));
455 return (fdc_err(fdc, bootverbose? "output ready timeout\n": 0));
467 fdc_cmd(struct fdc_data *fdc, int n_out, ...)
479 if (fdc_out(fdc, i) < 0) {
484 fdc->flags |= FDC_NEEDS_RESET;
486 return fdc_err(fdc, msg);
492 if (fdc_in(fdc, ptr) != 0) {
497 fdc->flags |= FDC_NEEDS_RESET;
499 return fdc_err(fdc, msg);
507 fdc_reset(struct fdc_data *fdc)
511 if (fdc->fdct == FDC_ENHANCED) {
513 fddsr_wr(fdc, I8207X_DSR_SR);
516 fdout_wr(fdc, fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
519 fdout_wr(fdc, fdc->fdout & ~FDO_FDMAEN);
522 fdout_wr(fdc, fdc->fdout);
525 if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, spec1, spec2, 0))
526 device_printf(fdc->fdc_dev, " SPECIFY failed in reset\n");
528 if (fdc->fdct == FDC_ENHANCED) {
529 if (fdc_cmd(fdc, 4,
538 device_printf(fdc->fdc_dev,
541 if (fdc_cmd(fdc, 1,
545 device_printf(fdc->fdc_dev,
555 fdc_sense_drive(struct fdc_data *fdc, int *st3p)
559 if (fdc_cmd(fdc, 2, NE7CMD_SENSED, fdc->fd->fdsu, 1, &st3))
560 return (fdc_err(fdc, "Sense Drive Status failed\n"));
567 fdc_sense_int(struct fdc_data *fdc, int *st0p, int *cylp)
571 ret = fdc_cmd(fdc, 1, NE7CMD_SENSEI, 1, &st0);
573 (void)fdc_err(fdc, "sense intr err reading stat reg 0\n");
587 if (fdc_in(fdc, &cyl) != 0)
588 return fdc_err(fdc, "can't get cyl num\n");
597 fdc_read_status(struct fdc_data *fdc)
602 ret = fdc_in(fdc, &status);
603 fdc->status[i] = status;
609 fdc->flags |= FDC_STAT_VALID;
611 fdc->flags &= ~FDC_STAT_VALID;
622 struct fdc_data *fdc;
625 fdc = fd->fdc;
626 fdc->fdout &= ~FDO_FDSEL;
627 fdc->fdout |= FDO_FDMAEN | FDO_FRST | fd->fdsu;
628 fdout_wr(fdc, fdc->fdout);
639 mtx_assert(&fd->fdc->fdc_mtx, MA_OWNED);
647 bioq_disksort(&fd->fdc->head, bp);
651 wakeup(&fd->fdc->head);
657 struct fdc_data *fdc;
659 fdc = fd->fdc;
661 mtx_assert(&fdc->fdc_mtx, MA_OWNED);
665 fdc->fdout |= (FDO_MOEN0 << fd->fdsu);
670 fdc->fdout &= ~(FDO_MOEN0 << fd->fdsu);
672 fdout_wr(fdc, fdc->fdout);
680 mtx_assert(&fd->fdc->fdc_mtx, MA_OWNED);
707 fdc_pio(struct fdc_data *fdc)
713 bp = fdc->bp;
714 cptr = fdc->fd->fd_ioptr;
715 count = fdc->fd->fd_iosize;
718 fdbcdr_wr(fdc, 0, count);
719 bus_space_read_multi_1(fdc->iot, fdc->ioh[FD_YE_DATAPORT],
720 fdc->ioff[FD_YE_DATAPORT], cptr, count);
722 bus_space_write_multi_1(fdc->iot, fdc->ioh[FD_YE_DATAPORT],
723 fdc->ioff[FD_YE_DATAPORT], cptr, count);
724 fdbcdr_wr(fdc, 0, count); /* needed? */
729 fdc_biodone(struct fdc_data *fdc, int error)
734 fd = fdc->fd;
735 bp = fdc->bp;
737 mtx_lock(&fdc->fdc_mtx);
740 fdc->bp = NULL;
741 fdc->fd = NULL;
742 mtx_unlock(&fdc->fdc_mtx);
744 if ((debugflags & 2) && fd->fdc->retry > 0)
745 printf("retries: %d\n", fd->fdc->retry);
758 fdc_worker(struct fdc_data *fdc)
773 bp = fdc->bp;
774 fd = fdc->fd;
776 (fdc->retry >= retries || (fd->options & FDOPT_NORETRY))) {
779 if (fdc->flags & FDC_NEEDS_RESET) {
780 mtx_lock(&fdc->fdc_mtx);
782 mtx_unlock(&fdc->fdc_mtx);
784 return (fdc_biodone(fdc, EIO));
791 fd->fd_ioptr, fd->fd_iosize, fdc->dmachan);
792 mtx_lock(&fdc->fdc_mtx);
794 mtx_unlock(&fdc->fdc_mtx);
798 if (fdc->flags & FDC_NEEDS_RESET) {
799 fdc->flags &= ~FDC_NEEDS_RESET;
800 fdc_reset(fdc);
804 tsleep(fdc, PRIBIO, "fdcrst", hz);
807 fdc_sense_int(fdc, &st0, &cyl);
813 if (fdc->bp == NULL) {
814 mtx_lock(&fdc->fdc_mtx);
816 fdc->bp = bioq_takefirst(&fdc->head);
817 if (fdc->bp == NULL)
818 msleep(&fdc->head, &fdc->fdc_mtx,
820 } while (fdc->bp == NULL &&
821 (fdc->flags & FDC_KTHREAD_EXIT) == 0);
822 mtx_unlock(&fdc->fdc_mtx);
824 if (fdc->bp == NULL)
831 bp = fdc->bp;
832 fd = fdc->fd = bp->bio_driver1;
833 fdc->retry = 0;
844 if (fdc->fdct == FDC_ENHANCED)
845 fddsr_wr(fdc, fd->ft->trans);
847 fdctl_wr(fdc, fd->ft->trans);
851 !(fdin_rd(fdc) & FDI_DCHG) &&
854 return (fdc_biodone(fdc, 0));
862 return (fdc_biodone(fdc, ENXIO));
865 if (fdin_rd(fdc) & FDI_DCHG) {
868 mtx_lock(&fdc->fdc_mtx);
871 mtx_unlock(&fdc->fdc_mtx);
879 return (fdc_biodone(fdc, ENXIO));
885 if(fdc_sense_drive(fdc, &st3) != 0)
888 return (fdc_biodone(fdc, EROFS));
902 if (fdc->retry == 0 &&
914 fdc->retry > 2) {
916 if (fdc_cmd(fdc, 2, NE7CMD_RECAL, fd->fdsu, 0))
918 tsleep(fdc, PRIBIO, "fdrecal", hz);
920 if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
929 tsleep(fdc->fd, PRIBIO, "fdhdstl", settle);
937 if (fdc_cmd(fdc, 3, NE7CMD_SEEK, fd->fdsu, descyl, 0))
939 tsleep(fdc, PRIBIO, "fdseek", hz);
941 if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
950 tsleep(fdc->fd, PRIBIO, "fdhdstl", settle);
957 fd->fd_ioptr, fdc->retry);
963 && !(fdc->flags & FDC_NODMA)) {
966 fd->fd_ioptr, fd->fd_iosize, fdc->dmachan);
967 mtx_lock(&fdc->fdc_mtx);
969 mtx_unlock(&fdc->fdc_mtx);
973 if (fdc->flags & FDC_NODMA) {
977 fdbcdr_wr(fdc, 1, fd->fd_iosize);
980 fdc_pio(fdc);
988 if (fdc_cmd(fdc, 6,
999 if (fdc_cmd(fdc, 2,
1006 if (fdc_cmd(fdc, 9,
1021 if (fdc_cmd(fdc, 9,
1039 i = tsleep(fdc, PRIBIO, "fddata", hz);
1042 if (i == 0 && (fdc->flags & FDC_NODMA) && (bp->bio_cmd == BIO_READ))
1043 fdc_pio(fdc);
1049 fd->fd_ioptr, fd->fd_iosize, fdc->dmachan);
1050 mtx_lock(&fdc->fdc_mtx);
1052 mtx_unlock(&fdc->fdc_mtx);
1066 fdc->flags |= FDC_NEEDS_RESET;
1071 if (fdc_read_status(fdc))
1076 fdc->status[0], fdc->status[1],
1077 fdc->status[2], fdc->status[3]);
1079 st0 = fdc->status[0] & NE7_ST0_IC;
1082 if (st0 == NE7_ST0_IC_AT && fdc->status[1] & NE7_ST1_OR) {
1092 fdc->flags |= FDC_NEEDS_RESET;
1096 if(st0 == NE7_ST0_IC_AT && fdc->status[2] & NE7_ST2_WC) {
1102 fdc->status[0], fdc->status[1], fdc->status[2],
1103 fdc->status[3], fdc->status[4], fdc->status[5]);
1116 idp->cyl = fdc->status[3];
1117 idp->head = fdc->status[4];
1118 idp->sec = fdc->status[5];
1119 idp->secshift = fdc->status[6];
1136 fdc->retry = 0;
1144 return (fdc_biodone(fdc, 0));
1150 struct fdc_data *fdc;
1152 fdc = arg;
1155 mtx_lock(&fdc->fdc_mtx);
1156 fdc->flags |= FDC_KTHREAD_ALIVE;
1157 while ((fdc->flags & FDC_KTHREAD_EXIT) == 0) {
1158 mtx_unlock(&fdc->fdc_mtx);
1159 i = fdc_worker(fdc);
1161 if (fdc->bp != NULL)
1162 g_print_bio("", fdc->bp, "");
1165 fdc->retry += i;
1166 mtx_lock(&fdc->fdc_mtx);
1168 fdc->flags &= ~(FDC_KTHREAD_EXIT | FDC_KTHREAD_ALIVE);
1169 mtx_unlock(&fdc->fdc_mtx);
1180 struct fdc_data *fdc;
1182 fdc = fd->fdc;
1183 mtx_lock(&fdc->fdc_mtx);
1189 bioq_disksort(&fdc->head, bp);
1190 wakeup(&fdc->head);
1197 mtx_unlock(&fdc->fdc_mtx);
1206 struct fdc_data *fdc;
1210 fdc = fd->fdc;
1221 mtx_lock(&fdc->fdc_mtx);
1223 mtx_unlock(&fdc->fdc_mtx);
1224 if (fdc_cmd(fdc, 2, NE7CMD_RECAL, fd->fdsu, 0))
1226 tsleep(fdc, PRIBIO, "fdrecal", hz);
1227 if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
1233 if (fdc_cmd(fdc, 3, NE7CMD_SEEK, fd->fdsu, 1, 0))
1235 tsleep(fdc, PRIBIO, "fdseek", hz);
1236 if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
1239 if (fdin_rd(fdc) & FDI_DCHG) {
1242 mtx_lock(&fdc->fdc_mtx);
1244 mtx_unlock(&fdc->fdc_mtx);
1246 if (fdc_sense_drive(fdc, &st3) != 0)
1250 mtx_lock(&fdc->fdc_mtx);
1256 mtx_unlock(&fdc->fdc_mtx);
1411 struct fdc_data *fdc;
1415 fdc = fd->fdc;
1441 mtx_lock(&fdc->fdc_mtx);
1443 mtx_unlock(&fdc->fdc_mtx);
1446 mtx_lock(&fdc->fdc_mtx);
1448 mtx_unlock(&fdc->fdc_mtx);
1531 fd->fdc->fdc_errs = 0;
1536 if ((fd->fdc->flags & FDC_STAT_VALID) == 0)
1538 memcpy(fsp->status, fd->fdc->status, 7 * sizeof(u_int));
1552 mtx_lock(&fd->fdc->fdc_mtx);
1554 mtx_unlock(&fd->fdc->fdc_mtx);
1588 fdc_release_resources(struct fdc_data *fdc)
1594 dev = fdc->fdc_dev;
1595 if (fdc->fdc_intr)
1596 bus_teardown_intr(dev, fdc->res_irq, fdc->fdc_intr);
1597 fdc->fdc_intr = NULL;
1598 if (fdc->res_irq != NULL)
1599 bus_release_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
1600 fdc->res_irq);
1601 fdc->res_irq = NULL;
1604 if (fdc->resio[i] != NULL && fdc->resio[i] != last) {
1606 fdc->ridio[i], fdc->resio[i]);
1607 last = fdc->resio[i];
1608 fdc->resio[i] = NULL;
1611 if (fdc->res_drq != NULL)
1612 bus_release_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
1613 fdc->res_drq);
1614 fdc->res_drq = NULL;
1654 fdc_initial_reset(device_t dev, struct fdc_data *fdc)
1662 if (fdsts_rd(fdc) == 0xff)
1669 fdout_wr(fdc, 0);
1670 fdout_wr(fdc, 0);
1671 if (fdsts_rd(fdc) != 0)
1677 fdout_wr(fdc, FDO_FRST);
1679 if (fdsts_rd(fdc) != 0x80)
1683 if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(6, 240),
1696 if (fdc_cmd(fdc, 1, NE7CMD_VERSION, 1, &ic_type))
1698 if (fdc_cmd(fdc, 1, 0x18, 1, &part_id))
1706 fdc->fdct = FDC_NE765;
1712 fdc->fdct = FDC_ENHANCED;
1716 fdc->fdct = FDC_UNKNOWN;
1725 struct fdc_data *fdc;
1728 fdc = device_get_softc(dev);
1734 if (fdc->fdc_intr)
1735 bus_teardown_intr(dev, fdc->res_irq, fdc->fdc_intr);
1736 fdc->fdc_intr = NULL;
1739 mtx_lock(&fdc->fdc_mtx);
1740 fdc->flags |= FDC_KTHREAD_EXIT;
1741 wakeup(&fdc->head);
1742 while ((fdc->flags & FDC_KTHREAD_ALIVE) != 0)
1743 msleep(fdc->fdc_thread, &fdc->fdc_mtx, PRIBIO, "fdcdet", 0);
1744 mtx_unlock(&fdc->fdc_mtx);
1747 fdout_wr(fdc, 0);
1749 if (!(fdc->flags & FDC_NODMA))
1750 isa_dma_release(fdc->dmachan);
1751 fdc_release_resources(fdc);
1752 mtx_destroy(&fdc->fdc_mtx);
1757 * Add a child device to the fdc controller. It will then be probed etc.
1784 struct fdc_data *fdc;
1787 fdc = device_get_softc(dev);
1788 fdc->fdc_dev = dev;
1789 error = fdc_initial_reset(dev, fdc);
1794 error = bus_setup_intr(dev, fdc->res_irq,
1796 ((fdc->flags & FDC_NOFAST) ? INTR_MPSAFE : 0),
1797 ((fdc->flags & FDC_NOFAST) ? NULL : fdc_intr_fast),
1798 ((fdc->flags & FDC_NOFAST) ? fdc_intr : NULL),
1799 fdc, &fdc->fdc_intr);
1804 if (!(fdc->flags & FDC_NODMA)) {
1805 error = isa_dma_acquire(fdc->dmachan);
1807 error = isa_dma_init(fdc->dmachan,
1810 isa_dma_release(fdc->dmachan);
1815 fdc->fdcu = device_get_unit(dev);
1816 fdc->flags |= FDC_NEEDS_RESET;
1818 mtx_init(&fdc->fdc_mtx, "fdc lock", NULL, MTX_DEF);
1821 fdout_wr(fdc, fdc->fdout = 0);
1822 bioq_init(&fdc->head);
1832 struct fdc_data *fdc;
1834 fdc = device_get_softc(dev);
1835 kproc_create(fdc_thread, fdc, &fdc->fdc_thread, 0, 0,
1836 "fdc%d", device_get_unit(dev));
1887 struct fdc_data *fdc;
1893 fdc = device_get_softc(device_get_parent(dev));
1897 fd->fdc = fdc;
1927 mtx_lock(&fdc->fdc_mtx);
1932 fdc->fd = fd;
1933 fdc_reset(fdc); /* XXX reset, then unreset, etc. */
1938 if ((fdc_sense_drive(fdc, &st3) == 0) &&
1941 if (fdc_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0) == 0) {
1945 fdc_sense_int(fdc, NULL, NULL);
1957 if (fdc_cmd(fdc, 2, NE7CMD_RECAL, fdsu, 0) == 0) {
1962 if (fdc_sense_int(fdc, &st0, NULL) == 0 &&
1970 fdc->fd = NULL;
1971 mtx_unlock(&fdc->fdc_mtx);
1999 fd->fdc = fdc;
2002 callout_init_mtx(&fd->toffhandle, &fd->fdc->fdc_mtx, 0);
2106 DRIVER_MODULE(fd, fdc, fd_driver, fdc_modevent, 0);