| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: isadma.c,v 1.66 2010/11/13 13:52:03 uebayasi Exp $ */ | | 1 | /* $NetBSD: isadma.c,v 1.66.52.1 2018/06/07 19:39:54 martin Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, |
9 | * NASA Ames Research Center. | | 9 | * NASA Ames Research Center. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -25,53 +25,57 @@ | | | @@ -25,53 +25,57 @@ |
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | /* | | 33 | /* |
34 | * Device driver for the ISA on-board DMA controller. | | 34 | * Device driver for the ISA on-board DMA controller. |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | __KERNEL_RCSID(0, "$NetBSD: isadma.c,v 1.66 2010/11/13 13:52:03 uebayasi Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: isadma.c,v 1.66.52.1 2018/06/07 19:39:54 martin Exp $"); |
39 | | | 39 | |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/systm.h> | | 41 | #include <sys/systm.h> |
42 | #include <sys/proc.h> | | 42 | #include <sys/proc.h> |
43 | #include <sys/device.h> | | 43 | #include <sys/device.h> |
44 | #include <sys/malloc.h> | | 44 | #include <sys/malloc.h> |
45 | | | 45 | |
46 | #include <sys/bus.h> | | 46 | #include <sys/bus.h> |
47 | | | 47 | |
48 | #include <dev/isa/isareg.h> | | 48 | #include <dev/isa/isareg.h> |
49 | #include <dev/isa/isavar.h> | | 49 | #include <dev/isa/isavar.h> |
50 | #include <dev/isa/isadmavar.h> | | 50 | #include <dev/isa/isadmavar.h> |
51 | #include <dev/isa/isadmareg.h> | | 51 | #include <dev/isa/isadmareg.h> |
52 | | | 52 | |
53 | struct isa_mem *isa_mem_head; | | 53 | struct isa_mem *isa_mem_head; |
54 | | | 54 | |
55 | /* | | 55 | /* |
56 | * High byte of DMA address is stored in this DMAPG register for | | 56 | * DMA Channel to Address Page Register offset mapping |
57 | * the Nth DMA channel. | | 57 | * |
| | | 58 | * Offset from IO_DMAPG is stored in this 2D array -- first dimension is |
| | | 59 | * the DMA controller, second dimension is the DMA channel. |
| | | 60 | * |
| | | 61 | * e.g. dmapageport[0][1] gives us the offset for DMA ch 1 on DMA1 |
58 | */ | | 62 | */ |
59 | static int dmapageport[2][4] = { | | 63 | static const int dmapageport[2][4] = { |
60 | {0x7, 0x3, 0x1, 0x2}, | | 64 | {0x6, 0x2, 0x0, 0x1}, |
61 | {0xf, 0xb, 0x9, 0xa} | | 65 | {0xe, 0xa, 0x8, 0x9} |
62 | }; | | 66 | }; |
63 | | | 67 | |
64 | static u_int8_t dmamode[] = { | | 68 | static const u_int8_t dmamode[] = { |
65 | /* write to device/read from device */ | | 69 | /* write to device/read from device */ |
66 | DMA37MD_READ | DMA37MD_SINGLE, | | 70 | DMA37MD_READ | DMA37MD_SINGLE, |
67 | DMA37MD_WRITE | DMA37MD_SINGLE, | | 71 | DMA37MD_WRITE | DMA37MD_SINGLE, |
68 | | | 72 | |
69 | /* write to device/read from device */ | | 73 | /* write to device/read from device */ |
70 | DMA37MD_READ | DMA37MD_DEMAND, | | 74 | DMA37MD_READ | DMA37MD_DEMAND, |
71 | DMA37MD_WRITE | DMA37MD_DEMAND, | | 75 | DMA37MD_WRITE | DMA37MD_DEMAND, |
72 | | | 76 | |
73 | /* write to device/read from device - DMAMODE_LOOP */ | | 77 | /* write to device/read from device - DMAMODE_LOOP */ |
74 | DMA37MD_READ | DMA37MD_SINGLE | DMA37MD_LOOP, | | 78 | DMA37MD_READ | DMA37MD_SINGLE | DMA37MD_LOOP, |
75 | DMA37MD_WRITE | DMA37MD_SINGLE | DMA37MD_LOOP, | | 79 | DMA37MD_WRITE | DMA37MD_SINGLE | DMA37MD_LOOP, |
76 | | | 80 | |
77 | /* write to device/read from device - DMAMODE_LOOPDEMAND */ | | 81 | /* write to device/read from device - DMAMODE_LOOPDEMAND */ |
| @@ -159,27 +163,27 @@ _isa_dmainit(struct isa_dma_state *ids, | | | @@ -159,27 +163,27 @@ _isa_dmainit(struct isa_dma_state *ids, |
159 | } else { | | 163 | } else { |
160 | ids->ids_bst = bst; | | 164 | ids->ids_bst = bst; |
161 | ids->ids_dmat = dmat; | | 165 | ids->ids_dmat = dmat; |
162 | | | 166 | |
163 | /* | | 167 | /* |
164 | * Map the registers used by the ISA DMA controller. | | 168 | * Map the registers used by the ISA DMA controller. |
165 | */ | | 169 | */ |
166 | if (bus_space_map(ids->ids_bst, IO_DMA1, DMA1_IOSIZE, 0, | | 170 | if (bus_space_map(ids->ids_bst, IO_DMA1, DMA1_IOSIZE, 0, |
167 | &ids->ids_dma1h)) | | 171 | &ids->ids_dma1h)) |
168 | panic("_isa_dmainit: unable to map DMA controller #1"); | | 172 | panic("_isa_dmainit: unable to map DMA controller #1"); |
169 | if (bus_space_map(ids->ids_bst, IO_DMA2, DMA2_IOSIZE, 0, | | 173 | if (bus_space_map(ids->ids_bst, IO_DMA2, DMA2_IOSIZE, 0, |
170 | &ids->ids_dma2h)) | | 174 | &ids->ids_dma2h)) |
171 | panic("_isa_dmainit: unable to map DMA controller #2"); | | 175 | panic("_isa_dmainit: unable to map DMA controller #2"); |
172 | if (bus_space_map(ids->ids_bst, IO_DMAPG, 0xf, 0, | | 176 | if (bus_space_map(ids->ids_bst, IO_DMAPG, DMAPG_IOSIZE, 0, |
173 | &ids->ids_dmapgh)) | | 177 | &ids->ids_dmapgh)) |
174 | panic("_isa_dmainit: unable to map DMA page registers"); | | 178 | panic("_isa_dmainit: unable to map DMA page registers"); |
175 | | | 179 | |
176 | /* | | 180 | /* |
177 | * All 8 DMA channels start out "masked". | | 181 | * All 8 DMA channels start out "masked". |
178 | */ | | 182 | */ |
179 | ids->ids_masked = 0xff; | | 183 | ids->ids_masked = 0xff; |
180 | | | 184 | |
181 | /* | | 185 | /* |
182 | * Initialize the max transfer size for each channel, if | | 186 | * Initialize the max transfer size for each channel, if |
183 | * it is not initialized already (i.e. by a bus-dependent | | 187 | * it is not initialized already (i.e. by a bus-dependent |
184 | * front-end). | | 188 | * front-end). |
185 | */ | | 189 | */ |
| @@ -201,27 +205,27 @@ _isa_dmainit(struct isa_dma_state *ids, | | | @@ -201,27 +205,27 @@ _isa_dmainit(struct isa_dma_state *ids, |
201 | } | | 205 | } |
202 | | | 206 | |
203 | void | | 207 | void |
204 | _isa_dmadestroy(struct isa_dma_state *ids) | | 208 | _isa_dmadestroy(struct isa_dma_state *ids) |
205 | { | | 209 | { |
206 | if (!ids->ids_initialized) | | 210 | if (!ids->ids_initialized) |
207 | return; | | 211 | return; |
208 | | | 212 | |
209 | _isa_dmacascade_stop(ids, 4); | | 213 | _isa_dmacascade_stop(ids, 4); |
210 | | | 214 | |
211 | /* | | 215 | /* |
212 | * Unmap the registers used by the ISA DMA controller. | | 216 | * Unmap the registers used by the ISA DMA controller. |
213 | */ | | 217 | */ |
214 | bus_space_unmap(ids->ids_bst, ids->ids_dmapgh, 0xf); | | 218 | bus_space_unmap(ids->ids_bst, ids->ids_dmapgh, DMAPG_IOSIZE); |
215 | bus_space_unmap(ids->ids_bst, ids->ids_dma2h, DMA2_IOSIZE); | | 219 | bus_space_unmap(ids->ids_bst, ids->ids_dma2h, DMA2_IOSIZE); |
216 | bus_space_unmap(ids->ids_bst, ids->ids_dma1h, DMA1_IOSIZE); | | 220 | bus_space_unmap(ids->ids_bst, ids->ids_dma1h, DMA1_IOSIZE); |
217 | | | 221 | |
218 | ids->ids_initialized = 0; | | 222 | ids->ids_initialized = 0; |
219 | } | | 223 | } |
220 | | | 224 | |
221 | /* | | 225 | /* |
222 | * _isa_dmacascade(): program 8237 DMA controller channel to accept | | 226 | * _isa_dmacascade(): program 8237 DMA controller channel to accept |
223 | * external dma control by a board. | | 227 | * external dma control by a board. |
224 | */ | | 228 | */ |
225 | int | | 229 | int |
226 | _isa_dmacascade(struct isa_dma_state *ids, int chan) | | 230 | _isa_dmacascade(struct isa_dma_state *ids, int chan) |
227 | { | | 231 | { |