summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2001-02-19 20:47:03 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2001-02-19 20:47:03 +0000
commitb17b5966654d8347623ebf5cfcf952ae3a80905f (patch)
treefd86bc21f898b58247217c5c8f0729979314167c
parentdcb334b09cab3e5fbb6b818bc8524121d50369af (diff)
propoer dmaable memory allocations
-rw-r--r--sys/dev/ic/twe.c66
1 files changed, 40 insertions, 26 deletions
diff --git a/sys/dev/ic/twe.c b/sys/dev/ic/twe.c
index 123434dcea0..1deb14db3d6 100644
--- a/sys/dev/ic/twe.c
+++ b/sys/dev/ic/twe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: twe.c,v 1.6 2001/01/07 20:27:46 mickey Exp $ */
+/* $OpenBSD: twe.c,v 1.7 2001/02/19 20:47:02 mickey Exp $ */
/*
* Copyright (c) 2000 Michael Shalayeff. All rights reserved.
@@ -44,10 +44,6 @@
#include <machine/bus.h>
-#include <vm/vm.h>
-#include <vm/vm_kern.h>
-#include <uvm/uvm_extern.h>
-
#include <scsi/scsi_all.h>
#include <scsi/scsi_disk.h>
#include <scsi/scsiconf.h>
@@ -118,14 +114,13 @@ twe_dispose(sc)
struct twe_softc *sc;
{
register struct twe_ccb *ccb;
- if (sc->sc_cmdmap != NULL)
- bus_dmamap_destroy(sc->dmat, sc->sc_cmdmap);
/* TODO: traverse the ccbs and destroy the maps */
for (ccb = &sc->sc_ccbs[TWE_MAXCMDS - 1]; ccb >= sc->sc_ccbs; ccb--)
if (ccb->ccb_dmamap)
bus_dmamap_destroy(sc->dmat, ccb->ccb_dmamap);
- uvm_km_free(kmem_map, (vaddr_t)sc->sc_cmds,
- sizeof(struct twe_cmd) * TWE_MAXCMDS);
+ if (sc->sc_cmdmap != NULL)
+ bus_dmamap_destroy(sc->dmat, sc->sc_cmdmap);
+ bus_dmamem_free(sc->dmat, &sc->sc_cmdseg, 1);
}
int
@@ -140,18 +135,24 @@ twe_attach(sc)
struct twe_ccb *ccb;
struct twe_cmd *cmd;
u_int32_t status;
- int error, i, retry, nunits;
+ int error, i, retry, nunits, nseg;
const char *errstr;
- TAILQ_INIT(&sc->sc_ccb2q);
- TAILQ_INIT(&sc->sc_ccbq);
- TAILQ_INIT(&sc->sc_free_ccb);
- sc->sc_cmds = (void *)uvm_km_kmemalloc(kmem_map, uvmexp.kmem_object,
- sizeof(struct twe_cmd) * TWE_MAXCMDS, UVM_KMF_NOWAIT);
- if (sc->sc_cmds == NULL) {
- printf(": cannot allocate commands\n");
+ error = bus_dmamem_alloc(sc->dmat, sizeof(struct twe_cmd) * TWE_MAXCMDS,
+ PAGE_SIZE, 0, &sc->sc_cmdseg, 1, &nseg, BUS_DMA_NOWAIT);
+ if (error) {
+ printf(": cannot allocate commands (%d)\n", error);
return (1);
}
+
+ error = bus_dmamem_map(sc->dmat, &sc->sc_cmdseg, nseg,
+ sizeof(struct twe_cmd) * TWE_MAXCMDS,
+ (caddr_t *)&sc->sc_cmds, BUS_DMA_NOWAIT);
+ if (error) {
+ printf(": cannot map commands (%d)\n", error);
+ return (1);
+ }
+
error = bus_dmamap_create(sc->dmat,
sizeof(struct twe_cmd) * TWE_MAXCMDS, TWE_MAXCMDS,
sizeof(struct twe_cmd) * TWE_MAXCMDS, 0,
@@ -168,6 +169,11 @@ twe_attach(sc)
twe_dispose(sc);
return (1);
}
+
+ TAILQ_INIT(&sc->sc_ccb2q);
+ TAILQ_INIT(&sc->sc_ccbq);
+ TAILQ_INIT(&sc->sc_free_ccb);
+
for (cmd = sc->sc_cmds + sizeof(struct twe_cmd) * (TWE_MAXCMDS - 1);
cmd >= (struct twe_cmd *)sc->sc_cmds; cmd--) {
@@ -396,14 +402,23 @@ twe_cmd(ccb, flags, wait)
bus_dmamap_t dmap;
struct twe_cmd *cmd;
struct twe_segs *sgp;
- int error, i;
+ int error, i, nseg;
if (ccb->ccb_data && ((u_long)ccb->ccb_data & (TWE_ALIGN - 1))) {
TWE_DPRINTF(TWE_D_DMA, ("data=%p is unaligned ",ccb->ccb_data));
ccb->ccb_realdata = ccb->ccb_data;
- ccb->ccb_data = (void *)uvm_km_kmemalloc(kmem_map,
- uvmexp.kmem_object, ccb->ccb_length, UVM_KMF_NOWAIT);
- if (!ccb->ccb_data) {
+
+ error = bus_dmamem_alloc(sc->dmat, ccb->ccb_length,
+ PAGE_SIZE, 0, &ccb->ccb_2bseg, 1, &nseg, BUS_DMA_NOWAIT);
+ if (error) {
+ TWE_DPRINTF(TWE_D_DMA, ("2buf alloc failed "));
+ twe_put_ccb(ccb);
+ return (ENOMEM);
+ }
+
+ error = bus_dmamem_map(sc->dmat, &ccb->ccb_2bseg, nseg,
+ ccb->ccb_length, (caddr_t *)&ccb->ccb_data, BUS_DMA_NOWAIT);
+ if (error) {
TWE_DPRINTF(TWE_D_DMA, ("2buf alloc failed "));
twe_put_ccb(ccb);
return (ENOMEM);
@@ -608,7 +623,7 @@ twe_done(sc, idx)
if (ccb->ccb_realdata) {
bcopy(ccb->ccb_data, ccb->ccb_realdata, ccb->ccb_length);
- uvm_km_free(kmem_map, (vaddr_t)ccb->ccb_data, ccb->ccb_length);
+ bus_dmamem_free(sc->dmat, &ccb->ccb_2bseg, 1);
ccb->ccb_data = ccb->ccb_realdata;
ccb->ccb_realdata = NULL;
}
@@ -851,11 +866,10 @@ twe_scsi_cmd(xs)
TWE_UNLOCK_TWE(sc, lock);
- if (xs->flags & SCSI_POLL) {
- scsi_done(xs);
+ if (xs->flags & SCSI_POLL)
return (COMPLETE);
- }
- return (SUCCESSFULLY_QUEUED);
+ else
+ return (SUCCESSFULLY_QUEUED);
default:
TWE_DPRINTF(TWE_D_CMD, ("unknown opc %d ", xs->cmd->opcode));