xref: /netbsd-src/sys/dev/isa/isa.c (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /*	$NetBSD: isa.c,v 1.108 2001/06/19 12:45:23 fvdl Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Charles M. Hannum.
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/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/device.h>
44 
45 #include <machine/intr.h>
46 
47 #include <dev/isa/isareg.h>
48 #include <dev/isa/isavar.h>
49 #include <dev/isa/isadmareg.h>
50 
51 #include "isadma.h"
52 
53 #include "isapnp.h"
54 #if NISAPNP > 0
55 #include <dev/isapnp/isapnpreg.h>
56 #include <dev/isapnp/isapnpvar.h>
57 #endif
58 
59 int isamatch __P((struct device *, struct cfdata *, void *));
60 void isaattach __P((struct device *, struct device *, void *));
61 int isaprint __P((void *, const char *));
62 
63 struct cfattach isa_ca = {
64 	sizeof(struct isa_softc), isamatch, isaattach
65 };
66 
67 int	isasearch __P((struct device *, struct cfdata *, void *));
68 
69 int
70 isamatch(parent, cf, aux)
71 	struct device *parent;
72 	struct cfdata *cf;
73 	void *aux;
74 {
75 	struct isabus_attach_args *iba = aux;
76 
77 	if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
78 		return (0);
79 
80 	/* XXX check other indicators */
81 
82         return (1);
83 }
84 
85 void
86 isaattach(parent, self, aux)
87 	struct device *parent, *self;
88 	void *aux;
89 {
90 	struct isa_softc *sc = (struct isa_softc *)self;
91 	struct isabus_attach_args *iba = aux;
92 
93 	isa_attach_hook(parent, self, iba);
94 	printf("\n");
95 
96 	sc->sc_iot = iba->iba_iot;
97 	sc->sc_memt = iba->iba_memt;
98 	sc->sc_dmat = iba->iba_dmat;
99 	sc->sc_ic = iba->iba_ic;
100 
101 #if NISAPNP > 0
102 	/*
103 	 * Reset isapnp cards that the bios configured for us
104 	 */
105 	isapnp_isa_attach_hook(sc);
106 #endif
107 
108 #if NISADMA > 0
109 	/*
110 	 * Initialize our DMA state.
111 	 */
112 	isa_dmainit(sc->sc_ic, sc->sc_iot, sc->sc_dmat, self);
113 #endif
114 
115 	config_search(isasearch, self, NULL);
116 }
117 
118 int
119 isaprint(aux, isa)
120 	void *aux;
121 	const char *isa;
122 {
123 	struct isa_attach_args *ia = aux;
124 
125 	if (ia->ia_iosize)
126 		printf(" port 0x%x", ia->ia_iobase);
127 	if (ia->ia_iosize > 1)
128 		printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
129 	if (ia->ia_msize)
130 		printf(" iomem 0x%x", ia->ia_maddr);
131 	if (ia->ia_msize > 1)
132 		printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
133 	if (ia->ia_irq != IRQUNK)
134 		printf(" irq %d", ia->ia_irq);
135 	if (ia->ia_drq != DRQUNK)
136 		printf(" drq %d", ia->ia_drq);
137 	if (ia->ia_drq2 != DRQUNK)
138 		printf(" drq2 %d", ia->ia_drq2);
139 	return (UNCONF);
140 }
141 
142 int
143 isasearch(parent, cf, aux)
144 	struct device *parent;
145 	struct cfdata *cf;
146 	void *aux;
147 {
148 	struct isa_softc *sc = (struct isa_softc *)parent;
149 	struct isa_attach_args ia;
150 	int tryagain;
151 
152 	do {
153 		ia.ia_iot = sc->sc_iot;
154 		ia.ia_memt = sc->sc_memt;
155 		ia.ia_dmat = sc->sc_dmat;
156 		ia.ia_ic = sc->sc_ic;
157 		ia.ia_iobase = cf->cf_iobase;
158 		ia.ia_iosize = 0x666; /* cf->cf_iosize; */
159 		ia.ia_maddr = cf->cf_maddr;
160 		ia.ia_msize = cf->cf_msize;
161 		ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq;
162 		ia.ia_drq = cf->cf_drq;
163 		ia.ia_drq2 = cf->cf_drq2;
164 
165 		tryagain = 0;
166 		if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) {
167 			config_attach(parent, cf, &ia, isaprint);
168 			tryagain = (cf->cf_fstate == FSTATE_STAR);
169 		}
170 	} while (tryagain);
171 
172 	return (0);
173 }
174 
175 char *
176 isa_intr_typename(type)
177 	int type;
178 {
179 
180 	switch (type) {
181         case IST_NONE :
182 		return ("none");
183         case IST_PULSE:
184 		return ("pulsed");
185         case IST_EDGE:
186 		return ("edge-triggered");
187         case IST_LEVEL:
188 		return ("level-triggered");
189 	default:
190 		panic("isa_intr_typename: invalid type %d", type);
191 	}
192 }
193