viaide.c revision 1.24.2.4 1 1.24.2.1 riz /* $NetBSD: viaide.c,v 1.24.2.4 2006/08/03 12:20:09 tron 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.24 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.1 bouyer
33 1.1 bouyer #include <sys/param.h>
34 1.1 bouyer #include <sys/systm.h>
35 1.1 bouyer
36 1.1 bouyer #include <dev/pci/pcivar.h>
37 1.1 bouyer #include <dev/pci/pcidevs.h>
38 1.1 bouyer #include <dev/pci/pciidereg.h>
39 1.1 bouyer #include <dev/pci/pciidevar.h>
40 1.1 bouyer #include <dev/pci/pciide_apollo_reg.h>
41 1.1 bouyer
42 1.5 fvdl static int via_pcib_match(struct pci_attach_args *);
43 1.4 enami static void via_chip_map(struct pciide_softc *, struct pci_attach_args *);
44 1.4 enami static void via_sata_chip_map(struct pciide_softc *,
45 1.4 enami struct pci_attach_args *);
46 1.15 thorpej static void via_setup_channel(struct ata_channel *);
47 1.4 enami
48 1.4 enami static int viaide_match(struct device *, struct cfdata *, void *);
49 1.4 enami static void viaide_attach(struct device *, struct device *, void *);
50 1.4 enami static const struct pciide_product_desc *
51 1.4 enami viaide_lookup(pcireg_t);
52 1.1 bouyer
53 1.1 bouyer CFATTACH_DECL(viaide, sizeof(struct pciide_softc),
54 1.1 bouyer viaide_match, viaide_attach, NULL, NULL);
55 1.1 bouyer
56 1.2 thorpej static const struct pciide_product_desc pciide_amd_products[] = {
57 1.1 bouyer { PCI_PRODUCT_AMD_PBC756_IDE,
58 1.1 bouyer 0,
59 1.1 bouyer "Advanced Micro Devices AMD756 IDE Controller",
60 1.1 bouyer via_chip_map
61 1.1 bouyer },
62 1.1 bouyer { PCI_PRODUCT_AMD_PBC766_IDE,
63 1.1 bouyer 0,
64 1.1 bouyer "Advanced Micro Devices AMD766 IDE Controller",
65 1.1 bouyer via_chip_map
66 1.1 bouyer },
67 1.1 bouyer { PCI_PRODUCT_AMD_PBC768_IDE,
68 1.1 bouyer 0,
69 1.1 bouyer "Advanced Micro Devices AMD768 IDE Controller",
70 1.1 bouyer via_chip_map
71 1.1 bouyer },
72 1.1 bouyer { PCI_PRODUCT_AMD_PBC8111_IDE,
73 1.1 bouyer 0,
74 1.1 bouyer "Advanced Micro Devices AMD8111 IDE Controller",
75 1.1 bouyer via_chip_map
76 1.1 bouyer },
77 1.1 bouyer { 0,
78 1.1 bouyer 0,
79 1.1 bouyer NULL,
80 1.1 bouyer NULL
81 1.1 bouyer }
82 1.1 bouyer };
83 1.1 bouyer
84 1.2 thorpej static const struct pciide_product_desc pciide_nvidia_products[] = {
85 1.1 bouyer { PCI_PRODUCT_NVIDIA_NFORCE_ATA100,
86 1.1 bouyer 0,
87 1.1 bouyer "NVIDIA nForce IDE Controller",
88 1.1 bouyer via_chip_map
89 1.1 bouyer },
90 1.1 bouyer { PCI_PRODUCT_NVIDIA_NFORCE2_ATA133,
91 1.1 bouyer 0,
92 1.1 bouyer "NVIDIA nForce2 IDE Controller",
93 1.1 bouyer via_chip_map
94 1.1 bouyer },
95 1.20 jdolecek { PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133,
96 1.20 jdolecek 0,
97 1.20 jdolecek "NVIDIA nForce2 Ultra 400 IDE Controller",
98 1.20 jdolecek via_chip_map
99 1.20 jdolecek },
100 1.20 jdolecek { PCI_PRODUCT_NVIDIA_NFORCE2_400_SATA,
101 1.20 jdolecek 0,
102 1.20 jdolecek "NVIDIA nForce2 Ultra 400 Serial ATA Controller",
103 1.20 jdolecek via_sata_chip_map
104 1.20 jdolecek },
105 1.10 fvdl { PCI_PRODUCT_NVIDIA_NFORCE3_ATA133,
106 1.10 fvdl 0,
107 1.10 fvdl "NVIDIA nForce3 IDE Controller",
108 1.10 fvdl via_chip_map
109 1.10 fvdl },
110 1.19 xtraeme { PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133,
111 1.19 xtraeme 0,
112 1.19 xtraeme "NVIDIA nForce3 250 IDE Controller",
113 1.19 xtraeme via_chip_map
114 1.19 xtraeme },
115 1.19 xtraeme { PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA,
116 1.19 xtraeme 0,
117 1.19 xtraeme "NVIDIA nForce3 250 Serial ATA Controller",
118 1.19 xtraeme via_sata_chip_map
119 1.19 xtraeme },
120 1.24.2.4 tron { PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA2,
121 1.24.2.4 tron 0,
122 1.24.2.4 tron "NVIDIA nForce3 250 Serial ATA Controller",
123 1.24.2.4 tron via_sata_chip_map
124 1.24.2.4 tron },
125 1.21 kent { PCI_PRODUCT_NVIDIA_NFORCE4_ATA133,
126 1.21 kent 0,
127 1.21 kent "NVIDIA nForce4 IDE Controller",
128 1.21 kent via_chip_map
129 1.21 kent },
130 1.21 kent { PCI_PRODUCT_NVIDIA_NFORCE4_SATA1,
131 1.21 kent 0,
132 1.21 kent "NVIDIA nForce4 Serial ATA Controller",
133 1.21 kent via_sata_chip_map
134 1.21 kent },
135 1.21 kent { PCI_PRODUCT_NVIDIA_NFORCE4_SATA2,
136 1.21 kent 0,
137 1.21 kent "NVIDIA nForce4 Serial ATA Controller",
138 1.21 kent via_sata_chip_map
139 1.21 kent },
140 1.24.2.1 riz { PCI_PRODUCT_NVIDIA_NFORCE430_ATA133,
141 1.24.2.1 riz 0,
142 1.24.2.1 riz "NVIDIA nForce430 IDE Controller",
143 1.24.2.1 riz via_chip_map
144 1.24.2.1 riz },
145 1.24.2.1 riz { PCI_PRODUCT_NVIDIA_NFORCE430_SATA1,
146 1.24.2.1 riz 0,
147 1.24.2.1 riz "NVIDIA nForce430 Serial ATA Controller",
148 1.24.2.1 riz via_sata_chip_map
149 1.24.2.1 riz },
150 1.24.2.1 riz { PCI_PRODUCT_NVIDIA_NFORCE430_SATA2,
151 1.24.2.1 riz 0,
152 1.24.2.1 riz "NVIDIA nForce430 Serial ATA Controller",
153 1.24.2.1 riz via_sata_chip_map
154 1.24.2.1 riz },
155 1.1 bouyer { 0,
156 1.1 bouyer 0,
157 1.1 bouyer NULL,
158 1.1 bouyer NULL
159 1.1 bouyer }
160 1.1 bouyer };
161 1.1 bouyer
162 1.2 thorpej static const struct pciide_product_desc pciide_via_products[] = {
163 1.1 bouyer { PCI_PRODUCT_VIATECH_VT82C586_IDE,
164 1.1 bouyer 0,
165 1.1 bouyer NULL,
166 1.1 bouyer via_chip_map,
167 1.1 bouyer },
168 1.1 bouyer { PCI_PRODUCT_VIATECH_VT82C586A_IDE,
169 1.1 bouyer 0,
170 1.1 bouyer NULL,
171 1.1 bouyer via_chip_map,
172 1.1 bouyer },
173 1.23 abs { PCI_PRODUCT_VIATECH_VT6421_RAID,
174 1.22 abs 0,
175 1.23 abs "VIA Technologies VT6421 Serial RAID Controller",
176 1.22 abs via_sata_chip_map,
177 1.22 abs },
178 1.1 bouyer { PCI_PRODUCT_VIATECH_VT8237_SATA,
179 1.6 mycroft 0,
180 1.1 bouyer "VIA Technologies VT8237 SATA Controller",
181 1.1 bouyer via_sata_chip_map,
182 1.1 bouyer },
183 1.24.2.3 riz { PCI_PRODUCT_VIATECH_VT8237R_SATA,
184 1.24.2.3 riz 0,
185 1.24.2.3 riz "VIA Technologies VT8237R SATA Controller",
186 1.24.2.3 riz via_sata_chip_map,
187 1.24.2.3 riz },
188 1.1 bouyer { 0,
189 1.1 bouyer 0,
190 1.1 bouyer NULL,
191 1.1 bouyer NULL
192 1.1 bouyer }
193 1.1 bouyer };
194 1.1 bouyer
195 1.4 enami static const struct pciide_product_desc *
196 1.4 enami viaide_lookup(pcireg_t id)
197 1.4 enami {
198 1.4 enami
199 1.4 enami switch (PCI_VENDOR(id)) {
200 1.4 enami case PCI_VENDOR_VIATECH:
201 1.4 enami return (pciide_lookup_product(id, pciide_via_products));
202 1.4 enami
203 1.4 enami case PCI_VENDOR_AMD:
204 1.4 enami return (pciide_lookup_product(id, pciide_amd_products));
205 1.4 enami
206 1.4 enami case PCI_VENDOR_NVIDIA:
207 1.4 enami return (pciide_lookup_product(id, pciide_nvidia_products));
208 1.4 enami }
209 1.4 enami return (NULL);
210 1.4 enami }
211 1.4 enami
212 1.2 thorpej static int
213 1.2 thorpej viaide_match(struct device *parent, struct cfdata *match, void *aux)
214 1.1 bouyer {
215 1.1 bouyer struct pci_attach_args *pa = aux;
216 1.1 bouyer
217 1.4 enami if (viaide_lookup(pa->pa_id) != NULL)
218 1.4 enami return (2);
219 1.1 bouyer return (0);
220 1.1 bouyer }
221 1.1 bouyer
222 1.2 thorpej static void
223 1.2 thorpej viaide_attach(struct device *parent, struct device *self, void *aux)
224 1.1 bouyer {
225 1.1 bouyer struct pci_attach_args *pa = aux;
226 1.1 bouyer struct pciide_softc *sc = (struct pciide_softc *)self;
227 1.4 enami const struct pciide_product_desc *pp;
228 1.1 bouyer
229 1.4 enami pp = viaide_lookup(pa->pa_id);
230 1.1 bouyer if (pp == NULL)
231 1.1 bouyer panic("viaide_attach");
232 1.1 bouyer pciide_common_attach(sc, pa, pp);
233 1.1 bouyer }
234 1.1 bouyer
235 1.5 fvdl static int
236 1.5 fvdl via_pcib_match(struct pci_attach_args *pa)
237 1.5 fvdl {
238 1.5 fvdl if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
239 1.5 fvdl PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA &&
240 1.5 fvdl PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH)
241 1.5 fvdl return (1);
242 1.5 fvdl return 0;
243 1.5 fvdl }
244 1.5 fvdl
245 1.2 thorpej static void
246 1.2 thorpej via_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
247 1.1 bouyer {
248 1.1 bouyer struct pciide_channel *cp;
249 1.1 bouyer pcireg_t interface = PCI_INTERFACE(pa->pa_class);
250 1.1 bouyer pcireg_t vendor = PCI_VENDOR(pa->pa_id);
251 1.1 bouyer int channel;
252 1.1 bouyer u_int32_t ideconf;
253 1.1 bouyer bus_size_t cmdsize, ctlsize;
254 1.1 bouyer pcireg_t pcib_id, pcib_class;
255 1.5 fvdl struct pci_attach_args pcib_pa;
256 1.1 bouyer
257 1.1 bouyer if (pciide_chipen(sc, pa) == 0)
258 1.1 bouyer return;
259 1.1 bouyer
260 1.3 enami switch (vendor) {
261 1.1 bouyer case PCI_VENDOR_VIATECH:
262 1.1 bouyer /*
263 1.5 fvdl * get a PCI tag for the ISA bridge.
264 1.1 bouyer */
265 1.12 drochner if (pci_find_device(&pcib_pa, via_pcib_match) == 0)
266 1.5 fvdl goto unknown;
267 1.5 fvdl pcib_id = pcib_pa.pa_id;
268 1.5 fvdl pcib_class = pcib_pa.pa_class;
269 1.1 bouyer aprint_normal("%s: VIA Technologies ",
270 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
271 1.1 bouyer switch (PCI_PRODUCT(pcib_id)) {
272 1.1 bouyer case PCI_PRODUCT_VIATECH_VT82C586_ISA:
273 1.1 bouyer aprint_normal("VT82C586 (Apollo VP) ");
274 1.1 bouyer if(PCI_REVISION(pcib_class) >= 0x02) {
275 1.1 bouyer aprint_normal("ATA33 controller\n");
276 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
277 1.1 bouyer } else {
278 1.1 bouyer aprint_normal("controller\n");
279 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
280 1.1 bouyer }
281 1.1 bouyer break;
282 1.1 bouyer case PCI_PRODUCT_VIATECH_VT82C596A:
283 1.1 bouyer aprint_normal("VT82C596A (Apollo Pro) ");
284 1.1 bouyer if (PCI_REVISION(pcib_class) >= 0x12) {
285 1.1 bouyer aprint_normal("ATA66 controller\n");
286 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
287 1.1 bouyer } else {
288 1.1 bouyer aprint_normal("ATA33 controller\n");
289 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
290 1.1 bouyer }
291 1.1 bouyer break;
292 1.1 bouyer case PCI_PRODUCT_VIATECH_VT82C686A_ISA:
293 1.1 bouyer aprint_normal("VT82C686A (Apollo KX133) ");
294 1.1 bouyer if (PCI_REVISION(pcib_class) >= 0x40) {
295 1.1 bouyer aprint_normal("ATA100 controller\n");
296 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
297 1.1 bouyer } else {
298 1.1 bouyer aprint_normal("ATA66 controller\n");
299 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
300 1.1 bouyer }
301 1.1 bouyer break;
302 1.1 bouyer case PCI_PRODUCT_VIATECH_VT8231:
303 1.1 bouyer aprint_normal("VT8231 ATA100 controller\n");
304 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
305 1.1 bouyer break;
306 1.1 bouyer case PCI_PRODUCT_VIATECH_VT8233:
307 1.1 bouyer aprint_normal("VT8233 ATA100 controller\n");
308 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
309 1.1 bouyer break;
310 1.1 bouyer case PCI_PRODUCT_VIATECH_VT8233A:
311 1.1 bouyer aprint_normal("VT8233A ATA133 controller\n");
312 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
313 1.1 bouyer break;
314 1.1 bouyer case PCI_PRODUCT_VIATECH_VT8235:
315 1.1 bouyer aprint_normal("VT8235 ATA133 controller\n");
316 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
317 1.1 bouyer break;
318 1.5 fvdl case PCI_PRODUCT_VIATECH_VT8237:
319 1.1 bouyer aprint_normal("VT8237 ATA133 controller\n");
320 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
321 1.1 bouyer break;
322 1.1 bouyer default:
323 1.5 fvdl unknown:
324 1.1 bouyer aprint_normal("unknown VIA ATA controller\n");
325 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
326 1.1 bouyer }
327 1.1 bouyer sc->sc_apo_regbase = APO_VIA_REGBASE;
328 1.1 bouyer break;
329 1.1 bouyer case PCI_VENDOR_AMD:
330 1.1 bouyer switch (sc->sc_pp->ide_product) {
331 1.11 bouyer case PCI_PRODUCT_AMD_PBC8111_IDE:
332 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
333 1.11 bouyer break;
334 1.1 bouyer case PCI_PRODUCT_AMD_PBC766_IDE:
335 1.1 bouyer case PCI_PRODUCT_AMD_PBC768_IDE:
336 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
337 1.1 bouyer break;
338 1.1 bouyer default:
339 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
340 1.1 bouyer }
341 1.1 bouyer sc->sc_apo_regbase = APO_AMD_REGBASE;
342 1.1 bouyer break;
343 1.1 bouyer case PCI_VENDOR_NVIDIA:
344 1.1 bouyer switch (sc->sc_pp->ide_product) {
345 1.1 bouyer case PCI_PRODUCT_NVIDIA_NFORCE_ATA100:
346 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
347 1.1 bouyer break;
348 1.1 bouyer case PCI_PRODUCT_NVIDIA_NFORCE2_ATA133:
349 1.20 jdolecek case PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133:
350 1.5 fvdl case PCI_PRODUCT_NVIDIA_NFORCE3_ATA133:
351 1.19 xtraeme case PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133:
352 1.21 kent case PCI_PRODUCT_NVIDIA_NFORCE4_ATA133:
353 1.24.2.2 tron case PCI_PRODUCT_NVIDIA_NFORCE430_ATA133:
354 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
355 1.1 bouyer break;
356 1.1 bouyer }
357 1.1 bouyer sc->sc_apo_regbase = APO_NVIDIA_REGBASE;
358 1.1 bouyer break;
359 1.1 bouyer default:
360 1.1 bouyer panic("via_chip_map: unknown vendor");
361 1.1 bouyer }
362 1.3 enami
363 1.1 bouyer aprint_normal("%s: bus-master DMA support present",
364 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
365 1.1 bouyer pciide_mapreg_dma(sc, pa);
366 1.1 bouyer aprint_normal("\n");
367 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
368 1.1 bouyer if (sc->sc_dma_ok) {
369 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
370 1.1 bouyer sc->sc_wdcdev.irqack = pciide_irqack;
371 1.17 thorpej if (sc->sc_wdcdev.sc_atac.atac_udma_cap > 0)
372 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
373 1.1 bouyer }
374 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
375 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
376 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_set_modes = via_setup_channel;
377 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
378 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
379 1.1 bouyer
380 1.15 thorpej wdc_allocate_regs(&sc->sc_wdcdev);
381 1.15 thorpej
382 1.14 thorpej ATADEBUG_PRINT(("via_chip_map: old APO_IDECONF=0x%x, "
383 1.1 bouyer "APO_CTLMISC=0x%x, APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
384 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc)),
385 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc)),
386 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
387 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))),
388 1.1 bouyer DEBUG_PROBE);
389 1.1 bouyer
390 1.1 bouyer ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
391 1.17 thorpej for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
392 1.17 thorpej channel++) {
393 1.1 bouyer cp = &sc->pciide_channels[channel];
394 1.1 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
395 1.1 bouyer continue;
396 1.1 bouyer
397 1.1 bouyer if ((ideconf & APO_IDECONF_EN(channel)) == 0) {
398 1.1 bouyer aprint_normal("%s: %s channel ignored (disabled)\n",
399 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
400 1.15 thorpej cp->ata_channel.ch_flags |= ATACH_DISABLED;
401 1.1 bouyer continue;
402 1.1 bouyer }
403 1.1 bouyer pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
404 1.1 bouyer pciide_pci_intr);
405 1.1 bouyer }
406 1.1 bouyer }
407 1.1 bouyer
408 1.2 thorpej static void
409 1.15 thorpej via_setup_channel(struct ata_channel *chp)
410 1.1 bouyer {
411 1.1 bouyer u_int32_t udmatim_reg, datatim_reg;
412 1.1 bouyer u_int8_t idedma_ctl;
413 1.18 thorpej int mode, drive, s;
414 1.1 bouyer struct ata_drive_datas *drvp;
415 1.17 thorpej struct atac_softc *atac = chp->ch_atac;
416 1.16 thorpej struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
417 1.16 thorpej struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
418 1.1 bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
419 1.1 bouyer int rev = PCI_REVISION(
420 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CLASS_REG));
421 1.1 bouyer #endif
422 1.1 bouyer
423 1.1 bouyer idedma_ctl = 0;
424 1.1 bouyer datatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
425 1.1 bouyer udmatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc));
426 1.9 thorpej datatim_reg &= ~APO_DATATIM_MASK(chp->ch_channel);
427 1.9 thorpej udmatim_reg &= ~APO_UDMA_MASK(chp->ch_channel);
428 1.1 bouyer
429 1.1 bouyer /* setup DMA if needed */
430 1.1 bouyer pciide_channel_dma_setup(cp);
431 1.1 bouyer
432 1.1 bouyer for (drive = 0; drive < 2; drive++) {
433 1.1 bouyer drvp = &chp->ch_drive[drive];
434 1.1 bouyer /* If no drive, skip */
435 1.1 bouyer if ((drvp->drive_flags & DRIVE) == 0)
436 1.1 bouyer continue;
437 1.1 bouyer /* add timing values, setup DMA if needed */
438 1.1 bouyer if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
439 1.1 bouyer (drvp->drive_flags & DRIVE_UDMA) == 0)) {
440 1.1 bouyer mode = drvp->PIO_mode;
441 1.1 bouyer goto pio;
442 1.1 bouyer }
443 1.17 thorpej if ((atac->atac_cap & ATAC_CAP_UDMA) &&
444 1.1 bouyer (drvp->drive_flags & DRIVE_UDMA)) {
445 1.1 bouyer /* use Ultra/DMA */
446 1.18 thorpej s = splbio();
447 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
448 1.18 thorpej splx(s);
449 1.9 thorpej udmatim_reg |= APO_UDMA_EN(chp->ch_channel, drive) |
450 1.9 thorpej APO_UDMA_EN_MTH(chp->ch_channel, drive);
451 1.3 enami switch (PCI_VENDOR(sc->sc_pci_id)) {
452 1.1 bouyer case PCI_VENDOR_VIATECH:
453 1.17 thorpej if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 6) {
454 1.1 bouyer /* 8233a */
455 1.1 bouyer udmatim_reg |= APO_UDMA_TIME(
456 1.9 thorpej chp->ch_channel,
457 1.1 bouyer drive,
458 1.1 bouyer via_udma133_tim[drvp->UDMA_mode]);
459 1.17 thorpej } else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 5) {
460 1.1 bouyer /* 686b */
461 1.1 bouyer udmatim_reg |= APO_UDMA_TIME(
462 1.9 thorpej chp->ch_channel,
463 1.1 bouyer drive,
464 1.1 bouyer via_udma100_tim[drvp->UDMA_mode]);
465 1.17 thorpej } else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 4) {
466 1.1 bouyer /* 596b or 686a */
467 1.1 bouyer udmatim_reg |= APO_UDMA_CLK66(
468 1.9 thorpej chp->ch_channel);
469 1.1 bouyer udmatim_reg |= APO_UDMA_TIME(
470 1.9 thorpej chp->ch_channel,
471 1.1 bouyer drive,
472 1.1 bouyer via_udma66_tim[drvp->UDMA_mode]);
473 1.1 bouyer } else {
474 1.1 bouyer /* 596a or 586b */
475 1.1 bouyer udmatim_reg |= APO_UDMA_TIME(
476 1.9 thorpej chp->ch_channel,
477 1.1 bouyer drive,
478 1.1 bouyer via_udma33_tim[drvp->UDMA_mode]);
479 1.1 bouyer }
480 1.1 bouyer break;
481 1.1 bouyer case PCI_VENDOR_AMD:
482 1.1 bouyer case PCI_VENDOR_NVIDIA:
483 1.9 thorpej udmatim_reg |= APO_UDMA_TIME(chp->ch_channel,
484 1.1 bouyer drive, amd7x6_udma_tim[drvp->UDMA_mode]);
485 1.1 bouyer break;
486 1.1 bouyer }
487 1.1 bouyer /* can use PIO timings, MW DMA unused */
488 1.1 bouyer mode = drvp->PIO_mode;
489 1.1 bouyer } else {
490 1.1 bouyer /* use Multiword DMA, but only if revision is OK */
491 1.18 thorpej s = splbio();
492 1.1 bouyer drvp->drive_flags &= ~DRIVE_UDMA;
493 1.18 thorpej splx(s);
494 1.1 bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
495 1.1 bouyer /*
496 1.1 bouyer * The workaround doesn't seem to be necessary
497 1.1 bouyer * with all drives, so it can be disabled by
498 1.1 bouyer * PCIIDE_AMD756_ENABLEDMA. It causes a hard hang if
499 1.1 bouyer * triggered.
500 1.1 bouyer */
501 1.1 bouyer if (PCI_VENDOR(sc->sc_pci_id) == PCI_VENDOR_AMD &&
502 1.1 bouyer sc->sc_pp->ide_product ==
503 1.3 enami PCI_PRODUCT_AMD_PBC756_IDE &&
504 1.1 bouyer AMD756_CHIPREV_DISABLEDMA(rev)) {
505 1.1 bouyer aprint_normal(
506 1.1 bouyer "%s:%d:%d: multi-word DMA disabled due "
507 1.1 bouyer "to chip revision\n",
508 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
509 1.9 thorpej chp->ch_channel, drive);
510 1.1 bouyer mode = drvp->PIO_mode;
511 1.18 thorpej s = splbio();
512 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
513 1.18 thorpej splx(s);
514 1.1 bouyer goto pio;
515 1.1 bouyer }
516 1.1 bouyer #endif
517 1.1 bouyer /* mode = min(pio, dma+2) */
518 1.3 enami if (drvp->PIO_mode <= (drvp->DMA_mode + 2))
519 1.1 bouyer mode = drvp->PIO_mode;
520 1.1 bouyer else
521 1.1 bouyer mode = drvp->DMA_mode + 2;
522 1.1 bouyer }
523 1.1 bouyer idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
524 1.1 bouyer
525 1.1 bouyer pio: /* setup PIO mode */
526 1.1 bouyer if (mode <= 2) {
527 1.1 bouyer drvp->DMA_mode = 0;
528 1.1 bouyer drvp->PIO_mode = 0;
529 1.1 bouyer mode = 0;
530 1.1 bouyer } else {
531 1.1 bouyer drvp->PIO_mode = mode;
532 1.1 bouyer drvp->DMA_mode = mode - 2;
533 1.1 bouyer }
534 1.1 bouyer datatim_reg |=
535 1.9 thorpej APO_DATATIM_PULSE(chp->ch_channel, drive,
536 1.1 bouyer apollo_pio_set[mode]) |
537 1.9 thorpej APO_DATATIM_RECOV(chp->ch_channel, drive,
538 1.1 bouyer apollo_pio_rec[mode]);
539 1.1 bouyer }
540 1.1 bouyer if (idedma_ctl != 0) {
541 1.1 bouyer /* Add software bits in status register */
542 1.7 fvdl bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
543 1.1 bouyer idedma_ctl);
544 1.1 bouyer }
545 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc), datatim_reg);
546 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, APO_UDMA(sc), udmatim_reg);
547 1.14 thorpej ATADEBUG_PRINT(("via_chip_map: APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
548 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
549 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))), DEBUG_PROBE);
550 1.1 bouyer }
551 1.1 bouyer
552 1.2 thorpej static void
553 1.2 thorpej via_sata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
554 1.1 bouyer {
555 1.1 bouyer struct pciide_channel *cp;
556 1.1 bouyer pcireg_t interface = PCI_INTERFACE(pa->pa_class);
557 1.1 bouyer int channel;
558 1.1 bouyer bus_size_t cmdsize, ctlsize;
559 1.1 bouyer
560 1.1 bouyer if (pciide_chipen(sc, pa) == 0)
561 1.1 bouyer return;
562 1.1 bouyer
563 1.3 enami if (interface == 0) {
564 1.14 thorpej ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
565 1.3 enami DEBUG_PROBE);
566 1.1 bouyer interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
567 1.3 enami PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
568 1.1 bouyer }
569 1.1 bouyer
570 1.1 bouyer aprint_normal("%s: bus-master DMA support present",
571 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
572 1.1 bouyer pciide_mapreg_dma(sc, pa);
573 1.1 bouyer aprint_normal("\n");
574 1.1 bouyer
575 1.1 bouyer if (sc->sc_dma_ok) {
576 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA | ATAC_CAP_DMA;
577 1.1 bouyer sc->sc_wdcdev.irqack = pciide_irqack;
578 1.1 bouyer }
579 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
580 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
581 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
582 1.17 thorpej
583 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
584 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
585 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
586 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
587 1.1 bouyer
588 1.15 thorpej wdc_allocate_regs(&sc->sc_wdcdev);
589 1.15 thorpej
590 1.17 thorpej for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
591 1.17 thorpej channel++) {
592 1.1 bouyer cp = &sc->pciide_channels[channel];
593 1.1 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
594 1.1 bouyer continue;
595 1.1 bouyer pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
596 1.3 enami pciide_pci_intr);
597 1.1 bouyer }
598 1.1 bouyer }
599