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