diff options
author | rik <rik@FreeBSD.org> | 2004-06-23 18:13:10 +0000 |
---|---|---|
committer | rik <rik@FreeBSD.org> | 2004-06-23 18:13:10 +0000 |
commit | 7c1f24f113cdd75f461006273324186a74e573f7 (patch) | |
tree | 3076b9aed8f43d43d0fe617a08a9ebd9208ead1f /sys/dev/cx | |
parent | b597657d93c100a9e52c4ec3f2cb9eb99ec92fe1 (diff) | |
download | FreeBSD-src-7c1f24f113cdd75f461006273324186a74e573f7.zip FreeBSD-src-7c1f24f113cdd75f461006273324186a74e573f7.tar.gz |
Use bus_dma* instead of contigmalloc()+vtophys() for RELENG_5.
Diffstat (limited to 'sys/dev/cx')
-rw-r--r-- | sys/dev/cx/if_cx.c | 154 |
1 files changed, 123 insertions, 31 deletions
diff --git a/sys/dev/cx/if_cx.c b/sys/dev/cx/if_cx.c index 5b69114..f7e57fa 100644 --- a/sys/dev/cx/if_cx.c +++ b/sys/dev/cx/if_cx.c @@ -19,8 +19,9 @@ * as long as this message is kept with the software, all derivative * works or modified versions. * - * Cronyx Id: if_cx.c,v 1.1.2.23 2004/02/26 17:56:40 rik Exp $ + * Cronyx Id: if_cx.c,v 1.1.2.34 2004/06/23 17:09:13 rik Exp $ */ + #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -57,8 +58,8 @@ __FBSDID("$FreeBSD$"); #include <machine/cserial.h> #include <machine/clock.h> #if __FreeBSD_version < 500000 -#include <machine/ipl.h> -#include <i386/isa/isa_device.h> +# include <machine/ipl.h> +# include <i386/isa/isa_device.h> #endif #include <machine/resource.h> #if __FreeBSD_version <= 501000 @@ -142,30 +143,21 @@ static device_method_t cx_isa_methods [] = { {0, 0} }; -typedef struct _bdrv_t { - cx_board_t *board; - struct resource *base_res; - struct resource *drq_res; - struct resource *irq_res; - int base_rid; - int drq_rid; - int irq_rid; - void *intrhand; -} bdrv_t; - -static driver_t cx_isa_driver = { - "cx", - cx_isa_methods, - sizeof (bdrv_t), -}; - -static devclass_t cx_devclass; +typedef struct _cx_dma_mem_t { + unsigned long phys; + void *virt; + size_t size; +#if __FreeBSD_version >= 500000 + bus_dma_tag_t dmat; + bus_dmamap_t mapp; +#endif +} cx_dma_mem_t; typedef struct _drv_t { char name [8]; cx_chan_t *chan; cx_board_t *board; - cx_buf_t buf; + cx_dma_mem_t dmamem; struct tty *tty; struct callout_handle dcd_timeout_handle; unsigned dtrwait; @@ -196,6 +188,26 @@ typedef struct _drv_t { short atimeout; } drv_t; +typedef struct _bdrv_t { + cx_board_t *board; + struct resource *base_res; + struct resource *drq_res; + struct resource *irq_res; + int base_rid; + int drq_rid; + int irq_rid; + void *intrhand; + drv_t channel [NCHAN]; +} bdrv_t; + +static driver_t cx_isa_driver = { + "cx", + cx_isa_methods, + sizeof (bdrv_t), +}; + +static devclass_t cx_devclass; + extern long csigma_fw_len; extern const char *csigma_fw_version; extern const char *csigma_fw_date; @@ -571,6 +583,86 @@ static int cx_probe (device_t dev) return 0; } +#if __FreeBSD_version >= 500000 +static void +cx_bus_dmamap_addr (void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + unsigned long *addr; + + if (error) + return; + + KASSERT(nseg == 1, ("too many DMA segments, %d should be 1", nseg)); + addr = arg; + *addr = segs->ds_addr; +} + +static int +cx_bus_dma_mem_alloc (int bnum, int cnum, cx_dma_mem_t *dmem) +{ + int error; + + error = bus_dma_tag_create (NULL, 16, 0, BUS_SPACE_MAXADDR_24BIT, + BUS_SPACE_MAXADDR, NULL, NULL, dmem->size, 1, + dmem->size, 0, NULL, NULL, &dmem->dmat); + if (error) { + if (cnum >= 0) printf ("cx%d-%d: ", bnum, cnum); + else printf ("cx%d: ", bnum); + printf ("couldn't allocate tag for dma memory\n"); + return 0; + } + error = bus_dmamem_alloc (dmem->dmat, (void **)&dmem->virt, + BUS_DMA_NOWAIT | BUS_DMA_ZERO, &dmem->mapp); + if (error) { + if (cnum >= 0) printf ("cx%d-%d: ", bnum, cnum); + else printf ("cx%d: ", bnum); + printf ("couldn't allocate mem for dma memory\n"); + bus_dma_tag_destroy (dmem->dmat); + return 0; + } + error = bus_dmamap_load (dmem->dmat, dmem->mapp, dmem->virt, + dmem->size, cx_bus_dmamap_addr, &dmem->phys, 0); + if (error) { + if (cnum >= 0) printf ("cx%d-%d: ", bnum, cnum); + else printf ("cx%d: ", bnum); + printf ("couldn't load mem map for dma memory\n"); + bus_dmamem_free (dmem->dmat, dmem->virt, dmem->mapp); + bus_dma_tag_destroy (dmem->dmat); + return 0; + } + return 1; +} + +static void +cx_bus_dma_mem_free (cx_dma_mem_t *dmem) +{ + bus_dmamap_unload (dmem->dmat, dmem->mapp); + bus_dmamem_free (dmem->dmat, dmem->virt, dmem->mapp); + bus_dma_tag_destroy (dmem->dmat); +} +#else +static int +cx_bus_dma_mem_alloc (int bnum, int cnum, cx_dma_mem_t *dmem) +{ + dmem->virt = contigmalloc (dmem->size, M_DEVBUF, M_WAITOK, + 0x100000, 0x1000000, 16, 0); + if (dmem->virt == NULL) { + if (cnum >= 0) printf ("cx%d-%d: ", bnum, cnum); + else printf ("cx%d: ", bnum); + printf ("couldn't allocate memory for dma memory\n", unit); + return 0; + } + dmem->phys = vtophys (dmem->virt); + return 1; +} + +static void +cx_bus_dma_mem_free (cx_dma_mem_t *dmem) +{ + contigfree (dmem->virt, dmem->size, M_DEVBUF); +} +#endif + /* * The adapter is present, initialize the driver structures. */ @@ -717,10 +809,11 @@ static int cx_attach (device_t dev) char *dnmc="cua %x"; if (c->type == T_NONE) continue; - d = contigmalloc (sizeof(drv_t), M_DEVBUF, M_WAITOK, - 0x100000, 0x1000000, 16, 0); + d = &bd->channel[c->num]; + d->dmamem.size = sizeof(cx_buf_t); + if (! cx_bus_dma_mem_alloc (unit, c->num, &d->dmamem)) + continue; channel [b->num*NCHAN + c->num] = d; - bzero (d, sizeof(drv_t)); sprintf (d->name, "cx%d.%d", b->num, c->num); d->board = b; d->chan = c; @@ -741,7 +834,7 @@ static int cx_attach (device_t dev) printf ("%s: cannot make common node\n", d->name); channel [b->num*NCHAN + c->num] = 0; c->sys = 0; - contigfree (d, sizeof (*d), M_DEVBUF); + cx_bus_dma_mem_free (&d->dmamem); continue; } #if __FreeBSD_version >= 500000 @@ -761,7 +854,7 @@ static int cx_attach (device_t dev) #endif channel [b->num*NCHAN + c->num] = 0; c->sys = 0; - contigfree (d, sizeof (*d), M_DEVBUF); + cx_bus_dma_mem_free (&d->dmamem); continue; } d->lo_queue.ifq_maxlen = IFQ_MAXLEN; @@ -793,7 +886,7 @@ static int cx_attach (device_t dev) bpfattach (&d->pp.pp_if, DLT_PPP, 4); #endif /*NETGRAPH*/ } - cx_start_chan (c, &d->buf, vtophys (&d->buf)); + cx_start_chan (c, d->dmamem.virt, d->dmamem.phys); cx_register_receive (c, &cx_receive); cx_register_transmit (c, &cx_transmit); cx_register_error (c, &cx_error); @@ -919,7 +1012,7 @@ static int cx_detach (device_t dev) continue; /* Deallocate buffers. */ - contigfree (d, sizeof (*d), M_DEVBUF); + cx_bus_dma_mem_free (&d->dmamem); } bd->board = 0; adapter [b->num] = 0; @@ -2815,9 +2908,8 @@ static struct ng_type typestruct = { .newhook = ng_cx_newhook, .connect = ng_cx_connect, .rcvdata = ng_cx_rcvdata, - .disconnect = ng_cx_disconnect + .disconnect = ng_cx_disconnect, }; - #endif /*NETGRAPH*/ #if __FreeBSD_version >= 500000 |