Subject: Re: wdc VS pciide
To: Samuel.Hornus <Samuel.Hornus@crans.org>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: port-macppc
Date: 06/12/2001 15:15:49
--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=us-ascii

Ops, I think I forgot to attach the patch
here it is.

--
Manuel Bouyer, LIP6, Universite Paris VI.           Manuel.Bouyer@lip6.fr
--

--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

Index: wdc_obio.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/macppc/dev/wdc_obio.c,v
retrieving revision 1.12
diff -u -r1.12 wdc_obio.c
--- wdc_obio.c	2001/06/08 00:32:02	1.12
+++ wdc_obio.c	2001/06/12 13:15:56
@@ -167,10 +167,13 @@
 		sc->sc_dmacmd = dbdma_alloc(sizeof(dbdma_command_t) * 20);
 		sc->sc_dmareg = mapiodev(ca->ca_baseaddr + ca->ca_reg[2],
 					 ca->ca_reg[3]);
-		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA;
+		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_MODE;
+		sc->sc_wdcdev.PIO_cap = 4;
+		sc->sc_wdcdev.DMA_cap = 2;
+	} else {
+		sc->sc_wdcdev.PIO_cap = 0;
 	}
 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
-	sc->sc_wdcdev.PIO_cap = 0;
 	sc->wdc_chanptr = chp;
 	sc->sc_wdcdev.channels = &sc->wdc_chanptr;
 	sc->sc_wdcdev.nchannels = 1;
@@ -178,6 +181,7 @@
 	sc->sc_wdcdev.dma_init = wdc_obio_dma_init;
 	sc->sc_wdcdev.dma_start = wdc_obio_dma_start;
 	sc->sc_wdcdev.dma_finish = wdc_obio_dma_finish;
+	sc->sc_wdcdev.set_modes = adjust_timing;
 	chp->channel = 0;
 	chp->wdc = &sc->sc_wdcdev;
 	chp->ch_queue = malloc(sizeof(struct channel_queue),
@@ -207,7 +211,6 @@
 	if (use_dma)
 		adjust_timing(chp);
 
-	wdc_print_modes(chp);
 }
 
 /* Multiword DMA transfer timings */
@@ -228,24 +231,34 @@
 adjust_timing(chp)
 	struct channel_softc *chp;
 {
-        struct ataparams params;
-	struct ata_drive_datas *drvp = &chp->ch_drive[0];	/* XXX */
+	struct ata_drive_datas *drvp;
 	u_int conf;
-	int mode;
-	int cycle, active, min_cycle, min_active;
+	int drive;
+	int mode = -1;
+	int min_cycle, min_active;
 	int cycle_tick, act_tick, inact_tick, half_tick;
 
-	if (ata_get_params(drvp, AT_POLL, &params) != CMD_OK)
-		return;
 
-	for (mode = 2; mode >= 0; mode--)
-		if (params.atap_dmamode_act & (1 << mode))
-			goto found;
+	for (drive = 0; drive < 2; drive++) {
+		drvp = &chp->ch_drive[drive];
+		if ((drvp->drive_flags & DRIVE) == 0)
+			continue;
+		if (drvp->drive_flags & DRIVE_DMA) {
+			if (mode == -1 || mode > drvp->DMA_mode)
+				mode = drvp->DMA_mode;
+		}
+	}
+	if (mode == -1)
+		/* No active DMA mode is found...  Do nothing. */
+		return;
 
-	/* No active DMA mode is found...  Do nothing. */
-	return;
+	for (drive = 0; drive < 2; drive++) {
+		drvp = &chp->ch_drive[drive];
+		if (drvp->drive_flags & DRIVE)
+			drvp->DMA_mode = mode;
+	}
 
-found:
+		
 	min_cycle = dma_timing[mode].cycle;
 	min_active = dma_timing[mode].active;
 
@@ -254,11 +267,8 @@
 	if (ohare && params.atap_dmatiming_recom < 150)
 		params.atap_dmatiming_recom = 150;
 #endif
-	cycle = max(min_cycle, params.atap_dmatiming_recom);
-	active = min_active + (cycle - min_cycle);		/* XXX */
-
-	cycle_tick = TIME_TO_TICK(cycle);
-	act_tick = TIME_TO_TICK(active);
+	cycle_tick = TIME_TO_TICK(min_cycle);
+	act_tick = TIME_TO_TICK(min_active);
 	inact_tick = cycle_tick - act_tick - 1;
 	if (inact_tick < 1)
 		inact_tick = 1;
@@ -267,8 +277,9 @@
 	bus_space_write_4(chp->cmd_iot, chp->cmd_ioh, CONFIG_REG, conf);
 #if 0
 	printf("conf = 0x%x, cyc = %d (%d ns), act = %d (%d ns), inact = %d\n",
-	    conf, cycle_tick, cycle, act_tick, active, inact_tick);
+	    conf, cycle_tick, min_cycle, act_tick, min_active, inact_tick);
 #endif
+	wdc_print_modes(chp);
 }
 
 int

--x+6KMIRAuhnl3hBn--