pdcsata.c revision 1.1 1 1.1 bouyer /* $NetBSD: pdcsata.c,v 1.1 2004/11/24 20:49:19 bouyer Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 2004, Manuel Bouyer.
5 1.1 bouyer *
6 1.1 bouyer * Redistribution and use in source and binary forms, with or without
7 1.1 bouyer * modification, are permitted provided that the following conditions
8 1.1 bouyer * are met:
9 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.1 bouyer * notice, this list of conditions and the following disclaimer.
11 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.1 bouyer * documentation and/or other materials provided with the distribution.
14 1.1 bouyer * 3. All advertising materials mentioning features or use of this software
15 1.1 bouyer * must display the following acknowledgement:
16 1.1 bouyer * This product includes software developed by Manuel Bouyer.
17 1.1 bouyer * 4. The name of the author may not be used to endorse or promote products
18 1.1 bouyer * derived from this software without specific prior written permission.
19 1.1 bouyer *
20 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 bouyer */
31 1.1 bouyer
32 1.1 bouyer #include <sys/types.h>
33 1.1 bouyer #include <sys/malloc.h>
34 1.1 bouyer #include <sys/param.h>
35 1.1 bouyer #include <sys/systm.h>
36 1.1 bouyer
37 1.1 bouyer #include <dev/pci/pcivar.h>
38 1.1 bouyer #include <dev/pci/pcidevs.h>
39 1.1 bouyer #include <dev/pci/pciidereg.h>
40 1.1 bouyer #include <dev/pci/pciidevar.h>
41 1.1 bouyer
42 1.1 bouyer #define PDC203xx_NCHANNELS 4
43 1.1 bouyer
44 1.1 bouyer #define PDC203xx_BAR_IDEREGS 0x1c /* BAR where the IDE registers are mapped */
45 1.1 bouyer
46 1.1 bouyer static void pdcsata_chip_map(struct pciide_softc *, struct pci_attach_args *);
47 1.1 bouyer static void pdc203xx_setup_channel(struct ata_channel *);
48 1.1 bouyer static int pdc203xx_pci_intr(void *);
49 1.1 bouyer static void pdc203xx_irqack(struct ata_channel *);
50 1.1 bouyer static int pdc203xx_dma_init(void *, int, int, void *, size_t, int);
51 1.1 bouyer static void pdc203xx_dma_start(void *,int ,int);
52 1.1 bouyer static int pdc203xx_dma_finish(void *, int, int, int);
53 1.1 bouyer
54 1.1 bouyer static int pdcsata_match(struct device *, struct cfdata *, void *);
55 1.1 bouyer static void pdcsata_attach(struct device *, struct device *, void *);
56 1.1 bouyer
57 1.1 bouyer CFATTACH_DECL(pdcsata, sizeof(struct pciide_softc),
58 1.1 bouyer pdcsata_match, pdcsata_attach, NULL, NULL);
59 1.1 bouyer
60 1.1 bouyer static const struct pciide_product_desc pciide_pdcsata_products[] = {
61 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20318,
62 1.1 bouyer 0,
63 1.1 bouyer "Promise PDC20318 SATA150 controller",
64 1.1 bouyer pdcsata_chip_map,
65 1.1 bouyer },
66 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20319,
67 1.1 bouyer 0,
68 1.1 bouyer "Promise PDC20319 SATA150 controller",
69 1.1 bouyer pdcsata_chip_map,
70 1.1 bouyer },
71 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20371,
72 1.1 bouyer 0,
73 1.1 bouyer "Promise PDC20371 SATA150 controller",
74 1.1 bouyer pdcsata_chip_map,
75 1.1 bouyer },
76 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20375,
77 1.1 bouyer 0,
78 1.1 bouyer "Promise PDC20375 SATA150 controller",
79 1.1 bouyer pdcsata_chip_map,
80 1.1 bouyer },
81 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20376,
82 1.1 bouyer 0,
83 1.1 bouyer "Promise PDC20376 SATA150 controller",
84 1.1 bouyer pdcsata_chip_map,
85 1.1 bouyer },
86 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20377,
87 1.1 bouyer 0,
88 1.1 bouyer "Promise PDC20377 SATA150 controller",
89 1.1 bouyer pdcsata_chip_map,
90 1.1 bouyer },
91 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20378,
92 1.1 bouyer 0,
93 1.1 bouyer "Promise PDC20378 SATA150 controller",
94 1.1 bouyer pdcsata_chip_map,
95 1.1 bouyer },
96 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20379,
97 1.1 bouyer 0,
98 1.1 bouyer "Promise PDC20379 SATA150 controller",
99 1.1 bouyer pdcsata_chip_map,
100 1.1 bouyer },
101 1.1 bouyer { 0,
102 1.1 bouyer 0,
103 1.1 bouyer NULL,
104 1.1 bouyer NULL
105 1.1 bouyer }
106 1.1 bouyer };
107 1.1 bouyer
108 1.1 bouyer static int
109 1.1 bouyer pdcsata_match(struct device *parent, struct cfdata *match, void *aux)
110 1.1 bouyer {
111 1.1 bouyer struct pci_attach_args *pa = aux;
112 1.1 bouyer
113 1.1 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_PROMISE) {
114 1.1 bouyer if (pciide_lookup_product(pa->pa_id, pciide_pdcsata_products))
115 1.1 bouyer return (2);
116 1.1 bouyer }
117 1.1 bouyer return (0);
118 1.1 bouyer }
119 1.1 bouyer
120 1.1 bouyer static void
121 1.1 bouyer pdcsata_attach(struct device *parent, struct device *self, void *aux)
122 1.1 bouyer {
123 1.1 bouyer struct pci_attach_args *pa = aux;
124 1.1 bouyer struct pciide_softc *sc = (struct pciide_softc *)self;
125 1.1 bouyer
126 1.1 bouyer pciide_common_attach(sc, pa,
127 1.1 bouyer pciide_lookup_product(pa->pa_id, pciide_pdcsata_products));
128 1.1 bouyer }
129 1.1 bouyer
130 1.1 bouyer static void
131 1.1 bouyer pdcsata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
132 1.1 bouyer {
133 1.1 bouyer struct pciide_channel *cp;
134 1.1 bouyer struct ata_channel *wdc_cp;
135 1.1 bouyer struct wdc_regs *wdr;
136 1.1 bouyer int channel, i;
137 1.1 bouyer bus_size_t dmasize;
138 1.1 bouyer pci_intr_handle_t intrhandle;
139 1.1 bouyer const char *intrstr;
140 1.1 bouyer
141 1.1 bouyer /*
142 1.1 bouyer * Promise SATA controllers have 3 or 4 channels,
143 1.1 bouyer * the usual IDE registers are mapped in I/O space, with offsets.
144 1.1 bouyer */
145 1.1 bouyer if (pci_intr_map(pa, &intrhandle) != 0) {
146 1.1 bouyer aprint_error("%s: couldn't map interrupt\n",
147 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
148 1.1 bouyer return;
149 1.1 bouyer }
150 1.1 bouyer intrstr = pci_intr_string(pa->pa_pc, intrhandle);
151 1.1 bouyer sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
152 1.1 bouyer intrhandle, IPL_BIO, pdc203xx_pci_intr, sc);
153 1.1 bouyer if (sc->sc_pci_ih == NULL) {
154 1.1 bouyer aprint_error("%s: couldn't establish native-PCI interrupt",
155 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
156 1.1 bouyer if (intrstr != NULL)
157 1.1 bouyer aprint_normal(" at %s", intrstr);
158 1.1 bouyer aprint_normal("\n");
159 1.1 bouyer return;
160 1.1 bouyer }
161 1.1 bouyer aprint_normal("%s: interrupting at %s\n",
162 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
163 1.1 bouyer intrstr ? intrstr : "unknown interrupt");
164 1.1 bouyer
165 1.1 bouyer sc->sc_dma_ok = (pci_mapreg_map(pa, PCIIDE_REG_BUS_MASTER_DMA,
166 1.1 bouyer PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_dma_iot,
167 1.1 bouyer &sc->sc_dma_ioh, NULL, &dmasize) == 0);
168 1.1 bouyer if (!sc->sc_dma_ok) {
169 1.1 bouyer aprint_error("%s: couldn't map bus-master DMA registers\n",
170 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
171 1.1 bouyer pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
172 1.1 bouyer return;
173 1.1 bouyer }
174 1.1 bouyer
175 1.1 bouyer sc->sc_dmat = pa->pa_dmat;
176 1.1 bouyer
177 1.1 bouyer if (pci_mapreg_map(pa, PDC203xx_BAR_IDEREGS,
178 1.1 bouyer PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_ba5_st,
179 1.1 bouyer &sc->sc_ba5_sh, NULL, NULL) != 0) {
180 1.1 bouyer aprint_error("%s: couldn't map IDE registers\n",
181 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
182 1.1 bouyer bus_space_unmap(sc->sc_dma_iot, sc->sc_dma_ioh, dmasize);
183 1.1 bouyer pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
184 1.1 bouyer return;
185 1.1 bouyer }
186 1.1 bouyer
187 1.1 bouyer aprint_normal("%s: bus-master DMA support present\n",
188 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
189 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
190 1.1 bouyer if (sc->sc_dma_ok) {
191 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
192 1.1 bouyer }
193 1.1 bouyer sc->sc_wdcdev.irqack = pdc203xx_irqack;
194 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
195 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
196 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
197 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_set_modes = pdc203xx_setup_channel;
198 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
199 1.1 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x06c, 0x00ff0033);
200 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_nchannels =
201 1.1 bouyer (bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x48) & 0x02) ?
202 1.1 bouyer PDC203xx_NCHANNELS : 3;
203 1.1 bouyer wdc_allocate_regs(&sc->sc_wdcdev);
204 1.1 bouyer
205 1.1 bouyer sc->sc_wdcdev.dma_arg = sc;
206 1.1 bouyer sc->sc_wdcdev.dma_init = pdc203xx_dma_init;
207 1.1 bouyer sc->sc_wdcdev.dma_start = pdc203xx_dma_start;
208 1.1 bouyer sc->sc_wdcdev.dma_finish = pdc203xx_dma_finish;
209 1.1 bouyer
210 1.1 bouyer for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
211 1.1 bouyer channel++) {
212 1.1 bouyer cp = &sc->pciide_channels[channel];
213 1.1 bouyer sc->wdc_chanarray[channel] = &cp->ata_channel;
214 1.1 bouyer
215 1.1 bouyer cp->ih = sc->sc_pci_ih;
216 1.1 bouyer cp->name = NULL;
217 1.1 bouyer cp->ata_channel.ch_channel = channel;
218 1.1 bouyer cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
219 1.1 bouyer cp->ata_channel.ch_queue =
220 1.1 bouyer malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
221 1.1 bouyer if (cp->ata_channel.ch_queue == NULL) {
222 1.1 bouyer aprint_error("%s channel %d: "
223 1.1 bouyer "can't allocate memory for command queue\n",
224 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
225 1.1 bouyer goto next_channel;
226 1.1 bouyer }
227 1.1 bouyer wdc_cp = &cp->ata_channel;
228 1.1 bouyer wdr = CHAN_TO_WDC_REGS(wdc_cp);
229 1.1 bouyer
230 1.1 bouyer wdr->ctl_iot = sc->sc_ba5_st;
231 1.1 bouyer wdr->cmd_iot = sc->sc_ba5_st;
232 1.1 bouyer
233 1.1 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
234 1.1 bouyer 0x0238 + (channel << 7), 1, &wdr->ctl_ioh) != 0) {
235 1.1 bouyer aprint_error("%s: couldn't map channel %d ctl regs\n",
236 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
237 1.1 bouyer channel);
238 1.1 bouyer goto next_channel;
239 1.1 bouyer }
240 1.1 bouyer for (i = 0; i < WDC_NREG; i++) {
241 1.1 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
242 1.1 bouyer 0x0200 + (i << 2) + (channel << 7), i == 0 ? 4 : 1,
243 1.1 bouyer &wdr->cmd_iohs[i]) != 0) {
244 1.1 bouyer aprint_error("%s: couldn't map channel %d cmd "
245 1.1 bouyer "regs\n",
246 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
247 1.1 bouyer channel);
248 1.1 bouyer goto next_channel;
249 1.1 bouyer }
250 1.1 bouyer }
251 1.1 bouyer wdc_init_shadow_regs(wdc_cp);
252 1.1 bouyer
253 1.1 bouyer /*
254 1.1 bouyer * subregion de busmaster registers. They're spread all over
255 1.1 bouyer * the controller's register space :(. They are also 4 bytes
256 1.1 bouyer * sized, with some specific extentions in the extra bits.
257 1.1 bouyer * It also seems that the IDEDMA_CTL register isn't available.
258 1.1 bouyer */
259 1.1 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
260 1.1 bouyer 0x260 + (channel << 7), 1,
261 1.1 bouyer &cp->dma_iohs[IDEDMA_CMD]) != 0) {
262 1.1 bouyer aprint_normal("%s channel %d: can't subregion DMA "
263 1.1 bouyer "registers\n",
264 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
265 1.1 bouyer goto next_channel;
266 1.1 bouyer }
267 1.1 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
268 1.1 bouyer 0x244 + (channel << 7), 4,
269 1.1 bouyer &cp->dma_iohs[IDEDMA_TBL]) != 0) {
270 1.1 bouyer aprint_normal("%s channel %d: can't subregion DMA "
271 1.1 bouyer "registers\n",
272 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
273 1.1 bouyer goto next_channel;
274 1.1 bouyer }
275 1.1 bouyer
276 1.1 bouyer wdcattach(wdc_cp);
277 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
278 1.1 bouyer (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
279 1.1 bouyer 0) & ~0x00003f9f) | (channel + 1));
280 1.1 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
281 1.1 bouyer (channel + 1) << 2, 0x00000001);
282 1.1 bouyer next_channel:
283 1.1 bouyer continue;
284 1.1 bouyer }
285 1.1 bouyer return;
286 1.1 bouyer }
287 1.1 bouyer
288 1.1 bouyer static void
289 1.1 bouyer pdc203xx_setup_channel(struct ata_channel *chp)
290 1.1 bouyer {
291 1.1 bouyer struct ata_drive_datas *drvp;
292 1.1 bouyer int drive, s;
293 1.1 bouyer struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
294 1.1 bouyer
295 1.1 bouyer pciide_channel_dma_setup(cp);
296 1.1 bouyer
297 1.1 bouyer for (drive = 0; drive < 2; drive++) {
298 1.1 bouyer drvp = &chp->ch_drive[drive];
299 1.1 bouyer if ((drvp->drive_flags & DRIVE) == 0)
300 1.1 bouyer continue;
301 1.1 bouyer if (drvp->drive_flags & DRIVE_UDMA) {
302 1.1 bouyer s = splbio();
303 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
304 1.1 bouyer splx(s);
305 1.1 bouyer }
306 1.1 bouyer }
307 1.1 bouyer }
308 1.1 bouyer
309 1.1 bouyer static int
310 1.1 bouyer pdc203xx_pci_intr(void *arg)
311 1.1 bouyer {
312 1.1 bouyer struct pciide_softc *sc = arg;
313 1.1 bouyer struct pciide_channel *cp;
314 1.1 bouyer struct ata_channel *wdc_cp;
315 1.1 bouyer int i, rv, crv;
316 1.1 bouyer u_int32_t scr;
317 1.1 bouyer
318 1.1 bouyer rv = 0;
319 1.1 bouyer scr = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x00040);
320 1.1 bouyer
321 1.1 bouyer for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
322 1.1 bouyer cp = &sc->pciide_channels[i];
323 1.1 bouyer wdc_cp = &cp->ata_channel;
324 1.1 bouyer if (scr & (1 << (i + 1))) {
325 1.1 bouyer crv = wdcintr(wdc_cp);
326 1.1 bouyer if (crv == 0) {
327 1.1 bouyer printf("%s:%d: bogus intr (reg 0x%x)\n",
328 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
329 1.1 bouyer i, scr);
330 1.1 bouyer } else
331 1.1 bouyer rv = 1;
332 1.1 bouyer }
333 1.1 bouyer }
334 1.1 bouyer return rv;
335 1.1 bouyer }
336 1.1 bouyer
337 1.1 bouyer static void
338 1.1 bouyer pdc203xx_irqack(struct ata_channel *chp)
339 1.1 bouyer {
340 1.1 bouyer struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
341 1.1 bouyer struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
342 1.1 bouyer
343 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
344 1.1 bouyer (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
345 1.1 bouyer 0) & ~0x00003f9f) | (cp->ata_channel.ch_channel + 1));
346 1.1 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
347 1.1 bouyer (cp->ata_channel.ch_channel + 1) << 2, 0x00000001);
348 1.1 bouyer }
349 1.1 bouyer
350 1.1 bouyer static int
351 1.1 bouyer pdc203xx_dma_init(void *v, int channel, int drive, void *databuf,
352 1.1 bouyer size_t datalen, int flags)
353 1.1 bouyer {
354 1.1 bouyer struct pciide_softc *sc = v;
355 1.1 bouyer
356 1.1 bouyer return pciide_dma_dmamap_setup(sc, channel, drive,
357 1.1 bouyer databuf, datalen, flags);
358 1.1 bouyer }
359 1.1 bouyer
360 1.1 bouyer static void
361 1.1 bouyer pdc203xx_dma_start(void *v, int channel, int drive)
362 1.1 bouyer {
363 1.1 bouyer struct pciide_softc *sc = v;
364 1.1 bouyer struct pciide_channel *cp = &sc->pciide_channels[channel];
365 1.1 bouyer struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
366 1.1 bouyer
367 1.1 bouyer /* Write table addr */
368 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_TBL], 0,
369 1.1 bouyer dma_maps->dmamap_table->dm_segs[0].ds_addr);
370 1.1 bouyer /* start DMA engine */
371 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
372 1.1 bouyer (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
373 1.1 bouyer 0) & ~0xc0) | ((dma_maps->dma_flags & WDC_DMA_READ) ? 0x80 : 0xc0));
374 1.1 bouyer }
375 1.1 bouyer
376 1.1 bouyer static int
377 1.1 bouyer pdc203xx_dma_finish(void *v, int channel, int drive, int force)
378 1.1 bouyer {
379 1.1 bouyer struct pciide_softc *sc = v;
380 1.1 bouyer struct pciide_channel *cp = &sc->pciide_channels[channel];
381 1.1 bouyer struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
382 1.1 bouyer
383 1.1 bouyer /* stop DMA channel */
384 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
385 1.1 bouyer (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
386 1.1 bouyer 0) & ~0x80));
387 1.1 bouyer
388 1.1 bouyer /* Unload the map of the data buffer */
389 1.1 bouyer bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
390 1.1 bouyer dma_maps->dmamap_xfer->dm_mapsize,
391 1.1 bouyer (dma_maps->dma_flags & WDC_DMA_READ) ?
392 1.1 bouyer BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
393 1.1 bouyer bus_dmamap_unload(sc->sc_dmat, dma_maps->dmamap_xfer);
394 1.1 bouyer
395 1.1 bouyer return 0;
396 1.1 bouyer }
397