1 /* $OpenBSD: tc_dma_3000_500.c,v 1.7 2017/10/29 08:50:43 mpi Exp $ */
2 /* $NetBSD: tc_dma_3000_500.c,v 1.13 2001/07/19 06:40:03 thorpej Exp $ */
3
4 /*-
5 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #define _ALPHA_BUS_DMA_PRIVATE
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41
42 #include <uvm/uvm_extern.h>
43
44 #include <machine/alpha_cpu.h>
45 #include <machine/bus.h>
46
47 #include <dev/tc/tcvar.h>
48 #include <alpha/tc/tc_conf.h>
49 #include <alpha/tc/tc_3000_500.h>
50 #include <alpha/tc/tc_sgmap.h>
51 #include <alpha/tc/tc_dma_3000_500.h>
52
53 #define KV(x) (ALPHA_PHYS_TO_K0SEG(x))
54
55 struct alpha_sgmap tc_dma_sgmap; /* sgmap shared by all slots */
56
57 struct alpha_bus_dma_tag tc_dmat_sgmap = {
58 NULL, /* _cookie, not used */
59 0, /* _wbase */
60 0x1000000, /* _wsize (256MB: 32K entries) */
61 NULL, /* _next_window */
62 0, /* _boundary */
63 &tc_dma_sgmap, /* _sgmap */
64 NULL, /* _get_tag, not used */
65 alpha_sgmap_dmamap_create,
66 alpha_sgmap_dmamap_destroy,
67 tc_bus_dmamap_load_sgmap,
68 tc_bus_dmamap_load_mbuf_sgmap,
69 tc_bus_dmamap_load_uio_sgmap,
70 tc_bus_dmamap_load_raw_sgmap,
71 tc_bus_dmamap_unload_sgmap,
72 _bus_dmamap_sync,
73 _bus_dmamem_alloc,
74 _bus_dmamem_free,
75 _bus_dmamem_map,
76 _bus_dmamem_unmap,
77 _bus_dmamem_mmap,
78 };
79
80 void
tc_dma_init_3000_500(nslots)81 tc_dma_init_3000_500(nslots)
82 int nslots;
83 {
84 int i;
85 struct alpha_bus_dma_tag *t;
86
87 for (i = 0; i < nslots; i++) {
88 /*
89 * Note that the use of sgmap on a slot is global, so we
90 * can not afford reverting to direct dma (by making
91 * _next_window point to the direct tag).
92 * On the other hand, the sgmap allows for 256MB of
93 * DMA transfers being programmed at the same time for all
94 * the slots, which should not be a liability.
95 */
96 tc_3000_500_ioslot(i, IOSLOT_S, !0);
97 }
98 /*
99 * The TURBOchannel sgmap is shared by all slots.
100 * We need a valid bus_dma_tag_t to pass alpha_sgmap_init() in order
101 * to allocate the sgmap fill page, so pick the first.
102 */
103 t = &tc_dmat_sgmap;
104 alpha_sgmap_init(t, t->_sgmap, "tc_sgmap",
105 t->_wbase, 0, t->_wsize,
106 SGMAP_PTE_SPACING * sizeof(SGMAP_PTE_TYPE),
107 (void *)TC_3000_500_SCMAP, 0);
108 }
109
110 /*
111 * Return the DMA tag for the given slot.
112 */
113 bus_dma_tag_t
tc_dma_get_tag_3000_500(slot)114 tc_dma_get_tag_3000_500(slot)
115 int slot;
116 {
117 return &tc_dmat_sgmap;
118 }
119
120 /*
121 * Load a TURBOchannel SGMAP-mapped DMA map with a linear buffer.
122 */
123 int
tc_bus_dmamap_load_sgmap(t,map,buf,buflen,p,flags)124 tc_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
125 bus_dma_tag_t t;
126 bus_dmamap_t map;
127 void *buf;
128 bus_size_t buflen;
129 struct proc *p;
130 int flags;
131 {
132 return (tc_sgmap_load(t, map, buf, buflen, p, flags, t->_sgmap));
133 }
134
135 /*
136 * Load a TURBOchannel SGMAP-mapped DMA map with an mbuf chain.
137 */
138 int
tc_bus_dmamap_load_mbuf_sgmap(t,map,m,flags)139 tc_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
140 bus_dma_tag_t t;
141 bus_dmamap_t map;
142 struct mbuf *m;
143 int flags;
144 {
145 return (tc_sgmap_load_mbuf(t, map, m, flags, t->_sgmap));
146 }
147
148 /*
149 * Load a TURBOchannel SGMAP-mapped DMA map with a uio.
150 */
151 int
tc_bus_dmamap_load_uio_sgmap(t,map,uio,flags)152 tc_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
153 bus_dma_tag_t t;
154 bus_dmamap_t map;
155 struct uio *uio;
156 int flags;
157 {
158 return (tc_sgmap_load_uio(t, map, uio, flags, t->_sgmap));
159 }
160
161 /*
162 * Load a TURBOchannel SGMAP-mapped DMA map with raw memory.
163 */
164 int
tc_bus_dmamap_load_raw_sgmap(t,map,segs,nsegs,size,flags)165 tc_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
166 bus_dma_tag_t t;
167 bus_dmamap_t map;
168 bus_dma_segment_t *segs;
169 int nsegs;
170 bus_size_t size;
171 int flags;
172 {
173 return (tc_sgmap_load_raw(t, map, segs, nsegs, size, flags, t->_sgmap));
174 }
175
176 /*
177 * Unload a TURBOchannel SGMAP-mapped DMA map.
178 */
179 void
tc_bus_dmamap_unload_sgmap(t,map)180 tc_bus_dmamap_unload_sgmap(t, map)
181 bus_dma_tag_t t;
182 bus_dmamap_t map;
183 {
184 /*
185 * Invalidate any SGMAP page table entries used by this
186 * mapping.
187 */
188 tc_sgmap_unload(t, map, t->_sgmap);
189
190 /*
191 * Do the generic bits of the unload.
192 */
193 _bus_dmamap_unload(t, map);
194 }
195