xref: /netbsd-src/sys/arch/arm/footbridge/isa/isadma_machdep.c (revision f82ca6eefb335bf699131a4ebe4cc00c8911db8a)
1 /*	$NetBSD: isadma_machdep.c,v 1.17 2022/09/27 06:36:41 skrll Exp $	*/
2 
3 #define ISA_DMA_STATS
4 
5 /*-
6  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
11  * NASA Ames Research Center.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: isadma_machdep.c,v 1.17 2022/09/27 06:36:41 skrll Exp $");
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/syslog.h>
41 #include <sys/device.h>
42 #include <sys/proc.h>
43 #include <sys/mbuf.h>
44 
45 #define _ARM32_BUS_DMA_PRIVATE
46 #include <sys/bus.h>
47 
48 #include <dev/isa/isareg.h>
49 #include <dev/isa/isavar.h>
50 
51 #include <uvm/uvm_extern.h>
52 
53 /*
54  * ISA has a 24-bit address limitation, so at most it has a 16M
55  * DMA range.  However, some platforms have a more limited range,
56  * e.g. the Shark NC.  On these systems, we are provided with
57  * a set of DMA ranges.  The pmap module is aware of these ranges
58  * and places DMA-safe memory for them onto an alternate free list
59  * so that they are protected from being used to service page faults,
60  * etc. (unless we've run out of memory elsewhere).
61  */
62 #define	ISA_DMA_BOUNCE_THRESHOLD	(16 * 1024 * 1024)
63 
64 struct arm32_dma_range *footbridge_isa_dma_ranges;
65 int footbridge_isa_dma_nranges;
66 
67 /*
68  * Entry points for ISA DMA.  These are mostly wrappers around
69  * the generic functions that understand how to deal with bounce
70  * buffers, if necessary.
71  */
72 struct arm32_bus_dma_tag isa_bus_dma_tag = {
73 	_BUS_DMAMAP_FUNCS,
74 	_BUS_DMAMEM_FUNCS,
75 	_BUS_DMATAG_FUNCS,
76 };
77 
78 /*
79  * Initialize ISA DMA.
80  */
81 void
isa_dma_init(void)82 isa_dma_init(void)
83 {
84 
85 	isa_bus_dma_tag._ranges = footbridge_isa_dma_ranges;
86 	isa_bus_dma_tag._nranges = footbridge_isa_dma_nranges;
87 }
88