plumiobus.c revision 1.9 1 /* $NetBSD: plumiobus.c,v 1.9 2003/07/15 02:29:30 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: plumiobus.c,v 1.9 2003/07/15 02:29:30 lukem Exp $");
41
42 #define PLUMIOBUSDEBUG
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47 #include <sys/malloc.h>
48
49 #include <machine/bus.h>
50 #include <machine/intr.h>
51
52 #include <hpcmips/tx/tx39var.h>
53 #include <hpcmips/dev/plumvar.h>
54 #include <hpcmips/dev/plumicuvar.h>
55 #include <hpcmips/dev/plumpowervar.h>
56 #include <hpcmips/dev/plumiobusreg.h>
57 #include <hpcmips/dev/plumiobusvar.h>
58
59 #include "locators.h"
60
61 #ifdef PLUMIOBUSDEBUG
62 int plumiobus_debug = 0;
63 #define DPRINTF(arg) if (plumiobus_debug) printf arg;
64 #define DPRINTFN(n, arg) if (plumiobus_debug > (n)) printf arg;
65 #else
66 #define DPRINTF(arg)
67 #define DPRINTFN(n, arg)
68 #endif
69
70 int plumiobus_match(struct device *, struct cfdata *, void *);
71 void plumiobus_attach(struct device *, struct device *, void *);
72 int plumiobus_print(void *, const char *);
73 int plumiobus_search(struct device *, struct cfdata *, void *);
74
75 struct plumisa_resource {
76 int pr_irq;
77 bus_space_tag_t pr_iot;
78 int pr_enabled;
79 };
80
81 struct plumiobus_softc {
82 struct device sc_dev;
83 plum_chipset_tag_t sc_pc;
84 bus_space_tag_t sc_regt;
85 bus_space_handle_t sc_regh;
86 bus_space_tag_t sc_iot;
87 bus_space_handle_t sc_ioh;
88 struct plumisa_resource sc_isa[PLUM_IOBUS_IO5CSMAX];
89 };
90
91 CFATTACH_DECL(plumiobus, sizeof(struct plumiobus_softc),
92 plumiobus_match, plumiobus_attach, NULL, NULL);
93
94 bus_space_tag_t __plumiobus_subregion(bus_space_tag_t, bus_addr_t,
95 bus_size_t);
96 #ifdef PLUMIOBUSDEBUG
97 void plumiobus_dump(struct plumiobus_softc *);
98 #endif
99
100 int
101 plumiobus_match(struct device *parent, struct cfdata *cf, void *aux)
102 {
103
104 return (1);
105 }
106
107 void
108 plumiobus_attach(struct device *parent, struct device *self, void *aux)
109 {
110 struct plum_attach_args *pa = aux;
111 struct plumiobus_softc *sc = (void*)self;
112 struct plumisa_resource *pr;
113
114 sc->sc_pc = pa->pa_pc;
115 sc->sc_regt = pa->pa_regt;
116 sc->sc_iot = pa->pa_iot;
117
118 if (bus_space_map(sc->sc_regt, PLUM_IOBUS_REGBASE,
119 PLUM_IOBUS_REGSIZE, 0, &sc->sc_regh)) {
120 printf(": register map failed.\n");
121 return;
122 }
123 printf("\n");
124 plum_power_establish(sc->sc_pc, PLUM_PWR_IO5);
125
126 /* Address space <-> IRQ mapping */
127 pr = &sc->sc_isa[IO5CS0];
128 pr->pr_irq = PLUM_INT_EXT5IO0;
129 pr->pr_iot = __plumiobus_subregion(
130 sc->sc_iot,
131 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS0BASE,
132 PLUM_IOBUS_IO5SIZE);
133
134 pr = &sc->sc_isa[IO5CS1];
135 pr->pr_irq = PLUM_INT_EXT5IO1;
136 pr->pr_iot = __plumiobus_subregion(
137 sc->sc_iot,
138 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS1BASE,
139 PLUM_IOBUS_IO5SIZE);
140
141 pr = &sc->sc_isa[IO5CS2];
142 pr->pr_irq = PLUM_INT_EXT5IO2;
143 pr->pr_iot = __plumiobus_subregion(
144 sc->sc_iot,
145 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS2BASE,
146 PLUM_IOBUS_IO5SIZE);
147
148 pr = &sc->sc_isa[IO5CS3];
149 pr->pr_irq = PLUM_INT_EXT5IO3;
150 pr->pr_iot = __plumiobus_subregion(
151 sc->sc_iot,
152 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS3BASE,
153 PLUM_IOBUS_IO5SIZE);
154
155 pr = &sc->sc_isa[IO5CS4];
156 pr->pr_irq = PLUM_INT_EXT3IO0; /* XXX */
157 pr->pr_iot = __plumiobus_subregion(
158 sc->sc_iot,
159 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS4BASE,
160 PLUM_IOBUS_IO5SIZE);
161
162
163 pr = &sc->sc_isa[IO5NCS];
164 pr->pr_irq = PLUM_INT_EXT3IO1;
165 pr->pr_iot = __plumiobus_subregion(
166 sc->sc_iot,
167 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS5BASE,
168 PLUM_IOBUS_IO5SIZE);
169
170 #ifdef PLUMIOBUSDEBUG
171 plumiobus_dump(sc);
172 #endif
173
174 config_search(plumiobus_search, self, plumiobus_print);
175 }
176
177 /* XXX something kludge */
178 bus_space_tag_t
179 __plumiobus_subregion(bus_space_tag_t t, bus_addr_t ofs, bus_size_t size)
180 {
181 struct hpcmips_bus_space *hbs;
182
183 if (!(hbs = malloc(sizeof(struct hpcmips_bus_space),
184 M_DEVBUF, M_NOWAIT))) {
185 panic ("__plumiobus_subregion: no memory.");
186 }
187 *hbs = *t;
188 hbs->t_base += ofs;
189 hbs->t_size = size;
190
191 return (hbs);
192 }
193
194 int
195 plumiobus_search(struct device *parent, struct cfdata *cf, void *aux)
196 {
197 struct plumiobus_softc *sc = (void*)parent;
198 struct plumiobus_attach_args pba;
199 int slot;
200
201 /* Disallow wildcarded IO5CS slot */
202 if (cf->cf_loc[PLUMIOBUSIFCF_SLOT] == PLUMIOBUSIFCF_SLOT_DEFAULT) {
203 printf("plumiobus_search: wildcarded slot, skipping\n");
204 return (0);
205 }
206 slot = pba.pba_slot = cf->cf_loc[PLUMIOBUSIFCF_SLOT];
207
208 pba.pba_pc = sc->sc_pc;
209 pba.pba_iot = sc->sc_isa[slot].pr_iot;
210 pba.pba_irq = sc->sc_isa[slot].pr_irq;
211 pba.pba_busname = "plumisab";
212
213 if (!(sc->sc_isa[slot].pr_enabled) && /* not attached slot */
214 config_match(parent, cf, &pba)) {
215 config_attach(parent, cf, &pba, plumiobus_print);
216 sc->sc_isa[slot].pr_enabled = 1;
217 }
218
219 return (0);
220 }
221
222 int
223 plumiobus_print(void *aux, const char *pnp)
224 {
225
226 return (pnp ? QUIET : UNCONF);
227 }
228
229 #ifdef PLUMIOBUSDEBUG
230 void
231 plumiobus_dump(struct plumiobus_softc *sc)
232 {
233 bus_space_tag_t regt = sc->sc_regt;
234 bus_space_handle_t regh = sc->sc_regh;
235 plumreg_t reg;
236 int i, wait;
237
238 reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXBSZ_REG);
239 printf("8bit port:");
240 for (i = 0; i < 6; i++) {
241 if (reg & (1 << i)) {
242 printf(" IO5CS%d", i);
243 }
244 }
245 printf("\n");
246
247 reg = PLUM_IOBUS_IOXCCNT_MASK &
248 plum_conf_read(regt, regh, PLUM_IOBUS_IOXCCNT_REG);
249 printf(" # of wait to become from the access begining: %d clock\n",
250 reg + 1);
251 reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXACNT_REG);
252 printf(" # of wait in access clock: ");
253 for (i = 0; i < 5; i++) {
254 wait = (reg >> (i * PLUM_IOBUS_IOXACNT_SHIFT))
255 & PLUM_IOBUS_IOXACNT_MASK;
256 printf("[CS%d:%d] ", i, wait + 1);
257 }
258 printf("\n");
259
260 reg = PLUM_IOBUS_IOXSCNT_MASK &
261 plum_conf_read(regt, regh, PLUM_IOBUS_IOXSCNT_REG);
262 printf(" # of wait during access by I/O bus : %d clock\n", reg + 1);
263
264 reg = plum_conf_read(regt, regh, PLUM_IOBUS_IDEMODE_REG);
265 if (reg & PLUM_IOBUS_IDEMODE) {
266 printf("IO5CS3,4 IDE mode\n");
267 }
268 }
269 #endif /* PLUMIOBUSDEBUG */
270