Merge the PC98 fdc(4) driver into the MI driver. While here, replace

the magic numbers used with NE7CMD_SPECIFY with invocations of the
NE7_SPEC_x() macros.

Approved by:	nyan
This commit is contained in:
John Baldwin 2014-09-25 20:40:24 +00:00
parent 55a803b32a
commit 83e78a7f6e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=272129
8 changed files with 309 additions and 2910 deletions

View File

@ -98,6 +98,8 @@ dev/ct/ct_isa.c optional ct isa
dev/ed/if_ed_cbus.c optional ed isa
dev/ed/if_ed_wd80x3.c optional ed isa
dev/fb/fb.c optional fb | gdc
dev/fdc/fdc.c optional fdc
dev/fdc/fdc_cbus.c optional fdc isa
dev/fe/if_fe_cbus.c optional fe isa
dev/hwpmc/hwpmc_amd.c optional hwpmc
dev/hwpmc/hwpmc_intel.c optional hwpmc
@ -217,8 +219,6 @@ libkern/udivdi3.c standard
libkern/umoddi3.c standard
pc98/apm/apm_bioscall.S optional apm
pc98/cbus/cbus_dma.c optional isa
pc98/cbus/fdc.c optional fdc
pc98/cbus/fdc_cbus.c optional fdc isa
pc98/cbus/gdc.c optional gdc
pc98/cbus/nmi.c standard
pc98/cbus/olpt.c optional olpt

View File

