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