Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/qbus Add functions to allocate mapped-in qbus memory.



details:   https://anonhg.NetBSD.org/src/rev/2d4df57b9b23
branches:  trunk
changeset: 509115:2d4df57b9b23
user:      ragge <ragge%NetBSD.org@localhost>
date:      Thu Apr 26 19:16:07 2001 +0000

description:
Add functions to allocate mapped-in qbus memory.

diffstat:

 sys/dev/qbus/uba.c    |  66 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/qbus/ubavar.h |  18 +++++++++++++-
 2 files changed, 82 insertions(+), 2 deletions(-)

diffs (126 lines):

diff -r aea1f5302730 -r 2d4df57b9b23 sys/dev/qbus/uba.c
--- a/sys/dev/qbus/uba.c        Thu Apr 26 18:50:13 2001 +0000
+++ b/sys/dev/qbus/uba.c        Thu Apr 26 19:16:07 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uba.c,v 1.56 2001/04/12 20:08:09 thorpej Exp $    */
+/*     $NetBSD: uba.c,v 1.57 2001/04/26 19:16:07 ragge Exp $      */
 /*
  * Copyright (c) 1996 Jonathan Stone.
  * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
@@ -115,6 +115,8 @@
        struct uba_reset *ur;
 
        ur = malloc(sizeof(struct uba_reset), M_DEVBUF, M_NOWAIT);
+       if (ur == NULL)
+               panic("uba_reset_establish");
        ur->ur_dev = dev;
        ur->ur_reset = reset;
 
@@ -122,6 +124,68 @@
 }
 
 /*
+ * Allocate a bunch of map registers and map them to the given address.
+ */
+int
+uballoc(struct uba_softc *uh, struct ubinfo *ui, int flags)
+{
+       int waitok = (flags & UBA_CANTWAIT) == 0;
+       int error;
+
+       if ((error = bus_dmamap_create(uh->uh_dmat, ui->ui_size, 1,
+           ui->ui_size, 0, (waitok ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT),
+           &ui->ui_dmam)))
+               return error;
+
+       if ((error = bus_dmamap_load(uh->uh_dmat, ui->ui_dmam, ui->ui_vaddr,
+           ui->ui_size, NULL, (waitok ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT)))) {
+               bus_dmamap_destroy(uh->uh_dmat, ui->ui_dmam);
+               return error;
+       }
+       ui->ui_baddr = ui->ui_dmam->dm_segs[0].ds_addr;
+       return 0;
+}
+
+/*
+ * Allocate DMA-able memory and map it on the unibus.
+ */
+int
+ubmemalloc(struct uba_softc *uh, struct ubinfo *ui, int flags)
+{
+       int waitok = (flags & UBA_CANTWAIT ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
+       int error;
+
+       if ((error = bus_dmamem_alloc(uh->uh_dmat, ui->ui_size, NBPG, 0,
+           &ui->ui_seg, 1, &ui->ui_rseg, waitok)))
+               return error;
+       if ((error = bus_dmamem_map(uh->uh_dmat, &ui->ui_seg, ui->ui_rseg,
+           ui->ui_size, &ui->ui_vaddr, waitok|BUS_DMA_COHERENT))) {
+               bus_dmamem_free(uh->uh_dmat, &ui->ui_seg, ui->ui_rseg);
+               return error;
+       }
+       if ((error = uballoc(uh, ui, flags))) {
+               bus_dmamem_unmap(uh->uh_dmat, ui->ui_vaddr, ui->ui_size);
+               bus_dmamem_free(uh->uh_dmat, &ui->ui_seg, ui->ui_rseg);
+       }
+       return error;
+}
+
+void
+ubfree(struct uba_softc *uh, struct ubinfo *ui)
+{
+       bus_dmamap_unload(uh->uh_dmat, ui->ui_dmam);
+       bus_dmamap_destroy(uh->uh_dmat, ui->ui_dmam);
+}
+
+void
+ubmemfree(struct uba_softc *uh, struct ubinfo *ui)
+{
+       bus_dmamem_unmap(uh->uh_dmat, ui->ui_vaddr, ui->ui_size);
+       bus_dmamem_free(uh->uh_dmat, &ui->ui_seg, ui->ui_rseg);
+       ubfree(uh, ui);
+}
+
+/*
  * Generate a reset on uba number uban.         Then
  * call each device that asked to be called during attach,
  * giving it a chance to clean up so as to be able to continue.
diff -r aea1f5302730 -r 2d4df57b9b23 sys/dev/qbus/ubavar.h
--- a/sys/dev/qbus/ubavar.h     Thu Apr 26 18:50:13 2001 +0000
+++ b/sys/dev/qbus/ubavar.h     Thu Apr 26 19:16:07 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ubavar.h,v 1.30 2000/06/05 00:09:18 matt Exp $ */
+/*     $NetBSD: ubavar.h,v 1.31 2001/04/26 19:16:07 ragge Exp $        */
 
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
@@ -135,6 +135,18 @@
 #define        UBA_DONTQUE     0x10            /* Do not enqueue xfer */
 
 /*
+ * Struct for unibus allocation.
+ */
+struct ubinfo {
+       bus_dmamap_t ui_dmam;
+       bus_dma_segment_t ui_seg;
+       int ui_rseg;
+       caddr_t ui_vaddr;
+       bus_addr_t ui_baddr;
+       bus_size_t ui_size;
+};
+
+/*
  * Some common defines for all subtypes of U/Q-buses/adapters.
  */
 #define        MAXUBAXFER      (63*1024)       /* Max transfer size in bytes */
@@ -147,6 +159,10 @@
 void uba_enqueue(struct uba_unit *);
 void uba_done(struct uba_softc *);
 void ubareset(struct uba_softc *);
+int uballoc(struct uba_softc *, struct ubinfo *, int);
+int ubmemalloc(struct uba_softc *, struct ubinfo *, int);
+void ubfree(struct uba_softc *, struct ubinfo *);
+void ubmemfree(struct uba_softc *, struct ubinfo *);
 #endif /* _KERNEL */
 
 #endif /* _QBUS_UBAVAR_H */



Home | Main Index | Thread Index | Old Index