2004-07-15 16:41:07 +00:00
|
|
|
/*-
|
2005-01-19 07:46:38 +00:00
|
|
|
* Copyright (c) 2004-2005 M. Warner Losh.
|
2004-07-07 22:35:27 +00:00
|
|
|
* 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
|
2005-01-11 06:24:40 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2004-07-07 22:35:27 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
2005-01-11 06:24:40 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2004-07-07 22:35:27 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-01-11 06:24:40 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
2004-07-07 22:35:27 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-08-20 15:14:25 +00:00
|
|
|
#include <sys/lock.h>
|
2004-07-07 22:35:27 +00:00
|
|
|
#include <sys/module.h>
|
2004-08-20 15:14:25 +00:00
|
|
|
#include <sys/mutex.h>
|
2004-07-07 22:35:27 +00:00
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
2004-07-13 02:42:23 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2004-07-07 22:35:27 +00:00
|
|
|
#include <dev/fdc/fdcvar.h>
|
|
|
|
|
|
|
|
#include <isa/isavar.h>
|
|
|
|
#include <isa/isareg.h>
|
|
|
|
|
|
|
|
static int fdc_isa_probe(device_t);
|
|
|
|
|
|
|
|
static struct isa_pnp_id fdc_ids[] = {
|
2005-01-19 07:46:38 +00:00
|
|
|
{0x0007d041, "PC standard floppy controller"}, /* PNP0700 */
|
2004-07-07 22:35:27 +00:00
|
|
|
{0x0107d041, "Standard floppy controller supporting MS Device Bay Spec"}, /* PNP0701 */
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2005-01-19 07:46:38 +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. So, on older hardware, we use 0x3f0-0x3f5 and 0x3f7.
|
|
|
|
* However, some BIOSs omit the control port, while others start at
|
|
|
|
* 0x3f2. Of the latter, sometimes we have two resources, other times
|
|
|
|
* we have one. We have to deal with the following cases:
|
|
|
|
*
|
|
|
|
* 1: 0x3f0-0x3f5 # very rare
|
|
|
|
* 2: 0x3f0 # hints -> 0x3f0-0x3f5,0x3f7
|
|
|
|
* 3: 0x3f0-0x3f5,0x3f7 # Most common
|
|
|
|
* 4: 0x3f2-0x3f5,0x3f7 # Second most common
|
|
|
|
* 5: 0x3f2-0x3f5 # implies 0x3f7 too.
|
|
|
|
* 6: 0x3f2-0x3f3,0x3f4-0x3f5,0x3f7 # becoming common
|
|
|
|
* 7: 0x3f2-0x3f3,0x3f4-0x3f5 # rare
|
|
|
|
* 8: 0x3f0-0x3f1,0x3f2-0x3f3,0x3f4-0x3f5,0x3f7
|
|
|
|
* 9: 0x3f0-0x3f3,0x3f4-0x3f5,0x3f7
|
|
|
|
*
|
|
|
|
* The following code is generic for any value of 0x3fx. It is also
|
|
|
|
* generic for all the above cases, as well as cases where things are
|
|
|
|
* even weirder.
|
|
|
|
*/
|
2004-07-15 16:41:07 +00:00
|
|
|
int
|
2004-07-14 06:59:58 +00:00
|
|
|
fdc_isa_alloc_resources(device_t dev, struct fdc_data *fdc)
|
|
|
|
{
|
2005-01-19 07:46:38 +00:00
|
|
|
struct resource *res;
|
Fix a couple of problems with the probe code when used with pnpbios
resources. When allocating 6 ports for a 4 port range isa code
returns an error. I'm not sure yet why this is the case, but suspect
it is just a non-regularity in how the resource allocation code works
which should be corrected. Use 1 as the ports size in this case.
However, in the hints case, we have to specify the length, so use 6 in
that case. I believe that this is also acpi friendly.
Also, complain when we can't allocate FDOUT register space. Right now we
silently fail when we can't. This failure is referred to above.
When there's no resource for FDCTL, go ahead and allocate one by hand.
Many PNPBIOS tables don't list this resource, and our hints mechanism also
doesn't cover that range. If we can't allocate it, whine, but fake up
something. Before, we were always bogusly faking it and no one noticed
the sham (save the original author who has now fixed his private shame).
2005-03-10 18:09:25 +00:00
|
|
|
int i, j, rid, newrid, nport;
|
|
|
|
u_long port;
|
2004-07-14 06:59:58 +00:00
|
|
|
|
2004-07-14 07:04:17 +00:00
|
|
|
fdc->fdc_dev = dev;
|
2005-01-19 07:46:38 +00:00
|
|
|
rid = 0;
|
|
|
|
for (i = 0; i < FDC_MAXREG; i++)
|
|
|
|
fdc->resio[i] = NULL;
|
|
|
|
|
Fix a couple of problems with the probe code when used with pnpbios
resources. When allocating 6 ports for a 4 port range isa code
returns an error. I'm not sure yet why this is the case, but suspect
it is just a non-regularity in how the resource allocation code works
which should be corrected. Use 1 as the ports size in this case.
However, in the hints case, we have to specify the length, so use 6 in
that case. I believe that this is also acpi friendly.
Also, complain when we can't allocate FDOUT register space. Right now we
silently fail when we can't. This failure is referred to above.
When there's no resource for FDCTL, go ahead and allocate one by hand.
Many PNPBIOS tables don't list this resource, and our hints mechanism also
doesn't cover that range. If we can't allocate it, whine, but fake up
something. Before, we were always bogusly faking it and no one noticed
the sham (save the original author who has now fixed his private shame).
2005-03-10 18:09:25 +00:00
|
|
|
nport = isa_get_logicalid(dev) ? 1 : 6;
|
2005-01-19 07:46:38 +00:00
|
|
|
for (rid = 0; ; rid++) {
|
|
|
|
newrid = rid;
|
2005-01-20 17:27:37 +00:00
|
|
|
res = bus_alloc_resource(dev, SYS_RES_IOPORT, &newrid,
|
2005-03-14 19:09:29 +00:00
|
|
|
0ul, ~0ul, rid == 0 ? nport : 1, RF_ACTIVE);
|
2005-01-19 07:46:38 +00:00
|
|
|
if (res == NULL)
|
|
|
|
break;
|
2005-01-20 17:27:37 +00:00
|
|
|
/*
|
|
|
|
* Mask off the upper bits of the register, and sanity
|
|
|
|
* check resource ranges.
|
|
|
|
*/
|
|
|
|
i = rman_get_start(res) & 0x7;
|
2005-03-15 08:02:47 +00:00
|
|
|
if (i + rman_get_size(res) - 1 > FDC_MAXREG) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, newrid, res);
|
2005-01-20 17:27:37 +00:00
|
|
|
return (ENXIO);
|
2005-03-15 08:02:47 +00:00
|
|
|
}
|
2005-01-19 07:46:38 +00:00
|
|
|
for (j = 0; j < rman_get_size(res); j++) {
|
|
|
|
fdc->resio[i + j] = res;
|
|
|
|
fdc->ridio[i + j] = newrid;
|
|
|
|
fdc->ioff[i + j] = j;
|
|
|
|
fdc->ioh[i + j] = rman_get_bushandle(res);
|
2004-09-14 07:06:49 +00:00
|
|
|
}
|
2004-07-14 06:59:58 +00:00
|
|
|
}
|
Fix a couple of problems with the probe code when used with pnpbios
resources. When allocating 6 ports for a 4 port range isa code
returns an error. I'm not sure yet why this is the case, but suspect
it is just a non-regularity in how the resource allocation code works
which should be corrected. Use 1 as the ports size in this case.
However, in the hints case, we have to specify the length, so use 6 in
that case. I believe that this is also acpi friendly.
Also, complain when we can't allocate FDOUT register space. Right now we
silently fail when we can't. This failure is referred to above.
When there's no resource for FDCTL, go ahead and allocate one by hand.
Many PNPBIOS tables don't list this resource, and our hints mechanism also
doesn't cover that range. If we can't allocate it, whine, but fake up
something. Before, we were always bogusly faking it and no one noticed
the sham (save the original author who has now fixed his private shame).
2005-03-10 18:09:25 +00:00
|
|
|
if (fdc->resio[2] == NULL) {
|
|
|
|
device_printf(dev, "No FDOUT register!\n");
|
2005-01-19 07:46:38 +00:00
|
|
|
return (ENXIO);
|
Fix a couple of problems with the probe code when used with pnpbios
resources. When allocating 6 ports for a 4 port range isa code
returns an error. I'm not sure yet why this is the case, but suspect
it is just a non-regularity in how the resource allocation code works
which should be corrected. Use 1 as the ports size in this case.
However, in the hints case, we have to specify the length, so use 6 in
that case. I believe that this is also acpi friendly.
Also, complain when we can't allocate FDOUT register space. Right now we
silently fail when we can't. This failure is referred to above.
When there's no resource for FDCTL, go ahead and allocate one by hand.
Many PNPBIOS tables don't list this resource, and our hints mechanism also
doesn't cover that range. If we can't allocate it, whine, but fake up
something. Before, we were always bogusly faking it and no one noticed
the sham (save the original author who has now fixed his private shame).
2005-03-10 18:09:25 +00:00
|
|
|
}
|
2005-01-19 07:46:38 +00:00
|
|
|
fdc->iot = rman_get_bustag(fdc->resio[2]);
|
|
|
|
if (fdc->resio[7] == NULL) {
|
Fix a couple of problems with the probe code when used with pnpbios
resources. When allocating 6 ports for a 4 port range isa code
returns an error. I'm not sure yet why this is the case, but suspect
it is just a non-regularity in how the resource allocation code works
which should be corrected. Use 1 as the ports size in this case.
However, in the hints case, we have to specify the length, so use 6 in
that case. I believe that this is also acpi friendly.
Also, complain when we can't allocate FDOUT register space. Right now we
silently fail when we can't. This failure is referred to above.
When there's no resource for FDCTL, go ahead and allocate one by hand.
Many PNPBIOS tables don't list this resource, and our hints mechanism also
doesn't cover that range. If we can't allocate it, whine, but fake up
something. Before, we were always bogusly faking it and no one noticed
the sham (save the original author who has now fixed his private shame).
2005-03-10 18:09:25 +00:00
|
|
|
port = (rman_get_start(fdc->resio[2]) & ~0x7) + 7;
|
|
|
|
newrid = rid;
|
|
|
|
res = bus_alloc_resource(dev, SYS_RES_IOPORT, &newrid, port,
|
|
|
|
port, 1, RF_ACTIVE);
|
|
|
|
if (res == NULL) {
|
|
|
|
device_printf(dev, "Faking up FDCTL\n");
|
|
|
|
fdc->resio[7] = fdc->resio[2];
|
|
|
|
fdc->ridio[7] = fdc->ridio[2];
|
|
|
|
fdc->ioff[7] = fdc->ioff[2] + 5;
|
|
|
|
fdc->ioh[7] = fdc->ioh[2];
|
|
|
|
} else {
|
|
|
|
fdc->resio[7] = res;
|
|
|
|
fdc->ridio[7] = newrid;
|
|
|
|
fdc->ioff[7] = rman_get_start(res) & 7;
|
|
|
|
fdc->ioh[7] = rman_get_bushandle(res);
|
|
|
|
}
|
2004-07-14 06:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
|
2004-09-14 07:06:49 +00:00
|
|
|
RF_ACTIVE | RF_SHAREABLE);
|
2005-01-19 07:46:38 +00:00
|
|
|
if (fdc->res_irq == NULL) {
|
2004-07-14 06:59:58 +00:00
|
|
|
device_printf(dev, "cannot reserve interrupt line\n");
|
2004-09-14 07:06:49 +00:00
|
|
|
return (ENXIO);
|
2004-07-14 06:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((fdc->flags & FDC_NODMA) == 0) {
|
|
|
|
fdc->res_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ,
|
|
|
|
&fdc->rid_drq, RF_ACTIVE | RF_SHAREABLE);
|
2005-01-19 07:46:38 +00:00
|
|
|
if (fdc->res_drq == NULL) {
|
2004-07-14 06:59:58 +00:00
|
|
|
device_printf(dev, "cannot reserve DMA request line\n");
|
2004-09-14 07:06:49 +00:00
|
|
|
/* This is broken and doesn't work for ISA case */
|
2004-07-14 06:59:58 +00:00
|
|
|
fdc->flags |= FDC_NODMA;
|
|
|
|
} else
|
|
|
|
fdc->dmachan = rman_get_start(fdc->res_drq);
|
|
|
|
}
|
|
|
|
|
2004-09-14 07:06:49 +00:00
|
|
|
return (0);
|
2004-07-14 06:59:58 +00:00
|
|
|
}
|
|
|
|
|
2004-07-07 22:35:27 +00:00
|
|
|
static int
|
|
|
|
fdc_isa_probe(device_t dev)
|
|
|
|
{
|
2004-08-20 15:14:25 +00:00
|
|
|
int error;
|
2004-07-07 22:35:27 +00:00
|
|
|
struct fdc_data *fdc;
|
|
|
|
|
|
|
|
fdc = device_get_softc(dev);
|
|
|
|
fdc->fdc_dev = dev;
|
|
|
|
|
|
|
|
/* Check pnp ids */
|
|
|
|
error = ISA_PNP_PROBE(device_get_parent(dev), dev, fdc_ids);
|
|
|
|
if (error == ENXIO)
|
2004-07-14 06:59:58 +00:00
|
|
|
return (ENXIO);
|
2004-07-07 22:35:27 +00:00
|
|
|
|
|
|
|
/* Attempt to allocate our resources for the duration of the probe */
|
2004-07-14 06:59:58 +00:00
|
|
|
error = fdc_isa_alloc_resources(dev, fdc);
|
2004-08-20 15:14:25 +00:00
|
|
|
if (error == 0)
|
|
|
|
error = fdc_initial_reset(dev, fdc);
|
2004-07-07 22:35:27 +00:00
|
|
|
|
|
|
|
fdc_release_resources(fdc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-07-14 06:59:58 +00:00
|
|
|
static int
|
|
|
|
fdc_isa_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct fdc_data *fdc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
fdc = device_get_softc(dev);
|
2005-01-20 17:27:37 +00:00
|
|
|
fdc->fdc_dev = dev;
|
2004-08-31 20:37:10 +00:00
|
|
|
error = fdc_isa_alloc_resources(dev, fdc);
|
2004-08-20 15:14:25 +00:00
|
|
|
if (error == 0)
|
|
|
|
error = fdc_attach(dev);
|
|
|
|
if (error == 0)
|
|
|
|
error = fdc_hints_probe(dev);
|
2004-07-15 16:41:07 +00:00
|
|
|
if (error)
|
|
|
|
fdc_release_resources(fdc);
|
|
|
|
return (error);
|
2004-07-14 06:59:58 +00:00
|
|
|
}
|
|
|
|
|
2004-07-07 22:35:27 +00:00
|
|
|
static device_method_t fdc_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, fdc_isa_probe),
|
2004-07-14 06:59:58 +00:00
|
|
|
DEVMETHOD(device_attach, fdc_isa_attach),
|
2004-07-07 22:35:27 +00:00
|
|
|
DEVMETHOD(device_detach, fdc_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),
|
2004-07-12 20:49:26 +00:00
|
|
|
DEVMETHOD(bus_write_ivar, fdc_write_ivar),
|
2004-07-07 22:35:27 +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);
|