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