Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Jun 2000 08:49:48 +0200 (CEST)
From:      Thomas Graichen <graichen@innominate.de>
To:        Takefumi SAYO <stake@niagara.shiojiri.ne.jp>
Cc:        tech@ioiscsi.com, scsi@FreeBSD.org
Subject:   Re: Initio INIC-941 PCI SCSI driver for FreeBSD 4.0-RELEASE
Message-ID:  <Pine.LNX.4.21.0006130836410.5729-300000@h2o.bln.innominate.de>
In-Reply-To: <20000611013840D.stake@po.shiojiri.ne.jp>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Sun, 11 Jun 2000, Takefumi SAYO wrote:

> Hello, graichen and IOI Technology Corporation developers.
> 
> I got 'iha-991210.tar.gz' from graichen's web page
> (http://www.innominate.org/~tgr/) and modified to fit
> FreeBSD 4.0-RELEASE.  It seems to work, but complains
> that
> 
> iha0: driver is using old-style compatability shims
> 
this comes from the fact that the driver is not yet "newbusified"
for that you may look into the mailinglists - i think there was
something in them about documenting how to newbusify a driver
in the last weeks - i'll attach the newbusify diff for the
amd and advansys scsi drivers which i once saved from the
liste in order to have a sample for the initio driver
maybe they help you as a startingpoint because i have
absolutely no time for this right now - please keep
me informed if you get anything done in this di-
rection (i also may test the a100 driver - ihb)

> and 
> 
> (cd0:iha0:0:6:0): got CAM status 0xb
> (cd0:iha0:0:6:0): fatal error, failed to attach to device
> (cd0:iha0:0:6:0): lost device
> (cd0:iha0:0:6:0): removing device entry
> 
> if no media presents in the removable device.
> 
> Could you fix this if you have time?  Because I don't know
> anything about SCSI and CAM. :-(
> 
i don't know much more either :-) ... but i think you may ask this
on the scsi list (i'll cc this mail to it too) - maybe someone
there might help ... in general my impression is that the
initio scsi driver for FreeBSD is not coded very well
(i for instance had problems with it and a tape
changer) but maybe the above message is even
ok (havent seen any scsi cdrom messages for
a long time)

maybe some more words about the initio driver: i currently have
absolutely no time to further work on this - so it would be
really fine if anyone might find the time to get this
going ... i may test it - i have both conteollers
here - one a100 and one 9100u ...

also if someone is working on it i may give the password for the
initio entry in the bsd driver database to this person

a lot of thanks in advance

> P.S.
> I thank IOI for making driver source code open. :-)

at least better than nothing :-)

t

-- 
thomas.graichen@innominate.de
                                                        innominate AG
                                                    networking people
fon: +49.30.308806-13 fax: -77 web: http://innominate.de pgp: /pgp/tg

[-- Attachment #2 --]
Index: sys/pci/amd.c
===================================================================
RCS file: /home/ncvs/src/sys/pci/amd.c,v
retrieving revision 1.5
diff -u -r1.5 amd.c
--- sys/pci/amd.c	2000/03/27 20:23:58	1.5
+++ sys/pci/amd.c	2000/03/31 09:57:27
@@ -61,12 +61,12 @@
 #include <vm/vm.h>
 #include <vm/pmap.h>
 
-#include <pci/pcivar.h>
-#include <pci/pcireg.h>
-
 #include <machine/bus_pio.h>
 #include <machine/bus.h>
 #include <machine/clock.h>
+#include <machine/resource.h>
+#include <sys/bus.h>
+#include <sys/rman.h>
 
 #include <cam/cam.h>
 #include <cam/cam_ccb.h>
@@ -77,12 +77,10 @@
 #include <cam/scsi/scsi_all.h>
 #include <cam/scsi/scsi_message.h>
 
+#include <pci/pcivar.h>
+#include <pci/pcireg.h>
 #include <pci/amd.h>
 
-#ifndef COMPAT_OLDPCI
-#error "The amd device requires the old pci compatibility shims"
-#endif
-
 #define PCI_DEVICE_ID_AMD53C974 	0x20201022ul
 #define PCI_BASE_ADDR0	    		0x10
 
@@ -128,8 +126,7 @@
 static u_int8_t * phystovirt(struct amd_srb *pSRB, u_int32_t xferCnt);
 
 void    amd_linkSRB(struct amd_softc *amd);
-static struct amd_softc *
-	amd_init(int unit, pcici_t config_id);
+static int amd_init(device_t);
 static void amd_load_defaults(struct amd_softc *amd);
 static void amd_load_eeprom_or_defaults(struct amd_softc *amd);
 static int amd_EEpromInDO(struct amd_softc *amd);
@@ -139,8 +136,8 @@
 static void amd_Prepare(struct amd_softc *amd, int *regval, u_int8_t EEpromCmd);
 static void amd_ReadEEprom(struct amd_softc *amd);
 
-static const char *amd_probe(pcici_t tag, pcidi_t type);
-static void amd_attach(pcici_t tag, int unit);
+static int amd_probe(device_t);
+static int amd_attach(device_t);
 static void amdcompletematch(struct amd_softc *amd, target_id_t target,
 			     lun_id_t lun, u_int tag, struct srb_queue *queue,
 			     cam_status status);
@@ -158,8 +155,6 @@
 	amd->msgin_index = 0;
 }
 
-static u_long amd_count;
-
 /* CAM SIM entry points */
 #define ccb_srb_ptr spriv_ptr0
 #define ccb_amd_ptr spriv_ptr1
@@ -167,24 +162,6 @@
 static void	amd_poll(struct cam_sim *sim);
 
 /*
- * PCI device module setup
- */
-static struct pci_device amd_device =
-{
-	"amd",
-	amd_probe,
-	amd_attach,
-	&amd_count,
-	NULL
-};
-
-#ifdef COMPAT_PCI_DRIVER
-COMPAT_PCI_DRIVER(amd, amd_device);
-#else
-DATA_SET(pcidevice_set, amd_device);
-#endif
-
-/*
  * State engine function tables indexed by SCSI phase number
  */
 phase_handler_func_t amd_SCSI_phase0[] = {
@@ -2138,9 +2115,9 @@
 	} else {
 		*regval = 0x80;
 	}
-	pci_cfgwrite(amd->config_id, *regval, 0, /*bytes*/1);
+	pci_write_config(amd->dev, *regval, 0, /*bytes*/1);
 	if (mode == DISABLE_CE) {
-		pci_cfgwrite(amd->config_id, *regval, 0, /*bytes*/1);
+		pci_write_config(amd->dev, *regval, 0, /*bytes*/1);
 	}
 	DELAY(160);
 }
