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