fdc.c (dc5df763e473f6204f45e438a84477b0f66668ed) fdc.c (dc16046f96bdcd9068aec31c1741e0db35296a94)
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Don Ahn.
7 *
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Don Ahn.
7 *
8 * Portions Copyright (c) 1993, 1994, 1995 by
8 * Copyright (c) 1993, 1994 by
9 * jc@irbs.UUCP (John Capo)
10 * vak@zebub.msk.su (Serge Vakulenko)
11 * ache@astral.msk.su (Andrew A. Chernov)
9 * jc@irbs.UUCP (John Capo)
10 * vak@zebub.msk.su (Serge Vakulenko)
11 * ache@astral.msk.su (Andrew A. Chernov)
12 *
13 * Copyright (c) 1993, 1994, 1995 by
12 * joerg_wunsch@uriah.sax.de (Joerg Wunsch)
13 * dufault@hda.com (Peter Dufault)
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.

--- 16 unchanged lines hidden (view full) ---

36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * SUCH DAMAGE.
42 *
43 * from: @(#)fd.c 7.4 (Berkeley) 5/25/91
14 * joerg_wunsch@uriah.sax.de (Joerg Wunsch)
15 * dufault@hda.com (Peter Dufault)
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.

--- 16 unchanged lines hidden (view full) ---

38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * SUCH DAMAGE.
44 *
45 * from: @(#)fd.c 7.4 (Berkeley) 5/25/91
44 * $Id: fd.c,v 1.46 1994/12/04 20:22:19 joerg Exp $
46 * $Id: fd.c,v 1.16.1.2 1995/01/10 23:49:30 j Exp $
45 *
46 */
47
48#include "ft.h"
49#if NFT < 1
50#undef NFDC
51#endif
52#include "fd.h"

--- 27 unchanged lines hidden (view full) ---

80#include <machine/stdarg.h>
81#if NFT > 0
82#include <sys/ftape.h>
83#include <i386/isa/ftreg.h>
84#endif
85
86static int fd_goaway(struct kern_devconf *, int);
87static int fdc_goaway(struct kern_devconf *, int);
47 *
48 */
49
50#include "ft.h"
51#if NFT < 1
52#undef NFDC
53#endif
54#include "fd.h"

--- 27 unchanged lines hidden (view full) ---

82#include <machine/stdarg.h>
83#if NFT > 0
84#include <sys/ftape.h>
85#include <i386/isa/ftreg.h>
86#endif
87
88static int fd_goaway(struct kern_devconf *, int);
89static int fdc_goaway(struct kern_devconf *, int);
88static int fd_externalize(struct proc *, struct kern_devconf *, void *, size_t);
90static int
91fd_externalize(struct proc *, struct kern_devconf *, void *, size_t);
89
90/*
91 * Templates for the kern_devconf structures used when we attach.
92 */
93static struct kern_devconf kdc_fd[NFD] = { {
94 0, 0, 0, /* filled in by kern_devconf.c */
95 "fd", 0, { MDDT_DISK, 0 },
96 fd_externalize, 0, fd_goaway, DISK_EXTERNALLEN,
97 0, /* parent */
98 0, /* parentdata */
92
93/*
94 * Templates for the kern_devconf structures used when we attach.
95 */
96static struct kern_devconf kdc_fd[NFD] = { {
97 0, 0, 0, /* filled in by kern_devconf.c */
98 "fd", 0, { MDDT_DISK, 0 },
99 fd_externalize, 0, fd_goaway, DISK_EXTERNALLEN,
100 0, /* parent */
101 0, /* parentdata */
99 DC_UNKNOWN, /* state */
102 DC_UNCONFIGURED, /* state */
100 "floppy disk"
101} };
102
103struct kern_devconf kdc_fdc[NFDC] = { {
104 0, 0, 0, /* filled in by kern_devconf.c */
105 "fdc", 0, { MDDT_ISA, 0, "bio" },
106 isa_generic_externalize, 0, fdc_goaway, ISA_EXTERNALLEN,
107 0, /* parent */
108 0, /* parentdata */
103 "floppy disk"
104} };
105
106struct kern_devconf kdc_fdc[NFDC] = { {
107 0, 0, 0, /* filled in by kern_devconf.c */
108 "fdc", 0, { MDDT_ISA, 0, "bio" },
109 isa_generic_externalize, 0, fdc_goaway, ISA_EXTERNALLEN,
110 0, /* parent */
111 0, /* parentdata */
109 DC_UNKNOWN, /* state */
112 DC_UNCONFIGURED, /* state */
110 "floppy disk/tape controller"
111} };
112
113static inline void
114fd_registerdev(int ctlr, int unit)
115{
116 if(unit != 0)
117 kdc_fd[unit] = kdc_fd[0];

--- 91 unchanged lines hidden (view full) ---

209{ 18,2,0xFF,0x02,80,2880,1,FDC_500KBPS,2,0x02,2 }, /* 1.44M in HD 5.25in */
210{ 10,2,0xFF,0x10,82,1640,1,FDC_300KBPS,2,0x2E,1 }, /* 820K in HD 5.25in */
211{ 10,2,0xFF,0x10,80,1600,1,FDC_300KBPS,2,0x2E,1 }, /* 800K in HD 5.25in */
212{ 9,2,0xFF,0x20,80,1440,1,FDC_300KBPS,2,0x50,1 }, /* 720K in HD 5.25in */
213{ 9,2,0xFF,0x23,40, 720,2,FDC_300KBPS,2,0x50,1 }, /* 360K in HD 5.25in */
214};
215
216#define DRVS_PER_CTLR 2 /* 2 floppies */
113 "floppy disk/tape controller"
114} };
115
116static inline void
117fd_registerdev(int ctlr, int unit)
118{
119 if(unit != 0)
120 kdc_fd[unit] = kdc_fd[0];

--- 91 unchanged lines hidden (view full) ---

212{ 18,2,0xFF,0x02,80,2880,1,FDC_500KBPS,2,0x02,2 }, /* 1.44M in HD 5.25in */
213{ 10,2,0xFF,0x10,82,1640,1,FDC_300KBPS,2,0x2E,1 }, /* 820K in HD 5.25in */
214{ 10,2,0xFF,0x10,80,1600,1,FDC_300KBPS,2,0x2E,1 }, /* 800K in HD 5.25in */
215{ 9,2,0xFF,0x20,80,1440,1,FDC_300KBPS,2,0x50,1 }, /* 720K in HD 5.25in */
216{ 9,2,0xFF,0x23,40, 720,2,FDC_300KBPS,2,0x50,1 }, /* 360K in HD 5.25in */
217};
218
219#define DRVS_PER_CTLR 2 /* 2 floppies */
220
217/***********************************************************************\
218* Per controller structure. *
219\***********************************************************************/
220struct fdc_data fdc_data[NFDC];
221
222/***********************************************************************\
223* Per drive structure. *
224* N per controller (DRVS_PER_CTLR) *

--- 102 unchanged lines hidden (view full) ---

327int fd_debug = 0;
328#define TRACE0(arg) if(fd_debug) printf(arg)
329#define TRACE1(arg1, arg2) if(fd_debug) printf(arg1, arg2)
330#else /* DEBUG */
331#define TRACE0(arg)
332#define TRACE1(arg1, arg2)
333#endif /* DEBUG */
334
221/***********************************************************************\
222* Per controller structure. *
223\***********************************************************************/
224struct fdc_data fdc_data[NFDC];
225
226/***********************************************************************\
227* Per drive structure. *
228* N per controller (DRVS_PER_CTLR) *

--- 102 unchanged lines hidden (view full) ---

331int fd_debug = 0;
332#define TRACE0(arg) if(fd_debug) printf(arg)
333#define TRACE1(arg1, arg2) if(fd_debug) printf(arg1, arg2)
334#else /* DEBUG */
335#define TRACE0(arg)
336#define TRACE1(arg1, arg2)
337#endif /* DEBUG */
338
339/* autoconfig structure */
340
341struct isa_driver fdcdriver = {
342 fdprobe, fdattach, "fdc",
343};
344
335struct isa_device *fdcdevs[NFDC];
336
337/*
338 * Provide hw.devconf information.
339 */
340static int
345struct isa_device *fdcdevs[NFDC];
346
347/*
348 * Provide hw.devconf information.
349 */
350static int
341fd_externalize(struct proc *p, struct kern_devconf *kdc, void *userp, size_t len)
351fd_externalize(struct proc *p, struct kern_devconf *kdc,
352 void *userp, size_t len)
342{
343 return disk_externalize(fd_data[kdc->kdc_unit].fdsu, userp, &len);
344}
345
346static int
353{
354 return disk_externalize(fd_data[kdc->kdc_unit].fdsu, userp, &len);
355}
356
357static int
347fdc_externalize(struct proc *p, struct kern_devconf *kdc, void *userp, size_t len)
358fdc_externalize(struct proc *p, struct kern_devconf *kdc,
359 void *userp, size_t len)
348{
349 return isa_externalize(fdcdevs[kdc->kdc_unit], userp, &len);
350}
351
352static int
353fdc_err(fdcu_t fdcu, const char *s)
354{
355 fdc_data[fdcu].fdc_errs++;

--- 121 unchanged lines hidden (view full) ---

477 fdc->flags &= ~FDC_STAT_VALID;
478
479 return ret;
480}
481
482/****************************************************************************/
483/* autoconfiguration stuff */
484/****************************************************************************/
360{
361 return isa_externalize(fdcdevs[kdc->kdc_unit], userp, &len);
362}
363
364static int
365fdc_err(fdcu_t fdcu, const char *s)
366{
367 fdc_data[fdcu].fdc_errs++;

--- 121 unchanged lines hidden (view full) ---

489 fdc->flags &= ~FDC_STAT_VALID;
490
491 return ret;
492}
493
494/****************************************************************************/
495/* autoconfiguration stuff */
496/****************************************************************************/
485struct isa_driver fdcdriver = {
486 fdprobe, fdattach, "fdc",
487};
488
497
489
490/*
491 * probe for existance of controller
492 */
493static int
494fdprobe(struct isa_device *dev)
495{
496 fdcu_t fdcu = dev->id_unit;
497 if(fdc_data[fdcu].flags & FDC_ATTACHED)

--- 12 unchanged lines hidden (view full) ---

510
511 /* see if it can handle a command */
512 if (fd_cmd(fdcu,
513 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240), NE7_SPEC_2(2, 0),
514 0))
515 {
516 return(0);
517 }
498/*
499 * probe for existance of controller
500 */
501static int
502fdprobe(struct isa_device *dev)
503{
504 fdcu_t fdcu = dev->id_unit;
505 if(fdc_data[fdcu].flags & FDC_ATTACHED)

--- 12 unchanged lines hidden (view full) ---

518
519 /* see if it can handle a command */
520 if (fd_cmd(fdcu,
521 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240), NE7_SPEC_2(2, 0),
522 0))
523 {
524 return(0);
525 }
526 kdc_fdc[fdcu].kdc_state = DC_IDLE;
518 return (IO_FDCSIZE);
519}
520
521/*
522 * wire controller into system, look for floppy units
523 */
524static int
525fdattach(struct isa_device *dev)

--- 33 unchanged lines hidden (view full) ---

559 case 1: fdt = ((rtcin(RTC_FDISKETTE) << 4) & 0xf0);
560 break;
561 default: fdt = RTCFDT_NONE;
562 break;
563 }
564 /* is there a unit? */
565 if ((fdt == RTCFDT_NONE)
566#if NFT > 0
527 return (IO_FDCSIZE);
528}
529
530/*
531 * wire controller into system, look for floppy units
532 */
533static int
534fdattach(struct isa_device *dev)

