DragonFly and FBSD 5.1

Matthew Dillon dillon at apollo.backplane.com
Mon Oct 27 08:51:12 PST 2003


:-On [20031027 17:12], Matthew Dillon (dillon at xxxxxxxxxxxxxxxxxxxx) wrote:
:>   I dunno.  I haven't run 5.x in several months.  I'm a little surprised
:>   that 5.x wouldn't be able to access a 4.x UFS filesystem, though... that
:>   can't be correct.
:
:Just for info:
:
:just tried 4.9-RC4 and it fails booting due to resetting the ata bus on
:my ad1 disk.  Used to work perfectly before with my other motherboard
:and 4.8-S and DragonFly.
:
:Now to try the latest 5.1 snapshot again and now with some messing
:around with the boot options.
:
:-- 
:Jeroen Ruigrok van der Werven <asmodai(at)wxs.nl> / asmodai / kita no mono
:PGP fingerprint: 2D92 980E 45FE 2C28 9DB7  9D88 97E6 839B 2EAC 625B
:http://www.tendra.org/   | http://www.in-nomine.org/~asmodai/diary/
:Everything comes to those who wait...

   DragonFly has a slightly older version of the ATA driver, more around
   the 4.8 time frame.

   Soren has made a lot of changes between the version we have and the one
   in 4.9-RC4, but most seem to be just reorganization.  Yet obviously
   something broke.  Perhaps you and Soren can figure out why your disk isn't
   working any more in 4.9-RC4 by comparing 4.8-S and 4.9-RC4.  If you do
   I'd appreciate a head's up.

					-Matt
					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>


diff -u -r ata/CVS/Entries /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/CVS/Entries
--- ata/ata-all.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-all.c	Sat Oct 11 20:33:53 2003
@@ -25,17 +25,16 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/ata-all.c,v 1.50.2.45 2003/03/12 14:47:12 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-all.c,v 1.7 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/ata-all.c,v 1.50.2.47 2003/09/05 18:27:38 dg Exp $
  */
 
 #include "opt_ata.h"
-#include "use_ata.h"
-#include "use_atadisk.h"
-#include "use_atapicd.h"
-#include "use_atapifd.h"
-#include "use_atapist.h"
-#include "use_atapicam.h"
+#include "ata.h"
+#include "atadisk.h"
+#include "atapicd.h"
+#include "atapifd.h"
+#include "atapist.h"
+#include "atapicam.h"
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/ata.h>
@@ -56,20 +55,14 @@
 #ifdef __alpha__
 #include <machine/md_var.h>
 #endif
-#include "ata-all.h"
-#include "ata-disk.h"
-#include "ata-raid.h"
-#include "atapi-all.h"
+#include <dev/ata/ata-all.h>
+#include <dev/ata/ata-disk.h>
+#include <dev/ata/ata-raid.h>
+#include <dev/ata/atapi-all.h>
 
 /* device structures */
 static	d_ioctl_t	ataioctl;
 static struct cdevsw ata_cdevsw = {  
-	/* name */	"ata",
-	/* maj */	159,
-	/* flags */	0,
-	/* port */      NULL,
-	/* autoq */	0,
-
 	/* open */	nullopen,
 	/* close */	nullclose,
 	/* read */	noread,
@@ -78,8 +71,11 @@
 	/* poll */	nopoll,
 	/* mmap */	nommap,
 	/* strategy */	nostrategy,
+	/* name */	"ata",
+	/* maj */	159,
 	/* dump */	nodump,
-	/* psize */	nopsize
+	/* psize */	nopsize,
+	/* flags */	0,
 };
 
 /* prototypes */
@@ -213,15 +209,15 @@
 		ch->devices &= ~ATA_ATAPI_MASTER;
 #if NATADISK > 0
 	if (ch->devices & ATA_ATA_MASTER)
-	    ad_attach(&ch->device[MASTER]);
+	    ad_attach(&ch->device[MASTER], 0);
 	if (ch->devices & ATA_ATA_SLAVE)
-	    ad_attach(&ch->device[SLAVE]);
+	    ad_attach(&ch->device[SLAVE], 0);
 #endif
 #if DEV_ATAPIALL
 	if (ch->devices & ATA_ATAPI_MASTER)
-	    atapi_attach(&ch->device[MASTER]);
+	    atapi_attach(&ch->device[MASTER], 0);
 	if (ch->devices & ATA_ATAPI_SLAVE)
-	    atapi_attach(&ch->device[SLAVE]);
+	    atapi_attach(&ch->device[SLAVE], 0);
 #endif
 #if NATAPICAM > 0
 	atapi_cam_attach_bus(ch);
@@ -275,6 +271,7 @@
     ch->device[MASTER].mode = ATA_PIO;
     ch->device[SLAVE].mode = ATA_PIO;
     ch->devices = 0;
+    ata_dmafreetags(ch);
 
     bus_teardown_intr(dev, ch->r_irq, ch->ih);
     bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
@@ -297,7 +294,7 @@
 }
 
 static int
-ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td)
+ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p)
 {
     struct ata_cmd *iocmd = (struct ata_cmd *)addr;
     struct ata_channel *ch;
@@ -555,9 +552,9 @@
 	if (!(ch = devclass_get_softc(ata_devclass, ctlr)))
 	    continue;
 	if (ch->devices & ATA_ATA_MASTER)
-	    ad_attach(&ch->device[MASTER]);
+	    ad_attach(&ch->device[MASTER], 0);
 	if (ch->devices & ATA_ATA_SLAVE)
-	    ad_attach(&ch->device[SLAVE]);
+	    ad_attach(&ch->device[SLAVE], 0);
     }
     ata_raid_attach();
 #endif
@@ -567,9 +564,9 @@
 	if (!(ch = devclass_get_softc(ata_devclass, ctlr)))
 	    continue;
 	if (ch->devices & ATA_ATAPI_MASTER)
-	    atapi_attach(&ch->device[MASTER]);
+	    atapi_attach(&ch->device[MASTER], 0);
 	if (ch->devices & ATA_ATAPI_SLAVE)
-	    atapi_attach(&ch->device[SLAVE]);
+	    atapi_attach(&ch->device[SLAVE], 0);
 #if NATAPICAM > 0
 	atapi_cam_attach_bus(ch);
 #endif
@@ -657,7 +654,7 @@
 void
 ata_start(struct ata_channel *ch)
 {
-#if NATADISK > 0
+#ifdef NATADISK
     struct ad_request *ad_request; 
 #endif
 #if DEV_ATAPIALL
@@ -899,13 +896,13 @@
 	printf("\n");
 #if NATADISK > 0
     if (newdev & ATA_ATA_MASTER && !ch->device[MASTER].driver)
-	ad_attach(&ch->device[MASTER]);
+	ad_attach(&ch->device[MASTER], 1);
     else if (ch->devices & ATA_ATA_MASTER && ch->device[MASTER].driver) {
 	ata_getparam(&ch->device[MASTER], ATA_C_ATA_IDENTIFY);
 	ad_reinit(&ch->device[MASTER]);
     }
     if (newdev & ATA_ATA_SLAVE && !ch->device[SLAVE].driver)
-	ad_attach(&ch->device[SLAVE]);
+	ad_attach(&ch->device[SLAVE], 1);
     else if (ch->devices & (ATA_ATA_SLAVE) && ch->device[SLAVE].driver) {
 	ata_getparam(&ch->device[SLAVE], ATA_C_ATA_IDENTIFY);
 	ad_reinit(&ch->device[SLAVE]);
@@ -913,13 +910,13 @@
 #endif
 #if DEV_ATAPIALL
     if (newdev & ATA_ATAPI_MASTER && !ch->device[MASTER].driver)
-	atapi_attach(&ch->device[MASTER]);
+	atapi_attach(&ch->device[MASTER], 1);
     else if (ch->devices & (ATA_ATAPI_MASTER) && ch->device[MASTER].driver) {
 	ata_getparam(&ch->device[MASTER], ATA_C_ATAPI_IDENTIFY);
 	atapi_reinit(&ch->device[MASTER]);
     }
     if (newdev & ATA_ATAPI_SLAVE && !ch->device[SLAVE].driver)
-	atapi_attach(&ch->device[SLAVE]);
+	atapi_attach(&ch->device[SLAVE], 1);
     else if (ch->devices & (ATA_ATAPI_SLAVE) && ch->device[SLAVE].driver) {
 	ata_getparam(&ch->device[SLAVE], ATA_C_ATAPI_IDENTIFY);
 	atapi_reinit(&ch->device[SLAVE]);
@@ -1108,7 +1105,7 @@
 	if (atadev->channel->flags & ATA_QUEUED)
 	    ATA_OUTB(atadev->channel->r_altio, ATA_ALTSTAT, ATA_A_4BIT);
 
-	if (tsleep((caddr_t)atadev->channel, 0, "atacmd", 10 * hz)) {
+	if (tsleep((caddr_t)atadev->channel, PRIBIO, "atacmd", 10 * hz)) {
 	    ata_prtdev(atadev, "timeout waiting for interrupt\n");
 	    atadev->channel->active &= ~ATA_WAIT_INTR;
 	    error = -1;
@@ -1354,7 +1351,7 @@
     }
 
     ATA_SLEEPLOCK_CH(atadev->channel, ATA_ACTIVE);
-    ata_dmainit(atadev->channel, atadev->unit, pmode, wmode, umode);
+    ata_dmainit(atadev, pmode, wmode, umode);
     ATA_UNLOCK_CH(atadev->channel);
     ata_start(atadev->channel); /* XXX SOS */
 }
diff -u -r ata/ata-all.h /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-all.h
--- ata/ata-all.h	Sat Jul 19 14:14:18 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-all.h	Sat Oct 11 20:33:53 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/ata-all.h,v 1.26.2.12 2003/01/30 07:19:59 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-all.h,v 1.3 2003/07/19 21:14:18 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/ata-all.h,v 1.26.2.13 2003/09/05 07:29:10 luoqi Exp $
  */
 
 /* ATA register defines */
@@ -159,6 +158,18 @@
     u_int32_t count;
 };  
 
+struct ata_dmastate {
+    bus_dma_tag_t		ddmatag;	/* data DMA tag */
+    bus_dmamap_t		ddmamap;	/* data DMA map */
+    bus_dma_tag_t		cdmatag;	/* control DMA tag */
+    bus_dmamap_t		cdmamap;	/* control DMA map */
+    struct ata_dmaentry		*dmatab;	/* DMA transfer table */
+    bus_addr_t			mdmatab;	/* bus address of dmatab */
+    int				flags;		/* debugging */
+#define	ATA_DS_ACTIVE			0x01	/* debugging */
+#define	ATA_DS_READ			0x02	/* transaction is a read */
+};
+
 /* structure describing an ATA/ATAPI device */
 struct ata_device {
     struct ata_channel		*channel;
@@ -178,6 +189,7 @@
     int				mode;		/* transfermode */
     int				cmd;		/* last cmd executed */
     void			*result;	/* misc data */
+    struct ata_dmastate		dmastate;	/* dma state */
 };
 
 /* structure describing an ATA channel */
@@ -187,6 +199,7 @@
     struct resource		*r_io;		/* io addr resource handle */
     struct resource		*r_altio;	/* altio addr resource handle */
     struct resource		*r_bmio;	/* bmio addr resource handle */
+    bus_dma_tag_t		dmatag;		/* parent dma tag */
     struct resource		*r_irq;		/* interrupt of this channel */
     void			*ih;		/* interrupt handle */
     int (*intr_func)(struct ata_channel *);	/* interrupt function */
@@ -263,12 +276,14 @@
 int ata_umode(struct ata_params *);
 int ata_find_dev(device_t, u_int32_t, u_int32_t);
 
-void *ata_dmaalloc(struct ata_channel *, int);
-void ata_dmainit(struct ata_channel *, int, int, int, int);
-int ata_dmasetup(struct ata_channel *, int, struct ata_dmaentry *, caddr_t, int);
-void ata_dmastart(struct ata_channel *, int, struct ata_dmaentry *, int);
+int ata_dmaalloc(struct ata_device *);
+void ata_dmafree(struct ata_device *);
+void ata_dmafreetags(struct ata_channel *);
+void ata_dmainit(struct ata_device *, int, int, int);
+int ata_dmasetup(struct ata_device *, caddr_t, int32_t);
+int ata_dmastart(struct ata_device *, caddr_t, int32_t, int);
 int ata_dmastatus(struct ata_channel *);
-int ata_dmadone(struct ata_channel *);
+int ata_dmadone(struct ata_device *);
 
 /* macros for locking a channel */
 #define ATA_LOCK_CH(ch, value)\
@@ -276,7 +291,7 @@
 
 #define ATA_SLEEPLOCK_CH(ch, value) {\
 	while ((ch)->active != ATA_IDLE)\
-	    tsleep((caddr_t)&(ch), 0, "atalck", 1);\
+	    tsleep((caddr_t)&(ch), PRIBIO, "atalck", 1);\
 	(ch)->active = value; }
 
 #define ATA_FORCELOCK_CH(ch, value) \
diff -u -r ata/ata-card.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-card.c
--- ata/ata-card.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-card.c	Mon Mar 18 00:37:33 2002
@@ -26,7 +26,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/ata-card.c,v 1.4.2.1 2002/03/18 08:37:33 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-card.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -43,7 +42,7 @@
 #include <machine/resource.h>
 #include <machine/bus.h>
 #include <sys/rman.h>
-#include "ata-all.h"
+#include <dev/ata/ata-all.h>
 
 static int
 ata_pccard_probe(device_t dev)
diff -u -r ata/ata-disk.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-disk.c
--- ata/ata-disk.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-disk.c	Sat Oct 11 20:33:53 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/ata-disk.c,v 1.60.2.24 2003/01/30 07:19:59 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-disk.c,v 1.7 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/ata-disk.c,v 1.60.2.27 2003/09/05 18:27:38 dg Exp $
  */
 
 #include "opt_ata.h"
@@ -49,25 +48,16 @@
 #include <machine/bus.h>
 #include <machine/clock.h>
 #include <sys/rman.h>
-#include "ata-all.h"
-#include "ata-disk.h"
-#include "ata-raid.h"
-#include <sys/proc.h>
-#include <sys/buf2.h>
+#include <dev/ata/ata-all.h>
+#include <dev/ata/ata-disk.h>
+#include <dev/ata/ata-raid.h>
 
 /* device structures */
 static d_open_t		adopen;
 static d_close_t	adclose;
 static d_strategy_t	adstrategy;
 static d_dump_t		addump;
-
 static struct cdevsw ad_cdevsw = {
-	/* name */	"ad",
-	/* maj */	116,
-	/* flags */	D_DISK,
-	/* port */      NULL,
-	/* autoq */	0,
-
 	/* open */	adopen,
 	/* close */	adclose,
 	/* read */	physread,
@@ -76,9 +66,14 @@
 	/* poll */	nopoll,
 	/* mmap */	nommap,
 	/* strategy */	adstrategy,
+	/* name */	"ad",
+	/* maj */	116,
 	/* dump */	addump,
-	/* psize */	nopsize
+	/* psize */	nopsize,
+	/* flags */	D_DISK,
+	/* bmaj */	30
 };
+static struct cdevsw addisk_cdevsw;
 
 /* prototypes */
 static void ad_invalidatequeue(struct ad_softc *, struct ad_request *);
@@ -110,7 +105,7 @@
 	   "ATA disk tagged queuing support");
 
 void
