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