1 /* $NetBSD: viaide.c,v 1.66 2009/12/23 00:11:36 mrg Exp $ */
4 * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: viaide.c,v 1.66 2009/12/23 00:11:36 mrg Exp $");
31 #include <sys/param.h>
32 #include <sys/systm.h>
34 #include <dev/pci/pcivar.h>
35 #include <dev/pci/pcidevs.h>
36 #include <dev/pci/pciidereg.h>
37 #include <dev/pci/pciidevar.h>
38 #include <dev/pci/pciide_apollo_reg.h>
40 static int via_pcib_match(struct pci_attach_args
*);
41 static void via_chip_map(struct pciide_softc
*, struct pci_attach_args
*);
42 static void via_mapchan(struct pci_attach_args
*, struct pciide_channel
*,
43 pcireg_t
, bus_size_t
*, bus_size_t
*, int (*)(void *));
44 static void via_mapregs_compat_native(struct pci_attach_args
*,
45 struct pciide_channel
*, bus_size_t
*, bus_size_t
*);
46 static int via_sata_chip_map_common(struct pciide_softc
*,
47 struct pci_attach_args
*);
48 static void via_sata_chip_map(struct pciide_softc
*,
49 struct pci_attach_args
*, int);
50 static void via_sata_chip_map_6(struct pciide_softc
*,
51 struct pci_attach_args
*);
52 static void via_sata_chip_map_7(struct pciide_softc
*,
53 struct pci_attach_args
*);
54 static void via_sata_chip_map_new(struct pciide_softc
*,
55 struct pci_attach_args
*);
56 static void via_setup_channel(struct ata_channel
*);
58 static int viaide_match(device_t
, cfdata_t
, void *);
59 static void viaide_attach(device_t
, device_t
, void *);
60 static const struct pciide_product_desc
*
61 viaide_lookup(pcireg_t
);
62 static bool viaide_suspend(device_t
, pmf_qual_t
);
63 static bool viaide_resume(device_t
, pmf_qual_t
);
65 CFATTACH_DECL_NEW(viaide
, sizeof(struct pciide_softc
),
66 viaide_match
, viaide_attach
, NULL
, NULL
);
68 static const struct pciide_product_desc pciide_amd_products
[] = {
69 { PCI_PRODUCT_AMD_PBC756_IDE
,
71 "AMD AMD756 IDE Controller",
74 { PCI_PRODUCT_AMD_PBC766_IDE
,
76 "AMD AMD766 IDE Controller",
79 { PCI_PRODUCT_AMD_PBC768_IDE
,
81 "AMD AMD768 IDE Controller",
84 { PCI_PRODUCT_AMD_PBC8111_IDE
,
86 "AMD AMD8111 IDE Controller",
89 { PCI_PRODUCT_AMD_CS5536_IDE
,
91 "AMD CS5536 IDE Controller",
101 static const struct pciide_product_desc pciide_nvidia_products
[] = {
102 { PCI_PRODUCT_NVIDIA_NFORCE_ATA100
,
104 "NVIDIA nForce IDE Controller",
107 { PCI_PRODUCT_NVIDIA_NFORCE2_ATA133
,
109 "NVIDIA nForce2 IDE Controller",
112 { PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133
,
114 "NVIDIA nForce2 Ultra 400 IDE Controller",
117 { PCI_PRODUCT_NVIDIA_NFORCE2_400_SATA
,
119 "NVIDIA nForce2 Ultra 400 Serial ATA Controller",
122 { PCI_PRODUCT_NVIDIA_NFORCE3_ATA133
,
124 "NVIDIA nForce3 IDE Controller",
127 { PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133
,
129 "NVIDIA nForce3 250 IDE Controller",
132 { PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA
,
134 "NVIDIA nForce3 250 Serial ATA Controller",
137 { PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA2
,
139 "NVIDIA nForce3 250 Serial ATA Controller",
142 { PCI_PRODUCT_NVIDIA_NFORCE4_ATA133
,
144 "NVIDIA nForce4 IDE Controller",
147 { PCI_PRODUCT_NVIDIA_NFORCE4_SATA1
,
149 "NVIDIA nForce4 Serial ATA Controller",
152 { PCI_PRODUCT_NVIDIA_NFORCE4_SATA2
,
154 "NVIDIA nForce4 Serial ATA Controller",
157 { PCI_PRODUCT_NVIDIA_NFORCE430_ATA133
,
159 "NVIDIA nForce430 IDE Controller",
162 { PCI_PRODUCT_NVIDIA_NFORCE430_SATA1
,
164 "NVIDIA nForce430 Serial ATA Controller",
167 { PCI_PRODUCT_NVIDIA_NFORCE430_SATA2
,
169 "NVIDIA nForce430 Serial ATA Controller",
172 { PCI_PRODUCT_NVIDIA_MCP04_IDE
,
174 "NVIDIA MCP04 IDE Controller",
177 { PCI_PRODUCT_NVIDIA_MCP04_SATA
,
179 "NVIDIA MCP04 Serial ATA Controller",
182 { PCI_PRODUCT_NVIDIA_MCP04_SATA2
,
184 "NVIDIA MCP04 Serial ATA Controller",
187 { PCI_PRODUCT_NVIDIA_MCP55_IDE
,
189 "NVIDIA MCP55 IDE Controller",
192 { PCI_PRODUCT_NVIDIA_MCP55_SATA
,
194 "NVIDIA MCP55 Serial ATA Controller",
197 { PCI_PRODUCT_NVIDIA_MCP55_SATA2
,
199 "NVIDIA MCP55 Serial ATA Controller",
202 { PCI_PRODUCT_NVIDIA_MCP61_IDE
,
204 "NVIDIA MCP61 IDE Controller",
207 { PCI_PRODUCT_NVIDIA_MCP65_IDE
,
209 "NVIDIA MCP65 IDE Controller",
212 { PCI_PRODUCT_NVIDIA_MCP73_IDE
,
214 "NVIDIA MCP73 IDE Controller",
217 { PCI_PRODUCT_NVIDIA_MCP77_IDE
,
219 "NVIDIA MCP77 IDE Controller",
222 { PCI_PRODUCT_NVIDIA_MCP61_SATA
,
224 "NVIDIA MCP61 Serial ATA Controller",
227 { PCI_PRODUCT_NVIDIA_MCP61_SATA2
,
229 "NVIDIA MCP61 Serial ATA Controller",
232 { PCI_PRODUCT_NVIDIA_MCP61_SATA3
,
234 "NVIDIA MCP61 Serial ATA Controller",
237 { PCI_PRODUCT_NVIDIA_MCP65_SATA
,
239 "NVIDIA MCP65 Serial ATA Controller",
242 { PCI_PRODUCT_NVIDIA_MCP65_SATA2
,
244 "NVIDIA MCP65 Serial ATA Controller",
247 { PCI_PRODUCT_NVIDIA_MCP65_SATA3
,
249 "NVIDIA MCP65 Serial ATA Controller",
252 { PCI_PRODUCT_NVIDIA_MCP65_SATA4
,
254 "NVIDIA MCP65 Serial ATA Controller",
257 { PCI_PRODUCT_NVIDIA_MCP67_IDE
,
259 "NVIDIA MCP67 IDE Controller",
262 { PCI_PRODUCT_NVIDIA_MCP67_SATA
,
264 "NVIDIA MCP67 Serial ATA Controller",
267 { PCI_PRODUCT_NVIDIA_MCP67_SATA2
,
269 "NVIDIA MCP67 Serial ATA Controller",
272 { PCI_PRODUCT_NVIDIA_MCP67_SATA3
,
274 "NVIDIA MCP67 Serial ATA Controller",
277 { PCI_PRODUCT_NVIDIA_MCP67_SATA4
,
279 "NVIDIA MCP67 Serial ATA Controller",
289 static const struct pciide_product_desc pciide_via_products
[] = {
290 { PCI_PRODUCT_VIATECH_VT82C586_IDE
,
295 { PCI_PRODUCT_VIATECH_VT82C586A_IDE
,
300 { PCI_PRODUCT_VIATECH_CX700_IDE
,
305 { PCI_PRODUCT_VIATECH_CX700M2_IDE
,
310 { PCI_PRODUCT_VIATECH_VT6421_RAID
,
312 "VIA Technologies VT6421 Serial RAID Controller",
313 via_sata_chip_map_new
,
315 { PCI_PRODUCT_VIATECH_VT8237_SATA
,
317 "VIA Technologies VT8237 SATA Controller",
320 { PCI_PRODUCT_VIATECH_VT8237A_SATA
,
322 "VIA Technologies VT8237A SATA Controller",
325 { PCI_PRODUCT_VIATECH_VT8237A_SATA_2
,
327 "VIA Technologies VT8237A (5337) SATA Controller",
330 { PCI_PRODUCT_VIATECH_VT8237R_SATA
,
332 "VIA Technologies VT8237R SATA Controller",
335 { PCI_PRODUCT_VIATECH_VT8237S_SATA
,
337 "VIA Technologies VT8237S SATA Controller",
347 static const struct pciide_product_desc
*
348 viaide_lookup(pcireg_t id
)
351 switch (PCI_VENDOR(id
)) {
352 case PCI_VENDOR_VIATECH
:
353 return (pciide_lookup_product(id
, pciide_via_products
));
356 return (pciide_lookup_product(id
, pciide_amd_products
));
358 case PCI_VENDOR_NVIDIA
:
359 return (pciide_lookup_product(id
, pciide_nvidia_products
));
365 viaide_match(device_t parent
, cfdata_t match
, void *aux
)
367 struct pci_attach_args
*pa
= aux
;
369 if (viaide_lookup(pa
->pa_id
) != NULL
)
375 viaide_attach(device_t parent
, device_t self
, void *aux
)
377 struct pci_attach_args
*pa
= aux
;
378 struct pciide_softc
*sc
= device_private(self
);
379 const struct pciide_product_desc
*pp
;
381 sc
->sc_wdcdev
.sc_atac
.atac_dev
= self
;
383 pp
= viaide_lookup(pa
->pa_id
);
385 panic("viaide_attach");
386 pciide_common_attach(sc
, pa
, pp
);
388 if (!pmf_device_register(self
, viaide_suspend
, viaide_resume
))
389 aprint_error_dev(self
, "couldn't establish power handler\n");
393 via_pcib_match(struct pci_attach_args
*pa
)
395 if (PCI_CLASS(pa
->pa_class
) == PCI_CLASS_BRIDGE
&&
396 PCI_SUBCLASS(pa
->pa_class
) == PCI_SUBCLASS_BRIDGE_ISA
&&
397 PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_VIATECH
)
403 viaide_suspend(device_t dv
, pmf_qual_t qual
)
405 struct pciide_softc
*sc
= device_private(dv
);
407 sc
->sc_pm_reg
[0] = pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_IDECONF(sc
));
408 /* APO_DATATIM(sc) includes APO_UDMA(sc) */
409 sc
->sc_pm_reg
[1] = pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_DATATIM(sc
));
410 /* This two are VIA-only, but should be ignored by other devices. */
411 sc
->sc_pm_reg
[2] = pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_CTLMISC(sc
));
412 sc
->sc_pm_reg
[3] = pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_MISCTIM(sc
));
418 viaide_resume(device_t dv
, pmf_qual_t qual
)
420 struct pciide_softc
*sc
= device_private(dv
);
422 pci_conf_write(sc
->sc_pc
, sc
->sc_tag
, APO_IDECONF(sc
),
424 pci_conf_write(sc
->sc_pc
, sc
->sc_tag
, APO_DATATIM(sc
),
426 /* This two are VIA-only, but should be ignored by other devices. */
427 pci_conf_write(sc
->sc_pc
, sc
->sc_tag
, APO_CTLMISC(sc
),
429 pci_conf_write(sc
->sc_pc
, sc
->sc_tag
, APO_MISCTIM(sc
),
436 via_chip_map(struct pciide_softc
*sc
, struct pci_attach_args
*pa
)
438 struct pciide_channel
*cp
;
439 pcireg_t interface
= PCI_INTERFACE(pa
->pa_class
);
440 pcireg_t vendor
= PCI_VENDOR(pa
->pa_id
);
443 bus_size_t cmdsize
, ctlsize
;
444 pcireg_t pcib_id
, pcib_class
;
445 struct pci_attach_args pcib_pa
;
447 if (pciide_chipen(sc
, pa
) == 0)
451 case PCI_VENDOR_VIATECH
:
453 * get a PCI tag for the ISA bridge.
455 if (pci_find_device(&pcib_pa
, via_pcib_match
) == 0)
457 pcib_id
= pcib_pa
.pa_id
;
458 pcib_class
= pcib_pa
.pa_class
;
459 aprint_normal_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
460 "VIA Technologies ");
461 switch (PCI_PRODUCT(pcib_id
)) {
462 case PCI_PRODUCT_VIATECH_VT82C586_ISA
:
463 aprint_normal("VT82C586 (Apollo VP) ");
464 if(PCI_REVISION(pcib_class
) >= 0x02) {
465 aprint_normal("ATA33 controller\n");
466 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 2;
468 aprint_normal("controller\n");
469 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 0;
472 case PCI_PRODUCT_VIATECH_VT82C596A
:
473 aprint_normal("VT82C596A (Apollo Pro) ");
474 if (PCI_REVISION(pcib_class
) >= 0x12) {
475 aprint_normal("ATA66 controller\n");
476 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 4;
478 aprint_normal("ATA33 controller\n");
479 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 2;
482 case PCI_PRODUCT_VIATECH_VT82C686A_ISA
:
483 aprint_normal("VT82C686A (Apollo KX133) ");
484 if (PCI_REVISION(pcib_class
) >= 0x40) {
485 aprint_normal("ATA100 controller\n");
486 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 5;
488 aprint_normal("ATA66 controller\n");
489 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 4;
492 case PCI_PRODUCT_VIATECH_VT8231
:
493 aprint_normal("VT8231 ATA100 controller\n");
494 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 5;
496 case PCI_PRODUCT_VIATECH_VT8233
:
497 aprint_normal("VT8233 ATA100 controller\n");
498 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 5;
500 case PCI_PRODUCT_VIATECH_VT8233A
:
501 aprint_normal("VT8233A ATA133 controller\n");
502 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
504 case PCI_PRODUCT_VIATECH_VT8235
:
505 aprint_normal("VT8235 ATA133 controller\n");
506 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
508 case PCI_PRODUCT_VIATECH_VT8237
:
509 aprint_normal("VT8237 ATA133 controller\n");
510 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
512 case PCI_PRODUCT_VIATECH_VT8237A_ISA
:
513 aprint_normal("VT8237A ATA133 controller\n");
514 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
516 case PCI_PRODUCT_VIATECH_CX700
:
517 aprint_normal("CX700 ATA133 controller\n");
518 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
520 case PCI_PRODUCT_VIATECH_VT8251
:
521 aprint_normal("VT8251 ATA133 controller\n");
522 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
526 aprint_normal("unknown VIA ATA controller\n");
527 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 0;
529 sc
->sc_apo_regbase
= APO_VIA_REGBASE
;
532 switch (sc
->sc_pp
->ide_product
) {
533 case PCI_PRODUCT_AMD_PBC8111_IDE
:
534 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
536 case PCI_PRODUCT_AMD_CS5536_IDE
:
537 case PCI_PRODUCT_AMD_PBC766_IDE
:
538 case PCI_PRODUCT_AMD_PBC768_IDE
:
539 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 5;
542 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 4;
544 sc
->sc_apo_regbase
= APO_AMD_REGBASE
;
546 case PCI_VENDOR_NVIDIA
:
547 switch (sc
->sc_pp
->ide_product
) {
548 case PCI_PRODUCT_NVIDIA_NFORCE_ATA100
:
549 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 5;
551 case PCI_PRODUCT_NVIDIA_NFORCE2_ATA133
:
552 case PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133
:
553 case PCI_PRODUCT_NVIDIA_NFORCE3_ATA133
:
554 case PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133
:
555 case PCI_PRODUCT_NVIDIA_NFORCE4_ATA133
:
556 case PCI_PRODUCT_NVIDIA_NFORCE430_ATA133
:
557 case PCI_PRODUCT_NVIDIA_MCP04_IDE
:
558 case PCI_PRODUCT_NVIDIA_MCP55_IDE
:
559 case PCI_PRODUCT_NVIDIA_MCP61_IDE
:
560 case PCI_PRODUCT_NVIDIA_MCP65_IDE
:
561 case PCI_PRODUCT_NVIDIA_MCP67_IDE
:
562 case PCI_PRODUCT_NVIDIA_MCP73_IDE
:
563 case PCI_PRODUCT_NVIDIA_MCP77_IDE
:
564 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
567 sc
->sc_apo_regbase
= APO_NVIDIA_REGBASE
;
570 panic("via_chip_map: unknown vendor");
573 aprint_verbose_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
574 "bus-master DMA support present");
575 pciide_mapreg_dma(sc
, pa
);
576 aprint_verbose("\n");
577 sc
->sc_wdcdev
.sc_atac
.atac_cap
= ATAC_CAP_DATA16
| ATAC_CAP_DATA32
;
579 sc
->sc_wdcdev
.sc_atac
.atac_cap
|= ATAC_CAP_DMA
;
580 sc
->sc_wdcdev
.irqack
= pciide_irqack
;
581 if (sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
> 0)
582 sc
->sc_wdcdev
.sc_atac
.atac_cap
|= ATAC_CAP_UDMA
;
584 sc
->sc_wdcdev
.sc_atac
.atac_pio_cap
= 4;
585 sc
->sc_wdcdev
.sc_atac
.atac_dma_cap
= 2;
586 sc
->sc_wdcdev
.sc_atac
.atac_set_modes
= via_setup_channel
;
587 sc
->sc_wdcdev
.sc_atac
.atac_channels
= sc
->wdc_chanarray
;
588 sc
->sc_wdcdev
.sc_atac
.atac_nchannels
= PCIIDE_NUM_CHANNELS
;
590 if (PCI_CLASS(pa
->pa_class
) == PCI_CLASS_MASS_STORAGE
&&
591 PCI_SUBCLASS(pa
->pa_class
) == PCI_SUBCLASS_MASS_STORAGE_RAID
)
592 sc
->sc_wdcdev
.sc_atac
.atac_cap
|= ATAC_CAP_RAID
;
594 wdc_allocate_regs(&sc
->sc_wdcdev
);
596 ATADEBUG_PRINT(("via_chip_map: old APO_IDECONF=0x%x, "
597 "APO_CTLMISC=0x%x, APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
598 pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_IDECONF(sc
)),
599 pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_CTLMISC(sc
)),
600 pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_DATATIM(sc
)),
601 pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_UDMA(sc
))),
604 ideconf
= pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_IDECONF(sc
));
605 for (channel
= 0; channel
< sc
->sc_wdcdev
.sc_atac
.atac_nchannels
;
607 cp
= &sc
->pciide_channels
[channel
];
608 if (pciide_chansetup(sc
, channel
, interface
) == 0)
611 if ((ideconf
& APO_IDECONF_EN(channel
)) == 0) {
612 aprint_normal_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
613 "%s channel ignored (disabled)\n", cp
->name
);
614 cp
->ata_channel
.ch_flags
|= ATACH_DISABLED
;
617 via_mapchan(pa
, cp
, interface
, &cmdsize
, &ctlsize
,
623 via_mapchan(struct pci_attach_args
*pa
, struct pciide_channel
*cp
,
624 pcireg_t interface
, bus_size_t
*cmdsizep
, bus_size_t
*ctlsizep
,
625 int (*pci_intr
)(void *))
627 struct ata_channel
*wdc_cp
;
628 struct pciide_softc
*sc
;
629 prop_bool_t compat_nat_enable
;
631 wdc_cp
= &cp
->ata_channel
;
632 sc
= CHAN_TO_PCIIDE(&cp
->ata_channel
);
633 compat_nat_enable
= prop_dictionary_get(
634 device_properties(sc
->sc_wdcdev
.sc_atac
.atac_dev
),
635 "use-compat-native-irq");
637 if (interface
& PCIIDE_INTERFACE_PCI(wdc_cp
->ch_channel
)) {
638 /* native mode with irq 14/15 requested? */
639 if (compat_nat_enable
!= NULL
&&
640 prop_bool_true(compat_nat_enable
))
641 via_mapregs_compat_native(pa
, cp
, cmdsizep
, ctlsizep
);
643 pciide_mapregs_native(pa
, cp
, cmdsizep
, ctlsizep
,
646 pciide_mapregs_compat(pa
, cp
, wdc_cp
->ch_channel
, cmdsizep
,
648 if ((cp
->ata_channel
.ch_flags
& ATACH_DISABLED
) == 0)
649 pciide_map_compat_intr(pa
, cp
, wdc_cp
->ch_channel
);
655 * At least under certain (mis)configurations (e.g. on the "Pegasos" board)
656 * the VT8231-IDE's native mode only works with irq 14/15, and cannot be
657 * programmed to use a single native PCI irq alone. So we install an interrupt
658 * handler for each channel, as in compatibility mode.
661 via_mapregs_compat_native(struct pci_attach_args
*pa
,
662 struct pciide_channel
*cp
, bus_size_t
*cmdsizep
, bus_size_t
*ctlsizep
)
664 struct ata_channel
*wdc_cp
;
665 struct pciide_softc
*sc
;
667 wdc_cp
= &cp
->ata_channel
;
668 sc
= CHAN_TO_PCIIDE(&cp
->ata_channel
);
670 /* XXX prevent pciide_mapregs_native from installing a handler */
671 if (sc
->sc_pci_ih
== NULL
)
672 sc
->sc_pci_ih
= (void *)~0;
673 pciide_mapregs_native(pa
, cp
, cmdsizep
, ctlsizep
, NULL
);
675 /* interrupts are fixed to 14/15, as in compatibility mode */
677 if ((wdc_cp
->ch_flags
& ATACH_DISABLED
) == 0) {
678 #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
679 cp
->ih
= pciide_machdep_compat_intr_establish(
680 sc
->sc_wdcdev
.sc_atac
.atac_dev
, pa
, wdc_cp
->ch_channel
,
681 pciide_compat_intr
, cp
);
682 if (cp
->ih
== NULL
) {
684 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
685 "no compatibility interrupt for "
686 "use by %s channel\n", cp
->name
);
687 wdc_cp
->ch_flags
|= ATACH_DISABLED
;
688 #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
690 sc
->sc_pci_ih
= cp
->ih
; /* XXX */
696 via_setup_channel(struct ata_channel
*chp
)
698 u_int32_t udmatim_reg
, datatim_reg
;
701 struct ata_drive_datas
*drvp
;
702 struct atac_softc
*atac
= chp
->ch_atac
;
703 struct pciide_channel
*cp
= CHAN_TO_PCHAN(chp
);
704 struct pciide_softc
*sc
= CHAN_TO_PCIIDE(chp
);
705 #ifndef PCIIDE_AMD756_ENABLEDMA
706 int rev
= PCI_REVISION(
707 pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, PCI_CLASS_REG
));
711 datatim_reg
= pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_DATATIM(sc
));
712 udmatim_reg
= pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_UDMA(sc
));
713 datatim_reg
&= ~APO_DATATIM_MASK(chp
->ch_channel
);
714 udmatim_reg
&= ~APO_UDMA_MASK(chp
->ch_channel
);
716 /* setup DMA if needed */
717 pciide_channel_dma_setup(cp
);
719 for (drive
= 0; drive
< 2; drive
++) {
720 drvp
= &chp
->ch_drive
[drive
];
721 /* If no drive, skip */
722 if ((drvp
->drive_flags
& DRIVE
) == 0)
724 /* add timing values, setup DMA if needed */
725 if (((drvp
->drive_flags
& DRIVE_DMA
) == 0 &&
726 (drvp
->drive_flags
& DRIVE_UDMA
) == 0)) {
727 mode
= drvp
->PIO_mode
;
730 if ((atac
->atac_cap
& ATAC_CAP_UDMA
) &&
731 (drvp
->drive_flags
& DRIVE_UDMA
)) {
734 drvp
->drive_flags
&= ~DRIVE_DMA
;
736 udmatim_reg
|= APO_UDMA_EN(chp
->ch_channel
, drive
) |
737 APO_UDMA_EN_MTH(chp
->ch_channel
, drive
);
738 switch (PCI_VENDOR(sc
->sc_pci_id
)) {
739 case PCI_VENDOR_VIATECH
:
740 if (sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
== 6) {
742 udmatim_reg
|= APO_UDMA_TIME(
745 via_udma133_tim
[drvp
->UDMA_mode
]);
746 } else if (sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
== 5) {
748 udmatim_reg
|= APO_UDMA_TIME(
751 via_udma100_tim
[drvp
->UDMA_mode
]);
752 } else if (sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
== 4) {
754 udmatim_reg
|= APO_UDMA_CLK66(
756 udmatim_reg
|= APO_UDMA_TIME(
759 via_udma66_tim
[drvp
->UDMA_mode
]);
762 udmatim_reg
|= APO_UDMA_TIME(
765 via_udma33_tim
[drvp
->UDMA_mode
]);
769 case PCI_VENDOR_NVIDIA
:
770 udmatim_reg
|= APO_UDMA_TIME(chp
->ch_channel
,
771 drive
, amd7x6_udma_tim
[drvp
->UDMA_mode
]);
774 /* can use PIO timings, MW DMA unused */
775 mode
= drvp
->PIO_mode
;
777 /* use Multiword DMA, but only if revision is OK */
779 drvp
->drive_flags
&= ~DRIVE_UDMA
;
781 #ifndef PCIIDE_AMD756_ENABLEDMA
783 * The workaround doesn't seem to be necessary
784 * with all drives, so it can be disabled by
785 * PCIIDE_AMD756_ENABLEDMA. It causes a hard hang if
788 if (PCI_VENDOR(sc
->sc_pci_id
) == PCI_VENDOR_AMD
&&
789 sc
->sc_pp
->ide_product
==
790 PCI_PRODUCT_AMD_PBC756_IDE
&&
791 AMD756_CHIPREV_DISABLEDMA(rev
)) {
793 "%s:%d:%d: multi-word DMA disabled due "
794 "to chip revision\n",
796 sc
->sc_wdcdev
.sc_atac
.atac_dev
),
797 chp
->ch_channel
, drive
);
798 mode
= drvp
->PIO_mode
;
800 drvp
->drive_flags
&= ~DRIVE_DMA
;
805 /* mode = min(pio, dma+2) */
806 if (drvp
->PIO_mode
<= (drvp
->DMA_mode
+ 2))
807 mode
= drvp
->PIO_mode
;
809 mode
= drvp
->DMA_mode
+ 2;
811 idedma_ctl
|= IDEDMA_CTL_DRV_DMA(drive
);
813 pio
: /* setup PIO mode */
819 drvp
->PIO_mode
= mode
;
820 drvp
->DMA_mode
= mode
- 2;
823 APO_DATATIM_PULSE(chp
->ch_channel
, drive
,
824 apollo_pio_set
[mode
]) |
825 APO_DATATIM_RECOV(chp
->ch_channel
, drive
,
826 apollo_pio_rec
[mode
]);
828 if (idedma_ctl
!= 0) {
829 /* Add software bits in status register */
830 bus_space_write_1(sc
->sc_dma_iot
, cp
->dma_iohs
[IDEDMA_CTL
], 0,
833 pci_conf_write(sc
->sc_pc
, sc
->sc_tag
, APO_DATATIM(sc
), datatim_reg
);
834 pci_conf_write(sc
->sc_pc
, sc
->sc_tag
, APO_UDMA(sc
), udmatim_reg
);
835 ATADEBUG_PRINT(("via_chip_map: APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
836 pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_DATATIM(sc
)),
837 pci_conf_read(sc
->sc_pc
, sc
->sc_tag
, APO_UDMA(sc
))), DEBUG_PROBE
);
841 via_sata_chip_map_common(struct pciide_softc
*sc
, struct pci_attach_args
*pa
)
846 if (pciide_chipen(sc
, pa
) == 0)
849 aprint_verbose_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
850 "bus-master DMA support present");
851 pciide_mapreg_dma(sc
, pa
);
852 aprint_verbose("\n");
855 * Enable memory-space access if it isn't already there.
857 if (pa
->pa_memt
&& (pa
->pa_flags
& PCI_FLAGS_MEM_ENABLED
) == 0) {
860 pa
->pa_flags
|= PCI_FLAGS_MEM_ENABLED
;
861 csr
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
);
862 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
,
863 csr
| PCI_COMMAND_MEM_ENABLE
);
867 sc
->sc_wdcdev
.sc_atac
.atac_cap
|= ATAC_CAP_UDMA
| ATAC_CAP_DMA
;
868 sc
->sc_wdcdev
.irqack
= pciide_irqack
;
870 sc
->sc_wdcdev
.sc_atac
.atac_pio_cap
= 4;
871 sc
->sc_wdcdev
.sc_atac
.atac_dma_cap
= 2;
872 sc
->sc_wdcdev
.sc_atac
.atac_udma_cap
= 6;
874 sc
->sc_wdcdev
.sc_atac
.atac_channels
= sc
->wdc_chanarray
;
875 sc
->sc_wdcdev
.sc_atac
.atac_nchannels
= PCIIDE_NUM_CHANNELS
;
876 sc
->sc_wdcdev
.sc_atac
.atac_cap
|= ATAC_CAP_DATA16
| ATAC_CAP_DATA32
;
877 sc
->sc_wdcdev
.sc_atac
.atac_set_modes
= sata_setup_channel
;
879 if (PCI_CLASS(pa
->pa_class
) == PCI_CLASS_MASS_STORAGE
&&
880 PCI_SUBCLASS(pa
->pa_class
) == PCI_SUBCLASS_MASS_STORAGE_RAID
)
881 sc
->sc_wdcdev
.sc_atac
.atac_cap
|= ATAC_CAP_RAID
;
883 wdc_allocate_regs(&sc
->sc_wdcdev
);
884 maptype
= pci_mapreg_type(pa
->pa_pc
, pa
->pa_tag
,
885 PCI_MAPREG_START
+ 0x14);
887 case PCI_MAPREG_TYPE_IO
:
888 ret
= pci_mapreg_map(pa
, PCI_MAPREG_START
+ 0x14,
889 PCI_MAPREG_TYPE_IO
, 0, &sc
->sc_ba5_st
, &sc
->sc_ba5_sh
,
892 case PCI_MAPREG_MEM_TYPE_32BIT
:
893 ret
= pci_mapreg_map(pa
, PCI_MAPREG_START
+ 0x14,
894 PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_32BIT
,
895 0, &sc
->sc_ba5_st
, &sc
->sc_ba5_sh
,
899 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
900 "couldn't map sata regs, unsupported maptype (0x%x)\n",
905 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
906 "couldn't map sata regs\n");
913 via_sata_chip_map(struct pciide_softc
*sc
, struct pci_attach_args
*pa
,
916 struct pciide_channel
*cp
;
917 struct ata_channel
*wdc_cp
;
918 struct wdc_regs
*wdr
;
919 pcireg_t interface
= PCI_INTERFACE(pa
->pa_class
);
921 bus_size_t cmdsize
, ctlsize
;
923 if (via_sata_chip_map_common(sc
, pa
) == 0)
926 if (interface
== 0) {
927 ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
929 interface
= PCIIDE_INTERFACE_BUS_MASTER_DMA
|
930 PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
933 for (channel
= 0; channel
< sc
->sc_wdcdev
.sc_atac
.atac_nchannels
;
935 cp
= &sc
->pciide_channels
[channel
];
936 if (pciide_chansetup(sc
, channel
, interface
) == 0)
938 wdc_cp
= &cp
->ata_channel
;
939 wdr
= CHAN_TO_WDC_REGS(wdc_cp
);
940 wdr
->sata_iot
= sc
->sc_ba5_st
;
941 wdr
->sata_baseioh
= sc
->sc_ba5_sh
;
942 if (bus_space_subregion(wdr
->sata_iot
, wdr
->sata_baseioh
,
943 (wdc_cp
->ch_channel
<< satareg_shift
) + 0x0, 4,
944 &wdr
->sata_status
) != 0) {
945 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
946 "couldn't map channel %d sata_status regs\n",
950 if (bus_space_subregion(wdr
->sata_iot
, wdr
->sata_baseioh
,
951 (wdc_cp
->ch_channel
<< satareg_shift
) + 0x4, 4,
952 &wdr
->sata_error
) != 0) {
953 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
954 "couldn't map channel %d sata_error regs\n",
958 if (bus_space_subregion(wdr
->sata_iot
, wdr
->sata_baseioh
,
959 (wdc_cp
->ch_channel
<< satareg_shift
) + 0x8, 4,
960 &wdr
->sata_control
) != 0) {
961 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
962 "couldn't map channel %d sata_control regs\n",
966 sc
->sc_wdcdev
.sc_atac
.atac_probe
= wdc_sataprobe
;
967 pciide_mapchan(pa
, cp
, interface
, &cmdsize
, &ctlsize
,
973 via_sata_chip_map_6(struct pciide_softc
*sc
, struct pci_attach_args
*pa
)
975 via_sata_chip_map(sc
, pa
, 6);
979 via_sata_chip_map_7(struct pciide_softc
*sc
, struct pci_attach_args
*pa
)
981 via_sata_chip_map(sc
, pa
, 7);
985 via_sata_chip_map_new(struct pciide_softc
*sc
, struct pci_attach_args
*pa
)
987 struct pciide_channel
*cp
;
988 struct ata_channel
*wdc_cp
;
989 struct wdc_regs
*wdr
;
990 pcireg_t interface
= PCI_INTERFACE(pa
->pa_class
);
993 pci_intr_handle_t intrhandle
;
997 if (via_sata_chip_map_common(sc
, pa
) == 0)
1000 if (interface
== 0) {
1001 ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
1003 interface
= PCIIDE_INTERFACE_BUS_MASTER_DMA
|
1004 PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
1007 if (pci_intr_map(pa
, &intrhandle
) != 0) {
1008 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1009 "couldn't map native-PCI interrupt\n");
1012 intrstr
= pci_intr_string(pa
->pa_pc
, intrhandle
);
1013 sc
->sc_pci_ih
= pci_intr_establish(pa
->pa_pc
,
1014 intrhandle
, IPL_BIO
, pciide_pci_intr
, sc
);
1015 if (sc
->sc_pci_ih
== NULL
) {
1016 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1017 "couldn't establish native-PCI interrupt");
1018 if (intrstr
!= NULL
)
1019 aprint_error(" at %s", intrstr
);
1023 aprint_normal_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1024 "using %s for native-PCI interrupt\n",
1025 intrstr
? intrstr
: "unknown interrupt");
1027 for (channel
= 0; channel
< sc
->sc_wdcdev
.sc_atac
.atac_nchannels
;
1029 cp
= &sc
->pciide_channels
[channel
];
1030 if (pciide_chansetup(sc
, channel
, interface
) == 0)
1032 cp
->ata_channel
.ch_ndrive
= 1;
1033 wdc_cp
= &cp
->ata_channel
;
1034 wdr
= CHAN_TO_WDC_REGS(wdc_cp
);
1036 wdr
->sata_iot
= sc
->sc_ba5_st
;
1037 wdr
->sata_baseioh
= sc
->sc_ba5_sh
;
1038 if (bus_space_subregion(wdr
->sata_iot
, wdr
->sata_baseioh
,
1039 (wdc_cp
->ch_channel
<< 6) + 0x0, 4,
1040 &wdr
->sata_status
) != 0) {
1041 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1042 "couldn't map channel %d sata_status regs\n",
1043 wdc_cp
->ch_channel
);
1046 if (bus_space_subregion(wdr
->sata_iot
, wdr
->sata_baseioh
,
1047 (wdc_cp
->ch_channel
<< 6) + 0x4, 4,
1048 &wdr
->sata_error
) != 0) {
1049 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1050 "couldn't map channel %d sata_error regs\n",
1051 wdc_cp
->ch_channel
);
1054 if (bus_space_subregion(wdr
->sata_iot
, wdr
->sata_baseioh
,
1055 (wdc_cp
->ch_channel
<< 6) + 0x8, 4,
1056 &wdr
->sata_control
) != 0) {
1057 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1058 "couldn't map channel %d sata_control regs\n",
1059 wdc_cp
->ch_channel
);
1062 sc
->sc_wdcdev
.sc_atac
.atac_probe
= wdc_sataprobe
;
1064 if (pci_mapreg_map(pa
, (PCI_MAPREG_START
+ (4 * (channel
))),
1065 PCI_MAPREG_TYPE_IO
, 0, &wdr
->cmd_iot
, &wdr
->cmd_baseioh
,
1066 NULL
, &cmdsize
) != 0) {
1067 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1068 "couldn't map %s channel regs\n", cp
->name
);
1070 wdr
->ctl_iot
= wdr
->cmd_iot
;
1071 for (i
= 0; i
< WDC_NREG
; i
++) {
1072 if (bus_space_subregion(wdr
->cmd_iot
,
1073 wdr
->cmd_baseioh
, i
, i
== 0 ? 4 : 1,
1074 &wdr
->cmd_iohs
[i
]) != 0) {
1076 sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1077 "couldn't subregion %s "
1078 "channel cmd regs\n", cp
->name
);
1082 if (bus_space_subregion(wdr
->cmd_iot
, wdr
->cmd_baseioh
,
1083 WDC_NREG
+ 2, 1, &wdr
->ctl_ioh
) != 0) {
1084 aprint_error_dev(sc
->sc_wdcdev
.sc_atac
.atac_dev
,
1085 "couldn't map channel %d ctl regs\n", channel
);
1088 wdc_init_shadow_regs(wdc_cp
);
1089 wdr
->data32iot
= wdr
->cmd_iot
;
1090 wdr
->data32ioh
= wdr
->cmd_iohs
[wd_data
];