Deleted Added
full compact
busdma_machdep-v6.c (269217) busdma_machdep-v6.c (269321)
1/*-
2 * Copyright (c) 2012 Ian Lepore
3 * Copyright (c) 2010 Mark Tinguely
4 * Copyright (c) 2004 Olivier Houchard
5 * Copyright (c) 2002 Peter Grehan
6 * Copyright (c) 1997, 1998 Justin T. Gibbs.
7 * All rights reserved.
8 *

--- 17 unchanged lines hidden (view full) ---

26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * From i386/busdma_machdep.c 191438 2009-04-23 20:24:19Z jhb
31 */
32
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2012 Ian Lepore
3 * Copyright (c) 2010 Mark Tinguely
4 * Copyright (c) 2004 Olivier Houchard
5 * Copyright (c) 2002 Peter Grehan
6 * Copyright (c) 1997, 1998 Justin T. Gibbs.
7 * All rights reserved.
8 *

--- 17 unchanged lines hidden (view full) ---

26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * From i386/busdma_machdep.c 191438 2009-04-23 20:24:19Z jhb
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/arm/arm/busdma_machdep-v6.c 269217 2014-07-29 02:38:02Z ian $");
34__FBSDID("$FreeBSD: head/sys/arm/arm/busdma_machdep-v6.c 269321 2014-07-31 03:59:00Z ian $");
35
36#define _ARM32_BUS_DMA_PRIVATE
37#include <sys/param.h>
38#include <sys/kdb.h>
39#include <ddb/ddb.h>
40#include <ddb/db_output.h>
41#include <sys/systm.h>
42#include <sys/malloc.h>
43#include <sys/bus.h>
44#include <sys/busdma_bufalloc.h>
35
36#define _ARM32_BUS_DMA_PRIVATE
37#include <sys/param.h>
38#include <sys/kdb.h>
39#include <ddb/ddb.h>
40#include <ddb/db_output.h>
41#include <sys/systm.h>
42#include <sys/malloc.h>
43#include <sys/bus.h>
44#include <sys/busdma_bufalloc.h>
45#include <sys/counter.h>
45#include <sys/interrupt.h>
46#include <sys/kernel.h>
47#include <sys/ktr.h>
48#include <sys/lock.h>
49#include <sys/memdesc.h>
50#include <sys/proc.h>
51#include <sys/mutex.h>
52#include <sys/sysctl.h>

--- 83 unchanged lines hidden (view full) ---

136
137static struct mtx bounce_lock;
138static int total_bpages;
139static int busdma_zonecount;
140static uint32_t tags_total;
141static uint32_t maps_total;
142static uint32_t maps_dmamem;
143static uint32_t maps_coherent;
46#include <sys/interrupt.h>
47#include <sys/kernel.h>
48#include <sys/ktr.h>
49#include <sys/lock.h>
50#include <sys/memdesc.h>
51#include <sys/proc.h>
52#include <sys/mutex.h>
53#include <sys/sysctl.h>

--- 83 unchanged lines hidden (view full) ---

