/*
 * Attach all the sub-devices we can find
 */
void
aha_isa_attach(device_t parent, device_t self, void *aux)
{
	struct isa_attach_args *ia = aux;
	struct aha_softc *sc = device_private(self);
	bus_space_tag_t iot = ia->ia_iot;
	bus_space_handle_t ioh;
	struct aha_probe_data apd;
	isa_chipset_tag_t ic = ia->ia_ic;
	int error;

	sc->sc_dev = self;

	printf("\n");

	if (bus_space_map(iot, ia->ia_io[0].ir_addr, AHA_ISA_IOSIZE, 0, &ioh)) {
		aprint_error_dev(self, "can't map i/o space\n");
		return;
	}

	sc->sc_iot = iot;
	sc->sc_ioh = ioh;
	sc->sc_dmat = ia->ia_dmat;
	if (!aha_find(iot, ioh, &apd)) {
		aprint_error_dev(self, "aha_find failed\n");
		return;
	}

	if (apd.sc_drq != -1) {
		if ((error = isa_dmacascade(ic, apd.sc_drq)) != 0) {
			aprint_error_dev(self,
			    "unable to cascade DRQ, error = %d\n", error);
			return;
		}
	}

	sc->sc_ih = isa_intr_establish(ic, apd.sc_irq, IST_EDGE, IPL_BIO,
	    aha_intr, sc);
	if (sc->sc_ih == NULL) {
		aprint_error_dev(self, "couldn't establish interrupt\n");
		return;
	}

	aha_attach(sc, &apd);
}
Exemple #2
0
/*
 * Attach all the sub-devices we can find
 */
static int
aha_isa_attach(device_t dev)
{
	struct	aha_softc *aha = device_get_softc(dev);
	int		 error = ENOMEM;

	aha->dev = dev;
	aha->portrid = 0;
	aha->port = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT,
	    &aha->portrid, AHA_NREGS, RF_ACTIVE);
	if (!aha->port) {
		device_printf(dev, "Unable to allocate I/O ports\n");
		goto fail;
	}

	aha->irqrid = 0;
	aha->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &aha->irqrid,
	    RF_ACTIVE);
	if (!aha->irq) {
		device_printf(dev, "Unable to allocate excluse use of irq\n");
		goto fail;
	}

	aha->drqrid = 0;
	aha->drq = bus_alloc_resource_any(dev, SYS_RES_DRQ, &aha->drqrid,
	    RF_ACTIVE);
	if (!aha->drq) {
		device_printf(dev, "Unable to allocate drq\n");
		goto fail;
	}

#if 0				/* is the drq ever unset? */
	if (dev->id_drq != -1)
		isa_dmacascade(dev->id_drq);
#endif
	isa_dmacascade(rman_get_start(aha->drq));

	/* Allocate our parent dmatag */
	if (bus_dma_tag_create(	/* parent	*/ bus_get_dma_tag(dev),
				/* alignemnt	*/ 1,
				/* boundary	*/ 0,
				/* lowaddr	*/ BUS_SPACE_MAXADDR_24BIT,
				/* highaddr	*/ BUS_SPACE_MAXADDR,
				/* filter	*/ NULL,
				/* filterarg	*/ NULL,
				/* maxsize	*/ BUS_SPACE_MAXSIZE_24BIT,
				/* nsegments	*/ ~0,
				/* maxsegsz	*/ BUS_SPACE_MAXSIZE_24BIT,
				/* flags	*/ 0,
				/* lockfunc	*/ NULL,
				/* lockarg	*/ NULL,
				&aha->parent_dmat) != 0) {
		device_printf(dev, "dma tag create failed.\n");
		goto fail;
        }                              

	if (aha_init(aha)) {
		device_printf(dev, "init failed\n");
		goto fail;
        }
	/*
	 * The 1542A and B look the same.  So we guess based on
	 * the firmware revision.  It appears that only rev 0 is on
	 * the A cards.
	 */
	if (aha->boardid <= BOARD_1542 && aha->fw_major == 0) {
		device_printf(dev, "154xA may not work\n");
		aha->ccb_sg_opcode = INITIATOR_SG_CCB;
		aha->ccb_ccb_opcode = INITIATOR_CCB;
	}
	
	error = aha_attach(aha);
	if (error) {
		device_printf(dev, "attach failed\n");
		goto fail;
	}

	error = bus_setup_intr(dev, aha->irq, INTR_TYPE_CAM|INTR_ENTROPY|
	    INTR_MPSAFE, NULL, aha_intr, aha, &aha->ih);
	if (error) {
		device_printf(dev, "Unable to register interrupt handler\n");
		aha_detach(aha);
                goto fail;
	}

	return (0);