@@ -2154,24 +2131,24 @@
 	if (Carry) {
 		bval = 0x40;
 		*regval = 0x80;
-		pci_cfgwrite(amd->config_id, *regval, bval, /*bytes*/1);
+		pci_write_config(amd->dev, *regval, bval, /*bytes*/1);
 	}
 	DELAY(160);
 	bval |= 0x80;
-	pci_cfgwrite(amd->config_id, *regval, bval, /*bytes*/1);
+	pci_write_config(amd->dev, *regval, bval, /*bytes*/1);
 	DELAY(160);
-	pci_cfgwrite(amd->config_id, *regval, 0, /*bytes*/1);
+	pci_write_config(amd->dev, *regval, 0, /*bytes*/1);
 	DELAY(160);
 }
 
 static int
 amd_EEpromInDO(struct amd_softc *amd)
 {
-	pci_cfgwrite(amd->config_id, 0x80, 0x80, /*bytes*/1);
+	pci_write_config(amd->dev, 0x80, 0x80, /*bytes*/1);
 	DELAY(160);
-	pci_cfgwrite(amd->config_id, 0x80, 0x40, /*bytes*/1);
+	pci_write_config(amd->dev, 0x80, 0x40, /*bytes*/1);
 	DELAY(160);
-	if (pci_cfgread(amd->config_id, 0, /*bytes*/1) == 0x22)
+	if (pci_read_config(amd->dev, 0, /*bytes*/1) == 0x22)
 		return (1);
 	return (0);
 }
@@ -2269,22 +2246,21 @@
  * Inputs        : host - pointer to this host adapter's structure/
  **********************************************************************
  */
-static struct amd_softc *
-amd_init(int unit, pcici_t config_id)
+static int
+amd_init(device_t dev)
 {
-	struct amd_softc *amd;
-	u_int  bval;
-	u_int  i;
+	struct amd_softc *amd = device_get_softc(dev);
+	struct resource	*iores;
+	int	i, rid = 0;
+	u_int	bval;
+
+	iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
+				   RF_ACTIVE);
+	if (iores == NULL)
+		return ENXIO;
+	amd->tag = rman_get_bustag(iores);
+	amd->bsh = rman_get_bushandle(iores);
 
-	amd = (struct amd_softc *)malloc(sizeof(struct amd_softc),
-					 M_DEVBUF, M_WAITOK);
-	if (amd == NULL) {
-		printf("DC390%d: cannot allocate ACB !\n", unit);
-		return (amd);
-	}
-	bzero(amd, sizeof(struct amd_softc));
-	amd->tag = I386_BUS_SPACE_IO;
-	amd->bsh = pci_conf_read(config_id, PCI_MAP_REG_START) & 0xFFFE;
 	/* DMA tag for mapping buffers into device visible space. */
 	if (bus_dma_tag_create(/*parent_dmat*/NULL, /*alignment*/1,
 			       /*boundary*/0,
@@ -2295,15 +2271,14 @@
 			       /*maxsegsz*/AMD_MAXTRANSFER_SIZE,
 			       /*flags*/BUS_DMA_ALLOCNOW,
 			       &amd->buffer_dmat) != 0) {
-		free(amd, M_DEVBUF);
-                return (NULL);
+		return ENXIO;
         }
 	TAILQ_INIT(&amd->free_srbs);
 	TAILQ_INIT(&amd->running_srbs);
 	TAILQ_INIT(&amd->waiting_srbs);
 	amd->last_phase = SCSI_BUS_FREE;