--- 33 unchanged lines hidden (view full) ---

568 case 1: fdt = ((rtcin(RTC_FDISKETTE) << 4) & 0xf0);
569 break;
570 default: fdt = RTCFDT_NONE;
571 break;
572 }
573 /* is there a unit? */
574 if ((fdt == RTCFDT_NONE)
575#if NFT > 0
567 || (fdsu >= DRVS_PER_CTLR)) {
576 || (fdsu >= DRVS_PER_CTLR)) {
568#else
569 ) {
570 fd->type = NO_TYPE;
571#endif
572#if NFT > 0
573 /* If BIOS says no floppy, or > 2nd device */
574 /* Probe for and attach a floppy tape. */
575 if ((dev->id_flags & FT_PROBE) && ftattach(dev, fdup))

--- 104 unchanged lines hidden (view full) ---

680 fd->type = FD_720;
681 break;
682 default:
683 printf("unknown]");
684 fd->type = NO_TYPE;
685 break;
686 }
687 fd_registerdev(fdcu, fdu);
577#else
578 ) {
579 fd->type = NO_TYPE;
580#endif
581#if NFT > 0
582 /* If BIOS says no floppy, or > 2nd device */
583 /* Probe for and attach a floppy tape. */
584 if ((dev->id_flags & FT_PROBE) && ftattach(dev, fdup))

--- 104 unchanged lines hidden (view full) ---

689 fd->type = FD_720;
690 break;
691 default:
692 printf("unknown]");
693 fd->type = NO_TYPE;
694 break;
695 }
696 fd_registerdev(fdcu, fdu);
697 kdc_fd[fdu].kdc_state = DC_IDLE;
688 if(dk_ndrive < DK_NDRIVE) {
689 sprintf(dk_names[dk_ndrive], "fd%d", fdu);
690 dk_wpms[dk_ndrive] = (500 * 1024 / 2) / 1000;
691 fd->dkunit = dk_ndrive++;
692 } else {
693 fd->dkunit = -1;
694 }
695 }

