wdc_isa.c revision 1.1 1 /* $NetBSD: wdc_isa.c,v 1.1 1998/01/14 23:42:07 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
5 *
6 * DMA and multi-sector PIO handling are derived from code contributed by
7 * Onno van der Linden.
8 *
9 * ISA attachment created by Christopher G. Demetriou.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Charles M. Hannum.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/conf.h>
41 #include <sys/file.h>
42 #include <sys/stat.h>
43 #include <sys/ioctl.h>
44 #include <sys/buf.h>
45 #include <sys/uio.h>
46 #include <sys/malloc.h>
47 #include <sys/device.h>
48 #include <sys/disklabel.h>
49 #include <sys/disk.h>
50 #include <sys/syslog.h>
51 #include <sys/proc.h>
52
53 #include <machine/intr.h>
54 #include <machine/bus.h>
55
56 #include <dev/isa/isavar.h>
57 #include <dev/isa/isadmavar.h>
58 #include <dev/ic/wdcvar.h>
59
60 #define WDC_ISA_REG_NPORTS 8
61 #define WDC_ISA_AUXREG_OFFSET 0x206
62 #define WDC_ISA_AUXREG_NPORTS 1
63
64 /*
65 * XXX This code currently doesn't even try to allow 32-bit data port use.
66 */
67
68 struct wdc_isa_softc {
69 struct wdc_softc sc_wdcdev;
70 struct wdc_attachment_data sc_ad;
71 void *sc_ih;
72 int sc_drq;
73 };
74
75 #ifdef __BROKEN_INDIRECT_CONFIG
76 int wdc_isa_probe __P((struct device *, void *, void *));
77 #else
78 int wdc_isa_probe __P((struct device *, struct cfdata *, void *));
79 #endif
80 void wdc_isa_attach __P((struct device *, struct device *, void *));
81
82 struct cfattach wdc_isa_ca = {
83 sizeof(struct wdc_isa_softc), wdc_isa_probe, wdc_isa_attach
84 };
85
86 static void wdc_isa_dma_setup __P((void *));
87 static void wdc_isa_dma_start __P((void *, void *, size_t, int));
88 static void wdc_isa_dma_finish __P((void *));
89
90 int
91 wdc_isa_probe(parent, match, aux)
92 struct device *parent;
93 #ifdef __BROKEN_INDIRECT_CONFIG
94 void *match;
95 #else
96 struct cfdata *match;
97 #endif
98 void *aux;
99 {
100 #if 0 /* XXX memset */
101 struct wdc_attachment_data ad = { 0 };
102 #else /* XXX memset */
103 struct wdc_attachment_data ad;
104 #endif /* XXX memset */
105 struct isa_attach_args *ia = aux;
106 int result = 0;
107
108 #if 0 /* XXX memset */
109 #else /* XXX memset */
110 bzero(&ad, sizeof ad);
111 #endif /* XXX memset */
112 ad.iot = ia->ia_iot;
113 if (bus_space_map(ad.iot, ia->ia_iobase, WDC_ISA_REG_NPORTS, 0,
114 &ad.ioh))
115 goto out;
116
117 ad.auxiot = ia->ia_iot;
118 if (bus_space_map(ad.auxiot, ia->ia_iobase + WDC_ISA_AUXREG_OFFSET,
119 WDC_ISA_AUXREG_NPORTS, 0, &ad.auxioh))
120 goto outunmap;
121
122 result = wdcprobe(&ad);
123 if (result) {
124 ia->ia_iosize = WDC_ISA_REG_NPORTS;
125 ia->ia_msize = 0;
126 }
127
128 outunmap:
129 bus_space_unmap(ad.auxiot, ad.auxioh, WDC_ISA_AUXREG_NPORTS);
130 out:
131 bus_space_unmap(ad.iot, ad.ioh, WDC_ISA_REG_NPORTS);
132 return (result);
133 }
134
135 void
136 wdc_isa_attach(parent, self, aux)
137 struct device *parent, *self;
138 void *aux;
139 {
140 struct wdc_isa_softc *sc = (struct wdc_isa_softc *)self;
141 struct isa_attach_args *ia = aux;
142
143 bzero(&sc->sc_ad, sizeof sc->sc_ad);
144 sc->sc_ad.iot = ia->ia_iot;
145 sc->sc_ad.auxiot = ia->ia_iot;
146 if (bus_space_map(sc->sc_ad.iot, ia->ia_iobase, WDC_ISA_REG_NPORTS, 0,
147 &sc->sc_ad.ioh) ||
148 bus_space_map(sc->sc_ad.auxiot,
149 ia->ia_iobase + WDC_ISA_AUXREG_OFFSET, WDC_ISA_AUXREG_NPORTS,
150 0, &sc->sc_ad.auxioh)) {
151 printf(": couldn't map registers\n");
152 panic("wdc_isa_attach: couldn't map registers\n");
153 }
154
155 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
156 IPL_BIO, wdcintr, sc);
157
158 if (ia->ia_drq != DRQUNK) {
159 sc->sc_drq = ia->ia_drq;
160
161 sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
162 sc->sc_ad.dma_setup = &wdc_isa_dma_setup;
163 sc->sc_ad.dma_start = &wdc_isa_dma_start;
164 sc->sc_ad.dma_finish = &wdc_isa_dma_finish;
165 }
166
167 wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
168 }
169
170 static void
171 wdc_isa_dma_setup(scv)
172 void *scv;
173 {
174 struct wdc_isa_softc *sc = scv;
175
176 if (isa_dmamap_create(sc->sc_wdcdev.sc_dev.dv_parent, sc->sc_drq,
177 MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
178 printf("%s: can't create map for drq %d\n",
179 sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
180 sc->sc_ad.cap &= ~WDC_CAPABILITY_DMA;
181 }
182 }
183
184 static void
185 wdc_isa_dma_start(scv, buf, size, read)
186 void *scv, *buf;
187 size_t size;
188 int read;
189 {
190 struct wdc_isa_softc *sc = scv;
191
192 isa_dmastart(sc->sc_wdcdev.sc_dev.dv_parent, sc->sc_drq, buf,
193 size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
194 BUS_DMA_NOWAIT);
195 }
196
197 static void
198 wdc_isa_dma_finish(scv)
199 void *scv;
200 {
201 struct wdc_isa_softc *sc = scv;
202
203 isa_dmadone(sc->sc_wdcdev.sc_dev.dv_parent, sc->sc_drq);
204 }
205