1 | /* $ZEL: plx9054dma_netbsd.c,v 1.2 2004/05/27 23:10:16 wuestner Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Copyright (c) 2003-2004
|
---|
5 | * Peter Wuestner. All rights reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | * 1. Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions, and the following disclaimer.
|
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | *
|
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
---|
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
---|
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
26 | * SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include "sis1100_sc.h"
|
---|
30 |
|
---|
31 | int
|
---|
32 | plx9054_dmaalloc(struct plx9054dma* sc, int maxlen)
|
---|
33 | {
|
---|
34 | bus_dma_tag_t dmat = sc->dmat;
|
---|
35 | int res, rsegs;
|
---|
36 |
|
---|
37 | sc->nsegs = (maxlen + NBPG - 2) / NBPG + 1;
|
---|
38 | #ifdef PLXDEBUG
|
---|
39 | printf("dma: allocating %d descriptors\n", sc->numdescs);
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | res = bus_dmamem_alloc(dmat, sc->nsegs*16, 16, 0, &sc->descsegs, 1,
|
---|
43 | &rsegs, 0);
|
---|
44 | if (res) {
|
---|
45 | printf("%s: bus_dmamem_alloc failed\n", sc->devname);
|
---|
46 | return (res);
|
---|
47 | }
|
---|
48 | res = bus_dmamem_map(dmat, &sc->descsegs, 1, sc->nsegs * 16,
|
---|
49 | (caddr_t *)&sc->descs, 0);
|
---|
50 | if (res) {
|
---|
51 | printf("%s: bus_dmamem_map failed\n", sc->devname);
|
---|
52 | return (res);
|
---|
53 | }
|
---|
54 |
|
---|
55 | res = bus_dmamap_create(dmat, sc->nsegs*16, 1, sc->nsegs*16, 0, 0,
|
---|
56 | &sc->descdma);
|
---|
57 | if (res) {
|
---|
58 | printf("%s: bus_dmamap_create failed\n", sc->devname);
|
---|
59 | return (res);
|
---|
60 | }
|
---|
61 | res = bus_dmamap_load(dmat, sc->descdma, sc->descs, sc->nsegs * 16,
|
---|
62 | NULL, 0);
|
---|
63 | if (res) {
|
---|
64 | printf("%s: bus_dmamap_load failed\n", sc->devname);
|
---|
65 | return (res);
|
---|
66 | }
|
---|
67 |
|
---|
68 | res = bus_dmamap_create(dmat, maxlen, sc->nsegs, maxlen, 0,
|
---|
69 | BUS_DMA_WAITOK|BUS_DMA_ALLOCNOW, &sc->userdma);
|
---|
70 | if (res) {
|
---|
71 | printf("%s: bus_dmamap_create failed\n", sc->devname);
|
---|
72 | return (res);
|
---|
73 | }
|
---|
74 | sc->userdma->dm_mapsize=0;
|
---|
75 | return (0);
|
---|
76 | }
|
---|
77 |
|
---|
78 | void
|
---|
79 | plx9054_dmafree(struct plx9054dma* sc)
|
---|
80 | {
|
---|
81 | if (sc->descdma)
|
---|
82 | bus_dmamap_destroy(sc->dmat, sc->descdma);
|
---|
83 | if (sc->userdma)
|
---|
84 | bus_dmamap_destroy(sc->dmat, sc->userdma);
|
---|
85 | if (sc->descs)
|
---|
86 | bus_dmamem_free(sc->dmat, &sc->descsegs, 1);
|
---|
87 | }
|
---|