plumiobus.c revision 1.10 1 /* $NetBSD: plumiobus.c,v 1.10 2005/06/30 17:03:53 drochner 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.10 2005/06/30 17:03:53 drochner 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 *,
74 const locdesc_t *, void *);
75
76 struct plumisa_resource {
77 int pr_irq;
78 bus_space_tag_t pr_iot;
79 int pr_enabled;
80 };
81
82 struct plumiobus_softc {
83 struct device sc_dev;
84 plum_chipset_tag_t sc_pc;
85 bus_space_tag_t sc_regt;
86 bus_space_handle_t sc_regh;
87 bus_space_tag_t sc_iot;
88 bus_space_handle_t sc_ioh;
89 struct plumisa_resource sc_isa[PLUM_IOBUS_IO5CSMAX];
90 };
91
92 CFATTACH_DECL(plumiobus, sizeof(struct plumiobus_softc),
93 plumiobus_match, plumiobus_attach, NULL, NULL);
94
95 bus_space_tag_t __plumiobus_subregion(bus_space_tag_t, bus_addr_t,
96 bus_size_t);
97 #ifdef PLUMIOBUSDEBUG
98 void plumiobus_dump(struct plumiobus_softc *);
99 #endif
100
101 int
102 plumiobus_match(struct device *parent, struct cfdata *cf, void *aux)
103 {
104
105 return (1);
106 }
107
108 void
109 plumiobus_attach(struct device *parent, struct device *self, void *aux)
110 {
111 struct plum_attach_args *pa = aux;
112 struct plumiobus_softc *sc = (void*)self;
113 struct plumisa_resource *pr;
114
115 sc->sc_pc = pa->pa_pc;
116 sc->sc_regt = pa->pa_regt;
117 sc->sc_iot = pa->pa_iot;
118
119 if (bus_space_map(sc->sc_regt, PLUM_IOBUS_REGBASE,
120 PLUM_IOBUS_REGSIZE, 0, &sc->sc_regh)) {
121 printf(": register map failed.\n");
122 return;
123 }
124 printf("\n");
125 plum_power_establish(sc->sc_pc, PLUM_PWR_IO5);
126
127 /* Address space <-> IRQ mapping */
128 pr = &sc->sc_isa[IO5CS0];
129 pr->pr_irq = PLUM_INT_EXT5IO0;
130 pr->pr_iot = __plumiobus_subregion(
131 sc->sc_iot,
132 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS0BASE,
133 PLUM_IOBUS_IO5SIZE);
134
135 pr = &sc->sc_isa[IO5CS1];
136 pr->pr_irq = PLUM_INT_EXT5IO1;
137 pr->pr_iot = __plumiobus_subregion(
138 sc->sc_iot,
139 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS1BASE,
140 PLUM_IOBUS_IO5SIZE);
141
142 pr = &sc->sc_isa[IO5CS2];
143 pr->pr_irq = PLUM_INT_EXT5IO2;
144 pr->pr_iot = __plumiobus_subregion(
145 sc->sc_iot,
146 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS2BASE,
147 PLUM_IOBUS_IO5SIZE);
148
149 pr = &sc->sc_isa[IO5CS3];
150 pr->pr_irq = PLUM_INT_EXT5IO3;
151 pr->pr_iot = __plumiobus_subregion(
152 sc->sc_iot,
153 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS3BASE,
154 PLUM_IOBUS_IO5SIZE);
155
156 pr = &sc->sc_isa[IO5CS4];
157 pr->pr_irq = PLUM_INT_EXT3IO0; /* XXX */
158 pr->pr_iot = __plumiobus_subregion(
159 sc->sc_iot,
160 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS4BASE,
161 PLUM_IOBUS_IO5SIZE);
162
163
164 pr = &sc->sc_isa[IO5NCS];
165 pr->pr_irq = PLUM_INT_EXT3IO1;
166 pr->pr_iot = __plumiobus_subregion(
167 sc->sc_iot,
168 PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS5BASE,
169 PLUM_IOBUS_IO5SIZE);
170
171 #ifdef PLUMIOBUSDEBUG
172 plumiobus_dump(sc);
173 #endif
174
175 config_search_ia(plumiobus_search, self, "plumiobusif", plumiobus_print);
176 }
177
178 /* XXX something kludge */
179 bus_space_tag_t
180 __plumiobus_subregion(bus_space_tag_t t, bus_addr_t ofs, bus_size_t size)
181 {
182 struct hpcmips_bus_space *hbs;
183
184 if (!(hbs = malloc(sizeof(struct hpcmips_bus_space),
185 M_DEVBUF, M_NOWAIT))) {
186 panic ("__plumiobus_subregion: no memory.");
187 }
188 *hbs = *t;
189 hbs->t_base += ofs;
190 hbs->t_size = size;
191
192 return (hbs);
193 }
194
195 int
196 plumiobus_search(struct device *parent, struct cfdata *cf,
197 const locdesc_t *ldesc, void *aux)
198 {
199 struct plumiobus_softc *sc = (void*)parent;
200 struct plumiobus_attach_args pba;
201 int slot;
202
203 /* Disallow wildcarded IO5CS slot */
204 if (cf->cf_loc[PLUMIOBUSIFCF_SLOT] == PLUMIOBUSIFCF_SLOT_DEFAULT) {
205 printf("plumiobus_search: wildcarded slot, skipping\n");
206 return (0);
207 }
208 slot = pba.pba_slot = cf->cf_loc[PLUMIOBUSIFCF_SLOT];
209
210 pba.pba_pc = sc->sc_pc;
211 pba.pba_iot = sc->sc_isa[slot].pr_iot;
212 pba.pba_irq = sc->sc_isa[slot].pr_irq;
213 pba.pba_busname = "plumisab";
214
215 if (!(sc->sc_isa[slot].pr_enabled) && /* not attached slot */
216 config_match(parent, cf, &pba)) {
217 config_attach(parent, cf, &pba, plumiobus_print);
218 sc->sc_isa[slot].pr_enabled = 1;
219 }
220
221 return (0);
222 }
223
224 int
225 plumiobus_print(void *aux, const char *pnp)
226 {
227
228 return (pnp ? QUIET : UNCONF);
229 }
230
231 #ifdef PLUMIOBUSDEBUG
232 void
233 plumiobus_dump(struct plumiobus_softc *sc)
234 {
235 bus_space_tag_t regt = sc->sc_regt;
236 bus_space_handle_t regh = sc->sc_regh;
237 plumreg_t reg;
238 int i, wait;
239
240 reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXBSZ_REG);
241 printf("8bit port:");
242 for (i = 0; i < 6; i++) {
243 if (reg & (1 << i)) {
244 printf(" IO5CS%d", i);
245 }
246 }
247 printf("\n");
248
249 reg = PLUM_IOBUS_IOXCCNT_MASK &
250 plum_conf_read(regt, regh, PLUM_IOBUS_IOXCCNT_REG);
251 printf(" # of wait to become from the access begining: %d clock\n",
252 reg + 1);
253 reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXACNT_REG);
254 printf(" # of wait in access clock: ");
255 for (i = 0; i < 5; i++) {
256 wait = (reg >> (i * PLUM_IOBUS_IOXACNT_SHIFT))
257 & PLUM_IOBUS_IOXACNT_MASK;
258 printf("[CS%d:%d] ", i, wait + 1);
259 }
260 printf("\n");
261
262 reg = PLUM_IOBUS_IOXSCNT_MASK &
263 plum_conf_read(regt, regh, PLUM_IOBUS_IOXSCNT_REG);
264 printf(" # of wait during access by I/O bus : %d clock\n", reg + 1);
265
266 reg = plum_conf_read(regt, regh, PLUM_IOBUS_IDEMODE_REG);
267 if (reg & PLUM_IOBUS_IDEMODE) {
268 printf("IO5CS3,4 IDE mode\n");
269 }
270 }
271 #endif /* PLUMIOBUSDEBUG */
272