-	amd->config_id = config_id;
-	amd->unit = unit;
+	amd->dev = dev;
+	amd->unit = device_get_unit(dev);
 	amd->SRBCount = MAX_SRB_CNT;
 	amd->status = 0;
 	amd_load_eeprom_or_defaults(amd);
@@ -2362,37 +2337,39 @@
 
 	/* Disable SCSI bus reset interrupt */
 	amd_write8(amd, CNTLREG1, DIS_INT_ON_SCSI_RST);
-	return (amd);
+
+	return 0;
 }
 
 /*
  * attach and init a host adapter
  */
-static void
-amd_attach(pcici_t config_id, int unit)
+static int
+amd_attach(device_t dev)
 {
-	struct cam_devq *devq;	/* Device Queue to use for this SIM */
-	u_int8_t   intstat;
-	u_int32_t  wlval;
-	struct amd_softc *amd = NULL;
+	struct cam_devq	*devq;	/* Device Queue to use for this SIM */
+	u_int8_t	intstat;
+	struct amd_softc *amd = device_get_softc(dev);
+	int		unit = device_get_unit(dev);
+	int		rid = 0;
+	void		*ih;
+	struct resource	*irqres;
 
-	wlval = pci_conf_read(config_id, PCI_ID_REG);
+	if (amd_init(dev))
+		return ENXIO;
 
-	if (wlval == PCI_DEVICE_ID_AMD53C974) {
-		if ((amd = amd_init(unit, config_id)) == NULL)
-			return;
-
-		/* Reset Pending INT */
-		intstat = amd_read8(amd, INTSTATREG);
-	}
+	/* Reset Pending INT */
+	intstat = amd_read8(amd, INTSTATREG);
 
 	/* After setting up the adapter, map our interrupt */
-	if (!pci_map_int(config_id, amd_intr, amd, &cam_imask)) {
+	irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
+				    RF_SHAREABLE | RF_ACTIVE);
+	if (irqres == NULL ||
+	    bus_setup_intr(dev, irqres, INTR_TYPE_CAM, amd_intr, amd, &ih)) {
 		if (bootverbose)
 			printf("amd%d: unable to register interrupt handler!\n",
 			       unit);
-		free(amd, M_DEVBUF);
-		return;
+		return ENXIO;
 	}
 
 	/*
@@ -2402,24 +2379,20 @@
 	 * max_sim_transactions
 	 */
 	devq = cam_simq_alloc(MAX_START_JOB);
-	if (devq == NULL) {
-		free(amd, M_DEVBUF);
-		return;
-	}
+	if (devq == NULL)
+		return ENXIO;
 
 	amd->psim = cam_sim_alloc(amd_action, amd_poll, "amd",
 				  amd, amd->unit, 1, MAX_TAGS_CMD_QUEUE,
 				  devq);
 	if (amd->psim == NULL) {
 		cam_simq_free(devq);
-		free(amd, M_DEVBUF);
-		return;
+		return ENXIO;
 	}
 
 	if (xpt_bus_register(amd->psim, 0) != CAM_SUCCESS) {
 		cam_sim_free(amd->psim, /*free_devq*/TRUE);
-		free(amd, M_DEVBUF);
-		return;
+		return ENXIO;
 	}
 
 	if (xpt_create_path(&amd->ppath, /* periph */ NULL,
@@ -2427,17 +2400,33 @@
 			    CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
 		xpt_bus_deregister(cam_sim_path(amd->psim));
 		cam_sim_free(amd->psim, /* free_simq */ TRUE);
-		free(amd, M_DEVBUF);
-		return;
+		return ENXIO;
 	}
+
+	return 0;
 }
 
-static const char *
-amd_probe(pcici_t tag, pcidi_t type)
+static int
+amd_probe(device_t dev)
 {
-	if (type == PCI_DEVICE_ID_AMD53C974) {
-		return ("Tekram DC390(T)/AMD53c974 SCSI Host Adapter");
-	} else {
-		return (NULL);
+	if (pci_get_devid(dev) == PCI_DEVICE_ID_AMD53C974) {
+		device_set_desc(dev,
+			"Tekram DC390(T)/AMD53c974 SCSI Host Adapter");
+		return 0;
 	}
+	return ENXIO;
 }
+
+static device_method_t amd_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		amd_probe),
+	DEVMETHOD(device_attach,	amd_attach),
+	{ 0, 0 }
+};
+
+static driver_t amd_driver = {
+	"amd", amd_methods, sizeof(struct amd_softc)
+};
+
+static devclass_t amd_devclass;
+DRIVER_MODULE(amd, pci, amd_driver, amd_devclass, 0, 0);
Index: sys/pci/amd.h
===================================================================
RCS file: /home/ncvs/src/sys/pci/amd.h,v
retrieving revision 1.1
diff -u -r1.1 amd.h
--- sys/pci/amd.h	1999/05/22 21:50:40	1.1
+++ sys/pci/amd.h	2000/03/31 09:56:49
@@ -192,6 +192,7 @@
  * Per-adapter, software configuration.
  */
 struct amd_softc {
+	device_t		dev;
 	bus_space_tag_t		tag;
 	bus_space_handle_t	bsh;
 	bus_dma_tag_t		buffer_dmat;   /* dmat for buffer I/O */  
@@ -209,7 +210,6 @@
 	struct	   srb_queue waiting_srbs;
 	struct	   srb_queue running_srbs;
 
-	pcici_t	   config_id;
 	struct	   amd_srb *pTmpSRB;
 
 	u_int16_t  SRBCount;

[-- Attachment #3 --]
Index: sys/conf/files
===================================================================
RCS file: /home/ncvs/src/sys/conf/files,v
retrieving revision 1.346
diff -u -r1.346 files
--- sys/conf/files	2000/03/30 05:16:14	1.346
+++ sys/conf/files	2000/04/01 13:18:14
@@ -96,7 +96,6 @@
 ddb/db_watch.c		optional ddb
 ddb/db_write_cmd.c	optional ddb
 dev/advansys/adv_eisa.c	optional adv eisa
-dev/advansys/adv_isa.c	optional adv isa
 dev/advansys/adv_pci.c	optional adv pci
 dev/advansys/advansys.c	optional adv
 dev/advansys/advlib.c	optional adv
Index: sys/conf/files.alpha
===================================================================
RCS file: /home/ncvs/src/sys/conf/files.alpha,v
retrieving revision 1.45
diff -u -r1.45 files.alpha
--- sys/conf/files.alpha	2000/03/29 14:32:30	1.45
+++ sys/conf/files.alpha	2000/04/01 13:18:58
@@ -159,6 +159,7 @@
 alpha/pci/pcibus.c		optional	pci
 alpha/pci/tsunami.c		optional	dec_st6600
 alpha/pci/tsunami_pci.c		optional	dec_st6600
+dev/advansys/adv_isa.c		optional	adv isa
 dev/aic/aic_isa.c		optional	aic isa
 dev/ata/ata-all.c		optional	ata
 dev/ata/ata-disk.c		optional	atadisk
Index: sys/conf/files.i386
===================================================================
RCS file: /home/ncvs/src/sys/conf/files.i386,v
retrieving revision 1.315
diff -u -r1.315 files.i386
--- sys/conf/files.i386	2000/03/30 05:16:15	1.315
+++ sys/conf/files.i386	2000/04/01 13:18:42
@@ -60,6 +60,7 @@
 contrib/dev/oltr/trlldbm.c	optional	oltr
 contrib/dev/oltr/trlldhm.c	optional	oltr
 contrib/dev/oltr/trlldmac.c	optional	oltr
+dev/advansys/adv_isa.c		optional	adv isa
 dev/aic/aic_isa.c		optional	aic isa
 dev/ata/ata-all.c		optional	ata 
 dev/ata/ata-disk.c		optional	atadisk
Index: sys/conf/files.pc98
===================================================================
RCS file: /home/ncvs/src/sys/conf/files.pc98,v
retrieving revision 1.147
diff -u -r1.147 files.pc98
--- sys/conf/files.pc98	2000/03/30 05:16:16	1.147
+++ sys/conf/files.pc98	2000/04/01 13:19:17
@@ -57,6 +57,7 @@
 contrib/dev/oltr/trlldbm.c	optional	oltr
 contrib/dev/oltr/trlldhm.c	optional	oltr
 contrib/dev/oltr/trlldmac.c	optional	oltr
+#dev/advansys/adv_isa.c		optional	adv isa
 dev/aic/aic_cbus.c		optional	aic isa
 dev/ata/ata-all.c		optional	ata 
 dev/ata/ata-dma.c		optional	ata 
Index: sys/dev/advansys/adv_eisa.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/advansys/adv_eisa.c,v
retrieving revision 1.9
diff -u -r1.9 adv_eisa.c
--- sys/dev/advansys/adv_eisa.c	2000/01/29 18:21:21	1.9
+++ sys/dev/advansys/adv_eisa.c	2000/03/31 10:17:54
@@ -78,10 +78,8 @@
 static	bus_dmamap_t	overrun_dmamap;
 static	bus_addr_t	overrun_physbase;
 
-static const char *adveisamatch(eisa_id_t type);
-
 static const char*
-adveisamatch(eisa_id_t type)
+adv_eisa_match(eisa_id_t type)
 {
 	switch (type & ~0xF) {
 	case EISA_DEVICE_ID_ADVANSYS_740:
@@ -97,19 +95,18 @@
 }
 
 static int
-adveisaprobe(device_t dev)
+adv_eisa_probe(device_t dev)
 {
 	const char *desc;
 	u_int32_t iobase;
 	u_int8_t irq;
 
-	desc = adveisamatch(eisa_get_id(dev));
+	desc = adv_eisa_match(eisa_get_id(dev));
 	if (!desc)
 		return (ENXIO);
 	device_set_desc(dev, desc);
 
-	iobase = (eisa_get_slot(dev) * EISA_SLOT_SIZE)
-	    + ADV_EISA_SLOT_OFFSET;
+	iobase = (eisa_get_slot(dev) * EISA_SLOT_SIZE) + ADV_EISA_SLOT_OFFSET;
 
 	eisa_add_iospace(dev, iobase, ADV_EISA_IOSIZE, RESVADDR_NONE);
 	irq = inb(iobase + ADV_EISA_IRQ_BURST_LEN_REG);
@@ -133,13 +130,12 @@
 }
 
 static int
-adveisaattach(device_t dev)
+adv_eisa_attach(device_t dev)
 {
 	struct adv_softc *adv;
 	struct adv_softc *adv_b;
 	struct resource *io;
 	struct resource *irq;
-	int unit = device_get_unit(dev);
 	int rid, error;
 	void *ih;
 
@@ -165,7 +161,7 @@
 
 	switch (eisa_get_id(dev) & ~0xF) {
 	case EISA_DEVICE_ID_ADVANSYS_750:
-		adv_b = adv_alloc(unit, rman_get_bustag(io),
+		adv_b = adv_alloc(dev, rman_get_bustag(io),
 				  rman_get_bushandle(io) + ADV_EISA_OFFSET_CHAN2);
 		if (adv_b == NULL)
 			goto bad;
@@ -197,7 +193,7 @@
 
 		/* FALLTHROUGH */
 	case EISA_DEVICE_ID_ADVANSYS_740:
-		adv = adv_alloc(unit, rman_get_bustag(io),
+		adv = adv_alloc(dev, rman_get_bustag(io),
 				rman_get_bushandle(io) + ADV_EISA_OFFSET_CHAN1);
 		if (adv == NULL) {
 			if (adv_b != NULL)
@@ -330,18 +326,14 @@
 
 static device_method_t adv_eisa_methods[] = {
 	/* Device interface */
-	DEVMETHOD(device_probe,		adveisaprobe),
-	DEVMETHOD(device_attach,	adveisaattach),
-
+	DEVMETHOD(device_probe,		adv_eisa_probe),
+	DEVMETHOD(device_attach,	adv_eisa_attach),
 	{ 0, 0 }
 };
 
 static driver_t adv_eisa_driver = {
-	"adv",
-	adv_eisa_methods,
-	1,			/* unused */
+	"adv", adv_eisa_methods, sizeof(struct adv_softc)
 };
-
-static devclass_t adv_devclass;
 
-DRIVER_MODULE(adv, eisa, adv_eisa_driver, adv_devclass, 0, 0);
+static devclass_t adv_eisa_devclass;
+DRIVER_MODULE(adv, eisa, adv_eisa_driver, adv_eisa_devclass, 0, 0);
Index: sys/dev/advansys/adv_isa.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/advansys/adv_isa.c,v
retrieving revision 1.14
diff -u -r1.14 adv_isa.c
--- sys/dev/advansys/adv_isa.c	2000/01/17 12:49:54	1.14
+++ sys/dev/advansys/adv_isa.c	2000/04/01 13:19:39
@@ -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 @@
 
 #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 @@
 	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;
 	}
@@ -146,25 +145,28 @@
 
 		if (port_addr == 0)
 			/* Already been attached */
+			continue;
+		
+		if (bus_set_resource(dev, SYS_RES_IOPORT, 0, port_addr, 1))
 			continue;
-		id->id_iobase = port_addr;
-		if (haveseen_iobase(id, 1))	/* XXX real portsize? */
+
+		/* 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 @@
 				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 @@
 				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 @@
 				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 @@
 						       /*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 @@
 						     &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 @@
 			
 			if (adv_init(adv) != 0) {
 				adv_free(adv);
-				return (0);
+				return ENXIO;
 			}
 
 			switch (adv->type) {
@@ -293,28 +296,35 @@
 			}
 			
 			/* 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);
 
-			id->id_intr = adv_isa_intr;
-			
+			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;
+			}
+
 			/* 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 @@
 		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);
Index: sys/dev/advansys/adv_pci.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/advansys/adv_pci.c,v
retrieving revision 1.11
diff -u -r1.11 adv_pci.c
--- sys/dev/advansys/adv_pci.c	2000/03/02 00:08:34	1.11
+++ sys/dev/advansys/adv_pci.c	2000/03/31 10:11:08
@@ -66,6 +66,9 @@
 
 #include <machine/bus_pio.h>
 #include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/bus.h>
+#include <sys/rman.h>
 
 #include <pci/pcireg.h>
 #include <pci/pcivar.h>
@@ -84,8 +87,8 @@
 #define ADV_PCI_MAX_DMA_ADDR    (0xFFFFFFFFL)
 #define ADV_PCI_MAX_DMA_COUNT   (0xFFFFFFFFL)
 
-static const char* advpciprobe(pcici_t tag, pcidi_t type);
-static void advpciattach(pcici_t config_id, int unit);
+static int adv_pci_probe(device_t);
+static int adv_pci_attach(device_t);
 
 /* 
  * The overrun buffer shared amongst all PCI adapters.
@@ -95,55 +98,54 @@
 static	bus_dmamap_t	overrun_dmamap;
 static	bus_addr_t	overrun_physbase;
 
-static struct  pci_device adv_pci_driver = {
-	"adv",
-        advpciprobe,
-        advpciattach,
-        &adv_unit,
-	NULL
-};
-
-COMPAT_PCI_DRIVER (adv_pci, adv_pci_driver);
-
-static const char*
-advpciprobe(pcici_t tag, pcidi_t type)
+static int
+adv_pci_probe(device_t dev)
 {
-	int rev;
+	int	rev = pci_get_revid(dev);
 
-	rev = pci_conf_read(tag, PCI_CLASS_REG) & PCI_REVISION_MASK;
-	switch (type) {
+	switch (pci_get_devid(dev)) {
 	case PCI_DEVICE_ID_ADVANSYS_1200A:
-		return ("AdvanSys ASC1200A SCSI controller");
+		device_set_desc(dev, "AdvanSys ASC1200A SCSI controller");
+		return 0;
 	case PCI_DEVICE_ID_ADVANSYS_1200B:
-		return ("AdvanSys ASC1200B SCSI controller");
+		device_set_desc(dev, "AdvanSys ASC1200B SCSI controller");
+		return 0;
 	case PCI_DEVICE_ID_ADVANSYS_3000:
-		if (rev == PCI_DEVICE_REV_ADVANSYS_3150)
-			return ("AdvanSys ASC3150 SCSI controller");
-		else if (rev == PCI_DEVICE_REV_ADVANSYS_3050)
-			return ("AdvanSys ASC3030/50 SCSI controller");
-		else if (rev >= PCI_DEVICE_REV_ADVANSYS_3150)
-			return ("Unknown AdvanSys controller");
+		if (rev == PCI_DEVICE_REV_ADVANSYS_3150) {
+			device_set_desc(dev,
+					"AdvanSys ASC3150 SCSI controller");
+			return 0;
+		} else if (rev == PCI_DEVICE_REV_ADVANSYS_3050) {
+			device_set_desc(dev,
+					"AdvanSys ASC3030/50 SCSI controller");
+			return 0;
+		} else if (rev >= PCI_DEVICE_REV_ADVANSYS_3150) {
+			device_set_desc(dev, "Unknown AdvanSys controller");
+			return 0;
+		}
 		break;
 	default:
 		break;
 	}
-	return (NULL);
+	return ENXIO;
 }
 
-static void
-advpciattach(pcici_t config_id, int unit)
+static int
+adv_pci_attach(device_t dev)
 {
-	u_int16_t	io_port;
 	struct		adv_softc *adv;
 	u_int32_t	id;
 	u_int32_t	command;
 	int		error;
- 
+	int		rid = 0;
+	void		*ih;
+	struct resource	*iores, *irqres;
+
 	/*
 	 * Determine the chip version.
 	 */
-	id = pci_cfgread(config_id, PCI_ID_REG, /*bytes*/4);
-	command = pci_cfgread(config_id, PCIR_COMMAND, /*bytes*/1);
+	id = pci_read_config(dev, PCI_ID_REG, /*bytes*/4);
+	command = pci_read_config(dev, PCIR_COMMAND, /*bytes*/1);
 
 	/*
 	 * These cards do not allow memory mapped accesses, so we must
@@ -153,7 +155,7 @@
 	if ((command & (PCIM_CMD_PORTEN|PCIM_CMD_BUSMASTEREN))
 	 != (PCIM_CMD_PORTEN|PCIM_CMD_BUSMASTEREN)) {
 		command |= PCIM_CMD_PORTEN|PCIM_CMD_BUSMASTEREN;
-		pci_cfgwrite(config_id, PCIR_COMMAND, command, /*bytes*/1);
+		pci_write_config(dev, PCIR_COMMAND, command, /*bytes*/1);
 	}
 
 	/*
@@ -161,19 +163,21 @@
 	 */
 	if (id == PCI_DEVICE_ID_ADVANSYS_1200A
 	 || id == PCI_DEVICE_ID_ADVANSYS_1200B) {
-		pci_cfgwrite(config_id, PCIR_LATTIMER, /*value*/0, /*bytes*/1);
+		pci_write_config(dev, PCIR_LATTIMER, /*value*/0, /*bytes*/1);
 	}
-
 
-	if (pci_map_port(config_id, PCI_BASEADR0, &io_port) == 0)
-		return;
+	iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
+				   RF_ACTIVE);
+	if (iores == NULL)
+		return ENXIO;
 
-	if (adv_find_signature(I386_BUS_SPACE_IO, io_port) == 0)
-		return;
+	if (adv_find_signature(rman_get_bustag(iores),
+			       rman_get_bushandle(iores)) == 0)
+		return ENXIO;
 
-	adv = adv_alloc(unit, I386_BUS_SPACE_IO, io_port);
+	adv = adv_alloc(dev, rman_get_bustag(iores), rman_get_bushandle(iores));
 	if (adv == NULL)
-		return;
+		return ENXIO;
 
 	/* Allocate a dmatag for our transfer DMA maps */
 	/* XXX Should be a child of the PCI bus dma tag */
@@ -192,7 +196,7 @@
 		printf("%s: Could not allocate DMA tag - error %d\n",
 		       adv_name(adv), error);
 		adv_free(adv);
-		return;
+		return ENXIO;
 	}
 
 	adv->init_level++;
@@ -208,7 +212,7 @@
 				       &overrun_dmat) != 0) {
 			bus_dma_tag_destroy(adv->parent_dmat);
 			adv_free(adv);
-			return;
+			return ENXIO;
        		}
 		if (bus_dmamem_alloc(overrun_dmat,
 				     (void **)&overrun_buf,
@@ -217,7 +221,7 @@
 			bus_dma_tag_destroy(overrun_dmat);
 			bus_dma_tag_destroy(adv->parent_dmat);
 			adv_free(adv);
-			return;
+			return ENXIO;
 		}
 		/* And permanently map it in */  
 		bus_dmamap_load(overrun_dmat, overrun_dmamap,
@@ -254,7 +258,7 @@
 
 	if (adv_init(adv) != 0) {
 		adv_free(adv);
-		return;
+		return ENXIO;
 	}
 
 	adv->max_dma_count = ADV_PCI_MAX_DMA_COUNT;
@@ -277,10 +281,28 @@
 		adv->fix_asyn_xfer = ~0;
 	}
 
-	if ((pci_map_int(config_id, adv_intr, (void *)adv, &cam_imask)) == 0) {
+	irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
+				    RF_SHAREABLE | RF_ACTIVE);
+	if (irqres == NULL ||
+	    bus_setup_intr(dev, irqres, INTR_TYPE_CAM, adv_intr, adv, &ih)) {
 		adv_free(adv);
-		return;
+		return ENXIO;
 	}
-	
+
 	adv_attach(adv);
+	return 0;
 }
+
+static device_method_t adv_pci_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		adv_pci_probe),
+	DEVMETHOD(device_attach,	adv_pci_attach),
+	{ 0, 0 }
+};
+
+static driver_t adv_pci_driver = {
+	"adv", adv_pci_methods, sizeof(struct adv_softc)
+};
+
+static devclass_t adv_pci_devclass;
+DRIVER_MODULE(adv, pci, adv_pci_driver, adv_pci_devclass, 0, 0);
Index: sys/dev/advansys/advansys.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/advansys/advansys.c,v
retrieving revision 1.14
diff -u -r1.14 advansys.c
--- sys/dev/advansys/advansys.c	2000/02/01 00:43:58	1.14
+++ sys/dev/advansys/advansys.c	2000/03/31 10:07:25
@@ -56,6 +56,9 @@
 #include <machine/bus_pio.h>
 #include <machine/bus.h>
 #include <machine/clock.h>
