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