137
138static struct mtx bounce_lock;
139static int total_bpages;
140static int busdma_zonecount;
141static uint32_t tags_total;
142static uint32_t maps_total;
143static uint32_t maps_dmamem;
144static uint32_t maps_coherent;
144static uint64_t maploads_total;
145static uint64_t maploads_bounced;
146static uint64_t maploads_coherent;
147static uint64_t maploads_dmamem;
148static uint64_t maploads_mbuf;
149static uint64_t maploads_physmem;
145static counter_u64_t maploads_total;
146static counter_u64_t maploads_bounced;
147static counter_u64_t maploads_coherent;
148static counter_u64_t maploads_dmamem;
149static counter_u64_t maploads_mbuf;
150static counter_u64_t maploads_physmem;
150
151static STAILQ_HEAD(, bounce_zone) bounce_zone_list;
152
153SYSCTL_NODE(_hw, OID_AUTO, busdma, CTLFLAG_RD, 0, "Busdma parameters");
154SYSCTL_UINT(_hw_busdma, OID_AUTO, tags_total, CTLFLAG_RD, &tags_total, 0,
151
152static STAILQ_HEAD(, bounce_zone) bounce_zone_list;
153
154SYSCTL_NODE(_hw, OID_AUTO, busdma, CTLFLAG_RD, 0, "Busdma parameters");
155SYSCTL_UINT(_hw_busdma, OID_AUTO, tags_total, CTLFLAG_RD, &tags_total, 0,
155 "Number of active tags");
156 "Number of active tags");
156SYSCTL_UINT(_hw_busdma, OID_AUTO, maps_total, CTLFLAG_RD, &maps_total, 0,
157SYSCTL_UINT(_hw_busdma, OID_AUTO, maps_total, CTLFLAG_RD, &maps_total, 0,
157 "Number of active maps");
158 "Number of active maps");
158SYSCTL_UINT(_hw_busdma, OID_AUTO, maps_dmamem, CTLFLAG_RD, &maps_dmamem, 0,
159SYSCTL_UINT(_hw_busdma, OID_AUTO, maps_dmamem, CTLFLAG_RD, &maps_dmamem, 0,
159 "Number of active maps for bus_dmamem_alloc buffers");
160 "Number of active maps for bus_dmamem_alloc buffers");
160SYSCTL_UINT(_hw_busdma, OID_AUTO, maps_coherent, CTLFLAG_RD, &maps_coherent, 0,
161SYSCTL_UINT(_hw_busdma, OID_AUTO, maps_coherent, CTLFLAG_RD, &maps_coherent, 0,
161 "Number of active maps with BUS_DMA_COHERENT flag set");
162SYSCTL_UQUAD(_hw_busdma, OID_AUTO, maploads_total, CTLFLAG_RD, &maploads_total, 0,
163 "Number of load operations performed");
164SYSCTL_UQUAD(_hw_busdma, OID_AUTO, maploads_bounced, CTLFLAG_RD, &maploads_bounced, 0,
165 "Number of load operations that used bounce buffers");
166SYSCTL_UQUAD(_hw_busdma, OID_AUTO, maploads_coherent, CTLFLAG_RD, &maploads_dmamem, 0,
167 "Number of load operations on BUS_DMA_COHERENT memory");
168SYSCTL_UQUAD(_hw_busdma, OID_AUTO, maploads_dmamem, CTLFLAG_RD, &maploads_dmamem, 0,
169 "Number of load operations on bus_dmamem_alloc buffers");
170SYSCTL_UQUAD(_hw_busdma, OID_AUTO, maploads_mbuf, CTLFLAG_RD, &maploads_mbuf, 0,
171 "Number of load operations for mbufs");
172SYSCTL_UQUAD(_hw_busdma, OID_AUTO, maploads_physmem, CTLFLAG_RD, &maploads_physmem, 0,
173 "Number of load operations on physical buffers");
162 "Number of active maps with BUS_DMA_COHERENT flag set");
163SYSCTL_COUNTER_U64(_hw_busdma, OID_AUTO, maploads_total, CTLFLAG_RD,
164 &maploads_total, "Number of load operations performed");
165SYSCTL_COUNTER_U64(_hw_busdma, OID_AUTO, maploads_bounced, CTLFLAG_RD,
166 &maploads_bounced, "Number of load operations that used bounce buffers");
167SYSCTL_COUNTER_U64(_hw_busdma, OID_AUTO, maploads_coherent, CTLFLAG_RD,
168 &maploads_dmamem, "Number of load operations on BUS_DMA_COHERENT memory");
169SYSCTL_COUNTER_U64(_hw_busdma, OID_AUTO, maploads_dmamem, CTLFLAG_RD,
170 &maploads_dmamem, "Number of load operations on bus_dmamem_alloc buffers");
171SYSCTL_COUNTER_U64(_hw_busdma, OID_AUTO, maploads_mbuf, CTLFLAG_RD,
172 &maploads_mbuf, "Number of load operations for mbufs");
173SYSCTL_COUNTER_U64(_hw_busdma, OID_AUTO, maploads_physmem, CTLFLAG_RD,
174 &maploads_physmem, "Number of load operations on physical buffers");
174SYSCTL_INT(_hw_busdma, OID_AUTO, total_bpages, CTLFLAG_RD, &total_bpages, 0,
175SYSCTL_INT(_hw_busdma, OID_AUTO, total_bpages, CTLFLAG_RD, &total_bpages, 0,
175 "Total bounce pages");
176 "Total bounce pages");
176
177struct bus_dmamap {
178 struct bp_list bpages;
179 int pagesneeded;
180 int pagesreserved;
181 bus_dma_tag_t dmat;
182 struct memdesc mem;
183 pmap_t pmap;

--- 30 unchanged lines hidden (view full) ---

214
215static busdma_bufalloc_t coherent_allocator; /* Cache of coherent buffers */
216static busdma_bufalloc_t standard_allocator; /* Cache of standard buffers */
217static void
218busdma_init(void *dummy)
219{
220 int uma_flags;
221
177
178struct bus_dmamap {
179 struct bp_list bpages;
180 int pagesneeded;
181 int pagesreserved;
182 bus_dma_tag_t dmat;
183 struct memdesc mem;
184 pmap_t pmap;

--- 30 unchanged lines hidden (view full) ---

215
216static busdma_bufalloc_t coherent_allocator; /* Cache of coherent buffers */
217static busdma_bufalloc_t standard_allocator; /* Cache of standard buffers */
218static void
219busdma_init(void *dummy)
220{
221 int uma_flags;
222
223 maploads_total = counter_u64_alloc(M_WAITOK);
224 maploads_bounced = counter_u64_alloc(M_WAITOK);
225 maploads_coherent = counter_u64_alloc(M_WAITOK);
226 maploads_dmamem = counter_u64_alloc(M_WAITOK);
227 maploads_mbuf = counter_u64_alloc(M_WAITOK);
228 maploads_physmem = counter_u64_alloc(M_WAITOK);
229
222 uma_flags = 0;
223
224 /* Create a cache of buffers in standard (cacheable) memory. */
225 standard_allocator = busdma_bufalloc_create("buffer",
226 arm_dcache_align, /* minimum_alignment */
227 NULL, /* uma_alloc func */
228 NULL, /* uma_free func */
229 uma_flags); /* uma_zcreate_flags */

--- 15 unchanged lines hidden (view full) ---

245 arm_dcache_align, /* minimum_alignment */
246 busdma_bufalloc_alloc_uncacheable,
247 busdma_bufalloc_free_uncacheable,
248 uma_flags); /* uma_zcreate_flags */
249}
250
251/*
252 * This init historically used SI_SUB_VM, but now the init code requires
230 uma_flags = 0;
231
232 /* Create a cache of buffers in standard (cacheable) memory. */
233 standard_allocator = busdma_bufalloc_create("buffer",
234 arm_dcache_align, /* minimum_alignment */
235 NULL, /* uma_alloc func */
236 NULL, /* uma_free func */
237 uma_flags); /* uma_zcreate_flags */

--- 15 unchanged lines hidden (view full) ---

253 arm_dcache_align, /* minimum_alignment */
254 busdma_bufalloc_alloc_uncacheable,
255 busdma_bufalloc_free_uncacheable,
256 uma_flags); /* uma_zcreate_flags */
257}
258
259/*
260 * This init historically used SI_SUB_VM, but now the init code requires
253 * malloc(9) using M_DEVBUF memory, which is set up later than SI_SUB_VM, by
254 * SI_SUB_KMEM and SI_ORDER_THIRD, so we'll go right after that by using
255 * SI_SUB_KMEM and SI_ORDER_FOURTH.
261 * malloc(9) using M_DEVBUF memory and the pcpu zones for counter(9), which get
262 * set up by SI_SUB_KMEM and SI_ORDER_LAST, so we'll go right after that by
263 * using SI_SUB_KMEM+1.
256 */
264 */
257SYSINIT(busdma, SI_SUB_KMEM, SI_ORDER_FOURTH, busdma_init, NULL);
265SYSINIT(busdma, SI_SUB_KMEM+1, SI_ORDER_FIRST, busdma_init, NULL);
258
259/*
260 * This routine checks the exclusion zone constraints from a tag against the
261 * physical RAM available on the machine. If a tag specifies an exclusion zone
262 * but there's no RAM in that zone, then we avoid allocating resources to bounce
263 * a request, and we can use any memory allocator (as opposed to needing
264 * kmem_alloc_contig() just because it can allocate pages in an address range).
265 *

--- 766 unchanged lines hidden (view full) ---

1032{
1033 bus_addr_t curaddr;
1034 bus_size_t sgsize;
1035 int error;
1036
1037 if (segs == NULL)
1038 segs = map->segments;
1039
266
267/*
268 * This routine checks the exclusion zone constraints from a tag against the
269 * physical RAM available on the machine. If a tag specifies an exclusion zone
270 * but there's no RAM in that zone, then we avoid allocating resources to bounce
271 * a request, and we can use any memory allocator (as opposed to needing
272 * kmem_alloc_contig() just because it can allocate pages in an address range).
273 *

--- 766 unchanged lines hidden (view full) ---

1040{
1041 bus_addr_t curaddr;
1042 bus_size_t sgsize;
1043 int error;
1044
1045 if (segs == NULL)
1046 segs = map->segments;
1047
1040 maploads_total++;
1041 maploads_physmem++;
1048 counter_u64_add(maploads_total, 1);
1049 counter_u64_add(maploads_physmem, 1);
1042
1043 if (might_bounce(dmat, map, buflen, buflen)) {
1044 _bus_dmamap_count_phys(dmat, map, buf, buflen, flags);
1045 if (map->pagesneeded != 0) {
1050
1051 if (might_bounce(dmat, map, buflen, buflen)) {
1052 _bus_dmamap_count_phys(dmat, map, buf, buflen, flags);
1053 if (map->pagesneeded != 0) {
1046 maploads_bounced++;
1054 counter_u64_add(maploads_bounced, 1);
1047 error = _bus_dmamap_reserve_pages(dmat, map, flags);
1048 if (error)
1049 return (error);
1050 }
1051 }
1052
1053 while (buflen > 0) {
1054 curaddr = buf;

--- 46 unchanged lines hidden (view full) ---

1101 int *segp)
1102{
1103 bus_size_t sgsize;
1104 bus_addr_t curaddr;
1105 vm_offset_t vaddr;
1106 struct sync_list *sl;
1107 int error;
1108
1055 error = _bus_dmamap_reserve_pages(dmat, map, flags);
1056 if (error)
1057 return (error);
1058 }
1059 }
1060
1061 while (buflen > 0) {
1062 curaddr = buf;

--- 46 unchanged lines hidden (view full) ---

1109 int *segp)
1110{
1111 bus_size_t sgsize;
1112 bus_addr_t curaddr;
1113 vm_offset_t vaddr;
1114 struct sync_list *sl;
1115 int error;
1116
1109 maploads_total++;
1117 counter_u64_add(maploads_total, 1);
1110 if (map->flags & DMAMAP_COHERENT)
1118 if (map->flags & DMAMAP_COHERENT)
1111 maploads_coherent++;
1119 counter_u64_add(maploads_coherent, 1);
1112 if (map->flags & DMAMAP_DMAMEM_ALLOC)
1120 if (map->flags & DMAMAP_DMAMEM_ALLOC)
1113 maploads_dmamem++;
1121 counter_u64_add(maploads_dmamem, 1);
1114
1115 if (segs == NULL)
1116 segs = map->segments;
1117
1118 if (flags & BUS_DMA_LOAD_MBUF) {
1122
1123 if (segs == NULL)
1124 segs = map->segments;
1125
1126 if (flags & BUS_DMA_LOAD_MBUF) {
1119 maploads_mbuf++;
1127 counter_u64_add(maploads_mbuf, 1);
1120 map->flags |= DMAMAP_MBUF;
1121 }
1122
1123 map->pmap = pmap;
1124
1125 if (might_bounce(dmat, map, (bus_addr_t)buf, buflen)) {
1126 _bus_dmamap_count_pages(dmat, map, buf, buflen, flags);
1127 if (map->pagesneeded != 0) {
1128 map->flags |= DMAMAP_MBUF;
1129 }
1130
1131 map->pmap = pmap;
1132
1133 if (might_bounce(dmat, map, (bus_addr_t)buf, buflen)) {
1134 _bus_dmamap_count_pages(dmat, map, buf, buflen, flags);
1135 if (map->pagesneeded != 0) {
1128 maploads_bounced++;
1136 counter_u64_add(maploads_bounced, 1);
1129 error = _bus_dmamap_reserve_pages(dmat, map, flags);
1130 if (error)
1131 return (error);
1132 }
1133 }
1134
1135 sl = NULL;
1136 vaddr = (vm_offset_t)buf;

--- 541 unchanged lines hidden ---
1137 error = _bus_dmamap_reserve_pages(dmat, map, flags);
1138 if (error)
1139 return (error);
1140 }
1141 }
1142
1143 sl = NULL;
1144 vaddr = (vm_offset_t)buf;

--- 541 unchanged lines hidden ---