xref: /netbsd-src/sys/arch/alpha/pci/irongate_dma.c (revision b13f63840eeeaed6c9aab95a9f055101875df377)
1 /* $NetBSD: irongate_dma.c,v 1.10 2021/07/04 22:42:36 thorpej Exp $ */
2 
3 /*-
4  * Copyright (c) 2000, 2020 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * DMA support for the AMD 751 (``Irongate'') core logic chipset.
34  *
35  * The AMD 751 is really unlike all of the other Alpha PCI core logic
36  * chipsets.  Instead, it looks like a normal PC chipset (not surprising,
37  * since it is used for Athlon processors).
38  *
39  * Because of this, it lacks all of the SGMAP hardware normally present
40  * on an Alpha system, and there are no DMA windows.  Instead, a memory
41  * bus address is a PCI DMA address, and ISA DMA above 16M has to be
42  * bounced (this is not unlike the Jensen, actually).
43  */
44 
45 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
46 
47 __KERNEL_RCSID(0, "$NetBSD: irongate_dma.c,v 1.10 2021/07/04 22:42:36 thorpej Exp $");
48 
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/device.h>
53 
54 #define _ALPHA_BUS_DMA_PRIVATE
55 #include <sys/bus.h>
56 
57 #include <dev/pci/pcireg.h>
58 #include <dev/pci/pcivar.h>
59 
60 #include <alpha/pci/irongatereg.h>
61 #include <alpha/pci/irongatevar.h>
62 
63 #include <dev/isa/isareg.h>
64 #include <dev/isa/isavar.h>
65 
66 #include <machine/alpha.h>
67 
68 static bus_dma_tag_t irongate_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
69 
70 void
irongate_page_physload(unsigned long const start_pfn,unsigned long const end_pfn)71 irongate_page_physload(unsigned long const start_pfn,
72     unsigned long const end_pfn)
73 {
74 	/*
75 	 * The Irongate does not have SGMAP DMA.  For this reason, we
76 	 * need to protect the first 16MB of RAM from random allocations
77 	 * in order to give ISA DMA a snowball's chance of working.
78 	 */
79 	alpha_page_physload_sheltered(start_pfn, end_pfn,
80 	    0, alpha_btop(0x1000000));
81 }
82 
83 void
irongate_dma_init(struct irongate_config * icp)84 irongate_dma_init(struct irongate_config *icp)
85 {
86 	bus_dma_tag_t t;
87 
88 	/*
89 	 * Initialize the DMA tag used for PCI DMA.
90 	 */
91 	t = &icp->ic_dmat_pci;
92 	t->_cookie = icp;
93 	t->_wbase = 0;
94 	t->_wsize = 0x100000000UL;
95 	t->_next_window = NULL;
96 	t->_boundary = 0;
97 	t->_sgmap = NULL;
98 	t->_get_tag = irongate_dma_get_tag;
99 	t->_dmamap_create = _bus_dmamap_create;
100 	t->_dmamap_destroy = _bus_dmamap_destroy;
101 	t->_dmamap_load = _bus_dmamap_load_direct;
102 	t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
103 	t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
104 	t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
105 	t->_dmamap_unload = _bus_dmamap_unload;
106 	t->_dmamap_sync = _bus_dmamap_sync;
107 
108 	t->_dmamem_alloc = _bus_dmamem_alloc;
109 	t->_dmamem_free = _bus_dmamem_free;
110 	t->_dmamem_map = _bus_dmamem_map;
111 	t->_dmamem_unmap = _bus_dmamem_unmap;
112 	t->_dmamem_mmap = _bus_dmamem_mmap;
113 
114 	/*
115 	 * Initialize the DMA tag used for ISA DMA.
116 	 */
117 	t = &icp->ic_dmat_isa;
118 	t->_cookie = icp;
119 	t->_wbase = 0;
120 	t->_wsize = 0x1000000;
121 	t->_next_window = NULL;
122 	t->_boundary = 0;
123 	t->_sgmap = NULL;
124 	t->_get_tag = irongate_dma_get_tag;
125 	t->_dmamap_create = isadma_bounce_dmamap_create;
126 	t->_dmamap_destroy = isadma_bounce_dmamap_destroy;
127 	t->_dmamap_load = isadma_bounce_dmamap_load;
128 	t->_dmamap_load_mbuf = isadma_bounce_dmamap_load_mbuf;
129 	t->_dmamap_load_uio = isadma_bounce_dmamap_load_uio;
130 	t->_dmamap_load_raw = isadma_bounce_dmamap_load_raw;
131 	t->_dmamap_unload = isadma_bounce_dmamap_unload;
132 	t->_dmamap_sync = isadma_bounce_dmamap_sync;
133 
134 	t->_dmamem_alloc = isadma_bounce_dmamem_alloc;
135 	t->_dmamem_free = _bus_dmamem_free;
136 	t->_dmamem_map = _bus_dmamem_map;
137 	t->_dmamem_unmap = _bus_dmamem_unmap;
138 	t->_dmamem_mmap = _bus_dmamem_mmap;
139 }
140 
141 /*
142  * Return the bus dma tag to be used for the specified bus type.
143  * INTERNAL USE ONLY!
144  */
145 static bus_dma_tag_t
irongate_dma_get_tag(bus_dma_tag_t t,alpha_bus_t bustype)146 irongate_dma_get_tag(bus_dma_tag_t t, alpha_bus_t bustype)
147 {
148 	struct irongate_config *icp = t->_cookie;
149 
150 	switch (bustype) {
151 	case ALPHA_BUS_PCI:
152 	case ALPHA_BUS_EISA:
153 		/*
154 		 * Busses capable of 32-bit DMA get the PCI DMA tag.
155 		 */
156 		return (&icp->ic_dmat_pci);
157 
158 	case ALPHA_BUS_ISA:
159 		/*
160 		 * Lame 24-bit busses have to bounce.
161 		 */
162 		return (&icp->ic_dmat_isa);
163 
164 	default:
165 		panic("irongate_dma_get_tag: shouldn't be here, really...");
166 	}
167 }
168