123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- /* $OpenBSD: isadma.c,v 1.34 2015/03/14 03:38:47 jsg Exp $ */
- /* $NetBSD: isadma.c,v 1.32 1997/09/05 01:48:33 thorpej Exp $ */
- /*-
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
- * NASA Ames Research Center.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * 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.
- */
- /*
- * Device driver for the ISA on-board DMA controller.
- */
- #include <sys/param.h>
- #include <sys/systm.h>
- #include <sys/device.h>
- #include <uvm/uvm_extern.h>
- #include <machine/bus.h>
- #include <dev/isa/isavar.h>
- #include <dev/isa/isadmavar.h>
- #include <dev/isa/isadmareg.h>
- #ifdef __ISADMA_COMPAT
- /* XXX ugly, but will go away soon... */
- struct device *isa_dev;
- bus_dmamap_t isadma_dmam[8];
- #endif
- /* Used by isa_malloc() */
- #include <sys/malloc.h>
- struct isa_mem {
- struct device *isadev;
- int chan;
- bus_size_t size;
- bus_addr_t addr;
- caddr_t kva;
- struct isa_mem *next;
- } *isa_mem_head = 0;
- /*
- * High byte of DMA address is stored in this DMAPG register for
- * the Nth DMA channel.
- */
- static int dmapageport[2][4] = {
- {0x7, 0x3, 0x1, 0x2},
- {0xf, 0xb, 0x9, 0xa}
- };
- static u_int8_t dmamode[4] = {
- DMA37MD_READ | DMA37MD_SINGLE,
- DMA37MD_WRITE | DMA37MD_SINGLE,
- DMA37MD_READ | DMA37MD_SINGLE | DMA37MD_LOOP,
- DMA37MD_WRITE | DMA37MD_SINGLE | DMA37MD_LOOP
- };
- int isadmamatch(struct device *, void *, void *);
- void isadmaattach(struct device *, struct device *, void *);
- struct cfattach isadma_ca = {
- sizeof(struct device), isadmamatch, isadmaattach
- };
- struct cfdriver isadma_cd = {
- NULL, "isadma", DV_DULL, 1
- };
- int
- isadmamatch(parent, match, aux)
- struct device *parent;
- void *match, *aux;
- {
- struct isa_attach_args *ia = aux;
- /* Sure we exist */
- ia->ia_iosize = 0;
- return (1);
- }
- void
- isadmaattach(parent, self, aux)
- struct device *parent, *self;
- void *aux;
- {
- #ifdef __ISADMA_COMPAT
- int i, sz;
- struct isa_softc *sc = (struct isa_softc *)parent;
- /* XXX ugly, but will go away soon... */
- isa_dev = parent;
- for (i = 0; i < 8; i++) {
- sz = (i & 4) ? 1 << 17 : 1 << 16;
- if ((bus_dmamap_create(sc->sc_dmat, sz, 1, sz, sz,
- BUS_DMA_24BIT|BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW,
- &isadma_dmam[i])) != 0)
- panic("isadmaattach: can not create DMA map");
- }
- #endif
- /* XXX I'd like to map the DMA ports here, see isa.c why not... */
- printf("\n");
- }
- static inline void isa_dmaunmask(struct isa_softc *, int);
- static inline void isa_dmamask(struct isa_softc *, int);
- static inline void
- isa_dmaunmask(sc, chan)
- struct isa_softc *sc;
- int chan;
- {
- int ochan = chan & 3;
- /* set dma channel mode, and set dma channel mode */
- if ((chan & 4) == 0)
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h,
- DMA1_SMSK, ochan | DMA37SM_CLEAR);
- else
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h,
- DMA2_SMSK, ochan | DMA37SM_CLEAR);
- }
- static inline void
- isa_dmamask(sc, chan)
- struct isa_softc *sc;
- int chan;
- {
- int ochan = chan & 3;
- /* set dma channel mode, and set dma channel mode */
- if ((chan & 4) == 0) {
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h,
- DMA1_SMSK, ochan | DMA37SM_SET);
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h,
- DMA1_FFC, 0);
- } else {
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h,
- DMA2_SMSK, ochan | DMA37SM_SET);
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h,
- DMA2_FFC, 0);
- }
- }
- /*
- * isa_dmacascade(): program 8237 DMA controller channel to accept
- * external dma control by a board.
- */
- void
- isa_dmacascade(isadev, chan)
- struct device *isadev;
- int chan;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- int ochan = chan & 3;
- if (chan < 0 || chan > 7) {
- printf("%s: bogus drq %d\n", sc->sc_dev.dv_xname, chan);
- goto lose;
- }
- if (ISA_DRQ_ISFREE(sc, chan) == 0) {
- printf("%s: DRQ %d is not free\n", sc->sc_dev.dv_xname, chan);
- goto lose;
- }
- ISA_DRQ_ALLOC(sc, chan);
- /* set dma channel mode, and set dma channel mode */
- if ((chan & 4) == 0)
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h,
- DMA1_MODE, ochan | DMA37MD_CASCADE);
- else
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h,
- DMA2_MODE, ochan | DMA37MD_CASCADE);
- isa_dmaunmask(sc, chan);
- return;
- lose:
- panic("isa_dmacascade");
- }
- int
- isa_dmamap_create(isadev, chan, size, flags)
- struct device *isadev;
- int chan;
- bus_size_t size;
- int flags;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- bus_size_t maxsize;
- if (chan < 0 || chan > 7) {
- printf("%s: bogus drq %d\n", sc->sc_dev.dv_xname, chan);
- goto lose;
- }
- if (chan & 4)
- maxsize = (1 << 17);
- else
- maxsize = (1 << 16);
- if (size > maxsize)
- return (EINVAL);
- if (ISA_DRQ_ISFREE(sc, chan) == 0) {
- printf("%s: drq %d is not free\n", sc->sc_dev.dv_xname, chan);
- goto lose;
- }
- ISA_DRQ_ALLOC(sc, chan);
- return (bus_dmamap_create(sc->sc_dmat, size, 1, size, maxsize,
- flags, &sc->sc_dmamaps[chan]));
- lose:
- panic("isa_dmamap_create");
- }
- void
- isa_dmamap_destroy(isadev, chan)
- struct device *isadev;
- int chan;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- if (chan < 0 || chan > 7) {
- printf("%s: bogus drq %d\n", sc->sc_dev.dv_xname, chan);
- goto lose;
- }
- if (ISA_DRQ_ISFREE(sc, chan)) {
- printf("%s: drq %d is already free\n",
- sc->sc_dev.dv_xname, chan);
- goto lose;
- }
- ISA_DRQ_FREE(sc, chan);
- bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamaps[chan]);
- return;
- lose:
- panic("isa_dmamap_destroy");
- }
- /*
- * isa_dmastart(): program 8237 DMA controller channel and set it
- * in motion.
- */
- int
- isa_dmastart(isadev, chan, addr, nbytes, p, flags, busdmaflags)
- struct device *isadev;
- int chan;
- void *addr;
- bus_size_t nbytes;
- struct proc *p;
- int flags;
- int busdmaflags;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- bus_dmamap_t dmam;
- bus_addr_t dmaaddr;
- int waport;
- int ochan = chan & 3;
- int error;
- #ifdef __ISADMA_COMPAT
- int compat = busdmaflags & BUS_DMA_BUS1;
- busdmaflags &= ~BUS_DMA_BUS1;
- #endif /* __ISADMA_COMPAT */
- if (chan < 0 || chan > 7) {
- printf("%s: bogus drq %d\n", sc->sc_dev.dv_xname, chan);
- goto lose;
- }
- #ifdef ISADMA_DEBUG
- printf("isa_dmastart: drq %d, addr %p, nbytes 0x%lx, p %p, "
- "flags 0x%x, dmaflags 0x%x\n",
- chan, addr, nbytes, p, flags, busdmaflags);
- #endif
- if (chan & 4) {
- if (nbytes > (1 << 17) || nbytes & 1 || (u_long)addr & 1) {
- printf("%s: drq %d, nbytes 0x%lx, addr %p\n",
- sc->sc_dev.dv_xname, chan, nbytes, addr);
- goto lose;
- }
- } else {
- if (nbytes > (1 << 16)) {
- printf("%s: drq %d, nbytes 0x%lx\n",
- sc->sc_dev.dv_xname, chan, nbytes);
- goto lose;
- }
- }
- dmam = sc->sc_dmamaps[chan];
- if (dmam == NULL) {
- #ifdef __ISADMA_COMPAT
- if (compat)
- dmam = sc->sc_dmamaps[chan] = isadma_dmam[chan];
- else
- #endif /* __ISADMA_COMPAT */
- panic("isa_dmastart: no DMA map for chan %d", chan);
- }
- error = bus_dmamap_load(sc->sc_dmat, dmam, addr, nbytes, p,
- busdmaflags);
- if (error)
- return (error);
- #ifdef ISADMA_DEBUG
- __asm(".globl isa_dmastart_afterload ; isa_dmastart_afterload:");
- #endif
- if (flags & DMAMODE_READ) {
- bus_dmamap_sync(sc->sc_dmat, dmam, 0, dmam->dm_mapsize,
- BUS_DMASYNC_PREREAD);
- sc->sc_dmareads |= (1 << chan);
- } else {
- bus_dmamap_sync(sc->sc_dmat, dmam, 0, dmam->dm_mapsize,
- BUS_DMASYNC_PREWRITE);
- sc->sc_dmareads &= ~(1 << chan);
- }
- dmaaddr = dmam->dm_segs[0].ds_addr;
- #ifdef ISADMA_DEBUG
- printf(" dmaaddr 0x%lx\n", dmaaddr);
- __asm(".globl isa_dmastart_aftersync ; isa_dmastart_aftersync:");
- #endif
- sc->sc_dmalength[chan] = nbytes;
- isa_dmamask(sc, chan);
- sc->sc_dmafinished &= ~(1 << chan);
- if ((chan & 4) == 0) {
- /* set dma channel mode */
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h, DMA1_MODE,
- ochan | dmamode[flags]);
- /* send start address */
- waport = DMA1_CHN(ochan);
- bus_space_write_1(sc->sc_iot, sc->sc_dmapgh,
- dmapageport[0][ochan], (dmaaddr >> 16) & 0xff);
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h, waport,
- dmaaddr & 0xff);
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h, waport,
- (dmaaddr >> 8) & 0xff);
- /* send count */
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h, waport + 1,
- (--nbytes) & 0xff);
- bus_space_write_1(sc->sc_iot, sc->sc_dma1h, waport + 1,
- (nbytes >> 8) & 0xff);
- } else {
- /* set dma channel mode */
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h, DMA2_MODE,
- ochan | dmamode[flags]);
- /* send start address */
- waport = DMA2_CHN(ochan);
- bus_space_write_1(sc->sc_iot, sc->sc_dmapgh,
- dmapageport[1][ochan], (dmaaddr >> 16) & 0xff);
- dmaaddr >>= 1;
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h, waport,
- dmaaddr & 0xff);
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h, waport,
- (dmaaddr >> 8) & 0xff);
- /* send count */
- nbytes >>= 1;
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h, waport + 2,
- (--nbytes) & 0xff);
- bus_space_write_1(sc->sc_iot, sc->sc_dma2h, waport + 2,
- (nbytes >> 8) & 0xff);
- }
- isa_dmaunmask(sc, chan);
- return (0);
- lose:
- panic("isa_dmastart");
- }
- void
- isa_dmaabort(isadev, chan)
- struct device *isadev;
- int chan;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- if (chan < 0 || chan > 7) {
- panic("isa_dmaabort: %s: bogus drq %d", sc->sc_dev.dv_xname,
- chan);
- }
- isa_dmamask(sc, chan);
- bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamaps[chan]);
- sc->sc_dmareads &= ~(1 << chan);
- }
- bus_size_t
- isa_dmacount(isadev, chan)
- struct device *isadev;
- int chan;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- int waport;
- bus_size_t nbytes;
- int ochan = chan & 3;
- if (chan < 0 || chan > 7) {
- panic("isa_dmacount: %s: bogus drq %d", sc->sc_dev.dv_xname,
- chan);
- }
- isa_dmamask(sc, chan);
- /*
- * We have to shift the byte count by 1. If we're in auto-initialize
- * mode, the count may have wrapped around to the initial value. We
- * can't use the TC bit to check for this case, so instead we compare
- * against the original byte count.
- * If we're not in auto-initialize mode, then the count will wrap to
- * -1, so we also handle that case.
- */
- if ((chan & 4) == 0) {
- waport = DMA1_CHN(ochan);
- nbytes = bus_space_read_1(sc->sc_iot, sc->sc_dma1h,
- waport + 1) + 1;
- nbytes += bus_space_read_1(sc->sc_iot, sc->sc_dma1h,
- waport + 1) << 8;
- nbytes &= 0xffff;
- } else {
- waport = DMA2_CHN(ochan);
- nbytes = bus_space_read_1(sc->sc_iot, sc->sc_dma2h,
- waport + 2) + 1;
- nbytes += bus_space_read_1(sc->sc_iot, sc->sc_dma2h,
- waport + 2) << 8;
- nbytes <<= 1;
- nbytes &= 0x1ffff;
- }
- if (nbytes == sc->sc_dmalength[chan])
- nbytes = 0;
- isa_dmaunmask(sc, chan);
- return (nbytes);
- }
- int
- isa_dmafinished(isadev, chan)
- struct device *isadev;
- int chan;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- if (chan < 0 || chan > 7) {
- panic("isa_dmafinished: %s: bogus drq %d", sc->sc_dev.dv_xname,
- chan);
- }
- /* check that the terminal count was reached */
- if ((chan & 4) == 0)
- sc->sc_dmafinished |= bus_space_read_1(sc->sc_iot,
- sc->sc_dma1h, DMA1_SR) & 0x0f;
- else
- sc->sc_dmafinished |= (bus_space_read_1(sc->sc_iot,
- sc->sc_dma2h, DMA2_SR) & 0x0f) << 4;
- return ((sc->sc_dmafinished & (1 << chan)) != 0);
- }
- void
- isa_dmadone(isadev, chan)
- struct device *isadev;
- int chan;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- bus_dmamap_t dmam;
- if (chan < 0 || chan > 7) {
- panic("isa_dmadone: %s: bogus drq %d", sc->sc_dev.dv_xname,
- chan);
- }
- dmam = sc->sc_dmamaps[chan];
- isa_dmamask(sc, chan);
- if (isa_dmafinished(isadev, chan) == 0)
- printf("%s: isa_dmadone: channel %d not finished\n",
- sc->sc_dev.dv_xname, chan);
- bus_dmamap_sync(sc->sc_dmat, dmam, 0, dmam->dm_mapsize,
- (sc->sc_dmareads & (1 << chan)) ? BUS_DMASYNC_POSTREAD :
- BUS_DMASYNC_POSTWRITE);
- bus_dmamap_unload(sc->sc_dmat, dmam);
- sc->sc_dmareads &= ~(1 << chan);
- }
- int
- isa_dmamem_alloc(isadev, chan, size, addrp, flags)
- struct device *isadev;
- int chan;
- bus_size_t size;
- bus_addr_t *addrp;
- int flags;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- bus_dma_segment_t seg;
- int error, boundary, rsegs;
- if (chan < 0 || chan > 7) {
- panic("isa_dmamem_alloc: %s: bogus drq %d",
- sc->sc_dev.dv_xname, chan);
- }
- boundary = (chan & 4) ? (1 << 17) : (1 << 16);
- size = round_page(size);
- error = bus_dmamem_alloc(sc->sc_dmat, size, NBPG, boundary,
- &seg, 1, &rsegs, flags);
- if (error)
- return (error);
- *addrp = seg.ds_addr;
- return (0);
- }
- void
- isa_dmamem_free(isadev, chan, addr, size)
- struct device *isadev;
- int chan;
- bus_addr_t addr;
- bus_size_t size;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- bus_dma_segment_t seg;
- if (chan < 0 || chan > 7) {
- panic("isa_dmamem_free: %s: bogus drq %d",
- sc->sc_dev.dv_xname, chan);
- }
- seg.ds_addr = addr;
- seg.ds_len = size;
- bus_dmamem_free(sc->sc_dmat, &seg, 1);
- }
- int
- isa_dmamem_map(isadev, chan, addr, size, kvap, flags)
- struct device *isadev;
- int chan;
- bus_addr_t addr;
- bus_size_t size;
- caddr_t *kvap;
- int flags;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- bus_dma_segment_t seg;
- if (chan < 0 || chan > 7) {
- panic("isa_dmamem_map: %s: bogus drq %d", sc->sc_dev.dv_xname,
- chan);
- }
- seg.ds_addr = addr;
- seg.ds_len = size;
- return (bus_dmamem_map(sc->sc_dmat, &seg, 1, size, kvap, flags));
- }
- void
- isa_dmamem_unmap(isadev, chan, kva, size)
- struct device *isadev;
- int chan;
- caddr_t kva;
- size_t size;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- if (chan < 0 || chan > 7) {
- panic("isa_dmamem_unmap: %s: bogus drq %d",
- sc->sc_dev.dv_xname, chan);
- }
- bus_dmamem_unmap(sc->sc_dmat, kva, size);
- }
- int
- isa_dmamem_mmap(isadev, chan, addr, size, off, prot, flags)
- struct device *isadev;
- int chan;
- bus_addr_t addr;
- bus_size_t size;
- int off, prot, flags;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- bus_dma_segment_t seg;
- if (chan < 0 || chan > 7) {
- panic("isa_dmamem_mmap: %s: bogus drq %d", sc->sc_dev.dv_xname,
- chan);
- }
- if (off < 0)
- return (-1);
- seg.ds_addr = addr;
- seg.ds_len = size;
- return (bus_dmamem_mmap(sc->sc_dmat, &seg, 1, off, prot, flags));
- }
- int
- isa_drq_isfree(isadev, chan)
- struct device *isadev;
- int chan;
- {
- struct isa_softc *sc = (struct isa_softc *)isadev;
- if (chan < 0 || chan > 7) {
- panic("isa_drq_isfree: %s: bogus drq %d", sc->sc_dev.dv_xname,
- chan);
- }
- return ISA_DRQ_ISFREE(sc, chan);
- }
- void *
- isa_malloc(isadev, chan, size, pool, flags)
- struct device *isadev;
- int chan;
- size_t size;
- int pool;
- int flags;
- {
- bus_addr_t addr;
- caddr_t kva;
- int bflags;
- struct isa_mem *m;
- bflags = flags & M_NOWAIT ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
- if (isa_dmamem_alloc(isadev, chan, size, &addr, bflags))
- return 0;
- if (isa_dmamem_map(isadev, chan, addr, size, &kva, bflags)) {
- isa_dmamem_free(isadev, chan, addr, size);
- return 0;
- }
- m = malloc(sizeof(*m), pool, flags);
- if (m == 0) {
- isa_dmamem_unmap(isadev, chan, kva, size);
- isa_dmamem_free(isadev, chan, addr, size);
- return 0;
- }
- m->isadev = isadev;
- m->chan = chan;
- m->size = size;
- m->addr = addr;
- m->kva = kva;
- m->next = isa_mem_head;
- isa_mem_head = m;
- return (void *)kva;
- }
- void
- isa_free(addr, pool)
- void *addr;
- int pool;
- {
- struct isa_mem **mp, *m;
- caddr_t kva = (caddr_t)addr;
- for(mp = &isa_mem_head; *mp && (*mp)->kva != kva; mp = &(*mp)->next)
- ;
- m = *mp;
- if (!m) {
- printf("isa_free: freeing unallocated memory\n");
- return;
- }
- *mp = m->next;
- isa_dmamem_unmap(m->isadev, m->chan, kva, m->size);
- isa_dmamem_free(m->isadev, m->chan, m->addr, m->size);
- free(m, pool, 0);
- }
- paddr_t
- isa_mappage(mem, off, prot)
- void *mem;
- off_t off;
- int prot;
- {
- struct isa_mem *m;
- for(m = isa_mem_head; m && m->kva != (caddr_t)mem; m = m->next)
- ;
- if (!m) {
- printf("isa_mappage: mapping unallocated memory\n");
- return -1;
- }
- return (isa_dmamem_mmap(m->isadev, m->chan, m->addr, m->size, off,
- prot, BUS_DMA_WAITOK));
- }
|