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