+#include <machine/resource.h>
+#include <sys/bus.h> 
+#include <sys/rman.h> 
 
 #include <cam/cam.h>
 #include <cam/cam_ccb.h>
@@ -73,8 +76,6 @@
 
 #include <dev/advansys/advansys.h>
 
-u_long adv_unit;
-
 static void	adv_action(struct cam_sim *sim, union ccb *ccb);
 static void	adv_execute_ccb(void *arg, bus_dma_segment_t *dm_segs,
 				int nsegments, int error);
@@ -92,8 +93,6 @@
 static __inline void adv_clear_state(struct adv_softc *adv, union ccb* ccb);
 static void adv_clear_state_really(struct adv_softc *adv, union ccb* ccb);
 
-struct adv_softc *advsoftcs[NADV];   /* XXX Config should handle this */
-
 static __inline struct adv_ccb_info *
 adv_get_ccb_info(struct adv_softc *adv)
 {
@@ -729,33 +728,17 @@
 }
 
 struct adv_softc *
-adv_alloc(int unit, bus_space_tag_t tag, bus_space_handle_t bsh)
+adv_alloc(device_t dev, bus_space_tag_t tag, bus_space_handle_t bsh)
 {
-	struct	 adv_softc *adv;
-   
-	if (unit >= NADV) {
-		printf("adv: unit number (%d) too high\n", unit);
-		return NULL;
-	}
+	struct adv_softc *adv = device_get_softc(dev);
 
 	/*
 	 * Allocate a storage area for us
 	 */
-	if (advsoftcs[unit]) {
-		printf("adv%d: memory already allocated\n", unit);
-		return NULL;
-	}
-
-	adv = malloc(sizeof(struct adv_softc), M_DEVBUF, M_NOWAIT);
-	if (!adv) {
-		printf("adv%d: cannot malloc!\n", unit);
-		return NULL;
-	}
-	bzero(adv, sizeof(struct adv_softc));
 	LIST_INIT(&adv->pending_ccbs);
 	SLIST_INIT(&adv->free_ccb_infos);
-	advsoftcs[unit] = adv;
-	adv->unit = unit;
+	adv->dev = dev;
+	adv->unit = device_get_unit(dev);
 	adv->tag = tag;
 	adv->bsh = bsh;
 
@@ -791,7 +774,6 @@
 	case 0:
 		break;
 	}