-ad_attach(struct ata_device *atadev)
+ad_attach(struct ata_device *atadev, int alreadylocked)
 {
     struct ad_softc *adp;
     dev_t dev;
@@ -146,7 +141,8 @@
 	atadev->param->lba_size48 > 268435455)
 	adp->total_secs = atadev->param->lba_size48;
     
-    ATA_SLEEPLOCK_CH(atadev->channel, ATA_CONTROL);
+    if (!alreadylocked)
+    	ATA_SLEEPLOCK_CH(atadev->channel, ATA_CONTROL);
     /* use multiple sectors/interrupt if device supports it */
     adp->transfersize = DEV_BSIZE;
     if (ad_version(atadev->param->version_major)) {
@@ -176,11 +172,10 @@
 
     /* use DMA if allowed and if drive/controller supports it */
     if (ata_dma)
-	ata_dmainit(atadev->channel, atadev->unit, ata_pmode(atadev->param), 
+	ata_dmainit(atadev, ata_pmode(atadev->param),
 		    ata_wmode(atadev->param), ata_umode(atadev->param));
     else
-	ata_dmainit(atadev->channel, atadev->unit,
-		    ata_pmode(atadev->param), -1, -1);
+	ata_dmainit(atadev, ata_pmode(atadev->param), -1, -1);
 
     /* use tagged queueing if allowed and supported */
     if (ata_tags && ad_tagsupported(adp)) {
@@ -202,7 +197,7 @@
 		      DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_IDE,
 		      DEVSTAT_PRIORITY_DISK);
 
-    dev = disk_create(adp->lun, &adp->disk, 0, &ad_cdevsw);
+    dev = disk_create(adp->lun, &adp->disk, 0, &ad_cdevsw, &addisk_cdevsw);
     dev->si_drv1 = adp;
     dev->si_iosize_max = 256 * DEV_BSIZE;
     adp->dev = dev;
@@ -249,6 +244,7 @@
 	biodone(request->bp);
 	ad_free(request);
     }
+    ata_dmafree(atadev);
     while ((bp = bufq_first(&adp->queue))) {
 	bufq_remove(&adp->queue, bp); 
 	bp->b_error = ENXIO;
@@ -256,8 +252,8 @@
 	biodone(bp);
     }
     disk_invalidate(&adp->disk);
+    disk_destroy(adp->dev);
     devstat_remove_entry(&adp->stats);
-    disk_destroy(&adp->disk);
     if (flush) {
 	if (ata_command(atadev, ATA_C_FLUSHCACHE, 0, 0, 0, ATA_WAIT_READY))
 	    ata_prtdev(atadev, "flushing cache on detach failed\n");
@@ -272,7 +268,7 @@
 }
 
 static int
-adopen(dev_t dev, int flags, int fmt, struct thread *td)
+adopen(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct ad_softc *adp = dev->si_drv1;
 
@@ -282,7 +278,7 @@
 }
 
 static int
-adclose(dev_t dev, int flags, int fmt, struct thread *td)
+adclose(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct ad_softc *adp = dev->si_drv1;
 
@@ -317,7 +313,7 @@
     struct ad_softc *adp = dev->si_drv1;
     struct ad_request request;
     u_int count, blkno, secsize;
-    vm_offset_t addr = 0;
+    vm_paddr_t addr = 0;
     long blkcnt;
     int dumppages = MAXDUMPPGS;
     int error;
@@ -343,7 +339,7 @@
 	    dumppages = count / blkcnt;
 
 	for (i = 0; i < dumppages; ++i) {
-	    vm_offset_t a = addr + (i * PAGE_SIZE);
+	    vm_paddr_t a = addr + (i * PAGE_SIZE);
 	    if (is_physical_memory(a))
 		va = pmap_kenter_temporary(trunc_page(a), i);
 	    else
@@ -412,7 +408,7 @@
     if (bp->b_flags & B_READ) 
 	request->flags |= ADR_F_READ;
     if (adp->device->mode >= ATA_DMA) {
-	if (!(request->dmatab = ata_dmaalloc(atadev->channel, atadev->unit)))
+	if (ata_dmaalloc(atadev))
 	    adp->device->mode = ATA_PIO;
     }
 
@@ -476,8 +472,7 @@
 	/* does this drive & transfer work with DMA ? */
 	request->flags &= ~ADR_F_DMA_USED;
 	if (adp->device->mode >= ATA_DMA &&
-	    !ata_dmasetup(adp->device->channel, adp->device->unit,
-			  request->dmatab, request->data, request->bytecount)) {
+	    !ata_dmasetup(adp->device, request->data, request->bytecount)) {
 	    request->flags |= ADR_F_DMA_USED;
 	    request->currentsize = request->bytecount;
 
@@ -526,8 +521,8 @@
 	    }
 
 	    /* start transfer, return and wait for interrupt */
-	    ata_dmastart(adp->device->channel, adp->device->unit,
-			 request->dmatab, request->flags & ADR_F_READ);
+	    ata_dmastart(adp->device, request->data, request->bytecount,
+			 request->flags & ADR_F_READ);
 	    return ATA_OP_CONTINUES;
 	}
 
@@ -598,7 +593,7 @@
 
     /* finish DMA transfer */
     if (request->flags & ADR_F_DMA_USED)
-	dma_stat = ata_dmadone(adp->device->channel);
+	dma_stat = ata_dmadone(adp->device);
 
     /* do we have a corrected soft error ? */
     if (adp->device->channel->status & ATA_S_CORR)
@@ -625,8 +620,7 @@
 	    if (request->retries++ < AD_MAX_RETRIES)
 		printf(" retrying\n");
 	    else {
-		ata_dmainit(adp->device->channel, adp->device->unit, 
-			    ata_pmode(adp->device->param), -1, -1);
+		ata_dmainit(adp->device, ata_pmode(adp->device->param), -1, -1);
 		printf(" falling back to PIO mode\n");
 	    }
 	    TAILQ_INSERT_HEAD(&adp->device->channel->ata_queue, request, chain);
@@ -637,8 +631,7 @@
 	if (request->flags & ADR_F_DMA_USED) {
 	    untimeout((timeout_t *)ad_timeout, request,request->timeout_handle);
 	    ad_invalidatequeue(adp, request);
-	    ata_dmainit(adp->device->channel, adp->device->unit,
-			ata_pmode(adp->device->param), -1, -1);
+	    ata_dmainit(adp->device, ata_pmode(adp->device->param), -1, -1);
 	    request->flags |= ADR_F_FORCE_PIO;
 	    printf(" trying PIO mode\n");
 	    TAILQ_INSERT_HEAD(&adp->device->channel->ata_queue, request, chain);
@@ -791,8 +784,8 @@
 	    ad_invalidatequeue(adp, NULL);
 	    return ATA_OP_FINISHED;
 	}
-	ata_dmastart(adp->device->channel, adp->device->unit,
-		     request->dmatab, request->flags & ADR_F_READ);
+	ata_dmastart(adp->device, request->data, request->bytecount,
+		     request->flags & ADR_F_READ);
 	return ATA_OP_CONTINUES;
     }
     return ATA_OP_FINISHED;
@@ -801,13 +794,8 @@
 static void
 ad_free(struct ad_request *request)
 {
-    int s = splbio();
-
-    if (request->dmatab)
-	free(request->dmatab, M_DEVBUF);
     request->softc->tags[request->tag] = NULL;
     free(request, M_AD);
-    splx(s);
 }
 
 static void
@@ -880,11 +868,10 @@
 	       request->tag, request->serv);
 
     if (request->flags & ADR_F_DMA_USED) {
-	ata_dmadone(adp->device->channel);
+	ata_dmadone(adp->device);
 	ad_invalidatequeue(adp, request);
 	if (request->retries == AD_MAX_RETRIES) {
-	    ata_dmainit(adp->device->channel, adp->device->unit,
-			ata_pmode(adp->device->param), -1, -1);
+	    ata_dmainit(adp->device, ata_pmode(adp->device->param), -1, -1);
 	    ata_prtdev(adp->device, "trying fallback to PIO mode\n");
 	    request->retries = 0;
 	}
@@ -915,13 +902,11 @@
     ata_command(atadev, ATA_C_SET_MULTI, 0,
 		adp->transfersize / DEV_BSIZE, 0, ATA_WAIT_READY);
     if (adp->device->mode >= ATA_DMA)
-	ata_dmainit(atadev->channel, atadev->unit,
-		    ata_pmode(adp->device->param),
+	ata_dmainit(atadev, ata_pmode(adp->device->param),
 		    ata_wmode(adp->device->param),
 		    ata_umode(adp->device->param));
     else
-	ata_dmainit(atadev->channel, atadev->unit,
-		    ata_pmode(adp->device->param), -1, -1);
+	ata_dmainit(atadev, ata_pmode(adp->device->param), -1, -1);
 }
 
 void
diff -u -r ata/ata-disk.h /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-disk.h
--- ata/ata-disk.h	Mon Jun 16 21:28:22 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-disk.h	Sat Oct 11 20:33:53 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/ata-disk.h,v 1.22.2.7 2002/03/18 08:37:33 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-disk.h,v 1.2 2003/06/17 04:28:22 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/ata-disk.h,v 1.22.2.9 2003/09/05 18:27:39 dg Exp $
  */
 
 /* structure describing an ATA disk request */
@@ -49,7 +48,6 @@
     struct buf			*bp;		/* associated bio ptr */
     u_int8_t			tag;		/* tag ID of this request */
     int				serv;		/* request had service */
-    struct ata_dmaentry		*dmatab;	/* DMA transfer table */
     TAILQ_ENTRY(ad_request)	chain;		/* list management */
 };
 
@@ -77,7 +75,7 @@
     dev_t			dev;		/* device place holder */
 };
 
-void ad_attach(struct ata_device *);
+void ad_attach(struct ata_device *, int);
 void ad_detach(struct ata_device *, int);
 void ad_reinit(struct ata_device *);
 void ad_start(struct ata_device *);
diff -u -r ata/ata-dma.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-dma.c
--- ata/ata-dma.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-dma.c	Sun Oct 26 10:29:03 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/ata-dma.c,v 1.35.2.31 2003/05/07 16:46:11 jhb Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-dma.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/ata-dma.c,v 1.35.2.34 2003/10/22 14:43:52 jhb Exp $
  */
 
 #include <sys/param.h>
@@ -36,83 +35,189 @@
 #include <sys/malloc.h> 
 #include <sys/bus.h>
 #include <sys/disk.h>
+#include <sys/endian.h>
 #include <sys/devicestat.h>
-#include <vm/vm.h>	     
-#include <vm/pmap.h>
-#include <bus/pci/pcivar.h>
+#include <pci/pcivar.h>
 #include <machine/bus.h>
 #include <sys/rman.h>
-#include "ata-all.h"
+#include <dev/ata/ata-all.h>
 
 /* prototypes */
-static void cyrix_timing(struct ata_channel *, int, int);
-static void promise_timing(struct ata_channel *, int, int);
-static void hpt_timing(struct ata_channel *, int, int);
-static int hpt_cable80(struct ata_channel *);
+static void ata_dmacreate(struct ata_device *, int, int);
+static void ata_dmasetupd_cb(void *, bus_dma_segment_t *, int, int);
+static void ata_dmasetupc_cb(void *, bus_dma_segment_t *, int, int);
+static void cyrix_timing(struct ata_device *, int, int);
+static void promise_timing(struct ata_device *, int, int);
+static void hpt_timing(struct ata_device *, int, int);
+static int hpt_cable80(struct ata_device *);
 
 /* misc defines */
