isa_machdep.c revision 1.5 1 /* $NetBSD: isa_machdep.c,v 1.5 2003/07/15 02:43:41 lukem Exp $ */
2
3 /*
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Wayne Knowles
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: isa_machdep.c,v 1.5 2003/07/15 02:43:41 lukem Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46 #include <sys/queue.h>
47
48 #include <machine/sysconf.h>
49 #include <machine/autoconf.h>
50 #include <machine/mainboard.h>
51 #include <machine/bus.h>
52
53 #include <dev/isa/isavar.h>
54 #include <dev/isa/isareg.h>
55
56 static int isabusprint __P((void *auxp, const char *));
57 static int isabusmatch __P((struct device *, struct cfdata *, void *));
58 static void isabusattach __P((struct device *, struct device *, void *));
59
60 struct isabus_softc {
61 struct device sc_dev;
62 struct mipsco_isa_chipset sc_isa_ic;
63 };
64
65 CFATTACH_DECL(isabus, sizeof(struct isabus_softc),
66 isabusmatch, isabusattach, NULL, NULL);
67
68 extern struct cfdriver isabus_cd;
69
70 static struct mipsco_bus_space isa_io_bst, isa_mem_bst, isa_ctl_bst;
71 static struct mipsco_bus_dma_tag isa_dmatag;
72
73 static void isa_bus_space_init __P((struct mipsco_bus_space *, const char *,
74 paddr_t, size_t));
75 int isa_intr __P((void *));
76
77
78 int
79 isabusmatch(pdp, cfp, aux)
80 struct device *pdp;
81 struct cfdata *cfp;
82 void *aux;
83 {
84 struct confargs *ca = aux;
85
86 if (strcmp(ca->ca_name, isabus_cd.cd_name) != 0)
87 return 0;
88 return 1;
89 }
90
91 static void
92 isa_bus_space_init(bst, type, paddr, len)
93 struct mipsco_bus_space *bst;
94 const char *type;
95 paddr_t paddr;
96 size_t len;
97 {
98 vaddr_t vaddr = MIPS_PHYS_TO_KSEG1(paddr); /* XXX */
99
100 /* Setup default bus_space */
101 mipsco_bus_space_init(bst, type, paddr, vaddr, 0x0, len);
102
103 /* ISA bus maps 1 word for every byte, therefore stride = 2 */
104 mipsco_bus_space_set_aligned_stride(bst, 2);
105
106 /*
107 * ISA bus will do an automatic byte swap, but when accessing
108 * memory using bus_space_stream functions we need to byte swap
109 * to reverse the one performed in hardware
110 */
111 bst->bs_bswap = 1;
112
113 bst->bs_intr_establish = (void *)isa_intr_establish;
114
115 printf(" %s %p", type, (void *)vaddr);
116 }
117
118
119 void
120 isabusattach(pdp, dp, aux)
121 struct device *pdp, *dp;
122 void *aux;
123 {
124 struct isabus_softc *sc = (struct isabus_softc *)dp;
125 struct mipsco_isa_chipset *ic = &sc->sc_isa_ic;
126 struct isabus_attach_args iba;
127
128 printf(":");
129
130 iba.iba_busname = "isa";
131 iba.iba_iot = &isa_io_bst;
132 iba.iba_memt = &isa_mem_bst;
133 iba.iba_dmat = &isa_dmatag;
134 iba.iba_ic = ic;
135
136 isa_bus_space_init(&isa_io_bst, "isa_io", PIZAZZ_ISA_IOBASE,
137 PIZAZZ_ISA_IOSIZE);
138
139 isa_bus_space_init(&isa_mem_bst, "isa_mem", PIZAZZ_ISA_MEMBASE,
140 PIZAZZ_ISA_MEMSIZE);
141
142 isa_bus_space_init(&isa_ctl_bst, "isa_intr", PIZAZZ_ISA_INTRLATCH,
143 sizeof(u_int32_t));
144
145 _bus_dma_tag_init(&isa_dmatag);
146
147 ic->ic_bst = &isa_ctl_bst;
148
149 if (bus_space_map(ic->ic_bst, 0x00000, sizeof(u_int32_t),
150 BUS_SPACE_MAP_LINEAR, &ic->ic_bsh) != 0) {
151 printf(": can't map intrreg\n");
152 return;
153 }
154
155 /* Clear ISA interrupt latch */
156 bus_space_write_4(ic->ic_bst, ic->ic_bsh, 0, 0);
157
158 evcnt_attach_dynamic(&ic->ic_intrcnt, EVCNT_TYPE_INTR, NULL,
159 dp->dv_xname, "intr");
160
161 LIST_INIT(&ic->intr_q);
162 (*platform.intr_establish)(SYS_INTR_ATBUS, isa_intr, ic);
163
164 printf("\n");
165 config_found(dp, &iba, isabusprint);
166 }
167
168 int
169 isabusprint(auxp, name)
170 void *auxp;
171 const char *name;
172 {
173 if(name == NULL)
174 return(UNCONF);
175 return(QUIET);
176 }
177
178 void
179 isa_attach_hook(parent, self, iba)
180 struct device *parent, *self;
181 struct isabus_attach_args *iba;
182 {
183 }
184
185 const struct evcnt *
186 isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
187 {
188 /* XXX for now, no evcnt parent reported */
189 return NULL;
190 }
191
192 void *
193 isa_intr_establish(ic, intr, type, level, ih_fun, ih_arg)
194 isa_chipset_tag_t ic;
195 int intr;
196 int type; /* XXX not yet */
197 int level; /* XXX not yet */
198 int (*ih_fun) __P((void*));
199 void *ih_arg;
200 {
201 struct mipsco_intrhand *ih;
202
203 ih = malloc(sizeof *ih, M_DEVBUF, M_NOWAIT);
204 if (ih == NULL)
205 panic("isa_intr_establish: malloc failed");
206
207 ih->ih_fun = ih_fun;
208 ih->ih_arg = ih_arg;
209 LIST_INSERT_HEAD(&ic->intr_q, ih, ih_q);
210 return ih;
211 }
212
213 void
214 isa_intr_disestablish(ic, cookie)
215 isa_chipset_tag_t ic;
216 void *cookie;
217 {
218 struct mipsco_intrhand *ih = cookie;
219
220 LIST_REMOVE(ih, ih_q);
221 free(ih, M_DEVBUF);
222 }
223
224 int
225 isa_intr_alloc(ic, mask, type, irq)
226 isa_chipset_tag_t ic;
227 int mask;
228 int type;
229 int *irq;
230 {
231 return 0;
232 }
233
234 int
235 isa_intr(arg)
236 void *arg;
237 {
238 struct mipsco_isa_chipset *ic = (struct mipsco_isa_chipset *)arg;
239 struct mipsco_intrhand *ih;
240 int rv, handled;
241
242 ic->ic_intrcnt.ev_count++;
243
244 handled = 0;
245 LIST_FOREACH(ih, &ic->intr_q, ih_q) {
246 /*
247 * The handler returns one of three values:
248 * 0: This interrupt wasn't for me.
249 * 1: This interrupt was for me.
250 * -1: This interrupt might have been for me, but I can't say
251 * for sure.
252 */
253 rv = (*ih->ih_fun)(ih->ih_arg);
254 handled |= (rv != 0);
255 }
256
257 /* Clear ISA interrupt latch */
258 bus_space_write_4(ic->ic_bst, ic->ic_bsh, 0, 0);
259
260 return handled;
261 }
262