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