sableio.c revision 1.9 1 1.9 drochner /* $NetBSD: sableio.c,v 1.9 2005/08/25 18:35:38 drochner Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1 thorpej * must display the following acknowledgement:
20 1.1 thorpej * This product includes software developed by the NetBSD
21 1.1 thorpej * Foundation, Inc. and its contributors.
22 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 thorpej * contributors may be used to endorse or promote products derived
24 1.1 thorpej * from this software without specific prior written permission.
25 1.1 thorpej *
26 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1 thorpej */
38 1.1 thorpej
39 1.1 thorpej /*
40 1.1 thorpej * Driver glue for the Sable STDIO module.
41 1.1 thorpej *
42 1.1 thorpej * This is kind of a hack. The STDIO is really a junk I/O module with
43 1.1 thorpej * your regular ISA junk peripherals and their regular ISA I/O addresses.
44 1.1 thorpej * However, the main issue we have here is *interrupts*. Not only are
45 1.1 thorpej * devices IRQs strange (i.e. not what you would expect to find if they
46 1.1 thorpej * were attached to a real ISA) IRQs, the keyboard controller isn't even
47 1.1 thorpej * connected to the (E)ISA IRQ space at all!
48 1.1 thorpej *
49 1.1 thorpej * In short, we're gluing together the following things:
50 1.1 thorpej *
51 1.1 thorpej * - Standard ISA junk I/O chip
52 1.1 thorpej * - ISA DMA
53 1.1 thorpej * - Pre-mapped "PCI" interrupts that are *edge triggered*
54 1.1 thorpej */
55 1.1 thorpej
56 1.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
57 1.1 thorpej
58 1.9 drochner __KERNEL_RCSID(0, "$NetBSD: sableio.c,v 1.9 2005/08/25 18:35:38 drochner Exp $");
59 1.1 thorpej
60 1.1 thorpej #include "isadma.h"
61 1.1 thorpej
62 1.1 thorpej #include <sys/param.h>
63 1.1 thorpej #include <sys/systm.h>
64 1.1 thorpej #include <sys/device.h>
65 1.1 thorpej
66 1.1 thorpej #include <dev/isa/isareg.h>
67 1.1 thorpej #include <dev/isa/isavar.h>
68 1.1 thorpej #include <dev/isa/isadmavar.h>
69 1.1 thorpej
70 1.1 thorpej #include <dev/pci/pcivar.h>
71 1.1 thorpej
72 1.1 thorpej #include <alpha/sableio/sableiovar.h>
73 1.1 thorpej
74 1.8 drochner #include "locators.h"
75 1.8 drochner
76 1.1 thorpej /*
77 1.1 thorpej * The devices built-in to the Sable STDIO module.
78 1.1 thorpej */
79 1.1 thorpej const struct sableio_dev {
80 1.1 thorpej const char *sd_name; /* device name */
81 1.1 thorpej bus_addr_t sd_ioaddr; /* I/O space address */
82 1.1 thorpej int sd_sableirq[2]; /* Sable IRQs */
83 1.1 thorpej int sd_drq; /* ISA DRQ */
84 1.1 thorpej } sableio_devs[] = {
85 1.1 thorpej /*
86 1.1 thorpej * See alpha/pci/pci_2100_a500.c for interrupt information.
87 1.1 thorpej */
88 1.1 thorpej { "pckbc", IO_KBD, { 6, 3 }, -1 },
89 1.1 thorpej { "fdc", IO_FD1, { 7, -1 }, 2 },
90 1.1 thorpej { "com", IO_COM1, { 15, -1 }, -1 },
91 1.1 thorpej { "com", IO_COM2, { 8, -1 }, -1 },
92 1.1 thorpej { "lpt", IO_LPT3, { 9, -1 }, -1 },
93 1.1 thorpej { NULL, 0, { -1, -1 }, -1 },
94 1.1 thorpej };
95 1.1 thorpej
96 1.1 thorpej struct sableio_softc {
97 1.1 thorpej struct device sc_dev; /* base device */
98 1.1 thorpej
99 1.1 thorpej /*
100 1.1 thorpej * We have to deal with ISA DMA, so that means we have to
101 1.1 thorpej * hold the ISA chipset, since we attach STDIO devices
102 1.1 thorpej * before we attach the PCI (and thus EISA) bus.
103 1.1 thorpej */
104 1.1 thorpej struct alpha_isa_chipset sc_isa_chipset;
105 1.1 thorpej };
106 1.1 thorpej
107 1.1 thorpej int sableio_match(struct device *, struct cfdata *, void *);
108 1.1 thorpej void sableio_attach(struct device *, struct device *, void *);
109 1.1 thorpej
110 1.5 thorpej CFATTACH_DECL(sableio, sizeof(struct sableio_softc),
111 1.5 thorpej sableio_match, sableio_attach, NULL, NULL);
112 1.1 thorpej
113 1.1 thorpej int sableio_print(void *, const char *);
114 1.8 drochner int sableio_submatch(struct device *, struct cfdata *,
115 1.8 drochner const locdesc_t *, void *);
116 1.1 thorpej
117 1.1 thorpej struct sableio_softc *sableio_attached;
118 1.1 thorpej
119 1.1 thorpej int
120 1.1 thorpej sableio_match(struct device *parent, struct cfdata *cf, void *aux)
121 1.1 thorpej {
122 1.1 thorpej struct pcibus_attach_args *pba = aux;
123 1.1 thorpej
124 1.1 thorpej /*
125 1.1 thorpej * These are really ISA devices, and thus must be on
126 1.1 thorpej * PCI bus 0.
127 1.1 thorpej */
128 1.8 drochner if (cf->cf_loc[SABLEIOBUSCF_BUS] != SABLEIOBUSCF_BUS_DEFAULT &&
129 1.8 drochner cf->cf_loc[SABLEIOBUSCF_BUS] != pba->pba_bus)
130 1.1 thorpej return (0);
131 1.1 thorpej
132 1.1 thorpej /* sanity */
133 1.1 thorpej if (pba->pba_bus != 0)
134 1.1 thorpej return (0);
135 1.1 thorpej
136 1.1 thorpej /* There can be only one. */
137 1.1 thorpej if (sableio_attached != NULL)
138 1.1 thorpej return (0);
139 1.1 thorpej
140 1.1 thorpej return (1);
141 1.1 thorpej }
142 1.1 thorpej
143 1.1 thorpej void
144 1.1 thorpej sableio_attach(struct device *parent, struct device *self, void *aux)
145 1.1 thorpej {
146 1.1 thorpej struct sableio_softc *sc = (void *) self;
147 1.1 thorpej struct pcibus_attach_args *pba = aux;
148 1.1 thorpej struct sableio_attach_args sa;
149 1.1 thorpej bus_dma_tag_t dmat;
150 1.1 thorpej int i;
151 1.9 drochner int locs[SABLEIOCF_NLOCS];
152 1.1 thorpej
153 1.1 thorpej printf(": Sable STDIO module\n");
154 1.1 thorpej
155 1.1 thorpej sableio_attached = sc;
156 1.1 thorpej
157 1.1 thorpej dmat = alphabus_dma_get_tag(pba->pba_dmat, ALPHA_BUS_ISA);
158 1.1 thorpej
159 1.1 thorpej #if NISADMA > 0
160 1.1 thorpej /*
161 1.1 thorpej * Initialize our DMA state.
162 1.1 thorpej */
163 1.1 thorpej isa_dmainit(&sc->sc_isa_chipset, pba->pba_iot, dmat, self);
164 1.1 thorpej #endif
165 1.1 thorpej
166 1.1 thorpej for (i = 0; sableio_devs[i].sd_name != NULL; i++) {
167 1.1 thorpej sa.sa_name = sableio_devs[i].sd_name;
168 1.1 thorpej sa.sa_ioaddr = sableio_devs[i].sd_ioaddr;
169 1.1 thorpej sa.sa_sableirq[0] = sableio_devs[i].sd_sableirq[0];
170 1.1 thorpej sa.sa_sableirq[1] = sableio_devs[i].sd_sableirq[1];
171 1.1 thorpej sa.sa_drq = sableio_devs[i].sd_drq;
172 1.1 thorpej
173 1.1 thorpej sa.sa_iot = pba->pba_iot;
174 1.1 thorpej sa.sa_dmat = dmat;
175 1.1 thorpej sa.sa_ic = &sc->sc_isa_chipset;
176 1.1 thorpej sa.sa_pc = pba->pba_pc;
177 1.1 thorpej
178 1.9 drochner locs[SABLEIOCF_PORT] = sableio_devs[i].sd_ioaddr;
179 1.8 drochner
180 1.9 drochner (void) config_found_sm_loc(self, "sableio", locs, &sa,
181 1.8 drochner sableio_print, sableio_submatch);
182 1.1 thorpej }
183 1.1 thorpej }
184 1.1 thorpej
185 1.1 thorpej int
186 1.8 drochner sableio_submatch(struct device *parent, struct cfdata *cf,
187 1.9 drochner const locdesc_t *locs, void *aux)
188 1.1 thorpej {
189 1.1 thorpej
190 1.1 thorpej if (cf->cf_loc[SABLEIOCF_PORT] != SABLEIOCF_PORT_DEFAULT &&
191 1.9 drochner cf->cf_loc[SABLEIOCF_PORT] != locs[SABLEIOCF_PORT])
192 1.1 thorpej return (0);
193 1.1 thorpej
194 1.3 thorpej return (config_match(parent, cf, aux));
195 1.1 thorpej }
196 1.1 thorpej
197 1.1 thorpej int
198 1.1 thorpej sableio_print(void *aux, const char *pnp)
199 1.1 thorpej {
200 1.1 thorpej struct sableio_attach_args *sa = aux;
201 1.1 thorpej
202 1.1 thorpej if (pnp != NULL)
203 1.6 thorpej aprint_normal("%s at %s", sa->sa_name, pnp);
204 1.1 thorpej
205 1.6 thorpej aprint_normal(" port 0x%lx", sa->sa_ioaddr);
206 1.1 thorpej return (UNCONF);
207 1.1 thorpej }
208 1.1 thorpej
209 1.1 thorpej isa_chipset_tag_t
210 1.1 thorpej sableio_pickisa(void)
211 1.1 thorpej {
212 1.1 thorpej
213 1.1 thorpej if (sableio_attached == NULL)
214 1.1 thorpej panic("sableio_pickisa");
215 1.1 thorpej
216 1.1 thorpej return (&sableio_attached->sc_isa_chipset);
217 1.1 thorpej }
218