piixide.c revision 1.37.14.2 1 1.37.14.2 jmcneill /* $NetBSD: piixide.c,v 1.37.14.2 2007/09/03 16:48:23 jmcneill Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 1999, 2000, 2001 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.19 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.20 lukem #include <sys/cdefs.h>
33 1.37.14.2 jmcneill __KERNEL_RCSID(0, "$NetBSD: piixide.c,v 1.37.14.2 2007/09/03 16:48:23 jmcneill Exp $");
34 1.20 lukem
35 1.1 bouyer #include <sys/param.h>
36 1.1 bouyer #include <sys/systm.h>
37 1.1 bouyer
38 1.1 bouyer #include <dev/pci/pcivar.h>
39 1.1 bouyer #include <dev/pci/pcidevs.h>
40 1.1 bouyer #include <dev/pci/pciidereg.h>
41 1.1 bouyer #include <dev/pci/pciidevar.h>
42 1.1 bouyer #include <dev/pci/pciide_piix_reg.h>
43 1.1 bouyer
44 1.2 thorpej static void piix_chip_map(struct pciide_softc*, struct pci_attach_args *);
45 1.12 thorpej static void piix_setup_channel(struct ata_channel *);
46 1.12 thorpej static void piix3_4_setup_channel(struct ata_channel *);
47 1.2 thorpej static u_int32_t piix_setup_idetim_timings(u_int8_t, u_int8_t, u_int8_t);
48 1.2 thorpej static u_int32_t piix_setup_idetim_drvs(struct ata_drive_datas *);
49 1.2 thorpej static u_int32_t piix_setup_sidetim_timings(u_int8_t, u_int8_t, u_int8_t);
50 1.5 bouyer static void piixsata_chip_map(struct pciide_softc*, struct pci_attach_args *);
51 1.37 itohy static int piix_dma_init(void *, int, int, void *, size_t, int);
52 1.2 thorpej
53 1.37.14.1 jmcneill static pnp_status_t piixide_power(device_t, pnp_request_t, void *);
54 1.2 thorpej static int piixide_match(struct device *, struct cfdata *, void *);
55 1.2 thorpej static void piixide_attach(struct device *, struct device *, void *);
56 1.1 bouyer
57 1.2 thorpej static const struct pciide_product_desc pciide_intel_products[] = {
58 1.1 bouyer { PCI_PRODUCT_INTEL_82092AA,
59 1.1 bouyer 0,
60 1.1 bouyer "Intel 82092AA IDE controller",
61 1.1 bouyer default_chip_map,
62 1.1 bouyer },
63 1.1 bouyer { PCI_PRODUCT_INTEL_82371FB_IDE,
64 1.1 bouyer 0,
65 1.1 bouyer "Intel 82371FB IDE controller (PIIX)",
66 1.1 bouyer piix_chip_map,
67 1.1 bouyer },
68 1.1 bouyer { PCI_PRODUCT_INTEL_82371SB_IDE,
69 1.1 bouyer 0,
70 1.1 bouyer "Intel 82371SB IDE Interface (PIIX3)",
71 1.1 bouyer piix_chip_map,
72 1.1 bouyer },
73 1.1 bouyer { PCI_PRODUCT_INTEL_82371AB_IDE,
74 1.1 bouyer 0,
75 1.1 bouyer "Intel 82371AB IDE controller (PIIX4)",
76 1.1 bouyer piix_chip_map,
77 1.1 bouyer },
78 1.1 bouyer { PCI_PRODUCT_INTEL_82440MX_IDE,
79 1.1 bouyer 0,
80 1.1 bouyer "Intel 82440MX IDE controller",
81 1.1 bouyer piix_chip_map
82 1.1 bouyer },
83 1.1 bouyer { PCI_PRODUCT_INTEL_82801AA_IDE,
84 1.1 bouyer 0,
85 1.1 bouyer "Intel 82801AA IDE Controller (ICH)",
86 1.1 bouyer piix_chip_map,
87 1.1 bouyer },
88 1.1 bouyer { PCI_PRODUCT_INTEL_82801AB_IDE,
89 1.1 bouyer 0,
90 1.1 bouyer "Intel 82801AB IDE Controller (ICH0)",
91 1.1 bouyer piix_chip_map,
92 1.1 bouyer },
93 1.1 bouyer { PCI_PRODUCT_INTEL_82801BA_IDE,
94 1.1 bouyer 0,
95 1.1 bouyer "Intel 82801BA IDE Controller (ICH2)",
96 1.1 bouyer piix_chip_map,
97 1.1 bouyer },
98 1.1 bouyer { PCI_PRODUCT_INTEL_82801BAM_IDE,
99 1.1 bouyer 0,
100 1.1 bouyer "Intel 82801BAM IDE Controller (ICH2-M)",
101 1.1 bouyer piix_chip_map,
102 1.1 bouyer },
103 1.1 bouyer { PCI_PRODUCT_INTEL_82801CA_IDE_1,
104 1.1 bouyer 0,
105 1.1 bouyer "Intel 82801CA IDE Controller (ICH3)",
106 1.1 bouyer piix_chip_map,
107 1.1 bouyer },
108 1.1 bouyer { PCI_PRODUCT_INTEL_82801CA_IDE_2,
109 1.1 bouyer 0,
110 1.1 bouyer "Intel 82801CA IDE Controller (ICH3)",
111 1.1 bouyer piix_chip_map,
112 1.1 bouyer },
113 1.1 bouyer { PCI_PRODUCT_INTEL_82801DB_IDE,
114 1.1 bouyer 0,
115 1.1 bouyer "Intel 82801DB IDE Controller (ICH4)",
116 1.1 bouyer piix_chip_map,
117 1.1 bouyer },
118 1.1 bouyer { PCI_PRODUCT_INTEL_82801DBM_IDE,
119 1.1 bouyer 0,
120 1.1 bouyer "Intel 82801DBM IDE Controller (ICH4-M)",
121 1.1 bouyer piix_chip_map,
122 1.1 bouyer },
123 1.1 bouyer { PCI_PRODUCT_INTEL_82801EB_IDE,
124 1.1 bouyer 0,
125 1.1 bouyer "Intel 82801EB IDE Controller (ICH5)",
126 1.1 bouyer piix_chip_map,
127 1.1 bouyer },
128 1.1 bouyer { PCI_PRODUCT_INTEL_82801EB_SATA,
129 1.1 bouyer 0,
130 1.1 bouyer "Intel 82801EB Serial ATA Controller",
131 1.5 bouyer piixsata_chip_map,
132 1.4 bouyer },
133 1.4 bouyer { PCI_PRODUCT_INTEL_82801ER_SATA,
134 1.4 bouyer 0,
135 1.4 bouyer "Intel 82801ER Serial ATA/Raid Controller",
136 1.5 bouyer piixsata_chip_map,
137 1.1 bouyer },
138 1.9 thorpej { PCI_PRODUCT_INTEL_6300ESB_IDE,
139 1.9 thorpej 0,
140 1.9 thorpej "Intel 6300ESB IDE Controller (ICH5)",
141 1.9 thorpej piix_chip_map,
142 1.9 thorpej },
143 1.9 thorpej { PCI_PRODUCT_INTEL_6300ESB_SATA,
144 1.9 thorpej 0,
145 1.9 thorpej "Intel 6300ESB Serial ATA Controller",
146 1.9 thorpej piixsata_chip_map,
147 1.9 thorpej },
148 1.22 briggs { PCI_PRODUCT_INTEL_6300ESB_RAID,
149 1.22 briggs 0,
150 1.22 briggs "Intel 6300ESB Serial ATA/RAID Controller",
151 1.22 briggs piixsata_chip_map,
152 1.22 briggs },
153 1.17 cube { PCI_PRODUCT_INTEL_82801FB_IDE,
154 1.17 cube 0,
155 1.17 cube "Intel 82801FB IDE Controller (ICH6)",
156 1.17 cube piix_chip_map,
157 1.17 cube },
158 1.16 cube { PCI_PRODUCT_INTEL_82801FB_SATA,
159 1.16 cube 0,
160 1.16 cube "Intel 82801FB Serial ATA/Raid Controller",
161 1.16 cube piixsata_chip_map,
162 1.16 cube },
163 1.16 cube { PCI_PRODUCT_INTEL_82801FR_SATA,
164 1.16 cube 0,
165 1.16 cube "Intel 82801FR Serial ATA/Raid Controller",
166 1.16 cube piixsata_chip_map,
167 1.16 cube },
168 1.21 bouyer { PCI_PRODUCT_INTEL_82801FBM_SATA,
169 1.21 bouyer 0,
170 1.21 bouyer "Intel 82801FBM Serial ATA Controller (ICH6)",
171 1.21 bouyer piixsata_chip_map,
172 1.21 bouyer },
173 1.23 tron { PCI_PRODUCT_INTEL_82801G_IDE,
174 1.23 tron 0,
175 1.23 tron "Intel 82801GB/GR IDE Controller (ICH7)",
176 1.23 tron piix_chip_map,
177 1.23 tron },
178 1.23 tron { PCI_PRODUCT_INTEL_82801G_SATA,
179 1.23 tron 0,
180 1.23 tron "Intel 82801GB/GR Serial ATA/Raid Controller (ICH7)",
181 1.23 tron piixsata_chip_map,
182 1.23 tron },
183 1.26 markd { PCI_PRODUCT_INTEL_82801GBM_SATA,
184 1.26 markd 0,
185 1.26 markd "Intel 82801GBM/GHM Serial ATA Controller (ICH7)",
186 1.26 markd piixsata_chip_map,
187 1.26 markd },
188 1.29 xtraeme { PCI_PRODUCT_INTEL_82801H_SATA_1,
189 1.29 xtraeme 0,
190 1.29 xtraeme "Intel 82801H Serial ATA Controller (ICH8)",
191 1.29 xtraeme piixsata_chip_map,
192 1.29 xtraeme },
193 1.29 xtraeme { PCI_PRODUCT_INTEL_82801H_SATA_RAID,
194 1.29 xtraeme 0,
195 1.29 xtraeme "Intel 82801H Serial ATA RAID Controller (ICH8)",
196 1.29 xtraeme piixsata_chip_map,
197 1.29 xtraeme },
198 1.29 xtraeme { PCI_PRODUCT_INTEL_82801H_SATA_2,
199 1.29 xtraeme 0,
200 1.29 xtraeme "Intel 82801H Serial ATA Controller (ICH8)",
201 1.29 xtraeme piixsata_chip_map,
202 1.29 xtraeme },
203 1.37.14.2 jmcneill { PCI_PRODUCT_INTEL_82801HBM_IDE,
204 1.37.14.2 jmcneill 0,
205 1.37.14.2 jmcneill "Intel 82801HBM IDE Controller (ICH8M)",
206 1.37.14.2 jmcneill piix_chip_map,
207 1.37.14.2 jmcneill },
208 1.29 xtraeme { PCI_PRODUCT_INTEL_82801HBM_SATA_1,
209 1.29 xtraeme 0,
210 1.29 xtraeme "Intel 82801HBM Serial ATA Controller (ICH8M)",
211 1.29 xtraeme piixsata_chip_map,
212 1.29 xtraeme },
213 1.29 xtraeme { PCI_PRODUCT_INTEL_82801HBM_SATA_2,
214 1.29 xtraeme 0,
215 1.29 xtraeme "Intel 82801HBM Serial ATA Controller (ICH8M)",
216 1.29 xtraeme piixsata_chip_map,
217 1.29 xtraeme },
218 1.28 cube { PCI_PRODUCT_INTEL_63XXESB_IDE,
219 1.28 cube 0,
220 1.28 cube "Intel 631xESB/632xESB IDE Controller",
221 1.28 cube piix_chip_map,
222 1.28 cube },
223 1.37.14.2 jmcneill { PCI_PRODUCT_INTEL_82801I_SATA_1,
224 1.37.14.2 jmcneill 0,
225 1.37.14.2 jmcneill "Intel 82801I Serial ATA Controller (ICH9)",
226 1.37.14.2 jmcneill piixsata_chip_map,
227 1.37.14.2 jmcneill },
228 1.37.14.2 jmcneill { PCI_PRODUCT_INTEL_82801I_SATA_2,
229 1.37.14.2 jmcneill 0,
230 1.37.14.2 jmcneill "Intel 82801I Serial ATA Controller (ICH9)",
231 1.37.14.2 jmcneill piixsata_chip_map,
232 1.37.14.2 jmcneill },
233 1.37.14.2 jmcneill { PCI_PRODUCT_INTEL_82801I_SATA_3,
234 1.37.14.2 jmcneill 0,
235 1.37.14.2 jmcneill "Intel 82801I Serial ATA Controller (ICH9)",
236 1.37.14.2 jmcneill piixsata_chip_map,
237 1.37.14.2 jmcneill },
238 1.28 cube { PCI_PRODUCT_INTEL_63XXESB_SATA,
239 1.28 cube 0,
240 1.28 cube "Intel 631xESB/632xESB Serial ATA Controller",
241 1.28 cube piixsata_chip_map,
242 1.28 cube },
243 1.1 bouyer { 0,
244 1.1 bouyer 0,
245 1.1 bouyer NULL,
246 1.1 bouyer NULL
247 1.1 bouyer }
248 1.1 bouyer };
249 1.1 bouyer
250 1.1 bouyer CFATTACH_DECL(piixide, sizeof(struct pciide_softc),
251 1.1 bouyer piixide_match, piixide_attach, NULL, NULL);
252 1.1 bouyer
253 1.2 thorpej static int
254 1.33 christos piixide_match(struct device *parent, struct cfdata *match,
255 1.31 christos void *aux)
256 1.1 bouyer {
257 1.1 bouyer struct pci_attach_args *pa = aux;
258 1.1 bouyer
259 1.1 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) {
260 1.1 bouyer if (pciide_lookup_product(pa->pa_id, pciide_intel_products))
261 1.1 bouyer return (2);
262 1.1 bouyer }
263 1.1 bouyer return (0);
264 1.1 bouyer }
265 1.1 bouyer
266 1.2 thorpej static void
267 1.33 christos piixide_attach(struct device *parent, struct device *self, void *aux)
268 1.1 bouyer {
269 1.1 bouyer struct pci_attach_args *pa = aux;
270 1.1 bouyer struct pciide_softc *sc = (struct pciide_softc *)self;
271 1.37.14.1 jmcneill pnp_status_t status;
272 1.1 bouyer
273 1.1 bouyer pciide_common_attach(sc, pa,
274 1.1 bouyer pciide_lookup_product(pa->pa_id, pciide_intel_products));
275 1.1 bouyer
276 1.37.14.1 jmcneill /* Setup our power handler */
277 1.37.14.1 jmcneill status = pnp_register(self, piixide_power);
278 1.37.14.1 jmcneill if (status != PNP_STATUS_SUCCESS)
279 1.37.14.1 jmcneill aprint_error("%s: couldn't establish power handler\n",
280 1.37.14.1 jmcneill device_xname(self));
281 1.37.14.1 jmcneill }
282 1.37.14.1 jmcneill
283 1.37.14.1 jmcneill static pnp_status_t
284 1.37.14.1 jmcneill piixide_power(device_t dv, pnp_request_t req, void *aux)
285 1.37.14.1 jmcneill {
286 1.37.14.1 jmcneill struct pciide_softc *sc = (struct pciide_softc *)dv;
287 1.37.14.1 jmcneill pnp_state_t *state;
288 1.37.14.1 jmcneill pnp_capabilities_t *caps;
289 1.37.14.1 jmcneill pcireg_t val;
290 1.37.14.1 jmcneill int off;
291 1.37.14.1 jmcneill
292 1.37.14.1 jmcneill switch (req) {
293 1.37.14.1 jmcneill case PNP_REQUEST_GET_CAPABILITIES:
294 1.37.14.1 jmcneill caps = (pnp_capabilities_t *)aux;
295 1.37.14.1 jmcneill pci_get_capability(sc->sc_pc, sc->sc_tag,
296 1.37.14.1 jmcneill PCI_CAP_PWRMGMT, &off, &val);
297 1.37.14.1 jmcneill caps->state = pci_pnp_capabilities(val);
298 1.37.14.1 jmcneill caps->state |= PNP_STATE_D0 | PNP_STATE_D3;
299 1.37.14.1 jmcneill break;
300 1.37.14.1 jmcneill case PNP_REQUEST_GET_STATE:
301 1.37.14.1 jmcneill state = (pnp_state_t *)aux;
302 1.37.14.1 jmcneill if (pci_get_powerstate(sc->sc_pc, sc->sc_tag, &val) != 0)
303 1.37.14.1 jmcneill *state = PNP_STATE_D0;
304 1.37.14.1 jmcneill else
305 1.37.14.1 jmcneill *state = pci_pnp_powerstate(val);
306 1.37.14.1 jmcneill break;
307 1.37.14.1 jmcneill case PNP_REQUEST_SET_STATE:
308 1.37.14.1 jmcneill state = (pnp_state_t *)aux;
309 1.18 jmcneill
310 1.37.14.1 jmcneill switch (*state) {
311 1.37.14.1 jmcneill case PNP_STATE_D3:
312 1.37.14.1 jmcneill val = PCI_PMCSR_STATE_D3;
313 1.37.14.1 jmcneill pci_conf_capture(sc->sc_pc, sc->sc_tag,
314 1.37.14.1 jmcneill &sc->sc_pciconf);
315 1.37.14.1 jmcneill sc->sc_idetim = pci_conf_read(sc->sc_pc, sc->sc_tag,
316 1.37.14.1 jmcneill PIIX_IDETIM);
317 1.37.14.1 jmcneill sc->sc_udmatim = pci_conf_read(sc->sc_pc, sc->sc_tag,
318 1.37.14.1 jmcneill PIIX_UDMATIM);
319 1.37.14.1 jmcneill break;
320 1.37.14.1 jmcneill case PNP_STATE_D0:
321 1.37.14.1 jmcneill val = PCI_PMCSR_STATE_D0;
322 1.37.14.1 jmcneill break;
323 1.37.14.1 jmcneill default:
324 1.37.14.1 jmcneill return PNP_STATUS_UNSUPPORTED;
325 1.37.14.1 jmcneill }
326 1.18 jmcneill
327 1.37.14.1 jmcneill (void)pci_set_powerstate(sc->sc_pc, sc->sc_tag, val);
328 1.37.14.1 jmcneill
329 1.37.14.1 jmcneill if (*state != PNP_STATE_D0)
330 1.37.14.1 jmcneill break;
331 1.37.14.1 jmcneill
332 1.37.14.1 jmcneill pci_conf_restore(sc->sc_pc, sc->sc_tag,
333 1.37.14.1 jmcneill &sc->sc_pciconf);
334 1.27 jmcneill pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_IDETIM,
335 1.27 jmcneill sc->sc_idetim);
336 1.27 jmcneill pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_UDMATIM,
337 1.27 jmcneill sc->sc_udmatim);
338 1.18 jmcneill break;
339 1.37.14.1 jmcneill default:
340 1.37.14.1 jmcneill return PNP_STATUS_UNSUPPORTED;
341 1.18 jmcneill }
342 1.18 jmcneill
343 1.37.14.1 jmcneill return PNP_STATUS_SUCCESS;
344 1.1 bouyer }
345 1.1 bouyer
346 1.2 thorpej static void
347 1.2 thorpej piix_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
348 1.1 bouyer {
349 1.1 bouyer struct pciide_channel *cp;
350 1.1 bouyer int channel;
351 1.1 bouyer u_int32_t idetim;
352 1.1 bouyer bus_size_t cmdsize, ctlsize;
353 1.24 bouyer pcireg_t interface = PCI_INTERFACE(pa->pa_class);
354 1.1 bouyer
355 1.1 bouyer if (pciide_chipen(sc, pa) == 0)
356 1.1 bouyer return;
357 1.1 bouyer
358 1.36 ad aprint_verbose("%s: bus-master DMA support present",
359 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
360 1.1 bouyer pciide_mapreg_dma(sc, pa);
361 1.36 ad aprint_verbose("\n");
362 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
363 1.1 bouyer if (sc->sc_dma_ok) {
364 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
365 1.1 bouyer sc->sc_wdcdev.irqack = pciide_irqack;
366 1.37 itohy /* Do all revisions require DMA alignment workaround? */
367 1.37 itohy sc->sc_wdcdev.dma_init = piix_dma_init;
368 1.1 bouyer switch(sc->sc_pp->ide_product) {
369 1.1 bouyer case PCI_PRODUCT_INTEL_82371AB_IDE:
370 1.1 bouyer case PCI_PRODUCT_INTEL_82440MX_IDE:
371 1.1 bouyer case PCI_PRODUCT_INTEL_82801AA_IDE:
372 1.1 bouyer case PCI_PRODUCT_INTEL_82801AB_IDE:
373 1.1 bouyer case PCI_PRODUCT_INTEL_82801BA_IDE:
374 1.1 bouyer case PCI_PRODUCT_INTEL_82801BAM_IDE:
375 1.1 bouyer case PCI_PRODUCT_INTEL_82801CA_IDE_1:
376 1.1 bouyer case PCI_PRODUCT_INTEL_82801CA_IDE_2:
377 1.1 bouyer case PCI_PRODUCT_INTEL_82801DB_IDE:
378 1.1 bouyer case PCI_PRODUCT_INTEL_82801DBM_IDE:
379 1.1 bouyer case PCI_PRODUCT_INTEL_82801EB_IDE:
380 1.9 thorpej case PCI_PRODUCT_INTEL_6300ESB_IDE:
381 1.17 cube case PCI_PRODUCT_INTEL_82801FB_IDE:
382 1.23 tron case PCI_PRODUCT_INTEL_82801G_IDE:
383 1.37.14.2 jmcneill case PCI_PRODUCT_INTEL_82801HBM_IDE:
384 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
385 1.1 bouyer }
386 1.1 bouyer }
387 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
388 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
389 1.1 bouyer switch(sc->sc_pp->ide_product) {
390 1.1 bouyer case PCI_PRODUCT_INTEL_82801AA_IDE:
391 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
392 1.1 bouyer break;
393 1.1 bouyer case PCI_PRODUCT_INTEL_82801BA_IDE:
394 1.1 bouyer case PCI_PRODUCT_INTEL_82801BAM_IDE:
395 1.1 bouyer case PCI_PRODUCT_INTEL_82801CA_IDE_1:
396 1.1 bouyer case PCI_PRODUCT_INTEL_82801CA_IDE_2:
397 1.1 bouyer case PCI_PRODUCT_INTEL_82801DB_IDE:
398 1.1 bouyer case PCI_PRODUCT_INTEL_82801DBM_IDE:
399 1.1 bouyer case PCI_PRODUCT_INTEL_82801EB_IDE:
400 1.9 thorpej case PCI_PRODUCT_INTEL_6300ESB_IDE:
401 1.17 cube case PCI_PRODUCT_INTEL_82801FB_IDE:
402 1.23 tron case PCI_PRODUCT_INTEL_82801G_IDE:
403 1.37.14.2 jmcneill case PCI_PRODUCT_INTEL_82801HBM_IDE:
404 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
405 1.1 bouyer break;
406 1.1 bouyer default:
407 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
408 1.1 bouyer }
409 1.1 bouyer if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82371FB_IDE)
410 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_set_modes = piix_setup_channel;
411 1.1 bouyer else
412 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_set_modes = piix3_4_setup_channel;
413 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
414 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
415 1.1 bouyer
416 1.11 thorpej ATADEBUG_PRINT(("piix_setup_chip: old idetim=0x%x",
417 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM)),
418 1.1 bouyer DEBUG_PROBE);
419 1.1 bouyer if (sc->sc_pp->ide_product != PCI_PRODUCT_INTEL_82371FB_IDE) {
420 1.11 thorpej ATADEBUG_PRINT((", sidetim=0x%x",
421 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_SIDETIM)),
422 1.1 bouyer DEBUG_PROBE);
423 1.14 thorpej if (sc->sc_wdcdev.sc_atac.atac_cap & ATAC_CAP_UDMA) {
424 1.11 thorpej ATADEBUG_PRINT((", udamreg 0x%x",
425 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_UDMAREG)),
426 1.1 bouyer DEBUG_PROBE);
427 1.1 bouyer }
428 1.1 bouyer if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AA_IDE ||
429 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AB_IDE ||
430 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BA_IDE ||
431 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BAM_IDE ||
432 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_1 ||
433 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_2 ||
434 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DB_IDE ||
435 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DBM_IDE ||
436 1.9 thorpej sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801EB_IDE ||
437 1.17 cube sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801FB_IDE ||
438 1.23 tron sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_6300ESB_IDE ||
439 1.37.14.2 jmcneill sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801G_IDE ||
440 1.37.14.2 jmcneill sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801HBM_IDE) {
441 1.11 thorpej ATADEBUG_PRINT((", IDE_CONTROL 0x%x",
442 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_CONFIG)),
443 1.1 bouyer DEBUG_PROBE);
444 1.1 bouyer }
445 1.1 bouyer
446 1.1 bouyer }
447 1.11 thorpej ATADEBUG_PRINT(("\n"), DEBUG_PROBE);
448 1.1 bouyer
449 1.12 thorpej wdc_allocate_regs(&sc->sc_wdcdev);
450 1.12 thorpej
451 1.14 thorpej for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
452 1.14 thorpej channel++) {
453 1.1 bouyer cp = &sc->pciide_channels[channel];
454 1.24 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
455 1.1 bouyer continue;
456 1.1 bouyer idetim = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM);
457 1.1 bouyer if ((PIIX_IDETIM_READ(idetim, channel) &
458 1.1 bouyer PIIX_IDETIM_IDE) == 0) {
459 1.1 bouyer #if 1
460 1.1 bouyer aprint_normal("%s: %s channel ignored (disabled)\n",
461 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
462 1.12 thorpej cp->ata_channel.ch_flags |= ATACH_DISABLED;
463 1.1 bouyer continue;
464 1.1 bouyer #else
465 1.1 bouyer pcireg_t interface;
466 1.1 bouyer
467 1.1 bouyer idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE,
468 1.1 bouyer channel);
469 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_IDETIM,
470 1.1 bouyer idetim);
471 1.1 bouyer interface = PCI_INTERFACE(pci_conf_read(sc->sc_pc,
472 1.1 bouyer sc->sc_tag, PCI_CLASS_REG));
473 1.1 bouyer aprint_normal("channel %d idetim=%08x interface=%02x\n",
474 1.1 bouyer channel, idetim, interface);
475 1.1 bouyer #endif
476 1.1 bouyer }
477 1.24 bouyer pciide_mapchan(pa, cp, interface,
478 1.24 bouyer &cmdsize, &ctlsize, pciide_pci_intr);
479 1.1 bouyer }
480 1.1 bouyer
481 1.11 thorpej ATADEBUG_PRINT(("piix_setup_chip: idetim=0x%x",
482 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM)),
483 1.1 bouyer DEBUG_PROBE);
484 1.1 bouyer if (sc->sc_pp->ide_product != PCI_PRODUCT_INTEL_82371FB_IDE) {
485 1.11 thorpej ATADEBUG_PRINT((", sidetim=0x%x",
486 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_SIDETIM)),
487 1.1 bouyer DEBUG_PROBE);
488 1.14 thorpej if (sc->sc_wdcdev.sc_atac.atac_cap & ATAC_CAP_UDMA) {
489 1.11 thorpej ATADEBUG_PRINT((", udamreg 0x%x",
490 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_UDMAREG)),
491 1.1 bouyer DEBUG_PROBE);
492 1.1 bouyer }
493 1.1 bouyer if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AA_IDE ||
494 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AB_IDE ||
495 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BA_IDE ||
496 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BAM_IDE ||
497 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_1 ||
498 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_2 ||
499 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DB_IDE ||
500 1.9 thorpej sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DBM_IDE ||
501 1.9 thorpej sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801EB_IDE ||
502 1.17 cube sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801FB_IDE ||
503 1.23 tron sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_6300ESB_IDE ||
504 1.37.14.2 jmcneill sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801G_IDE ||
505 1.37.14.2 jmcneill sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801HBM_IDE) {
506 1.11 thorpej ATADEBUG_PRINT((", IDE_CONTROL 0x%x",
507 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_CONFIG)),
508 1.1 bouyer DEBUG_PROBE);
509 1.1 bouyer }
510 1.1 bouyer }
511 1.11 thorpej ATADEBUG_PRINT(("\n"), DEBUG_PROBE);
512 1.1 bouyer }
513 1.1 bouyer
514 1.2 thorpej static void
515 1.12 thorpej piix_setup_channel(struct ata_channel *chp)
516 1.1 bouyer {
517 1.1 bouyer u_int8_t mode[2], drive;
518 1.1 bouyer u_int32_t oidetim, idetim, idedma_ctl;
519 1.13 thorpej struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
520 1.13 thorpej struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
521 1.12 thorpej struct ata_drive_datas *drvp = cp->ata_channel.ch_drive;
522 1.1 bouyer
523 1.1 bouyer oidetim = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM);
524 1.8 thorpej idetim = PIIX_IDETIM_CLEAR(oidetim, 0xffff, chp->ch_channel);
525 1.1 bouyer idedma_ctl = 0;
526 1.1 bouyer
527 1.1 bouyer /* set up new idetim: Enable IDE registers decode */
528 1.1 bouyer idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE,
529 1.8 thorpej chp->ch_channel);
530 1.1 bouyer
531 1.1 bouyer /* setup DMA */
532 1.1 bouyer pciide_channel_dma_setup(cp);
533 1.1 bouyer
534 1.1 bouyer /*
535 1.1 bouyer * Here we have to mess up with drives mode: PIIX can't have
536 1.1 bouyer * different timings for master and slave drives.
537 1.1 bouyer * We need to find the best combination.
538 1.1 bouyer */
539 1.1 bouyer
540 1.1 bouyer /* If both drives supports DMA, take the lower mode */
541 1.1 bouyer if ((drvp[0].drive_flags & DRIVE_DMA) &&
542 1.1 bouyer (drvp[1].drive_flags & DRIVE_DMA)) {
543 1.1 bouyer mode[0] = mode[1] =
544 1.1 bouyer min(drvp[0].DMA_mode, drvp[1].DMA_mode);
545 1.1 bouyer drvp[0].DMA_mode = mode[0];
546 1.1 bouyer drvp[1].DMA_mode = mode[1];
547 1.1 bouyer goto ok;
548 1.1 bouyer }
549 1.1 bouyer /*
550 1.1 bouyer * If only one drive supports DMA, use its mode, and
551 1.1 bouyer * put the other one in PIO mode 0 if mode not compatible
552 1.1 bouyer */
553 1.1 bouyer if (drvp[0].drive_flags & DRIVE_DMA) {
554 1.1 bouyer mode[0] = drvp[0].DMA_mode;
555 1.1 bouyer mode[1] = drvp[1].PIO_mode;
556 1.1 bouyer if (piix_isp_pio[mode[1]] != piix_isp_dma[mode[0]] ||
557 1.1 bouyer piix_rtc_pio[mode[1]] != piix_rtc_dma[mode[0]])
558 1.1 bouyer mode[1] = drvp[1].PIO_mode = 0;
559 1.1 bouyer goto ok;
560 1.1 bouyer }
561 1.1 bouyer if (drvp[1].drive_flags & DRIVE_DMA) {
562 1.1 bouyer mode[1] = drvp[1].DMA_mode;
563 1.1 bouyer mode[0] = drvp[0].PIO_mode;
564 1.1 bouyer if (piix_isp_pio[mode[0]] != piix_isp_dma[mode[1]] ||
565 1.1 bouyer piix_rtc_pio[mode[0]] != piix_rtc_dma[mode[1]])
566 1.1 bouyer mode[0] = drvp[0].PIO_mode = 0;
567 1.1 bouyer goto ok;
568 1.1 bouyer }
569 1.1 bouyer /*
570 1.1 bouyer * If both drives are not DMA, takes the lower mode, unless
571 1.1 bouyer * one of them is PIO mode < 2
572 1.1 bouyer */
573 1.1 bouyer if (drvp[0].PIO_mode < 2) {
574 1.1 bouyer mode[0] = drvp[0].PIO_mode = 0;
575 1.1 bouyer mode[1] = drvp[1].PIO_mode;
576 1.1 bouyer } else if (drvp[1].PIO_mode < 2) {
577 1.1 bouyer mode[1] = drvp[1].PIO_mode = 0;
578 1.1 bouyer mode[0] = drvp[0].PIO_mode;
579 1.1 bouyer } else {
580 1.1 bouyer mode[0] = mode[1] =
581 1.1 bouyer min(drvp[1].PIO_mode, drvp[0].PIO_mode);
582 1.1 bouyer drvp[0].PIO_mode = mode[0];
583 1.1 bouyer drvp[1].PIO_mode = mode[1];
584 1.1 bouyer }
585 1.1 bouyer ok: /* The modes are setup */
586 1.1 bouyer for (drive = 0; drive < 2; drive++) {
587 1.1 bouyer if (drvp[drive].drive_flags & DRIVE_DMA) {
588 1.1 bouyer idetim |= piix_setup_idetim_timings(
589 1.8 thorpej mode[drive], 1, chp->ch_channel);
590 1.1 bouyer goto end;
591 1.1 bouyer }
592 1.1 bouyer }
593 1.1 bouyer /* If we are there, none of the drives are DMA */
594 1.1 bouyer if (mode[0] >= 2)
595 1.1 bouyer idetim |= piix_setup_idetim_timings(
596 1.8 thorpej mode[0], 0, chp->ch_channel);
597 1.19 perry else
598 1.1 bouyer idetim |= piix_setup_idetim_timings(
599 1.8 thorpej mode[1], 0, chp->ch_channel);
600 1.1 bouyer end: /*
601 1.1 bouyer * timing mode is now set up in the controller. Enable
602 1.1 bouyer * it per-drive
603 1.1 bouyer */
604 1.1 bouyer for (drive = 0; drive < 2; drive++) {
605 1.1 bouyer /* If no drive, skip */
606 1.1 bouyer if ((drvp[drive].drive_flags & DRIVE) == 0)
607 1.1 bouyer continue;
608 1.1 bouyer idetim |= piix_setup_idetim_drvs(&drvp[drive]);
609 1.1 bouyer if (drvp[drive].drive_flags & DRIVE_DMA)
610 1.1 bouyer idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
611 1.1 bouyer }
612 1.1 bouyer if (idedma_ctl != 0) {
613 1.1 bouyer /* Add software bits in status register */
614 1.3 fvdl bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
615 1.1 bouyer idedma_ctl);
616 1.1 bouyer }
617 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_IDETIM, idetim);
618 1.1 bouyer }
619 1.1 bouyer
620 1.2 thorpej static void
621 1.12 thorpej piix3_4_setup_channel(struct ata_channel *chp)
622 1.1 bouyer {
623 1.1 bouyer struct ata_drive_datas *drvp;
624 1.1 bouyer u_int32_t oidetim, idetim, sidetim, udmareg, ideconf, idedma_ctl;
625 1.13 thorpej struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
626 1.13 thorpej struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
627 1.8 thorpej struct wdc_softc *wdc = &sc->sc_wdcdev;
628 1.15 thorpej int drive, s;
629 1.8 thorpej int channel = chp->ch_channel;
630 1.1 bouyer
631 1.1 bouyer oidetim = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM);
632 1.1 bouyer sidetim = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_SIDETIM);
633 1.1 bouyer udmareg = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_UDMAREG);
634 1.1 bouyer ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_CONFIG);
635 1.1 bouyer idetim = PIIX_IDETIM_CLEAR(oidetim, 0xffff, channel);
636 1.1 bouyer sidetim &= ~(PIIX_SIDETIM_ISP_MASK(channel) |
637 1.1 bouyer PIIX_SIDETIM_RTC_MASK(channel));
638 1.1 bouyer idedma_ctl = 0;
639 1.1 bouyer
640 1.1 bouyer /* set up new idetim: Enable IDE registers decode */
641 1.1 bouyer idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, channel);
642 1.1 bouyer
643 1.1 bouyer /* setup DMA if needed */
644 1.1 bouyer pciide_channel_dma_setup(cp);
645 1.1 bouyer
646 1.1 bouyer for (drive = 0; drive < 2; drive++) {
647 1.1 bouyer udmareg &= ~(PIIX_UDMACTL_DRV_EN(channel, drive) |
648 1.1 bouyer PIIX_UDMATIM_SET(0x3, channel, drive));
649 1.1 bouyer drvp = &chp->ch_drive[drive];
650 1.1 bouyer /* If no drive, skip */
651 1.1 bouyer if ((drvp->drive_flags & DRIVE) == 0)
652 1.1 bouyer continue;
653 1.1 bouyer if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
654 1.1 bouyer (drvp->drive_flags & DRIVE_UDMA) == 0))
655 1.1 bouyer goto pio;
656 1.1 bouyer
657 1.1 bouyer if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AA_IDE ||
658 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AB_IDE ||
659 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BA_IDE ||
660 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BAM_IDE ||
661 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_1 ||
662 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_2 ||
663 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DB_IDE ||
664 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DBM_IDE ||
665 1.9 thorpej sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801EB_IDE ||
666 1.17 cube sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801FB_IDE ||
667 1.23 tron sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_6300ESB_IDE ||
668 1.37.14.2 jmcneill sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801G_IDE ||
669 1.37.14.2 jmcneill sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801HBM_IDE) {
670 1.1 bouyer ideconf |= PIIX_CONFIG_PINGPONG;
671 1.1 bouyer }
672 1.1 bouyer if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BA_IDE ||
673 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BAM_IDE ||
674 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_1 ||
675 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_2 ||
676 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DB_IDE ||
677 1.1 bouyer sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DBM_IDE ||
678 1.9 thorpej sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801EB_IDE ||
679 1.17 cube sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801FB_IDE ||
680 1.23 tron sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_6300ESB_IDE ||
681 1.37.14.2 jmcneill sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801G_IDE ||
682 1.37.14.2 jmcneill sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801HBM_IDE) {
683 1.1 bouyer /* setup Ultra/100 */
684 1.1 bouyer if (drvp->UDMA_mode > 2 &&
685 1.1 bouyer (ideconf & PIIX_CONFIG_CR(channel, drive)) == 0)
686 1.1 bouyer drvp->UDMA_mode = 2;
687 1.1 bouyer if (drvp->UDMA_mode > 4) {
688 1.1 bouyer ideconf |= PIIX_CONFIG_UDMA100(channel, drive);
689 1.1 bouyer } else {
690 1.1 bouyer ideconf &= ~PIIX_CONFIG_UDMA100(channel, drive);
691 1.1 bouyer if (drvp->UDMA_mode > 2) {
692 1.1 bouyer ideconf |= PIIX_CONFIG_UDMA66(channel,
693 1.1 bouyer drive);
694 1.1 bouyer } else {
695 1.1 bouyer ideconf &= ~PIIX_CONFIG_UDMA66(channel,
696 1.1 bouyer drive);
697 1.1 bouyer }
698 1.1 bouyer }
699 1.1 bouyer }
700 1.1 bouyer if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AA_IDE) {
701 1.1 bouyer /* setup Ultra/66 */
702 1.1 bouyer if (drvp->UDMA_mode > 2 &&
703 1.1 bouyer (ideconf & PIIX_CONFIG_CR(channel, drive)) == 0)
704 1.1 bouyer drvp->UDMA_mode = 2;
705 1.1 bouyer if (drvp->UDMA_mode > 2)
706 1.1 bouyer ideconf |= PIIX_CONFIG_UDMA66(channel, drive);
707 1.1 bouyer else
708 1.1 bouyer ideconf &= ~PIIX_CONFIG_UDMA66(channel, drive);
709 1.1 bouyer }
710 1.14 thorpej if ((wdc->sc_atac.atac_cap & ATAC_CAP_UDMA) &&
711 1.1 bouyer (drvp->drive_flags & DRIVE_UDMA)) {
712 1.1 bouyer /* use Ultra/DMA */
713 1.15 thorpej s = splbio();
714 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
715 1.15 thorpej splx(s);
716 1.1 bouyer udmareg |= PIIX_UDMACTL_DRV_EN( channel, drive);
717 1.1 bouyer udmareg |= PIIX_UDMATIM_SET(
718 1.1 bouyer piix4_sct_udma[drvp->UDMA_mode], channel, drive);
719 1.1 bouyer } else {
720 1.1 bouyer /* use Multiword DMA */
721 1.15 thorpej s = splbio();
722 1.1 bouyer drvp->drive_flags &= ~DRIVE_UDMA;
723 1.15 thorpej splx(s);
724 1.1 bouyer if (drive == 0) {
725 1.1 bouyer idetim |= piix_setup_idetim_timings(
726 1.1 bouyer drvp->DMA_mode, 1, channel);
727 1.1 bouyer } else {
728 1.1 bouyer sidetim |= piix_setup_sidetim_timings(
729 1.1 bouyer drvp->DMA_mode, 1, channel);
730 1.1 bouyer idetim =PIIX_IDETIM_SET(idetim,
731 1.1 bouyer PIIX_IDETIM_SITRE, channel);
732 1.1 bouyer }
733 1.1 bouyer }
734 1.1 bouyer idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
735 1.19 perry
736 1.1 bouyer pio: /* use PIO mode */
737 1.1 bouyer idetim |= piix_setup_idetim_drvs(drvp);
738 1.1 bouyer if (drive == 0) {
739 1.1 bouyer idetim |= piix_setup_idetim_timings(
740 1.1 bouyer drvp->PIO_mode, 0, channel);
741 1.1 bouyer } else {
742 1.1 bouyer sidetim |= piix_setup_sidetim_timings(
743 1.1 bouyer drvp->PIO_mode, 0, channel);
744 1.1 bouyer idetim =PIIX_IDETIM_SET(idetim,
745 1.1 bouyer PIIX_IDETIM_SITRE, channel);
746 1.1 bouyer }
747 1.1 bouyer }
748 1.1 bouyer if (idedma_ctl != 0) {
749 1.1 bouyer /* Add software bits in status register */
750 1.3 fvdl bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
751 1.1 bouyer idedma_ctl);
752 1.1 bouyer }
753 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_IDETIM, idetim);
754 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_SIDETIM, sidetim);
755 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_UDMAREG, udmareg);
756 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_CONFIG, ideconf);
757 1.1 bouyer }
758 1.1 bouyer
759 1.1 bouyer
760 1.1 bouyer /* setup ISP and RTC fields, based on mode */
761 1.1 bouyer static u_int32_t
762 1.1 bouyer piix_setup_idetim_timings(mode, dma, channel)
763 1.1 bouyer u_int8_t mode;
764 1.1 bouyer u_int8_t dma;
765 1.1 bouyer u_int8_t channel;
766 1.1 bouyer {
767 1.19 perry
768 1.1 bouyer if (dma)
769 1.1 bouyer return PIIX_IDETIM_SET(0,
770 1.19 perry PIIX_IDETIM_ISP_SET(piix_isp_dma[mode]) |
771 1.1 bouyer PIIX_IDETIM_RTC_SET(piix_rtc_dma[mode]),
772 1.1 bouyer channel);
773 1.19 perry else
774 1.1 bouyer return PIIX_IDETIM_SET(0,
775 1.19 perry PIIX_IDETIM_ISP_SET(piix_isp_pio[mode]) |
776 1.1 bouyer PIIX_IDETIM_RTC_SET(piix_rtc_pio[mode]),
777 1.1 bouyer channel);
778 1.1 bouyer }
779 1.1 bouyer
780 1.1 bouyer /* setup DTE, PPE, IE and TIME field based on PIO mode */
781 1.1 bouyer static u_int32_t
782 1.1 bouyer piix_setup_idetim_drvs(drvp)
783 1.1 bouyer struct ata_drive_datas *drvp;
784 1.1 bouyer {
785 1.1 bouyer u_int32_t ret = 0;
786 1.12 thorpej struct ata_channel *chp = drvp->chnl_softc;
787 1.8 thorpej u_int8_t channel = chp->ch_channel;
788 1.1 bouyer u_int8_t drive = drvp->drive;
789 1.1 bouyer
790 1.1 bouyer /*
791 1.34 wiz * If drive is using UDMA, timings setups are independent
792 1.1 bouyer * So just check DMA and PIO here.
793 1.1 bouyer */
794 1.1 bouyer if (drvp->drive_flags & DRIVE_DMA) {
795 1.1 bouyer /* if mode = DMA mode 0, use compatible timings */
796 1.1 bouyer if ((drvp->drive_flags & DRIVE_DMA) &&
797 1.1 bouyer drvp->DMA_mode == 0) {
798 1.1 bouyer drvp->PIO_mode = 0;
799 1.1 bouyer return ret;
800 1.1 bouyer }
801 1.1 bouyer ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_TIME(drive), channel);
802 1.1 bouyer /*
803 1.1 bouyer * PIO and DMA timings are the same, use fast timings for PIO
804 1.1 bouyer * too, else use compat timings.
805 1.1 bouyer */
806 1.1 bouyer if ((piix_isp_pio[drvp->PIO_mode] !=
807 1.1 bouyer piix_isp_dma[drvp->DMA_mode]) ||
808 1.1 bouyer (piix_rtc_pio[drvp->PIO_mode] !=
809 1.1 bouyer piix_rtc_dma[drvp->DMA_mode]))
810 1.1 bouyer drvp->PIO_mode = 0;
811 1.1 bouyer /* if PIO mode <= 2, use compat timings for PIO */
812 1.1 bouyer if (drvp->PIO_mode <= 2) {
813 1.1 bouyer ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_DTE(drive),
814 1.1 bouyer channel);
815 1.1 bouyer return ret;
816 1.1 bouyer }
817 1.1 bouyer }
818 1.1 bouyer
819 1.1 bouyer /*
820 1.1 bouyer * Now setup PIO modes. If mode < 2, use compat timings.
821 1.1 bouyer * Else enable fast timings. Enable IORDY and prefetch/post
822 1.1 bouyer * if PIO mode >= 3.
823 1.1 bouyer */
824 1.1 bouyer
825 1.1 bouyer if (drvp->PIO_mode < 2)
826 1.1 bouyer return ret;
827 1.1 bouyer
828 1.1 bouyer ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_TIME(drive), channel);
829 1.1 bouyer if (drvp->PIO_mode >= 3) {
830 1.1 bouyer ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_IE(drive), channel);
831 1.1 bouyer ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_PPE(drive), channel);
832 1.1 bouyer }
833 1.1 bouyer return ret;
834 1.1 bouyer }
835 1.1 bouyer
836 1.1 bouyer /* setup values in SIDETIM registers, based on mode */
837 1.1 bouyer static u_int32_t
838 1.1 bouyer piix_setup_sidetim_timings(mode, dma, channel)
839 1.1 bouyer u_int8_t mode;
840 1.1 bouyer u_int8_t dma;
841 1.1 bouyer u_int8_t channel;
842 1.1 bouyer {
843 1.1 bouyer if (dma)
844 1.1 bouyer return PIIX_SIDETIM_ISP_SET(piix_isp_dma[mode], channel) |
845 1.1 bouyer PIIX_SIDETIM_RTC_SET(piix_rtc_dma[mode], channel);
846 1.19 perry else
847 1.1 bouyer return PIIX_SIDETIM_ISP_SET(piix_isp_pio[mode], channel) |
848 1.1 bouyer PIIX_SIDETIM_RTC_SET(piix_rtc_pio[mode], channel);
849 1.5 bouyer }
850 1.5 bouyer
851 1.5 bouyer static void
852 1.5 bouyer piixsata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
853 1.5 bouyer {
854 1.5 bouyer struct pciide_channel *cp;
855 1.5 bouyer bus_size_t cmdsize, ctlsize;
856 1.22 briggs pcireg_t interface, cmdsts;
857 1.35 cube int channel;
858 1.5 bouyer
859 1.5 bouyer if (pciide_chipen(sc, pa) == 0)
860 1.5 bouyer return;
861 1.5 bouyer
862 1.36 ad aprint_verbose("%s: bus-master DMA support present",
863 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
864 1.5 bouyer pciide_mapreg_dma(sc, pa);
865 1.36 ad aprint_verbose("\n");
866 1.1 bouyer
867 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
868 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
869 1.1 bouyer if (sc->sc_dma_ok) {
870 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
871 1.1 bouyer sc->sc_wdcdev.irqack = pciide_irqack;
872 1.37 itohy /* Do all revisions require DMA alignment workaround? */
873 1.37 itohy sc->sc_wdcdev.dma_init = piix_dma_init;
874 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
875 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
876 1.1 bouyer }
877 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
878 1.1 bouyer
879 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
880 1.14 thorpej sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
881 1.1 bouyer
882 1.22 briggs cmdsts = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_COMMAND_STATUS_REG);
883 1.32 drochner cmdsts &= ~PCI_COMMAND_INTERRUPT_DISABLE;
884 1.22 briggs pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_COMMAND_STATUS_REG, cmdsts);
885 1.22 briggs
886 1.22 briggs if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
887 1.22 briggs PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
888 1.22 briggs sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
889 1.22 briggs
890 1.1 bouyer interface = PCI_INTERFACE(pa->pa_class);
891 1.29 xtraeme
892 1.12 thorpej wdc_allocate_regs(&sc->sc_wdcdev);
893 1.12 thorpej
894 1.14 thorpej for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
895 1.14 thorpej channel++) {
896 1.1 bouyer cp = &sc->pciide_channels[channel];
897 1.1 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
898 1.1 bouyer continue;
899 1.1 bouyer pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
900 1.1 bouyer pciide_pci_intr);
901 1.1 bouyer }
902 1.1 bouyer }
903 1.37 itohy
904 1.37 itohy static int
905 1.37 itohy piix_dma_init(void *v, int channel, int drive, void *databuf,
906 1.37 itohy size_t datalen, int flags)
907 1.37 itohy {
908 1.37 itohy
909 1.37 itohy /* use PIO for unaligned transfer */
910 1.37 itohy if (((uintptr_t)databuf) & 0x1)
911 1.37 itohy return EINVAL;
912 1.37 itohy
913 1.37 itohy return pciide_dma_init(v, channel, drive, databuf, datalen, flags);
914 1.37 itohy }
915