-#ifdef __alpha__
-#undef vtophys
-#define vtophys(va)	alpha_XXX_dmamap((vm_offset_t)va)
-#endif
-#define ATAPI_DEVICE(ch, device) \
-	((device == ATA_MASTER && ch->devices & ATA_ATAPI_MASTER) || \
-	 (device == ATA_SLAVE && ch->devices & ATA_ATAPI_SLAVE))
+#define ATAPI_DEVICE(atadev) \
+	((atadev->unit == ATA_MASTER && \
+	  atadev->channel->devices & ATA_ATAPI_MASTER) || \
+	 (atadev->unit == ATA_SLAVE && \
+	  atadev->channel->devices & ATA_ATAPI_SLAVE))
+
+#define	MAXSEGSZ	PAGE_SIZE
+#define	MAXTABSZ	PAGE_SIZE
+#define	MAXCTLDMASZ	(2 * (MAXTABSZ + MAXPHYS))
+
+struct ata_dc_cb_args {
+    bus_addr_t maddr;
+    int error;
+};
+
+static void
+ata_dmasetupc_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
+{
+    struct ata_dc_cb_args *cba = (struct ata_dc_cb_args *)xsc;
+
+    if (!(cba->error = error))
+	cba->maddr = segs[0].ds_addr;
+}
+
+int
+ata_dmaalloc(struct ata_device *atadev)
+{
+    struct ata_channel *ch;
+    struct ata_dc_cb_args ccba;
+    struct ata_dmastate *ds;
+    int error;
+
+    ch = atadev->channel;
+    ds = &atadev->dmastate;
+    if (!ds->cdmatag) {
+	if ((error = bus_dma_tag_create(ch->dmatag, 1, PAGE_SIZE,
+					BUS_SPACE_MAXADDR_32BIT,
+					BUS_SPACE_MAXADDR, NULL, NULL,
+					MAXTABSZ, 1, MAXTABSZ,
+					BUS_DMA_ALLOCNOW, &ds->cdmatag)))
+	    return error;
+    }
+    if (!ds->ddmatag) {
+	if ((error = bus_dma_tag_create(ch->dmatag, ch->alignment + 1, 0,
+					BUS_SPACE_MAXADDR_32BIT,
+					BUS_SPACE_MAXADDR, NULL, NULL,
+					MAXPHYS, ATA_DMA_ENTRIES, MAXSEGSZ,
+					BUS_DMA_ALLOCNOW, &ds->ddmatag)))
+	    return error;
+    }
+    if (!ds->mdmatab) {
+	if ((error = bus_dmamem_alloc(ds->cdmatag, (void **)&ds->dmatab, 0,
+				      &ds->cdmamap)))
+	    return error;
+
+	if ((error = bus_dmamap_load(ds->cdmatag, ds->cdmamap, ds->dmatab,
+				     MAXTABSZ, ata_dmasetupc_cb, &ccba,
+				     0)) != 0 || ccba.error != 0) {
+	    bus_dmamem_free(ds->cdmatag, ds->dmatab, ds->cdmamap);
+	    return error;
+	}
+	ds->mdmatab = ccba.maddr;
+    }
+    if (!ds->ddmamap) {
+	if ((error = bus_dmamap_create(ds->ddmatag, 0, &ds->ddmamap)) != 0)
+	    return error;
+    }
+    return 0;
+}
+
+void
+ata_dmafree(struct ata_device *atadev)
+{
+    struct ata_dmastate *ds;
+
+    ds = &atadev->dmastate;
+    if (ds->mdmatab) {
+	bus_dmamap_unload(ds->cdmatag, ds->cdmamap);
+	bus_dmamem_free(ds->cdmatag, ds->dmatab, ds->cdmamap);
+	ds->mdmatab = 0;
+	ds->cdmamap = NULL;
+	ds->dmatab = NULL;
+    }
+    if (ds->ddmamap) {
+	bus_dmamap_destroy(ds->ddmatag, ds->ddmamap);
+	ds->ddmamap = NULL;
+    }
+    if (ds->cdmatag) {
+	bus_dma_tag_destroy(ds->cdmatag);
+	ds->cdmatag = NULL;
+    }
+    if (ds->ddmatag) {
+	bus_dma_tag_destroy(ds->ddmatag);
+	ds->ddmatag = NULL;
+    }
+}
+
+void
+ata_dmafreetags(struct ata_channel *ch)
+{
+
+    if (ch->dmatag) {
+	bus_dma_tag_destroy(ch->dmatag);
+	ch->dmatag = NULL;
+    }
+}
 
-void *
-ata_dmaalloc(struct ata_channel *ch, int device)
+static void
+ata_dmacreate(struct ata_device *atadev, int apiomode, int mode)
 {
-    void *dmatab;
 
-    if ((dmatab = malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT))) {
-	if (((uintptr_t)dmatab >> PAGE_SHIFT) ^
-	    (((uintptr_t)dmatab + PAGE_SIZE - 1) >> PAGE_SHIFT)) {
-	    ata_printf(ch, device, "dmatab crosses page boundary, no DMA\n");
-	    free(dmatab, M_DEVBUF);
-	    dmatab = NULL;
+    atadev->mode = mode;
+    if (!atadev->channel->dmatag) {
+	if (bus_dma_tag_create(NULL, 1, 0,
+			       BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
+			       NULL, NULL, MAXCTLDMASZ, ATA_DMA_ENTRIES,
+			       BUS_SPACE_MAXSIZE_32BIT, 0,
+			       &atadev->channel->dmatag)) {
+	    ata_prtdev(atadev, "DMA tag allocation failed, disabling DMA\n");
+	    ata_dmainit(atadev, apiomode, -1, -1);
 	}
     }
-    return dmatab;
 }
 
 void
-ata_dmainit(struct ata_channel *ch, int device,
-	    int apiomode, int wdmamode, int udmamode)
+ata_dmainit(struct ata_device *atadev, int apiomode, int wdmamode, int udmamode)
 {
-    struct ata_device *atadev = &ch->device[ATA_DEV(device)];
-    device_t parent = device_get_parent(ch->dev);
-    int devno = (ch->unit << 1) + ATA_DEV(device);
+    device_t parent = device_get_parent(atadev->channel->dev);
+    int chiptype = atadev->channel->chiptype;
+    int chiprev = pci_get_revid(parent);
+    int channel = atadev->channel->unit;
+    int device = ATA_DEV(atadev->unit);
+    int devno = (channel << 1) + device;
     int error;
 
     /* set our most pessimistic default mode */
     atadev->mode = ATA_PIO;
 
-    if (!ch->r_bmio)
+    if (!atadev->channel->r_bmio)
 	return;
 
     /* if simplex controller, only allow DMA on primary channel */
-    if (ch->unit == 1) {
-	ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT,
-		 ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT) &
+    if (channel == 1) {
+	ATA_OUTB(atadev->channel->r_bmio, ATA_BMSTAT_PORT,
+		 ATA_INB(atadev->channel->r_bmio, ATA_BMSTAT_PORT) &
 		 (ATA_BMSTAT_DMA_MASTER | ATA_BMSTAT_DMA_SLAVE));
-	if (ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT) & ATA_BMSTAT_DMA_SIMPLEX) {
+	if (ATA_INB(atadev->channel->r_bmio, ATA_BMSTAT_PORT) &
+	    ATA_BMSTAT_DMA_SIMPLEX) {
 	    ata_prtdev(atadev, "simplex device, DMA on primary only\n");
 	    return;
 	}
     }
 
     /* DMA engine address alignment is usually 1 word (2 bytes) */
-    ch->alignment = 0x1;
+    atadev->channel->alignment = 0x1;
 
 #if 1
-    if (udmamode > 2 && !ch->device[ATA_DEV(device)].param->hwres_cblid) {
+    if (udmamode > 2 && !atadev->param->hwres_cblid) {
 	ata_prtdev(atadev,"DMA limited to UDMA33, non-ATA66 cable or device\n");
 	udmamode = 2;
     }
 #endif
-    switch (ch->chiptype) {
+    switch (chiptype) {
 
     case 0x24db8086:	/* Intel ICH5 */
+    case 0x24d18086:	/* Intel ICH5 SATA */
     case 0x24cb8086:	/* Intel ICH4 */
     case 0x248a8086:	/* Intel ICH3 mobile */ 
     case 0x248b8086:	/* Intel ICH3 */
@@ -136,7 +241,7 @@
 				     (pci_read_config(parent, 0x48, 4) &
 				     ~mask48) | new48, 4);
 		    pci_write_config(parent, 0x54, word54 | (0x1000<<devno), 2);
-		    atadev->mode = ATA_UDMA5;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		    return;
 		}
 	    }
@@ -166,7 +271,7 @@
 				     (pci_read_config(parent, 0x48, 4) &
 				     ~mask48) | new48, 4);
 		    pci_write_config(parent, 0x54, word54 | (1 << devno), 2);
-		    atadev->mode = ATA_UDMA4;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		    return;
 		}
 	    }
@@ -194,7 +299,7 @@
 		pci_write_config(parent, 0x48, 
 				 (pci_read_config(parent, 0x48, 4) &
 				 ~mask48) | new48, 4);
-		atadev->mode = ATA_UDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
@@ -208,7 +313,7 @@
 	    int32_t mask40, new40, mask44, new44;
 
 	    /* if SITRE not set doit for both channels */
-	    if (!((pci_read_config(parent,0x40,4)>>(ch->unit<<8))&0x4000)) {
+	    if (!((pci_read_config(parent, 0x40, 4) >> (channel<<8)) & 0x4000)){
 		new40 = pci_read_config(parent, 0x40, 4);
 		new44 = pci_read_config(parent, 0x44, 4); 
 		if (!(new40 & 0x00004000)) {
@@ -241,7 +346,7 @@
 		    mask44 = 0x0000000f;
 		    new44 = 0x0000000b;
 		}
-		if (ch->unit) {
+		if (channel) {
 		    mask40 <<= 16;
 		    new40 <<= 16;
 		    mask44 <<= 4;
@@ -253,7 +358,7 @@
 		pci_write_config(parent, 0x44,
 				 (pci_read_config(parent, 0x44, 4) & ~mask44)|
 				 new44, 4);
-		atadev->mode = ATA_WDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -265,11 +370,11 @@
 	    int32_t word40;
 
 	    word40 = pci_read_config(parent, 0x40, 4);
-	    word40 >>= ch->unit * 16;
+	    word40 >>= channel * 16;
 
 	    /* Check for timing config usable for DMA on controller */
 	    if (!((word40 & 0x3300) == 0x2300 &&
-		  ((word40 >> (device == ATA_MASTER ? 0 : 4)) & 1) == 1))
+		  ((word40 >> (device ? 4 : 0)) & 1) == 1))
 		break;
 
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
@@ -278,7 +383,7 @@
 		ata_prtdev(atadev, "%s setting WDMA2 on Intel chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		atadev->mode = ATA_WDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -286,12 +391,14 @@
 
     case 0x522910b9:	/* AcerLabs Aladdin IV/V */
 	/* the older Aladdin doesn't support ATAPI DMA on both master & slave */
-	if (pci_get_revid(parent) < 0xc2 &&
-	    ch->devices & ATA_ATAPI_MASTER && ch->devices & ATA_ATAPI_SLAVE) {
+	if (chiprev < 0xc2 &&
+	    atadev->channel->devices & ATA_ATAPI_MASTER &&
+	    atadev->channel->devices & ATA_ATAPI_SLAVE) {
 	    ata_prtdev(atadev, "two atapi devices on this channel, no DMA\n");
 	    break;
 	}
-	if (udmamode >= 5 && pci_get_revid(parent) >= 0xc4) {
+	pci_write_config(parent, 0x58 + (channel << 2), 0x00310001, 4);
+	if (udmamode >= 5 && chiprev >= 0xc4) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA5, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
@@ -307,11 +414,11 @@
 		pci_write_config(parent, 0x54, word54, 4);
 		pci_write_config(parent, 0x53, 
 				 pci_read_config(parent, 0x53, 1) | 0x03, 1);
-		atadev->mode = ATA_UDMA5;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		return;
 	    }
 	}
-	if (udmamode >= 4 && pci_get_revid(parent) >= 0xc2) {
+	if (udmamode >= 4 && chiprev >= 0xc2) {
 				ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
@@ -327,11 +434,11 @@
 		pci_write_config(parent, 0x54, word54, 4);
 		pci_write_config(parent, 0x53, 
 				 pci_read_config(parent, 0x53, 1) | 0x03, 1);
-		atadev->mode = ATA_UDMA4;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		return;
 	    }
 	}
-	if (udmamode >= 2 && pci_get_revid(parent) >= 0x20) {
+	if (udmamode >= 2 && chiprev >= 0x20) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
@@ -345,8 +452,8 @@
 		pci_write_config(parent, 0x54, word54, 4);
 		pci_write_config(parent, 0x53, 
 				 pci_read_config(parent, 0x53, 1) | 0x03, 1);
-		ch->flags |= ATA_ATAPI_DMA_RO;
-		atadev->mode = ATA_UDMA2;
+		atadev->channel->flags |= ATA_ATAPI_DMA_RO;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
@@ -364,14 +471,39 @@
 	    if (!error) {
 		pci_write_config(parent, 0x53, 
 				 pci_read_config(parent, 0x53, 1) | 0x03, 1);
-		ch->flags |= ATA_ATAPI_DMA_RO;
-		atadev->mode = ATA_WDMA2;
+		atadev->channel->flags |= ATA_ATAPI_DMA_RO;
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
 	pci_write_config(parent, 0x53,
 			 (pci_read_config(parent, 0x53, 1) & ~0x01) | 0x02, 1);
-	/* we could set PIO mode timings, but we assume the BIOS did that */
+	error = ata_command(atadev, ATA_C_SETFEATURES, 0,
+			    ATA_PIO0 + apiomode,
+			    ATA_C_F_SETXFER, ATA_WAIT_READY);
+	if (bootverbose)
+	    ata_prtdev(atadev, "%s setting PIO%d on Acer chip\n",
+		       (error) ? "failed" : "success",
+		       (apiomode >= 0) ? apiomode : 0);
+	if (!error) {
+	    int32_t word54 = pci_read_config(parent, 0x54, 4);
+	    int32_t timing;
+
+	    switch(ATA_PIO0 + apiomode) {
+	    case ATA_PIO0: timing = 0x006d0003;
+	    case ATA_PIO1: timing = 0x00580002;
+	    case ATA_PIO2: timing = 0x00440001;
+	    case ATA_PIO3: timing = 0x00330001;
+	    case ATA_PIO4: timing = 0x00310001;
+	    default:	   timing = 0x006d0003;
+	    }
+	    pci_write_config(parent, 0x58 + (channel << 2), timing, 4);
+	    word54 &= ~(0x000f000f << (devno << 2));
+	    word54 |= (0x00000004 << (devno << 2));
+	    pci_write_config(parent, 0x54, word54, 4);
+	    atadev->mode = ATA_PIO0 + apiomode;
+	    return;
+	}
 	break;
 
     case 0x01bc10de:	/* nVIDIA nForce */
@@ -381,11 +513,11 @@
     case 0x05711106:	/* VIA 82C571, 82C586, 82C596, 82C686, 8231,8233,8235 */
 	{
 	    int via_modes[5][7] = {
-		{ 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00 },	/* ATA33 */
-		{ 0x00, 0x00, 0xea, 0x00, 0xe8, 0x00, 0x00 },	/* ATA66 */
-		{ 0x00, 0x00, 0xf4, 0x00, 0xf1, 0xf0, 0x00 },	/* ATA100 */
-		{ 0x00, 0x00, 0xf6, 0x00, 0xf2, 0xf1, 0xf0 },   /* VIA ATA133 */
-		{ 0x00, 0x00, 0xc0, 0x00, 0xc5, 0xc6, 0x00 }};  /* AMD/nVIDIA */
+		{ 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00 },	/* VIA ATA33 */
+		{ 0x00, 0x00, 0xea, 0x00, 0xe8, 0x00, 0x00 },	/* VIA ATA66 */
+		{ 0x00, 0x00, 0xf4, 0x00, 0xf1, 0xf0, 0x00 },	/* VIA ATA100 */
+		{ 0x00, 0x00, 0xf6, 0x00, 0xf2, 0xf1, 0xf0 },	/* VIA ATA133 */
+		{ 0x00, 0x00, 0xc0, 0x00, 0xc5, 0xc6, 0x00 }};	/* AMD/nVIDIA */
 	    int *reg_val = NULL;
 	    char *chip = "VIA";
 
@@ -415,18 +547,18 @@
 		udmamode = imin(udmamode, 2);
 		reg_val = via_modes[0];
 	    }
-	    else if (ch->chiptype == 0x74411022 ||		/* AMD 768 */
-		     ch->chiptype == 0x74111022) {		/* AMD 766 */
+	    else if (chiptype == 0x74411022 ||			/* AMD 768 */
+		     chiptype == 0x74111022) {			/* AMD 766 */
 		udmamode = imin(udmamode, 5);
 		reg_val = via_modes[4];
 		chip = "AMD";
 	    }
-	    else if (ch->chiptype == 0x74091022) {		/* AMD 756 */
+	    else if (chiptype == 0x74091022) {			/* AMD 756 */
 		udmamode = imin(udmamode, 4);
 		reg_val = via_modes[4];
 		chip = "AMD";
 	    }
-	    else if (ch->chiptype == 0x01bc10de) {		/* nVIDIA */
+	    else if (chiptype == 0x01bc10de) {			/* nVIDIA */
 		udmamode = imin(udmamode, 5);
 		reg_val = via_modes[4];
 		chip = "nVIDIA";
@@ -442,7 +574,7 @@
 			       (error) ? "failed" : "success", chip);
 		if (!error) {
 		    pci_write_config(parent, 0x53 - devno, reg_val[6], 1);
-		    atadev->mode = ATA_UDMA6;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA6);
 		    return;
 		}
 	    }
@@ -454,7 +586,7 @@
 			       (error) ? "failed" : "success", chip);
 		if (!error) {
 		    pci_write_config(parent, 0x53 - devno, reg_val[5], 1);
-		    atadev->mode = ATA_UDMA5;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		    return;
 		}
 	    }
@@ -466,7 +598,7 @@
 			       (error) ? "failed" : "success", chip);
 		if (!error) {
 		    pci_write_config(parent, 0x53 - devno, reg_val[4], 1);
-		    atadev->mode = ATA_UDMA4;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		    return;
 		}
 	    }
@@ -478,7 +610,7 @@
 			       (error) ? "failed" : "success", chip);
 		if (!error) {
 		    pci_write_config(parent, 0x53 - devno, reg_val[2], 1);
-		    atadev->mode = ATA_UDMA2;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		    return;
 		}
 	    }