-	free(adv, M_DEVBUF);
 }
 
 int
Index: sys/dev/advansys/advansys.h
===================================================================
RCS file: /home/ncvs/src/sys/dev/advansys/advansys.h,v
retrieving revision 1.2
diff -u -r1.2 advansys.h
--- sys/dev/advansys/advansys.h	1999/08/28 00:41:16	1.2
+++ sys/dev/advansys/advansys.h	2000/03/31 09:37:33
@@ -36,10 +36,9 @@
 #ifndef _ADVANSYS_H_
 #define _ADVANSYS_H_
 
-#include "adv.h"
 #include <dev/advansys/advlib.h>
 
-struct adv_softc *	adv_alloc(int unit, bus_space_tag_t tag,
+struct adv_softc *	adv_alloc(device_t dev, bus_space_tag_t tag,
 				  bus_space_handle_t bsh);
 char *			adv_name(struct adv_softc *adv);
 void			adv_map(void *arg, bus_dma_segment_t *segs,
@@ -53,7 +52,4 @@
 				 u_int scsi_stat, u_int q_no);
 timeout_t		adv_timeout;
 
-extern struct adv_softc *advsoftcs[NADV];   /* XXX Config should handle this */
-
-extern u_long adv_unit;
 #endif /* _ADVANSYS_H_ */
Index: sys/dev/advansys/advlib.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/advansys/advlib.c,v
retrieving revision 1.15
diff -u -r1.15 advlib.c
--- sys/dev/advansys/advlib.c	2000/01/14 03:33:37	1.15
+++ sys/dev/advansys/advlib.c	2000/03/29 12:06:11
@@ -50,6 +50,9 @@
 #include <machine/bus_pio.h>
 #include <machine/bus.h>
 #include <machine/clock.h>
+#include <machine/resource.h>
+#include <sys/bus.h> 
+#include <sys/rman.h> 
 
 #include <cam/cam.h>
 #include <cam/cam_ccb.h>
Index: sys/dev/advansys/advlib.h
===================================================================
RCS file: /home/ncvs/src/sys/dev/advansys/advlib.h,v
retrieving revision 1.8
diff -u -r1.8 advlib.h
--- sys/dev/advansys/advlib.h	2000/01/14 03:33:38	1.8
+++ sys/dev/advansys/advlib.h	2000/03/31 09:59:46
@@ -492,8 +492,8 @@
 	struct adv_transinfo user;
 };
 
