aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-core.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-02-01 01:06:36 -0500
committerJeff Garzik <jeff@garzik.org>2007-02-09 17:39:38 -0500
commit0d5ff566779f894ca9937231a181eb31e4adff0e (patch)
treed1c7495c932581c1d41aa7f0fdb303348da49106 /drivers/ata/libata-core.c
parent1a68ff13c8a9b517de3fd4187dc525412a6eba1b (diff)
libata: convert to iomap
Convert libata core layer and LLDs to use iomap. * managed iomap is used. Pointer to pcim_iomap_table() is cached at host->iomap and used through out LLDs. This basically replaces host->mmio_base. * if possible, pcim_iomap_regions() is used Most iomap operation conversions are taken from Jeff Garzik <jgarzik@pobox.com>'s iomap branch. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r--drivers/ata/libata-core.c213
1 files changed, 37 insertions, 176 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index ed11ee41673c..f210dbd4cbe6 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -601,51 +601,7 @@ void ata_dev_disable(struct ata_device *dev)
601} 601}
602 602
603/** 603/**
604 * ata_pio_devchk - PATA device presence detection 604 * ata_devchk - PATA device presence detection
605 * @ap: ATA channel to examine
606 * @device: Device to examine (starting at zero)
607 *
608 * This technique was originally described in
609 * Hale Landis's ATADRVR (www.ata-atapi.com), and
610 * later found its way into the ATA/ATAPI spec.
611 *
612 * Write a pattern to the ATA shadow registers,
613 * and if a device is present, it will respond by
614 * correctly storing and echoing back the
615 * ATA shadow register contents.
616 *
617 * LOCKING:
618 * caller.
619 */
620
621static unsigned int ata_pio_devchk(struct ata_port *ap,
622 unsigned int device)
623{
624 struct ata_ioports *ioaddr = &ap->ioaddr;
625 u8 nsect, lbal;
626
627 ap->ops->dev_select(ap, device);
628
629 outb(0x55, ioaddr->nsect_addr);
630 outb(0xaa, ioaddr->lbal_addr);
631
632 outb(0xaa, ioaddr->nsect_addr);
633 outb(0x55, ioaddr->lbal_addr);
634
635 outb(0x55, ioaddr->nsect_addr);
636 outb(0xaa, ioaddr->lbal_addr);
637
638 nsect = inb(ioaddr->nsect_addr);
639 lbal = inb(ioaddr->lbal_addr);
640
641 if ((nsect == 0x55) && (lbal == 0xaa))
642 return 1; /* we found a device */
643
644 return 0; /* nothing found */
645}
646
647/**
648 * ata_mmio_devchk - PATA device presence detection
649 * @ap: ATA channel to examine 605 * @ap: ATA channel to examine
650 * @device: Device to examine (starting at zero) 606 * @device: Device to examine (starting at zero)
651 * 607 *
@@ -662,25 +618,24 @@ static unsigned int ata_pio_devchk(struct ata_port *ap,
662 * caller. 618 * caller.
663 */ 619 */
664 620
665static unsigned int ata_mmio_devchk(struct ata_port *ap, 621static unsigned int ata_devchk(struct ata_port *ap, unsigned int device)
666 unsigned int device)
667{ 622{
668 struct ata_ioports *ioaddr = &ap->ioaddr; 623 struct ata_ioports *ioaddr = &ap->ioaddr;
669 u8 nsect, lbal; 624 u8 nsect, lbal;
670 625
671 ap->ops->dev_select(ap, device); 626 ap->ops->dev_select(ap, device);
672 627
673 writeb(0x55, (void __iomem *) ioaddr->nsect_addr); 628 iowrite8(0x55, ioaddr->nsect_addr);
674 writeb(0xaa, (void __iomem *) ioaddr->lbal_addr); 629 iowrite8(0xaa, ioaddr->lbal_addr);
675 630
676 writeb(0xaa, (void __iomem *) ioaddr->nsect_addr); 631 iowrite8(0xaa, ioaddr->nsect_addr);
677 writeb(0x55, (void __iomem *) ioaddr->lbal_addr); 632 iowrite8(0x55, ioaddr->lbal_addr);
678 633
679 writeb(0x55, (void __iomem *) ioaddr->nsect_addr); 634 iowrite8(0x55, ioaddr->nsect_addr);
680 writeb(0xaa, (void __iomem *) ioaddr->lbal_addr); 635 iowrite8(0xaa, ioaddr->lbal_addr);
681 636
682 nsect = readb((void __iomem *) ioaddr->nsect_addr); 637 nsect = ioread8(ioaddr->nsect_addr);
683 lbal = readb((void __iomem *) ioaddr->lbal_addr); 638 lbal = ioread8(ioaddr->lbal_addr);
684 639
685 if ((nsect == 0x55) && (lbal == 0xaa)) 640 if ((nsect == 0x55) && (lbal == 0xaa))
686 return 1; /* we found a device */ 641 return 1; /* we found a device */
@@ -689,27 +644,6 @@ static unsigned int ata_mmio_devchk(struct ata_port *ap,
689} 644}
690 645
691/** 646/**
692 * ata_devchk - PATA device presence detection
693 * @ap: ATA channel to examine
694 * @device: Device to examine (starting at zero)
695 *
696 * Dispatch ATA device presence detection, depending
697 * on whether we are using PIO or MMIO to talk to the
698 * ATA shadow registers.
699 *
700 * LOCKING:
701 * caller.
702 */
703
704static unsigned int ata_devchk(struct ata_port *ap,
705 unsigned int device)
706{
707 if (ap->flags & ATA_FLAG_MMIO)
708 return ata_mmio_devchk(ap, device);
709 return ata_pio_devchk(ap, device);
710}
711
712/**
713 * ata_dev_classify - determine device type based on ATA-spec signature 647 * ata_dev_classify - determine device type based on ATA-spec signature
714 * @tf: ATA taskfile register set for device to be identified 648 * @tf: ATA taskfile register set for device to be identified
715 * 649 *
@@ -926,11 +860,7 @@ void ata_std_dev_select (struct ata_port *ap, unsigned int device)
926 else 860 else
927 tmp = ATA_DEVICE_OBS | ATA_DEV1; 861 tmp = ATA_DEVICE_OBS | ATA_DEV1;
928 862
929 if (ap->flags & ATA_FLAG_MMIO) { 863 iowrite8(tmp, ap->ioaddr.device_addr);
930 writeb(tmp, (void __iomem *) ap->ioaddr.device_addr);
931 } else {
932 outb(tmp, ap->ioaddr.device_addr);
933 }
934 ata_pause(ap); /* needed; also flushes, for mmio */ 864 ata_pause(ap); /* needed; also flushes, for mmio */
935} 865}
936 866
@@ -2616,13 +2546,8 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
2616 u8 nsect, lbal; 2546 u8 nsect, lbal;
2617 2547
2618 ap->ops->dev_select(ap, 1); 2548 ap->ops->dev_select(ap, 1);
2619 if (ap->flags & ATA_FLAG_MMIO) { 2549 nsect = ioread8(ioaddr->nsect_addr);
2620 nsect = readb((void __iomem *) ioaddr->nsect_addr); 2550 lbal = ioread8(ioaddr->lbal_addr);
2621 lbal = readb((void __iomem *) ioaddr->lbal_addr);
2622 } else {
2623 nsect = inb(ioaddr->nsect_addr);
2624 lbal = inb(ioaddr->lbal_addr);
2625 }
2626 if ((nsect == 1) && (lbal == 1)) 2551 if ((nsect == 1) && (lbal == 1))
2627 break; 2552 break;
2628 if (time_after(jiffies, timeout)) { 2553 if (time_after(jiffies, timeout)) {
@@ -2650,19 +2575,11 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2650 DPRINTK("ata%u: bus reset via SRST\n", ap->id); 2575 DPRINTK("ata%u: bus reset via SRST\n", ap->id);
2651 2576
2652 /* software reset. causes dev0 to be selected */ 2577 /* software reset. causes dev0 to be selected */
2653 if (ap->flags & ATA_FLAG_MMIO) { 2578 iowrite8(ap->ctl, ioaddr->ctl_addr);
2654 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr); 2579 udelay(20); /* FIXME: flush */
2655 udelay(20); /* FIXME: flush */ 2580 iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr);
2656 writeb(ap->ctl | ATA_SRST, (void __iomem *) ioaddr->ctl_addr); 2581 udelay(20); /* FIXME: flush */
2657 udelay(20); /* FIXME: flush */ 2582 iowrite8(ap->ctl, ioaddr->ctl_addr);
2658 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
2659 } else {
2660 outb(ap->ctl, ioaddr->ctl_addr);
2661 udelay(10);
2662 outb(ap->ctl | ATA_SRST, ioaddr->ctl_addr);
2663 udelay(10);
2664 outb(ap->ctl, ioaddr->ctl_addr);
2665 }
2666 2583
2667 /* spec mandates ">= 2ms" before checking status. 2584 /* spec mandates ">= 2ms" before checking status.
2668 * We wait 150ms, because that was the magic delay used for 2585 * We wait 150ms, because that was the magic delay used for
@@ -2763,10 +2680,7 @@ void ata_bus_reset(struct ata_port *ap)
2763 2680
2764 if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) { 2681 if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) {
2765 /* set up device control for ATA_FLAG_SATA_RESET */ 2682 /* set up device control for ATA_FLAG_SATA_RESET */
2766 if (ap->flags & ATA_FLAG_MMIO) 2683 iowrite8(ap->ctl, ioaddr->ctl_addr);
2767 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
2768 else
2769 outb(ap->ctl, ioaddr->ctl_addr);
2770 } 2684 }
2771 2685
2772 DPRINTK("EXIT\n"); 2686 DPRINTK("EXIT\n");
@@ -3159,12 +3073,8 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
3159 } 3073 }
3160 3074
3161 /* set up device control */ 3075 /* set up device control */
3162 if (ap->ioaddr.ctl_addr) { 3076 if (ap->ioaddr.ctl_addr)
3163 if (ap->flags & ATA_FLAG_MMIO) 3077 iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
3164 writeb(ap->ctl, (void __iomem *) ap->ioaddr.ctl_addr);
3165 else
3166 outb(ap->ctl, ap->ioaddr.ctl_addr);
3167 }
3168 3078
3169 DPRINTK("EXIT\n"); 3079 DPRINTK("EXIT\n");
3170} 3080}
@@ -3880,53 +3790,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
3880} 3790}
3881 3791
3882/** 3792/**
3883 * ata_mmio_data_xfer - Transfer data by MMIO 3793 * ata_data_xfer - Transfer data by PIO
3884 * @adev: device for this I/O
3885 * @buf: data buffer
3886 * @buflen: buffer length
3887 * @write_data: read/write
3888 *
3889 * Transfer data from/to the device data register by MMIO.
3890 *
3891 * LOCKING:
3892 * Inherited from caller.
3893 */
3894
3895void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
3896 unsigned int buflen, int write_data)
3897{
3898 struct ata_port *ap = adev->ap;
3899 unsigned int i;
3900 unsigned int words = buflen >> 1;
3901 u16 *buf16 = (u16 *) buf;
3902 void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr;
3903
3904 /* Transfer multiple of 2 bytes */
3905 if (write_data) {
3906 for (i = 0; i < words; i++)
3907 writew(le16_to_cpu(buf16[i]), mmio);
3908 } else {
3909 for (i = 0; i < words; i++)
3910 buf16[i] = cpu_to_le16(readw(mmio));
3911 }
3912
3913 /* Transfer trailing 1 byte, if any. */
3914 if (unlikely(buflen & 0x01)) {
3915 u16 align_buf[1] = { 0 };
3916 unsigned char *trailing_buf = buf + buflen - 1;
3917
3918 if (write_data) {
3919 memcpy(align_buf, trailing_buf, 1);
3920 writew(le16_to_cpu(align_buf[0]), mmio);
3921 } else {
3922 align_buf[0] = cpu_to_le16(readw(mmio));
3923 memcpy(trailing_buf, align_buf, 1);
3924 }
3925 }
3926}
3927
3928/**
3929 * ata_pio_data_xfer - Transfer data by PIO
3930 * @adev: device to target 3794 * @adev: device to target
3931 * @buf: data buffer 3795 * @buf: data buffer
3932 * @buflen: buffer length 3796 * @buflen: buffer length
@@ -3937,18 +3801,17 @@ void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
3937 * LOCKING: 3801 * LOCKING:
3938 * Inherited from caller. 3802 * Inherited from caller.
3939 */ 3803 */
3940 3804void ata_data_xfer(struct ata_device *adev, unsigned char *buf,
3941void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf, 3805 unsigned int buflen, int write_data)
3942 unsigned int buflen, int write_data)
3943{ 3806{
3944 struct ata_port *ap = adev->ap; 3807 struct ata_port *ap = adev->ap;
3945 unsigned int words = buflen >> 1; 3808 unsigned int words = buflen >> 1;
3946 3809
3947 /* Transfer multiple of 2 bytes */ 3810 /* Transfer multiple of 2 bytes */
3948 if (write_data) 3811 if (write_data)
3949 outsw(ap->ioaddr.data_addr, buf, words); 3812 iowrite16_rep(ap->ioaddr.data_addr, buf, words);
3950 else 3813 else
3951 insw(ap->ioaddr.data_addr, buf, words); 3814 ioread16_rep(ap->ioaddr.data_addr, buf, words);
3952 3815
3953 /* Transfer trailing 1 byte, if any. */ 3816 /* Transfer trailing 1 byte, if any. */
3954 if (unlikely(buflen & 0x01)) { 3817 if (unlikely(buflen & 0x01)) {
@@ -3957,16 +3820,16 @@ void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
3957 3820
3958 if (write_data) { 3821 if (write_data) {
3959 memcpy(align_buf, trailing_buf, 1); 3822 memcpy(align_buf, trailing_buf, 1);
3960 outw(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr); 3823 iowrite16(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr);
3961 } else { 3824 } else {
3962 align_buf[0] = cpu_to_le16(inw(ap->ioaddr.data_addr)); 3825 align_buf[0] = cpu_to_le16(ioread16(ap->ioaddr.data_addr));
3963 memcpy(trailing_buf, align_buf, 1); 3826 memcpy(trailing_buf, align_buf, 1);
3964 } 3827 }
3965 } 3828 }
3966} 3829}
3967 3830
3968/** 3831/**
3969 * ata_pio_data_xfer_noirq - Transfer data by PIO 3832 * ata_data_xfer_noirq - Transfer data by PIO
3970 * @adev: device to target 3833 * @adev: device to target
3971 * @buf: data buffer 3834 * @buf: data buffer
3972 * @buflen: buffer length 3835 * @buflen: buffer length
@@ -3978,13 +3841,12 @@ void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
3978 * LOCKING: 3841 * LOCKING:
3979 * Inherited from caller. 3842 * Inherited from caller.
3980 */ 3843 */
3981 3844void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
3982void ata_pio_data_xfer_noirq(struct ata_device *adev, unsigned char *buf, 3845 unsigned int buflen, int write_data)
3983 unsigned int buflen, int write_data)
3984{ 3846{
3985 unsigned long flags; 3847 unsigned long flags;
3986 local_irq_save(flags); 3848 local_irq_save(flags);
3987 ata_pio_data_xfer(adev, buf, buflen, write_data); 3849 ata_data_xfer(adev, buf, buflen, write_data);
3988 local_irq_restore(flags); 3850 local_irq_restore(flags);
3989} 3851}
3990 3852
@@ -5770,7 +5632,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
5770 host->n_ports = ent->n_ports; 5632 host->n_ports = ent->n_ports;
5771 host->irq = ent->irq; 5633 host->irq = ent->irq;
5772 host->irq2 = ent->irq2; 5634 host->irq2 = ent->irq2;
5773 host->mmio_base = ent->mmio_base; 5635 host->iomap = ent->iomap;
5774 host->private_data = ent->private_data; 5636 host->private_data = ent->private_data;
5775 5637
5776 /* register each port bound to this device */ 5638 /* register each port bound to this device */
@@ -5808,8 +5670,8 @@ int ata_device_add(const struct ata_probe_ent *ent)
5808 (ap->pio_mask << ATA_SHIFT_PIO); 5670 (ap->pio_mask << ATA_SHIFT_PIO);
5809 5671
5810 /* print per-port info to dmesg */ 5672 /* print per-port info to dmesg */
5811 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%lX " 5673 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%p "
5812 "ctl 0x%lX bmdma 0x%lX irq %d\n", 5674 "ctl 0x%p bmdma 0x%p irq %d\n",
5813 ap->flags & ATA_FLAG_SATA ? 'S' : 'P', 5675 ap->flags & ATA_FLAG_SATA ? 'S' : 'P',
5814 ata_mode_string(xfer_mode_mask), 5676 ata_mode_string(xfer_mode_mask),
5815 ap->ioaddr.cmd_addr, 5677 ap->ioaddr.cmd_addr,
@@ -6328,9 +6190,8 @@ EXPORT_SYMBOL_GPL(ata_altstatus);
6328EXPORT_SYMBOL_GPL(ata_exec_command); 6190EXPORT_SYMBOL_GPL(ata_exec_command);
6329EXPORT_SYMBOL_GPL(ata_port_start); 6191EXPORT_SYMBOL_GPL(ata_port_start);
6330EXPORT_SYMBOL_GPL(ata_interrupt); 6192EXPORT_SYMBOL_GPL(ata_interrupt);
6331EXPORT_SYMBOL_GPL(ata_mmio_data_xfer); 6193EXPORT_SYMBOL_GPL(ata_data_xfer);
6332EXPORT_SYMBOL_GPL(ata_pio_data_xfer); 6194EXPORT_SYMBOL_GPL(ata_data_xfer_noirq);
6333EXPORT_SYMBOL_GPL(ata_pio_data_xfer_noirq);
6334EXPORT_SYMBOL_GPL(ata_qc_prep); 6195EXPORT_SYMBOL_GPL(ata_qc_prep);
6335EXPORT_SYMBOL_GPL(ata_noop_qc_prep); 6196EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
6336EXPORT_SYMBOL_GPL(ata_bmdma_setup); 6197EXPORT_SYMBOL_GPL(ata_bmdma_setup);