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