Deleted Added
full compact
ata-pci.c (104684) ata-pci.c (107562)
1/*-
2 * Copyright (c) 1998,1999,2000,2001,2002 S�ren Schmidt <sos@FreeBSD.org>
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,2001,2002 S�ren Schmidt <sos@FreeBSD.org>
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-pci.c 104684 2002-10-08 18:25:10Z sos $
28 * $FreeBSD: head/sys/dev/ata/ata-pci.c 107562 2002-12-03 20:20:44Z sos $
29 */
30
31#include "opt_ata.h"
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/bus.h>

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

47#include <dev/ata/ata-all.h>
48
49/* device structures */
50struct ata_pci_controller {
51 struct resource *bmio;
52 int bmaddr;
53 struct resource *irq;
54 int irqcnt;
29 */
30
31#include "opt_ata.h"
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/bus.h>

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

47#include <dev/ata/ata-all.h>
48
49/* device structures */
50struct ata_pci_controller {
51 struct resource *bmio;
52 int bmaddr;
53 struct resource *irq;
54 int irqcnt;
55 int lock;
55};
56
57/* misc defines */
58#define IOMASK 0xfffffffc
59#define GRANDPARENT(dev) device_get_parent(device_get_parent(dev))
60#define ATA_MASTERDEV(dev) ((pci_get_progif(dev) & 0x80) && \
61 (pci_get_progif(dev) & 0x05) != 0x05)
62

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

309 case 0x01:
310 return "HighPoint HPT372 ATA133 controller";
311 }
312 return NULL;
313
314 case 0x00081103:
315 switch (pci_get_revid(dev)) {
316 case 0x07:
56};
57
58/* misc defines */
59#define IOMASK 0xfffffffc
60#define GRANDPARENT(dev) device_get_parent(device_get_parent(dev))
61#define ATA_MASTERDEV(dev) ((pci_get_progif(dev) & 0x80) && \
62 (pci_get_progif(dev) & 0x05) != 0x05)
63

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

310 case 0x01:
311 return "HighPoint HPT372 ATA133 controller";
312 }
313 return NULL;
314
315 case 0x00081103:
316 switch (pci_get_revid(dev)) {
317 case 0x07:
318 if (pci_get_function(dev) == 0)
319 return "HighPoint HPT374 ATA133 controller (channel 0+1)";
320 if (pci_get_function(dev) == 1)
321 return "HighPoint HPT374 ATA133 controller (channel 2+3)";
317 return "HighPoint HPT374 ATA133 controller";
318 }
319 return NULL;
320
322 return "HighPoint HPT374 ATA133 controller";
323 }
324 return NULL;
325
326 case 0x00051191:
327 return "Acard ATP850 ATA-33 controller";
328
329 case 0x00061191:
330 case 0x00071191:
331 return "Acard ATP860 ATA-66 controller";
332
333 case 0x00081191:
334 case 0x00091191:
335 return "Acard ATP865 ATA-133 controller";
336
321 case 0x000116ca:
322 return "Cenatek Rocket Drive controller";
323
324 /* unsupported but known chipsets, generic DMA only */
325 case 0x10001042:
326 case 0x10011042:
327 return "RZ 100? ATA controller !WARNING! buggy chip data loss possible";
328

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

