1 | /* $ZEL: sis1100_dma_alloc_netbsd.c,v 1.4 2004/05/27 23:10:18 wuestner Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Copyright (c) 2001-2004
|
---|
5 | * Matthias Drochner, 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 | #if !defined(__NetBSD__)
|
---|
32 | #error Invalid Operating System
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | /*
|
---|
36 | #include <sys/param.h>
|
---|
37 | #include <sys/systm.h>
|
---|
38 | #include <sys/device.h>
|
---|
39 | #include <sys/select.h>
|
---|
40 | #include <sys/malloc.h>
|
---|
41 | #include <sys/callout.h>
|
---|
42 | #include <sys/signalvar.h>
|
---|
43 | #include <sys/kernel.h>
|
---|
44 | #include <vm/vm.h>
|
---|
45 |
|
---|
46 | #include <dev/pci/pcivar.h>
|
---|
47 | #include <dev/pci/pcidevs.h>
|
---|
48 |
|
---|
49 | #include <dev/pci/sis1100_var.h>
|
---|
50 | #include <dev/pci/sis1100_sc.h>
|
---|
51 | */
|
---|
52 |
|
---|
53 | #if 0
|
---|
54 | paddr_t
|
---|
55 | sis1100_mmap(dev_t dev, off_t off, int prot)
|
---|
56 | {
|
---|
57 | struct sis1100_softc *sc = SIS1100SC(dev);
|
---|
58 | struct sis1100_fdata* fd=SIS1100FD(dev);
|
---|
59 | paddr_t addr=0;
|
---|
60 |
|
---|
61 | switch (fd->subdev) {
|
---|
62 | case sis1100_subdev_remote:
|
---|
63 | if (off>=sc->rem_size)
|
---|
64 | return -1;
|
---|
65 | addr=i386_btop(sc->rem_addr+off);
|
---|
66 | break;
|
---|
67 | case sis1100_subdev_ram:
|
---|
68 | return -1;
|
---|
69 | case sis1100_subdev_ctrl:
|
---|
70 | if (off<sc->reg_size) {
|
---|
71 | addr=i386_btop(sc->reg_addr+off);
|
---|
72 | } else { /* mapped for DMA in userspace ? */
|
---|
73 | if ((off>=fd->mmapdma.off) &&
|
---|
74 | (off-fd->mmapdma.off<fd->mmapdma.size))
|
---|
75 | addr=bus_dmamem_mmap(fd->mmapdma.dmat,
|
---|
76 | &fd->mmapdma.segs, 1,
|
---|
77 | off-fd->mmapdma.off,
|
---|
78 | VM_PROT_READ|VM_PROT_WRITE,
|
---|
79 | BUS_DMA_WAITOK|BUS_DMA_COHERENT);
|
---|
80 | else
|
---|
81 | return -1;
|
---|
82 | }
|
---|
83 | break;
|
---|
84 | case sis1100_subdev_dsp:
|
---|
85 | return -1;
|
---|
86 | }
|
---|
87 | /*
|
---|
88 | printf("mmap(dev=%d, %lld): 0x%08x\n", fd->subdev, off, (unsigned int)addr);
|
---|
89 | */
|
---|
90 | return addr;
|
---|
91 | }
|
---|
92 | #endif
|
---|
93 |
|
---|
94 | int
|
---|
95 | sis1100_dma_alloc(struct sis1100_softc *sc, struct sis1100_fdata* fd,
|
---|
96 | struct sis1100_dma_alloc* d)
|
---|
97 | {
|
---|
98 | int rsegs, res;
|
---|
99 |
|
---|
100 | if (fd->mmapdma.valid) {
|
---|
101 | pINFO(sc, "mmapdma already valid");
|
---|
102 | return EINVAL;
|
---|
103 | }
|
---|
104 |
|
---|
105 | fd->mmapdma.dmat=sc->sc_dmat;
|
---|
106 | fd->mmapdma.size=d->size;
|
---|
107 | fd->mmapdma.off=i386_round_page(sc->reg_size);
|
---|
108 |
|
---|
109 | res=bus_dmamem_alloc(fd->mmapdma.dmat, fd->mmapdma.size, 0, 0,
|
---|
110 | &fd->mmapdma.segs, 1, &rsegs, BUS_DMA_WAITOK);
|
---|
111 | if (res) {
|
---|
112 | printf("%s: dmamem_alloc(%d) failed\n", sc->sc_dev.dv_xname, d->size);
|
---|
113 | return res;
|
---|
114 | }
|
---|
115 |
|
---|
116 | res=bus_dmamem_map(fd->mmapdma.dmat, &fd->mmapdma.segs, 1,
|
---|
117 | fd->mmapdma.size, &fd->mmapdma.kva,
|
---|
118 | BUS_DMA_WAITOK|BUS_DMA_COHERENT);
|
---|
119 | if (res) {
|
---|
120 | printf("%s: bus_dmamem_map(%ld) failed\n", sc->sc_dev.dv_xname,
|
---|
121 | fd->mmapdma.size);
|
---|
122 | return res;
|
---|
123 | }
|
---|
124 |
|
---|
125 | res=bus_dmamap_create(fd->mmapdma.dmat, fd->mmapdma.size, 1,
|
---|
126 | fd->mmapdma.size, 0, BUS_DMA_WAITOK,
|
---|
127 | &fd->mmapdma.dm);
|
---|
128 | if (res) {
|
---|
129 | printf("%s: bus_dmamap_create(%ld) failed\n", sc->sc_dev.dv_xname,
|
---|
130 | fd->mmapdma.size);
|
---|
131 | return res;
|
---|
132 | }
|
---|
133 |
|
---|
134 | res=bus_dmamap_load(fd->mmapdma.dmat, fd->mmapdma.dm, fd->mmapdma.kva,
|
---|
135 | fd->mmapdma.size, NULL, BUS_DMA_WAITOK);
|
---|
136 | if (res) {
|
---|
137 | printf("%s: bus_dmamap_load(%ld) failed\n", sc->sc_dev.dv_xname,
|
---|
138 | fd->mmapdma.size);
|
---|
139 | return res;
|
---|
140 | }
|
---|
141 | fd->mmapdma.valid=1;
|
---|
142 | d->size=fd->mmapdma.size;
|
---|
143 | d->offset=fd->mmapdma.off;
|
---|
144 | d->dma_addr=fd->mmapdma.segs.ds_addr;
|
---|
145 | pINFO(sc, "%ld bytes for DMA mapped", fd->mmapdma.size);
|
---|
146 | return 0;
|
---|
147 | }
|
---|
148 |
|
---|
149 | int
|
---|
150 | sis1100_dma_free(struct sis1100_softc *sc, struct sis1100_fdata* fd,
|
---|
151 | struct sis1100_dma_alloc* d)
|
---|
152 | {
|
---|
153 | if (!fd->mmapdma.valid) return 0;
|
---|
154 | fd->mmapdma.valid=0;
|
---|
155 | bus_dmamap_destroy(fd->mmapdma.dmat, fd->mmapdma.dm);
|
---|
156 | bus_dmamem_unmap(fd->mmapdma.dmat, fd->mmapdma.kva, fd->mmapdma.size);
|
---|
157 | bus_dmamem_free(fd->mmapdma.dmat, &fd->mmapdma.segs, 1);
|
---|
158 | pINFO(sc, "%ld bytes for DMA unmapped", fd->mmapdma.size);
|
---|
159 | return 0;
|
---|
160 | }
|
---|