[PATCH 2/11] drivers/watchdog: Eliminate a NULL pointer dereference
[safe/jmp/linux-2.6] / drivers / ata / pata_efar.c
index 2a6412f..a088347 100644 (file)
@@ -2,6 +2,7 @@
  *    pata_efar.c - EFAR PIIX clone controller driver
  *
  *     (C) 2005 Red Hat
+ *     (C) 2009-2010 Bartlomiej Zolnierkiewicz
  *
  *    Some parts based on ata_piix.c by Jeff Garzik and others.
  *
@@ -67,6 +68,8 @@ static int efar_cable_detect(struct ata_port *ap)
        return ATA_CBL_PATA80;
 }
 
+static DEFINE_SPINLOCK(efar_lock);
+
 /**
  *     efar_set_piomode - Initialize host controller PATA PIO timings
  *     @ap: Port whose timings we are configuring
@@ -83,7 +86,9 @@ static void efar_set_piomode (struct ata_port *ap, struct ata_device *adev)
        unsigned int pio        = adev->pio_mode - XFER_PIO_0;
        struct pci_dev *dev     = to_pci_dev(ap->host->dev);
        unsigned int idetm_port= ap->port_no ? 0x42 : 0x40;
+       unsigned long flags;
        u16 idetm_data;
+       u8 udma_enable;
        int control = 0;
 
        /*
@@ -106,6 +111,8 @@ static void efar_set_piomode (struct ata_port *ap, struct ata_device *adev)
        if (adev->class == ATA_DEV_ATA)
                control |= 4;   /* PPE */
 
+       spin_lock_irqsave(&efar_lock, flags);
+
        pci_read_config_word(dev, idetm_port, &idetm_data);
 
        /* Set PPE, IE, and TIME as appropriate */
@@ -118,18 +125,23 @@ static void efar_set_piomode (struct ata_port *ap, struct ata_device *adev)
                int shift = 4 * ap->port_no;
                u8 slave_data;
 
-               idetm_data &= 0xCC0F;
+               idetm_data &= 0xFF0F;
                idetm_data |= (control << 4);
 
                /* Slave timing in separate register */
                pci_read_config_byte(dev, 0x44, &slave_data);
-               slave_data &= 0x0F << shift;
+               slave_data &= ap->port_no ? 0x0F : 0xF0;
                slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << shift;
                pci_write_config_byte(dev, 0x44, slave_data);
        }
 
        idetm_data |= 0x4000;   /* Ensure SITRE is set */
        pci_write_config_word(dev, idetm_port, idetm_data);
+
+       pci_read_config_byte(dev, 0x48, &udma_enable);
+       udma_enable &= ~(1 << (2 * ap->port_no + adev->devno));
+       pci_write_config_byte(dev, 0x48, udma_enable);
+       spin_unlock_irqrestore(&efar_lock, flags);
 }
 
 /**
@@ -150,6 +162,7 @@ static void efar_set_dmamode (struct ata_port *ap, struct ata_device *adev)
        u16 master_data;
        u8 speed                = adev->dma_mode;
        int devid               = adev->devno + 2 * ap->port_no;
+       unsigned long flags;
        u8 udma_enable;
 
        static const     /* ISP  RTC */
@@ -159,6 +172,8 @@ static void efar_set_dmamode (struct ata_port *ap, struct ata_device *adev)
                            { 2, 1 },
                            { 2, 3 }, };
 
+       spin_lock_irqsave(&efar_lock, flags);
+
        pci_read_config_word(dev, master_port, &master_data);
        pci_read_config_byte(dev, 0x48, &udma_enable);
 
@@ -200,7 +215,7 @@ static void efar_set_dmamode (struct ata_port *ap, struct ata_device *adev)
                        master_data &= 0xFF4F;  /* Mask out IORDY|TIME1|DMAONLY */
                        master_data |= control << 4;
                        pci_read_config_byte(dev, 0x44, &slave_data);
-                       slave_data &= (0x0F + 0xE1 * ap->port_no);
+                       slave_data &= ap->port_no ? 0x0F : 0xF0;
                        /* Load the matching timing */
                        slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
                        pci_write_config_byte(dev, 0x44, slave_data);
@@ -216,6 +231,7 @@ static void efar_set_dmamode (struct ata_port *ap, struct ata_device *adev)
                pci_write_config_word(dev, master_port, master_data);
        }
        pci_write_config_byte(dev, 0x48, udma_enable);
+       spin_unlock_irqrestore(&efar_lock, flags);
 }
 
 static struct scsi_host_template efar_sht = {
@@ -251,17 +267,18 @@ static int efar_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
        static const struct ata_port_info info = {
                .flags          = ATA_FLAG_SLAVE_POSS,
                .pio_mask       = ATA_PIO4,
-               .mwdma_mask     = ATA_MWDMA2,
+               .mwdma_mask     = ATA_MWDMA12_ONLY,
                .udma_mask      = ATA_UDMA4,
                .port_ops       = &efar_ops,
        };
-       const struct ata_port_info *ppi[] = { &info, NULL };
+       const struct ata_port_info *ppi[] = { &info, &info };
 
        if (!printed_version++)
                dev_printk(KERN_DEBUG, &pdev->dev,
                           "version " DRV_VERSION "\n");
 
-       return ata_pci_sff_init_one(pdev, ppi, &efar_sht, NULL);
+       return ata_pci_bmdma_init_one(pdev, ppi, &efar_sht, NULL,
+                                     ATA_HOST_PARALLEL_SCAN);
 }
 
 static const struct pci_device_id efar_pci_tbl[] = {