diff options
Diffstat (limited to 'sys/dev/advansys/adv_isa.c')
-rw-r--r-- | sys/dev/advansys/adv_isa.c | 125 |
1 files changed, 68 insertions, 57 deletions
diff --git a/sys/dev/advansys/adv_isa.c b/sys/dev/advansys/adv_isa.c index 790933d..52cc387 100644 --- a/sys/dev/advansys/adv_isa.c +++ b/sys/dev/advansys/adv_isa.c @@ -49,11 +49,15 @@ #include <sys/param.h> #include <sys/systm.h> +#include <sys/kernel.h> #include <machine/bus_pio.h> #include <machine/bus.h> +#include <machine/resource.h> +#include <sys/bus.h> +#include <sys/rman.h> -#include <i386/isa/isa_device.h> +#include <isa/isavar.h> #include <dev/advansys/advansys.h> @@ -91,26 +95,21 @@ static u_int16_t adv_isa_ioports[] = #define MAX_ISA_IOPORT_INDEX (sizeof(adv_isa_ioports)/sizeof(u_int16_t) - 1) -static int advisaprobe(struct isa_device *id); -static int advisaattach(struct isa_device *id); +static int adv_isa_probe(device_t dev); +static int adv_isa_attach(device_t dev); static void adv_set_isapnp_wait_for_key(void); static int adv_get_isa_dma_channel(struct adv_softc *adv); static int adv_set_isa_dma_settings(struct adv_softc *adv); -static void adv_isa_intr(void *unit); - -struct isa_driver advdriver = -{ - advisaprobe, - advisaattach, - "adv" -}; - static int -advisaprobe(struct isa_device *id) +adv_isa_probe(device_t dev) { int port_index; int max_port_index; + u_long iobase, irq; + int rid = 0; + void *ih; + struct resource *iores, *irqres; /* * Default to scanning all possible device locations. @@ -118,19 +117,19 @@ advisaprobe(struct isa_device *id) port_index = 0; max_port_index = MAX_ISA_IOPORT_INDEX; - if (id->id_iobase > 0) { + if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) == 0) { for (;port_index <= max_port_index; port_index++) - if (id->id_iobase <= adv_isa_ioports[port_index]) + if (iobase <= adv_isa_ioports[port_index]) break; if ((port_index > max_port_index) - || (id->id_iobase != adv_isa_ioports[port_index])) { - printf("adv%d: Invalid baseport of 0x%x specified. " + || (iobase != adv_isa_ioports[port_index])) { + printf("adv%d: Invalid baseport of 0x%lx specified. " "Neerest valid baseport is 0x%x. Failing " - "probe.\n", id->id_unit, id->id_iobase, + "probe.\n", device_get_unit(dev), iobase, (port_index <= max_port_index) ? adv_isa_ioports[port_index] : adv_isa_ioports[max_port_index]); - return 0; + return ENXIO; } max_port_index = port_index; } @@ -147,24 +146,27 @@ advisaprobe(struct isa_device *id) if (port_addr == 0) /* Already been attached */ continue; - id->id_iobase = port_addr; - if (haveseen_iobase(id, 1)) /* XXX real portsize? */ + + if (bus_set_resource(dev, SYS_RES_IOPORT, 0, port_addr, 1)) + continue; + + /* XXX what is the real portsize? */ + iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, + RF_ACTIVE); + if (iores == NULL) continue; - if (adv_find_signature(I386_BUS_SPACE_IO, port_addr)) { + if (adv_find_signature(rman_get_bustag(iores), + rman_get_bushandle(iores))) { /* * Got one. Now allocate our softc * and see if we can initialize the card. */ struct adv_softc *adv; - adv = adv_alloc(id->id_unit, I386_BUS_SPACE_IO, - port_addr); + adv = adv_alloc(dev, rman_get_bustag(iores), + rman_get_bushandle(iores)); if (adv == NULL) - return (0); - - adv_unit++; - - id->id_iobase = adv->bsh; + return ENXIO; /* * Stop the chip. @@ -182,7 +184,7 @@ advisaprobe(struct isa_device *id) maxsegsz = ADV_VL_MAX_DMA_COUNT; maxsize = BUS_SPACE_MAXSIZE_32BIT; lowaddr = ADV_VL_MAX_DMA_ADDR; - id->id_drq = -1; + bus_delete_resource(dev, SYS_RES_DRQ, 0); } else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA) && (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) { if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) { @@ -198,7 +200,8 @@ advisaprobe(struct isa_device *id) adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED; adv->isa_dma_channel = adv_get_isa_dma_channel(adv); - id->id_drq = adv->isa_dma_channel; + bus_set_resource(dev, SYS_RES_DRQ, 0, + adv->isa_dma_channel, 1); } else { panic("advisaprobe: Unknown card revision\n"); } @@ -226,7 +229,7 @@ advisaprobe(struct isa_device *id) printf("%s: Could not allocate DMA tag - error %d\n", adv_name(adv), error); adv_free(adv); - return (0); + return ENXIO; } adv->init_level++; @@ -246,7 +249,7 @@ advisaprobe(struct isa_device *id) /*flags*/0, &overrun_dmat) != 0) { adv_free(adv); - return (0); + return ENXIO; } if (bus_dmamem_alloc(overrun_dmat, (void **)&overrun_buf, @@ -254,7 +257,7 @@ advisaprobe(struct isa_device *id) &overrun_dmamap) != 0) { bus_dma_tag_destroy(overrun_dmat); adv_free(adv); - return (0); + return ENXIO; } /* And permanently map it in */ bus_dmamap_load(overrun_dmat, overrun_dmamap, @@ -267,7 +270,7 @@ advisaprobe(struct isa_device *id) if (adv_init(adv) != 0) { adv_free(adv); - return (0); + return ENXIO; } switch (adv->type) { @@ -293,28 +296,35 @@ advisaprobe(struct isa_device *id) } /* Determine our IRQ */ - if (id->id_irq == 0 /* irq ? */) - id->id_irq = 1 << adv_get_chip_irq(adv); + if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL)) + bus_set_resource(dev, SYS_RES_IRQ, 0, + adv_get_chip_irq(adv), 1); else - adv_set_chip_irq(adv, ffs(id->id_irq) - 1); + adv_set_chip_irq(adv, irq); + + irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, + 0, ~0, 1, RF_ACTIVE); + if (irqres == NULL || + bus_setup_intr(dev, irqres, INTR_TYPE_CAM, + adv_intr, adv, &ih)) { + adv_free(adv); + return ENXIO; + } - id->id_intr = adv_isa_intr; - /* Mark as probed */ adv_isa_ioports[port_index] = 0; - return 1; /* XXX what is the real portsize? */ + return 0; } } - return 0; + return ENXIO; } static int -advisaattach(struct isa_device *id) +adv_isa_attach(device_t dev) { - struct adv_softc *adv; + struct adv_softc *adv = device_get_softc(dev); - adv = advsoftcs[id->id_unit]; return (adv_attach(adv)); } @@ -365,17 +375,18 @@ adv_set_isapnp_wait_for_key(void) outb(ADV_ISA_PNP_PORT_WRITE, 0x02); isapnp_wait_set++; } - return; } -/* - * Handle an ISA interrupt. - * XXX should go away as soon as ISA interrupt handlers - * take a (void *) arg. - */ -static void -adv_isa_intr(void *unit) -{ - struct adv_softc *arg = advsoftcs[(int)unit]; - adv_intr((void *)arg); -} +static device_method_t adv_isa_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, adv_isa_probe), + DEVMETHOD(device_attach, adv_isa_attach), + { 0, 0 } +}; + +static driver_t adv_isa_driver = { + "adv", adv_isa_methods, sizeof(struct adv_softc) +}; + +static devclass_t adv_isa_devclass; +DRIVER_MODULE(adv, isa, adv_isa_driver, adv_isa_devclass, 0, 0); |