@@ -491,7 +623,7 @@
 		if (!error) {
 		    pci_write_config(parent, 0x53 - devno, 0x0b, 1);
 		    pci_write_config(parent, 0x4b - devno, 0x31, 1);
-		    atadev->mode = ATA_WDMA2;
+		    ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		    return;
 		}
 	    }
@@ -523,7 +655,7 @@
 			       (error) ? "failed" : "success");
 		if (!error) {
 		    pci_write_config(parent, reg, val | 0x8000, 2);
-		    atadev->mode = ATA_UDMA5;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		    return;
 		}
 	    }
@@ -535,7 +667,7 @@
 			       (error) ? "failed" : "success");
 		if (!error) {
 		    pci_write_config(parent, reg, val | 0x9000, 2);
-		    atadev->mode = ATA_UDMA4;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		    return;
 		}
 	    }
@@ -547,7 +679,7 @@
 			       (error) ? "failed" : "success");
 		if (!error) {
 		    pci_write_config(parent, reg, val | 0xb000, 2);
-		    atadev->mode = ATA_UDMA2;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		    return;
 		}
 	    }
@@ -566,7 +698,7 @@
 			       (error) ? "failed" : "success");
 		if (!error) {
 		    pci_write_config(parent, reg, val | 0x9000, 2);
-		    atadev->mode = ATA_UDMA4;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		    return;
 		}
 	    }
@@ -578,11 +710,11 @@
 			       (error) ? "failed" : "success");
 		if (!error) {
 		    pci_write_config(parent, reg, val | 0xa000, 2);
-		    atadev->mode = ATA_UDMA2;
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		    return;
 		}
 	    }
-	} else if (udmamode >= 2 && pci_get_revid(parent) > 0xc1) {
+	} else if (udmamode >= 2 && chiprev > 0xc1) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
@@ -590,7 +722,7 @@
 			   (error) ? "failed" : "success");
 	    if (!error) {
 		pci_write_config(parent, 0x40 + (devno << 1), 0xa301, 2);
-		atadev->mode = ATA_UDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
@@ -602,7 +734,7 @@
 			   (error) ? "failed" : "success");
 	    if (!error) {
 		pci_write_config(parent, 0x40 + (devno << 1), 0x0301, 2);
-		atadev->mode = ATA_WDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -611,10 +743,10 @@
 
     case 0x06801095:	/* SiI 0680 ATA133 controller */
 	{
-	    u_int8_t ureg = 0xac + (ATA_DEV(device) * 0x02) + (ch->unit * 0x10);
+	    u_int8_t ureg = 0xac + (device * 0x02) + (channel * 0x10);
 	    u_int8_t uval = pci_read_config(parent, ureg, 1);
-	    u_int8_t mreg = ch->unit ? 0x84 : 0x80;
-	    u_int8_t mask = ATA_DEV(device) ? 0x30 : 0x03;
+	    u_int8_t mreg = channel ? 0x84 : 0x80;
+	    u_int8_t mask = device ? 0x30 : 0x03;
 	    u_int8_t mode = pci_read_config(parent, mreg, 1);
 
 	    /* enable UDMA mode */
@@ -627,8 +759,8 @@
 		    ata_prtdev(atadev, "%s setting UDMA6 on SiI chip\n",
 			       (error) ? "failed" : "success");
 		if (!error) {
-		    pci_write_config(parent, ureg, (uval & 0x3f) | 0x01, 1);
-		    atadev->mode = ATA_UDMA6;
+		    pci_write_config(parent, ureg, (uval & ~0x3f) | 0x01, 1);
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA6);
 		    return;
 		}
 	    }
@@ -639,8 +771,8 @@
 		    ata_prtdev(atadev, "%s setting UDMA5 on SiI chip\n",
 			       (error) ? "failed" : "success");
 		if (!error) {
-		    pci_write_config(parent, ureg, (uval & 0x3f) | 0x02, 1);
-		    atadev->mode = ATA_UDMA5;
+		    pci_write_config(parent, ureg, (uval & ~0x3f) | 0x02, 1);
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		    return;
 		}
 	    }
@@ -651,8 +783,8 @@
 		    ata_prtdev(atadev, "%s setting UDMA4 on SiI chip\n",
 			       (error) ? "failed" : "success");
 		if (!error) {
-		    pci_write_config(parent, ureg, (uval & 0x3f) | 0x03, 1);
-		    atadev->mode = ATA_UDMA4;
+		    pci_write_config(parent, ureg, (uval & ~0x3f) | 0x03, 1);
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		    return;
 		}
 	    }
@@ -663,8 +795,8 @@
 		    ata_prtdev(atadev, "%s setting UDMA2 on SiI chip\n",
 			       (error) ? "failed" : "success");
 		if (!error) {
-		    pci_write_config(parent, ureg, (uval & 0x3f) | 0x07, 1);
-		    atadev->mode = ATA_UDMA2;
+		    pci_write_config(parent, ureg, (uval & ~0x3f) | 0x07, 1);
+		    ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		    return;
 		}
 	    }
@@ -680,7 +812,7 @@
 			       (error) ? "failed" : "success");
 		if (!error) {
 		    pci_write_config(parent, ureg - 0x4, 0x10c1, 2);
-		    atadev->mode = ATA_WDMA2;
+		    ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		    return;
 		}
 	    }
@@ -702,11 +834,11 @@
 		ata_prtdev(atadev, "%s setting UDMA5 on CMD chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		umode = pci_read_config(parent, ch->unit ? 0x7b : 0x73, 1);
-		umode &= ~(device == ATA_MASTER ? 0x35 : 0xca);
-		umode |= (device == ATA_MASTER ? 0x05 : 0x0a);
-		pci_write_config(parent, ch->unit ? 0x7b : 0x73, umode, 1);
-		atadev->mode = ATA_UDMA5;
+		umode = pci_read_config(parent, channel ? 0x7b : 0x73, 1);
+		umode &= ~(device ? 0xca : 0x35);
+		umode |= (device ? 0x0a : 0x05);
+		pci_write_config(parent, channel ? 0x7b : 0x73, umode, 1);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		return;
 	    }
 	}
@@ -722,11 +854,11 @@
 		ata_prtdev(atadev, "%s setting UDMA4 on CMD chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		umode = pci_read_config(parent, ch->unit ? 0x7b : 0x73, 1);
-		umode &= ~(device == ATA_MASTER ? 0x35 : 0xca);
-		umode |= (device == ATA_MASTER ? 0x15 : 0x4a);
-		pci_write_config(parent, ch->unit ? 0x7b : 0x73, umode, 1);
-		atadev->mode = ATA_UDMA4;
+		umode = pci_read_config(parent, channel ? 0x7b : 0x73, 1);
+		umode &= ~(device ? 0xca : 0x35);
+		umode |= (device ? 0x4a : 0x15);
+		pci_write_config(parent, channel ? 0x7b : 0x73, umode, 1);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		return;
 	    }
 	}
@@ -739,18 +871,18 @@
 		ata_prtdev(atadev, "%s setting UDMA2 on CMD chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		umode = pci_read_config(parent, ch->unit ? 0x7b : 0x73, 1);
-		umode &= ~(device == ATA_MASTER ? 0x35 : 0xca);
-		umode |= (device == ATA_MASTER ? 0x11 : 0x42);
-		pci_write_config(parent, ch->unit ? 0x7b : 0x73, umode, 1);
-		atadev->mode = ATA_UDMA2;
+		umode = pci_read_config(parent, channel ? 0x7b : 0x73, 1);
+		umode &= ~(device ? 0xca : 0x35);
+		umode |= (device ? 0x42 : 0x11);
+		pci_write_config(parent, channel ? 0x7b : 0x73, umode, 1);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
 	/* make sure eventual UDMA mode from the BIOS is disabled */
-	pci_write_config(parent, ch->unit ? 0x7b : 0x73, 
-			 pci_read_config(parent, ch->unit ? 0x7b : 0x73, 1)&
-			 ~(device == ATA_MASTER ? 0x35 : 0xca), 1);
+	pci_write_config(parent, channel ? 0x7b : 0x73, 
+			 pci_read_config(parent, channel ? 0x7b : 0x73, 1) &
+					 ~(device ? 0xca : 0x53), 1);
 	/* FALLTHROUGH */
 
     case 0x06461095:	/* CMD 646 ATA controller */
@@ -764,7 +896,7 @@
 		int32_t offset = (devno < 3) ? (devno << 1) : 7;
 
 		pci_write_config(parent, 0x54 + offset, 0x3f, 1);
-		atadev->mode = ATA_WDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -779,8 +911,9 @@
 		ata_prtdev(atadev, "%s setting WDMA2 on Cypress chip\n",
 			   error ? "failed" : "success");
 	    if (!error) {
-		pci_write_config(ch->dev, ch->unit ? 0x4e:0x4c, 0x2020, 2);
-		atadev->mode = ATA_WDMA2;
+		pci_write_config(atadev->channel->dev,
+				 channel ? 0x4e:0x4c, 0x2020, 2);
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -788,7 +921,7 @@
 	break;
 
     case 0x01021078:	/* Cyrix 5530 ATA33 controller */
-	ch->alignment = 0xf;	/* DMA engine requires 16 byte alignment */
+	atadev->channel->alignment = 0xf;
 	if (udmamode >= 2) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
@@ -796,8 +929,8 @@
 		ata_prtdev(atadev, "%s setting UDMA2 on Cyrix chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		cyrix_timing(ch, devno, ATA_UDMA2);
-		atadev->mode = ATA_UDMA2;
+		cyrix_timing(atadev, devno, ATA_UDMA2);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
@@ -808,8 +941,8 @@
 		ata_prtdev(atadev, "%s setting WDMA2 on Cyrix chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		cyrix_timing(ch, devno, ATA_WDMA2);
-		atadev->mode = ATA_WDMA2;
+		cyrix_timing(atadev, devno, ATA_WDMA2);
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -820,12 +953,12 @@
 	    ata_prtdev(atadev, "%s setting %s on Cyrix chip\n",
 		       (error) ? "failed" : "success",
 		       ata_mode2str(ATA_PIO0 + apiomode));
-	cyrix_timing(ch, devno, ATA_PIO0 + apiomode);
+	cyrix_timing(atadev, devno, ATA_PIO0 + apiomode);
 	atadev->mode = ATA_PIO0 + apiomode;
 	return;
 
     case 0x02121166:	/* ServerWorks CSB5 ATA66/100 controller */
-	if (udmamode >= 5 && pci_get_revid(parent) >= 0x92) {
+	if (udmamode >= 5 && chiprev >= 0x92) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA5, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
@@ -841,7 +974,7 @@
 		reg56 &= ~(0xf << (devno * 4));
 		reg56 |= (0x5 << (devno * 4));
 		pci_write_config(parent, 0x56, reg56, 2);
-		atadev->mode = ATA_UDMA5;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		return;
 	    }
 	}
@@ -861,7 +994,7 @@
 		reg56 &= ~(0xf << (devno * 4));
 		reg56 |= (0x4 << (devno * 4));
 		pci_write_config(parent, 0x56, reg56, 2);
-		atadev->mode = ATA_UDMA4;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		return;
 	    }
 	}
@@ -884,7 +1017,7 @@
 		reg56 &= ~(0xf << (devno * 4));
 		reg56 |= (0x2 << (devno * 4));
 		pci_write_config(parent, 0x56, reg56, 2);
-		atadev->mode = ATA_UDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
@@ -895,7 +1028,7 @@
 		ata_prtdev(atadev, "%s setting WDMA2 on ServerWorks chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		int offset = (ch->unit * 2) + (device == ATA_MASTER);
+		int offset = devno ^ 0x01;
 		int word44 = pci_read_config(parent, 0x44, 4);
 
 		pci_write_config(parent, 0x54,
@@ -904,7 +1037,7 @@
 		word44 &= ~(0xff << (offset << 8));
 		word44 |= (0x20 << (offset << 8));
 		pci_write_config(parent, 0x44, 0x20, 4);
-		atadev->mode = ATA_WDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -915,15 +1048,16 @@
     case 0x5275105a:	/* Promise TX2 ATA133 controllers */
     case 0x6269105a:	/* Promise TX2 ATA133 controllers */
     case 0x7275105a:	/* Promise TX2 ATA133 controllers */
-	ATA_OUTB(ch->r_bmio, ATA_BMDEVSPEC_0, 0x0b);
-	if (udmamode >= 6 && !(ATA_INB(ch->r_bmio, ATA_BMDEVSPEC_1) & 0x04)) {
+	ATA_OUTB(atadev->channel->r_bmio, ATA_BMDEVSPEC_0, 0x0b);
+	if (udmamode >= 6 &&
+	    !(ATA_INB(atadev->channel->r_bmio, ATA_BMDEVSPEC_1) & 0x04)) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA6, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA6 on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		atadev->mode = ATA_UDMA6;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA6);
 		return;
 	    }
 	}
@@ -931,27 +1065,29 @@
 
     case 0x4d68105a:	/* Promise TX2 ATA100 controllers */
     case 0x6268105a:	/* Promise TX2 ATA100 controllers */
-	ATA_OUTB(ch->r_bmio, ATA_BMDEVSPEC_0, 0x0b);
-	if (udmamode >= 5 && !(ATA_INB(ch->r_bmio, ATA_BMDEVSPEC_1) & 0x04)) {
+	ATA_OUTB(atadev->channel->r_bmio, ATA_BMDEVSPEC_0, 0x0b);
+	if (udmamode >= 5 &&
+	    !(ATA_INB(atadev->channel->r_bmio, ATA_BMDEVSPEC_1) & 0x04)) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA5, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA5 on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		atadev->mode = ATA_UDMA5;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		return;
 	    }
 	}
