summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1996-01-28 22:16:20 +0000
committerwollman <wollman@FreeBSD.org>1996-01-28 22:16:20 +0000
commitc02be74f05c64f577351db45298df1c42fcf75f2 (patch)
tree37f28d8762c4340f63d487d23ac932afd883fb9c
parentfbcc7783adf8c464e809cded0cb18ee191cc9a58 (diff)
downloadFreeBSD-src-c02be74f05c64f577351db45298df1c42fcf75f2.zip
FreeBSD-src-c02be74f05c64f577351db45298df1c42fcf75f2.tar.gz
Implement a prototype interface to bus-master IDE DMA on the Triton
chipset. This does not attempt to do anything special with the timing on the hope that the BIOS will have done the right thing already. The actual interface from the wd driver to the new facility is not implemented yet (this commit being an attempt at prodding someone else to do it because looking at the wd driver always confuses the h*** out of me).
-rw-r--r--sys/conf/files.i3863
-rw-r--r--sys/i386/conf/files.i3863
-rw-r--r--sys/i386/isa/wd.c4
-rw-r--r--sys/i386/isa/wdreg.h47
-rw-r--r--sys/pci/pcisupport.c10
-rw-r--r--sys/pci/wd82371.c308
-rw-r--r--sys/pci/wd82371reg.h80
7 files changed, 446 insertions, 9 deletions
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index 47b1aa5..4027d80 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -1,7 +1,7 @@
# This file tells config what files go into building a kernel,
# files marked standard are always included.
#
-# $Id: files.i386,v 1.124 1996/01/15 10:28:14 phk Exp $
+# $Id: files.i386,v 1.125 1996/01/24 18:47:58 peter Exp $
#
aic7xxx_asm optional ahc device-driver \
dependency "$S/dev/aic7xxx/aic7xxx_asm.c" \
@@ -247,3 +247,4 @@ gnu/i386/fpemul/wm_sqrt.s optional gpl_math_emulate
gnu/i386/isa/dgb.c optional dgb device-driver
gnu/i386/isa/nic3008.c optional nic device-driver
gnu/i386/isa/nic3009.c optional nnic device-driver
+pci/wd82371.c optional wd device-driver
diff --git a/sys/i386/conf/files.i386 b/sys/i386/conf/files.i386
index 47b1aa5..4027d80 100644
--- a/sys/i386/conf/files.i386
+++ b/sys/i386/conf/files.i386
@@ -1,7 +1,7 @@
# This file tells config what files go into building a kernel,
# files marked standard are always included.
#
-# $Id: files.i386,v 1.124 1996/01/15 10:28:14 phk Exp $
+# $Id: files.i386,v 1.125 1996/01/24 18:47:58 peter Exp $
#
aic7xxx_asm optional ahc device-driver \
dependency "$S/dev/aic7xxx/aic7xxx_asm.c" \
@@ -247,3 +247,4 @@ gnu/i386/fpemul/wm_sqrt.s optional gpl_math_emulate
gnu/i386/isa/dgb.c optional dgb device-driver
gnu/i386/isa/nic3008.c optional nic device-driver
gnu/i386/isa/nic3009.c optional nnic device-driver
+pci/wd82371.c optional wd device-driver
diff --git a/sys/i386/isa/wd.c b/sys/i386/isa/wd.c
index bd1a526..44bc86c 100644
--- a/sys/i386/isa/wd.c
+++ b/sys/i386/isa/wd.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)wd.c 7.2 (Berkeley) 5/9/91
- * $Id: wd.c,v 1.102 1996/01/16 18:13:16 phk Exp $
+ * $Id: wd.c,v 1.103 1996/01/27 04:17:52 bde Exp $
*/
/* TODO:
@@ -269,6 +269,8 @@ static struct {
int b_active;
} wdtab[NWDC];
+struct wddma wddma;
+
#ifdef notyet
static struct buf rwdbuf[NWD]; /* buffers for raw IO */
#endif
diff --git a/sys/i386/isa/wdreg.h b/sys/i386/isa/wdreg.h
index b1ceeb7..426d2ff 100644
--- a/sys/i386/isa/wdreg.h
+++ b/sys/i386/isa/wdreg.h
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)wdreg.h 7.1 (Berkeley) 5/9/91
- * $Id: wdreg.h,v 1.9 1995/11/04 13:23:45 bde Exp $
+ * $Id: wdreg.h,v 1.10 1995/11/04 17:07:58 bde Exp $
*/
/*
@@ -142,4 +142,49 @@ struct wdparams {
int wdformat(struct buf *bp);
#endif
+/*
+ * IDE DMA support.
+ * This is based on what is needed for the IDE DMA function of the Intel
+ * Triton chipset; hopefully it's general enough to be used for other
+ * chipsets as well.
+ *
+ * To use this:
+ * For each drive which you might want to do DMA on, call wdd_candma()
+ * to get a cookie. If it returns a null pointer, then the drive
+ * can't do DMA.
+ *
+ * Set up the transfer be calling wdd_dmaprep(). The cookie is what
+ * you got before; vaddr is the virtual address of the buffer to be
+ * written; len is the length of the buffer; and direction is either
+ * B_READ or B_WRITE.
+ *
+ * Send a read/write DMA command to the drive.
+ *
+ * Call wdd_dmastart().
+ *
+ * Wait for an interrupt. Multi-sector transfers will only interrupt
+ * at the end of the transfer.
+ *
+ * Call wdd_dmadone(). It will return the status as defined by the
+ * WDDS_* constants below.
+ */
+struct wddma {
+ void *(*wdd_candma) /* returns a cookie if can do DMA */
+ __P((int ctlr, int drive));
+ int (*wdd_dmaprep) /* prepare DMA hardware */
+ __P((void *cookie, char *vaddr, u_long len, int direction));
+ void (*wdd_dmastart) /* begin DMA transfer */
+ __P((void *cookie));
+ int (*wdd_dmadone) /* DMA transfer completed */
+ __P((void *cookie));
+ int (*wdd_dmastatus) /* return status of DMA */
+ __P((void *cookie));
+};
+
+#define WDDS_ACTIVE 0x0001
+#define WDDS_ERROR 0x0002
+#define WDDS_INTERRUPT 0x0004
+
+extern struct wddma wddma;
+
#endif /* KERNEL */
diff --git a/sys/pci/pcisupport.c b/sys/pci/pcisupport.c
index e185cd3..ea3f73b 100644
--- a/sys/pci/pcisupport.c
+++ b/sys/pci/pcisupport.c
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** $Id: pcisupport.c,v 1.29 1996/01/25 20:38:31 wollman Exp $
+** $Id: pcisupport.c,v 1.30 1996/01/27 20:14:32 wollman Exp $
**
** Device driver for DEC/INTEL PCI chipsets.
**
@@ -107,8 +107,6 @@ chipset_probe (pcici_t tag, pcidi_t type)
return ("Intel 82437 (Triton) PCI cache memory controller");
case 0x122e8086:
return ("Intel 82371 (Triton) PCI-ISA bridge");
- case 0x12308086:
- return ("Intel 82371 (Triton) Bus-master IDE controller");
case 0x04961039:
return ("SiS 85c496");
case 0x04061039:
@@ -501,6 +499,7 @@ static const struct condmsg conf82371fb[] =
{ 0 }
};
+#if 0 /* xxx not used */
static const struct condmsg conf82371fb2[] =
{
/* IDETM -- IDE Timing Register */
@@ -513,6 +512,7 @@ static const struct condmsg conf82371fb2[] =
/* end of list */
{ 0 }
};
+#endif
static char confread (pcici_t config_id, int port)
{
@@ -587,11 +587,11 @@ chipset_attach (pcici_t config_id, int unit)
case 0x122e8086:
writeconfig (config_id, conf82371fb);
break;
+#if 0
case 0x12308086:
- printf("\tI/O Base Address: %#lx\n",
- (u_long)pci_conf_read(config_id, 0x20) & 0xfff0);
writeconfig (config_id, conf82371fb2);
break;
+#endif
};
#endif /* PCI_QUIET */
}
diff --git a/sys/pci/wd82371.c b/sys/pci/wd82371.c
new file mode 100644
index 0000000..34aac8f
--- /dev/null
+++ b/sys/pci/wd82371.c
@@ -0,0 +1,308 @@
+/*
+ * Copyright 1996 Massachusetts Institute of Technology
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby
+ * granted, provided that both the above copyright notice and this
+ * permission notice appear in all copies, that both the above
+ * copyright notice and this permission notice appear in all
+ * supporting documentation, and that the name of M.I.T. not be used
+ * in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. M.I.T. makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
+ * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
+ * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#include "pci.h"
+#if NPCI > 0
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/queue.h>
+#include <sys/proc.h>
+#include <sys/buf.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <machine/cpu.h>
+#include <machine/pmap.h> /* for vtophys */
+
+#include <i386/isa/wdreg.h>
+
+#include <pci/pcivar.h>
+#include <pci/pcireg.h>
+#include <pci/wd82371reg.h>
+
+static void *piix_candma(int, int);
+static int piix_dmasetup(void *, char *, u_long, int);
+static void piix_dmastart(void *);
+static int piix_dmadone(void *);
+static int piix_status(void *);
+
+struct piix_cookie {
+ LIST_ENTRY(piix_cookie) le;
+ int ctlr;
+ int unit;
+ struct piix_prd *prd;
+};
+
+struct piix_softc {
+ unsigned iobase;
+ pcici_t tag;
+ LIST_HEAD(, piix_cookie) cookies;
+};
+
+static struct piix_softc softc;
+
+static struct piix_cookie *
+mkcookie(int ctlr, int unit)
+{
+ struct piix_cookie *cp;
+
+ cp = malloc(sizeof *cp, M_DEVBUF, M_NOWAIT);
+ if (!cp) return cp;
+ cp->ctlr = ctlr;
+ cp->unit = unit;
+ cp->prd = malloc(PRD_ALLOC_SIZE, M_DEVBUF, M_NOWAIT);
+ if (!cp->prd) {
+ FREE(cp, M_DEVBUF);
+ return 0;
+ }
+ LIST_INSERT_HEAD(&softc.cookies, cp, le);
+ return cp;
+}
+
+static char *
+piix_probe(pcici_t tag, pcidi_t type)
+{
+ if (type == 0x12308086)
+ return ("Intel 82371 (Triton) Bus-master IDE controller");
+
+ return 0;
+}
+
+static void
+piix_attach(pcici_t tag, int unit)
+{
+ u_long idetm;
+ int bmista;
+ int iobase;
+
+ if (unit) return;
+
+ softc.tag = tag;
+ iobase = softc.iobase = pci_conf_read(tag, 0x20) & 0xfff0;
+ idetm = pci_conf_read(tag, 0x40);
+
+ LIST_INIT(&softc.cookies);
+
+ if (IDETM_CTLR_0(idetm) & IDETM_ENABLE) {
+ bmista = inb(iobase + BMISTA_PORT);
+ if (bmista & BMISTA_DMA0CAP)
+ mkcookie(0, 0);
+
+ if (bmista & BMISTA_DMA1CAP)
+ mkcookie(0, 1);
+ }
+
+ if (IDETM_CTLR_1(idetm) & IDETM_ENABLE) {
+ bmista = inb(iobase + PIIX_CTLR_1 + BMISTA_PORT);
+ if (bmista & BMISTA_DMA0CAP)
+ mkcookie(1, 0);
+ if (bmista & BMISTA_DMA1CAP)
+ mkcookie(1, 1);
+ }
+
+ wddma.wdd_candma = piix_candma;
+ wddma.wdd_dmaprep = piix_dmasetup;
+ wddma.wdd_dmastart = piix_dmastart;
+ wddma.wdd_dmadone = piix_dmadone;
+ wddma.wdd_dmastatus = piix_status;
+}
+
+static u_long piix_count;
+
+static struct pci_device piix_device = {
+ "piix",
+ piix_probe,
+ piix_attach,
+ &piix_count,
+ 0
+};
+
+DATA_SET(pcidevice_set, piix_device);
+
+/*
+ * Return a cookie if we can do DMA on the specified (ctlr, unit).
+ */
+static void *
+piix_candma(int ctlr, int unit)
+{
+ struct piix_cookie *cp;
+
+ cp = softc.cookies.lh_first;
+ while(cp) {
+ if (cp->unit == unit && cp->ctlr == ctlr)
+ break;
+ cp = cp->le.le_next;
+ }
+
+ return cp;
+}
+
+/*
+ * Set up DMA for cp. It is the responsibility of the caller
+ * to ensure that the controller is idle before this routine
+ * is called.
+ */
+static int
+piix_dmasetup(void *xcp, char *vaddr, u_long count, int dir)
+{
+ struct piix_cookie *cp = xcp;
+ struct piix_prd *prd;
+ int i;
+ u_long pgresid;
+ int iobase;
+
+ prd = cp->prd;
+ i = 0;
+ iobase = softc.iobase + cp->ctlr ? PIIX_CTLR_1 : 0;
+
+ /*
+ * Deal with transfers that don't start on a page
+ * boundary.
+ */
+ pgresid = (u_long)vaddr & ~NBPG;
+ if (pgresid) {
+ prd[i].prd_base = vtophys(vaddr);
+ if (count >= (NBPG - pgresid))
+ prd[i].prd_count = NBPG - pgresid;
+ else
+ prd[i].prd_count = count;
+ vaddr += prd[i].prd_count;
+ count -= prd[i].prd_count;
+ prd[i].prd_eot |= PRD_EOT_BIT;
+ i++;
+ }
+
+ /*
+ * We have now ensured that vaddr is page-aligned, so just
+ * step through the pages adding each one onto the list.
+ */
+ while(count) {
+ u_long phys, n;
+
+ phys = vtophys(vaddr);
+ n = (count > NBPG) ? NBPG : count;
+ /*
+ * If the current page is physically contiguous with
+ * whatever we have in the previous PRD, just tack it
+ * onto the end.
+ * CAVEAT: due to a hardware deficiency, PRDs
+ * cannot cross a 64K boundary.
+ */
+ if (i > 0
+ && phys == prd[i - 1].prd_base + prd[i - 1].prd_count
+ && ((prd[i - 1].prd_base & 0xffff)
+ + prd[i - 1].prd_count + n) <= 65535) {
+
+ prd[i - 1].prd_count += n;
+ } else {
+ if (i > 0)
+ prd[i - 1].prd_eot &= ~PRD_EOT_BIT;
+ prd[i].prd_base = phys;
+ prd[i].prd_count = n;
+ prd[i].prd_eot |= PRD_EOT_BIT;
+ i++;
+ if (i >= PRD_MAX_SEGS)
+ panic("wd82371: too many segments\n");
+ }
+ count -= n;
+ vaddr += n;
+ }
+
+ /* Set up PRD base register */
+ outl(iobase + BMIDTP_PORT, vtophys(prd));
+
+ /* Set direction of transfer */
+ if (dir == B_READ) {
+ outb(iobase + BMICOM_PORT, 0);
+ } else {
+ outb(iobase + BMICOM_PORT, BMICOM_READ_WRITE);
+ }
+
+ /* Clear interrupt and error bits */
+ outb(iobase + BMISTA_PORT,
+ (inb(iobase + BMISTA_PORT)
+ & ~(BMISTA_INTERRUPT | BMISTA_DMA_ERROR)));
+
+ return 0;
+}
+
+static void
+piix_dmastart(void *xcp)
+{
+ struct piix_cookie *cp = xcp;
+ int iobase;
+
+ iobase = softc.iobase + cp->ctlr ? PIIX_CTLR_1 : 0;
+
+ outb(iobase + BMICOM_PORT,
+ inb(iobase + BMICOM_PORT) | BMICOM_STOP_START);
+}
+
+static int
+piix_dmadone(void *xcp)
+{
+ struct piix_cookie *cp = xcp;
+ int iobase, status;
+
+ status = piix_status(xcp);
+ iobase = softc.iobase + cp->ctlr ? PIIX_CTLR_1 : 0;
+
+ outb(iobase + BMICOM_PORT,
+ inb(iobase + BMICOM_PORT) & ~BMICOM_STOP_START);
+
+ return status;
+}
+
+static int
+piix_status(void *xcp)
+{
+ struct piix_cookie *cp = xcp;
+ int iobase, status, bmista;
+
+ status = 0;
+ iobase = softc.iobase + cp->ctlr ? PIIX_CTLR_1 : 0;
+
+ bmista = inb(iobase + BMISTA_PORT);
+
+ if (bmista & BMISTA_INTERRUPT)
+ status |= WDDS_INTERRUPT;
+ if (bmista & BMISTA_DMA_ERROR)
+ status |= WDDS_ERROR;
+ if (bmista & BMISTA_DMA_ACTIVE)
+ status |= WDDS_ACTIVE;
+
+ return status;
+}
+
+#endif /* NPCI > 0 */
diff --git a/sys/pci/wd82371reg.h b/sys/pci/wd82371reg.h
new file mode 100644
index 0000000..33a997f
--- /dev/null
+++ b/sys/pci/wd82371reg.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright 1996 Massachusetts Institute of Technology
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby
+ * granted, provided that both the above copyright notice and this
+ * permission notice appear in all copies, that both the above
+ * copyright notice and this permission notice appear in all
+ * supporting documentation, and that the name of M.I.T. not be used
+ * in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. M.I.T. makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
+ * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
+ * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#ifndef _PCI_WD82371REG_H_
+#define _PCI_WD82371REG_H_ 1
+
+/* Contents of IDETM register, as two 16-bit words (high ctlr 1, low ctlr 0) */
+#define IDETM_ENABLE 0x8000
+#define IDETM_IORDY_SAMP 0x3000 /* 00:5, 01:4, 10:3, 11:2 clocks */
+#define IDETM_RECOVERY_TIME 0x0300 /* 00:4, 01:3, 10:2, 11:1 clocks */
+#define IDETM_TIMING_ENB_1 0x0080
+#define IDETM_PREFETCH_POST_1 0x0040
+#define IDETM_ISP_ENB_1 0x0020 /* enabled IORDY sampling */
+#define IDETM_FAST_TIMING_1 0x0010
+#define IDETM_TIMING_ENB_0 0x0008
+#define IDETM_PREFETCH_POST_0 0x0004
+#define IDETM_ISP_ENB_0 0x0002
+#define IDETM_FAST_TIMING_0 0x0001
+
+#define IDETM_CTLR_0(x) (x)
+#define IDETM_CTLR_1(x) ((x) >> 16)
+
+/* Ports are for controller 0. Add PIIX_CTLR_1 for controller 1. */
+#define PIIX_CTLR_1 8
+
+/* Contents of BMICOM register */
+#define BMICOM_PORT 0
+#define BMICOM_READ_WRITE 0x0008 /* false = read, true = write */
+#define BMICOM_STOP_START 0x0001 /* false = stop, true = start */
+
+/* Contents of BMISTA register */
+#define BMISTA_PORT 2
+#define BMISTA_DMA1CAP 0x0040 /* true = drive 1 can DMA */
+#define BMISTA_DMA0CAP 0x0020 /* true = drive 0 can DMA */
+#define BMISTA_INTERRUPT 0x0004
+#define BMISTA_DMA_ERROR 0x0002
+#define BMISTA_DMA_ACTIVE 0x0001
+
+#define BMIDTP_PORT 4 /* use outl */
+
+struct piix_prd {
+ u_int32_t prd_base;
+ u_int16_t prd_eot;
+ u_int16_t prd_count;
+};
+
+#define PRD_EOT_BIT 0x8000
+
+#define PRD_ALLOC_SIZE 4096
+#define PRD_MAX_SEGS (PRD_ALLOC_SIZE / 4)
+
+#endif /* _PCI_WD82371REG_H_ */
OpenPOWER on IntegriCloud