1996-06-14 10:04:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Don Ahn.
|
|
|
|
*
|
1998-12-14 09:06:23 +00:00
|
|
|
* Libretto PCMCIA floppy support by David Horwitt (dhorwitt@ucsd.edu)
|
|
|
|
* aided by the Linux floppy driver modifications from David Bateman
|
|
|
|
* (dbateman@eng.uts.edu.au).
|
|
|
|
*
|
1996-06-14 10:04:54 +00:00
|
|
|
* Copyright (c) 1993, 1994 by
|
|
|
|
* jc@irbs.UUCP (John Capo)
|
|
|
|
* vak@zebub.msk.su (Serge Vakulenko)
|
|
|
|
* ache@astral.msk.su (Andrew A. Chernov)
|
|
|
|
*
|
|
|
|
* Copyright (c) 1993, 1994, 1995 by
|
|
|
|
* joerg_wunsch@uriah.sax.de (Joerg Wunsch)
|
|
|
|
* dufault@hda.com (Peter Dufault)
|
|
|
|
*
|
|
|
|
* 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 the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
* from: @(#)fd.c 7.4 (Berkeley) 5/25/91
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1996-06-14 10:04:54 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-09-17 08:01:07 +00:00
|
|
|
#include "opt_fdc.h"
|
2000-03-19 15:18:22 +00:00
|
|
|
#include "card.h"
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2001-05-06 05:49:11 +00:00
|
|
|
#include <sys/kernel.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1999-04-18 14:42:20 +00:00
|
|
|
#include <sys/bus.h>
|
1996-06-14 10:04:54 +00:00
|
|
|
#include <sys/conf.h>
|
2001-05-02 13:59:03 +00:00
|
|
|
#include <sys/disklabel.h>
|
2001-05-06 05:49:11 +00:00
|
|
|
#include <sys/devicestat.h>
|
1999-04-18 14:42:20 +00:00
|
|
|
#include <sys/fcntl.h>
|
2001-05-02 13:59:03 +00:00
|
|
|
#include <sys/lock.h>
|
1996-06-14 10:04:54 +00:00
|
|
|
#include <sys/malloc.h>
|
1999-04-18 14:42:20 +00:00
|
|
|
#include <sys/module.h>
|
2001-05-02 13:59:03 +00:00
|
|
|
#include <sys/mutex.h>
|
1996-06-14 10:04:54 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/syslog.h>
|
1999-04-18 14:42:20 +00:00
|
|
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <machine/ioctl_fd.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
|
|
|
#include <isa/isavar.h>
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#include <pc98/pc98/pc98.h>
|
1997-02-07 19:07:43 +00:00
|
|
|
#include <pc98/pc98/pc98_machdep.h>
|
1996-10-23 07:25:35 +00:00
|
|
|
#include <pc98/pc98/epsonio.h>
|
1996-06-14 10:04:54 +00:00
|
|
|
#include <pc98/pc98/fdreg.h>
|
1999-09-23 14:21:14 +00:00
|
|
|
#include <isa/fdc.h>
|
1996-06-14 10:04:54 +00:00
|
|
|
#else
|
1999-09-23 14:21:14 +00:00
|
|
|
#include <isa/isareg.h>
|
|
|
|
#include <isa/fdreg.h>
|
|
|
|
#include <isa/fdc.h>
|
1999-06-01 13:14:35 +00:00
|
|
|
#include <isa/rtc.h>
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
|
|
|
|
2000-11-05 14:31:19 +00:00
|
|
|
/* misuse a flag to identify format operation */
|
|
|
|
|
1997-10-21 09:48:38 +00:00
|
|
|
/* configuration flags */
|
|
|
|
#define FDC_PRETEND_D0 (1 << 0) /* pretend drive 0 to be there */
|
2000-01-09 10:01:21 +00:00
|
|
|
#define FDC_NO_FIFO (1 << 2) /* do not enable FIFO */
|
1997-10-21 09:48:38 +00:00
|
|
|
|
|
|
|
/* internally used only, not really from CMOS: */
|
|
|
|
#define RTCFDT_144M_PRETENDED 0x1000
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
/* error returns for fd_cmd() */
|
|
|
|
#define FD_FAILED -1
|
|
|
|
#define FD_NOT_VALID -2
|
|
|
|
#define FDC_ERRMAX 100 /* do not log more */
|
|
|
|
|
|
|
|
#ifdef PC98
|
1999-09-23 14:21:14 +00:00
|
|
|
#define NUMTYPES 12
|
1996-06-14 10:04:54 +00:00
|
|
|
#define NUMDENS NUMTYPES
|
|
|
|
#else
|
2000-01-09 10:01:21 +00:00
|
|
|
#define NUMTYPES 17
|
|
|
|
#define NUMDENS (NUMTYPES - 7)
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* These defines (-1) must match index for fd_types */
|
|
|
|
#define F_TAPE_TYPE 0x020 /* bit for fd_types to indicate tape */
|
|
|
|
#define NO_TYPE 0 /* must match NO_TYPE in ft.c */
|
|
|
|
#define FD_1720 1
|
|
|
|
#define FD_1480 2
|
|
|
|
#define FD_1440 3
|
|
|
|
#define FD_1200 4
|
|
|
|
#define FD_820 5
|
|
|
|
#define FD_800 6
|
|
|
|
#define FD_720 7
|
|
|
|
#define FD_360 8
|
1999-09-23 14:21:14 +00:00
|
|
|
#define FD_640 9
|
|
|
|
#define FD_1232 10
|
2000-01-09 10:01:21 +00:00
|
|
|
|
|
|
|
#ifdef PC98
|
1999-09-23 14:21:14 +00:00
|
|
|
#define FD_1280 11
|
|
|
|
#define FD_1476 12
|
|
|
|
|
|
|
|
#define FDT_NONE 0 /* none present */
|
|
|
|
#define FDT_12M 1 /* 1M/640K FDD */
|
|
|
|
#define FDT_144M 2 /* 1.44M/1M/640K FDD */
|
|
|
|
#else
|
2000-01-09 10:01:21 +00:00
|
|
|
#define FD_1480in5_25 11
|
|
|
|
#define FD_1440in5_25 12
|
|
|
|
#define FD_820in5_25 13
|
|
|
|
#define FD_800in5_25 14
|
|
|
|
#define FD_720in5_25 15
|
|
|
|
#define FD_360in5_25 16
|
|
|
|
#define FD_640in5_25 17
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static struct fd_type fd_types[NUMTYPES] =
|
|
|
|
{
|
|
|
|
#ifdef PC98
|
1999-09-23 14:21:14 +00:00
|
|
|
{ 21,2,0xFF,0x04,82,3444,1,2,2,0x0C,2 }, /* 1.72M in 3mode */
|
|
|
|
{ 18,2,0xFF,0x1B,82,2952,1,2,2,0x54,1 }, /* 1.48M in 3mode */
|
|
|
|
{ 18,2,0xFF,0x1B,80,2880,1,2,2,0x54,1 }, /* 1.44M in 3mode */
|
|
|
|
{ 15,2,0xFF,0x1B,80,2400,1,0,2,0x54,1 }, /* 1.2M */
|
|
|
|
{ 10,2,0xFF,0x10,82,1640,1,1,2,0x30,1 }, /* 820K */
|
|
|
|
{ 10,2,0xFF,0x10,80,1600,1,1,2,0x30,1 }, /* 800K */
|
|
|
|
{ 9,2,0xFF,0x20,80,1440,1,1,2,0x50,1 }, /* 720K */
|
|
|
|
{ 9,2,0xFF,0x20,40, 720,2,1,2,0x50,1 }, /* 360K */
|
|
|
|
{ 8,2,0xFF,0x2A,80,1280,1,1,2,0x50,1 }, /* 640K */
|
|
|
|
{ 8,3,0xFF,0x35,77,1232,1,0,2,0x74,1 }, /* 1.23M 1024/sec */
|
2000-01-09 10:01:21 +00:00
|
|
|
|
1999-09-23 14:21:14 +00:00
|
|
|
{ 8,3,0xFF,0x35,80,1280,1,0,2,0x74,1 }, /* 1.28M 1024/sec */
|
|
|
|
{ 9,3,0xFF,0x35,82,1476,1,0,2,0x47,1 }, /* 1.48M 1024/sec 9sec */
|
|
|
|
#if 0
|
|
|
|
{ 10,3,0xFF,0x1B,82,1640,1,2,2,0x54,1 }, /* 1.64M in 3mode - Reserve */
|
|
|
|
#endif
|
1996-06-14 10:04:54 +00:00
|
|
|
#else
|
|
|
|
{ 21,2,0xFF,0x04,82,3444,1,FDC_500KBPS,2,0x0C,2 }, /* 1.72M in HD 3.5in */
|
|
|
|
{ 18,2,0xFF,0x1B,82,2952,1,FDC_500KBPS,2,0x6C,1 }, /* 1.48M in HD 3.5in */
|
|
|
|
{ 18,2,0xFF,0x1B,80,2880,1,FDC_500KBPS,2,0x6C,1 }, /* 1.44M in HD 3.5in */
|
|
|
|
{ 15,2,0xFF,0x1B,80,2400,1,FDC_500KBPS,2,0x54,1 }, /* 1.2M in HD 5.25/3.5 */
|
|
|
|
{ 10,2,0xFF,0x10,82,1640,1,FDC_250KBPS,2,0x2E,1 }, /* 820K in HD 3.5in */
|
|
|
|
{ 10,2,0xFF,0x10,80,1600,1,FDC_250KBPS,2,0x2E,1 }, /* 800K in HD 3.5in */
|
|
|
|
{ 9,2,0xFF,0x20,80,1440,1,FDC_250KBPS,2,0x50,1 }, /* 720K in HD 3.5in */
|
|
|
|
{ 9,2,0xFF,0x2A,40, 720,1,FDC_250KBPS,2,0x50,1 }, /* 360K in DD 5.25in */
|
2000-01-09 10:01:21 +00:00
|
|
|
{ 8,2,0xFF,0x2A,80,1280,1,FDC_250KBPS,2,0x50,1 }, /* 640K in DD 5.25in */
|
|
|
|
{ 8,3,0xFF,0x35,77,1232,1,FDC_500KBPS,2,0x74,1 }, /* 1.23M in HD 5.25in */
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
{ 18,2,0xFF,0x02,82,2952,1,FDC_500KBPS,2,0x02,2 }, /* 1.48M in HD 5.25in */
|
|
|
|
{ 18,2,0xFF,0x02,80,2880,1,FDC_500KBPS,2,0x02,2 }, /* 1.44M in HD 5.25in */
|
|
|
|
{ 10,2,0xFF,0x10,82,1640,1,FDC_300KBPS,2,0x2E,1 }, /* 820K in HD 5.25in */
|
|
|
|
{ 10,2,0xFF,0x10,80,1600,1,FDC_300KBPS,2,0x2E,1 }, /* 800K in HD 5.25in */
|
|
|
|
{ 9,2,0xFF,0x20,80,1440,1,FDC_300KBPS,2,0x50,1 }, /* 720K in HD 5.25in */
|
|
|
|
{ 9,2,0xFF,0x23,40, 720,2,FDC_300KBPS,2,0x50,1 }, /* 360K in HD 5.25in */
|
2000-01-09 10:01:21 +00:00
|
|
|
{ 8,2,0xFF,0x2A,80,1280,1,FDC_300KBPS,2,0x50,1 }, /* 640K in HD 5.25in */
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef PC98
|
|
|
|
#define DRVS_PER_CTLR 4 /* 4 floppies */
|
|
|
|
#else
|
|
|
|
#define DRVS_PER_CTLR 2 /* 2 floppies */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/***********************************************************************\
|
|
|
|
* Per controller structure. *
|
|
|
|
\***********************************************************************/
|
1999-04-18 14:42:20 +00:00
|
|
|
static devclass_t fdc_devclass;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
/***********************************************************************\
|
|
|
|
* Per drive structure. *
|
|
|
|
* N per controller (DRVS_PER_CTLR) *
|
|
|
|
\***********************************************************************/
|
1999-04-18 14:42:20 +00:00
|
|
|
struct fd_data {
|
1996-06-14 10:04:54 +00:00
|
|
|
struct fdc_data *fdc; /* pointer to controller structure */
|
|
|
|
int fdsu; /* this units number on this controller */
|
|
|
|
int type; /* Drive type (FD_1440...) */
|
|
|
|
struct fd_type *ft; /* pointer to the type descriptor */
|
|
|
|
int flags;
|
|
|
|
#define FD_OPEN 0x01 /* it's open */
|
|
|
|
#define FD_ACTIVE 0x02 /* it's active */
|
|
|
|
#define FD_MOTOR 0x04 /* motor should be on */
|
|
|
|
#define FD_MOTOR_WAIT 0x08 /* motor coming up */
|
|
|
|
int skip;
|
|
|
|
int hddrv;
|
|
|
|
#define FD_NO_TRACK -2
|
|
|
|
int track; /* where we think the head is */
|
|
|
|
int options; /* user configurable options, see ioctl_fd.h */
|
1997-09-22 12:23:49 +00:00
|
|
|
struct callout_handle toffhandle;
|
|
|
|
struct callout_handle tohandle;
|
1998-09-15 14:07:08 +00:00
|
|
|
struct devstat device_stats;
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef PC98
|
|
|
|
int pc98_trans;
|
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
device_t dev;
|
|
|
|
fdu_t fdu;
|
|
|
|
};
|
2000-01-09 10:01:21 +00:00
|
|
|
|
|
|
|
struct fdc_ivars {
|
|
|
|
int fdunit;
|
|
|
|
};
|
1999-04-18 14:42:20 +00:00
|
|
|
static devclass_t fd_devclass;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
typedef unsigned int nrd_t;
|
|
|
|
|
|
|
|
#define P_NRD_ADDRH 0xc24
|
|
|
|
#define P_NRD_ADDRM 0xc22
|
|
|
|
#define P_NRD_ADDRL 0xc20
|
|
|
|
#define P_NRD_CHECK 0xc20
|
|
|
|
#define P_NRD_DATA 0xc26
|
|
|
|
#define P_NRD_LED 0xc36
|
|
|
|
#define B_NRD_CHK 0x80
|
|
|
|
#define B_NRD_LED 0x40
|
|
|
|
#define A_NRD_INFO 0x2
|
|
|
|
#define A_NRD_BASE 0x400
|
|
|
|
#define NRD_STATUS 0x0
|
|
|
|
#define NRD_ST0_HD 0x04
|
|
|
|
|
|
|
|
static fdu_t nrdu=-1;
|
|
|
|
static int nrdsec=0;
|
|
|
|
static nrd_t nrdblkn=0;
|
|
|
|
static nrd_t nrdaddr=0x0;
|
|
|
|
|
|
|
|
#define nrd_check_ready() ({ \
|
|
|
|
(epson_inb(P_NRD_CHECK) & B_NRD_CHK) ? 0 : 1; \
|
|
|
|
})
|
|
|
|
#define nrd_LED_on() epson_outb(P_NRD_LED, B_NRD_LED)
|
|
|
|
#define nrd_LED_off() epson_outb(P_NRD_LED, ~B_NRD_LED)
|
|
|
|
#define nrd_trac() ((int)(nrd_info(nrdaddr) & 0xff))
|
|
|
|
#define nrd_head() ((int)((nrd_info(nrdaddr) >> 8) & 0xff))
|
|
|
|
#define nrd_sec() ((int)(nrd_info(nrdaddr + 2) & 0xff))
|
|
|
|
#define nrd_secsize() ((int)((nrd_info(A_NRD_INFO) >> 8) & 0xff))
|
|
|
|
#define nrd_addrset(p) nrd_addr((nrd_t)((nrd_t)p+A_NRD_BASE))
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
nrd_addr(addr)
|
|
|
|
nrd_t addr;
|
|
|
|
{
|
|
|
|
epson_outb(P_NRD_ADDRH, (u_char)((addr >> 16) & 0x1f));
|
|
|
|
epson_outb(P_NRD_ADDRM, (u_char)((addr >> 8) & 0xff));
|
|
|
|
epson_outb(P_NRD_ADDRL, (u_char)(addr & 0xff));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u_short
|
|
|
|
nrd_info(addr)
|
|
|
|
nrd_t addr;
|
|
|
|
{
|
|
|
|
u_short tmp;
|
|
|
|
|
|
|
|
nrd_addr(addr);
|
|
|
|
outb(0x43f, 0x42);
|
|
|
|
tmp = (short)inw(P_NRD_DATA);
|
|
|
|
outb(0x43f, 0x40);
|
|
|
|
return ((u_short)tmp);
|
|
|
|
}
|
|
|
|
#endif /* EPSON_NRDISK */
|
|
|
|
|
|
|
|
/***********************************************************************\
|
|
|
|
* Throughout this file the following conventions will be used: *
|
|
|
|
* fd is a pointer to the fd_data struct for the drive in question *
|
|
|
|
* fdc is a pointer to the fdc_data struct for the controller *
|
|
|
|
* fdu is the floppy drive unit number *
|
|
|
|
* fdcu is the floppy controller unit number *
|
|
|
|
* fdsu is the floppy drive unit number on that controller. (sub-unit) *
|
|
|
|
\***********************************************************************/
|
|
|
|
|
|
|
|
/* needed for ft driver, thus exported */
|
1999-04-18 14:42:20 +00:00
|
|
|
int in_fdc(struct fdc_data *);
|
|
|
|
int out_fdc(struct fdc_data *, int);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
/* internal functions */
|
1999-04-18 14:42:20 +00:00
|
|
|
static void fdc_intr(void *);
|
|
|
|
static void set_motor(struct fdc_data *, int, int);
|
1996-06-14 10:04:54 +00:00
|
|
|
# define TURNON 1
|
|
|
|
# define TURNOFF 0
|
|
|
|
static timeout_t fd_turnoff;
|
|
|
|
static timeout_t fd_motor_on;
|
1999-04-18 14:42:20 +00:00
|
|
|
static void fd_turnon(struct fd_data *);
|
1996-06-14 10:04:54 +00:00
|
|
|
static void fdc_reset(fdc_p);
|
1999-04-18 14:42:20 +00:00
|
|
|
static int fd_in(struct fdc_data *, int *);
|
|
|
|
static void fdstart(struct fdc_data *);
|
1998-07-30 09:01:12 +00:00
|
|
|
static timeout_t fd_iotimeout;
|
1996-06-14 10:04:54 +00:00
|
|
|
static timeout_t fd_pseudointr;
|
1999-04-18 14:42:20 +00:00
|
|
|
static int fdstate(struct fdc_data *);
|
|
|
|
static int retrier(struct fdc_data *);
|
1996-06-14 10:04:54 +00:00
|
|
|
static int fdformat(dev_t, struct fd_formb *, struct proc *);
|
|
|
|
|
1997-09-18 08:10:45 +00:00
|
|
|
static int enable_fifo(fdc_p fdc);
|
|
|
|
|
|
|
|
static int fifo_threshold = 8; /* XXX: should be accessible via sysctl */
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
#define DEVIDLE 0
|
|
|
|
#define FINDWORK 1
|
|
|
|
#define DOSEEK 2
|
|
|
|
#define SEEKCOMPLETE 3
|
|
|
|
#define IOCOMPLETE 4
|
|
|
|
#define RECALCOMPLETE 5
|
|
|
|
#define STARTRECAL 6
|
|
|
|
#define RESETCTLR 7
|
|
|
|
#define SEEKWAIT 8
|
|
|
|
#define RECALWAIT 9
|
|
|
|
#define MOTORWAIT 10
|
|
|
|
#define IOTIMEDOUT 11
|
1998-07-30 09:01:12 +00:00
|
|
|
#define RESETCOMPLETE 12
|
1998-12-14 09:06:23 +00:00
|
|
|
#define PIOREAD 13
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1997-09-17 08:01:07 +00:00
|
|
|
#ifdef FDC_DEBUG
|
1996-07-23 07:46:59 +00:00
|
|
|
static char const * const fdstates[] =
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
"DEVIDLE",
|
|
|
|
"FINDWORK",
|
|
|
|
"DOSEEK",
|
|
|
|
"SEEKCOMPLETE",
|
|
|
|
"IOCOMPLETE",
|
|
|
|
"RECALCOMPLETE",
|
|
|
|
"STARTRECAL",
|
|
|
|
"RESETCTLR",
|
|
|
|
"SEEKWAIT",
|
|
|
|
"RECALWAIT",
|
|
|
|
"MOTORWAIT",
|
1998-07-30 09:01:12 +00:00
|
|
|
"IOTIMEDOUT",
|
|
|
|
"RESETCOMPLETE",
|
1998-12-17 08:40:36 +00:00
|
|
|
"PIOREAD",
|
1996-06-14 10:04:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* CAUTION: fd_debug causes huge amounts of logging output */
|
1996-07-23 07:46:59 +00:00
|
|
|
static int volatile fd_debug = 0;
|
1996-06-14 10:04:54 +00:00
|
|
|
#define TRACE0(arg) if(fd_debug) printf(arg)
|
|
|
|
#define TRACE1(arg1, arg2) if(fd_debug) printf(arg1, arg2)
|
1997-09-17 08:01:07 +00:00
|
|
|
#else /* FDC_DEBUG */
|
1996-06-14 10:04:54 +00:00
|
|
|
#define TRACE0(arg)
|
|
|
|
#define TRACE1(arg1, arg2)
|
1997-09-17 08:01:07 +00:00
|
|
|
#endif /* FDC_DEBUG */
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-11-11 12:15:15 +00:00
|
|
|
static void
|
|
|
|
fdout_wr(fdc_p fdc, u_int8_t v)
|
|
|
|
{
|
|
|
|
bus_space_write_1(fdc->portt, fdc->porth, FDOUT+fdc->port_off, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u_int8_t
|
|
|
|
fdsts_rd(fdc_p fdc)
|
|
|
|
{
|
|
|
|
return bus_space_read_1(fdc->portt, fdc->porth, FDSTS+fdc->port_off);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fddata_wr(fdc_p fdc, u_int8_t v)
|
|
|
|
{
|
|
|
|
bus_space_write_1(fdc->portt, fdc->porth, FDDATA+fdc->port_off, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u_int8_t
|
|
|
|
fddata_rd(fdc_p fdc)
|
|
|
|
{
|
|
|
|
return bus_space_read_1(fdc->portt, fdc->porth, FDDATA+fdc->port_off);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef PC98
|
|
|
|
static void
|
2000-03-19 15:18:22 +00:00
|
|
|
fdctl_wr_isa(fdc_p fdc, u_int8_t v)
|
1999-11-11 12:15:15 +00:00
|
|
|
{
|
2000-01-09 10:01:21 +00:00
|
|
|
bus_space_write_1(fdc->ctlt, fdc->ctlh, 0, v);
|
1999-11-11 12:15:15 +00:00
|
|
|
}
|
2000-03-19 15:18:22 +00:00
|
|
|
|
2000-11-05 14:31:19 +00:00
|
|
|
#if NCARD > 0
|
2000-03-19 15:18:22 +00:00
|
|
|
static void
|
|
|
|
fdctl_wr_pcmcia(fdc_p fdc, u_int8_t v)
|
|
|
|
{
|
|
|
|
bus_space_write_1(fdc->portt, fdc->porth, FDCTL+fdc->port_off, v);
|
|
|
|
}
|
1999-11-11 12:15:15 +00:00
|
|
|
#endif
|
2000-11-05 14:31:19 +00:00
|
|
|
#endif /* PC98 */
|
1999-11-11 12:15:15 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
static u_int8_t
|
|
|
|
fdin_rd(fdc_p fdc)
|
|
|
|
{
|
|
|
|
return bus_space_read_1(fdc->portt, fdc->porth, FDIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
static d_open_t Fdopen; /* NOTE, not fdopen */
|
|
|
|
static d_close_t fdclose;
|
|
|
|
static d_ioctl_t fdioctl;
|
|
|
|
static d_strategy_t fdstrategy;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 9
|
1998-07-06 10:09:42 +00:00
|
|
|
|
1999-05-30 16:53:49 +00:00
|
|
|
static struct cdevsw fd_cdevsw = {
|
|
|
|
/* open */ Fdopen,
|
|
|
|
/* close */ fdclose,
|
|
|
|
/* read */ physread,
|
|
|
|
/* write */ physwrite,
|
|
|
|
/* ioctl */ fdioctl,
|
|
|
|
/* poll */ nopoll,
|
|
|
|
/* mmap */ nommap,
|
|
|
|
/* strategy */ fdstrategy,
|
|
|
|
/* name */ "fd",
|
|
|
|
/* maj */ CDEV_MAJOR,
|
|
|
|
/* dump */ nodump,
|
|
|
|
/* psize */ nopsize,
|
|
|
|
/* flags */ D_DISK,
|
|
|
|
};
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
static int
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_err(struct fdc_data *fdc, const char *s)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc->fdc_errs++;
|
|
|
|
if (s) {
|
2000-01-09 10:01:21 +00:00
|
|
|
if (fdc->fdc_errs < FDC_ERRMAX)
|
|
|
|
device_printf(fdc->fdc_dev, "%s", s);
|
|
|
|
else if (fdc->fdc_errs == FDC_ERRMAX)
|
|
|
|
device_printf(fdc->fdc_dev, "too many errors, not "
|
|
|
|
"logging any more\n");
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FD_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fd_cmd: Send a command to the chip. Takes a varargs with this structure:
|
|
|
|
* Unit number,
|
|
|
|
* # of output bytes, output bytes as ints ...,
|
|
|
|
* # of input bytes, input bytes as ints ...
|
|
|
|
*/
|
|
|
|
static int
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_cmd(struct fdc_data *fdc, int n_out, ...)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
u_char cmd;
|
|
|
|
int n_in;
|
|
|
|
int n;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, n_out);
|
|
|
|
cmd = (u_char)(va_arg(ap, int));
|
|
|
|
va_end(ap);
|
|
|
|
va_start(ap, n_out);
|
|
|
|
for (n = 0; n < n_out; n++)
|
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
if (out_fdc(fdc, va_arg(ap, int)) < 0)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
char msg[50];
|
1998-12-05 09:24:20 +00:00
|
|
|
snprintf(msg, sizeof(msg),
|
1996-06-14 10:04:54 +00:00
|
|
|
"cmd %x failed at out byte %d of %d\n",
|
|
|
|
cmd, n + 1, n_out);
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, msg);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
n_in = va_arg(ap, int);
|
|
|
|
for (n = 0; n < n_in; n++)
|
|
|
|
{
|
|
|
|
int *ptr = va_arg(ap, int *);
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_in(fdc, ptr) < 0)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
char msg[50];
|
1998-12-05 09:24:20 +00:00
|
|
|
snprintf(msg, sizeof(msg),
|
1996-06-14 10:04:54 +00:00
|
|
|
"cmd %02x failed at in byte %d of %d\n",
|
|
|
|
cmd, n + 1, n_in);
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, msg);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-09-18 08:10:45 +00:00
|
|
|
static int
|
|
|
|
enable_fifo(fdc_p fdc)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if ((fdc->flags & FDC_HAS_FIFO) == 0) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX:
|
|
|
|
* Cannot use fd_cmd the normal way here, since
|
|
|
|
* this might be an invalid command. Thus we send the
|
|
|
|
* first byte, and check for an early turn of data directon.
|
|
|
|
*/
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (out_fdc(fdc, I8207X_CONFIGURE) < 0)
|
|
|
|
return fdc_err(fdc, "Enable FIFO failed\n");
|
1997-09-18 08:10:45 +00:00
|
|
|
|
|
|
|
/* If command is invalid, return */
|
|
|
|
j = 100000;
|
1999-11-11 12:15:15 +00:00
|
|
|
while ((i = fdsts_rd(fdc) & (NE7_DIO | NE7_RQM))
|
1997-09-18 08:10:45 +00:00
|
|
|
!= NE7_RQM && j-- > 0)
|
|
|
|
if (i == (NE7_DIO | NE7_RQM)) {
|
|
|
|
fdc_reset(fdc);
|
|
|
|
return FD_FAILED;
|
|
|
|
}
|
|
|
|
if (j<0 ||
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_cmd(fdc, 3,
|
1997-09-18 08:10:45 +00:00
|
|
|
0, (fifo_threshold - 1) & 0xf, 0, 0) < 0) {
|
|
|
|
fdc_reset(fdc);
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, "Enable FIFO failed\n");
|
1997-09-18 08:10:45 +00:00
|
|
|
}
|
|
|
|
fdc->flags |= FDC_HAS_FIFO;
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_cmd(fdc, 4,
|
1997-09-18 08:10:45 +00:00
|
|
|
I8207X_CONFIGURE, 0, (fifo_threshold - 1) & 0xf, 0, 0) < 0)
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, "Re-enable FIFO failed\n");
|
1997-09-18 08:10:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
static int
|
|
|
|
fd_sense_drive_status(fdc_p fdc, int *st3p)
|
|
|
|
{
|
|
|
|
int st3;
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_cmd(fdc, 2, NE7CMD_SENSED, fdc->fdu, 1, &st3))
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, "Sense Drive Status failed\n");
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
if (st3p)
|
|
|
|
*st3p = st3;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fd_sense_int(fdc_p fdc, int *st0p, int *cylp)
|
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
int cyl, st0, ret;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdc->fdu == nrdu) {
|
|
|
|
if (fdc->fd->track >= 0) nrdaddr = (fdc->fd->track + 1) * 8;
|
|
|
|
else nrdaddr = 0x0;
|
|
|
|
*st0p = nrd_head() ? NRD_ST0_HD : NRD_STATUS;
|
|
|
|
*cylp = nrd_trac();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif /* EPSON_NRDISK */
|
1999-04-18 14:42:20 +00:00
|
|
|
ret = fd_cmd(fdc, 1, NE7CMD_SENSEI, 1, &st0);
|
|
|
|
if (ret) {
|
|
|
|
(void)fdc_err(fdc,
|
1996-06-14 10:04:54 +00:00
|
|
|
"sense intr err reading stat reg 0\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (st0p)
|
|
|
|
*st0p = st0;
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if ((st0 & NE7_ST0_IC) == NE7_ST0_IC_IV) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/*
|
|
|
|
* There doesn't seem to have been an interrupt.
|
|
|
|
*/
|
|
|
|
return FD_NOT_VALID;
|
|
|
|
}
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_in(fdc, &cyl) < 0) {
|
|
|
|
return fdc_err(fdc, "can't get cyl num\n");
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cylp)
|
|
|
|
*cylp = cyl;
|
|
|
|
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
}
|
|
|
|
#endif /* EPSON_NRDISK */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
fd_read_status(fdc_p fdc, int fdsu)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
for (i = 0; i < 7; i++) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/*
|
|
|
|
* XXX types are poorly chosen. Only bytes can by read
|
1998-07-11 17:02:07 +00:00
|
|
|
* from the hardware, but fdc->status[] wants u_ints and
|
1996-06-14 10:04:54 +00:00
|
|
|
* fd_in() gives ints.
|
|
|
|
*/
|
|
|
|
int status;
|
|
|
|
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdc->fdu == nrdu) {
|
|
|
|
switch (i) {
|
|
|
|
case 0: fdc->status[i] = nrd_head()
|
|
|
|
? NRD_ST0_HD : NRD_STATUS; break;
|
|
|
|
case 1: fdc->status[i] = NRD_STATUS; break;
|
|
|
|
case 2: fdc->status[i] = NRD_STATUS; break;
|
|
|
|
case 3: fdc->status[i] = nrd_trac(); break;
|
|
|
|
case 4: fdc->status[i] = nrd_head(); break;
|
|
|
|
case 5: fdc->status[i] = nrdsec; break;
|
|
|
|
case 6: fdc->status[i] = nrd_secsize(); break;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif /* EPSON_NRDISK */
|
1999-04-18 14:42:20 +00:00
|
|
|
ret = fd_in(fdc, &status);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->status[i] = status;
|
|
|
|
if (ret != 0)
|
|
|
|
break;
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
}
|
|
|
|
#endif /* EPSON_NRDISK */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
fdc->flags |= FDC_STAT_VALID;
|
|
|
|
else
|
|
|
|
fdc->flags &= ~FDC_STAT_VALID;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* autoconfiguration stuff */
|
|
|
|
/****************************************************************************/
|
|
|
|
#ifdef PC98
|
|
|
|
static int pc98_trans = 0; /* 0 : HD , 1 : DD , 2 : 1.44 */
|
|
|
|
static int pc98_trans_prev = 0;
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
static void set_density(fdc_p fdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
/* always motor on */
|
1999-04-18 14:42:20 +00:00
|
|
|
outb(IO_FDPORT, (pc98_trans != 1 ? FDP_FDDEXC : 0) | FDP_PORTEXC);
|
1996-06-14 10:04:54 +00:00
|
|
|
DELAY(100);
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, FDO_RST | FDO_DMAE);
|
1996-06-14 10:04:54 +00:00
|
|
|
/* in the case of note W, always inhibit 100ms timer */
|
|
|
|
}
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
static int pc98_fd_check_ready(fdu_t fdu)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_p fd = devclass_get_softc(fd_devclass, fdu);
|
|
|
|
struct fdc_data *fdc = fd->fdc;
|
1996-06-14 10:04:54 +00:00
|
|
|
int retry = 0;
|
|
|
|
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdu == nrdu) {
|
|
|
|
if (nrd_check_ready()) return 0;
|
|
|
|
else return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
while (retry++ < 30000) {
|
1999-04-18 14:42:20 +00:00
|
|
|
set_motor(fdc, fd->fdsu, TURNON);
|
|
|
|
out_fdc(fdc, NE7CMD_SENSED); /* Sense Drive Status */
|
1996-06-14 10:04:54 +00:00
|
|
|
DELAY(100);
|
1999-04-18 14:42:20 +00:00
|
|
|
out_fdc(fdc, fdu); /* Drive number */
|
1996-06-14 10:04:54 +00:00
|
|
|
DELAY(100);
|
1999-04-18 14:42:20 +00:00
|
|
|
if ((in_fdc(fdc) & NE7_ST3_RD)){
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, FDO_DMAE | FDO_MTON);
|
1996-06-14 10:04:54 +00:00
|
|
|
DELAY(10);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2000-01-09 10:01:21 +00:00
|
|
|
fdc_alloc_resources(struct fdc_data *fdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
2000-01-09 10:01:21 +00:00
|
|
|
device_t dev;
|
2000-03-19 15:18:22 +00:00
|
|
|
int ispnp, ispcmcia;
|
1999-09-27 03:32:31 +00:00
|
|
|
|
2000-01-09 10:01:21 +00:00
|
|
|
dev = fdc->fdc_dev;
|
2000-03-19 15:18:22 +00:00
|
|
|
ispnp = (fdc->flags & FDC_ISPNP) != 0;
|
|
|
|
ispcmcia = (fdc->flags & FDC_ISPCMCIA) != 0;
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc->rid_ioport = fdc->rid_irq = fdc->rid_drq = 0;
|
|
|
|
fdc->res_ioport = fdc->res_irq = fdc->res_drq = 0;
|
|
|
|
|
2000-01-09 10:01:21 +00:00
|
|
|
#ifdef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
|
|
|
|
&fdc->rid_ioport, 0ul, ~0ul,
|
1999-11-11 12:15:15 +00:00
|
|
|
ispnp ? 1 : IO_FDCSIZE,
|
|
|
|
RF_ACTIVE);
|
2000-01-09 10:01:21 +00:00
|
|
|
#else
|
|
|
|
/*
|
2000-03-19 15:18:22 +00:00
|
|
|
* On standard ISA, we don't just use an 8 port range
|
|
|
|
* (e.g. 0x3f0-0x3f7) since that covers an IDE control
|
|
|
|
* register at 0x3f6.
|
|
|
|
*
|
2000-01-09 10:01:21 +00:00
|
|
|
* Isn't PC hardware wonderful.
|
2000-03-19 15:18:22 +00:00
|
|
|
*
|
|
|
|
* The Y-E Data PCMCIA FDC doesn't have this problem, it
|
|
|
|
* uses the register with offset 6 for pseudo-DMA, and the
|
|
|
|
* one with offset 7 as control register.
|
2000-01-09 10:01:21 +00:00
|
|
|
*/
|
|
|
|
fdc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
|
|
|
|
&fdc->rid_ioport, 0ul, ~0ul,
|
2000-03-19 15:18:22 +00:00
|
|
|
ispcmcia ? 8 : (ispnp ? 1 : 6),
|
|
|
|
RF_ACTIVE);
|
2000-01-09 10:01:21 +00:00
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fdc->res_ioport == 0) {
|
1999-11-11 12:15:15 +00:00
|
|
|
device_printf(dev, "cannot reserve I/O port range\n");
|
2000-01-09 10:01:21 +00:00
|
|
|
return ENXIO;
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1999-11-11 12:15:15 +00:00
|
|
|
fdc->portt = rman_get_bustag(fdc->res_ioport);
|
|
|
|
fdc->porth = rman_get_bushandle(fdc->res_ioport);
|
|
|
|
|
|
|
|
#ifndef PC98
|
2000-03-19 15:18:22 +00:00
|
|
|
if (!ispcmcia) {
|
|
|
|
/*
|
|
|
|
* Some BIOSen report the device at 0x3f2-0x3f5,0x3f7
|
|
|
|
* and some at 0x3f0-0x3f5,0x3f7. We detect the former
|
|
|
|
* by checking the size and adjust the port address
|
|
|
|
* accordingly.
|
|
|
|
*/
|
|
|
|
if (bus_get_resource_count(dev, SYS_RES_IOPORT, 0) == 4)
|
|
|
|
fdc->port_off = -2;
|
2000-01-09 10:01:21 +00:00
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
/*
|
|
|
|
* Register the control port range as rid 1 if it
|
|
|
|
* isn't there already. Most PnP BIOSen will have
|
|
|
|
* already done this but non-PnP configurations don't.
|
|
|
|
*
|
|
|
|
* And some (!!) report 0x3f2-0x3f5 and completely
|
|
|
|
* leave out the control register! It seems that some
|
|
|
|
* non-antique controller chips have a different
|
|
|
|
* method of programming the transfer speed which
|
|
|
|
* doesn't require the control register, but it's
|
|
|
|
* mighty bogus as the chip still responds to the
|
|
|
|
* address for the control register.
|
|
|
|
*/
|
|
|
|
if (bus_get_resource_count(dev, SYS_RES_IOPORT, 1) == 0) {
|
|
|
|
u_long ctlstart;
|
2000-01-09 10:01:21 +00:00
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
/* Find the control port, usually 0x3f7 */
|
|
|
|
ctlstart = rman_get_start(fdc->res_ioport) +
|
|
|
|
fdc->port_off + 7;
|
2000-01-09 10:01:21 +00:00
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
bus_set_resource(dev, SYS_RES_IOPORT, 1, ctlstart, 1);
|
|
|
|
}
|
2000-01-09 10:01:21 +00:00
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
/*
|
|
|
|
* Now (finally!) allocate the control port.
|
|
|
|
*/
|
|
|
|
fdc->rid_ctl = 1;
|
|
|
|
fdc->res_ctl = bus_alloc_resource(dev, SYS_RES_IOPORT,
|
|
|
|
&fdc->rid_ctl,
|
|
|
|
0ul, ~0ul, 1, RF_ACTIVE);
|
|
|
|
if (fdc->res_ctl == 0) {
|
|
|
|
device_printf(dev,
|
|
|
|
"cannot reserve control I/O port range\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
fdc->ctlt = rman_get_bustag(fdc->res_ctl);
|
|
|
|
fdc->ctlh = rman_get_bushandle(fdc->res_ctl);
|
1999-11-11 12:15:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
|
|
|
|
fdc->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ,
|
|
|
|
&fdc->rid_irq, 0ul, ~0ul, 1,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if (fdc->res_irq == 0) {
|
1999-11-11 12:15:15 +00:00
|
|
|
device_printf(dev, "cannot reserve interrupt line\n");
|
2000-01-09 10:01:21 +00:00
|
|
|
return ENXIO;
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
2000-03-19 15:18:22 +00:00
|
|
|
|
|
|
|
if ((fdc->flags & FDC_NODMA) == 0) {
|
|
|
|
fdc->res_drq = bus_alloc_resource(dev, SYS_RES_DRQ,
|
|
|
|
&fdc->rid_drq, 0ul, ~0ul, 1,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if (fdc->res_drq == 0) {
|
|
|
|
device_printf(dev, "cannot reserve DMA request line\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
fdc->dmachan = fdc->res_drq->r_start;
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
2000-01-09 10:01:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fdc_release_resources(struct fdc_data *fdc)
|
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
|
|
|
|
dev = fdc->fdc_dev;
|
|
|
|
if (fdc->res_irq != 0) {
|
|
|
|
bus_deactivate_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
|
|
|
|
fdc->res_irq);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
|
|
|
|
fdc->res_irq);
|
|
|
|
}
|
|
|
|
#ifndef PC98
|
|
|
|
if (fdc->res_ctl != 0) {
|
|
|
|
bus_deactivate_resource(dev, SYS_RES_IOPORT, fdc->rid_ctl,
|
|
|
|
fdc->res_ctl);
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ctl,
|
|
|
|
fdc->res_ctl);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (fdc->res_ioport != 0) {
|
|
|
|
bus_deactivate_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
|
|
|
|
fdc->res_ioport);
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
|
|
|
|
fdc->res_ioport);
|
|
|
|
}
|
|
|
|
if (fdc->res_drq != 0) {
|
|
|
|
bus_deactivate_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
|
|
|
|
fdc->res_drq);
|
|
|
|
bus_release_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
|
|
|
|
fdc->res_drq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* autoconfiguration stuff */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
static struct isa_pnp_id fdc_ids[] = {
|
|
|
|
{0x0007d041, "PC standard floppy disk controller"}, /* PNP0700 */
|
|
|
|
{0x0107d041, "Standard floppy controller supporting MS Device Bay Spec"}, /* PNP0701 */
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2000-07-11 12:50:34 +00:00
|
|
|
fdc_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
|
2000-01-09 10:01:21 +00:00
|
|
|
{
|
|
|
|
struct fdc_ivars *ivars = device_get_ivars(child);
|
|
|
|
|
|
|
|
switch (which) {
|
|
|
|
case FDC_IVAR_FDUNIT:
|
|
|
|
*result = ivars->fdunit;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fdc controller section.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fdc_probe(device_t dev)
|
|
|
|
{
|
2000-10-15 04:54:17 +00:00
|
|
|
#ifdef PC98
|
|
|
|
int error;
|
|
|
|
#else
|
2000-01-09 10:01:21 +00:00
|
|
|
int error, ic_type;
|
2000-10-15 04:54:17 +00:00
|
|
|
#endif
|
2000-01-09 10:01:21 +00:00
|
|
|
struct fdc_data *fdc;
|
|
|
|
|
|
|
|
fdc = device_get_softc(dev);
|
|
|
|
bzero(fdc, sizeof *fdc);
|
|
|
|
fdc->fdc_dev = dev;
|
2000-03-19 15:18:22 +00:00
|
|
|
#ifndef PC98
|
|
|
|
fdc->fdctl_wr = fdctl_wr_isa;
|
|
|
|
#endif
|
2000-01-09 10:01:21 +00:00
|
|
|
|
|
|
|
/* Check pnp ids */
|
|
|
|
error = ISA_PNP_PROBE(device_get_parent(dev), dev, fdc_ids);
|
|
|
|
if (error == ENXIO)
|
|
|
|
return ENXIO;
|
2000-03-19 15:18:22 +00:00
|
|
|
if (error == 0)
|
|
|
|
fdc->flags |= FDC_ISPNP;
|
2000-01-09 10:01:21 +00:00
|
|
|
|
|
|
|
/* Attempt to allocate our resources for the duration of the probe */
|
|
|
|
error = fdc_alloc_resources(fdc);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
#ifndef PC98
|
|
|
|
/* First - lets reset the floppy controller */
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, 0);
|
1996-06-14 10:04:54 +00:00
|
|
|
DELAY(100);
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, FDO_FRST);
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* see if it can handle a command */
|
|
|
|
#ifdef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(4, 240),
|
|
|
|
NE7_SPEC_2(2, 0), 0)) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
#else
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
|
|
|
|
NE7_SPEC_2(2, 0), 0)) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
|
|
|
|
#ifndef PC98
|
|
|
|
if (fd_cmd(fdc, 1, NE7CMD_VERSION, 1, &ic_type) == 0) {
|
|
|
|
ic_type = (u_char)ic_type;
|
|
|
|
switch (ic_type) {
|
|
|
|
case 0x80:
|
|
|
|
device_set_desc(dev, "NEC 765 or clone");
|
|
|
|
fdc->fdct = FDC_NE765;
|
|
|
|
break;
|
|
|
|
case 0x81:
|
|
|
|
device_set_desc(dev, "Intel 82077 or clone");
|
|
|
|
fdc->fdct = FDC_I82077;
|
|
|
|
break;
|
|
|
|
case 0x90:
|
|
|
|
device_set_desc(dev, "NEC 72065B or clone");
|
|
|
|
fdc->fdct = FDC_NE72065;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device_set_desc(dev, "generic floppy controller");
|
|
|
|
fdc->fdct = FDC_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
out:
|
2000-01-09 10:01:21 +00:00
|
|
|
fdc_release_resources(fdc);
|
1999-04-18 14:42:20 +00:00
|
|
|
return (error);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
#if NCARD > 0
|
|
|
|
|
|
|
|
static int
|
|
|
|
fdc_pccard_probe(device_t dev)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct fdc_data *fdc;
|
|
|
|
|
|
|
|
fdc = device_get_softc(dev);
|
|
|
|
bzero(fdc, sizeof *fdc);
|
|
|
|
fdc->fdc_dev = dev;
|
2000-03-23 08:50:56 +00:00
|
|
|
#ifndef PC98
|
2000-03-19 15:18:22 +00:00
|
|
|
fdc->fdctl_wr = fdctl_wr_pcmcia;
|
2000-03-23 08:50:56 +00:00
|
|
|
#endif
|
2000-11-05 14:31:19 +00:00
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
fdc->flags |= FDC_ISPCMCIA | FDC_NODMA;
|
|
|
|
|
|
|
|
/* Attempt to allocate our resources for the duration of the probe */
|
|
|
|
error = fdc_alloc_resources(fdc);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
2000-03-23 08:50:56 +00:00
|
|
|
#ifndef PC98
|
2000-03-19 15:18:22 +00:00
|
|
|
/* First - lets reset the floppy controller */
|
|
|
|
fdout_wr(fdc, 0);
|
|
|
|
DELAY(100);
|
|
|
|
fdout_wr(fdc, FDO_FRST);
|
2000-03-23 08:50:56 +00:00
|
|
|
#endif
|
2000-03-19 15:18:22 +00:00
|
|
|
|
|
|
|
/* see if it can handle a command */
|
|
|
|
if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
|
|
|
|
NE7_SPEC_2(2, 0), 0)) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_set_desc(dev, "Y-E Data PCMCIA floppy");
|
|
|
|
fdc->fdct = FDC_NE765;
|
|
|
|
|
|
|
|
out:
|
|
|
|
fdc_release_resources(fdc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fdc_pccard_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct fdc_data *fdc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
fdc = device_get_softc(dev);
|
|
|
|
|
|
|
|
/* have our children detached first */
|
|
|
|
if ((error = bus_generic_detach(dev)))
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if ((fdc->flags & FDC_ATTACHED) == 0) {
|
|
|
|
device_printf(dev, "already unloaded\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
fdc->flags &= ~FDC_ATTACHED;
|
|
|
|
|
|
|
|
BUS_TEARDOWN_INTR(device_get_parent(dev), dev, fdc->res_irq,
|
|
|
|
fdc->fdc_intr);
|
|
|
|
fdc_release_resources(fdc);
|
|
|
|
device_printf(dev, "unload\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NCARD > 0 */
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
/*
|
2000-01-09 10:01:21 +00:00
|
|
|
* Add a child device to the fdc controller. It will then be probed etc.
|
1996-06-14 10:04:54 +00:00
|
|
|
*/
|
1999-04-18 14:42:20 +00:00
|
|
|
static void
|
2000-01-09 10:01:21 +00:00
|
|
|
fdc_add_child(device_t dev, const char *name, int unit)
|
1999-04-18 14:42:20 +00:00
|
|
|
{
|
2000-01-09 10:01:21 +00:00
|
|
|
int disabled;
|
|
|
|
struct fdc_ivars *ivar;
|
1999-04-18 14:42:20 +00:00
|
|
|
device_t child;
|
|
|
|
|
2000-12-08 21:51:06 +00:00
|
|
|
ivar = malloc(sizeof *ivar, M_DEVBUF /* XXX */, M_NOWAIT | M_ZERO);
|
2000-01-09 10:01:21 +00:00
|
|
|
if (ivar == NULL)
|
1999-04-18 14:42:20 +00:00
|
|
|
return;
|
2000-01-09 10:01:21 +00:00
|
|
|
if (resource_int_value(name, unit, "drive", &ivar->fdunit) != 0)
|
|
|
|
ivar->fdunit = 0;
|
1999-12-03 08:41:24 +00:00
|
|
|
child = device_add_child(dev, name, unit);
|
2000-01-09 10:01:21 +00:00
|
|
|
if (child == NULL)
|
1999-04-18 14:42:20 +00:00
|
|
|
return;
|
2000-01-09 10:01:21 +00:00
|
|
|
device_set_ivars(child, ivar);
|
1999-09-27 03:32:31 +00:00
|
|
|
if (resource_int_value(name, unit, "disabled", &disabled) == 0
|
|
|
|
&& disabled != 0)
|
1999-04-18 14:42:20 +00:00
|
|
|
device_disable(child);
|
|
|
|
}
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
static int
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_attach(device_t dev)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
2000-01-09 10:01:21 +00:00
|
|
|
struct fdc_data *fdc;
|
|
|
|
int i, error;
|
2000-10-15 09:32:58 +00:00
|
|
|
const char *name;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
2000-01-09 10:01:21 +00:00
|
|
|
fdc = device_get_softc(dev);
|
|
|
|
error = fdc_alloc_resources(fdc);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "cannot re-aquire resources\n");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
error = BUS_SETUP_INTR(device_get_parent(dev), dev, fdc->res_irq,
|
2001-05-06 05:49:11 +00:00
|
|
|
INTR_TYPE_BIO | INTR_ENTROPY, fdc_intr, fdc,
|
|
|
|
&fdc->fdc_intr);
|
2000-01-09 10:01:21 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "cannot setup interrupt\n");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
fdc->fdcu = device_get_unit(dev);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->flags |= FDC_ATTACHED;
|
1999-04-18 14:42:20 +00:00
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
if ((fdc->flags & FDC_NODMA) == 0) {
|
|
|
|
/* Acquire the DMA channel forever, The driver will do the rest */
|
1999-04-18 14:42:20 +00:00
|
|
|
/* XXX should integrate with rman */
|
2000-03-19 15:18:22 +00:00
|
|
|
isa_dma_acquire(fdc->dmachan);
|
|
|
|
isa_dmainit(fdc->dmachan, 128 << 3 /* XXX max secsize */);
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->state = DEVIDLE;
|
1999-04-18 14:42:20 +00:00
|
|
|
|
|
|
|
#ifdef PC98
|
|
|
|
/* reset controller, turn motor off, clear fdout mirror reg */
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc_reset(fdc);
|
|
|
|
#else
|
|
|
|
/* reset controller, turn motor off, clear fdout mirror reg */
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, ((fdc->fdout = 0)));
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq_init(&fdc->head);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
/*
|
2000-01-09 10:01:21 +00:00
|
|
|
* Probe and attach any children. We should probably detect
|
|
|
|
* devices from the BIOS unless overridden.
|
1999-04-18 14:42:20 +00:00
|
|
|
*/
|
2000-10-15 09:32:58 +00:00
|
|
|
name = device_get_nameunit(dev);
|
|
|
|
i = -1;
|
|
|
|
while ((i = resource_query_string(i, "at", name)) != -1)
|
2000-01-09 10:01:21 +00:00
|
|
|
fdc_add_child(dev, resource_query_name(i),
|
|
|
|
resource_query_unit(i));
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
return (bus_generic_attach(dev));
|
|
|
|
}
|
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
static int
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_print_child(device_t me, device_t child)
|
|
|
|
{
|
1999-07-29 01:03:04 +00:00
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
retval += bus_print_child_header(me, child);
|
|
|
|
retval += printf(" on %s drive %d\n", device_get_nameunit(me),
|
2000-01-09 10:01:21 +00:00
|
|
|
fdc_get_fdunit(child));
|
1999-09-23 14:21:14 +00:00
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
return (retval);
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 03:32:31 +00:00
|
|
|
static device_method_t fdc_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, fdc_probe),
|
|
|
|
DEVMETHOD(device_attach, fdc_attach),
|
|
|
|
DEVMETHOD(device_detach, bus_generic_detach),
|
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, fdc_print_child),
|
2000-01-09 10:01:21 +00:00
|
|
|
DEVMETHOD(bus_read_ivar, fdc_read_ivar),
|
1999-09-27 03:32:31 +00:00
|
|
|
/* Our children never use any other bus interface methods. */
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t fdc_driver = {
|
|
|
|
"fdc",
|
|
|
|
fdc_methods,
|
|
|
|
sizeof(struct fdc_data)
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(fdc, isa, fdc_driver, fdc_devclass, 0, 0);
|
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
#if NCARD > 0
|
|
|
|
|
|
|
|
static device_method_t fdc_pccard_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, fdc_pccard_probe),
|
|
|
|
DEVMETHOD(device_attach, fdc_attach),
|
|
|
|
DEVMETHOD(device_detach, fdc_pccard_detach),
|
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, fdc_print_child),
|
|
|
|
DEVMETHOD(bus_read_ivar, fdc_read_ivar),
|
|
|
|
/* Our children never use any other bus interface methods. */
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t fdc_pccard_driver = {
|
|
|
|
"fdc",
|
|
|
|
fdc_pccard_methods,
|
|
|
|
sizeof(struct fdc_data)
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(fdc, pccard, fdc_pccard_driver, fdc_devclass, 0, 0);
|
|
|
|
|
|
|
|
#endif /* NCARD > 0 */
|
|
|
|
|
2000-11-05 14:31:19 +00:00
|
|
|
static void fd_clone __P((void *arg, char *name, int namelen, dev_t *dev));
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
char *match;
|
|
|
|
int minor;
|
|
|
|
int link;
|
|
|
|
} fd_suffix[] = {
|
|
|
|
{ "a", 0, 1 },
|
|
|
|
{ "b", 0, 1 },
|
|
|
|
{ "c", 0, 1 },
|
|
|
|
{ "d", 0, 1 },
|
|
|
|
{ "e", 0, 1 },
|
|
|
|
{ "f", 0, 1 },
|
|
|
|
{ "g", 0, 1 },
|
|
|
|
{ "h", 0, 1 },
|
|
|
|
{ ".1720", 1, 0 },
|
|
|
|
{ ".1480", 2, 0 },
|
|
|
|
{ ".1440", 3, 0 },
|
|
|
|
{ ".1200", 4, 0 },
|
|
|
|
{ ".820", 5, 0 },
|
|
|
|
{ ".800", 6, 0 },
|
|
|
|
{ ".720", 7, 0 },
|
|
|
|
{ ".360", 8, 0 },
|
|
|
|
{ ".640", 9, 0 },
|
|
|
|
{ ".1232", 10, 0 },
|
|
|
|
#ifdef PC98
|
|
|
|
{ ".1280", 11, 0 },
|
|
|
|
{ ".1476", 12, 0 },
|
|
|
|
#endif
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
static void
|
|
|
|
fd_clone(arg, name, namelen, dev)
|
|
|
|
void *arg;
|
|
|
|
char *name;
|
|
|
|
int namelen;
|
|
|
|
dev_t *dev;
|
|
|
|
{
|
|
|
|
int u, d, i;
|
|
|
|
char *n;
|
|
|
|
dev_t pdev;
|
|
|
|
|
|
|
|
if (*dev != NODEV)
|
|
|
|
return;
|
|
|
|
if (dev_stdclone(name, &n, "fd", &u) != 2)
|
|
|
|
return;
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
if (fd_suffix[i].match == NULL)
|
|
|
|
return;
|
|
|
|
if (strcmp(n, fd_suffix[i].match))
|
|
|
|
continue;
|
|
|
|
d = fd_suffix[i].minor;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fd_suffix[i].link == 0) {
|
|
|
|
*dev = make_dev(&fd_cdevsw, (u << 6) + d,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0640, name);
|
|
|
|
} else {
|
|
|
|
pdev = makedev(fd_cdevsw.d_maj, (u << 6) + d);
|
|
|
|
*dev = make_dev_alias(pdev, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-27 03:32:31 +00:00
|
|
|
/******************************************************************/
|
|
|
|
/*
|
|
|
|
* devices attached to the controller section.
|
|
|
|
*/
|
1999-04-18 14:42:20 +00:00
|
|
|
static int
|
|
|
|
fd_probe(device_t dev)
|
|
|
|
{
|
2000-10-15 04:54:17 +00:00
|
|
|
#ifdef PC98
|
|
|
|
u_int fdt;
|
|
|
|
#else
|
1999-04-18 14:42:20 +00:00
|
|
|
int i;
|
|
|
|
u_int fdt, st0, st3;
|
2000-10-15 04:54:17 +00:00
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
struct fd_data *fd;
|
|
|
|
struct fdc_data *fdc;
|
|
|
|
fdsu_t fdsu;
|
2000-10-15 04:54:17 +00:00
|
|
|
#ifndef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
static int fd_fifo = 0;
|
2000-10-15 04:54:17 +00:00
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
|
|
|
|
fdsu = *(int *)device_get_ivars(dev); /* xxx cheat a bit... */
|
|
|
|
fd = device_get_softc(dev);
|
|
|
|
fdc = device_get_softc(device_get_parent(dev));
|
|
|
|
|
|
|
|
bzero(fd, sizeof *fd);
|
|
|
|
fd->dev = dev;
|
|
|
|
fd->fdc = fdc;
|
|
|
|
fd->fdsu = fdsu;
|
|
|
|
fd->fdu = device_get_unit(dev);
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
/* look up what bios thinks we have */
|
|
|
|
switch (fd->fdu) {
|
|
|
|
case 0: case 1: case 2: case 3:
|
|
|
|
if ((PC98_SYSTEM_PARAMETER(0x5ae) >> fd->fdu) & 0x01)
|
|
|
|
fdt = FDT_144M;
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef EPSON_NRDISK
|
1999-04-18 14:42:20 +00:00
|
|
|
else if ((PC98_SYSTEM_PARAMETER(0x55c) >> fd->fdu) & 0x01) {
|
|
|
|
fdt = FDT_12M;
|
|
|
|
switch (epson_machine_id) {
|
|
|
|
case 0x20: case 0x27:
|
|
|
|
if ((PC98_SYSTEM_PARAMETER(0x488) >> fd->fdu) & 0x01) {
|
|
|
|
if (nrd_check_ready()) {
|
|
|
|
nrd_LED_on();
|
|
|
|
nrdu = fd->fdu;
|
|
|
|
} else {
|
|
|
|
fdt = FDT_NONE;
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
#else /* !EPSON_NRDISK */
|
1999-04-18 14:42:20 +00:00
|
|
|
else if ((PC98_SYSTEM_PARAMETER(0x55c) >> fd->fdu) & 0x01) {
|
|
|
|
fdt = FDT_12M;
|
|
|
|
switch (epson_machine_id) {
|
|
|
|
case 0x20: case 0x27:
|
|
|
|
if ((PC98_SYSTEM_PARAMETER(0x488) >> fd->fdu) & 0x01)
|
|
|
|
fdt = FDT_NONE;
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif /* EPSON_NRDISK */
|
1999-04-18 14:42:20 +00:00
|
|
|
else
|
1996-06-14 10:04:54 +00:00
|
|
|
fdt = FDT_NONE;
|
1999-04-18 14:42:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fdt = FDT_NONE;
|
|
|
|
break;
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
#else
|
1999-09-27 03:32:31 +00:00
|
|
|
#ifdef __i386__
|
1999-04-18 14:42:20 +00:00
|
|
|
/* look up what bios thinks we have */
|
|
|
|
switch (fd->fdu) {
|
|
|
|
case 0:
|
2000-03-19 15:18:22 +00:00
|
|
|
if ((fdc->flags & FDC_ISPCMCIA))
|
|
|
|
fdt = RTCFDT_144M;
|
|
|
|
else if (device_get_flags(fdc->fdc_dev) & FDC_PRETEND_D0)
|
1999-04-18 14:42:20 +00:00
|
|
|
fdt = RTCFDT_144M | RTCFDT_144M_PRETENDED;
|
|
|
|
else
|
|
|
|
fdt = (rtcin(RTC_FDISKETTE) & 0xf0);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fdt = ((rtcin(RTC_FDISKETTE) << 4) & 0xf0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fdt = RTCFDT_NONE;
|
|
|
|
break;
|
|
|
|
}
|
1999-09-27 03:32:31 +00:00
|
|
|
#else
|
|
|
|
fdt = RTCFDT_144M; /* XXX probably */
|
|
|
|
#endif
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
|
|
|
|
/* is there a unit? */
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fdt == FDT_NONE)
|
|
|
|
return (ENXIO);
|
1996-06-14 10:04:54 +00:00
|
|
|
#else
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fdt == RTCFDT_NONE)
|
|
|
|
return (ENXIO);
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
|
|
|
|
1996-09-10 09:39:22 +00:00
|
|
|
#ifndef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
/* select it */
|
|
|
|
set_motor(fdc, fdsu, TURNON);
|
|
|
|
DELAY(1000000); /* 1 sec */
|
|
|
|
|
1999-11-18 11:34:26 +00:00
|
|
|
/* XXX This doesn't work before the first set_motor() */
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_fifo == 0 && fdc->fdct != FDC_NE765 && fdc->fdct != FDC_UNKNOWN
|
2000-01-09 10:01:21 +00:00
|
|
|
&& (device_get_flags(fdc->fdc_dev) & FDC_NO_FIFO) == 0
|
1999-04-18 14:42:20 +00:00
|
|
|
&& enable_fifo(fdc) == 0) {
|
2000-01-09 10:01:21 +00:00
|
|
|
device_printf(device_get_parent(dev),
|
|
|
|
"FIFO enabled, %d bytes threshold\n", fifo_threshold);
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
|
|
|
fd_fifo = 1;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if ((fd_cmd(fdc, 2, NE7CMD_SENSED, fdsu, 1, &st3) == 0)
|
|
|
|
&& (st3 & NE7_ST3_T0)) {
|
|
|
|
/* if at track 0, first seek inwards */
|
|
|
|
/* seek some steps: */
|
|
|
|
fd_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0);
|
|
|
|
DELAY(300000); /* ...wait a moment... */
|
|
|
|
fd_sense_int(fdc, 0, 0); /* make ctrlr happy */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're at track 0 first seek inwards. */
|
|
|
|
if ((fd_sense_drive_status(fdc, &st3) == 0) && (st3 & NE7_ST3_T0)) {
|
|
|
|
/* Seek some steps... */
|
|
|
|
if (fd_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0) == 0) {
|
|
|
|
/* ...wait a moment... */
|
|
|
|
DELAY(300000);
|
|
|
|
/* make ctrlr happy: */
|
|
|
|
fd_sense_int(fdc, 0, 0);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
/*
|
|
|
|
* we must recalibrate twice, just in case the
|
|
|
|
* heads have been beyond cylinder 76, since most
|
|
|
|
* FDCs still barf when attempting to recalibrate
|
|
|
|
* more than 77 steps
|
|
|
|
*/
|
|
|
|
/* go back to 0: */
|
|
|
|
if (fd_cmd(fdc, 2, NE7CMD_RECAL, fdsu, 0) == 0) {
|
|
|
|
/* a second being enough for full stroke seek*/
|
|
|
|
DELAY(i == 0 ? 1000000 : 300000);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
/* anything responding? */
|
|
|
|
if (fd_sense_int(fdc, &st0, 0) == 0 &&
|
|
|
|
(st0 & NE7_ST0_EC) == 0)
|
|
|
|
break; /* already probed succesfully */
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
set_motor(fdc, fdsu, TURNOFF);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (st0 & NE7_ST0_EC) /* no track 0 -> no drive present */
|
|
|
|
return (ENXIO);
|
|
|
|
#endif /* PC98 */
|
|
|
|
|
|
|
|
fd->track = FD_NO_TRACK;
|
|
|
|
fd->fdc = fdc;
|
|
|
|
fd->fdsu = fdsu;
|
|
|
|
fd->options = 0;
|
|
|
|
callout_handle_init(&fd->toffhandle);
|
|
|
|
callout_handle_init(&fd->tohandle);
|
|
|
|
|
|
|
|
#ifdef PC98
|
|
|
|
switch (fdt) {
|
1999-09-23 14:21:14 +00:00
|
|
|
case FDT_144M:
|
|
|
|
/* Check 3mode I/F */
|
|
|
|
fd->pc98_trans = 0;
|
|
|
|
outb(0x4be, (fd->fdu << 5) | 0x10);
|
|
|
|
if (!(inb(0x4be) & 0x01)) {
|
|
|
|
device_set_desc(dev, "1.44M FDD");
|
|
|
|
fd->type = FD_1440;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Warning: can't control 3mode I/F, "
|
|
|
|
"fallback to 2mode.\n"
|
|
|
|
"fd%d: ", fd->fdu);
|
|
|
|
/* FALLTHROUGH */
|
1999-04-18 14:42:20 +00:00
|
|
|
case FDT_12M:
|
|
|
|
#ifdef EPSON_NRDISK
|
1999-09-23 14:21:14 +00:00
|
|
|
if (fd->fdu == nrdu) {
|
1999-04-18 14:42:20 +00:00
|
|
|
device_set_desc(dev, "EPSON RAM DRIVE");
|
|
|
|
nrd_LED_off();
|
|
|
|
} else
|
|
|
|
#endif
|
1999-09-23 14:21:14 +00:00
|
|
|
device_set_desc(dev, "1M/640K FDD");
|
1999-04-18 14:42:20 +00:00
|
|
|
fd->type = FD_1200;
|
|
|
|
fd->pc98_trans = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
switch (fdt) {
|
|
|
|
case RTCFDT_12M:
|
|
|
|
device_set_desc(dev, "1200-KB 5.25\" drive");
|
|
|
|
fd->type = FD_1200;
|
|
|
|
break;
|
|
|
|
case RTCFDT_144M | RTCFDT_144M_PRETENDED:
|
|
|
|
device_set_desc(dev, "config-pretended 1440-MB 3.5\" drive");
|
|
|
|
fdt = RTCFDT_144M;
|
|
|
|
fd->type = FD_1440;
|
|
|
|
case RTCFDT_144M:
|
|
|
|
device_set_desc(dev, "1440-KB 3.5\" drive");
|
|
|
|
fd->type = FD_1440;
|
|
|
|
break;
|
|
|
|
case RTCFDT_288M:
|
|
|
|
case RTCFDT_288M_1:
|
|
|
|
device_set_desc(dev, "2880-KB 3.5\" drive (in 1440-KB mode)");
|
|
|
|
fd->type = FD_1440;
|
|
|
|
break;
|
|
|
|
case RTCFDT_360K:
|
|
|
|
device_set_desc(dev, "360-KB 5.25\" drive");
|
|
|
|
fd->type = FD_360;
|
|
|
|
break;
|
|
|
|
case RTCFDT_720K:
|
|
|
|
printf("720-KB 3.5\" drive");
|
|
|
|
fd->type = FD_720;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
static int
|
|
|
|
fd_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct fd_data *fd;
|
2000-09-15 05:47:56 +00:00
|
|
|
static int cdevsw_add_done = 0;
|
1999-04-18 14:42:20 +00:00
|
|
|
|
|
|
|
fd = device_get_softc(dev);
|
|
|
|
|
2000-09-15 05:47:56 +00:00
|
|
|
if (!cdevsw_add_done) {
|
2000-11-05 14:31:19 +00:00
|
|
|
cdevsw_add(&fd_cdevsw); /* XXX */
|
|
|
|
cdevsw_add_done++;
|
2000-09-15 05:47:56 +00:00
|
|
|
}
|
2000-11-05 14:31:19 +00:00
|
|
|
EVENTHANDLER_REGISTER(dev_clone, fd_clone, 0, 1000);
|
1999-08-27 07:26:26 +00:00
|
|
|
make_dev(&fd_cdevsw, (fd->fdu << 6),
|
2000-11-05 14:31:19 +00:00
|
|
|
UID_ROOT, GID_OPERATOR, 0640, "fd%d", fd->fdu);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
/*
|
|
|
|
* Export the drive to the devstat interface.
|
|
|
|
*/
|
|
|
|
devstat_add_entry(&fd->device_stats, device_get_name(dev),
|
|
|
|
device_get_unit(dev), 512, DEVSTAT_NO_ORDERED_TAGS,
|
|
|
|
DEVSTAT_TYPE_FLOPPY | DEVSTAT_TYPE_IF_OTHER,
|
|
|
|
DEVSTAT_PRIORITY_FD);
|
|
|
|
return (0);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
static int
|
|
|
|
fd_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct fd_data *fd;
|
|
|
|
|
|
|
|
fd = device_get_softc(dev);
|
|
|
|
untimeout(fd_turnoff, fd, fd->toffhandle);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-09-27 03:32:31 +00:00
|
|
|
static device_method_t fd_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, fd_probe),
|
|
|
|
DEVMETHOD(device_attach, fd_attach),
|
2000-03-19 15:18:22 +00:00
|
|
|
DEVMETHOD(device_detach, fd_detach),
|
1999-09-27 03:32:31 +00:00
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend), /* XXX */
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume), /* XXX */
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t fd_driver = {
|
|
|
|
"fd",
|
|
|
|
fd_methods,
|
|
|
|
sizeof(struct fd_data)
|
|
|
|
};
|
|
|
|
|
1999-11-08 07:46:28 +00:00
|
|
|
DRIVER_MODULE(fd, fdc, fd_driver, fd_devclass, 0, 0);
|
1999-09-27 03:32:31 +00:00
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* motor control stuff */
|
|
|
|
/* remember to not deselect the drive we're working on */
|
|
|
|
/****************************************************************************/
|
|
|
|
static void
|
1999-04-18 14:42:20 +00:00
|
|
|
set_motor(struct fdc_data *fdc, int fdsu, int turnon)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
int fdout = fdc->fdout;
|
1996-06-14 10:04:54 +00:00
|
|
|
int needspecify = 0;
|
|
|
|
|
|
|
|
#ifdef PC98
|
|
|
|
outb(IO_FDPORT, (pc98_trans != 1 ? FDP_FDDEXC : 0)|FDP_PORTEXC);
|
|
|
|
DELAY(10);
|
|
|
|
fdout = FDO_DMAE|FDO_MTON;
|
|
|
|
#else
|
|
|
|
if(turnon) {
|
|
|
|
fdout &= ~FDO_FDSEL;
|
|
|
|
fdout |= (FDO_MOEN0 << fdsu) + fdsu;
|
|
|
|
} else
|
|
|
|
fdout &= ~(FDO_MOEN0 << fdsu);
|
|
|
|
|
|
|
|
if(!turnon
|
|
|
|
&& (fdout & (FDO_MOEN0+FDO_MOEN1+FDO_MOEN2+FDO_MOEN3)) == 0)
|
|
|
|
/* gonna turn off the last drive, put FDC to bed */
|
|
|
|
fdout &= ~ (FDO_FRST|FDO_FDMAEN);
|
|
|
|
else {
|
|
|
|
/* make sure controller is selected and specified */
|
|
|
|
if((fdout & (FDO_FRST|FDO_FDMAEN)) == 0)
|
|
|
|
needspecify = 1;
|
|
|
|
fdout |= (FDO_FRST|FDO_FDMAEN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, fdout);
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc->fdout = fdout;
|
1996-06-14 10:04:54 +00:00
|
|
|
TRACE1("[0x%x->FDOUT]", fdout);
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (needspecify) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* special case: since we have just woken up the FDC
|
|
|
|
* from its sleep, we silently assume the command will
|
|
|
|
* be accepted, and do not test for a timeout
|
|
|
|
*/
|
|
|
|
#ifdef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
(void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
|
1996-06-14 10:04:54 +00:00
|
|
|
NE7_SPEC_1(4, 240), NE7_SPEC_2(2, 0),
|
|
|
|
0);
|
|
|
|
#else
|
1999-04-18 14:42:20 +00:00
|
|
|
(void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
|
1996-06-14 10:04:54 +00:00
|
|
|
NE7_SPEC_1(3, 240), NE7_SPEC_2(2, 0),
|
|
|
|
0);
|
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fdc->flags & FDC_HAS_FIFO)
|
|
|
|
(void) enable_fifo(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_turnoff(void *xfd)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
int s;
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_p fd = xfd;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
TRACE1("[fd%d: turnoff]", fd->fdu);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
2000-03-19 15:18:22 +00:00
|
|
|
s = splbio();
|
1996-06-14 10:04:54 +00:00
|
|
|
/*
|
|
|
|
* Don't turn off the motor yet if the drive is active.
|
2000-03-19 15:18:22 +00:00
|
|
|
*
|
|
|
|
* If we got here, this could only mean we missed an interrupt.
|
|
|
|
* This can e. g. happen on the Y-E Date PCMCIA floppy controller
|
|
|
|
* after a controller reset. Just schedule a pseudo-interrupt
|
|
|
|
* so the state machine gets re-entered.
|
1996-06-14 10:04:54 +00:00
|
|
|
*/
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd->fdc->state != DEVIDLE && fd->fdc->fdu == fd->fdu) {
|
2000-03-19 15:18:22 +00:00
|
|
|
fdc_intr(fd->fdc);
|
|
|
|
splx(s);
|
1996-06-14 10:04:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd->flags &= ~FD_MOTOR;
|
1999-04-18 14:42:20 +00:00
|
|
|
set_motor(fd->fdc, fd->fdsu, TURNOFF);
|
1996-06-14 10:04:54 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_motor_on(void *xfd)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
int s;
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_p fd = xfd;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
fd->flags &= ~FD_MOTOR_WAIT;
|
|
|
|
if((fd->fdc->fd == fd) && (fd->fdc->state == MOTORWAIT))
|
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_intr(fd->fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_turnon(fd_p fd)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
if(!(fd->flags & FD_MOTOR))
|
|
|
|
{
|
|
|
|
fd->flags |= (FD_MOTOR + FD_MOTOR_WAIT);
|
1999-04-18 14:42:20 +00:00
|
|
|
set_motor(fd->fdc, fd->fdsu, TURNON);
|
|
|
|
timeout(fd_motor_on, fd, hz); /* in 1 sec its ok */
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fdc_reset(fdc_p fdc)
|
|
|
|
{
|
|
|
|
/* Try a reset, keep motor on */
|
|
|
|
#ifdef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
set_density(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
if (pc98_machine_type & M_EPSON_PC98)
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, 0xe8);
|
1996-06-14 10:04:54 +00:00
|
|
|
else
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, 0xd8);
|
1996-06-14 10:04:54 +00:00
|
|
|
DELAY(200);
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, 0x18);
|
1996-06-14 10:04:54 +00:00
|
|
|
DELAY(10);
|
|
|
|
#else
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
|
1996-06-14 10:04:54 +00:00
|
|
|
TRACE1("[0x%x->FDOUT]", fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
|
|
|
|
DELAY(100);
|
|
|
|
/* enable FDC, but defer interrupts a moment */
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, fdc->fdout & ~FDO_FDMAEN);
|
1996-06-14 10:04:54 +00:00
|
|
|
TRACE1("[0x%x->FDOUT]", fdc->fdout & ~FDO_FDMAEN);
|
|
|
|
DELAY(100);
|
1999-11-11 12:15:15 +00:00
|
|
|
fdout_wr(fdc, fdc->fdout);
|
1996-06-14 10:04:54 +00:00
|
|
|
TRACE1("[0x%x->FDOUT]", fdc->fdout);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* XXX after a reset, silently believe the FDC will accept commands */
|
|
|
|
#ifdef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
(void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
|
1996-06-14 10:04:54 +00:00
|
|
|
NE7_SPEC_1(4, 240), NE7_SPEC_2(2, 0),
|
|
|
|
0);
|
|
|
|
#else
|
1999-04-18 14:42:20 +00:00
|
|
|
(void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
|
1996-06-14 10:04:54 +00:00
|
|
|
NE7_SPEC_1(3, 240), NE7_SPEC_2(2, 0),
|
|
|
|
0);
|
|
|
|
#endif
|
1997-09-18 08:10:45 +00:00
|
|
|
if (fdc->flags & FDC_HAS_FIFO)
|
|
|
|
(void) enable_fifo(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* fdc in/out */
|
|
|
|
/****************************************************************************/
|
|
|
|
int
|
1999-04-18 14:42:20 +00:00
|
|
|
in_fdc(struct fdc_data *fdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1997-01-18 15:51:43 +00:00
|
|
|
int i, j = 100000;
|
1999-11-11 12:15:15 +00:00
|
|
|
while ((i = fdsts_rd(fdc) & (NE7_DIO|NE7_RQM))
|
1996-12-04 04:21:30 +00:00
|
|
|
!= (NE7_DIO|NE7_RQM) && j-- > 0)
|
1996-06-14 10:04:54 +00:00
|
|
|
if (i == NE7_RQM)
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, "ready for output in input\n");
|
1996-06-14 10:04:54 +00:00
|
|
|
if (j <= 0)
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, bootverbose? "input ready timeout\n": 0);
|
1997-09-17 08:01:07 +00:00
|
|
|
#ifdef FDC_DEBUG
|
1999-11-11 12:15:15 +00:00
|
|
|
i = fddata_rd(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
TRACE1("[FDDATA->0x%x]", (unsigned char)i);
|
|
|
|
return(i);
|
1997-09-17 08:01:07 +00:00
|
|
|
#else /* !FDC_DEBUG */
|
1999-11-11 12:15:15 +00:00
|
|
|
return fddata_rd(fdc);
|
1997-09-17 08:01:07 +00:00
|
|
|
#endif /* FDC_DEBUG */
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fd_in: Like in_fdc, but allows you to see if it worked.
|
|
|
|
*/
|
|
|
|
static int
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_in(struct fdc_data *fdc, int *ptr)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1997-01-18 15:51:43 +00:00
|
|
|
int i, j = 100000;
|
1999-11-11 12:15:15 +00:00
|
|
|
while ((i = fdsts_rd(fdc) & (NE7_DIO|NE7_RQM))
|
1997-01-18 15:51:43 +00:00
|
|
|
!= (NE7_DIO|NE7_RQM) && j-- > 0)
|
1996-06-14 10:04:54 +00:00
|
|
|
if (i == NE7_RQM)
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, "ready for output in input\n");
|
1996-06-14 10:04:54 +00:00
|
|
|
if (j <= 0)
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, bootverbose? "input ready timeout\n": 0);
|
1997-09-17 08:01:07 +00:00
|
|
|
#ifdef FDC_DEBUG
|
1999-11-11 12:15:15 +00:00
|
|
|
i = fddata_rd(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
TRACE1("[FDDATA->0x%x]", (unsigned char)i);
|
|
|
|
*ptr = i;
|
|
|
|
return 0;
|
1997-09-17 08:01:07 +00:00
|
|
|
#else /* !FDC_DEBUG */
|
1999-11-11 12:15:15 +00:00
|
|
|
i = fddata_rd(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
if (ptr)
|
|
|
|
*ptr = i;
|
|
|
|
return 0;
|
1997-09-17 08:01:07 +00:00
|
|
|
#endif /* FDC_DEBUG */
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-04-18 14:42:20 +00:00
|
|
|
out_fdc(struct fdc_data *fdc, int x)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Check that the direction bit is set */
|
1997-01-18 15:51:43 +00:00
|
|
|
i = 100000;
|
1999-11-11 12:15:15 +00:00
|
|
|
while ((fdsts_rd(fdc) & NE7_DIO) && i-- > 0);
|
1999-04-18 14:42:20 +00:00
|
|
|
if (i <= 0) return fdc_err(fdc, "direction bit not set\n");
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
/* Check that the floppy controller is ready for a command */
|
1997-01-18 15:51:43 +00:00
|
|
|
i = 100000;
|
1999-11-11 12:15:15 +00:00
|
|
|
while ((fdsts_rd(fdc) & NE7_RQM) == 0 && i-- > 0);
|
1996-06-14 10:04:54 +00:00
|
|
|
if (i <= 0)
|
1999-04-18 14:42:20 +00:00
|
|
|
return fdc_err(fdc, bootverbose? "output ready timeout\n": 0);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
/* Send the command and return */
|
1999-11-11 12:15:15 +00:00
|
|
|
fddata_wr(fdc, x);
|
1996-06-14 10:04:54 +00:00
|
|
|
TRACE1("[0x%x->FDDATA]", x);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* fdopen/fdclose */
|
|
|
|
/****************************************************************************/
|
|
|
|
int
|
|
|
|
Fdopen(dev_t dev, int flags, int mode, struct proc *p)
|
|
|
|
{
|
|
|
|
fdu_t fdu = FDUNIT(minor(dev));
|
|
|
|
int type = FDTYPE(minor(dev));
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_p fd;
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc_p fdc;
|
|
|
|
|
|
|
|
/* check bounds */
|
1999-04-18 14:42:20 +00:00
|
|
|
if ((fd = devclass_get_softc(fd_devclass, fdu)) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
fdc = fd->fdc;
|
|
|
|
if ((fdc == NULL) || (fd->type == NO_TYPE))
|
|
|
|
return (ENXIO);
|
1996-06-14 10:04:54 +00:00
|
|
|
if (type > NUMDENS)
|
1999-04-18 14:42:20 +00:00
|
|
|
return (ENXIO);
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef PC98
|
1999-09-23 14:21:14 +00:00
|
|
|
if (type == 0)
|
|
|
|
type = FD_1200; /* XXX backward compatibility */
|
|
|
|
else
|
|
|
|
; /* XXX any types are OK for PC-98 */
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
if (pc98_fd_check_ready(fdu) == -1)
|
|
|
|
return(EIO);
|
1999-09-23 14:21:14 +00:00
|
|
|
#else
|
1996-06-14 10:04:54 +00:00
|
|
|
if (type == 0)
|
1999-04-18 14:42:20 +00:00
|
|
|
type = fd->type;
|
1996-06-14 10:04:54 +00:00
|
|
|
else {
|
1998-04-20 13:50:58 +00:00
|
|
|
/*
|
|
|
|
* For each type of basic drive, make sure we are trying
|
|
|
|
* to open a type it can do,
|
|
|
|
*/
|
1999-04-18 14:42:20 +00:00
|
|
|
if (type != fd->type) {
|
|
|
|
switch (fd->type) {
|
1996-06-14 10:04:54 +00:00
|
|
|
case FD_360:
|
1999-04-18 14:42:20 +00:00
|
|
|
return (ENXIO);
|
1996-06-14 10:04:54 +00:00
|
|
|
case FD_720:
|
|
|
|
if ( type != FD_820
|
|
|
|
&& type != FD_800
|
2000-01-09 10:01:21 +00:00
|
|
|
&& type != FD_640
|
1996-06-14 10:04:54 +00:00
|
|
|
)
|
1999-04-18 14:42:20 +00:00
|
|
|
return (ENXIO);
|
1996-06-14 10:04:54 +00:00
|
|
|
break;
|
|
|
|
case FD_1200:
|
|
|
|
switch (type) {
|
|
|
|
case FD_1480:
|
|
|
|
type = FD_1480in5_25;
|
|
|
|
break;
|
|
|
|
case FD_1440:
|
|
|
|
type = FD_1440in5_25;
|
|
|
|
break;
|
2000-01-09 10:01:21 +00:00
|
|
|
case FD_1232:
|
|
|
|
break;
|
1996-06-14 10:04:54 +00:00
|
|
|
case FD_820:
|
|
|
|
type = FD_820in5_25;
|
|
|
|
break;
|
|
|
|
case FD_800:
|
|
|
|
type = FD_800in5_25;
|
|
|
|
break;
|
|
|
|
case FD_720:
|
|
|
|
type = FD_720in5_25;
|
|
|
|
break;
|
2000-01-09 10:01:21 +00:00
|
|
|
case FD_640:
|
|
|
|
type = FD_640in5_25;
|
|
|
|
break;
|
1996-06-14 10:04:54 +00:00
|
|
|
case FD_360:
|
|
|
|
type = FD_360in5_25;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FD_1440:
|
|
|
|
if ( type != FD_1720
|
|
|
|
&& type != FD_1480
|
|
|
|
&& type != FD_1200
|
|
|
|
&& type != FD_820
|
|
|
|
&& type != FD_800
|
|
|
|
&& type != FD_720
|
2000-01-09 10:01:21 +00:00
|
|
|
&& type != FD_640
|
1996-06-14 10:04:54 +00:00
|
|
|
)
|
|
|
|
return(ENXIO);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
fd->ft = fd_types + type - 1;
|
|
|
|
fd->flags |= FD_OPEN;
|
2000-03-19 15:18:22 +00:00
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fdclose(dev_t dev, int flags, int mode, struct proc *p)
|
|
|
|
{
|
|
|
|
fdu_t fdu = FDUNIT(minor(dev));
|
1999-04-18 14:42:20 +00:00
|
|
|
struct fd_data *fd;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
fd = devclass_get_softc(fd_devclass, fdu);
|
|
|
|
fd->flags &= ~FD_OPEN;
|
|
|
|
fd->options &= ~FDOPT_NORETRY;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
return (0);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* fdstrategy */
|
|
|
|
/****************************************************************************/
|
|
|
|
void
|
2000-04-15 05:54:02 +00:00
|
|
|
fdstrategy(struct bio *bp)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1996-11-09 00:39:59 +00:00
|
|
|
unsigned nblocks, blknum, cando;
|
1996-06-14 10:04:54 +00:00
|
|
|
int s;
|
|
|
|
fdu_t fdu;
|
|
|
|
fdc_p fdc;
|
|
|
|
fd_p fd;
|
|
|
|
size_t fdblk;
|
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
fdu = FDUNIT(minor(bp->bio_dev));
|
1999-04-18 14:42:20 +00:00
|
|
|
fd = devclass_get_softc(fd_devclass, fdu);
|
|
|
|
if (fd == 0)
|
|
|
|
panic("fdstrategy: buf for nonexistent device (%#lx, %#lx)",
|
2000-04-15 05:54:02 +00:00
|
|
|
(u_long)major(bp->bio_dev), (u_long)minor(bp->bio_dev));
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc = fd->fdc;
|
1998-12-14 09:06:23 +00:00
|
|
|
if (fd->type == NO_TYPE) {
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = ENXIO;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
2000-01-09 10:01:21 +00:00
|
|
|
goto bad;
|
1998-12-14 09:06:23 +00:00
|
|
|
};
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
fdblk = 128 << (fd->ft->secsize);
|
2000-04-15 05:54:02 +00:00
|
|
|
if (!(bp->bio_cmd & BIO_FORMAT)) {
|
|
|
|
if (bp->bio_blkno < 0) {
|
1996-06-14 10:04:54 +00:00
|
|
|
printf(
|
|
|
|
"fd%d: fdstrat: bad request blkno = %lu, bcount = %ld\n",
|
2000-04-15 05:54:02 +00:00
|
|
|
fdu, (u_long)bp->bio_blkno, bp->bio_bcount);
|
|
|
|
bp->bio_error = EINVAL;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1996-06-14 10:04:54 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2000-04-15 05:54:02 +00:00
|
|
|
if ((bp->bio_bcount % fdblk) != 0) {
|
|
|
|
bp->bio_error = EINVAL;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1996-06-14 10:04:54 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up block calculations.
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
if (bp->bio_blkno > 20000000) {
|
1996-11-09 00:39:59 +00:00
|
|
|
/*
|
|
|
|
* Reject unreasonably high block number, prevent the
|
|
|
|
* multiplication below from overflowing.
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = EINVAL;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1996-11-09 00:39:59 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2000-04-15 05:54:02 +00:00
|
|
|
blknum = (unsigned) bp->bio_blkno * DEV_BSIZE/fdblk;
|
1996-06-14 10:04:54 +00:00
|
|
|
nblocks = fd->ft->size;
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_resid = 0;
|
|
|
|
if (blknum + (bp->bio_bcount / fdblk) > nblocks) {
|
1996-11-09 00:39:59 +00:00
|
|
|
if (blknum <= nblocks) {
|
|
|
|
cando = (nblocks - blknum) * fdblk;
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_resid = bp->bio_bcount - cando;
|
1996-11-09 00:39:59 +00:00
|
|
|
if (cando == 0)
|
|
|
|
goto bad; /* not actually bad but EOF */
|
1996-06-14 10:04:54 +00:00
|
|
|
} else {
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = EINVAL;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1996-11-09 00:39:59 +00:00
|
|
|
goto bad;
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_pblkno = bp->bio_blkno;
|
1996-06-14 10:04:54 +00:00
|
|
|
s = splbio();
|
2000-04-15 05:54:02 +00:00
|
|
|
bioqdisksort(&fdc->head, bp);
|
1999-04-18 14:42:20 +00:00
|
|
|
untimeout(fd_turnoff, fd, fd->toffhandle); /* a good idea */
|
1998-09-15 14:07:08 +00:00
|
|
|
|
|
|
|
/* Tell devstat we are starting on the transaction */
|
|
|
|
devstat_start_transaction(&fd->device_stats);
|
2000-03-19 15:18:22 +00:00
|
|
|
device_busy(fd->dev);
|
1998-09-15 14:07:08 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
fdstart(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************\
|
|
|
|
* fdstart *
|
|
|
|
* We have just queued something.. if the controller is not busy *
|
|
|
|
* then simulate the case where it has just finished a command *
|
|
|
|
* So that it (the interrupt routine) looks on the queue for more*
|
|
|
|
* work to do and picks up what we just added. *
|
|
|
|
* If the controller is already busy, we need do nothing, as it *
|
|
|
|
* will pick up our work when the present work completes *
|
|
|
|
\***************************************************************/
|
|
|
|
static void
|
1999-04-18 14:42:20 +00:00
|
|
|
fdstart(struct fdc_data *fdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
1999-04-18 14:42:20 +00:00
|
|
|
if(fdc->state == DEVIDLE)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_intr(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_iotimeout(void *xfdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1998-07-30 09:01:12 +00:00
|
|
|
fdc_p fdc;
|
1996-06-14 10:04:54 +00:00
|
|
|
int s;
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc = xfdc;
|
1998-07-30 09:01:12 +00:00
|
|
|
TRACE1("fd%d[fd_iotimeout()]", fdc->fdu);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Due to IBM's brain-dead design, the FDC has a faked ready
|
|
|
|
* signal, hardwired to ready == true. Thus, any command
|
|
|
|
* issued if there's no diskette in the drive will _never_
|
|
|
|
* complete, and must be aborted by resetting the FDC.
|
|
|
|
* Many thanks, Big Blue!
|
1998-07-30 09:01:12 +00:00
|
|
|
* The FDC must not be reset directly, since that would
|
|
|
|
* interfere with the state machine. Instead, pretend that
|
|
|
|
* the command completed but was invalid. The state machine
|
|
|
|
* will reset the FDC and retry once.
|
1996-06-14 10:04:54 +00:00
|
|
|
*/
|
|
|
|
s = splbio();
|
1998-07-30 09:01:12 +00:00
|
|
|
fdc->status[0] = NE7_ST0_IC_IV;
|
|
|
|
fdc->flags &= ~FDC_STAT_VALID;
|
|
|
|
fdc->state = IOTIMEDOUT;
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_intr(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* just ensure it has the right spl */
|
|
|
|
static void
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_pseudointr(void *xfdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_intr(xfdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************\
|
|
|
|
* fdintr *
|
|
|
|
* keep calling the state machine until it returns a 0 *
|
|
|
|
* ALWAYS called at SPLBIO *
|
|
|
|
\***********************************************************************/
|
1998-10-22 05:58:45 +00:00
|
|
|
static void
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_intr(void *xfdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
fdc_p fdc = xfdc;
|
|
|
|
while(fdstate(fdc))
|
|
|
|
;
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-14 09:06:23 +00:00
|
|
|
/*
|
|
|
|
* magic pseudo-DMA initialization for YE FDC. Sets count and
|
|
|
|
* direction
|
|
|
|
*/
|
2000-01-09 10:01:21 +00:00
|
|
|
#define SET_BCDR(fdc,wr,cnt,port) \
|
|
|
|
bus_space_write_1(fdc->portt, fdc->porth, fdc->port_off + port, \
|
|
|
|
((cnt)-1) & 0xff); \
|
|
|
|
bus_space_write_1(fdc->portt, fdc->porth, fdc->port_off + port + 1, \
|
|
|
|
((wr ? 0x80 : 0) | ((((cnt)-1) >> 8) & 0x7f)));
|
1998-12-14 09:06:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fdcpio(): perform programmed IO read/write for YE PCMCIA floppy
|
|
|
|
*/
|
2000-01-09 10:01:21 +00:00
|
|
|
static int fdcpio(fdc_p fdc, long flags, caddr_t addr, u_int count)
|
1998-12-14 09:06:23 +00:00
|
|
|
{
|
|
|
|
u_char *cptr = (u_char *)addr;
|
|
|
|
|
2000-03-20 10:44:49 +00:00
|
|
|
if (flags == BIO_READ) {
|
1998-12-14 09:06:23 +00:00
|
|
|
if (fdc->state != PIOREAD) {
|
|
|
|
fdc->state = PIOREAD;
|
|
|
|
return(0);
|
|
|
|
};
|
2000-01-09 10:01:21 +00:00
|
|
|
SET_BCDR(fdc, 0, count, 0);
|
|
|
|
bus_space_read_multi_1(fdc->portt, fdc->porth, fdc->port_off +
|
|
|
|
FDC_YE_DATAPORT, cptr, count);
|
1998-12-14 09:06:23 +00:00
|
|
|
} else {
|
2000-01-09 10:01:21 +00:00
|
|
|
bus_space_write_multi_1(fdc->portt, fdc->porth, fdc->port_off +
|
|
|
|
FDC_YE_DATAPORT, cptr, count);
|
|
|
|
SET_BCDR(fdc, 0, count, 0);
|
1998-12-14 09:06:23 +00:00
|
|
|
};
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
/***********************************************************************\
|
|
|
|
* The controller state machine. *
|
|
|
|
* if it returns a non zero value, it should be called again immediatly *
|
|
|
|
\***********************************************************************/
|
|
|
|
static int
|
1999-04-18 14:42:20 +00:00
|
|
|
fdstate(fdc_p fdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
2000-03-28 15:09:13 +00:00
|
|
|
int read, format, head, i, sec = 0, sectrac, st0, cyl, st3, idf;
|
1996-11-09 00:39:59 +00:00
|
|
|
unsigned blknum = 0, b_cylinder = 0;
|
1996-06-14 10:04:54 +00:00
|
|
|
fdu_t fdu = fdc->fdu;
|
|
|
|
fd_p fd;
|
2000-04-15 05:54:02 +00:00
|
|
|
register struct bio *bp;
|
1996-06-14 10:04:54 +00:00
|
|
|
struct fd_formb *finfo = NULL;
|
|
|
|
size_t fdblk;
|
|
|
|
|
1999-01-16 11:40:02 +00:00
|
|
|
bp = fdc->bp;
|
|
|
|
if (bp == NULL) {
|
2000-04-15 05:54:02 +00:00
|
|
|
bp = bioq_first(&fdc->head);
|
1999-01-16 11:40:02 +00:00
|
|
|
if (bp != NULL) {
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq_remove(&fdc->head, bp);
|
1999-01-16 11:40:02 +00:00
|
|
|
fdc->bp = bp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bp == NULL) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/***********************************************\
|
|
|
|
* nothing left for this controller to do *
|
|
|
|
* Force into the IDLE state, *
|
|
|
|
\***********************************************/
|
|
|
|
fdc->state = DEVIDLE;
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fdc->fd) {
|
2000-01-09 10:01:21 +00:00
|
|
|
device_printf(fdc->fdc_dev,
|
|
|
|
"unexpected valid fd pointer\n");
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->fd = (fd_p) 0;
|
|
|
|
fdc->fdu = -1;
|
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
TRACE1("[fdc%d IDLE]", fdc->fdcu);
|
|
|
|
return (0);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
2000-04-15 05:54:02 +00:00
|
|
|
fdu = FDUNIT(minor(bp->bio_dev));
|
1999-04-18 14:42:20 +00:00
|
|
|
fd = devclass_get_softc(fd_devclass, fdu);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdblk = 128 << fd->ft->secsize;
|
2000-01-09 10:01:21 +00:00
|
|
|
if (fdc->fd && (fd != fdc->fd))
|
|
|
|
device_printf(fd->dev, "confused fd pointers\n");
|
2000-04-15 05:54:02 +00:00
|
|
|
read = bp->bio_cmd == BIO_READ;
|
2000-03-28 15:09:13 +00:00
|
|
|
if (read)
|
|
|
|
idf = ISADMA_READ;
|
|
|
|
else
|
|
|
|
idf = ISADMA_WRITE;
|
2000-04-15 05:54:02 +00:00
|
|
|
format = bp->bio_cmd & BIO_FORMAT;
|
1999-04-18 14:42:20 +00:00
|
|
|
if (format) {
|
2000-04-15 05:54:02 +00:00
|
|
|
finfo = (struct fd_formb *)bp->bio_data;
|
1996-11-09 00:39:59 +00:00
|
|
|
fd->skip = (char *)&(finfo->fd_formb_cylno(0))
|
|
|
|
- (char *)finfo;
|
|
|
|
}
|
|
|
|
if (fdc->state == DOSEEK || fdc->state == SEEKCOMPLETE) {
|
2000-04-15 05:54:02 +00:00
|
|
|
blknum = (unsigned) bp->bio_pblkno * DEV_BSIZE/fdblk +
|
1996-11-09 00:39:59 +00:00
|
|
|
fd->skip/fdblk;
|
|
|
|
b_cylinder = blknum / (fd->ft->sectrac * fd->ft->heads);
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
TRACE1("fd%d", fdu);
|
|
|
|
TRACE1("[%s]", fdstates[fdc->state]);
|
|
|
|
TRACE1("(0x%x)", fd->flags);
|
1999-04-18 14:42:20 +00:00
|
|
|
untimeout(fd_turnoff, fd, fd->toffhandle);
|
|
|
|
fd->toffhandle = timeout(fd_turnoff, fd, 4 * hz);
|
1996-06-14 10:04:54 +00:00
|
|
|
switch (fdc->state)
|
|
|
|
{
|
|
|
|
case DEVIDLE:
|
|
|
|
case FINDWORK: /* we have found new work */
|
|
|
|
fdc->retry = 0;
|
|
|
|
fd->skip = 0;
|
|
|
|
fdc->fd = fd;
|
|
|
|
fdc->fdu = fdu;
|
|
|
|
#ifdef PC98
|
|
|
|
pc98_trans = fd->ft->trans;
|
|
|
|
if (pc98_trans_prev != pc98_trans) {
|
|
|
|
int i;
|
1999-04-18 14:42:20 +00:00
|
|
|
set_density(fdc);
|
1996-06-14 10:04:54 +00:00
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
outb(0x5f, 0);
|
|
|
|
outb(0x5f, 0);
|
|
|
|
}
|
|
|
|
pc98_trans_prev = pc98_trans;
|
|
|
|
}
|
|
|
|
if (pc98_trans != fd->pc98_trans) {
|
1999-09-23 14:21:14 +00:00
|
|
|
if (fd->type == FD_1440) {
|
1996-06-14 10:04:54 +00:00
|
|
|
outb(0x4be, (fdu << 5) | 0x10 | (pc98_trans >> 1));
|
|
|
|
outb(0x5f, 0);
|
|
|
|
outb(0x5f, 0);
|
|
|
|
}
|
|
|
|
fd->pc98_trans = pc98_trans;
|
|
|
|
}
|
|
|
|
#else
|
2000-03-19 15:18:22 +00:00
|
|
|
fdc->fdctl_wr(fdc, fd->ft->trans);
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
|
|
|
TRACE1("[0x%x->FDCTL]", fd->ft->trans);
|
|
|
|
/*******************************************************\
|
|
|
|
* If the next drive has a motor startup pending, then *
|
1998-04-17 22:37:19 +00:00
|
|
|
* it will start up in its own good time *
|
1996-06-14 10:04:54 +00:00
|
|
|
\*******************************************************/
|
1999-04-18 14:42:20 +00:00
|
|
|
if(fd->flags & FD_MOTOR_WAIT) {
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->state = MOTORWAIT;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (0); /* come back later */
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
/*******************************************************\
|
|
|
|
* Maybe if it's not starting, it SHOULD be starting *
|
|
|
|
\*******************************************************/
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdu != nrdu) {
|
|
|
|
if (!(fd->flags & FD_MOTOR))
|
|
|
|
{
|
|
|
|
fdc->state = MOTORWAIT;
|
|
|
|
fd_turnon(fdu);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
else /* at least make sure we are selected */
|
|
|
|
{
|
|
|
|
set_motor(fdcu, fd->fdsu, TURNON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* !EPSON_NRDISK */
|
|
|
|
if (!(fd->flags & FD_MOTOR))
|
|
|
|
{
|
|
|
|
fdc->state = MOTORWAIT;
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_turnon(fd);
|
|
|
|
return (0);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
else /* at least make sure we are selected */
|
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
set_motor(fdc, fd->fdsu, TURNON);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
1998-07-30 09:01:12 +00:00
|
|
|
if (fdc->flags & FDC_NEEDS_RESET) {
|
|
|
|
fdc->state = RESETCTLR;
|
|
|
|
fdc->flags &= ~FDC_NEEDS_RESET;
|
|
|
|
} else
|
|
|
|
fdc->state = DOSEEK;
|
1996-06-14 10:04:54 +00:00
|
|
|
break;
|
|
|
|
case DOSEEK:
|
1996-11-09 00:39:59 +00:00
|
|
|
if (b_cylinder == (unsigned)fd->track)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
|
|
|
fdc->state = SEEKCOMPLETE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef PC98
|
|
|
|
pc98_fd_check_ready(fdu);
|
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_cmd(fdc, 3, NE7CMD_SEEK,
|
1996-11-09 00:39:59 +00:00
|
|
|
fd->fdsu, b_cylinder * fd->ft->steptrac,
|
1996-06-14 10:04:54 +00:00
|
|
|
0))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* seek command not accepted, looks like
|
|
|
|
* the FDC went off to the Saints...
|
|
|
|
*/
|
|
|
|
fdc->retry = 6; /* try a reset */
|
1999-04-18 14:42:20 +00:00
|
|
|
return(retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
fd->track = FD_NO_TRACK;
|
|
|
|
fdc->state = SEEKWAIT;
|
|
|
|
return(0); /* will return later */
|
|
|
|
case SEEKWAIT:
|
|
|
|
/* allow heads to settle */
|
1999-04-18 14:42:20 +00:00
|
|
|
timeout(fd_pseudointr, fdc, hz / 16);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->state = SEEKCOMPLETE;
|
|
|
|
return(0); /* will return later */
|
|
|
|
case SEEKCOMPLETE : /* SEEK DONE, START DMA */
|
|
|
|
/* Make sure seek really happened*/
|
1999-04-18 14:42:20 +00:00
|
|
|
if(fd->track == FD_NO_TRACK) {
|
1996-11-09 00:39:59 +00:00
|
|
|
int descyl = b_cylinder * fd->ft->steptrac;
|
1996-06-14 10:04:54 +00:00
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* This might be a "ready changed" interrupt,
|
|
|
|
* which cannot really happen since the
|
|
|
|
* RDY pin is hardwired to + 5 volts. This
|
|
|
|
* generally indicates a "bouncing" intr
|
|
|
|
* line, so do one of the following:
|
|
|
|
*
|
|
|
|
* When running on an enhanced FDC that is
|
|
|
|
* known to not go stuck after responding
|
|
|
|
* with INVALID, fetch all interrupt states
|
|
|
|
* until seeing either an INVALID or a
|
|
|
|
* real interrupt condition.
|
|
|
|
*
|
|
|
|
* When running on a dumb old NE765, give
|
|
|
|
* up immediately. The controller will
|
|
|
|
* provide up to four dummy RC interrupt
|
|
|
|
* conditions right after reset (for the
|
|
|
|
* corresponding four drives), so this is
|
|
|
|
* our only chance to get notice that it
|
|
|
|
* was not the FDC that caused the interrupt.
|
|
|
|
*/
|
|
|
|
if (fd_sense_int(fdc, &st0, &cyl)
|
|
|
|
== FD_NOT_VALID)
|
|
|
|
return 0;
|
|
|
|
if(fdc->fdct == FDC_NE765
|
|
|
|
&& (st0 & NE7_ST0_IC) == NE7_ST0_IC_RC)
|
|
|
|
return 0; /* hope for a real intr */
|
|
|
|
} while ((st0 & NE7_ST0_IC) == NE7_ST0_IC_RC);
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (0 == descyl) {
|
1996-06-14 10:04:54 +00:00
|
|
|
int failed = 0;
|
|
|
|
/*
|
|
|
|
* seek to cyl 0 requested; make sure we are
|
|
|
|
* really there
|
|
|
|
*/
|
|
|
|
if (fd_sense_drive_status(fdc, &st3))
|
|
|
|
failed = 1;
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdu == nrdu) st3 = NE7_ST3_T0;
|
|
|
|
#endif /* EPSON_NRDISK */
|
|
|
|
if ((st3 & NE7_ST3_T0) == 0) {
|
|
|
|
printf(
|
|
|
|
"fd%d: Seek to cyl 0, but not really there (ST3 = %b)\n",
|
|
|
|
fdu, st3, NE7_ST3BITS);
|
|
|
|
failed = 1;
|
|
|
|
}
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (failed) {
|
1996-06-14 10:04:54 +00:00
|
|
|
if(fdc->retry < 3)
|
|
|
|
fdc->retry = 3;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdu == nrdu) cyl = descyl;
|
|
|
|
#endif
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (cyl != descyl) {
|
1996-06-14 10:04:54 +00:00
|
|
|
printf(
|
|
|
|
"fd%d: Seek to cyl %d failed; am at cyl %d (ST0 = 0x%x)\n",
|
|
|
|
fdu, descyl, cyl, st0);
|
1998-07-19 15:03:49 +00:00
|
|
|
if (fdc->retry < 3)
|
|
|
|
fdc->retry = 3;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-11-09 00:39:59 +00:00
|
|
|
fd->track = b_cylinder;
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdu != nrdu) {
|
|
|
|
#endif /* EPSON_NRDISK */
|
2000-01-09 10:01:21 +00:00
|
|
|
if (!(fdc->flags & FDC_NODMA))
|
2000-04-15 05:54:02 +00:00
|
|
|
isa_dmastart(idf, bp->bio_data+fd->skip,
|
|
|
|
format ? bp->bio_bcount : fdblk, fdc->dmachan);
|
1996-06-14 10:04:54 +00:00
|
|
|
sectrac = fd->ft->sectrac;
|
|
|
|
sec = blknum % (sectrac * fd->ft->heads);
|
|
|
|
head = sec / sectrac;
|
|
|
|
sec = sec % sectrac + 1;
|
|
|
|
fd->hddrv = ((head&1)<<2)+fdu;
|
1999-04-18 14:42:20 +00:00
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
if(format || !read)
|
|
|
|
{
|
|
|
|
/* make sure the drive is writable */
|
|
|
|
if(fd_sense_drive_status(fdc, &st3) != 0)
|
|
|
|
{
|
|
|
|
/* stuck controller? */
|
2000-03-19 15:18:22 +00:00
|
|
|
if (!(fdc->flags & FDC_NODMA))
|
2000-03-28 15:09:13 +00:00
|
|
|
isa_dmadone(idf,
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_data + fd->skip,
|
|
|
|
format ? bp->bio_bcount : fdblk,
|
2000-03-19 15:18:22 +00:00
|
|
|
fdc->dmachan);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->retry = 6; /* reset the beast */
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
if(st3 & NE7_ST3_WP)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* XXX YES! this is ugly.
|
|
|
|
* in order to force the current operation
|
|
|
|
* to fail, we will have to fake an FDC
|
|
|
|
* error - all error handling is done
|
|
|
|
* by the retrier()
|
|
|
|
*/
|
|
|
|
fdc->status[0] = NE7_ST0_IC_AT;
|
|
|
|
fdc->status[1] = NE7_ST1_NW;
|
|
|
|
fdc->status[2] = 0;
|
|
|
|
fdc->status[3] = fd->track;
|
|
|
|
fdc->status[4] = head;
|
|
|
|
fdc->status[5] = sec;
|
|
|
|
fdc->retry = 8; /* break out immediately */
|
|
|
|
fdc->state = IOTIMEDOUT; /* not really... */
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (format) {
|
2000-03-19 15:18:22 +00:00
|
|
|
if (fdc->flags & FDC_NODMA) {
|
|
|
|
/*
|
|
|
|
* This seems to be necessary for
|
|
|
|
* whatever obscure reason; if we omit
|
|
|
|
* it, we end up filling the sector ID
|
|
|
|
* fields of the newly formatted track
|
|
|
|
* entirely with garbage, causing
|
|
|
|
* `wrong cylinder' errors all over
|
|
|
|
* the place when trying to read them
|
|
|
|
* back.
|
|
|
|
*
|
|
|
|
* Umpf.
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
SET_BCDR(fdc, 1, bp->bio_bcount, 0);
|
2000-03-19 15:18:22 +00:00
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
(void)fdcpio(fdc,bp->bio_cmd,
|
|
|
|
bp->bio_data+fd->skip,
|
|
|
|
bp->bio_bcount);
|
2000-03-19 15:18:22 +00:00
|
|
|
|
|
|
|
}
|
1996-06-14 10:04:54 +00:00
|
|
|
/* formatting */
|
1999-04-18 14:42:20 +00:00
|
|
|
if(fd_cmd(fdc, 6, NE7CMD_FORMAT, head << 2 | fdu,
|
1996-06-14 10:04:54 +00:00
|
|
|
finfo->fd_formb_secshift,
|
|
|
|
finfo->fd_formb_nsecs,
|
|
|
|
finfo->fd_formb_gaplen,
|
1999-04-18 14:42:20 +00:00
|
|
|
finfo->fd_formb_fillbyte, 0)) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/* controller fell over */
|
2000-03-19 15:18:22 +00:00
|
|
|
if (!(fdc->flags & FDC_NODMA))
|
2000-03-28 15:09:13 +00:00
|
|
|
isa_dmadone(idf,
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_data + fd->skip,
|
|
|
|
format ? bp->bio_bcount : fdblk,
|
2000-03-19 15:18:22 +00:00
|
|
|
fdc->dmachan);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->retry = 6;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
} else {
|
2000-01-09 10:01:21 +00:00
|
|
|
if (fdc->flags & FDC_NODMA) {
|
1998-12-14 09:06:23 +00:00
|
|
|
/*
|
|
|
|
* this seems to be necessary even when
|
|
|
|
* reading data
|
|
|
|
*/
|
2000-01-09 10:01:21 +00:00
|
|
|
SET_BCDR(fdc, 1, fdblk, 0);
|
1998-12-14 09:06:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* perform the write pseudo-DMA before
|
|
|
|
* the WRITE command is sent
|
|
|
|
*/
|
|
|
|
if (!read)
|
2000-04-15 05:54:02 +00:00
|
|
|
(void)fdcpio(fdc,bp->bio_cmd,
|
|
|
|
bp->bio_data+fd->skip,
|
1998-12-14 09:06:23 +00:00
|
|
|
fdblk);
|
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_cmd(fdc, 9,
|
1996-06-14 10:04:54 +00:00
|
|
|
(read ? NE7CMD_READ : NE7CMD_WRITE),
|
|
|
|
head << 2 | fdu, /* head & unit */
|
|
|
|
fd->track, /* track */
|
|
|
|
head,
|
|
|
|
sec, /* sector + 1 */
|
|
|
|
fd->ft->secsize, /* sector size */
|
|
|
|
sectrac, /* sectors/track */
|
|
|
|
fd->ft->gap, /* gap size */
|
|
|
|
fd->ft->datalen, /* data length */
|
1999-04-18 14:42:20 +00:00
|
|
|
0)) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/* the beast is sleeping again */
|
2000-03-19 15:18:22 +00:00
|
|
|
if (!(fdc->flags & FDC_NODMA))
|
2000-03-28 15:09:13 +00:00
|
|
|
isa_dmadone(idf,
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_data + fd->skip,
|
|
|
|
format ? bp->bio_bcount : fdblk,
|
2000-03-19 15:18:22 +00:00
|
|
|
fdc->dmachan);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->retry = 6;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-09 10:01:21 +00:00
|
|
|
if (fdc->flags & FDC_NODMA)
|
1998-12-14 09:06:23 +00:00
|
|
|
/*
|
|
|
|
* if this is a read, then simply await interrupt
|
|
|
|
* before performing PIO
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
if (read && !fdcpio(fdc,bp->bio_cmd,
|
|
|
|
bp->bio_data+fd->skip,fdblk)) {
|
2000-01-09 10:01:21 +00:00
|
|
|
fd->tohandle = timeout(fd_iotimeout, fdc, hz);
|
1998-12-14 09:06:23 +00:00
|
|
|
return(0); /* will return later */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write (or format) operation will fall through and
|
|
|
|
* await completion interrupt
|
|
|
|
*/
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->state = IOCOMPLETE;
|
1999-04-18 14:42:20 +00:00
|
|
|
fd->tohandle = timeout(fd_iotimeout, fdc, hz);
|
|
|
|
return (0); /* will return later */
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nrdblkn = (nrd_t)((unsigned long)bp->b_blkno*DEV_BSIZE/fdblk
|
|
|
|
+ fd->skip/fdblk);
|
|
|
|
nrd_LED_on();
|
|
|
|
nrd_addrset(fdblk * nrdblkn);
|
|
|
|
while (!nrd_check_ready()) DELAY(1);
|
|
|
|
if (read) epson_insw(P_NRD_DATA,
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_data + fd->skip,
|
1996-06-14 10:04:54 +00:00
|
|
|
fdblk / sizeof(short));
|
|
|
|
else epson_outsw(P_NRD_DATA,
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_data + fd->skip,
|
|
|
|
(format ? bp->bio_bcount : fdblk)
|
1996-06-14 10:04:54 +00:00
|
|
|
/ sizeof(short));
|
|
|
|
|
|
|
|
blknum = (unsigned long)bp->b_blkno*DEV_BSIZE/fdblk
|
|
|
|
+ fd->skip/fdblk;
|
|
|
|
sectrac = fd->ft->sectrac;
|
|
|
|
sec = blknum % (sectrac * fd->ft->heads);
|
|
|
|
head = sec / sectrac;
|
|
|
|
sec = sec % sectrac + 1;
|
|
|
|
fd->hddrv = ((head&1)<<2)+fdu;
|
|
|
|
|
1997-01-18 15:51:43 +00:00
|
|
|
if (nrdsec++ >= nrd_sec())
|
1996-06-14 10:04:54 +00:00
|
|
|
nrdaddr = (nrd_t)(fd->track * 8 + head * 4);
|
|
|
|
nrdsec = sec;
|
|
|
|
fdc->state = IOCOMPLETE;
|
|
|
|
}
|
1998-12-14 09:06:23 +00:00
|
|
|
#endif
|
|
|
|
case PIOREAD:
|
|
|
|
/*
|
|
|
|
* actually perform the PIO read. The IOCOMPLETE case
|
|
|
|
* removes the timeout for us.
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
(void)fdcpio(fdc,bp->bio_cmd,bp->bio_data+fd->skip,fdblk);
|
1998-12-14 09:06:23 +00:00
|
|
|
fdc->state = IOCOMPLETE;
|
|
|
|
/* FALLTHROUGH */
|
1996-06-14 10:04:54 +00:00
|
|
|
case IOCOMPLETE: /* IO DONE, post-analyze */
|
|
|
|
#ifdef EPSON_NRDISK
|
1997-09-22 12:23:49 +00:00
|
|
|
if (fdu != nrdu)
|
1999-04-18 14:42:20 +00:00
|
|
|
untimeout(fd_iotimeout, fdc, fd->tohandle);
|
1996-06-14 10:04:54 +00:00
|
|
|
#else
|
1999-04-18 14:42:20 +00:00
|
|
|
untimeout(fd_iotimeout, fdc, fd->tohandle);
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fd_read_status(fdc, fd->fdsu)) {
|
2000-03-19 15:18:22 +00:00
|
|
|
if (!(fdc->flags & FDC_NODMA))
|
2000-04-15 05:54:02 +00:00
|
|
|
isa_dmadone(idf, bp->bio_data + fd->skip,
|
|
|
|
format ? bp->bio_bcount : fdblk,
|
2000-03-19 15:18:22 +00:00
|
|
|
fdc->dmachan);
|
1996-06-14 10:04:54 +00:00
|
|
|
if (fdc->retry < 6)
|
|
|
|
fdc->retry = 6; /* force a reset */
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fdc->state = IOTIMEDOUT;
|
|
|
|
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case IOTIMEDOUT:
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdu != nrdu) {
|
|
|
|
#endif /* EPSON_NRDISK */
|
2000-01-09 10:01:21 +00:00
|
|
|
if (!(fdc->flags & FDC_NODMA))
|
2000-04-15 05:54:02 +00:00
|
|
|
isa_dmadone(idf, bp->bio_data + fd->skip,
|
|
|
|
format ? bp->bio_bcount : fdblk, fdc->dmachan);
|
1996-06-14 10:04:54 +00:00
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
}
|
|
|
|
else nrd_LED_off();
|
|
|
|
#endif /* EPSON_NRDISK */
|
1999-04-18 14:42:20 +00:00
|
|
|
if (fdc->status[0] & NE7_ST0_IC) {
|
1996-06-14 10:04:54 +00:00
|
|
|
if ((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
|
|
|
|
&& fdc->status[1] & NE7_ST1_OR) {
|
|
|
|
/*
|
|
|
|
* DMA overrun. Someone hogged the bus
|
|
|
|
* and didn't release it in time for the
|
|
|
|
* next FDC transfer.
|
|
|
|
* Just restart it, don't increment retry
|
|
|
|
* count. (vak)
|
|
|
|
*/
|
|
|
|
fdc->state = SEEKCOMPLETE;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
else if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_IV
|
|
|
|
&& fdc->retry < 6)
|
|
|
|
fdc->retry = 6; /* force a reset */
|
|
|
|
else if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
|
|
|
|
&& fdc->status[2] & NE7_ST2_WC
|
|
|
|
&& fdc->retry < 3)
|
|
|
|
fdc->retry = 3; /* force recalibrate */
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
/* All OK */
|
|
|
|
fd->skip += fdblk;
|
2000-04-15 05:54:02 +00:00
|
|
|
if (!format && fd->skip < bp->bio_bcount - bp->bio_resid) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/* set up next transfer */
|
|
|
|
fdc->state = DOSEEK;
|
1999-04-18 14:42:20 +00:00
|
|
|
} else {
|
1996-06-14 10:04:54 +00:00
|
|
|
/* ALL DONE */
|
|
|
|
fd->skip = 0;
|
1999-01-16 11:40:02 +00:00
|
|
|
fdc->bp = NULL;
|
2000-03-19 15:18:22 +00:00
|
|
|
device_unbusy(fd->dev);
|
2000-04-15 05:54:02 +00:00
|
|
|
devstat_end_transaction_bio(&fd->device_stats, bp);
|
1996-06-14 10:04:54 +00:00
|
|
|
biodone(bp);
|
|
|
|
fdc->fd = (fd_p) 0;
|
|
|
|
fdc->fdu = -1;
|
|
|
|
fdc->state = FINDWORK;
|
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
return (1);
|
1996-06-14 10:04:54 +00:00
|
|
|
case RESETCTLR:
|
|
|
|
fdc_reset(fdc);
|
|
|
|
fdc->retry++;
|
1998-07-30 09:01:12 +00:00
|
|
|
fdc->state = RESETCOMPLETE;
|
|
|
|
return (0);
|
|
|
|
case RESETCOMPLETE:
|
|
|
|
/*
|
|
|
|
* Discard all the results from the reset so that they
|
|
|
|
* can't cause an unexpected interrupt later.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
(void)fd_sense_int(fdc, &st0, &cyl);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->state = STARTRECAL;
|
1998-07-30 09:01:12 +00:00
|
|
|
/* Fall through. */
|
1996-06-14 10:04:54 +00:00
|
|
|
case STARTRECAL:
|
|
|
|
#ifdef PC98
|
|
|
|
pc98_fd_check_ready(fdu);
|
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
if(fd_cmd(fdc, 2, NE7CMD_RECAL, fdu, 0)) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/* arrgl */
|
|
|
|
fdc->retry = 6;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
fdc->state = RECALWAIT;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (0); /* will return later */
|
1996-06-14 10:04:54 +00:00
|
|
|
case RECALWAIT:
|
|
|
|
/* allow heads to settle */
|
1999-04-18 14:42:20 +00:00
|
|
|
timeout(fd_pseudointr, fdc, hz / 8);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->state = RECALCOMPLETE;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (0); /* will return later */
|
1996-06-14 10:04:54 +00:00
|
|
|
case RECALCOMPLETE:
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* See SEEKCOMPLETE for a comment on this:
|
|
|
|
*/
|
|
|
|
if (fd_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
|
|
|
|
return 0;
|
|
|
|
if(fdc->fdct == FDC_NE765
|
|
|
|
&& (st0 & NE7_ST0_IC) == NE7_ST0_IC_RC)
|
|
|
|
return 0; /* hope for a real intr */
|
|
|
|
} while ((st0 & NE7_ST0_IC) == NE7_ST0_IC_RC);
|
|
|
|
#ifdef EPSON_NRDISK
|
|
|
|
if (fdu == nrdu) {
|
|
|
|
st0 = NE7_ST0_IC_NT;
|
|
|
|
cyl = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((st0 & NE7_ST0_IC) != NE7_ST0_IC_NT || cyl != 0)
|
|
|
|
{
|
|
|
|
if(fdc->retry > 3)
|
|
|
|
/*
|
|
|
|
* a recalibrate from beyond cylinder 77
|
|
|
|
* will "fail" due to the FDC limitations;
|
|
|
|
* since people used to complain much about
|
|
|
|
* the failure message, try not logging
|
|
|
|
* this one if it seems to be the first
|
|
|
|
* time in a line
|
|
|
|
*/
|
|
|
|
printf("fd%d: recal failed ST0 %b cyl %d\n",
|
|
|
|
fdu, st0, NE7_ST0BITS, cyl);
|
|
|
|
if(fdc->retry < 3) fdc->retry = 3;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (retrier(fdc));
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
fd->track = 0;
|
|
|
|
/* Seek (probably) necessary */
|
|
|
|
fdc->state = DOSEEK;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (1); /* will return immediatly */
|
1996-06-14 10:04:54 +00:00
|
|
|
case MOTORWAIT:
|
|
|
|
if(fd->flags & FD_MOTOR_WAIT)
|
|
|
|
{
|
1999-04-18 14:42:20 +00:00
|
|
|
return (0); /* time's not up yet */
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
1998-07-30 09:01:12 +00:00
|
|
|
if (fdc->flags & FDC_NEEDS_RESET) {
|
|
|
|
fdc->state = RESETCTLR;
|
|
|
|
fdc->flags &= ~FDC_NEEDS_RESET;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If all motors were off, then the controller was
|
|
|
|
* reset, so it has lost track of the current
|
|
|
|
* cylinder. Recalibrate to handle this case.
|
1999-05-11 08:37:16 +00:00
|
|
|
* But first, discard the results of the reset.
|
1998-07-30 09:01:12 +00:00
|
|
|
*/
|
1999-05-11 08:37:16 +00:00
|
|
|
fdc->state = RESETCOMPLETE;
|
1998-07-30 09:01:12 +00:00
|
|
|
}
|
1999-04-18 14:42:20 +00:00
|
|
|
return (1); /* will return immediatly */
|
1996-06-14 10:04:54 +00:00
|
|
|
default:
|
2000-01-09 10:01:21 +00:00
|
|
|
device_printf(fdc->fdc_dev, "unexpected FD int->");
|
1996-06-14 10:04:54 +00:00
|
|
|
if (fd_read_status(fdc, fd->fdsu) == 0)
|
1998-07-11 17:02:07 +00:00
|
|
|
printf("FDC status :%x %x %x %x %x %x %x ",
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->status[0],
|
|
|
|
fdc->status[1],
|
|
|
|
fdc->status[2],
|
|
|
|
fdc->status[3],
|
|
|
|
fdc->status[4],
|
|
|
|
fdc->status[5],
|
|
|
|
fdc->status[6] );
|
|
|
|
else
|
|
|
|
printf("No status available ");
|
|
|
|
if (fd_sense_int(fdc, &st0, &cyl) != 0)
|
|
|
|
{
|
|
|
|
printf("[controller is dead now]\n");
|
1999-04-18 14:42:20 +00:00
|
|
|
return (0);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
printf("ST0 = %x, PCN = %x\n", st0, cyl);
|
1999-04-18 14:42:20 +00:00
|
|
|
return (0);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
/*XXX confusing: some branches return immediately, others end up here*/
|
1999-04-18 14:42:20 +00:00
|
|
|
return (1); /* Come back immediatly to new state */
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-04-18 14:42:20 +00:00
|
|
|
retrier(struct fdc_data *fdc)
|
1996-06-14 10:04:54 +00:00
|
|
|
{
|
2000-11-05 14:31:19 +00:00
|
|
|
struct bio *bp;
|
1999-04-18 14:42:20 +00:00
|
|
|
struct fd_data *fd;
|
|
|
|
int fdu;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-01-16 11:40:02 +00:00
|
|
|
bp = fdc->bp;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
/* XXX shouldn't this be cached somewhere? */
|
2000-04-15 05:54:02 +00:00
|
|
|
fdu = FDUNIT(minor(bp->bio_dev));
|
1999-04-18 14:42:20 +00:00
|
|
|
fd = devclass_get_softc(fd_devclass, fdu);
|
|
|
|
if (fd->options & FDOPT_NORETRY)
|
1996-06-14 10:04:54 +00:00
|
|
|
goto fail;
|
1999-04-18 14:42:20 +00:00
|
|
|
|
|
|
|
switch (fdc->retry) {
|
1996-06-14 10:04:54 +00:00
|
|
|
case 0: case 1: case 2:
|
|
|
|
fdc->state = SEEKCOMPLETE;
|
|
|
|
break;
|
|
|
|
case 3: case 4: case 5:
|
|
|
|
fdc->state = STARTRECAL;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
fdc->state = RESETCTLR;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fail:
|
|
|
|
{
|
2000-11-05 14:31:19 +00:00
|
|
|
dev_t sav_bio_dev = bp->bio_dev;
|
1996-06-14 10:04:54 +00:00
|
|
|
/* Trick diskerr */
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_dev = makedev(major(bp->bio_dev),
|
|
|
|
(FDUNIT(minor(bp->bio_dev))<<3)|RAW_PART);
|
2001-05-06 05:49:11 +00:00
|
|
|
diskerr(bp, "hard error", fdc->fd->skip / DEV_BSIZE,
|
1996-06-14 10:04:54 +00:00
|
|
|
(struct disklabel *)NULL);
|
2000-11-05 14:31:19 +00:00
|
|
|
bp->bio_dev = sav_bio_dev;
|
1996-06-14 10:04:54 +00:00
|
|
|
if (fdc->flags & FDC_STAT_VALID)
|
|
|
|
{
|
|
|
|
printf(
|
1998-07-11 17:02:07 +00:00
|
|
|
" (ST0 %b ST1 %b ST2 %b cyl %u hd %u sec %u)\n",
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->status[0], NE7_ST0BITS,
|
|
|
|
fdc->status[1], NE7_ST1BITS,
|
|
|
|
fdc->status[2], NE7_ST2BITS,
|
|
|
|
fdc->status[3], fdc->status[4],
|
|
|
|
fdc->status[5]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf(" (No status)\n");
|
|
|
|
}
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
bp->bio_error = EIO;
|
|
|
|
bp->bio_resid += bp->bio_bcount - fdc->fd->skip;
|
1999-01-16 11:40:02 +00:00
|
|
|
fdc->bp = NULL;
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->fd->skip = 0;
|
2000-03-19 15:18:22 +00:00
|
|
|
device_unbusy(fd->dev);
|
2000-04-15 05:54:02 +00:00
|
|
|
devstat_end_transaction_bio(&fdc->fd->device_stats, bp);
|
1996-06-14 10:04:54 +00:00
|
|
|
biodone(bp);
|
|
|
|
fdc->state = FINDWORK;
|
1998-07-30 09:01:12 +00:00
|
|
|
fdc->flags |= FDC_NEEDS_RESET;
|
1996-06-14 10:04:54 +00:00
|
|
|
fdc->fd = (fd_p) 0;
|
|
|
|
fdc->fdu = -1;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (1);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
fdc->retry++;
|
1999-04-18 14:42:20 +00:00
|
|
|
return (1);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
|
|
|
|
2000-07-11 12:50:34 +00:00
|
|
|
static void
|
|
|
|
fdbiodone(struct bio *bp)
|
|
|
|
{
|
|
|
|
wakeup(bp);
|
|
|
|
}
|
|
|
|
|
1996-06-14 10:04:54 +00:00
|
|
|
static int
|
|
|
|
fdformat(dev, finfo, p)
|
|
|
|
dev_t dev;
|
|
|
|
struct fd_formb *finfo;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
fdu_t fdu;
|
|
|
|
fd_p fd;
|
|
|
|
|
2000-07-11 12:50:34 +00:00
|
|
|
struct bio *bp;
|
1996-06-14 10:04:54 +00:00
|
|
|
int rv = 0, s;
|
|
|
|
size_t fdblk;
|
|
|
|
|
1998-04-20 13:50:58 +00:00
|
|
|
fdu = FDUNIT(minor(dev));
|
1999-04-18 14:42:20 +00:00
|
|
|
fd = devclass_get_softc(fd_devclass, fdu);
|
1996-06-14 10:04:54 +00:00
|
|
|
fdblk = 128 << fd->ft->secsize;
|
|
|
|
|
|
|
|
/* set up a buffer header for fdstrategy() */
|
2000-07-11 12:50:34 +00:00
|
|
|
bp = (struct bio *)malloc(sizeof(struct bio), M_TEMP, M_NOWAIT);
|
1996-06-14 10:04:54 +00:00
|
|
|
if(bp == 0)
|
2000-07-11 12:50:34 +00:00
|
|
|
return ENOMEM;
|
1996-06-14 10:04:54 +00:00
|
|
|
/*
|
|
|
|
* keep the process from being swapped
|
|
|
|
*/
|
1999-04-06 03:12:22 +00:00
|
|
|
PHOLD(p);
|
2000-07-11 12:50:34 +00:00
|
|
|
bzero((void *)bp, sizeof(*bp));
|
|
|
|
bp->bio_cmd = BIO_FORMAT;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* calculate a fake blkno, so fdstrategy() would initiate a
|
|
|
|
* seek to the requested cylinder
|
|
|
|
*/
|
2000-07-11 12:50:34 +00:00
|
|
|
bp->bio_blkno = (finfo->cyl * (fd->ft->sectrac * fd->ft->heads)
|
1996-06-14 10:04:54 +00:00
|
|
|
+ finfo->head * fd->ft->sectrac) * fdblk / DEV_BSIZE;
|
|
|
|
|
2000-07-11 12:50:34 +00:00
|
|
|
bp->bio_bcount = sizeof(struct fd_idfield_data) * finfo->fd_formb_nsecs;
|
|
|
|
bp->bio_data = (caddr_t)finfo;
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
/* now do the format */
|
2000-07-11 12:50:34 +00:00
|
|
|
bp->bio_dev = dev;
|
|
|
|
bp->bio_done = fdbiodone;
|
|
|
|
fdstrategy(bp);
|
1996-06-14 10:04:54 +00:00
|
|
|
|
|
|
|
/* ...and wait for it to complete */
|
|
|
|
s = splbio();
|
2000-07-11 12:50:34 +00:00
|
|
|
while(!(bp->bio_flags & BIO_DONE)) {
|
1996-06-14 10:04:54 +00:00
|
|
|
rv = tsleep((caddr_t)bp, PRIBIO, "fdform", 20 * hz);
|
1999-04-18 14:42:20 +00:00
|
|
|
if (rv == EWOULDBLOCK)
|
1996-06-14 10:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
1999-04-18 14:42:20 +00:00
|
|
|
if (rv == EWOULDBLOCK) {
|
1996-06-14 10:04:54 +00:00
|
|
|
/* timed out */
|
|
|
|
rv = EIO;
|
2000-03-19 15:18:22 +00:00
|
|
|
device_unbusy(fd->dev);
|
1996-06-14 10:04:54 +00:00
|
|
|
}
|
2000-07-11 12:50:34 +00:00
|
|
|
if (bp->bio_flags & BIO_ERROR)
|
|
|
|
rv = bp->bio_error;
|
1996-06-14 10:04:54 +00:00
|
|
|
/*
|
|
|
|
* allow the process to be swapped
|
|
|
|
*/
|
1999-04-06 03:12:22 +00:00
|
|
|
PRELE(p);
|
1996-06-14 10:04:54 +00:00
|
|
|
free(bp, M_TEMP);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: don't allocate buffer on stack.
|
|
|
|
*/
|
|
|
|
|
1998-04-20 13:50:58 +00:00
|
|
|
static int
|
1996-06-14 10:04:54 +00:00
|
|
|
fdioctl(dev, cmd, addr, flag, p)
|
|
|
|
dev_t dev;
|
1998-06-08 08:55:47 +00:00
|
|
|
u_long cmd;
|
1996-06-14 10:04:54 +00:00
|
|
|
caddr_t addr;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
fdu_t fdu = FDUNIT(minor(dev));
|
1999-04-18 14:42:20 +00:00
|
|
|
fd_p fd = devclass_get_softc(fd_devclass, fdu);
|
1996-06-14 10:04:54 +00:00
|
|
|
size_t fdblk;
|
|
|
|
|
|
|
|
struct fd_type *fdt;
|
|
|
|
struct disklabel *dl;
|
|
|
|
char buffer[DEV_BSIZE];
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
fdblk = 128 << fd->ft->secsize;
|
|
|
|
|
|
|
|
#ifdef PC98
|
1999-04-18 14:42:20 +00:00
|
|
|
pc98_fd_check_ready(fdu);
|
1996-06-14 10:04:54 +00:00
|
|
|
#endif
|
1999-04-18 14:42:20 +00:00
|
|
|
switch (cmd) {
|
1996-06-14 10:04:54 +00:00
|
|
|
case DIOCGDINFO:
|
|
|
|
bzero(buffer, sizeof (buffer));
|
|
|
|
dl = (struct disklabel *)buffer;
|
|
|
|
dl->d_secsize = fdblk;
|
1999-04-18 14:42:20 +00:00
|
|
|
fdt = fd->ft;
|
1996-06-14 10:04:54 +00:00
|
|
|
dl->d_secpercyl = fdt->size / fdt->tracks;
|
|
|
|
dl->d_type = DTYPE_FLOPPY;
|
|
|
|
|
1999-08-14 11:40:51 +00:00
|
|
|
if (readdisklabel(dkmodpart(dev, RAW_PART), dl)
|
1996-06-14 10:04:54 +00:00
|
|
|
== NULL)
|
|
|
|
error = 0;
|
|
|
|
else
|
|
|
|
error = EINVAL;
|
|
|
|
|
|
|
|
*(struct disklabel *)addr = *dl;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCSDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
error = EBADF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
error = EBADF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
1999-04-18 14:42:20 +00:00
|
|
|
if ((flag & FWRITE) == 0) {
|
1996-06-14 10:04:54 +00:00
|
|
|
error = EBADF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dl = (struct disklabel *)addr;
|
|
|
|
|
|
|
|
if ((error = setdisklabel((struct disklabel *)buffer, dl,
|
|
|
|
(u_long)0)) != 0)
|
|
|
|
break;
|
|
|
|
|
1999-08-14 11:40:51 +00:00
|
|
|
error = writedisklabel(dev, (struct disklabel *)buffer);
|
1996-06-14 10:04:54 +00:00
|
|
|
break;
|
|
|
|
case FD_FORM:
|
1999-04-18 14:42:20 +00:00
|
|
|
if ((flag & FWRITE) == 0)
|
1996-06-14 10:04:54 +00:00
|
|
|
error = EBADF; /* must be opened for writing */
|
1999-04-18 14:42:20 +00:00
|
|
|
else if (((struct fd_formb *)addr)->format_version !=
|
1996-06-14 10:04:54 +00:00
|
|
|
FD_FORMAT_VERSION)
|
|
|
|
error = EINVAL; /* wrong version of formatting prog */
|
|
|
|
else
|
|
|
|
error = fdformat(dev, (struct fd_formb *)addr, p);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_GTYPE: /* get drive type */
|
1998-04-20 13:50:58 +00:00
|
|
|
*(struct fd_type *)addr = *fd->ft;
|
1996-06-14 10:04:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_STYPE: /* set drive type */
|
|
|
|
/* this is considered harmful; only allow for superuser */
|
1999-04-27 11:18:52 +00:00
|
|
|
if (suser(p) != 0)
|
1996-06-14 10:04:54 +00:00
|
|
|
return EPERM;
|
1998-04-20 13:50:58 +00:00
|
|
|
*fd->ft = *(struct fd_type *)addr;
|
1996-06-14 10:04:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_GOPTS: /* get drive options */
|
1998-04-20 13:50:58 +00:00
|
|
|
*(int *)addr = fd->options;
|
1996-06-14 10:04:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_SOPTS: /* set drive options */
|
1998-04-20 13:50:58 +00:00
|
|
|
fd->options = *(int *)addr;
|
1996-06-14 10:04:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hello emacs, these are the
|
|
|
|
* Local Variables:
|
|
|
|
* c-indent-level: 8
|
|
|
|
* c-continued-statement-offset: 8
|
|
|
|
* c-continued-brace-offset: 0
|
|
|
|
* c-brace-offset: -8
|
|
|
|
* c-brace-imaginary-offset: 0
|
|
|
|
* c-argdecl-indent: 8
|
|
|
|
* c-label-offset: -8
|
|
|
|
* c++-hanging-braces: 1
|
|
|
|
* c++-access-specifier-offset: -8
|
|
|
|
* c++-empty-arglist-indent: 8
|
|
|
|
* c++-friend-offset: 0
|
|
|
|
* End:
|
|
|
|
*/
|