pdcsata.c revision 1.20 1 1.20 dyoung /* $NetBSD: pdcsata.c,v 1.20 2011/04/04 20:37:56 dyoung 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 *
15 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.3 perry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 bouyer */
26 1.1 bouyer
27 1.9 xtraeme #include <sys/cdefs.h>
28 1.20 dyoung __KERNEL_RCSID(0, "$NetBSD: pdcsata.c,v 1.20 2011/04/04 20:37:56 dyoung Exp $");
29 1.9 xtraeme
30 1.1 bouyer #include <sys/types.h>
31 1.1 bouyer #include <sys/malloc.h>
32 1.1 bouyer #include <sys/param.h>
33 1.1 bouyer #include <sys/systm.h>
34 1.1 bouyer
35 1.1 bouyer #include <dev/pci/pcivar.h>
36 1.1 bouyer #include <dev/pci/pcidevs.h>
37 1.1 bouyer #include <dev/pci/pciidereg.h>
38 1.1 bouyer #include <dev/pci/pciidevar.h>
39 1.4 christos #include <dev/ata/atareg.h>
40 1.4 christos #include <dev/ata/satavar.h>
41 1.4 christos #include <dev/ata/satareg.h>
42 1.1 bouyer
43 1.13 bouyer #define PDC203xx_SATA_NCHANNELS 4
44 1.13 bouyer #define PDC203xx_COMBO_NCHANNELS 3
45 1.13 bouyer #define PDC40718_SATA_NCHANNELS 4
46 1.13 bouyer #define PDC20575_COMBO_NCHANNELS 3
47 1.1 bouyer
48 1.1 bouyer #define PDC203xx_BAR_IDEREGS 0x1c /* BAR where the IDE registers are mapped */
49 1.1 bouyer
50 1.7 christos #define PDC_CHANNELBASE(ch) 0x200 + ((ch) * 0x80)
51 1.7 christos #define PDC_ERRMASK 0x00780700
52 1.7 christos
53 1.13 bouyer #define PDC205_REGADDR(base,ch) ((base)+((ch)<<8))
54 1.13 bouyer #define PDC205_SSTATUS(ch) PDC205_REGADDR(0x400,ch)
55 1.13 bouyer #define PDC205_SERROR(ch) PDC205_REGADDR(0x404,ch)
56 1.13 bouyer #define PDC205_SCONTROL(ch) PDC205_REGADDR(0x408,ch)
57 1.13 bouyer #define PDC205_MULTIPLIER(ch) PDC205_REGADDR(0x4e8,ch)
58 1.13 bouyer
59 1.20 dyoung static void pdcsata_chip_map(struct pciide_softc *,
60 1.20 dyoung const struct pci_attach_args *);
61 1.1 bouyer static void pdc203xx_setup_channel(struct ata_channel *);
62 1.1 bouyer static void pdc203xx_irqack(struct ata_channel *);
63 1.1 bouyer static int pdc203xx_dma_init(void *, int, int, void *, size_t, int);
64 1.1 bouyer static void pdc203xx_dma_start(void *,int ,int);
65 1.1 bouyer static int pdc203xx_dma_finish(void *, int, int, int);
66 1.13 bouyer static void pdc203xx_combo_probe(struct ata_channel *);
67 1.7 christos static int pdcsata_pci_intr(void *);
68 1.7 christos static void pdcsata_do_reset(struct ata_channel *, int);
69 1.1 bouyer
70 1.16 cube static int pdcsata_match(device_t, cfdata_t, void *);
71 1.16 cube static void pdcsata_attach(device_t, device_t, void *);
72 1.1 bouyer
73 1.16 cube CFATTACH_DECL_NEW(pdcsata, sizeof(struct pciide_softc),
74 1.1 bouyer pdcsata_match, pdcsata_attach, NULL, NULL);
75 1.1 bouyer
76 1.1 bouyer static const struct pciide_product_desc pciide_pdcsata_products[] = {
77 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20318,
78 1.1 bouyer 0,
79 1.1 bouyer "Promise PDC20318 SATA150 controller",
80 1.1 bouyer pdcsata_chip_map,
81 1.1 bouyer },
82 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20319,
83 1.1 bouyer 0,
84 1.1 bouyer "Promise PDC20319 SATA150 controller",
85 1.1 bouyer pdcsata_chip_map,
86 1.1 bouyer },
87 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20371,
88 1.1 bouyer 0,
89 1.1 bouyer "Promise PDC20371 SATA150 controller",
90 1.1 bouyer pdcsata_chip_map,
91 1.1 bouyer },
92 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20375,
93 1.1 bouyer 0,
94 1.1 bouyer "Promise PDC20375 SATA150 controller",
95 1.1 bouyer pdcsata_chip_map,
96 1.1 bouyer },
97 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20376,
98 1.1 bouyer 0,
99 1.1 bouyer "Promise PDC20376 SATA150 controller",
100 1.1 bouyer pdcsata_chip_map,
101 1.1 bouyer },
102 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20377,
103 1.1 bouyer 0,
104 1.1 bouyer "Promise PDC20377 SATA150 controller",
105 1.1 bouyer pdcsata_chip_map,
106 1.1 bouyer },
107 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20378,
108 1.1 bouyer 0,
109 1.1 bouyer "Promise PDC20378 SATA150 controller",
110 1.1 bouyer pdcsata_chip_map,
111 1.1 bouyer },
112 1.1 bouyer { PCI_PRODUCT_PROMISE_PDC20379,
113 1.1 bouyer 0,
114 1.1 bouyer "Promise PDC20379 SATA150 controller",
115 1.1 bouyer pdcsata_chip_map,
116 1.1 bouyer },
117 1.8 xtraeme { PCI_PRODUCT_PROMISE_PDC40518,
118 1.8 xtraeme 0,
119 1.11 xtraeme "Promise PDC40518 SATA150 controller",
120 1.11 xtraeme pdcsata_chip_map,
121 1.11 xtraeme },
122 1.11 xtraeme { PCI_PRODUCT_PROMISE_PDC40519,
123 1.11 xtraeme 0,
124 1.11 xtraeme "Promise PDC40519 SATA 150 controller",
125 1.8 xtraeme pdcsata_chip_map,
126 1.8 xtraeme },
127 1.4 christos { PCI_PRODUCT_PROMISE_PDC40718,
128 1.4 christos 0,
129 1.4 christos "Promise PDC40718 SATA300 controller",
130 1.4 christos pdcsata_chip_map,
131 1.4 christos },
132 1.4 christos { PCI_PRODUCT_PROMISE_PDC40719,
133 1.4 christos 0,
134 1.4 christos "Promise PDC40719 SATA300 controller",
135 1.4 christos pdcsata_chip_map,
136 1.4 christos },
137 1.11 xtraeme { PCI_PRODUCT_PROMISE_PDC40779,
138 1.11 xtraeme 0,
139 1.11 xtraeme "Promise PDC40779 SATA300 controller",
140 1.11 xtraeme pdcsata_chip_map,
141 1.11 xtraeme },
142 1.6 bouyer { PCI_PRODUCT_PROMISE_PDC20571,
143 1.6 bouyer 0,
144 1.6 bouyer "Promise PDC20571 SATA150 controller",
145 1.6 bouyer pdcsata_chip_map,
146 1.6 bouyer },
147 1.6 bouyer { PCI_PRODUCT_PROMISE_PDC20575,
148 1.6 bouyer 0,
149 1.6 bouyer "Promise PDC20575 SATA150 controller",
150 1.6 bouyer pdcsata_chip_map,
151 1.6 bouyer },
152 1.6 bouyer { PCI_PRODUCT_PROMISE_PDC20579,
153 1.6 bouyer 0,
154 1.6 bouyer "Promise PDC20579 SATA150 controller",
155 1.6 bouyer pdcsata_chip_map,
156 1.6 bouyer },
157 1.10 dsainty { PCI_PRODUCT_PROMISE_PDC20771,
158 1.10 dsainty 0,
159 1.10 dsainty "Promise PDC20771 SATA300 controller",
160 1.10 dsainty pdcsata_chip_map,
161 1.10 dsainty },
162 1.8 xtraeme { PCI_PRODUCT_PROMISE_PDC20775,
163 1.8 xtraeme 0,
164 1.8 xtraeme "Promise PDC20775 SATA300 controller",
165 1.8 xtraeme pdcsata_chip_map,
166 1.8 xtraeme },
167 1.13 bouyer { PCI_PRODUCT_PROMISE_PDC20617,
168 1.13 bouyer 0,
169 1.13 bouyer "Promise PDC2020617 Ultra/133 controller",
170 1.13 bouyer pdcsata_chip_map,
171 1.13 bouyer },
172 1.13 bouyer { PCI_PRODUCT_PROMISE_PDC20618,
173 1.13 bouyer 0,
174 1.13 bouyer "Promise PDC20618 Ultra/133 controller",
175 1.13 bouyer pdcsata_chip_map,
176 1.13 bouyer },
177 1.13 bouyer { PCI_PRODUCT_PROMISE_PDC20619,
178 1.13 bouyer 0,
179 1.13 bouyer "Promise PDC20619 Ultra/133 controller",
180 1.13 bouyer pdcsata_chip_map,
181 1.13 bouyer },
182 1.13 bouyer { PCI_PRODUCT_PROMISE_PDC20620,
183 1.13 bouyer 0,
184 1.13 bouyer "Promise PDC20620 Ultra/133 controller",
185 1.13 bouyer pdcsata_chip_map,
186 1.13 bouyer },
187 1.13 bouyer { PCI_PRODUCT_PROMISE_PDC20621,
188 1.13 bouyer 0,
189 1.13 bouyer "Promise PDC20621 Ultra/133 controller",
190 1.13 bouyer pdcsata_chip_map,
191 1.13 bouyer },
192 1.1 bouyer { 0,
193 1.1 bouyer 0,
194 1.1 bouyer NULL,
195 1.1 bouyer NULL
196 1.1 bouyer }
197 1.1 bouyer };
198 1.1 bouyer
199 1.1 bouyer static int
200 1.16 cube pdcsata_match(device_t parent, cfdata_t match, void *aux)
201 1.1 bouyer {
202 1.1 bouyer struct pci_attach_args *pa = aux;
203 1.1 bouyer
204 1.1 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_PROMISE) {
205 1.1 bouyer if (pciide_lookup_product(pa->pa_id, pciide_pdcsata_products))
206 1.1 bouyer return (2);
207 1.1 bouyer }
208 1.1 bouyer return (0);
209 1.1 bouyer }
210 1.1 bouyer
211 1.1 bouyer static void
212 1.16 cube pdcsata_attach(device_t parent, device_t self, void *aux)
213 1.1 bouyer {
214 1.1 bouyer struct pci_attach_args *pa = aux;
215 1.16 cube struct pciide_softc *sc = device_private(self);
216 1.16 cube
217 1.16 cube sc->sc_wdcdev.sc_atac.atac_dev = self;
218 1.1 bouyer
219 1.1 bouyer pciide_common_attach(sc, pa,
220 1.1 bouyer pciide_lookup_product(pa->pa_id, pciide_pdcsata_products));
221 1.1 bouyer }
222 1.1 bouyer
223 1.1 bouyer static void
224 1.20 dyoung pdcsata_chip_map(struct pciide_softc *sc, const struct pci_attach_args *pa)
225 1.1 bouyer {
226 1.1 bouyer struct pciide_channel *cp;
227 1.1 bouyer struct ata_channel *wdc_cp;
228 1.1 bouyer struct wdc_regs *wdr;
229 1.1 bouyer int channel, i;
230 1.1 bouyer pci_intr_handle_t intrhandle;
231 1.1 bouyer const char *intrstr;
232 1.1 bouyer
233 1.1 bouyer /*
234 1.1 bouyer * Promise SATA controllers have 3 or 4 channels,
235 1.1 bouyer * the usual IDE registers are mapped in I/O space, with offsets.
236 1.1 bouyer */
237 1.1 bouyer if (pci_intr_map(pa, &intrhandle) != 0) {
238 1.16 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
239 1.16 cube "couldn't map interrupt\n");
240 1.1 bouyer return;
241 1.1 bouyer }
242 1.1 bouyer intrstr = pci_intr_string(pa->pa_pc, intrhandle);
243 1.7 christos sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
244 1.7 christos intrhandle, IPL_BIO, pdcsata_pci_intr, sc);
245 1.4 christos
246 1.1 bouyer if (sc->sc_pci_ih == NULL) {
247 1.16 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
248 1.16 cube "couldn't establish native-PCI interrupt");
249 1.1 bouyer if (intrstr != NULL)
250 1.18 njoly aprint_error(" at %s", intrstr);
251 1.18 njoly aprint_error("\n");
252 1.1 bouyer return;
253 1.1 bouyer }
254 1.16 cube aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
255 1.16 cube "interrupting at %s\n",
256 1.16 cube intrstr ? intrstr : "unknown interrupt");
257 1.3 perry
258 1.1 bouyer sc->sc_dma_ok = (pci_mapreg_map(pa, PCIIDE_REG_BUS_MASTER_DMA,
259 1.1 bouyer PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_dma_iot,
260 1.19 jakllsch &sc->sc_dma_ioh, NULL, &sc->sc_dma_ios) == 0);
261 1.1 bouyer if (!sc->sc_dma_ok) {
262 1.16 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
263 1.16 cube "couldn't map bus-master DMA registers\n");
264 1.1 bouyer pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
265 1.1 bouyer return;
266 1.1 bouyer }
267 1.1 bouyer
268 1.1 bouyer sc->sc_dmat = pa->pa_dmat;
269 1.1 bouyer
270 1.1 bouyer if (pci_mapreg_map(pa, PDC203xx_BAR_IDEREGS,
271 1.1 bouyer PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_ba5_st,
272 1.19 jakllsch &sc->sc_ba5_sh, NULL, &sc->sc_ba5_ss) != 0) {
273 1.16 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
274 1.16 cube "couldn't map IDE registers\n");
275 1.19 jakllsch bus_space_unmap(sc->sc_dma_iot, sc->sc_dma_ioh, sc->sc_dma_ios);
276 1.1 bouyer pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
277 1.1 bouyer return;
278 1.1 bouyer }
279 1.1 bouyer
280 1.16 cube aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
281 1.16 cube "bus-master DMA support present\n");
282 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
283 1.1 bouyer if (sc->sc_dma_ok) {
284 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
285 1.1 bouyer }
286 1.2 bouyer if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
287 1.2 bouyer PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
288 1.2 bouyer sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
289 1.1 bouyer sc->sc_wdcdev.irqack = pdc203xx_irqack;
290 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
291 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
292 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
293 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_set_modes = pdc203xx_setup_channel;
294 1.1 bouyer sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
295 1.4 christos
296 1.7 christos sc->sc_wdcdev.reset = pdcsata_do_reset;
297 1.7 christos
298 1.4 christos switch (sc->sc_pp->ide_product) {
299 1.4 christos case PCI_PRODUCT_PROMISE_PDC20318:
300 1.4 christos case PCI_PRODUCT_PROMISE_PDC20319:
301 1.13 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x6c,
302 1.13 bouyer 0x00ff0033);
303 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
304 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_nchannels = PDC203xx_SATA_NCHANNELS;
305 1.13 bouyer break;
306 1.4 christos case PCI_PRODUCT_PROMISE_PDC20371:
307 1.4 christos case PCI_PRODUCT_PROMISE_PDC20375:
308 1.4 christos case PCI_PRODUCT_PROMISE_PDC20376:
309 1.4 christos case PCI_PRODUCT_PROMISE_PDC20377:
310 1.4 christos case PCI_PRODUCT_PROMISE_PDC20378:
311 1.4 christos case PCI_PRODUCT_PROMISE_PDC20379:
312 1.13 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x6c,
313 1.13 bouyer 0x00ff0033);
314 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_probe = pdc203xx_combo_probe;
315 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_nchannels = PDC203xx_COMBO_NCHANNELS;
316 1.4 christos break;
317 1.4 christos
318 1.8 xtraeme case PCI_PRODUCT_PROMISE_PDC40518:
319 1.11 xtraeme case PCI_PRODUCT_PROMISE_PDC40519:
320 1.4 christos case PCI_PRODUCT_PROMISE_PDC40718:
321 1.4 christos case PCI_PRODUCT_PROMISE_PDC40719:
322 1.11 xtraeme case PCI_PRODUCT_PROMISE_PDC40779:
323 1.13 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60,
324 1.13 bouyer 0x00ff00ff);
325 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_nchannels = PDC40718_SATA_NCHANNELS;
326 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
327 1.13 bouyer break;
328 1.13 bouyer
329 1.6 bouyer case PCI_PRODUCT_PROMISE_PDC20571:
330 1.6 bouyer case PCI_PRODUCT_PROMISE_PDC20575:
331 1.6 bouyer case PCI_PRODUCT_PROMISE_PDC20579:
332 1.10 dsainty case PCI_PRODUCT_PROMISE_PDC20771:
333 1.8 xtraeme case PCI_PRODUCT_PROMISE_PDC20775:
334 1.13 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60,
335 1.13 bouyer 0x00ff00ff);
336 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_nchannels = PDC20575_COMBO_NCHANNELS;
337 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_probe = pdc203xx_combo_probe;
338 1.13 bouyer break;
339 1.6 bouyer
340 1.13 bouyer case PCI_PRODUCT_PROMISE_PDC20617:
341 1.13 bouyer case PCI_PRODUCT_PROMISE_PDC20618:
342 1.13 bouyer case PCI_PRODUCT_PROMISE_PDC20619:
343 1.13 bouyer case PCI_PRODUCT_PROMISE_PDC20620:
344 1.13 bouyer case PCI_PRODUCT_PROMISE_PDC20621:
345 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_nchannels =
346 1.13 bouyer ((bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh,
347 1.13 bouyer 0x48) & 0x01) ? 1 : 0) +
348 1.13 bouyer ((bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh,
349 1.13 bouyer 0x48) & 0x02) ? 1 : 0) +
350 1.13 bouyer 2;
351 1.13 bouyer sc->sc_wdcdev.sc_atac.atac_probe = wdc_drvprobe;
352 1.6 bouyer
353 1.13 bouyer default:
354 1.13 bouyer aprint_error("unknown promise product 0x%x\n",
355 1.13 bouyer sc->sc_pp->ide_product);
356 1.4 christos }
357 1.4 christos
358 1.1 bouyer wdc_allocate_regs(&sc->sc_wdcdev);
359 1.1 bouyer
360 1.1 bouyer sc->sc_wdcdev.dma_arg = sc;
361 1.1 bouyer sc->sc_wdcdev.dma_init = pdc203xx_dma_init;
362 1.1 bouyer sc->sc_wdcdev.dma_start = pdc203xx_dma_start;
363 1.1 bouyer sc->sc_wdcdev.dma_finish = pdc203xx_dma_finish;
364 1.1 bouyer
365 1.1 bouyer for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
366 1.1 bouyer channel++) {
367 1.1 bouyer cp = &sc->pciide_channels[channel];
368 1.1 bouyer sc->wdc_chanarray[channel] = &cp->ata_channel;
369 1.1 bouyer
370 1.1 bouyer cp->ih = sc->sc_pci_ih;
371 1.1 bouyer cp->name = NULL;
372 1.1 bouyer cp->ata_channel.ch_channel = channel;
373 1.1 bouyer cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
374 1.1 bouyer cp->ata_channel.ch_queue =
375 1.1 bouyer malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
376 1.5 bouyer cp->ata_channel.ch_ndrive = 2;
377 1.1 bouyer if (cp->ata_channel.ch_queue == NULL) {
378 1.1 bouyer aprint_error("%s channel %d: "
379 1.1 bouyer "can't allocate memory for command queue\n",
380 1.16 cube device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
381 1.16 cube channel);
382 1.1 bouyer goto next_channel;
383 1.1 bouyer }
384 1.1 bouyer wdc_cp = &cp->ata_channel;
385 1.1 bouyer wdr = CHAN_TO_WDC_REGS(wdc_cp);
386 1.1 bouyer
387 1.1 bouyer wdr->ctl_iot = sc->sc_ba5_st;
388 1.1 bouyer wdr->cmd_iot = sc->sc_ba5_st;
389 1.1 bouyer
390 1.1 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
391 1.1 bouyer 0x0238 + (channel << 7), 1, &wdr->ctl_ioh) != 0) {
392 1.16 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
393 1.16 cube "couldn't map channel %d ctl regs\n", channel);
394 1.1 bouyer goto next_channel;
395 1.1 bouyer }
396 1.1 bouyer for (i = 0; i < WDC_NREG; i++) {
397 1.1 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
398 1.1 bouyer 0x0200 + (i << 2) + (channel << 7), i == 0 ? 4 : 1,
399 1.1 bouyer &wdr->cmd_iohs[i]) != 0) {
400 1.16 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
401 1.16 cube "couldn't map channel %d cmd regs\n",
402 1.1 bouyer channel);
403 1.1 bouyer goto next_channel;
404 1.1 bouyer }
405 1.1 bouyer }
406 1.1 bouyer wdc_init_shadow_regs(wdc_cp);
407 1.1 bouyer
408 1.1 bouyer /*
409 1.1 bouyer * subregion de busmaster registers. They're spread all over
410 1.1 bouyer * the controller's register space :(. They are also 4 bytes
411 1.1 bouyer * sized, with some specific extentions in the extra bits.
412 1.1 bouyer * It also seems that the IDEDMA_CTL register isn't available.
413 1.1 bouyer */
414 1.1 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
415 1.1 bouyer 0x260 + (channel << 7), 1,
416 1.1 bouyer &cp->dma_iohs[IDEDMA_CMD]) != 0) {
417 1.1 bouyer aprint_normal("%s channel %d: can't subregion DMA "
418 1.1 bouyer "registers\n",
419 1.16 cube device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
420 1.16 cube channel);
421 1.1 bouyer goto next_channel;
422 1.1 bouyer }
423 1.1 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
424 1.1 bouyer 0x244 + (channel << 7), 4,
425 1.1 bouyer &cp->dma_iohs[IDEDMA_TBL]) != 0) {
426 1.1 bouyer aprint_normal("%s channel %d: can't subregion DMA "
427 1.1 bouyer "registers\n",
428 1.16 cube device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
429 1.16 cube channel);
430 1.1 bouyer goto next_channel;
431 1.1 bouyer }
432 1.1 bouyer
433 1.13 bouyer /* subregion the SATA registers */
434 1.13 bouyer if (sc->sc_wdcdev.sc_atac.atac_probe == wdc_sataprobe ||
435 1.13 bouyer (sc->sc_wdcdev.sc_atac.atac_probe == pdc203xx_combo_probe
436 1.13 bouyer && channel < 2)) {
437 1.13 bouyer wdr->sata_iot = sc->sc_ba5_st;
438 1.13 bouyer wdr->sata_baseioh = sc->sc_ba5_sh;
439 1.13 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
440 1.13 bouyer PDC205_SSTATUS(channel), 1,
441 1.13 bouyer &wdr->sata_status) != 0) {
442 1.16 cube aprint_error_dev(
443 1.16 cube sc->sc_wdcdev.sc_atac.atac_dev,
444 1.16 cube "couldn't map channel %d "
445 1.16 cube "sata_status regs\n", channel);
446 1.13 bouyer goto next_channel;
447 1.13 bouyer }
448 1.13 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
449 1.13 bouyer PDC205_SERROR(channel), 1, &wdr->sata_error) != 0) {
450 1.16 cube aprint_error_dev(
451 1.16 cube sc->sc_wdcdev.sc_atac.atac_dev,
452 1.16 cube "couldn't map channel %d "
453 1.16 cube "sata_error regs\n", channel);
454 1.13 bouyer goto next_channel;
455 1.13 bouyer }
456 1.13 bouyer if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
457 1.13 bouyer PDC205_SCONTROL(channel), 1,
458 1.13 bouyer &wdr->sata_control) != 0) {
459 1.16 cube aprint_error_dev(
460 1.16 cube sc->sc_wdcdev.sc_atac.atac_dev,
461 1.16 cube "couldn't map channel %d "
462 1.16 cube "sata_control regs\n", channel);
463 1.13 bouyer goto next_channel;
464 1.13 bouyer }
465 1.13 bouyer }
466 1.13 bouyer
467 1.1 bouyer wdcattach(wdc_cp);
468 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
469 1.1 bouyer (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
470 1.1 bouyer 0) & ~0x00003f9f) | (channel + 1));
471 1.1 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
472 1.1 bouyer (channel + 1) << 2, 0x00000001);
473 1.1 bouyer next_channel:
474 1.1 bouyer continue;
475 1.1 bouyer }
476 1.1 bouyer return;
477 1.1 bouyer }
478 1.1 bouyer
479 1.1 bouyer static void
480 1.13 bouyer pdc203xx_combo_probe(struct ata_channel *chp)
481 1.13 bouyer {
482 1.13 bouyer if (chp->ch_channel < 2)
483 1.13 bouyer wdc_sataprobe(chp);
484 1.13 bouyer else
485 1.13 bouyer wdc_drvprobe(chp);
486 1.13 bouyer }
487 1.13 bouyer
488 1.13 bouyer static void
489 1.1 bouyer pdc203xx_setup_channel(struct ata_channel *chp)
490 1.1 bouyer {
491 1.1 bouyer struct ata_drive_datas *drvp;
492 1.1 bouyer int drive, s;
493 1.1 bouyer struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
494 1.1 bouyer
495 1.1 bouyer pciide_channel_dma_setup(cp);
496 1.1 bouyer
497 1.1 bouyer for (drive = 0; drive < 2; drive++) {
498 1.1 bouyer drvp = &chp->ch_drive[drive];
499 1.1 bouyer if ((drvp->drive_flags & DRIVE) == 0)
500 1.1 bouyer continue;
501 1.1 bouyer if (drvp->drive_flags & DRIVE_UDMA) {
502 1.1 bouyer s = splbio();
503 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
504 1.1 bouyer splx(s);
505 1.1 bouyer }
506 1.1 bouyer }
507 1.1 bouyer }
508 1.1 bouyer
509 1.1 bouyer static int
510 1.7 christos pdcsata_pci_intr(void *arg)
511 1.1 bouyer {
512 1.1 bouyer struct pciide_softc *sc = arg;
513 1.1 bouyer struct pciide_channel *cp;
514 1.1 bouyer struct ata_channel *wdc_cp;
515 1.3 perry int i, rv, crv;
516 1.7 christos u_int32_t scr, status, chanbase;
517 1.4 christos
518 1.4 christos rv = 0;
519 1.4 christos scr = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x40);
520 1.7 christos if (scr == 0xffffffff) return(rv);
521 1.4 christos bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x40, scr & 0x0000ffff);
522 1.7 christos scr = scr & 0x0000ffff;
523 1.7 christos if (!scr) return(rv);
524 1.4 christos
525 1.4 christos for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
526 1.4 christos cp = &sc->pciide_channels[i];
527 1.4 christos wdc_cp = &cp->ata_channel;
528 1.4 christos if (scr & (1 << (i + 1))) {
529 1.7 christos chanbase = PDC_CHANNELBASE(i) + 0x48;
530 1.7 christos status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
531 1.7 christos if (status & PDC_ERRMASK) {
532 1.7 christos chanbase = PDC_CHANNELBASE(i) + 0x60;
533 1.7 christos status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
534 1.7 christos status |= 0x800;
535 1.7 christos bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
536 1.7 christos status &= ~0x800;
537 1.7 christos bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
538 1.7 christos status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
539 1.7 christos continue;
540 1.7 christos }
541 1.4 christos crv = wdcintr(wdc_cp);
542 1.4 christos if (crv == 0) {
543 1.16 cube aprint_error("%s:%d: bogus intr (reg 0x%x)\n",
544 1.16 cube device_xname(
545 1.16 cube sc->sc_wdcdev.sc_atac.atac_dev), i, scr);
546 1.4 christos } else
547 1.4 christos rv = 1;
548 1.4 christos }
549 1.4 christos }
550 1.4 christos return rv;
551 1.4 christos }
552 1.4 christos
553 1.1 bouyer static void
554 1.1 bouyer pdc203xx_irqack(struct ata_channel *chp)
555 1.1 bouyer {
556 1.1 bouyer struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
557 1.1 bouyer struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
558 1.1 bouyer
559 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
560 1.1 bouyer (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
561 1.1 bouyer 0) & ~0x00003f9f) | (cp->ata_channel.ch_channel + 1));
562 1.1 bouyer bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
563 1.1 bouyer (cp->ata_channel.ch_channel + 1) << 2, 0x00000001);
564 1.1 bouyer }
565 1.1 bouyer
566 1.1 bouyer static int
567 1.1 bouyer pdc203xx_dma_init(void *v, int channel, int drive, void *databuf,
568 1.1 bouyer size_t datalen, int flags)
569 1.1 bouyer {
570 1.1 bouyer struct pciide_softc *sc = v;
571 1.1 bouyer
572 1.1 bouyer return pciide_dma_dmamap_setup(sc, channel, drive,
573 1.1 bouyer databuf, datalen, flags);
574 1.1 bouyer }
575 1.1 bouyer
576 1.1 bouyer static void
577 1.1 bouyer pdc203xx_dma_start(void *v, int channel, int drive)
578 1.1 bouyer {
579 1.1 bouyer struct pciide_softc *sc = v;
580 1.1 bouyer struct pciide_channel *cp = &sc->pciide_channels[channel];
581 1.1 bouyer struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
582 1.1 bouyer
583 1.1 bouyer /* Write table addr */
584 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_TBL], 0,
585 1.1 bouyer dma_maps->dmamap_table->dm_segs[0].ds_addr);
586 1.1 bouyer /* start DMA engine */
587 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
588 1.1 bouyer (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
589 1.1 bouyer 0) & ~0xc0) | ((dma_maps->dma_flags & WDC_DMA_READ) ? 0x80 : 0xc0));
590 1.1 bouyer }
591 1.1 bouyer
592 1.1 bouyer static int
593 1.14 christos pdc203xx_dma_finish(void *v, int channel, int drive, int force)
594 1.1 bouyer {
595 1.1 bouyer struct pciide_softc *sc = v;
596 1.1 bouyer struct pciide_channel *cp = &sc->pciide_channels[channel];
597 1.1 bouyer struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
598 1.1 bouyer
599 1.1 bouyer /* stop DMA channel */
600 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
601 1.1 bouyer (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
602 1.1 bouyer 0) & ~0x80));
603 1.1 bouyer
604 1.1 bouyer /* Unload the map of the data buffer */
605 1.1 bouyer bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
606 1.1 bouyer dma_maps->dmamap_xfer->dm_mapsize,
607 1.1 bouyer (dma_maps->dma_flags & WDC_DMA_READ) ?
608 1.1 bouyer BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
609 1.1 bouyer bus_dmamap_unload(sc->sc_dmat, dma_maps->dmamap_xfer);
610 1.1 bouyer
611 1.1 bouyer return 0;
612 1.1 bouyer }
613 1.4 christos
614 1.4 christos
615 1.4 christos static void
616 1.7 christos pdcsata_do_reset(struct ata_channel *chp, int poll)
617 1.4 christos {
618 1.4 christos struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
619 1.7 christos int reset, status, i, chanbase;
620 1.7 christos
621 1.7 christos /* reset SATA */
622 1.7 christos reset = (1 << 11);
623 1.7 christos chanbase = PDC_CHANNELBASE(chp->ch_channel) + 0x60;
624 1.7 christos for (i = 0; i < 11;i ++) {
625 1.7 christos status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
626 1.7 christos if (status & reset) break;
627 1.7 christos delay(100);
628 1.7 christos status |= reset;
629 1.7 christos bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
630 1.7 christos }
631 1.7 christos status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
632 1.7 christos status &= ~reset;
633 1.7 christos bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
634 1.7 christos status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
635 1.4 christos
636 1.4 christos wdc_do_reset(chp, poll);
637 1.4 christos }
638