349 }
350 else
351 return ENXIO;
352}
353
354static int
355ata_pci_add_child(device_t dev, int unit)
356{
337 case 0x000116ca:
338 return "Cenatek Rocket Drive controller";
339
340 /* unsupported but known chipsets, generic DMA only */
341 case 0x10001042:
342 case 0x10011042:
343 return "RZ 100? ATA controller !WARNING! buggy chip data loss possible";
344

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

365 }
366 else
367 return ENXIO;
368}
369
370static int
371ata_pci_add_child(device_t dev, int unit)
372{
357 device_t child;
358
359 /* check if this is located at one of the std addresses */
360 if (ATA_MASTERDEV(dev)) {
373 /* check if this is located at one of the std addresses */
374 if (ATA_MASTERDEV(dev)) {
361 if (!(child = device_add_child(dev, "ata", unit)))
375 if (!device_add_child(dev, "ata", unit))
362 return ENOMEM;
363 }
364 else {
376 return ENOMEM;
377 }
378 else {
365 if (!(child =
366 device_add_child(dev, "ata",
367 devclass_find_free_unit(ata_devclass, 2))))
379 if (!device_add_child(dev, "ata",
380 devclass_find_free_unit(ata_devclass, 2)))
368 return ENOMEM;
369 }
370 return 0;
371}
372
373static int
374ata_pci_attach(device_t dev)
375{

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

534 }
535
536 if (controller->bmio) {
537 controller->bmaddr = rman_get_start(controller->bmio);
538 BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
539 SYS_RES_IOPORT, rid, controller->bmio);
540 controller->bmio = NULL;
541 }
381 return ENOMEM;
382 }
383 return 0;
384}
385
386static int
387ata_pci_attach(device_t dev)
388{

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

547 }
548
549 if (controller->bmio) {
550 controller->bmaddr = rman_get_start(controller->bmio);
551 BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
552 SYS_RES_IOPORT, rid, controller->bmio);
553 controller->bmio = NULL;
554 }
555 controller->lock = -1;
542
543 /*
544 * the Cypress chip is a mess, it contains two ATA functions, but
545 * both channels are visible on the first one.
546 * simply ignore the second function for now, as the right
547 * solution (ignoring the second channel on the first function)
548 * doesn't work with the crappy ATA interrupt setup on the alpha.
549 */

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