-	ATA_OUTB(ch->r_bmio, ATA_BMDEVSPEC_0, 0x0b);
-	if (udmamode >= 4 && !(ATA_INB(ch->r_bmio, ATA_BMDEVSPEC_1) & 0x04)) {
+	ATA_OUTB(atadev->channel->r_bmio, ATA_BMDEVSPEC_0, 0x0b);
+	if (udmamode >= 4 &&
+	    !(ATA_INB(atadev->channel->r_bmio, ATA_BMDEVSPEC_1) & 0x04)) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA4 on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		atadev->mode = ATA_UDMA4;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		return;
 	    }
 	}
@@ -962,7 +1098,7 @@
 		ata_prtdev(atadev, "%s setting UDMA on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		atadev->mode = ATA_UDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
@@ -973,7 +1109,7 @@
 		ata_prtdev(atadev, "%s setting WDMA2 on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		atadev->mode = ATA_WDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -981,16 +1117,16 @@
 
     case 0x0d30105a:	/* Promise OEM ATA100 controllers */
     case 0x4d30105a:	/* Promise Ultra/FastTrak 100 controllers */
-	if (!ATAPI_DEVICE(ch, device) && udmamode >= 5 && 
-	    !(pci_read_config(parent, 0x50, 2)&(ch->unit ? 1<<11 : 1<<10))){
+	if (!ATAPI_DEVICE(atadev) && udmamode >= 5 && 
+	    !(pci_read_config(parent, 0x50, 2) & (channel ? 1<<11 : 1<<10))) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA5, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA5 on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		promise_timing(ch, devno, ATA_UDMA5);
-		atadev->mode = ATA_UDMA5;
+		promise_timing(atadev, devno, ATA_UDMA5);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		return;
 	    }
 	}
@@ -998,43 +1134,43 @@
 
     case 0x0d38105a:	/* Promise FastTrak 66 controllers */
     case 0x4d38105a:	/* Promise Ultra/FastTrak 66 controllers */
-	if (!ATAPI_DEVICE(ch, device) && udmamode >= 4 && 
-	    !(pci_read_config(parent, 0x50, 2)&(ch->unit ? 1<<11 : 1<<10))){
+	if (!ATAPI_DEVICE(atadev) && udmamode >= 4 && 
+	    !(pci_read_config(parent, 0x50, 2) & (channel ? 1<<11 : 1<<10))) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA4 on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		promise_timing(ch, devno, ATA_UDMA4);
-		atadev->mode = ATA_UDMA4;
+		promise_timing(atadev, devno, ATA_UDMA4);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		return;
 	    }
 	}
 	/* FALLTHROUGH */
 
     case 0x4d33105a:	/* Promise Ultra/FastTrak 33 controllers */
-	if (!ATAPI_DEVICE(ch, device) && udmamode >= 2) {
+	if (!ATAPI_DEVICE(atadev) && udmamode >= 2) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA2 on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		promise_timing(ch, devno, ATA_UDMA2);
-		atadev->mode = ATA_UDMA2;
+		promise_timing(atadev, devno, ATA_UDMA2);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
-	if (!ATAPI_DEVICE(ch, device) && wdmamode >= 2 && apiomode >= 4) {
+	if (!ATAPI_DEVICE(atadev) && wdmamode >= 2 && apiomode >= 4) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting WDMA2 on Promise chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		promise_timing(ch, devno, ATA_WDMA2);
-		atadev->mode = ATA_WDMA2;
+		promise_timing(atadev, devno, ATA_WDMA2);
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -1045,76 +1181,76 @@
 	    ata_prtdev(atadev, "%s setting PIO%d on Promise chip\n",
 		       (error) ? "failed" : "success",
 		       (apiomode >= 0) ? apiomode : 0);
-	promise_timing(ch, devno, ATA_PIO0 + apiomode);
+	promise_timing(atadev, devno, ATA_PIO0 + apiomode);
 	atadev->mode = ATA_PIO0 + apiomode;
 	return;
     
     case 0x00041103:	/* HighPoint HPT366/368/370/372 controllers */
     case 0x00051103:	/* HighPoint HPT372 controllers */
     case 0x00081103:	/* HighPoint HPT374 controllers */
-	if (!ATAPI_DEVICE(ch, device) && udmamode >= 6 && hpt_cable80(ch) &&
-	    ((ch->chiptype == 0x00041103 && pci_get_revid(parent) >= 0x05) ||
-	     (ch->chiptype == 0x00051103 && pci_get_revid(parent) >= 0x01) ||
-	     (ch->chiptype == 0x00081103 && pci_get_revid(parent) >= 0x07))) {
+	if (!ATAPI_DEVICE(atadev) && udmamode >= 6 && hpt_cable80(atadev) &&
+	    ((chiptype == 0x00041103 && chiprev >= 0x05) ||
+	     (chiptype == 0x00051103 && chiprev >= 0x01) ||
+	     (chiptype == 0x00081103 && chiprev >= 0x07))) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA6, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA6 on HighPoint chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		hpt_timing(ch, devno, ATA_UDMA6);
-		atadev->mode = ATA_UDMA6;
+		hpt_timing(atadev, devno, ATA_UDMA6);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA6);
 		return;
 	    }
 	}
-	if (!ATAPI_DEVICE(ch, device) && udmamode >= 5 && hpt_cable80(ch) &&
-	    ((ch->chiptype == 0x00041103 && pci_get_revid(parent) >= 0x03) ||
-	     (ch->chiptype == 0x00051103 && pci_get_revid(parent) >= 0x01) ||
-	     (ch->chiptype == 0x00081103 && pci_get_revid(parent) >= 0x07))) {
+	if (!ATAPI_DEVICE(atadev) && udmamode >= 5 && hpt_cable80(atadev) &&
+	    ((chiptype == 0x00041103 && chiprev >= 0x03) ||
+	     (chiptype == 0x00051103 && chiprev >= 0x01) ||
+	     (chiptype == 0x00081103 && chiprev >= 0x07))) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA5, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA5 on HighPoint chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		hpt_timing(ch, devno, ATA_UDMA5);
-		atadev->mode = ATA_UDMA5;
+		hpt_timing(atadev, devno, ATA_UDMA5);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA5);
 		return;
 	    }
 	}
-	if (!ATAPI_DEVICE(ch, device) && udmamode >= 4 && hpt_cable80(ch)) {
+	if (!ATAPI_DEVICE(atadev) && udmamode >= 4 && hpt_cable80(atadev)) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA4 on HighPoint chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		hpt_timing(ch, devno, ATA_UDMA4);
-		atadev->mode = ATA_UDMA4;
+		hpt_timing(atadev, devno, ATA_UDMA4);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA4);
 		return;
 	    }
 	}
-	if (!ATAPI_DEVICE(ch, device) && udmamode >= 2) {
+	if (!ATAPI_DEVICE(atadev) && udmamode >= 2) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting UDMA2 on HighPoint chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		hpt_timing(ch, devno, ATA_UDMA2);
-		atadev->mode = ATA_UDMA2;
+		hpt_timing(atadev, devno, ATA_UDMA2);
+		ata_dmacreate(atadev, apiomode, ATA_UDMA2);
 		return;
 	    }
 	}
-	if (!ATAPI_DEVICE(ch, device) && wdmamode >= 2 && apiomode >= 4) {
+	if (!ATAPI_DEVICE(atadev) && wdmamode >= 2 && apiomode >= 4) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting WDMA2 on HighPoint chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		hpt_timing(ch, devno, ATA_WDMA2);
-		atadev->mode = ATA_WDMA2;
+		hpt_timing(atadev, devno, ATA_WDMA2);
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -1125,44 +1261,42 @@
 	    ata_prtdev(atadev, "%s setting PIO%d on HighPoint chip\n",
 		       (error) ? "failed" : "success",
 		       (apiomode >= 0) ? apiomode : 0);
-	hpt_timing(ch, devno, ATA_PIO0 + apiomode);
+	hpt_timing(atadev, devno, ATA_PIO0 + apiomode);
 	atadev->mode = ATA_PIO0 + apiomode;
 	return;
 
     case 0x000116ca:	/* Cenatek Rocket Drive controller */
 	if (wdmamode >= 0 &&
-	    (ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT) & 
-	     ((device==ATA_MASTER)?ATA_BMSTAT_DMA_MASTER:ATA_BMSTAT_DMA_SLAVE)))
-	    atadev->mode = ATA_DMA;
+	    (ATA_INB(atadev->channel->r_bmio, ATA_BMSTAT_PORT) & 
+	     (device ? ATA_BMSTAT_DMA_SLAVE : ATA_BMSTAT_DMA_MASTER)))
+	    ata_dmacreate(atadev, apiomode, ATA_DMA);
 	else
 	    atadev->mode = ATA_PIO;
 	return;
 
     default:		/* unknown controller chip */
 	/* better not try generic DMA on ATAPI devices it almost never works */
-	if ((device == ATA_MASTER && ch->devices & ATA_ATAPI_MASTER) ||
-	    (device == ATA_SLAVE && ch->devices & ATA_ATAPI_SLAVE))
+	if (ATAPI_DEVICE(atadev))
 	    break;
 
 	/* if controller says its setup for DMA take the easy way out */
 	/* the downside is we dont know what DMA mode we are in */
 	if ((udmamode >= 0 || wdmamode >= 2) &&
-	    (ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT) &
-	     ((device==ATA_MASTER) ? 
-	      ATA_BMSTAT_DMA_MASTER : ATA_BMSTAT_DMA_SLAVE))) {
-	    atadev->mode = ATA_DMA;
+	    (ATA_INB(atadev->channel->r_bmio, ATA_BMSTAT_PORT) &
+	     (device ? ATA_BMSTAT_DMA_SLAVE : ATA_BMSTAT_DMA_MASTER))) {
+	    ata_dmacreate(atadev, apiomode, ATA_DMA);
 	    return;
 	}
 
 	/* well, we have no support for this, but try anyways */
-	if ((wdmamode >= 2 && apiomode >= 4) && ch->r_bmio) {
+	if ((wdmamode >= 2 && apiomode >= 4) && atadev->channel->r_bmio) {
 	    error = ata_command(atadev, ATA_C_SETFEATURES, 0,
 				ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
 	    if (bootverbose)
 		ata_prtdev(atadev, "%s setting WDMA2 on generic chip\n",
 			   (error) ? "failed" : "success");
 	    if (!error) {
-		atadev->mode = ATA_WDMA2;
+		ata_dmacreate(atadev, apiomode, ATA_WDMA2);
 		return;
 	    }
 	}
@@ -1181,72 +1315,111 @@
     }
 }
 
+struct ata_dmasetup_data_cb_args {
+    struct ata_dmaentry *dmatab;
+    int error;
+};
+
+static void
+ata_dmasetupd_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
+{
+    struct ata_dmasetup_data_cb_args *cba =
+	(struct ata_dmasetup_data_cb_args *)xsc;
+    bus_size_t cnt;
+    u_int32_t lastcount;
+    int i, j;
+
+    cba->error = error;
+    if (error != 0)
+	return;
+    lastcount = j = 0;
+    for (i = 0; i < nsegs; i++) {
+	/*
+	 * A maximum segment size was specified for bus_dma_tag_create, but
+	 * some busdma code does not seem to honor this, so fix up if needed.
+	 */
+	for (cnt = 0; cnt < segs[i].ds_len; cnt += MAXSEGSZ, j++) {
+	    cba->dmatab[j].base = htole32(segs[i].ds_addr + cnt);
+	    lastcount = ulmin(segs[i].ds_len - cnt, MAXSEGSZ) & 0xffff;
+	    cba->dmatab[j].count = htole32(lastcount);
+	}
+    }
+    cba->dmatab[j - 1].count = htole32(lastcount | ATA_DMA_EOT);
+}
+
 int
-ata_dmasetup(struct ata_channel *ch, int device, struct ata_dmaentry *dmatab,
-	     caddr_t data, int32_t count)
+ata_dmasetup(struct ata_device *atadev, caddr_t data, int32_t count)
 {
-    u_int32_t dma_count, dma_base;
-    int i = 0;
+    struct ata_channel *ch = atadev->channel;
 
     if (((uintptr_t)data & ch->alignment) || (count & ch->alignment)) {
-	ata_printf(ch, device, "non aligned DMA transfer attempted\n");
+	ata_prtdev(atadev, "non aligned DMA transfer attempted\n");
 	return -1;
     }
 
     if (!count) {
-	ata_printf(ch, device, "zero length DMA transfer attempted\n");
+	ata_prtdev(atadev, "zero length DMA transfer attempted\n");
 	return -1;
     }
-    
-    dma_base = vtophys(data);
-    dma_count = imin(count, (PAGE_SIZE - ((uintptr_t)data & PAGE_MASK)));
-    data += dma_count;
-    count -= dma_count;
-
-    while (count) {
-	dmatab[i].base = dma_base;
-	dmatab[i].count = (dma_count & 0xffff);
-	i++; 
-	if (i >= ATA_DMA_ENTRIES) {
-	    ata_printf(ch, device, "too many segments in DMA table\n");
-	    return -1;
-	}
-	dma_base = vtophys(data);
-	dma_count = imin(count, PAGE_SIZE);
-	data += imin(count, PAGE_SIZE);
-	count -= imin(count, PAGE_SIZE);
-    }
-    dmatab[i].base = dma_base;
-    dmatab[i].count = (dma_count & 0xffff) | ATA_DMA_EOT;
     return 0;
 }
 
