sableio.c revision 1.10 1 /* $NetBSD: sableio.c,v 1.10 2005/08/26 10:13:05 drochner 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.10 2005/08/26 10:13:05 drochner 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 #include "locators.h"
75
76 /*
77 * The devices built-in to the Sable STDIO module.
78 */
79 const struct sableio_dev {
80 const char *sd_name; /* device name */
81 bus_addr_t sd_ioaddr; /* I/O space address */
82 int sd_sableirq[2]; /* Sable IRQs */
83 int sd_drq; /* ISA DRQ */
84 } sableio_devs[] = {
85 /*
86 * See alpha/pci/pci_2100_a500.c for interrupt information.
87 */
88 { "pckbc", IO_KBD, { 6, 3 }, -1 },
89 { "fdc", IO_FD1, { 7, -1 }, 2 },
90 { "com", IO_COM1, { 15, -1 }, -1 },
91 { "com", IO_COM2, { 8, -1 }, -1 },
92 { "lpt", IO_LPT3, { 9, -1 }, -1 },
93 { NULL, 0, { -1, -1 }, -1 },
94 };
95
96 struct sableio_softc {
97 struct device sc_dev; /* base device */
98
99 /*
100 * We have to deal with ISA DMA, so that means we have to
101 * hold the ISA chipset, since we attach STDIO devices
102 * before we attach the PCI (and thus EISA) bus.
103 */
104 struct alpha_isa_chipset sc_isa_chipset;
105 };
106
107 int sableio_match(struct device *, struct cfdata *, void *);
108 void sableio_attach(struct device *, struct device *, void *);
109
110 CFATTACH_DECL(sableio, sizeof(struct sableio_softc),
111 sableio_match, sableio_attach, NULL, NULL);
112
113 int sableio_print(void *, const char *);
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 /*
123 * These are really ISA devices, and thus must be on
124 * PCI bus 0.
125 */
126 if (cf->cf_loc[SABLEIOBUSCF_BUS] != SABLEIOBUSCF_BUS_DEFAULT &&
127 cf->cf_loc[SABLEIOBUSCF_BUS] != pba->pba_bus)
128 return (0);
129
130 /* sanity */
131 if (pba->pba_bus != 0)
132 return (0);
133
134 /* There can be only one. */
135 if (sableio_attached != NULL)
136 return (0);
137
138 return (1);
139 }
140
141 void
142 sableio_attach(struct device *parent, struct device *self, void *aux)
143 {
144 struct sableio_softc *sc = (void *) self;
145 struct pcibus_attach_args *pba = aux;
146 struct sableio_attach_args sa;
147 bus_dma_tag_t dmat;
148 int i;
149 int locs[SABLEIOCF_NLOCS];
150
151 printf(": Sable STDIO module\n");
152
153 sableio_attached = sc;
154
155 dmat = alphabus_dma_get_tag(pba->pba_dmat, ALPHA_BUS_ISA);
156
157 #if NISADMA > 0
158 /*
159 * Initialize our DMA state.
160 */
161 isa_dmainit(&sc->sc_isa_chipset, pba->pba_iot, dmat, self);
162 #endif
163
164 for (i = 0; sableio_devs[i].sd_name != NULL; i++) {
165 sa.sa_name = sableio_devs[i].sd_name;
166 sa.sa_ioaddr = sableio_devs[i].sd_ioaddr;
167 sa.sa_sableirq[0] = sableio_devs[i].sd_sableirq[0];
168 sa.sa_sableirq[1] = sableio_devs[i].sd_sableirq[1];
169 sa.sa_drq = sableio_devs[i].sd_drq;
170
171 sa.sa_iot = pba->pba_iot;
172 sa.sa_dmat = dmat;
173 sa.sa_ic = &sc->sc_isa_chipset;
174 sa.sa_pc = pba->pba_pc;
175
176 locs[SABLEIOCF_PORT] = sableio_devs[i].sd_ioaddr;
177
178 (void) config_found_sm_loc(self, "sableio", locs, &sa,
179 sableio_print, config_stdsubmatch);
180 }
181 }
182
183 int
184 sableio_print(void *aux, const char *pnp)
185 {
186 struct sableio_attach_args *sa = aux;
187
188 if (pnp != NULL)
189 aprint_normal("%s at %s", sa->sa_name, pnp);
190
191 aprint_normal(" port 0x%lx", sa->sa_ioaddr);
192 return (UNCONF);
193 }
194
195 isa_chipset_tag_t
196 sableio_pickisa(void)
197 {
198
199 if (sableio_attached == NULL)
200 panic("sableio_pickisa");
201
202 return (&sableio_attached->sc_isa_chipset);
203 }
204