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