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