summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorHugh Graham <hugh@cvs.openbsd.org>2003-02-03 19:43:25 +0000
committerHugh Graham <hugh@cvs.openbsd.org>2003-02-03 19:43:25 +0000
commite833d6e3ca9f6d12cc33c23560330c709b6d7e26 (patch)
tree7360477e165ed97cf9c18dd22b40ff78456916c6 /sys
parent58fa2623cf2a3b8e31f8287a7e6592901912d388 (diff)
From NetBSD: Add functions to allocate mapped-in qbus memory.
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/vax/qbus/uba.c66
-rw-r--r--sys/arch/vax/qbus/ubavar.h20
2 files changed, 82 insertions, 4 deletions
diff --git a/sys/arch/vax/qbus/uba.c b/sys/arch/vax/qbus/uba.c
index a2cf0e51e2d..22e46225f03 100644
--- a/sys/arch/vax/qbus/uba.c
+++ b/sys/arch/vax/qbus/uba.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: uba.c,v 1.6 2002/01/16 20:50:17 miod Exp $ */
-/* $NetBSD: uba.c,v 1.52 2000/06/04 02:14:12 matt Exp $ */
+/* $OpenBSD: uba.c,v 1.7 2003/02/03 19:43:24 hugh 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.
@@ -125,6 +125,68 @@ uba_reset_establish(void (*reset)(struct device *), struct device *dev)
}
/*
+ * 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 --git a/sys/arch/vax/qbus/ubavar.h b/sys/arch/vax/qbus/ubavar.h
index cc401eb8acd..5ed45cbd66e 100644
--- a/sys/arch/vax/qbus/ubavar.h
+++ b/sys/arch/vax/qbus/ubavar.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: ubavar.h,v 1.3 2002/03/14 01:26:48 millert Exp $ */
-/* $NetBSD: ubavar.h,v 1.29 2000/06/04 06:17:04 matt Exp $ */
+/* $OpenBSD: ubavar.h,v 1.4 2003/02/03 19:43:24 hugh 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 @@ struct uba_attach_args {
#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 */
@@ -148,6 +160,10 @@ void uba_attach(struct uba_softc *, unsigned long);
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 */