This source file includes following definitions.
- wdc_isa_probe
- wdc_isa_attach
- wdc_isa_dma_setup
- wdc_isa_dma_init
- wdc_isa_dma_start
- wdc_isa_dma_finish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44 #include <sys/malloc.h>
45
46 #include <machine/bus.h>
47 #include <machine/intr.h>
48
49 #include <dev/isa/isavar.h>
50 #include <dev/isa/isadmavar.h>
51
52 #include <dev/ata/atavar.h>
53 #include <dev/ic/wdcvar.h>
54
55 #include "isadma.h"
56
57 #define WDC_ISA_REG_NPORTS 8
58 #define WDC_ISA_AUXREG_OFFSET 0x206
59 #define WDC_ISA_AUXREG_NPORTS 1
60
61
62 #define WDC_OPTIONS_32 0x01
63
64 struct wdc_isa_softc {
65 struct wdc_softc sc_wdcdev;
66 struct channel_softc *wdc_chanptr;
67 struct channel_softc wdc_channel;
68 struct device *sc_isa;
69 isa_chipset_tag_t sc_ic;
70 void *sc_ih;
71 int sc_drq;
72 };
73
74 int wdc_isa_probe(struct device *, void *, void *);
75 void wdc_isa_attach(struct device *, struct device *, void *);
76
77 struct cfattach wdc_isa_ca = {
78 sizeof(struct wdc_isa_softc), wdc_isa_probe, wdc_isa_attach
79 };
80
81 #if NISADMA > 0
82 static void wdc_isa_dma_setup(struct wdc_isa_softc *);
83 static int wdc_isa_dma_init(void *, int, int, void *, size_t, int);
84 static void wdc_isa_dma_start(void *, int, int);
85 static int wdc_isa_dma_finish(void *, int, int, int);
86 #endif
87
88 int
89 wdc_isa_probe(struct device *parent, void *match, void *aux)
90 {
91 struct channel_softc ch;
92 struct isa_attach_args *ia = aux;
93 struct cfdata *cf = match;
94 int result = 0;
95
96 bzero(&ch, sizeof ch);
97 ch.cmd_iot = ia->ia_iot;
98 if (bus_space_map(ch.cmd_iot, ia->ia_iobase, WDC_ISA_REG_NPORTS, 0,
99 &ch.cmd_ioh))
100 goto out;
101
102 ch.ctl_iot = ia->ia_iot;
103 if (bus_space_map(ch.ctl_iot, ia->ia_iobase + WDC_ISA_AUXREG_OFFSET,
104 WDC_ISA_AUXREG_NPORTS, 0, &ch.ctl_ioh))
105 goto outunmap;
106
107 if (cf->cf_flags & WDC_OPTION_PROBE_VERBOSE)
108 ch.ch_flags |= WDCF_VERBOSE_PROBE;
109
110 result = wdcprobe(&ch);
111 if (result) {
112 ia->ia_iosize = WDC_ISA_REG_NPORTS;
113 ia->ia_msize = 0;
114 }
115
116 bus_space_unmap(ch.ctl_iot, ch.ctl_ioh, WDC_ISA_AUXREG_NPORTS);
117 outunmap:
118 bus_space_unmap(ch.cmd_iot, ch.cmd_ioh, WDC_ISA_REG_NPORTS);
119 out:
120 return (result);
121 }
122
123 void
124 wdc_isa_attach(struct device *parent, struct device *self, void *aux)
125 {
126 struct wdc_isa_softc *sc = (void *)self;
127 struct isa_attach_args *ia = aux;
128
129 printf("\n");
130
131 sc->wdc_channel.cmd_iot = ia->ia_iot;
132 sc->wdc_channel.ctl_iot = ia->ia_iot;
133 sc->sc_ic = ia->ia_ic;
134 sc->sc_isa = parent;
135
136 if (bus_space_map(sc->wdc_channel.cmd_iot, ia->ia_iobase,
137 WDC_ISA_REG_NPORTS, 0, &sc->wdc_channel.cmd_ioh) ||
138 bus_space_map(sc->wdc_channel.ctl_iot,
139 ia->ia_iobase + WDC_ISA_AUXREG_OFFSET, WDC_ISA_AUXREG_NPORTS,
140 0, &sc->wdc_channel.ctl_ioh)) {
141 printf("%s: couldn't map registers\n",
142 sc->sc_wdcdev.sc_dev.dv_xname);
143 }
144 sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
145 sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_ioh;
146
147 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
148 IPL_BIO, wdcintr, &sc->wdc_channel, sc->sc_wdcdev.sc_dev.dv_xname);
149
150 if (ia->ia_drq != DRQUNK) {
151 #if NISADMA > 0
152 sc->sc_drq = ia->ia_drq;
153
154 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA;
155 sc->sc_wdcdev.dma_arg = sc;
156 sc->sc_wdcdev.dma_init = wdc_isa_dma_init;
157 sc->sc_wdcdev.dma_start = wdc_isa_dma_start;
158 sc->sc_wdcdev.dma_finish = wdc_isa_dma_finish;
159 wdc_isa_dma_setup(sc);
160 #else
161 printf("%s: ignoring drq, isa dma not supported",
162 sc->sc_wdcdev.sc_dev.dv_xname);
163 #endif
164 }
165 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_PREATA;
166 if (sc->sc_wdcdev.sc_dev.dv_cfdata->cf_flags & WDC_OPTIONS_32)
167 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
168 sc->sc_wdcdev.PIO_cap = 0;
169 sc->wdc_chanptr = &sc->wdc_channel;
170 sc->sc_wdcdev.channels = &sc->wdc_chanptr;
171 sc->sc_wdcdev.nchannels = 1;
172 sc->wdc_channel.channel = 0;
173 sc->wdc_channel.wdc = &sc->sc_wdcdev;
174 sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
175 M_DEVBUF, M_NOWAIT);
176 if (sc->wdc_channel.ch_queue == NULL) {
177 printf("%s: can't allocate memory for command queue",
178 sc->sc_wdcdev.sc_dev.dv_xname);
179 return;
180 }
181 wdcattach(&sc->wdc_channel);
182 wdc_print_current_modes(&sc->wdc_channel);
183 }
184
185 #if NISADMA > 0
186 static void
187 wdc_isa_dma_setup(struct wdc_isa_softc *sc)
188 {
189 if (isa_dmamap_create(sc->sc_isa, sc->sc_drq,
190 MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
191 printf("%s: can't create map for drq %d\n",
192 sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
193 sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
194 }
195 }
196
197 static int
198 wdc_isa_dma_init(void *v, int channel, int drive, void *databuf, size_t datalen,
199 int read)
200 {
201 struct wdc_isa_softc *sc = v;
202
203 isa_dmastart(sc->sc_isa, sc->sc_drq, databuf, datalen, NULL,
204 (read ? DMAMODE_READ : DMAMODE_WRITE),
205 BUS_DMA_NOWAIT);
206
207 return 0;
208 }
209
210 static void
211 wdc_isa_dma_start(void *v, int channel, int drive)
212 {
213
214 }
215
216 static int
217 wdc_isa_dma_finish(void *v, int channel, int drive, int force)
218 {
219 struct wdc_isa_softc *sc = v;
220
221 isa_dmadone(sc->sc_isa, sc->sc_drq);
222
223 return 0;
224 }
225 #endif