KVM: VMX: Fix exceptions of mov to dr
[safe/jmp/linux-2.6] / drivers / ata / pata_via.c
index 79a6c9a..0d97890 100644 (file)
@@ -62,7 +62,7 @@
 #include <linux/dmi.h>
 
 #define DRV_NAME "pata_via"
-#define DRV_VERSION "0.3.3"
+#define DRV_VERSION "0.3.4"
 
 /*
  *     The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx
@@ -110,7 +110,8 @@ static const struct via_isa_bridge {
        { "vt8237s",    PCI_DEVICE_ID_VIA_8237S,    0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
        { "vt8251",     PCI_DEVICE_ID_VIA_8251,     0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
        { "cx700",      PCI_DEVICE_ID_VIA_CX700,    0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_SATA_PATA },
-       { "vt6410",     PCI_DEVICE_ID_VIA_6410,     0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES},
+       { "vt6410",     PCI_DEVICE_ID_VIA_6410,     0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES },
+       { "vt6415",     PCI_DEVICE_ID_VIA_6415,     0x00, 0xff, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES },
        { "vt8237a",    PCI_DEVICE_ID_VIA_8237A,    0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
        { "vt8237",     PCI_DEVICE_ID_VIA_8237,     0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
        { "vt8235",     PCI_DEVICE_ID_VIA_8235,     0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
@@ -135,6 +136,9 @@ static const struct via_isa_bridge {
        { NULL }
 };
 
+struct via_port {
+       u8 cached_device;
+};
 
 /*
  *     Cable special cases
@@ -299,14 +303,21 @@ static void via_do_set_mode(struct ata_port *ap, struct ata_device *adev, int mo
        }
 
        /* Set UDMA unless device is not UDMA capable */
-       if (udma_type && t.udma) {
-               u8 cable80_status;
+       if (udma_type) {
+               u8 udma_etc;
+
+               pci_read_config_byte(pdev, 0x50 + offset, &udma_etc);
 
-               /* Get 80-wire cable detection bit */
-               pci_read_config_byte(pdev, 0x50 + offset, &cable80_status);
-               cable80_status &= 0x10;
+               /* clear transfer mode bit */
+               udma_etc &= ~0x20;
+
+               if (t.udma) {
+                       /* preserve 80-wire cable detection bit */
+                       udma_etc &= 0x10;
+                       udma_etc |= ut;
+               }
 
-               pci_write_config_byte(pdev, 0x50 + offset, ut | cable80_status);
+               pci_write_config_byte(pdev, 0x50 + offset, udma_etc);
        }
 }
 
@@ -333,6 +344,32 @@ static void via_set_dmamode(struct ata_port *ap, struct ata_device *adev)
 }
 
 /**
+ *     via_mode_filter         -       filter buggy device/mode pairs
+ *     @dev: ATA device
+ *     @mask: Mode bitmask
+ *
+ *     We need to apply some minimal filtering for old controllers and at least
+ *     one breed of Transcend SSD. Return the updated mask.
+ */
+
+static unsigned long via_mode_filter(struct ata_device *dev, unsigned long mask)
+{
+       struct ata_host *host = dev->link->ap->host;
+       const struct via_isa_bridge *config = host->private_data;
+       unsigned char model_num[ATA_ID_PROD_LEN + 1];
+
+       if (config->id == PCI_DEVICE_ID_VIA_82C586_0) {
+               ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
+               if (strcmp(model_num, "TS64GSSD25-M") == 0) {
+                       ata_dev_printk(dev, KERN_WARNING,
+       "disabling UDMA mode due to reported lockups with this device.\n");
+                       mask &= ~ ATA_MASK_UDMA;
+               }
+       }
+       return ata_bmdma_mode_filter(dev, mask);
+}
+
+/**
  *     via_tf_load - send taskfile registers to host controller
  *     @ap: Port to which output is sent
  *     @tf: ATA taskfile register set
@@ -345,14 +382,70 @@ static void via_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  */
 static void via_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
 {
-       struct ata_taskfile tmp_tf;
+       struct ata_ioports *ioaddr = &ap->ioaddr;
+       struct via_port *vp = ap->private_data;
+       unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
+       int newctl = 0;
+
+       if (tf->ctl != ap->last_ctl) {
+               iowrite8(tf->ctl, ioaddr->ctl_addr);
+               ap->last_ctl = tf->ctl;
+               ata_wait_idle(ap);
+               newctl = 1;
+       }
+
+       if (tf->flags & ATA_TFLAG_DEVICE) {
+               iowrite8(tf->device, ioaddr->device_addr);
+               vp->cached_device = tf->device;
+       } else if (newctl)
+               iowrite8(vp->cached_device, ioaddr->device_addr);
+
+       if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
+               WARN_ON_ONCE(!ioaddr->ctl_addr);
+               iowrite8(tf->hob_feature, ioaddr->feature_addr);
+               iowrite8(tf->hob_nsect, ioaddr->nsect_addr);
+               iowrite8(tf->hob_lbal, ioaddr->lbal_addr);
+               iowrite8(tf->hob_lbam, ioaddr->lbam_addr);
+               iowrite8(tf->hob_lbah, ioaddr->lbah_addr);
+               VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
+                       tf->hob_feature,
+                       tf->hob_nsect,
+                       tf->hob_lbal,
+                       tf->hob_lbam,
+                       tf->hob_lbah);
+       }
 
