xref: /openbsd/sys/arch/alpha/pci/irongate_dma.c (revision d415bd75)
1 /*	$OpenBSD: irongate_dma.c,v 1.5 2008/06/26 05:42:08 ray Exp $	*/
2 /* $NetBSD: irongate_dma.c,v 1.3 2000/06/29 08:58:47 mrg Exp $ */
3 
4 /*-
5  * Copyright (c) 2000 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.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * DMA support for the AMD 751 (``Irongate'') core logic chipset.
35  *
36  * The AMD 751 is really unlike all of the other Alpha PCI core logic
37  * chipsets.  Instead, it looks like a normal PC chipset (not surprising,
38  * since it is used for Athlon processors).
39  *
40  * Because of this, it lacks all of the SGMAP hardware normally present
41  * on an Alpha system, and there are no DMA windows.  Instead, a memory
42  * bus address is a PCI DMA address, and ISA DMA above 16M has to be
43  * bounced (this is not unlike the Jensen, actually).
44  */
45 
46 /*
47  * XXX - We should define this before including bus.h, but since other stuff
48  *       pulls in bus.h we must do this here.
49  */
50 #define _ALPHA_BUS_DMA_PRIVATE
51 
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/kernel.h>
55 #include <sys/device.h>
56 #include <sys/malloc.h>
57 
58 #include <uvm/uvm_extern.h>
59 
60 #include <machine/bus.h>
61 
62 #include <dev/pci/pcireg.h>
63 #include <dev/pci/pcivar.h>
64 
65 #include <alpha/pci/irongatereg.h>
66 #include <alpha/pci/irongatevar.h>
67 
68 #include <dev/isa/isareg.h>
69 #include <dev/isa/isavar.h>
70 
71 #include "isadma.h"
72 
73 bus_dma_tag_t irongate_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
74 
75 void
76 irongate_dma_init(struct irongate_config *icp)
77 {
78 	bus_dma_tag_t t;
79 
80 	/*
81 	 * Initialize the DMA tag used for PCI DMA.
82 	 */
83 	t = &icp->ic_dmat_pci;
84 	t->_cookie = icp;
85 	t->_wbase = 0;
86 	t->_wsize = 0x100000000UL;
87 	t->_next_window = NULL;
88 	t->_boundary = 0;
89 	t->_sgmap = NULL;
90 	t->_get_tag = irongate_dma_get_tag;
91 	t->_dmamap_create = _bus_dmamap_create;
92 	t->_dmamap_destroy = _bus_dmamap_destroy;
93 	t->_dmamap_load = _bus_dmamap_load_direct;
94 	t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
95 	t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
96 	t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
97 	t->_dmamap_unload = _bus_dmamap_unload;
98 	t->_dmamap_sync = _bus_dmamap_sync;
99 
100 	t->_dmamem_alloc = _bus_dmamem_alloc;
101 	t->_dmamem_free = _bus_dmamem_free;
102 	t->_dmamem_map = _bus_dmamem_map;
103 	t->_dmamem_unmap = _bus_dmamem_unmap;
104 	t->_dmamem_mmap = _bus_dmamem_mmap;
105 
106 #if NISADMA > 0
107 	/*
108 	 * Initialize the DMA tag used for ISA DMA.
109 	 */
110 	t = &icp->ic_dmat_isa;
111 	t->_cookie = icp;
112 	t->_wbase = 0;
113 	t->_wsize = 0x1000000;
114 	t->_next_window = NULL;
115 	t->_boundary = 0;
116 	t->_sgmap = NULL;
117 	t->_get_tag = irongate_dma_get_tag;
118 	t->_dmamap_create = isadma_bounce_dmamap_create;
119 	t->_dmamap_destroy = isadma_bounce_dmamap_destroy;
120 	t->_dmamap_load = isadma_bounce_dmamap_load;
121 	t->_dmamap_load_mbuf = isadma_bounce_dmamap_load_mbuf;
122 	t->_dmamap_load_uio = isadma_bounce_dmamap_load_uio;
123 	t->_dmamap_load_raw = isadma_bounce_dmamap_load_raw;
124 	t->_dmamap_unload = isadma_bounce_dmamap_unload;
125 	t->_dmamap_sync = isadma_bounce_dmamap_sync;
126 
127 	t->_dmamem_alloc = isadma_bounce_dmamem_alloc;
128 	t->_dmamem_free = _bus_dmamem_free;
129 	t->_dmamem_map = _bus_dmamem_map;
130 	t->_dmamem_unmap = _bus_dmamem_unmap;
131 	t->_dmamem_mmap = _bus_dmamem_mmap;
132 #endif
133 
134 	/* XXX XXX BEGIN XXX XXX */
135 	{							/* XXX */
136 		extern paddr_t alpha_XXX_dmamap_or;		/* XXX */
137 		alpha_XXX_dmamap_or = 0;			/* XXX */
138 	}							/* XXX */
139 	/* XXX XXX END XXX XXX */
140 }
141 
142 /*
143  * Return the bus dma tag to be used for the specified bus type.
144  * INTERNAL USE ONLY!
145  */
146 bus_dma_tag_t
147 irongate_dma_get_tag(bus_dma_tag_t t, alpha_bus_t bustype)
148 {
149 	struct irongate_config *icp = t->_cookie;
150 
151 	switch (bustype) {
152 	case ALPHA_BUS_PCI:
153 	case ALPHA_BUS_EISA:
154 		/*
155 		 * Busses capable of 32-bit DMA get the PCI DMA tag.
156 		 */
157 		return (&icp->ic_dmat_pci);
158 
159 	case ALPHA_BUS_ISA:
160 		/*
161 		 * Lame 24-bit busses have to bounce.
162 		 */
163 		return (&icp->ic_dmat_isa);
164 
165 	default:
166 		panic("irongate_dma_get_tag: shouldn't be here, really...");
167 	}
168 }
169