569 * that we know this channel generated.
570 */
571 switch (ch->chiptype) {
572 case 0x00041103: /* HighPoint HPT366/368/370/372 */
573 case 0x00051103: /* HighPoint HPT372 */
574 case 0x00081103: /* HighPoint HPT374 */
575 if (((dmastat = ata_dmastatus(ch)) &
576 (ATA_BMSTAT_ACTIVE | ATA_BMSTAT_INTERRUPT)) != ATA_BMSTAT_INTERRUPT)
556
557 /*
558 * the Cypress chip is a mess, it contains two ATA functions, but
559 * both channels are visible on the first one.
560 * simply ignore the second function for now, as the right
561 * solution (ignoring the second channel on the first function)
562 * doesn't work with the crappy ATA interrupt setup on the alpha.
563 */

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

583 * that we know this channel generated.
584 */
585 switch (ch->chiptype) {
586 case 0x00041103: /* HighPoint HPT366/368/370/372 */
587 case 0x00051103: /* HighPoint HPT372 */
588 case 0x00081103: /* HighPoint HPT374 */
589 if (((dmastat = ata_dmastatus(ch)) &
590 (ATA_BMSTAT_ACTIVE | ATA_BMSTAT_INTERRUPT)) != ATA_BMSTAT_INTERRUPT)
577 return 1;
591 return 0;
578 ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
579 DELAY(1);
592 ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
593 DELAY(1);
580 return 0;
594 return 1;
581
582 case 0x06481095: /* CMD 648 */
583 case 0x06491095: /* CMD 649 */
584 if (!(pci_read_config(device_get_parent(ch->dev), 0x71, 1) &
585 (ch->unit ? 0x08 : 0x04)))
595
596 case 0x06481095: /* CMD 648 */
597 case 0x06491095: /* CMD 649 */
598 if (!(pci_read_config(device_get_parent(ch->dev), 0x71, 1) &
599 (ch->unit ? 0x08 : 0x04)))
586 return 1;
600 return 0;
587 break;
588
589 case 0x4d33105a: /* Promise Ultra/Fasttrak 33 */
590 case 0x0d38105a: /* Promise Fasttrak 66 */
591 case 0x4d38105a: /* Promise Ultra/Fasttrak 66 */
592 case 0x0d30105a: /* Promise OEM ATA100 */
593 case 0x4d30105a: /* Promise Ultra/Fasttrak 100 */
594 if (!(ATA_INL(ch->r_bmio, (ch->unit ? 0x14 : 0x1c)) &
595 (ch->unit ? 0x00004000 : 0x00000400)))
601 break;
602
603 case 0x4d33105a: /* Promise Ultra/Fasttrak 33 */
604 case 0x0d38105a: /* Promise Fasttrak 66 */
605 case 0x4d38105a: /* Promise Ultra/Fasttrak 66 */
606 case 0x0d30105a: /* Promise OEM ATA100 */
607 case 0x4d30105a: /* Promise Ultra/Fasttrak 100 */
608 if (!(ATA_INL(ch->r_bmio, (ch->unit ? 0x14 : 0x1c)) &
609 (ch->unit ? 0x00004000 : 0x00000400)))
596 return 1;
610 return 0;
597 break;
598
599 case 0x4d68105a: /* Promise TX2 ATA100 */
600 case 0x6268105a: /* Promise TX2 ATA100 */
601 case 0x4d69105a: /* Promise TX2 ATA133 */
602 case 0x5275105a: /* Promise TX2 ATA133 */
603 case 0x6269105a: /* Promise TX2 ATA133 */
604 case 0x7275105a: /* Promise TX2 ATA133 */
605 ATA_OUTB(ch->r_bmio, ATA_BMDEVSPEC_0, 0x0b);
606 if (!(ATA_INB(ch->r_bmio, ATA_BMDEVSPEC_1) & 0x20))
611 break;
612
613 case 0x4d68105a: /* Promise TX2 ATA100 */
614 case 0x6268105a: /* Promise TX2 ATA100 */
615 case 0x4d69105a: /* Promise TX2 ATA133 */
616 case 0x5275105a: /* Promise TX2 ATA133 */
617 case 0x6269105a: /* Promise TX2 ATA133 */
618 case 0x7275105a: /* Promise TX2 ATA133 */
619 ATA_OUTB(ch->r_bmio, ATA_BMDEVSPEC_0, 0x0b);
620 if (!(ATA_INB(ch->r_bmio, ATA_BMDEVSPEC_1) & 0x20))
607 return 1;
621 return 0;
608 break;
622 break;
623
624 case 0x00051191: /* Acard ATP850 */
625 {
626 struct ata_pci_controller *scp =
627 device_get_softc(device_get_parent(ch->dev));
628
629 if (ch->unit != scp->lock)
630 return 0;
631 }
632 /* FALLTHROUGH */
633
634 case 0x00061191: /* Acard ATP860 */
635 case 0x00071191: /* Acard ATP860R */
636 case 0x00081191: /* Acard ATP865 */
637 case 0x00091191: /* Acard ATP865R */
638 if (ch->flags & ATA_DMA_ACTIVE) {
639 if (!((dmastat = ata_dmastatus(ch)) & ATA_BMSTAT_INTERRUPT))
640 return 0;
641 ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, dmastat|ATA_BMSTAT_INTERRUPT);
642 DELAY(1);
643 ATA_OUTB(ch->r_bmio, ATA_BMCMD_PORT,
644 ATA_INB(ch->r_bmio, ATA_BMCMD_PORT)&~ATA_BMCMD_START_STOP);
645 DELAY(1);
646 }
647 return 1;
609 }
610
611 if (ch->flags & ATA_DMA_ACTIVE) {
612 if (!((dmastat = ata_dmastatus(ch)) & ATA_BMSTAT_INTERRUPT))
648 }
649
650 if (ch->flags & ATA_DMA_ACTIVE) {
651 if (!((dmastat = ata_dmastatus(ch)) & ATA_BMSTAT_INTERRUPT))
613 return 1;
652 return 0;
614 ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
615 DELAY(1);
616 }
653 ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
654 DELAY(1);
655 }
617 return 0;
656 return 1;
618}
619
657}
658
659static void
660ata_pci_locknoop(struct ata_channel *ch, int type)
661{
662}
663
664static void
665ata_pci_serialize(struct ata_channel *ch, int flags)
666{
667 struct ata_pci_controller *scp =
668 device_get_softc(device_get_parent(ch->dev));
669
670 switch (flags) {
671 case ATA_LF_LOCK:
672 if (scp->lock == ch->unit)
673 break;
674 while (!atomic_cmpset_acq_int(&scp->lock, -1, ch->unit))
675 tsleep((caddr_t)ch->lock_func, PRIBIO, "atalck", 1);
676 break;
677
678 case ATA_LF_UNLOCK:
679 if (scp->lock == -1 || scp->lock != ch->unit)
680 break;
681 atomic_store_rel_int(&scp->lock, -1);
682 break;
683 }
684 return;
685}
686
620static int
621ata_pci_print_child(device_t dev, device_t child)
622{
623 struct ata_channel *ch = device_get_softc(child);
624 int retval = 0;
625
626 retval += bus_print_child_header(dev, child);
627 retval += printf(": at 0x%lx", rman_get_start(ch->r_io));

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

859
860 /* find channel number on this controller */
861 device_get_children(device_get_parent(dev), &children, &count);
862 for (i = 0; i < count; i++) {
863 if (children[i] == dev)
864 ch->unit = i;
865 }
866 free(children, M_TEMP);
687static int
688ata_pci_print_child(device_t dev, device_t child)
689{
690 struct ata_channel *ch = device_get_softc(child);
691 int retval = 0;
692
693 retval += bus_print_child_header(dev, child);
694 retval += printf(": at 0x%lx", rman_get_start(ch->r_io));

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

926
927 /* find channel number on this controller */
928 device_get_children(device_get_parent(dev), &children, &count);
929 for (i = 0; i < count; i++) {
930 if (children[i] == dev)
931 ch->unit = i;
932 }
933 free(children, M_TEMP);
867 ch->chiptype = pci_get_devid(device_get_parent(dev));
934
868 ch->intr_func = ata_pci_intr;
935 ch->intr_func = ata_pci_intr;
936 ch->chiptype = pci_get_devid(device_get_parent(dev));
937 switch (ch->chiptype) {
938 case 0x10001042: /* RZ 1000 */
939 case 0x10011042: /* RZ 1001 */
940 case 0x06401095: /* CMD 640 */
941 case 0x00051191: /* Acard ATP850 */
942 ch->lock_func = ata_pci_serialize;
943 break;
944 default:
945 ch->lock_func = ata_pci_locknoop;
946 }
869 return ata_probe(dev);
870}
871
872static device_method_t ata_pcisub_methods[] = {
873 /* device interface */
874 DEVMETHOD(device_probe, ata_pcisub_probe),
875 DEVMETHOD(device_attach, ata_attach),
876 DEVMETHOD(device_detach, ata_detach),
877 DEVMETHOD(device_resume, ata_resume),
878 { 0, 0 }
879};
880
881static driver_t ata_pcisub_driver = {
882 "ata",
883 ata_pcisub_methods,
884 sizeof(struct ata_channel),
885};
886
887DRIVER_MODULE(ata, atapci, ata_pcisub_driver, ata_devclass, 0, 0);
947 return ata_probe(dev);
948}
949
950static device_method_t ata_pcisub_methods[] = {
951 /* device interface */
952 DEVMETHOD(device_probe, ata_pcisub_probe),
953 DEVMETHOD(device_attach, ata_attach),
954 DEVMETHOD(device_detach, ata_detach),
955 DEVMETHOD(device_resume, ata_resume),
956 { 0, 0 }
957};
958
959static driver_t ata_pcisub_driver = {
960 "ata",
961 ata_pcisub_methods,
962 sizeof(struct ata_channel),
963};
964
965DRIVER_MODULE(ata, atapci, ata_pcisub_driver, ata_devclass, 0, 0);