Пример #1
0
static int
bt_mca_probe (device_t dev)
{
	const char *		desc;
	mca_id_t		id = mca_get_id(dev);
	struct bt_probe_info	info;
	u_int32_t		iobase = 0;
	u_int32_t		iosize = 0;
	u_int8_t		drq = 0;
	u_int8_t		irq = 0;
	u_int8_t		pos;
	int			result;

	desc = mca_match_id(id, bt_mca_devs);
	if (!desc)
		return (ENXIO);
	device_set_desc(dev, desc);

	pos = (mca_pos_read(dev, BT_MCA_IOPORT_POS1) & BT_MCA_IOPORT_MASK1) |
	      (mca_pos_read(dev, BT_MCA_IOPORT_POS2) & BT_MCA_IOPORT_MASK2);
	iobase = BT_MCA_IOPORT(pos);
	iosize = BT_MCA_IOPORT_SIZE;

	pos = mca_pos_read(dev, BT_MCA_DRQ_POS);
	drq = BT_MCA_DRQ(pos);

	pos = mca_pos_read(dev, BT_MCA_IRQ_POS);
	irq = BT_MCA_IRQ(pos);

	bt_mark_probed_iop(iobase);

	mca_add_iospace(dev, iobase, iosize);

	/* And allocate them */
	bt_mca_alloc_resources(dev, BT_MCA_PROBE);
			
	if (bt_port_probe(dev, &info) != 0) {
		printf("bt_mca_probe: Probe failed for "
		       "card at slot %d\n", mca_get_slot(dev) + 1);
		result = ENXIO;
	} else {	       
		mca_add_drq(dev, drq);
		mca_add_irq(dev, irq);
		result = BUS_PROBE_DEFAULT;    
	}	       
	bt_mca_release_resources(dev);

	return (result);
}
Пример #2
0
static int
bt_mca_alloc_resources(device_t dev, int mode)
{
	struct resource *	io = NULL;
	struct resource *	irq = NULL;
	struct resource *	drq = NULL;
	int			rid;

	rid = 0;
	io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
				0, ~0, 1, RF_ACTIVE);
	if (io == NULL) {
		printf("bt_mca_alloc_resources() failed to allocate IOPORT\n");
		return (ENOMEM);
	}

	if (mode == BT_MCA_ATTACH) {

		rid = 0;
		irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
					 0, ~0, 1, RF_ACTIVE);
		if (irq == NULL) {
			printf("bt_mca_alloc_resources() failed to allocate IRQ\n");
			goto bad;
		}
	
		rid = 0;
		drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid,
						 0, ~0, 1, RF_ACTIVE);
		if (drq == NULL) {
			printf("bt_mca_alloc_resources() failed to allocate DRQ\n");
			goto bad;
		}
	}
	
	bt_init_softc(dev, io, irq, drq);

	return (0);
bad:
	bt_mca_release_resources(dev);
	return (ENOMEM);
}
Пример #3
0
static int
bt_mca_attach (device_t dev)
{
	struct bt_softc *	bt = device_get_softc(dev);
	int			error = 0;

	/* Allocate resources */      
	if ((error = bt_mca_alloc_resources(dev, BT_MCA_ATTACH))) {
		device_printf(dev, "Unable to allocate resources in bt_mca_attach()\n");
		return (error);
	}

	isa_dmacascade(rman_get_start(bt->drq));

	/* Allocate a dmatag for our CCB DMA maps */
	if (bus_dma_tag_create( /* parent	*/ NULL,
				/* alignemnt	*/ 1,
				/* boundary	*/ 0,
				/* lowaddr	*/ BUS_SPACE_MAXADDR_24BIT,
				/* highaddr	*/ BUS_SPACE_MAXADDR,
				/* filter	*/ btvlbouncefilter,
				/* filterarg	*/ bt,
				/* maxsize	*/ BUS_SPACE_MAXSIZE_32BIT,
				/* nsegments	*/ ~0,
				/* maxsegsz	*/ BUS_SPACE_MAXSIZE_32BIT,
				/* flags	*/ 0,
				/* lockfunc	*/ NULL,
				/* lockarg	*/ NULL,
				&bt->parent_dmat) != 0) {
		bt_mca_release_resources(dev);
		return (ENOMEM);
	}

	if (bt_init(dev)) {
		bt_mca_release_resources(dev);
		return (ENOMEM);
	}

	/* DMA tag for our sense buffers */
	if (bus_dma_tag_create(	/* parent	*/ bt->parent_dmat,
				/* alignment	*/ 1, 
				/* boundary	*/ 0,
				/* lowaddr	*/ BUS_SPACE_MAXADDR,    
				/* highaddr	*/ BUS_SPACE_MAXADDR,   
				/* filter	*/ NULL,
				/* filterarg	*/ NULL,
				/* maxsize	*/ bt->max_ccbs *
						   sizeof(struct scsi_sense_data),
				/* nsegments	*/ 1,
				/* maxsegsz	*/ BUS_SPACE_MAXSIZE_32BIT,
				/* flags	*/ 0,
				/* lockfunc	*/ NULL,
				/* lockarg	*/ NULL,
				&bt->sense_dmat) != 0) {
		bt_mca_release_resources(dev);
		return (ENOMEM);
	}

	bt->init_level++;     

	/* Allocation of sense buffers */
	if (bus_dmamem_alloc(bt->sense_dmat,
			     (void **)&bt->sense_buffers,       
			     BUS_DMA_NOWAIT, &bt->sense_dmamap) != 0) {
		bt_mca_release_resources(dev);
		return (ENOMEM);
	}

	bt->init_level++;     

	/* And permanently map them */
	bus_dmamap_load(bt->sense_dmat, bt->sense_dmamap,       
			bt->sense_buffers,
			bt->max_ccbs * sizeof(*bt->sense_buffers),
			btmapsensebuffers, bt, /*flags*/0);     

	bt->init_level++;     

	if ((error = bt_attach(dev))) {
		bt_mca_release_resources(dev);
		return (error);
	}

	return (0);
}