diff options
author | nyan <nyan@FreeBSD.org> | 2004-07-15 15:00:02 +0000 |
---|---|---|
committer | nyan <nyan@FreeBSD.org> | 2004-07-15 15:00:02 +0000 |
commit | e190a12d82375584f5eac4ed284c571ef1fbccb0 (patch) | |
tree | 40d0e24f61ea30610f52e9e77d944dd9b1de0f75 /sys/pc98/cbus/fdc_cbus.c | |
parent | 4cb8610989f25db27d267dc958b0997af5576139 (diff) | |
download | FreeBSD-src-e190a12d82375584f5eac4ed284c571ef1fbccb0.zip FreeBSD-src-e190a12d82375584f5eac4ed284c571ef1fbccb0.tar.gz |
Move the fdc_alloc_resources function into the bus front end.
Diffstat (limited to 'sys/pc98/cbus/fdc_cbus.c')
-rw-r--r-- | sys/pc98/cbus/fdc_cbus.c | 85 |
1 files changed, 82 insertions, 3 deletions
diff --git a/sys/pc98/cbus/fdc_cbus.c b/sys/pc98/cbus/fdc_cbus.c index 643b9c9..e0634a0 100644 --- a/sys/pc98/cbus/fdc_cbus.c +++ b/sys/pc98/cbus/fdc_cbus.c @@ -45,6 +45,69 @@ __FBSDID("$FreeBSD$"); #include <isa/isavar.h> #include <pc98/pc98/pc98.h> +static bus_addr_t fdc_iat[] = {0, 2, 4}; + +static int +fdc_cbus_alloc_resources(device_t dev, struct fdc_data *fdc) +{ + int 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) { + device_printf(dev, "cannot reserve I/O port range\n"); + 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); + + 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); + + 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); + + fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq, + RF_ACTIVE); + if (fdc->res_irq == 0) { + device_printf(dev, "cannot reserve interrupt line\n"); + 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) { + device_printf(dev, "cannot reserve DMA request line\n"); + return ENXIO; + } + fdc->dmachan = rman_get_start(fdc->res_drq); + } + + return 0; +} + static int fdc_cbus_probe(device_t dev) { @@ -52,14 +115,13 @@ fdc_cbus_probe(device_t dev) struct fdc_data *fdc; fdc = device_get_softc(dev); - fdc->fdc_dev = dev; /* Check pnp ids */ if (isa_get_vendorid(dev)) return (ENXIO); /* Attempt to allocate our resources for the duration of the probe */ - error = fdc_alloc_resources(fdc); + error = fdc_cbus_alloc_resources(dev, fdc); if (!error) error = fdc_initial_reset(fdc); @@ -67,10 +129,27 @@ fdc_cbus_probe(device_t dev) return (error); } +static int +fdc_cbus_attach(device_t dev) +{ + int error; + struct fdc_data *fdc; + + fdc = device_get_softc(dev); + + if ((error = fdc_cbus_alloc_resources(dev, fdc)) != 0 || + (error = fdc_attach(dev)) != 0) { + fdc_release_resources(fdc); + return (error); + } + + return (0); +} + static device_method_t fdc_methods[] = { /* Device interface */ DEVMETHOD(device_probe, fdc_cbus_probe), - DEVMETHOD(device_attach, fdc_attach), + DEVMETHOD(device_attach, fdc_cbus_attach), DEVMETHOD(device_detach, fdc_detach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD(device_suspend, bus_generic_suspend), |