sableio.c revision 1.3 1 /* $NetBSD: sableio.c,v 1.3 2002/09/27 03:17:43 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.3 2002/09/27 03:17:43 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 struct cfattach sableio_ca = {
109 sizeof(struct sableio_softc), sableio_match, sableio_attach
110 };
111
112 int sableio_print(void *, const char *);
113 int sableio_submatch(struct device *, struct cfdata *, void *);
114
115 struct sableio_softc *sableio_attached;
116
117 int
118 sableio_match(struct device *parent, struct cfdata *cf, void *aux)
119 {
120 struct pcibus_attach_args *pba = aux;
121
122 if (strcmp(pba->pba_busname, cf->cf_name) != 0)
123 return (0);
124
125 /*
126 * These are really ISA devices, and thus must be on
127 * PCI bus 0.
128 */
129 if (cf->pcibuscf_bus != PCIBUS_UNK_BUS &&
130 cf->pcibuscf_bus != pba->pba_bus)
131 return (0);
132
133 /* sanity */
134 if (pba->pba_bus != 0)
135 return (0);
136
137 /* There can be only one. */
138 if (sableio_attached != NULL)
139 return (0);
140
141 return (1);
142 }
143
144 void
145 sableio_attach(struct device *parent, struct device *self, void *aux)
146 {
147 struct sableio_softc *sc = (void *) self;
148 struct pcibus_attach_args *pba = aux;
149 struct sableio_attach_args sa;
150 bus_dma_tag_t dmat;
151 int i;
152
153 printf(": Sable STDIO module\n");
154
155 sableio_attached = sc;
156
157 dmat = alphabus_dma_get_tag(pba->pba_dmat, ALPHA_BUS_ISA);
158
159 #if NISADMA > 0
160 /*
161 * Initialize our DMA state.
162 */
163 isa_dmainit(&sc->sc_isa_chipset, pba->pba_iot, dmat, self);
164 #endif
165
166 for (i = 0; sableio_devs[i].sd_name != NULL; i++) {
167 sa.sa_name = sableio_devs[i].sd_name;
168 sa.sa_ioaddr = sableio_devs[i].sd_ioaddr;
169 sa.sa_sableirq[0] = sableio_devs[i].sd_sableirq[0];
170 sa.sa_sableirq[1] = sableio_devs[i].sd_sableirq[1];
171 sa.sa_drq = sableio_devs[i].sd_drq;
172
173 sa.sa_iot = pba->pba_iot;
174 sa.sa_dmat = dmat;
175 sa.sa_ic = &sc->sc_isa_chipset;
176 sa.sa_pc = pba->pba_pc;
177
178 (void) config_found_sm(self, &sa, sableio_print,
179 sableio_submatch);
180 }
181 }
182
183 int
184 sableio_submatch(struct device *parent, struct cfdata *cf, void *aux)
185 {
186 struct sableio_attach_args *sa = aux;
187
188 if (cf->cf_loc[SABLEIOCF_PORT] != SABLEIOCF_PORT_DEFAULT &&
189 cf->cf_loc[SABLEIOCF_PORT] != sa->sa_ioaddr)
190 return (0);
191
192 return (config_match(parent, cf, aux));
193 }
194
195 int
196 sableio_print(void *aux, const char *pnp)
197 {
198 struct sableio_attach_args *sa = aux;
199
200 if (pnp != NULL)
201 printf("%s at %s", sa->sa_name, pnp);
202
203 printf(" port 0x%lx", sa->sa_ioaddr);
204 return (UNCONF);
205 }
206
207 isa_chipset_tag_t
208 sableio_pickisa(void)
209 {
210
211 if (sableio_attached == NULL)
212 panic("sableio_pickisa");
213
214 return (&sableio_attached->sc_isa_chipset);
215 }
216