sableio.c revision 1.6 1 /* $NetBSD: sableio.c,v 1.6 2003/01/01 00:39:20 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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 /*
40 * Driver glue for the Sable STDIO module.
41 *
42 * This is kind of a hack. The STDIO is really a junk I/O module with
43 * your regular ISA junk peripherals and their regular ISA I/O addresses.
44 * However, the main issue we have here is *interrupts*. Not only are
45 * devices IRQs strange (i.e. not what you would expect to find if they
46 * were attached to a real ISA) IRQs, the keyboard controller isn't even
47 * connected to the (E)ISA IRQ space at all!
48 *
49 * In short, we're gluing together the following things:
50 *
51 * - Standard ISA junk I/O chip
52 * - ISA DMA
53 * - Pre-mapped "PCI" interrupts that are *edge triggered*
54 */
55
56 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
57
58 __KERNEL_RCSID(0, "$NetBSD: sableio.c,v 1.6 2003/01/01 00:39:20 thorpej Exp $");
59
60 #include "isadma.h"
61
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/device.h>
65
66 #include <dev/isa/isareg.h>
67 #include <dev/isa/isavar.h>
68 #include <dev/isa/isadmavar.h>
69
70 #include <dev/pci/pcivar.h>
71
72 #include <alpha/sableio/sableiovar.h>
73
74 /*
75 * The devices built-in to the Sable STDIO module.
76 */
77 const struct sableio_dev {
78 const char *sd_name; /* device name */
79 bus_addr_t sd_ioaddr; /* I/O space address */
80 int sd_sableirq[2]; /* Sable IRQs */
81 int sd_drq; /* ISA DRQ */
82 } sableio_devs[] = {
83 /*
84 * See alpha/pci/pci_2100_a500.c for interrupt information.
85 */
86 { "pckbc", IO_KBD, { 6, 3 }, -1 },
87 { "fdc", IO_FD1, { 7, -1 }, 2 },
88 { "com", IO_COM1, { 15, -1 }, -1 },
89 { "com", IO_COM2, { 8, -1 }, -1 },
90 { "lpt", IO_LPT3, { 9, -1 }, -1 },
91 { NULL, 0, { -1, -1 }, -1 },
92 };
93
94 struct sableio_softc {
95 struct device sc_dev; /* base device */
96
97 /*
98 * We have to deal with ISA DMA, so that means we have to
99 * hold the ISA chipset, since we attach STDIO devices
100 * before we attach the PCI (and thus EISA) bus.
101 */
102 struct alpha_isa_chipset sc_isa_chipset;
103 };
104
105 int sableio_match(struct device *, struct cfdata *, void *);
106 void sableio_attach(struct device *, struct device *, void *);
107
108 CFATTACH_DECL(sableio, sizeof(struct sableio_softc),
109 sableio_match, sableio_attach, NULL, NULL);
110
111 int sableio_print(void *, const char *);
112 int sableio_submatch(struct device *, struct cfdata *, void *);
113
114 struct sableio_softc *sableio_attached;
115
116 int
117 sableio_match(struct device *parent, struct cfdata *cf, void *aux)
118 {
119 struct pcibus_attach_args *pba = aux;
120
121 if (strcmp(pba->pba_busname, cf->cf_name) != 0)
122 return (0);
123
124 /*
125 * These are really ISA devices, and thus must be on
126 * PCI bus 0.
127 */
128 if (cf->pcibuscf_bus != PCIBUS_UNK_BUS &&
129 cf->pcibuscf_bus != pba->pba_bus)
130 return (0);
131
132 /* sanity */
133 if (pba->pba_bus != 0)
134 return (0);
135
136 /* There can be only one. */
137 if (sableio_attached != NULL)
138 return (0);
139
140 return (1);
141 }
142
143 void
144 sableio_attach(struct device *parent, struct device *self, void *aux)
145 {
146 struct sableio_softc *sc = (void *) self;
147 struct pcibus_attach_args *pba = aux;
148 struct sableio_attach_args sa;
149 bus_dma_tag_t dmat;
150 int i;
151
152 printf(": Sable STDIO module\n");
153
154 sableio_attached = sc;
155
156 dmat = alphabus_dma_get_tag(pba->pba_dmat, ALPHA_BUS_ISA);
157
158 #if NISADMA > 0
159 /*
160 * Initialize our DMA state.
161 */
162 isa_dmainit(&sc->sc_isa_chipset, pba->pba_iot, dmat, self);
163 #endif
164
165 for (i = 0; sableio_devs[i].sd_name != NULL; i++) {
166 sa.sa_name = sableio_devs[i].sd_name;
167 sa.sa_ioaddr = sableio_devs[i].sd_ioaddr;
168 sa.sa_sableirq[0] = sableio_devs[i].sd_sableirq[0];
169 sa.sa_sableirq[1] = sableio_devs[i].sd_sableirq[1];
170 sa.sa_drq = sableio_devs[i].sd_drq;
171
172 sa.sa_iot = pba->pba_iot;
173 sa.sa_dmat = dmat;
174 sa.sa_ic = &sc->sc_isa_chipset;
175 sa.sa_pc = pba->pba_pc;
176
177 (void) config_found_sm(self, &sa, sableio_print,
178 sableio_submatch);
179 }
180 }
181
182 int
183 sableio_submatch(struct device *parent, struct cfdata *cf, void *aux)
184 {
185 struct sableio_attach_args *sa = aux;
186
187 if (cf->cf_loc[SABLEIOCF_PORT] != SABLEIOCF_PORT_DEFAULT &&
188 cf->cf_loc[SABLEIOCF_PORT] != sa->sa_ioaddr)
189 return (0);
190
191 return (config_match(parent, cf, aux));
192 }
193
194 int
195 sableio_print(void *aux, const char *pnp)
196 {
197 struct sableio_attach_args *sa = aux;
198
199 if (pnp != NULL)
200 aprint_normal("%s at %s", sa->sa_name, pnp);
201
202 aprint_normal(" port 0x%lx", sa->sa_ioaddr);
203 return (UNCONF);
204 }
205
206 isa_chipset_tag_t
207 sableio_pickisa(void)
208 {
209
210 if (sableio_attached == NULL)
211 panic("sableio_pickisa");
212
213 return (&sableio_attached->sc_isa_chipset);
214 }
215