-       if (ap->ctl != ap->last_ctl && !(tf->flags & ATA_TFLAG_DEVICE)) {
-               tmp_tf = *tf;
-               tmp_tf.flags |= ATA_TFLAG_DEVICE;
-               tf = &tmp_tf;
+       if (is_addr) {
+               iowrite8(tf->feature, ioaddr->feature_addr);
+               iowrite8(tf->nsect, ioaddr->nsect_addr);
+               iowrite8(tf->lbal, ioaddr->lbal_addr);
+               iowrite8(tf->lbam, ioaddr->lbam_addr);
+               iowrite8(tf->lbah, ioaddr->lbah_addr);
+               VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
+                       tf->feature,
+                       tf->nsect,
+                       tf->lbal,
+                       tf->lbam,
+                       tf->lbah);
        }
-       ata_sff_tf_load(ap, tf);
+
+       ata_wait_idle(ap);
+}
+
+static int via_port_start(struct ata_port *ap)
+{
+       struct via_port *vp;
+       struct pci_dev *pdev = to_pci_dev(ap->host->dev);
+
+       int ret = ata_sff_port_start(ap);
+       if (ret < 0)
+               return ret;
+
+       vp = devm_kzalloc(&pdev->dev, sizeof(struct via_port), GFP_KERNEL);
+       if (vp == NULL)
+               return -ENOMEM;
+       ap->private_data = vp;
+       return 0;
 }
 
 static struct scsi_host_template via_sht = {
@@ -366,6 +459,8 @@ static struct ata_port_operations via_port_ops = {
        .set_dmamode    = via_set_dmamode,
        .prereset       = via_pre_reset,
        .sff_tf_load    = via_tf_load,
+       .port_start     = via_port_start,
+       .mode_filter    = via_mode_filter,
 };
 
 static struct ata_port_operations via_port_ops_noirq = {
@@ -421,51 +516,51 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
        /* Early VIA without UDMA support */
        static const struct ata_port_info via_mwdma_info = {
                .flags = ATA_FLAG_SLAVE_POSS,
-               .pio_mask = 0x1f,
-               .mwdma_mask = 0x07,
+               .pio_mask = ATA_PIO4,
+               .mwdma_mask = ATA_MWDMA2,
                .port_ops = &via_port_ops
        };
        /* Ditto with IRQ masking required */
        static const struct ata_port_info via_mwdma_info_borked = {
                .flags = ATA_FLAG_SLAVE_POSS,
-               .pio_mask = 0x1f,
-               .mwdma_mask = 0x07,
+               .pio_mask = ATA_PIO4,
+               .mwdma_mask = ATA_MWDMA2,
                .port_ops = &via_port_ops_noirq,
        };
        /* VIA UDMA 33 devices (and borked 66) */
        static const struct ata_port_info via_udma33_info = {
                .flags = ATA_FLAG_SLAVE_POSS,
-               .pio_mask = 0x1f,
-               .mwdma_mask = 0x07,
+               .pio_mask = ATA_PIO4,
+               .mwdma_mask = ATA_MWDMA2,
                .udma_mask = ATA_UDMA2,
                .port_ops = &via_port_ops
        };
        /* VIA UDMA 66 devices */
        static const struct ata_port_info via_udma66_info = {
                .flags = ATA_FLAG_SLAVE_POSS,
-               .pio_mask = 0x1f,
-               .mwdma_mask = 0x07,
+               .pio_mask = ATA_PIO4,
+               .mwdma_mask = ATA_MWDMA2,
                .udma_mask = ATA_UDMA4,
                .port_ops = &via_port_ops
        };
        /* VIA UDMA 100 devices */
        static const struct ata_port_info via_udma100_info = {
                .flags = ATA_FLAG_SLAVE_POSS,
-               .pio_mask = 0x1f,
-               .mwdma_mask = 0x07,
+               .pio_mask = ATA_PIO4,
+               .mwdma_mask = ATA_MWDMA2,
                .udma_mask = ATA_UDMA5,
                .port_ops = &via_port_ops
        };
        /* UDMA133 with bad AST (All current 133) */
        static const struct ata_port_info via_udma133_info = {
                .flags = ATA_FLAG_SLAVE_POSS,
-               .pio_mask = 0x1f,
-               .mwdma_mask = 0x07,
+               .pio_mask = ATA_PIO4,
+               .mwdma_mask = ATA_MWDMA2,
                .udma_mask = ATA_UDMA6, /* FIXME: should check north bridge */
                .port_ops = &via_port_ops
        };
        const struct ata_port_info *ppi[] = { NULL, NULL };
-       struct pci_dev *isa = NULL;
+       struct pci_dev *isa;
        const struct via_isa_bridge *config;
        static int printed_version;
        u8 enable;
@@ -490,15 +585,13 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
                if ((isa = pci_get_device(PCI_VENDOR_ID_VIA +
                        !!(config->flags & VIA_BAD_ID),
                        config->id, NULL))) {
+                       u8 rev = isa->revision;
+                       pci_dev_put(isa);
 
-                       if (isa->revision >= config->rev_min &&
-                           isa->revision <= config->rev_max)
+                       if (rev >= config->rev_min && rev <= config->rev_max)
                                break;
-                       pci_dev_put(isa);
                }
 
-       pci_dev_put(isa);
-
        if (!(config->flags & VIA_NO_ENABLES)) {
                /* 0x40 low bits indicate enabled channels */
                pci_read_config_byte(pdev, 0x40 , &enable);
@@ -593,6 +686,7 @@ static int via_reinit_one(struct pci_dev *pdev)
 #endif
 
 static const struct pci_device_id via[] = {
+       { PCI_VDEVICE(VIA, 0x0415), },
        { PCI_VDEVICE(VIA, 0x0571), },
        { PCI_VDEVICE(VIA, 0x0581), },
        { PCI_VDEVICE(VIA, 0x1571), },