Deleted Added
full compact
ata-all.c (66698) ata-all.c (67058)
1/*-
2 * Copyright (c) 1998,1999,2000 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
1/*-
2 * Copyright (c) 1998,1999,2000 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/dev/ata/ata-all.c 66698 2000-10-05 23:09:57Z jhb $
28 * $FreeBSD: head/sys/dev/ata/ata-all.c 67058 2000-10-13 11:21:27Z sos $
29 */
30
31#include "ata.h"
32#include "isa.h"
33#include "card.h"
34#include "pci.h"
35#include "atadisk.h"
36#include "atapicd.h"

--- 88 unchanged lines hidden (view full) ---

125
126 /* alloctate the altport range */
127 if (bus_get_resource(dev, SYS_RES_IOPORT, 1, &tmp, &tmp)) {
128 bus_set_resource(dev, SYS_RES_IOPORT, 1,
129 rman_get_start(port) + ATA_ALTOFFSET,
130 ATA_ALTIOSIZE);
131 }
132 bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
29 */
30
31#include "ata.h"
32#include "isa.h"
33#include "card.h"
34#include "pci.h"
35#include "atadisk.h"
36#include "atapicd.h"

--- 88 unchanged lines hidden (view full) ---

125
126 /* alloctate the altport range */
127 if (bus_get_resource(dev, SYS_RES_IOPORT, 1, &tmp, &tmp)) {
128 bus_set_resource(dev, SYS_RES_IOPORT, 1,
129 rman_get_start(port) + ATA_ALTOFFSET,
130 ATA_ALTIOSIZE);
131 }
132 bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
133 scp->unit = device_get_unit(dev);
133 scp->channel = 0;
134 scp->flags |= ATA_USE_16BIT;
135 return ata_probe(dev);
136}
137
138static device_method_t ata_isa_methods[] = {
139 /* device interface */
140 DEVMETHOD(device_probe, ata_isa_probe),
141 DEVMETHOD(device_attach, ata_attach),

--- 30 unchanged lines hidden (view full) ---

172 * a pccard system where the altio ports are located just after the
173 * normal io ports, so no need to allocate them.
174 */
175 if (len <= ATA_IOSIZE) {
176 bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
177 rman_get_start(port) + ATA_ALTOFFSET, ATA_ALTIOSIZE);
178 }
179 bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
134 scp->flags |= ATA_USE_16BIT;
135 return ata_probe(dev);
136}
137
138static device_method_t ata_isa_methods[] = {
139 /* device interface */
140 DEVMETHOD(device_probe, ata_isa_probe),
141 DEVMETHOD(device_attach, ata_attach),

--- 30 unchanged lines hidden (view full) ---

172 * a pccard system where the altio ports are located just after the
173 * normal io ports, so no need to allocate them.
174 */
175 if (len <= ATA_IOSIZE) {
176 bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
177 rman_get_start(port) + ATA_ALTOFFSET, ATA_ALTIOSIZE);
178 }
179 bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
180 scp->unit = device_get_unit(dev);
180 scp->channel = 0;
181 scp->flags |= ATA_USE_16BIT;
182 return ata_probe(dev);
183}
184
185static device_method_t ata_pccard_methods[] = {
186 /* device interface */
187 DEVMETHOD(device_probe, ata_pccard_probe),
188 DEVMETHOD(device_attach, ata_attach),

--- 174 unchanged lines hidden (view full) ---

363 if (ATA_MASTERDEV(dev)) {
364 if (!(child = device_add_child(dev, "ata", unit)))
365 return ENOMEM;
366 }
367 else {
368 if (!(child = device_add_child(dev, "ata", 2)))
369 return ENOMEM;
370 }
181 scp->flags |= ATA_USE_16BIT;
182 return ata_probe(dev);
183}
184
185static device_method_t ata_pccard_methods[] = {
186 /* device interface */
187 DEVMETHOD(device_probe, ata_pccard_probe),
188 DEVMETHOD(device_attach, ata_attach),

--- 174 unchanged lines hidden (view full) ---

363 if (ATA_MASTERDEV(dev)) {
364 if (!(child = device_add_child(dev, "ata", unit)))
365 return ENOMEM;
366 }
367 else {
368 if (!(child = device_add_child(dev, "ata", 2)))
369 return ENOMEM;
370 }
371 device_set_ivars(child, (void *)(uintptr_t) unit);
372 return 0;
373}
374
375static int
376ata_pci_attach(device_t dev)
377{
378 struct ata_pci_softc *sc = device_get_softc(dev);
379 u_int8_t class, subclass;

--- 9 unchanged lines hidden (view full) ---

389 /* is busmastering supported ? */
390 if ((cmd & (PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN)) ==
391 (PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN)) {
392
393 /* is there a valid port range to connect to ? */
394 rid = 0x20;
395 sc->bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
396 0, ~0, 1, RF_ACTIVE);
371 return 0;
372}
373
374static int
375ata_pci_attach(device_t dev)
376{
377 struct ata_pci_softc *sc = device_get_softc(dev);
378 u_int8_t class, subclass;

--- 9 unchanged lines hidden (view full) ---

388 /* is busmastering supported ? */
389 if ((cmd & (PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN)) ==
390 (PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN)) {
391
392 /* is there a valid port range to connect to ? */
393 rid = 0x20;
394 sc->bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
395 0, ~0, 1, RF_ACTIVE);
397 device_printf(dev, "Busmastering DMA %s\n",
398 sc->bmio ? "enabled" : "not supported");
396 if (!sc->bmio)
397 device_printf(dev, "Busmastering DMA not supported\n");
399 }
400
401 /* do extra chipset specific setups */
402 switch (type) {
403 case 0x522910b9: /* Aladdin need to activate the ATAPI FIFO */
404 pci_write_config(dev, 0x53,
405 (pci_read_config(dev, 0x53, 1) & ~0x01) | 0x02, 1);
406 break;

--- 80 unchanged lines hidden (view full) ---

487
488 return bus_generic_attach(dev);
489}
490
491static int
492ata_pci_print_child(device_t dev, device_t child)
493{
494 struct ata_softc *scp = device_get_softc(child);
398 }
399
400 /* do extra chipset specific setups */
401 switch (type) {
402 case 0x522910b9: /* Aladdin need to activate the ATAPI FIFO */
403 pci_write_config(dev, 0x53,
404 (pci_read_config(dev, 0x53, 1) & ~0x01) | 0x02, 1);
405 break;

--- 80 unchanged lines hidden (view full) ---

486
487 return bus_generic_attach(dev);
488}
489
490static int
491ata_pci_print_child(device_t dev, device_t child)
492{
493 struct ata_softc *scp = device_get_softc(child);
495 int unit = (uintptr_t) device_get_ivars(child);
496 int retval = 0;
497
498 retval += bus_print_child_header(dev, child);
499 retval += printf(": at 0x%x", scp->ioaddr);
500
501 if (ATA_MASTERDEV(dev))
494 int retval = 0;
495
496 retval += bus_print_child_header(dev, child);
497 retval += printf(": at 0x%x", scp->ioaddr);
498
499 if (ATA_MASTERDEV(dev))
502 retval += printf(" irq %d", 14 + unit);
500 retval += printf(" irq %d", 14 + scp->channel);
503
504 retval += bus_print_child_footer(dev, child);
505
506 return retval;
507}
508
509static struct resource *
510ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
511 u_long start, u_long end, u_long count, u_int flags)
512{
513 struct ata_pci_softc *sc = device_get_softc(dev);
501
502 retval += bus_print_child_footer(dev, child);
503
504 return retval;
505}
506
507static struct resource *
508ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
509 u_long start, u_long end, u_long count, u_int flags)
510{
511 struct ata_pci_softc *sc = device_get_softc(dev);
514 int unit = (intptr_t)device_get_ivars(child);
512 int channel = ((struct ata_softc *)device_get_softc(child))->channel;
515 int myrid;
516
517 if (type == SYS_RES_IOPORT) {
518 switch (*rid) {
519 case ATA_IOADDR_RID:
520 if (ATA_MASTERDEV(dev)) {
521 myrid = 0;
513 int myrid;
514
515 if (type == SYS_RES_IOPORT) {
516 switch (*rid) {
517 case ATA_IOADDR_RID:
518 if (ATA_MASTERDEV(dev)) {
519 myrid = 0;
522 start = (unit == 0 ? IO_WD1 : IO_WD2);
520 start = (channel == 0 ? IO_WD1 : IO_WD2);
523 end = start + ATA_IOSIZE - 1;
524 count = ATA_IOSIZE;
525 }
526 else
521 end = start + ATA_IOSIZE - 1;
522 count = ATA_IOSIZE;
523 }
524 else
527 myrid = 0x10 + 8 * unit;
525 myrid = 0x10 + 8 * channel;
528 break;
529
530 case ATA_ALTADDR_RID:
531 if (ATA_MASTERDEV(dev)) {
532 myrid = 0;
526 break;
527
528 case ATA_ALTADDR_RID:
529 if (ATA_MASTERDEV(dev)) {
530 myrid = 0;
533 start = (unit == 0 ? IO_WD1 : IO_WD2) + ATA_ALTOFFSET;
531 start = (channel == 0 ? IO_WD1 : IO_WD2) + ATA_ALTOFFSET;
534 end = start + ATA_ALTIOSIZE - 1;
535 count = ATA_ALTIOSIZE;
536 }
537 else
532 end = start + ATA_ALTIOSIZE - 1;
533 count = ATA_ALTIOSIZE;
534 }
535 else
538 myrid = 0x14 + 8 * unit;
536 myrid = 0x14 + 8 * channel;
539 break;
540
541 case ATA_BMADDR_RID:
542 /* the busmaster resource is shared between the two channels */
543 if (sc->bmio) {
537 break;
538
539 case ATA_BMADDR_RID:
540 /* the busmaster resource is shared between the two channels */
541 if (sc->bmio) {
544 if (unit == 0) {
542 if (channel == 0) {
545 sc->bmio_1 = *sc->bmio;
546 sc->bmio_1.r_end = sc->bmio->r_start + ATA_BM_OFFSET1;
547 return &sc->bmio_1;
548 } else {
549 sc->bmio_2 = *sc->bmio;
550 sc->bmio_2.r_start = sc->bmio->r_start + ATA_BM_OFFSET1;
551 sc->bmio_2.r_end = sc->bmio_2.r_start + ATA_BM_OFFSET1;
552 return &sc->bmio_2;

--- 18 unchanged lines hidden (view full) ---

571 }
572
573 if (type == SYS_RES_IRQ) {
574 if (*rid != 0)
575 return 0;
576
577 if (ATA_MASTERDEV(dev)) {
578#ifdef __alpha__
543 sc->bmio_1 = *sc->bmio;
544 sc->bmio_1.r_end = sc->bmio->r_start + ATA_BM_OFFSET1;
545 return &sc->bmio_1;
546 } else {
547 sc->bmio_2 = *sc->bmio;
548 sc->bmio_2.r_start = sc->bmio->r_start + ATA_BM_OFFSET1;
549 sc->bmio_2.r_end = sc->bmio_2.r_start + ATA_BM_OFFSET1;
550 return &sc->bmio_2;

--- 18 unchanged lines hidden (view full) ---

569 }
570
571 if (type == SYS_RES_IRQ) {
572 if (*rid != 0)
573 return 0;
574
575 if (ATA_MASTERDEV(dev)) {
576#ifdef __alpha__
579 return alpha_platform_alloc_ide_intr(unit);
577 return alpha_platform_alloc_ide_intr(channel);
580#else
578#else
581 int irq = (unit == 0 ? 14 : 15);
579 int irq = (channel == 0 ? 14 : 15);
582
583 return BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
584 SYS_RES_IRQ, rid,
585 irq, irq, 1, flags & ~RF_SHAREABLE);
586#endif
587 } else {
588 /* primary and secondary channels share the same interrupt */
589 sc->irqcnt++;

--- 6 unchanged lines hidden (view full) ---

596 return 0;
597}
598
599static int
600ata_pci_release_resource(device_t dev, device_t child, int type, int rid,
601 struct resource *r)
602{
603 struct ata_pci_softc *sc = device_get_softc(dev);
580
581 return BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
582 SYS_RES_IRQ, rid,
583 irq, irq, 1, flags & ~RF_SHAREABLE);
584#endif
585 } else {
586 /* primary and secondary channels share the same interrupt */
587 sc->irqcnt++;

--- 6 unchanged lines hidden (view full) ---

594 return 0;
595}
596
597static int
598ata_pci_release_resource(device_t dev, device_t child, int type, int rid,
599 struct resource *r)
600{
601 struct ata_pci_softc *sc = device_get_softc(dev);
604 int unit = (uintptr_t) device_get_ivars(child);
602 int channel = ((struct ata_softc *)device_get_softc(child))->channel;
605 int myrid = 0;
606
607 if (type == SYS_RES_IOPORT) {
608 switch (rid) {
609 case ATA_IOADDR_RID:
610 if (ATA_MASTERDEV(dev))
611 myrid = 0;
612 else
603 int myrid = 0;
604
605 if (type == SYS_RES_IOPORT) {
606 switch (rid) {
607 case ATA_IOADDR_RID:
608 if (ATA_MASTERDEV(dev))
609 myrid = 0;
610 else
613 myrid = 0x10 + 8 * unit;
611 myrid = 0x10 + 8 * channel;
614 break;
615
616 case ATA_ALTADDR_RID:
617 if (ATA_MASTERDEV(dev))
618 myrid = 0;
619 else
612 break;
613
614 case ATA_ALTADDR_RID:
615 if (ATA_MASTERDEV(dev))
616 myrid = 0;
617 else
620 myrid = 0x14 + 8 * unit;
618 myrid = 0x14 + 8 * channel;
621 break;
622
623 case ATA_BMADDR_RID:
624 return 0;
625
626 default:
627 return ENOENT;
628 }

--- 8 unchanged lines hidden (view full) ---

637 SYS_RES_IOPORT, myrid, r);
638 }
639 if (type == SYS_RES_IRQ) {
640 if (rid != 0)
641 return ENOENT;
642
643 if (ATA_MASTERDEV(dev)) {
644#ifdef __alpha__
619 break;
620
621 case ATA_BMADDR_RID:
622 return 0;
623
624 default:
625 return ENOENT;
626 }

--- 8 unchanged lines hidden (view full) ---

635 SYS_RES_IOPORT, myrid, r);
636 }
637 if (type == SYS_RES_IRQ) {
638 if (rid != 0)
639 return ENOENT;
640
641 if (ATA_MASTERDEV(dev)) {
642#ifdef __alpha__
645 return alpha_platform_release_ide_intr(unit, r);
643 return alpha_platform_release_ide_intr(channel, r);
646#else
647 return BUS_RELEASE_RESOURCE(device_get_parent(dev),
648 child, SYS_RES_IRQ, rid, r);
649#endif
650 }
651 else {
652 if (--sc->irqcnt)
653 return 0;

--- 64 unchanged lines hidden (view full) ---

718};
719
720DRIVER_MODULE(atapci, pci, ata_pci_driver, ata_pci_devclass, 0, 0);
721
722static int
723ata_pcisub_probe(device_t dev)
724{
725 struct ata_softc *scp = device_get_softc(dev);
644#else
645 return BUS_RELEASE_RESOURCE(device_get_parent(dev),
646 child, SYS_RES_IRQ, rid, r);
647#endif
648 }
649 else {
650 if (--sc->irqcnt)
651 return 0;

--- 64 unchanged lines hidden (view full) ---

716};
717
718DRIVER_MODULE(atapci, pci, ata_pci_driver, ata_pci_devclass, 0, 0);
719
720static int
721ata_pcisub_probe(device_t dev)
722{
723 struct ata_softc *scp = device_get_softc(dev);
724 device_t *list;
725 int count, i;
726
726
727 /* kids of pci ata chipsets has their physical unit number in ivars */
728 scp->unit = (uintptr_t) device_get_ivars(dev);
727 /* find channel number on this controller */
728 device_get_children(device_get_parent(dev), &list, &count);
729 for (i = 0; i < count; i++) {
730 if (list[i] == dev)
731 scp->channel = i;
732 }
733
729 scp->chiptype = pci_get_devid(device_get_parent(dev));
734 scp->chiptype = pci_get_devid(device_get_parent(dev));
735
736 /* is this an ATA RAID setup ? */
737 if (((pci_get_subclass(device_get_parent(dev)) == PCIS_STORAGE_RAID) &&
738 (scp->chiptype == 0x4d33105a || scp->chiptype == 0x4d38105a ||
739 scp->chiptype == 0x4d30105a || scp->chiptype == 0x0d30105a)) ||
740 scp->chiptype == 0x00041103) {
741 scp->flags |= ATA_RAID;
742 }
730 return ata_probe(dev);
731}
732
733static device_method_t ata_pcisub_methods[] = {
734 /* device interface */
735 DEVMETHOD(device_probe, ata_pcisub_probe),
736 DEVMETHOD(device_attach, ata_attach),
737 DEVMETHOD(device_detach, ata_detach),

--- 339 unchanged lines hidden (view full) ---

1077 (ATA_BMSTAT_ACTIVE | ATA_BMSTAT_INTERRUPT)) != ATA_BMSTAT_INTERRUPT)
1078 return;
1079 outb(scp->bmaddr + ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
1080 break;
1081
1082 case 0x06481095: /* CMD 648 */
1083 case 0x06491095: /* CMD 649 */
1084 if (!(pci_read_config(device_get_parent(scp->dev), 0x71, 1) &
743 return ata_probe(dev);
744}
745
746static device_method_t ata_pcisub_methods[] = {
747 /* device interface */
748 DEVMETHOD(device_probe, ata_pcisub_probe),
749 DEVMETHOD(device_attach, ata_attach),
750 DEVMETHOD(device_detach, ata_detach),

--- 339 unchanged lines hidden (view full) ---

1090 (ATA_BMSTAT_ACTIVE | ATA_BMSTAT_INTERRUPT)) != ATA_BMSTAT_INTERRUPT)
1091 return;
1092 outb(scp->bmaddr + ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
1093 break;
1094
1095 case 0x06481095: /* CMD 648 */
1096 case 0x06491095: /* CMD 649 */
1097 if (!(pci_read_config(device_get_parent(scp->dev), 0x71, 1) &
1085 (scp->unit ? 0x08 : 0x04)))
1098 (scp->channel ? 0x08 : 0x04)))
1086 return;
1087 goto out;
1088
1089 case 0x4d33105a: /* Promise Ultra/Fasttrak 33 */
1090 case 0x4d38105a: /* Promise Ultra/Fasttrak 66 */
1091 case 0x4d30105a: /* Promise Ultra/Fasttrak 100 */
1092 case 0x0d30105a: /* Promise OEM ATA100 */
1093 if (!(inl(rman_get_start(sc->bmio) + 0x1c) &
1099 return;
1100 goto out;
1101
1102 case 0x4d33105a: /* Promise Ultra/Fasttrak 33 */
1103 case 0x4d38105a: /* Promise Ultra/Fasttrak 66 */
1104 case 0x4d30105a: /* Promise Ultra/Fasttrak 100 */
1105 case 0x0d30105a: /* Promise OEM ATA100 */
1106 if (!(inl(rman_get_start(sc->bmio) + 0x1c) &
1094 (scp->unit ? 0x00004000 : 0x00000400)))
1107 (scp->channel ? 0x00004000 : 0x00000400)))
1095 return;
1096 /* FALLTHROUGH */
1097out:
1098#endif
1099 default:
1100 if (scp->flags & ATA_DMA_ACTIVE) {
1101 if (((dmastat = ata_dmastatus(scp)) &
1102 (ATA_BMSTAT_ACTIVE|ATA_BMSTAT_INTERRUPT))!=ATA_BMSTAT_INTERRUPT)

--- 673 unchanged lines hidden ---
1108 return;
1109 /* FALLTHROUGH */
1110out:
1111#endif
1112 default:
1113 if (scp->flags & ATA_DMA_ACTIVE) {
1114 if (((dmastat = ata_dmastatus(scp)) &
1115 (ATA_BMSTAT_ACTIVE|ATA_BMSTAT_INTERRUPT))!=ATA_BMSTAT_INTERRUPT)

--- 673 unchanged lines hidden ---