--- 32 unchanged lines hidden (view full) ---

728 /* make sure controller is selected and specified */
729 if((fdout & (FDO_FRST|FDO_FDMAEN)) == 0)
730 needspecify = 1;
731 fdout |= (FDO_FRST|FDO_FDMAEN);
732 }
733
734 outb(fdc_data[fdcu].baseport+FDOUT, fdout);
735 fdc_data[fdcu].fdout = fdout;
698 if(dk_ndrive < DK_NDRIVE) {
699 sprintf(dk_names[dk_ndrive], "fd%d", fdu);
700 dk_wpms[dk_ndrive] = (500 * 1024 / 2) / 1000;
701 fd->dkunit = dk_ndrive++;
702 } else {
703 fd->dkunit = -1;
704 }
705 }

--- 32 unchanged lines hidden (view full) ---

738 /* make sure controller is selected and specified */
739 if((fdout & (FDO_FRST|FDO_FDMAEN)) == 0)
740 needspecify = 1;
741 fdout |= (FDO_FRST|FDO_FDMAEN);
742 }
743
744 outb(fdc_data[fdcu].baseport+FDOUT, fdout);
745 fdc_data[fdcu].fdout = fdout;
746 kdc_fdc[fdcu].kdc_state = (fdout & FDO_FRST)? DC_BUSY: DC_IDLE;
736 TRACE1("[0x%x->FDOUT]", fdout);
737
738 if(needspecify) {
739 /*
740 * XXX
741 * special case: since we have just woken up the FDC
742 * from its sleep, we silently assume the command will
743 * be accepted, and do not test for a timeout

--- 5 unchanged lines hidden (view full) ---

749}
750
751/* ARGSUSED */
752static void
753fd_turnoff(void *arg1)
754{
755 fdu_t fdu = (fdu_t)arg1;
756 int s;
747 TRACE1("[0x%x->FDOUT]", fdout);
748
749 if(needspecify) {
750 /*
751 * XXX
752 * special case: since we have just woken up the FDC
753 * from its sleep, we silently assume the command will
754 * be accepted, and do not test for a timeout

--- 5 unchanged lines hidden (view full) ---

760}
761
762/* ARGSUSED */
763static void
764fd_turnoff(void *arg1)
765{
766 fdu_t fdu = (fdu_t)arg1;
767 int s;
757
758 fd_p fd = fd_data + fdu;
768 fd_p fd = fd_data + fdu;
769
770 TRACE1("[fd%d: turnoff]", fdu);
759 s = splbio();
760 fd->flags &= ~FD_MOTOR;
761 set_motor(fd->fdc->fdcu, fd->fdsu, TURNOFF);
762 splx(s);
763}
764
765/* ARGSUSED */
766static void

--- 201 unchanged lines hidden (view full) ---

968 * Check to make sure the diskette is writable:
969 */
970 int err = 0;
971
972 if (fd_sense_drive_status(fdc, &st3) != 0)
973 err = EIO;
974 else if ( (st3 & NE7_ST3_WP) )
975 {
771 s = splbio();
772 fd->flags &= ~FD_MOTOR;
773 set_motor(fd->fdc->fdcu, fd->fdsu, TURNOFF);
774 splx(s);
775}
776
777/* ARGSUSED */
778static void

--- 201 unchanged lines hidden (view full) ---

980 * Check to make sure the diskette is writable:
981 */
982 int err = 0;
983
984 if (fd_sense_drive_status(fdc, &st3) != 0)
985 err = EIO;
986 else if ( (st3 & NE7_ST3_WP) )
987 {
988 /* XXX should be tprintf() */
976 printf("fd%d: drive is write protected.\n", fdu);
989 printf("fd%d: drive is write protected.\n", fdu);
977 err = ENXIO;
990 err = EIO;
978 }
979
980 if (err) {
981 set_motor(fdc->fdcu, fd_data[fdu].fdsu, TURNOFF);
982 return err;
983 }
984 }
985
986 set_motor(fdc->fdcu, fd_data[fdu].fdsu, TURNOFF);
987
988 fd_data[fdu].ft = fd_types + type - 1;
989 fd_data[fdu].flags |= FD_OPEN;
991 }
992
993 if (err) {
994 set_motor(fdc->fdcu, fd_data[fdu].fdsu, TURNOFF);
995 return err;
996 }
997 }
998
999 set_motor(fdc->fdcu, fd_data[fdu].fdsu, TURNOFF);
1000
1001 fd_data[fdu].ft = fd_types + type - 1;
1002 fd_data[fdu].flags |= FD_OPEN;
1003 kdc_fd[fdu].kdc_state = DC_BUSY;
990
991 return 0;
992}
993
994int
995fdclose(dev_t dev, int flags)
996{
997 fdu_t fdu = FDUNIT(minor(dev));
998
999#if NFT > 0
1000 int type = FDTYPE(minor(dev));
1001
1002 if (type & F_TAPE_TYPE)
1003 return ftclose(dev, flags);
1004#endif
1005 fd_data[fdu].flags &= ~FD_OPEN;
1006 fd_data[fdu].options &= ~FDOPT_NORETRY;
1004
1005 return 0;
1006}
1007
1008int
1009fdclose(dev_t dev, int flags)
1010{
1011 fdu_t fdu = FDUNIT(minor(dev));
1012
1013#if NFT > 0
1014 int type = FDTYPE(minor(dev));
1015
1016 if (type & F_TAPE_TYPE)
1017 return ftclose(dev, flags);
1018#endif
1019 fd_data[fdu].flags &= ~FD_OPEN;
1020 fd_data[fdu].options &= ~FDOPT_NORETRY;
1021 kdc_fd[fdu].kdc_state = DC_IDLE;
1022
1007 return(0);
1008}
1009
1010
1011/****************************************************************************/
1012/* fdstrategy */
1013/****************************************************************************/
1014void

--- 848 unchanged lines hidden ---
1023 return(0);
1024}
1025
1026
1027/****************************************************************************/
1028/* fdstrategy */
1029/****************************************************************************/
1030void

--- 848 unchanged lines hidden ---