neptune.c revision 1.1.2.4 1 /* $NetBSD: neptune.c,v 1.1.2.4 1999/02/13 17:57:50 minoura Exp $ */
2
3 /*
4 *
5 * Copyright (c) 1998 NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Minoura Makoto.
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 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Charles D. Cranor and
22 * Washington University.
23 * 4. The name of the author may not be used to endorse or promote products
24 * derived from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Neptune-X -- X68k-ISA Bus Bridge
40 */
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46
47 #include <machine/bus.h>
48 #include <machine/cpu.h>
49 #include <machine/frame.h>
50
51 #include <arch/x68k/dev/intiovar.h>
52 #include <arch/x68k/dev/neptunevar.h>
53
54 /* bus_space stuff */
55 static int neptune_bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t,
56 int, bus_space_handle_t*));
57 static void neptune_bus_space_unmap __P((bus_space_tag_t,
58 bus_space_handle_t, bus_size_t));
59 static int neptune_bus_space_subregion __P((bus_space_tag_t, bus_space_handle_t,
60 bus_size_t, bus_size_t,
61 bus_space_handle_t*));
62
63 static struct x68k_bus_space neptune_bus = {
64 #if 0
65 X68K_NEPUTUNE_BUS,
66 #endif
67 neptune_bus_space_map, neptune_bus_space_unmap,
68 neptune_bus_space_subregion,
69 x68k_bus_space_alloc, x68k_bus_space_free,
70
71 x68k_bus_space_read_1,
72 x68k_bus_space_read_2,
73 x68k_bus_space_read_4,
74 x68k_bus_space_read_multi_1,
75 x68k_bus_space_read_multi_2,
76 x68k_bus_space_read_multi_4,
77 x68k_bus_space_read_region_1,
78 x68k_bus_space_read_region_2,
79 x68k_bus_space_read_region_4,
80
81 x68k_bus_space_write_1,
82 x68k_bus_space_write_2,
83 x68k_bus_space_write_4,
84 x68k_bus_space_write_multi_1,
85 x68k_bus_space_write_multi_2,
86 x68k_bus_space_write_multi_4,
87 x68k_bus_space_write_region_1,
88 x68k_bus_space_write_region_2,
89 x68k_bus_space_write_region_4,
90
91 x68k_bus_space_set_region_1,
92 x68k_bus_space_set_region_2,
93 x68k_bus_space_set_region_4,
94 x68k_bus_space_copy_region_1,
95 x68k_bus_space_copy_region_2,
96 x68k_bus_space_copy_region_4
97 };
98
99
100 static int neptune_match __P((struct device *, struct cfdata *, void *));
101 static void neptune_attach __P((struct device *, struct device *, void *));
102 static int neptune_search __P((struct device *, struct cfdata *cf, void *));
103 static int neptune_print __P((void *, const char *));
104
105 struct cfattach neptune_ca = {
106 sizeof(struct neptune_softc), neptune_match, neptune_attach
107 };
108
109 static int
110 neptune_match(parent, cf, aux)
111 struct device *parent;
112 struct cfdata *cf;
113 void *aux;
114 {
115 struct intio_attach_args *ia = aux;
116
117 if (strcmp(ia->ia_name, "neptune") != 0)
118 return 0;
119
120 ia->ia_size = 0x400;
121 if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY))
122 return 0;
123
124 /* Neptune is a virtual device. Always there. */
125
126 return (1);
127 }
128
129
130 static void
131 neptune_attach(parent, self, aux)
132 struct device *parent, *self;
133 void *aux;
134 {
135 struct neptune_softc *sc = (struct neptune_softc *)self;
136 struct intio_attach_args *ia = aux;
137 struct neptune_attach_args na;
138 int r;
139 struct cfdata *cf;
140
141 ia->ia_size = 0x400;
142 r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
143 #ifdef DIAGNOSTIC
144 if (r)
145 panic ("IO map for Neptune corruption??");
146 #endif
147
148 sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_NOWAIT);
149 if (sc->sc_bst == NULL)
150 panic("neptune_attach: can't allocate bus_space structure");
151 *sc->sc_bst = neptune_bus;
152 sc->sc_bst->x68k_bus_device = self;
153
154 sc->sc_addr = (vaddr_t) (ia->ia_addr - PHYS_INTIODEV + intiobase);
155
156 na.na_bst = sc->sc_bst;
157 na.na_intr = ia->ia_intr;
158
159 cf = config_search (neptune_search, self, &na);
160 if (cf) {
161 printf (": Neptune-X ISA bridge\n");
162 config_attach(self, cf, &na, neptune_print);
163 } else {
164 printf (": no device found.\n");
165 intio_map_free_region(parent, ia);
166 }
167 }
168
169 static int
170 neptune_search(parent, cf, aux)
171 struct device *parent;
172 struct cfdata *cf;
173 void *aux;
174 {
175 struct neptune_attach_args *na = aux;
176
177 na->na_addr = cf->neptune_cf_addr;
178
179 return (*cf->cf_attach->ca_match)(parent, cf, na);
180 }
181
182 static int
183 neptune_print(aux, name)
184 void *aux;
185 const char *name;
186 {
187 struct neptune_attach_args *na = aux;
188
189 /* if (na->na_addr > 0) */
190 printf (" addr 0x%06x", na->na_addr);
191
192 return (QUIET);
193 }
194
195
196 /*
197 * neptune bus space stuff.
198 */
199 static int
200 neptune_bus_space_map(t, bpa, size, flags, bshp)
201 bus_space_tag_t t;
202 bus_addr_t bpa;
203 bus_size_t size;
204 int flags;
205 bus_space_handle_t *bshp;
206 {
207 vaddr_t start = ((struct neptune_softc*) ((struct x68k_bus_space*) t)
208 ->x68k_bus_device)->sc_addr;
209
210 /*
211 * Neptune bus is mapped permanently.
212 */
213 *bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2);
214
215 if (badaddr(*bshp)) {
216 printf ("XXX\n");
217 return 1;
218 }
219
220 *bshp |= 0x80000000; /* higher byte (= even address) only */
221
222 return (0);
223 }
224
225 static void
226 neptune_bus_space_unmap(t, bsh, size)
227 bus_space_tag_t t;
228 bus_space_handle_t bsh;
229 bus_size_t size;
230 {
231 return;
232 }
233
234 static int
235 neptune_bus_space_subregion(t, bsh, offset, size, nbshp)
236 bus_space_tag_t t;
237 bus_space_handle_t bsh;
238 bus_size_t offset, size;
239 bus_space_handle_t *nbshp;
240 {
241
242 *nbshp = bsh + offset*2;
243 return (0);
244 }
245