-struct adv_softc
-{
+struct adv_softc {
+	device_t		dev;
 	bus_space_tag_t		 tag;
 	bus_space_handle_t	 bsh;
 	struct cam_sim		*sim;
Index: sys/dev/advansys/adwlib.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/advansys/adwlib.c,v
retrieving revision 1.6
diff -u -r1.6 adwlib.c
--- sys/dev/advansys/adwlib.c	2000/03/02 00:08:35	1.6
+++ sys/dev/advansys/adwlib.c	2000/03/31 10:18:34
@@ -54,6 +54,9 @@
 #include <machine/clock.h>
 
 #include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/cam_sim.h>
+#include <cam/cam_xpt_sim.h>
 #include <cam/scsi/scsi_all.h>
 
 #include <dev/advansys/adwlib.h>
Index: sys/i386/isa/isa_compat.h
===================================================================
RCS file: /home/ncvs/src/sys/i386/isa/isa_compat.h,v
retrieving revision 1.34
diff -u -r1.34 isa_compat.h
--- sys/i386/isa/isa_compat.h	2000/03/30 05:16:01	1.34
+++ sys/i386/isa/isa_compat.h	2000/03/31 10:14:09
@@ -27,7 +27,6 @@
  */
 
 #include "vt.h"
-#include "adv.h"
 #include "ar.h"
 #include "cx.h"
 #include "el.h"
@@ -79,7 +78,6 @@
 };
 
 extern struct isa_driver  vtdriver;
-extern struct isa_driver advdriver;
 extern struct isa_driver  ardriver;
 extern struct isa_driver  cxdriver;
 extern struct isa_driver  eldriver;
@@ -226,18 +224,6 @@
 #endif
 #if NTINA > 0
 	{ INTR_TYPE_NET, &tinadriver },
-#endif
-
-/* CAM */
-
-#if NADV > 0
-	{ INTR_TYPE_CAM, &advdriver },
-#endif
-
-#ifdef PC98
-#if NBS > 0
-	{ INTR_TYPE_CAM, &bsdriver },
-#endif
 #endif
 
 /* MISC */
Index: sys/pc98/pc98/isa_compat.h
===================================================================
RCS file: /home/ncvs/src/sys/pc98/pc98/isa_compat.h,v
retrieving revision 1.15
diff -u -r1.15 isa_compat.h
--- sys/pc98/pc98/isa_compat.h	2000/03/30 05:16:06	1.15
+++ sys/pc98/pc98/isa_compat.h	2000/03/31 10:14:27
@@ -27,7 +27,6 @@
  */
 
 #include "vt.h"
-#include "adv.h"
 #include "wdc.h"
 #include "ar.h"
 #include "cx.h"
@@ -85,7 +84,6 @@
 };
 
 extern struct isa_driver  vtdriver;
-extern struct isa_driver advdriver;
 extern struct isa_driver wdcdriver;
 extern struct isa_driver  ardriver;
 extern struct isa_driver  cxdriver;
@@ -247,12 +245,6 @@
 #endif
 
 /* CAM */
-
-#ifndef PC98
-#if NADV > 0
-	{ INTR_TYPE_CAM, &advdriver },
-#endif
-#endif
 
 #ifdef PC98
 #if NBS > 0

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.21.0006130836410.5729-300000>