-void
-ata_dmastart(struct ata_channel *ch, int device, 
-	     struct ata_dmaentry *dmatab, int dir)
+int
+ata_dmastart(struct ata_device *atadev, caddr_t data, int32_t count, int dir)
 {
+    struct ata_channel *ch = atadev->channel;
+    struct ata_dmastate *ds = &atadev->dmastate;
+    struct ata_dmasetup_data_cb_args cba;
+
+    if (ds->flags & ATA_DS_ACTIVE)
+	    panic("ata_dmasetup: transfer active on this device!");
+
+    cba.dmatab = ds->dmatab;
+    bus_dmamap_sync(ds->cdmatag, ds->cdmamap, BUS_DMASYNC_PREWRITE);
+    if (bus_dmamap_load(ds->ddmatag, ds->ddmamap, data, count,
+			ata_dmasetupd_cb, &cba, 0) || cba.error)
+	return -1;
+
+    bus_dmamap_sync(ds->cdmatag, ds->cdmamap, BUS_DMASYNC_POSTWRITE);
+    bus_dmamap_sync(ds->ddmatag, ds->ddmamap, dir ? BUS_DMASYNC_PREREAD :
+		    BUS_DMASYNC_PREWRITE);
+
     ch->flags |= ATA_DMA_ACTIVE;
-    ATA_OUTL(ch->r_bmio, ATA_BMDTP_PORT, vtophys(dmatab));
+    ds->flags = ATA_DS_ACTIVE;
+    if (dir)
+	    ds->flags |= ATA_DS_READ;
+
+    ATA_OUTL(ch->r_bmio, ATA_BMDTP_PORT, ds->mdmatab);
     ATA_OUTB(ch->r_bmio, ATA_BMCMD_PORT, dir ? ATA_BMCMD_WRITE_READ : 0);
     ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, 
 	 (ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT) | 
 	  (ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR)));
     ATA_OUTB(ch->r_bmio, ATA_BMCMD_PORT, 
 	 ATA_INB(ch->r_bmio, ATA_BMCMD_PORT) | ATA_BMCMD_START_STOP);
+    return 0;
 }
 
 int
-ata_dmadone(struct ata_channel *ch)
+ata_dmadone(struct ata_device *atadev)
 {
+    struct ata_channel *ch;
+    struct ata_dmastate *ds;
     int error;
 
+    ch = atadev->channel;
+    ds = &atadev->dmastate;
+    bus_dmamap_sync(ds->ddmatag, ds->ddmamap, (ds->flags & ATA_DS_READ) != 0 ?
+		    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
+    bus_dmamap_unload(ds->ddmatag, ds->ddmamap);
+
     ATA_OUTB(ch->r_bmio, ATA_BMCMD_PORT, 
 		ATA_INB(ch->r_bmio, ATA_BMCMD_PORT) & ~ATA_BMCMD_START_STOP);
-    ch->flags &= ~ATA_DMA_ACTIVE;
     error = ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT);
     ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, 
 	     error | ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR);
-    return error & ATA_BMSTAT_MASK;
+    ch->flags &= ~ATA_DMA_ACTIVE;
+    ds->flags = 0;
+    return (error & ATA_BMSTAT_MASK);
 }
 
 int
@@ -1256,7 +1429,7 @@
 }
 
 static void
-cyrix_timing(struct ata_channel *ch, int devno, int mode)
+cyrix_timing(struct ata_device *atadev, int devno, int mode)
 {
     u_int32_t reg20 = 0x0000e132;
     u_int32_t reg24 = 0x00017771;
@@ -1270,14 +1443,15 @@
     case ATA_WDMA2:	reg24 = 0x00002020; break;
     case ATA_UDMA2:	reg24 = 0x00911030; break;
     }
-    ATA_OUTL(ch->r_bmio, (devno << 3) + 0x20, reg20);
-    ATA_OUTL(ch->r_bmio, (devno << 3) + 0x24, reg24);
+    ATA_OUTL(atadev->channel->r_bmio, (devno << 3) + 0x20, reg20);
+    ATA_OUTL(atadev->channel->r_bmio, (devno << 3) + 0x24, reg24);
 }
 
 static void
