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