@ -82,9 +82,13 @@ __FBSDID("$FreeBSD$");
#include <machine/stdarg.h>
#include <isa/isavar.h>
#ifdef PC98
#include <pc98/pc98/pc98_machdep.h>
#else
#include <isa/isareg.h>
#include <dev/fdc/fdcvar.h>
#include <isa/rtc.h>
#endif
#include <dev/fdc/fdcvar.h>
#include <dev/ic/nec765.h>
@ -136,33 +140,56 @@ __FBSDID("$FreeBSD$");
*/
static struct fd_type fd_searchlist_360k[] = {
#ifndef PC98
{ FDF_5_360 },
#endif
{ 0 }
};
static struct fd_type fd_searchlist_12m[] = {
#ifdef PC98
{ FDF_5_1200 | FL_AUTO },
{ FDF_5_720 | FL_AUTO },
{ FDF_5_360 | FL_AUTO },
{ FDF_5_640 | FL_AUTO },
{ FDF_5_1230 | FL_AUTO },
#else
{ FDF_5_1200 | FL_AUTO },
{ FDF_5_360 | FL_2STEP | FL_AUTO},
#endif
{ 0 }
};
static struct fd_type fd_searchlist_720k[] = {
#ifndef PC98
{ FDF_3_720 },
#endif
{ 0 }
};
static struct fd_type fd_searchlist_144m[] = {
#ifdef PC98
{ FDF_3_1440 | FL_AUTO},
{ FDF_3_1200 | FL_AUTO},
{ FDF_3_720 | FL_AUTO},
{ FDF_3_360 | FL_AUTO},
{ FDF_3_640 | FL_AUTO},
{ FDF_3_1230 | FL_AUTO},
#else
{ FDF_3_1440 | FL_AUTO},
{ FDF_3_720 | FL_AUTO},
#endif
{ 0 }
};
static struct fd_type fd_searchlist_288m[] = {
#ifndef PC98
{ FDF_3_1440 | FL_AUTO },
#if 0
{ FDF_3_2880 | FL_AUTO }, /* XXX: probably doesn't work */
#endif
{ FDF_3_720 | FL_AUTO},
#endif
{ 0 }
};
@ -183,6 +210,26 @@ static struct fd_type *fd_native_types[] = {
* Internals start here
*/
#ifdef PC98
/* registers */
#define FDSTS 0 /* NEC 765 Main Status Register (R) */
#define FDDATA 1 /* NEC 765 Data Register (R/W) */
#define FDCTL 2 /* FD Control Register */
#define FDC_RST 0x80 /* FDC RESET */
#define FDC_RDY 0x40 /* force READY */
#define FDC_DD 0x20 /* FDD Mode Exchange 0:1M 1:640K */
#define FDC_DMAE 0x10 /* enable floppy DMA */
#define FDC_MTON 0x08 /* MOTOR ON (when EMTON=1)*/
#define FDC_TMSK 0x04 /* TIMER MASK */
#define FDC_TTRG 0x01 /* TIMER TRIGER */
#define FDP 3
#define FDP_EMTON 0x04 /* enable MTON */
#define FDP_FDDEXC 0x02 /* FDD Mode Exchange 1:1M 0:640K */
#define FDP_PORTEXC 0x01 /* PORT Exchane 1:1M 0:640K */
#define FDEM 4
#else
/* registers */
#define FDOUT 2 /* Digital Output Register (W) */
#define FDO_FDSEL 0x03 /* floppy device select */
@ -197,6 +244,7 @@ static struct fd_type *fd_native_types[] = {
#define FDDSR 4 /* Data Rate Select Register (W) */
#define FDDATA 5 /* NEC 765 Data Register (R/W) */
#define FDCTL 7 /* Control Register (W) */
#endif /* PC98 */
/*
* The YE-DATA PC Card floppies use PIO to read in the data rather
@ -219,9 +267,11 @@ static struct fd_type *fd_native_types[] = {
#define FDBCDR 0 /* And 1 */
#define FD_YE_DATAPORT 6 /* Drive Data port */
#ifndef PC98
#define FDI_DCHG 0x80 /* diskette has been changed */
/* requires drive and motor being selected */
/* is cleared by any step pulse to drive */
#endif
/*
* We have three private BIO commands.
@ -258,6 +308,9 @@ struct fd_data {
struct g_provider *fd_provider;
device_t dev;
struct bio_queue_head fd_bq;
#ifdef PC98
int pc98_trans;
#endif
};
#define FD_NOT_VALID -2
@ -281,11 +334,19 @@ static int retries = 10;
SYSCTL_INT(_debug_fdc, OID_AUTO, retries, CTLFLAG_RW, &retries, 0,
"Number of retries to attempt");
static int spec1 = 0xaf;
#ifdef PC98
static int spec1 = NE7_SPEC_1(4, 240);
#else
static int spec1 = NE7_SPEC_1(6, 240);
#endif
SYSCTL_INT(_debug_fdc, OID_AUTO, spec1, CTLFLAG_RW, &spec1, 0,
"Specification byte one (step-rate + head unload)");
static int spec2 = 0x10;
#ifdef PC98
static int spec2 = NE7_SPEC_2(2, 0);
#else
static int spec2 = NE7_SPEC_2(16, 0);
#endif
SYSCTL_INT(_debug_fdc, OID_AUTO, spec2, CTLFLAG_RW, &spec2, 0,
"Specification byte two (head load time + no-dma)");
@ -335,12 +396,14 @@ fdctl_wr(struct fdc_data *fdc, u_int8_t v)
fdregwr(fdc, FDCTL, v);
}
#ifndef PC98
static void
fdout_wr(struct fdc_data *fdc, u_int8_t v)
{
fdregwr(fdc, FDOUT, v);
}
#endif
static u_int8_t
fdsts_rd(struct fdc_data *fdc)
@ -349,12 +412,14 @@ fdsts_rd(struct fdc_data *fdc)
return fdregrd(fdc, FDSTS);
}
#ifndef PC98
static void
fddsr_wr(struct fdc_data *fdc, u_int8_t v)
{
fdregwr(fdc, FDDSR, v);
}
#endif
static void
fddata_wr(struct fdc_data *fdc, u_int8_t v)
@ -370,12 +435,14 @@ fddata_rd(struct fdc_data *fdc)
return fdregrd(fdc, FDDATA);
}
#ifndef PC98
static u_int8_t
fdin_rd(struct fdc_data *fdc)
{
return fdregrd(fdc, FDCTL);
}
#endif
/*
* Magic pseudo-DMA initialization for YE FDC. Sets count and
@ -502,11 +569,90 @@ fdc_cmd(struct fdc_data *fdc, int n_out, ...)
return (0);
}
#ifdef PC98
static void fd_motor(struct fd_data *fd, int turnon);
static int pc98_trans = 0; /* 0 : HD , 1 : DD , 2 : 1.44 */
static int pc98_trans_prev = -1;
static void
set_density(struct fdc_data *fdc)
{
/* always motor on */
fdregwr(fdc, FDP, (pc98_trans != 1 ? FDP_FDDEXC : 0) | FDP_PORTEXC);
DELAY(100);
fdctl_wr(fdc, FDC_RST | FDC_DMAE);
/* in the case of note W, always inhibit 100ms timer */
}
static int
pc98_fd_check_ready(struct fd_data *fd)
{
struct fdc_data *fdc = fd->fdc;
int retry = 0, status;
int fdu = device_get_unit(fd->dev);
while (retry++ < 30000) {
fd_motor(fd, 1);
fdc_out(fdc, NE7CMD_SENSED); /* Sense Drive Status */
DELAY(100);
fdc_out(fdc, fdu); /* Drive number */
DELAY(100);
if ((fdc_in(fdc, &status) == 0) && (status & NE7_ST3_RD)) {
fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
DELAY(10);
return (0);
}
}
return (-1);
}
static void
pc98_fd_check_type(struct fd_data *fd, int unit)
{
struct fdc_data *fdc;
if (fd->type != FDT_NONE || unit < 0 || unit > 3)
return;
fdc = fd->fdc;
/* Look up what the BIOS thinks we have. */
if (!((PC98_SYSTEM_PARAMETER(0x55c) >> unit) & 0x01)) {
fd->type = FDT_NONE;
return;
}
if ((PC98_SYSTEM_PARAMETER(0x5ae) >> unit) & 0x01) {
/* Check 3mode I/F */
fd->pc98_trans = 0;
fdregwr(fdc, FDEM, (unit << 5) | 0x10);
if (!(fdregrd(fdc, FDEM) & 0x01)) {
fd->type = FDT_144M;
return;
}
device_printf(fd->dev,
"Warning: can't control 3mode I/F, fallback to 2mode.\n");
}
fd->type = FDT_12M;
}
#endif /* PC98 */
static void
fdc_reset(struct fdc_data *fdc)
{
int i, r[10];
#ifdef PC98
set_density(fdc);
if (pc98_machine_type & M_EPSON_PC98)
fdctl_wr(fdc, FDC_RST | FDC_RDY | FDC_DD | FDC_MTON);
else
fdctl_wr(fdc, FDC_RST | FDC_RDY | FDC_DMAE | FDC_MTON);
DELAY(200);
fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
DELAY(10);
#else
if (fdc->fdct == FDC_ENHANCED) {
/* Try a software reset, default precomp, and 500 kb/s */
fddsr_wr(fdc, I8207X_DSR_SR);
@ -519,6 +665,7 @@ fdc_reset(struct fdc_data *fdc)
}
DELAY(100);
fdout_wr(fdc, fdc->fdout);
#endif
/* XXX after a reset, silently believe the FDC will accept commands */
if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, spec1, spec2, 0))
@ -612,6 +759,7 @@ fdc_read_status(struct fdc_data *fdc)
return ret;
}
#ifndef PC98
/*
* Select this drive
*/
@ -649,6 +797,7 @@ fd_turnon(void *arg)
if (once)
wakeup(&fd->fdc->head);
}
#endif
static void
fd_motor(struct fd_data *fd, int turnon)
@ -659,6 +808,11 @@ fd_motor(struct fd_data *fd, int turnon)
/*
mtx_assert(&fdc->fdc_mtx, MA_OWNED);
*/
#ifdef PC98
fdregwr(fdc, FDP, (pc98_trans != 1 ? FDP_FDDEXC : 0) | FDP_PORTEXC);
DELAY(10);
fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
#else
if (turnon) {
fd->flags |= FD_MOTORWAIT;
fdc->fdout |= (FDO_MOEN0 << fd->fdsu);
@ -669,6 +823,7 @@ fd_motor(struct fd_data *fd, int turnon)
fdc->fdout &= ~(FDO_MOEN0 << fd->fdsu);
}
fdout_wr(fdc, fdc->fdout);
#endif
}
static void
@ -836,15 +991,41 @@ fdc_worker(struct fdc_data *fdc)
}
/* Select drive, setup params */
#ifdef PC98
pc98_trans = fd->ft->trans;
if (pc98_trans_prev != pc98_trans) {
int i;
set_density(fdc);
for (i = 0; i < 10; i++) {
outb(0x5f, 0);
outb(0x5f, 0);
}
pc98_trans_prev = pc98_trans;
}
if (pc98_trans != fd->pc98_trans) {
if (fd->type == FDT_144M) {
fdregwr(fdc, FDEM,
(device_get_unit(fd->dev) << 5) | 0x10 |
(pc98_trans >> 1));
outb(0x5f, 0);
outb(0x5f, 0);
}
fd->pc98_trans = pc98_trans;
}
#else
fd_select(fd);
if (fdc->fdct == FDC_ENHANCED)
fddsr_wr(fdc, fd->ft->trans);
else
fdctl_wr(fdc, fd->ft->trans);
#endif
if (bp->bio_cmd & BIO_PROBE) {
if ((!(device_get_flags(fd->dev) & FD_NO_CHLINE) &&
#ifndef PC98
!(fdin_rd(fdc) & FDI_DCHG) &&
#endif
!(fd->flags & FD_EMPTY)) ||
fd_probe_disk(fd, &need_recal) == 0)
return (fdc_biodone(fdc, 0));
@ -857,6 +1038,7 @@ fdc_worker(struct fdc_data *fdc)
if (fd->flags & FD_EMPTY)
return (fdc_biodone(fdc, ENXIO));
#ifndef PC98
/* Check if we lost our media */
if (fdin_rd(fdc) & FDI_DCHG) {
if (debugflags & 0x40)
@ -874,9 +1056,10 @@ fdc_worker(struct fdc_data *fdc)
g_topology_unlock();
return (fdc_biodone(fdc, ENXIO));
}
#endif
/* Check if the floppy is write-protected */
if(bp->bio_cmd & (BIO_FMT | BIO_WRITE)) {
if (bp->bio_cmd & (BIO_FMT | BIO_WRITE)) {
retry_line = __LINE__;
if(fdc_sense_drive(fdc, &st3) != 0)
return (1);
@ -907,6 +1090,9 @@ fdc_worker(struct fdc_data *fdc)
if ((need_recal & (1 << fd->fdsu)) ||
(cylinder == 0 && fd->track != 0) ||
fdc->retry > 2) {
#ifdef PC98
pc98_fd_check_ready(fd);
#endif
retry_line = __LINE__;
if (fdc_cmd(fdc, 2, NE7CMD_RECAL, fd->fdsu, 0))
return (1);
@ -928,6 +1114,9 @@ fdc_worker(struct fdc_data *fdc)
* SEEK to where we want to be
*/
if (cylinder != fd->track) {
#ifdef PC98
pc98_fd_check_ready(fd);
#endif
retry_line = __LINE__;
if (fdc_cmd(fdc, 3, NE7CMD_SEEK, fd->fdsu, descyl, 0))
return (1);
@ -1230,6 +1419,7 @@ fd_probe_disk(struct fd_data *fd, int *recal)
if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
goto done; /* XXX */
*recal |= (1 << fd->fdsu);
#ifndef PC98
if (fdin_rd(fdc) & FDI_DCHG) {
if (debugflags & 0x40)
printf("Empty in probe\n");
@ -1237,6 +1427,9 @@ fd_probe_disk(struct fd_data *fd, int *recal)
fd->flags |= FD_EMPTY;
mtx_unlock(&fdc->fdc_mtx);
} else {
#else
{
#endif
if (fdc_sense_drive(fdc, &st3) != 0)
goto done;
if (debugflags & 0x40)
@ -1372,7 +1565,12 @@ fdautoselect(struct fd_data *fd)
} else {
if (debugflags & 0x40) {
device_printf(fd->dev,
"autoselected %d KB medium\n", fd->ft->size / 2);
"autoselected %d KB medium\n",
#ifdef PC98
(128 << (fd->ft->secsize)) * fd->ft->size / 1024);
#else
fd->ft->size / 2);
#endif
fdprinttype(fd->ft);
}
return (0);
@ -1425,6 +1623,10 @@ fd_access(struct g_provider *pp, int r, int w, int e)
busy = 0;
if (pp->acr == 0 && pp->acw == 0 && pp->ace == 0) {
#ifdef PC98
if (pc98_fd_check_ready(fd) == -1)
return (ENXIO);
#endif
if (fdmisccmd(fd, BIO_PROBE, NULL))
return (ENXIO);
if (fd->flags & FD_EMPTY)
@ -1494,6 +1696,10 @@ fd_ioctl(struct g_provider *pp, u_long cmd, void *data, int fflag, struct thread
fd = pp->geom->softc;
#ifdef PC98
pc98_fd_check_ready(fd);
#endif
switch (cmd) {
case FD_GTYPE: /* get drive type */
*(struct fd_type *)data = *fd->ft;
@ -1661,6 +1867,12 @@ fdc_initial_reset(device_t dev, struct fdc_data *fdc)
{
int ic_type, part_id;
#ifdef PC98
/* See if it can handle a command. */
if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(4, 240),
NE7_SPEC_2(2, 0), 0))
return (ENXIO);
#else
/*
* A status value of 0xff is very unlikely, but not theoretically
* impossible, but it is far more likely to indicate an empty bus.
@ -1686,8 +1898,10 @@ fdc_initial_reset(device_t dev, struct fdc_data *fdc)
return (ENXIO);
/* Then, see if it can handle a command. */
if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, 0xaf, 0x1e, 0))
if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(6, 240),
NE7_SPEC_2(31, 0), 0))
return (ENXIO);
#endif
/*
* Try to identify the chip.
@ -1749,7 +1963,11 @@ fdc_detach(device_t dev)
mtx_unlock(&fdc->fdc_mtx);
/* reset controller, turn motor off */
#ifdef PC98
fdc_reset(fdc);
#else
fdout_wr(fdc, 0);
#endif
if (!(fdc->flags & FDC_NODMA))
isa_dma_release(fdc->dmachan);
@ -1823,7 +2041,11 @@ fdc_attach(device_t dev)
mtx_init(&fdc->fdc_mtx, "fdc lock", NULL, MTX_DEF);
/* reset controller, turn motor off, clear fdout mirror reg */
#ifdef PC98
fdc_reset(fdc);
#else
fdout_wr(fdc, fdc->fdout = 0);
#endif
bioq_init(&fdc->head);
kproc_create(fdc_thread, fdc, &fdc->fdc_thread, 0, 0,
@ -1877,8 +2099,11 @@ fdc_print_child(device_t me, device_t child)
static int
fd_probe(device_t dev)
{
int i, unit;
int unit;
#ifndef PC98
int i;
u_int st0, st3;
#endif
struct fd_data *fd;
struct fdc_data *fdc;
int fdsu;
@ -1905,7 +2130,9 @@ fd_probe(device_t dev)
fd->type = type;
}
#if (defined(__i386__) && !defined(PC98)) || defined(__amd64__)
#ifdef PC98
pc98_fd_check_type(fd, unit);
#elif defined(__i386__) || defined(__amd64__)
if (fd->type == FDT_NONE && (unit == 0 || unit == 1)) {
/* Look up what the BIOS thinks we have. */
if (unit == 0)
@ -1920,6 +2147,7 @@ fd_probe(device_t dev)
if (fd->type == FDT_NONE)
return (ENXIO);
#ifndef PC98
/*
mtx_lock(&fdc->fdc_mtx);
*/
@ -1972,10 +2200,19 @@ fd_probe(device_t dev)
if ((flags & FD_NO_PROBE) == 0 &&
(st0 & NE7_ST0_EC) != 0) /* no track 0 -> no drive present */
return (ENXIO);
#endif /* PC98 */
done:
switch (fd->type) {
#ifdef PC98
case FDT_144M:
device_set_desc(dev, "1.44M FDD");
break;
case FDT_12M:
device_set_desc(dev, "1M/640K FDD");
break;
#else
case FDT_12M:
device_set_desc(dev, "1200-KB 5.25\" drive");
break;
@ -1991,6 +2228,7 @@ fd_probe(device_t dev)
case FDT_720K:
device_set_desc(dev, "720-KB 3.5\" drive");
break;
#endif
default:
return (ENXIO);
}
@ -1998,6 +2236,9 @@ fd_probe(device_t dev)
fd->fdc = fdc;
fd->fdsu = fdsu;
fd->options = 0;
#ifdef PC98
fd->pc98_trans = 0;
#endif
callout_init_mtx(&fd->toffhandle, &fd->fdc->fdc_mtx, 0);
/* initialize densities for subdevices */

View File

@ -33,15 +33,16 @@ __FBSDID("$FreeBSD$");
#include <sys/bio.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/rman.h>
#include <sys/systm.h>
#include <machine/bus.h>
#include <pc98/cbus/cbus.h>
#include <pc98/cbus/fdcreg.h>
#include <pc98/cbus/fdcvar.h>
#include <dev/fdc/fdcvar.h>
#include <isa/isavar.h>
@ -50,62 +51,70 @@ static bus_addr_t fdc_iat[] = {0, 2, 4};
static int
fdc_cbus_alloc_resources(device_t dev, struct fdc_data *fdc)
{
int rid;
struct resource *res;
int i, rid;
fdc->fdc_dev = dev;
fdc->rid_ioport = 0;
fdc->rid_irq = 0;
fdc->rid_drq = 0;
fdc->res_irq = 0;
fdc->res_drq = 0;
fdc->res_ioport = isa_alloc_resourcev(dev, SYS_RES_IOPORT,
&fdc->rid_ioport, fdc_iat,
3, RF_ACTIVE);
if (fdc->res_ioport == 0) {
rid = 0;
res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, fdc_iat, 3,
RF_ACTIVE);
if (res == NULL) {
device_printf(dev, "cannot reserve I/O port range\n");
return ENXIO;
return (ENXIO);
}
isa_load_resourcev(fdc->res_ioport, fdc_iat, 3);
fdc->portt = rman_get_bustag(fdc->res_ioport);
fdc->porth = rman_get_bushandle(fdc->res_ioport);
isa_load_resourcev(res, fdc_iat, 3);
for (i = 0; i < 3; i++) {
fdc->resio[i] = res;
fdc->ridio[i] = rid;
fdc->ioff[i] = i;
fdc->ioh[i] = rman_get_bushandle(res);
}
fdc->iot = rman_get_bustag(res);
rid = 3;
bus_set_resource(dev, SYS_RES_IOPORT, rid, IO_FDPORT, 1);
fdc->res_fdsio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
RF_ACTIVE);
if (fdc->res_fdsio == 0)
return ENXIO;
fdc->sc_fdsiot = rman_get_bustag(fdc->res_fdsio);
fdc->sc_fdsioh = rman_get_bushandle(fdc->res_fdsio);
res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
if (res == NULL) {
device_printf(dev, "cannot reserve I/O port range\n");
return (ENXIO);
}
fdc->resio[3] = res;
fdc->ridio[3] = rid;
fdc->ioff[3] = 0;
fdc->ioh[3] = rman_get_bushandle(res);
/* XXX: Reuses fdc->iot */
rid = 4;
bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x4be, 1);
fdc->res_fdemsio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
RF_ACTIVE);
if (fdc->res_fdemsio == 0)
return ENXIO;
fdc->sc_fdemsiot = rman_get_bustag(fdc->res_fdemsio);
fdc->sc_fdemsioh = rman_get_bushandle(fdc->res_fdemsio);
res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
if (res == NULL) {
device_printf(dev, "cannot reserve I/O port range\n");
return (ENXIO);
}
fdc->resio[4] = res;
fdc->ridio[4] = rid;
fdc->ioff[4] = 0;
fdc->ioh[4] = rman_get_bushandle(res);
/* XXX: Reuses fdc->iot */
fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
RF_ACTIVE);
if (fdc->res_irq == 0) {
RF_ACTIVE);
if (fdc->res_irq == NULL) {
device_printf(dev, "cannot reserve interrupt line\n");
return ENXIO;
return (ENXIO);
}
if ((fdc->flags & FDC_NODMA) == 0) {
fdc->res_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ,
&fdc->rid_drq, RF_ACTIVE);
if (fdc->res_drq == 0) {
&fdc->rid_drq, RF_ACTIVE);
if (fdc->res_drq == NULL) {
device_printf(dev, "cannot reserve DMA request line\n");
return ENXIO;
return (ENXIO);
}
fdc->dmachan = rman_get_start(fdc->res_drq);
}
return 0;
return (0);
}
static int
@ -122,8 +131,8 @@ fdc_cbus_probe(device_t dev)
/* Attempt to allocate our resources for the duration of the probe */
error = fdc_cbus_alloc_resources(dev, fdc);
if (!error)
error = fdc_initial_reset(fdc);
if (error == 0)
error = fdc_initial_reset(dev, fdc);
fdc_release_resources(fdc);
return (error);
@ -136,15 +145,14 @@ fdc_cbus_attach(device_t dev)
int error;
fdc = device_get_softc(dev);
if ((error = fdc_cbus_alloc_resources(dev, fdc)) != 0 ||
(error = fdc_attach(dev)) != 0 ||
(error = fdc_hints_probe(dev)) != 0) {
error = fdc_cbus_alloc_resources(dev, fdc);
if (error == 0)
error = fdc_attach(dev);
if (error == 0)
error = fdc_hints_probe(dev);
if (error)
fdc_release_resources(fdc);
return (error);
}
return (0);
return (error);
}
static device_method_t fdc_methods[] = {

View File

@ -49,7 +49,9 @@ struct fdc_data {
#define FDC_KTHREAD_ALIVE 0x2000 /* worker thread is alive */
struct fd_data *fd; /* The active drive */
int retry;
#ifndef PC98
int fdout; /* mirror of the w/o digital output reg */
#endif
u_int status[7]; /* copy of the registers */
enum fdc_type fdct; /* chip version of FDC */
int fdc_errs; /* number of logged errors */

View File

@ -2,11 +2,10 @@
KMOD= fdc
.PATH: ${.CURDIR}/../../dev/fdc
.if ${MACHINE} == "pc98"
.PATH: ${.CURDIR}/../../pc98/cbus
SRCS= fdc.c fdc_cbus.c
.else
.PATH: ${.CURDIR}/../../dev/fdc
SRCS= fdc.c fdc_isa.c fdc_pccard.c
.if ${MACHINE} == "i386" || ${MACHINE} == "amd64"
SRCS+= opt_acpi.h acpi_if.h fdc_acpi.c

File diff suppressed because it is too large Load Diff

View File

@ -1,88 +0,0 @@
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 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: @(#)fdreg.h 7.1 (Berkeley) 5/9/91
* $FreeBSD$
*/
/*
* AT floppy controller registers and bitfields
*/
/* uses NEC765 controller */
#include <dev/ic/nec765.h>
#ifdef PC98
/* registers */
#define FDSTS 0 /* NEC 765 Main Status Register (R) */
#define FDDATA 1 /* NEC 765 Data Register (R/W) */
#define FDCTL 2 /* FD Control Register */
#define FDC_RST 0x80 /* FDC RESET */
#define FDC_RDY 0x40 /* force READY */
#define FDC_DD 0x20 /* FDD Mode Exchange 0:1M 1:640K */
#define FDC_DMAE 0x10 /* enable floppy DMA */
#define FDC_MTON 0x08 /* MOTOR ON (when EMTON=1)*/
#define FDC_TMSK 0x04 /* TIMER MASK */
#define FDC_TTRG 0x01 /* TIMER TRIGER */
#define FDP_EMTON 0x04 /* enable MTON */
#define FDP_FDDEXC 0x02 /* FDD Mode Exchange 1:1M 0:640K */
#define FDP_PORTEXC 0x01 /* PORT Exchane 1:1M 0:640K */
#else
/* registers */
#define FDOUT 2 /* Digital Output Register (W) */
#define FDO_FDSEL 0x03 /* floppy device select */
#define FDO_FRST 0x04 /* floppy controller reset */
#define FDO_FDMAEN 0x08 /* enable floppy DMA and Interrupt */
#define FDO_MOEN0 0x10 /* motor enable drive 0 */
#define FDO_MOEN1 0x20 /* motor enable drive 1 */
#define FDO_MOEN2 0x40 /* motor enable drive 2 */
#define FDO_MOEN3 0x80 /* motor enable drive 3 */
#define FDSTS 4 /* NEC 765 Main Status Register (R) */
#define FDDATA 5 /* NEC 765 Data Register (R/W) */
#define FDCTL 7 /* Control Register (W) */
#endif /* PC98 */
/*
* The definitions for FDC_500KBPS etc. have been moved out to <sys/fdcio.h>
* since they need to be visible in userland. They cover the lower two bits
* of FDCTL when used for output.
*/
/*
* this is the secret PIO data port (offset from base)
*/
#define FDC_YE_DATAPORT 6
#ifndef PC98
#define FDIN 7 /* Digital Input Register (R) */
#define FDI_DCHG 0x80 /* diskette has been changed */
/* requires drive and motor being selected */
/* is cleared by any step pulse to drive */
#endif

View File

@ -1,167 +0,0 @@
/*-
* Copyright (c) 2004 M. Warner Losh.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD$
*/
/* XXX should audit this file to see if additional copyrights needed */
enum fdc_type
{
FDC_NE765, FDC_ENHANCED, FDC_UNKNOWN = -1
};
enum fdc_states {
DEVIDLE,
FINDWORK,
DOSEEK,
SEEKCOMPLETE ,
IOCOMPLETE,
RECALCOMPLETE,
STARTRECAL,
RESETCTLR,
SEEKWAIT,
RECALWAIT,
MOTORWAIT,
IOTIMEDOUT,
RESETCOMPLETE,
PIOREAD
};
#ifdef FDC_DEBUG
static char const * const fdstates[] = {
"DEVIDLE",
"FINDWORK",
"DOSEEK",
"SEEKCOMPLETE",
"IOCOMPLETE",
"RECALCOMPLETE",
"STARTRECAL",
"RESETCTLR",
"SEEKWAIT",
"RECALWAIT",
"MOTORWAIT",
"IOTIMEDOUT",
"RESETCOMPLETE",
"PIOREAD"
};
#endif
/*
* Per controller structure (softc).
*/
struct fdc_data
{
int fdcu; /* our unit number */
int dmacnt;
int dmachan;
int flags;
#define FDC_STAT_VALID 0x08
#define FDC_HAS_FIFO 0x10
#define FDC_NEEDS_RESET 0x20
#define FDC_NODMA 0x40
#define FDC_ISPNP 0x80
#define FDC_ISPCMCIA 0x100
struct fd_data *fd;
int fdu; /* the active drive */
enum fdc_states state;
int retry;
#ifndef PC98
int fdout; /* mirror of the w/o digital output reg */
#endif
u_int status[7]; /* copy of the registers */
enum fdc_type fdct; /* chip version of FDC */
int fdc_errs; /* number of logged errors */
int dma_overruns; /* number of DMA overruns */
struct bio_queue_head head;
struct bio *bp; /* active buffer */
#ifdef PC98
struct resource *res_ioport, *res_fdsio, *res_fdemsio;
struct resource *res_irq, *res_drq;
int rid_ioport, rid_irq, rid_drq;
#else
struct resource *res_ioport, *res_ctl, *res_irq, *res_drq;
int rid_ioport, rid_ctl, rid_irq, rid_drq;
#endif
int port_off;
bus_space_tag_t portt;
bus_space_handle_t porth;
#ifdef PC98
bus_space_tag_t sc_fdsiot;
bus_space_handle_t sc_fdsioh;
bus_space_tag_t sc_fdemsiot;
bus_space_handle_t sc_fdemsioh;
#else
bus_space_tag_t ctlt;
bus_space_handle_t ctlh;
#endif
void *fdc_intr;
struct device *fdc_dev;
#ifndef PC98
void (*fdctl_wr)(struct fdc_data *fdc, u_int8_t v);
#endif
};
typedef int fdu_t;
typedef int fdcu_t;
typedef int fdsu_t;
typedef struct fd_data *fd_p;
typedef struct fdc_data *fdc_p;
typedef enum fdc_type fdc_t;
/* error returns for fd_cmd() */
#define FD_FAILED -1
#define FD_NOT_VALID -2
#define FDC_ERRMAX 100 /* do not log more */
extern devclass_t fdc_devclass;
enum fdc_device_ivars {
FDC_IVAR_FDUNIT,
FDC_IVAR_FDTYPE,
};
__BUS_ACCESSOR(fdc, fdunit, FDC, FDUNIT, int);
__BUS_ACCESSOR(fdc, fdtype, FDC, FDTYPE, int);
int fdc_alloc_resources(struct fdc_data *);
#ifndef PC98
void fdout_wr(fdc_p, u_int8_t);
#endif
int fd_cmd(struct fdc_data *, int, ...);
void fdc_release_resources(struct fdc_data *);
int fdc_attach(device_t);
int fdc_hints_probe(device_t);
int fdc_detach(device_t dev);
device_t fdc_add_child(device_t, const char *, int);
int fdc_initial_reset(struct fdc_data *);
int fdc_print_child(device_t, device_t);
int fdc_read_ivar(device_t, device_t, int, uintptr_t *);
int fdc_write_ivar(device_t, device_t, int, uintptr_t);
#ifndef PC98
int fdc_isa_alloc_resources(device_t, struct fdc_data *);
#endif