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 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); |
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); |
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 } |
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); |
396 if (!sc->bmio) 397 device_printf(dev, "Busmastering DMA not supported\n"); |
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); |
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)) |
500 retval += printf(" irq %d", 14 + scp->channel); |
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); |
512 int channel = ((struct ata_softc *)device_get_softc(child))->channel; |
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; |
520 start = (channel == 0 ? IO_WD1 : IO_WD2); |
521 end = start + ATA_IOSIZE - 1; 522 count = ATA_IOSIZE; 523 } 524 else |
525 myrid = 0x10 + 8 * channel; |
526 break; 527 528 case ATA_ALTADDR_RID: 529 if (ATA_MASTERDEV(dev)) { 530 myrid = 0; |
531 start = (channel == 0 ? IO_WD1 : IO_WD2) + ATA_ALTOFFSET; |
532 end = start + ATA_ALTIOSIZE - 1; 533 count = ATA_ALTIOSIZE; 534 } 535 else |
536 myrid = 0x14 + 8 * channel; |
537 break; 538 539 case ATA_BMADDR_RID: 540 /* the busmaster resource is shared between the two channels */ 541 if (sc->bmio) { |
542 if (channel == 0) { |
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__ |
577 return alpha_platform_alloc_ide_intr(channel); |
578#else |
579 int irq = (channel == 0 ? 14 : 15); |
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); |
602 int channel = ((struct ata_softc *)device_get_softc(child))->channel; |
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 |
611 myrid = 0x10 + 8 * channel; |
612 break; 613 614 case ATA_ALTADDR_RID: 615 if (ATA_MASTERDEV(dev)) 616 myrid = 0; 617 else |
618 myrid = 0x14 + 8 * channel; |
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__ |
643 return alpha_platform_release_ide_intr(channel, r); |
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 |
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 |
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 } |
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) & |
1098 (scp->channel ? 0x08 : 0x04))) |
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) & |
1107 (scp->channel ? 0x00004000 : 0x00000400))) |
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 --- |