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