Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / x68k / dev / neptune.c
blob45727e5363f3b61db85da101de670183d870bc78
1 /* $NetBSD: neptune.c,v 1.18 2008/06/25 08:14:59 isaki Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Minoura Makoto.
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.
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.
33 * Neptune-X -- X68k-ISA Bus Bridge
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: neptune.c,v 1.18 2008/06/25 08:14:59 isaki Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
44 #include <machine/bus.h>
45 #include <machine/cpu.h>
46 #include <machine/frame.h>
48 #include <arch/x68k/dev/intiovar.h>
49 #include <arch/x68k/dev/neptunevar.h>
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 *);
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,
69 static int neptune_match(device_t, cfdata_t, void *);
70 static void neptune_attach(device_t, device_t, void *);
71 static int neptune_search(device_t, cfdata_t, const int *, void *);
72 static int neptune_print(void *, const char *);
74 CFATTACH_DECL_NEW(neptune, sizeof(struct neptune_softc),
75 neptune_match, neptune_attach, NULL, NULL);
77 static int
78 neptune_match(device_t parent, cfdata_t cf, void *aux)
80 struct intio_attach_args *ia = aux;
82 if (strcmp(ia->ia_name, "neptune") != 0)
83 return 0;
85 ia->ia_size = 0x400;
86 if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
87 return 0;
89 /* Neptune is a virtual device. Always there. */
91 return (1);
95 static void
96 neptune_attach(device_t parent, device_t self, void *aux)
98 struct neptune_softc *sc = device_private(self);
99 struct intio_attach_args *ia = aux;
100 struct neptune_attach_args na;
101 int r;
102 cfdata_t cf;
104 ia->ia_size = 0x400;
105 r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
106 #ifdef DIAGNOSTIC
107 if (r)
108 panic("IO map for Neptune corruption??");
109 #endif
111 sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_NOWAIT);
112 if (sc->sc_bst == NULL)
113 panic("neptune_attach: can't allocate bus_space structure");
114 *sc->sc_bst = neptune_bus;
115 sc->sc_bst->x68k_bus_device = self;
117 sc->sc_addr = (vaddr_t)IIOV(ia->ia_addr);
119 na.na_bst = sc->sc_bst;
120 na.na_intr = ia->ia_intr;
122 cf = config_search_ia(neptune_search, self, "neptune", &na);
123 if (cf) {
124 aprint_normal(": Neptune-X ISA bridge\n");
125 config_attach(self, cf, &na, neptune_print);
126 } else {
127 aprint_normal(": no device found.\n");
128 intio_map_free_region(parent, ia);
132 static int
133 neptune_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
135 struct neptune_attach_args *na = aux;
137 na->na_addr = cf->neptune_cf_addr;
139 return config_match(parent, cf, na);
142 static int
143 neptune_print(void *aux, const char *name)
145 struct neptune_attach_args *na = aux;
147 /* if (na->na_addr > 0) */
148 aprint_normal(" addr 0x%06x", na->na_addr);
150 return (QUIET);
155 * neptune bus space stuff.
157 static int
158 neptune_bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size,
159 int flags, bus_space_handle_t *bshp)
161 struct neptune_softc *sc = device_private(t->x68k_bus_device);
162 vaddr_t start = sc->sc_addr;
165 * Neptune bus is mapped permanently.
167 *bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2);
169 if (badaddr((void *)*bshp)) {
170 return 1;
173 *bshp |= 0x80000000; /* higher byte (= even address) only */
175 return (0);
178 static void
179 neptune_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
180 bus_size_t size)
182 return;
185 static int
186 neptune_bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
187 bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
190 *nbshp = bsh + offset*2;
191 return (0);