isa.c revision 1.84 1 1.84 mycroft /* $NetBSD: isa.c,v 1.84 1996/05/12 23:53:01 mycroft Exp $ */
2 1.58 cgd
3 1.1 cgd /*-
4 1.59 mycroft * Copyright (c) 1993, 1994 Charles Hannum. All rights reserved.
5 1.1 cgd *
6 1.1 cgd * Redistribution and use in source and binary forms, with or without
7 1.1 cgd * modification, are permitted provided that the following conditions
8 1.1 cgd * are met:
9 1.1 cgd * 1. Redistributions of source code must retain the above copyright
10 1.1 cgd * notice, this list of conditions and the following disclaimer.
11 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 cgd * notice, this list of conditions and the following disclaimer in the
13 1.1 cgd * documentation and/or other materials provided with the distribution.
14 1.1 cgd * 3. All advertising materials mentioning features or use of this software
15 1.1 cgd * must display the following acknowledgement:
16 1.59 mycroft * This product includes software developed by Charles Hannum.
17 1.59 mycroft * 4. The name of the author may not be used to endorse or promote products
18 1.59 mycroft * derived from this software without specific prior written permission.
19 1.1 cgd *
20 1.59 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.59 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.59 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.59 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.59 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.59 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.59 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.59 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.59 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.59 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.31 mycroft #include <sys/param.h>
33 1.31 mycroft #include <sys/systm.h>
34 1.40 mycroft #include <sys/kernel.h>
35 1.31 mycroft #include <sys/conf.h>
36 1.31 mycroft #include <sys/malloc.h>
37 1.46 mycroft #include <sys/device.h>
38 1.31 mycroft
39 1.72 cgd #include <dev/isa/isareg.h>
40 1.72 cgd #include <dev/isa/isavar.h>
41 1.77 cgd
42 1.77 cgd int isamatch __P((struct device *, void *, void *));
43 1.77 cgd void isaattach __P((struct device *, struct device *, void *));
44 1.81 christos int isaprint __P((void *, char *));
45 1.77 cgd
46 1.79 thorpej struct cfattach isa_ca = {
47 1.79 thorpej sizeof(struct isa_softc), isamatch, isaattach
48 1.79 thorpej };
49 1.79 thorpej
50 1.79 thorpej struct cfdriver isa_cd = {
51 1.79 thorpej NULL, "isa", DV_DULL, 1
52 1.77 cgd };
53 1.77 cgd
54 1.77 cgd int
55 1.77 cgd isamatch(parent, match, aux)
56 1.77 cgd struct device *parent;
57 1.77 cgd void *match, *aux;
58 1.77 cgd {
59 1.77 cgd struct cfdata *cf = match;
60 1.77 cgd struct isabus_attach_args *iba = aux;
61 1.77 cgd
62 1.77 cgd if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
63 1.77 cgd return (0);
64 1.77 cgd
65 1.77 cgd /* XXX check other indicators */
66 1.77 cgd
67 1.77 cgd return (1);
68 1.77 cgd }
69 1.77 cgd
70 1.77 cgd void
71 1.77 cgd isaattach(parent, self, aux)
72 1.77 cgd struct device *parent, *self;
73 1.77 cgd void *aux;
74 1.77 cgd {
75 1.77 cgd struct isa_softc *sc = (struct isa_softc *)self;
76 1.77 cgd struct isabus_attach_args *iba = aux;
77 1.77 cgd
78 1.80 cgd isa_attach_hook(parent, self, iba);
79 1.77 cgd printf("\n");
80 1.77 cgd
81 1.78 cgd sc->sc_bc = iba->iba_bc;
82 1.80 cgd sc->sc_ic = iba->iba_ic;
83 1.78 cgd
84 1.82 thorpej /*
85 1.83 thorpej * Map port 0x84, which causes a 1.25us delay when read.
86 1.82 thorpej * We do this now, since several drivers need it.
87 1.82 thorpej */
88 1.82 thorpej if (bus_io_map(sc->sc_bc, 0x84, 1, &sc->sc_delayioh))
89 1.82 thorpej panic("isaattach: can't map `delay port'"); /* XXX */
90 1.82 thorpej
91 1.77 cgd TAILQ_INIT(&sc->sc_subdevs);
92 1.77 cgd config_scan(isascan, self);
93 1.77 cgd }
94 1.1 cgd
95 1.46 mycroft int
96 1.46 mycroft isaprint(aux, isa)
97 1.46 mycroft void *aux;
98 1.46 mycroft char *isa;
99 1.46 mycroft {
100 1.46 mycroft struct isa_attach_args *ia = aux;
101 1.46 mycroft
102 1.46 mycroft if (ia->ia_iosize)
103 1.46 mycroft printf(" port 0x%x", ia->ia_iobase);
104 1.46 mycroft if (ia->ia_iosize > 1)
105 1.46 mycroft printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
106 1.46 mycroft if (ia->ia_msize)
107 1.70 mycroft printf(" iomem 0x%x", ia->ia_maddr);
108 1.46 mycroft if (ia->ia_msize > 1)
109 1.70 mycroft printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
110 1.69 mycroft if (ia->ia_irq != IRQUNK)
111 1.66 mycroft printf(" irq %d", ia->ia_irq);
112 1.69 mycroft if (ia->ia_drq != DRQUNK)
113 1.46 mycroft printf(" drq %d", ia->ia_drq);
114 1.71 mycroft return (UNCONF);
115 1.46 mycroft }
116 1.46 mycroft
117 1.21 andrew void
118 1.64 mycroft isascan(parent, match)
119 1.64 mycroft struct device *parent;
120 1.64 mycroft void *match;
121 1.64 mycroft {
122 1.78 cgd struct isa_softc *sc = (struct isa_softc *)parent;
123 1.64 mycroft struct device *dev = match;
124 1.64 mycroft struct cfdata *cf = dev->dv_cfdata;
125 1.64 mycroft struct isa_attach_args ia;
126 1.64 mycroft
127 1.64 mycroft if (cf->cf_fstate == FSTATE_STAR)
128 1.76 mycroft panic("clone devices not supported on ISA bus");
129 1.64 mycroft
130 1.78 cgd ia.ia_bc = sc->sc_bc;
131 1.80 cgd ia.ia_ic = sc->sc_ic;
132 1.64 mycroft ia.ia_iobase = cf->cf_loc[0];
133 1.64 mycroft ia.ia_iosize = 0x666;
134 1.70 mycroft ia.ia_maddr = cf->cf_loc[2];
135 1.64 mycroft ia.ia_msize = cf->cf_loc[3];
136 1.70 mycroft ia.ia_irq = cf->cf_loc[4] == 2 ? 9 : cf->cf_loc[4];
137 1.64 mycroft ia.ia_drq = cf->cf_loc[5];
138 1.82 thorpej ia.ia_delayioh = sc->sc_delayioh;
139 1.64 mycroft
140 1.79 thorpej if ((*cf->cf_attach->ca_match)(parent, dev, &ia) > 0)
141 1.64 mycroft config_attach(parent, dev, &ia, isaprint);
142 1.64 mycroft else
143 1.64 mycroft free(dev, M_DEVBUF);
144 1.72 cgd }
145 1.72 cgd
146 1.72 cgd char *
147 1.72 cgd isa_intr_typename(type)
148 1.75 mycroft int type;
149 1.72 cgd {
150 1.72 cgd
151 1.72 cgd switch (type) {
152 1.75 mycroft case IST_NONE :
153 1.72 cgd return ("none");
154 1.75 mycroft case IST_PULSE:
155 1.72 cgd return ("pulsed");
156 1.75 mycroft case IST_EDGE:
157 1.72 cgd return ("edge-triggered");
158 1.75 mycroft case IST_LEVEL:
159 1.72 cgd return ("level-triggered");
160 1.72 cgd default:
161 1.72 cgd panic("isa_intr_typename: invalid type %d", type);
162 1.72 cgd }
163 1.1 cgd }
164