vme.c revision 1.13 1 1.13 tsutsui /* $NetBSD: vme.c,v 1.13 2007/02/03 16:58:08 tsutsui Exp $ */
2 1.1 gwr
3 1.1 gwr /*-
4 1.1 gwr * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 gwr * All rights reserved.
6 1.1 gwr *
7 1.1 gwr * This code is derived from software contributed to The NetBSD Foundation
8 1.1 gwr * by Gordon W. Ross.
9 1.1 gwr *
10 1.1 gwr * Redistribution and use in source and binary forms, with or without
11 1.1 gwr * modification, are permitted provided that the following conditions
12 1.1 gwr * are met:
13 1.1 gwr * 1. Redistributions of source code must retain the above copyright
14 1.1 gwr * notice, this list of conditions and the following disclaimer.
15 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 gwr * notice, this list of conditions and the following disclaimer in the
17 1.1 gwr * documentation and/or other materials provided with the distribution.
18 1.1 gwr * 3. All advertising materials mentioning features or use of this software
19 1.1 gwr * must display the following acknowledgement:
20 1.1 gwr * This product includes software developed by the NetBSD
21 1.1 gwr * Foundation, Inc. and its contributors.
22 1.1 gwr * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 gwr * contributors may be used to endorse or promote products derived
24 1.1 gwr * from this software without specific prior written permission.
25 1.1 gwr *
26 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 gwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 gwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 gwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 gwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 gwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 gwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 gwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 gwr * POSSIBILITY OF SUCH DAMAGE.
37 1.1 gwr */
38 1.8 lukem
39 1.8 lukem #include <sys/cdefs.h>
40 1.13 tsutsui __KERNEL_RCSID(0, "$NetBSD: vme.c,v 1.13 2007/02/03 16:58:08 tsutsui Exp $");
41 1.1 gwr
42 1.1 gwr #include <sys/param.h>
43 1.1 gwr #include <sys/systm.h>
44 1.1 gwr #include <sys/device.h>
45 1.1 gwr
46 1.13 tsutsui #include <uvm/uvm_extern.h>
47 1.13 tsutsui
48 1.13 tsutsui #define _SUN68K_BUS_DMA_PRIVATE
49 1.1 gwr #include <machine/autoconf.h>
50 1.13 tsutsui #include <machine/bus.h>
51 1.13 tsutsui #include <machine/dvma.h>
52 1.13 tsutsui #include <machine/pmap.h>
53 1.13 tsutsui
54 1.13 tsutsui #include <sun3/sun3x/vme.h>
55 1.1 gwr
56 1.2 gwr /* Does this machine have a VME bus? */
57 1.2 gwr extern int cpu_has_vme;
58 1.1 gwr
59 1.4 gwr /*
60 1.4 gwr * Convert vme unit number to bus type,
61 1.4 gwr * but only for supported bus types.
62 1.4 gwr * (See autoconf.h and vme.h)
63 1.4 gwr */
64 1.4 gwr #define VME_UNITS 6
65 1.4 gwr static const struct {
66 1.4 gwr int bustype;
67 1.13 tsutsui const char *name;
68 1.13 tsutsui int pmtype;
69 1.13 tsutsui vaddr_t base;
70 1.13 tsutsui vaddr_t mask;
71 1.4 gwr } vme_info[VME_UNITS] = {
72 1.13 tsutsui { BUS_VME16D16, "A16/D16", PMAP_VME16, VME16_BASE, VME16_MASK },
73 1.13 tsutsui { BUS_VME16D32, "A16/D32", PMAP_VME32, VME16_BASE, VME16_MASK },
74 1.13 tsutsui { BUS_VME24D16, "A24/D16", PMAP_VME16, VME24_BASE, VME24_MASK },
75 1.13 tsutsui { BUS_VME24D32, "A24/D32", PMAP_VME32, VME24_BASE, VME24_MASK },
76 1.13 tsutsui { BUS_VME32D16, "A32/D16", PMAP_VME16, VME32_BASE, VME32_MASK },
77 1.13 tsutsui { BUS_VME32D32, "A32/D32", PMAP_VME32, VME32_BASE, VME32_MASK },
78 1.4 gwr };
79 1.4 gwr
80 1.9 chs static int vme_match(struct device *, struct cfdata *, void *);
81 1.9 chs static void vme_attach(struct device *, struct device *, void *);
82 1.1 gwr
83 1.13 tsutsui struct vme_softc {
84 1.13 tsutsui struct device sc_dev;
85 1.13 tsutsui bus_space_tag_t sc_bustag;
86 1.13 tsutsui bus_dma_tag_t sc_dmatag;
87 1.13 tsutsui int sc_bustype;
88 1.13 tsutsui };
89 1.13 tsutsui
90 1.13 tsutsui CFATTACH_DECL(vme, sizeof(struct vme_softc),
91 1.7 thorpej vme_match, vme_attach, NULL, NULL);
92 1.1 gwr
93 1.13 tsutsui static int vme_bus_map(bus_space_tag_t, bus_type_t, bus_addr_t, bus_size_t,
94 1.13 tsutsui int, vaddr_t, bus_space_handle_t *);
95 1.13 tsutsui static paddr_t vme_bus_mmap(bus_space_tag_t, bus_type_t, bus_addr_t,
96 1.13 tsutsui off_t, int, int);
97 1.13 tsutsui static int vme_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
98 1.13 tsutsui struct proc *, int);
99 1.13 tsutsui
100 1.13 tsutsui static struct sun68k_bus_space_tag vme_space_tag = {
101 1.13 tsutsui NULL, /* cookie */
102 1.13 tsutsui NULL, /* parent bus space tag */
103 1.13 tsutsui vme_bus_map, /* bus_space_map */
104 1.13 tsutsui NULL, /* bus_space_unmap */
105 1.13 tsutsui NULL, /* bus_space_subregion */
106 1.13 tsutsui NULL, /* bus_space_barrier */
107 1.13 tsutsui vme_bus_mmap, /* bus_space_mmap */
108 1.13 tsutsui NULL, /* bus_intr_establish */
109 1.13 tsutsui NULL, /* bus_space_peek_N */
110 1.13 tsutsui NULL /* bus_space_poke_N */
111 1.13 tsutsui };
112 1.13 tsutsui
113 1.13 tsutsui static struct sun68k_bus_dma_tag vme_dma_tag;
114 1.13 tsutsui
115 1.9 chs static int
116 1.9 chs vme_match(struct device *parent, struct cfdata *cf, void *aux)
117 1.1 gwr {
118 1.1 gwr struct confargs *ca = aux;
119 1.4 gwr int unit;
120 1.1 gwr
121 1.2 gwr if (cpu_has_vme == 0)
122 1.1 gwr return (0);
123 1.1 gwr
124 1.2 gwr unit = cf->cf_unit;
125 1.2 gwr if (unit >= VME_UNITS)
126 1.2 gwr return (0);
127 1.4 gwr
128 1.4 gwr if (ca->ca_bustype != vme_info[unit].bustype)
129 1.2 gwr return (0);
130 1.1 gwr
131 1.2 gwr return (1);
132 1.1 gwr }
133 1.1 gwr
134 1.9 chs static void
135 1.9 chs vme_attach(struct device *parent, struct device *self, void *args)
136 1.1 gwr {
137 1.13 tsutsui struct confargs *ca = aux;
138 1.13 tsutsui struct vme_softc *sc = (void *)self;
139 1.13 tsutsui struct confargs vmea;
140 1.4 gwr int unit;
141 1.2 gwr
142 1.12 thorpej unit = device_unit(self);
143 1.4 gwr printf(": (%s)\n", vme_info[unit].name);
144 1.1 gwr
145 1.13 tsutsui sc->sc_bustag = ca->ca_bustag;
146 1.13 tsutsui sc->sc_dmatag = ca->ca_dmatag;
147 1.13 tsutsui sc->sc_bustype = unit;
148 1.13 tsutsui
149 1.13 tsutsui vme_space_tag.cookie = sc;
150 1.13 tsutsui vme_space_tag.parent = sc->sc_bustag;
151 1.13 tsutsui
152 1.13 tsutsui vme_dma_tag = *sc->sc_dmatag;
153 1.13 tsutsui vme_dma_tag._cookie = sc;
154 1.13 tsutsui vme_dma_tag._dmamap_load = vme_dmamap_load;
155 1.13 tsutsui
156 1.13 tsutsui vmea = *ca;
157 1.13 tsutsui vmea.ca_bustag = &vme_space_tag;
158 1.13 tsutsui vmea.ca_dmatag = &vme_dma_tag;
159 1.13 tsutsui
160 1.1 gwr /* We know ca_bustype == BUS_VMExx */
161 1.10 drochner config_search_ia(bus_scan, self, "vme", args);
162 1.1 gwr }
163 1.13 tsutsui
164 1.13 tsutsui int
165 1.13 tsutsui vme_bus_map(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr,
166 1.13 tsutsui bus_size_t size, int flags, vaddr_t vaddr, bus_space_handle_t *hp)
167 1.13 tsutsui {
168 1.13 tsutsui struct vme_softc *sc = t->cookie;
169 1.13 tsutsui paddr_t pa;
170 1.13 tsutsui int bustype, pmtype;
171 1.13 tsutsui
172 1.13 tsutsui bustype = sc->sc_bustype;
173 1.13 tsutsui pa = paddr;
174 1.13 tsutsui pa &= vme_info[bustype].mask;
175 1.13 tsutsui pa |= vme_info[bustype].base;
176 1.13 tsutsui pmtype = vme_info[bustype].pmtype;
177 1.13 tsutsui
178 1.13 tsutsui return bus_space_map2(sc->sc_bustag, pmtype, pa, size,
179 1.13 tsutsui flags | _SUN68K_BUS_MAP_USE_PROM, vaddr, hp);
180 1.13 tsutsui }
181 1.13 tsutsui
182 1.13 tsutsui paddr_t
183 1.13 tsutsui vme_bus_mmap(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr, off_t off,
184 1.13 tsutsui int prot, int flags)
185 1.13 tsutsui {
186 1.13 tsutsui struct vme_softc *sc = t->cookie;
187 1.13 tsutsui paddr_t pa;
188 1.13 tsutsui int bustype, pmtype;
189 1.13 tsutsui
190 1.13 tsutsui bustype = sc->sc_bustype;
191 1.13 tsutsui pa = paddr;
192 1.13 tsutsui pa &= vme_info[bustype].mask;
193 1.13 tsutsui pa |= vme_info[bustype].base;
194 1.13 tsutsui pmtype = vme_info[bustype].pmtype;
195 1.13 tsutsui
196 1.13 tsutsui return bus_space_mmap2(sc->sc_bustag, pmtype, pa, off, prot, flags);
197 1.13 tsutsui }
198 1.13 tsutsui
199 1.13 tsutsui static int
200 1.13 tsutsui vme_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
201 1.13 tsutsui bus_size_t buflen, struct proc *p, int flags)
202 1.13 tsutsui {
203 1.13 tsutsui int error;
204 1.13 tsutsui
205 1.13 tsutsui error = _bus_dmamap_load(t, map, buf, buflen, p, flags);
206 1.13 tsutsui if (error == 0)
207 1.13 tsutsui map->dm_segs[0].ds_addr &= DVMA_VME_SLAVE_MASK;
208 1.13 tsutsui return error;
209 1.13 tsutsui }
210