fail: ;
	aha_free(aha);
	bus_free_resource(dev, SYS_RES_IOPORT, aha->port);
	bus_free_resource(dev, SYS_RES_IRQ, aha->irq);
	bus_free_resource(dev, SYS_RES_DRQ, aha->drq);
	return (error);
}
Exemple #3
0
/*
 * Attach all the sub-devices we can find
 */
static int
aha_isa_attach(device_t dev)
{
	struct	aha_softc **sc = device_get_softc(dev);
	struct	aha_softc *aha;
	bus_dma_filter_t *filter;
	void		 *filter_arg;
	bus_addr_t	 lowaddr;
	void		 *ih;
	int		 error;

	aha = *sc;
	aha->portrid = 0;
	aha->port = bus_alloc_resource(dev, SYS_RES_IOPORT, &aha->portrid,
	    0, ~0, AHA_NREGS, RF_ACTIVE);
	if (!aha->port) {
		device_printf(dev, "Unable to allocate I/O ports\n");
		return ENOMEM;
	}

	aha->irqrid = 0;
	aha->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &aha->irqrid, 0, ~0, 1,
	    RF_ACTIVE);
	if (!aha->irq) {
		device_printf(dev, "Unable to allocate excluse use of irq\n");
		bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
		return ENOMEM;
	}

	aha->drqrid = 0;
	aha->drq = bus_alloc_resource(dev, SYS_RES_DRQ, &aha->drqrid, 0, ~0, 1,
	    RF_ACTIVE);
	if (!aha->drq) {
		device_printf(dev, "Unable to allocate drq\n");
		bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
		bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
		return ENOMEM;
	}

#if 0				/* is the drq ever unset? */
	if (dev->id_drq != -1)
		isa_dmacascade(dev->id_drq);
#endif
	isa_dmacascade(rman_get_start(aha->drq));

	/* Allocate our parent dmatag */
	filter = NULL;
	filter_arg = NULL;
	lowaddr = BUS_SPACE_MAXADDR_24BIT;

	if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/1, /*boundary*/0,
	    lowaddr, /*highaddr*/BUS_SPACE_MAXADDR,
	    filter, filter_arg,
	    /*maxsize*/BUS_SPACE_MAXSIZE_24BIT,
	    /*nsegments*/BUS_SPACE_UNRESTRICTED,
	    /*maxsegsz*/BUS_SPACE_MAXSIZE_24BIT,
	    /*flags*/0, &aha->parent_dmat) != 0) {
                aha_free(aha);
		bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
		bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
		bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
                return (ENOMEM);
        }                              

        if (aha_init(aha)) {
		device_printf(dev, "init failed\n");
                aha_free(aha);
		bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
		bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
		bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
                return (ENOMEM);
        }

	error = aha_attach(aha);
	if (error) {
		device_printf(dev, "attach failed\n");
                aha_free(aha);
		bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
		bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
		bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
                return (error);
	}

	error = bus_setup_intr(dev, aha->irq, INTR_TYPE_CAM, aha_intr, aha,
	    &ih);
	if (error) {
		device_printf(dev, "Unable to register interrupt handler\n");
                aha_free(aha);
		bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
		bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
		bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
                return (error);
	}

	return (0);
}