-promise_timing(struct ata_channel *ch, int devno, int mode)
+promise_timing(struct ata_device *atadev, int devno, int mode)
 {
     u_int32_t timing = 0;
+    /* XXX: Endianess */
     struct promise_timing {
 	u_int8_t  pa:4;
 	u_int8_t  prefetch:1;
@@ -1299,7 +1473,7 @@
 	t->prefetch = 1; t->errdy = 1; t->syncin = 1;
     }
 
-    switch (ch->chiptype) {
+    switch (atadev->channel->chiptype) {
     case 0x4d33105a:  /* Promise Ultra/Fasttrak 33 */
 	switch (mode) {
 	default:
@@ -1330,16 +1504,19 @@
 	}
 	break;
     }
-    pci_write_config(device_get_parent(ch->dev), 0x60 + (devno<<2), timing, 4);
+    pci_write_config(device_get_parent(atadev->channel->dev),
+		     0x60 + (devno << 2), timing, 4);
 }
 
 static void
-hpt_timing(struct ata_channel *ch, int devno, int mode)
+hpt_timing(struct ata_device *atadev, int devno, int mode)
 {
-    device_t parent = device_get_parent(ch->dev);
+    device_t parent = device_get_parent(atadev->channel->dev);
+    u_int32_t chiptype = atadev->channel->chiptype;
+    int chiprev = pci_get_revid(parent);
     u_int32_t timing;
 
-    if (ch->chiptype == 0x00081103 && pci_get_revid(parent) >= 0x07) {
+    if (chiptype == 0x00081103 && chiprev >= 0x07) {
 	switch (mode) {						/* HPT374 */
 	case ATA_PIO0:	timing = 0x0ac1f48a; break;
 	case ATA_PIO1:	timing = 0x0ac1f465; break;
@@ -1354,8 +1531,8 @@
 	default:	timing = 0x0d029d5e;
 	}
     }
-    else if ((ch->chiptype == 0x00041103 && pci_get_revid(parent) >= 0x05) ||
-	     (ch->chiptype == 0x00051103 && pci_get_revid(parent) >= 0x01)) {
+    else if ((chiptype == 0x00041103 && chiprev >= 0x05) ||
+	     (chiptype == 0x00051103 && chiprev >= 0x01)) {
 	switch (mode) {						/* HPT372 */
 	case ATA_PIO0:	timing = 0x0d029d5e; break;
 	case ATA_PIO1:	timing = 0x0d029d26; break;
@@ -1370,7 +1547,7 @@
 	default:	timing = 0x0d029d5e;
 	}
     }
-    else if (ch->chiptype == 0x00041103 && pci_get_revid(parent) >= 0x03) {
+    else if (chiptype == 0x00041103 && chiprev >= 0x03) {
 	switch (mode) {						/* HPT370 */
 	case ATA_PIO0:	timing = 0x06914e57; break;
 	case ATA_PIO1:	timing = 0x06914e43; break;
@@ -1432,13 +1609,13 @@
 }
 
 static int
-hpt_cable80(struct ata_channel *ch)
+hpt_cable80(struct ata_device *atadev)
-    device_t parent = device_get_parent(ch->dev);
+    device_t parent = device_get_parent(atadev->channel->dev);
     u_int8_t reg, val, res;
 
-    if (ch->chiptype == 0x00081103 && pci_get_function(parent) == 1) {
-	reg = ch->unit ? 0x57 : 0x53;
+    if (atadev->channel->chiptype==0x00081103 && pci_get_function(parent)==1) {
+	reg = atadev->channel->unit ? 0x57 : 0x53;
 	val = pci_read_config(parent, reg, 1);
 	pci_write_config(parent, reg, val | 0x80, 1);
     }
@@ -1447,7 +1624,7 @@
 	val = pci_read_config(parent, reg, 1);
 	pci_write_config(parent, reg, val & 0xfe, 1);
     }
-    res = pci_read_config(parent, 0x5a, 1) & (ch->unit ? 0x01 : 0x02);
+    res = pci_read_config(parent, 0x5a, 1) & (atadev->channel->unit ? 0x1:0x2);
     pci_write_config(parent, reg, val, 1);
     return !res;
 }
diff -u -r ata/ata-isa.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-isa.c
--- ata/ata-isa.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-isa.c	Sat Oct 11 20:33:54 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/ata-isa.c,v 1.4.2.1 2002/03/18 08:37:33 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-isa.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/ata-isa.c,v 1.4.2.3 2003/10/01 04:02:18 luoqi Exp $
  */
 
 #include <sys/param.h>
@@ -43,8 +42,8 @@
 #include <machine/resource.h>
 #include <machine/bus.h>
 #include <sys/rman.h>
-#include <bus/isa/isavar.h>
-#include "ata-all.h"
+#include <isa/isavar.h>
+#include <dev/ata/ata-all.h>
 
 /* local vars */
 static struct isa_pnp_id ata_ids[] = {
@@ -106,35 +105,43 @@
  * the following is a bandaid to get ISA only setups to link,
  * since these are getting rare the ugliness is kept here
  */
-#include "use_pci.h"
+#include "pci.h"
 #if NPCI == 0
-void *
-ata_dmaalloc(struct ata_channel *ch, int device)
+int
+ata_dmaalloc(struct ata_device *atadev)
+{
+    return ENXIO;
+}
+
+void
+ata_dmafree(struct ata_device *atadev)
+{
+}
+
+void
+ata_dmafreetags(struct ata_channel *ch)
 {
-    return 0;
 }
 
 void
-ata_dmainit(struct ata_channel *ch, int device,
-	    int piomode, int wdmamode, int udmamode)
+ata_dmainit(struct ata_device *atadev, int piomode, int wdmamode, int udmamode)
 {
 }
 
 int
-ata_dmasetup(struct ata_channel *ch, int device, struct ata_dmaentry *dmatab,
-	     caddr_t data, int32_t count)
+ata_dmasetup(struct ata_device *atadev, caddr_t data, int32_t count)
 {
     return -1;
 }
 
-void
-ata_dmastart(struct ata_channel *ch, int device, 
-	     struct ata_dmaentry *dmatab, int dir)
+int
+ata_dmastart(struct ata_device *atadev, caddr_t data, int32_t count, int dir)
 {
+    return -1;
 }
 
 int
-ata_dmadone(struct ata_channel *ch)
+ata_dmadone(struct ata_device *atadev)
 {
     return -1;
 }
diff -u -r ata/ata-pci.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-pci.c
--- ata/ata-pci.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-pci.c	Sun Oct 26 10:29:03 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/ata-pci.c,v 1.32.2.15 2003/06/06 13:27:05 fjoe Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-pci.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/ata-pci.c,v 1.32.2.17 2003/10/22 14:43:52 jhb Exp $
  */
 
 #include <sys/param.h>
@@ -47,9 +46,9 @@
 #include <machine/md_var.h>
 #endif
 #include <sys/rman.h>
-#include <bus/pci/pcivar.h>
-#include <bus/pci/pcireg.h>
-#include "ata-all.h"
+#include <pci/pcivar.h>
+#include <pci/pcireg.h>
+#include <dev/ata/ata-all.h>
 
 /* device structures */
 struct ata_pci_controller {
@@ -150,6 +149,9 @@
     case 0x24cb8086:
 	return "Intel ICH4 ATA100 controller";
 
+    case 0x24d18086:
+	return "Intel ICH5 SATA150 controller";
+
     case 0x24db8086:
 	return "Intel ICH5 ATA100 controller";
 
@@ -580,6 +582,12 @@
 	    return 1;
 	break;
 
+    case 0x06801095:	/* SiI 680 */
+	if (!(pci_read_config(device_get_parent(ch->dev),
+			      (ch->unit ? 0xb1 : 0xa1), 1) & 0x08))
+	    return 1;
+	break;
+
     case 0x4d33105a:	/* Promise Ultra/Fasttrak 33 */
     case 0x0d38105a:	/* Promise Fasttrak 66 */
     case 0x4d38105a:	/* Promise Ultra/Fasttrak 66 */
@@ -600,6 +608,16 @@
 	if (!(ATA_INB(ch->r_bmio, ATA_BMDEVSPEC_1) & 0x20))
 	    return 1;
 	break;
+
+    case 0x24d18086:	/* Intel ICH5 SATA150 */
+	dmastat = ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT);
+	if ((dmastat & (ATA_BMSTAT_ACTIVE | ATA_BMSTAT_INTERRUPT)) !=
+		ATA_BMSTAT_INTERRUPT)
+	    return 1;
+	ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, dmastat &
+	    ~(ATA_BMSTAT_DMA_SIMPLEX | ATA_BMSTAT_ERROR));
+	DELAY(1);
+	return 0;
     }
 
     if (ch->flags & ATA_DMA_ACTIVE) {
diff -u -r ata/ata-raid.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-raid.c
--- ata/ata-raid.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-raid.c	Fri Jan 31 10:26:00 2003
@@ -26,7 +26,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/ata-raid.c,v 1.3.2.19 2003/01/30 07:19:59 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-raid.c,v 1.8 2003/08/07 21:16:51 dillon Exp $
  */
 
 #include "opt_ata.h"
@@ -43,23 +42,14 @@
 #include <sys/cons.h>
 #include <machine/bus.h>
 #include <sys/rman.h>
-#include "ata-all.h"
-#include "ata-disk.h"
-#include "ata-raid.h"
-#include <sys/proc.h>
-#include <sys/buf2.h>
+#include <dev/ata/ata-all.h>
+#include <dev/ata/ata-disk.h>
+#include <dev/ata/ata-raid.h>
 
 /* device structures */
 static d_open_t		aropen;
 static d_strategy_t	arstrategy;
-
 static struct cdevsw ar_cdevsw = {
-	/* name */	"ar",
-	/* maj */	157,
-	/* flags */	D_DISK,
-	/* port */      NULL,
-	/* autoq */	0,
-
 	/* open */	aropen,
 	/* close */	nullclose,
 	/* read */	physread,
@@ -68,9 +58,14 @@
 	/* poll */	nopoll,
 	/* mmap */	nommap,
 	/* strategy */	arstrategy,
+	/* name */	"ar",
+	/* maj */	157,
 	/* dump */	nodump,
-	/* psize */	nopsize
+	/* psize */	nopsize,
+	/* flags */	D_DISK,
+	/* bmaj */	-1
 };  
+static struct cdevsw ardisk_cdevsw;
 
 /* prototypes */
 static void ar_attach_raid(struct ar_softc *, int);
@@ -187,7 +182,7 @@
     int disk;
 
     ar_config_changed(rdp, update);
-    dev = disk_create(rdp->lun, &rdp->disk, 0, &ar_cdevsw);
+    dev = disk_create(rdp->lun, &rdp->disk, 0, &ar_cdevsw, &ardisk_cdevsw);
     dev->si_drv1 = rdp;
     dev->si_iosize_max = 256 * DEV_BSIZE;
     rdp->dev = dev;
@@ -409,7 +404,7 @@
     else
 	ar_highpoint_write_conf(rdp);
     disk_invalidate(&rdp->disk);
-    disk_destroy(&rdp->disk);
+    disk_destroy(rdp->dev);
     free(rdp, M_AR);
     ar_table[array] = NULL;
     return 0;
@@ -472,7 +467,7 @@
 }
 
 static int
-aropen(dev_t dev, int flags, int fmt, struct thread *td)
+aropen(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct ar_softc *rdp = dev->si_drv1;
     struct disklabel *dl;
@@ -588,7 +583,7 @@
 		     bp->b_pblkno < rdp->lock_end) ||
 		    ((bp->b_pblkno + chunk) > rdp->lock_start &&
 		     (bp->b_pblkno + chunk) <= rdp->lock_end)) {
-		    tsleep(rdp, 0, "arwait", 0);
+		    tsleep(rdp, PRIBIO, "arwait", 0);
 		}
 	    }
 	    if ((rdp->disks[buf1->drive].flags &
@@ -1433,7 +1428,7 @@
 
     if (flags & AR_WAIT) {
 	while ((retry++ < (15*hz/10)) && (error = !(bp->b_flags & B_DONE)))
-	    error = tsleep(bp, 0, "arrw", 10);
+	    error = tsleep(bp, PRIBIO, "arrw", 10);
 	if (!error && (bp->b_flags & B_ERROR))
 	    error = bp->b_error;
 	free(bp, M_AR);
diff -u -r ata/ata-raid.h /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-raid.h
--- ata/ata-raid.h	Tue Jul 22 10:03:27 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/ata-raid.h	Mon May  6 19:08:50 2002
@@ -26,7 +26,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/ata-raid.h,v 1.2.2.8 2002/04/11 09:31:57 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-raid.h,v 1.3 2003/07/22 17:03:27 dillon Exp $
  */
 
 /* misc defines */
@@ -36,7 +35,7 @@
 #define AR_READ		0x01
 #define AR_WRITE	0x02
 #define AR_WAIT		0x04
-#define AR_STRATEGY(x)	dev_port_dstrategy((x)->b_dev->si_disk->d_fwdport, (x)->b_dev->si_disk->d_dev, x)
+#define AR_STRATEGY(x)	(x)->b_dev->si_disk->d_devsw->d_strategy((x))
 #define AD_SOFTC(x)	((struct ad_softc *)(x.device->driver))
 #define ATA_MAGIC	"FreeBSD ATA driver RAID "
 
diff -u -r ata/atapi-all.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-all.c
--- ata/atapi-all.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-all.c	Sat Oct 11 20:33:54 2003
@@ -25,16 +25,14 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/atapi-all.c,v 1.46.2.18 2002/10/31 23:10:33 thomas Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-all.c,v 1.4 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/atapi-all.c,v 1.46.2.20 2003/09/05 18:27:39 dg Exp $
  */
 
 #include "opt_ata.h"
-#include "use_atapicd.h"
-#include "use_atapifd.h"
-#include "use_atapist.h"
-#include "use_atapicam.h"
-
+#include "atapicd.h"
+#include "atapifd.h"
+#include "atapist.h"
+#include "atapicam.h"
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/ata.h>
@@ -46,8 +44,8 @@
 #include <machine/bus.h>
 #include <machine/clock.h>
 #include <sys/rman.h>
-#include "ata-all.h"
-#include "atapi-all.h"
+#include <dev/ata/ata-all.h>
+#include <dev/ata/atapi-all.h>
 
 /* prototypes */
 static void atapi_read(struct atapi_request *, int);
@@ -71,16 +69,17 @@
 	   "ATAPI device DMA mode control");
 
 void
-atapi_attach(struct ata_device *atadev)
+atapi_attach(struct ata_device *atadev, int alreadylocked)
 {
     if (bootverbose) 
 	ata_prtdev(atadev, "piomode=%d dmamode=%d udmamode=%d dmaflag=%d\n",
 		   ata_pmode(atadev->param), ata_wmode(atadev->param),
 		   ata_umode(atadev->param), atadev->param->support_dma);
 
-    ATA_SLEEPLOCK_CH(atadev->channel, ATA_CONTROL);
+    if (!alreadylocked)
+	ATA_SLEEPLOCK_CH(atadev->channel, ATA_CONTROL);
     if (atapi_dma && !(atadev->param->drq_type == ATAPI_DRQT_INTR)) {
-	ata_dmainit(atadev->channel, atadev->unit,
+	ata_dmainit(atadev,
 		    (ata_pmode(atadev->param) < 0) ? 
 		    (atadev->param->support_dma ? 4:0):ata_pmode(atadev->param),
 		    (ata_wmode(atadev->param) < 0) ? 
@@ -88,7 +87,7 @@
 		    ata_umode(atadev->param));
     }
     else
-	ata_dmainit(atadev->channel, atadev->unit,
+	ata_dmainit(atadev,
 		    ata_pmode(atadev->param) < 0 ? 0 : ata_pmode(atadev->param),
 		    -1, -1);
     ATA_UNLOCK_CH(atadev->channel);
@@ -161,10 +160,9 @@
 	    bp->b_error = ENXIO;
 	    biodone(bp);
 	}
-	if (request->dmatab)
-	    free(request->dmatab, M_DEVBUF);
 	free(request, M_ATAPI);
     }
+    ata_dmafree(atadev);
     free(atadev->result, M_ATAPI);
     atadev->driver = NULL;
     atadev->flags = 0;
@@ -196,7 +194,7 @@
 	request->driver = driver;
     }
     if (atadev->mode >= ATA_DMA) {
-	if (!(request->dmatab = ata_dmaalloc(atadev->channel, atadev->unit)))
+	if (ata_dmaalloc(atadev))
 	    atadev->mode = ATA_PIO;
     }
 
@@ -220,13 +218,11 @@
 
     /* only sleep when command is in progress */
     if (request->error == EINPROGRESS)
-	tsleep((caddr_t)request, 0, "atprq", 0);
+	tsleep((caddr_t)request, PRIBIO, "atprq", 0);
     splx(s);
     error = request->error;
     if (error)
 	 bcopy(&request->sense, atadev->result, sizeof(struct atapi_reqsense));
-    if (request->dmatab)
-	free(request->dmatab, M_DEVBUF);
     free(request, M_ATAPI);
     return error;
 }
@@ -294,8 +290,7 @@
 	 ((request->ccb[0] == ATAPI_WRITE ||
 	   request->ccb[0] == ATAPI_WRITE_BIG) &&
 	  !(atadev->channel->flags & ATA_ATAPI_DMA_RO))) &&
-	!ata_dmasetup(atadev->channel, atadev->unit, request->dmatab,
-		      (void *)request->data, request->bytecount)) {
+	!ata_dmasetup(atadev, (void *)request->data, request->bytecount)) {
 	request->flags |= ATPR_F_DMA_USED;
     }
 
@@ -307,8 +302,8 @@
 	ata_prtdev(atadev, "failure to send ATAPI packet command\n");
 
     if (request->flags & ATPR_F_DMA_USED)
-	ata_dmastart(atadev->channel, atadev->unit, 
-		     request->dmatab, request->flags & ATPR_F_READ);
+	ata_dmastart(atadev, request->data, request->bytecount,
+		     request->flags & ATPR_F_READ);
 
     /* command interrupt device ? just return */
     if (atadev->param->drq_type == ATAPI_DRQT_INTR)
@@ -365,7 +360,7 @@
     }
 
     if (request->flags & ATPR_F_DMA_USED) {
-	dma_stat = ata_dmadone(atadev->channel);
+	dma_stat = ata_dmadone(atadev);
 	if ((atadev->channel->status & (ATA_S_ERROR | ATA_S_DWF)) ||
 	    dma_stat & ATA_BMSTAT_ERROR) {
 	    request->result = ATA_INB(atadev->channel->r_io, ATA_ERROR);
@@ -487,14 +482,14 @@
 {
     /* reinit device parameters */
      if (atadev->mode >= ATA_DMA)
-	ata_dmainit(atadev->channel, atadev->unit,
+	ata_dmainit(atadev,
 		    (ata_pmode(atadev->param) < 0) ?
 		    (atadev->param->support_dma ? 4:0):ata_pmode(atadev->param),
 		    (ata_wmode(atadev->param) < 0) ? 
 		    (atadev->param->support_dma ? 2:0):ata_wmode(atadev->param),
 		    ata_umode(atadev->param));
     else
-	ata_dmainit(atadev->channel, atadev->unit,
+	ata_dmainit(atadev,
 		    ata_pmode(atadev->param)<0 ? 0 : ata_pmode(atadev->param),
 		    -1, -1);
 }
@@ -520,7 +515,7 @@
 	error = atapi_queue_cmd(atadev, ccb, NULL, 0, 0, 0, NULL, NULL);
 	if (error != EBUSY)
 	    break;
-	tsleep((caddr_t)&error, 0, "atpwt", hz / 2);
+	tsleep((caddr_t)&error, PRIBIO, "atpwt", hz / 2);
 	timeout -= (hz / 2);
     }
     return error;
@@ -604,11 +599,8 @@
 	       atapi_cmd2str(request->ccb[0]));
 #endif
     if (request->callback) {
-	if (!((request->callback)(request))) {
-	    if (request->dmatab)
-		free(request->dmatab, M_DEVBUF);
+	if (!((request->callback)(request)))
 	    free(request, M_ATAPI);
-	}
     }
     else 
 	wakeup((caddr_t)request);	
@@ -624,9 +616,9 @@
 	       atapi_cmd2str(request->ccb[0]));
 
     if (request->flags & ATPR_F_DMA_USED) {
-	ata_dmadone(atadev->channel);
+	ata_dmadone(atadev);
 	if (request->retries == ATAPI_MAX_RETRIES) {
-	    ata_dmainit(atadev->channel, atadev->unit,
+	    ata_dmainit(atadev,
 			(ata_pmode(atadev->param) < 0) ? 0 :
 			 ata_pmode(atadev->param), -1, -1);
 	    ata_prtdev(atadev, "trying fallback to PIO mode\n");
diff -u -r ata/atapi-all.h /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-all.h
--- ata/atapi-all.h	Mon Jun 16 21:28:22 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-all.h	Sat Oct 11 20:33:54 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/atapi-all.h,v 1.22.2.10 2002/10/31 23:10:33 thomas Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-all.h,v 1.2 2003/06/17 04:28:22 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/atapi-all.h,v 1.22.2.12 2003/09/05 18:27:39 dg Exp $
  */
 
 /* ATAPI misc defines */
@@ -167,12 +166,11 @@
 
     caddr_t			data;		/* pointer to data buf */
     atapi_callback_t		*callback;	/* ptr to callback func */
-    struct ata_dmaentry		*dmatab;	/* DMA transfer table */
     void			*driver;	/* driver specific */
     TAILQ_ENTRY(atapi_request)	chain;		/* list management */
 };
 
-void atapi_attach(struct ata_device *);
+void atapi_attach(struct ata_device *, int);
 void atapi_cam_attach_bus(struct ata_channel *);
 void atapi_detach(struct ata_device *);
 void atapi_cam_detach_bus(struct ata_channel *);
diff -u -r ata/atapi-cam.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-cam.c
--- ata/atapi-cam.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-cam.c	Sat Oct 11 20:33:54 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/atapi-cam.c,v 1.10.2.3 2003/05/21 09:24:55 thomas Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-cam.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/atapi-cam.c,v 1.10.2.6 2003/09/18 20:15:55 thomas Exp $
  */
 
 #include <sys/param.h>
@@ -38,16 +37,16 @@
 #include <sys/ata.h>
 #include <machine/bus.h>
 
-#include <bus/cam/cam.h>
-#include <bus/cam/cam_ccb.h>
-#include <bus/cam/cam_periph.h>
-#include <bus/cam/cam_sim.h>
-#include <bus/cam/cam_xpt_sim.h>
-#include <bus/cam/cam_debug.h>
-#include <bus/cam/scsi/scsi_all.h>
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/cam_periph.h>
+#include <cam/cam_sim.h>
+#include <cam/cam_xpt_sim.h>
+#include <cam/cam_debug.h>
+#include <cam/scsi/scsi_all.h>
 
-#include "ata-all.h"
-#include "atapi-all.h"
+#include <dev/ata/ata-all.h>
+#include <dev/ata/atapi-all.h>
 
 /* hardware command descriptor block */
 struct atapi_hcb {
@@ -240,7 +239,7 @@
 	cpi->version_num = 1;
 	cpi->hba_inquiry = 0;
 	cpi->target_sprt = 0;
-	cpi->hba_misc = 0;
+	cpi->hba_misc = PIM_NO_6_BYTE;
 	cpi->hba_eng_cnt = 0;
 	bzero(cpi->vuhba_flags, sizeof(cpi->vuhba_flags));
 	cpi->max_target = 1;
@@ -253,7 +252,9 @@
 	strncpy(cpi->dev_name, cam_sim_name(sim), sizeof cpi->dev_name);
 	cpi->unit_number = cam_sim_unit(sim);
 	cpi->bus_id = cam_sim_bus(sim);
-	if (softc->ata_ch && ccb_h->target_id >= 0) {
+	cpi->base_transfer_speed = 3300;
+
+	if (softc->ata_ch && ccb_h->target_id != CAM_TARGET_WILDCARD) {
 	    switch (softc->ata_ch->device[ccb_h->target_id].mode) {
 	    case ATA_PIO1:
 		cpi->base_transfer_speed = 5200;
@@ -281,7 +282,8 @@
 	    case ATA_UDMA6:
 		cpi->base_transfer_speed = 133000;
 		break;
-	    default: cpi->base_transfer_speed = 3300;
+	    default:
+		break;
 	    }
 	}
 	ccb->ccb_h.status = CAM_REQ_CMP;
@@ -428,36 +430,6 @@
 	    }
 	    break;
 	}
-	case MODE_SELECT_6:
-	    /* FALLTHROUGH */
-
-	case MODE_SENSE_6:
-	    /*
-	     * not supported by ATAPI/MMC devices (per SCSI MMC spec)
-	     * translate to _10 equivalent.
-	     * (actually we should do this only if we have tried 
-	     * MODE_foo_6 and received ILLEGAL_REQUEST or
-	     * INVALID COMMAND OPERATION CODE)
-	     * alternative fix: behave like a honest CAM transport, 
-	     * do not muck with CDB contents, and change scsi_cd to 
-	     * always use MODE_SENSE_10 in cdgetmode(), or let scsi_cd
-	     * know that this specific unit is an ATAPI/MMC one, 
-	     * and in /that case/ use MODE_SENSE_10
-	     */
-
-	    CAM_DEBUG(ccb_h->path, CAM_DEBUG_SUBTRACE, 
-		      ("Translating %s into _10 equivalent\n",
-		      (hcb->cmd[0] == MODE_SELECT_6) ?
-		      "MODE_SELECT_6" : "MODE_SENSE_6"));
-	    hcb->cmd[0] |= 0x40;
-	    hcb->cmd[6] = 0;
-	    hcb->cmd[7] = 0;
-	    hcb->cmd[8] = hcb->cmd[4];
-	    hcb->cmd[9] = hcb->cmd[5];
-	    hcb->cmd[4] = 0;
-	    hcb->cmd[5] = 0;
-	    break;
-
 	case READ_6:
 	    /* FALLTHROUGH */
 
diff -u -r ata/atapi-cd.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-cd.c
--- ata/atapi-cd.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-cd.c	Sat Oct 11 20:33:54 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/atapi-cd.c,v 1.48.2.20 2002/11/25 05:30:31 njl Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-cd.c,v 1.8 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/atapi-cd.c,v 1.48.2.21 2003/09/05 07:29:10 luoqi Exp $
  */
 
 #include "opt_ata.h"
@@ -46,24 +45,17 @@
 #include <sys/fcntl.h>
 #include <sys/conf.h>
 #include <sys/ctype.h>
-#include <sys/buf2.h>
-#include "ata-all.h"
-#include "atapi-all.h"
-#include "atapi-cd.h"
+#include <machine/bus.h>
+#include <dev/ata/ata-all.h>
+#include <dev/ata/atapi-all.h>
+#include <dev/ata/atapi-cd.h>
 
 /* device structures */
 static d_open_t		acdopen;
 static d_close_t	acdclose;
 static d_ioctl_t	acdioctl;
 static d_strategy_t	acdstrategy;
-
 static struct cdevsw acd_cdevsw = {
-	/* name */	"acd",
-	/* maj */	117,
-	/* flags */	D_DISK | D_TRACKCLOSE,
-	/* port */      NULL,
-	/* autoq */	0,
-
 	/* open */	acdopen,
 	/* close */	acdclose,
 	/* read */	physread,
@@ -72,8 +64,11 @@
 	/* poll */	nopoll,
 	/* mmap */	nommap,
 	/* strategy */	acdstrategy,
+	/* name */	"acd",
+	/* maj */	117,
 	/* dump */	nodump,
-	/* psize */	nopsize
+	/* psize */	nopsize,
+	/* flags */	D_DISK | D_TRACKCLOSE,
 };
 
 /* prototypes */
@@ -493,7 +488,7 @@
 }
 
 static int
-acdopen(dev_t dev, int flags, int fmt, struct thread *td)
+acdopen(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct acd_softc *cdp = dev->si_drv1;
     int timeout = 60;
@@ -513,7 +508,7 @@
 	if (!atapi_test_ready(cdp->device))
 	    break;
 	if (sense->sense_key == 2  && sense->asc == 4 && sense->ascq == 1)
-	    tsleep(&timeout, 0, "acdld", hz / 2);
+	    tsleep(&timeout, PRIBIO, "acdld", hz / 2);
 	else
 	    break;
     }
@@ -521,7 +516,7 @@
     if (count_dev(dev) == 1) {
 	if (cdp->changer_info && cdp->slot != cdp->changer_info->current_slot) {
 	    acd_select_slot(cdp);
-	    tsleep(&cdp->changer_info, 0, "acdopn", 0);
+	    tsleep(&cdp->changer_info, PRIBIO, "acdopn", 0);
 	}
 	acd_prevent_allow(cdp, 1);
 	cdp->flags |= F_LOCKED;
@@ -531,7 +526,7 @@
 }
 
 static int 
-acdclose(dev_t dev, int flags, int fmt, struct thread *td)
+acdclose(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct acd_softc *cdp = dev->si_drv1;
     
@@ -541,7 +536,7 @@
     if (count_dev(dev) == 1) {
 	if (cdp->changer_info && cdp->slot != cdp->changer_info->current_slot) {
 	    acd_select_slot(cdp);
-	    tsleep(&cdp->changer_info, 0, "acdclo", 0);
+	    tsleep(&cdp->changer_info, PRIBIO, "acdclo", 0);
 	}
 	acd_prevent_allow(cdp, 0);
 	cdp->flags &= ~F_LOCKED;
@@ -550,7 +545,7 @@
 }
 
 static int 
-acdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
+acdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
 {
     struct acd_softc *cdp = dev->si_drv1;
     int error = 0;
@@ -560,7 +555,7 @@
 
     if (cdp->changer_info && cdp->slot != cdp->changer_info->current_slot) {
 	acd_select_slot(cdp);
-	tsleep(&cdp->changer_info, 0, "acdctl", 0);
+	tsleep(&cdp->changer_info, PRIBIO, "acdctl", 0);
     }
     if (cdp->device->flags & ATA_D_MEDIA_CHANGED)
 	switch (cmd) {
@@ -603,7 +598,7 @@
 	break;
 
     case CDIOCRESET:
-	error = suser(td);	/* note: if no proc EPERM will be returned */
+	error = suser(p);
 	if (error)
 	    break;
 	error = atapi_test_ready(cdp->device);
@@ -1470,14 +1465,14 @@
     /* some drives just return ready, wait for the expected fixate time */
     if ((error = atapi_test_ready(cdp->device)) != EBUSY) {
 	timeout = timeout / (cdp->cap.cur_write_speed / 177);
-	tsleep(&error, 0, "acdfix", timeout * hz / 2);
+	tsleep(&error, PRIBIO, "acdfix", timeout * hz / 2);
 	return atapi_test_ready(cdp->device);
     }
 
     while (timeout-- > 0) {
 	if ((error = atapi_test_ready(cdp->device)) != EBUSY)
 	    return error;
-	tsleep(&error, 0, "acdcld", hz/2);
+	tsleep(&error, PRIBIO, "acdcld", hz/2);
     }
     return EIO;
 }
diff -u -r ata/atapi-cd.h /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-cd.h
--- ata/atapi-cd.h	Mon Jun 16 21:28:22 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-cd.h	Wed Mar 20 12:20:12 2002
@@ -26,7 +26,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/atapi-cd.h,v 1.15.2.9 2002/03/18 08:37:34 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-cd.h,v 1.2 2003/06/17 04:28:22 dillon Exp $
  */
 
 /* CDROM Table Of Contents */
diff -u -r ata/atapi-fd.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-fd.c
--- ata/atapi-fd.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-fd.c	Sat Oct 11 20:33:54 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/atapi-fd.c,v 1.44.2.9 2002/07/31 11:19:26 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-fd.c,v 1.7 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/atapi-fd.c,v 1.44.2.10 2003/09/05 07:29:10 luoqi Exp $
  */
 
 #include <sys/param.h>
@@ -40,25 +39,17 @@
 #include <sys/disk.h>
 #include <sys/devicestat.h>
 #include <sys/cdio.h>
-#include <sys/proc.h>
-#include <sys/buf2.h>
-#include "ata-all.h"
-#include "atapi-all.h"
-#include "atapi-fd.h"
+#include <machine/bus.h>
+#include <dev/ata/ata-all.h>
+#include <dev/ata/atapi-all.h>
+#include <dev/ata/atapi-fd.h>
 
 /* device structures */
 static	d_open_t	afdopen;
 static	d_close_t	afdclose;
 static	d_ioctl_t	afdioctl;
 static	d_strategy_t	afdstrategy;
-
 static struct cdevsw afd_cdevsw = {
-	/* name */	"afd",
-	/* maj */	118,
-	/* flags */	D_DISK | D_TRACKCLOSE,
-	/* port */      NULL,
-	/* autoq */	0,
-
 	/* open */	afdopen,
 	/* close */	afdclose,
 	/* read */	physread,
@@ -67,9 +58,13 @@
 	/* poll */	nopoll,
 	/* mmap */	nommap,
 	/* strategy */	afdstrategy,
+	/* name */	"afd",
+	/* maj */	118,
 	/* dump */	nodump,
-	/* psize */	nopsize
+	/* psize */	nopsize,
+	/* flags */	D_DISK | D_TRACKCLOSE,
 };
+static struct cdevsw afddisk_cdevsw;
 
 /* prototypes */
 static int afd_sense(struct afd_softc *);
@@ -109,7 +104,7 @@
 		      DEVSTAT_NO_ORDERED_TAGS,
 		      DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_IDE,
 		      DEVSTAT_PRIORITY_WFD);
-    dev = disk_create(fdp->lun, &fdp->disk, 0, &afd_cdevsw);
+    dev = disk_create(fdp->lun, &fdp->disk, 0, &afd_cdevsw, &afddisk_cdevsw);
     dev->si_drv1 = fdp;
     fdp->dev = dev;
 
@@ -138,7 +133,7 @@
 	biodone(bp);
     }
     disk_invalidate(&fdp->disk);
-    disk_destroy(&fdp->disk);
+    disk_destroy(fdp->dev);
     devstat_remove_entry(&fdp->stats);
     ata_free_name(atadev);
     ata_free_lun(&afd_lun_map, fdp->lun);
@@ -233,7 +228,7 @@
 }
 
 static int
-afdopen(dev_t dev, int flags, int fmt, struct thread *td)
+afdopen(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct afd_softc *fdp = dev->si_drv1;
     struct disklabel *label = &fdp->disk.d_label;
@@ -259,7 +254,7 @@
 }
 
 static int 
-afdclose(dev_t dev, int flags, int fmt, struct thread *td)
+afdclose(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct afd_softc *fdp = dev->si_drv1;
 
@@ -269,7 +264,7 @@
 }
 
 static int 
-afdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
+afdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
 {
     struct afd_softc *fdp = dev->si_drv1;
 
diff -u -r ata/atapi-fd.h /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-fd.h
--- ata/atapi-fd.h	Mon Jun 16 21:28:22 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-fd.h	Wed Jul 31 12:29:53 2002
@@ -26,7 +26,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/atapi-fd.h,v 1.10.2.5 2002/07/31 11:19:26 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-fd.h,v 1.2 2003/06/17 04:28:22 dillon Exp $
  */
 
 /* ATAPI Rewriteable drive Capabilities and Mechanical Status Page */
diff -u -r ata/atapi-tape.c /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-tape.c
--- ata/atapi-tape.c	Thu Aug  7 14:16:51 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-tape.c	Sat Oct 11 20:33:54 2003
@@ -25,8 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/ata/atapi-tape.c,v 1.36.2.12 2002/07/31 11:19:26 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-tape.c,v 1.7 2003/08/07 21:16:51 dillon Exp $
+ * $FreeBSD: src/sys/dev/ata/atapi-tape.c,v 1.36.2.13 2003/09/05 07:29:10 luoqi Exp $
  */
 
 #include "opt_ata.h"
@@ -41,25 +40,17 @@
 #include <sys/mtio.h>
 #include <sys/disklabel.h>
 #include <sys/devicestat.h>
-#include <sys/proc.h>
-#include <sys/buf2.h>
-#include "ata-all.h"
-#include "atapi-all.h"
-#include "atapi-tape.h"
+#include <machine/bus.h>
+#include <dev/ata/ata-all.h>
+#include <dev/ata/atapi-all.h>
+#include <dev/ata/atapi-tape.h>
 
 /* device structures */
 static	d_open_t	astopen;
 static	d_close_t	astclose;
 static	d_ioctl_t	astioctl;
 static	d_strategy_t	aststrategy;
-
 static struct cdevsw ast_cdevsw = {
-	/* name */	"ast",
-	/* maj */	119,
-	/* flags */	D_TAPE | D_TRACKCLOSE,
-	/* port */      NULL,
-	/* autoq */	0,
-
 	/* open */	astopen,
 	/* close */	astclose,
 	/* read */	physread,
@@ -68,8 +59,11 @@
 	/* poll */	nopoll,
 	/* mmap */	nommap,
 	/* strategy */	aststrategy,
+	/* name */	"ast",
+	/* maj */	119,
 	/* dump */	nodump,
-	/* psize */	nopsize
+	/* psize */	nopsize,
+	/* flags */	D_TAPE | D_TRACKCLOSE,
 };
 
 /* prototypes */
@@ -252,7 +246,7 @@
 }
 
 static int
-astopen(dev_t dev, int flags, int fmt, struct thread *td)
+astopen(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct ast_softc *stp = dev->si_drv1;
 
@@ -277,7 +271,7 @@
 }
 
 static int 
-astclose(dev_t dev, int flags, int fmt, struct thread *td)
+astclose(dev_t dev, int flags, int fmt, struct proc *p)
 {
     struct ast_softc *stp = dev->si_drv1;
 
@@ -305,7 +299,7 @@
 }
 
 static int 
-astioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
+astioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
 {
     struct ast_softc *stp = dev->si_drv1;
     int error = 0;
@@ -633,7 +627,7 @@
     error = atapi_queue_cmd(stp->device, ccb, NULL, 0, 0, 10, NULL, NULL);
     if (error)
 	return error;
-    tsleep((caddr_t)&error, 0, "astlu", 1 * hz);
+    tsleep((caddr_t)&error, PRIBIO, "astlu", 1 * hz);
     if (function == SS_EJECT)
 	return 0;
     return atapi_wait_dsc(stp->device, 60*60);
diff -u -r ata/atapi-tape.h /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-tape.h
--- ata/atapi-tape.h	Mon Jun 16 21:28:22 2003
+++ /FreeBSD/FreeBSD-4.x/src/sys/dev/ata/atapi-tape.h	Wed Mar 20 12:20:12 2002
@@ -26,7 +26,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/atapi-tape.h,v 1.11.2.5 2002/03/18 08:37:34 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-tape.h,v 1.2 2003/06/17 04:28:22 dillon Exp $
  */
 
 /* ATAPI tape drive Capabilities and Mechanical Status Page */





More information about the Kernel mailing list